From 9643e3393d546ae8a7bfb68ab52b5c72c92320b2 Mon Sep 17 00:00:00 2001 From: Andy Allan Date: Wed, 8 Jan 2020 18:26:57 +0100 Subject: [PATCH] Update tests to ensure referer is working This reinstates the form tests in the controller test, but uses the system tests to actually click the button and make sure that it works --- test/controllers/users_controller_test.rb | 14 ++++++++++++ test/system/user_logout_test.rb | 26 +++++++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/test/controllers/users_controller_test.rb b/test/controllers/users_controller_test.rb index 4417d353f..c40c30b28 100644 --- a/test/controllers/users_controller_test.rb +++ b/test/controllers/users_controller_test.rb @@ -355,6 +355,20 @@ class UsersControllerTest < ActionController::TestCase assert_redirected_to "/test" end + def test_logout_fallback_without_referer + get :logout + assert_response :success + assert_template :logout + assert_select "input[name=referer][value=?]", "" + end + + def test_logout_fallback_with_referer + get :logout, :params => { :referer => "/test" } + assert_response :success + assert_template :logout + assert_select "input[name=referer][value=?]", "/test" + end + def test_logout_with_token token = create(:user).tokens.create diff --git a/test/system/user_logout_test.rb b/test/system/user_logout_test.rb index a2e145fcc..099d2c0c0 100644 --- a/test/system/user_logout_test.rb +++ b/test/system/user_logout_test.rb @@ -4,14 +4,28 @@ class UserLogoutTest < ApplicationSystemTestCase test "Sign out via link" do user = create(:user) sign_in_as(user) + assert_not page.has_content? "Log In" click_on user.display_name click_on "Log Out" assert page.has_content? "Log In" end + test "Sign out via link with referer" do + user = create(:user) + sign_in_as(user) + visit traces_path + assert_not page.has_content? "Log In" + + click_on user.display_name + click_on "Log Out" + assert page.has_content? "Log In" + assert page.has_content? "Public GPS traces" + end + test "Sign out via fallback page" do sign_in_as(create(:user)) + assert_not page.has_content? "Log In" visit logout_path assert page.has_content? "Logout from OpenStreetMap" @@ -19,4 +33,16 @@ class UserLogoutTest < ApplicationSystemTestCase click_button "Logout" assert page.has_content? "Log In" end + + test "Sign out via fallback page with referer" do + sign_in_as(create(:user)) + assert_not page.has_content? "Log In" + + visit logout_path(:referer => "/traces") + assert page.has_content? "Logout from OpenStreetMap" + + click_button "Logout" + assert page.has_content? "Log In" + assert page.has_content? "Public GPS traces" + end end -- 2.39.5