Commit 40ba2f7d authored by Robert Speicher's avatar Robert Speicher

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

parent 4ef0c688
......@@ -60,7 +60,9 @@ Feature: Profile
Then I should see a password error message
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
Then I should see my activity
......
......@@ -41,8 +41,7 @@ Feature: Project Forked Merge Requests
@javascript
Scenario: I see the users in the target project for a new merge request
Given I logout
And I sign in as an admin
Given I sign in as an admin
And I have a project forked off of "Shop" called "Forked Shop"
Then I visit project "Forked Shop" merge requests page
And I click link "New Merge Request"
......
......@@ -6,7 +6,7 @@ class Spinach::Features::ProjectForkedMergeRequests < Spinach::FeatureSteps
include Select2Helper
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.team << [@user, :reporter]
end
......
......@@ -43,7 +43,7 @@ class Spinach::Features::ProjectMergeRequestsAcceptance < Spinach::FeatureSteps
end
step 'I am signed in as a developer of the project' do
login_as(@user)
sign_in(@user)
end
step 'I should see merge request merged' do
......
......@@ -31,7 +31,7 @@ class Spinach::Features::RevertMergeRequests < Spinach::FeatureSteps
step 'I am signed in as a developer of the project' do
@user = create(:user) { |u| @project.add_developer(u) }
login_as(@user)
sign_in(@user)
end
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
include Spinach::DSL
include LoginHelpers
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
step 'I sign in as an admin' do
login_as :admin
sign_out(@user) if @user
@user = create(:admin)
sign_in(@user)
end
step 'I sign in as "John Doe"' do
login_with(user_exists("John Doe"))
gitlab_sign_in(user_exists("John Doe"))
end
step 'I sign in as "Mary Jane"' do
login_with(user_exists("Mary Jane"))
gitlab_sign_in(user_exists("Mary Jane"))
end
step 'I should be redirected to sign in page' do
......@@ -25,14 +35,41 @@ module SharedAuthentication
end
step "I logout" do
logout
gitlab_sign_out
end
step "I logout directly" do
logout_direct
gitlab_sign_out
end
def current_user
@user || User.reorder(nil).first
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
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
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