Skip to content

Fix: entity instance methods exposure (0.4) #164

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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