Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

force checkouts and holds pages reload on browser back button #231

Merged
merged 2 commits into from
Aug 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,11 @@ def renew_session_token
def item_details
{}
end

# Force page to reload on browser back in Rails
def set_cache_headers
response.headers['Cache-Control'] = 'no-cache, no-store, max-age=0, must-revalidate'
response.headers['Pragma'] = 'no-cache'
response.headers['Expires'] = 'Fri, 01 Jan 1990 00:00:00 GMT'
end
end
1 change: 1 addition & 0 deletions app/controllers/checkouts_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

class CheckoutsController < ApplicationController
include ActionView::Helpers::TagHelper
before_action :set_cache_headers
before_action :authenticate_user!
before_action :renew_params, only: :batch_update
before_action :authorize_update!, only: :batch_update
Expand Down
1 change: 1 addition & 0 deletions app/controllers/holds_controller.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# frozen_string_literal: true

class HoldsController < ApplicationController
before_action :set_cache_headers
before_action :authenticate_user!
before_action :check_for_blanks!, only: :create
rescue_from HoldCreateException, with: :deny_create
Expand Down
4 changes: 2 additions & 2 deletions app/models/patron.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ def display_name

def checkouts
@checkouts ||= fields['circRecordList']
.map { |checkout| Checkout.new(checkout) }
.select { |checkout| checkout.status == 'ACTIVE' }
&.map { |checkout| Checkout.new(checkout) }
&.select { |checkout| checkout.status == 'ACTIVE' }
end

def holds
Expand Down
9 changes: 9 additions & 0 deletions spec/features/checkouts_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,13 @@
expect(page).to have_css('.toast')
end
end

context 'when patron uses browser back button to checkouts page' do
it 'forces checkout page to reload', js: true do
visit checkouts_path
visit summaries_path
page.go_back
expect(page).to have_css '[id="checkout2145643:5:1"]'
end
end
end
9 changes: 9 additions & 0 deletions spec/features/holds_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,13 @@
expect(page).to have_text 'Hold Placed'
end
end

context 'when patron uses browser back button to holds page' do
it 'forces checkout page to reload', js: true do
visit holds_path
visit summaries_path
page.go_back
expect(page).to have_css '#hold3911148'
end
end
end