Skip to content

Commit

Permalink
Merge 28189b6 into fc304ab
Browse files Browse the repository at this point in the history
  • Loading branch information
HugoLnx committed Apr 21, 2015
2 parents fc304ab + 28189b6 commit 98d0c4c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
12 changes: 6 additions & 6 deletions lib/omniauth.rb
Expand Up @@ -84,21 +84,21 @@ def before_request_phase(&block)

def add_mock(provider, mock = {})
# Stringify keys recursively one level.
mock.keys.each do |key|
mock[key.to_s] = mock.delete(key)
end
mock.each_pair do |_key, val|
new_mock = {}
mock.keys.each { |key| new_mock[key.to_s] = mock[key] }
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
end
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.
Expand Down
13 changes: 13 additions & 0 deletions spec/omniauth_spec.rb
Expand Up @@ -110,6 +110,19 @@ 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'},
}

OmniAuth.config.add_mock(:facebook, @hash_inputed)

expect(@hash_inputed[:uid]).to be == '12345'
expect(@hash_inputed[:info][:name]).to be == 'Joe'
expect(@hash_inputed[:info][:email]).to be == 'joe@example.com'
end
end

describe '.logger' do
Expand Down

0 comments on commit 98d0c4c

Please sign in to comment.