randombits
randombits

Reputation: 48500

Mongoid hash property in FactoryGirl

How does one write a Factory Girl definition for a Mongoid class where one of the properties is a hash? (it is not an embedded document)

The Mongoid class looks something such as

class Foo
  field :bar, :type => Hash
end

so an instance of Foo should be able to access bar via foo.bar['foobar'] = 1

This cannot be depicted in a Factory Girl definition though by doing something like:

Factory.define :foo do |f|
  f.bar   {:foobar => 1}
end

Upvotes: 0

Views: 695

Answers (1)

Koraktor
Koraktor

Reputation: 42983

I don't know FactoryGirl, but I'd guess that Ruby is interpreting the curly brackets as a block. This should work:

Factory.define :foo do |f|
  f.bar({:foobar => 1})
end

Upvotes: 5

Related Questions