CARVIEW |
Select Language
HTTP/2 200
date: Sat, 26 Jul 2025 03:59:50 GMT
content-type: text/html; charset=utf-8
vary: X-PJAX, X-PJAX-Container, Turbo-Visit, Turbo-Frame, X-Requested-With,Accept-Encoding, Accept, X-Requested-With
x-robots-tag: none
etag: W/"dc6de02f0bce1b2ef258205c7047bc8d"
cache-control: max-age=0, private, must-revalidate
strict-transport-security: max-age=31536000; includeSubdomains; preload
x-frame-options: deny
x-content-type-options: nosniff
x-xss-protection: 0
referrer-policy: no-referrer-when-downgrade
content-security-policy: default-src 'none'; base-uri 'self'; child-src github.githubassets.com github.com/assets-cdn/worker/ github.com/assets/ gist.github.com/assets-cdn/worker/; connect-src 'self' uploads.github.com www.githubstatus.com collector.github.com raw.githubusercontent.com api.github.com github-cloud.s3.amazonaws.com github-production-repository-file-5c1aeb.s3.amazonaws.com github-production-upload-manifest-file-7fdce7.s3.amazonaws.com github-production-user-asset-6210df.s3.amazonaws.com *.rel.tunnels.api.visualstudio.com wss://*.rel.tunnels.api.visualstudio.com objects-origin.githubusercontent.com copilot-proxy.githubusercontent.com proxy.individual.githubcopilot.com proxy.business.githubcopilot.com proxy.enterprise.githubcopilot.com *.actions.githubusercontent.com wss://*.actions.githubusercontent.com productionresultssa0.blob.core.windows.net/ productionresultssa1.blob.core.windows.net/ productionresultssa2.blob.core.windows.net/ productionresultssa3.blob.core.windows.net/ productionresultssa4.blob.core.windows.net/ productionresultssa5.blob.core.windows.net/ productionresultssa6.blob.core.windows.net/ productionresultssa7.blob.core.windows.net/ productionresultssa8.blob.core.windows.net/ productionresultssa9.blob.core.windows.net/ productionresultssa10.blob.core.windows.net/ productionresultssa11.blob.core.windows.net/ productionresultssa12.blob.core.windows.net/ productionresultssa13.blob.core.windows.net/ productionresultssa14.blob.core.windows.net/ productionresultssa15.blob.core.windows.net/ productionresultssa16.blob.core.windows.net/ productionresultssa17.blob.core.windows.net/ productionresultssa18.blob.core.windows.net/ productionresultssa19.blob.core.windows.net/ github-production-repository-image-32fea6.s3.amazonaws.com github-production-release-asset-2e65be.s3.amazonaws.com insights.github.com wss://alive.github.com api.githubcopilot.com api.individual.githubcopilot.com api.business.githubcopilot.com api.enterprise.githubcopilot.com; font-src github.githubassets.com; form-action 'self' github.com gist.github.com copilot-workspace.githubnext.com objects-origin.githubusercontent.com; frame-ancestors 'none'; frame-src viewscreen.githubusercontent.com notebooks.githubusercontent.com; img-src 'self' data: blob: github.githubassets.com media.githubusercontent.com camo.githubusercontent.com identicons.github.com avatars.githubusercontent.com private-avatars.githubusercontent.com github-cloud.s3.amazonaws.com objects.githubusercontent.com release-assets.githubusercontent.com secured-user-images.githubusercontent.com/ user-images.githubusercontent.com/ private-user-images.githubusercontent.com opengraph.githubassets.com copilotprodattachments.blob.core.windows.net/github-production-copilot-attachments/ github-production-user-asset-6210df.s3.amazonaws.com customer-stories-feed.github.com spotlights-feed.github.com objects-origin.githubusercontent.com *.githubusercontent.com; manifest-src 'self'; media-src github.com user-images.githubusercontent.com/ secured-user-images.githubusercontent.com/ private-user-images.githubusercontent.com github-production-user-asset-6210df.s3.amazonaws.com gist.github.com; script-src github.githubassets.com; style-src 'unsafe-inline' github.githubassets.com; upgrade-insecure-requests; worker-src github.githubassets.com github.com/assets-cdn/worker/ github.com/assets/ gist.github.com/assets-cdn/worker/
server: github.com
content-encoding: gzip
accept-ranges: bytes
set-cookie: _gh_sess=HkBoKMoTGWepyhCbYaYMjJ5HIwBmBGUkovz8otmzuxqhx99f9rJEDqlQmc6koiZlZzpu%2FqoAeCd4TG1AnI0OhLVqz367uFShXBwok2zB8z%2FM7XdXob3KeZVusDh%2Ff1jSVzNdxkqKrrnvkIEAc2GRfUKaC1UUrqYojaMLM8%2BApED5XZlfC%2Bl476%2B0rXvD%2Bfu8Im%2FG%2FjyjpJeZePBrbE1j9nu3gP73rqINzvsjwq%2FeXzf98AA8eAO4gb0Ry9iNzmCOZozKWjFq4JWydTTvjBMnqg%3D%3D--E30yeiJ2ZA42eelq--rigmtD%2FcX5IolU73gu3E0g%3D%3D; Path=/; HttpOnly; Secure; SameSite=Lax
set-cookie: _octo=GH1.1.466839439.1753502389; Path=/; Domain=github.com; Expires=Sun, 26 Jul 2026 03:59:49 GMT; Secure; SameSite=Lax
set-cookie: logged_in=no; Path=/; Domain=github.com; Expires=Sun, 26 Jul 2026 03:59:49 GMT; HttpOnly; Secure; SameSite=Lax
x-github-request-id: CC38:1FA760:13AD7D:1DB18F:688452B5
Testing · janko/rodauth-rails Wiki · GitHub
Skip to content
Navigation Menu
{{ message }}
-
-
Notifications
You must be signed in to change notification settings - Fork 41
Testing
Janko Marohnić edited this page Dec 25, 2023
·
7 revisions
System (browser) tests for Rodauth actions could look something like this:
# test/system/authentication_test.rb
require "test_helper"
class AuthenticationTest < ActionDispatch::SystemTestCase
include ActiveJob::TestHelper
driven_by :rack_test
test "creating and verifying an account" do
create_account
assert_match "An email has been sent to you with a link to verify your account", page.text
verify_account
assert_match "Your account has been verified", page.text
end
test "logging in and logging out" do
create_account(verify: true)
logout
assert_match "You have been logged out", page.text
login
assert_match "You have been logged in", page.text
end
private
def create_account(email: "user@example.com", password: "secret", verify: false)
visit "/create-account"
fill_in "Login", with: email
fill_in "Password", with: password
fill_in "Confirm Password", with: password
click_on "Create Account"
verify_account if verify
end
def verify_account
perform_enqueued_jobs # run enqueued email deliveries
email = ActionMailer::Base.deliveries.last
verify_account_link = email.body.to_s[/\S+verify-account\S+/]
visit verify_account_link
click_on "Verify Account"
end
def login(email: "user@example.com", password: "secret")
visit "/login"
fill_in "Login", with: email
fill_in "Password", with: password
click_on "Login"
end
def logout
visit "/logout"
click_on "Logout"
end
end
While request tests in JSON API mode with JWT tokens could look something like this:
# test/integration/authentication_test.rb
require "test_helper"
class AuthenticationTest < ActionDispatch::IntegrationTest
test "creating and verifying an account" do
create_account
assert_response :success
assert_match "An email has been sent to you with a link to verify your account", JSON.parse(body)["success"]
verify_account
assert_response :success
assert_match "Your account has been verified", JSON.parse(body)["success"]
end
test "logging in and logging out" do
create_account(verify: true)
logout
assert_response :success
assert_match "You have been logged out", JSON.parse(body)["success"]
login
assert_response :success
assert_match "You have been logged in", JSON.parse(body)["success"]
end
private
def create_account(email: "user@example.com", password: "secret", verify: false)
post "/create-account", as: :json, params: { email: email, password: password, "password-confirm": password }
verify_account if verify
end
def verify_account
perform_enqueued_jobs # run enqueued email deliveries
email = ActionMailer::Base.deliveries.last
verify_account_key = email.body.to_s[/verify-account\?key=(\S+)/, 1]
post "/verify-account", as: :json, params: { key: verify_account_key }
end
def login(email: "user@example.com", password: "secret")
post "/login", as: :json, params: { email: email, password: password }
end
def logout
post "/logout", as: :json, headers: { "Authorization" => headers["Authorization"] }
end
end
Note: Rails now discourages these tests in favor of ActionDispatch::Integration
tests.
Since these tests don't load the middleware stack, Rodauth routes won't be available here. To authenticate the session, you can call Rodauth methods directly:
# test/controllers/articles_controller_test.rb
class ArticlesControllerTest < ActionController::TestCase
test "required authentication" do
get :index
assert_response 302
assert_redirected_to "/login"
assert_equal "Please login to continue", flash[:alert]
account = Account.create!(email: "user@example.com", password: "secret123", status: "verified")
login(account)
get :index
assert_response 200
logout
get :index
assert_response 302
assert_equal "Please login to continue", flash[:alert]
end
private
# Call `rodauth(:admin)` if you want to use a secondary :admin configuration
def login(account)
rodauth.account_from_login(account.email)
rodauth.login_session("password")
end
def logout
rodauth.logout
end
end
If you're using RSpec, you'll need to first include the controller test helpers:
RSpec.configure do |config|
config.include Rodauth::Rails::Test::Controller, type: :controller
end
If you're delivering emails in the background, make sure to set Active Job
queue adapter to :test
or :inline
:
# config/environments/test.rb
Rails.application.configure do |config|
# ...
config.active_job.queue_adapter = :test # or :inline
# ...
end
You can’t perform that action at this time.