Skip to content

Commit

Permalink
Fix #249: leaking of options and internals in default serialization.
Browse files Browse the repository at this point in the history
  • Loading branch information
dblock committed Nov 20, 2016
1 parent bca979c commit 6347bfb
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 11 deletions.
25 changes: 14 additions & 11 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -1,42 +1,45 @@
# This configuration was generated by `rubocop --auto-gen-config`
# on 2015-08-10 13:14:22 +0300 using RuboCop version 0.31.0.
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2016-11-20 09:52:08 -0500 using RuboCop version 0.45.0.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
# versions of RuboCop, may require this file to be generated again.

# Offense count: 6
Metrics/AbcSize:
Max: 33
Max: 32

# Offense count: 2
# Configuration parameters: CountComments.
Metrics/ClassLength:
Max: 202
Max: 205

# Offense count: 3
Metrics/CyclomaticComplexity:
Max: 11

# Offense count: 210
# Configuration parameters: AllowURI, URISchemes.
# Offense count: 237
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives.
# URISchemes: http, https
Metrics/LineLength:
Max: 146

# Offense count: 8
# Offense count: 6
# Configuration parameters: CountComments.
Metrics/MethodLength:
Max: 28

# Offense count: 5
# Offense count: 2
Metrics/PerceivedComplexity:
Max: 13

# Offense count: 58
# Offense count: 33
Style/Documentation:
Enabled: false

# Offense count: 1
# Configuration parameters: Exclude.
# Configuration parameters: ExpectMatchingDefinition, Regex, IgnoreExecutableScripts.
Style/FileName:
Enabled: false
Exclude:
- 'lib/grape-entity.rb'
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#### Fixes

* [#249](https://github.com/ruby-grape/grape-entity/issues/249): Fix leaking of options and internals in default serialization - [@dblock](https://github.com/dblock), [@KingsleyKelly](https://github.com/KingsleyKelly).
* [#248](https://github.com/ruby-grape/grape-entity/pull/248): Fix `nil` values causing errors when `merge` option passed - [@arempe93](https://github.com/arempe93).
* Your contribution here.

Expand Down
5 changes: 5 additions & 0 deletions lib/grape_entity/entity.rb
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,11 @@ def presented
end
end

# Prevent default serialization of :options or :delegator.
def inspect
"#<#{self.class.name}:#{object_id} @object=#{@object}>"
end

def initialize(object, options = {})
@object = object
@delegator = Delegator.new object
Expand Down
7 changes: 7 additions & 0 deletions spec/grape_entity/entity_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1347,6 +1347,13 @@ class NoPathCharacterEntity < Grape::Entity
end
end

describe '#inspect' do
it 'does not serialize delegator or options' do
expect(subject.inspect).to_not include '@options'
expect(subject.inspect).to_not include '@delegator'
end
end

describe '#value_for' do
before do
fresh_class.class_eval do
Expand Down

0 comments on commit 6347bfb

Please sign in to comment.