aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/test
diff options
context:
space:
mode:
authorJeremy Kemper <jeremykemper@gmail.com>2014-08-17 06:59:03 -0700
committerJeremy Kemper <jeremykemper@gmail.com>2014-08-17 06:59:03 -0700
commita08ca4a846ac5fb7b3fbd1e53ea3df2daa01fd8c (patch)
tree16868e6662b05de0d942f61e179d934db5bdfa86 /actionpack/test
parentd20270612cd9be3eed910171934a6b3463dbead7 (diff)
parent6c96602bc1480b41f5fd20aef46fc70bcf582aab (diff)
downloadrails-a08ca4a846ac5fb7b3fbd1e53ea3df2daa01fd8c.tar.gz
rails-a08ca4a846ac5fb7b3fbd1e53ea3df2daa01fd8c.tar.bz2
rails-a08ca4a846ac5fb7b3fbd1e53ea3df2daa01fd8c.zip
Merge pull request #16527 from jeremy/etag_with_template_digest
When your templates change, browser caches bust automatically.
Diffstat (limited to 'actionpack/test')
-rw-r--r--actionpack/test/controller/live_stream_test.rb2
-rw-r--r--actionpack/test/controller/render_test.rb36
2 files changed, 35 insertions, 3 deletions
diff --git a/actionpack/test/controller/live_stream_test.rb b/actionpack/test/controller/live_stream_test.rb
index 0500b7c789..7fd1276e98 100644
--- a/actionpack/test/controller/live_stream_test.rb
+++ b/actionpack/test/controller/live_stream_test.rb
@@ -162,7 +162,7 @@ module ActionController
end
def with_stale
- render :text => 'stale' if stale?(:etag => "123")
+ render text: 'stale' if stale?(etag: "123", template: false)
end
def exception_in_view
diff --git a/actionpack/test/controller/render_test.rb b/actionpack/test/controller/render_test.rb
index 9926130c02..b036b6c08e 100644
--- a/actionpack/test/controller/render_test.rb
+++ b/actionpack/test/controller/render_test.rb
@@ -10,11 +10,17 @@ class TestControllerWithExtraEtags < ActionController::Base
etag { nil }
def fresh
- render text: "stale" if stale?(etag: '123')
+ render text: "stale" if stale?(etag: '123', template: false)
end
def array
- render text: "stale" if stale?(etag: %w(1 2 3))
+ render text: "stale" if stale?(etag: %w(1 2 3), template: false)
+ end
+
+ def with_template
+ if stale? template: 'test/hello_world'
+ render text: 'stale'
+ end
end
end
@@ -409,6 +415,32 @@ class EtagRenderTest < ActionController::TestCase
assert_response :success
end
+ def test_etag_reflects_template_digest
+ get :with_template
+ assert_response :ok
+ assert_not_nil etag = @response.etag
+
+ request.if_none_match = etag
+ get :with_template
+ assert_response :not_modified
+
+ # Modify the template digest
+ path = File.expand_path('../../fixtures/test/hello_world.erb', __FILE__)
+ old = File.read(path)
+
+ begin
+ File.write path, 'foo'
+ ActionView::Digestor.cache.clear
+
+ request.if_none_match = etag
+ get :with_template
+ assert_response :ok
+ assert_not_equal etag, @response.etag
+ ensure
+ File.write path, old
+ end
+ end
+
def etag(record)
Digest::MD5.hexdigest(ActiveSupport::Cache.expand_cache_key(record)).inspect
end