Skip to content

Commit

Permalink
Fix profile_url set from omniauth hash
Browse files Browse the repository at this point in the history
  • Loading branch information
skogsmaskin committed Aug 21, 2013
1 parent 117418c commit 8f2a707
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
10 changes: 9 additions & 1 deletion lib/checkpoint/models/account.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,14 @@ def declare_with_omniauth(auth_data, options = {})
# Create a new identity!
identity ||= Identity.create!(:realm => options[:realm])

# Try find profile_url
profile_url = nil
if auth_data['info']['urls'] and auth_data['info']['urls'].any?
profile_url = auth_data['info']['urls'][auth_data['provider'].titleize]
elsif auth_data['extra']['raw_info']
profile_url = auth_data['extra']['raw_info']['link']
end

account = declare!(
:provider => auth_data['provider'],
:uid => auth_data['uid'],
Expand All @@ -102,7 +110,7 @@ def declare_with_omniauth(auth_data, options = {})
:image_url => auth_data['info']['image'],
:description => auth_data['info']['description'],
:email => auth_data['info']['email'],
:profile_url => (auth_data['info']['urls'] || {})['Twitter']
:profile_url => profile_url
)
account
end
Expand Down
9 changes: 8 additions & 1 deletion spec/lib/models/account_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@
"description"=>"Gartner pa Underskog og vaktmester pa Origo",
"urls"=>
{"Website"=>"http://origo.no/simen",
"Facebook"=>"http://twitter.com/svale"}}}
"Facebook"=>"http://facebook.com/svale"}}}
end

it "gets the proper fields set when declared" do
Expand Down Expand Up @@ -229,5 +229,12 @@
identity.primary_account.should eq account2
end

it "Provides profile urls" do
account_with_twitter = Account.declare_with_omniauth(twitter_auth, :realm => realm)
account_with_facebook = Account.declare_with_omniauth(facebook_auth, :realm => realm)
account_with_twitter.profile_url.should eq "http://twitter.com/svale"
account_with_facebook.profile_url.should eq "http://facebook.com/svale"
end

end
end

0 comments on commit 8f2a707

Please sign in to comment.