问题
I am trying to build a fabricator using 'fabrication', '2.8.1' with a hstore attribute.
Fabricator(:inventory_item_change) do
attribute_changes Hash.new("num_units" => "to:50")
state "scheduled"
change_code 1
execution_at Time.now.advance(days: 3)
inventory_item
end
This is the error message I am receiving when running tests with this fabricator. I've isolated the problem to be the hstore attribute: attribute changes.
Failure/Error: attr = Fabricate.attributes_for(:inventory_item_change)
ArgumentError:
bad value for range
Can anyone assist in identifying the correct syntax, or another suitable solution for fabricating objects with hstore attributes?
回答1:
take a look at the following issue at on github:
https://github.com/paulelliott/fabrication/issues/202
It seems as though you can't directly pass the hash in as it is then treated as an options argument.
The correct syntax for you would be:
Fabricator(:inventory_item_change) do
attribute_changes do
{ "num_units" => "to:50"}
end
state "scheduled"
change_code 1
execution_at Time.now.advance(days: 3)
inventory_item
end
来源:https://stackoverflow.com/questions/23769399/fabricator-with-hstore-attribute