2017-07-23 11:36:41 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-08-06 12:50:17 -04:00
|
|
|
require "active_record_unit"
|
2015-08-28 01:31:54 -04:00
|
|
|
|
2016-10-28 23:05:58 -04:00
|
|
|
class RelationCacheTest < ActionView::TestCase
|
2015-08-28 01:31:54 -04:00
|
|
|
tests ActionView::Helpers::CacheHelper
|
|
|
|
|
|
|
|
def setup
|
2018-09-24 17:49:26 -04:00
|
|
|
super
|
2017-06-07 16:17:34 -04:00
|
|
|
view_paths = ActionController::Base.view_paths
|
|
|
|
lookup_context = ActionView::LookupContext.new(view_paths, {}, ["test"])
|
|
|
|
@view_renderer = ActionView::Renderer.new(lookup_context)
|
|
|
|
@virtual_path = "path"
|
2019-02-15 20:10:28 -05:00
|
|
|
@current_template = lookup_context.find "test/hello_world"
|
2017-06-07 16:17:34 -04:00
|
|
|
|
2015-08-28 01:31:54 -04:00
|
|
|
controller.cache_store = ActiveSupport::Cache::MemoryStore.new
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_cache_relation_other
|
2019-07-28 02:24:44 -04:00
|
|
|
assert_queries(1) do
|
|
|
|
cache(Project.all) { concat("Hello World") }
|
|
|
|
end
|
2019-02-15 20:10:28 -05:00
|
|
|
assert_equal "Hello World", controller.cache_store.read("views/test/hello_world:fa9482a68ce25bf7589b8eddad72f736/projects-#{Project.count}")
|
2015-08-28 01:31:54 -04:00
|
|
|
end
|
|
|
|
|
2018-09-07 14:45:01 -04:00
|
|
|
def view_cache_dependencies; []; end
|
2019-07-28 02:24:44 -04:00
|
|
|
|
|
|
|
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
|
2015-08-28 01:31:54 -04:00
|
|
|
end
|