Skip to content

Commit

Permalink
Merge 3fed07b into e1408f5
Browse files Browse the repository at this point in the history
  • Loading branch information
HugoLnx committed Feb 10, 2015
2 parents e1408f5 + 3fed07b commit 9c6857b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
10 changes: 6 additions & 4 deletions lib/omniauth.rb
Expand Up @@ -84,21 +84,23 @@ 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
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
15 changes: 15 additions & 0 deletions spec/omniauth_spec.rb
Expand Up @@ -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
Expand Down

0 comments on commit 9c6857b

Please sign in to comment.