archival_record 3.0.0 → 4.0.0

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.
Files changed (57) hide show
  1. checksums.yaml +4 -4
  2. data/.envrc +9 -0
  3. data/.gitignore +1 -1
  4. data/.rubocop.yml +1 -1
  5. data/Appraisals +14 -0
  6. data/CHANGELOG.md +16 -2
  7. data/Gemfile.lock +67 -47
  8. data/LICENSE +1 -1
  9. data/README.md +63 -31
  10. data/archival_record.gemspec +5 -3
  11. data/gemfiles/rails_6.0.gemfile +2 -0
  12. data/gemfiles/rails_6.1.gemfile +2 -0
  13. data/gemfiles/rails_7.0.gemfile +2 -0
  14. data/gemfiles/rails_7.2.gemfile +7 -0
  15. data/gemfiles/rails_8.0.gemfile +7 -0
  16. data/lib/archival_record/version.rb +1 -1
  17. data/lib/archival_record.rb +2 -9
  18. data/lib/archival_record_core/archival_record.rb +21 -8
  19. data/lib/archival_record_core/archival_record_active_record_methods.rb +1 -3
  20. data/lib/archival_record_core/association_operation/archive.rb +0 -4
  21. data/lib/archival_record_core/association_operation/base.rb +25 -2
  22. data/shell.nix +41 -0
  23. data/test/associations_test.rb +22 -2
  24. data/test/bogus_relation_test.rb +22 -0
  25. data/test/callbacks_test.rb +14 -33
  26. data/test/exception_test.rb +9 -0
  27. data/test/fixtures/another_polys_holder.rb +1 -1
  28. data/test/fixtures/archival.rb +13 -7
  29. data/test/fixtures/archival_grandkid.rb +1 -1
  30. data/test/fixtures/archival_kid.rb +1 -1
  31. data/test/fixtures/archival_table_name.rb +1 -1
  32. data/test/fixtures/bogus_relation.rb +6 -0
  33. data/test/fixtures/{callback_archival4.rb → callback_archival.rb} +3 -2
  34. data/test/fixtures/deprecated_warning_archival.rb +1 -1
  35. data/test/fixtures/exception_raiser.rb +11 -0
  36. data/test/fixtures/explicit_act_on_dependents_archival.rb +1 -1
  37. data/test/fixtures/exploder.rb +1 -1
  38. data/test/fixtures/ignorable_dependent.rb +1 -1
  39. data/test/fixtures/ignore_dependents_archival.rb +1 -1
  40. data/test/fixtures/independent_archival.rb +1 -1
  41. data/test/fixtures/many_many_archival.rb +9 -0
  42. data/test/fixtures/missing_archive_number.rb +1 -1
  43. data/test/fixtures/missing_archived_at.rb +1 -1
  44. data/test/fixtures/nonignorable_dependent.rb +1 -1
  45. data/test/fixtures/plain.rb +1 -1
  46. data/test/fixtures/poly.rb +1 -1
  47. data/test/fixtures/readonly_when_archived.rb +1 -1
  48. data/test/performance/the_test.rb +29 -0
  49. data/test/schema.rb +19 -12
  50. data/test/scope_test.rb +3 -9
  51. data/test/test_helper.rb +30 -29
  52. metadata +47 -13
  53. data/.gitlab-ci.yml +0 -20
  54. data/test/application_record_test.rb +0 -20
  55. data/test/fixtures/application_record_row.rb +0 -8
  56. data/test/fixtures/callback_archival5.rb +0 -23
  57. /data/test/{fixtures/application_record.rb → application_record.rb} +0 -0
@@ -3,6 +3,21 @@ module ArchivalRecordCore
3
3
  module AssociationOperation
4
4
  class Base
5
5
 
6
+ ACTIVE_RECORD_REQUIREMENT_DESTROY_ASYNC = Gem::Requirement.new(">= 6.1.0")
7
+
8
+ # :destroy_async was added as an option in rails 6.1 but seems very buggy there
9
+ # wrt to configuration
10
+ DEPENDENT_OPTIONS_TO_OPERATE_ON_RAILS_6_0 = %i[
11
+ destroy
12
+ delete_all
13
+ ].freeze
14
+
15
+ DEPENDENT_OPTIONS_TO_OPERATE_ON_RAILS = %i[
16
+ destroy
17
+ destroy_async
18
+ delete_all
19
+ ].freeze
20
+
6
21
  attr_reader :model, :head_archive_number
