Merge branch 'master' of bitbucket.org:jamkazam/jam-web

This commit is contained in:
Brian Smith 2012-11-22 03:28:14 -05:00
commit a8291be566
4 changed files with 56 additions and 3 deletions

View File

@ -53,8 +53,10 @@ class SessionsController < ApplicationController
# Users who sign up using oauth are presumed to have valid email adddresses.
user.confirm_email!
auth = 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])
auth = 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])
user.save
complete_sign_in user
end

View File

@ -39,4 +39,8 @@ SampleApp::Application.configure do
silence_warnings do
BCrypt::Engine::DEFAULT_COST = BCrypt::Engine::MIN_COST
end
# For testing omniauth
OmniAuth.config.test_mode = true
end

View File

@ -28,12 +28,58 @@ describe SessionsController do
controller.signed_in?.should == true
end
it "should redirect the user to the proper page" do
post :create, :session => @attr
response.should redirect_to(client_url)
end
end
describe "create_oauth" do
before(:each) do
OmniAuth.config.mock_auth[:facebook] = OmniAuth::AuthHash.new({
'uid' => '100',
'provider' => 'facebook',
'info' => {
'first_name' => 'FirstName',
'last_name' => 'LastName',
'email' => 'test_oauth@example.com',
'location' => 'mylocation'
},
'credentials' => {
'token' => 'facebooktoken',
'expires_at' => 1000000000
}
})
end
it "should create a user when oauth comes in with a non-currently existing user" do
request.env["omniauth.auth"] = OmniAuth.config.mock_auth[:facebook]
lambda do
visit '/auth/facebook'
end.should change(User, :count).by(1)
user = User.find_by_email('test_oauth@example.com')
user.should_not be_nil
user.first_name.should == "FirstName"
response.should be_success
# also verify that a second visit does *not* create another new user
lambda do
visit '/auth/facebook'
end.should change(User, :count).by(0)
end
it "should not create a user when oauth comes in with a currently existing user" do
user = FactoryGirl.create(:user) # in the jam session
OmniAuth.config.mock_auth[:facebook][:info][:email] = user.email
OmniAuth.config.mock_auth[:facebook] = OmniAuth.config.mock_auth[:facebook]
lambda do
visit '/auth/facebook'
end.should change(User, :count).by(0)
end
end

View File

@ -4,6 +4,7 @@ describe "Static pages" do
subject { page }
describe "Home page" do
before { visit '/oldhome' }