paranoia 2.1.2 → 2.1.3
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/README.md +24 -1
- data/lib/paranoia.rb +1 -1
- data/lib/paranoia/version.rb +1 -1
- data/test/paranoia_test.rb +32 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 16d15104c160fe11573395f01bcf18d026d64291
|
4
|
+
data.tar.gz: 009671430b1d508dc3a020773aa8a34666933b30
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9d8cbcb3adc56426e31fdfdfe551c0e557ea023053358ce22083ef5a7140fa480ef004c6e363b95dfddd838f244090edf8cc6dc86a0cc05d98d00f6716d892a0
|
7
|
+
data.tar.gz: c9a6eb1e4da8f21976b01152b0faed9ce736f9019896db44595475c75079266b3dccc6dc4f41a972ef1fba25003ebcb0b3ef76f29fb13884535b02ea5fa8fd69
|
data/README.md
CHANGED
@@ -4,10 +4,14 @@ Paranoia is a re-implementation of [acts\_as\_paranoid](http://github.com/techno
|
|
4
4
|
|
5
5
|
You would use either plugin / gem if you wished that when you called `destroy` on an Active Record object that it didn't actually destroy it, but just *hide* the record. Paranoia does this by setting a `deleted_at` field to the current time when you `destroy` a record, and hides it by scoping all queries on your model to only include records which do not have a `deleted_at` field.
|
6
6
|
|
7
|
-
If you wish to actually destroy an object you may call `really_destroy!`. **WARNING**: This will also *really destroy* all `dependent: destroy` records, so please aim this method away from face when using.
|
7
|
+
If you wish to actually destroy an object you may call `really_destroy!`. **WARNING**: This will also *really destroy* all `dependent: :destroy` records, so please aim this method away from face when using.
|
8
8
|
|
9
9
|
If a record has `has_many` associations defined AND those associations have `dependent: :destroy` set on them, then they will also be soft-deleted if `acts_as_paranoid` is set, otherwise the normal destroy will be called.
|
10
10
|
|
11
|
+
## Getting Started Video
|
12
|
+
Setup and basic usage of the paranoia gem
|
13
|
+
[GoRails #41](https://gorails.com/episodes/soft-delete-with-paranoia)
|
14
|
+
|
11
15
|
## Installation & Usage
|
12
16
|
|
13
17
|
For Rails 3, please use version 1 of Paranoia:
|
@@ -184,6 +188,25 @@ before_restore :callback_name_goes_here
|
|
184
188
|
|
185
189
|
For more information, please look at the tests.
|
186
190
|
|
191
|
+
#### About indexes:
|
192
|
+
|
193
|
+
Beware that you should adapt all your indexes for them to work as fast as previously.
|
194
|
+
For example,
|
195
|
+
|
196
|
+
``` ruby
|
197
|
+
add_index :clients, :group_id
|
198
|
+
add_index :clients, [:group_id, :other_id]
|
199
|
+
```
|
200
|
+
|
201
|
+
should be replaced with
|
202
|
+
|
203
|
+
``` ruby
|
204
|
+
add_index :clients, :group_id, where: "deleted_at IS NULL"
|
205
|
+
add_index :clients, [:group_id, :other_id], where: "deleted_at IS NULL"
|
206
|
+
```
|
207
|
+
|
208
|
+
Of course, this is not necessary for the indexes you always use in association with `with_deleted` or `only_deleted`.
|
209
|
+
|
187
210
|
## Acts As Paranoid Migration
|
188
211
|
|
189
212
|
You can replace the older `acts_as_paranoid` methods as follows:
|
data/lib/paranoia.rb
CHANGED
@@ -144,7 +144,7 @@ module Paranoia
|
|
144
144
|
end
|
145
145
|
|
146
146
|
if association_data.nil? && association.macro.to_s == "has_one"
|
147
|
-
association_class_name = association.
|
147
|
+
association_class_name = association.klass.name
|
148
148
|
association_foreign_key = association.foreign_key
|
149
149
|
|
150
150
|
if association.type
|
data/lib/paranoia/version.rb
CHANGED
data/test/paranoia_test.rb
CHANGED
@@ -34,7 +34,9 @@ def setup!
|
|
34
34
|
'custom_column_models' => 'destroyed_at DATETIME',
|
35
35
|
'custom_sentinel_models' => 'deleted_at DATETIME NOT NULL',
|
36
36
|
'non_paranoid_models' => 'parent_model_id INTEGER',
|
37
|
-
'polymorphic_models' => 'parent_id INTEGER, parent_type STRING, deleted_at DATETIME'
|
37
|
+
'polymorphic_models' => 'parent_id INTEGER, parent_type STRING, deleted_at DATETIME',
|
38
|
+
'namespaced_paranoid_has_ones' => 'deleted_at DATETIME, paranoid_belongs_tos_id INTEGER',
|
39
|
+
'namespaced_paranoid_belongs_tos' => 'deleted_at DATETIME, paranoid_has_one_id INTEGER',
|
38
40
|
}.each do |table_name, columns_as_sql_string|
|
39
41
|
ActiveRecord::Base.connection.execute "CREATE TABLE #{table_name} (id INTEGER NOT NULL PRIMARY KEY, #{columns_as_sql_string})"
|
40
42
|
end
|
@@ -618,6 +620,19 @@ class ParanoiaTest < test_framework
|
|
618
620
|
assert hasOne.reload.deleted_at.nil?
|
619
621
|
end
|
620
622
|
|
623
|
+
def test_restore_with_module_scoped_has_one_association
|
624
|
+
# setup and destroy test object
|
625
|
+
hasOne = Namespaced::ParanoidHasOne.create
|
626
|
+
hasOne.destroy
|
627
|
+
assert_equal false, hasOne.reload.deleted_at.nil?
|
628
|
+
|
629
|
+
# Does it raise "uninitialized constant ParanoidBelongsTo"
|
630
|
+
# on restore of ParanoidHasOne?
|
631
|
+
hasOne.restore(:recursive => true)
|
632
|
+
|
633
|
+
assert hasOne.reload.deleted_at.nil?
|
634
|
+
end
|
635
|
+
|
621
636
|
# covers #185
|
622
637
|
def test_restoring_recursive_has_one_restores_correct_object
|
623
638
|
hasOnes = 2.times.map { ParanoidModelWithHasOne.create }
|
@@ -1001,3 +1016,19 @@ class PolymorphicModel < ActiveRecord::Base
|
|
1001
1016
|
acts_as_paranoid
|
1002
1017
|
belongs_to :parent, polymorphic: true
|
1003
1018
|
end
|
1019
|
+
|
1020
|
+
module Namespaced
|
1021
|
+
def self.table_name_prefix
|
1022
|
+
"namespaced_"
|
1023
|
+
end
|
1024
|
+
|
1025
|
+
class ParanoidHasOne < ActiveRecord::Base
|
1026
|
+
acts_as_paranoid
|
1027
|
+
has_one :paranoid_belongs_to, dependent: :destroy
|
1028
|
+
end
|
1029
|
+
|
1030
|
+
class ParanoidBelongsTo < ActiveRecord::Base
|
1031
|
+
acts_as_paranoid
|
1032
|
+
belongs_to :paranoid_has_one
|
1033
|
+
end
|
1034
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: paranoia
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.1.
|
4
|
+
version: 2.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- radarlistener@gmail.com
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-06-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -94,7 +94,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
94
94
|
version: 1.3.6
|
95
95
|
requirements: []
|
96
96
|
rubyforge_project: paranoia
|
97
|
-
rubygems_version: 2.4.
|
97
|
+
rubygems_version: 2.4.8
|
98
98
|
signing_key:
|
99
99
|
specification_version: 4
|
100
100
|
summary: Paranoia is a re-implementation of acts_as_paranoid for Rails 3, using much,
|