diff --git a/lib/identity_cache/belongs_to_caching.rb b/lib/identity_cache/belongs_to_caching.rb index 185bbff1..3c09a0f7 100644 --- a/lib/identity_cache/belongs_to_caching.rb +++ b/lib/identity_cache/belongs_to_caching.rb @@ -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 diff --git a/lib/identity_cache/configuration_dsl.rb b/lib/identity_cache/configuration_dsl.rb index fddc1d9d..230d9fe7 100644 --- a/lib/identity_cache/configuration_dsl.rb +++ b/lib/identity_cache/configuration_dsl.rb @@ -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" diff --git a/test/association_error_test.rb b/test/association_error_test.rb new file mode 100644 index 00000000..ad5ae5a4 --- /dev/null +++ b/test/association_error_test.rb @@ -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