私は既存のアプリを引き継いだので、Devise は初めてです。認証にDeviseを使用しています(確認不可)。update_with_password メソッドを使用する users_controller の update メソッドのテストを作成しようとしています。
ここで何が間違っているのかわかりません。リクエストに正しいパラメーターを渡していないか (ただし、開発とモデル化されたテストで確認しましたが (フォームの Authenticity_token を除く))、何か問題が発生しています。
私は Test::Unit とフィクスチャを使用しています:
users_controller で:
def update
@user = current_account.users.find(params[:id])
raise @user.valid_password?(params[:user][:current_password]).inspect
if @user.update_with_password(params[:user])
sign_in(@user, :bypass => true)
flash[:notice] = flash_saved
redirect_to edit_user_path(@user)
else
flash[:alert] = flash_not_saved
render 'edit'
end
end
users_controller_test では:
test "should update user with password" do
@user = users(:participant)
sign_in(@user)
assert_equal(true, @user.valid_password?('<password>'))
put :update, {id: @user.id, method: :put, :user => {email: @user.email, password: nil, password_confirmation: nil, current_password: "<password>", firstname: "louis"}, subaccount: "test"}
end
備品で:
participant:
email: participant@test.com
id: 3
confirmed_at: 2013-01-01 00:10:00
account_id: 1
firstname: participant
last_sign_in_at: <%= Time.now - 30 %>
encrypted_password: <encrypted_password>
password_salt: <password_salt>
開発中のユーザーから encrypted_password と password_salt をコピーしましたが、テストのアサーションは false を返します。
開発中のリクエスト パラメータ:
{"utf8"=>"✓",
"_method"=>"put",
"authenticity_token"=>"hy3IJ8C7qQs+iyxZ/VCnrVWEh9vecZCGrAuxwEWxWEE=",
"user"=>{"email"=>"my@email.com",
"firstname"=>"",
"lastname"=>"",
"gender"=>"",
"phone1"=>"",
"current_password"=>"[FILTERED]",
"password"=>"[FILTERED]",
"password_confirmation"=>"[FILTERED]"},
"commit"=>"Opslaan",
"subaccount"=>"experience",
"id"=>"3087"}
テスト中のリクエスト パラメータ:
{"subdomain"=>nil, "method"=>"put", "user"=>{"email"=>"participant@test.com", "firstname"=>"louis"}, "id"=>"3", "subaccount"=>"test", "controller"=>"users", "action"=>"update"}
リクエストで送信していますが、どういうわけか :current_password が表示されません。
どうすればこのテストに合格できますか? あなたの助けは大歓迎です...