acts_as_archival 1.1.1 → 1.2.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 +4 -4
- data/.rubocop.yml +81 -0
- data/.rubocop_todo.yml +7 -0
- data/.travis.yml +34 -0
- data/Appraisals +5 -2
- data/CHANGELOG.md +8 -0
- data/README.md +14 -7
- data/Rakefile +6 -3
- data/acts_as_archival.gemspec +3 -4
- data/gemfiles/rails_4.1.gemfile +0 -1
- data/gemfiles/rails_5.0.gemfile +1 -1
- data/gemfiles/rails_5.1.beta.gemfile +7 -0
- data/lib/acts_as_archival/version.rb +3 -1
- data/lib/expected_behavior/acts_as_archival.rb +115 -77
- data/lib/expected_behavior/acts_as_archival_active_record_methods.rb +22 -2
- data/lib/expected_behavior/association_operation/base.rb +7 -8
- data/lib/expected_behavior/association_operation/unarchive.rb +1 -1
- data/script/setup +0 -3
- data/test/ambiguous_table_test.rb +2 -0
- data/test/application_record_test.rb +3 -1
- data/test/associations_test.rb +2 -0
- data/test/basic_test.rb +6 -4
- data/test/callbacks_test.rb +4 -2
- data/test/column_test.rb +8 -6
- data/test/deep_nesting_test.rb +4 -2
- 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 +4 -2
- data/test/readonly_when_archived_test.rb +4 -2
- data/test/responds_test.rb +22 -4
- data/test/schema.rb +59 -79
- data/test/scope_test.rb +10 -6
- data/test/test_helper.rb +46 -40
- data/test/through_association_test.rb +3 -1
- data/test/transaction_test.rb +2 -53
- metadata +16 -41
- 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/fixtures/poly.rb
CHANGED
data/test/polymorphic_test.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
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!
|
@@ -12,8 +13,8 @@ class PolymorphicTest < ActiveSupport::TestCase
|
|
12
13
|
|
13
14
|
test "unarchive item with polymorphic association" do
|
14
15
|
archive_attributes = {
|
15
|
-
:
|
16
|
-
:
|
16
|
+
archive_number: "test",
|
17
|
+
archived_at: Time.now
|
17
18
|
}
|
18
19
|
archival = Archival.create!(archive_attributes)
|
19
20
|
poly = archival.polys.create!(archive_attributes)
|
@@ -22,4 +23,5 @@ class PolymorphicTest < ActiveSupport::TestCase
|
|
22
23
|
assert_not archival.reload.archived?
|
23
24
|
assert_not poly.reload.archived?
|
24
25
|
end
|
26
|
+
|
25
27
|
end
|
@@ -1,8 +1,9 @@
|
|
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 = Archival.create!(name: "original")
|
6
7
|
archival.archive
|
7
8
|
archival.name = "updated"
|
8
9
|
archival.save!
|
@@ -11,7 +12,7 @@ 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 = ReadonlyWhenArchived.create!(name: "original")
|
15
16
|
archival.archive
|
16
17
|
archival.name = "updated"
|
17
18
|
|
@@ -19,4 +20,5 @@ class ReadonlyWhenArchivedTest < ActiveSupport::TestCase
|
|
19
20
|
assert_equal "Cannot modify an archived record.",
|
20
21
|
archival.errors.full_messages.first
|
21
22
|
end
|
23
|
+
|
22
24
|
end
|
data/test/responds_test.rb
CHANGED
@@ -1,13 +1,31 @@
|
|
1
1
|
require_relative "test_helper"
|
2
2
|
|
3
3
|
class RespondsTest < ActiveSupport::TestCase
|
4
|
+
|
5
|
+
test "archival class responds correctly to 'archival?'" do
|
6
|
+
assert Archival.archival?
|
7
|
+
assert_not Plain.archival?
|
8
|
+
end
|
9
|
+
|
10
|
+
test "archival object responds correctly to 'archival?'" do
|
11
|
+
assert Archival.new.archival?
|
12
|
+
assert_not Plain.new.archival?
|
13
|
+
end
|
14
|
+
|
15
|
+
### Deprecation Zone ###
|
16
|
+
|
4
17
|
test "archival class responds correctly to 'is_archival?'" do
|
5
|
-
|
6
|
-
|
18
|
+
ActiveSupport::Deprecation.silence do
|
19
|
+
assert Archival.is_archival?
|
20
|
+
assert_not Plain.is_archival?
|
21
|
+
end
|
7
22
|
end
|
8
23
|
|
9
24
|
test "archival object responds correctly to 'is_archival?'" do
|
10
|
-
|
11
|
-
|
25
|
+
ActiveSupport::Deprecation.silence do
|
26
|
+
assert Archival.new.is_archival?
|
27
|
+
assert_not Plain.new.is_archival?
|
28
|
+
end
|
12
29
|
end
|
30
|
+
|
13
31
|
end
|
data/test/schema.rb
CHANGED
@@ -1,103 +1,83 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
if (ActiveRecord.version <=> Gem::Version.new("4.1.0")) < 0
|
4
|
-
class ActiveRecord::ConnectionAdapters::Mysql2Adapter
|
5
|
-
NATIVE_DATABASE_TYPES[:primary_key] = "int(11) auto_increment PRIMARY KEY"
|
6
|
-
end
|
7
|
-
end
|
8
|
-
|
9
|
-
ActiveRecord::Schema.define(:version => 1) do
|
10
|
-
create_table :archivals, :force => true do |t|
|
1
|
+
ActiveRecord::Schema.define(version: 1) do
|
2
|
+
create_table :archivals, force: true do |t|
|
11
3
|
t.column :name, :string
|
12
4
|
t.column :archival_id, :integer
|
13
5
|
t.column :archive_number, :string
|
14
6
|
t.column :archived_at, :datetime
|
15
7
|
end
|
16
8
|
|
17
|
-
create_table :exploders, :
|
9
|
+
create_table :exploders, force: true do |t|
|
18
10
|
t.column :archival_id, :integer
|
19
11
|
t.column :archive_number, :string
|
20
12
|
t.column :archived_at, :datetime
|
21
13
|
end
|
22
14
|
|
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
|
15
|
+
create_table :archival_kids, force: true do |t|
|
16
|
+
t.column :archival_id, :integer
|
17
|
+
t.column :archive_number, :string
|
18
|
+
t.column :archived_at, :datetime
|
19
|
+
end
|
39
20
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
end
|
21
|
+
create_table :archival_grandkids, force: true do |t|
|
22
|
+
t.column :archival_kid_id, :integer
|
23
|
+
t.column :archive_number, :string
|
24
|
+
t.column :archived_at, :datetime
|
25
|
+
end
|
46
26
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
27
|
+
create_table :independent_archivals, force: true do |t|
|
28
|
+
t.column :name, :string
|
29
|
+
t.column :archival_id, :integer
|
30
|
+
t.column :archive_number, :string
|
31
|
+
t.column :archived_at, :datetime
|
32
|
+
end
|
51
33
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
end
|
34
|
+
create_table :plains, force: true do |t|
|
35
|
+
t.column :name, :string
|
36
|
+
t.column :archival_id, :integer
|
37
|
+
end
|
57
38
|
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
39
|
+
create_table :readonly_when_archiveds, force: true do |t|
|
40
|
+
t.column :name, :string
|
41
|
+
t.column :archive_number, :string
|
42
|
+
t.column :archived_at, :datetime
|
43
|
+
end
|
63
44
|
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
45
|
+
create_table :missing_archived_ats, force: true do |t|
|
46
|
+
t.column :name, :string
|
47
|
+
t.column :archive_number, :string
|
48
|
+
end
|
68
49
|
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
50
|
+
create_table :missing_archive_numbers, force: true do |t|
|
51
|
+
t.column :name, :string
|
52
|
+
t.column :archived_at, :datetime
|
53
|
+
end
|
73
54
|
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
55
|
+
create_table :polys, force: true do |t|
|
56
|
+
t.references :archiveable, polymorphic: true
|
57
|
+
t.column :archive_number, :string
|
58
|
+
t.column :archived_at, :datetime
|
59
|
+
end
|
79
60
|
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
61
|
+
create_table :legacy, force: true do |t|
|
62
|
+
t.column :name, :string
|
63
|
+
t.column :archive_number, :string
|
64
|
+
t.column :archived_at, :datetime
|
65
|
+
end
|
85
66
|
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
67
|
+
create_table :application_record_rows, force: true do |t|
|
68
|
+
t.column :archive_number, :string
|
69
|
+
t.column :archived_at, :datetime
|
70
|
+
end
|
90
71
|
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
72
|
+
create_table :callback_archival4s, force: true do |t|
|
73
|
+
t.column :settable_field, :string
|
74
|
+
t.column :archive_number, :string
|
75
|
+
t.column :archived_at, :datetime
|
76
|
+
end
|
96
77
|
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
end
|
78
|
+
create_table :callback_archival5s, force: true do |t|
|
79
|
+
t.column :settable_field, :string
|
80
|
+
t.column :archive_number, :string
|
81
|
+
t.column :archived_at, :datetime
|
102
82
|
end
|
103
83
|
end
|
data/test/scope_test.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require_relative "test_helper"
|
2
2
|
|
3
3
|
class ScopeTest < ActiveSupport::TestCase
|
4
|
+
|
4
5
|
test "simple unarchived scope" do
|
5
6
|
Archival.create!
|
6
7
|
Archival.create!
|
@@ -55,17 +56,19 @@ class ScopeTest < ActiveSupport::TestCase
|
|
55
56
|
else
|
56
57
|
" "
|
57
58
|
end
|
58
|
-
archived_sql =
|
59
|
-
|
59
|
+
archived_sql = "SELECT \"legacy\".* FROM \"legacy\"#{spaces}" \
|
60
|
+
'WHERE ("legacy"."archived_at" IS NOT NULL) AND ("legacy"."archive_number" IS NOT NULL)'
|
61
|
+
unarchived_sql = "SELECT \"legacy\".* FROM \"legacy\"#{spaces}" \
|
62
|
+
'WHERE "legacy"."archived_at" IS NULL AND "legacy"."archive_number" IS NULL'
|
60
63
|
assert_equal archived_sql, ArchivalTableName.archived.to_sql
|
61
64
|
assert_equal unarchived_sql, ArchivalTableName.unarchived.to_sql
|
62
65
|
end
|
63
66
|
|
64
67
|
test "combines with other scope properly" do
|
65
|
-
Archival.create!(:
|
66
|
-
Archival.create!(:
|
67
|
-
Archival.create!(:
|
68
|
-
bob = Archival.create!(:
|
68
|
+
Archival.create!(name: "Robert")
|
69
|
+
Archival.create!(name: "Bobby")
|
70
|
+
Archival.create!(name: "Sue")
|
71
|
+
bob = Archival.create!(name: "Bob")
|
69
72
|
bob.archive
|
70
73
|
assert_equal 3, Archival.bobs.count
|
71
74
|
assert_equal 3, Archival.unarchived.count
|
@@ -85,4 +88,5 @@ class ScopeTest < ActiveSupport::TestCase
|
|
85
88
|
assert_equal 1, parent.archivals.archived.count
|
86
89
|
assert_equal 2, parent.archivals.unarchived.count
|
87
90
|
end
|
91
|
+
|
88
92
|
end
|
data/test/test_helper.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
|
-
|
1
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__) + "/../lib")
|
2
2
|
require "bundler/setup"
|
3
3
|
require "minitest/autorun"
|
4
|
+
require "minitest/pride"
|
4
5
|
|
5
6
|
require "active_record"
|
6
7
|
require "assertions"
|
@@ -13,8 +14,7 @@ if ActiveSupport::TestCase.respond_to?(:test_order=)
|
|
13
14
|
end
|
14
15
|
|
15
16
|
def prepare_for_tests
|
16
|
-
setup_logging
|
17
|
-
setup_active_record
|
17
|
+
setup_logging
|
18
18
|
setup_database_cleaner
|
19
19
|
create_test_tables
|
20
20
|
require_test_classes
|
@@ -26,11 +26,6 @@ def setup_logging
|
|
26
26
|
ActiveRecord::Base.logger = Logger.new(logfile)
|
27
27
|
end
|
28
28
|
|
29
|
-
def setup_active_record
|
30
|
-
dbconfig_file = File.dirname(__FILE__) + "/database.yml"
|
31
|
-
$dbconfig = YAML.load(File.read(dbconfig_file))
|
32
|
-
end
|
33
|
-
|
34
29
|
def setup_database_cleaner
|
35
30
|
DatabaseCleaner.strategy = :truncation
|
36
31
|
ActiveSupport::TestCase.send(:setup) do
|
@@ -38,48 +33,59 @@ def setup_database_cleaner
|
|
38
33
|
end
|
39
34
|
end
|
40
35
|
|
36
|
+
def sqlite_config
|
37
|
+
{
|
38
|
+
adapter: "sqlite3",
|
39
|
+
database: "aaa_test.sqlite3",
|
40
|
+
pool: 5,
|
41
|
+
timeout: 5000
|
42
|
+
}
|
43
|
+
end
|
44
|
+
|
41
45
|
def create_test_tables
|
42
46
|
schema_file = File.dirname(__FILE__) + "/schema.rb"
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
load(schema_file) if File.exist?(schema_file)
|
47
|
-
end
|
47
|
+
puts "** Loading schema for SQLite"
|
48
|
+
ActiveRecord::Base.establish_connection(sqlite_config)
|
49
|
+
load(schema_file) if File.exist?(schema_file)
|
48
50
|
end
|
49
51
|
|
52
|
+
BASE_FIXTURE_CLASSES = [
|
53
|
+
:archival,
|
54
|
+
:archival_kid,
|
55
|
+
:archival_grandkid,
|
56
|
+
:archival_table_name,
|
57
|
+
:exploder,
|
58
|
+
:independent_archival,
|
59
|
+
:missing_archived_at,
|
60
|
+
:missing_archive_number,
|
61
|
+
:plain,
|
62
|
+
:poly,
|
63
|
+
:readonly_when_archived
|
64
|
+
].freeze
|
65
|
+
|
66
|
+
RAILS_4_FIXTURE_CLASSES = [
|
67
|
+
:callback_archival_4
|
68
|
+
].freeze
|
69
|
+
|
70
|
+
RAILS_5_FIXTURE_CLASSES = [
|
71
|
+
:application_record,
|
72
|
+
:application_record_row,
|
73
|
+
:callback_archival_5
|
74
|
+
].freeze
|
75
|
+
|
50
76
|
def require_test_classes
|
51
77
|
ActiveSupport::Inflector.inflections do |inflect|
|
52
78
|
inflect.irregular "poly", "polys"
|
53
79
|
end
|
54
80
|
|
55
|
-
fixtures =
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
fixtures += [:callback_archival_4]
|
61
|
-
end
|
81
|
+
fixtures = if ActiveRecord::VERSION::MAJOR >= 4
|
82
|
+
RAILS_5_FIXTURE_CLASSES + BASE_FIXTURE_CLASSES
|
83
|
+
else
|
84
|
+
RAILS_4_FIXTURE_CLASSES + BASE_FIXTURE_CLASSES
|
85
|
+
end
|
62
86
|
|
63
|
-
fixtures +=
|
64
|
-
|
65
|
-
:archival_kid,
|
66
|
-
:archival_grandkid,
|
67
|
-
:archival_table_name,
|
68
|
-
:exploder,
|
69
|
-
:independent_archival,
|
70
|
-
:missing_archived_at,
|
71
|
-
:missing_archive_number,
|
72
|
-
:mysql_archival,
|
73
|
-
:mysql_exploder,
|
74
|
-
:plain,
|
75
|
-
:poly,
|
76
|
-
:pg_archival,
|
77
|
-
:pg_exploder,
|
78
|
-
:readonly_when_archived
|
79
|
-
]
|
80
|
-
$require_mass_protection = ActiveModel.constants.include?(:MassAssignmentSecurity)
|
81
|
-
fixtures << :mass_attribute_protected if $require_mass_protection
|
82
|
-
fixtures.each {|test_class_file| require_relative "fixtures/#{test_class_file}"}
|
87
|
+
fixtures += BASE_FIXTURE_CLASSES
|
88
|
+
fixtures.each { |test_class_file| require_relative "fixtures/#{test_class_file}" }
|
83
89
|
end
|
84
90
|
|
85
91
|
prepare_for_tests
|
@@ -1,6 +1,7 @@
|
|
1
1
|
require_relative "test_helper"
|
2
2
|
|
3
3
|
class ThroughAssociationTest < ActiveSupport::TestCase
|
4
|
+
|
4
5
|
test "archive a through associated object whose 'bridge' is archival" do
|
5
6
|
archival = Archival.create!
|
6
7
|
bridge = archival.archival_kids.create!
|
@@ -12,7 +13,7 @@ class ThroughAssociationTest < ActiveSupport::TestCase
|
|
12
13
|
assert through.reload.archived?
|
13
14
|
end
|
14
15
|
|
15
|
-
# TODO Make something like this pass
|
16
|
+
# TODO: Make something like this pass
|
16
17
|
# test "archive a through associated object whose 'bridge' is not archival" do
|
17
18
|
# archival = Archival.create!
|
18
19
|
# bridge = archival.independent_archival_kids.create!
|
@@ -22,4 +23,5 @@ class ThroughAssociationTest < ActiveSupport::TestCase
|
|
22
23
|
# assert archival.reload.archived?
|
23
24
|
# assert through.reload.archived?
|
24
25
|
# end
|
26
|
+
|
25
27
|
end
|