fabricator with hstore attribute

雨燕双飞 提交于 2019-12-11 02:59:57

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!