Skip to content

Commit

Permalink
Fix #891: only dup (not deep_dup) InheritableValues.
Browse files Browse the repository at this point in the history
Please also see #1034, where StackableValues are only dup'ed (not
deep_dup'ed).

Other changes:

* Add test to reproduce bug #891
* Remove support for deep_dup (no longer used)
* Add item to CHANGELOG
  • Loading branch information
Todd Mazierski committed Jun 29, 2015
1 parent b8b6053 commit bdb334c
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 158 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Next Release
* [#1038](https://github.com/intridea/grape/pull/1038): Avoid dup-ing the String class when used in inherited params - [@rnubel](https://github.com/rnubel).
* [#1042](https://github.com/intridea/grape/issues/1042): Fix coercion of complex arrays - [@dim](https://github.com/dim).
* [#1045](https://github.com/intridea/grape/pull/1045): Do not convert `Rack::Response` to `Rack::Response` in middleware - [@dmitry](https://github.com/dmitry).
* [#1048](https://github.com/intridea/grape/pull/1048): Only dup `InheritableValues`, remove support for `deep_dup` - [@toddmazierski](https://github.com/toddmazierski/)

0.12.0 (6/18/2015)
==================
Expand Down
49 changes: 0 additions & 49 deletions lib/backports/active_support/deep_dup.rb

This file was deleted.

97 changes: 0 additions & 97 deletions lib/backports/active_support/duplicable.rb

This file was deleted.

8 changes: 0 additions & 8 deletions lib/grape.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,6 @@
require 'set'
require 'active_support/version'
require 'active_support/core_ext/hash/indifferent_access'

if ActiveSupport::VERSION::MAJOR >= 4
require 'active_support/core_ext/object/deep_dup'
else
require_relative 'backports/active_support/deep_dup'
end
require_relative 'backports/active_support/duplicable'

require 'active_support/ordered_hash'
require 'active_support/core_ext/object/conversions'
require 'active_support/core_ext/array/extract_options'
Expand Down
2 changes: 1 addition & 1 deletion lib/grape/util/inheritable_values.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def to_hash
def initialize_copy(other)
super
self.inherited_values = other.inherited_values
self.new_values = other.new_values.deep_dup
self.new_values = other.new_values.dup
end

protected
Expand Down
13 changes: 10 additions & 3 deletions spec/grape/util/inheritable_values_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,16 @@ module Util
end

describe '#clone' do
it 'clones itself even when containing a String class' do
subject[:foo] = String
expect(subject.clone.to_hash).to eq(foo: String)
let(:obj_cloned) { subject.clone }

context 'complex (i.e. not primitive) data types (ex. entity classes, please see bug #891)' do
let(:description) { { entity: double } }

before { subject[:description] = description }

it 'copies values; does not duplicate them' do
expect(obj_cloned[:description]).to eq description
end
end
end
end
Expand Down

0 comments on commit bdb334c

Please sign in to comment.