acts_as_archival 1.1.1 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (57) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +81 -0
  3. data/.rubocop_todo.yml +7 -0
  4. data/.travis.yml +34 -0
  5. data/Appraisals +5 -2
  6. data/CHANGELOG.md +8 -0
  7. data/README.md +14 -7
  8. data/Rakefile +6 -3
  9. data/acts_as_archival.gemspec +3 -4
  10. data/gemfiles/rails_4.1.gemfile +0 -1
  11. data/gemfiles/rails_5.0.gemfile +1 -1
  12. data/gemfiles/rails_5.1.beta.gemfile +7 -0
  13. data/lib/acts_as_archival/version.rb +3 -1
  14. data/lib/expected_behavior/acts_as_archival.rb +115 -77
  15. data/lib/expected_behavior/acts_as_archival_active_record_methods.rb +22 -2
  16. data/lib/expected_behavior/association_operation/base.rb +7 -8
  17. data/lib/expected_behavior/association_operation/unarchive.rb +1 -1
  18. data/script/setup +0 -3
  19. data/test/ambiguous_table_test.rb +2 -0
  20. data/test/application_record_test.rb +3 -1
  21. data/test/associations_test.rb +2 -0
  22. data/test/basic_test.rb +6 -4
  23. data/test/callbacks_test.rb +4 -2
  24. data/test/column_test.rb +8 -6
  25. data/test/deep_nesting_test.rb +4 -2
  26. data/test/fixtures/application_record.rb +2 -0
  27. data/test/fixtures/application_record_row.rb +2 -0
  28. data/test/fixtures/archival.rb +9 -7
  29. data/test/fixtures/archival_grandkid.rb +2 -0
  30. data/test/fixtures/archival_kid.rb +3 -1
  31. data/test/fixtures/archival_table_name.rb +2 -0
  32. data/test/fixtures/callback_archival_4.rb +2 -0
  33. data/test/fixtures/callback_archival_5.rb +4 -1
  34. data/test/fixtures/exploder.rb +2 -0
  35. data/test/fixtures/independent_archival.rb +2 -0
  36. data/test/fixtures/missing_archive_number.rb +2 -0
  37. data/test/fixtures/missing_archived_at.rb +2 -0
  38. data/test/fixtures/plain.rb +2 -0
  39. data/test/fixtures/poly.rb +3 -1
  40. data/test/fixtures/readonly_when_archived.rb +3 -1
  41. data/test/polymorphic_test.rb +4 -2
  42. data/test/readonly_when_archived_test.rb +4 -2
  43. data/test/responds_test.rb +22 -4
  44. data/test/schema.rb +59 -79
  45. data/test/scope_test.rb +10 -6
  46. data/test/test_helper.rb +46 -40
  47. data/test/through_association_test.rb +3 -1
  48. data/test/transaction_test.rb +2 -53
  49. metadata +16 -41
  50. data/script/db_setup +0 -51
  51. data/test/database.yml +0 -26
  52. data/test/fixtures/mass_attribute_protected.rb +0 -7
  53. data/test/fixtures/mysql_archival.rb +0 -10
  54. data/test/fixtures/mysql_exploder.rb +0 -9
  55. data/test/fixtures/pg_archival.rb +0 -10
  56. data/test/fixtures/pg_exploder.rb +0 -9
  57. data/test/mass_attribute_test.rb +0 -20
@@ -3,6 +3,8 @@
3
3
  # archive_number - string
4
4
  # archived_at - datetime
5
5
  class Poly < ActiveRecord::Base
6
+
6
7
  acts_as_archival
7
- belongs_to :archiveable, :polymorphic => true
8
+ belongs_to :archiveable, polymorphic: true
9
+
8
10
  end
@@ -2,5 +2,7 @@
2
2
  # archive_number - string
3
3
  # archived_at - datetime
4
4
  class ReadonlyWhenArchived < ActiveRecord::Base
