diff --git a/lib/omniauth.rb b/lib/omniauth.rb index a94d975b1..13dc9c255 100644 --- a/lib/omniauth.rb +++ b/lib/omniauth.rb @@ -84,13 +84,15 @@ def before_request_phase(&block) def add_mock(provider, mock = {}) # Stringify keys recursively one level. + new_mock = {} mock.keys.each do |key| - mock[key.to_s] = mock.delete(key) + new_mock[key.to_s] = mock[key] end - mock.each_pair do |_key, val| + new_mock.each_pair do |_key, val| if val.is_a? Hash + new_val = {} val.keys.each do |subkey| - val[subkey.to_s] = val.delete(subkey) + new_val[subkey.to_s] = val[subkey] end else next @@ -98,7 +100,7 @@ def add_mock(provider, mock = {}) end # Merge with the default mock and ensure provider is correct. - mock = mock_auth[:default].dup.merge(mock) + mock = mock_auth[:default].dup.merge(new_mock) mock['provider'] = provider.to_s # Add it to the mocks. diff --git a/spec/omniauth_spec.rb b/spec/omniauth_spec.rb index 90b9db1d8..33078b801 100644 --- a/spec/omniauth_spec.rb +++ b/spec/omniauth_spec.rb @@ -110,6 +110,21 @@ class ExampleStrategy end end end + + specify '.add_mock does not change the hash inputed' do + @hash_inputed = { + :uid => '12345', + :info => {:name => 'Joe', :email => 'joe@example.com'} + } + @original_hash = { + :uid => '12345', + :info => {:name => 'Joe', :email => 'joe@example.com'} + } + + OmniAuth.config.add_mock(:facebook, @hash_inputed) + + expect(@hash_inputed).to be == @original_hash + end end describe '.logger' do