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

Subclass documentation #121 #122

Merged
merged 1 commit into from
May 8, 2015
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 @@ -3,6 +3,7 @@

* [#114](https://github.com/intridea/grape-entity/pull/114): Added 'only' option that selects which attributes should be returned - [@estevaoam](https://github.com/estevaoam).
* [#115](https://github.com/intridea/grape-entity/pull/115): Allowing 'root' to be inherited from parent to child entities - [@guidoprincess](https://github.com/guidoprincess).
* [#121](https://github.com/intridea/grape-entity/pull/122): Sublcassed Entity#documentation properly handles unexposed params - [@dan-corneanu](https://github.com/dan-corneanu).
* Your contribution here.

0.4.5 (2015-03-10)
Expand Down
4 changes: 0 additions & 4 deletions lib/grape_entity/entity.rb
Original file line number Diff line number Diff line change
Expand Up @@ -240,10 +240,6 @@ def self.documentation
memo
end

if superclass.respond_to? :documentation
@documentation = superclass.documentation.merge(@documentation)
end

@documentation
end

Expand Down
40 changes: 40 additions & 0 deletions spec/grape_entity/entity_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1149,6 +1149,46 @@ class UserEntity < Grape::Entity

expect(subject.documentation).to eq(label: doc, email: doc)
end

context 'inherited documentation' do
it 'returns documentation from ancestor' do
doc = { type: 'foo', desc: 'bar' }
fresh_class.expose :name, documentation: doc
child_class = Class.new(fresh_class)
child_class.expose :email, documentation: doc

expect(fresh_class.documentation).to eq(name: doc)
expect(child_class.documentation).to eq(name: doc, email: doc)
end

it 'obeys unexposed attributes in subclass' do
doc = { type: 'foo', desc: 'bar' }
fresh_class.expose :name, documentation: doc
fresh_class.expose :email, documentation: doc
child_class = Class.new(fresh_class)
child_class.unexpose :email

expect(fresh_class.documentation).to eq(name: doc, email: doc)
expect(child_class.documentation).to eq(name: doc)
end

it 'obeys re-exposed attributes in subclass' do
doc = { type: 'foo', desc: 'bar' }
fresh_class.expose :name, documentation: doc
fresh_class.expose :email, documentation: doc

child_class = Class.new(fresh_class)
child_class.unexpose :email

nephew_class = Class.new(child_class)
new_doc = { type: 'todler', descr: '???' }
nephew_class.expose :email, documentation: new_doc

expect(fresh_class.documentation).to eq(name: doc, email: doc)
expect(child_class.documentation).to eq(name: doc)
expect(nephew_class.documentation).to eq(name: doc, email: new_doc)
end
end
end

describe '#key_for' do
Expand Down