acts_as_paranoid 0.5.0 → 0.6.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: 59510a8af45d737dccea2ee97aa62553790c49a2
4
- data.tar.gz: d9b52994074e903a7b9d7f4d88f5113d37039f12
2
+ SHA256:
3
+ metadata.gz: 45239a76ba68990d6273016fdba8c582ecd44d93475ebabf5ae6717b5c58ddcc
4
+ data.tar.gz: 330ed8379df4137f3016de1db1def095ae268b3f99a6dce075b4fea8adf4eb42
5
5
  SHA512:
6
- metadata.gz: 75b9853cab16dbce9e96a8976b0337e01fce18b38273e087ec68c39eae4fe3b4d2b347f1ead9f147226db2bced977eee5c4ae5a87658208737ae8ec9bd8e7d25
7
- data.tar.gz: 3f6f6a1337fe18092b37f84de3bb08740ab971fa55cb7fb9cb5d7db5551275d498079f8ba38b6cf282e069d529fb0bd32e6765fc364b71dbca23dab90e542d42
6
+ metadata.gz: a2f9c1437125d81959809addcdbee54003711ad8f339b2d1f78987b81aaab3766ac813563c110879f594b127ca90d59186ba84ca0079eeec5e69005b9e0dae08
7
+ data.tar.gz: 51f5f32565a0ae3f90de5f7afe517372a55c63c887c9de7ed07791f196b03e568f9cc275586c43f9e19806c5f45ef1431de4f446c819344cfebda64c0608d997
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2014 Zachary Scott, Gonçalo Silva, Rick Olson
1
+ Copyright (c) 2014-2017 Zachary Scott, Gonçalo Silva, Rick Olson
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/README.md CHANGED
@@ -4,17 +4,40 @@
4
4
 
5
5
  A Rails plugin to add soft delete.
6
6
 
7
- This gem can be used to hide records instead of deleting them, making them recoverable later.
7
+ This gem can be used to hide records instead of deleting them, making them
8
+ recoverable later.
8
9
 
9
10
  ## Support
10
11
 
11
- **This branch targets Rails 4.x. and 5.x**
12
+ **This branch targets Rails 4.2, 5.0 and 5.1, with experimental support for 5.2**
12
13
 
