1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00
rails--rails/actionview/test/activerecord/multifetch_cache_test.rb
2018-03-06 14:10:45 +11:00

35 lines
1 KiB
Ruby

# frozen_string_literal: true
require "active_record_unit"
require "active_record/railties/collection_cache_association_loading"
ActionView::PartialRenderer.prepend(ActiveRecord::Railties::CollectionCacheAssociationLoading)
class MultifetchCacheTest < ActiveRecordTestCase
fixtures :topics, :replies
def setup
view_paths = ActionController::Base.view_paths
@view = Class.new(ActionView::Base) do
def view_cache_dependencies
[]
end
def combined_fragment_cache_key(key)
[ :views, key ]
end
end.new(view_paths, {})
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