aboutsummaryrefslogtreecommitdiffstats
path: root/actionview/test/template/render_test.rb
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2016-02-24 11:29:16 -0800
committerAaron Patterson <aaron.patterson@gmail.com>2016-02-24 11:29:16 -0800
commita5776ed2b2bf8bccb083e303992a174110b3ef7f (patch)
treecfef331bdccd3742e2696a5e2f50312d2f4e132d /actionview/test/template/render_test.rb
parent0c9f5f56f7a1628c8c9ff3a91a52f17a15e31b26 (diff)
parentf6fecabc0cb8ad7be3783d31656a0b10fe3b5bc7 (diff)
downloadrails-a5776ed2b2bf8bccb083e303992a174110b3ef7f.tar.gz
rails-a5776ed2b2bf8bccb083e303992a174110b3ef7f.tar.bz2
rails-a5776ed2b2bf8bccb083e303992a174110b3ef7f.zip
Merge branch 'master' into treewip
* master: (113 commits) remove useless method Updated file documentation [ci skip] changes caching guide to add note on weak etags Don't put config.action_mailer.perform_caching entry twice in development.rb Fix wording and wrong reference Add Ruby formatting to CHANGELOG entry Fix ActionView's cache section reference Do not define methods in the included block Add caching guide in ActionMailer basics Add ActionMailer configuration options Preparing for 5.0.0.beta3 release Update 5.0 release notes Enable tmp_restart plugin for puma Prep release for Rails 5 beta3 [ci skip] Move collection caching changelog entry. Ensure `drop_table` even if tests failure or interrupted :bomb: run the test @rafaelfranca :angry: Remove changelog entry for reverted commit Add CHANGELOG for https://github.com/rails/rails/pull/23734 [ci skip] No need CHANGELOG entry for #23849. ...
Diffstat (limited to 'actionview/test/template/render_test.rb')
-rw-r--r--actionview/test/template/render_test.rb55
1 files changed, 29 insertions, 26 deletions
diff --git a/actionview/test/template/render_test.rb b/actionview/test/template/render_test.rb
index bf811abdd0..3561114d90 100644
--- a/actionview/test/template/render_test.rb
+++ b/actionview/test/template/render_test.rb
@@ -628,56 +628,59 @@ class LazyViewRenderTest < ActiveSupport::TestCase
end
end
-class CachedCollectionViewRenderTest < CachedViewRenderTest
+class CachedCollectionViewRenderTest < ActiveSupport::TestCase
class CachedCustomer < Customer; end
- teardown do
- ActionView::PartialRenderer.collection_cache.clear
- end
+ include RenderTestCases
- test "with custom key" do
- customer = Customer.new("david")
- key = cache_key([customer, 'key'], "test/_customer")
+ # Ensure view path cache is primed
+ setup do
+ view_paths = ActionController::Base.view_paths
+ assert_equal ActionView::OptimizedFileSystemResolver, view_paths.first.class
- ActionView::PartialRenderer.collection_cache.write(key, 'Hello')
+ ActionView::PartialRenderer.collection_cache = ActiveSupport::Cache::MemoryStore.new
- assert_equal "Hello",
- @view.render(partial: "test/customer", collection: [customer], cache: ->(item) { [item, 'key'] })
+ setup_view(view_paths)
end
- test "with caching with custom key and rendering with different key" do
- customer = Customer.new("david")
- key = cache_key([customer, 'key'], "test/_customer")
+ teardown do
+ GC.start
+ I18n.reload!
+ end
- ActionView::PartialRenderer.collection_cache.write(key, 'Hello')
+ test "collection caching does not cache by default" do
+ customer = Customer.new("david", 1)
+ key = cache_key(customer, "test/_customer")
- assert_equal "Hello: david",
- @view.render(partial: "test/customer", collection: [customer], cache: ->(item) { [item, 'another_key'] })
+ ActionView::PartialRenderer.collection_cache.write(key, 'Cached')
+
+ assert_not_equal "Cached",
+ @view.render(partial: "test/customer", collection: [customer])
end
- test "automatic caching with inferred cache name" do
- customer = CachedCustomer.new("david")
- key = cache_key(customer, "test/_cached_customer")
+ test "collection caching with partial that doesn't use fragment caching" do
+ customer = Customer.new("david", 1)
+ key = cache_key(customer, "test/_customer")
ActionView::PartialRenderer.collection_cache.write(key, 'Cached')
assert_equal "Cached",
- @view.render(partial: "test/cached_customer", collection: [customer])
+ @view.render(partial: "test/customer", collection: [customer], cached: true)
end
- test "automatic caching with as name" do
- customer = CachedCustomer.new("david")
- key = cache_key(customer, "test/_cached_customer_as")
+ test "collection caching with cached true" do
+ customer = CachedCustomer.new("david", 1)
+ key = cache_key(customer, "test/_cached_customer")
ActionView::PartialRenderer.collection_cache.write(key, 'Cached')
assert_equal "Cached",
- @view.render(partial: "test/cached_customer_as", collection: [customer], as: :buyer)
+ @view.render(partial: "test/cached_customer", collection: [customer], cached: true)
end
private
- def cache_key(names, virtual_path)
+ def cache_key(*names, virtual_path)
digest = ActionView::Digestor.digest name: virtual_path, finder: @view.lookup_context, dependencies: []
- @view.fragment_cache_key([ *Array(names), digest ])
+ @view.fragment_cache_key([ *names, digest ])
end
end