2015-10-11 05:41:23 -04:00
|
|
|
require 'rails_helper'
|
2013-08-26 03:36:20 -04:00
|
|
|
|
|
|
|
# In the ghetto ... getting the spec to run in autospec
|
|
|
|
# thing is we need to load up all auth really early pre-fork
|
|
|
|
# it means that the require is not going to get a new copy
|
|
|
|
Auth.send(:remove_const, :FacebookAuthenticator)
|
|
|
|
load 'auth/facebook_authenticator.rb'
|
|
|
|
|
|
|
|
describe Auth::FacebookAuthenticator do
|
|
|
|
|
|
|
|
context 'after_authenticate' do
|
|
|
|
it 'can authenticate and create a user record for already existing users' do
|
|
|
|
authenticator = Auth::FacebookAuthenticator.new
|
|
|
|
user = Fabricate(:user)
|
|
|
|
|
|
|
|
hash = {
|
|
|
|
"extra" => {
|
|
|
|
"raw_info" => {
|
|
|
|
"username" => "bob"
|
|
|
|
}
|
|
|
|
},
|
|
|
|
"info" => {
|
2016-09-19 02:14:11 -04:00
|
|
|
:email => user.email,
|
|
|
|
"location" => "America",
|
|
|
|
"description" => "bio",
|
|
|
|
"urls" => {
|
|
|
|
"Website" => "https://awesome.com"
|
|
|
|
}
|
2013-08-26 03:36:20 -04:00
|
|
|
},
|
|
|
|
"uid" => "100"
|
|
|
|
}
|
|
|
|
|
|
|
|
result = authenticator.after_authenticate(hash)
|
|
|
|
|
2015-01-09 11:34:37 -05:00
|
|
|
expect(result.user.id).to eq(user.id)
|
2016-09-19 02:14:11 -04:00
|
|
|
expect(result.user.user_profile.website).to eq("https://awesome.com")
|
|
|
|
expect(result.user.user_profile.bio_raw).to eq("bio")
|
|
|
|
expect(result.user.user_profile.location).to eq("America")
|
2013-08-26 03:36:20 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'can create a proper result for non existing users' do
|
|
|
|
|
|
|
|
hash = {
|
|
|
|
"extra" => {
|
|
|
|
"raw_info" => {
|
|
|
|
"username" => "bob",
|
|
|
|
"name" => "bob bob"
|
|
|
|
}
|
|
|
|
},
|
|
|
|
"info" => {
|
|
|
|
:email => "bob@bob.com"
|
|
|
|
},
|
|
|
|
"uid" => "100"
|
|
|
|
}
|
|
|
|
|
|
|
|
authenticator = Auth::FacebookAuthenticator.new
|
|
|
|
|
|
|
|
result = authenticator.after_authenticate(hash)
|
|
|
|
|
2015-01-09 11:34:37 -05:00
|
|
|
expect(result.user).to eq(nil)
|
|
|
|
expect(result.extra_data[:name]).to eq("bob bob")
|
2013-08-26 03:36:20 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|