Skip to content

Commit 381a1d3

Browse files
authored
Merge pull request #3299 from basecamp/fix/public-cache-signed-in
Don't publicly cache public pages rendered for a signed-in person
2 parents 2de1de3 + 795a07f commit 381a1d3

2 files changed

Lines changed: 16 additions & 1 deletion

File tree

‎app/controllers/public/base_controller.rb‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def set_card
1616
end
1717

1818
def set_public_cache_expiration
19-
expires_in 30.seconds, public: true
19+
expires_in 30.seconds, public: true unless authenticated?
2020
end
2121

2222
def ensure_board_accessible

‎test/controllers/public/boards_controller_test.rb‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,19 @@ class Public::BoardsControllerTest < ActionDispatch::IntegrationTest
3636
get published_board_path(boards(:writebook))
3737
assert_response :success
3838
end
39+
40+
test "show is publicly cacheable without authentication" do
41+
sign_out
42+
get published_board_path(boards(:writebook))
43+
44+
assert response.cache_control[:public]
45+
assert_equal 30.seconds.to_s, response.cache_control[:max_age]
46+
end
47+
48+
test "show is not publicly cacheable when signed in" do
49+
get published_board_path(boards(:writebook))
50+
51+
assert_not response.cache_control[:public]
52+
assert response.cache_control[:private]
53+
end
3954
end

0 commit comments

Comments
 (0)