Skip to content

Commit ad72908

Browse files
committed
Merge pull request #122 from dan-corneanu/subclass-documentation-#121
Subclass documentation #121
2 parents 35c3e24 + df9d306 commit ad72908

File tree

3 files changed

+41
-4
lines changed

3 files changed

+41
-4
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

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

89
0.4.5 (2015-03-10)

lib/grape_entity/entity.rb

-4
Original file line numberDiff line numberDiff line change
@@ -240,10 +240,6 @@ def self.documentation
240240
memo
241241
end
242242

243-
if superclass.respond_to? :documentation
244-
@documentation = superclass.documentation.merge(@documentation)
245-
end
246-
247243
@documentation
248244
end
249245

spec/grape_entity/entity_spec.rb

+40
Original file line numberDiff line numberDiff line change
@@ -1149,6 +1149,46 @@ class UserEntity < Grape::Entity
11491149

11501150
expect(subject.documentation).to eq(label: doc, email: doc)
11511151
end
1152+
1153+
context 'inherited documentation' do
1154+
it 'returns documentation from ancestor' do
1155+
doc = { type: 'foo', desc: 'bar' }
1156+
fresh_class.expose :name, documentation: doc
1157+
child_class = Class.new(fresh_class)
1158+
child_class.expose :email, documentation: doc
1159+
1160+
expect(fresh_class.documentation).to eq(name: doc)
1161+
expect(child_class.documentation).to eq(name: doc, email: doc)
1162+
end
1163+
1164+
it 'obeys unexposed attributes in subclass' do
1165+
doc = { type: 'foo', desc: 'bar' }
1166+
fresh_class.expose :name, documentation: doc
1167+
fresh_class.expose :email, documentation: doc
1168+
child_class = Class.new(fresh_class)
1169+
child_class.unexpose :email
1170+
1171+
expect(fresh_class.documentation).to eq(name: doc, email: doc)
1172+
expect(child_class.documentation).to eq(name: doc)
1173+
end
1174+
1175+
it 'obeys re-exposed attributes in subclass' do
1176+
doc = { type: 'foo', desc: 'bar' }
1177+
fresh_class.expose :name, documentation: doc
1178+
fresh_class.expose :email, documentation: doc
1179+
1180+
child_class = Class.new(fresh_class)
1181+
child_class.unexpose :email
1182+
1183+
nephew_class = Class.new(child_class)
1184+
new_doc = { type: 'todler', descr: '???' }
1185+
nephew_class.expose :email, documentation: new_doc
1186+
1187+
expect(fresh_class.documentation).to eq(name: doc, email: doc)
1188+
expect(child_class.documentation).to eq(name: doc)
1189+
expect(nephew_class.documentation).to eq(name: doc, email: new_doc)
1190+
end
1191+
end
11521192
end
11531193

11541194
describe '#key_for' do

0 commit comments

Comments
 (0)