acts_as_archival 1.3.0 → 1.4.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 57fc429ad5b01bdcf06307addddfbfbcaa6d9c28
4
- data.tar.gz: cd104110c549dd3e187c7e0095e22b1c4ba59fda
2
+ SHA256:
3
+ metadata.gz: 0453a0ad7518b6953ccc8fd43220c553177f41af9adf664c17ffc79b863ea08b
4
+ data.tar.gz: 71ae456902253a456381a61b6db990c3406e55c388c0d4cf61997015820b00ba
5
5
  SHA512:
6
- metadata.gz: 67046bb797b64b2b7de8079f4b95a1c55e1a07d92614711a775ff372931997f156139ad6aa920d7bd2398d9376c5f06834c25a4404dd524728eb0602c659ee7b
7
- data.tar.gz: 24cf648a878a16eba6b089bf60504f2609386cd4a39735e6e163e6ffe48d70a50830005fb4ac58a303f87ae73854c3b608cab6dd8669e1bafd340ab95b555e4d
6
+ metadata.gz: 913f3ba460d1bf0d214f9a1971fae666ab381d28f2177b07f93d6be7dc5d96ea3e9b2446de382292cbe1f861b13c0e7e1ace5dbe2b1787232eef2dde52848431
7
+ data.tar.gz: 928fb526a60d9c8c244c61a062095ba456be6124a20f6cc34240ec15dee6423229ac6ee179380d33ff946e84a97f98e9fc962b89bc90b84c0007f41e4cb9797e
@@ -9,6 +9,7 @@ rvm:
9
9
  - 2.2.6
10
10
  - 2.3.3
11
11
  - 2.4.0
12
+ - 2.5.1
12
13
 
13
14
  gemfile:
14
15
  - gemfiles/rails_4.1.gemfile
@@ -30,3 +31,5 @@ matrix:
30
31
  gemfile: gemfiles/rails_5.1.gemfile
31
32
  - rvm: 2.4.0
32
33
  gemfile: gemfiles/rails_4.1.gemfile
34
+ - rvm: 2.5.1
35
+ gemfile: gemfiles/rails_4.1.gemfile
data/Appraisals CHANGED
@@ -1,15 +1,19 @@
1
- appraise "rails-4.1" do
2
- gem "rails", "~> 4.1.0"
3
- end
4
-
5
1
  appraise "rails-4.2" do
6
2
  gem "rails", "~> 4.2.0"
3
+ gem "sqlite3", "~> 1.3.13"
7
4
  end
8
5
 
9
6
  appraise "rails-5.0" do
10
7
  gem "rails", "~> 5.0.0"
8
+ gem "sqlite3", "~> 1.3.13"
11
9
  end
12
10
 
13
11
  appraise "rails-5.1" do
14
12
  gem "rails", "~> 5.1.0"
13
+ gem "sqlite3", "~> 1.4.1"
14
+ end
15
+
16
+ appraise "rails-5.2" do
17
+ gem "rails", "~> 5.2.0"
18
+ gem "sqlite3", "~> 1.4.1"
15
19
  end
@@ -1,5 +1,13 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 1.4.0 - July 10, 2019
4
+ * **BREAKING CHANGE** drop support for rails 4.1
5
+ * **BUGFIX** polymorphic associations that are archived/unarchived can be acted on safely if they share the same ID.
6
+ * add support officially for rails 5.2
7
+ * sqlite upgrades for various rails
8
+ * new methods `#archive_all!` and `#unarchive_all` that can be called off scopes
9
+
10
+
3
11
  ## 1.3.0 - October 21, 2017
