使用 factory_girl 填充 Rails PostgreSQL hstore

Populate Rails PostgreSQL hstore using factory_girl

我正在使用 Rails 4.2 和 factory_girl 来填充我的测试数据库。我有一个使用 hstore 存储一些非结构化数据的模型。如何从 factory_girl 填充 hstore?传递一个哈希值就这么简单吗?

最初我试过这个:

FactoryGirl.define do
  factory :thingy do
    unstructured_data {
      foo: "foo",
      bar: "bar"
    }
  end
end

看起来你只是传递了一个哈希。我确实发现我必须将哈希分配给一个对象,但我可能也可以使用括号来让它工作。

FactoryGirl.define do
  factory :thingy do
    hash = {
      foo: "foo",
      bar: "bar"
    }

    unstructured_data hash
  end
end