diff --git a/Gemfile.lock b/Gemfile.lock index 5a9598a..29774ce 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - demo_mode (1.2.2) + demo_mode (1.2.3) cli-ui rails (>= 6.1) sprockets-rails diff --git a/app/controllers/concerns/demo_mode/demoable.rb b/app/controllers/concerns/demo_mode/demoable.rb index 601e5de..2f1fded 100644 --- a/app/controllers/concerns/demo_mode/demoable.rb +++ b/app/controllers/concerns/demo_mode/demoable.rb @@ -12,7 +12,14 @@ module Demoable def current_demo_session if session.key?(:demo_session) @current_demo_session = nil if @current_demo_session&.id != session[:demo_session]['id'] - @current_demo_session ||= Session.find(session[:demo_session]['id']) + @current_demo_session ||= Session.find_by(id: session[:demo_session]['id']) + + if @current_demo_session.nil? + session.delete(:demo_session) + sign_out + end + + @current_demo_session end end diff --git a/gemfiles/rails_6_1.gemfile.lock b/gemfiles/rails_6_1.gemfile.lock index 0d9088a..3ea0268 100644 --- a/gemfiles/rails_6_1.gemfile.lock +++ b/gemfiles/rails_6_1.gemfile.lock @@ -1,7 +1,7 @@ PATH remote: .. specs: - demo_mode (1.2.2) + demo_mode (1.2.3) cli-ui rails (>= 6.1) sprockets-rails diff --git a/gemfiles/rails_7_0.gemfile.lock b/gemfiles/rails_7_0.gemfile.lock index 459b0fd..4afb7c2 100644 --- a/gemfiles/rails_7_0.gemfile.lock +++ b/gemfiles/rails_7_0.gemfile.lock @@ -1,7 +1,7 @@ PATH remote: .. specs: - demo_mode (1.2.2) + demo_mode (1.2.3) cli-ui rails (>= 6.1) sprockets-rails diff --git a/lib/demo_mode/version.rb b/lib/demo_mode/version.rb index c8170ed..9819e93 100644 --- a/lib/demo_mode/version.rb +++ b/lib/demo_mode/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module DemoMode - VERSION = '1.2.2' + VERSION = '1.2.3' end diff --git a/spec/system/demo_splash_spec.rb b/spec/system/demo_splash_spec.rb index 1b0594a..756f3bb 100644 --- a/spec/system/demo_splash_spec.rb +++ b/spec/system/demo_splash_spec.rb @@ -213,6 +213,25 @@ expect(DemoMode::Session.last.signinable).to be_a(Widget) end end + + context "When the session no longer exists in the database" do + it 'redirects to the splash screen' do + visit '/' + + within '.dm-Persona--theEveryperson' do + click_button 'Sign In' + end + + expect(page).to have_text('Your Name: Spruce Bringsteen') + + DemoMode::Session.delete_all + + visit '/' + + expect(page).to have_text('Demo Mode') + expect(page).to have_text('The Everyperson') + end + end end context 'when demo mode is not enabled' do