diff --git a/.github/workflows/pipeline.yml b/.github/workflows/pipeline.yml index ee5ab9f..9dcfc14 100644 --- a/.github/workflows/pipeline.yml +++ b/.github/workflows/pipeline.yml @@ -4,10 +4,8 @@ jobs: check: runs-on: ubuntu-latest steps: - - name: Checkout code - uses: actions/checkout@v3 - - name: Install Ruby/Gems - uses: ruby/setup-ruby@v1 + - uses: actions/checkout@v4 + - uses: ruby/setup-ruby@v1 with: bundler-cache: true - name: Run code checks @@ -19,7 +17,7 @@ jobs: fail-fast: false matrix: ruby: [2.7.5, 3.0.6, 3.1.4, 3.2.2] - rails: [6.0.6, 6.1.7, 7.0.4] + rails: [6.0.6, 6.1.7, 7.0.4, 7.1.3] exclude: - ruby: 3.1.4 rails: 6.0.6 @@ -29,12 +27,10 @@ jobs: RAILS_VERSION: ${{ matrix.rails }} CUSTOM_RUBY_VERSION: ${{ matrix.ruby }} steps: - - name: Checkout code - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Remove `Gemfile.lock` because this is a matrix job run: rm Gemfile.lock - - name: Install Ruby/Gems - uses: ruby/setup-ruby@v1 + - uses: ruby/setup-ruby@v1 with: ruby-version: ${{ matrix.ruby }} bundler-cache: true @@ -44,7 +40,7 @@ jobs: run: BACKTRACE=1 bin/rails test - name: Check if coverage LCOV file exists id: lcov_exists - uses: andstor/file-existence-action@v2 + uses: andstor/file-existence-action@v3 with: files: coverage/lcov.info - name: Submit coverage to `coveralls.io` if LCOV file exists @@ -57,23 +53,42 @@ jobs: runs-on: ubuntu-latest if: github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/') steps: - - name: Trigger render.com deploy hook - run: curl -X POST '${{ secrets.RENDER_COM_DEPLOY_HOOK }}' + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + fetch-tags: true + - uses: webfactory/ssh-agent@v0.9.0 + with: + ssh-private-key: ${{ secrets.APPSERVER_DEPLOY_SSH_KEY }} + - name: Setup appserver known_hosts + run: cat config/appserver.known_hosts >> ~/.ssh/known_hosts + - name: Set up Docker Buildx for cache + uses: docker/setup-buildx-action@v3 + - name: Expose GitHub Runtime for cache + uses: crazy-max/ghaction-github-runtime@v3 + - uses: ruby/setup-ruby@v1 + with: + bundler-cache: true + - name: Build and deploy using Kamal + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: bundle exec kamal deploy release: needs: test runs-on: ubuntu-latest if: startsWith(github.ref, 'refs/tags/') steps: - - name: Checkout code - uses: actions/checkout@v3 - - name: Ensure latest tag is fetched - run: git fetch --unshallow --prune --tags --force - - name: Install Ruby/Gems - uses: ruby/setup-ruby@v1 + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + fetch-tags: true + - uses: ruby/setup-ruby@v1 with: bundler-cache: true - name: Build the gem run: gem build rest_framework.gemspec -o rest_framework.gem + - name: Display VERSION + run: cat VERSION - name: Push to RubyGems env: GEM_HOST_API_KEY: ${{ secrets.RUBYGEMS_API_KEY }} diff --git a/.rails-version b/.rails-version index 4489f5a..1996c50 100644 --- a/.rails-version +++ b/.rails-version @@ -1 +1 @@ -7.0.4 +7.1.3 diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..ad4c36f --- /dev/null +++ b/Dockerfile @@ -0,0 +1,31 @@ +FROM ruby:3.2.2-bookworm as base +LABEL org.opencontainers.image.source=https://github.com/gregschmit/rails-rest-framework +WORKDIR /app +ENV BUNDLE_PATH="/usr/local/bundle" +ENV RAILS_ENV="production" +ENV DISABLE_DATABASE_ENVIRONMENT_CHECK="1" + +# Throw-away build stage to reduce size of final image +FROM base as build + +# Setup application gems. +COPY .ruby-version .rails-version rest_framework.gemspec Gemfile Gemfile.lock ./ +RUN bundle install + +# Setup application. +COPY . . +RUN bin/rails runner "RESTFramework::Version.stamp_version" +RUN bin/rails db:reset +RUN LOGS=all bin/rails log:clear tmp:clear +RUN rm -rf ~/.bundle "${BUNDLE_PATH}"/ruby/*/cache "${BUNDLE_PATH}"/ruby/*/bundler/gems/*/.git +RUN rm -rf .git + +# Final stage for app image. +FROM base + +# Copy built artifacts: gems, application. +COPY --from=build /usr/local/bundle /usr/local/bundle +COPY --from=build /app /app + +EXPOSE 3000 +CMD ["bin/rails", "server"] diff --git a/Gemfile b/Gemfile index 553a358..060b80c 100644 --- a/Gemfile +++ b/Gemfile @@ -16,20 +16,18 @@ RAILS_VERSION = Gem::Version.new( gem "rails", "~> #{RAILS_VERSION}" gem "rake" gem "sqlite3" +gem "puma" -# Only include ransack for Rails >=7. +# Only Rails >=7.1 gems. if RAILS_VERSION >= Gem::Version.new("7") + gem "kamal" gem "ransack", ">= 4.0" -end - -# Ruby 3 removed webrick, so we need to install it manually. -if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("3") - gem "webrick" + gem "solid_queue" end # Include `active_model_serializers` for custom integration (Rails >=6 only). if RAILS_VERSION >= Gem::Version.new("6") - gem "active_model_serializers", "0.10.13" + gem "active_model_serializers", "0.10.14" end # Include `translate_enum` for custom integration. @@ -47,6 +45,12 @@ elsif ENV["ASSET_PIPELINE"] == "propshaft" gem "propshaft" end +if ENV["ASSET_PIPELINE"] + # Requires an asset pipeline. Originally to schedule a periodic data wipe for demo data, however + # that would require the worker to restart which is not currently possible in Ruby. + # gem "mission_control-jobs" +end + gem "kramdown" gem "kramdown-parser-gfm" @@ -55,6 +59,7 @@ group :development do gem "better_errors", "2.9.1" # Avoid `sassc` dependency. gem "binding_of_caller" gem "byebug" + gem "foreman" gem "pry-rails" gem "rubocop-shopify", require: false gem "web-console" @@ -70,6 +75,6 @@ end group :test do gem "minitest" - gem "simplecov" + gem "simplecov", require: false gem "simplecov-lcov", "0.8.0", require: false end diff --git a/Gemfile.lock b/Gemfile.lock index 292c0bf..b533e08 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -7,117 +7,153 @@ PATH GEM remote: https://rubygems.org/ specs: - actioncable (7.0.7) - actionpack (= 7.0.7) - activesupport (= 7.0.7) + actioncable (7.1.3.2) + actionpack (= 7.1.3.2) + activesupport (= 7.1.3.2) nio4r (~> 2.0) websocket-driver (>= 0.6.1) - actionmailbox (7.0.7) - actionpack (= 7.0.7) - activejob (= 7.0.7) - activerecord (= 7.0.7) - activestorage (= 7.0.7) - activesupport (= 7.0.7) + zeitwerk (~> 2.6) + actionmailbox (7.1.3.2) + actionpack (= 7.1.3.2) + activejob (= 7.1.3.2) + activerecord (= 7.1.3.2) + activestorage (= 7.1.3.2) + activesupport (= 7.1.3.2) mail (>= 2.7.1) net-imap net-pop net-smtp - actionmailer (7.0.7) - actionpack (= 7.0.7) - actionview (= 7.0.7) - activejob (= 7.0.7) - activesupport (= 7.0.7) + actionmailer (7.1.3.2) + actionpack (= 7.1.3.2) + actionview (= 7.1.3.2) + activejob (= 7.1.3.2) + activesupport (= 7.1.3.2) mail (~> 2.5, >= 2.5.4) net-imap net-pop net-smtp - rails-dom-testing (~> 2.0) - actionpack (7.0.7) - actionview (= 7.0.7) - activesupport (= 7.0.7) - rack (~> 2.0, >= 2.2.4) + rails-dom-testing (~> 2.2) + actionpack (7.1.3.2) + actionview (= 7.1.3.2) + activesupport (= 7.1.3.2) + nokogiri (>= 1.8.5) + racc + rack (>= 2.2.4) + rack-session (>= 1.0.1) rack-test (>= 0.6.3) - rails-dom-testing (~> 2.0) - rails-html-sanitizer (~> 1.0, >= 1.2.0) - actiontext (7.0.7) - actionpack (= 7.0.7) - activerecord (= 7.0.7) - activestorage (= 7.0.7) - activesupport (= 7.0.7) + rails-dom-testing (~> 2.2) + rails-html-sanitizer (~> 1.6) + actiontext (7.1.3.2) + actionpack (= 7.1.3.2) + activerecord (= 7.1.3.2) + activestorage (= 7.1.3.2) + activesupport (= 7.1.3.2) globalid (>= 0.6.0) nokogiri (>= 1.8.5) - actionview (7.0.7) - activesupport (= 7.0.7) + actionview (7.1.3.2) + activesupport (= 7.1.3.2) builder (~> 3.1) - erubi (~> 1.4) - rails-dom-testing (~> 2.0) - rails-html-sanitizer (~> 1.1, >= 1.2.0) - active_model_serializers (0.10.13) - actionpack (>= 4.1, < 7.1) - activemodel (>= 4.1, < 7.1) + erubi (~> 1.11) + rails-dom-testing (~> 2.2) + rails-html-sanitizer (~> 1.6) + active_model_serializers (0.10.14) + actionpack (>= 4.1) + activemodel (>= 4.1) case_transform (>= 0.2) jsonapi-renderer (>= 0.1.1.beta1, < 0.3) - activejob (7.0.7) - activesupport (= 7.0.7) + activejob (7.1.3.2) + activesupport (= 7.1.3.2) globalid (>= 0.3.6) - activemodel (7.0.7) - activesupport (= 7.0.7) - activerecord (7.0.7) - activemodel (= 7.0.7) - activesupport (= 7.0.7) - activestorage (7.0.7) - actionpack (= 7.0.7) - activejob (= 7.0.7) - activerecord (= 7.0.7) - activesupport (= 7.0.7) + activemodel (7.1.3.2) + activesupport (= 7.1.3.2) + activerecord (7.1.3.2) + activemodel (= 7.1.3.2) + activesupport (= 7.1.3.2) + timeout (>= 0.4.0) + activestorage (7.1.3.2) + actionpack (= 7.1.3.2) + activejob (= 7.1.3.2) + activerecord (= 7.1.3.2) + activesupport (= 7.1.3.2) marcel (~> 1.0) - mini_mime (>= 1.1.0) - activesupport (7.0.7) + activesupport (7.1.3.2) + base64 + bigdecimal concurrent-ruby (~> 1.0, >= 1.0.2) + connection_pool (>= 2.2.5) + drb i18n (>= 1.6, < 2) minitest (>= 5.1) + mutex_m tzinfo (~> 2.0) annotate (3.2.0) activerecord (>= 3.2, < 8.0) rake (>= 10.4, < 14.0) ast (2.4.2) - base64 (0.1.1) + base64 (0.2.0) + bcrypt_pbkdf (1.1.0) better_errors (2.9.1) coderay (>= 1.0.0) erubi (>= 1.0.0) rack (>= 0.9.0) + bigdecimal (3.1.7) bindex (0.8.1) - binding_of_caller (1.0.0) - debug_inspector (>= 0.0.1) + binding_of_caller (1.0.1) + debug_inspector (>= 1.2.0) builder (3.2.4) - bullet (7.0.7) + bullet (7.1.6) activesupport (>= 3.0.0) uniform_notifier (~> 1.11) byebug (11.1.3) case_transform (0.2) activesupport coderay (1.1.3) - concurrent-ruby (1.2.2) + concurrent-ruby (1.2.3) + connection_pool (2.4.1) crass (1.0.6) - date (3.3.3) - debug_inspector (1.1.0) + date (3.3.4) + debug_inspector (1.2.0) docile (1.4.0) + dotenv (2.8.1) + drb (2.2.1) + ed25519 (1.3.0) erubi (1.12.0) - globalid (1.1.0) - activesupport (>= 5.0) + et-orbi (1.2.9) + tzinfo + foreman (0.87.2) + fugit (1.9.0) + et-orbi (~> 1, >= 1.2.7) + raabro (~> 1.4) + globalid (1.2.1) + activesupport (>= 6.1) httparty (0.21.0) mini_mime (>= 1.0.0) multi_xml (>= 0.5.2) - i18n (1.14.1) + i18n (1.14.4) concurrent-ruby (~> 1.0) - json (2.6.3) + io-console (0.7.2) + irb (1.12.0) + rdoc + reline (>= 0.4.2) + json (2.7.1) jsonapi-renderer (0.2.2) + kamal (1.3.1) + activesupport (>= 7.0) + base64 (~> 0.2) + bcrypt_pbkdf (~> 1.0) + concurrent-ruby (~> 1.2) + dotenv (~> 2.8) + ed25519 (~> 1.2) + net-ssh (~> 7.0) + sshkit (~> 1.21) + thor (~> 1.2) + zeitwerk (~> 2.5) kramdown (2.4.0) rexml kramdown-parser-gfm (1.1.0) kramdown (~> 2.0) language_server-protocol (3.17.0.3) - loofah (2.21.3) + loofah (2.22.0) crass (~> 1.0.2) nokogiri (>= 1.12.0) mail (2.8.1) @@ -125,27 +161,33 @@ GEM net-imap net-pop net-smtp - marcel (1.0.2) + marcel (1.0.4) method_source (1.0.0) mini_mime (1.1.5) - minitest (5.19.0) + minitest (5.22.3) multi_xml (0.6.0) - net-imap (0.3.7) + mutex_m (0.2.0) + net-imap (0.4.10) date net-protocol net-pop (0.1.2) net-protocol - net-protocol (0.2.1) + net-protocol (0.2.2) timeout - net-smtp (0.3.3) + net-scp (4.0.0) + net-ssh (>= 2.6.5, < 8.0.0) + net-sftp (4.0.0) + net-ssh (>= 5.0.0, < 8.0.0) + net-smtp (0.4.0.1) net-protocol - nio4r (2.5.9) - nokogiri (1.15.4-x86_64-darwin) + net-ssh (7.2.1) + nio4r (2.7.1) + nokogiri (1.16.3-x86_64-darwin) racc (~> 1.4) - nokogiri (1.15.4-x86_64-linux) + nokogiri (1.16.3-x86_64-linux) racc (~> 1.4) - parallel (1.23.0) - parser (3.2.2.3) + parallel (1.24.0) + parser (3.3.0.5) ast (~> 2.4.1) racc pry (0.14.2) @@ -153,26 +195,36 @@ GEM method_source (~> 1.0) pry-rails (0.3.9) pry (>= 0.10.4) - racc (1.7.1) - rack (2.2.8) - rack-mini-profiler (3.1.1) + psych (5.1.2) + stringio + puma (6.4.2) + nio4r (~> 2.0) + raabro (1.4.0) + racc (1.7.3) + rack (2.2.9) + rack-mini-profiler (3.3.1) rack (>= 1.2.0) + rack-session (1.0.2) + rack (< 3) rack-test (2.1.0) rack (>= 1.3) - rails (7.0.7) - actioncable (= 7.0.7) - actionmailbox (= 7.0.7) - actionmailer (= 7.0.7) - actionpack (= 7.0.7) - actiontext (= 7.0.7) - actionview (= 7.0.7) - activejob (= 7.0.7) - activemodel (= 7.0.7) - activerecord (= 7.0.7) - activestorage (= 7.0.7) - activesupport (= 7.0.7) + rackup (1.0.0) + rack (< 3) + webrick + rails (7.1.3.2) + actioncable (= 7.1.3.2) + actionmailbox (= 7.1.3.2) + actionmailer (= 7.1.3.2) + actionpack (= 7.1.3.2) + actiontext (= 7.1.3.2) + actionview (= 7.1.3.2) + activejob (= 7.1.3.2) + activemodel (= 7.1.3.2) + activerecord (= 7.1.3.2) + activestorage (= 7.1.3.2) + activesupport (= 7.1.3.2) bundler (>= 1.15.0) - railties (= 7.0.7) + railties (= 7.1.3.2) rails-dom-testing (2.2.0) activesupport (>= 5.0.0) minitest @@ -180,36 +232,40 @@ GEM rails-html-sanitizer (1.6.0) loofah (~> 2.21) nokogiri (~> 1.14) - railties (7.0.7) - actionpack (= 7.0.7) - activesupport (= 7.0.7) - method_source + railties (7.1.3.2) + actionpack (= 7.1.3.2) + activesupport (= 7.1.3.2) + irb + rackup (>= 1.0.0) rake (>= 12.2) - thor (~> 1.0) - zeitwerk (~> 2.5) + thor (~> 1.0, >= 1.2.2) + zeitwerk (~> 2.6) rainbow (3.1.1) - rake (13.0.6) - ransack (4.0.0) + rake (13.1.0) + ransack (4.1.1) activerecord (>= 6.1.5) activesupport (>= 6.1.5) i18n - regexp_parser (2.8.1) + rdoc (6.6.3.1) + psych (>= 4.0.0) + regexp_parser (2.9.0) + reline (0.4.3) + io-console (~> 0.5) rexml (3.2.6) - rubocop (1.56.0) - base64 (~> 0.1.1) + rubocop (1.62.1) json (~> 2.3) language_server-protocol (>= 3.17.0) parallel (~> 1.10) - parser (>= 3.2.2.3) + parser (>= 3.3.0.2) rainbow (>= 2.2.2, < 4.0) regexp_parser (>= 1.8, < 3.0) rexml (>= 3.2.5, < 4.0) - rubocop-ast (>= 1.28.1, < 2.0) + rubocop-ast (>= 1.31.1, < 2.0) ruby-progressbar (~> 1.7) unicode-display_width (>= 2.4.0, < 3.0) - rubocop-ast (1.29.0) - parser (>= 3.2.1.0) - rubocop-shopify (2.14.0) + rubocop-ast (1.31.2) + parser (>= 3.3.0.4) + rubocop-shopify (2.15.1) rubocop (~> 1.51) ruby-progressbar (1.13.0) simplecov (0.22.0) @@ -219,18 +275,30 @@ GEM simplecov-html (0.12.3) simplecov-lcov (0.8.0) simplecov_json_formatter (0.1.4) - sqlite3 (1.6.3-x86_64-darwin) - sqlite3 (1.6.3-x86_64-linux) - stackprof (0.2.25) - thor (1.2.2) - timeout (0.4.0) + solid_queue (0.3.0) + activejob (>= 7.1) + activerecord (>= 7.1) + concurrent-ruby (~> 1.2.2) + fugit (~> 1.9.0) + railties (>= 7.1) + sqlite3 (1.7.3-x86_64-darwin) + sqlite3 (1.7.3-x86_64-linux) + sshkit (1.22.0) + mutex_m + net-scp (>= 1.1.2) + net-sftp (>= 2.1.2) + net-ssh (>= 2.8.0) + stackprof (0.2.26) + stringio (3.1.0) + thor (1.3.1) + timeout (0.4.1) translate_enum (0.2.0) activesupport tzinfo (2.0.6) concurrent-ruby (~> 1.0) - unicode-display_width (2.4.2) + unicode-display_width (2.5.0) uniform_notifier (1.16.0) - web-console (4.2.0) + web-console (4.2.1) actionview (>= 6.0.0) activemodel (>= 6.0.0) bindex (>= 0.4.0) @@ -239,37 +307,41 @@ GEM websocket-driver (0.7.6) websocket-extensions (>= 0.1.0) websocket-extensions (0.1.5) - zeitwerk (2.6.11) + zeitwerk (2.6.13) PLATFORMS x86_64-darwin-22 + x86_64-darwin-23 x86_64-linux DEPENDENCIES - active_model_serializers (= 0.10.13) + active_model_serializers (= 0.10.14) annotate better_errors (= 2.9.1) binding_of_caller bullet byebug + foreman httparty + kamal kramdown kramdown-parser-gfm minitest pry-rails + puma rack-mini-profiler - rails (~> 7.0.4) + rails (~> 7.1.3) rake ransack (>= 4.0) rest_framework! rubocop-shopify simplecov simplecov-lcov (= 0.8.0) + solid_queue sqlite3 stackprof translate_enum web-console - webrick RUBY VERSION ruby 3.2.2p53 diff --git a/Procfile b/Procfile new file mode 100644 index 0000000..06b82b0 --- /dev/null +++ b/Procfile @@ -0,0 +1,4 @@ +# For development environment only. +rails: bin/rails server -p 3000 --no-log-to-stdout +worker: bin/rails solid_queue:start +log: tail -f test/log/development.log diff --git a/bin/setup b/bin/setup index 8c9b8d2..6dbdb9e 100755 --- a/bin/setup +++ b/bin/setup @@ -8,27 +8,15 @@ def system!(*args) system(*args) || abort("\n== Command #{args} failed ==") end -PRODUCTION = ENV["RAILS_ENV"] == "production" - FileUtils.chdir(File.expand_path("..", __dir__)) do puts "== Installing Ruby dependencies ==" system!("bundle install") puts "\n== Preparing database ==" - if PRODUCTION - system!("RAILS_ENV=production bin/rails db:reset") - else - system!("bin/rails db:reset") - end + system!("bin/rails db:reset") - unless PRODUCTION - puts "\n== Removing old logs and tempfiles ==" - system!("bin/rails log:clear tmp:clear") - end + puts "\n== Removing old logs and tempfiles ==" + system!("bin/rails log:clear tmp:clear") - if PRODUCTION - puts "\n\nšŸš€ Ready to go! šŸš€\n" - else - puts "\n\nšŸš€ Run the test application with: `rails s`. šŸš€\n" - end + puts "\n\nšŸš€ Ready! Run the test application with: `rails s`. šŸš€\n" end diff --git a/config/appserver.known_hosts b/config/appserver.known_hosts new file mode 100644 index 0000000..37a6090 --- /dev/null +++ b/config/appserver.known_hosts @@ -0,0 +1,5 @@ +appserver.schmit.net ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIB17PQQeC0fzQ2yUqxKwpIx1/YiYso1Ze+55spIxujQD +appserver.schmit.net ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBM4jU4VVk2KLzrp3/hvCr8xkYbL4AVBXDB+xEhYQO3z58iwlKakpdf5c9iFa7UyT9Ijskr3W7UbJ5zNmoV1BA3o= +home.schmit.net ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIKkf+2E5+bPjCqLXL71/CTCMAmzE4xUz2WxwOobCkNNe +home.schmit.net ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCvSOElIr37cKmZ4EpyrWRTW78G2pfQ0aJpcHxADoi0C42FTM0ME6C1vSsViZdjm7skNqwjASHn4aSBwFZ3uuvAnw46m/CsdwH8iqFiHjuQEccoub6ZZn9H0k3iPAoGXsLRMmorqLRmgCCpVjtdyqGs22iPgZxq5Nwi1qc0LuzZ4ppkSHtf3l+XzHUf49fHO1MrXtYGinpxe9EJ5EGA+2VSq7zss1AGgrJEsxd/yvsEmy5vRiXFoYyCD/bRKAfiBVxju0GHlLmS5m0HgMlcx8MuXgyW4UE2aRVoAyqrONssmChM9Ik4mdHAwHVsP6V2LKWWCSZo7v+C2kmPvFy2fbvh +home.schmit.net ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBCjU/H4fwiAuBh/wI0mHK5ZiGFmdU9YUfDixTh7bfs+al00V7akuqtpdzbSPFOIGmlSelXGCgbd24N5NXz6g8/U= diff --git a/config/deploy.yml b/config/deploy.yml new file mode 100644 index 0000000..e25be55 --- /dev/null +++ b/config/deploy.yml @@ -0,0 +1,25 @@ +service: rails-rest-framework + +image: ghcr.io/gregschmit/rails-rest-framework +labels: + org.opencontainers.image.source: https://github.com/gregschmit/rails-rest-framework +builder: + multiarch: false + +servers: + web: + - appserver.schmit.net + worker: + hosts: + - appserver.schmit.net + cmd: bin/rails solid_queue:start + +ssh: + user: deploy + proxy: "appserver@home.schmit.net" + +registry: + server: ghcr.io + username: gregschmit + password: + - GITHUB_TOKEN diff --git a/lib/rest_framework/utils.rb b/lib/rest_framework/utils.rb index b6a159b..00f8c00 100644 --- a/lib/rest_framework/utils.rb +++ b/lib/rest_framework/utils.rb @@ -99,12 +99,10 @@ def self.get_routes(application_routes, request, current_route: nil) return route_props, application_routes.routes.select { |r| # We `select` first to avoid unnecessarily calculating metadata for routes we don't even want # to show. - ( - (r.defaults[:subdomain].blank? || r.defaults[:subdomain] == request.subdomain) && + (r.defaults[:subdomain].blank? || r.defaults[:subdomain] == request.subdomain) && current_comparable_path.match?(self.comparable_path(r.path.spec.to_s)) && r.defaults[:controller].present? && r.defaults[:action].present? - ) }.map { |r| path = r.path.spec.to_s.gsub("(.:format)", "") levels = path.count("/") diff --git a/rest_framework.gemspec b/rest_framework.gemspec index 7a91dd5..9853da8 100644 --- a/rest_framework.gemspec +++ b/rest_framework.gemspec @@ -1,11 +1,18 @@ -require_relative "lib/rest_framework/version" +rrf_version = ENV["RRF_OVERRIDE_VERSION"] -# Stamp version before packaging. -RESTFramework::Version.stamp_version +unless rrf_version + require_relative "lib/rest_framework/version" + + # Stamp version before packaging. + RESTFramework::Version.stamp_version + + # Use the stamped version. + rrf_version = RESTFramework::VERSION +end Gem::Specification.new do |spec| spec.name = "rest_framework" - spec.version = ENV["RRF_OVERRIDE_VERSION"] || RESTFramework::VERSION + spec.version = rrf_version spec.authors = ["Gregory N. Schmit"] spec.email = ["schmitgreg@gmail.com"] diff --git a/test/.gitignore b/test/.gitignore index ab4c6d4..d2ddddd 100644 --- a/test/.gitignore +++ b/test/.gitignore @@ -1,3 +1,5 @@ +/db/*.sqlite3* + # Created by https://www.toptal.com/developers/gitignore/api/rails # Edit at https://www.toptal.com/developers/gitignore?templates=rails diff --git a/test/app/controllers/jobs_controller.rb b/test/app/controllers/jobs_controller.rb new file mode 100644 index 0000000..a313c08 --- /dev/null +++ b/test/app/controllers/jobs_controller.rb @@ -0,0 +1,11 @@ +class JobsController < ApplicationController + around_action :skip_bullet, if: -> { defined?(Bullet) } + + def skip_bullet + previous_value = Bullet.enable? + Bullet.enable = false + yield + ensure + Bullet.enable = previous_value + end +end diff --git a/test/app/jobs/application_job.rb b/test/app/jobs/application_job.rb new file mode 100644 index 0000000..a009ace --- /dev/null +++ b/test/app/jobs/application_job.rb @@ -0,0 +1,2 @@ +class ApplicationJob < ActiveJob::Base +end diff --git a/test/app/jobs/test_job.rb b/test/app/jobs/test_job.rb new file mode 100644 index 0000000..76e3fdc --- /dev/null +++ b/test/app/jobs/test_job.rb @@ -0,0 +1,5 @@ +class TestJob < ApplicationJob + def perform(*args) + Rails.logger.info("šŸ”„šŸ”„šŸ”„ Test job was called: #{args.inspect} šŸ”„šŸ”„šŸ”„") + end +end diff --git a/test/app/models/marble.rb b/test/app/models/marble.rb index 511df23..c89678e 100644 --- a/test/app/models/marble.rb +++ b/test/app/models/marble.rb @@ -21,7 +21,7 @@ # user_id (user_id => users.id) ON DELETE => cascade # class Marble < ApplicationRecord - belongs_to :user + belongs_to :user, optional: true has_one_attached :picture diff --git a/test/app/models/movie.rb b/test/app/models/movie.rb index cdadc1f..fe4afe4 100644 --- a/test/app/models/movie.rb +++ b/test/app/models/movie.rb @@ -19,7 +19,7 @@ # main_genre_id (main_genre_id => genres.id) ON DELETE => nullify # class Movie < ApplicationRecord - belongs_to :main_genre, class_name: "Genre" + belongs_to :main_genre, optional: true, class_name: "Genre" has_and_belongs_to_many :genres has_and_belongs_to_many :users diff --git a/test/bin/rails b/test/bin/rails index efc0377..55d5216 100755 --- a/test/bin/rails +++ b/test/bin/rails @@ -1,4 +1,5 @@ #!/usr/bin/env ruby + APP_PATH = File.expand_path("../config/application", __dir__) require_relative "../config/boot" require "rails/commands" diff --git a/test/config/application.rb b/test/config/application.rb index 31a9115..7a0623b 100644 --- a/test/config/application.rb +++ b/test/config/application.rb @@ -1,35 +1,39 @@ require_relative "boot" require "uri" -# Rather than `require 'rails/all'`, only require things we absolutely need. -require "rails" -[ - "active_record/railtie", - "active_storage/engine", - "action_controller/railtie", - "action_view/railtie", - "active_job/railtie", - "action_text/engine", - "rails/test_unit/railtie", -].each do |railtie| - require railtie -end +require "rails/all" # Require `sprockets` if testing asset pipeline. if ENV["ASSET_PIPELINE"] == "sprockets" require "sprockets/railtie" end +# Patch for Ransack (fixes `undefined method 'table_name' for #= 7 + config.load_defaults(7.0) + end + config.hosts = nil config.autoloader = :zeitwerk config.eager_load = false - config.action_dispatch.show_exceptions = !Rails.env.test? + if Rails::VERSION::MAJOR >= 7 && Rails::VERSION::MINOR >= 1 + config.action_dispatch.show_exceptions = Rails.env.test? ? :none : :all + else + config.action_dispatch.show_exceptions = !Rails.env.test? + end + config.consider_all_requests_local = !Rails.env.production? config.serve_static_files = true @@ -38,7 +42,7 @@ class Application < Rails::Application config.active_storage.service = :local - config.session_store(:cookie_store, key: "_session") + config.session_store(:cookie_store, key: "rrf_session") config.secret_token = "a_test_token" config.secret_key_base = "a_test_secret" @@ -52,6 +56,14 @@ class Application < Rails::Application end end + if defined?(MissionControl) + config.mission_control.jobs.base_controller_class = "JobsController" + end + + if defined?(SolidQueue) + config.active_job.queue_adapter = :solid_queue + end + RESTFramework.config.freeze_config = true # Use vendored assets if testing `sprockets` or `propshaft`. @@ -59,7 +71,7 @@ class Application < Rails::Application RESTFramework.config.use_vendored_assets = true end - if Rails::VERSION::MAJOR >= 7 + if Rails::VERSION::MAJOR >= 7 && Rails::VERSION::MINOR < 1 config.active_record.legacy_connection_handling = false config.active_support.remove_deprecated_time_with_zone_name = true end diff --git a/test/config/boot.rb b/test/config/boot.rb index 335b288..000ac98 100644 --- a/test/config/boot.rb +++ b/test/config/boot.rb @@ -1,3 +1,9 @@ # Set up gems listed in the Gemfile. ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", __dir__) require "bundler/setup" + +# Starting at Rails 7.1, we had to start requiring simplecov here to ensure it was loaded prior to +# the lib/application code. +if ARGV[0] == "test" + require_relative "simplecov_setup" +end diff --git a/test/config/database.yml b/test/config/database.yml index 70bd320..52293db 100644 --- a/test/config/database.yml +++ b/test/config/database.yml @@ -1,6 +1,6 @@ default: &sqlite adapter: sqlite3 - pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %> + pool: <%= ENV.fetch("RAILS_MAX_THREADS", 10) %> timeout: 5000 development: diff --git a/test/config/puma.rb b/test/config/puma.rb new file mode 100644 index 0000000..57abd2e --- /dev/null +++ b/test/config/puma.rb @@ -0,0 +1,21 @@ +# Check for best practices at: https://github.com/rails/rails, file: +# `railties/lib/rails/generators/rails/app/templates/config/puma.rb.tt`. +threads_count = ENV.fetch("RAILS_MAX_THREADS", 3) +threads threads_count, threads_count + +rails_env = ENV.fetch("RAILS_ENV", "development") +environment rails_env + +case rails_env +when "production" + workers_count = Integer(ENV.fetch("WEB_CONCURRENCY", 1)) + workers(workers_count) if workers_count > 1 + + preload_app! +when "development" + worker_timeout(3600) +end + +port ENV.fetch("PORT", 3000) +plugin :tmp_restart +pidfile ENV["PIDFILE"] if ENV["PIDFILE"] diff --git a/test/config/routes.rb b/test/config/routes.rb index 2da104e..c3e472b 100644 --- a/test/config/routes.rb +++ b/test/config/routes.rb @@ -1,6 +1,12 @@ Rails.application.routes.draw do root to: "home#index" + get "up" => "rails/health#show", as: :rails_health_check + + if defined?(MissionControl) + mount MissionControl::Jobs::Engine, at: "/jobs" + end + get "guide", to: "home#guide_first", format: false get "guide/:section", to: "home#show_guide_section", as: :show_guide_section, format: false get( diff --git a/test/config/simplecov_setup.rb b/test/config/simplecov_setup.rb new file mode 100644 index 0000000..57b34d7 --- /dev/null +++ b/test/config/simplecov_setup.rb @@ -0,0 +1,42 @@ +require "simplecov" + +# Initialize Coveralls only for main test and when in CI pipeline. +IS_MAIN_RUBY = File.read(File.expand_path("../../.ruby-version", __dir__)).strip.match?( + RUBY_VERSION, +) +IS_MAIN_RAILS = ENV["RAILS_VERSION"]&.match?( + File.read(File.expand_path("../../.rails-version", __dir__)).strip, +) +if IS_COVERALLS = IS_MAIN_RUBY && IS_MAIN_RAILS && ENV["CI"] + puts("Configuring SimpleCov output for submission to `coveralls.io`.") +else + puts("Configuring SimpleCov output for HTML viewing.") +end + +# Configure SimpleCov. +SimpleCov.start do + minimum_coverage 10 + + # The `rest_framework` project directory should be the root for coverage purposes. + root ".." + + # Filter out everything but the lib directory. + add_filter "app/" + add_filter "bin/" + add_filter "docs/" + add_filter "test/" + + # Setup formatter for submission to `coveralls.io` if configured, otherwise use an HTML formatter. + if IS_COVERALLS + require "simplecov-lcov" + + SimpleCov::Formatter::LcovFormatter.config do |c| + c.report_with_single_file = true + c.single_report_path = "../coverage/lcov.info" + end + + formatter SimpleCov::Formatter::LcovFormatter + else + formatter SimpleCov::Formatter::HTMLFormatter + end +end diff --git a/test/config/solid_queue.yml b/test/config/solid_queue.yml new file mode 100644 index 0000000..8eff4dd --- /dev/null +++ b/test/config/solid_queue.yml @@ -0,0 +1,18 @@ +default: &default + dispatchers: + - polling_interval: 1 + batch_size: 500 + workers: + - queues: "*" + threads: 5 + processes: 1 + polling_interval: 0.1 + +development: + <<: *default + +test: + <<: *default + +production: + <<: *default diff --git a/test/db/migrate/20240321180851_create_solid_queue_tables.solid_queue.rb b/test/db/migrate/20240321180851_create_solid_queue_tables.solid_queue.rb new file mode 100644 index 0000000..af7c705 --- /dev/null +++ b/test/db/migrate/20240321180851_create_solid_queue_tables.solid_queue.rb @@ -0,0 +1,129 @@ +# This migration comes from solid_queue (originally 20231211200639) +class CreateSolidQueueTables < ActiveRecord::Migration[6.0] + def change + create_table(:solid_queue_jobs) do |t| + t.string(:queue_name, null: false) + t.string(:class_name, null: false, index: true) + t.text(:arguments) + t.integer(:priority, default: 0, null: false) + t.string(:active_job_id, index: true) + t.datetime(:scheduled_at) + t.datetime(:finished_at, index: true) + t.string(:concurrency_key) + + t.timestamps + + t.index([:queue_name, :finished_at], name: "index_solid_queue_jobs_for_filtering") + t.index([:scheduled_at, :finished_at], name: "index_solid_queue_jobs_for_alerting") + end + + create_table(:solid_queue_scheduled_executions) do |t| + t.references(:job, index: {unique: true}, null: false) + t.string(:queue_name, null: false) + t.integer(:priority, default: 0, null: false) + t.datetime(:scheduled_at, null: false) + + t.datetime(:created_at, null: false) + + t.index([:scheduled_at, :priority, :job_id], name: "index_solid_queue_dispatch_all") + end + + create_table(:solid_queue_ready_executions) do |t| + t.references(:job, index: {unique: true}, null: false) + t.string(:queue_name, null: false) + t.integer(:priority, default: 0, null: false) + + t.datetime(:created_at, null: false) + + t.index([:priority, :job_id], name: "index_solid_queue_poll_all") + t.index([:queue_name, :priority, :job_id], name: "index_solid_queue_poll_by_queue") + end + + create_table(:solid_queue_claimed_executions) do |t| + t.references(:job, index: {unique: true}, null: false) + t.bigint(:process_id) + t.datetime(:created_at, null: false) + + t.index([:process_id, :job_id]) + end + + create_table(:solid_queue_blocked_executions) do |t| + t.references(:job, index: {unique: true}, null: false) + t.string(:queue_name, null: false) + t.integer(:priority, default: 0, null: false) + t.string(:concurrency_key, null: false) + t.datetime(:expires_at, null: false) + + t.datetime(:created_at, null: false) + + t.index( + [:expires_at, :concurrency_key], + name: "index_solid_queue_blocked_executions_for_maintenance", + ) + end + + create_table(:solid_queue_failed_executions) do |t| + t.references(:job, index: {unique: true}, null: false) + t.text(:error) + t.datetime(:created_at, null: false) + end + + create_table(:solid_queue_pauses) do |t| + t.string(:queue_name, null: false, index: {unique: true}) + t.datetime(:created_at, null: false) + end + + create_table(:solid_queue_processes) do |t| + t.string(:kind, null: false) + t.datetime(:last_heartbeat_at, null: false, index: true) + t.bigint(:supervisor_id, index: true) + + t.integer(:pid, null: false) + t.string(:hostname) + t.text(:metadata) + + t.datetime(:created_at, null: false) + end + + create_table(:solid_queue_semaphores) do |t| + t.string(:key, null: false, index: {unique: true}) + t.integer(:value, default: 1, null: false) + t.datetime(:expires_at, null: false, index: true) + + t.timestamps + + t.index([:key, :value], name: "index_solid_queue_semaphores_on_key_and_value") + end + + add_foreign_key( + :solid_queue_blocked_executions, + :solid_queue_jobs, + column: :job_id, + on_delete: :cascade, + ) + add_foreign_key( + :solid_queue_claimed_executions, + :solid_queue_jobs, + column: :job_id, + on_delete: :cascade, + ) + add_foreign_key( + :solid_queue_failed_executions, + :solid_queue_jobs, + column: :job_id, + on_delete: :cascade, + ) + add_foreign_key( + :solid_queue_ready_executions, + :solid_queue_jobs, + column: :job_id, + on_delete: :cascade, + ) + add_foreign_key( + :solid_queue_scheduled_executions, + :solid_queue_jobs, + column: :job_id, + on_delete: :cascade, + ) + end +end diff --git a/test/db/migrate/20240321180852_add_missing_index_to_blocked_executions.solid_queue.rb b/test/db/migrate/20240321180852_add_missing_index_to_blocked_executions.solid_queue.rb new file mode 100644 index 0000000..ddfb72b --- /dev/null +++ b/test/db/migrate/20240321180852_add_missing_index_to_blocked_executions.solid_queue.rb @@ -0,0 +1,10 @@ +# This migration comes from solid_queue (originally 20240110143450) +class AddMissingIndexToBlockedExecutions < ActiveRecord::Migration[6.0] + def change + add_index( + :solid_queue_blocked_executions, + [:concurrency_key, :priority, :job_id], + name: "index_solid_queue_blocked_executions_for_release", + ) + end +end diff --git a/test/db/migrate/20240321180853_create_recurring_executions.solid_queue.rb b/test/db/migrate/20240321180853_create_recurring_executions.solid_queue.rb new file mode 100644 index 0000000..1604d7c --- /dev/null +++ b/test/db/migrate/20240321180853_create_recurring_executions.solid_queue.rb @@ -0,0 +1,20 @@ +# This migration comes from solid_queue (originally 20240218110712) +class CreateRecurringExecutions < ActiveRecord::Migration[6.0] + def change + create_table(:solid_queue_recurring_executions) do |t| + t.references(:job, index: {unique: true}, null: false) + t.string(:task_key, null: false) + t.datetime(:run_at, null: false) + t.datetime(:created_at, null: false) + + t.index([:task_key, :run_at], unique: true) + end + + add_foreign_key( + :solid_queue_recurring_executions, + :solid_queue_jobs, + column: :job_id, + on_delete: :cascade, + ) + end +end diff --git a/test/db/migrate/20230115233930_test_app_tables.rb b/test/db/migrate/20240321190000_test_app_tables.rb similarity index 100% rename from test/db/migrate/20230115233930_test_app_tables.rb rename to test/db/migrate/20240321190000_test_app_tables.rb diff --git a/test/db/schema.rb b/test/db/schema.rb index 3da0509..1b16d5f 100644 --- a/test/db/schema.rb +++ b/test/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.0].define(version: 2023_01_15_233930) do +ActiveRecord::Schema[7.1].define(version: 2024_03_21_190000) do create_table "action_text_rich_texts", force: :cascade do |t| t.string "name", null: false t.text "body" @@ -104,6 +104,109 @@ t.index ["user_id"], name: "index_phone_numbers_on_user_id", unique: true end + create_table "solid_queue_blocked_executions", force: :cascade do |t| + t.integer "job_id", null: false + t.string "queue_name", null: false + t.integer "priority", default: 0, null: false + t.string "concurrency_key", null: false + t.datetime "expires_at", precision: nil, null: false + t.datetime "created_at", precision: nil, null: false + t.index ["concurrency_key", "priority", "job_id"], name: "index_solid_queue_blocked_executions_for_release" + t.index ["expires_at", "concurrency_key"], name: "index_solid_queue_blocked_executions_for_maintenance" + t.index ["job_id"], name: "index_solid_queue_blocked_executions_on_job_id", unique: true + end + + create_table "solid_queue_claimed_executions", force: :cascade do |t| + t.integer "job_id", null: false + t.bigint "process_id" + t.datetime "created_at", precision: nil, null: false + t.index ["job_id"], name: "index_solid_queue_claimed_executions_on_job_id", unique: true + t.index ["process_id", "job_id"], name: "index_solid_queue_claimed_executions_on_process_id_and_job_id" + end + + create_table "solid_queue_failed_executions", force: :cascade do |t| + t.integer "job_id", null: false + t.text "error" + t.datetime "created_at", precision: nil, null: false + t.index ["job_id"], name: "index_solid_queue_failed_executions_on_job_id", unique: true + end + + create_table "solid_queue_jobs", force: :cascade do |t| + t.string "queue_name", null: false + t.string "class_name", null: false + t.text "arguments" + t.integer "priority", default: 0, null: false + t.string "active_job_id" + t.datetime "scheduled_at", precision: nil + t.datetime "finished_at", precision: nil + t.string "concurrency_key" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.index ["active_job_id"], name: "index_solid_queue_jobs_on_active_job_id" + t.index ["class_name"], name: "index_solid_queue_jobs_on_class_name" + t.index ["finished_at"], name: "index_solid_queue_jobs_on_finished_at" + t.index ["queue_name", "finished_at"], name: "index_solid_queue_jobs_for_filtering" + t.index ["scheduled_at", "finished_at"], name: "index_solid_queue_jobs_for_alerting" + end + + create_table "solid_queue_pauses", force: :cascade do |t| + t.string "queue_name", null: false + t.datetime "created_at", precision: nil, null: false + t.index ["queue_name"], name: "index_solid_queue_pauses_on_queue_name", unique: true + end + + create_table "solid_queue_processes", force: :cascade do |t| + t.string "kind", null: false + t.datetime "last_heartbeat_at", precision: nil, null: false + t.bigint "supervisor_id" + t.integer "pid", null: false + t.string "hostname" + t.text "metadata" + t.datetime "created_at", precision: nil, null: false + t.index ["last_heartbeat_at"], name: "index_solid_queue_processes_on_last_heartbeat_at" + t.index ["supervisor_id"], name: "index_solid_queue_processes_on_supervisor_id" + end + + create_table "solid_queue_ready_executions", force: :cascade do |t| + t.integer "job_id", null: false + t.string "queue_name", null: false + t.integer "priority", default: 0, null: false + t.datetime "created_at", precision: nil, null: false + t.index ["job_id"], name: "index_solid_queue_ready_executions_on_job_id", unique: true + t.index ["priority", "job_id"], name: "index_solid_queue_poll_all" + t.index ["queue_name", "priority", "job_id"], name: "index_solid_queue_poll_by_queue" + end + + create_table "solid_queue_recurring_executions", force: :cascade do |t| + t.integer "job_id", null: false + t.string "task_key", null: false + t.datetime "run_at", precision: nil, null: false + t.datetime "created_at", precision: nil, null: false + t.index ["job_id"], name: "index_solid_queue_recurring_executions_on_job_id", unique: true + t.index ["task_key", "run_at"], name: "index_solid_queue_recurring_executions_on_task_key_and_run_at", unique: true + end + + create_table "solid_queue_scheduled_executions", force: :cascade do |t| + t.integer "job_id", null: false + t.string "queue_name", null: false + t.integer "priority", default: 0, null: false + t.datetime "scheduled_at", precision: nil, null: false + t.datetime "created_at", precision: nil, null: false + t.index ["job_id"], name: "index_solid_queue_scheduled_executions_on_job_id", unique: true + t.index ["scheduled_at", "priority", "job_id"], name: "index_solid_queue_dispatch_all" + end + + create_table "solid_queue_semaphores", force: :cascade do |t| + t.string "key", null: false + t.integer "value", default: 1, null: false + t.datetime "expires_at", precision: nil, null: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.index ["expires_at"], name: "index_solid_queue_semaphores_on_expires_at" + t.index ["key", "value"], name: "index_solid_queue_semaphores_on_key_and_value" + t.index ["key"], name: "index_solid_queue_semaphores_on_key", unique: true + end + create_table "users", force: :cascade do |t| t.string "login", default: "", null: false t.boolean "is_admin", default: false @@ -130,6 +233,12 @@ add_foreign_key "movies_users", "movies", on_delete: :cascade add_foreign_key "movies_users", "users", on_delete: :cascade add_foreign_key "phone_numbers", "users", on_delete: :cascade + add_foreign_key "solid_queue_blocked_executions", "solid_queue_jobs", column: "job_id", on_delete: :cascade + add_foreign_key "solid_queue_claimed_executions", "solid_queue_jobs", column: "job_id", on_delete: :cascade + add_foreign_key "solid_queue_failed_executions", "solid_queue_jobs", column: "job_id", on_delete: :cascade + add_foreign_key "solid_queue_ready_executions", "solid_queue_jobs", column: "job_id", on_delete: :cascade + add_foreign_key "solid_queue_recurring_executions", "solid_queue_jobs", column: "job_id", on_delete: :cascade + add_foreign_key "solid_queue_scheduled_executions", "solid_queue_jobs", column: "job_id", on_delete: :cascade add_foreign_key "users", "emails", on_delete: :nullify add_foreign_key "users", "users", column: "manager_id", on_delete: :nullify end diff --git a/test/test/integration/rescuing_unknown_formats_test.rb b/test/test/integration/rescuing_unknown_formats_test.rb index eab9438..7cd8b49 100644 --- a/test/test/integration/rescuing_unknown_formats_test.rb +++ b/test/test/integration/rescuing_unknown_formats_test.rb @@ -21,6 +21,6 @@ def test_rescue_unknown_format assert_response(:success) resp2 = @response.body - assert_equal(resp1, resp2.gsub(/jsom/, "json")) + assert_equal(resp1, resp2.gsub("jsom", "json")) end end diff --git a/test/test/test_helper.rb b/test/test/test_helper.rb index 02fd90d..ed0ef51 100644 --- a/test/test/test_helper.rb +++ b/test/test/test_helper.rb @@ -1,47 +1,5 @@ ENV["RAILS_ENV"] ||= "test" -# Initialize SimpleCov before including application code. -require "simplecov" - -# Initialize Coveralls only for main test and when in CI pipeline. -IS_MAIN_RUBY = File.read(File.expand_path("../../.ruby-version", __dir__)).strip.match?( - RUBY_VERSION, -) -IS_MAIN_RAILS = ENV["RAILS_VERSION"]&.match?( - File.read(File.expand_path("../../.rails-version", __dir__)).strip, -) -if IS_COVERALLS = IS_MAIN_RUBY && IS_MAIN_RAILS && ENV["CI"] - puts("Configured to format coverage for submission to `coveralls.io`.") -end - -# Configure SimpleCov. -SimpleCov.start do - minimum_coverage 10 - - # The `rest_framework` project directory should be the root for coverage purposes. - root ".." - - # Filter out everything but the lib directory. - add_filter "app/" - add_filter "bin/" - add_filter "docs/" - add_filter "test/" - - # Setup formatter for submission to `coveralls.io` if configured, otherwise use an HTML formatter. - if IS_COVERALLS - require "simplecov-lcov" - - SimpleCov::Formatter::LcovFormatter.config do |c| - c.report_with_single_file = true - c.single_report_path = "../coverage/lcov.info" - end - - formatter SimpleCov::Formatter::LcovFormatter - else - formatter SimpleCov::Formatter::HTMLFormatter - end -end - require_relative "../config/environment" # TODO: Get working? Not working now.