Skip to content

Commit

Permalink
Merge pull request ruby-grape#164 from marshall-lee/fix_entity_privat…
Browse files Browse the repository at this point in the history
…e_methods_regression

Fix: entity instance methods exposure (0.4)
  • Loading branch information
marshall-lee committed Aug 3, 2015
2 parents 8af8074 + 52be44a commit 7235364
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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)
==================

Expand Down
5 changes: 3 additions & 2 deletions lib/grape_entity/entity.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/grape_entity/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module GrapeEntity
VERSION = '0.4.6'
VERSION = '0.4.7'
end
4 changes: 4 additions & 0 deletions spec/grape_entity/entity_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 '[email protected]'

another_friend = double('Friend', email: '[email protected]')
rep = EntitySpec::DelegatingEntity.new(another_friend)
expect(rep.send(:value_for, :name)).to eq 'cooler name'
end

context 'using' do
Expand Down

0 comments on commit 7235364

Please sign in to comment.