2017-11-20 23:38:21 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require "active_record_unit"
|
|
|
|
|
|
|
|
class MultifetchCacheTest < ActiveRecordTestCase
|
|
|
|
fixtures :topics, :replies
|
|
|
|
|
|
|
|
def setup
|
|
|
|
view_paths = ActionController::Base.view_paths
|
2019-01-23 17:19:50 -05:00
|
|
|
view_paths.each(&:clear_cache)
|
2017-11-20 23:38:21 -05:00
|
|
|
|
2019-01-23 17:19:50 -05:00
|
|
|
@view = Class.new(ActionView::Base.with_empty_template_cache) do
|
2017-11-20 23:38:21 -05:00
|
|
|
def view_cache_dependencies
|
|
|
|
[]
|
|
|
|
end
|
|
|
|
|
|
|
|
def combined_fragment_cache_key(key)
|
|
|
|
[ :views, key ]
|
|
|
|
end
|
2019-01-29 18:17:52 -05:00
|
|
|
end.with_view_paths(view_paths, {})
|
2019-11-08 12:52:26 -05:00
|
|
|
|
|
|
|
controller = ActionController::Base.new
|
|
|
|
controller.perform_caching = true
|
|
|
|
@view.controller = controller
|
2017-11-20 23:38:21 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_only_preloading_for_records_that_miss_the_cache
|
|
|
|
@view.render partial: "test/partial", collection: [topics(:rails)], cached: true
|
|
|
|
|
|
|
|
@topics = Topic.preload(:replies)
|
|
|
|
|
|
|
|
@view.render partial: "test/partial", collection: @topics, cached: true
|
|
|
|
|
|
|
|
assert_not @topics.detect { |topic| topic.id == topics(:rails).id }.replies.loaded?
|
|
|
|
assert @topics.detect { |topic| topic.id != topics(:rails).id }.replies.loaded?
|
|
|
|
end
|
|
|
|
end
|