diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 69677f6..c084b8b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -2,22 +2,26 @@ name: CI on: pull_request: push: - branches: - - master + branches: [master] + +permissions: + contents: read + pages: write + id-token: write + jobs: test: - name: Tests with Ruby ${{ matrix.ruby }} Rails ${{ matrix.rails }} Active Admin ${{ matrix.activeadmin }} + name: Ruby ${{ matrix.ruby }} / Rails ${{ matrix.rails }} / AA ${{ matrix.activeadmin }} runs-on: ubuntu-latest strategy: + fail-fast: false matrix: - ruby: - - '3.2.0' - - '3.3.0' - rails: - - '7.1.0' - - '7.2.0' - activeadmin: - - '3.3.0' + ruby: ['3.2', '3.3', '3.4'] + rails: ['7.1.0', '7.2.0', '8.0.0'] + activeadmin: ['3.2.0', '3.3.0', '3.4.0', '3.5.0'] + exclude: + - rails: '8.0.0' + activeadmin: '3.2.0' env: RAILS: ${{ matrix.rails }} AA: ${{ matrix.activeadmin }} @@ -26,8 +30,58 @@ jobs: - uses: ruby/setup-ruby@v1 with: ruby-version: ${{ matrix.ruby }} + bundler-cache: true - name: Run tests + run: bundle exec rspec spec + + - name: Generate badge.json + if: matrix.ruby == '3.4' && matrix.rails == '8.0.0' && matrix.activeadmin == '3.5.0' run: | - gem install bundler -v '< 2' - bundle install - bundle exec rspec spec + LAST_RUN="coverage/.last_run.json" + if [ ! -f "$LAST_RUN" ]; then + mkdir -p badge + echo '{"schemaVersion":1,"label":"coverage","message":"unknown","color":"lightgrey"}' > badge/badge.json + exit 0 + fi + PERCENT=$(ruby -rjson -e "puts JSON.parse(File.read('$LAST_RUN')).dig('result','line').round(1)") + PERCENT_NUM=$(ruby -rjson -e "puts JSON.parse(File.read('$LAST_RUN')).dig('result','line')") + if ruby -e "exit(($PERCENT_NUM >= 90) ? 0 : 1)"; then COLOR="brightgreen" + elif ruby -e "exit(($PERCENT_NUM >= 75) ? 0 : 1)"; then COLOR="green" + elif ruby -e "exit(($PERCENT_NUM >= 60) ? 0 : 1)"; then COLOR="yellow" + else COLOR="red"; fi + mkdir -p badge + echo "{\"schemaVersion\":1,\"label\":\"coverage\",\"message\":\"${PERCENT}%\",\"color\":\"${COLOR}\"}" > badge/badge.json + + - name: Upload badge artifact + if: matrix.ruby == '3.4' && matrix.rails == '8.0.0' && matrix.activeadmin == '3.5.0' + uses: actions/upload-artifact@v4 + with: + name: coverage-badge + path: badge + + deploy-coverage: + needs: test + if: github.ref == 'refs/heads/master' && github.event_name == 'push' + runs-on: ubuntu-latest + environment: + name: github-pages + url: ${{ steps.deployment.outputs.page_url }} + + steps: + - name: Download coverage badge + uses: actions/download-artifact@v4 + with: + name: coverage-badge + path: coverage + + - name: Setup Pages + uses: actions/configure-pages@v5 + + - name: Upload Pages artifact + uses: actions/upload-pages-artifact@v3 + with: + path: coverage + + - name: Deploy to GitHub Pages + id: deployment + uses: actions/deploy-pages@v4 diff --git a/Gemfile b/Gemfile index 01c54cf..a54dcbc 100644 --- a/Gemfile +++ b/Gemfile @@ -1,24 +1,21 @@ source 'https://rubygems.org' - gemspec -group :test do - default_rails_version = '7.1.0' - default_activeadmin_version = '3.2.0' +default_rails_version = '7.1.0' +default_activeadmin_version = '3.5.0' - gem 'rails', "~> #{ENV['RAILS'] || default_rails_version}" - gem 'activeadmin', "~> #{ENV['AA'] || default_activeadmin_version}" +gem 'rails', "~> #{ENV['RAILS'] || default_rails_version}" +gem 'activeadmin', "~> #{ENV['AA'] || default_activeadmin_version}" +gem 'sprockets-rails' +gem 'sass-rails' - gem 'sprockets-rails' +group :test do + gem 'simplecov', require: false gem 'rspec-rails' - gem 'coveralls_reborn', require: false - gem 'sass-rails' - gem 'sqlite3', '~> 1.4.0' - gem 'launchy' + gem 'sqlite3', '~> 2.0' gem 'database_cleaner' gem 'capybara' - gem 'webdrivers' - gem 'byebug' + gem 'cuprite' gem 'draper' gem 'webrick', require: false end diff --git a/README.md b/README.md index 1facfb2..22bc15e 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,5 @@ [![Build Status](https://github.com/activeadmin-plugins/active_admin_scoped_collection_actions/actions/workflows/ci.yml/badge.svg)](https://github.com/activeadmin-plugins/active_admin_scoped_collection_actions/actions/workflows/ci.yml) +![Coverage](https://img.shields.io/endpoint?url=https://activeadmin-plugins.github.io/active_admin_scoped_collection_actions/badge.json) # ActiveAdmin Scoped Collection Actions diff --git a/active_admin_scoped_collection_actions.gemspec b/active_admin_scoped_collection_actions.gemspec index a7a785b..3101124 100644 --- a/active_admin_scoped_collection_actions.gemspec +++ b/active_admin_scoped_collection_actions.gemspec @@ -12,10 +12,12 @@ Gem::Specification.new do |spec| spec.homepage = "https://github.com/activeadmin-plugins/active_admin_scoped_collection_actions" spec.license = "MIT" + spec.required_ruby_version = '>= 3.1.0' + spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) } spec.bindir = "exe" spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) } spec.require_paths = ["lib"] - spec.add_dependency "activeadmin", ">= 1.1", "< 4.0" + spec.add_dependency "activeadmin", ">= 3.0", "< 4.0" end diff --git a/lib/active_admin_scoped_collection_actions/version.rb b/lib/active_admin_scoped_collection_actions/version.rb index 3d83a1a..bf65707 100644 --- a/lib/active_admin_scoped_collection_actions/version.rb +++ b/lib/active_admin_scoped_collection_actions/version.rb @@ -1,3 +1,3 @@ module ActiveAdminScopedCollectionActions - VERSION = '1.0.1'.freeze + VERSION = '2.0.0'.freeze end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 64e4eea..1e1713d 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,3 +1,8 @@ +require 'simplecov' +SimpleCov.start do + add_filter '/spec/' +end + $LOAD_PATH.unshift(File.dirname(__FILE__)) $LOAD_PATH << File.expand_path('../support', __FILE__) @@ -29,8 +34,6 @@ require 'rspec/rails' require 'capybara/rails' require 'capybara/rspec' -require 'selenium-webdriver' - require 'support/admin' require 'support/capybara' @@ -38,6 +41,7 @@ config.use_transactional_fixtures = false config.before(:suite) do + ActiveRecord::Migration.maintain_test_schema! DatabaseCleaner.strategy = :truncation DatabaseCleaner.clean_with(:truncation) end diff --git a/spec/support/capybara.rb b/spec/support/capybara.rb index 9e644a4..e09d7e9 100644 --- a/spec/support/capybara.rb +++ b/spec/support/capybara.rb @@ -1,16 +1,8 @@ -Capybara.server = :webrick - -Capybara.configure do |config| - config.match = :prefer_exact -end +require 'capybara/cuprite' -Webdrivers::Chromedriver.update - -Capybara.register_driver :selenium_chrome do |app| - options = Selenium::WebDriver::Chrome::Options.new( - args: %w[headless disable-gpu no-sandbox] - ) - Capybara::Selenium::Driver.new(app, browser: :chrome, options: options) +Capybara.server = :webrick +Capybara.register_driver :cuprite do |app| + Capybara::Cuprite::Driver.new(app, headless: true, window_size: [1280, 800]) end - -Capybara.javascript_driver = :selenium_chrome +Capybara.javascript_driver = :cuprite +Capybara.default_max_wait_time = 5 diff --git a/spec/support/rails_template.rb b/spec/support/rails_template.rb index ecaa23e..02fe183 100644 --- a/spec/support/rails_template.rb +++ b/spec/support/rails_template.rb @@ -1,7 +1,11 @@ # Rails template to build the sample app for specs -generate :model, 'author name:string{10}:uniq last_name:string birthday:date' -generate :model, 'post title:string:uniq body:text author:references' +# Ensure Sprockets manifest exists (Rails 8.0+ no longer generates it) +FileUtils.mkdir_p("app/assets/config") +File.write("app/assets/config/manifest.js", "//= link_tree ../images\n") + +generate :model, 'author name:string{10}:uniq last_name:string birthday:date --force' +generate :model, 'post title:string:uniq body:text author:references --force' #Add validation inject_into_file "app/models/author.rb", " validates_presence_of :name\n validates_uniqueness_of :last_name\n", after: "ApplicationRecord\n" @@ -23,15 +27,10 @@ " end\n", after: "ApplicationRecord\n" -# Configure default_url_options in test environment -inject_into_file "config/environments/test.rb", " config.action_mailer.default_url_options = { :host => 'example.com' }\n", after: "config.cache_classes = true\n" - -# Add our local Active Admin to the load path -inject_into_file "config/environment.rb", - "\n$LOAD_PATH.unshift('#{File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'lib'))}')\nrequire \"active_admin\"\n", - after: "require File.expand_path('../application', __FILE__)" - -run "rm Gemfile" +# Add our local Active Admin to the load path (Rails 7.1+) +gsub_file "config/environment.rb", + 'require_relative "application"', + "require_relative \"application\"\n$LOAD_PATH.unshift('#{File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'lib'))}')\nrequire \"active_admin\"\n" $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib')) @@ -39,24 +38,18 @@ generate :'formtastic:install' generate :'decorator Author' -# Install active_admin_date_time_datetimepicker assets +# Install active_admin_scoped_collection_actions assets inject_into_file "app/assets/stylesheets/active_admin.scss", "@import \"active_admin_scoped_collection_actions\";\n", after: "@import \"active_admin/base\";\n" -if File.file?("app/assets/javascripts/active_admin.js.coffee") - inject_into_file "app/assets/javascripts/active_admin.js.coffee", - "#= require active_admin_scoped_collection_actions\n", - after: "#= require active_admin/base\n" -else - inject_into_file "app/assets/javascripts/active_admin.js", - "//= require active_admin_scoped_collection_actions\n", - after: "//= require active_admin/base\n" -end - -run "rm -r test" -run "rm -r spec" +inject_into_file "app/assets/javascripts/active_admin.js", + "//= require active_admin_scoped_collection_actions\n", + after: "//= require active_admin/base\n" +run "rm -rf test" route "root :to => 'admin/dashboard#index'" - rake "db:migrate" + +# Remove Gemfile last so rake/route/generate work during template +run "rm -f Gemfile Gemfile.lock" diff --git a/vendor/assets/javascripts/lib/dialog_mass_fields_update.js b/vendor/assets/javascripts/lib/dialog_mass_fields_update.js index 53fcbda..9f28e80 100644 --- a/vendor/assets/javascripts/lib/dialog_mass_fields_update.js +++ b/vendor/assets/javascripts/lib/dialog_mass_fields_update.js @@ -47,6 +47,7 @@ ActiveAdmin.dialogMassFieldsUpdate = function(message, inputs, callback){ return form.dialog({ modal: true, + classes: { 'ui-dialog': 'ui-corner-all active_admin_dialog active_admin_dialog_mass_update_by_filter' }, dialogClass: 'active_admin_dialog active_admin_dialog_mass_update_by_filter', maxHeight: window.innerHeight - (window.innerHeight * 0.1), open() {