我到Rails的教程section 11.3.3讓我吃驚了以下錯誤現在出現(Rails的教程第11章):用戶編輯測試將帳號激活郵件失敗後
FAIL [「test_unsuccessful_edit」,UsersEditTest ,90.26555655000266] test_unsuccessful_edit#UsersEditTest(90.27s) 期待< 「用戶/編輯」>但< []> 測試/集成渲染/ users_edit_test.rb:13:在`塊'
FAIL [」 test_successful_edit_with_friendly_forwarding「,我們ersEditTest, 90.43167781096417] test_successful_edit_with_friendly_forwarding#UsersEditTest(90.43s) 預期響應爲重定向至,但重定向至 www.example.com/>。 預計「www.example.com/users/637627528/edit」爲===「www.example.com/」。 測試/集成/ users_edit_test.rb:23:在`塊'
下面是失敗的測試:
test "unsuccessful edit" do
log_in_as(@user)
get edit_user_path(@user)
assert_template 'users/edit'
patch user_path(@user), params: { user: { name: "", email: "[email protected]", password: "foo", password_confirmation: "bar" } }
assert_template 'users/edit'
assert_select 'div.alert', "The form contains 4 errors."
assert_select 'div.alert-danger'
end
test "successful edit with friendly forwarding" do
get edit_user_path(@user)
log_in_as(@user)
assert_redirected_to edit_user_path(@user)
assert session[:forwarding_url] == nil
name = "Foo bar"
email = "[email protected]"
patch user_path(@user), params: { user: { name: name, email: email, password: "", password_confirmation: "" } }
assert_not flash.empty?
assert_redirected_to @user
@user.reload # Reloads the user's values from the database
assert_equal name, @user.name
assert_equal email, @user.email
end
位於users_controller.rb以下:
def update
@user = User.find(params[:id])
if @user.update_attributes(user_params)
flash[:success] = "Profile updated"
redirect_to @user
else
render 'edit'
end
end
出於某種原因,在更新會話控制器以包含帳戶激活後出現這些錯誤。所以,如果它以某種方式相關,下面是我更新sessions_controller.rb部分:
def create
user = User.find_by(email: params[:session][:email].downcase)
if user && user.authenticate(params[:session][:password])
if user.activated?
log_in user
params[:session][:remember_me] == '1' ? remember(user) : forget(user)
redirect_back_or user
else
message = "Account not activated. "
message += "Check your email for the activation link."
flash[:warning] = message
redirect_to root_url
end
else
flash.now[:danger] = 'Invalid email/password combination'
render 'new'
end
end
我嘗試使用byebug但我似乎無法找到的問題!有任何想法嗎?