diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 4ee68f3..40ba65a 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -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 diff --git a/.tool-versions b/.tool-versions new file mode 100644 index 0000000..02c5ae8 --- /dev/null +++ b/.tool-versions @@ -0,0 +1,2 @@ +ruby 3.3.0 +nodejs 20.10.0 diff --git a/Gemfile b/Gemfile index 7e81cd2..f0febd4 100644 --- a/Gemfile +++ b/Gemfile @@ -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 diff --git a/Gemfile.lock b/Gemfile.lock index 2181aa1..0c773d4 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -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) @@ -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) @@ -347,6 +351,7 @@ DEPENDENCIES phlex-rails phlex_ui postmark-rails + pry puma (~> 5.0) rack-www rails (~> 7.0.8) diff --git a/test/controllers/components_controller_test.rb b/test/controllers/components_controller_test.rb index b6816ee..148c581 100644 --- a/test/controllers/components_controller_test.rb +++ b/test/controllers/components_controller_test.rb @@ -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 diff --git a/test/controllers/errors_controller_test.rb b/test/controllers/errors_controller_test.rb index 4ca2df2..cb3250c 100644 --- a/test/controllers/errors_controller_test.rb +++ b/test/controllers/errors_controller_test.rb @@ -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 diff --git a/test/controllers/pages_controller_test.rb b/test/controllers/pages_controller_test.rb index 05728b4..aebf859 100644 --- a/test/controllers/pages_controller_test.rb +++ b/test/controllers/pages_controller_test.rb @@ -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 diff --git a/test/controllers/payments_controller_test.rb b/test/controllers/payments_controller_test.rb deleted file mode 100644 index c96d27f..0000000 --- a/test/controllers/payments_controller_test.rb +++ /dev/null @@ -1,8 +0,0 @@ -require "test_helper" - -class PaymentsControllerTest < ActionDispatch::IntegrationTest - test "should get confirmation" do - get payments_confirmation_url - assert_response :success - end -end diff --git a/test/controllers/themes_controller_test.rb b/test/controllers/themes_controller_test.rb index 9d34d64..3f23ed8 100644 --- a/test/controllers/themes_controller_test.rb +++ b/test/controllers/themes_controller_test.rb @@ -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 diff --git a/test/test_helper.rb b/test/test_helper.rb index d713e37..1f51904 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -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