Commit 90f73438 authored by Rémy Coutable's avatar Rémy Coutable

Merge branch 'rs-rename-login_as' into 'master'

Except where necessary, use `sign_in` over `login_as` in features

See merge request !10320
parents 499d8756 6b298d06
...@@ -60,7 +60,9 @@ Feature: Profile ...@@ -60,7 +60,9 @@ Feature: Profile
Then I should see a password error message Then I should see a password error message
Scenario: I visit history tab Scenario: I visit history tab
Given I have activity Given I logout
And I sign in via the UI
And I have activity
When I visit Audit Log page When I visit Audit Log page
Then I should see my activity Then I should see my activity
......
...@@ -41,8 +41,7 @@ Feature: Project Forked Merge Requests ...@@ -41,8 +41,7 @@ Feature: Project Forked Merge Requests
@javascript @javascript
Scenario: I see the users in the target project for a new merge request Scenario: I see the users in the target project for a new merge request
Given I logout Given I sign in as an admin
And I sign in as an admin
And I have a project forked off of "Shop" called "Forked Shop" And I have a project forked off of "Shop" called "Forked Shop"
Then I visit project "Forked Shop" merge requests page Then I visit project "Forked Shop" merge requests page
And I click link "New Merge Request" And I click link "New Merge Request"
......
...@@ -6,7 +6,7 @@ class Spinach::Features::ProjectForkedMergeRequests < Spinach::FeatureSteps ...@@ -6,7 +6,7 @@ class Spinach::Features::ProjectForkedMergeRequests < Spinach::FeatureSteps
include Select2Helper include Select2Helper
step 'I am a member of project "Shop"' do step 'I am a member of project "Shop"' do
@project = Project.find_by(name: "Shop") @project = ::Project.find_by(name: "Shop")
@project ||= create(:project, :repository, name: "Shop") @project ||= create(:project, :repository, name: "Shop")
@project.team << [@user, :reporter] @project.team << [@user, :reporter]
end end
......
...@@ -43,7 +43,7 @@ class Spinach::Features::ProjectMergeRequestsAcceptance < Spinach::FeatureSteps ...@@ -43,7 +43,7 @@ class Spinach::Features::ProjectMergeRequestsAcceptance < Spinach::FeatureSteps
end end
step 'I am signed in as a developer of the project' do step 'I am signed in as a developer of the project' do
login_as(@user) sign_in(@user)
end end
step 'I should see merge request merged' do step 'I should see merge request merged' do
......
...@@ -31,7 +31,7 @@ class Spinach::Features::RevertMergeRequests < Spinach::FeatureSteps ...@@ -31,7 +31,7 @@ class Spinach::Features::RevertMergeRequests < Spinach::FeatureSteps
step 'I am signed in as a developer of the project' do step 'I am signed in as a developer of the project' do
@user = create(:user) { |u| @project.add_developer(u) } @user = create(:user) { |u| @project.add_developer(u) }
login_as(@user) sign_in(@user)
end end
step 'There is an open Merge Request' do step 'There is an open Merge Request' do
......
require Rails.root.join('spec', 'support', 'login_helpers') require Rails.root.join('features', 'support', 'login_helpers')
module SharedAuthentication module SharedAuthentication
include Spinach::DSL include Spinach::DSL
include LoginHelpers include LoginHelpers
step 'I sign in as a user' do step 'I sign in as a user' do
login_as :user sign_out(@user) if @user
@user = create(:user)
sign_in(@user)
end
step 'I sign in via the UI' do
gitlab_sign_in(create(:user))
end end
step 'I sign in as an admin' do step 'I sign in as an admin' do
login_as :admin sign_out(@user) if @user
@user = create(:admin)
sign_in(@user)
end end
step 'I sign in as "John Doe"' do step 'I sign in as "John Doe"' do
login_with(user_exists("John Doe")) gitlab_sign_in(user_exists("John Doe"))
end end
step 'I sign in as "Mary Jane"' do step 'I sign in as "Mary Jane"' do
login_with(user_exists("Mary Jane")) gitlab_sign_in(user_exists("Mary Jane"))
end end
step 'I should be redirected to sign in page' do step 'I should be redirected to sign in page' do
...@@ -25,14 +35,41 @@ module SharedAuthentication ...@@ -25,14 +35,41 @@ module SharedAuthentication
end end
step "I logout" do step "I logout" do
logout gitlab_sign_out
end end
step "I logout directly" do step "I logout directly" do
logout_direct gitlab_sign_out
end end
def current_user def current_user
@user || User.reorder(nil).first @user || User.reorder(nil).first
end end
private
def gitlab_sign_in(user)
visit new_user_session_path
fill_in "user_login", with: user.email
fill_in "user_password", with: "12345678"
check 'user_remember_me'
click_button "Sign in"
@user = user
end
def gitlab_sign_out
return unless @user
if Capybara.current_driver == Capybara.javascript_driver
find('.header-user-dropdown-toggle').click
click_link 'Sign out'
expect(page).to have_button('Sign in')
else
sign_out(@user)
end
@user = nil
end
end end
module LoginHelpers
# After inclusion, IntegrationHelpers calls these two methods that aren't
# supported by Spinach, so we perform the end results ourselves
class << self
def setup(*args)
Spinach.hooks.before_scenario do
Warden.test_mode!
end
end
def teardown(*args)
Spinach.hooks.after_scenario do
Warden.test_reset!
end
end
end
include Devise::Test::IntegrationHelpers
end
...@@ -84,8 +84,4 @@ module LoginHelpers ...@@ -84,8 +84,4 @@ module LoginHelpers
def logout_direct def logout_direct
page.driver.submit :delete, '/users/sign_out', {} page.driver.submit :delete, '/users/sign_out', {}
end end
def skip_ci_admin_auth
allow_any_instance_of(Ci::Admin::ApplicationController).to receive_messages(authenticate_admin!: true)
end
end end
...@@ -6,10 +6,13 @@ module WaitForAjax ...@@ -6,10 +6,13 @@ module WaitForAjax
end end
def finished_all_ajax_requests? def finished_all_ajax_requests?
return true unless javascript_test?
return true if page.evaluate_script('typeof jQuery === "undefined"')
page.evaluate_script('jQuery.active').zero? page.evaluate_script('jQuery.active').zero?
end end
def javascript_test? def javascript_test?
[:selenium, :webkit, :chrome, :poltergeist].include?(Capybara.current_driver) Capybara.current_driver == Capybara.javascript_driver
end end
end end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment