Я использую rails с authlogic для входа. Я пытаюсь написать интеграционный тест для выхода из rspec и webrat.
Проблема, с которой я сталкиваюсь, заключается в том, что webrat, похоже, становится другимповедение, чем я, когда я нажимаю.Итак, я могу войти в систему, а затем просто выйти из нее, когда я нажимаю в браузере, но webrat, похоже, не может выйти из системы.Я диагностирую это, потому что я показываю ссылку выхода из системы только в том случае, если вы вошли в систему, но webrat все равно находит ее после нажатия кнопки «Выйти».
Вот мой тестовый код
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
Aнесколько строк из моего rout.rb
map.resources :users
map.resources :user_sessions
map.login '/login', :controller => 'user_sessions', :action => 'new'
map.logout '/logout', :controller => 'user_sessions', :action => 'destroy'
ссылки, которые я ищу
<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>
из user_sessions_controller
def destroy
current_user_session.destroy
flash[:notice] = "Logout successful!"
redirect_to root_url
end
из 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
Соответствующие версии gem
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)
Итак, в заключение, когда я выхожу вручную, я перехожу на домашнюю страницу, и у меня есть доступная ссылка для входа без ссылки на выход.Когда я прохожу webrat в тесте, приведенном выше, я не получаю ссылку для входа в систему, а ссылка для выхода из системы все еще там - это указывает на то, что я все еще вошел в систему.