Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Rollbar::Util.deep_merge so it has default values for arguments #362

Merged
merged 3 commits into from
Dec 18, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions lib/rollbar/util.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,13 @@ def self.deep_copy(obj)
end

def self.deep_merge(hash1, hash2)
hash1 ||= {}
hash2 ||= {}

hash2.each_key do |k|
if hash1[k].is_a? ::Hash and hash2[k].is_a? ::Hash
if hash1[k].is_a?(::Hash) && hash2[k].is_a?(::Hash)
hash1[k] = deep_merge(hash1[k], hash2[k])
elsif hash1[k].is_a? Array and hash2[k].is_a? Array
elsif hash1[k].is_a?(Array) && hash2[k].is_a?(Array)
hash1[k] += deep_copy(hash2[k])
elsif hash2[k]
hash1[k] = deep_copy(hash2[k])
Expand Down
19 changes: 19 additions & 0 deletions spec/rollbar/util_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
require 'spec_helper'

require 'rollbar/util'

describe Rollbar::Util do
describe '.deep_merge' do
context 'with nil arguments' do
let(:data) do
{ :foo => :bar }
end

it 'doesnt fail and returns same hash' do
result = Rollbar::Util.deep_merge(nil, data)

expect(result).to be_eql(data)
end
end
end
end
3 changes: 2 additions & 1 deletion spec/rollbar_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

require 'logger'
require 'socket'
require 'spec_helper'
require 'girl_friday'
require 'redis'
require 'active_support/core_ext/object'
Expand All @@ -14,6 +13,8 @@
rescue LoadError
end

require 'spec_helper'

describe Rollbar do
let(:notifier) { Rollbar.notifier }
before do
Expand Down