4
12
  * deprecate `#archive` and `#unarchive` in favor of `#archive!` and `#unarchive!` [#36](https://github.com/expectedbehavior/acts_as_archival/pull/36)
5
13
 
data/README.md CHANGED
@@ -79,6 +79,25 @@ r.archived_at # => nil
79
79
  r.archived? # => false
80
80
  ```
81
81
 
82
+ ### Relations
83
+
84
+ ```ruby
85
+ Hole.create!
86
+ Hole.create!
87
+ Hole.create!
88
+
89
+ holes = Hole.all
90
+
91
+ # All records in the relation will be archived with the same archive_number.
92
+ # Dependent/Destroy relationships will be archived, and callbacks will still be honored.
93
+ holes.archive_all! # => [array of Hole records in the relation]
94
+
95
+ holes.first.archive_number # => "b56876de48a5dcfe71b2c13eec15e4a2"
96
+ holes.last.archive_number # => "b56876de48a5dcfe71b2c13eec15e4a2"
97
+
98
+ holes.unarchive_all! # => [array of Hole records in the relation]
99
+ ```
100
+
82
101
  ### Scopes
83
102
 
84
103
  ``` ruby
@@ -144,8 +163,8 @@ end
144
163
 
145
164
  #### Halting the callback chain
146
165
 
147
- * Rails 4.1/4.2 - the callback method should return a `false`/`nil` value.
148
- * Rails 5x - the callback should `throw(:abort)`/`raise(:abort)`.
166
+ * Rails 4.2 - the callback method should return a `false`/`nil` value.
167
+ * Rails 5.x - the callback should `throw(:abort)`/`raise(:abort)`.
149
168
 
150
169
  ## Caveats
151
170
 
@@ -190,6 +209,8 @@ ActsAsParanoid and PermanentRecords were both inspirations for this:
190
209
  * Anthony Panozzo
191
210
  * Aaron Milam
192
211
  * Anton Rieder
212
+ * Josh Menden
213
+ * Sergey Gnuskov
193
214
 
194
215
  Thanks!
195
216
 
@@ -14,7 +14,12 @@ Gem::Specification.new do |gem|
14
14
  "Dave Woodward",
15
15
  "Miles Sterrett",
16
16
  "James Hill",
17
- "Maarten Claes"]
17
+ "Maarten Claes",
18
+ "Anthony Panozzo",
19
+ "Aaron Milam",
20
+ "Anton Rieder",
21
+ "Josh Menden",
22
+ "Sergey Gnuskov"]
18
23
  gem.email = ["joel@expectedbehavior.com",
19
24
  "matt@expectedbehavior.com",
20
25
  "jason@expectedbehavior.com",
@@ -32,8 +37,8 @@ Gem::Specification.new do |gem|
32
37
  gem.add_development_dependency "database_cleaner"
33
38
  gem.add_development_dependency "rake"
34
39
  gem.add_development_dependency "rr"
35
- gem.add_development_dependency "sqlite3"
36
40
  gem.add_development_dependency "rubocop", "~> 0.47.1"
41
+ gem.add_development_dependency "sqlite3"
37
42
 
38
43
  gem.description = <<-END
39
44
  *Atomic archiving/unarchiving for ActiveRecord-based apps*
@@ -3,5 +3,6 @@
3
3
  source "https://rubygems.org"
4
4
 
5
5
  gem "rails", "~> 4.2.0"
6
+ gem "sqlite3", "~> 1.3.13"
6
7
 
7
- gemspec :path => "../"
8
+ gemspec path: "../"
@@ -3,5 +3,6 @@
3
3
  source "https://rubygems.org"
4
4
 
5
5
  gem "rails", "~> 5.0.0"
6
+ gem "sqlite3", "~> 1.3.13"
6
7
 
7
- gemspec :path => "../"
8
+ gemspec path: "../"
@@ -3,5 +3,6 @@
3
3
  source "https://rubygems.org"
4
4
 
5
5
  gem "rails", "~> 5.1.0"
6
+ gem "sqlite3", "~> 1.4.1"
6
7
 
7
- gemspec :path => "../"
8
+ gemspec path: "../"
@@ -2,6 +2,7 @@
2
2
 
3
3
  source "https://rubygems.org"
4
4
 
5
- gem "rails", "~> 4.1.0"
5
+ gem "rails", "~> 5.2.0"
6
+ gem "sqlite3", "~> 1.4.1"
6
7
 
7
- gemspec :path => "../"
8
+ gemspec path: "../"
@@ -15,3 +15,5 @@ else
15
15
  ActiveRecord::Base.send :include, ExpectedBehavior::ActsAsArchival
16
16
  ActiveRecord::Base.send :include, ExpectedBehavior::ActsAsArchivalActiveRecordMethods
17
17
  end
18
+
19
+ ActiveRecord::Relation.send :include, ExpectedBehavior::ActsAsArchivalActiveRecordMethods::ARRelationMethods
@@ -1,5 +1,5 @@
1
1
  module ActsAsArchival
2
2
 
3
- VERSION = "1.3.0".freeze
3
+ VERSION = "1.4.0".freeze
4
4
 
5
5
  end
@@ -36,5 +36,24 @@ module ExpectedBehavior
36
36
 
37
37
  end
38
38
 
39
+ module ARRelationMethods
40
+
41
+ def archive_all!
42
+ error_message = "The #{klass} must implement 'act_on_archivals' in order to call `archive_all!`"
43
+ raise NotImplementedError.new(error_message) unless archival?
44
+
45
+ head_archive_number = Digest::MD5.hexdigest("#{klass}#{Time.now.utc.to_i}")
46
+ each { |record| record.archive!(head_archive_number) }.tap { reset }
47
+ end
48
+
49
+ def unarchive_all!
50
+ error_message = "The #{klass} must implement 'act_on_archivals' in order to call `unarchive_all!`"
51
+ raise NotImplementedError.new(error_message) unless archival?
52
+
53
+ each(&:unarchive!).tap { reset }
54
+ end
55
+
56
+ end
57
+
39
58
  end
40
59
  end
@@ -36,7 +36,11 @@ module ExpectedBehavior
36
36
 
37
37
  def act_on_association(association)
38
38
  key = association.respond_to?(:foreign_key) ? association.foreign_key : association.primary_key_name
39
- scope = association.klass.where(key => model.id)
39
+ scope_conditions = { key => model.id }
40
+ # polymorphic associations need a type so we don't accidentally act on multiple associated objects
41
+ # that have the same ID
42
+ scope_conditions[association.type] = model.class.base_class.name if association.type
43
+ scope = association.klass.where(scope_conditions)
40
44
  act_on_archivals(scope)
41
45
  end
42
46
 
@@ -0,0 +1,11 @@
1
+ # name - string
2
+ # archival_id - integer
3
+ # archive_number - string
4
+ # archived_at - datetime
5
+ class AnotherPolysHolder < ActiveRecord::Base
6
+
7
+ acts_as_archival
8
+
9
+ has_many :polys, dependent: :destroy, as: :archiveable
10
+
11
+ end
@@ -11,6 +11,15 @@ class PolymorphicTest < ActiveSupport::TestCase
11
11
  assert poly.reload.archived?
12
12
  end
13
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
+
14
23
  test "unarchive item with polymorphic association" do
15
24
  archive_attributes = {
16
25
  archive_number: "test",
@@ -24,4 +33,18 @@ class PolymorphicTest < ActiveSupport::TestCase
24
33
  assert_not poly.reload.archived?
25
34
  end
26
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
+
27
50
  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
@@ -1,4 +1,11 @@
1
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
7
+ end
8
+
2
9
  create_table :archivals, force: true do |t|
3
10
  t.column :name, :string
4
11
  t.column :archival_id, :integer
@@ -1,3 +1,4 @@
1
+ # coding: utf-8
1
2
  require_relative "test_helper"
2
3
 
3
4
  class ScopeTest < ActiveSupport::TestCase
@@ -50,15 +51,15 @@ class ScopeTest < ActiveSupport::TestCase
50
51
  end
51
52
 
52
53
  test "table_name is set to 'legacy'" do
53
- # ActiveRecord 4.2 changed the output by one space (╯°□°)╯︵ ┻━┻
54
- spaces = if (ActiveRecord.version <=> Gem::Version.new("4.2.0")) >= 0
55
- " "
56
- else
57
- " "
58
- end
59
- archived_sql = "SELECT \"legacy\".* FROM \"legacy\"#{spaces}" \
54
+ archived_sql =
55
+ if ActiveRecord.version >= Gem::Version.new("5.2.0")
56
+ "SELECT \"legacy\".* FROM \"legacy\" " \
57
+ 'WHERE "legacy"."archived_at" IS NOT NULL AND "legacy"."archive_number" IS NOT NULL'
58
+ else
59
+ "SELECT \"legacy\".* FROM \"legacy\" " \
60
60
  'WHERE ("legacy"."archived_at" IS NOT NULL) AND ("legacy"."archive_number" IS NOT NULL)'
61
- unarchived_sql = "SELECT \"legacy\".* FROM \"legacy\"#{spaces}" \
61
+ end
62
+ unarchived_sql = "SELECT \"legacy\".* FROM \"legacy\" " \
62
63
  'WHERE "legacy"."archived_at" IS NULL AND "legacy"."archive_number" IS NULL'
63
64
  assert_equal archived_sql, ArchivalTableName.archived.to_sql
64
65
  assert_equal unarchived_sql, ArchivalTableName.unarchived.to_sql
@@ -50,6 +50,7 @@ def create_test_tables
50
50
  end
51
51
 
52
52
  BASE_FIXTURE_CLASSES = [
53
+ :another_polys_holder,
53
54
  :archival,
54
55
  :archival_kid,
55
56
  :archival_grandkid,
@@ -79,9 +80,9 @@ def require_test_classes
79
80
  end
80
81
 
81
82
  fixtures = if ActiveRecord::VERSION::MAJOR >= 4
82
- RAILS_5_FIXTURE_CLASSES + BASE_FIXTURE_CLASSES
83
+ RAILS_5_FIXTURE_CLASSES
83
84
  else
84
- RAILS_4_FIXTURE_CLASSES + BASE_FIXTURE_CLASSES
85
+ RAILS_4_FIXTURE_CLASSES
85
86
  end
86
87
 
87
88
  fixtures += BASE_FIXTURE_CLASSES
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: acts_as_archival
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0
4
+ version: 1.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joel Meador
@@ -13,10 +13,15 @@ authors:
13
13
  - Miles Sterrett
14
14
  - James Hill
15
15
  - Maarten Claes
16
+ - Anthony Panozzo
17
+ - Aaron Milam
18
+ - Anton Rieder
19
+ - Josh Menden
20
+ - Sergey Gnuskov
16
21
  autorequire:
17
22
  bindir: bin
18
23
  cert_chain: []
19
- date: 2017-10-21 00:00:00.000000000 Z
24
+ date: 2019-07-09 00:00:00.000000000 Z
20
25
  dependencies:
21
26
  - !ruby/object:Gem::Dependency
22
27
  name: activerecord
@@ -103,33 +108,33 @@ dependencies:
103
108
  - !ruby/object:Gem::Version
104
109
  version: '0'
105
110
  - !ruby/object:Gem::Dependency
106
- name: sqlite3
111
+ name: rubocop
107
112
  requirement: !ruby/object:Gem::Requirement
108
113
  requirements:
109
- - - ">="
114
+ - - "~>"
110
115
  - !ruby/object:Gem::Version
111
- version: '0'
116
+ version: 0.47.1
112
117
  type: :development
113
118
  prerelease: false
114
119
  version_requirements: !ruby/object:Gem::Requirement
115
120
  requirements:
116
- - - ">="
121
+ - - "~>"
117
122
  - !ruby/object:Gem::Version
118
- version: '0'
123
+ version: 0.47.1
119
124
  - !ruby/object:Gem::Dependency
120
- name: rubocop
125
+ name: sqlite3
121
126
  requirement: !ruby/object:Gem::Requirement
122
127
  requirements:
123
- - - "~>"
128
+ - - ">="
124
129
  - !ruby/object:Gem::Version
125
- version: 0.47.1
130
+ version: '0'
126
131
  type: :development
127
132
  prerelease: false
128
133
  version_requirements: !ruby/object:Gem::Requirement
129
134
  requirements:
130
- - - "~>"
135
+ - - ">="
131
136
  - !ruby/object:Gem::Version
132
- version: 0.47.1
137
+ version: '0'
133
138
  description: |
134
139
  *Atomic archiving/unarchiving for ActiveRecord-based apps*
135
140
 
@@ -164,10 +169,10 @@ files:
164
169
  - README.md
165
170
  - Rakefile
166
171
  - acts_as_archival.gemspec
167
- - gemfiles/rails_4.1.gemfile
168
172
  - gemfiles/rails_4.2.gemfile
169
173
  - gemfiles/rails_5.0.gemfile
170
174
  - gemfiles/rails_5.1.gemfile
175
+ - gemfiles/rails_5.2.gemfile
171
176
  - init.rb
172
177
  - lib/acts_as_archival.rb
173
178
  - lib/acts_as_archival/version.rb
@@ -184,6 +189,7 @@ files:
184
189
  - test/callbacks_test.rb
185
190
  - test/column_test.rb
186
191
  - test/deep_nesting_test.rb
192
+ - test/fixtures/another_polys_holder.rb
187
193
  - test/fixtures/application_record.rb
188
194
  - test/fixtures/application_record_row.rb
189
195
  - test/fixtures/archival.rb
@@ -201,6 +207,7 @@ files:
201
207
  - test/fixtures/readonly_when_archived.rb
202
208
  - test/polymorphic_test.rb
203
209
  - test/readonly_when_archived_test.rb
210
+ - test/relations_test.rb
204
211
  - test/responds_test.rb
205
212
  - test/schema.rb
206
213
  - test/scope_test.rb
@@ -225,8 +232,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
225
232
  - !ruby/object:Gem::Version
226
233
  version: '0'
227
234
  requirements: []
228
- rubyforge_project:
229
- rubygems_version: 2.5.1
235
+ rubygems_version: 3.0.3
230
236
  signing_key:
231
237
  specification_version: 4
232
238
  summary: Atomic archiving/unarchiving for ActiveRecord-based apps
@@ -238,6 +244,7 @@ test_files:
238
244
  - test/callbacks_test.rb
239
245
  - test/column_test.rb
240
246
  - test/deep_nesting_test.rb
247
+ - test/fixtures/another_polys_holder.rb
241
248
  - test/fixtures/application_record.rb
242
249
  - test/fixtures/application_record_row.rb
243
250
  - test/fixtures/archival.rb
@@ -255,6 +262,7 @@ test_files:
255
262
  - test/fixtures/readonly_when_archived.rb
256
263
  - test/polymorphic_test.rb
257
264
  - test/readonly_when_archived_test.rb
265
+ - test/relations_test.rb
258
266
  - test/responds_test.rb
259
267
  - test/schema.rb
260
268
  - test/scope_test.rb