7
22
 
8
23
  def initialize(model, head_archive_number)
@@ -32,8 +47,16 @@ module ArchivalRecordCore
32
47
  association.options[:through].nil?
33
48
  end
34
49
 
35
- def association_conditions_met?(_association)
36
- true
50
+ def dependent_options_to_operate_on
51
+ if ACTIVE_RECORD_REQUIREMENT_DESTROY_ASYNC.satisfied_by?(ActiveRecord.version)
52
+ DEPENDENT_OPTIONS_TO_OPERATE_ON_RAILS
53
+ else
54
+ DEPENDENT_OPTIONS_TO_OPERATE_ON_RAILS_6_0
55
+ end
56
+ end
57
+
58
+ def association_conditions_met?(association)
59
+ dependent_options_to_operate_on.include?(association.options[:dependent])
37
60
  end
38
61
 
39
62
  def act_on_association(association)
data/shell.nix ADDED
@@ -0,0 +1,41 @@
1
+ {
2
+ lib ? import <lib> {},
3
+ pkgs ? import (fetchTarball channel:nixos-24.11) {}
4
+ }:
5
+
6
+ let
7
+
8
+ # define packages to install with special handling for OSX
9
+ basePackages = [
10
+ pkgs.gnumake
11
+ pkgs.gcc
12
+ pkgs.readline
13
+ pkgs.zlib
14
+ pkgs.libxml2
15
+ pkgs.libiconv
16
+ pkgs.libffi
17
+ pkgs.openssl
18
+ pkgs.curl
19
+ pkgs.git
20
+
21
+ pkgs.sqlite
22
+
23
+ pkgs.ruby_3_2
24
+ pkgs.bundler
25
+ ];
26
+
27
+ inputs = basePackages
28
+ ++ [ pkgs.bashInteractive ]
29
+ ++ pkgs.lib.optionals pkgs.stdenv.isLinux [ pkgs.inotify-tools ]
30
+ ++ pkgs.lib.optionals pkgs.stdenv.isDarwin (with pkgs.darwin.apple_sdk.frameworks; [
31
+ CoreFoundation
32
+ CoreServices
33
+ ]);
34
+
35
+ in pkgs.mkShell {
36
+ buildInputs = inputs;
37
+
38
+ shellHook = ''
39
+ export APP_HOME=$(pwd);
40
+ '';
41
+ }
@@ -11,6 +11,26 @@ class AssociationsTest < ActiveSupport::TestCase
11
11
  assert child.reload.archived?
12
12
  end
13
13
 
14
+ if ActiveRecord.version >= Gem::Version.new("6.1.0")
15
+ test "archive archives 'has_' associated archival objects that are dependent destroy_async" do
16
+ archival = Archival.create!
17
+ child = archival.archivals_destroy_async.create!
18
+ archival.archive!
19
+
20
+ assert archival.reload.archived?
21
+ assert child.reload.archived?
22
+ end
23
+ end
24
+
25
+ test "archive archives 'has_' associated archival objects that are dependent delete_all" do
26
+ archival = Archival.create!
27
+ child = archival.archivals_delete.create!
28
+ archival.archive!
29
+
30
+ assert archival.reload.archived?
31
+ assert child.reload.archived?
32
+ end
33
+
14
34
  test "archive acts on all objects in the 'has_' relationship" do
15
35
  archival = Archival.create!
16
36
  children = [archival.archivals.create!, archival.archivals.create!]
@@ -81,7 +101,7 @@ class AssociationsTest < ActiveSupport::TestCase
81
101
  assert prearchived_child.reload.archived?
82
102
  end
83
103
 
84
- test "unarchive acts on 'has_' associated non-dependent_destroy objects" do
104
+ test "unarchive does not act on 'has_' associated non-dependent_destroy objects" do
85
105
  archival = Archival.create!
86
106
  independent = archival.independent_archivals.create!
87
107
  archival.archive!
@@ -89,7 +109,7 @@ class AssociationsTest < ActiveSupport::TestCase
89
109
  archival.unarchive!
90
110
 
91
111
  assert_not archival.reload.archived?
92
- assert_not independent.reload.archived?
112
+ assert independent.reload.archived?
93
113
  end
94
114
 
95
115
  test "unarchive doesn't unarchive associated objects if the head object is already unarchived" do
