ユーザーモデルでオーバーライドしたデバイスからの update_with_password メソッドをテストするのに問題があります。
Rails 3.2、Devise 2.2.3、Rspec-rails 2.13 を使用しています。
ユーザー モデルの update_with_password メソッドは次のようになります。
#app/model/user.rb
def update_with_password(params, *options)
if encrypted_password.blank?
update_attributes(params, *options)
else
super
end
end
これが私の仕様です:
#spec/model/user_spec.rb
describe "#update_with_password" do
context "when encrypted password is blank" do
before(:each) do
@user = FactoryGirl.build(:user_via_facebook)
@user.save(validate: false)
@facebook_profile = FactoryGirl.create(:facebook_profile, user: @user)
end
it "updates user attributes without asking current password" do
@user.update_with_password(params: {first_name: "New First Name"})
@user.first_name.should eql "New First Name"
end
end
end
そして、これは仕様を実行した後に私が得ているエラーです:
User#update_with_password when encrypted password is blank updates user attributes without asking current password
Failure/Error: @user.update_with_password(params: {first_name: "New First Name"})
ActiveModel::MassAssignmentSecurity::Error:
Can't mass-assign protected attributes: params
このメソッドをどのようにテストすればよいですか? 私には欠けているものがあり、これを理解することはできません。前もって感謝します。