我試圖在rails應用程序中第一次使用devise,並鬆散地遵循Michael Hartl的RoR教程。我想測試用有效的信息與成功登錄後重定向登錄測試在設備上給我的Rails應用程序提供錯誤
def setup
@user = users(:michael)
end
...
test "login with valid information" do
get new_user_session_path
post new_user_session_path, session: { email: @user.email, password: 'password' }
assert_redirected_to user_path(@user)
follow_redirect!
assert_template 'users/show'
assert_select "a[href=?]", login_path, count: 0
assert_select "a[href=?]", logout_path
assert_select "a[href=?]", user_path(@user)
end
登錄,但我得到的錯誤
FAIL["test_login_with_valid_information", UsersLoginTest, 2016-04-17 19:45:37 -0400]
test_login_with_valid_information#UsersLoginTest (1460936737.50s)
Expected response to be a <redirect>, but was <200>
test/integration/users_login_test.rb:22:in `block in <class:UsersLoginTest>'
因此,它看起來像它具有與該行assert_redirected_to user_path(@user)
的問題。我知道這是事實。我加
def after_sign_in_path_for(resource)
user_path(current_user)
end
我application_controller.rb
,並通過本地主機測試驗證它。我GOOGLE了這個錯誤,並發現了幾個職位與這個相同的問題,但大多數使用的東西稱爲工廠女孩,並有解決方案,似乎並不適用於我的情況。這是怎麼回事?讓我知道是否有任何額外的信息需要。
編輯:「邁克爾」用戶在/test/fixtures/users.yml
michael:
first_name: Michael
last_name: Example
email: [email protected]
encrypted_password: <%= User.new.send(:password_digest, 'password') %>
confirmed_at: Time.zone.now
您確定登陸信息有效嗎?如果'@ user.email'和'password'的登錄組合不起作用,那麼控制器可能會再次渲染新的用戶會話路徑並出現閃存錯誤。這將解釋200狀態,而不是重定向。 – FaithoftheFallen
檢查我的更新。我在測試中添加了一行,以驗證安裝程序中的用戶是否通過了經過的'assert @ user.valid?',但我仍然得到相同的錯誤。 – mjswartz