aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack
diff options
context:
space:
mode:
authorRafael Mendonça França <rafaelmfranca@gmail.com>2015-02-25 11:54:07 -0300
committerRafael Mendonça França <rafaelmfranca@gmail.com>2015-02-25 11:54:07 -0300
commit68a2a6711643db6b8b0775fe004bc0de0cdc07db (patch)
treed18132851add017e8766c533d31cac2c7e939d19 /actionpack
parent5a6868b6175167d91fcfaed82b4d4627281a4878 (diff)
parentca6aba7f30ad9910f17e4c5b39667889d9518794 (diff)
downloadrails-68a2a6711643db6b8b0775fe004bc0de0cdc07db.tar.gz
rails-68a2a6711643db6b8b0775fe004bc0de0cdc07db.tar.bz2
rails-68a2a6711643db6b8b0775fe004bc0de0cdc07db.zip
Merge pull request #18948 from kaspth/automatic-collection-caching
Merge multi_fetch_fragments.
Diffstat (limited to 'actionpack')
-rw-r--r--actionpack/test/controller/caching_test.rb58
-rw-r--r--actionpack/test/fixtures/collection_cache/index.html.erb1
-rw-r--r--actionpack/test/fixtures/customers/_commented_customer.html.erb4
-rw-r--r--actionpack/test/fixtures/customers/_customer.html.erb3
4 files changed, 66 insertions, 0 deletions
diff --git a/actionpack/test/controller/caching_test.rb b/actionpack/test/controller/caching_test.rb
index 4760ec1698..2d6607041d 100644
--- a/actionpack/test/controller/caching_test.rb
+++ b/actionpack/test/controller/caching_test.rb
@@ -1,5 +1,6 @@
require 'fileutils'
require 'abstract_unit'
+require 'lib/controller/fake_models'
CACHE_DIR = 'test_cache'
# Don't change '/../temp/' cavalierly or you might hose something you don't want hosed
@@ -349,3 +350,60 @@ class ViewCacheDependencyTest < ActionController::TestCase
assert_equal %w(trombone flute), HasDependenciesController.new.view_cache_dependencies
end
end
+
+class CollectionCacheController < ActionController::Base
+ def index
+ @customers = [Customer.new('david', params[:id] || 1)]
+ end
+
+ def index_ordered
+ @customers = [Customer.new('david', 1), Customer.new('david', 2), Customer.new('david', 3)]
+ render 'index'
+ end
+
+ def index_explicit_render
+ @customers = [Customer.new('david', 1)]
+ render partial: 'customers/customer', collection: @customers
+ end
+
+ def index_with_comment
+ @customers = [Customer.new('david', 1)]
+ render partial: 'customers/commented_customer', collection: @customers, as: :customer
+ end
+end
+
+class AutomaticCollectionCacheTest < ActionController::TestCase
+ def setup
+ super
+ @controller = CollectionCacheController.new
+ @controller.perform_caching = true
+ @controller.cache_store = ActiveSupport::Cache::MemoryStore.new
+ end
+
+ def test_collection_fetches_cached_views
+ get :index
+
+ ActionView::PartialRenderer.expects(:collection_with_template).never
+ get :index
+ end
+
+ def test_preserves_order_when_reading_from_cache_plus_rendering
+ get :index, params: { id: 2 }
+ get :index_ordered
+
+ assert_select ':root', "david, 1\n david, 2\n david, 3"
+ end
+
+ def test_explicit_render_call_with_options
+ get :index_explicit_render
+
+ assert_select ':root', "david, 1"
+ end
+
+ def test_caching_works_with_beginning_comment
+ get :index_with_comment
+
+ ActionView::PartialRenderer.expects(:collection_with_template).never
+ get :index_with_comment
+ end
+end
diff --git a/actionpack/test/fixtures/collection_cache/index.html.erb b/actionpack/test/fixtures/collection_cache/index.html.erb
new file mode 100644
index 0000000000..521b1450df
--- /dev/null
+++ b/actionpack/test/fixtures/collection_cache/index.html.erb
@@ -0,0 +1 @@
+<%= render @customers %> \ No newline at end of file
diff --git a/actionpack/test/fixtures/customers/_commented_customer.html.erb b/actionpack/test/fixtures/customers/_commented_customer.html.erb
new file mode 100644
index 0000000000..d5f6e3b491
--- /dev/null
+++ b/actionpack/test/fixtures/customers/_commented_customer.html.erb
@@ -0,0 +1,4 @@
+<%# I'm a comment %>
+<% cache customer do %>
+ <%= customer.name %>, <%= customer.id %>
+<% end %> \ No newline at end of file
diff --git a/actionpack/test/fixtures/customers/_customer.html.erb b/actionpack/test/fixtures/customers/_customer.html.erb
new file mode 100644
index 0000000000..67e9f6d411
--- /dev/null
+++ b/actionpack/test/fixtures/customers/_customer.html.erb
@@ -0,0 +1,3 @@
+<% cache customer do %>
+ <%= customer.name %>, <%= customer.id %>
+<% end %> \ No newline at end of file