Skip to content

Commit 471dc4c

Browse files
committed
Merge pull request #105 from jhollinger/explain-missing-attributes
Specify which attribute is missing on which Entity
2 parents 72e289f + f8dedd2 commit 471dc4c

File tree

4 files changed

+8
-3
lines changed

4 files changed

+8
-3
lines changed

.rubocop_todo.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Metrics/AbcSize:
1212
# Offense count: 1
1313
# Configuration parameters: CountComments.
1414
Metrics/ClassLength:
15-
Max: 292
15+
Max: 296
1616

1717
# Offense count: 4
1818
Metrics/CyclomaticComplexity:

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ Next Release
44
* Your contribution here.
55
* [#98](https://github.com/intridea/grape-entity/pull/98): Add nested conditionals - [@zbelzer](https://github.com/zbelzer).
66
* [#91](https://github.com/intridea/grape-entity/pull/91): Fix OpenStruct serializing - [@etehtsea](https://github.com/etehtsea).
7+
* [#105](https://github.com/intridea/grape-entity/pull/105): Specify which attribute is missing in which Entity - [@jhollinger](https://github.com/jhollinger).
78

89
0.4.4 (2014-08-17)
910
==================

lib/grape_entity/entity.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -558,7 +558,11 @@ def delegate_attribute(attribute)
558558
elsif object.respond_to?(:fetch, true)
559559
object.fetch(name)
560560
else
561-
object.send(name)
561+
begin
562+
object.send(name)
563+
rescue NoMethodError
564+
raise NoMethodError, "#{self.class.name} missing attribute `#{name}' on #{object}"
565+
end
562566
end
563567
end
564568
end

spec/grape_entity/entity_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,7 @@ class Parent < Person
462462
subject.expose(:awesome)
463463
expect do
464464
subject.represent(Object.new, serializable: true)
465-
end.to raise_error(NoMethodError)
465+
end.to raise_error(NoMethodError, /missing attribute `awesome'/)
466466
end
467467
end
468468

0 commit comments

Comments
 (0)