Skip to content

Commit 52be44a

Browse files
committed
Fix: entity instance methods exposure.
This one fixes a regression introduced in ruby-grape#147: entity instance methods were exposed with `NoMethodError`. Fixes ruby-grape#163. Additional specs are added.
1 parent 8af8074 commit 52be44a

File tree

4 files changed

+12
-3
lines changed

4 files changed

+12
-3
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
0.4.7 (2015-08-03)
2+
==================
3+
* [#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).
4+
15
0.4.6 (2015-07-27)
26
==================
37

lib/grape_entity/entity.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -589,10 +589,11 @@ def valid_exposure?(attribute, exposure_options)
589589
true
590590
else
591591
name = self.class.name_for(attribute)
592+
is_delegatable = delegator.delegatable?(name) || respond_to?(name, true)
592593
if exposure_options[:safe]
593-
delegator.delegatable?(name)
594+
is_delegatable
594595
else
595-
delegator.delegatable?(name) || fail(NoMethodError, "#{self.class.name} missing attribute `#{name}' on #{object}")
596+
is_delegatable || fail(NoMethodError, "#{self.class.name} missing attribute `#{name}' on #{object}")
596597
end
597598
end
598599
end

lib/grape_entity/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module GrapeEntity
2-
VERSION = '0.4.6'
2+
VERSION = '0.4.7'
33
end

spec/grape_entity/entity_spec.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1198,6 +1198,10 @@ def name
11981198
rep = EntitySpec::DelegatingEntity.new(friend)
11991199
expect(rep.send(:value_for, :name)).to eq 'cooler name'
12001200
expect(rep.send(:value_for, :email)).to eq '[email protected]'
1201+
1202+
another_friend = double('Friend', email: '[email protected]')
1203+
rep = EntitySpec::DelegatingEntity.new(another_friend)
1204+
expect(rep.send(:value_for, :name)).to eq 'cooler name'
12011205
end
12021206

12031207
context 'using' do

0 commit comments

Comments
 (0)