1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Assert query counts in cache relation test

This is to guard the change in #35982
This commit is contained in:
st0012 2019-07-28 14:24:44 +08:00
parent d1ffe59ab5
commit e289c8d775

View file

@ -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