Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mock browser login for integration specs. #17488

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion spec/features/my/sessions_management_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

require "spec_helper"

RSpec.describe "My account session management", :js do
RSpec.describe "My account session management", :js, :with_cookies do
include Redmine::I18n
let(:user) { create(:user) }

Expand Down
2 changes: 1 addition & 1 deletion spec/features/oauth/authorization_code_flow_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ def get_and_test_token(code)
end

# Selenium can't return response headers
context "in browser that can log response headers", js: false do
context "in browser that can log response headers", :with_cookies, js: false do
before do
login_as user
end
Expand Down
7 changes: 6 additions & 1 deletion spec/support/authentication_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def self.included(base)
end

def login_as(user)
if is_a?(RSpec::Rails::FeatureExampleGroup)
if using_browser_cookies? && is_a?(RSpec::Rails::FeatureExampleGroup)
# If we want to mock having finished the login process
# we must set the user_id in rack.session accordingly
# Otherwise e.g. calls to Warden will behave unexpectantly
Expand All @@ -49,6 +49,7 @@ def login_as(user)
end
end

allow(User).to receive(:current).and_return user
allow(RequestStore).to receive(:[]).and_call_original
allow(RequestStore).to receive(:[]).with(:current_user).and_return(user)
end
Expand Down Expand Up @@ -94,6 +95,10 @@ def session_value_for(user)
{ user_id: user.id, updated_at: Time.current }
end

def using_browser_cookies?
RSpec.current_example.metadata[:with_cookies]
end

module ClassMethods
# Sets the current user.
#
Expand Down
Loading