ruby-on-railsrspechstorefabrication-gem

fabricator with hstore attribute


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?


Solution

  • 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