我认为我的用户工厂构建存在问题。我收到一个错误,说密码不能为空,但是在我的factories.rb文件中已经明确设置了密码。有没有人看到我可能遗漏的内容?或者规范失败的原因?我对另一个模型执行非常类似的操作,看起来很成功。我不确定这个错误是否由devise引起。
Rspec Error
User should create a new instance of a user given valid attributes
Failure/Error: User.create!(@user.attributes)
ActiveRecord::RecordInvalid:
Validation failed: Password can't be blank
# ./spec/models/user_spec.rb:28:in `block (2 levels) in <top (required)>'
Factories.rb
Factory.define :user do |user|
user.name "Test User"
user.email "user@example.com"
user.password "password"
user.password_confirmation "password"
end
user_spec.rb
require 'spec_helper'
describe User do
before(:each) do
@user = Factory.build(:user)
end
it "should create a new instance of a user given valid attributes" do
User.create!(@user.attributes)
end
end
user.rb
class User < ActiveRecord::Base
# Include default devise modules. Others available are:
# :token_authenticatable, :encryptable, :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
# Setup accessible (or protected) attributes for your model
attr_accessible :email, :password, :password_confirmation, :remember_me
end