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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5d06484805624dd702d8643850b8f78b685c98af
4
- data.tar.gz: d0d99bfb2bcabbf43ba9b862ee70feeef8a25397
3
+ metadata.gz: 9bc7d600d04c50b142c9c5191f0c10fc6da97818
4
+ data.tar.gz: 3013c9ef4cd5f8e2702a9c2299c34277bfddad9c
5
5
  SHA512:
6
- metadata.gz: 2e0fff0a4085b7a3ee28b2fec68eb9899b91689933fa1abf1e3deb780eac1b7d1d3259041033879f65bc580d8c99cc5ce736f3242aacf0359133354ec044d2f0
7
- data.tar.gz: 4e13c5e59e4a735df53c146a1c60c35852b74f2f2164e9ae2d8ed6ccb282b9066d26a69a62540c84b8cbc3b378fbfa1fbd6b0d00637e88644bd57fa299aaa265
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.update_attribute(:destroyed_at, current_time_from_proper_timezone)
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
- if state = self.update_attribute(:destroyed_at, nil)
26
+ self.destroyed_at = nil
27
+ if state = self.save(callbacks: false)
26
28
  @destroyed = false
27
29
  _restore_associations
28
30
  end
@@ -1,3 +1,3 @@
1
1
  module DestroyedAt
2
- VERSION = "0.1.3"
2
+ VERSION = "0.1.4"
3
3
  end
@@ -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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: destroyed_at
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Dupuis Jr.