로그인을 위해 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를 통과하면 아무런 로그인 링크도 없으며 로그 아웃 링크도 계속 남아 있습니다. 여전히 로그인되어 있음을 나타냅니다.
버그가'click_link/log out/i' 행에 있다고 생각합니다. 대신'click_link "로그 아웃"을 사용해야합니까? – tjeden
나는 그것을 시도했다. 설명 된 것과 동일한 동작입니다. –