delete_paranoid 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,3 @@
1
1
  module DeleteParanoid
2
- VERSION = "1.0.0"
2
+ VERSION = "1.0.1"
3
3
  end
@@ -17,6 +17,7 @@ module DeleteParanoid
17
17
  default_scope where(:deleted_at => nil)
18
18
 
19
19
  extend DeleteParanoid::ClassMethods
20
+ include DeleteParanoid::InstanceMethods
20
21
  end
21
22
 
22
23
  def paranoid?
@@ -39,6 +40,25 @@ module DeleteParanoid
39
40
  true
40
41
  end
41
42
  end
43
+
44
+ module InstanceMethods
45
+ # permenantly delete this specific instance from the database
46
+ def destroy!
47
+ result = destroy
48
+ self.class.with_deleted do
49
+ self.class.delete! self.id
50
+ end
51
+ result
52
+ end
53
+ # permenantly delete this specific instance from the database
54
+ def delete!
55
+ result = delete
56
+ self.class.with_deleted do
57
+ self.class.delete! self.id
58
+ end
59
+ result
60
+ end
61
+ end
42
62
  end
43
63
 
44
64
  ActiveRecord::Base.send(:extend, DeleteParanoid::ActiveRecordExtensions)
data/test/helper.rb CHANGED
@@ -37,7 +37,7 @@ class Test::Unit::TestCase
37
37
  destroyed_subject = instance_variable_get(:"@#{subject}")
38
38
  destroyed_subject.class.with_deleted do
39
39
  assert_nothing_raised ActiveRecord::RecordNotFound do
40
- destroyed_subject.class.find destroyed_subject.id
40
+ assert_not_nil destroyed_subject.class.find destroyed_subject.id
41
41
  end
42
42
  end
43
43
  end
@@ -31,7 +31,7 @@ class TestDeleteParanoid < Test::Unit::TestCase
31
31
  setup do
32
32
  @blog = Blog.create! :title => 'foo'
33
33
  end
34
- context 'when destroying instance' do
34
+ context 'when destroying instance with instance.destroy' do
35
35
  setup do
36
36
  @now = Time.now.utc
37
37
  Timecop.travel @now do
@@ -49,7 +49,7 @@ class TestDeleteParanoid < Test::Unit::TestCase
49
49
  assert_equal @now.to_i, blog.deleted_at.to_i
50
50
  end
51
51
  end
52
- context 'when destroying instance with destroy_all' do
52
+ context 'when destroying instance with Class.destroy_all' do
53
53
  setup do
54
54
  Blog.destroy_all :id => @blog.id
55
55
  end
@@ -66,20 +66,31 @@ class TestDeleteParanoid < Test::Unit::TestCase
66
66
  end
67
67
  end
68
68
  end
69
- context "when destroying instance with delete_all!" do
69
+ context "when destroying instance with Class.delete_all!" do
70
70
  setup do
71
- @blog = Blog.create! :title => 'foo'
72
71
  Blog.where({:id => @blog.id}).delete_all!
73
72
  end
74
73
  should_hard_destroy :blog
75
74
  end
76
- context "when destroying instance with delete!" do
75
+ context "when destroying instance with Class.delete!" do
77
76
  setup do
78
- @blog = Blog.create! :title => 'foo'
79
77
  Blog.delete! @blog.id
80
78
  end
81
79
  should_hard_destroy :blog
82
80
  end
81
+ context 'when destroying instance with instance.destroy!' do
82
+ setup do
83
+ @blog.destroy!
84
+ end
85
+ should_hard_destroy :blog
86
+ should_trigger_destroy_callbacks :blog
87
+ end
88
+ context 'when destroying instance with instance.delete!' do
89
+ setup do
90
+ @blog.delete!
91
+ end
92
+ should_hard_destroy :blog
93
+ end
83
94
  end
84
95
 
85
96
  context 'with paranoid instance that has dependents' do
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: delete_paranoid
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
4
+ hash: 21
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
8
  - 0
9
- - 0
10
- version: 1.0.0
9
+ - 1
10
+ version: 1.0.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Ryan Sonnek