adds feature tests for sign up and sign using OAuth
This commit is contained in:
@@ -2,6 +2,7 @@ require 'rails_helper'
|
|||||||
|
|
||||||
feature 'Users' do
|
feature 'Users' do
|
||||||
|
|
||||||
|
context 'Regular authentication' do
|
||||||
scenario 'Sign up' do
|
scenario 'Sign up' do
|
||||||
visit '/'
|
visit '/'
|
||||||
click_link 'Sign up'
|
click_link 'Sign up'
|
||||||
@@ -41,6 +42,120 @@ feature 'Users' do
|
|||||||
|
|
||||||
expect(page).to have_content 'Signed in successfully.'
|
expect(page).to have_content 'Signed in successfully.'
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'OAuth authentication' do
|
||||||
|
context 'Twitter' do
|
||||||
|
background do
|
||||||
|
#request.env["devise.mapping"] = Devise.mappings[:user]
|
||||||
|
end
|
||||||
|
|
||||||
|
scenario 'Sign up, when email was provided by OAuth provider' do
|
||||||
|
omniauth_twitter_hash = { 'provider' => 'twitter',
|
||||||
|
'uid' => '12345',
|
||||||
|
'info' => {
|
||||||
|
'name' => 'manuela',
|
||||||
|
'email' => 'manuelacarmena@example.com',
|
||||||
|
'nickname' => 'ManuelaRocks',
|
||||||
|
'verified' => '1'
|
||||||
|
},
|
||||||
|
'extra' => { 'raw_info' =>
|
||||||
|
{ 'location' => 'Madrid',
|
||||||
|
'name' => 'Manuela de las Carmenas'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
OmniAuth.config.add_mock(:twitter, omniauth_twitter_hash)
|
||||||
|
|
||||||
|
visit '/'
|
||||||
|
click_link 'Sign up'
|
||||||
|
|
||||||
|
expect do
|
||||||
|
expect do
|
||||||
|
expect do
|
||||||
|
click_link 'Sign in with Twitter'
|
||||||
|
end.not_to change { ActionMailer::Base.deliveries.size }
|
||||||
|
end.to change { Identity.count }.by(1)
|
||||||
|
end.to change { User.count }.by(1)
|
||||||
|
|
||||||
|
expect(current_path).to eq(root_path)
|
||||||
|
expect_to_be_signed_in
|
||||||
|
|
||||||
|
user = User.last
|
||||||
|
expect(user.username).to eq('ManuelaRocks')
|
||||||
|
expect(user.email).to eq('manuelacarmena@example.com')
|
||||||
|
expect(user.confirmed?).to eq(true)
|
||||||
|
end
|
||||||
|
|
||||||
|
scenario 'Sign up, when neither email nor nickname were provided by OAuth provider' do
|
||||||
|
omniauth_twitter_hash = { 'provider' => 'twitter',
|
||||||
|
'uid' => '12345',
|
||||||
|
'info' => {
|
||||||
|
'name' => 'manuela'
|
||||||
|
},
|
||||||
|
'extra' => { 'raw_info' =>
|
||||||
|
{ 'location' => 'Madrid',
|
||||||
|
'name' => 'Manuela de las Carmenas'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
OmniAuth.config.add_mock(:twitter, omniauth_twitter_hash)
|
||||||
|
|
||||||
|
visit '/'
|
||||||
|
click_link 'Sign up'
|
||||||
|
|
||||||
|
expect do
|
||||||
|
expect do
|
||||||
|
expect do
|
||||||
|
click_link 'Sign in with Twitter'
|
||||||
|
end.not_to change { ActionMailer::Base.deliveries.size }
|
||||||
|
end.to change { Identity.count }.by(1)
|
||||||
|
end.to change { User.count }.by(1)
|
||||||
|
|
||||||
|
expect(current_path).to eq(finish_signup_path)
|
||||||
|
|
||||||
|
user = User.last
|
||||||
|
expect(user.username).to eq('manuela-de-las-carmenas')
|
||||||
|
expect(user.email).to eq("omniauth@participacion-12345-twitter.com")
|
||||||
|
|
||||||
|
fill_in 'user_email', with: 'manueladelascarmenas@example.com'
|
||||||
|
click_button 'Sign up'
|
||||||
|
|
||||||
|
sent_token = /.*confirmation_token=(.*)".*/.match(ActionMailer::Base.deliveries.last.body.to_s)[1]
|
||||||
|
visit user_confirmation_path(confirmation_token: sent_token)
|
||||||
|
|
||||||
|
expect(page).to have_content "Your email address has been successfully confirmed"
|
||||||
|
|
||||||
|
expect(user.reload.email).to eq('manueladelascarmenas@example.com')
|
||||||
|
end
|
||||||
|
|
||||||
|
scenario 'Sign in, user was already signed up with OAuth' do
|
||||||
|
user = create(:user, email: 'manuela@madrid.es', password: 'judgementday')
|
||||||
|
identity = create(:identity, uid: '12345', provider: 'twitter', user: user)
|
||||||
|
omniauth_twitter_hash = { 'provider' => 'twitter',
|
||||||
|
'uid' => '12345',
|
||||||
|
'info' => {
|
||||||
|
'name' => 'manuela'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
OmniAuth.config.add_mock(:twitter, omniauth_twitter_hash)
|
||||||
|
|
||||||
|
visit '/'
|
||||||
|
click_link 'Log in'
|
||||||
|
|
||||||
|
expect do
|
||||||
|
expect do
|
||||||
|
click_link 'Sign in with Twitter'
|
||||||
|
end.not_to change { Identity.count }
|
||||||
|
end.not_to change { User.count }
|
||||||
|
|
||||||
|
expect_to_be_signed_in
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
scenario 'Sign out' do
|
scenario 'Sign out' do
|
||||||
user = create(:user)
|
user = create(:user)
|
||||||
@@ -73,5 +188,4 @@ feature 'Users' do
|
|||||||
|
|
||||||
expect(page).to have_content "Your password has been changed successfully. You are now signed in."
|
expect(page).to have_content "Your password has been changed successfully. You are now signed in."
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -22,3 +22,5 @@ RSpec.configure do |config|
|
|||||||
end
|
end
|
||||||
|
|
||||||
Capybara.javascript_driver = :poltergeist
|
Capybara.javascript_driver = :poltergeist
|
||||||
|
|
||||||
|
OmniAuth.config.test_mode = true
|
||||||
|
|||||||
@@ -77,4 +77,7 @@ module CommonActions
|
|||||||
/\d errors? prohibited this (.*) from being saved:/
|
/\d errors? prohibited this (.*) from being saved:/
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def expect_to_be_signed_in
|
||||||
|
expect(find('.top-bar')).to have_content 'My account'
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user