mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Fix calling cache helper with a relation
This commit is contained in:
parent
93a4dfaebc
commit
a9c6a583b6
3 changed files with 24 additions and 3 deletions
|
@ -229,10 +229,9 @@ module ActionView
|
|||
def fragment_name_with_digest(name, virtual_path) #:nodoc:
|
||||
virtual_path ||= @virtual_path
|
||||
if virtual_path
|
||||
names = Array(name.is_a?(Hash) ? controller.url_for(name).split("://").last : name)
|
||||
name = controller.url_for(name).split("://").last if name.is_a?(Hash)
|
||||
digest = Digestor.digest name: virtual_path, finder: lookup_context, dependencies: view_cache_dependencies
|
||||
|
||||
[ *names, digest ]
|
||||
[ name, digest ]
|
||||
else
|
||||
name
|
||||
end
|
||||
|
|
18
actionview/test/activerecord/relation_cache_test.rb
Normal file
18
actionview/test/activerecord/relation_cache_test.rb
Normal file
|
@ -0,0 +1,18 @@
|
|||
require 'active_record_unit'
|
||||
|
||||
class RelationCacheTest < ActionView::TestCase
|
||||
tests ActionView::Helpers::CacheHelper
|
||||
|
||||
def setup
|
||||
@virtual_path = "path"
|
||||
controller.cache_store = ActiveSupport::Cache::MemoryStore.new
|
||||
end
|
||||
|
||||
def test_cache_relation_other
|
||||
cache(Project.all){ concat("Hello World") }
|
||||
assert_equal "Hello World", controller.cache_store.read("views/projects-#{Project.count}/")
|
||||
end
|
||||
|
||||
def view_cache_dependencies; end
|
||||
|
||||
end
|
4
actionview/test/fixtures/project.rb
vendored
4
actionview/test/fixtures/project.rb
vendored
|
@ -1,3 +1,7 @@
|
|||
class Project < ActiveRecord::Base
|
||||
has_and_belongs_to_many :developers, -> { uniq }
|
||||
|
||||
def self.collection_cache_key(collection = all, timestamp_column = :updated_at)
|
||||
"projects-#{collection.count}"
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue