From a8cb7ea0267fd1ff6de1691b684e9ce1efe03281 Mon Sep 17 00:00:00 2001 From: msalzburg Date: Wed, 9 Oct 2019 10:57:25 +0200 Subject: [PATCH 01/31] Freeze sqlite3 dependency --- permanent_records.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/permanent_records.gemspec b/permanent_records.gemspec index 90fe030..ad1fb86 100644 --- a/permanent_records.gemspec +++ b/permanent_records.gemspec @@ -34,5 +34,5 @@ EOS s.add_development_dependency 'rake' # For Travis-ci s.add_development_dependency 'rspec', '>= 3.5.0' s.add_development_dependency 'rubocop' - s.add_development_dependency 'sqlite3' + s.add_development_dependency 'sqlite3', '~> 1.3.6' # freeze to ensure specs are working end From 31deccc11f30eabdf07346927667797bc57e3cf7 Mon Sep 17 00:00:00 2001 From: msalzburg Date: Wed, 9 Oct 2019 10:59:28 +0200 Subject: [PATCH 02/31] Update ruby and rails versions for travis --- .travis.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index 3f8d83d..7f8a428 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,8 +1,8 @@ language: ruby rvm: - - 2.0.0 - - 2.2.2 - - 2.3.0 + - 2.0.0-p648 + - 2.2.10 + - 2.3.8 env: - AR_TEST_VERSION: 4.2.0 - - AR_TEST_VERSION: 4.2.5 + - AR_TEST_VERSION: 4.2.11.1 From 3559ba4b5b6a8f103415ba24f0dd167c40c4c70d Mon Sep 17 00:00:00 2001 From: msalzburg Date: Wed, 9 Oct 2019 11:08:19 +0200 Subject: [PATCH 03/31] Freeze to ensure ruby 2.0 compatibility --- .rubocop.yml | 1 + permanent_records.gemspec | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.rubocop.yml b/.rubocop.yml index 12e6bfc..47e0306 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,6 +1,7 @@ AllCops: Exclude: - bin/* + TargetRubyVersion: 2.0 Metrics/LineLength: Max: 120 diff --git a/permanent_records.gemspec b/permanent_records.gemspec index ad1fb86..baa7cb4 100644 --- a/permanent_records.gemspec +++ b/permanent_records.gemspec @@ -33,6 +33,6 @@ EOS s.add_development_dependency 'pry-byebug' s.add_development_dependency 'rake' # For Travis-ci s.add_development_dependency 'rspec', '>= 3.5.0' - s.add_development_dependency 'rubocop' + s.add_development_dependency 'rubocop', '~> 0.50.0' # freeze to ensure ruby 2.0 compatibility s.add_development_dependency 'sqlite3', '~> 1.3.6' # freeze to ensure specs are working end From c07b5d8832f29adcd05af9a3295c9c01665875f8 Mon Sep 17 00:00:00 2001 From: msalzburg Date: Wed, 9 Oct 2019 11:09:16 +0200 Subject: [PATCH 04/31] Fix "Parenthesize the param" cop --- spec/permanent_records_spec.rb | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/spec/permanent_records_spec.rb b/spec/permanent_records_spec.rb index 5276133..33bb795 100644 --- a/spec/permanent_records_spec.rb +++ b/spec/permanent_records_spec.rb @@ -32,7 +32,7 @@ end it 'does not really remove the record' do - expect { subject }.to_not change { record.class.count } + expect { subject }.to_not change(record.class.count) end it 'handles serialized attributes correctly' do @@ -85,7 +85,7 @@ end it 'does not set deleted_at' do - expect { subject }.not_to change { record.deleted_at } + expect { subject }.not_to change(record.deleted_at) end context 'and using the !' do @@ -112,7 +112,7 @@ context 'with dependent records' do context 'that are permanent' do it '' do - expect { subject }.to_not change { Muskrat.count } + expect { subject }.to_not change(Muskrat.count) end context 'with has_many cardinality' do @@ -137,8 +137,8 @@ before do allow_any_instance_of(Difficulty).to receive(:destroy).and_return(false) 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 @@ -165,8 +165,8 @@ before do allow_any_instance_of(Difficulty).to receive(:destroy).and_return(false) 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 @@ -192,7 +192,7 @@ before do allow_any_instance_of(Difficulty).to receive(:destroy).and_return(false) end - it('') { expect { subject }.not_to change { Dirt.count } } + it('') { expect { subject }.not_to change(Dirt.count) } end end end @@ -226,18 +226,18 @@ context 'with habtm association' do it 'does not remove the associated records' do - expect { subject }.not_to change { Meerkat.count } + expect { subject }.not_to change(Meerkat.count) end it 'does not remove the entry from the join table' do - expect { subject }.not_to change { meerkat.holes.count } + expect { subject }.not_to change(meerkat.holes.count) end context 'with force argument set to truthy' do let(:should_force) { :force } it 'does not remove the associated records' do - expect { subject }.not_to change { Meerkat.count } + expect { subject }.not_to change(Meerkat.count) end it 'removes the entry from the join table' do @@ -289,13 +289,13 @@ context 'with dependent records' do context 'that are permanent' do it '' do - expect { subject }.to_not change { Muskrat.count } + expect { subject }.to_not change(Muskrat.count) end context 'that were deleted previously' do before { muskrat.update_attributes! deleted_at: 2.minutes.ago } it 'does not restore' do - expect { subject }.to_not change { muskrat.deleted? } + expect { subject }.to_not change(muskrat.deleted?) end end @@ -342,7 +342,7 @@ context 'that are non-permanent' do it 'cannot revive them' do - expect { subject }.to_not change { Mole.count } + expect { subject }.to_not change(Mole.count) end end @@ -371,7 +371,7 @@ context 'with habtm association' do it 'does not change entries from the join table' do - expect { subject }.not_to change { meerkat.holes.count } + expect { subject }.not_to change(meerkat.holes.count) end end end From 7105e01a1ef553169e5ad348f28653547a3a3c7b Mon Sep 17 00:00:00 2001 From: msalzburg Date: Wed, 9 Oct 2019 11:10:19 +0200 Subject: [PATCH 05/31] Fix several cops automatically --- Rakefile | 4 ++-- lib/permanent_records.rb | 8 ++++---- permanent_records.gemspec | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Rakefile b/Rakefile index a8c1b01..362294e 100644 --- a/Rakefile +++ b/Rakefile @@ -37,7 +37,7 @@ task :pandoc do system('pandoc -s -r markdown -w rst README.md -o README.rst') end -task publish: [:pandoc, :rubocop, :rspec] do +task publish: %i[pandoc rubocop rspec] do # Ensure the gem builds system('gem build permanent_records.gemspec') && # And we didn't leave anything (aside from the gem) uncommitted @@ -46,4 +46,4 @@ task publish: [:pandoc, :rubocop, :rspec] do system("gem push permanent_records-#{version}.gem") end -task default: [:rspec, :rubocop] +task default: %i[rspec rubocop] diff --git a/lib/permanent_records.rb b/lib/permanent_records.rb index 400ded3..d1b9bfe 100644 --- a/lib/permanent_records.rb +++ b/lib/permanent_records.rb @@ -232,7 +232,7 @@ def not_deleted # Included into ActiveRecord for all models module IsPermanent def is_permanent? # rubocop:disable Style/PredicateName - columns.detect { |c| 'deleted_at' == c.name } + columns.detect { |c| c.name == 'deleted_at' } end end @@ -240,16 +240,16 @@ def self.should_force_destroy?(force) if force.is_a?(Hash) force[:force] else - :force == force + force == :force end end def self.should_revive_parent_first?(order) - order.is_a?(Hash) && true == order[:reverse] + order.is_a?(Hash) && order[:reverse] == true end def self.should_ignore_validations?(force) - force.is_a?(Hash) && false == force[:validate] + force.is_a?(Hash) && force[:validate] == false end def self.dependent_record_window diff --git a/permanent_records.gemspec b/permanent_records.gemspec index baa7cb4..116bf4b 100644 --- a/permanent_records.gemspec +++ b/permanent_records.gemspec @@ -1,4 +1,4 @@ -# encoding: utf-8 + Gem::Specification.new do |s| s.name = 'permanent_records' s.version = File.read('VERSION') From 69e3cc7076e0de9f44542fcdcf082eb600ac7045 Mon Sep 17 00:00:00 2001 From: msalzburg Date: Wed, 9 Oct 2019 11:11:24 +0200 Subject: [PATCH 06/31] Use meaningful heredoc delimiter --- permanent_records.gemspec | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/permanent_records.gemspec b/permanent_records.gemspec index 116bf4b..212103d 100644 --- a/permanent_records.gemspec +++ b/permanent_records.gemspec @@ -8,10 +8,10 @@ Gem::Specification.new do |s| 'Trond Arve Nordheim', 'Josh Teneycke', 'Maximilian Herold', 'Hugh Evans', 'Sergey Gnuskov', 'aq', 'Joel AZEMAR'] s.summary = 'Soft-delete your ActiveRecord records' - s.description = <<-EOS + s.description = <<-DESCRIPTION Never Lose Data. Rather than deleting rows this sets Record#deleted_at and gives you all the scopes you need to work with your data. -EOS +DESCRIPTION s.email = 'github@jackcanty.com' s.extra_rdoc_files = [ 'LICENSE', From 8392b25ace690df61f8404e28fd4fd556327baee Mon Sep 17 00:00:00 2001 From: msalzburg Date: Wed, 9 Oct 2019 11:14:33 +0200 Subject: [PATCH 07/31] Disable "Metrics/BlockLength" cop --- .rubocop.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.rubocop.yml b/.rubocop.yml index 47e0306..9b7cc4d 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -3,6 +3,9 @@ AllCops: - bin/* TargetRubyVersion: 2.0 +Metrics/BlockLength: + Enabled: false + Metrics/LineLength: Max: 120 From a2ed0353ffe58b1774a5e0efe2ca7facdba9833d Mon Sep 17 00:00:00 2001 From: msalzburg Date: Wed, 9 Oct 2019 11:37:07 +0200 Subject: [PATCH 08/31] Indent heredoc in gemspec --- permanent_records.gemspec | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/permanent_records.gemspec b/permanent_records.gemspec index 212103d..3f1bc8e 100644 --- a/permanent_records.gemspec +++ b/permanent_records.gemspec @@ -1,4 +1,3 @@ - Gem::Specification.new do |s| s.name = 'permanent_records' s.version = File.read('VERSION') @@ -9,8 +8,8 @@ Gem::Specification.new do |s| 'Hugh Evans', 'Sergey Gnuskov', 'aq', 'Joel AZEMAR'] s.summary = 'Soft-delete your ActiveRecord records' s.description = <<-DESCRIPTION -Never Lose Data. Rather than deleting rows this sets Record#deleted_at and -gives you all the scopes you need to work with your data. + Never Lose Data. Rather than deleting rows this sets Record#deleted_at and + gives you all the scopes you need to work with your data. DESCRIPTION s.email = 'github@jackcanty.com' s.extra_rdoc_files = [ From db6e27b24ac5e434b6d2ce69ca98c7b8d8d2d7f7 Mon Sep 17 00:00:00 2001 From: msalzburg Date: Wed, 9 Oct 2019 11:37:48 +0200 Subject: [PATCH 09/31] Fix and update enabled/disabled inline cops --- lib/permanent_records.rb | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/lib/permanent_records.rb b/lib/permanent_records.rb index d1b9bfe..92e8c51 100644 --- a/lib/permanent_records.rb +++ b/lib/permanent_records.rb @@ -22,7 +22,7 @@ def self.included(base) end end - def is_permanent? # rubocop:disable Style/PredicateName + def is_permanent? # rubocop:disable Naming/PredicateName respond_to?(:deleted_at) end @@ -76,11 +76,12 @@ def revival # rubocop:disable Metrics/MethodLength ] end - def get_deleted_record # rubocop:disable Style/AccessorMethodName + def get_deleted_record # rubocop:disable Naming/AccessorMethodName self.class.unscoped.find(id) end # rubocop:disable Metrics/MethodLength + # rubocop:disable Lint/RescueWithoutErrorClass def set_deleted_at(value, force = nil) return self unless is_permanent? record = get_deleted_record @@ -104,6 +105,8 @@ def set_deleted_at(value, force = nil) raise e end end + # rubocop:enable Lint/RescueWithoutErrorClass + # rubocop:enable Metrics/MethodLength def each_counter_cache _reflections.each do |name, reflection| @@ -119,6 +122,7 @@ def each_counter_cache end end + # rubocop:disable Metrics/MethodLength def destroy_with_permanent_records(force = nil) run_callbacks(:destroy) do if deleted? || new_record? @@ -134,6 +138,7 @@ def destroy_with_permanent_records(force = nil) end deleted? ? self : false end + # rubocop:enable Metrics/MethodLength def add_record_window(_request, name, reflection) send(name).unscope(where: :deleted_at).where( @@ -157,6 +162,7 @@ def revive_destroyed_dependent_records(force = nil) reload end + # rubocop:disable Metrics/MethodLength def destroyed_dependent_relations PermanentRecords.dependent_permanent_reflections(self.class).map do |name, relation| cardinality = relation.macro.to_s.gsub('has_', '').to_sym @@ -172,6 +178,7 @@ def destroyed_dependent_relations end end end + # rubocop:enable Metrics/MethodLength def attempt_notifying_observers(callback) notify_observers(callback) @@ -231,7 +238,7 @@ def not_deleted # Included into ActiveRecord for all models module IsPermanent - def is_permanent? # rubocop:disable Style/PredicateName + def is_permanent? # rubocop:disable Naming/PredicateName columns.detect { |c| c.name == 'deleted_at' } end end From 20e54f9a4284930bf03216a5daf21c1d567b4fb4 Mon Sep 17 00:00:00 2001 From: msalzburg Date: Wed, 9 Oct 2019 11:47:46 +0200 Subject: [PATCH 10/31] Revert "Fix "Parenthesize the param" cop" This reverts commit c07b5d8832f29adcd05af9a3295c9c01665875f8. --- spec/permanent_records_spec.rb | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/spec/permanent_records_spec.rb b/spec/permanent_records_spec.rb index 33bb795..5276133 100644 --- a/spec/permanent_records_spec.rb +++ b/spec/permanent_records_spec.rb @@ -32,7 +32,7 @@ end it 'does not really remove the record' do - expect { subject }.to_not change(record.class.count) + expect { subject }.to_not change { record.class.count } end it 'handles serialized attributes correctly' do @@ -85,7 +85,7 @@ end it 'does not set deleted_at' do - expect { subject }.not_to change(record.deleted_at) + expect { subject }.not_to change { record.deleted_at } end context 'and using the !' do @@ -112,7 +112,7 @@ context 'with dependent records' do context 'that are permanent' do it '' do - expect { subject }.to_not change(Muskrat.count) + expect { subject }.to_not change { Muskrat.count } end context 'with has_many cardinality' do @@ -137,8 +137,8 @@ before do allow_any_instance_of(Difficulty).to receive(:destroy).and_return(false) 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 @@ -165,8 +165,8 @@ before do allow_any_instance_of(Difficulty).to receive(:destroy).and_return(false) 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 @@ -192,7 +192,7 @@ before do allow_any_instance_of(Difficulty).to receive(:destroy).and_return(false) end - it('') { expect { subject }.not_to change(Dirt.count) } + it('') { expect { subject }.not_to change { Dirt.count } } end end end @@ -226,18 +226,18 @@ context 'with habtm association' do it 'does not remove the associated records' do - expect { subject }.not_to change(Meerkat.count) + expect { subject }.not_to change { Meerkat.count } end it 'does not remove the entry from the join table' do - expect { subject }.not_to change(meerkat.holes.count) + expect { subject }.not_to change { meerkat.holes.count } end context 'with force argument set to truthy' do let(:should_force) { :force } it 'does not remove the associated records' do - expect { subject }.not_to change(Meerkat.count) + expect { subject }.not_to change { Meerkat.count } end it 'removes the entry from the join table' do @@ -289,13 +289,13 @@ context 'with dependent records' do context 'that are permanent' do it '' do - expect { subject }.to_not change(Muskrat.count) + expect { subject }.to_not change { Muskrat.count } end context 'that were deleted previously' do before { muskrat.update_attributes! deleted_at: 2.minutes.ago } it 'does not restore' do - expect { subject }.to_not change(muskrat.deleted?) + expect { subject }.to_not change { muskrat.deleted? } end end @@ -342,7 +342,7 @@ context 'that are non-permanent' do it 'cannot revive them' do - expect { subject }.to_not change(Mole.count) + expect { subject }.to_not change { Mole.count } end end @@ -371,7 +371,7 @@ context 'with habtm association' do it 'does not change entries from the join table' do - expect { subject }.not_to change(meerkat.holes.count) + expect { subject }.not_to change { meerkat.holes.count } end end end From ea89161fa1b329b67c9ca91e092bce9f01f6f964 Mon Sep 17 00:00:00 2001 From: msalzburg Date: Wed, 9 Oct 2019 11:50:02 +0200 Subject: [PATCH 11/31] Solve "Lint/AmbiguousBlockAssociation" with rubocop todo file. Should be fixed with newer rubocop version. --- .rubocop.yml | 2 ++ .rubocop_todo.yml | 12 ++++++++++++ 2 files changed, 14 insertions(+) create mode 100644 .rubocop_todo.yml diff --git a/.rubocop.yml b/.rubocop.yml index 9b7cc4d..2f21f90 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,3 +1,5 @@ +inherit_from: .rubocop_todo.yml + AllCops: Exclude: - bin/* diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml new file mode 100644 index 0000000..da47076 --- /dev/null +++ b/.rubocop_todo.yml @@ -0,0 +1,12 @@ +# This configuration was generated by +# `rubocop --auto-gen-config` +# on 2019-10-09 11:48:30 +0200 using RuboCop version 0.50.0. +# 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: 15 +Lint/AmbiguousBlockAssociation: + Exclude: + - 'spec/permanent_records_spec.rb' From 4a05cc08e5ce697cda68536c0c66764c21a1eb50 Mon Sep 17 00:00:00 2001 From: msalzburg Date: Wed, 9 Oct 2019 12:07:21 +0200 Subject: [PATCH 12/31] Update rails version in READMEs --- README.md | 2 +- README.rst | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index bd8aff5..9781e9f 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# PermanentRecords (Rails 3.1+) +# PermanentRecords (Rails 4.2) [http://github.com/JackDanger/permanent_records/](http://github.com/JackDanger/permanent_records/) diff --git a/README.rst b/README.rst index 3ad8fc5..24360b9 100644 --- a/README.rst +++ b/README.rst @@ -1,4 +1,4 @@ -PermanentRecords (Rails 3.1+) +PermanentRecords (Rails 4.2) ============================= http://github.com/JackDanger/permanent_records/ From f9456d52db2f0c923c478e44e20a4174addf7323 Mon Sep 17 00:00:00 2001 From: msalzburg Date: Wed, 9 Oct 2019 12:25:18 +0200 Subject: [PATCH 13/31] Update travis testing matrix --- .travis.yml | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 7f8a428..b136eee 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,8 +1,11 @@ language: ruby rvm: - - 2.0.0-p648 - 2.2.10 - 2.3.8 + - 2.4.9 + - 2.5.7 + - 2.6.5 env: - - AR_TEST_VERSION: 4.2.0 - - AR_TEST_VERSION: 4.2.11.1 + - AR_TEST_VERSION: 5.0.7.2 + - AR_TEST_VERSION: 5.1.7 + - AR_TEST_VERSION: 5.2.3 From 8c37457c2360f135f82c70070ccde2d1cf2fc6df Mon Sep 17 00:00:00 2001 From: msalzburg Date: Wed, 9 Oct 2019 13:34:36 +0200 Subject: [PATCH 14/31] Update rubocop and configure ruby 2.2 compatibility --- .rubocop.yml | 4 +++- permanent_records.gemspec | 3 ++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 2f21f90..dcbc607 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,9 +1,11 @@ +require: rubocop-performance + inherit_from: .rubocop_todo.yml AllCops: Exclude: - bin/* - TargetRubyVersion: 2.0 + TargetRubyVersion: 2.2 Metrics/BlockLength: Enabled: false diff --git a/permanent_records.gemspec b/permanent_records.gemspec index 3f1bc8e..88be483 100644 --- a/permanent_records.gemspec +++ b/permanent_records.gemspec @@ -32,6 +32,7 @@ DESCRIPTION s.add_development_dependency 'pry-byebug' s.add_development_dependency 'rake' # For Travis-ci s.add_development_dependency 'rspec', '>= 3.5.0' - s.add_development_dependency 'rubocop', '~> 0.50.0' # freeze to ensure ruby 2.0 compatibility + s.add_development_dependency 'rubocop', '~> 0.68.0' # freeze to ensure ruby 2.2 compatibility + s.add_development_dependency 'rubocop-performance' s.add_development_dependency 'sqlite3', '~> 1.3.6' # freeze to ensure specs are working end From bb3b6f60b493df5005bf7a3a1bf25bfa42f97d9d Mon Sep 17 00:00:00 2001 From: msalzburg Date: Wed, 9 Oct 2019 13:38:09 +0200 Subject: [PATCH 15/31] Fix some cops --- .rubocop_todo.yml | 6 +++++- lib/permanent_records.rb | 12 ++++++------ permanent_records.gemspec | 2 +- spec/permanent_records_spec.rb | 1 + spec/spec_helper.rb | 4 +--- 5 files changed, 14 insertions(+), 11 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index da47076..c958d01 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-09 11:48:30 +0200 using RuboCop version 0.50.0. +# on 2019-10-09 13:37:22 +0200 using RuboCop version 0.68.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 @@ -10,3 +10,7 @@ Lint/AmbiguousBlockAssociation: Exclude: - 'spec/permanent_records_spec.rb' + +# Offense count: 1 +Metrics/AbcSize: + Max: 17 diff --git a/lib/permanent_records.rb b/lib/permanent_records.rb index 92e8c51..8c44670 100644 --- a/lib/permanent_records.rb +++ b/lib/permanent_records.rb @@ -81,9 +81,9 @@ def get_deleted_record # rubocop:disable Naming/AccessorMethodName end # rubocop:disable Metrics/MethodLength - # rubocop:disable Lint/RescueWithoutErrorClass def set_deleted_at(value, force = nil) return self unless is_permanent? + record = get_deleted_record record.deleted_at = value begin @@ -98,14 +98,14 @@ def set_deleted_at(value, force = nil) end @attributes = record.instance_variable_get('@attributes') - rescue => e + rescue StandardError => e # trigger dependent record destruction (they were revived before this # record, which cannot be revived due to validations) record.destroy raise e end end - # rubocop:enable Lint/RescueWithoutErrorClass + # rubocop:enable Metrics/MethodLength def each_counter_cache @@ -152,9 +152,7 @@ def add_record_window(_request, name, reflection) ) end - # TODO: Feel free to refactor this without polluting the ActiveRecord - # namespace. - # rubocop:disable Metrics/AbcSize + # TODO: Feel free to refactor this without polluting the ActiveRecord namespace. def revive_destroyed_dependent_records(force = nil) destroyed_dependent_relations.each do |relation| relation.to_a.each { |destroyed_dependent_record| destroyed_dependent_record.try(:revive, force) } @@ -194,6 +192,7 @@ def dependent_record_ids .reduce({}) do |records, (key, _)| found = Array(send(key)).compact next records if found.empty? + records.update found.first.class => found.map(&:id) end end @@ -218,6 +217,7 @@ def permanently_delete_records(dependent_records) ids.each do |id| record = klass.unscoped.where(klass.primary_key => id).first next unless record + record.deleted_at = nil record.destroy(:force) end diff --git a/permanent_records.gemspec b/permanent_records.gemspec index 88be483..7ab6824 100644 --- a/permanent_records.gemspec +++ b/permanent_records.gemspec @@ -10,7 +10,7 @@ Gem::Specification.new do |s| s.description = <<-DESCRIPTION Never Lose Data. Rather than deleting rows this sets Record#deleted_at and gives you all the scopes you need to work with your data. -DESCRIPTION + DESCRIPTION s.email = 'github@jackcanty.com' s.extra_rdoc_files = [ 'LICENSE', diff --git a/spec/permanent_records_spec.rb b/spec/permanent_records_spec.rb index 5276133..227ee08 100644 --- a/spec/permanent_records_spec.rb +++ b/spec/permanent_records_spec.rb @@ -403,3 +403,4 @@ end end end +# rubocop:enable Performance/TimesMap diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index c11805f..5a0a495 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -23,9 +23,7 @@ def self.env end end -if I18n.config.respond_to?(:enforce_available_locales) - I18n.config.enforce_available_locales = true -end +I18n.config.enforce_available_locales = true if I18n.config.respond_to?(:enforce_available_locales) require 'logger' ActiveRecord::Base.logger = Logger.new support.join('debug.log') From a32269f3dc66a42268ffe40ef55352a716f766dd Mon Sep 17 00:00:00 2001 From: msalzburg Date: Wed, 9 Oct 2019 14:34:44 +0200 Subject: [PATCH 16/31] Improve formatting of database config --- spec/support/database.yml | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/spec/support/database.yml b/spec/support/database.yml index aefc70c..fcb309a 100644 --- a/spec/support/database.yml +++ b/spec/support/database.yml @@ -1,16 +1,16 @@ test: - :adapter: sqlite3 - :database: ":memory:" - :min_messages: ERROR + adapter: sqlite3 + database: ":memory:" + min_messages: ERROR # sqlite: -# :adapter: sqlite -# :database: plugin.sqlite.db +# adapter: sqlite +# database: plugin.sqlite.db # sqlite3: -# :adapter: sqlite3 -# :database: ":memory:" +# adapter: sqlite3 +# database: ":memory:" # mysql: -# :adapter: mysql -# :host: localhost -# :username: rails -# :password: -# :database: plugin_test +# adapter: mysql +# host: localhost +# username: rails +# password: +# database: plugin_test From 4530470ad752ede9e5a767ac815e2122ee2fc5d5 Mon Sep 17 00:00:00 2001 From: msalzburg Date: Wed, 9 Oct 2019 14:35:09 +0200 Subject: [PATCH 17/31] Update rails version in README files --- README.md | 2 +- README.rst | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 9781e9f..5f407c3 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# PermanentRecords (Rails 4.2) +# PermanentRecords (Rails 5) [http://github.com/JackDanger/permanent_records/](http://github.com/JackDanger/permanent_records/) diff --git a/README.rst b/README.rst index 24360b9..4ffc096 100644 --- a/README.rst +++ b/README.rst @@ -1,4 +1,4 @@ -PermanentRecords (Rails 4.2) +PermanentRecords (Rails 5) ============================= http://github.com/JackDanger/permanent_records/ From 798d861409eff9939caec03becdc7501d2a9693f Mon Sep 17 00:00:00 2001 From: msalzburg Date: Wed, 9 Oct 2019 14:52:45 +0200 Subject: [PATCH 18/31] Fix "Lint/AmbiguousBlockAssociation" cop --- .rubocop_todo.yml | 7 +------ spec/permanent_records_spec.rb | 30 +++++++++++++++--------------- 2 files changed, 16 insertions(+), 21 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index c958d01..322396f 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,16 +1,11 @@ # This configuration was generated by # `rubocop --auto-gen-config` -# on 2019-10-09 13:37:22 +0200 using RuboCop version 0.68.1. +# on 2019-10-09 14:51:57 +0200 using RuboCop version 0.68.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: 15 -Lint/AmbiguousBlockAssociation: - Exclude: - - 'spec/permanent_records_spec.rb' - # Offense count: 1 Metrics/AbcSize: Max: 17 diff --git a/spec/permanent_records_spec.rb b/spec/permanent_records_spec.rb index 227ee08..eaa48c0 100644 --- a/spec/permanent_records_spec.rb +++ b/spec/permanent_records_spec.rb @@ -32,7 +32,7 @@ end it 'does not really remove the record' do - expect { subject }.to_not change { record.class.count } + expect { subject }.to_not change(record.class, :count) end it 'handles serialized attributes correctly' do @@ -85,7 +85,7 @@ end it 'does not set deleted_at' do - expect { subject }.not_to change { record.deleted_at } + expect { subject }.not_to change(record, :deleted_at) end context 'and using the !' do @@ -112,7 +112,7 @@ context 'with dependent records' do context 'that are permanent' do it '' do - expect { subject }.to_not change { Muskrat.count } + expect { subject }.to_not change(Muskrat, :count) end context 'with has_many cardinality' do @@ -137,8 +137,8 @@ before do allow_any_instance_of(Difficulty).to receive(:destroy).and_return(false) 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 @@ -165,8 +165,8 @@ before do allow_any_instance_of(Difficulty).to receive(:destroy).and_return(false) 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 @@ -192,7 +192,7 @@ before do allow_any_instance_of(Difficulty).to receive(:destroy).and_return(false) end - it('') { expect { subject }.not_to change { Dirt.count } } + it('') { expect { subject }.not_to change(Dirt, :count) } end end end @@ -226,18 +226,18 @@ context 'with habtm association' do it 'does not remove the associated records' do - expect { subject }.not_to change { Meerkat.count } + expect { subject }.not_to change(Muskrat, :count) end it 'does not remove the entry from the join table' do - expect { subject }.not_to change { meerkat.holes.count } + expect { subject }.not_to change(meerkat.holes, :count) end context 'with force argument set to truthy' do let(:should_force) { :force } it 'does not remove the associated records' do - expect { subject }.not_to change { Meerkat.count } + expect { subject }.not_to change(Meerkat, :count) end it 'removes the entry from the join table' do @@ -289,13 +289,13 @@ context 'with dependent records' do context 'that are permanent' do it '' do - expect { subject }.to_not change { Muskrat.count } + expect { subject }.to_not change(Muskrat, :count) end context 'that were deleted previously' do before { muskrat.update_attributes! deleted_at: 2.minutes.ago } it 'does not restore' do - expect { subject }.to_not change { muskrat.deleted? } + expect { subject }.to_not change(muskrat, :deleted?) end end @@ -342,7 +342,7 @@ context 'that are non-permanent' do it 'cannot revive them' do - expect { subject }.to_not change { Mole.count } + expect { subject }.to_not change(Mole, :count) end end @@ -371,7 +371,7 @@ context 'with habtm association' do it 'does not change entries from the join table' do - expect { subject }.not_to change { meerkat.holes.count } + expect { subject }.not_to change(meerkat.holes, :count) end end end From 9962b261ee332585c3412b4edf8c9313f1037031 Mon Sep 17 00:00:00 2001 From: msalzburg Date: Wed, 9 Oct 2019 15:28:54 +0200 Subject: [PATCH 19/31] Fix "Metrics/AbcSize" cop and clear rubocop todos --- .rubocop_todo.yml | 6 +----- lib/permanent_records.rb | 7 +++---- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 322396f..9122900 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,11 +1,7 @@ # This configuration was generated by # `rubocop --auto-gen-config` -# on 2019-10-09 14:51:57 +0200 using RuboCop version 0.68.1. +# on 2019-10-09 15:29:14 +0200 using RuboCop version 0.68.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: 1 -Metrics/AbcSize: - Max: 17 diff --git a/lib/permanent_records.rb b/lib/permanent_records.rb index 8c44670..954aae1 100644 --- a/lib/permanent_records.rb +++ b/lib/permanent_records.rb @@ -163,15 +163,14 @@ def revive_destroyed_dependent_records(force = nil) # rubocop:disable Metrics/MethodLength def destroyed_dependent_relations PermanentRecords.dependent_permanent_reflections(self.class).map do |name, relation| - cardinality = relation.macro.to_s.gsub('has_', '').to_sym - case cardinality - when :many + case relation.macro.to_sym + when :has_many if deleted_at add_record_window(send(name), name, relation) else send(name).unscope(where: :deleted_at) end - when :one, :belongs_to + when :has_one, :belongs_to self.class.unscoped { Array(send(name)) } end end From f07ddaf3f50512b25f57c25e42160a4f960aee1b Mon Sep 17 00:00:00 2001 From: msalzburg Date: Wed, 9 Oct 2019 16:49:35 +0200 Subject: [PATCH 20/31] Fix broken callback chains for rails 5.1 --- spec/permanent_records_spec.rb | 6 +++--- spec/support/hole.rb | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/spec/permanent_records_spec.rb b/spec/permanent_records_spec.rb index eaa48c0..6d23dae 100644 --- a/spec/permanent_records_spec.rb +++ b/spec/permanent_records_spec.rb @@ -135,7 +135,7 @@ context 'when error occurs' do before do - allow_any_instance_of(Difficulty).to receive(:destroy).and_return(false) + 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) } @@ -163,7 +163,7 @@ context 'when error occurs' do before do - allow_any_instance_of(Difficulty).to receive(:destroy).and_return(false) + 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) } @@ -190,7 +190,7 @@ context 'when error occurs' do before do - allow_any_instance_of(Difficulty).to receive(:destroy).and_return(false) + allow_any_instance_of(Difficulty).to receive(:destroy).and_raise(ActiveRecord::RecordNotDestroyed) end it('') { expect { subject }.not_to change(Dirt, :count) } end diff --git a/spec/support/hole.rb b/spec/support/hole.rb index 63ea24c..3071827 100644 --- a/spec/support/hole.rb +++ b/spec/support/hole.rb @@ -27,6 +27,6 @@ class Hole < ActiveRecord::Base private def check_youre_not_in_the_hole - !youre_in_the_hole + throw(:abort) if youre_in_the_hole end end From 1e44eab16e09784ae2d0221790840f279607ef88 Mon Sep 17 00:00:00 2001 From: msalzburg Date: Wed, 9 Oct 2019 16:50:52 +0200 Subject: [PATCH 21/31] Fix deprecation for rails 5.2 use quoted_table_name class method --- lib/permanent_records.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/permanent_records.rb b/lib/permanent_records.rb index 954aae1..15bfa09 100644 --- a/lib/permanent_records.rb +++ b/lib/permanent_records.rb @@ -143,9 +143,9 @@ def destroy_with_permanent_records(force = nil) def add_record_window(_request, name, reflection) send(name).unscope(where: :deleted_at).where( [ - "#{reflection.quoted_table_name}.deleted_at > ?" \ + "#{reflection.klass.quoted_table_name}.deleted_at > ?" \ ' AND ' \ - "#{reflection.quoted_table_name}.deleted_at < ?", + "#{reflection.klass.quoted_table_name}.deleted_at < ?", deleted_at - PermanentRecords.dependent_record_window, deleted_at + PermanentRecords.dependent_record_window ] From 2b0119be7a8d8316a270b69e10008bb906baf8d5 Mon Sep 17 00:00:00 2001 From: msalzburg Date: Wed, 9 Oct 2019 17:00:39 +0200 Subject: [PATCH 22/31] Update activerecord and activesupport dependencies to >= 5.0 --- permanent_records.gemspec | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/permanent_records.gemspec b/permanent_records.gemspec index 7ab6824..023d95b 100644 --- a/permanent_records.gemspec +++ b/permanent_records.gemspec @@ -26,8 +26,8 @@ Gem::Specification.new do |s| ver = ENV['AR_TEST_VERSION'] ver = ver.dup.chomp if ver - s.add_runtime_dependency 'activerecord', ver || '>= 4.2.0' - s.add_runtime_dependency 'activesupport', ver || '>= 4.2.0' + s.add_runtime_dependency 'activerecord', ver || '>= 5.0.0' + s.add_runtime_dependency 'activesupport', ver || '>= 5.0.0' s.add_development_dependency 'database_cleaner', '>= 1.5.1' s.add_development_dependency 'pry-byebug' s.add_development_dependency 'rake' # For Travis-ci From c71dd5ff0234141759fb90fecea362b2e7ae741e Mon Sep 17 00:00:00 2001 From: Jack Danger Date: Mon, 14 Oct 2019 23:32:25 -0700 Subject: [PATCH 23/31] bumping version to 4.2.8 --- VERSION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/VERSION b/VERSION index 4739c61..ad9e446 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -4.2.7 +4.2.8 From 10be3a13f7274b12c1c0639ae486c0de61112027 Mon Sep 17 00:00:00 2001 From: msalzburg Date: Tue, 15 Oct 2019 11:44:29 +0200 Subject: [PATCH 24/31] Unify code formatting by using parentheses for parms --- lib/permanent_records.rb | 12 +++++------- .../circular_sti_dependency_spec.rb | 2 +- spec/permanent_records/counter_cache_spec.rb | 10 +++++----- spec/permanent_records_spec.rb | 2 +- 4 files changed, 12 insertions(+), 14 deletions(-) diff --git a/lib/permanent_records.rb b/lib/permanent_records.rb index 15bfa09..14349ba 100644 --- a/lib/permanent_records.rb +++ b/lib/permanent_records.rb @@ -51,7 +51,7 @@ def destroy(force = nil) if !is_permanent? || PermanentRecords.should_force_destroy?(force) permanently_delete_records_after { super() } else - destroy_with_permanent_records force + destroy_with_permanent_records(force) end end end @@ -68,7 +68,7 @@ def revival # rubocop:disable Metrics/MethodLength set_deleted_at(nil, validate) # increment all associated counters for counter cache each_counter_cache do |assoc_class, counter_cache_column, assoc_id| - assoc_class.increment_counter counter_cache_column, assoc_id + assoc_class.increment_counter(counter_cache_column, assoc_id) end true end @@ -116,9 +116,7 @@ def each_counter_cache associated_class = association.class - yield(associated_class, - reflection.counter_cache_column, - send(reflection.foreign_key)) + yield(associated_class, reflection.counter_cache_column, send(reflection.foreign_key)) end end @@ -131,7 +129,7 @@ def destroy_with_permanent_records(force = nil) set_deleted_at(Time.now, force) # decrement all associated counters for counter cache each_counter_cache do |assoc_class, counter_cache_column, assoc_id| - assoc_class.decrement_counter counter_cache_column, assoc_id + assoc_class.decrement_counter(counter_cache_column, assoc_id) end end true @@ -281,5 +279,5 @@ def self.dependent_permanent_reflections(klass) end ActiveSupport.on_load(:active_record) do - ActiveRecord::Base.send :include, PermanentRecords::ActiveRecord + ActiveRecord::Base.send(:include, PermanentRecords::ActiveRecord) end diff --git a/spec/permanent_records/circular_sti_dependency_spec.rb b/spec/permanent_records/circular_sti_dependency_spec.rb index b334567..9a56466 100644 --- a/spec/permanent_records/circular_sti_dependency_spec.rb +++ b/spec/permanent_records/circular_sti_dependency_spec.rb @@ -5,7 +5,7 @@ let(:dirt) { Dirt.create(hole: hole) } let(:location) { Location.create(name: 'location', hole: hole) } let!(:zone) do - location.zones.create name: 'zone', parent_id: location.id + location.zones.create(name: 'zone', parent_id: location.id) end describe '#revive' do diff --git a/spec/permanent_records/counter_cache_spec.rb b/spec/permanent_records/counter_cache_spec.rb index a5c9bc1..f3b0c55 100644 --- a/spec/permanent_records/counter_cache_spec.rb +++ b/spec/permanent_records/counter_cache_spec.rb @@ -15,7 +15,7 @@ end it 'decrements counter_cache after destroying ant' do - expect(hole.reload.ants_count).to eq 0 + expect(hole.reload.ants_count).to eq(0) end context 'revive' do @@ -24,7 +24,7 @@ end it 'increment counter_cache after reviving ant' do - expect(hole.reload.ants_count).to eq 1 + expect(hole.reload.ants_count).to eq(1) end end end @@ -40,7 +40,7 @@ end it 'increments counter_cache after creating new ant' do - expect(hole.ants_count).to eq 2 + expect(hole.ants_count).to eq(2) end end @@ -50,7 +50,7 @@ end it 'decrements counter_cache after destroying ant' do - expect(hole.reload.ants_count).to eq 0 + expect(hole.reload.ants_count).to eq(0) end context 'revive' do @@ -59,7 +59,7 @@ end it 'increment counter_cache after reviving ant' do - expect(hole.reload.ants_count).to eq 1 + expect(hole.reload.ants_count).to eq(1) end end end diff --git a/spec/permanent_records_spec.rb b/spec/permanent_records_spec.rb index 6d23dae..19ab10b 100644 --- a/spec/permanent_records_spec.rb +++ b/spec/permanent_records_spec.rb @@ -17,7 +17,7 @@ let(:record) { hole } let(:should_force) { false } - subject { record.destroy should_force } + subject { record.destroy(should_force) } it 'returns the record' do expect(subject).to eq(record) From a46dbf0d46d16f53659a47e692e557c6c26d309d Mon Sep 17 00:00:00 2001 From: msalzburg Date: Tue, 15 Oct 2019 12:27:15 +0200 Subject: [PATCH 25/31] Introduce rails 5.2 fix from Nancy Cai PR #100 --- lib/permanent_records.rb | 4 +++ lib/permanent_records/active_record_5_2.rb | 33 ++++++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 lib/permanent_records/active_record_5_2.rb diff --git a/lib/permanent_records.rb b/lib/permanent_records.rb index 14349ba..820c5f8 100644 --- a/lib/permanent_records.rb +++ b/lib/permanent_records.rb @@ -280,4 +280,8 @@ def self.dependent_permanent_reflections(klass) ActiveSupport.on_load(:active_record) do ActiveRecord::Base.send(:include, PermanentRecords::ActiveRecord) + + if [ActiveRecord::VERSION::MAJOR, ActiveRecord::VERSION::MINOR] == [5, 2] || ActiveRecord::VERSION::MAJOR > 5 + require 'permanent_records/active_record_5_2' + end end diff --git a/lib/permanent_records/active_record_5_2.rb b/lib/permanent_records/active_record_5_2.rb new file mode 100644 index 0000000..dec29e7 --- /dev/null +++ b/lib/permanent_records/active_record_5_2.rb @@ -0,0 +1,33 @@ +module HandlePermanentRecordsDestroyedInBelongsToAssociation + def handle_dependency + return unless load_target + + case options[:dependent] + when :destroy + target.destroy + raise ActiveRecord::Rollback if target.respond_to?(:deleted?) && !target.deleted? + else + target.send(options[:dependent]) + end + end +end + +module HandlePermanentRecordsDestroyedInHasOneAssociation + def delete(method = options[:dependent]) + return unless load_target + + 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? + end + end +end + +ActiveRecord::Associations::BelongsToAssociation.prepend(HandlePermanentRecordsDestroyedInBelongsToAssociation) +ActiveRecord::Associations::HasOneAssociation.prepend(HandlePermanentRecordsDestroyedInHasOneAssociation) From 1bf04926ed9af67bdc020ad60cef954e79fefc8d Mon Sep 17 00:00:00 2001 From: msalzburg Date: Tue, 15 Oct 2019 12:31:59 +0200 Subject: [PATCH 26/31] Silence rubocop by updating its todo file --- .rubocop_todo.yml | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 9122900..03539bc 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,7 +1,27 @@ # This configuration was generated by # `rubocop --auto-gen-config` -# on 2019-10-09 15:29:14 +0200 using RuboCop version 0.68.1. +# on 2019-10-15 12:31:22 +0200 using RuboCop version 0.68.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: 2 +Metrics/AbcSize: + Max: 21 + +# Offense count: 1 +Metrics/CyclomaticComplexity: + Max: 8 + +# Offense count: 1 +# Configuration parameters: CountComments, ExcludedMethods. +Metrics/MethodLength: + Max: 11 + +# Offense count: 2 +Style/Documentation: + Exclude: + - 'spec/**/*' + - 'test/**/*' + - 'lib/permanent_records/active_record_5_2.rb' From 486cbbc8e25cbc016b637369aa19324e4c29b968 Mon Sep 17 00:00:00 2001 From: msalzburg Date: Tue, 15 Oct 2019 13:29:44 +0200 Subject: [PATCH 27/31] Fix Style/Documentation cop --- .rubocop_todo.yml | 9 +-------- lib/permanent_records/active_record_5_2.rb | 2 ++ 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 03539bc..fed9c93 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 12:31:22 +0200 using RuboCop version 0.68.1. +# on 2019-10-15 13:29:16 +0200 using RuboCop version 0.68.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 @@ -18,10 +18,3 @@ Metrics/CyclomaticComplexity: # Configuration parameters: CountComments, ExcludedMethods. Metrics/MethodLength: Max: 11 - -# Offense count: 2 -Style/Documentation: - Exclude: - - 'spec/**/*' - - 'test/**/*' - - 'lib/permanent_records/active_record_5_2.rb' diff --git a/lib/permanent_records/active_record_5_2.rb b/lib/permanent_records/active_record_5_2.rb index dec29e7..ed511dd 100644 --- a/lib/permanent_records/active_record_5_2.rb +++ b/lib/permanent_records/active_record_5_2.rb @@ -1,3 +1,4 @@ +# Support destroy for rails belongs_to assocations. module HandlePermanentRecordsDestroyedInBelongsToAssociation def handle_dependency return unless load_target @@ -12,6 +13,7 @@ def handle_dependency end end +# Support destroy for rails 5.2. has_on associations. module HandlePermanentRecordsDestroyedInHasOneAssociation def delete(method = options[:dependent]) return unless load_target From 9eb7f691e9e53ac7c5cb69a1f07bec627b8a6875 Mon Sep 17 00:00:00 2001 From: msalzburg Date: Tue, 15 Oct 2019 13:32:35 +0200 Subject: [PATCH 28/31] Fix remaining cops by disabling them inline --- .rubocop_todo.yml | 15 +-------------- lib/permanent_records/active_record_5_2.rb | 7 ++++++- 2 files changed, 7 insertions(+), 15 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index fed9c93..5e87886 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,20 +1,7 @@ # This configuration was generated by # `rubocop --auto-gen-config` -# on 2019-10-15 13:29:16 +0200 using RuboCop version 0.68.1. +# on 2019-10-15 13:32:11 +0200 using RuboCop version 0.68.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: 2 -Metrics/AbcSize: - Max: 21 - -# Offense count: 1 -Metrics/CyclomaticComplexity: - Max: 8 - -# Offense count: 1 -# Configuration parameters: CountComments, ExcludedMethods. -Metrics/MethodLength: - Max: 11 diff --git a/lib/permanent_records/active_record_5_2.rb b/lib/permanent_records/active_record_5_2.rb index ed511dd..911d17a 100644 --- a/lib/permanent_records/active_record_5_2.rb +++ b/lib/permanent_records/active_record_5_2.rb @@ -1,3 +1,4 @@ +# rubocop:disable Metrics/AbcSize # Support destroy for rails belongs_to assocations. module HandlePermanentRecordsDestroyedInBelongsToAssociation def handle_dependency @@ -13,6 +14,8 @@ def handle_dependency end end +# rubocop:disable Metrics/MethodLength +# rubocop:disable Metrics/CyclomaticComplexity # Support destroy for rails 5.2. has_on associations. module HandlePermanentRecordsDestroyedInHasOneAssociation def delete(method = options[:dependent]) @@ -30,6 +33,8 @@ def delete(method = options[:dependent]) 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 3ca3fc5e8ef17759ff2b4e3e889320755925e3ab Mon Sep 17 00:00:00 2001 From: msalzburg Date: Tue, 15 Oct 2019 13:35:12 +0200 Subject: [PATCH 29/31] Update sqlite3 to newest patch version --- permanent_records.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/permanent_records.gemspec b/permanent_records.gemspec index 023d95b..5caada1 100644 --- a/permanent_records.gemspec +++ b/permanent_records.gemspec @@ -34,5 +34,5 @@ Gem::Specification.new do |s| 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-performance' - s.add_development_dependency 'sqlite3', '~> 1.3.6' # freeze to ensure specs are working + s.add_development_dependency 'sqlite3', '~> 1.3.13' # freeze to ensure specs are working end From 6a52c5fc0845381431c5b28b5127a6a7e80bdbf3 Mon Sep 17 00:00:00 2001 From: Jack Danger Date: Wed, 16 Oct 2019 12:19:33 -0700 Subject: [PATCH 30/31] Configuring GitHub Actions Running matrixed tests under GitHub Actions Deploying to Rubygems.org from GitHub Actions --- .github/workflows/gempush.yml | 28 ++++++++++++++++++++++++++++ .github/workflows/test.yml | 31 +++++++++++++++++++++++++++++++ bin/gempush-if-changed | 8 ++++++++ github-actions-test.yml | 1 + 4 files changed, 68 insertions(+) create mode 100644 .github/workflows/gempush.yml create mode 100644 .github/workflows/test.yml create mode 100755 bin/gempush-if-changed create mode 120000 github-actions-test.yml diff --git a/.github/workflows/gempush.yml b/.github/workflows/gempush.yml new file mode 100644 index 0000000..b7430dc --- /dev/null +++ b/.github/workflows/gempush.yml @@ -0,0 +1,28 @@ +name: Ruby Gem + +on: + push: + branches: + - master + +jobs: + build: + name: gem publishing + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@master + - name: Set up Ruby 2.6 + uses: actions/setup-ruby@v1 + with: + ruby-version: 2.6.x + + - name: Publish to RubyGems + run: | + mkdir -p $HOME/.gem + touch $HOME/.gem/credentials + chmod 0600 $HOME/.gem/credentials + printf -- "---\n:rubygems_api_key: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials + bin/gempush-if-changed + env: + GEM_HOST_API_KEY: ${{secrets.RUBYGEMS_AUTH_TOKEN}} diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..fcd9025 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,31 @@ +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: + - '4.2.0' + - '4.2.11.1' + 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/bin/gempush-if-changed b/bin/gempush-if-changed new file mode 100755 index 0000000..fdae54e --- /dev/null +++ b/bin/gempush-if-changed @@ -0,0 +1,8 @@ +#!/bin/bash + +set -x +if git diff --name-only HEAD..HEAD^ | egrep -q '^VERSION$'; then + # The VERSION file changed in the last commit, build the gem and push + gem build *.gemspec + gem push *.gem +fi diff --git a/github-actions-test.yml b/github-actions-test.yml new file mode 120000 index 0000000..576a5b4 --- /dev/null +++ b/github-actions-test.yml @@ -0,0 +1 @@ +.github/workflows/test.yml \ No newline at end of file From 07cfe2c505e4aa14d3db18fdcf9bab866098750d Mon Sep 17 00:00:00 2001 From: Jack Danger Date: Wed, 16 Oct 2019 14:35:49 -0700 Subject: [PATCH 31/31] only testing under Rails 5 --- .github/workflows/test.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index fcd9025..8a4b0f3 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -14,8 +14,9 @@ jobs: - '2.5.x' - '2.6.x' rails: - - '4.2.0' - - '4.2.11.1' + - '5.0.7.2' + - '5.1.7' + - '5.2.3' steps: - name: Install system dependencies run: sudo apt-get install -y libsqlite3-dev