VRFS-2033 : Spec and fixes for google_oauth2 provider-type

user_authentications.  These are named “google_login” in our app.
This commit is contained in:
Steven Miers 2014-10-15 13:41:49 -05:00
parent 077d3f4253
commit ece7cf2d56
2 changed files with 45 additions and 4 deletions

View File

@ -134,11 +134,16 @@ class SessionsController < ApplicationController
# Always make and save a new authorization. This is because they expire, and honestly there's no cost
# to just making and saving it.
user_auth_hash = {
:provider => auth_hash[:provider],
:uid => auth_hash[:uid],
:token => auth_hash[:credentials][:token],
:token_expiration => Time.at(auth_hash[:credentials][:expires_at]),
:secret => auth_hash[:credentials][:secret]
}
#if authorization.nil?
authorization = current_user.user_authorizations.build :provider => auth_hash[:provider],
:uid => auth_hash[:uid],
:token => auth_hash[:credentials][:token],
:token_expiration => Time.at(auth_hash[:credentials][:expires_at])
authorization = current_user.user_authorizations.build(user_auth_hash)
authorization.save
#end

View File

@ -111,6 +111,42 @@ describe SessionsController do
end
end
describe "google_login" do
before(:each) do
OmniAuth.config.mock_auth[:google_login] = OmniAuth::AuthHash.new({
'uid' => '100',
'provider' => 'google_login',
'credentials' => {
'token' => 'google_logintoken',
'secret' => 'google_loginsecret',
'expires_at' => 1000000000
}
})
end
it "should update user_authorization for existing user" do
cookie_jar[:remember_token] = user.remember_token # controller.current_user is not working. i think because of omniauth
request.env["omniauth.auth"] = OmniAuth.config.mock_auth[:google_login]
visit '/auth/google_login'
user.reload
auth = user.user_authorization('google_login')
auth.uid.should == '100'
auth.token.should == 'google_logintoken'
auth.secret.should == 'google_loginsecret'
# also verify that a second visit does *not* create another new user
visit '/auth/google_login'
user.reload
auth = user.user_authorization('google_login')
auth.uid.should == '100'
auth.token.should == 'google_logintoken'
auth.secret.should == 'google_loginsecret'
end
end
end