2015-02-05 2 views
0

나는 Hartl의 RoR 튜토리얼을 통해 작업 해 왔고, 잠시 동안이 부분에 갇혀있다. 나는이 넣어지고 결국실패한 단언, 주어진 메시지 없음 : rails

$ bundle exec rake test 

: 내가 가진 계정 활성화 테스트 실행하려고 여기

1) Failure: 
    UsersSignupTest#test_valid_signup_information_with_account_activation  [/Users/*name/blogger1/test/integration/users_signup_test.rb:44]: 
Failed assertion, no message given. 

나의 users_signup_test.rb 파일에 내 테스트 코드입니다 :

require 'test_helper' 

class UsersSignupTest < ActionDispatch::IntegrationTest 

def setup 
    ActionMailer::Base.deliveries.clear 
end 

test "invalid signup information" do 
    get signup_path 
    assert_no_difference 'User.count' do 
    post users_path, user: { name: "", 
          email: "[email protected]", 
          password:    "foo", 
          password_confirmation: "bar" } 
end 
assert_template 'users/new' 
assert_select 'div#error_explanation' 
assert_select 'div.field_with_errors' 
end 

test "valid signup information with account activation" do 
get signup_path 
assert_difference 'User.count', 1 do 
    post users_path, user: { name: "Example User", 
          email: "[email protected]", 
          password:    "password", 
          password_confirmation: "password" } 
end 
assert_equal 1, ActionMailer::Base.deliveries.size 
user = assigns(:user) 
assert_not user.activated? 
# Try to log in before activation. 
log_in_as(user) 
assert_not is_logged_in? 
# Invalid activation token 
get edit_account_activation_path("invalid token") 
assert_not is_logged_in? 
# Valid token, wrong email 
get edit_account_activation_path(user.activation_token, email: 'wrong') 
assert_not is_logged_in? 
# Valid activation token 
get edit_account_activation_path(user.activation_token, email: user.email) 
assert user.reload.activated? 
follow_redirect! 
assert_template 'users/show' 
assert is_logged_in? 
end 
end 

튜토리얼을 따라 갔을 때 코드를 읽고 나서 직접 입력했습니다. 그러나 이번에는 모든 문제를 가지고 돌아가서 복사하고 붙여 넣었습니다. 어떤 아이디어가 될 수 있을까요?

라인 (44)은 다음과 같습니다

assert user.reload.activated? 

하지만 다른 곳에서는 논리적 인 사람이어야했다 아무것도 찾을 수 없습니다?

답변

0

나는 어제 똑같은 문제가 있었지만, 문제는 테스트에 있지 않지만 '활성화 된 것입니까?' 메서드 자체가 제대로 작동하지 않습니다.

'정품 인증'을 추적하여 해결책을 찾았습니다. 제 경우에는 사용자 모델의 create_activation_digest 메소드에서 오류를 발견 한 오류를 입력하는 메소드입니다.

희망이 도움이됩니다.

-1

인증 된? 방법 : return false if digest.nil?. 내 오류는 그것에서 비롯되었습니다.

0

나는 정확히 같은 문제가있어 해결되었습니다. 필자의 경우 AccountActivationsController에서 log_in (user) 메서드가 누락되었습니다.

성공적으로 활성화 된 사용자는 AccountActivationsController에 로그인하십시오.

class AccountActivationsController < ApplicationController 

    def edit 
    user = User.find_by(email: params[:email]) 
    if user && !user.activated? && user.authenticate_with_token(:activation, params[:id]) 
     user.activate 
     **log_in user** 
     flash[:success] = "Account activated!" 
     redirect_to user 
    else 
     flash[:danger] = "Invalid activation link" 
     redirect_to root_url 
    end 
    end 
end 

마이클 하틀의 Ruby on Rails Tutorial

관련 문제