diff options
Diffstat (limited to 'actionview/test')
-rw-r--r-- | actionview/test/activerecord/relation_cache_test.rb | 17 | ||||
-rw-r--r-- | actionview/test/template/form_options_helper_test.rb | 2 | ||||
-rw-r--r-- | actionview/test/template/output_safety_helper_test.rb | 8 |
3 files changed, 24 insertions, 3 deletions
diff --git a/actionview/test/activerecord/relation_cache_test.rb b/actionview/test/activerecord/relation_cache_test.rb index 6fe83dcb9a..26f3bfbcbc 100644 --- a/actionview/test/activerecord/relation_cache_test.rb +++ b/actionview/test/activerecord/relation_cache_test.rb @@ -17,9 +17,24 @@ class RelationCacheTest < ActionView::TestCase end def test_cache_relation_other - cache(Project.all) { concat("Hello World") } + assert_queries(1) do + cache(Project.all) { concat("Hello World") } + end assert_equal "Hello World", controller.cache_store.read("views/test/hello_world:fa9482a68ce25bf7589b8eddad72f736/projects-#{Project.count}") end def view_cache_dependencies; []; end + + def assert_queries(num) + ActiveRecord::Base.connection.materialize_transactions + count = 0 + + ActiveSupport::Notifications.subscribe("sql.active_record") do |_name, _start, _finish, _id, payload| + count += 1 unless ["SCHEMA", "TRANSACTION"].include? payload[:name] + end + + result = yield + assert_equal num, count, "#{count} instead of #{num} queries were executed." + result + end end diff --git a/actionview/test/template/form_options_helper_test.rb b/actionview/test/template/form_options_helper_test.rb index d7a7b95ab3..273646b077 100644 --- a/actionview/test/template/form_options_helper_test.rb +++ b/actionview/test/template/form_options_helper_test.rb @@ -47,6 +47,7 @@ class FormOptionsHelperTest < ActionView::TestCase FakeZone = Struct.new(:name) do def to_s; name; end def =~(_re); end + def match?(_re); end end module ClassMethods @@ -1266,6 +1267,7 @@ class FormOptionsHelperTest < ActionView::TestCase @fake_timezones.each do |tz| def tz.=~(re); %(A D).include?(name) end + def tz.match?(re); %(A D).include?(name) end end html = time_zone_select("firm", "time_zone", /A|D/) diff --git a/actionview/test/template/output_safety_helper_test.rb b/actionview/test/template/output_safety_helper_test.rb index faeeded1c8..b2c6ae99ed 100644 --- a/actionview/test/template/output_safety_helper_test.rb +++ b/actionview/test/template/output_safety_helper_test.rb @@ -43,7 +43,9 @@ class OutputSafetyHelperTest < ActionView::TestCase joined = safe_join(["a", "b"]) assert_equal "ab", joined - $, = "|" + silence_warnings do + $, = "|" + end joined = safe_join(["a", "b"]) assert_equal "a|b", joined ensure @@ -108,7 +110,9 @@ class OutputSafetyHelperTest < ActionView::TestCase test "to_sentence is not affected by $," do separator_was = $, - $, = "|" + silence_warnings do + $, = "|" + end begin assert_equal "one and two", to_sentence(["one", "two"]) assert_equal "one, two, and three", to_sentence(["one", "two", "three"]) |