acts_as_paranoid 0.4.5 → 0.5.0.beta1

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
2
  SHA1:
3
- metadata.gz: 57c69c6d7676bda21b0f8da016bd556f77003894
4
- data.tar.gz: 5293e8a3b417fecdfe117aefddcd8e2a0d2f4b09
3
+ metadata.gz: 6e4085cb11f666dff4eb490e4214f010f46216ab
4
+ data.tar.gz: 7c694f1b21233c47299c523696111a7fc4454194
5
5
  SHA512:
6
- metadata.gz: 8ae49e59c2f487c80243bb42c4d6e33c4f1676ecd0d039ba420c1e1e49e02b83a4c6635515d1ef53dd4ba0c68ebce427b386ce684992d4139ef2e4c638f61dd5
7
- data.tar.gz: f449a10feae541515688ed6c55446aa815025982f293a2375c44ec74b68a8cfe7928abc1dffee3758a868bca4d6d92eb13632642bb0dc40279d47e5973a7bfb0
6
+ metadata.gz: 2910ee9bdae09c7e52d7c7157c57192dda2b6b72fb7ef4b5cbf2055c47ba40f7f7505bc26f781a46acd55a2d079ee5ac0dc8c6c0225e5367173e3db0c7b7d70b
7
+ data.tar.gz: d0c8fbaffa54e3052f031c1e3bb94d6baefb186277386674da739a9d3e288d670e4c6c7a7afa3c760c492cd03680fa6845c1ca0f13f120564f773c343a477821
data/README.md CHANGED
@@ -1,10 +1,16 @@
1
1
  # ActsAsParanoid
2
2
 
