Merging Hashie::Mash now correctly only calls the block on duplicate values
This commit is contained in:
parent
cdf6c832c0
commit
cebfebb801
|
@ -1,6 +1,7 @@
|
|||
## Next Release
|
||||
|
||||
* Your contribution here.
|
||||
* [#224](https://github.com/intridea/hashie/pull/224): Merging Hashie::Mash now correctly only calls the block on duplicate values - [@amysutedja](https://github.com/amysutedja).
|
||||
* [#221](https://github.com/intridea/hashie/pull/221): Reduce amount of allocated objects on calls with suffixes in Hashie::Mash - [@kubum](https://github.com/kubum).
|
||||
|
||||
## 3.3.1 (8/26/2014)
|
||||
|
|
|
@ -37,7 +37,7 @@ module Hashie
|
|||
defaults.delete property_name
|
||||
end
|
||||
|
||||
unless instance_methods.map { |m| m.to_s }.include?("#{property_name}=")
|
||||
unless instance_methods.map(&:to_s).include?("#{property_name}=")
|
||||
define_method(property_name) { |&block| self.[](property_name, &block) }
|
||||
property_assignment = property_name.to_s.concat('=').to_sym
|
||||
define_method(property_assignment) { |value| self.[]=(property_name, value) }
|
||||
|
|
|
@ -172,7 +172,7 @@ module Hashie
|
|||
end
|
||||
|
||||
def method?(name)
|
||||
methods.map { |m| m.to_s }.include?(name)
|
||||
methods.map(&:to_s).include?(name)
|
||||
end
|
||||
|
||||
def redefine_method(method_name)
|
||||
|
|
|
@ -8,7 +8,7 @@ module Hashie
|
|||
|
||||
def hashie_inspect
|
||||
ret = "#<#{self.class}"
|
||||
keys.sort_by { |key| key.to_s }.each do |key|
|
||||
keys.sort_by(&:to_s).each do |key|
|
||||
ret << " #{key}=#{self[key].inspect}"
|
||||
end
|
||||
ret << '>'
|
||||
|
|
|
@ -181,7 +181,7 @@ module Hashie
|
|||
custom_reader(key).deep_update(v, &blk)
|
||||
else
|
||||
value = convert_value(v, true)
|
||||
value = convert_value(blk.call(key, self[k], value), true) if blk
|
||||
value = convert_value(blk.call(key, self[k], value), true) if blk && self.key?(k)
|
||||
custom_writer(key, value, false)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -269,7 +269,7 @@ describe DashTest do
|
|||
end
|
||||
|
||||
it 'leaves only specified keys and keys with default values' do
|
||||
expect(subject.keys.sort_by { |key| key.to_s }).to eq [:count, :first_name]
|
||||
expect(subject.keys.sort_by(&:to_s)).to eq [:count, :first_name]
|
||||
expect(subject.email).to be_nil
|
||||
expect(subject.count).to eq 0
|
||||
end
|
||||
|
|
|
@ -160,7 +160,7 @@ describe Hashie::Extensions::Coercion do
|
|||
|
||||
instance[:foo] = %w('bar', 'bar2')
|
||||
expect(instance[:foo].map(&:value)).to all(eq 'String')
|
||||
expect(instance[:foo]).to be_none { |v| v.coerced? }
|
||||
expect(instance[:foo]).to be_none(&:coerced?)
|
||||
expect(instance[:foo]).to be_a(Set)
|
||||
end
|
||||
|
||||
|
|
|
@ -189,6 +189,12 @@ describe Hashie::Mash do
|
|||
duped = subject.merge(details: { address: 'Pasadena CA' }) { |_, oldv, newv| [oldv, newv].join(', ') }
|
||||
expect(duped.details.address).to eq 'Nowhere road, Pasadena CA'
|
||||
end
|
||||
|
||||
it 'copies values for non-duplicate keys when a block is supplied' do
|
||||
duped = subject.merge(details: { address: 'Pasadena CA', state: 'West Thoughtleby' }) { |_, oldv, _| oldv }
|
||||
expect(duped.details.address).to eq 'Nowhere road'
|
||||
expect(duped.details.state).to eq 'West Thoughtleby'
|
||||
end
|
||||
end
|
||||
|
||||
describe 'shallow update' do
|
||||
|
|
Loading…
Reference in New Issue