Skip to content

Commit

Permalink
Merge pull request #105 from jhollinger/explain-missing-attributes
Browse files Browse the repository at this point in the history
Specify which attribute is missing on which Entity
  • Loading branch information
dblock committed Jan 15, 2015
2 parents 72e289f + f8dedd2 commit 471dc4c
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Metrics/AbcSize:
# Offense count: 1
# Configuration parameters: CountComments.
Metrics/ClassLength:
Max: 292
Max: 296

# Offense count: 4
Metrics/CyclomaticComplexity:
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Next Release
* Your contribution here.
* [#98](https://github.com/intridea/grape-entity/pull/98): Add nested conditionals - [@zbelzer](https://github.com/zbelzer).
* [#91](https://github.com/intridea/grape-entity/pull/91): Fix OpenStruct serializing - [@etehtsea](https://github.com/etehtsea).
* [#105](https://github.com/intridea/grape-entity/pull/105): Specify which attribute is missing in which Entity - [@jhollinger](https://github.com/jhollinger).

0.4.4 (2014-08-17)
==================
Expand Down
6 changes: 5 additions & 1 deletion lib/grape_entity/entity.rb
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,11 @@ def delegate_attribute(attribute)
elsif object.respond_to?(:fetch, true)
object.fetch(name)
else
object.send(name)
begin
object.send(name)
rescue NoMethodError
raise NoMethodError, "#{self.class.name} missing attribute `#{name}' on #{object}"
end
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/grape_entity/entity_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ class Parent < Person
subject.expose(:awesome)
expect do
subject.represent(Object.new, serializable: true)
end.to raise_error(NoMethodError)
end.to raise_error(NoMethodError, /missing attribute `awesome'/)
end
end

Expand Down

0 comments on commit 471dc4c

Please sign in to comment.