acts_as_archival 1.1.1 → 2.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.
- checksums.yaml +5 -5
- data/.gitignore +1 -1
- data/.rubocop.yml +71 -0
- data/.rubocop_todo.yml +98 -0
- data/.travis.yml +23 -0
- data/Appraisals +7 -7
- data/CHANGELOG.md +29 -0
- data/Gemfile.lock +70 -0
- data/README.md +49 -19
- data/Rakefile +6 -3
- data/acts_as_archival.gemspec +23 -17
- data/gemfiles/rails_5.2.gemfile +8 -0
- data/gemfiles/{rails_4.2.gemfile → rails_6.0.gemfile} +2 -2
- data/gemfiles/{rails_5.0.gemfile → rails_6.1.gemfile} +2 -2
- data/lib/acts_as_archival/version.rb +3 -1
- data/lib/acts_as_archival.rb +2 -0
- data/lib/expected_behavior/acts_as_archival.rb +111 -77
- data/lib/expected_behavior/acts_as_archival_active_record_methods.rb +29 -4
- data/lib/expected_behavior/association_operation/archive.rb +1 -1
- data/lib/expected_behavior/association_operation/base.rb +12 -9
- data/lib/expected_behavior/association_operation/unarchive.rb +2 -2
- data/script/setup +0 -3
- data/test/ambiguous_table_test.rb +3 -1
- data/test/application_record_test.rb +5 -3
- data/test/associations_test.rb +19 -17
- data/test/basic_test.rb +16 -14
- data/test/callbacks_test.rb +8 -6
- data/test/column_test.rb +8 -6
- data/test/deep_nesting_test.rb +6 -4
- data/test/fixtures/another_polys_holder.rb +11 -0
- data/test/fixtures/application_record.rb +2 -0
- data/test/fixtures/application_record_row.rb +2 -0
- data/test/fixtures/archival.rb +9 -7
- data/test/fixtures/archival_grandkid.rb +2 -0
- data/test/fixtures/archival_kid.rb +3 -1
- data/test/fixtures/archival_table_name.rb +2 -0
- data/test/fixtures/callback_archival_4.rb +2 -0
- data/test/fixtures/callback_archival_5.rb +4 -1
- data/test/fixtures/exploder.rb +2 -0
- data/test/fixtures/independent_archival.rb +2 -0
- data/test/fixtures/missing_archive_number.rb +2 -0
- data/test/fixtures/missing_archived_at.rb +2 -0
- data/test/fixtures/plain.rb +2 -0
- data/test/fixtures/poly.rb +3 -1
- data/test/fixtures/readonly_when_archived.rb +3 -1
- data/test/polymorphic_test.rb +29 -4
- data/test/readonly_when_archived_test.rb +6 -4
- data/test/relations_test.rb +63 -0
- data/test/responds_test.rb +8 -6
- data/test/schema.rb +64 -77
- data/test/scope_test.rb +28 -23
- data/test/test_helper.rb +47 -40
- data/test/through_association_test.rb +4 -2
- data/test/transaction_test.rb +7 -58
- metadata +33 -50
- data/gemfiles/rails_4.1.gemfile +0 -8
- data/script/db_setup +0 -51
- data/test/database.yml +0 -26
- data/test/fixtures/mass_attribute_protected.rb +0 -7
- data/test/fixtures/mysql_archival.rb +0 -10
- data/test/fixtures/mysql_exploder.rb +0 -9
- data/test/fixtures/pg_archival.rb +0 -10
- data/test/fixtures/pg_exploder.rb +0 -9
- data/test/mass_attribute_test.rb +0 -20
data/test/deep_nesting_test.rb
CHANGED
@@ -1,11 +1,12 @@
|
|
1
1
|
require_relative "test_helper"
|
2
2
|
|
3
3
|
class DeepNestingTest < ActiveSupport::TestCase
|
4
|
+
|
4
5
|
test "archiving deeply nested items" do
|
5
6
|
archival = Archival.create!
|
6
7
|
child = archival.archivals.create!
|
7
8
|
grandchild = child.archivals.create!
|
8
|
-
archival.archive
|
9
|
+
archival.archive!
|
9
10
|
assert archival.reload.archived?
|
10
11
|
assert child.reload.archived?
|
11
12
|
assert grandchild.reload.archived?
|
@@ -15,15 +16,16 @@ class DeepNestingTest < ActiveSupport::TestCase
|
|
15
16
|
|
16
17
|
test "unarchiving deeply nested items doesn't blow up" do
|
17
18
|
archival_attributes = {
|
18
|
-
:
|
19
|
-
:
|
19
|
+
archived_at: Time.now,
|
20
|
+
archive_number: "test"
|
20
21
|
}
|
21
22
|
archival = Archival.create!(archival_attributes)
|
22
23
|
child = archival.archivals.create!(archival_attributes)
|
23
24
|
grandchild = child.archivals.create!(archival_attributes)
|
24
|
-
archival.unarchive
|
25
|
+
archival.unarchive!
|
25
26
|
assert_not archival.reload.archived?
|
26
27
|
assert_not child.reload.archived?
|
27
28
|
assert_not grandchild.reload.archived?
|
28
29
|
end
|
30
|
+
|
29
31
|
end
|
data/test/fixtures/archival.rb
CHANGED
@@ -3,15 +3,17 @@
|
|
3
3
|
# archive_number - string
|
4
4
|
# archived_at - datetime
|
5
5
|
class Archival < ActiveRecord::Base
|
6
|
+
|
6
7
|
acts_as_archival
|
7
8
|
|
8
|
-
has_many :archivals, :
|
9
|
-
has_many :archival_kids, :
|
10
|
-
has_many :archival_grandkids, :
|
11
|
-
has_many :exploders, :
|
12
|
-
has_many :plains, :
|
13
|
-
has_many :polys, :
|
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
|
14
15
|
has_many :independent_archivals
|
15
16
|
|
16
|
-
scope :bobs,
|
17
|
+
scope :bobs, -> { where(name: %w[Bob Bobby Robert]) }
|
18
|
+
|
17
19
|
end
|
@@ -1,4 +1,5 @@
|
|
1
1
|
class CallbackArchival4 < ActiveRecord::Base
|
2
|
+
|
2
3
|
acts_as_archival
|
3
4
|
|
4
5
|
attr_accessor :set_this_value,
|
@@ -14,4 +15,5 @@ class CallbackArchival4 < ActiveRecord::Base
|
|
14
15
|
private def conditional_callback_passer
|
15
16
|
pass_callback || pass_callback.nil?
|
16
17
|
end
|
18
|
+
|
17
19
|
end
|
@@ -1,6 +1,7 @@
|
|
1
1
|
# necessary for ApplicationRecord
|
2
2
|
if defined?(ApplicationRecord)
|
3
3
|
class CallbackArchival5 < ApplicationRecord
|
4
|
+
|
4
5
|
acts_as_archival
|
5
6
|
|
6
7
|
attr_accessor :set_this_value,
|
@@ -14,7 +15,9 @@ if defined?(ApplicationRecord)
|
|
14
15
|
end
|
15
16
|
|
16
17
|
private def conditional_callback_passer
|
17
|
-
throw
|
18
|
+
# we want to throw only for the value false
|
19
|
+
throw(:abort) unless pass_callback || pass_callback.nil?
|
18
20
|
end
|
21
|
+
|
19
22
|
end
|
20
23
|
end
|
data/test/fixtures/exploder.rb
CHANGED
data/test/fixtures/plain.rb
CHANGED
data/test/fixtures/poly.rb
CHANGED
data/test/polymorphic_test.rb
CHANGED
@@ -1,25 +1,50 @@
|
|
1
1
|
require_relative "test_helper"
|
2
2
|
|
3
3
|
class PolymorphicTest < ActiveSupport::TestCase
|
4
|
+
|
4
5
|
test "archive item with polymorphic association" do
|
5
6
|
archival = Archival.create!
|
6
7
|
poly = archival.polys.create!
|
7
|
-
archival.archive
|
8
|
+
archival.archive!
|
8
9
|
|
9
10
|
assert archival.reload.archived?
|
10
11
|
assert poly.reload.archived?
|
11
12
|
end
|
12
13
|
|
14
|
+
test "does not archive polymorphic association of different item with same id" do
|
15
|
+
archival = Archival.create!
|
16
|
+
another_polys_holder = AnotherPolysHolder.create!(id: archival.id)
|
17
|
+
poly = another_polys_holder.polys.create!
|
18
|
+
archival.archive!
|
19
|
+
|
20
|
+
assert_not poly.reload.archived?
|
21
|
+
end
|
22
|
+
|
13
23
|
test "unarchive item with polymorphic association" do
|
14
24
|
archive_attributes = {
|
15
|
-
:
|
16
|
-
:
|
25
|
+
archive_number: "test",
|
26
|
+
archived_at: Time.now
|
17
27
|
}
|
18
28
|
archival = Archival.create!(archive_attributes)
|
19
29
|
poly = archival.polys.create!(archive_attributes)
|
20
|
-
archival.unarchive
|
30
|
+
archival.unarchive!
|
21
31
|
|
22
32
|
assert_not archival.reload.archived?
|
23
33
|
assert_not poly.reload.archived?
|
24
34
|
end
|
35
|
+
|
36
|
+
test "does not unarchive polymorphic association of different item with same id" do
|
37
|
+
archive_attributes = {
|
38
|
+
archive_number: "test",
|
39
|
+
archived_at: Time.now
|
40
|
+
}
|
41
|
+
|
42
|
+
archival = Archival.create!(archive_attributes)
|
43
|
+
another_polys_holder = AnotherPolysHolder.create!(archive_attributes.merge(id: archival.id))
|
44
|
+
poly = another_polys_holder.polys.create!(archive_attributes)
|
45
|
+
archival.unarchive!
|
46
|
+
|
47
|
+
assert poly.reload.archived?
|
48
|
+
end
|
49
|
+
|
25
50
|
end
|
@@ -1,9 +1,10 @@
|
|
1
1
|
require_relative "test_helper"
|
2
2
|
|
3
3
|
class ReadonlyWhenArchivedTest < ActiveSupport::TestCase
|
4
|
+
|
4
5
|
test "acts_as_archival objects can normally be altered after archive" do
|
5
|
-
archival = Archival.create!(:
|
6
|
-
archival.archive
|
6
|
+
archival = Archival.create!(name: "original")
|
7
|
+
archival.archive!
|
7
8
|
archival.name = "updated"
|
8
9
|
archival.save!
|
9
10
|
|
@@ -11,12 +12,13 @@ class ReadonlyWhenArchivedTest < ActiveSupport::TestCase
|
|
11
12
|
end
|
12
13
|
|
13
14
|
test "acts_as_archival marked as readonly_when_archived cannot be updated after archive" do
|
14
|
-
archival = ReadonlyWhenArchived.create!(:
|
15
|
-
archival.archive
|
15
|
+
archival = ReadonlyWhenArchived.create!(name: "original")
|
16
|
+
archival.archive!
|
16
17
|
archival.name = "updated"
|
17
18
|
|
18
19
|
assert_not archival.save
|
19
20
|
assert_equal "Cannot modify an archived record.",
|
20
21
|
archival.errors.full_messages.first
|
21
22
|
end
|
23
|
+
|
22
24
|
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
require_relative "test_helper"
|
2
|
+
|
3
|
+
class RelationsTest < ActiveSupport::TestCase
|
4
|
+
|
5
|
+
test "archive_all! archives all records in an AR Association" do
|
6
|
+
3.times { Archival.create! }
|
7
|
+
|
8
|
+
archivals = Archival.all
|
9
|
+
archivals.archive_all!
|
10
|
+
assert archivals.first.archived?
|
11
|
+
assert archivals.last.archived?
|
12
|
+
end
|
13
|
+
|
14
|
+
test "archive_all! archives all records with the same archival number" do
|
15
|
+
3.times { Archival.create! }
|
16
|
+
|
17
|
+
archivals = Archival.all
|
18
|
+
archivals.archive_all!
|
19
|
+
assert_equal archivals.first.archive_number, archivals.last.archive_number
|
20
|
+
end
|
21
|
+
|
22
|
+
test "archive_all! archives children records" do
|
23
|
+
3.times do
|
24
|
+
parent = Archival.create!
|
25
|
+
2.times do
|
26
|
+
parent.archivals.create!
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
parents = Archival.all
|
31
|
+
parents.archive_all!
|
32
|
+
|
33
|
+
assert parents.first.archivals.first.archived?
|
34
|
+
assert parents.first.archivals.last.archived?
|
35
|
+
end
|
36
|
+
|
37
|
+
test "unarchive_all! unarchives all records in an AR Assocation" do
|
38
|
+
3.times { Archival.create! }
|
39
|
+
|
40
|
+
archivals = Archival.all
|
41
|
+
archivals.archive_all!
|
42
|
+
archivals.unarchive_all!
|
43
|
+
assert_not archivals.first.archived?
|
44
|
+
assert_not archivals.last.archived?
|
45
|
+
end
|
46
|
+
|
47
|
+
test "unarchive_all! unarchives children records" do
|
48
|
+
3.times do
|
49
|
+
parent = Archival.create!
|
50
|
+
2.times do
|
51
|
+
parent.archivals.create!
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
parents = Archival.all
|
56
|
+
parents.archive_all!
|
57
|
+
parents.unarchive_all!
|
58
|
+
|
59
|
+
assert_not parents.first.archivals.first.archived?
|
60
|
+
assert_not parents.first.archivals.last.archived?
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|
data/test/responds_test.rb
CHANGED
@@ -1,13 +1,15 @@
|
|
1
1
|
require_relative "test_helper"
|
2
2
|
|
3
3
|
class RespondsTest < ActiveSupport::TestCase
|
4
|
-
|
5
|
-
|
6
|
-
|
4
|
+
|
5
|
+
test "archival class responds correctly to 'archival?'" do
|
6
|
+
assert Archival.archival?
|
7
|
+
assert_not Plain.archival?
|
7
8
|
end
|
8
9
|
|
9
|
-
test "archival object responds correctly to '
|
10
|
-
assert Archival.new.
|
11
|
-
assert_not Plain.new.
|
10
|
+
test "archival object responds correctly to 'archival?'" do
|
11
|
+
assert Archival.new.archival?
|
12
|
+
assert_not Plain.new.archival?
|
12
13
|
end
|
14
|
+
|
13
15
|
end
|
data/test/schema.rb
CHANGED
@@ -1,103 +1,90 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
1
|
+
ActiveRecord::Schema.define(version: 1) do
|
2
|
+
create_table :another_polys_holders, force: true do |t|
|
3
|
+
t.column :name, :string
|
4
|
+
t.column :archival_id, :integer
|
5
|
+
t.column :archive_number, :string
|
6
|
+
t.column :archived_at, :datetime
|
6
7
|
end
|
7
|
-
end
|
8
8
|
|
9
|
-
|
10
|
-
create_table :archivals, :force => true do |t|
|
9
|
+
create_table :archivals, force: true do |t|
|
11
10
|
t.column :name, :string
|
12
11
|
t.column :archival_id, :integer
|
13
12
|
t.column :archive_number, :string
|
14
13
|
t.column :archived_at, :datetime
|
15
14
|
end
|
16
15
|
|
17
|
-
create_table :exploders, :
|
16
|
+
create_table :exploders, force: true do |t|
|
18
17
|
t.column :archival_id, :integer
|
19
18
|
t.column :archive_number, :string
|
20
19
|
t.column :archived_at, :datetime
|
21
20
|
end
|
22
21
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
create_table :archival_kids, :force => true do |t|
|
29
|
-
t.column :archival_id, :integer
|
30
|
-
t.column :archive_number, :string
|
31
|
-
t.column :archived_at, :datetime
|
32
|
-
end
|
33
|
-
|
34
|
-
create_table :archival_grandkids, :force => true do |t|
|
35
|
-
t.column :archival_kid_id, :integer
|
36
|
-
t.column :archive_number, :string
|
37
|
-
t.column :archived_at, :datetime
|
38
|
-
end
|
22
|
+
create_table :archival_kids, force: true do |t|
|
23
|
+
t.column :archival_id, :integer
|
24
|
+
t.column :archive_number, :string
|
25
|
+
t.column :archived_at, :datetime
|
26
|
+
end
|
39
27
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
end
|
28
|
+
create_table :archival_grandkids, force: true do |t|
|
29
|
+
t.column :archival_kid_id, :integer
|
30
|
+
t.column :archive_number, :string
|
31
|
+
t.column :archived_at, :datetime
|
32
|
+
end
|
46
33
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
34
|
+
create_table :independent_archivals, force: true do |t|
|
35
|
+
t.column :name, :string
|
36
|
+
t.column :archival_id, :integer
|
37
|
+
t.column :archive_number, :string
|
38
|
+
t.column :archived_at, :datetime
|
39
|
+
end
|
51
40
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
end
|
41
|
+
create_table :plains, force: true do |t|
|
42
|
+
t.column :name, :string
|
43
|
+
t.column :archival_id, :integer
|
44
|
+
end
|
57
45
|
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
46
|
+
create_table :readonly_when_archiveds, force: true do |t|
|
47
|
+
t.column :name, :string
|
48
|
+
t.column :archive_number, :string
|
49
|
+
t.column :archived_at, :datetime
|
50
|
+
end
|
63
51
|
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
52
|
+
create_table :missing_archived_ats, force: true do |t|
|
53
|
+
t.column :name, :string
|
54
|
+
t.column :archive_number, :string
|
55
|
+
end
|
68
56
|
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
57
|
+
create_table :missing_archive_numbers, force: true do |t|
|
58
|
+
t.column :name, :string
|
59
|
+
t.column :archived_at, :datetime
|
60
|
+
end
|
73
61
|
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
62
|
+
create_table :polys, force: true do |t|
|
63
|
+
t.references :archiveable, polymorphic: true
|
64
|
+
t.column :archive_number, :string
|
65
|
+
t.column :archived_at, :datetime
|
66
|
+
end
|
79
67
|
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
68
|
+
create_table :legacy, force: true do |t|
|
69
|
+
t.column :name, :string
|
70
|
+
t.column :archive_number, :string
|
71
|
+
t.column :archived_at, :datetime
|
72
|
+
end
|
85
73
|
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
74
|
+
create_table :application_record_rows, force: true do |t|
|
75
|
+
t.column :archive_number, :string
|
76
|
+
t.column :archived_at, :datetime
|
77
|
+
end
|
90
78
|
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
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
|
96
84
|
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
end
|
85
|
+
create_table :callback_archival5s, force: true do |t|
|
86
|
+
t.column :settable_field, :string
|
87
|
+
t.column :archive_number, :string
|
88
|
+
t.column :archived_at, :datetime
|
102
89
|
end
|
103
90
|
end
|