aboutsummaryrefslogtreecommitdiffstats
path: root/actionview/test
diff options
context:
space:
mode:
authorst0012 <stan001212@gmail.com>2019-02-03 22:06:38 +0800
committerst0012 <stan001212@gmail.com>2019-04-04 09:59:06 +0800
commite8688ddb33347eb9de078843a75a075b70cc9f04 (patch)
tree8bf3464a59d468044dd540fbbae1ddde8e09124f /actionview/test
parent2c44e22942cdf8e93a72084db2773f088b4ad486 (diff)
downloadrails-e8688ddb33347eb9de078843a75a075b70cc9f04.tar.gz
rails-e8688ddb33347eb9de078843a75a075b70cc9f04.tar.bz2
rails-e8688ddb33347eb9de078843a75a075b70cc9f04.zip
Fix partial caching ignore repeated items issue
This is because we only use hash to maintain the result. So when the key are the same, the result would be skipped. The solution is to maintain an array for tracking every item's position to restructure the result.
Diffstat (limited to 'actionview/test')
-rw-r--r--actionview/test/fixtures/test/_cached_set.erb1
-rw-r--r--actionview/test/template/render_test.rb22
2 files changed, 23 insertions, 0 deletions
diff --git a/actionview/test/fixtures/test/_cached_set.erb b/actionview/test/fixtures/test/_cached_set.erb
new file mode 100644
index 0000000000..cd492fc519
--- /dev/null
+++ b/actionview/test/fixtures/test/_cached_set.erb
@@ -0,0 +1 @@
+<%= cached_set.first %> | <%= cached_set.second %> | <%= cached_set.third %> | <%= cached_set.fourth %> | <%= cached_set.fifth %>
diff --git a/actionview/test/template/render_test.rb b/actionview/test/template/render_test.rb
index 15c41051de..f0b5d7d95e 100644
--- a/actionview/test/template/render_test.rb
+++ b/actionview/test/template/render_test.rb
@@ -811,6 +811,28 @@ class CachedCollectionViewRenderTest < ActiveSupport::TestCase
end
end
+ test "collection caching with repeated collection" do
+ sets = [
+ [1, 2, 3, 4, 5],
+ [1, 2, 3, 4, 4],
+ [1, 2, 3, 4, 5],
+ [1, 2, 3, 4, 4],
+ [1, 2, 3, 4, 6]
+ ]
+
+ result = @view.render(partial: "test/cached_set", collection: sets, cached: true)
+
+ splited_result = result.split("\n")
+ assert_equal 5, splited_result.count
+ assert_equal [
+ "1 | 2 | 3 | 4 | 5",
+ "1 | 2 | 3 | 4 | 4",
+ "1 | 2 | 3 | 4 | 5",
+ "1 | 2 | 3 | 4 | 4",
+ "1 | 2 | 3 | 4 | 6"
+ ], splited_result
+ end
+
private
def cache_key(*names, virtual_path)
digest = ActionView::Digestor.digest name: virtual_path, format: :html, finder: @view.lookup_context, dependencies: []