destroyed_at 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/destroyed_at.rb +4 -2
- data/lib/destroyed_at/version.rb +1 -1
- data/test/destroyed_at_test.rb +9 -1
- data/test/test_helper.rb +10 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9bc7d600d04c50b142c9c5191f0c10fc6da97818
|
4
|
+
data.tar.gz: 3013c9ef4cd5f8e2702a9c2299c34277bfddad9c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7344d639a761abc3ba0765fc53e7ffafd94eac0b155879b0e99fc6f937e35f445945667842aff8ebd3f5e71a9c5b933e479ca1059eb24d78851805c26e803265
|
7
|
+
data.tar.gz: 0717292ca7a7b3075d4fb00c49a226a50f91ba337dcdd19866e638604eca59297c3a16110204900e5b9e3d30db9bc4ca04d7eeda21192523b24d879f851771ed
|
data/lib/destroyed_at.rb
CHANGED
@@ -13,7 +13,8 @@ module DestroyedAt
|
|
13
13
|
def destroy
|
14
14
|
run_callbacks(:destroy) do
|
15
15
|
destroy_associations
|
16
|
-
self.
|
16
|
+
self.destroyed_at = current_time_from_proper_timezone
|
17
|
+
self.save(callbacks: false)
|
17
18
|
@destroyed = true
|
18
19
|
end
|
19
20
|
end
|
@@ -22,7 +23,8 @@ module DestroyedAt
|
|
22
23
|
def restore
|
23
24
|
state = nil
|
24
25
|
run_callbacks(:restore) do
|
25
|
-
|
26
|
+
self.destroyed_at = nil
|
27
|
+
if state = self.save(callbacks: false)
|
26
28
|
@destroyed = false
|
27
29
|
_restore_associations
|
28
30
|
end
|
data/lib/destroyed_at/version.rb
CHANGED
data/test/destroyed_at_test.rb
CHANGED
@@ -108,7 +108,7 @@ describe 'Destroying AR models' do
|
|
108
108
|
2.times do
|
109
109
|
User.create(dinners: [Dinner.create, Dinner.create, Dinner.create])
|
110
110
|
end
|
111
|
-
|
111
|
+
|
112
112
|
User.first.destroy
|
113
113
|
Dinner.count.must_equal 3
|
114
114
|
User.first.destroy
|
@@ -116,4 +116,12 @@ describe 'Destroying AR models' do
|
|
116
116
|
User.unscoped.first.restore
|
117
117
|
Dinner.count.must_equal 3
|
118
118
|
end
|
119
|
+
|
120
|
+
it 'skips callbacks' do
|
121
|
+
user = User.create
|
122
|
+
user.destroy
|
123
|
+
user.before_save_count.must_equal nil
|
124
|
+
user.restore
|
125
|
+
user.before_save_count.must_equal nil
|
126
|
+
end
|
119
127
|
end
|
data/test/test_helper.rb
CHANGED
@@ -42,6 +42,16 @@ class User < ActiveRecord::Base
|
|
42
42
|
has_one :show
|
43
43
|
has_many :fleets
|
44
44
|
has_many :cars, :through => :fleets, :dependent => :destroy
|
45
|
+
before_save :increment_counter
|
46
|
+
|
47
|
+
attr_accessor :before_save_count
|
48
|
+
|
49
|
+
private
|
50
|
+
|
51
|
+
def increment_counter
|
52
|
+
@counter ||= 0
|
53
|
+
@counter = @counter + 1
|
54
|
+
end
|
45
55
|
end
|
46
56
|
|
47
57
|
class Person < User
|