From 52be44a3536989d09fe1f70a6294f4a878fdbe28 Mon Sep 17 00:00:00 2001 From: Vladimir Kochnev Date: Mon, 3 Aug 2015 19:34:43 +0300 Subject: [PATCH] Fix: entity instance methods exposure. This one fixes a regression introduced in #147: entity instance methods were exposed with `NoMethodError`. Fixes #163. Additional specs are added. --- CHANGELOG.md | 4 ++++ lib/grape_entity/entity.rb | 5 +++-- lib/grape_entity/version.rb | 2 +- spec/grape_entity/entity_spec.rb | 4 ++++ 4 files changed, 12 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ba1b01b6..0c477047 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +0.4.7 (2015-08-03) +================== +* [#164](https://github.com/intridea/grape-entity/pull/164): Regression: entity instance methods were exposed with `NoMethodError`: [#163](https://github.com/intridea/grape-entity/issues/163) - [@marshall-lee](http://github.com/marshall-lee). + 0.4.6 (2015-07-27) ================== diff --git a/lib/grape_entity/entity.rb b/lib/grape_entity/entity.rb index 7e67fd34..644d928d 100644 --- a/lib/grape_entity/entity.rb +++ b/lib/grape_entity/entity.rb @@ -589,10 +589,11 @@ def valid_exposure?(attribute, exposure_options) true else name = self.class.name_for(attribute) + is_delegatable = delegator.delegatable?(name) || respond_to?(name, true) if exposure_options[:safe] - delegator.delegatable?(name) + is_delegatable else - delegator.delegatable?(name) || fail(NoMethodError, "#{self.class.name} missing attribute `#{name}' on #{object}") + is_delegatable || fail(NoMethodError, "#{self.class.name} missing attribute `#{name}' on #{object}") end end end diff --git a/lib/grape_entity/version.rb b/lib/grape_entity/version.rb index c51b837c..ff8bdcf1 100644 --- a/lib/grape_entity/version.rb +++ b/lib/grape_entity/version.rb @@ -1,3 +1,3 @@ module GrapeEntity - VERSION = '0.4.6' + VERSION = '0.4.7' end diff --git a/spec/grape_entity/entity_spec.rb b/spec/grape_entity/entity_spec.rb index f11cacd0..af4ac549 100644 --- a/spec/grape_entity/entity_spec.rb +++ b/spec/grape_entity/entity_spec.rb @@ -1198,6 +1198,10 @@ def name rep = EntitySpec::DelegatingEntity.new(friend) expect(rep.send(:value_for, :name)).to eq 'cooler name' expect(rep.send(:value_for, :email)).to eq 'joe@example.com' + + another_friend = double('Friend', email: 'joe@example.com') + rep = EntitySpec::DelegatingEntity.new(another_friend) + expect(rep.send(:value_for, :name)).to eq 'cooler name' end context 'using' do