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

Render new page when there is a flash message #1525

Merged
merged 1 commit into from
Apr 26, 2019
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
13 changes: 9 additions & 4 deletions app/controllers/alchemy/pages_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -155,10 +155,10 @@ def render_page
end

def set_expiration_headers
if @page.cache_page?
expires_in @page.expiration_time, public: !@page.restricted, must_revalidate: true
else
if must_not_cache?
expires_now
else
expires_in @page.expiration_time, public: !@page.restricted, must_revalidate: true
end
end

Expand Down Expand Up @@ -190,12 +190,17 @@ def page_etag
# or the cache is stale, because it's been republished by the user.
#
def render_fresh_page?
!@page.cache_page? || stale?(etag: page_etag,
must_not_cache? || stale?(etag: page_etag,
last_modified: @page.published_at,
public: !@page.restricted,
template: 'pages/show')
end

# don't cache pages if we have flash message to display or the page has caching disabled
def must_not_cache?
flash.present? || !@page.cache_page?
end

def page_not_found!
not_found_error!("Alchemy::Page not found \"#{request.fullpath}\"")
end
Expand Down
24 changes: 24 additions & 0 deletions spec/requests/alchemy/page_request_caching_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,30 @@
end
end

context "but a flash message is present" do
before do
allow_any_instance_of(ActionDispatch::Flash::FlashHash).to receive(:present?) do
true
end
end

it "sets no-cache header" do
get "/#{page.urlname}"
expect(response.headers).to have_key('Cache-Control')
expect(response.headers['Cache-Control']).to eq('no-cache')
end

it "does not set etag header" do
get "/#{page.urlname}"
expect(response.headers).to_not have_key('ETag')
end

it "does not set last-modified header" do
get "/#{page.urlname}"
expect(response.headers).to_not have_key('Last-Modified')
end
end

after do
Rails.application.config.action_controller.perform_caching = false
end
Expand Down