【问题标题】:fabricator with hstore attribute具有 hstore 属性的制造商
【发布时间】:2014-05-20 20:32:11
【问题描述】:

我正在尝试使用带有 hstore 属性的“fabrication”、“2.8.1”来构建制造商。

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

这是我在使用此制造商运行测试时收到的错误消息。我已将问题隔离为 hstore 属性:属性更改。

 Failure/Error: attr = Fabricate.attributes_for(:inventory_item_change)
 ArgumentError:
   bad value for range

任何人都可以帮助确定正确的语法,或其他合适的解决方案来制造具有 hstore 属性的对象吗?

【问题讨论】:

    标签: ruby-on-rails rspec hstore fabrication-gem


    【解决方案1】:

    在 github 上查看以下问题:
    https://github.com/paulelliott/fabrication/issues/202

    似乎您不能直接传递哈希值,因为它会被视为选项参数。

    正确的语法是:

    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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-03-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多