2011-02-10 4 views
1

비슷한 질문 (Ruby on Rails Tutorial Test Not Passing)이 발견되었지만 그 대답이 내 문제와 맞지 않았습니다. 가능한 한 많은 관련 정보를 포함하려고했습니다.rspec 테스트 실패 - 사용자 로그 아웃 - 튜토리얼 서적 930

RSpec에 오류 :

Failures: 1) SessionsController DELETE 'destroy' should sign a user out Failure/Error: controller.should_not be_signed_in expected signed_in? to return false, got true # ./spec/controllers/sessions_controller_spec.rb:58:in `block (3 levels) in '

시험 :

describe "DELETE 'destroy'" do 
    it "should sign a user out" do 
     test_sign_in(Factory(:user)) 
     delete :destroy 
     controller.should_not be_signed_in 
     response.should redirect_to(root_path) 
    end 
    end 

SessionsController :

class SessionsController < ApplicationController 
    def destroy 
    sign_out 
    redirect_to root_path 
    end 

    def new 
    @title = "Sign in" 
    end 

    def create 
    user = User.authenticate(params[:session][:email], 
         params[:session][:password]) 

    if user.nil? 
     flash.now[:error] = "Invalid email/password combination" 
     @title = "Sign in" 
     render 'new' 
    else 
     sign_in user 
     redirect_to user 
    end 
    end 

    def destroy 
    end 
end 

세션 도우미

module SessionsHelper 
    def sign_in(user) 
    cookies.permanent.signed[:remember_token] = [user.id, user.salt] 
    self.current_user = user 
    end 

    def signed_in? 
    !current_user.nil? 
    end 

    def sign_out 
    cookies.delete(:remember_token) 
    self.current_user = nil 
    end 

    def current_user=(user) 
    @current_user = user 
    end 

    def current_user 
    @current_user ||= user_from_remember_token 
    end 

    private 
    def user_from_remember_token 
     User.authenticate_with_salt(*remember_token) 
    end 

    def remember_token 
     cookies.signed[:remember_token] || [nil,nil] 
    end 
end 

모든 도움을 주실 수 있습니다. 이 책을 통해 작업하는 문제를 처음 접한 것은 아니지만 문제를 해결할 수 없었던 것은 처음입니다 (다른 시간과 마찬가지로 나는 그것이 내 오류라고 확신합니다 :-)). 나는 심지어 git repo를 찾았지만, 내가 다르게 할 수 있었던 것을 확신하지 못한다.

레이크 dB : CTRL-C와
정지 자동 측정을 마이그레이션 :
레이크 DB를 다시

답변

0

그래서, 어떤 약속이 여기지만, 나도 내가 이런 짓을 할 때 멀리 갔다 이상한 RSpec에 관련된 세션 행동을 보지 못했다
다시 시작 자동 측정
중지 CTRL-C와 레일 서버
다시 시작과 레일 서버 "레일의"

나는이 문제가 해결 이유에 대한 좋은 설명이없는 있지만, 그것은 나를 위해있다. 일반적으로, 나는 Michael Hartl의 튜토리얼의 품질에 매우 감명을 받았다. 문제가 발생했을 때 그들은 항상 내가 잘못한 일을 한 결과였습니다. 이 특별한 이슈와 CH 11의 또 다른 사건은 DB의 상태로 인해 예기치 않은 행동이 발생할 수 있다고 생각하게했습니다. CH 11 문제에 대한 Q &이 여기에 있습니다 Rails 3 Tutorial Chapter 11 "Validation failed: Email has already been taken" error

Hartl은 db를 시작 지점으로 되돌리기위한 권장 방법으로 들어 가지 않습니다. 위의 내 접근 방식입니다. 거기서 내가보기에 기쁠 것 같은 더 좋은 것들이 있을지도 모릅니다.

+0

나는 이전에 이것을 업데이트하려고 했었습니다. 나는 당신이 논평 해 주셔서 감사합니다. 내 실수는 내가 개발에 반대했던 것처럼 시험에 대항하여 긁어 모으지 않았다. 그래서 나는 두 개의 차이 데이터베이스 스키마로 인해 혼합 된 결과를 얻고있었습니다. –

1

나는 위와 같은 시도를 성공적으로 시도했다. 나는 rspec에 의해 오류가 발생했기 때문에 서버가 그 일을 처리해야한다고 생각하지 않는다.

0

아마도 def destroy이 SessionsController에서 두 번 발생했기 때문에 문제가 발생한 것일 수 있습니다.

class SessionsController < ApplicationController 
    def destroy 
    sign_out 
    redirect_to root_path 
    end 

    . 
    . 
    . 

    def destroy 
    end