Skip to content

Commit

Permalink
Fix record not found error when session no longer exists in database (#…
Browse files Browse the repository at this point in the history
…27)

This addresses issue #7.

- Changes `Session.find` to `Session.find_by` in
`DemoMode::Demoable#current_demo_session` to prevent a Not Found
exception when the session is no longer in the database, e.g., after
resetting the database.
- Checks that the `current_demo_session` is not `nil` in
`DemoMode::Demoable#demo_splash!`.
- Adds a system spec for this scenario
  • Loading branch information
rafahuaman authored Jul 10, 2024
1 parent fb63de7 commit 3bef013
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
demo_mode (1.2.2)
demo_mode (1.2.3)
cli-ui
rails (>= 6.1)
sprockets-rails
Expand Down
9 changes: 8 additions & 1 deletion app/controllers/concerns/demo_mode/demoable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion gemfiles/rails_6_1.gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: ..
specs:
demo_mode (1.2.2)
demo_mode (1.2.3)
cli-ui
rails (>= 6.1)
sprockets-rails
Expand Down
2 changes: 1 addition & 1 deletion gemfiles/rails_7_0.gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: ..
specs:
demo_mode (1.2.2)
demo_mode (1.2.3)
cli-ui
rails (>= 6.1)
sprockets-rails
Expand Down
2 changes: 1 addition & 1 deletion lib/demo_mode/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module DemoMode
VERSION = '1.2.2'
VERSION = '1.2.3'
end
19 changes: 19 additions & 0 deletions spec/system/demo_splash_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 3bef013

Please sign in to comment.