@@ -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(ApplicationRecord.logger).error(
8
+ satisfy do |arg|
9
+ if arg.is_a?(String)
10
+ arg.match?(/\ASQLite3::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
@@ -2,40 +2,21 @@ require_relative "test_helper"
2
2
 
3
3
  class CallbacksTest < ActiveSupport::TestCase
4
4
 
5
- if defined?(ApplicationRecord)
6
- test "can set a value as part of archiving" do
7
- archival = CallbackArchival5.create
8
- archival.set_this_value = "a test string"
9
- assert_nil archival.settable_field
10
- archival.archive!
11
- assert_equal "a test string", archival.reload.settable_field
12
- end
13
-
14
- test "can be halted" do
15
- archival = CallbackArchival5.create
16
- archival.set_this_value = "a test string"
17
- archival.pass_callback = false
18
- assert_nil archival.settable_field
19
- archival.archive!
20
- assert_nil archival.reload.settable_field
21
- end
22
- else
23
- test "can set a value as part of archiving" do
24
- archival = CallbackArchival4.create
25
- archival.set_this_value = "a test string"
26
- assert_nil archival.settable_field
27
- archival.archive!
28
- assert_equal "a test string", archival.reload.settable_field
29
- end
5
+ test "can set a value as part of archiving" do
6
+ archival = CallbackArchival.create
7
+ archival.set_this_value = "a test string"
8
+ assert_nil archival.settable_field
9
+ archival.archive!
10
+ assert_equal "a test string", archival.reload.settable_field
11
+ end
30
12
 
31
- test "can be halted" do
32
- archival = CallbackArchival4.create
33
- archival.set_this_value = "a test string"
34
- archival.pass_callback = false
35
- assert_nil archival.settable_field
36
- archival.archive!
37
- assert_nil archival.reload.settable_field
38
- end
13
+ test "can be halted" do
14
+ archival = CallbackArchival.create
15
+ archival.set_this_value = "a test string"
16
+ archival.pass_callback = false
17
+ assert_nil archival.settable_field
18
+ archival.archive!
19
+ assert_nil archival.reload.settable_field
39
20
  end
40
21
 
41
22
  end
@@ -0,0 +1,9 @@
1
+ class ExceptionTest < ActiveSupport::TestCase
2
+
3
+ test "raises an exception when given that option" do
4
+ readonly = ExceptionRaiser.create!(archived_at: Time.now.utc, archive_number: "1")
5
+ readonly.readonly!
6
+ assert_raises(ActiveRecord::ReadOnlyRecord) { readonly.unarchive! }
7
+ end
8
+
9
+ end
@@ -2,7 +2,7 @@
2
2
  # archival_id - integer
3
3
  # archive_number - string
4
4
  # archived_at - datetime
5
- class AnotherPolysHolder < ActiveRecord::Base
5
+ class AnotherPolysHolder < ApplicationRecord
6
6
 
7
7
  archival_record
8
8
 
@@ -2,18 +2,24 @@
2
2
  # archival_id - integer
3
3
  # archive_number - string
4
4
  # archived_at - datetime
5
- class Archival < ActiveRecord::Base
5
+ class Archival < ApplicationRecord
6
6
 
7
7
  archival_record
8
8
 
9
- has_many :archivals, dependent: :destroy
10
- has_many :archival_kids, dependent: :destroy
11
- has_many :archival_grandkids, dependent: :destroy, through: :archival_kids
12
- has_many :exploders, dependent: :destroy
13
- has_many :plains, dependent: :destroy
14
- has_many :polys, dependent: :destroy, as: :archiveable
9
+ has_many :archivals, dependent: :destroy
10
+ if ActiveRecord.version >= Gem::Version.new("6.1.0")
11
+ has_many :archivals_destroy_async, dependent: :destroy_async, class_name: "Archival"
12
+ end
13
+ has_many :archivals_delete, dependent: :delete_all, class_name: "Archival"
14
+ has_many :archival_kids, dependent: :destroy
15
+ has_many :archival_grandkids, dependent: :destroy, through: :archival_kids
16
+ has_many :exploders, dependent: :destroy
17
+ has_many :plains, dependent: :destroy
18
+ has_many :polys, dependent: :destroy, as: :archiveable
15
19
  has_many :independent_archivals
16
20
 
21
+ has_and_belongs_to_many :many_many_archivals
22
+
17
23
  scope :bobs, -> { where(name: %w[Bob Bobby Robert]) }
18
24
 
19
25
  end
@@ -1,7 +1,7 @@
1
1
  # archival_kid_id - integer
2
2
  # archive_number - string
3
3
  # archived_at - datetime
4
- class ArchivalGrandkid < ActiveRecord::Base
4
+ class ArchivalGrandkid < ApplicationRecord
5
5
 
6
6
  archival_record
7
7
 
@@ -1,7 +1,7 @@
1
1
  # archival_id - integer
2
2
  # archive_number - string
3
3
  # archived_at - datetime
4
- class ArchivalKid < ActiveRecord::Base
4
+ class ArchivalKid < ApplicationRecord
5
5
 
6
6
  archival_record
7
7
 
@@ -1,7 +1,7 @@
1
1
  # name - string
2
2
  # archive_number - string
3
3
  # archived_at - datetime
4
- class ArchivalTableName < ActiveRecord::Base
4
+ class ArchivalTableName < ApplicationRecord
5
5
 
6
6
  self.table_name = "legacy"
7
7
 
@@ -0,0 +1,6 @@
1
+ class BogusRelation < ApplicationRecord
2
+
3
+ archival_record
4
+ has_many :bogus_relations, dependent: :destroy
5
+
6
+ end
@@ -1,4 +1,4 @@
1
- class CallbackArchival4 < ActiveRecord::Base
1
+ class CallbackArchival < ApplicationRecord
2
2
 
3
3
  archival_record
4
4
 
@@ -13,7 +13,8 @@ class CallbackArchival4 < ActiveRecord::Base
13
13
  end
14
14
 
15
15
  private def conditional_callback_passer
16
- pass_callback || pass_callback.nil?
16
+ # we want to throw only for the value false
17
+ throw(:abort) unless pass_callback || pass_callback.nil?
17
18
  end
18
19
 
19
20
  end
@@ -1,7 +1,7 @@
1
1
  # archival_id - integer
2
2
  # archive_number - string
3
3
  # archived_at - datetime
4
- class DeprecatedWarningArchival < ActiveRecord::Base
4
+ class DeprecatedWarningArchival < ApplicationRecord
5
5
 
6
6
  # This should throw a deprecation warning
7
7
  acts_as_archival
@@ -0,0 +1,11 @@
1
+ # name - string
2
+ # archival_id - integer
3
+ # archive_number - string
4
+ # archived_at - datetime
5
+ class ExceptionRaiser < ApplicationRecord
6
+
7
+ self.table_name = :archivals
8
+
9
+ archival_record raise_on_error: true
10
+
11
+ end
@@ -1,6 +1,6 @@
1
1
  # archive_number - string
2
2
  # archived_at - datetime
3
- class ExplicitActOnDependentsArchival < ActiveRecord::Base
3
+ class ExplicitActOnDependentsArchival < ApplicationRecord
4
4
 
5
5
  archival_record archive_dependents: true
6
6
 
@@ -1,7 +1,7 @@
1
1
  # archival_id - integer
2
2
  # archive_number - string
3
3
  # archived_at - datetime
4
- class Exploder < ActiveRecord::Base
4
+ class Exploder < ApplicationRecord
5
5
 
6
6
  archival_record
7
7
 
@@ -1,7 +1,7 @@
1
1
  # ignore_dependents_archival_id - integer
2
2
  # archive_number - string
3
3
  # archived_at - datetime
4
- class IgnorableDependent < ActiveRecord::Base
4
+ class IgnorableDependent < ApplicationRecord
5
5
 
6
6
  archival_record
7
7
 
@@ -1,6 +1,6 @@
1
1
  # archive_number - string
2
2
  # archived_at - datetime
3
- class IgnoreDependentsArchival < ActiveRecord::Base
3
+ class IgnoreDependentsArchival < ApplicationRecord
4
4
 
5
5
  archival_record archive_dependents: false
6
6
 
@@ -2,7 +2,7 @@
2
2
  # archival_id - integer
3
3
  # archive_number - string
4
4
  # archived_at - datetime
5
- class IndependentArchival < ActiveRecord::Base
5
+ class IndependentArchival < ApplicationRecord
6
6
 
7
7
  archival_record
8
8
 
@@ -0,0 +1,9 @@
1
+ # archive_number - string
2
+ # archived_at - datetime
3
+ class ManyManyArchival < ApplicationRecord
4
+
5
+ archival_record
6
+
7
+ has_and_belongs_to_many :archivals
8
+
9
+ end
@@ -1,6 +1,6 @@
1
1
  # name - string
2
2
  # archived_at - datetime
3
- class MissingArchiveNumber < ActiveRecord::Base
3
+ class MissingArchiveNumber < ApplicationRecord
4
4
 
5
5
  archival_record
6
6
 
@@ -1,6 +1,6 @@
1
1
  # name - string
2
2
  # archive_number - string
3
- class MissingArchivedAt < ActiveRecord::Base
3
+ class MissingArchivedAt < ApplicationRecord
4
4
 
5
5
  archival_record
6
6
 
@@ -1,7 +1,7 @@
1
1
  # explicit_act_on_dependents_archival_id - integer
2
2
  # archive_number - string
3
3
  # archived_at - datetime
4
- class NonignorableDependent < ActiveRecord::Base
4
+ class NonignorableDependent < ApplicationRecord
5
5
 
6
6
  archival_record
7
7
 
@@ -1,6 +1,6 @@
1
1
  # name - string
2
2
  # archival_id - integer
3
- class Plain < ActiveRecord::Base
3
+ class Plain < ApplicationRecord
4
4
 
5
5
  belongs_to :archival
6
6
 
@@ -2,7 +2,7 @@
2
2
  # archiveable_type - string
3
3
  # archive_number - string
4
4
  # archived_at - datetime
5
- class Poly < ActiveRecord::Base
5
+ class Poly < ApplicationRecord
6
6
 
7
7
  archival_record
8
8
 
@@ -1,7 +1,7 @@
1
1
  # name - string
2
2
  # archive_number - string
3
3
  # archived_at - datetime
4
- class ReadonlyWhenArchived < ActiveRecord::Base
4
+ class ReadonlyWhenArchived < ApplicationRecord
5
5
 
6
6
  archival_record readonly_when_archived: true
7
7
 
@@ -0,0 +1,29 @@
1
+ require_relative "../test_helper"
2
+
3
+ module Performance
4
+ class TheTest < ActiveSupport::TestCase
5
+
6
+ ### What is this?
7
+ ### Well currently it's a testing harness for checking indices but it's useful to have a
8
+ ### test to check things out. And this is that.
9
+
10
+ # test "performance tester" do
11
+ # puts "please hold, we are making ~10K records"
12
+
13
+ # percent_to_archive = 20
14
+ # records_to_make = 10_000
15
+
16
+ # records_to_make.times do
17
+ # archival = Archival.create!
18
+ # archival.archive! if rand(100) <= percent_to_archive
19
+ # end
20
+
21
+ # # Archival.archived.explain
22
+ # # Archival.unarchived.explain
23
+ # # binding.pry
24
+
25
+ # assert "we did it"
26
+ # end
27
+
28
+ end
29
+ end
data/test/schema.rb CHANGED
@@ -13,6 +13,9 @@ ActiveRecord::Schema.define(version: 1) do
13
13
  t.column :archived_at, :datetime
14
14
  end
15
15
 
16
+ add_index(:archivals, :archive_number)
17
+ add_index(:archivals, :archived_at)
18
+
16
19
  create_table :exploders, force: true do |t|
17
20
  t.column :archival_id, :integer
18
21
  t.column :archive_number, :string
@@ -71,18 +74,7 @@ ActiveRecord::Schema.define(version: 1) do
71
74
  t.column :archived_at, :datetime
72
75
  end
73
76
 
74
- create_table :application_record_rows, force: true do |t|
75
- t.column :archive_number, :string
76
- t.column :archived_at, :datetime
77
- end
78
-
79
- create_table :callback_archival4s, force: true do |t|
80
- t.column :settable_field, :string
81
- t.column :archive_number, :string
82
- t.column :archived_at, :datetime
83
- end
84
-
85
- create_table :callback_archival5s, force: true do |t|
77
+ create_table :callback_archivals, force: true do |t|
86
78
  t.column :settable_field, :string
87
79
  t.column :archive_number, :string
88
80
  t.column :archived_at, :datetime
@@ -115,4 +107,19 @@ ActiveRecord::Schema.define(version: 1) do
115
107
  t.column :archive_number, :string
116
108
  t.column :archived_at, :datetime
117
109
  end
110
+
111
+ create_table :bogus_relations, force: true do |t|
112
+ t.column :archive_number, :string
113
+ t.column :archived_at, :datetime
114
+ end
115
+
116
+ create_table :many_many_archivals, force: true do |t|
117
+ t.column :archive_number, :string
118
+ t.column :archived_at, :datetime
119
+ end
120
+
121
+ create_table :archivals_many_many_archivals, force: true do |t|
122
+ t.column :archival_id, :integer
123
+ t.column :many_many_archival_id, :integer
124
+ end
118
125
  end
data/test/scope_test.rb CHANGED
@@ -50,16 +50,10 @@ 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"."archive_number" IS NOT NULL'
61
55
  unarchived_sql = 'SELECT "legacy".* FROM "legacy" ' \
62
- 'WHERE "legacy"."archived_at" IS NULL AND "legacy"."archive_number" IS NULL'
56
+ 'WHERE "legacy"."archive_number" IS NULL'
63
57
  assert_equal archived_sql, ArchivalTableName.archived.to_sql
64
58
  assert_equal unarchived_sql, ArchivalTableName.unarchived.to_sql
65
59
  end
data/test/test_helper.rb CHANGED
@@ -1,10 +1,17 @@
1
1
  $LOAD_PATH.unshift("#{File.dirname(__FILE__)}/../lib")
2
2
 
3
3
  require "bundler/setup"
4
+ # you might be tempted to alphabetize this list of requires, but you should not.
5
+ # and logger definitely needs to go first or nearly first.
6
+ require "logger"
7
+
4
8
  require "minitest/autorun"
5
9
  require "minitest/pride"
10
+ require "pry"
6
11
 
12
+ require "active_job"
7
13
  require "active_record"
14
+ require_relative "application_record"
8
15
  require "database_cleaner"
9
16
 
10
17
  require "archival_record"
@@ -12,6 +19,7 @@ require "archival_record"
12
19
  ActiveSupport::TestCase.test_order = :random if ActiveSupport::TestCase.respond_to?(:test_order=)
13
20
 
14
21
  def prepare_for_tests
22
+ setup_active_job if ActiveRecord.version >= Gem::Version.new("6.1.0")
15
23
  setup_logging
16
24
  setup_database_cleaner
17
25
  create_test_tables
@@ -19,9 +27,15 @@ def prepare_for_tests
19
27
  end
20
28
 
21
29
  def setup_logging
22
- require "logger"
30
+ return if ENV["AR_LOGGER"] != "1"
31
+
23
32
  logfile = "#{File.dirname(__FILE__)}/debug.log"
24
- ActiveRecord::Base.logger = Logger.new(logfile)
33
+ ApplicationRecord.logger = Logger.new(logfile)
34
+ end
35
+
36
+ def setup_active_job
37
+ # usually rails does this for you but we don't have rails do we
38
+ ActiveRecord::Base.destroy_association_async_job = ActiveRecord::DestroyAssociationAsyncJob
25
39
  end
26
40
 
27
41
  def setup_database_cleaner
@@ -46,38 +60,32 @@ end
46
60
 
47
61
  def create_test_tables
48
62
  puts "** Loading schema for SQLite"
49
- ActiveRecord::Base.establish_connection(sqlite_config)
63
+ ApplicationRecord.establish_connection(sqlite_config)
50
64
  load(schema_file) if File.exist?(schema_file)
51
65
  end
52
66
 
53
- BASE_FIXTURE_CLASSES = %I[
67
+ FIXTURE_CLASSES = %I[
54
68
  another_polys_holder
55
69
  archival
56
- archival_kid
57
70
  archival_grandkid
71
+ archival_kid
58
72
  archival_table_name
73
+ bogus_relation
74
+ callback_archival
75
+ deprecated_warning_archival
76
+ exception_raiser
77
+ explicit_act_on_dependents_archival
59
78
  exploder
79
+ ignorable_dependent
80
+ ignore_dependents_archival
60
81
  independent_archival
61
- missing_archived_at
82
+ many_many_archival
62
83
  missing_archive_number
84
+ missing_archived_at
85
+ nonignorable_dependent
63
86
  plain
64
87
  poly
65
88
  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
89
  ].freeze
82
90
 
83
91
  def require_test_classes
@@ -85,14 +93,7 @@ def require_test_classes
85
93
  inflect.irregular "poly", "polys"
86
94
  end
87
95
 
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}" }
96
+ FIXTURE_CLASSES.each { |test_class_file| require_relative "fixtures/#{test_class_file}" }
96
97
  end
97
98
 
98
99
  prepare_for_tests