From bae3fb31f7f8861c83564bfe649fb416e38762a1 Mon Sep 17 00:00:00 2001 From: Luciano Maiwald Date: Thu, 21 Mar 2024 09:24:49 +0100 Subject: [PATCH 1/5] Update version support: Rails >= 5.2, Ruby >= 2.7.8 Also introduce appraisal for multi-version testing --- .github/workflows/gempush.yml | 11 ++++-- .github/workflows/test.yml | 32 ------------------ .github/workflows/test_and_lint.yml | 52 +++++++++++++++++++++++++++++ .rubocop.yml | 6 ++-- .travis.yml | 11 ------ Appraisals | 11 ++++++ README.md | 2 +- ci | 7 ---- gemfiles/.gitignore | 1 + gemfiles/rails_5.2.gemfile | 7 ++++ gemfiles/rails_6.0.gemfile | 7 ++++ gemfiles/rails_6.1.gemfile | 7 ++++ github-actions-test.yml | 1 - permanent_records.gemspec | 16 ++++----- 14 files changed, 106 insertions(+), 65 deletions(-) delete mode 100644 .github/workflows/test.yml create mode 100644 .github/workflows/test_and_lint.yml delete mode 100644 .travis.yml create mode 100644 Appraisals delete mode 100755 ci create mode 100644 gemfiles/.gitignore create mode 100644 gemfiles/rails_5.2.gemfile create mode 100644 gemfiles/rails_6.0.gemfile create mode 100644 gemfiles/rails_6.1.gemfile delete mode 120000 github-actions-test.yml diff --git a/.github/workflows/gempush.yml b/.github/workflows/gempush.yml index 381a76e..031f174 100644 --- a/.github/workflows/gempush.yml +++ b/.github/workflows/gempush.yml @@ -12,10 +12,15 @@ jobs: steps: - uses: actions/checkout@master - - name: Set up Ruby 2.6 - uses: actions/setup-ruby@v1 + - name: Set up Ruby 2.7 + uses: ruby/setup-ruby@v1 with: - ruby-version: 2.6.x + ruby-version: 2.7.8 + + - name: Install bundle + run: bundle + - name: Run rubocop + run: bundle exec rubocop - name: Publish to RubyGems run: | diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml deleted file mode 100644 index 8a4b0f3..0000000 --- a/.github/workflows/test.yml +++ /dev/null @@ -1,32 +0,0 @@ -name: Tests - -on: push - -jobs: - ci: - name: CI - runs-on: ubuntu-latest - strategy: - matrix: - ruby: - - '2.3.x' - - '2.4.x' - - '2.5.x' - - '2.6.x' - rails: - - '5.0.7.2' - - '5.1.7' - - '5.2.3' - steps: - - name: Install system dependencies - run: sudo apt-get install -y libsqlite3-dev - - uses: actions/checkout@master - - name: Setup ruby - uses: actions/setup-ruby@v1 - with: - ruby-version: ${{ matrix.ruby }} - architecture: 'x64' - - run: gem install bundler && bundle && bundle exec rake - env: - AR_TEST_VERSION: ${{ matrix.rails }} - diff --git a/.github/workflows/test_and_lint.yml b/.github/workflows/test_and_lint.yml new file mode 100644 index 0000000..3d4a0bd --- /dev/null +++ b/.github/workflows/test_and_lint.yml @@ -0,0 +1,52 @@ +name: Lint & Test + +on: push + +jobs: + test: + name: Test + runs-on: ubuntu-latest + strategy: + matrix: + ruby: + - 2.7.8 + - 3.0.6 + - 3.1.4 + appraisal: + - rails-5.2 + - rails-6.0 + - rails-6.1 + exclude: + - ruby: 3.0.6 + appraisal: rails-5.2 + - ruby: 3.1.4 + appraisal: rails-5.2 + steps: + - name: Install system dependencies + run: sudo apt-get install -y libsqlite3-dev + - uses: actions/checkout@master + - name: Setup ruby + uses: ruby/setup-ruby@v1 + with: + ruby-version: ${{ matrix.ruby }} + - name: Install bundle + run: bundle + - name: Install appraisal + run: bundle exec appraisal install + - name: Run tests + run: bundle exec appraisal ${{ matrix.appraisal }} rspec + lint: + name: Lint + runs-on: ubuntu-latest + steps: + - name: Install system dependencies + run: sudo apt-get install -y libsqlite3-dev + - uses: actions/checkout@master + - name: Setup ruby + uses: ruby/setup-ruby@v1 + with: + ruby-version: 2.7.8 + - name: Install bundle + run: bundle + - name: Run rubocop + run: bundle exec rubocop diff --git a/.rubocop.yml b/.rubocop.yml index dcbc607..6fc946c 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -5,12 +5,14 @@ inherit_from: .rubocop_todo.yml AllCops: Exclude: - bin/* - TargetRubyVersion: 2.2 + - gemfiles/* + - vendor/bundle/**/* + TargetRubyVersion: 2.7 Metrics/BlockLength: Enabled: false -Metrics/LineLength: +Layout/LineLength: Max: 120 Style/BlockDelimiters: diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index b136eee..0000000 --- a/.travis.yml +++ /dev/null @@ -1,11 +0,0 @@ -language: ruby -rvm: - - 2.2.10 - - 2.3.8 - - 2.4.9 - - 2.5.7 - - 2.6.5 -env: - - AR_TEST_VERSION: 5.0.7.2 - - AR_TEST_VERSION: 5.1.7 - - AR_TEST_VERSION: 5.2.3 diff --git a/Appraisals b/Appraisals new file mode 100644 index 0000000..c20438c --- /dev/null +++ b/Appraisals @@ -0,0 +1,11 @@ +appraise 'rails-5.2' do + gem 'rails', '5.2.8.1' +end + +appraise 'rails-6.0' do + gem 'rails', '6.0.6.1' +end + +appraise 'rails-6.1' do + gem 'rails', '6.1.7.7' +end diff --git a/README.md b/README.md index 5f407c3..78b909f 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# PermanentRecords (Rails 5) +# PermanentRecords (Rails 5.2, 6.0, 6.1) [http://github.com/JackDanger/permanent_records/](http://github.com/JackDanger/permanent_records/) diff --git a/ci b/ci deleted file mode 100755 index 32db69a..0000000 --- a/ci +++ /dev/null @@ -1,7 +0,0 @@ -#!/bin/bash -for version in `grep AR_TEST_VERSION .travis.yml | awk '{print $3}'`; do - export AR_TEST_VERSION=$version - echo "Testing against ActiveRecord $version" - bundle - bundle exec rake -done diff --git a/gemfiles/.gitignore b/gemfiles/.gitignore new file mode 100644 index 0000000..71afd1c --- /dev/null +++ b/gemfiles/.gitignore @@ -0,0 +1 @@ +*.gemfile.lock diff --git a/gemfiles/rails_5.2.gemfile b/gemfiles/rails_5.2.gemfile new file mode 100644 index 0000000..5cf2d7a --- /dev/null +++ b/gemfiles/rails_5.2.gemfile @@ -0,0 +1,7 @@ +# This file was generated by Appraisal + +source "https://rubygems.org" + +gem "rails", "5.2.8.1" + +gemspec path: "../" diff --git a/gemfiles/rails_6.0.gemfile b/gemfiles/rails_6.0.gemfile new file mode 100644 index 0000000..e050d93 --- /dev/null +++ b/gemfiles/rails_6.0.gemfile @@ -0,0 +1,7 @@ +# This file was generated by Appraisal + +source "https://rubygems.org" + +gem "rails", "6.0.6.1" + +gemspec path: "../" diff --git a/gemfiles/rails_6.1.gemfile b/gemfiles/rails_6.1.gemfile new file mode 100644 index 0000000..5056f0c --- /dev/null +++ b/gemfiles/rails_6.1.gemfile @@ -0,0 +1,7 @@ +# This file was generated by Appraisal + +source "https://rubygems.org" + +gem "rails", "6.1.7.7" + +gemspec path: "../" diff --git a/github-actions-test.yml b/github-actions-test.yml deleted file mode 120000 index 576a5b4..0000000 --- a/github-actions-test.yml +++ /dev/null @@ -1 +0,0 @@ -.github/workflows/test.yml \ No newline at end of file diff --git a/permanent_records.gemspec b/permanent_records.gemspec index 5caada1..f88e65c 100644 --- a/permanent_records.gemspec +++ b/permanent_records.gemspec @@ -22,17 +22,17 @@ Gem::Specification.new do |s| s.homepage = 'https://github.com/JackDanger/permanent_records' s.require_paths = ['lib'] - # For testing against multiple AR versions - ver = ENV['AR_TEST_VERSION'] - ver = ver.dup.chomp if ver + s.required_ruby_version = '>= 2.7.8' - s.add_runtime_dependency 'activerecord', ver || '>= 5.0.0' - s.add_runtime_dependency 'activesupport', ver || '>= 5.0.0' + s.add_runtime_dependency 'activerecord', '>= 5.2' + s.add_runtime_dependency 'activesupport', '>= 5.2' + + s.add_development_dependency 'appraisal' s.add_development_dependency 'database_cleaner', '>= 1.5.1' s.add_development_dependency 'pry-byebug' - s.add_development_dependency 'rake' # For Travis-ci + s.add_development_dependency 'rake' s.add_development_dependency 'rspec', '>= 3.5.0' - s.add_development_dependency 'rubocop', '~> 0.68.0' # freeze to ensure ruby 2.2 compatibility + s.add_development_dependency 'rubocop' s.add_development_dependency 'rubocop-performance' - s.add_development_dependency 'sqlite3', '~> 1.3.13' # freeze to ensure specs are working + s.add_development_dependency 'sqlite3' end From 52a3e0ef690753a6cf28ecd227ad38f6b83891d8 Mon Sep 17 00:00:00 2001 From: Luciano Maiwald Date: Tue, 26 Mar 2024 10:39:27 +0100 Subject: [PATCH 2/5] Fix rubocop offenses --- .rubocop.yml | 5 +++++ .rubocop_todo.yml | 2 +- Appraisals | 2 ++ Gemfile | 11 ++++++++++ Rakefile | 2 ++ gemfiles/rails_5.2.gemfile | 8 ++++++++ gemfiles/rails_6.0.gemfile | 8 ++++++++ gemfiles/rails_6.1.gemfile | 8 ++++++++ lib/permanent_records.rb | 14 +++++++------ lib/permanent_records/active_record_5_2.rb | 2 ++ permanent_records.gemspec | 20 +++++-------------- .../circular_sti_dependency_spec.rb | 2 ++ spec/permanent_records/counter_cache_spec.rb | 2 ++ .../propagate_validation_flag_spec.rb | 2 ++ .../revive_parent_first_spec.rb | 2 ++ .../validate_presence_spec.rb | 2 ++ spec/permanent_records_spec.rb | 16 +++++++++------ spec/spec_helper.rb | 4 +++- spec/support/ant.rb | 2 ++ spec/support/bed.rb | 2 ++ spec/support/comment.rb | 2 ++ spec/support/difficulty.rb | 2 ++ spec/support/dirt.rb | 2 ++ spec/support/earthworm.rb | 2 ++ spec/support/hole.rb | 2 ++ spec/support/house.rb | 2 ++ spec/support/kitty.rb | 2 ++ spec/support/location.rb | 2 ++ spec/support/meerkat.rb | 2 ++ spec/support/mole.rb | 2 ++ spec/support/muskrat.rb | 2 ++ spec/support/room.rb | 2 ++ spec/support/schema.rb | 2 ++ spec/support/unused_model.rb | 2 ++ 34 files changed, 115 insertions(+), 29 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 6fc946c..94c7755 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -7,8 +7,13 @@ AllCops: - bin/* - gemfiles/* - vendor/bundle/**/* + NewCops: enable TargetRubyVersion: 2.7 +Gemspec/RequireMFA: + Exclude: + - 'permanent_records.gemspec' + Metrics/BlockLength: Enabled: false diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 5e87886..ac436f6 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,6 +1,6 @@ # This configuration was generated by # `rubocop --auto-gen-config` -# on 2019-10-15 13:32:11 +0200 using RuboCop version 0.68.1. +# on 2024-03-26 10:28:30 UTC using RuboCop version 1.62.1. # The point is for the user to remove these configuration records # one by one as the offenses are removed from the code base. # Note that changes in the inspected code, or installation of new diff --git a/Appraisals b/Appraisals index c20438c..cb851bb 100644 --- a/Appraisals +++ b/Appraisals @@ -1,3 +1,5 @@ +# frozen_string_literal: true + appraise 'rails-5.2' do gem 'rails', '5.2.8.1' end diff --git a/Gemfile b/Gemfile index fa75df1..ded0e1c 100644 --- a/Gemfile +++ b/Gemfile @@ -1,3 +1,14 @@ +# frozen_string_literal: true + source 'https://rubygems.org' gemspec + +gem 'appraisal' +gem 'database_cleaner', '>= 1.5.1' +gem 'pry-byebug' +gem 'rake' +gem 'rspec', '>= 3.5.0' +gem 'rubocop' +gem 'rubocop-performance' +gem 'sqlite3' diff --git a/Rakefile b/Rakefile index 362294e..b8b149d 100644 --- a/Rakefile +++ b/Rakefile @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'bundler' require 'yaml' require 'English' diff --git a/gemfiles/rails_5.2.gemfile b/gemfiles/rails_5.2.gemfile index 5cf2d7a..e79007c 100644 --- a/gemfiles/rails_5.2.gemfile +++ b/gemfiles/rails_5.2.gemfile @@ -2,6 +2,14 @@ source "https://rubygems.org" +gem "appraisal" +gem "database_cleaner", ">= 1.5.1" +gem "pry-byebug" +gem "rake" +gem "rspec", ">= 3.5.0" +gem "rubocop" +gem "rubocop-performance" +gem "sqlite3" gem "rails", "5.2.8.1" gemspec path: "../" diff --git a/gemfiles/rails_6.0.gemfile b/gemfiles/rails_6.0.gemfile index e050d93..2d10665 100644 --- a/gemfiles/rails_6.0.gemfile +++ b/gemfiles/rails_6.0.gemfile @@ -2,6 +2,14 @@ source "https://rubygems.org" +gem "appraisal" +gem "database_cleaner", ">= 1.5.1" +gem "pry-byebug" +gem "rake" +gem "rspec", ">= 3.5.0" +gem "rubocop" +gem "rubocop-performance" +gem "sqlite3" gem "rails", "6.0.6.1" gemspec path: "../" diff --git a/gemfiles/rails_6.1.gemfile b/gemfiles/rails_6.1.gemfile index 5056f0c..b6d3983 100644 --- a/gemfiles/rails_6.1.gemfile +++ b/gemfiles/rails_6.1.gemfile @@ -2,6 +2,14 @@ source "https://rubygems.org" +gem "appraisal" +gem "database_cleaner", ">= 1.5.1" +gem "pry-byebug" +gem "rake" +gem "rspec", ">= 3.5.0" +gem "rubocop" +gem "rubocop-performance" +gem "sqlite3" gem "rails", "6.1.7.7" gemspec path: "../" diff --git a/lib/permanent_records.rb b/lib/permanent_records.rb index 1898fcc..80cb510 100644 --- a/lib/permanent_records.rb +++ b/lib/permanent_records.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # PermanentRecords works with ActiveRecord to set deleted_at columns with a # timestamp reflecting when a record was 'deleted' instead of actually deleting # the record. All dependent records and associations are treated exactly as @@ -28,7 +30,7 @@ def is_permanent? # rubocop:disable Naming/PredicateName def deleted? if is_permanent? - !!deleted_at # rubocop:disable Style/DoubleNegation + !!deleted_at else destroyed? end @@ -97,7 +99,7 @@ def set_deleted_at(value, force = nil) record.save! end - @attributes = record.instance_variable_get('@attributes') + @attributes = record.instance_variable_get(:@attributes) rescue StandardError => e # trigger dependent record destruction (they were revived before this # record, which cannot be revived due to validations) @@ -141,8 +143,8 @@ def destroy_with_permanent_records(force = nil) def add_record_window(_request, name, reflection) send(name).unscope(where: :deleted_at).where( [ - "#{reflection.klass.quoted_table_name}.deleted_at > ?" \ - ' AND ' \ + "#{reflection.klass.quoted_table_name}.deleted_at > ? " \ + 'AND ' \ "#{reflection.klass.quoted_table_name}.deleted_at < ?", deleted_at - PermanentRecords.dependent_record_window, deleted_at + PermanentRecords.dependent_record_window @@ -177,7 +179,7 @@ def destroyed_dependent_relations def attempt_notifying_observers(callback) notify_observers(callback) - rescue NoMethodError # rubocop:disable Lint/HandleExceptions + rescue NoMethodError # do nothing: this model isn't being observed end @@ -279,7 +281,7 @@ def self.dependent_permanent_reflections(klass) end ActiveSupport.on_load(:active_record) do - ActiveRecord::Base.send(:include, PermanentRecords::ActiveRecord) + ActiveRecord::Base.include PermanentRecords::ActiveRecord if [ActiveRecord::VERSION::MAJOR, ActiveRecord::VERSION::MINOR] == [5, 2] || ActiveRecord::VERSION::MAJOR > 5 require 'permanent_records/active_record_5_2' diff --git a/lib/permanent_records/active_record_5_2.rb b/lib/permanent_records/active_record_5_2.rb index 911d17a..8f8db5c 100644 --- a/lib/permanent_records/active_record_5_2.rb +++ b/lib/permanent_records/active_record_5_2.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # rubocop:disable Metrics/AbcSize # Support destroy for rails belongs_to assocations. module HandlePermanentRecordsDestroyedInBelongsToAssociation diff --git a/permanent_records.gemspec b/permanent_records.gemspec index f88e65c..5d0f004 100644 --- a/permanent_records.gemspec +++ b/permanent_records.gemspec @@ -1,3 +1,5 @@ +# frozen_string_literal: true + Gem::Specification.new do |s| s.name = 'permanent_records' s.version = File.read('VERSION') @@ -12,10 +14,7 @@ Gem::Specification.new do |s| gives you all the scopes you need to work with your data. DESCRIPTION s.email = 'github@jackcanty.com' - s.extra_rdoc_files = [ - 'LICENSE', - 'README.md' - ] + s.extra_rdoc_files = %w[LICENSE README.md] s.files = `git ls-files -z`.split("\x0").reject do |f| f.match(%r{^(test|spec|features)/}) end @@ -24,15 +23,6 @@ Gem::Specification.new do |s| s.required_ruby_version = '>= 2.7.8' - s.add_runtime_dependency 'activerecord', '>= 5.2' - s.add_runtime_dependency 'activesupport', '>= 5.2' - - s.add_development_dependency 'appraisal' - s.add_development_dependency 'database_cleaner', '>= 1.5.1' - s.add_development_dependency 'pry-byebug' - s.add_development_dependency 'rake' - s.add_development_dependency 'rspec', '>= 3.5.0' - s.add_development_dependency 'rubocop' - s.add_development_dependency 'rubocop-performance' - s.add_development_dependency 'sqlite3' + s.add_runtime_dependency 'activerecord', ['>= 5.2', '< 7'] + s.add_runtime_dependency 'activesupport', ['>= 5.2', '< 7'] end diff --git a/spec/permanent_records/circular_sti_dependency_spec.rb b/spec/permanent_records/circular_sti_dependency_spec.rb index 9a56466..8b4b6ed 100644 --- a/spec/permanent_records/circular_sti_dependency_spec.rb +++ b/spec/permanent_records/circular_sti_dependency_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe PermanentRecords do diff --git a/spec/permanent_records/counter_cache_spec.rb b/spec/permanent_records/counter_cache_spec.rb index f3b0c55..31cda87 100644 --- a/spec/permanent_records/counter_cache_spec.rb +++ b/spec/permanent_records/counter_cache_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe PermanentRecords do diff --git a/spec/permanent_records/propagate_validation_flag_spec.rb b/spec/permanent_records/propagate_validation_flag_spec.rb index 3753fe7..d0d6afb 100644 --- a/spec/permanent_records/propagate_validation_flag_spec.rb +++ b/spec/permanent_records/propagate_validation_flag_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe PermanentRecords do diff --git a/spec/permanent_records/revive_parent_first_spec.rb b/spec/permanent_records/revive_parent_first_spec.rb index 30b46b7..a702704 100644 --- a/spec/permanent_records/revive_parent_first_spec.rb +++ b/spec/permanent_records/revive_parent_first_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe PermanentRecords do diff --git a/spec/permanent_records/validate_presence_spec.rb b/spec/permanent_records/validate_presence_spec.rb index 146e49b..aa65a34 100644 --- a/spec/permanent_records/validate_presence_spec.rb +++ b/spec/permanent_records/validate_presence_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe PermanentRecords do diff --git a/spec/permanent_records_spec.rb b/spec/permanent_records_spec.rb index 331de34..8c9267c 100644 --- a/spec/permanent_records_spec.rb +++ b/spec/permanent_records_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # rubocop:disable Performance/TimesMap require 'spec_helper' @@ -11,8 +13,8 @@ let!(:difficulty) { hole.create_difficulty } let!(:comments) { 2.times.map { hole.comments.create! } } let!(:bed) { Bed.create! } - let!(:kitty) { Kitty.create!(beds: [bed]) } - let!(:meerkat) { Meerkat.create!(holes: [hole]) } + let!(:kitty) { Kitty.create!(beds: [bed]) } + let!(:meerkat) { Meerkat.create!(holes: [hole]) } describe '#destroy' do let(:record) { hole } @@ -363,8 +365,10 @@ end end it 'revives them' do - subject.comments.each { |c| expect(c).not_to be_deleted } - subject.comments.each { |c| expect(Comment.find_by_id(c.id)).to eq(c) } + subject.comments.each { |c| + expect(c).not_to be_deleted + expect(Comment.find_by_id(c.id)).to eq(c) + } end end context 'with :has_one cardinality' do @@ -391,7 +395,7 @@ context '.not_deleted' do it 'counts' do - expect(Muskrat.not_deleted.count).to eq(Muskrat.all.reject(&:deleted?).size) + expect(Muskrat.not_deleted.count).to eq(Muskrat.all.count { |element| !element.deleted? }) end it 'has no deleted records' do @@ -401,7 +405,7 @@ context '.deleted' do it 'counts' do - expect(Muskrat.deleted.count).to eq(Muskrat.all.select(&:deleted?).size) + expect(Muskrat.deleted.count).to eq(Muskrat.all.count(&:deleted?)) end it 'has no non-deleted records' do diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 5a0a495..1134d68 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # rubocop:disable # Include this file in your test by copying the following line to your test: # require File.expand_path(File.dirname(__FILE__) + "/test_helper") @@ -32,7 +34,7 @@ def self.env load 'schema.rb' if File.exist?(support.join('schema.rb')) -Dir.glob(support.join('*.rb')).each do |file| +Dir.glob(support.join('*.rb')).sort.each do |file| autoload File.basename(file).chomp('.rb').camelcase.intern, file require file end diff --git a/spec/support/ant.rb b/spec/support/ant.rb index 4858907..b9a6fef 100644 --- a/spec/support/ant.rb +++ b/spec/support/ant.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class Ant < ActiveRecord::Base belongs_to :hole, counter_cache: true belongs_to :any_hole, polymorphic: true, counter_cache: true diff --git a/spec/support/bed.rb b/spec/support/bed.rb index 0a42450..db7d9d0 100644 --- a/spec/support/bed.rb +++ b/spec/support/bed.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class Bed < ActiveRecord::Base has_one :kitty end diff --git a/spec/support/comment.rb b/spec/support/comment.rb index c4a4883..a310e2e 100644 --- a/spec/support/comment.rb +++ b/spec/support/comment.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class Comment < ActiveRecord::Base belongs_to :hole validates :hole, presence: true diff --git a/spec/support/difficulty.rb b/spec/support/difficulty.rb index 3324879..e07b813 100644 --- a/spec/support/difficulty.rb +++ b/spec/support/difficulty.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class Difficulty < ActiveRecord::Base belongs_to :hole diff --git a/spec/support/dirt.rb b/spec/support/dirt.rb index 240aeaa..6cd783e 100644 --- a/spec/support/dirt.rb +++ b/spec/support/dirt.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class Dirt < ActiveRecord::Base has_one :hole # validates :hole, presence: true diff --git a/spec/support/earthworm.rb b/spec/support/earthworm.rb index d5a6b1b..038e595 100644 --- a/spec/support/earthworm.rb +++ b/spec/support/earthworm.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class Earthworm < ActiveRecord::Base belongs_to :dirt validates :dirt, presence: true diff --git a/spec/support/hole.rb b/spec/support/hole.rb index 3071827..fa991cc 100644 --- a/spec/support/hole.rb +++ b/spec/support/hole.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class Hole < ActiveRecord::Base # Because when we're destroying a mole hole we're obviously using high # explosives. diff --git a/spec/support/house.rb b/spec/support/house.rb index 1cf9ba4..96d3835 100644 --- a/spec/support/house.rb +++ b/spec/support/house.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class House < ActiveRecord::Base has_many :rooms, dependent: :destroy validates_associated :rooms diff --git a/spec/support/kitty.rb b/spec/support/kitty.rb index c1c11af..d009fa3 100644 --- a/spec/support/kitty.rb +++ b/spec/support/kitty.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class Kitty < ActiveRecord::Base has_and_belongs_to_many :beds, dependent: :destroy end diff --git a/spec/support/location.rb b/spec/support/location.rb index f7b4cb3..396511d 100644 --- a/spec/support/location.rb +++ b/spec/support/location.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class Location < ActiveRecord::Base belongs_to :hole validates :hole, presence: true, unless: :zone? diff --git a/spec/support/meerkat.rb b/spec/support/meerkat.rb index fafafde..14e478c 100644 --- a/spec/support/meerkat.rb +++ b/spec/support/meerkat.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class Meerkat < ActiveRecord::Base has_and_belongs_to_many :holes end diff --git a/spec/support/mole.rb b/spec/support/mole.rb index 75fbe6b..81b0a55 100644 --- a/spec/support/mole.rb +++ b/spec/support/mole.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class Mole < ActiveRecord::Base belongs_to :hole validates :hole, presence: true diff --git a/spec/support/muskrat.rb b/spec/support/muskrat.rb index 11e847e..b3bbd78 100644 --- a/spec/support/muskrat.rb +++ b/spec/support/muskrat.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class Muskrat < ActiveRecord::Base belongs_to :hole validates :hole, presence: true diff --git a/spec/support/room.rb b/spec/support/room.rb index 51665d8..9b7534c 100644 --- a/spec/support/room.rb +++ b/spec/support/room.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class Room < ActiveRecord::Base belongs_to :house validates :house, presence: true diff --git a/spec/support/schema.rb b/spec/support/schema.rb index 0254311..3e148f9 100644 --- a/spec/support/schema.rb +++ b/spec/support/schema.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + ActiveRecord::Schema.define(version: 1) do create_table :ants, force: true do |t| t.column :name, :string diff --git a/spec/support/unused_model.rb b/spec/support/unused_model.rb index 00cf53b..2f2aacd 100644 --- a/spec/support/unused_model.rb +++ b/spec/support/unused_model.rb @@ -1,2 +1,4 @@ +# frozen_string_literal: true + class UnusedModel < ActiveRecord::Base end From b2bceaa5b055d5ffc13bdce60e2244f5aaa1009a Mon Sep 17 00:00:00 2001 From: Luciano Maiwald Date: Mon, 25 Mar 2024 11:58:53 +0100 Subject: [PATCH 3/5] Restrict to Rails < 7, minimize active record patch ... by delegating to super so we don't have to copy more of active record than necessary. --- lib/permanent_records.rb | 5 +---- .../{active_record_5_2.rb => active_record.rb} | 18 ++++++------------ 2 files changed, 7 insertions(+), 16 deletions(-) rename lib/permanent_records/{active_record_5_2.rb => active_record.rb} (66%) diff --git a/lib/permanent_records.rb b/lib/permanent_records.rb index 80cb510..1439851 100644 --- a/lib/permanent_records.rb +++ b/lib/permanent_records.rb @@ -282,8 +282,5 @@ def self.dependent_permanent_reflections(klass) ActiveSupport.on_load(:active_record) do ActiveRecord::Base.include PermanentRecords::ActiveRecord - - if [ActiveRecord::VERSION::MAJOR, ActiveRecord::VERSION::MINOR] == [5, 2] || ActiveRecord::VERSION::MAJOR > 5 - require 'permanent_records/active_record_5_2' - end + require 'permanent_records/active_record' end diff --git a/lib/permanent_records/active_record_5_2.rb b/lib/permanent_records/active_record.rb similarity index 66% rename from lib/permanent_records/active_record_5_2.rb rename to lib/permanent_records/active_record.rb index 8f8db5c..74c484f 100644 --- a/lib/permanent_records/active_record_5_2.rb +++ b/lib/permanent_records/active_record.rb @@ -1,42 +1,36 @@ # frozen_string_literal: true -# rubocop:disable Metrics/AbcSize # Support destroy for rails belongs_to assocations. module HandlePermanentRecordsDestroyedInBelongsToAssociation def handle_dependency return unless load_target + # only patch :destroy case and delegate to super otherwise case options[:dependent] when :destroy target.destroy raise ActiveRecord::Rollback if target.respond_to?(:deleted?) && !target.deleted? else - target.send(options[:dependent]) + super end end end -# rubocop:disable Metrics/MethodLength -# rubocop:disable Metrics/CyclomaticComplexity -# Support destroy for rails 5.2. has_on associations. +# Support destroy for rails has_one associations. module HandlePermanentRecordsDestroyedInHasOneAssociation def delete(method = options[:dependent]) return unless load_target + # only patch :destroy case and delegate to super otherwise case method - when :delete - target.delete when :destroy target.destroyed_by_association = reflection target.destroy throw(:abort) if target.respond_to?(:deleted?) && !target.deleted? - when :nullify - target.update_columns(reflection.foreign_key => nil) if target.persisted? + else + super(method) end end end -# rubocop:enable Metrics/CyclomaticComplexity -# rubocop:enable Metrics/MethodLength -# rubocop:enable Metrics/AbcSize ActiveRecord::Associations::BelongsToAssociation.prepend(HandlePermanentRecordsDestroyedInBelongsToAssociation) ActiveRecord::Associations::HasOneAssociation.prepend(HandlePermanentRecordsDestroyedInHasOneAssociation) From 4db0479da5e646848c54bc410e1218d236bd9006 Mon Sep 17 00:00:00 2001 From: Maximilian Herold Date: Tue, 26 Mar 2024 11:42:09 +0100 Subject: [PATCH 4/5] Add rubocop-rake and rubocop-rspec, fix more warnings Keep some warnings in rubocop todos for now, also disabled some cops in rubocop config that would definitely mean lots of rewriting ... to be examinated later. --- .rubocop.yml | 17 +++- .rubocop_todo.yml | 60 ++++++++++- Gemfile | 2 + gemfiles/rails_5.2.gemfile | 2 + gemfiles/rails_6.0.gemfile | 2 + gemfiles/rails_6.1.gemfile | 2 + .../circular_sti_dependency_spec.rb | 2 +- .../propagate_validation_flag_spec.rb | 11 +-- .../revive_parent_first_spec.rb | 6 +- spec/permanent_records_spec.rb | 99 +++++++++++-------- spec/spec_helper.rb | 4 +- 11 files changed, 154 insertions(+), 53 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 94c7755..3782bde 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,4 +1,7 @@ -require: rubocop-performance +require: + - rubocop-performance + - rubocop-rake + - rubocop-rspec inherit_from: .rubocop_todo.yml @@ -20,5 +23,17 @@ Metrics/BlockLength: Layout/LineLength: Max: 120 +RSpec/ContextWording: + Enabled: false + +RSpec/MultipleExpectations: + Enabled: false + +RSpec/MultipleMemoizedHelpers: + Enabled: false + +RSpec/NestedGroups: + Enabled: false + Style/BlockDelimiters: Enabled: false diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index ac436f6..1406a22 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,7 +1,65 @@ # This configuration was generated by # `rubocop --auto-gen-config` -# on 2024-03-26 10:28:30 UTC using RuboCop version 1.62.1. +# on 2024-03-26 14:12:23 UTC using RuboCop version 1.62.1. # The point is for the user to remove these configuration records # one by one as the offenses are removed from the code base. # Note that changes in the inspected code, or installation of new # versions of RuboCop, may require this file to be generated again. + +# Offense count: 11 +RSpec/AnyInstance: + Exclude: + - 'spec/permanent_records_spec.rb' + +# Offense count: 3 +# Configuration parameters: CountAsOne. +RSpec/ExampleLength: + Max: 22 + +# Offense count: 5 +# Configuration parameters: Include, CustomTransform, IgnoreMethods, SpecSuffixOnly. +# Include: **/*_spec*rb*, **/spec/**/* +RSpec/FilePath: + Exclude: + - 'spec/permanent_records/circular_sti_dependency_spec.rb' + - 'spec/permanent_records/counter_cache_spec.rb' + - 'spec/permanent_records/propagate_validation_flag_spec.rb' + - 'spec/permanent_records/revive_parent_first_spec.rb' + - 'spec/permanent_records/validate_presence_spec.rb' + +# Offense count: 5 +RSpec/LetSetup: + Exclude: + - 'spec/permanent_records/revive_parent_first_spec.rb' + - 'spec/permanent_records_spec.rb' + +# Offense count: 1 +# Configuration parameters: . +# SupportedStyles: have_received, receive +RSpec/MessageSpies: + EnforcedStyle: receive + +# Offense count: 60 +# Configuration parameters: EnforcedStyle, IgnoreSharedExamples. +# SupportedStyles: always, named_only +RSpec/NamedSubject: + Exclude: + - 'spec/permanent_records_spec.rb' + +# Offense count: 5 +# Configuration parameters: Include, CustomTransform, IgnoreMethods, IgnoreMetadata. +# Include: **/*_spec.rb +RSpec/SpecFilePathFormat: + Exclude: + - '**/spec/routing/**/*' + - 'spec/permanent_records/circular_sti_dependency_spec.rb' + - 'spec/permanent_records/counter_cache_spec.rb' + - 'spec/permanent_records/propagate_validation_flag_spec.rb' + - 'spec/permanent_records/revive_parent_first_spec.rb' + - 'spec/permanent_records/validate_presence_spec.rb' + +# Offense count: 2 +# This cop supports safe autocorrection (--autocorrect). +Rake/Desc: + Exclude: + - 'Rakefile' diff --git a/Gemfile b/Gemfile index ded0e1c..f33b06d 100644 --- a/Gemfile +++ b/Gemfile @@ -11,4 +11,6 @@ gem 'rake' gem 'rspec', '>= 3.5.0' gem 'rubocop' gem 'rubocop-performance' +gem 'rubocop-rake' +gem 'rubocop-rspec' gem 'sqlite3' diff --git a/gemfiles/rails_5.2.gemfile b/gemfiles/rails_5.2.gemfile index e79007c..0af4ab3 100644 --- a/gemfiles/rails_5.2.gemfile +++ b/gemfiles/rails_5.2.gemfile @@ -9,6 +9,8 @@ gem "rake" gem "rspec", ">= 3.5.0" gem "rubocop" gem "rubocop-performance" +gem "rubocop-rake" +gem "rubocop-rspec" gem "sqlite3" gem "rails", "5.2.8.1" diff --git a/gemfiles/rails_6.0.gemfile b/gemfiles/rails_6.0.gemfile index 2d10665..6219554 100644 --- a/gemfiles/rails_6.0.gemfile +++ b/gemfiles/rails_6.0.gemfile @@ -9,6 +9,8 @@ gem "rake" gem "rspec", ">= 3.5.0" gem "rubocop" gem "rubocop-performance" +gem "rubocop-rake" +gem "rubocop-rspec" gem "sqlite3" gem "rails", "6.0.6.1" diff --git a/gemfiles/rails_6.1.gemfile b/gemfiles/rails_6.1.gemfile index b6d3983..693bd9e 100644 --- a/gemfiles/rails_6.1.gemfile +++ b/gemfiles/rails_6.1.gemfile @@ -9,6 +9,8 @@ gem "rake" gem "rspec", ">= 3.5.0" gem "rubocop" gem "rubocop-performance" +gem "rubocop-rake" +gem "rubocop-rspec" gem "sqlite3" gem "rails", "6.1.7.7" diff --git a/spec/permanent_records/circular_sti_dependency_spec.rb b/spec/permanent_records/circular_sti_dependency_spec.rb index 8b4b6ed..42d5e15 100644 --- a/spec/permanent_records/circular_sti_dependency_spec.rb +++ b/spec/permanent_records/circular_sti_dependency_spec.rb @@ -11,7 +11,7 @@ end describe '#revive' do - it 'should revive children properly on STI' do + it 'revives children properly on STI' do expect { hole.destroy }.to change { diff --git a/spec/permanent_records/propagate_validation_flag_spec.rb b/spec/permanent_records/propagate_validation_flag_spec.rb index d0d6afb..a18d2fd 100644 --- a/spec/permanent_records/propagate_validation_flag_spec.rb +++ b/spec/permanent_records/propagate_validation_flag_spec.rb @@ -9,13 +9,12 @@ before { hole.destroy } describe '#revive' do - before do - expect(dirt).to receive(:get_deleted_record) { dirt } - expect(dirt).to receive(:save).with(validate: false) - end + subject(:revive) { hole.revive(validate: false) } - it 'should propagate validation flag on dependent records' do - hole.revive(validate: false) + it 'propagates validation flag on dependent records' do + allow(dirt).to receive(:get_deleted_record) { dirt } + expect(dirt).to receive(:save).with(validate: false) + revive end end end diff --git a/spec/permanent_records/revive_parent_first_spec.rb b/spec/permanent_records/revive_parent_first_spec.rb index a702704..121efc2 100644 --- a/spec/permanent_records/revive_parent_first_spec.rb +++ b/spec/permanent_records/revive_parent_first_spec.rb @@ -10,8 +10,10 @@ before { hole.destroy } describe '#revive' do - it 'should revive parent first' do - hole.revive(reverse: true) + subject(:revive) { hole.revive(reverse: true) } + + it 'revives parent first' do + expect { revive }.not_to raise_error end end end diff --git a/spec/permanent_records_spec.rb b/spec/permanent_records_spec.rb index 8c9267c..f413bb8 100644 --- a/spec/permanent_records_spec.rb +++ b/spec/permanent_records_spec.rb @@ -17,11 +17,11 @@ let!(:meerkat) { Meerkat.create!(holes: [hole]) } describe '#destroy' do + subject { record.destroy(should_force) } + let(:record) { hole } let(:should_force) { false } - subject { record.destroy(should_force) } - it 'returns the record' do expect(subject).to eq(record) end @@ -35,7 +35,7 @@ end it 'does not really remove the record' do - expect { subject }.to_not change(record.class, :count) + expect { subject }.not_to change(record.class, :count) end it 'handles serialized attributes correctly' do @@ -63,15 +63,18 @@ before do allow_any_instance_of(Hole).to receive(:valid?).and_return(false) end + it 'raises' do expect { subject }.to raise_error(ActiveRecord::RecordInvalid) end context 'with validation opt-out' do let(:should_force) { { validate: false } } + it 'doesnt raise' do - expect { subject }.to_not raise_error + expect { subject }.not_to raise_error end + it 'soft-deletes the invalid record' do expect(subject).to be_deleted end @@ -84,7 +87,7 @@ end it 'returns false' do - expect(subject).to eql(false) + expect(subject).to be(false) end it 'does not set deleted_at' do @@ -102,17 +105,16 @@ context 'with dependent records' do context 'that are permanent' do - it '' do - expect { subject }.to_not change(Muskrat, :count) - end + it { expect { subject }.not_to change(Muskrat, :count) } context 'with has_many cardinality' do it 'marks records as deleted' do - subject.muskrats.each { |m| expect(m).to be_deleted } + expect(subject.muskrats).to all(be_deleted) end context 'when error occurs' do before { allow_any_instance_of(Hole).to receive(:valid?).and_return(false) } + it 'does not mark records as deleted' do expect { subject }.to raise_error(ActiveRecord::RecordInvalid) expect(record.muskrats.not_deleted.count).to eq(1) @@ -121,15 +123,17 @@ context 'with force delete' do let(:should_force) { :force } - it('') { expect { subject }.to change { Muskrat.count }.by(-1) } - it('') { expect { subject }.to change { Comment.count }.by(-2) } + + it { expect { subject }.to change(Muskrat, :count).by(-1) } + it { expect { subject }.to change(Comment, :count).by(-2) } context 'when error occurs' do before do allow_any_instance_of(Difficulty).to receive(:destroy).and_raise(ActiveRecord::RecordNotDestroyed) end - it('') { expect { subject }.not_to change(Muskrat, :count) } - it('') { expect { subject }.not_to change(Comment, :count) } + + it { expect { subject }.not_to change(Muskrat, :count) } + it { expect { subject }.not_to change(Comment, :count) } end end end @@ -141,6 +145,7 @@ context 'when error occurs' do before { allow_any_instance_of(Hole).to receive(:valid?).and_return(false) } + it('does not mark records as deleted') do expect { subject }.to raise_error(ActiveRecord::RecordInvalid) expect(record.reload.location).not_to be_deleted @@ -149,15 +154,17 @@ context 'with force delete' do let(:should_force) { :force } - it('') { expect { subject }.to change { Muskrat.count }.by(-1) } - it('') { expect { subject }.to change { Location.count }.by(-1) } + + it { expect { subject }.to change(Muskrat, :count).by(-1) } + it { expect { subject }.to change(Location, :count).by(-1) } context 'when error occurs' do before do allow_any_instance_of(Difficulty).to receive(:destroy).and_raise(ActiveRecord::RecordNotDestroyed) end - it('') { expect { subject }.not_to change(Muskrat, :count) } - it('') { expect { subject }.not_to change(Location, :count) } + + it { expect { subject }.not_to change(Muskrat, :count) } + it { expect { subject }.not_to change(Location, :count) } end end end @@ -169,6 +176,7 @@ context 'when error occurs' do before { allow_any_instance_of(Hole).to receive(:valid?).and_return(false) } + it 'does not mark records as deleted' do expect { subject }.to raise_error(ActiveRecord::RecordInvalid) expect(record.dirt).not_to be_deleted @@ -177,13 +185,15 @@ context 'with force delete' do let(:should_force) { :force } - it('') { expect { subject }.to change { Dirt.count }.by(-1) } + + it { expect { subject }.to change(Dirt, :count).by(-1) } context 'when error occurs' do before do allow_any_instance_of(Difficulty).to receive(:destroy).and_raise(ActiveRecord::RecordNotDestroyed) end - it('') { expect { subject }.not_to change(Dirt, :count) } + + it { expect { subject }.not_to change(Dirt, :count) } end end end @@ -191,7 +201,7 @@ context 'that are non-permanent' do it 'removes them' do - expect { subject }.to change { Mole.count }.by(-1) + expect { subject }.to change(Mole, :count).by(-1) end context 'with has many cardinality' do @@ -203,7 +213,7 @@ end it 'really removes the associations' do - expect { subject }.to change { Bed.count }.by(-1) + expect { subject }.to change(Bed, :count).by(-1) end it 'makes deleted? return true' do @@ -215,15 +225,15 @@ context 'as default scope' do let(:load_comments) { Comment.unscoped.where(hole_id: subject.id) } + context 'with :has_many cardinality' do - before do - expect(load_comments.size).to eq(2) - end it 'deletes them' do - expect(load_comments.all?(&:deleted?)).to be_truthy + expect(load_comments.size).to eq(2) + expect(load_comments).to be_all(&:deleted?) expect(subject.comments).to be_blank end end + context 'with :has_one cardinality' do it 'deletes them' do expect(subject.difficulty).to be_deleted @@ -257,19 +267,17 @@ end describe '#revive' do + subject { record.revive should_validate } + let!(:record) { hole.tap(&:destroy) } let(:should_validate) { nil } - subject { record.revive should_validate } - it 'returns the record' do expect(subject).to eq(record) end it 'unsets deleted_at' do - expect { subject }.to change { - record.deleted_at - }.to(nil) + expect { subject }.to change(record, :deleted_at).to(nil) end it 'makes deleted? return false' do @@ -280,15 +288,18 @@ before do allow_any_instance_of(Hole).to receive(:valid?).and_return(false) end + it 'raises' do expect { subject }.to raise_error(ActiveRecord::RecordInvalid) end context 'with validation opt-out' do let(:should_validate) { { validate: false } } + it 'doesnt raise' do - expect { subject }.to_not raise_error + expect { subject }.not_to raise_error end + it 'makes deleted? return false' do expect(subject).not_to be_deleted end @@ -297,14 +308,13 @@ context 'with dependent records' do context 'that are permanent' do - it '' do - expect { subject }.to_not change(Muskrat, :count) - end + it { expect { subject }.not_to change(Muskrat, :count) } context 'that were deleted previously' do before { muskrat.update_attribute :deleted_at, 2.minutes.ago } + it 'does not restore' do - expect { subject }.to_not change(muskrat, :deleted?) + expect { subject }.not_to change(muskrat, :deleted?) end end @@ -312,8 +322,10 @@ it 'revives them' do subject.muskrats.each { |m| expect(m).not_to be_deleted } end + context 'when error occurs' do before { allow_any_instance_of(Hole).to receive(:valid?).and_return(false) } + it 'does not revive them' do expect { subject }.to raise_error(ActiveRecord::RecordInvalid) expect(record.muskrats.deleted.count).to eq(1) @@ -325,8 +337,10 @@ it 'revives them' do expect(subject.location).not_to be_deleted end + context 'when error occurs' do before { allow_any_instance_of(Hole).to receive(:valid?).and_return(false) } + it('does not mark records as deleted') do expect { subject }.to raise_error(ActiveRecord::RecordInvalid) expect(record.location).to be_deleted @@ -341,6 +355,7 @@ context 'when error occurs' do before { allow_any_instance_of(Hole).to receive(:valid?).and_return(false) } + it 'does not revive them' do expect { subject }.to raise_error(ActiveRecord::RecordInvalid) expect(record.dirt).to be_deleted @@ -351,7 +366,7 @@ context 'that are non-permanent' do it 'cannot revive them' do - expect { subject }.to_not change(Mole, :count) + expect { subject }.not_to change(Mole, :count) end end @@ -359,11 +374,14 @@ context 'with :has_many cardinality' do describe '#comments' do subject { super().comments } + describe '#size' do subject { super().size } - it { should == 2 } + + it { is_expected.to eq(2) } end end + it 'revives them' do subject.comments.each { |c| expect(c).not_to be_deleted @@ -371,6 +389,7 @@ } end end + context 'with :has_one cardinality' do it 'revives them' do expect(subject.difficulty).not_to be_deleted @@ -393,7 +412,7 @@ 6.times { Muskrat.create!(hole: hole).destroy } end - context '.not_deleted' do + describe '.not_deleted' do it 'counts' do expect(Muskrat.not_deleted.count).to eq(Muskrat.all.count { |element| !element.deleted? }) end @@ -403,13 +422,13 @@ end end - context '.deleted' do + describe '.deleted' do it 'counts' do expect(Muskrat.deleted.count).to eq(Muskrat.all.count(&:deleted?)) end it 'has no non-deleted records' do - Muskrat.deleted.each { |m| expect(m).to be_deleted } + expect(Muskrat.deleted).to all(be_deleted) end end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 1134d68..26fb459 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -47,11 +47,11 @@ def self.env DatabaseCleaner.clean_with(:truncation) end - config.before(:each) do + config.before do DatabaseCleaner.start end - config.after(:each) do + config.after do DatabaseCleaner.clean end end From 466bfb3698fc43b5a5e5faec6f1f7189a9c9cd4b Mon Sep 17 00:00:00 2001 From: Luciano Maiwald Date: Wed, 27 Mar 2024 10:31:46 +0100 Subject: [PATCH 5/5] Relax rails version constraint to include 7, add appraisals --- .github/workflows/test_and_lint.yml | 5 +++++ Appraisals | 8 ++++++++ README.md | 2 +- gemfiles/rails_7.0.gemfile | 17 +++++++++++++++++ gemfiles/rails_7.1.gemfile | 17 +++++++++++++++++ permanent_records.gemspec | 4 ++-- 6 files changed, 50 insertions(+), 3 deletions(-) create mode 100644 gemfiles/rails_7.0.gemfile create mode 100644 gemfiles/rails_7.1.gemfile diff --git a/.github/workflows/test_and_lint.yml b/.github/workflows/test_and_lint.yml index 3d4a0bd..7379fc7 100644 --- a/.github/workflows/test_and_lint.yml +++ b/.github/workflows/test_and_lint.yml @@ -12,15 +12,20 @@ jobs: - 2.7.8 - 3.0.6 - 3.1.4 + - 3.2.3 appraisal: - rails-5.2 - rails-6.0 - rails-6.1 + - rails-7.0 + - rails-7.1 exclude: - ruby: 3.0.6 appraisal: rails-5.2 - ruby: 3.1.4 appraisal: rails-5.2 + - ruby: 3.2.3 + appraisal: rails-5.2 steps: - name: Install system dependencies run: sudo apt-get install -y libsqlite3-dev diff --git a/Appraisals b/Appraisals index cb851bb..7bf145f 100644 --- a/Appraisals +++ b/Appraisals @@ -11,3 +11,11 @@ end appraise 'rails-6.1' do gem 'rails', '6.1.7.7' end + +appraise 'rails-7.0' do + gem 'rails', '7.0.8.1' +end + +appraise 'rails-7.1' do + gem 'rails', '7.1.3.2' +end diff --git a/README.md b/README.md index 78b909f..ec7082f 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# PermanentRecords (Rails 5.2, 6.0, 6.1) +# PermanentRecords [http://github.com/JackDanger/permanent_records/](http://github.com/JackDanger/permanent_records/) diff --git a/gemfiles/rails_7.0.gemfile b/gemfiles/rails_7.0.gemfile new file mode 100644 index 0000000..b9eaf42 --- /dev/null +++ b/gemfiles/rails_7.0.gemfile @@ -0,0 +1,17 @@ +# This file was generated by Appraisal + +source "https://rubygems.org" + +gem "appraisal" +gem "database_cleaner", ">= 1.5.1" +gem "pry-byebug" +gem "rake" +gem "rspec", ">= 3.5.0" +gem "rubocop" +gem "rubocop-performance" +gem "rubocop-rake" +gem "rubocop-rspec" +gem "sqlite3" +gem "rails", "7.0.8.1" + +gemspec path: "../" diff --git a/gemfiles/rails_7.1.gemfile b/gemfiles/rails_7.1.gemfile new file mode 100644 index 0000000..4e64224 --- /dev/null +++ b/gemfiles/rails_7.1.gemfile @@ -0,0 +1,17 @@ +# This file was generated by Appraisal + +source "https://rubygems.org" + +gem "appraisal" +gem "database_cleaner", ">= 1.5.1" +gem "pry-byebug" +gem "rake" +gem "rspec", ">= 3.5.0" +gem "rubocop" +gem "rubocop-performance" +gem "rubocop-rake" +gem "rubocop-rspec" +gem "sqlite3" +gem "rails", "7.1.3.2" + +gemspec path: "../" diff --git a/permanent_records.gemspec b/permanent_records.gemspec index 5d0f004..98bd47e 100644 --- a/permanent_records.gemspec +++ b/permanent_records.gemspec @@ -23,6 +23,6 @@ Gem::Specification.new do |s| s.required_ruby_version = '>= 2.7.8' - s.add_runtime_dependency 'activerecord', ['>= 5.2', '< 7'] - s.add_runtime_dependency 'activesupport', ['>= 5.2', '< 7'] + s.add_runtime_dependency 'activerecord', '>= 5.2' + s.add_runtime_dependency 'activesupport', '>= 5.2' end