5
- acts_as_archival :readonly_when_archived => true
5
+
6
+ acts_as_archival readonly_when_archived: true
7
+
6
8
  end
@@ -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
- :archive_number => "test",
16
- :archived_at => Time.now
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!(:name => "original")
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!(:name => "original")
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
@@ -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
- assert Archival.is_archival?
6
- assert_not Plain.is_archival?
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
- assert Archival.new.is_archival?
11
- assert_not Plain.new.is_archival?
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
- # Rails 4.0 and before do not deal correctly with newer versions of mysql, so we're
2
- # gonna force a non-null primary ID for old versions of Rails just as new ones do.
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, :force => true do |t|
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
- # The classes above are used to test database-specific
25
- # things in PG and MySQL, and we don't need to do all
26
- # the tests there.
27
- if "SQLite" == ActiveRecord::Base.connection.adapter_name
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
- create_table :independent_archivals, :force => true do |t|
41
- t.column :name, :string
42
- t.column :archival_id, :integer
43
- t.column :archive_number, :string
44
- t.column :archived_at, :datetime
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
- create_table :plains, :force => true do |t|
48
- t.column :name, :string
49
- t.column :archival_id, :integer
50
- end
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
- create_table :mass_attribute_protecteds, :force => true do |t|
53
- t.column :name, :string
54
- t.column :archive_number, :string
55
- t.column :archived_at, :datetime
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
- create_table :readonly_when_archiveds, :force => true do |t|
59
- t.column :name, :string
60
- t.column :archive_number, :string
61
- t.column :archived_at, :datetime
62
- end
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
- create_table :missing_archived_ats, :force => true do |t|
65
- t.column :name, :string
66
- t.column :archive_number, :string
67
- end
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
- create_table :missing_archive_numbers, :force => true do |t|
70
- t.column :name, :string
71
- t.column :archived_at, :datetime
72
- end
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
- create_table :polys, :force => true do |t|
75
- t.references :archiveable, :polymorphic => true
76
- t.column :archive_number, :string
77
- t.column :archived_at, :datetime
78
- end
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
- create_table :legacy, :force => true do |t|
81
- t.column :name, :string
82
- t.column :archive_number, :string
83
- t.column :archived_at, :datetime
84
- end
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
- create_table :application_record_rows, :force => true do |t|
87
- t.column :archive_number, :string
88
- t.column :archived_at, :datetime
89
- end
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
- create_table :callback_archival4s, :force => true do |t|
92
- t.column :settable_field, :string
93
- t.column :archive_number, :string
94
- t.column :archived_at, :datetime
95
- end
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
- create_table :callback_archival5s, :force => true do |t|
98
- t.column :settable_field, :string
99
- t.column :archive_number, :string
100
- t.column :archived_at, :datetime
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 = %Q{SELECT "legacy".* FROM "legacy"#{spaces}WHERE ("legacy"."archived_at" IS NOT NULL) AND ("legacy"."archive_number" IS NOT NULL)}
59
- unarchived_sql = %Q{SELECT "legacy".* FROM "legacy"#{spaces}WHERE "legacy"."archived_at" IS NULL AND "legacy"."archive_number" IS NULL}
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!(:name => "Robert")
66
- Archival.create!(:name => "Bobby")
67
- Archival.create!(:name => "Sue")
68
- bob = Archival.create!(:name => "Bob")
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
- $:.unshift(File.dirname(__FILE__) + '/../lib')
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# if ENV["LOGGING_ENABLED"]
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
- ["pg", "mysql", "sqlite"].each do |db|
44
- puts "** Loading schema for #{db}"
45
- ActiveRecord::Base.establish_connection($dbconfig[db])
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
- $require_application_record = ActiveRecord.version >= Gem::Version.new("4.99.99")
57
- if $require_application_record
58
- fixtures += [:application_record, :application_record_row, :callback_archival_5]
59
- else
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
- :archival,
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