mongoid-ordering 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/mongoid/ordering.rb +10 -0
- data/spec/mongoid/ordering_spec.rb +18 -6
- data/spec/support/models.rb +3 -2
- metadata +12 -12
data/lib/mongoid/ordering.rb
CHANGED
@@ -205,6 +205,16 @@ module Mongoid
|
|
205
205
|
private
|
206
206
|
|
207
207
|
def move_lower_siblings_up
|
208
|
+
return if self.ordering_scopes.any? do |scope|
|
209
|
+
scope_metadata = self.reflect_on_association(scope)
|
210
|
+
next if scope_metadata.nil?
|
211
|
+
|
212
|
+
relation = send(scope_metadata.name)
|
213
|
+
next if relation.nil?
|
214
|
+
|
215
|
+
relation.flagged_for_destroy? && scope_metadata.inverse_metadata(relation).destructive?
|
216
|
+
end
|
217
|
+
|
208
218
|
self.lower_siblings.each { |s| s.inc(:position, -1) }
|
209
219
|
end
|
210
220
|
|
@@ -277,15 +277,27 @@ describe Mongoid::Ordering do
|
|
277
277
|
|
278
278
|
describe "destroying a document" do
|
279
279
|
|
280
|
-
let!(:
|
281
|
-
let!(:
|
282
|
-
let!(:
|
280
|
+
let!(:parent1) { DummyParentDocument.create }
|
281
|
+
let!(:parent2) { DummyParentDocument.create }
|
282
|
+
let!(:parent3) { DummyParentDocument.create }
|
283
|
+
let!(:parent3_child1) { DummyChildDocument.create(parent: parent3) }
|
284
|
+
let!(:parent3_child2) { DummyChildDocument.create(parent: parent3) }
|
285
|
+
let!(:parent3_child3) { DummyChildDocument.create(parent: parent3) }
|
283
286
|
|
284
287
|
it "moves lower siblings up" do
|
285
|
-
|
288
|
+
parent2.destroy
|
286
289
|
|
287
|
-
|
288
|
-
|
290
|
+
parent1.reload.position.should eq(0)
|
291
|
+
parent3.reload.position.should eq(1)
|
292
|
+
end
|
293
|
+
|
294
|
+
context "when deletion is cascaded to the document's children" do
|
295
|
+
|
296
|
+
it "doesn't move lower siblings of those children up" do
|
297
|
+
DummyChildDocument.any_instance.should_not_receive(:inc)
|
298
|
+
|
299
|
+
parent3.destroy
|
300
|
+
end
|
289
301
|
end
|
290
302
|
end
|
291
303
|
end
|
data/spec/support/models.rb
CHANGED
@@ -5,7 +5,8 @@ class DummyParentDocument
|
|
5
5
|
ordered scope: nil
|
6
6
|
|
7
7
|
has_many :children, class_name: "DummyChildDocument",
|
8
|
-
inverse_of: :parent
|
8
|
+
inverse_of: :parent,
|
9
|
+
dependent: :destroy
|
9
10
|
end
|
10
11
|
|
11
12
|
class DummyChildDocument
|
@@ -14,6 +15,6 @@ class DummyChildDocument
|
|
14
15
|
|
15
16
|
ordered scope: :parent
|
16
17
|
|
17
|
-
belongs_to :parent, class_name: DummyParentDocument
|
18
|
+
belongs_to :parent, class_name: "DummyParentDocument",
|
18
19
|
inverse_of: :children
|
19
20
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mongoid-ordering
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2013-08-01 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: mongoid
|
16
|
-
requirement: &
|
16
|
+
requirement: &70141127517200 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '3.0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70141127517200
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: mongoid-siblings
|
27
|
-
requirement: &
|
27
|
+
requirement: &70141127516720 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ~>
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: 0.1.0
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70141127516720
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: rake
|
38
|
-
requirement: &
|
38
|
+
requirement: &70141127516340 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70141127516340
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: rspec
|
49
|
-
requirement: &
|
49
|
+
requirement: &70141127515880 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,7 +54,7 @@ dependencies:
|
|
54
54
|
version: '0'
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *70141127515880
|
58
58
|
description: mongoid-ordering makes it easy to keep your Mongoid documents in order.
|
59
59
|
email: douwe@selenight.nl
|
60
60
|
executables: []
|
@@ -84,7 +84,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
84
84
|
version: '0'
|
85
85
|
segments:
|
86
86
|
- 0
|
87
|
-
hash:
|
87
|
+
hash: -1977126769264338189
|
88
88
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
89
89
|
none: false
|
90
90
|
requirements:
|
@@ -93,7 +93,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
93
93
|
version: '0'
|
94
94
|
segments:
|
95
95
|
- 0
|
96
|
-
hash:
|
96
|
+
hash: -1977126769264338189
|
97
97
|
requirements: []
|
98
98
|
rubyforge_project:
|
99
99
|
rubygems_version: 1.8.6
|