soft_deletion 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +1 -1
- data/gemfiles/rails2.gemfile.lock +1 -1
- data/gemfiles/rails3.gemfile.lock +1 -1
- data/lib/soft_deletion/version.rb +1 -1
- data/lib/soft_deletion.rb +6 -1
- data/test/soft_deletion_test.rb +19 -4
- metadata +4 -4
data/Gemfile.lock
CHANGED
data/lib/soft_deletion.rb
CHANGED
@@ -8,7 +8,12 @@ module SoftDeletion
|
|
8
8
|
raise "You can only include this if #{base} extends ActiveRecord::Base"
|
9
9
|
end
|
10
10
|
base.extend(ClassMethods)
|
11
|
-
|
11
|
+
|
12
|
+
# Avoids a bad SQL request with versions of code without the colun deleted_at (for example a migration prior to the migration
|
13
|
+
# that adds deleted_at)
|
14
|
+
if base.column_names.include?('deleted_at')
|
15
|
+
base.send(:default_scope, :conditions => base.soft_delete_default_scope_conditions)
|
16
|
+
end
|
12
17
|
|
13
18
|
# backport after_soft_delete so we can safely upgrade to rails 3
|
14
19
|
if ActiveRecord::VERSION::MAJOR > 2
|
data/test/soft_deletion_test.rb
CHANGED
@@ -20,6 +20,9 @@ ActiveRecord::Schema.define(:version => 1) do
|
|
20
20
|
create_table :categories do |t|
|
21
21
|
t.timestamp :deleted_at
|
22
22
|
end
|
23
|
+
|
24
|
+
create_table :original_categories do |t|
|
25
|
+
end
|
23
26
|
end
|
24
27
|
|
25
28
|
class ActiveRecord::Base
|
@@ -45,31 +48,35 @@ end
|
|
45
48
|
|
46
49
|
# No association
|
47
50
|
class NACategory < ActiveRecord::Base
|
48
|
-
include SoftDeletion
|
49
51
|
silent_set_table_name 'categories'
|
52
|
+
include SoftDeletion
|
50
53
|
end
|
51
54
|
|
52
55
|
# Independent association
|
53
56
|
class IDACategory < ActiveRecord::Base
|
54
|
-
include SoftDeletion
|
55
57
|
silent_set_table_name 'categories'
|
58
|
+
include SoftDeletion
|
56
59
|
has_many :forums, :dependent => :destroy, :foreign_key => :category_id
|
57
60
|
end
|
58
61
|
|
59
62
|
# Nullified dependent association
|
60
63
|
class NDACategory < ActiveRecord::Base
|
61
|
-
include SoftDeletion
|
62
64
|
silent_set_table_name 'categories'
|
65
|
+
include SoftDeletion
|
63
66
|
has_many :forums, :dependent => :destroy, :foreign_key => :category_id
|
64
67
|
end
|
65
68
|
|
66
69
|
# Has ome association
|
67
70
|
class HOACategory < ActiveRecord::Base
|
68
|
-
include SoftDeletion
|
69
71
|
silent_set_table_name 'categories'
|
72
|
+
include SoftDeletion
|
70
73
|
has_one :forum, :dependent => :destroy, :foreign_key => :category_id
|
71
74
|
end
|
72
75
|
|
76
|
+
# Class without column deleted_at
|
77
|
+
class OriginalCategory < ActiveRecord::Base
|
78
|
+
include SoftDeletion
|
79
|
+
end
|
73
80
|
|
74
81
|
def clear_callbacks(model, callback)
|
75
82
|
if ActiveRecord::VERSION::MAJOR > 2
|
@@ -214,4 +221,12 @@ class SoftDeletionTest < ActiveSupport::TestCase
|
|
214
221
|
#assert_nil forum.category_id # TODO
|
215
222
|
end
|
216
223
|
end
|
224
|
+
|
225
|
+
context 'without deleted_at column' do
|
226
|
+
should 'default scope should not provoke an error' do
|
227
|
+
assert_nothing_raised do
|
228
|
+
OriginalCategory.create!
|
229
|
+
end
|
230
|
+
end
|
231
|
+
end
|
217
232
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: soft_deletion
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 19
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 4
|
10
|
+
version: 0.1.4
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Zendesk
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2012-05
|
18
|
+
date: 2012-06-05 00:00:00 Z
|
19
19
|
dependencies: []
|
20
20
|
|
21
21
|
description:
|