acts_as_paranoid 0.4.2 → 0.4.3.pre
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE +1 -1
- data/{README.markdown → README.md} +15 -11
- data/lib/acts_as_paranoid.rb +8 -15
- data/lib/acts_as_paranoid/core.rb +14 -6
- data/lib/acts_as_paranoid/relation.rb +2 -2
- data/lib/acts_as_paranoid/version.rb +3 -0
- data/test/test_associations.rb +222 -0
- data/test/test_core.rb +387 -0
- data/test/test_default_scopes.rb +52 -0
- data/test/test_helper.rb +442 -0
- data/test/test_inheritance.rb +14 -0
- data/test/test_observers.rb +16 -0
- data/test/test_relations.rb +117 -0
- data/test/test_validations.rb +42 -0
- metadata +92 -24
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class InheritanceTest < ParanoidBaseTest
|
4
|
+
def test_destroy_dependents_with_inheritance
|
5
|
+
has_many_inherited_super_paranoidz = HasManyInheritedSuperParanoidz.new
|
6
|
+
has_many_inherited_super_paranoidz.save
|
7
|
+
has_many_inherited_super_paranoidz.super_paranoidz.create
|
8
|
+
assert_nothing_raised(NoMethodError) { has_many_inherited_super_paranoidz.destroy }
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_class_instance_variables_are_inherited
|
12
|
+
assert_nothing_raised(ActiveRecord::StatementInvalid) { InheritedParanoid.paranoid_column }
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class ParanoidObserverTest < ParanoidBaseTest
|
4
|
+
def test_called_observer_methods
|
5
|
+
@subject = ParanoidWithCallback.new
|
6
|
+
@subject.save
|
7
|
+
|
8
|
+
assert_nil ParanoidObserver.instance.called_before_recover
|
9
|
+
assert_nil ParanoidObserver.instance.called_after_recover
|
10
|
+
|
11
|
+
ParanoidWithCallback.find(@subject.id).recover
|
12
|
+
|
13
|
+
assert_equal @subject, ParanoidObserver.instance.called_before_recover
|
14
|
+
assert_equal @subject, ParanoidObserver.instance.called_after_recover
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,117 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class RelationsTest < ParanoidBaseTest
|
4
|
+
def setup
|
5
|
+
setup_db
|
6
|
+
|
7
|
+
@paranoid_forest_1 = ParanoidForest.create! :name => "ParanoidForest #1"
|
8
|
+
@paranoid_forest_2 = ParanoidForest.create! :name => "ParanoidForest #2", :rainforest => true
|
9
|
+
@paranoid_forest_3 = ParanoidForest.create! :name => "ParanoidForest #3", :rainforest => true
|
10
|
+
|
11
|
+
assert_equal 3, ParanoidForest.count
|
12
|
+
assert_equal 2, ParanoidForest.rainforest.count
|
13
|
+
|
14
|
+
@paranoid_forest_1.paranoid_trees.create! :name => 'ParanoidTree #1'
|
15
|
+
@paranoid_forest_1.paranoid_trees.create! :name => 'ParanoidTree #2'
|
16
|
+
@paranoid_forest_2.paranoid_trees.create! :name => 'ParanoidTree #3'
|
17
|
+
@paranoid_forest_2.paranoid_trees.create! :name => 'ParanoidTree #4'
|
18
|
+
|
19
|
+
assert_equal 4, ParanoidTree.count
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_filtering_with_scopes
|
23
|
+
assert_equal 2, ParanoidForest.rainforest.with_deleted.count
|
24
|
+
assert_equal 2, ParanoidForest.with_deleted.rainforest.count
|
25
|
+
|
26
|
+
assert_equal 0, ParanoidForest.rainforest.only_deleted.count
|
27
|
+
assert_equal 0, ParanoidForest.only_deleted.rainforest.count
|
28
|
+
|
29
|
+
ParanoidForest.rainforest.first.destroy
|
30
|
+
assert_equal 1, ParanoidForest.rainforest.count
|
31
|
+
|
32
|
+
assert_equal 2, ParanoidForest.rainforest.with_deleted.count
|
33
|
+
assert_equal 2, ParanoidForest.with_deleted.rainforest.count
|
34
|
+
|
35
|
+
assert_equal 1, ParanoidForest.rainforest.only_deleted.count
|
36
|
+
assert_equal 1, ParanoidForest.only_deleted.rainforest.count
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_associations_filtered_by_with_deleted
|
40
|
+
assert_equal 2, @paranoid_forest_1.paranoid_trees.with_deleted.count
|
41
|
+
assert_equal 2, @paranoid_forest_2.paranoid_trees.with_deleted.count
|
42
|
+
|
43
|
+
@paranoid_forest_1.paranoid_trees.first.destroy
|
44
|
+
assert_equal 1, @paranoid_forest_1.paranoid_trees.count
|
45
|
+
assert_equal 2, @paranoid_forest_1.paranoid_trees.with_deleted.count
|
46
|
+
assert_equal 4, ParanoidTree.with_deleted.count
|
47
|
+
|
48
|
+
@paranoid_forest_2.paranoid_trees.first.destroy
|
49
|
+
assert_equal 1, @paranoid_forest_2.paranoid_trees.count
|
50
|
+
assert_equal 2, @paranoid_forest_2.paranoid_trees.with_deleted.count
|
51
|
+
assert_equal 4, ParanoidTree.with_deleted.count
|
52
|
+
|
53
|
+
@paranoid_forest_1.paranoid_trees.first.destroy
|
54
|
+
assert_equal 0, @paranoid_forest_1.paranoid_trees.count
|
55
|
+
assert_equal 2, @paranoid_forest_1.paranoid_trees.with_deleted.count
|
56
|
+
assert_equal 4, ParanoidTree.with_deleted.count
|
57
|
+
end
|
58
|
+
|
59
|
+
def test_associations_filtered_by_only_deleted
|
60
|
+
assert_equal 0, @paranoid_forest_1.paranoid_trees.only_deleted.count
|
61
|
+
assert_equal 0, @paranoid_forest_2.paranoid_trees.only_deleted.count
|
62
|
+
|
63
|
+
@paranoid_forest_1.paranoid_trees.first.destroy
|
64
|
+
assert_equal 1, @paranoid_forest_1.paranoid_trees.only_deleted.count
|
65
|
+
assert_equal 1, ParanoidTree.only_deleted.count
|
66
|
+
|
67
|
+
@paranoid_forest_2.paranoid_trees.first.destroy
|
68
|
+
assert_equal 1, @paranoid_forest_2.paranoid_trees.only_deleted.count
|
69
|
+
assert_equal 2, ParanoidTree.only_deleted.count
|
70
|
+
|
71
|
+
@paranoid_forest_1.paranoid_trees.first.destroy
|
72
|
+
assert_equal 2, @paranoid_forest_1.paranoid_trees.only_deleted.count
|
73
|
+
assert_equal 3, ParanoidTree.only_deleted.count
|
74
|
+
end
|
75
|
+
|
76
|
+
def test_fake_removal_through_relation
|
77
|
+
# destroy: through a relation.
|
78
|
+
ParanoidForest.rainforest.destroy(@paranoid_forest_3)
|
79
|
+
assert_equal 1, ParanoidForest.rainforest.count
|
80
|
+
assert_equal 2, ParanoidForest.rainforest.with_deleted.count
|
81
|
+
assert_equal 1, ParanoidForest.rainforest.only_deleted.count
|
82
|
+
|
83
|
+
# destroy_all: through a relation
|
84
|
+
@paranoid_forest_2.paranoid_trees.order(:id).destroy_all
|
85
|
+
assert_equal 0, @paranoid_forest_2.paranoid_trees(true).count
|
86
|
+
assert_equal 2, @paranoid_forest_2.paranoid_trees(true).with_deleted.count
|
87
|
+
end
|
88
|
+
|
89
|
+
def test_real_removal_through_relation
|
90
|
+
# destroy!: aliased to delete
|
91
|
+
ParanoidForest.rainforest.destroy!(@paranoid_forest_3)
|
92
|
+
assert_equal 1, ParanoidForest.rainforest.count
|
93
|
+
assert_equal 1, ParanoidForest.rainforest.with_deleted.count
|
94
|
+
assert_equal 0, ParanoidForest.rainforest.only_deleted.count
|
95
|
+
|
96
|
+
# destroy: two-step through a relation
|
97
|
+
paranoid_tree = @paranoid_forest_1.paranoid_trees.first
|
98
|
+
@paranoid_forest_1.paranoid_trees.order(:id).destroy(paranoid_tree)
|
99
|
+
@paranoid_forest_1.paranoid_trees.only_deleted.destroy(paranoid_tree)
|
100
|
+
assert_equal 1, @paranoid_forest_1.paranoid_trees(true).count
|
101
|
+
assert_equal 1, @paranoid_forest_1.paranoid_trees(true).with_deleted.count
|
102
|
+
assert_equal 0, @paranoid_forest_1.paranoid_trees(true).only_deleted.count
|
103
|
+
|
104
|
+
# destroy_all: two-step through a relation
|
105
|
+
@paranoid_forest_1.paranoid_trees.order(:id).destroy_all
|
106
|
+
@paranoid_forest_1.paranoid_trees.only_deleted.destroy_all
|
107
|
+
assert_equal 0, @paranoid_forest_1.paranoid_trees(true).count
|
108
|
+
assert_equal 0, @paranoid_forest_1.paranoid_trees(true).with_deleted.count
|
109
|
+
assert_equal 0, @paranoid_forest_1.paranoid_trees(true).only_deleted.count
|
110
|
+
|
111
|
+
# delete_all!: through a relation
|
112
|
+
@paranoid_forest_2.paranoid_trees.order(:id).delete_all!
|
113
|
+
assert_equal 0, @paranoid_forest_2.paranoid_trees(true).count
|
114
|
+
assert_equal 0, @paranoid_forest_2.paranoid_trees(true).with_deleted.count
|
115
|
+
assert_equal 0, @paranoid_forest_2.paranoid_trees(true).only_deleted.count
|
116
|
+
end
|
117
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class ValidatesUniquenessTest < ParanoidBaseTest
|
4
|
+
def test_should_include_deleted_by_default
|
5
|
+
ParanoidTime.new(:name => 'paranoid').tap do |record|
|
6
|
+
assert !record.valid?
|
7
|
+
ParanoidTime.first.destroy
|
8
|
+
assert !record.valid?
|
9
|
+
ParanoidTime.only_deleted.first.destroy!
|
10
|
+
assert record.valid?
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_should_validate_without_deleted
|
15
|
+
ParanoidBoolean.new(:name => 'paranoid').tap do |record|
|
16
|
+
ParanoidBoolean.first.destroy
|
17
|
+
assert record.valid?
|
18
|
+
ParanoidBoolean.only_deleted.first.destroy!
|
19
|
+
assert record.valid?
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_models_with_scoped_validations_can_be_multiply_deleted
|
24
|
+
model_a = ParanoidWithScopedValidation.create(:name => "Model A", :category => "Category A")
|
25
|
+
model_b = ParanoidWithScopedValidation.create(:name => "Model B", :category => "Category B")
|
26
|
+
|
27
|
+
ParanoidWithScopedValidation.delete([model_a.id, model_b.id])
|
28
|
+
|
29
|
+
assert_paranoid_deletion(model_a)
|
30
|
+
assert_paranoid_deletion(model_b)
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_models_with_scoped_validations_can_be_multiply_destroyed
|
34
|
+
model_a = ParanoidWithScopedValidation.create(:name => "Model A", :category => "Category A")
|
35
|
+
model_b = ParanoidWithScopedValidation.create(:name => "Model B", :category => "Category B")
|
36
|
+
|
37
|
+
ParanoidWithScopedValidation.destroy([model_a.id, model_b.id])
|
38
|
+
|
39
|
+
assert_paranoid_deletion(model_a)
|
40
|
+
assert_paranoid_deletion(model_b)
|
41
|
+
end
|
42
|
+
end
|
metadata
CHANGED
@@ -1,22 +1,22 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: acts_as_paranoid
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
5
|
-
prerelease:
|
4
|
+
version: 0.4.3.pre
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
7
|
+
- Zachary Scott
|
8
|
+
- André Medeiros
|
8
9
|
- Goncalo Silva
|
9
10
|
- Charles G.
|
10
11
|
- Rick Olson
|
11
12
|
autorequire:
|
12
13
|
bindir: bin
|
13
14
|
cert_chain: []
|
14
|
-
date:
|
15
|
+
date: 2014-05-12 00:00:00.000000000 Z
|
15
16
|
dependencies:
|
16
17
|
- !ruby/object:Gem::Dependency
|
17
18
|
name: activerecord
|
18
19
|
requirement: !ruby/object:Gem::Requirement
|
19
|
-
none: false
|
20
20
|
requirements:
|
21
21
|
- - ~>
|
22
22
|
- !ruby/object:Gem::Version
|
@@ -24,15 +24,69 @@ dependencies:
|
|
24
24
|
type: :runtime
|
25
25
|
prerelease: false
|
26
26
|
version_requirements: !ruby/object:Gem::Requirement
|
27
|
-
none: false
|
28
27
|
requirements:
|
29
28
|
- - ~>
|
30
29
|
- !ruby/object:Gem::Version
|
31
30
|
version: '3.2'
|
32
|
-
|
33
|
-
|
31
|
+
- !ruby/object:Gem::Dependency
|
32
|
+
name: bundler
|
33
|
+
requirement: !ruby/object:Gem::Requirement
|
34
|
+
requirements:
|
35
|
+
- - ~>
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '1.5'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
requirements:
|
42
|
+
- - ~>
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: '1.5'
|
45
|
+
- !ruby/object:Gem::Dependency
|
46
|
+
name: rake
|
47
|
+
requirement: !ruby/object:Gem::Requirement
|
48
|
+
requirements:
|
49
|
+
- - '>='
|
50
|
+
- !ruby/object:Gem::Version
|
51
|
+
version: '0'
|
52
|
+
type: :development
|
53
|
+
prerelease: false
|
54
|
+
version_requirements: !ruby/object:Gem::Requirement
|
55
|
+
requirements:
|
56
|
+
- - '>='
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
version: '0'
|
59
|
+
- !ruby/object:Gem::Dependency
|
60
|
+
name: rdoc
|
61
|
+
requirement: !ruby/object:Gem::Requirement
|
62
|
+
requirements:
|
63
|
+
- - '>='
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: '0'
|
66
|
+
type: :development
|
67
|
+
prerelease: false
|
68
|
+
version_requirements: !ruby/object:Gem::Requirement
|
69
|
+
requirements:
|
70
|
+
- - '>='
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: '0'
|
73
|
+
- !ruby/object:Gem::Dependency
|
74
|
+
name: minitest
|
75
|
+
requirement: !ruby/object:Gem::Requirement
|
76
|
+
requirements:
|
77
|
+
- - ~>
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
version: '4.0'
|
80
|
+
type: :development
|
81
|
+
prerelease: false
|
82
|
+
version_requirements: !ruby/object:Gem::Requirement
|
83
|
+
requirements:
|
84
|
+
- - ~>
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
version: '4.0'
|
87
|
+
description: Check the home page for more in-depth information.
|
34
88
|
email:
|
35
|
-
-
|
89
|
+
- e@zzak.io
|
36
90
|
executables: []
|
37
91
|
extensions: []
|
38
92
|
extra_rdoc_files: []
|
@@ -41,35 +95,49 @@ files:
|
|
41
95
|
- lib/acts_as_paranoid/core.rb
|
42
96
|
- lib/acts_as_paranoid/relation.rb
|
43
97
|
- lib/acts_as_paranoid/validations.rb
|
98
|
+
- lib/acts_as_paranoid/version.rb
|
44
99
|
- lib/acts_as_paranoid.rb
|
45
100
|
- LICENSE
|
46
|
-
- README.
|
47
|
-
|
48
|
-
|
101
|
+
- README.md
|
102
|
+
- test/test_associations.rb
|
103
|
+
- test/test_core.rb
|
104
|
+
- test/test_default_scopes.rb
|
105
|
+
- test/test_helper.rb
|
106
|
+
- test/test_inheritance.rb
|
107
|
+
- test/test_observers.rb
|
108
|
+
- test/test_relations.rb
|
109
|
+
- test/test_validations.rb
|
110
|
+
homepage: https://github.com/zzak/acts_as_paranoid
|
111
|
+
licenses:
|
112
|
+
- MIT
|
113
|
+
metadata: {}
|
49
114
|
post_install_message:
|
50
115
|
rdoc_options: []
|
51
116
|
require_paths:
|
52
117
|
- lib
|
53
118
|
required_ruby_version: !ruby/object:Gem::Requirement
|
54
|
-
none: false
|
55
119
|
requirements:
|
56
|
-
- -
|
120
|
+
- - '>='
|
57
121
|
- !ruby/object:Gem::Version
|
58
122
|
version: '0'
|
59
|
-
segments:
|
60
|
-
- 0
|
61
|
-
hash: 713582617655354259
|
62
123
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
63
|
-
none: false
|
64
124
|
requirements:
|
65
|
-
- -
|
125
|
+
- - '>='
|
66
126
|
- !ruby/object:Gem::Version
|
67
127
|
version: 1.3.6
|
68
128
|
requirements: []
|
69
|
-
rubyforge_project:
|
70
|
-
rubygems_version:
|
129
|
+
rubyforge_project:
|
130
|
+
rubygems_version: 2.0.14
|
71
131
|
signing_key:
|
72
|
-
specification_version:
|
73
|
-
summary: Active Record
|
74
|
-
|
75
|
-
test_files:
|
132
|
+
specification_version: 4
|
133
|
+
summary: Active Record plugin which allows you to hide and restore records without
|
134
|
+
actually deleting them.
|
135
|
+
test_files:
|
136
|
+
- test/test_associations.rb
|
137
|
+
- test/test_core.rb
|
138
|
+
- test/test_default_scopes.rb
|
139
|
+
- test/test_helper.rb
|
140
|
+
- test/test_inheritance.rb
|
141
|
+
- test/test_observers.rb
|
142
|
+
- test/test_relations.rb
|
143
|
+
- test/test_validations.rb
|