paranoia 2.1.4 → 2.1.5
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/.travis.yml +2 -0
- data/CHANGELOG.md +12 -0
- data/lib/paranoia.rb +25 -24
- data/lib/paranoia/version.rb +1 -1
- data/test/paranoia_test.rb +19 -0
- 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: 32a4bc8e17adc564a3c87661d90c1457b44323bd
|
4
|
+
data.tar.gz: 94527885cf5fb887a88ee2a938472995623639dd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 865a43181fa3699d92554cc800dff88a20070f2a00d839bc583c99b9e6ad2da78217711a0ca52cb5c358322a33865dbe378332c90c9182b7cf47971d2751f8a2
|
7
|
+
data.tar.gz: d55b46e33174f428e607557b60ba25b8adf6058acdac6dedd3aad00d5f010d7df4c9a5045b9d445c6d640ec1606399f75fbf0f383a6f8297569fd8b90c3d29f8
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
data/lib/paranoia.rb
CHANGED
@@ -110,6 +110,7 @@ module Paranoia
|
|
110
110
|
if (noop_if_frozen && !@attributes.frozen?) || !noop_if_frozen
|
111
111
|
write_attribute paranoia_column, paranoia_sentinel_value
|
112
112
|
update_columns(paranoia_restore_attributes)
|
113
|
+
touch
|
113
114
|
end
|
114
115
|
restore_associated_records if opts[:recursive]
|
115
116
|
end
|
@@ -124,6 +125,30 @@ module Paranoia
|
|
124
125
|
end
|
125
126
|
alias :deleted? :paranoia_destroyed?
|
126
127
|
|
128
|
+
def really_destroy!
|
129
|
+
transaction do
|
130
|
+
run_callbacks(:real_destroy) do
|
131
|
+
dependent_reflections = self.class.reflections.select do |name, reflection|
|
132
|
+
reflection.options[:dependent] == :destroy
|
133
|
+
end
|
134
|
+
if dependent_reflections.any?
|
135
|
+
dependent_reflections.each do |name, reflection|
|
136
|
+
association_data = self.send(name)
|
137
|
+
# has_one association can return nil
|
138
|
+
# .paranoid? will work for both instances and classes
|
139
|
+
next unless association_data && association_data.paranoid?
|
140
|
+
if reflection.collection?
|
141
|
+
next association_data.with_deleted.each(&:really_destroy!)
|
142
|
+
end
|
143
|
+
association_data.really_destroy!
|
144
|
+
end
|
145
|
+
end
|
146
|
+
write_attribute(paranoia_column, current_time_from_proper_timezone)
|
147
|
+
destroy_without_paranoia
|
148
|
+
end
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
127
152
|
private
|
128
153
|
|
129
154
|
def paranoia_restore_attributes
|
@@ -184,31 +209,7 @@ class ActiveRecord::Base
|
|
184
209
|
def self.acts_as_paranoid(options={})
|
185
210
|
alias :really_destroyed? :destroyed?
|
186
211
|
alias :really_delete :delete
|
187
|
-
|
188
212
|
alias :destroy_without_paranoia :destroy
|
189
|
-
def really_destroy!
|
190
|
-
transaction do
|
191
|
-
run_callbacks(:real_destroy) do
|
192
|
-
dependent_reflections = self.class.reflections.select do |name, reflection|
|
193
|
-
reflection.options[:dependent] == :destroy
|
194
|
-
end
|
195
|
-
if dependent_reflections.any?
|
196
|
-
dependent_reflections.each do |name, reflection|
|
197
|
-
association_data = self.send(name)
|
198
|
-
# has_one association can return nil
|
199
|
-
# .paranoid? will work for both instances and classes
|
200
|
-
next unless association_data && association_data.paranoid?
|
201
|
-
if reflection.collection?
|
202
|
-
next association_data.with_deleted.each(&:really_destroy!)
|
203
|
-
end
|
204
|
-
association_data.really_destroy!
|
205
|
-
end
|
206
|
-
end
|
207
|
-
write_attribute(paranoia_column, current_time_from_proper_timezone)
|
208
|
-
destroy_without_paranoia
|
209
|
-
end
|
210
|
-
end
|
211
|
-
end
|
212
213
|
|
213
214
|
include Paranoia
|
214
215
|
class_attribute :paranoia_column, :paranoia_sentinel_value
|
data/lib/paranoia/version.rb
CHANGED
data/test/paranoia_test.rb
CHANGED
@@ -20,6 +20,7 @@ def setup!
|
|
20
20
|
'paranoid_model_with_build_belongs' => 'parent_model_id INTEGER, deleted_at DATETIME, paranoid_model_with_has_one_and_build_id INTEGER, name VARCHAR(32)',
|
21
21
|
'paranoid_model_with_anthor_class_name_belongs' => 'parent_model_id INTEGER, deleted_at DATETIME, paranoid_model_with_has_one_id INTEGER',
|
22
22
|
'paranoid_model_with_foreign_key_belongs' => 'parent_model_id INTEGER, deleted_at DATETIME, has_one_foreign_key_id INTEGER',
|
23
|
+
'paranoid_model_with_timestamps' => 'parent_model_id INTEGER, created_at DATETIME, updated_at DATETIME, deleted_at DATETIME',
|
23
24
|
'not_paranoid_model_with_belongs' => 'parent_model_id INTEGER, paranoid_model_with_has_one_id INTEGER',
|
24
25
|
'paranoid_model_with_has_one_and_builds' => 'parent_model_id INTEGER, color VARCHAR(32), deleted_at DATETIME, has_one_foreign_key_id INTEGER',
|
25
26
|
'featureful_models' => 'deleted_at DATETIME, name VARCHAR(32)',
|
@@ -757,6 +758,19 @@ class ParanoiaTest < test_framework
|
|
757
758
|
refute b.valid?
|
758
759
|
end
|
759
760
|
|
761
|
+
def test_updated_at_modification_on_restore
|
762
|
+
parent1 = ParentModel.create
|
763
|
+
pt1 = ParanoidModelWithTimestamp.create(:parent_model => parent1)
|
764
|
+
ParanoidModelWithTimestamp.record_timestamps = false
|
765
|
+
pt1.update_columns(created_at: 20.years.ago, updated_at: 10.years.ago, deleted_at: 10.years.ago)
|
766
|
+
ParanoidModelWithTimestamp.record_timestamps = true
|
767
|
+
assert pt1.updated_at < 10.minutes.ago
|
768
|
+
refute pt1.deleted_at.nil?
|
769
|
+
pt1.restore!
|
770
|
+
assert pt1.deleted_at.nil?
|
771
|
+
assert pt1.updated_at > 10.minutes.ago
|
772
|
+
end
|
773
|
+
|
760
774
|
def test_i_am_the_destroyer
|
761
775
|
expected = %Q{
|
762
776
|
Sharon: "There should be a method called I_AM_THE_DESTROYER!"
|
@@ -1122,6 +1136,11 @@ class ParanoidModelWithForeignKeyBelong < ActiveRecord::Base
|
|
1122
1136
|
belongs_to :paranoid_model_with_has_one
|
1123
1137
|
end
|
1124
1138
|
|
1139
|
+
class ParanoidModelWithTimestamp < ActiveRecord::Base
|
1140
|
+
belongs_to :parent_model
|
1141
|
+
acts_as_paranoid
|
1142
|
+
end
|
1143
|
+
|
1125
1144
|
class NotParanoidModelWithBelong < ActiveRecord::Base
|
1126
1145
|
belongs_to :paranoid_model_with_has_one
|
1127
1146
|
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.5
|
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:
|
11
|
+
date: 2016-01-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -95,7 +95,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
95
95
|
version: 1.3.6
|
96
96
|
requirements: []
|
97
97
|
rubyforge_project: paranoia
|
98
|
-
rubygems_version: 2.4.5
|
98
|
+
rubygems_version: 2.4.5
|
99
99
|
signing_key:
|
100
100
|
specification_version: 4
|
101
101
|
summary: Paranoia is a re-implementation of acts_as_paranoid for Rails 3, using much,
|