-
Notifications
You must be signed in to change notification settings - Fork 128
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add initial system tests This covers current functionality. Asserting redirects isn't available in system tests so we'll need to create integration tests instead for that assertion. * Switch to headless_chrome This avoids bringing up the actual browser when running tests and should also just work in CI too. * Disable admin user fixtures These cause errors since they have database constraints and we'd need to fill these out. For now we'll just have a helper to create a default admin user. * Add simplecov gem setup * Add tests CI workflow * Fix Rails secrets deprecation from Devise Known issue and waiting on PR merge and new release. In the meantime, we can apply this simple fix. ``` DEPRECATION WARNING: `Rails.application.secrets` is deprecated in favor of `Rails.application.credentials` and will be removed in Rails 7.2. (called from <top (required)> at /home/runner/work/demo.activeadmin.info/demo.activeadmin.info/config/environment.rb:5) ``` heartcombo/devise#5645 (comment)
- Loading branch information
1 parent
612fc85
commit cd9193d
Showing
11 changed files
with
186 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
name: Tests | ||
|
||
on: | ||
pull_request: | ||
push: | ||
branches: | ||
- main | ||
|
||
concurrency: | ||
group: ${{ github.repository }}-${{ github.workflow }}-${{ github.ref }} | ||
cancel-in-progress: ${{ github.event_name == 'pull_request' }} | ||
|
||
env: | ||
COVERAGE_RETENTION_DAYS: 3 | ||
|
||
jobs: | ||
run_tests: | ||
name: Run tests | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: ruby/setup-ruby@v1 | ||
with: | ||
ruby-version: .ruby-version | ||
bundler-cache: true | ||
- name: Run tests | ||
env: | ||
COVERAGE: true | ||
RAILS_ENV: test | ||
run: bin/rails db:setup test:all | ||
- name: Upload screenshots from failed system tests | ||
uses: actions/upload-artifact@v4 | ||
if: failure() | ||
with: | ||
name: screenshots | ||
path: ${{ github.workspace }}/tmp/screenshots | ||
if-no-files-found: ignore | ||
- uses: actions/upload-artifact@v4 | ||
with: | ||
name: rails-coverage | ||
path: coverage | ||
if-no-files-found: error | ||
retention-days: ${{ env.COVERAGE_RETENTION_DAYS }} | ||
|
||
upload_coverage: | ||
name: Upload Coverage | ||
runs-on: ubuntu-latest | ||
needs: | ||
- run_tests | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: actions/download-artifact@v4 | ||
with: | ||
name: rails-coverage | ||
- uses: codecov/codecov-action@v3 | ||
with: | ||
token: ${{ secrets.CODECOV_TOKEN }} | ||
files: coverage.xml | ||
fail_ci_if_error: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,3 +38,4 @@ | |
!/app/assets/builds/.keep | ||
|
||
/node_modules | ||
/coverage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
require "test_helper" | ||
|
||
class ApplicationSystemTestCase < ActionDispatch::SystemTestCase | ||
driven_by :selenium, using: :chrome, screen_size: [1400, 1400] | ||
driven_by :selenium, using: :headless_chrome, screen_size: [1400, 1400] | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
require "application_system_test_case" | ||
|
||
class AdminUsersTest < ApplicationSystemTestCase | ||
test "visiting the index" do | ||
sign_in default_admin_user | ||
|
||
visit admin_admin_users_path | ||
|
||
assert_text "Admin Users" | ||
assert_text "Showing 1 of 1" | ||
assert_text "admin@example.com" | ||
end | ||
|
||
test "visiting the show" do | ||
sign_in default_admin_user | ||
|
||
visit admin_admin_user_path(default_admin_user) | ||
|
||
assert_text "admin@example.com" | ||
assert_selector "a", text: "Edit Admin User" | ||
assert_selector "a", text: "Delete Admin User" | ||
end | ||
|
||
test "visiting the new and submitting" do | ||
sign_in default_admin_user | ||
|
||
visit new_admin_admin_user_path | ||
|
||
fill_in "Email", with: "test@test.com" | ||
fill_in "Password", with: "password", id: "admin_user_password" | ||
fill_in "Password confirmation", with: "password" | ||
click_on "Create Admin user" | ||
|
||
assert_text "Admin user was successfully created." | ||
assert_text "test@test.com" | ||
end | ||
|
||
test "visiting the edit" do | ||
sign_in default_admin_user | ||
|
||
visit edit_admin_admin_user_path(default_admin_user) | ||
|
||
assert_text "admin@example.com" | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
require "application_system_test_case" | ||
|
||
class AdminUsersTest < ApplicationSystemTestCase | ||
test "visiting root redirects to admin root" do | ||
sign_in default_admin_user | ||
visit root_path | ||
assert_text "Welcome to ActiveAdmin" | ||
end | ||
|
||
test "visiting the admin root renders dashboard" do | ||
sign_in default_admin_user | ||
visit admin_root_path | ||
assert_text "Welcome to ActiveAdmin" | ||
end | ||
|
||
test "visiting the admin dashboard" do | ||
sign_in default_admin_user | ||
visit admin_dashboard_path | ||
assert_text "Welcome to ActiveAdmin" | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
require "application_system_test_case" | ||
|
||
class SessionsTest < ApplicationSystemTestCase | ||
test "visiting the root redirects to admin login" do | ||
visit root_path | ||
# assert_redirected_to new_admin_user_session_path | ||
assert_text "Active Admin Demo Sign In" | ||
end | ||
|
||
test "submitting the login form successfully" do | ||
default_admin_user | ||
|
||
visit new_admin_user_session_path | ||
|
||
fill_in "Email", with: "admin@example.com" | ||
fill_in "Password", with: "password" | ||
click_on "Sign In" | ||
|
||
# assert_redirected_to admin_dashboard_path | ||
assert_text "Welcome to ActiveAdmin" | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters