archival_record 3.0.0 → 3.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d4b5a4d0030a23027b25b835935225c690a2d5badb2c80e1d37a145fd583e55c
4
- data.tar.gz: 4a2e5a720bdab5cf97297cc66d9289f1beeced5d6c632d5c969816467a9928a4
3
+ metadata.gz: de698cb4c6c28dbc975343cbb8c64040423a401fe1963486e4d43feacdaf70fd
4
+ data.tar.gz: 423dc258212a7b8ff4fb78a6acc29bc979846820c50263859e0d9d2a9e634c81
5
5
  SHA512:
6
- metadata.gz: a989cbb3679373d79edec6e55f8393ba1c32ea8ee4cdea237b848a867208d436127cfb7465d50344c2fa45a05bb32917d2acd8282d010523c721fd3b7731285c
7
- data.tar.gz: 4cefa4eac2f34e69c40029979760173db1c1d24852b3db8368e077fb60a78a592597d876f4ebc4875c4312f81bea55cab6b39cadce0fc05ecdee586951e678d4
6
+ metadata.gz: a24054ef6cd9fc3ed12233e10e11fa194e26f72499534925bdd4d4bad05b9245bb994763ba6b449b7100e48dda00ce30de641b51f9d6a797697fba2805335f84
7
+ data.tar.gz: 3dab3e39d40c31fcfe60129b8eb9a3fb420be3ece65c18a7bfa3da367026b9c44ecee1e4b721ea71bd28cc85920308d427d391ddab10e2a0a82e1e2203e9ff30
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 3.0.1 - June 10, 2024
4
+ * a few more tidying items like fixing up some raw sql in a query to be arel
5
+ * changing a logging method to use error instead of debug so it surfaces more easily
6
+
3
7
  ## 3.0.0 - June 10, 2024
4
8
  * **BREAKING CHANGE** Drop support for rails 5 - see `rails__4.x-and-5.x` branch for relevant code
5
9
  * **BREAKING CHANGE** Drop support for Ruby 2.x
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- archival_record (3.0.0)
4
+ archival_record (3.0.1)
5
5
  activerecord (>= 6.0)
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -20,13 +20,13 @@ Gemfile:
20
20
 
21
21
  `gem "archival_record"`
22
22
 
23
- Any models you want to be archival should have the columns `archive_number` (String) and `archived_at` (DateTime).
23
+ Any models you want to be archival should have the columns `archive_number` (`String`) and `archived_at` (`DateTime`).
24
24
 
25
25
  i.e. `rails g migration AddArchivalRecordToPost archive_number archived_at:datetime`
26
26
 
27
27
  Any dependent-destroy ArchivalRecord model associated to an ArchivalRecord model will be archived with its parent.
28
28
 
29
- _If you're stuck on Rails 4.0x/3x/2x, check out the older tags/branches, which are no longer in active development._
29
+ _If you're stuck on Rails 5x/4x/3x/2x, check out the older tags/branches, which are no longer in active development._
30
30
 
31
31
  ## Example
32
32
 
@@ -23,7 +23,7 @@ Gem::Specification.new do |gem|
23
23
  "Elijah Miller"]
24
24
  gem.email = ["joel.meador+archival_record@gmail.com"]
25
25
  gem.homepage = "https://gitlab.com/joelmeador/archival_record/"
26
- gem.licenses = ['MIT']
26
+ gem.licenses = ["MIT"]
27
27
 
28
28
  gem.files = `git ls-files`.split("\n")
29
29
  gem.require_paths = ["lib"]
@@ -1,5 +1,5 @@
1
1
  module ArchivalRecord
2
2
 
3
- VERSION = "3.0.0".freeze
3
+ VERSION = "3.0.1".freeze
4
4
 
5
5
  end
@@ -55,9 +55,13 @@ module ArchivalRecordCore
55
55
  private def setup_scopes
56
56
  scope :archived, -> { where.not(archived_at: nil).where.not(archive_number: nil) }
57
57
  scope :unarchived, -> { where(archived_at: nil, archive_number: nil) }
58
- scope :archived_from_archive_number, (lambda do |head_archive_number|
59
- where(["archived_at IS NOT NULL AND archive_number = ?", head_archive_number])
60
- end)
58
+ scope :archived_from_archive_number,
59
+ (lambda do |head_archive_number|
60
+ table = arel_table
61
+ archive_at_check = table[:archived_at].not_eq(nil)
62
+ archive_number_check = table[:archive_number].eq(head_archive_number)
63
+ where(archive_at_check.and(archive_number_check))
64
+ end)
61
65
  end
62
66
 
63
67
  private def setup_callbacks
@@ -166,8 +170,8 @@ module ArchivalRecordCore
166
170
  end
167
171
 
168
172
  private def handle_archival_action_exception(exception)
169
- ActiveRecord::Base.logger.try(:debug, exception.message)
170
- ActiveRecord::Base.logger.try(:debug, exception.backtrace)
173
+ ActiveRecord::Base.logger.try(:error, exception.message)
174
+ ActiveRecord::Base.logger.try(:error, exception.backtrace)
171
175
  raise(ActiveRecord::Rollback)
172
176
  end
173
177
 
@@ -0,0 +1,22 @@
1
+ require_relative "test_helper"
2
+
3
+ class BogusRelationTest < ActiveSupport::TestCase
4
+
5
+ test "does not successfully archive" do
6
+ archival = BogusRelation.create!
7
+ stub(ActiveRecord::Base.logger).error(
8
+ satisfy do |arg|
9
+ if arg.is_a?(String)
10
+ arg == "SQLite3::SQLException: no such column: bogus_relations.bogus_relation_id"
11
+ elsif arg.is_a?(Array)
12
+ arg.join.match?(%r{gems/activerecord}) # this is gonna be in the stack trace somewhere
13
+ else
14
+ raise "unexpected logging"
15
+ end
16
+ end
17
+ )
18
+ assert_not archival.archive!
19
+ assert_not archival.reload.archived?
20
+ end
21
+
22
+ end
@@ -0,0 +1,6 @@
1
+ class BogusRelation < ApplicationRecord
2
+
3
+ archival_record
4
+ has_many :bogus_relations, dependent: :destroy
5
+
6
+ end
data/test/schema.rb CHANGED
@@ -115,4 +115,9 @@ ActiveRecord::Schema.define(version: 1) do
115
115
  t.column :archive_number, :string
116
116
  t.column :archived_at, :datetime
117
117
  end
118
+
119
+ create_table :bogus_relations, force: true do |t|
120
+ t.column :archive_number, :string
121
+ t.column :archived_at, :datetime
122
+ end
118
123
  end
data/test/scope_test.rb CHANGED
@@ -50,14 +50,8 @@ class ScopeTest < ActiveSupport::TestCase
50
50
  end
51
51
 
52
52
  test "table_name is set to 'legacy'" do
53
- archived_sql =
54
- if ActiveRecord.version >= Gem::Version.new("5.2.0")
55
- 'SELECT "legacy".* FROM "legacy" ' \
56
- 'WHERE "legacy"."archived_at" IS NOT NULL AND "legacy"."archive_number" IS NOT NULL'
57
- else
58
- 'SELECT "legacy".* FROM "legacy" ' \
59
- 'WHERE ("legacy"."archived_at" IS NOT NULL) AND ("legacy"."archive_number" IS NOT NULL)'
60
- end
53
+ archived_sql = 'SELECT "legacy".* FROM "legacy" ' \
54
+ 'WHERE "legacy"."archived_at" IS NOT NULL AND "legacy"."archive_number" IS NOT NULL'
61
55
  unarchived_sql = 'SELECT "legacy".* FROM "legacy" ' \
62
56
  'WHERE "legacy"."archived_at" IS NULL AND "legacy"."archive_number" IS NULL'
63
57
  assert_equal archived_sql, ArchivalTableName.archived.to_sql
data/test/test_helper.rb CHANGED
@@ -50,34 +50,28 @@ def create_test_tables
50
50
  load(schema_file) if File.exist?(schema_file)
51
51
  end
52
52
 
53
- BASE_FIXTURE_CLASSES = %I[
53
+ FIXTURE_CLASSES = %I[
54
54
  another_polys_holder
55
+ application_record
56
+ application_record_row
55
57
  archival
56
- archival_kid
57
58
  archival_grandkid
59
+ archival_kid
58
60
  archival_table_name
61
+ bogus_relation
62
+ callback_archival
63
+ deprecated_warning_archival
64
+ explicit_act_on_dependents_archival
59
65
  exploder
66
+ ignorable_dependent
67
+ ignore_dependents_archival
60
68
  independent_archival
61
- missing_archived_at
62
69
  missing_archive_number
70
+ missing_archived_at
71
+ nonignorable_dependent
63
72
  plain
64
73
  poly
65
74
  readonly_when_archived
66
- deprecated_warning_archival
67
- ignore_dependents_archival
68
- ignorable_dependent
69
- explicit_act_on_dependents_archival
70
- nonignorable_dependent
71
- ].freeze
72
-
73
- RAILS_4_FIXTURE_CLASSES = %I[
74
- callback_archival4
75
- ].freeze
76
-
77
- RAILS_5_FIXTURE_CLASSES = %I[
78
- application_record
79
- application_record_row
80
- callback_archival5
81
75
  ].freeze
82
76
 
83
77
  def require_test_classes
@@ -85,14 +79,7 @@ def require_test_classes
85
79
  inflect.irregular "poly", "polys"
86
80
  end
87
81
 
88
- fixtures = if ActiveRecord::VERSION::MAJOR >= 4
89
- RAILS_5_FIXTURE_CLASSES
90
- else
91
- RAILS_4_FIXTURE_CLASSES
92
- end
93
-
94
- fixtures += BASE_FIXTURE_CLASSES
95
- fixtures.each { |test_class_file| require_relative "fixtures/#{test_class_file}" }
82
+ FIXTURE_CLASSES.each { |test_class_file| require_relative "fixtures/#{test_class_file}" }
96
83
  end
97
84
 
98
85
  prepare_for_tests
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: archival_record
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.0
4
+ version: 3.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joel Meador
@@ -195,6 +195,7 @@ files:
195
195
  - test/archive_dependents_option_test.rb
196
196
  - test/associations_test.rb
197
197
  - test/basic_test.rb
198
+ - test/bogus_relation_test.rb
198
199
  - test/callbacks_test.rb
199
200
  - test/column_test.rb
200
201
  - test/deep_nesting_test.rb
@@ -206,8 +207,8 @@ files:
206
207
  - test/fixtures/archival_grandkid.rb
207
208
  - test/fixtures/archival_kid.rb
208
209
  - test/fixtures/archival_table_name.rb
209
- - test/fixtures/callback_archival4.rb
210
- - test/fixtures/callback_archival5.rb
210
+ - test/fixtures/bogus_relation.rb
211
+ - test/fixtures/callback_archival.rb
211
212
  - test/fixtures/deprecated_warning_archival.rb
212
213
  - test/fixtures/explicit_act_on_dependents_archival.rb
213
214
  - test/fixtures/exploder.rb
@@ -1,19 +0,0 @@
1
- class CallbackArchival4 < ActiveRecord::Base
2
-
3
- archival_record
4
-
5
- attr_accessor :set_this_value,
6
- :pass_callback
7
-
8
- before_archive :set_value,
9
- :conditional_callback_passer
10
-
11
- private def set_value
12
- self.settable_field = set_this_value
13
- end
14
-
15
- private def conditional_callback_passer
16
- pass_callback || pass_callback.nil?
17
- end
18
-
19
- end