Factory Girl, Mongoid, and Embedded Documents
I am setting up my first app with Mongoid and Devise. I am trying to Factory a user in my test with this factory:
Factory.define(:user) do |f|
f.email "bob1234@example.com"
f.password "testing"
f.password_confirmation "testing"
end
When I try and factory this I get this error:
NoMethodError: undefined method `add_on_blank' for []:Array
from /Library/Ruby/Gems/1.8/gems/mongoid-2.0.1/lib/mongoid/criteria.rb:213:in `send'
from /Library/Ruby/Gems/1.8/gems/mongoid-2.0.1/lib/mongoid/criteria.rb:213:in `method_missing'
from /Library/Ruby/Gems/1.8/gems/mongoid-2.0.1/lib/mongoid/relations/embedded/many.rb:373:in `send'
from /Library/Ruby/Gems/1.8/gems/mongoid-2.0.1/lib/mongoid/relations/embedded/many.rb:373:in `method_missing'
from /Library/Ruby/Gems/1.8/gems/mongoid-2.0.1/lib/mongoid/named_scope.rb:121:in `with_scope'
from /Library/Ruby/Gems/1.8/gems/mongoid-2.0.1/lib/mongoid/relations/embedded/many.rb:372:in `send'
from /开发者_高级运维Library/Ruby/Gems/1.8/gems/mongoid-2.0.1/lib/mongoid/relations/embedded/many.rb:372:in `method_missing'
My models look like:
User:
class User
include Mongoid::Document
# Include default devise modules. Others available are:
# :token_authenticatable, :encryptable, :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
attr_accessible :email, :password, :password_confirmation, :remember_me
embeds_many :errors
end
Error:
class Error
include Mongoid::Document
field :klass, :type => String
embedded_in :user
end
How should a user model be created without creating any embedded documents at the same time?
精彩评论