geekq / workflow

Ruby finite-state-machine-inspired API for modeling workflow
MIT License
1.75k stars 207 forks source link

x.spec throws error. Is spec keyword in workflow? - no implicit conversion of Workflow::Specification into String #170

Closed emclab closed 2 years ago

emclab commented 8 years ago

In Rails 4.2.0 app with workflow 1.2.0, there are 2 models order and order_items. order has_many order_items. There is a workflow defined in model order. In order_item table there is a spec attribute which stores part specification (in text) .

class Order < ActiveRecord::Base include Workflow has_many :order_items end

class Order_Item < ActiveRecord::Base belong_to :order end

Given an order in @order, we did the following:

@order.order_items.map {|x| [x.name + x.spec, x.item_num]}

which should return an array. However the x.spec causes the error below:

no implicit conversion of Workflow::Specification into String

In debug, here is what it returns for @order.order_items.first.spec

@order.ordr_items.first.spec = #Workflow::Specification:0x6a96530 @order.ordr_items.first.name = 'Sensor'

It seems that x.spec triggers workflow in model order and tried to return Workflow::Specification. In debug we examine the value in order_item and there is a valid text value for spec attribute.

Why x.spec (x is an order_item) tries to return workflow specification in order? Is it a bug in workflow engine?

emclab commented 8 years ago

@order.order_items.map {|x| [x.name, x.item_num]} works fine.