From a82938808a51cad671037b245edeb2678b285444 Mon Sep 17 00:00:00 2001 From: fatkodima Date: Sat, 10 Aug 2024 14:22:25 +0300 Subject: [PATCH] Drop support for older activerecord and ruby versions --- .github/dependabot.yml | 6 - .github/workflows/test.yml | 10 +- .rubocop.yml | 4 - CHANGELOG.md | 2 + Gemfile | 17 +- Gemfile.lock | 186 +++++++++--------- README.md | 5 + data_checks.gemspec | 4 +- gemfiles/rails_42.gemfile | 17 -- gemfiles/rails_70.gemfile | 15 ++ lib/data_checks/check_run.rb | 2 +- lib/data_checks/ensure_equal.rb | 3 +- lib/data_checks/ensure_less.rb | 2 +- lib/data_checks/ensure_more.rb | 2 +- lib/data_checks/ensure_no.rb | 3 +- .../data_checks/install_generator.rb | 8 +- test/test_helper.rb | 18 +- 17 files changed, 146 insertions(+), 158 deletions(-) delete mode 100644 .github/dependabot.yml delete mode 100644 gemfiles/rails_42.gemfile create mode 100644 gemfiles/rails_70.gemfile diff --git a/.github/dependabot.yml b/.github/dependabot.yml deleted file mode 100644 index 5ace460..0000000 --- a/.github/dependabot.yml +++ /dev/null @@ -1,6 +0,0 @@ -version: 2 -updates: - - package-ecosystem: "github-actions" - directory: "/" - schedule: - interval: "weekly" diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 7192867..a9615be 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -10,7 +10,7 @@ jobs: - uses: actions/checkout@v4 - uses: ruby/setup-ruby@v1 with: - ruby-version: 3.2.0 + ruby-version: 3.3 bundler-cache: true - run: bundle exec rubocop @@ -20,11 +20,9 @@ jobs: strategy: matrix: include: - - ruby-version: 2.3.8 - gemfile: gemfiles/rails_42.gemfile - - ruby-version: 3.1.0 - gemfile: Gemfile - - ruby-version: 3.2.0 + - ruby-version: 3.0 + gemfile: gemfiles/rails_70.gemfile + - ruby-version: 3.3 gemfile: Gemfile env: BUNDLE_GEMFILE: ${{ github.workspace }}/${{ matrix.gemfile }} diff --git a/.rubocop.yml b/.rubocop.yml index a925d79..80824ce 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -37,10 +37,6 @@ Style/NumericPredicate: Style/Lambda: EnforcedStyle: literal -# only for ruby 2.6+ -Style/MapToHash: - Enabled: false - Style/FetchEnvVar: Enabled: false diff --git a/CHANGELOG.md b/CHANGELOG.md index 5044c9c..55d9bac 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ ## master (unreleased) +- Drop support for older activerecord and ruby versions + ## 0.2.0 (2023-11-09) - Add `ensure_equal` check method diff --git a/Gemfile b/Gemfile index 8673079..1e232e8 100644 --- a/Gemfile +++ b/Gemfile @@ -5,14 +5,13 @@ source "https://rubygems.org" # Specify your gem's dependencies in data_checks.gemspec gemspec -rails_version = "~> 7.1.0" -gem "actionmailer", rails_version -gem "activerecord", rails_version -gem "railties", rails_version # to test generator +gem "actionmailer" +gem "activerecord" +gem "railties" # to test generator -gem "rake", "~> 13.0" -gem "minitest", "~> 5.0" -gem "rubocop", "< 2" -gem "rubocop-minitest", "< 1" +gem "rake" +gem "minitest" +gem "rubocop" +gem "rubocop-minitest" gem "sqlite3" -gem "webmock", "~> 3.18" +gem "webmock" diff --git a/Gemfile.lock b/Gemfile.lock index 3620001..536b913 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -2,82 +2,83 @@ PATH remote: . specs: data_checks (0.2.0) - activerecord (>= 4.2) + activerecord (>= 7.0) GEM remote: https://rubygems.org/ specs: - actionmailer (7.1.1) - actionpack (= 7.1.1) - actionview (= 7.1.1) - activejob (= 7.1.1) - activesupport (= 7.1.1) - mail (~> 2.5, >= 2.5.4) - net-imap - net-pop - net-smtp + actionmailer (7.2.0) + actionpack (= 7.2.0) + actionview (= 7.2.0) + activejob (= 7.2.0) + activesupport (= 7.2.0) + mail (>= 2.8.0) rails-dom-testing (~> 2.2) - actionpack (7.1.1) - actionview (= 7.1.1) - activesupport (= 7.1.1) + actionpack (7.2.0) + actionview (= 7.2.0) + activesupport (= 7.2.0) nokogiri (>= 1.8.5) - rack (>= 2.2.4) + racc + rack (>= 2.2.4, < 3.2) rack-session (>= 1.0.1) rack-test (>= 0.6.3) rails-dom-testing (~> 2.2) rails-html-sanitizer (~> 1.6) - actionview (7.1.1) - activesupport (= 7.1.1) + useragent (~> 0.16) + actionview (7.2.0) + activesupport (= 7.2.0) builder (~> 3.1) erubi (~> 1.11) rails-dom-testing (~> 2.2) rails-html-sanitizer (~> 1.6) - activejob (7.1.1) - activesupport (= 7.1.1) + activejob (7.2.0) + activesupport (= 7.2.0) globalid (>= 0.3.6) - activemodel (7.1.1) - activesupport (= 7.1.1) - activerecord (7.1.1) - activemodel (= 7.1.1) - activesupport (= 7.1.1) + activemodel (7.2.0) + activesupport (= 7.2.0) + activerecord (7.2.0) + activemodel (= 7.2.0) + activesupport (= 7.2.0) timeout (>= 0.4.0) - activesupport (7.1.1) + activesupport (7.2.0) base64 bigdecimal - concurrent-ruby (~> 1.0, >= 1.0.2) + concurrent-ruby (~> 1.0, >= 1.3.1) connection_pool (>= 2.2.5) drb i18n (>= 1.6, < 2) + logger (>= 1.4.2) minitest (>= 5.1) - mutex_m - tzinfo (~> 2.0) - addressable (2.8.5) - public_suffix (>= 2.0.2, < 6.0) + securerandom (>= 0.3) + tzinfo (~> 2.0, >= 2.0.5) + addressable (2.8.7) + public_suffix (>= 2.0.2, < 7.0) ast (2.4.2) base64 (0.2.0) - bigdecimal (3.1.4) - builder (3.2.4) - concurrent-ruby (1.2.2) + bigdecimal (3.1.8) + builder (3.3.0) + concurrent-ruby (1.3.3) connection_pool (2.4.1) - crack (0.4.5) + crack (1.0.0) + bigdecimal rexml crass (1.0.6) date (3.3.4) - drb (2.2.0) - ruby2_keywords - erubi (1.12.0) + drb (2.2.1) + erubi (1.13.0) globalid (1.2.1) activesupport (>= 6.1) - hashdiff (1.0.1) - i18n (1.14.1) + hashdiff (1.1.1) + i18n (1.14.5) concurrent-ruby (~> 1.0) - io-console (0.6.0) - irb (1.8.3) - rdoc - reline (>= 0.3.8) - json (2.6.3) + io-console (0.7.2) + irb (1.14.0) + rdoc (>= 4.0.0) + reline (>= 0.4.2) + json (2.7.2) language_server-protocol (3.17.0.3) - loofah (2.21.4) + logger (1.6.0) + loofah (2.22.0) crass (~> 1.0.2) nokogiri (>= 1.12.0) mail (2.8.1) @@ -86,34 +87,33 @@ GEM net-pop net-smtp mini_mime (1.1.5) - mini_portile2 (2.8.5) - minitest (5.20.0) - mutex_m (0.2.0) - net-imap (0.4.4) + mini_portile2 (2.8.7) + minitest (5.24.1) + net-imap (0.4.14) date net-protocol net-pop (0.1.2) net-protocol net-protocol (0.2.2) timeout - net-smtp (0.4.0) + net-smtp (0.5.0) net-protocol - nokogiri (1.15.4) + nokogiri (1.16.7) mini_portile2 (~> 2.8.2) racc (~> 1.4) - nokogiri (1.15.4-x86_64-darwin) + nokogiri (1.16.7-x86_64-darwin) racc (~> 1.4) - nokogiri (1.15.4-x86_64-linux) + nokogiri (1.16.7-x86_64-linux) racc (~> 1.4) - parallel (1.23.0) - parser (3.2.2.4) + parallel (1.26.1) + parser (3.3.4.2) ast (~> 2.4.1) racc - psych (5.1.1.1) + psych (5.1.2) stringio - public_suffix (5.0.3) - racc (1.7.3) - rack (3.0.8) + public_suffix (6.0.1) + racc (1.8.1) + rack (3.1.7) rack-session (2.0.0) rack (>= 3.0.0) rack-test (2.1.0) @@ -128,55 +128,59 @@ GEM rails-html-sanitizer (1.6.0) loofah (~> 2.21) nokogiri (~> 1.14) - railties (7.1.1) - actionpack (= 7.1.1) - activesupport (= 7.1.1) - irb + railties (7.2.0) + actionpack (= 7.2.0) + activesupport (= 7.2.0) + irb (~> 1.13) rackup (>= 1.0.0) rake (>= 12.2) thor (~> 1.0, >= 1.2.2) zeitwerk (~> 2.6) rainbow (3.1.1) - rake (13.1.0) - rdoc (6.6.0) + rake (13.2.1) + rdoc (6.7.0) psych (>= 4.0.0) - regexp_parser (2.8.2) - reline (0.4.0) + regexp_parser (2.9.2) + reline (0.5.9) io-console (~> 0.5) - rexml (3.2.6) - rubocop (1.57.2) + rexml (3.3.4) + strscan + rubocop (1.65.1) json (~> 2.3) language_server-protocol (>= 3.17.0) parallel (~> 1.10) - parser (>= 3.2.2.4) + parser (>= 3.3.0.2) rainbow (>= 2.2.2, < 4.0) - regexp_parser (>= 1.8, < 3.0) + regexp_parser (>= 2.4, < 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.30.0) - parser (>= 3.2.1.0) - rubocop-minitest (0.33.0) - rubocop (>= 1.39, < 2.0) + rubocop-ast (1.32.0) + parser (>= 3.3.1.0) + rubocop-minitest (0.35.1) + rubocop (>= 1.61, < 2.0) + rubocop-ast (>= 1.31.1, < 2.0) ruby-progressbar (1.13.0) - ruby2_keywords (0.0.5) - sqlite3 (1.6.8) + securerandom (0.3.1) + sqlite3 (2.0.3) mini_portile2 (~> 2.8.0) - sqlite3 (1.6.8-x86_64-darwin) - sqlite3 (1.6.8-x86_64-linux) - stringio (3.0.9) - thor (1.3.0) + sqlite3 (2.0.3-x86_64-darwin) + sqlite3 (2.0.3-x86_64-linux-gnu) + stringio (3.1.1) + strscan (3.1.0) + thor (1.3.1) timeout (0.4.1) tzinfo (2.0.6) concurrent-ruby (~> 1.0) unicode-display_width (2.5.0) - webmock (3.19.1) + useragent (0.16.10) + webmock (3.23.1) addressable (>= 2.8.0) crack (>= 0.3.2) hashdiff (>= 0.4.0, < 2.0.0) webrick (1.8.1) - zeitwerk (2.6.12) + zeitwerk (2.6.17) PLATFORMS ruby @@ -184,16 +188,16 @@ PLATFORMS x86_64-linux DEPENDENCIES - actionmailer (~> 7.1.0) - activerecord (~> 7.1.0) + actionmailer + activerecord data_checks! - minitest (~> 5.0) - railties (~> 7.1.0) - rake (~> 13.0) - rubocop (< 2) - rubocop-minitest (< 1) + minitest + railties + rake + rubocop + rubocop-minitest sqlite3 - webmock (~> 3.18) + webmock BUNDLED WITH 2.4.21 diff --git a/README.md b/README.md index 7c8d812..46293d3 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,11 @@ This gem provides a small DSL to check your data for inconsistencies and anomali [![Build Status](https://github.com/fatkodima/data_checks/actions/workflows/test.yml/badge.svg?branch=master)](https://github.com/fatkodima/data_checks/actions/workflows/test.yml) +## Requirements + +- ruby 3.0+ +- activerecord 7.0+ + ## Installation Add this line to your application's Gemfile: diff --git a/data_checks.gemspec b/data_checks.gemspec index 9252d01..19b207d 100644 --- a/data_checks.gemspec +++ b/data_checks.gemspec @@ -11,7 +11,7 @@ Gem::Specification.new do |spec| spec.summary = "Regression testing for data" spec.homepage = "https://github.com/fatkodima/data_checks" spec.license = "MIT" - spec.required_ruby_version = ">= 2.3.0" + spec.required_ruby_version = ">= 3.0.0" spec.metadata["homepage_uri"] = spec.homepage spec.metadata["source_code_uri"] = spec.homepage @@ -20,5 +20,5 @@ Gem::Specification.new do |spec| spec.files = Dir["*.{md,txt}", "{lib}/**/*"] spec.require_paths = ["lib"] - spec.add_dependency "activerecord", ">= 4.2" + spec.add_dependency "activerecord", ">= 7.0" end diff --git a/gemfiles/rails_42.gemfile b/gemfiles/rails_42.gemfile deleted file mode 100644 index cedc8a4..0000000 --- a/gemfiles/rails_42.gemfile +++ /dev/null @@ -1,17 +0,0 @@ -# frozen_string_literal: true - -source "https://rubygems.org" - -# Specify your gem's dependencies in data_checks.gemspec -gemspec path: ".." - -gem "actionmailer", "~> 4.2.0" -gem "activerecord", "~> 4.2.0" -gem "railties", "~> 4.2.0" # to test generator -gem "rake", "~> 13.0" -gem "minitest", "~> 5.0" -gem "sqlite3", "~> 1.3.6" -gem "webmock", "~> 3.14" - -# Needs to explicitly downgrade - newer versions raise an error -gem "loofah", "2.2.3" diff --git a/gemfiles/rails_70.gemfile b/gemfiles/rails_70.gemfile new file mode 100644 index 0000000..7af4f05 --- /dev/null +++ b/gemfiles/rails_70.gemfile @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +source "https://rubygems.org" + +# Specify your gem's dependencies in data_checks.gemspec +gemspec path: ".." + +version = "~> 7.0.0" +gem "actionmailer", version +gem "activerecord", version +gem "railties", version # to test generator +gem "rake" +gem "minitest" +gem "sqlite3", "< 2" +gem "webmock" diff --git a/lib/data_checks/check_run.rb b/lib/data_checks/check_run.rb index 2b1760f..dfc3d90 100644 --- a/lib/data_checks/check_run.rb +++ b/lib/data_checks/check_run.rb @@ -5,7 +5,7 @@ class CheckRun < ActiveRecord::Base self.table_name = :data_checks_runs STATUSES = [:passing, :failing, :error] - enum status: STATUSES.map { |status| [status, status.to_s] }.to_h + enum :status, STATUSES.index_with(&:to_s) serialize :backtrace diff --git a/lib/data_checks/ensure_equal.rb b/lib/data_checks/ensure_equal.rb index c6ffc1c..9f44394 100644 --- a/lib/data_checks/ensure_equal.rb +++ b/lib/data_checks/ensure_equal.rb @@ -14,8 +14,7 @@ def handle_result(result) passing = false count = result end - # In ActiveRecord <= 4.2 ActiveRecord::Relation is not an Enumerable! - when Enumerable, ActiveRecord::Relation + when Enumerable count = result.size if count != expected passing = false diff --git a/lib/data_checks/ensure_less.rb b/lib/data_checks/ensure_less.rb index 76425b8..9c2e270 100644 --- a/lib/data_checks/ensure_less.rb +++ b/lib/data_checks/ensure_less.rb @@ -9,7 +9,7 @@ def handle_result(result) case result when Numeric count = result - when Enumerable, ActiveRecord::Relation + when Enumerable count = result.size else raise ArgumentError, "Unsupported result: '#{result.class.name}' for 'ensure_less'" diff --git a/lib/data_checks/ensure_more.rb b/lib/data_checks/ensure_more.rb index 7c0eda8..332cc09 100644 --- a/lib/data_checks/ensure_more.rb +++ b/lib/data_checks/ensure_more.rb @@ -9,7 +9,7 @@ def handle_result(result) case result when Numeric count = result - when Enumerable, ActiveRecord::Relation + when Enumerable count = result.size else raise ArgumentError, "Unsupported result: '#{result.class.name}' for 'ensure_more'" diff --git a/lib/data_checks/ensure_no.rb b/lib/data_checks/ensure_no.rb index 5ada9fb..5454116 100644 --- a/lib/data_checks/ensure_no.rb +++ b/lib/data_checks/ensure_no.rb @@ -13,8 +13,7 @@ def handle_result(result) passing = false count = result end - # In ActiveRecord <= 4.2 ActiveRecord::Relation is not an Enumerable! - when Enumerable, ActiveRecord::Relation + when Enumerable unless result.to_a.empty? # loads records for ActiveRecord::Relation passing = false count = result.size diff --git a/lib/generators/data_checks/install_generator.rb b/lib/generators/data_checks/install_generator.rb index 7617825..bcae0e5 100644 --- a/lib/generators/data_checks/install_generator.rb +++ b/lib/generators/data_checks/install_generator.rb @@ -10,7 +10,7 @@ class InstallGenerator < Rails::Generators::Base source_root File.expand_path("templates", __dir__) def create_migration_file - migration_template("migration.rb", File.join(migrations_dir, "install_data_checks.rb")) + migration_template("migration.rb", File.join(db_migrate_path, "install_data_checks.rb")) end def copy_initializer_file @@ -19,11 +19,7 @@ def copy_initializer_file private def start_after - self.class.next_migration_number(migrations_dir) - end - - def migrations_dir - ar_version >= 5.1 ? db_migrate_path : "db/migrate" + self.class.next_migration_number(db_migrate_path) end def ar_version diff --git a/test/test_helper.rb b/test/test_helper.rb index 593eb35..05d6672 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -74,16 +74,14 @@ def run_check(name) self.error_handler = ->(error, context) {} end -if defined?(Warning) - module TestRunWarningFilter - # Ignore warnings output from mail v2.8.1 gem. - def warn(message, category: nil, **kwargs) - if message =~ /gems\/mail-/ - # ignore - else - super - end +module TestRunWarningFilter + # Ignore warnings output from mail v2.8.1 gem. + def warn(message, category: nil, **kwargs) + if message =~ /gems\/mail-/ + # ignore + else + super end end - Warning.extend TestRunWarningFilter end +Warning.extend TestRunWarningFilter