Commit edc9564a authored by Paul Slaughter's avatar Paul Slaughter

Fix "sign out" button in error pages

- Added some vanilla JS since we don't have
  rails_ujs here. If rails_ujs was here we could
  simple use data-method.
parent 16e74e4e
...@@ -4,7 +4,8 @@ ...@@ -4,7 +4,8 @@
= link_to s_('Nav|Home'), root_path = link_to s_('Nav|Home'), root_path
%li %li
- if current_user - if current_user
= link_to s_('Nav|Sign out and sign in with a different account'), destroy_user_session_path, method: :post = link_to s_('Nav|Sign out and sign in with a different account'), '#', id: 'sign_out_link'
%form{ action: destroy_user_session_path, method: :post, id: 'sign_out_form' }
- else - else
= link_to s_('Nav|Sign In / Register'), new_session_path(:user, redirect_to_referer: 'yes') = link_to s_('Nav|Sign In / Register'), new_session_path(:user, redirect_to_referer: 'yes')
%li %li
......
...@@ -20,4 +20,10 @@ ...@@ -20,4 +20,10 @@
history.back(); history.back();
}); });
} }
// We do not have rails_ujs here, so we're manually making a link trigger a form submit.
document.getElementById('sign_out_link').addEventListener('click', function(e) {
e.preventDefault();
document.getElementById('sign_out_form').submit();
});
}()); }());
---
title: Fix sign out button in error pages
merge_request: 59030
author:
type: fixed
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
require 'spec_helper' require 'spec_helper'
RSpec.describe 'Error Pages' do RSpec.describe 'Error Pages', :js do
let(:user) { create(:user) } let(:user) { create(:user) }
let(:project) { create(:project, :public) } let(:project) { create(:project, :public) }
...@@ -14,7 +14,12 @@ RSpec.describe 'Error Pages' do ...@@ -14,7 +14,12 @@ RSpec.describe 'Error Pages' do
it 'shows nav links' do it 'shows nav links' do
expect(page).to have_link("Home", href: root_path) expect(page).to have_link("Home", href: root_path)
expect(page).to have_link("Help", href: help_path) expect(page).to have_link("Help", href: help_path)
expect(page).to have_link(nil, href: destroy_user_session_path) end
it 'allows user to sign out' do
click_link 'Sign out and sign in with a different account'
expect(page).to have_current_path(new_user_session_path)
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment