本文介绍了具有hstore属性的制造者的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用具有hstore属性的'fabrication','2.8.1'来构建fabricator.

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

这是使用此制造器运行测试时收到的错误消息.我已经将问题归结为hstore属性:属性更改.

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

任何人都可以协助识别正确的语法,或者其他合适的解决方案来构造具有hstore属性的对象?

Can anyone assist in identifying the correct syntax, or another suitable solution for fabricating objects with hstore attributes?

推荐答案

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

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.

您的正确语法将是:

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

这篇关于具有hstore属性的制造者的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-21 08:56