Skip to content

Commit

Permalink
Fix tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
xet7 committed Nov 2, 2024
1 parent 8c72f0a commit 1dc4be6
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 12 deletions.
29 changes: 17 additions & 12 deletions test/support/authentication_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,24 @@

module AuthenticationHelpers
def sign_in_as(user)
if respond_to?(:visit)
visit sign_in_url
fill_in :email, with: user.email
fill_in :password, with: "Secret1*3*5*"
click_on "Login to your account"
elsif defined?(controller) && controller.respond_to?(:session)
controller.session[:user_id] = user.id
elsif respond_to?(:session)
session[:user_id] = user.id
else
post sign_in_url, params: { email: user.email, password: "Secret1*3*5*" }
if respond_to?(:session)
session[:current_user_id] = user.id
elsif respond_to?(:post)
# For integration tests
post sign_in_path, params: {
email: user.email,
password: user.password
}
end
user
end

def sign_out
if respond_to?(:session)
session.delete(:current_user_id)
elsif respond_to?(:delete)
delete sign_out_path
end
@current_user = user
end

def current_user
Expand Down
6 changes: 6 additions & 0 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,13 @@ def permit(user, record, action)
end

class ActionController::TestCase
include Devise::Test::IntegrationHelpers if defined?(Devise)
include AuthenticationHelpers

# Add session support
def setup
@request ||= ActionController::TestRequest.create(self.class)
end
end

class ActionDispatch::IntegrationTest
Expand Down

0 comments on commit 1dc4be6

Please sign in to comment.