diff options
author | Stan Lo <a22301613@yahoo.com.tw> | 2017-04-02 00:24:03 +0800 |
---|---|---|
committer | Kasper Timm Hansen <kaspth@gmail.com> | 2017-06-08 21:42:46 +0200 |
commit | 2abf6ca0c8304a3cfcdae6e14060b561780be43c (patch) | |
tree | 189b1f287e37b3c79ad2056ca659e8733fe88491 /actionview/test/template | |
parent | f1e42fe267342ffa4cea84cf09b0caaee733632c (diff) | |
download | rails-2abf6ca0c8304a3cfcdae6e14060b561780be43c.tar.gz rails-2abf6ca0c8304a3cfcdae6e14060b561780be43c.tar.bz2 rails-2abf6ca0c8304a3cfcdae6e14060b561780be43c.zip |
Use a hash to record every partial's cache hit status instead of sharing a boolean.
Diffstat (limited to 'actionview/test/template')
-rw-r--r-- | actionview/test/template/log_subscriber_test.rb | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/actionview/test/template/log_subscriber_test.rb b/actionview/test/template/log_subscriber_test.rb index 584666d54b..94d2c35635 100644 --- a/actionview/test/template/log_subscriber_test.rb +++ b/actionview/test/template/log_subscriber_test.rb @@ -113,6 +113,46 @@ class AVLogSubscriberTest < ActiveSupport::TestCase end end + def test_render_nested_partial_while_outter_partial_not_cached + Rails.stub(:root, File.expand_path(FIXTURE_LOAD_PATH)) do + set_view_cache_dependencies + set_cache_controller + + @view.render(partial: "test/nested_cached_customer", locals: { cached_customer: Customer.new("Stan") }) + wait + assert_match(/Rendered test\/_nested_cached_customer\.erb (.*) \[cache miss\]/, @logger.logged(:info).last) + assert_match(/Rendered test\/_cached_customer\.erb (.*) \[cache miss\]/, @logger.logged(:info)[-2]) + + @view.render(partial: "test/nested_cached_customer", locals: { cached_customer: Customer.new("Stan") }) + wait + # Outter partial's log should not be affected by inner partial's result. + assert_match(/Rendered test\/_nested_cached_customer\.erb (.*) \[cache miss\]/, @logger.logged(:info).last) + assert_match(/Rendered test\/_cached_customer\.erb (.*) \[cache hit\]/, @logger.logged(:info)[-2]) + end + end + + def test_render_nested_partial_while_outter_partial_cached + Rails.stub(:root, File.expand_path(FIXTURE_LOAD_PATH)) do + set_view_cache_dependencies + set_cache_controller + + @view.render(partial: "test/cached_nested_cached_customer", locals: { cached_customer: Customer.new("Stan") }) + wait + assert_match(/Rendered test\/_cached_nested_cached_customer\.erb (.*) \[cache miss\]/, @logger.logged(:info).last) + assert_match(/Rendered test\/_cached_customer\.erb (.*) \[cache miss\]/, @logger.logged(:info)[-2]) + + @view.render(partial: "test/cached_nested_cached_customer", locals: { cached_customer: Customer.new("Stan") }) + wait + assert_match(/Rendered test\/_cached_nested_cached_customer\.erb (.*) \[cache hit\]/, @logger.logged(:info).last) + # Should not generate log about cached_customer partial + assert_equal 3, @logger.logged(:info).size + + @view.render(partial: "test/cached_customer", locals: { cached_customer: Customer.new("Stan") }) + wait + assert_match(/Rendered test\/_cached_customer\.erb (.*) \[cache hit\]/, @logger.logged(:info).last) + end + end + def test_render_partial_with_cache_hitted_and_missed Rails.stub(:root, File.expand_path(FIXTURE_LOAD_PATH)) do set_view_cache_dependencies |