3
- [![Build Status](https://travis-ci.org/ActsAsParanoid/acts_as_paranoid.png?branch=0-4-stable)](https://travis-ci.org/ActsAsParanoid/acts_as_paranoid)
3
+ [![Build Status](https://travis-ci.org/ActsAsParanoid/acts_as_paranoid.png?branch=master)](https://travis-ci.org/ActsAsParanoid/acts_as_paranoid)
4
4
 
5
- A simple plugin which hides records instead of deleting them, being able to recover them.
5
+ A Rails plugin to add soft delete.
6
6
 
7
- **This branch targets Rails 3.2.** If you're working with another version, switch to the corresponding branch.
7
+ This gem can be used to hide records instead of deleting them, making them recoverable later.
8
+
9
+ ## Support
10
+
11
+ **This branch targets Rails 4.x.**
12
+
13
+ If you're working with another version, switch to the corresponding branch, or require an older version of the acts_as_paranoid gem.
8
14
 
9
15
  ## Usage
10
16
 
@@ -212,32 +218,9 @@ Watch out for these caveats:
212
218
  - You cannot name association `*_with_deleted`
213
219
  - `unscoped` will return all records, deleted or not
214
220
 
215
- # Support
216
-
217
- This gem supports the most recent versions of Rails and Ruby.
218
-
219
- ## Rails
220
-
221
- For Rails 3.2 check the README at the [rails3.2](https://github.com/goncalossilva/rails3_acts_as_paranoid/tree/rails3.2) branch and add this to your Gemfile:
222
-
223
- gem "acts_as_paranoid", "~> 0.4.0"
224
-
225
- For Rails 3.1 check the README at the [rails3.1](https://github.com/goncalossilva/rails3_acts_as_paranoid/tree/rails3.1) branch and add this to your Gemfile:
226
-
227
- gem "rails3_acts_as_paranoid", "~>0.1.4"
228
-
229
- For Rails 3.0 check the README at the [rails3.0](https://github.com/goncalossilva/rails3_acts_as_paranoid/tree/rails3.0) branch and add this to your Gemfile:
230
-
231
- gem "rails3_acts_as_paranoid", "~>0.0.9"
232
-
233
-
234
- ## Ruby
235
-
236
- This gem is tested on Ruby 1.9, JRuby and Rubinius (both in 1.9 mode).
237
-
238
-
239
221
  # Acknowledgements
240
222
 
223
+ * To [Rick Olson](https://github.com/technoweenie) for creating acts_as_paranoid
241
224
  * To [cheerfulstoic](https://github.com/cheerfulstoic) for adding recursive recovery
242
225
  * To [Jonathan Vaught](https://github.com/gravelpup) for adding paranoid validations
243
226
  * To [Geoffrey Hichborn](https://github.com/phene) for improving the overral code quality and adding support for after_commit
@@ -245,12 +228,7 @@ This gem is tested on Ruby 1.9, JRuby and Rubinius (both in 1.9 mode).
245
228
  * To [vikramdhillon](https://github.com/vikramdhillon) for the idea and initial implementation of support for string column type
246
229
  * To [Craig Walker](https://github.com/softcraft-development) for Rails 3.1 support and fixing various pending issues
247
230
  * To [Charles G.](https://github.com/chuckg) for Rails 3.2 support and for making a desperately needed global code refactoring
231
+ * To [Gonçalo Silva](https://github.com/goncalossilva) for supporting this gem prior to v0.4.3
232
+ * To [Jean Boussier](https://github.com/byroot) for initial Rails 4.0.0 support
248
233
 
249
- ## Credits
250
-
251
- This plugin was inspired by [acts_as_paranoid](http://github.com/technoweenie/acts_as_paranoid) and [acts_as_active](http://github.com/fernandoluizao/acts_as_active).
252
-
253
- While porting it to Rails 3, I decided to apply the ideas behind those plugins to an unified solution while removing a **lot** of the complexity found in them. I eventually ended up writing a new plugin from scratch.
254
-
255
-
256
- Copyright © 2014 Zachary Scott, Gonçalo Silva, Rick Olson, released under the MIT license
234
+ See `LICENSE`.
@@ -38,8 +38,8 @@ module ActsAsParanoid
38
38
  deleted_after_time((time - window)).deleted_before_time((time + window))
39
39
  }
40
40
 
41
- scope :deleted_after_time, lambda { |time| where("#{self.table_name}.#{paranoid_column} > ?", time) }
42
- scope :deleted_before_time, lambda { |time| where("#{self.table_name}.#{paranoid_column} < ?", time) }
41
+ scope :deleted_after_time, lambda { |time| where("#{paranoid_column} > ?", time) }
42
+ scope :deleted_before_time, lambda { |time| where("#{paranoid_column} < ?", time) }
43
43
  end
44
44
  end
45
45
  end
@@ -8,9 +8,9 @@ module ActsAsParanoid
8
8
  end
9
9
 
10
10
  module ClassMethods
11
- def belongs_to_with_deleted(target, options = {})
12
- with_deleted = options.delete(:with_deleted)
13
- result = belongs_to_without_deleted(target, options)
11
+ def belongs_to_with_deleted(target, scope = nil, options = {})
12
+ with_deleted = (scope.is_a?(Hash) ? scope : options).delete(:with_deleted)
13
+ result = belongs_to_without_deleted(target, scope, options)
14
14
 
15
15
  if with_deleted
16
16
  result.options[:with_deleted] = with_deleted
@@ -34,16 +34,16 @@ module ActsAsParanoid
34
34
  end
35
35
 
36
36
  def delete_all(conditions = nil)
37
- update_all ["#{paranoid_configuration[:column]} = ?", delete_now_value], conditions
37
+ where(conditions).update_all(["#{paranoid_configuration[:column]} = ?", delete_now_value])
38
38
  end
39
39
 
40
40
  def paranoid_default_scope_sql
41
41
  if string_type_with_deleted_value?
42
- self.scoped.table[paranoid_column].eq(nil).
43
- or(self.scoped.table[paranoid_column].not_eq(paranoid_configuration[:deleted_value])).
42
+ self.all.table[paranoid_column].eq(nil).
43
+ or(self.all.table[paranoid_column].not_eq(paranoid_configuration[:deleted_value])).
44
44
  to_sql
45
45
  else
46
- self.scoped.table[paranoid_column].eq(nil).to_sql
46
+ self.all.table[paranoid_column].eq(nil).to_sql
47
47
  end
48
48
  end
49
49
 
@@ -74,7 +74,7 @@ module ActsAsParanoid
74
74
  protected
75
75
 
76
76
  def without_paranoid_default_scope
77
- scope = self.scoped.with_default_scope
77
+ scope = self.all.with_default_scope
78
78
  scope.where_values.delete(paranoid_default_scope_sql)
79
79
 
80
80
  scope
@@ -21,7 +21,7 @@ module ActsAsParanoid
21
21
 
22
22
  def delete_all(conditions = nil)
23
23
  if paranoid?
24
- update_all(paranoid_deletion_attributes, conditions)
24
+ where(conditions).update_all(paranoid_deletion_attributes)
25
25
  else
26
26
  delete_all!(conditions)
27
27
  end
@@ -1,3 +1,3 @@
1
1
  module ActsAsParanoid
2
- VERSION = "0.4.5"
2
+ VERSION = "0.5.0.beta1"
3
3
  end
@@ -32,6 +32,13 @@ class AssociationsTest < ParanoidBaseTest
32
32
  assert_equal 0, ParanoidProduct.with_deleted.count
33
33
  end
34
34
 
35
+ def test_belongs_to_with_scope_option
36
+ paranoid_has_many_dependant = ParanoidHasManyDependant.new
37
+ includes_values = ParanoidTime.includes(:not_paranoid).includes_values
38
+
39
+ assert_equal includes_values, paranoid_has_many_dependant.association(:paranoid_time_with_scope).scope.includes_values
40
+ end
41
+
35
42
  def test_belongs_to_with_deleted
36
43
  paranoid_time = ParanoidTime.first
37
44
  paranoid_has_many_dependant = paranoid_time.paranoid_has_many_dependants.create(:name => 'dependant!')
@@ -4,7 +4,6 @@ class ParanoidTest < ParanoidBaseTest
4
4
  def test_paranoid?
5
5
  assert !NotParanoid.paranoid?
6
6
  assert_raise(NoMethodError) { NotParanoid.delete_all! }
7
- assert_raise(NoMethodError) { NotParanoid.first.destroy! }
8
7
  assert_raise(NoMethodError) { NotParanoid.with_deleted }
9
8
  assert_raise(NoMethodError) { NotParanoid.only_deleted }
10
9
 
@@ -60,7 +59,7 @@ class ParanoidTest < ParanoidBaseTest
60
59
 
61
60
  ParanoidTime.delete_all!
62
61
  assert_empty ParanoidTime.all
63
- assert_empty ParanoidTime.with_deleted.all
62
+ assert_empty ParanoidTime.with_deleted
64
63
  end
65
64
 
66
65
  def test_non_persisted_destroy
@@ -77,6 +76,10 @@ class ParanoidTest < ParanoidBaseTest
77
76
  assert_not_nil pt.paranoid_value
78
77
  end
79
78
 
79
+ def test_removal_not_persisted
80
+ assert ParanoidTime.new.destroy
81
+ end
82
+
80
83
  def test_recovery
81
84
  assert_equal 3, ParanoidBoolean.count
82
85
  ParanoidBoolean.first.destroy
@@ -233,6 +233,7 @@ end
233
233
  class ParanoidHasManyDependant < ActiveRecord::Base
234
234
  acts_as_paranoid
235
235
  belongs_to :paranoid_time
236
+ belongs_to :paranoid_time_with_scope, -> { includes(:not_paranoid) }, :class_name => 'ParanoidTime', :foreign_key => :paranoid_time_id
236
237
  belongs_to :paranoid_time_with_deleted, :class_name => 'ParanoidTime', :foreign_key => :paranoid_time_id, :with_deleted => true
237
238
  belongs_to :paranoid_time_polymorphic_with_deleted, :class_name => 'ParanoidTime', :foreign_key => :paranoid_time_id, :polymorphic => true, :with_deleted => true
238
239
 
@@ -323,25 +324,6 @@ class InheritedParanoid < SuperParanoid
323
324
  acts_as_paranoid
324
325
  end
325
326
 
326
- class ParanoidObserver < ActiveRecord::Observer
327
- observe :paranoid_with_callback
328
-
329
- attr_accessor :called_before_recover, :called_after_recover
330
-
331
- def before_recover(paranoid_object)
332
- self.called_before_recover = paranoid_object
333
- end
334
-
335
- def after_recover(paranoid_object)
336
- self.called_after_recover = paranoid_object
337
- end
338
-
339
- def reset
340
- self.called_before_recover = nil
341
- self.called_after_recover = nil
342
- end
343
- end
344
-
345
327
 
346
328
  class ParanoidManyManyParentLeft < ActiveRecord::Base
347
329
  has_many :paranoid_many_many_children
@@ -364,8 +346,6 @@ class ParanoidWithScopedValidation < ActiveRecord::Base
364
346
  validates_uniqueness_of :name, :scope => :category
365
347
  end
366
348
 
367
- ParanoidWithCallback.add_observer(ParanoidObserver.instance)
368
-
369
349
  class ParanoidBaseTest < ActiveSupport::TestCase
370
350
  def setup
371
351
  setup_db
@@ -378,8 +358,6 @@ class ParanoidBaseTest < ActiveSupport::TestCase
378
358
  ParanoidString.create! :name => "strings can be paranoid"
379
359
  NotParanoid.create! :name => "no paranoid goals"
380
360
  ParanoidWithCallback.create! :name => "paranoid with callbacks"
381
-
382
- ParanoidObserver.instance.reset
383
361
  end
384
362
 
385
363
  def teardown
@@ -415,7 +393,7 @@ class ParanoidForest < ActiveRecord::Base
415
393
  require "active_support/core_ext/logger.rb"
416
394
  ActiveRecord::Base.logger = Logger.new(StringIO.new)
417
395
 
418
- scope :rainforest, where(:rainforest => true)
396
+ scope :rainforest, lambda{ where(:rainforest => true) }
419
397
 
420
398
  has_many :paranoid_trees, :dependent => :destroy
421
399
  end
@@ -428,7 +406,7 @@ end
428
406
 
429
407
  class ParanoidHuman < ActiveRecord::Base
430
408
  acts_as_paranoid
431
- default_scope where('gender = ?', 'male')
409
+ default_scope { where('gender = ?', 'male') }
432
410
  end
433
411
 
434
412
  class ParanoidAndroid < ActiveRecord::Base
metadata CHANGED
@@ -1,87 +1,99 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: acts_as_paranoid
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.5
4
+ version: 0.5.0.beta1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Zachary Scott
8
- - André Medeiros
9
8
  - Goncalo Silva
10
- - Charles G.
11
9
  - Rick Olson
12
10
  autorequire:
13
11
  bindir: bin
14
12
  cert_chain: []
15
- date: 2016-07-09 00:00:00.000000000 Z
13
+ date: 2014-08-26 00:00:00.000000000 Z
16
14
  dependencies:
17
15
  - !ruby/object:Gem::Dependency
18
16
  name: activerecord
19
17
  requirement: !ruby/object:Gem::Requirement
20
18
  requirements:
21
- - - "~>"
19
+ - - ~>
22
20
  - !ruby/object:Gem::Version
23
- version: '3.2'
21
+ version: '4.0'
24
22
  type: :runtime
25
23
  prerelease: false
26
24
  version_requirements: !ruby/object:Gem::Requirement
27
25
  requirements:
28
- - - "~>"
26
+ - - ~>
29
27
  - !ruby/object:Gem::Version
30
- version: '3.2'
28
+ version: '4.0'
29
+ - !ruby/object:Gem::Dependency
30
+ name: activesupport
31
+ requirement: !ruby/object:Gem::Requirement
32
+ requirements:
33
+ - - ~>
34
+ - !ruby/object:Gem::Version
35
+ version: '4.0'
36
+ type: :runtime
37
+ prerelease: false
38
+ version_requirements: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - ~>
41
+ - !ruby/object:Gem::Version
42
+ version: '4.0'
31
43
  - !ruby/object:Gem::Dependency
32
44
  name: bundler
33
45
  requirement: !ruby/object:Gem::Requirement
34
46
  requirements:
35
- - - "~>"
47
+ - - ~>
36
48
  - !ruby/object:Gem::Version
37
49
  version: '1.5'
38
50
  type: :development
39
51
  prerelease: false
40
52
  version_requirements: !ruby/object:Gem::Requirement
41
53
  requirements:
42
- - - "~>"
54
+ - - ~>
43
55
  - !ruby/object:Gem::Version
44
56
  version: '1.5'
45
57
  - !ruby/object:Gem::Dependency
46
58
  name: rake
47
59
  requirement: !ruby/object:Gem::Requirement
48
60
  requirements:
49
- - - ">="
61
+ - - '>='
50
62
  - !ruby/object:Gem::Version
51
63
  version: '0'
52
64
  type: :development
53
65
  prerelease: false
54
66
  version_requirements: !ruby/object:Gem::Requirement
55
67
  requirements:
56
- - - ">="
68
+ - - '>='
57
69
  - !ruby/object:Gem::Version
58
70
  version: '0'
59
71
  - !ruby/object:Gem::Dependency
60
72
  name: rdoc
61
73
  requirement: !ruby/object:Gem::Requirement
62
74
  requirements:
63
- - - ">="
75
+ - - '>='
64
76
  - !ruby/object:Gem::Version
65
77
  version: '0'
66
78
  type: :development
67
79
  prerelease: false
68
80
  version_requirements: !ruby/object:Gem::Requirement
69
81
  requirements:
70
- - - ">="
82
+ - - '>='
71
83
  - !ruby/object:Gem::Version
72
84
  version: '0'
73
85
  - !ruby/object:Gem::Dependency
74
86
  name: minitest
75
87
  requirement: !ruby/object:Gem::Requirement
76
88
  requirements:
77
- - - "~>"
89
+ - - ~>
78
90
  - !ruby/object:Gem::Version
79
91
  version: '4.0'
80
92
  type: :development
81
93
  prerelease: false
82
94
  version_requirements: !ruby/object:Gem::Requirement
83
95
  requirements:
84
- - - "~>"
96
+ - - ~>
85
97
  - !ruby/object:Gem::Version
86
98
  version: '4.0'
87
99
  description: Check the home page for more in-depth information.
@@ -104,10 +116,9 @@ files:
104
116
  - test/test_default_scopes.rb
105
117
  - test/test_helper.rb
106
118
  - test/test_inheritance.rb
107
- - test/test_observers.rb
108
119
  - test/test_relations.rb
109
120
  - test/test_validations.rb
110
- homepage: https://github.com/zzak/acts_as_paranoid
121
+ homepage: https://github.com/ActsAsParanoid/acts_as_paranoid
111
122
  licenses:
112
123
  - MIT
113
124
  metadata: {}
@@ -117,28 +128,26 @@ require_paths:
117
128
  - lib
118
129
  required_ruby_version: !ruby/object:Gem::Requirement
119
130
  requirements:
120
- - - ">="
131
+ - - '>='
121
132
  - !ruby/object:Gem::Version
122
133
  version: '0'
123
134
  required_rubygems_version: !ruby/object:Gem::Requirement
124
135
  requirements:
125
- - - ">="
136
+ - - '>='
126
137
  - !ruby/object:Gem::Version
127
138
  version: 1.3.6
128
139
  requirements: []
129
140
  rubyforge_project:
130
- rubygems_version: 2.5.1
141
+ rubygems_version: 2.4.1
131
142
  signing_key:
132
143
  specification_version: 4
133
144
  summary: Active Record plugin which allows you to hide and restore records without
134
145
  actually deleting them.
135
146
  test_files:
147
+ - test/test_associations.rb
148
+ - test/test_core.rb
149
+ - test/test_default_scopes.rb
150
+ - test/test_helper.rb
136
151
  - test/test_inheritance.rb
137
- - test/test_observers.rb
138
152
  - test/test_relations.rb
139
- - test/test_core.rb
140
153
  - test/test_validations.rb
141
- - test/test_associations.rb
142
- - test/test_helper.rb
143
- - test/test_default_scopes.rb
144
- has_rdoc:
@@ -1,16 +0,0 @@
1
- require 'test_helper'
2
-
3
- class ParanoidObserverTest < ParanoidBaseTest
4
- def test_called_observer_methods
5
- @subject = ParanoidWithCallback.new
6
- @subject.save
7
-
8
- assert_nil ParanoidObserver.instance.called_before_recover
9
- assert_nil ParanoidObserver.instance.called_after_recover
10
-
11
- ParanoidWithCallback.find(@subject.id).recover
12
-
13
- assert_equal @subject, ParanoidObserver.instance.called_before_recover
14
- assert_equal @subject, ParanoidObserver.instance.called_after_recover
15
- end
16
- end