paranoia 2.1.4 → 2.1.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 45933ae6db17d7ae34422587c41002a61915c588
4
- data.tar.gz: 993a0cf0d2414179bcc916b3a3f00debf582332a
3
+ metadata.gz: 32a4bc8e17adc564a3c87661d90c1457b44323bd
4
+ data.tar.gz: 94527885cf5fb887a88ee2a938472995623639dd
5
5
  SHA512:
6
- metadata.gz: ef70ba0f7801c7f6cc624159120fd149a25d15e3ba8a06b050a1549bedb75bfc4bcf16c70c2882104ee7623294890c4760c2baae0f99ef2eb18dca8093c3a3f1
7
- data.tar.gz: 452e9212c38168259988b8df9e26656cb3799cae8ab093341a9679b5d6b5430eae3430da82d67e4a46aa92cdefd92354dc61d126394e96f934b3bd6fb6119a92
6
+ metadata.gz: 865a43181fa3699d92554cc800dff88a20070f2a00d839bc583c99b9e6ad2da78217711a0ca52cb5c358322a33865dbe378332c90c9182b7cf47971d2751f8a2
7
+ data.tar.gz: d55b46e33174f428e607557b60ba25b8adf6058acdac6dedd3aad00d5f010d7df4c9a5045b9d445c6d640ec1606399f75fbf0f383a6f8297569fd8b90c3d29f8
@@ -1,8 +1,10 @@
1
+ sudo: false
1
2
  language: ruby
2
3
  rvm:
3
4
  - 2.0.0
4
5
  - 2.1.0
5
6
  - 2.2.0
7
+ - 2.3.0
6
8
  - jruby-19mode
7
9
 
8
10
  env:
@@ -1,5 +1,17 @@
1
1
  # paranoia Changelog
2
2
 
3
+ ## 2.1.5 (2016-01-06)
4
+
5
+ * Ruby 2.3 support
6
+
7
+ ## 2.1.4
8
+
9
+ ## 2.1.3
10
+
11
+ ## 2.1.2
12
+
13
+ ## 2.1.1
14
+
3
15
  ## 2.1.0 (2015-01-23)
4
16
 
5
17
  ### Major changes
@@ -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
@@ -1,3 +1,3 @@
1
1
  module Paranoia
2
- VERSION = "2.1.4"
2
+ VERSION = "2.1.5"
3
3
  end
@@ -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
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: 2015-11-05 00:00:00.000000000 Z
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.1
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,