13
- If you're working with another version, switch to the corresponding branch, or require an older version of the `acts_as_paranoid` gem.
14
+ If you're working with another version, switch to the corresponding branch, or
15
+ require an older version of the `acts_as_paranoid` gem.
16
+
17
+ ### Known issues with Rails 5.2
18
+
19
+ * Using acts_as_paranoid and ActiveStorage on the same model
20
+ [leads to a SystemStackError](https://github.com/ActsAsParanoid/acts_as_paranoid/issues/103).
21
+ * You cannot directly create a model in a deleted state.
14
22
 
15
23
  ## Usage
16
24
 
17
- You can enable ActsAsParanoid like this:
25
+ #### Install gem:
26
+
27
+ ``` ruby
28
+ gem 'acts_as_paranoid', '~> 0.6.0'
29
+ ```
30
+ ``` shell
31
+ bundle install
32
+ ```
33
+
34
+ #### Create migration
35
+
36
+ ``` shell
37
+ bin/rails generate migration AddDeletedAtToParanoiac deleted_at:datetime:index
38
+ ```
39
+
40
+ #### Enable ActsAsParanoid:
18
41
 
19
42
  ```ruby
20
43
  class Paranoiac < ActiveRecord::Base
@@ -22,14 +45,19 @@ class Paranoiac < ActiveRecord::Base
22
45
  end
23
46
  ```
24
47
 
25
- ### Options
26
-
27
- You can also specify the name of the column to store it's *deletion* and the type of data it holds:
48
+ The default column name and type are as follows:
28
49
 
29
50
  - `:column => 'deleted_at'`
30
51
  - `:column_type => 'time'`
31
52
 
32
- The values shown are the defaults. While *column* can be anything (as long as it exists in your database), *type* is restricted to:
53
+ ### Options
54
+
55
+ If you are using a different column name and type to store a record's *deletion*, you can specify them as follows:
56
+
57
+ - `:column => 'deleted'`
58
+ - `:column_type => 'boolean'`
59
+
60
+ While *column* can be anything (as long as it exists in your database), *type* is restricted to:
33
61
 
34
62
  - `boolean`
35
63
  - `time` or
@@ -69,11 +97,10 @@ Paranoiac.deleted_inside_time_window(time, 2.minutes)
69
97
  In order to really delete a record, just use:
70
98
 
71
99
  ```ruby
72
- paranoiac.destroy!
100
+ paranoiac.destroy_fully!
73
101
  Paranoiac.delete_all!(conditions)
74
102
  ```
75
-
76
- You can also permanently delete a record by calling `destroy_fully!` on the object.
103
+ **NOTE:** The `.destroy!` method is still usable, but equivalent to `.destroy`. It just hides the object.
77
104
 
78
105
  Alternatively you can permanently delete a record by calling `destroy` or `delete_all` on the object **twice**.
79
106
 
@@ -84,7 +111,7 @@ Take this example:
84
111
  ```ruby
85
112
  p = Paranoiac.first
86
113
  p.destroy # does NOT delete the first record, just hides it
87
- Paranoiac.only_deleted.where(:id => p.id).destroy # deletes the first record from the database
114
+ Paranoiac.only_deleted.where(:id => p.id).first.destroy # deletes the first record from the database
88
115
  ```
89
116
 
90
117
  ### Recovery
@@ -107,7 +134,7 @@ If you would like to change this default behavior for one model, you can use the
107
134
 
108
135
  ```ruby
109
136
  class Paranoiac < ActiveRecord::Base
110
- acts_as_paranoid :recover_dependent_associations => false
137
+ acts_as_paranoid :recover_dependent_associations => false
111
138
  end
112
139
  ```
113
140
 
@@ -121,16 +148,16 @@ This window can be changed with the `dependent_recovery_window` option:
121
148
 
122
149
  ```ruby
123
150
  class Paranoiac < ActiveRecord::Base
124
- acts_as_paranoid
125
- has_many :paranoids, :dependent => :destroy
151
+ acts_as_paranoid
152
+ has_many :paranoids, :dependent => :destroy
126
153
  end
127
154
 
128
155
  class Paranoid < ActiveRecord::Base
129
- belongs_to :paranoic
156
+ belongs_to :paranoic
130
157
 
131
- # Paranoid objects will be recovered alongside Paranoic objects
132
- # if they were deleted within 10 minutes of the Paranoic object
133
- acts_as_paranoid :dependent_recovery_window => 10.minutes
158
+ # Paranoid objects will be recovered alongside Paranoic objects
159
+ # if they were deleted within 10 minutes of the Paranoic object
160
+ acts_as_paranoid :dependent_recovery_window => 10.minutes
134
161
  end
135
162
  ```
136
163
 
@@ -19,7 +19,7 @@ module ActsAsParanoid
19
19
 
20
20
  class_attribute :paranoid_configuration, :paranoid_column_reference
21
21
 
22
- self.paranoid_configuration = { :column => "deleted_at", :column_type => "time", :recover_dependent_associations => true, :dependent_recovery_window => 2.minutes }
22
+ self.paranoid_configuration = { :column => "deleted_at", :column_type => "time", :recover_dependent_associations => true, :dependent_recovery_window => 2.minutes, :recovery_value => nil }
23
23
  self.paranoid_configuration.merge!({ :deleted_value => "deleted" }) if options[:column_type] == "string"
24
24
  self.paranoid_configuration.merge!({ :allow_nulls => true }) if options[:column_type] == "boolean"
25
25
  self.paranoid_configuration.merge!(options) # user options
@@ -3,13 +3,19 @@ module ActsAsParanoid
3
3
  def self.included(base)
4
4
  base.extend ClassMethods
5
5
  class << base
6
- alias_method_chain :belongs_to, :deleted
6
+ alias_method :belongs_to_without_deleted, :belongs_to
7
+ alias_method :belongs_to, :belongs_to_with_deleted
7
8
  end
8
9
  end
9
10
 
10
11
  module ClassMethods
11
12
  def belongs_to_with_deleted(target, scope = nil, options = {})
12
- with_deleted = (scope.is_a?(Hash) ? scope : options).delete(:with_deleted)
13
+ if scope.is_a?(Hash)
14
+ options = scope
15
+ scope = nil
16
+ end
17
+
18
+ with_deleted = options.delete(:with_deleted)
13
19
  result = belongs_to_without_deleted(target, scope, options)
14
20
 
15
21
  if with_deleted
@@ -27,7 +33,8 @@ module ActsAsParanoid
27
33
  return #{target}_without_unscoped(*args) unless association.klass.paranoid?
28
34
  association.klass.with_deleted.scoping { #{target}_without_unscoped(*args) }
29
35
  end
30
- alias_method_chain :#{target}, :unscoped
36
+ alias_method :#{target}_without_unscoped, :#{target}
37
+ alias_method :#{target}, :#{target}_with_unscoped
31
38
  RUBY
32
39
  end
33
40
  end
@@ -105,6 +105,13 @@ module ActsAsParanoid
105
105
  self.send(self.class.paranoid_column)
106
106
  end
107
107
 
108
+ # Straight from ActiveRecord 5.1!
109
+ def delete
110
+ self.class.delete(id) if persisted?
111
+ @destroyed = true
112
+ freeze
113
+ end
114
+
108
115
  def destroy_fully!
109
116
  with_transaction_returning_status do
110
117
  run_callbacks :destroy do
@@ -122,7 +129,12 @@ module ActsAsParanoid
122
129
  with_transaction_returning_status do
123
130
  run_callbacks :destroy do
124
131
  # Handle composite keys, otherwise we would just use `self.class.primary_key.to_sym => self.id`.
125
- self.class.delete_all(Hash[[Array(self.class.primary_key), Array(self.id)].transpose]) if persisted?
132
+ @_trigger_destroy_callback = if persisted?
133
+ self.class.delete_all(Hash[[Array(self.class.primary_key), Array(self.id)].transpose])
134
+ else
135
+ true
136
+ end
137
+
126
138
  self.paranoid_value = self.class.delete_now_value
127
139
  self
128
140
  end
@@ -144,7 +156,7 @@ module ActsAsParanoid
144
156
  run_callbacks :recover do
145
157
  recover_dependent_associations(options[:recovery_window], options) if options[:recursive]
146
158
 
147
- self.paranoid_value = nil
159
+ self.paranoid_value = self.class.paranoid_configuration[:recovery_value]
148
160
  self.save
149
161
  end
150
162
  end
@@ -4,11 +4,12 @@ module ActsAsParanoid
4
4
  base.class_eval do
5
5
  def build_scope_with_deleted
6
6
  scope = build_scope_without_deleted
7
- scope = scope.with_deleted if options[:with_deleted] && klass.respond_to?(:with_deleted)
7
+ scope = scope.with_deleted if reflection.options[:with_deleted] && klass.respond_to?(:with_deleted)
8
8
  scope
9
9
  end
10
10
 
11
- alias_method_chain :build_scope, :deleted
11
+ alias_method :build_scope_without_deleted, :build_scope
12
+ alias_method :build_scope, :build_scope_with_deleted
12
13
  end
13
14
  end
14
15
  end
@@ -21,10 +21,7 @@ module ActsAsParanoid
21
21
  finder_class = find_finder_class_for(record)
22
22
  table = finder_class.arel_table
23
23
 
24
- coder = record.class.attribute_types[attribute.to_s]
25
- value = coder.type_cast_for_schema value if value && coder
26
-
27
- relation = build_relation(finder_class, table, attribute, value)
24
+ relation = build_relation(finder_class, attribute, value)
28
25
  [Array(finder_class.primary_key), Array(record.send(:id))].transpose.each do |pk_key, pk_value|
29
26
  relation = relation.where(table[pk_key.to_sym].not_eq(pk_value))
30
27
  end if record.persisted?
@@ -33,10 +30,17 @@ module ActsAsParanoid
33
30
  relation = relation.where(table[scope_item].eq(record.public_send(scope_item)))
34
31
  end
35
32
 
36
- if relation.where(finder_class.paranoid_default_scope).where(relation).exists?
33
+ if relation.where(finder_class.paranoid_default_scope).exists?(relation)
37
34
  record.errors.add(attribute, :taken, options.except(:case_sensitive, :scope).merge(:value => value))
38
35
  end
39
36
  end
37
+
38
+ protected
39
+
40
+ def build_relation(klass, attribute, value)
41
+ return super(klass, klass.arel_table, attribute, value) if ActiveRecord::VERSION::MINOR == 0
42
+ super
43
+ end
40
44
  end
41
45
 
42
46
  class V4 < ActiveRecord::Validations::UniquenessValidator
@@ -1,3 +1,3 @@
1
1
  module ActsAsParanoid
2
- VERSION = "0.5.0"
2
+ VERSION = "0.6.0"
3
3
  end
@@ -52,8 +52,8 @@ class AssociationsTest < ParanoidBaseTest
52
52
 
53
53
  paranoid_time.destroy
54
54
 
55
- assert_nil paranoid_has_many_dependant.paranoid_time(true)
56
- assert_equal paranoid_time, paranoid_has_many_dependant.paranoid_time_with_deleted(true)
55
+ assert_nil paranoid_has_many_dependant.reload.paranoid_time
56
+ assert_equal paranoid_time, paranoid_has_many_dependant.reload.paranoid_time_with_deleted
57
57
  end
58
58
 
59
59
  def test_belongs_to_polymorphic_with_deleted
@@ -65,8 +65,8 @@ class AssociationsTest < ParanoidBaseTest
65
65
 
66
66
  paranoid_time.destroy
67
67
 
68
- assert_nil paranoid_has_many_dependant.paranoid_time(true)
69
- assert_equal paranoid_time, paranoid_has_many_dependant.paranoid_time_polymorphic_with_deleted(true)
68
+ assert_nil paranoid_has_many_dependant.reload.paranoid_time
69
+ assert_equal paranoid_time, paranoid_has_many_dependant.reload.paranoid_time_polymorphic_with_deleted
70
70
  end
71
71
 
72
72
  def test_belongs_to_nil_polymorphic_with_deleted
@@ -78,8 +78,8 @@ class AssociationsTest < ParanoidBaseTest
78
78
 
79
79
  paranoid_time.destroy
80
80
 
81
- assert_nil paranoid_has_many_dependant.paranoid_time(true)
82
- assert_nil paranoid_has_many_dependant.paranoid_time_polymorphic_with_deleted(true)
81
+ assert_nil paranoid_has_many_dependant.reload.paranoid_time
82
+ assert_nil paranoid_has_many_dependant.reload.paranoid_time_polymorphic_with_deleted
83
83
  end
84
84
 
85
85
  def test_belongs_to_options
@@ -228,6 +228,9 @@ class AssociationsTest < ParanoidBaseTest
228
228
  end
229
229
 
230
230
  def test_mass_assignment_of_paranoid_column_enabled
231
+ if ActiveRecord::VERSION::MAJOR > 4 && ActiveRecord::VERSION::MINOR > 1
232
+ skip 'Creation as deleted is not supported with Rails >= 5.2'
233
+ end
231
234
  now = Time.now
232
235
  record = ParanoidTime.create! :name => 'Foo', :deleted_at => now
233
236
  assert_equal 'Foo', record.name
@@ -186,15 +186,19 @@ class ParanoidTest < ParanoidBaseTest
186
186
  def test_recursive_recovery_dependant_window
187
187
  setup_recursive_tests
188
188
 
189
- @paranoid_time_object.destroy
190
- @paranoid_time_object.reload
191
-
192
189
  # Stop the following from recovering:
193
190
  # - ParanoidHasManyDependant and its ParanoidBelongsDependant
194
191
  # - A single ParanoidBelongsDependant, but not its parent
195
- dependants = @paranoid_time_object.paranoid_has_many_dependants.with_deleted
196
- dependants.first.update_attribute(:deleted_at, 2.days.ago)
197
- ParanoidBelongsDependant.with_deleted.where(:id => dependants.last.paranoid_belongs_dependant_id).first.update_attribute(:deleted_at, 1.hour.ago)
192
+ Time.stub :now, 2.days.ago do
193
+ @paranoid_time_object.paranoid_has_many_dependants.first.destroy
194
+ end
195
+ Time.stub :now, 1.hour.ago do
196
+ @paranoid_time_object.paranoid_has_many_dependants.
197
+ last.paranoid_belongs_dependant.
198
+ destroy
199
+ end
200
+ @paranoid_time_object.destroy
201
+ @paranoid_time_object.reload
198
202
 
199
203
  @paranoid_time_object.recover(:recursive => true)
200
204
 
@@ -211,13 +215,13 @@ class ParanoidTest < ParanoidBaseTest
211
215
  child_1 = ParanoidAndroid.create
212
216
  section_1 = ParanoidSection.create(:paranoid_thing => child_1)
213
217
 
214
- child_2 = ParanoidHuman.create(:gender => 'male')
218
+ child_2 = ParanoidPolygon.create(:sides => 3)
215
219
  section_2 = ParanoidSection.create(:paranoid_thing => child_2)
216
220
 
217
221
  assert_equal section_1.paranoid_thing, child_1
218
222
  assert_equal section_1.paranoid_thing.class, ParanoidAndroid
219
223
  assert_equal section_2.paranoid_thing, child_2
220
- assert_equal section_2.paranoid_thing.class, ParanoidHuman
224
+ assert_equal section_2.paranoid_thing.class, ParanoidPolygon
221
225
 
222
226
  parent = ParanoidTime.create(:name => "paranoid_parent")
223
227
  parent.paranoid_sections << section_1
@@ -226,14 +230,14 @@ class ParanoidTest < ParanoidBaseTest
226
230
  assert_equal 4, ParanoidTime.count
227
231
  assert_equal 2, ParanoidSection.count
228
232
  assert_equal 1, ParanoidAndroid.count
229
- assert_equal 1, ParanoidHuman.count
233
+ assert_equal 1, ParanoidPolygon.count
230
234
 
231
235
  parent.destroy
232
236
 
233
237
  assert_equal 3, ParanoidTime.count
234
238
  assert_equal 0, ParanoidSection.count
235
239
  assert_equal 0, ParanoidAndroid.count
236
- assert_equal 0, ParanoidHuman.count
240
+ assert_equal 0, ParanoidPolygon.count
237
241
 
238
242
  parent.reload
239
243
  parent.recover
@@ -241,7 +245,7 @@ class ParanoidTest < ParanoidBaseTest
241
245
  assert_equal 4, ParanoidTime.count
242
246
  assert_equal 2, ParanoidSection.count
243
247
  assert_equal 1, ParanoidAndroid.count
244
- assert_equal 1, ParanoidHuman.count
248
+ assert_equal 1, ParanoidPolygon.count
245
249
  end
246
250
 
247
251
  def test_non_recursive_recovery
@@ -5,48 +5,48 @@ class MultipleDefaultScopesTest < ParanoidBaseTest
5
5
  setup_db
6
6
 
7
7
  # Naturally, the default scope for humans is male. Sexism++
8
- ParanoidHuman.create! :gender => 'male'
9
- ParanoidHuman.create! :gender => 'male'
10
- ParanoidHuman.create! :gender => 'male'
11
- ParanoidHuman.create! :gender => 'female'
8
+ ParanoidPolygon.create! :sides => 3
9
+ ParanoidPolygon.create! :sides => 3
10
+ ParanoidPolygon.create! :sides => 3
11
+ ParanoidPolygon.create! :sides => 8
12
12
 
13
- assert_equal 3, ParanoidHuman.count
14
- assert_equal 4, ParanoidHuman.unscoped.count
13
+ assert_equal 3, ParanoidPolygon.count
14
+ assert_equal 4, ParanoidPolygon.unscoped.count
15
15
  end
16
16
 
17
17
  def test_fake_removal_with_multiple_default_scope
18
- ParanoidHuman.first.destroy
19
- assert_equal 2, ParanoidHuman.count
20
- assert_equal 3, ParanoidHuman.with_deleted.count
21
- assert_equal 1, ParanoidHuman.only_deleted.count
22
- assert_equal 4, ParanoidHuman.unscoped.count
23
-
24
- ParanoidHuman.destroy_all
25
- assert_equal 0, ParanoidHuman.count
26
- assert_equal 3, ParanoidHuman.with_deleted.count
27
- assert_equal 3, ParanoidHuman.with_deleted.count
28
- assert_equal 4, ParanoidHuman.unscoped.count
18
+ ParanoidPolygon.first.destroy
19
+ assert_equal 2, ParanoidPolygon.count
20
+ assert_equal 3, ParanoidPolygon.with_deleted.count
21
+ assert_equal 1, ParanoidPolygon.only_deleted.count
22
+ assert_equal 4, ParanoidPolygon.unscoped.count
23
+
24
+ ParanoidPolygon.destroy_all
25
+ assert_equal 0, ParanoidPolygon.count
26
+ assert_equal 3, ParanoidPolygon.with_deleted.count
27
+ assert_equal 3, ParanoidPolygon.with_deleted.count
28
+ assert_equal 4, ParanoidPolygon.unscoped.count
29
29
  end
30
30
 
31
31
  def test_real_removal_with_multiple_default_scope
32
32
  # two-step
33
- ParanoidHuman.first.destroy
34
- ParanoidHuman.only_deleted.first.destroy
35
- assert_equal 2, ParanoidHuman.count
36
- assert_equal 2, ParanoidHuman.with_deleted.count
37
- assert_equal 0, ParanoidHuman.only_deleted.count
38
- assert_equal 3, ParanoidHuman.unscoped.count
39
-
40
- ParanoidHuman.first.destroy_fully!
41
- assert_equal 1, ParanoidHuman.count
42
- assert_equal 1, ParanoidHuman.with_deleted.count
43
- assert_equal 0, ParanoidHuman.only_deleted.count
44
- assert_equal 2, ParanoidHuman.unscoped.count
45
-
46
- ParanoidHuman.delete_all!
47
- assert_equal 0, ParanoidHuman.count
48
- assert_equal 0, ParanoidHuman.with_deleted.count
49
- assert_equal 0, ParanoidHuman.only_deleted.count
50
- assert_equal 1, ParanoidHuman.unscoped.count
33
+ ParanoidPolygon.first.destroy
34
+ ParanoidPolygon.only_deleted.first.destroy
35
+ assert_equal 2, ParanoidPolygon.count
36
+ assert_equal 2, ParanoidPolygon.with_deleted.count
37
+ assert_equal 0, ParanoidPolygon.only_deleted.count
38
+ assert_equal 3, ParanoidPolygon.unscoped.count
39
+
40
+ ParanoidPolygon.first.destroy_fully!
41
+ assert_equal 1, ParanoidPolygon.count
42
+ assert_equal 1, ParanoidPolygon.with_deleted.count
43
+ assert_equal 0, ParanoidPolygon.only_deleted.count
44
+ assert_equal 2, ParanoidPolygon.unscoped.count
45
+
46
+ ParanoidPolygon.delete_all!
47
+ assert_equal 0, ParanoidPolygon.count
48
+ assert_equal 0, ParanoidPolygon.with_deleted.count
49
+ assert_equal 0, ParanoidPolygon.only_deleted.count
50
+ assert_equal 1, ParanoidPolygon.unscoped.count
51
51
  end
52
52
  end
@@ -164,8 +164,8 @@ def setup_db
164
164
  timestamps t
165
165
  end
166
166
 
167
- create_table :paranoid_humen do |t|
168
- t.string :gender
167
+ create_table :paranoid_polygons do |t|
168
+ t.integer :sides
169
169
  t.datetime :deleted_at
170
170
 
171
171
  timestamps t
@@ -193,20 +193,20 @@ def setup_db
193
193
  t.integer :parent_id
194
194
  t.datetime :deleted_at
195
195
 
196
- t.timestamps
196
+ timestamps t
197
197
  end
198
198
 
199
199
  create_table :not_paranoid_has_many_as_parents do |t|
200
200
  t.string :name
201
201
 
202
- t.timestamps
202
+ timestamps t
203
203
  end
204
204
 
205
205
  create_table :paranoid_has_many_as_parents do |t|
206
206
  t.string :name
207
207
  t.datetime :deleted_at
208
208
 
209
- t.timestamps
209
+ timestamps t
210
210
  end
211
211
  end
212
212
  end
@@ -451,9 +451,9 @@ class ParanoidTree < ActiveRecord::Base
451
451
  validates_presence_of :name
452
452
  end
453
453
 
454
- class ParanoidHuman < ActiveRecord::Base
454
+ class ParanoidPolygon < ActiveRecord::Base
455
455
  acts_as_paranoid
456
- default_scope { where('gender = ?', 'male') }
456
+ default_scope { where('sides = ?', 3) }
457
457
  end
458
458
 
459
459
  class ParanoidAndroid < ActiveRecord::Base
@@ -5,10 +5,10 @@ class InheritanceTest < ParanoidBaseTest
5
5
  has_many_inherited_super_paranoidz = HasManyInheritedSuperParanoidz.new
6
6
  has_many_inherited_super_paranoidz.save
7
7
  has_many_inherited_super_paranoidz.super_paranoidz.create
8
- assert_nothing_raised(NoMethodError) { has_many_inherited_super_paranoidz.destroy }
8
+ assert_nothing_raised { has_many_inherited_super_paranoidz.destroy }
9
9
  end
10
10
 
11
11
  def test_class_instance_variables_are_inherited
12
- assert_nothing_raised(ActiveRecord::StatementInvalid) { InheritedParanoid.paranoid_column }
12
+ assert_nothing_raised { InheritedParanoid.paranoid_column }
13
13
  end
14
14
  end
@@ -82,8 +82,8 @@ class RelationsTest < ParanoidBaseTest
82
82
 
83
83
  # destroy_all: through a relation
84
84
  @paranoid_forest_2.paranoid_trees.order(:id).destroy_all
85
- assert_equal 0, @paranoid_forest_2.paranoid_trees(true).count
86
- assert_equal 2, @paranoid_forest_2.paranoid_trees(true).with_deleted.count
85
+ assert_equal 0, @paranoid_forest_2.paranoid_trees.count
86
+ assert_equal 2, @paranoid_forest_2.paranoid_trees.with_deleted.count
87
87
  end
88
88
 
89
89
  def test_real_removal_through_relation
@@ -97,21 +97,21 @@ class RelationsTest < ParanoidBaseTest
97
97
  paranoid_tree = @paranoid_forest_1.paranoid_trees.first
98
98
  @paranoid_forest_1.paranoid_trees.order(:id).destroy(paranoid_tree.id)
99
99
  @paranoid_forest_1.paranoid_trees.only_deleted.destroy(paranoid_tree.id)
100
- assert_equal 1, @paranoid_forest_1.paranoid_trees(true).count
101
- assert_equal 1, @paranoid_forest_1.paranoid_trees(true).with_deleted.count
102
- assert_equal 0, @paranoid_forest_1.paranoid_trees(true).only_deleted.count
100
+ assert_equal 1, @paranoid_forest_1.paranoid_trees.count
101
+ assert_equal 1, @paranoid_forest_1.paranoid_trees.with_deleted.count
102
+ assert_equal 0, @paranoid_forest_1.paranoid_trees.only_deleted.count
103
103
 
104
104
  # destroy_all: two-step through a relation
105
105
  @paranoid_forest_1.paranoid_trees.order(:id).destroy_all
106
106
  @paranoid_forest_1.paranoid_trees.only_deleted.destroy_all
107
- assert_equal 0, @paranoid_forest_1.paranoid_trees(true).count
108
- assert_equal 0, @paranoid_forest_1.paranoid_trees(true).with_deleted.count
109
- assert_equal 0, @paranoid_forest_1.paranoid_trees(true).only_deleted.count
107
+ assert_equal 0, @paranoid_forest_1.paranoid_trees.count
108
+ assert_equal 0, @paranoid_forest_1.paranoid_trees.with_deleted.count
109
+ assert_equal 0, @paranoid_forest_1.paranoid_trees.only_deleted.count
110
110
 
111
111
  # delete_all!: through a relation
112
112
  @paranoid_forest_2.paranoid_trees.order(:id).delete_all!
113
- assert_equal 0, @paranoid_forest_2.paranoid_trees(true).count
114
- assert_equal 0, @paranoid_forest_2.paranoid_trees(true).with_deleted.count
115
- assert_equal 0, @paranoid_forest_2.paranoid_trees(true).only_deleted.count
113
+ assert_equal 0, @paranoid_forest_2.paranoid_trees.count
114
+ assert_equal 0, @paranoid_forest_2.paranoid_trees.with_deleted.count
115
+ assert_equal 0, @paranoid_forest_2.paranoid_trees.only_deleted.count
116
116
  end
117
117
  end
@@ -13,6 +13,7 @@ class ValidatesUniquenessTest < ParanoidBaseTest
13
13
 
14
14
  def test_should_validate_without_deleted
15
15
  ParanoidBoolean.new(:name => 'paranoid').tap do |record|
16
+ refute record.valid?
16
17
  ParanoidBoolean.first.destroy
17
18
  assert record.valid?
18
19
  ParanoidBoolean.only_deleted.first.destroy!
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: acts_as_paranoid
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Zachary Scott
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2016-08-09 00:00:00.000000000 Z
13
+ date: 2018-06-07 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activerecord
@@ -18,40 +18,40 @@ dependencies:
18
18
  requirements:
19
19
  - - ">="
20
20
  - !ruby/object:Gem::Version
21
- version: '4.0'
21
+ version: '4.2'
22
22
  - - "<"
23
23
  - !ruby/object:Gem::Version
24
- version: '5.1'
24
+ version: '6.0'
25
25
  type: :runtime
26
26
  prerelease: false
27
27
  version_requirements: !ruby/object:Gem::Requirement
28
28
  requirements:
29
29
  - - ">="
30
30
  - !ruby/object:Gem::Version
31
- version: '4.0'
31
+ version: '4.2'
32
32
  - - "<"
33
33
  - !ruby/object:Gem::Version
34
- version: '5.1'
34
+ version: '6.0'
35
35
  - !ruby/object:Gem::Dependency
36
36
  name: activesupport
37
37
  requirement: !ruby/object:Gem::Requirement
38
38
  requirements:
39
39
  - - ">="
40
40
  - !ruby/object:Gem::Version
41
- version: '4.0'
41
+ version: '4.2'
42
42
  - - "<"
43
43
  - !ruby/object:Gem::Version
44
- version: '5.1'
44
+ version: '6.0'
45
45
  type: :runtime
46
46
  prerelease: false
47
47
  version_requirements: !ruby/object:Gem::Requirement
48
48
  requirements:
49
49
  - - ">="
50
50
  - !ruby/object:Gem::Version
51
- version: '4.0'
51
+ version: '4.2'
52
52
  - - "<"
53
53
  - !ruby/object:Gem::Version
54
- version: '5.1'
54
+ version: '6.0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: bundler
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -155,21 +155,20 @@ required_rubygems_version: !ruby/object:Gem::Requirement
155
155
  requirements:
156
156
  - - ">="
157
157
  - !ruby/object:Gem::Version
158
- version: 1.3.6
158
+ version: '0'
159
159
  requirements: []
160
160
  rubyforge_project:
161
- rubygems_version: 2.5.1
161
+ rubygems_version: 2.7.6
162
162
  signing_key:
163
163
  specification_version: 4
164
164
  summary: Active Record plugin which allows you to hide and restore records without
165
165
  actually deleting them.
166
166
  test_files:
167
- - test/test_inheritance.rb
168
- - test/test_preloader_association.rb
169
- - test/test_relations.rb
170
- - test/test_core.rb
171
167
  - test/test_validations.rb
168
+ - test/test_relations.rb
169
+ - test/test_inheritance.rb
170
+ - test/test_default_scopes.rb
172
171
  - test/test_associations.rb
173
172
  - test/test_helper.rb
174
- - test/test_default_scopes.rb
175
- has_rdoc:
173
+ - test/test_core.rb
174
+ - test/test_preloader_association.rb