From 169507f4e5bbf7be904f9c2701c233d3f5cd8eb1 Mon Sep 17 00:00:00 2001 From: baarkerlounger <5101747+baarkerlounger@users.noreply.github.com> Date: Tue, 25 Jan 2022 18:32:52 +0000 Subject: [PATCH] Fix sign out link (UJS -> Turbo) (#246) * Fix sign out link (UJS -> Turbo) * Only works for JS... * Specify method and turbo method so that we also get a delete request --- Gemfile.lock | 2 +- app/views/layouts/application.html.erb | 2 +- spec/features/user_spec.rb | 20 ++++++++++++++++++++ 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 346f575c9..46cfa6279 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -8,7 +8,7 @@ GIT GIT remote: https://github.com/baarkerlounger/devise.git - revision: 223969286e51b02e78309b7dad908d223d6ba7f5 + revision: ac956cc2a58daa57e071202967a212a1dac08053 branch: dluhc-fixes specs: devise (4.8.1) diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 660b80bb8..4055cda6c 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -46,7 +46,7 @@ component.navigation_item(text: 'Your logs', href: case_logs_path) component.navigation_item(text: 'Your organisation', href: "/organisations/#{current_user.organisation.id}") component.navigation_item(text: 'Your account', href: user_path(current_user)) - component.navigation_item(text: 'Sign out', href: destroy_user_session_path, options: {:method => :delete}) + component.navigation_item(text: 'Sign out', href: destroy_user_session_path, options: { data: {turbo_method: :delete}, method: :delete }) end end %> diff --git a/spec/features/user_spec.rb b/spec/features/user_spec.rb index dd8eacfce..835321c6a 100644 --- a/spec/features/user_spec.rb +++ b/spec/features/user_spec.rb @@ -30,6 +30,26 @@ RSpec.describe "User Features" do click_button("Sign in") expect(page).to have_current_path("/logs") end + + it " can log out again", js: true do + visit("/logs") + fill_in("user[email]", with: user.email) + fill_in("user[password]", with: "pAssword1") + click_button("Sign in") + click_link("Sign out") + expect(page).to have_current_path("/") + expect(page).to have_content("Start now") + end + + it " can log out again with js disabled" do + visit("/logs") + fill_in("user[email]", with: user.email) + fill_in("user[password]", with: "pAssword1") + click_button("Sign in") + click_link("Sign out") + expect(page).to have_current_path("/") + expect(page).to have_content("Start now") + end end context "A user who has forgotten their password" do