Skip to content

Commit

Permalink
Merge pull request #36031 from st0012/guard-35982
Browse files Browse the repository at this point in the history
Add test case to guard the query count for relation cache (for #35982)
  • Loading branch information
rafaelfranca committed Jul 29, 2019
2 parents f1cfe1e + e289c8d commit d880fae
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion actionview/test/activerecord/relation_cache_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,24 @@ def setup
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

0 comments on commit d880fae

Please sign in to comment.