2010-11-25 2 views
0

로그인을 위해 authlogic과 함께 레일을 사용하고 있습니다. rspec 및 webrat로 로그 아웃하기위한 통합 테스트를 작성하려고합니다.Webrat, Rails with Authlogic으로 테스트하지 못함

내가보기에 문제는 우리가 클릭 할 때와 다른 동작을하는 것 같습니다. 따라서 브라우저를 클릭 할 때 로그인하여 로그 아웃 할 수는 있지만 로그 아웃 할 수없는 것 같습니다. 로그인 한 경우 로그 아웃 링크 만 표시하기 때문에 진단 할 수 있지만 로그 아웃을 클릭 한 후에는 여전히 webrat에서 발견하고 있습니다.

여기 내 테스트 코드의 내 routes.rb

map.resources :users                                              
    map.resources :user_sessions 
    map.login '/login', :controller => 'user_sessions', :action => 'new' 
    map.logout '/logout', :controller => 'user_sessions', :action => 'destroy' 

에서

describe "when not signed in" do 
    it "should have a sign in link" do 
     visit root_path   
     response.should have_tag("a[href=?]", login_path, "Log In") 
    end       
    end 

    describe "when signed in" do 
    before :each do    
     @user = Factory(:user) 
     visit login_path   
     fill_in :user_session_email, :with => @user.email 
     fill_in :user_session_password, :with => @user.password 
     click_button 
    end 

    it "should have a log out button" do 
     visit root_path   
     response.should have_tag("a[href=?]", logout_path, "Log Out") 
    end 

    # This is the test that's failing                                           
    it "we should be able to log out" do 
     visit root_path 
     click_link /log out/i 
     response.should render_template('merchant_pages/home') 
     #this next line is the one that fails 
     #I've played around with this, and the log out link is still there 
     response.should have_tag("a[href=?]", login_path, "Log In") 
    end 
    end 

몇 줄 내가 user_sessions_controller에서

<ul class="navigation round"> 
    <li><%= link_to("Log In", login_path) unless current_user %></li> 
    <li><%= link_to("Log Out", logout_path) if current_user %></li> 
    </ul> 

찾고 있어요 링크

def destroy 
    current_user_session.destroy 
    flash[:notice] = "Logout successful!" 
    redirect_to root_url 
    end 
012 내가 수동으로 로그 아웃 할 때

authlogic (2.1.6) 
rails (2.3.8) 
rake (0.8.7) 
rspec (1.3.0) 
rspec-core (2.0.1) 
rspec-expectations (2.0.1) 
rspec-mocks (2.0.1) 
rspec-rails (1.3.2) 
webrat (0.7.2) 

그래서 application_controller

def current_user_session 
    return @current_user_session if defined?(@current_user_session) 
    @current_user_session = UserSession.find 
end 

def current_user 
    return @current_user if defined?(@current_user) 
    @current_user = current_user_session && current_user_session.record 
end 

관련 보석 버전 3,516,

, 결론에서, 나는 홈 페이지로 이동, 나는 나에게 가능한 링크의 로그를 로그 아웃 링크 없음. 위의 테스트에서 webrat를 통과하면 아무런 로그인 링크도 없으며 로그 아웃 링크도 계속 남아 있습니다. 여전히 로그인되어 있음을 나타냅니다.

+0

버그가'click_link/log out/i' 행에 있다고 생각합니다. 대신'click_link "로그 아웃"을 사용해야합니까? – tjeden

+0

나는 그것을 시도했다. 설명 된 것과 동일한 동작입니다. –

답변

1

데이터베이스 세션 저장소가 아닌 쿠키 세션 저장소. config/initializers/session_store.rb를 참조하십시오.

어제 저는 2.3.5에서 2.3.8까지 개발중인 프로젝트를 포팅하기 시작했습니다. 2.3.5에서 모든 사양과 기능은 녹색이었습니다. Rails 버전을 2.3.8로 변경 한 후 몇몇 오이 단계가 실패하기 시작했습니다. 이 단계는 로그 아웃 할 수 없음 (정확히 여기서 설명하는 내용)과 플래시 [: 통지]가 손실된다는 것과 관련이 있습니다. 이 프로젝트는 다른 프로젝트의 파일을 깨끗한 슬레이트 레일 프로젝트로 복사하여 만들었습니다. 이 과정에서 세션 마이그레이션이 복사되었지만 session_store.rb가 실제로 데이터베이스를 사용하도록 업데이트되지 않았습니다.

session_store.rb에서 "ActionController :: Base.session_store = : active_record_store"의 주석을 제거한 후에 오이 단계가 전달되기 시작했습니다.

+0

동일한 오류가 발생합니다. 활성 레코드 세션 저장소를 계속 사용하고 세션에서 오이 작업을 계속하는 것이 좋을 것입니다. –