Skip to content

Commit

Permalink
Find, test and fix cache_versioning exception message
Browse files Browse the repository at this point in the history
  • Loading branch information
kaspth committed Feb 13, 2025
1 parent fa9e214 commit e21bb24
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/active_record/associated_object.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def cache_key_with_version
def cache_key
case
when !record.cache_versioning?
raise "ActiveRecord::AssociatedObject#cache_key only supports #{record_klass}.cache_versioning = true"
raise "ActiveRecord::AssociatedObject#cache_key only supports #{record.class}.cache_versioning = true"
when new_record?
"#{model_name.cache_key}/new"
else
Expand Down
3 changes: 2 additions & 1 deletion test/active_record/associated_object_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,8 @@ class ActiveRecord::AssociatedObjectTest < ActiveSupport::TestCase

test "cache_key integration without cache_versioning" do
previous_versioning, Post.cache_versioning = Post.cache_versioning, false
assert_raises { @publisher.cache_key }
error = assert_raises { @publisher.cache_key }
assert_match /cache_key.*?Post.cache_versioning = true/, error.message
ensure
Post.cache_versioning = previous_versioning
end
Expand Down

0 comments on commit e21bb24

Please sign in to comment.