Skip to content

Commit

Permalink
Fix class name in AssociationError message (#557)
Browse files Browse the repository at this point in the history
`self` is the model here, so `self.class` is always "Class".
  • Loading branch information
eugeneius authored Feb 12, 2024
1 parent 8074117 commit d1e53f7
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/identity_cache/belongs_to_caching.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def cache_belongs_to(association)
ensure_base_model

unless (reflection = reflect_on_association(association))
raise AssociationError, "Association named '#{association}' was not found on #{self.class}"
raise AssociationError, "Association named '#{association}' was not found on #{self}"
end

if reflection.scope
Expand Down
2 changes: 1 addition & 1 deletion lib/identity_cache/configuration_dsl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ def ensure_base_model

def check_association_for_caching(association)
unless (association_reflection = reflect_on_association(association))
raise AssociationError, "Association named '#{association}' was not found on #{self.class}"
raise AssociationError, "Association named '#{association}' was not found on #{self}"
end
if association_reflection.options[:through]
raise UnsupportedAssociationError, "caching through associations isn't supported"
Expand Down
26 changes: 26 additions & 0 deletions test/association_error_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# frozen_string_literal: true

require "test_helper"

class AssociationErrorTest < IdentityCache::TestCase
def test_cache_belongs_to
error = assert_raises(IdentityCache::AssociationError) do
Item.send(:cache_belongs_to, :foo)
end
assert_equal("Association named 'foo' was not found on Item", error.message)
end

def test_cache_has_one
error = assert_raises(IdentityCache::AssociationError) do
Item.send(:cache_has_one, :foo, embed: true)
end
assert_equal("Association named 'foo' was not found on Item", error.message)
end

def test_cache_has_many
error = assert_raises(IdentityCache::AssociationError) do
Item.send(:cache_has_many, :foo)
end
assert_equal("Association named 'foo' was not found on Item", error.message)
end
end

0 comments on commit d1e53f7

Please sign in to comment.