Skip to content

Commit

Permalink
add tests for pages and add dynamic tests for all component pages
Browse files Browse the repository at this point in the history
  • Loading branch information
SethHorsley committed Mar 3, 2024
1 parent bf49851 commit fc09293
Show file tree
Hide file tree
Showing 10 changed files with 98 additions and 17 deletions.
58 changes: 58 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,61 @@ jobs:

- name: Lint code for consistent style
run: bundle exec standardrb


test:
timeout-minutes: 10
runs-on: ubuntu-latest
services:
postgres:
image: postgres:latest
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: password
POSTGRES_DB: test
ports: ['5432:5432']
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
redis:
image: redis
ports: ['6379:6379']
options: >-
--health-cmd "redis-cli ping"
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
- uses: actions/checkout@v4

- name: Setup Ruby
uses: ruby/setup-ruby@v1
with:
bundler-cache: true

- name: Setup Node
uses: actions/setup-node@v4
with:
node-version-file: '.tool-versions'
cache: yarn

- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install -y -qq libvips
yarn install --frozen-lockfile
- name: Run tests
env:
DATABASE_URL: postgres://postgres:password@localhost:5432/test
REDIS_URL: redis://localhost:6379/0
RAILS_ENV: test
# RAILS_MASTER_KEY: ${{ secrets.RAILS_MASTER_KEY }}
run: |
bin/rails test:prepare
bin/rails db:test:prepare
bin/rails test
bin/rails test:system
2 changes: 2 additions & 0 deletions .tool-versions
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ruby 3.3.0
nodejs 20.10.0
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ gem "dotenv-rails", groups: [:development, :test]
group :development, :test do
# See https://guides.rubyonrails.org/debugging_rails_applications.html#debugging-with-the-debug-gem
gem "debug", platforms: %i[mri mingw x64_mingw]
gem "pry"
end

group :development do
Expand Down
5 changes: 5 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ GEM
regexp_parser (>= 1.5, < 3.0)
xpath (~> 3.2)
cgi (0.4.1)
coderay (1.1.3)
concurrent-ruby (1.2.3)
crass (1.0.6)
cssbundling-rails (1.3.3)
Expand Down Expand Up @@ -190,6 +191,9 @@ GEM
postmark-rails (0.22.1)
actionmailer (>= 3.0.0)
postmark (>= 1.21.3, < 2.0)
pry (0.14.2)
coderay (~> 1.1)
method_source (~> 1.0)
psych (5.1.2)
stringio
public_suffix (5.0.4)
Expand Down Expand Up @@ -347,6 +351,7 @@ DEPENDENCIES
phlex-rails
phlex_ui
postmark-rails
pry
puma (~> 5.0)
rack-www
rails (~> 7.0.8)
Expand Down
23 changes: 20 additions & 3 deletions test/controllers/components_controller_test.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,25 @@
require "test_helper"

class ComponentsControllerTest < ActionDispatch::IntegrationTest
test "should get typography" do
get components_typography_url
assert_response :success
def self.all_docs_routes
scope_prefix = "/docs"

Rails.application.routes.routes.select do |route|
route.path.spec.to_s.start_with?(scope_prefix)
end.map do |route|
{
method: route.verb,
path: route.path.spec.to_s.sub(/\(\.:format\)\z/, ""),
controller: route.defaults[:controller],
action: route.defaults[:action]
}
end
end

all_docs_routes.each do |route|
test "should get #{route[:action]}" do
get route[:path]
assert_response :success
end
end
end
8 changes: 4 additions & 4 deletions test/controllers/errors_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

class ErrorsControllerTest < ActionDispatch::IntegrationTest
test "should get not_found" do
get errors_not_found_url
assert_response :success
get "/404"
assert_response :not_found
end

test "should get internal_server_error" do
get errors_internal_server_error_url
assert_response :success
get "/500"
assert_response :internal_server_error
end
end
2 changes: 1 addition & 1 deletion test/controllers/pages_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

class PagesControllerTest < ActionDispatch::IntegrationTest
test "should get home" do
get pages_home_url
get root_path
assert_response :success
end
end
8 changes: 0 additions & 8 deletions test/controllers/payments_controller_test.rb

This file was deleted.

2 changes: 1 addition & 1 deletion test/controllers/themes_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

class ThemesControllerTest < ActionDispatch::IntegrationTest
test "should get index" do
get themes_index_url
get theme_path("violet")
assert_response :success
end
end
6 changes: 6 additions & 0 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,9 @@ class ActiveSupport::TestCase

# Add more helper methods to be used by all tests here...
end

class ActionDispatch::IntegrationTest
setup do
host! "example.com"
end
end

0 comments on commit fc09293

Please sign in to comment.