soft_deletion 0.2.1 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- soft_deletion (0.2.1)
4
+ soft_deletion (0.3.0)
5
5
 
6
6
  GEM
7
7
  remote: http://rubygems.org/
data/Readme.md CHANGED
@@ -12,8 +12,8 @@ Usage
12
12
  class User < ActiveRecord::Base
13
13
  has_soft_deletion :default_scope => true
14
14
 
15
- after_soft_delete :send_deletion_emails # Rails 2 + 3
16
- set_callback :soft_delete, :after, :prepare_emails # Rails 3
15
+ before_soft_delete :validate_deletability # soft_delete stops if this returns false
16
+ after_soft_delete :send_deletion_emails
17
17
 
18
18
  has_many :products
19
19
  end
@@ -38,12 +38,6 @@ Usage
38
38
  # soft delete many
39
39
  User.soft_delete_all!(1,2,3,4)
40
40
 
41
-
42
- TODO
43
- ====
44
- - Rails 3 with inspiration from https://github.com/JackDanger/permanent_records/blob/master/lib/permanent_records.rb
45
- - maybe stuff from https://github.com/smoku/soft_delete
46
-
47
41
  Authors
48
42
  =======
49
43
 
@@ -51,8 +45,9 @@ Authors
51
45
  - [Michel Pigassou](https://github.com/Dagnan)
52
46
  - [Steven Davidovitz](https://github.com/steved555)
53
47
  - [PikachuEXE](https://github.com/PikachuEXE)
48
+ - [Noel Dellofano](https://github.com/pinkvelociraptor)
54
49
 
55
50
  [Zendesk](http://zendesk.com)<br/>
56
51
  michael@grosser.it<br/>
57
52
  License: MIT<br/>
58
- [![Build Status](https://secure.travis-ci.org/grosser/soft_deletion.png)](http://travis-ci.org/grosser/soft_deletion)
53
+ [![Build Status](https://travis-ci.org/grosser/soft_deletion.png)](https://travis-ci.org/grosser/soft_deletion)
@@ -0,0 +1,20 @@
1
+ -----BEGIN CERTIFICATE-----
2
+ MIIDMjCCAhqgAwIBAgIBADANBgkqhkiG9w0BAQUFADA/MRAwDgYDVQQDDAdtaWNo
3
+ YWVsMRcwFQYKCZImiZPyLGQ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XCKM5pon/GU
19
+ ycwMXfl0
20
+ -----END CERTIFICATE-----
@@ -7,6 +7,7 @@ gem "rake"
7
7
  gem "sqlite3"
8
8
  gem "rspec"
9
9
  gem "database_cleaner"
10
+ gem "bump"
10
11
  gem "activerecord", "2.3.14"
11
12
  gem "activesupport", "2.3.14"
12
13
 
@@ -7,6 +7,7 @@ gem "rake"
7
7
  gem "sqlite3"
8
8
  gem "rspec"
9
9
  gem "database_cleaner"
10
+ gem "bump"
10
11
  gem "activerecord", "3.2.3"
11
12
  gem "activesupport", "3.2.3"
12
13
 
@@ -8,16 +8,7 @@ module SoftDeletion
8
8
 
9
9
  # backport after_soft_delete so we can safely upgrade to rails 3
10
10
  if ActiveRecord::VERSION::MAJOR > 2
11
- base.define_callbacks :soft_delete
12
- class << base
13
- def before_soft_delete(*callbacks, &block)
14
- set_callback :soft_delete, :before, *callbacks, &block
15
- end
16
-
17
- def after_soft_delete(*callbacks, &block)
18
- set_callback :soft_delete, :after, *callbacks, &block
19
- end
20
- end
11
+ base.define_model_callbacks :soft_delete
21
12
  else
22
13
  base.define_callbacks :before_soft_delete
23
14
  base.define_callbacks :after_soft_delete
@@ -106,7 +97,7 @@ module SoftDeletion
106
97
  result = block.call
107
98
  end
108
99
  else
109
- run_callbacks :before_soft_delete
100
+ return false if !run_callbacks(:before_soft_delete) { |result, object| result == false }
110
101
  mark_as_deleted
111
102
  soft_delete_dependencies.each(&:soft_delete!)
112
103
  result = block.call
@@ -1,3 +1,3 @@
1
1
  module SoftDeletion
2
- VERSION = '0.2.1'
2
+ VERSION = '0.3.0'
3
3
  end
@@ -1,4 +1,4 @@
1
- $LOAD_PATH.unshift File.expand_path('../lib', __FILE__)
1
+ $LOAD_PATH.unshift File.expand_path("../lib", __FILE__)
2
2
  name = "soft_deletion"
3
3
  require "#{name}/version"
4
4
 
@@ -6,7 +6,9 @@ Gem::Specification.new name, SoftDeletion::VERSION do |s|
6
6
  s.summary = "Explicit soft deletion for ActiveRecord via deleted_at and default scope."
7
7
  s.authors = ["Zendesk"]
8
8
  s.email = "michael@grosser.it"
9
- s.homepage = "http://github.com/grosser/#{name}"
9
+ s.homepage = "https://github.com/grosser/#{name}"
10
10
  s.files = `git ls-files`.split("\n")
11
- s.license = 'MIT'
11
+ s.license = "MIT"
12
+ s.signing_key = File.expand_path("~/.ssh/gem-private_key.pem")
13
+ s.cert_chain = ["gem-public_cert.pem"]
12
14
  end
@@ -47,7 +47,7 @@ describe SoftDeletion do
47
47
 
48
48
  describe "callbacks" do
49
49
  describe ".before_soft_delete" do
50
- it "should be called on soft-deletion" do
50
+ it "is called on soft-deletion" do
51
51
  Category.before_soft_delete :foo
52
52
  category = Category.create!
53
53
 
@@ -55,10 +55,22 @@ describe SoftDeletion do
55
55
 
56
56
  category.soft_delete!
57
57
  end
58
+
59
+ it "stops execution chain if false is returned" do
60
+ Category.before_soft_delete :foo, :bar
61
+ category = Category.create!
62
+
63
+ category.should_receive(:foo).and_return(false)
64
+ category.should_not_receive(:bar)
65
+
66
+ category.soft_delete!
67
+ category.reload
68
+ category.should_not be_deleted
69
+ end
58
70
  end
59
71
 
60
72
  describe ".after_soft_delete" do
61
- it "should be called after soft-deletion" do
73
+ it "is called after soft-deletion" do
62
74
  Category.after_soft_delete :foo
63
75
  category = Category.create!
64
76
 
@@ -67,7 +79,7 @@ describe SoftDeletion do
67
79
  category.soft_delete!
68
80
  end
69
81
 
70
- it "should be called after bulk soft-deletion" do
82
+ it "is called after bulk soft-deletion" do
71
83
  Category.after_soft_delete :foo
72
84
  category = Category.create!
73
85
 
@@ -85,7 +97,7 @@ describe SoftDeletion do
85
97
  category.soft_delete!
86
98
  end
87
99
 
88
- it "should be call multiple after soft-deletion" do
100
+ it "calls multiple after soft-deletion" do
89
101
  Category.after_soft_delete :foo, :bar
90
102
  category = Category.create!
91
103
 
@@ -95,7 +107,19 @@ describe SoftDeletion do
95
107
  category.soft_delete!
96
108
  end
97
109
 
98
- it "should not be called after normal destroy" do
110
+ it "does not stop deletion when returning false" do
111
+ Category.after_soft_delete :foo
112
+ category = Category.create!
113
+
114
+ category.should_receive(:foo).and_return false
115
+
116
+ category.soft_delete!
117
+
118
+ category.reload
119
+ category.should be_deleted
120
+ end
121
+
122
+ it "is not called after normal destroy" do
99
123
  Category.after_soft_delete :foo
100
124
  category = Category.create!
101
125
 
data.tar.gz.sig ADDED
Binary file
metadata CHANGED
@@ -1,15 +1,42 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: soft_deletion
3
3
  version: !ruby/object:Gem::Version
4
+ version: 0.3.0
4
5
  prerelease:
5
- version: 0.2.1
6
6
  platform: ruby
7
7
  authors:
8
8
  - Zendesk
9
9
  autorequire:
10
10
  bindir: bin
11
- cert_chain: []
12
- date: 2012-12-30 00:00:00.000000000 Z
11
+ cert_chain:
12
+ - !binary |-
13
+ LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSURNakNDQWhxZ0F3SUJB
14
+ Z0lCQURBTkJna3Foa2lHOXcwQkFRVUZBREEvTVJBd0RnWURWUVFEREFkdGFX
15
+ Tm8KWVdWc01SY3dGUVlLQ1pJbWlaUHlMR1FCR1JZSFozSnZjM05sY2pFU01C
16
+ QUdDZ21TSm9tVDhpeGtBUmtXQW1sMApNQjRYRFRFek1ESXdNekU0TVRNeE1W
17
+ b1hEVEUwTURJd016RTRNVE14TVZvd1B6RVFNQTRHQTFVRUF3d0hiV2xqCmFH
18
+ RmxiREVYTUJVR0NnbVNKb21UOGl4a0FSa1dCMmR5YjNOelpYSXhFakFRQmdv
19
+ SmtpYUprL0lzWkFFWkZnSnAKZERDQ0FTSXdEUVlKS29aSWh2Y05BUUVCQlFB
20
+ RGdnRVBBRENDQVFvQ2dnRUJBTW9yWG8vaGdiVXE5NytrSUk5SApNc1FjTGRD
21
+ Lzd3UTFaUDJPc2hWSFBrZVAwcUg4TUJIR2c2ZVlpc09YMnViTmFnRjlZVENa
22
+ V25ocmRLcndwTE9PCmNQTGFaYmpVamxqSjNjUV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S0tLS0tCg==
39
+ date: 2013-02-19 00:00:00.000000000 Z
13
40
  dependencies: []
14
41
  description:
15
42
  email: michael@grosser.it
@@ -25,6 +52,7 @@ files:
25
52
  - MIT-LICENSE
26
53
  - Rakefile
27
54
  - Readme.md
55
+ - gem-public_cert.pem
28
56
  - gemfiles/rails2.gemfile
29
57
  - gemfiles/rails3.gemfile
30
58
  - lib/soft_deletion.rb
@@ -35,7 +63,7 @@ files:
35
63
  - soft_deletion.gemspec
36
64
  - spec/soft_deletion_spec.rb
37
65
  - spec/spec_helper.rb
38
- homepage: http://github.com/grosser/soft_deletion
66
+ homepage: https://github.com/grosser/soft_deletion
39
67
  licenses:
40
68
  - MIT
41
69
  post_install_message:
@@ -43,23 +71,23 @@ rdoc_options: []
43
71
  require_paths:
44
72
  - lib
45
73
  required_ruby_version: !ruby/object:Gem::Requirement
74
+ none: false
46
75
  requirements:
47
76
  - - ! '>='
48
77
  - !ruby/object:Gem::Version
49
78
  version: '0'
50
79
  segments:
51
80
  - 0
52
- hash: 3946818531354053907
53
- none: false
81
+ hash: -3470966134953021274
54
82
  required_rubygems_version: !ruby/object:Gem::Requirement
83
+ none: false
55
84
  requirements:
56
85
  - - ! '>='
57
86
  - !ruby/object:Gem::Version
58
87
  version: '0'
59
88
  segments:
60
89
  - 0
61
- hash: 3946818531354053907
62
- none: false
90
+ hash: -3470966134953021274
63
91
  requirements: []
64
92
  rubyforge_project:
65
93
  rubygems_version: 1.8.24
metadata.gz.sig ADDED
Binary file