Skip to content
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

do not use any Entity constant that is available in namespace, as it can... #600

Merged
merged 1 commit into from
Mar 20, 2014
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Next Release

#### Fixes

* [#600](https://github.com/intridea/grape/pull/600): Do not use any Entity constant that is available in namespace as presenter - [@fuksito](https://github.com/fuksito)
* [#590](https://github.com/intridea/grape/pull/590): Fix Issue Where Endpoint Param of Type Integer Cannot Set Values Array - [@xevix](https://github.com/xevix)
* [#586](https://github.com/intridea/grape/pull/586): Do not repeat the same validation error messages - [@kiela](https://github.com/kiela)
* [#508](https://github.com/intridea/grape/pull/508): Allow parameters, such as content encoding, in `content_type` - [@dm1try](https://github.com/dm1try).
Expand Down
2 changes: 1 addition & 1 deletion lib/grape/endpoint.rb
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ def present(*args)
entity_class ||= (settings[:representations] || {})[potential]
end

entity_class ||= object_instance.class.const_get(:Entity) if object_instance.class.const_defined?(:Entity)
entity_class ||= object_instance.class.const_get(:Entity) if object_instance.class.const_defined?(:Entity) && object_instance.class.const_get(:Entity).respond_to?(:represent)
end

root = options.delete(:root)
Expand Down
13 changes: 13 additions & 0 deletions spec/grape/entity_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,19 @@ def first
get '/example'
end

it 'autodetection does not use Entity if it is not a presenter' do
some_model = Class.new
entity = Class.new

some_model.class.const_set :Entity, entity

subject.get '/example' do
present some_model
end
get '/example'
entity.should_not_receive(:represent)
end

it 'adds a root key to the output if one is given' do
subject.get '/example' do
present({ abc: 'def' }, root: :root)
Expand Down