snusnu-dm-is-awesome_set 0.7.1 → 0.10.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README +17 -1
- data/Rakefile +5 -6
- data/lib/dm-is-awesome_set.rb +0 -1
- data/lib/dm-is-awesome_set/is/awesome_set.rb +3 -3
- data/spec/dm-is-awesome_set_spec.rb +569 -241
- metadata +11 -17
data/README
CHANGED
@@ -6,9 +6,25 @@ I _think_ it does. Please test this out and let me know at jnicoll@gnexp.com
|
|
6
6
|
if you run into any problems. This readme will eventually have examples. Until
|
7
7
|
then, check the RDoc's and you should be fine.
|
8
8
|
|
9
|
+
The latest versions of merb_datamapper by default use repository blocks which
|
10
|
+
also enable the Identity Map. This plugin relies on dm_adjust which does not
|
11
|
+
currently work with the Identity Map. Please add this line to your config/init.rb
|
12
|
+
file in your Merb project:
|
13
|
+
|
14
|
+
Merb::Plugins.config[:merb_datamapper][:use_repository_block] = false
|
15
|
+
|
16
|
+
If you want to activate the IM, simply wrap code in a DataMapper repository block
|
17
|
+
like so:
|
18
|
+
|
19
|
+
DataMapper.repository do
|
20
|
+
# Your code here
|
21
|
+
end
|
22
|
+
|
9
23
|
A quick note about discriminators:
|
10
24
|
|
11
25
|
This version enables scoping that can either include or ignore discriminators.
|
12
26
|
If you wish to scope by a discriminator, please include that column name in
|
13
27
|
the scope option. Otherwise this plugin will work with all rows regardless of
|
14
|
-
the discriminator column.
|
28
|
+
the discriminator column.
|
29
|
+
|
30
|
+
|
data/Rakefile
CHANGED
@@ -4,9 +4,9 @@ require 'rake/gempackagetask'
|
|
4
4
|
GEM_NAME = 'dm-is-awesome_set'
|
5
5
|
|
6
6
|
spec = Gem::Specification.new do |s|
|
7
|
-
s.rubyforge_project =
|
7
|
+
s.rubyforge_project = GEM_NAME
|
8
8
|
s.name = GEM_NAME
|
9
|
-
s.version = "0.
|
9
|
+
s.version = "0.10.0"
|
10
10
|
s.platform = Gem::Platform::RUBY
|
11
11
|
s.has_rdoc = true
|
12
12
|
s.extra_rdoc_files = ["README", "LICENSE", 'TODO']
|
@@ -15,10 +15,9 @@ spec = Gem::Specification.new do |s|
|
|
15
15
|
s.author = "Jeremy Nicoll"
|
16
16
|
s.email = "jnicoll@gnexp.com"
|
17
17
|
s.homepage = "http://gnexp.com/"
|
18
|
-
s.add_dependency('dm-core',
|
19
|
-
s.add_dependency('dm-adjust',
|
20
|
-
s.add_dependency('dm-aggregates', '>= 0.
|
21
|
-
s.add_dependency('dm-validations', '>= 0.9.10')
|
18
|
+
s.add_dependency('dm-core', '>= 0.10.0')
|
19
|
+
s.add_dependency('dm-adjust', '>= 0.10.0')
|
20
|
+
s.add_dependency('dm-aggregates', '>= 0.10.0')
|
22
21
|
s.require_path = 'lib'
|
23
22
|
s.files = %w(LICENSE README Rakefile TODO) + Dir.glob("{lib,spec}/**/*")
|
24
23
|
end
|
data/lib/dm-is-awesome_set.rb
CHANGED
@@ -31,7 +31,7 @@ module DataMapper
|
|
31
31
|
property :lft, Integer, :writer => :private, :index => true
|
32
32
|
property :rgt, Integer, :writer => :private, :index => true
|
33
33
|
|
34
|
-
class_opts = {:
|
34
|
+
class_opts = {:model => self.name, :child_key => opts[:child_key], :order => [:lft.asc], :writer => :protected}
|
35
35
|
belongs_to :parent, class_opts
|
36
36
|
has n, :children, class_opts
|
37
37
|
|
@@ -153,7 +153,7 @@ module DataMapper
|
|
153
153
|
def move(vector)
|
154
154
|
transaction do
|
155
155
|
move_without_saving(vector)
|
156
|
-
save!
|
156
|
+
respond_to?(:save!) ? save! : save
|
157
157
|
end
|
158
158
|
reload
|
159
159
|
end
|
@@ -229,7 +229,7 @@ module DataMapper
|
|
229
229
|
|
230
230
|
def update!(hash) #:nodoc#
|
231
231
|
attributes_set(hash)
|
232
|
-
save!
|
232
|
+
respond_to?(:save!) ? save! : save
|
233
233
|
end
|
234
234
|
|
235
235
|
# Destroys the current node and all children nodes, running their before and after hooks
|
@@ -5,250 +5,578 @@ scope = {:scope => 1, :scope_2 => 2}
|
|
5
5
|
scope2 = {:scope => 1, :scope_2 => 5}
|
6
6
|
|
7
7
|
describe DataMapper::Is::AwesomeSet do
|
8
|
-
before :each do
|
9
|
-
Category.auto_migrate!
|
10
|
-
Discrim1.auto_migrate!
|
11
|
-
Discrim2.auto_migrate!
|
12
|
-
end
|
13
|
-
|
14
|
-
it "puts itself as the last root in the defined scope on initial save" do
|
15
|
-
|
16
|
-
c1 = Category.create(scope)
|
17
|
-
c2 = Category.create(scope)
|
18
|
-
c1.pos.should eql([1,2])
|
19
|
-
c2.pos.should eql([3,4])
|
20
|
-
|
21
|
-
c3 = Category.create(scope2)
|
22
|
-
c4 = Category.create(scope2)
|
23
|
-
c3.pos.should eql([1,2])
|
24
|
-
c4.pos.should eql([3,4])
|
25
|
-
|
26
|
-
end
|
27
|
-
|
28
|
-
|
29
|
-
it "moves itself into a parent" do
|
30
|
-
|
31
|
-
c1 = Category.create(scope)
|
32
|
-
c2 = Category.create(scope)
|
33
|
-
c3 = Category.create(scope)
|
34
|
-
c2.move(:into => c1)
|
35
|
-
|
36
|
-
[c1,c2,c3].each { |c| c.reload }
|
37
|
-
c1.pos.should eql([1,4])
|
38
|
-
c2.pos.should eql([2,3])
|
39
|
-
c3.pos.should eql([5,6])
|
40
|
-
|
41
|
-
|
42
|
-
c2.move(:into => c3)
|
43
|
-
[c1,c2,c3].each { |c| c.reload }
|
44
|
-
c1.pos.should eql([1,2])
|
45
|
-
c3.pos.should eql([3,6])
|
46
|
-
c2.pos.should eql([4,5])
|
47
|
-
|
48
|
-
# This is to ensure that
|
49
|
-
c4 = Category.new
|
50
|
-
c4.move(:into => c1)
|
51
|
-
[c1,c2,c3, c4].each { |c| c.reload }
|
52
|
-
c4.sco.should eql(c1.sco)
|
53
|
-
c1.pos.should eql([1,4])
|
54
|
-
c4.pos.should eql([2,3])
|
55
|
-
c3.pos.should eql([5,8])
|
56
|
-
c2.pos.should eql([6,7])
|
57
|
-
end
|
58
|
-
|
59
|
-
it "moves around properly" do
|
60
|
-
c1 = Category.create(scope)
|
61
|
-
c2 = Category.create(scope)
|
62
|
-
c3 = Category.create(scope)
|
63
|
-
c4 = Category.new(scope)
|
64
|
-
|
65
|
-
c2.move(:to => 1)
|
66
|
-
[c1,c2,c3].each { |c| c.reload }
|
67
|
-
c2.pos.should eql([1,2])
|
68
|
-
c1.pos.should eql([3,4])
|
69
|
-
c3.pos.should eql([5,6])
|
70
|
-
|
71
|
-
c3.move(:higher)
|
72
|
-
[c1,c2,c3].each { |c| c.reload }
|
73
|
-
c2.pos.should eql([1,2])
|
74
|
-
c3.pos.should eql([3,4])
|
75
|
-
c1.pos.should eql([5,6])
|
76
|
-
|
77
|
-
c3.move(:lower)
|
78
|
-
[c1,c2,c3].each { |c| c.reload }
|
79
|
-
c2.pos.should eql([1,2])
|
80
|
-
c1.pos.should eql([3,4])
|
81
|
-
c3.pos.should eql([5,6])
|
82
|
-
|
83
|
-
c1.move(:lowest)
|
84
|
-
[c1,c2,c3].each { |c| c.reload }
|
85
|
-
c2.pos.should eql([1,2])
|
86
|
-
c3.pos.should eql([3,4])
|
87
|
-
c1.pos.should eql([5,6])
|
88
|
-
|
89
|
-
c1.move(:highest)
|
90
|
-
[c1,c2,c3].each { |c| c.reload }
|
91
|
-
c1.pos.should eql([1,2])
|
92
|
-
c2.pos.should eql([3,4])
|
93
|
-
c3.pos.should eql([5,6])
|
94
|
-
|
95
|
-
c4.move(:highest)
|
96
|
-
[c1,c2,c3].each { |c| c.reload }
|
97
|
-
|
98
|
-
c4.pos.should eql([1,2])
|
99
|
-
c1.pos.should eql([3,4])
|
100
|
-
c2.pos.should eql([5,6])
|
101
|
-
c3.pos.should eql([7,8])
|
102
|
-
|
103
|
-
end
|
104
|
-
|
105
|
-
it "puts in proper places for above and below" do
|
106
|
-
c1 = Category.create(scope)
|
107
|
-
c2 = Category.create(scope)
|
108
|
-
c3 = Category.create(scope)
|
109
|
-
|
110
|
-
c2.move(:into => c1)
|
111
|
-
[c1,c2,c3].each { |c| c.reload }
|
112
|
-
c1.pos.should eql([1,4])
|
113
|
-
c2.pos.should eql([2,3])
|
114
|
-
c3.pos.should eql([5,6])
|
115
|
-
|
116
|
-
|
117
|
-
c3.move(:above => c2)
|
118
|
-
[c1,c2,c3].each { |c| c.reload }
|
119
|
-
c1.pos.should eql([1,6])
|
120
|
-
c2.pos.should eql([4,5])
|
121
|
-
c3.pos.should eql([2,3])
|
122
|
-
|
123
|
-
c3.move(:below => c1)
|
124
|
-
[c1,c2,c3].each { |c| c.reload }
|
125
|
-
c1.pos.should eql([1,4])
|
126
|
-
c2.pos.should eql([2,3])
|
127
|
-
c3.pos.should eql([5,6])
|
128
|
-
|
129
|
-
c2.move(:below => c1)
|
130
|
-
[c1,c2,c3].each { |c| c.reload }
|
131
|
-
c1.pos.should eql([1,2])
|
132
|
-
c2.pos.should eql([3,4])
|
133
|
-
c3.pos.should eql([5,6])
|
134
|
-
end
|
135
|
-
|
136
|
-
it "gets the parent" do
|
137
|
-
c1 = Category.create(scope)
|
138
|
-
c2 = Category.create(scope)
|
139
|
-
c2.move(:into => c1)
|
140
|
-
c2.parent.should_not be_nil
|
141
|
-
c2.parent.id.should eql(c1.id)
|
142
|
-
end
|
143
|
-
|
144
|
-
it "identifies the root" do
|
145
|
-
|
146
|
-
c1 = Category.create(scope)
|
147
|
-
c2 = Category.create(scope)
|
148
|
-
c3 = Category.create(scope)
|
149
|
-
c2.move :into => c1
|
150
|
-
c3.move :into => c2
|
151
|
-
c3.root.should_not be_nil
|
152
|
-
c3.root.id.should eql(c1.id)
|
153
|
-
end
|
154
|
-
|
155
|
-
it "gets all roots in the current scope" do
|
156
|
-
c1 = Category.create(scope)
|
157
|
-
c2 = Category.create(scope)
|
158
|
-
c2.roots.size.should eql(2)
|
159
|
-
|
160
|
-
c3 = Category.create(scope2)
|
161
|
-
c4 = Category.create(scope2)
|
162
|
-
c3.roots.size.should eql(2)
|
163
|
-
end
|
164
|
-
|
165
|
-
it "gets all ancestors" do
|
166
|
-
c1 = Category.create(scope)
|
167
|
-
c2 = Category.create(scope)
|
168
|
-
c3 = Category.create(scope)
|
169
|
-
|
170
|
-
c2.move(:into => c1)
|
171
|
-
c3.move(:into => c2)
|
172
|
-
c3.ancestors.size.should eql(2)
|
173
|
-
end
|
174
|
-
|
175
|
-
it "gets all siblings" do
|
176
|
-
c1 = Category.create(scope)
|
177
|
-
c2 = Category.create(scope)
|
178
|
-
c3 = Category.create(scope)
|
179
|
-
|
180
|
-
c2.move(:into => c1)
|
181
|
-
c3.move(:into => c1)
|
182
|
-
c3.siblings.size.should eql(1)
|
183
|
-
end
|
184
|
-
|
185
|
-
it "moves scope properly" do
|
186
|
-
c1 = Category.create(scope)
|
187
|
-
c2 = Category.create(scope)
|
188
|
-
c3 = Category.create(scope)
|
189
|
-
|
190
|
-
c4 = Category.create(scope2)
|
191
|
-
c5 = Category.create(scope2)
|
192
|
-
c6 = Category.create(scope2)
|
193
|
-
|
194
|
-
c1.move(:into => c4)
|
195
|
-
[c1,c2,c3,c4,c5,c6].each { |c| c.reload }
|
196
|
-
|
197
|
-
c1.sco.should eql(scope2)
|
198
|
-
|
199
|
-
c2.pos.should eql([1,2])
|
200
|
-
c3.pos.should eql([3,4])
|
201
|
-
|
202
|
-
c4.pos.should eql([1,4])
|
203
|
-
c1.pos.should eql([2,3])
|
204
|
-
c5.pos.should eql([5,6])
|
205
|
-
c6.pos.should eql([7,8])
|
206
|
-
|
207
|
-
c4.move(:into => c2)
|
208
|
-
[c1,c2,c3,c4,c5,c6].each { |c| c.reload }
|
209
|
-
c1.sco.should eql(scope)
|
210
|
-
c4.sco.should eql(scope)
|
211
|
-
|
212
|
-
c2.pos.should eql([1,6])
|
213
|
-
c4.pos.should eql([2,5])
|
214
|
-
c1.pos.should eql([3,4])
|
215
|
-
c3.pos.should eql([7,8])
|
216
|
-
|
217
|
-
|
218
|
-
c5.pos.should eql([1,2])
|
219
|
-
c6.pos.should eql([3,4])
|
220
|
-
|
221
|
-
# You can move into the root of a different scope by passing an object from that scope
|
222
|
-
# or a hash that represents that scope
|
223
|
-
c5.move(:root => scope)
|
224
|
-
[c1,c2,c3,c4,c5,c6].each { |c| c.reload }
|
225
|
-
c5.sco.should eql(scope)
|
226
|
-
|
227
|
-
c2.pos.should eql([1,6])
|
228
|
-
c4.pos.should eql([2,5])
|
229
|
-
c1.pos.should eql([3,4])
|
230
|
-
c3.pos.should eql([7,8])
|
231
|
-
c5.pos.should eql([9,10])
|
232
|
-
|
233
|
-
c6.pos.should eql([1,2])
|
234
|
-
|
235
|
-
end
|
236
8
|
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
9
|
+
describe "without active DM Identity Map" do
|
10
|
+
|
11
|
+
before :each do
|
12
|
+
Category.auto_migrate!
|
13
|
+
Discrim1.auto_migrate!
|
14
|
+
Discrim2.auto_migrate!
|
15
|
+
end
|
16
|
+
|
17
|
+
it "puts itself as the last root in the defined scope on initial save" do
|
18
|
+
|
19
|
+
c1 = Category.create(scope)
|
20
|
+
c2 = Category.create(scope)
|
21
|
+
c1.pos.should eql([1,2])
|
22
|
+
c2.pos.should eql([3,4])
|
23
|
+
|
24
|
+
c3 = Category.create(scope2)
|
25
|
+
c4 = Category.create(scope2)
|
26
|
+
c3.pos.should eql([1,2])
|
27
|
+
c4.pos.should eql([3,4])
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
it "moves itself into a parent" do
|
32
|
+
|
33
|
+
c1 = Category.create(scope)
|
34
|
+
c2 = Category.create(scope)
|
35
|
+
c3 = Category.create(scope)
|
36
|
+
c2.move(:into => c1)
|
37
|
+
|
38
|
+
[c1,c2,c3].each { |c| c.reload }
|
39
|
+
c1.pos.should eql([1,4])
|
40
|
+
c2.pos.should eql([2,3])
|
41
|
+
c3.pos.should eql([5,6])
|
42
|
+
|
43
|
+
|
44
|
+
c2.move(:into => c3)
|
45
|
+
[c1,c2,c3].each { |c| c.reload }
|
46
|
+
c1.pos.should eql([1,2])
|
47
|
+
c3.pos.should eql([3,6])
|
48
|
+
c2.pos.should eql([4,5])
|
49
|
+
|
50
|
+
# This is to ensure that
|
51
|
+
c4 = Category.new
|
52
|
+
c4.move(:into => c1)
|
53
|
+
[c1,c2,c3, c4].each { |c| c.reload }
|
54
|
+
c4.sco.should eql(c1.sco)
|
55
|
+
c1.pos.should eql([1,4])
|
56
|
+
c4.pos.should eql([2,3])
|
57
|
+
c3.pos.should eql([5,8])
|
58
|
+
c2.pos.should eql([6,7])
|
59
|
+
end
|
60
|
+
|
61
|
+
it "moves around properly" do
|
62
|
+
c1 = Category.create(scope)
|
63
|
+
c2 = Category.create(scope)
|
64
|
+
c3 = Category.create(scope)
|
65
|
+
c4 = Category.new(scope)
|
66
|
+
|
67
|
+
c2.move(:to => 1)
|
68
|
+
[c1,c2,c3].each { |c| c.reload }
|
69
|
+
c2.pos.should eql([1,2])
|
70
|
+
c1.pos.should eql([3,4])
|
71
|
+
c3.pos.should eql([5,6])
|
72
|
+
|
73
|
+
c3.move(:higher)
|
74
|
+
[c1,c2,c3].each { |c| c.reload }
|
75
|
+
c2.pos.should eql([1,2])
|
76
|
+
c3.pos.should eql([3,4])
|
77
|
+
c1.pos.should eql([5,6])
|
78
|
+
|
79
|
+
c3.move(:lower)
|
80
|
+
[c1,c2,c3].each { |c| c.reload }
|
81
|
+
c2.pos.should eql([1,2])
|
82
|
+
c1.pos.should eql([3,4])
|
83
|
+
c3.pos.should eql([5,6])
|
84
|
+
|
85
|
+
c1.move(:lowest)
|
86
|
+
[c1,c2,c3].each { |c| c.reload }
|
87
|
+
c2.pos.should eql([1,2])
|
88
|
+
c3.pos.should eql([3,4])
|
89
|
+
c1.pos.should eql([5,6])
|
90
|
+
|
91
|
+
c1.move(:highest)
|
92
|
+
[c1,c2,c3].each { |c| c.reload }
|
93
|
+
c1.pos.should eql([1,2])
|
94
|
+
c2.pos.should eql([3,4])
|
95
|
+
c3.pos.should eql([5,6])
|
96
|
+
|
97
|
+
c4.move(:highest)
|
98
|
+
[c1,c2,c3].each { |c| c.reload }
|
99
|
+
|
100
|
+
c4.pos.should eql([1,2])
|
101
|
+
c1.pos.should eql([3,4])
|
102
|
+
c2.pos.should eql([5,6])
|
103
|
+
c3.pos.should eql([7,8])
|
104
|
+
|
105
|
+
end
|
106
|
+
|
107
|
+
it "puts in proper places for above and below with scope" do
|
108
|
+
c1 = Category.create(scope)
|
109
|
+
c2 = Category.create(scope)
|
110
|
+
c3 = Category.create(scope)
|
111
|
+
|
112
|
+
c2.move(:into => c1)
|
113
|
+
[c1,c2,c3].each { |c| c.reload }
|
114
|
+
c1.pos.should eql([1,4])
|
115
|
+
c2.pos.should eql([2,3])
|
116
|
+
c3.pos.should eql([5,6])
|
117
|
+
|
118
|
+
|
119
|
+
c3.move(:above => c2)
|
120
|
+
[c1,c2,c3].each { |c| c.reload }
|
121
|
+
c1.pos.should eql([1,6])
|
122
|
+
c2.pos.should eql([4,5])
|
123
|
+
c3.pos.should eql([2,3])
|
124
|
+
|
125
|
+
c3.move(:below => c1)
|
126
|
+
[c1,c2,c3].each { |c| c.reload }
|
127
|
+
c1.pos.should eql([1,4])
|
128
|
+
c2.pos.should eql([2,3])
|
129
|
+
c3.pos.should eql([5,6])
|
130
|
+
|
131
|
+
c2.move(:below => c1)
|
132
|
+
[c1,c2,c3].each { |c| c.reload }
|
133
|
+
c1.pos.should eql([1,2])
|
134
|
+
c2.pos.should eql([3,4])
|
135
|
+
c3.pos.should eql([5,6])
|
136
|
+
end
|
137
|
+
|
138
|
+
it "puts in proper places for above and below without scope" do
|
139
|
+
c1 = Category.create
|
140
|
+
c2 = Category.create
|
141
|
+
c3 = Category.create
|
142
|
+
|
143
|
+
c2.move(:into => c1)
|
144
|
+
[c1,c2,c3].each { |c| c.reload }
|
145
|
+
c1.pos.should eql([1,4])
|
146
|
+
c2.pos.should eql([2,3])
|
147
|
+
c3.pos.should eql([5,6])
|
148
|
+
|
149
|
+
|
150
|
+
c3.move(:above => c2)
|
151
|
+
[c1,c2,c3].each { |c| c.reload }
|
152
|
+
c1.pos.should eql([1,6])
|
153
|
+
c2.pos.should eql([4,5])
|
154
|
+
c3.pos.should eql([2,3])
|
155
|
+
|
156
|
+
c3.move(:below => c1)
|
157
|
+
[c1,c2,c3].each { |c| c.reload }
|
158
|
+
c1.pos.should eql([1,4])
|
159
|
+
c2.pos.should eql([2,3])
|
160
|
+
c3.pos.should eql([5,6])
|
161
|
+
|
162
|
+
c2.move(:below => c1)
|
163
|
+
[c1,c2,c3].each { |c| c.reload }
|
164
|
+
c1.pos.should eql([1,2])
|
165
|
+
c2.pos.should eql([3,4])
|
166
|
+
c3.pos.should eql([5,6])
|
167
|
+
end
|
168
|
+
|
169
|
+
it "gets the parent" do
|
170
|
+
c1 = Category.create(scope)
|
171
|
+
c2 = Category.create(scope)
|
172
|
+
c2.move(:into => c1)
|
173
|
+
c2.parent.should_not be_nil
|
174
|
+
c2.parent.id.should eql(c1.id)
|
175
|
+
end
|
176
|
+
|
177
|
+
it "identifies the root" do
|
178
|
+
|
179
|
+
c1 = Category.create(scope)
|
180
|
+
c2 = Category.create(scope)
|
181
|
+
c3 = Category.create(scope)
|
182
|
+
c2.move :into => c1
|
183
|
+
c3.move :into => c2
|
184
|
+
c3.root.should_not be_nil
|
185
|
+
c3.root.id.should eql(c1.id)
|
186
|
+
end
|
187
|
+
|
188
|
+
it "gets all roots in the current scope" do
|
189
|
+
c1 = Category.create(scope)
|
190
|
+
c2 = Category.create(scope)
|
191
|
+
c2.roots.size.should eql(2)
|
192
|
+
|
193
|
+
c3 = Category.create(scope2)
|
194
|
+
c4 = Category.create(scope2)
|
195
|
+
c3.roots.size.should eql(2)
|
196
|
+
end
|
197
|
+
|
198
|
+
it "gets all ancestors" do
|
199
|
+
c1 = Category.create(scope)
|
200
|
+
c2 = Category.create(scope)
|
201
|
+
c3 = Category.create(scope)
|
202
|
+
|
203
|
+
c2.move(:into => c1)
|
204
|
+
c3.move(:into => c2)
|
205
|
+
c3.ancestors.size.should eql(2)
|
206
|
+
end
|
207
|
+
|
208
|
+
it "gets all siblings" do
|
209
|
+
c1 = Category.create(scope)
|
210
|
+
c2 = Category.create(scope)
|
211
|
+
c3 = Category.create(scope)
|
212
|
+
|
213
|
+
c2.move(:into => c1)
|
214
|
+
c3.move(:into => c1)
|
215
|
+
c3.siblings.size.should eql(1)
|
216
|
+
end
|
217
|
+
|
218
|
+
it "moves scope properly" do
|
219
|
+
c1 = Category.create(scope)
|
220
|
+
c2 = Category.create(scope)
|
221
|
+
c3 = Category.create(scope)
|
222
|
+
|
223
|
+
c4 = Category.create(scope2)
|
224
|
+
c5 = Category.create(scope2)
|
225
|
+
c6 = Category.create(scope2)
|
226
|
+
|
227
|
+
c1.move(:into => c4)
|
228
|
+
[c1,c2,c3,c4,c5,c6].each { |c| c.reload }
|
229
|
+
|
230
|
+
c1.sco.should eql(scope2)
|
231
|
+
|
232
|
+
c2.pos.should eql([1,2])
|
233
|
+
c3.pos.should eql([3,4])
|
234
|
+
|
235
|
+
c4.pos.should eql([1,4])
|
236
|
+
c1.pos.should eql([2,3])
|
237
|
+
c5.pos.should eql([5,6])
|
238
|
+
c6.pos.should eql([7,8])
|
239
|
+
|
240
|
+
c4.move(:into => c2)
|
241
|
+
[c1,c2,c3,c4,c5,c6].each { |c| c.reload }
|
242
|
+
c1.sco.should eql(scope)
|
243
|
+
c4.sco.should eql(scope)
|
244
|
+
|
245
|
+
c2.pos.should eql([1,6])
|
246
|
+
c4.pos.should eql([2,5])
|
247
|
+
c1.pos.should eql([3,4])
|
248
|
+
c3.pos.should eql([7,8])
|
249
|
+
|
250
|
+
|
251
|
+
c5.pos.should eql([1,2])
|
252
|
+
c6.pos.should eql([3,4])
|
253
|
+
|
254
|
+
# You can move into the root of a different scope by passing an object from that scope
|
255
|
+
# or a hash that represents that scope
|
256
|
+
c5.move(:root => scope)
|
257
|
+
[c1,c2,c3,c4,c5,c6].each { |c| c.reload }
|
258
|
+
c5.sco.should eql(scope)
|
259
|
+
|
260
|
+
c2.pos.should eql([1,6])
|
261
|
+
c4.pos.should eql([2,5])
|
262
|
+
c1.pos.should eql([3,4])
|
263
|
+
c3.pos.should eql([7,8])
|
264
|
+
c5.pos.should eql([9,10])
|
265
|
+
|
266
|
+
c6.pos.should eql([1,2])
|
267
|
+
|
268
|
+
end
|
269
|
+
|
270
|
+
it "should get all rows in the database if the discrimator is not part of scope" do
|
271
|
+
c1 = CatD11.create(scope)
|
272
|
+
c2 = CatD11.create(scope)
|
273
|
+
c3 = CatD12.create(scope)
|
274
|
+
c4 = CatD12.create(scope)
|
275
|
+
CatD12.roots(scope).size.should eql(4)
|
276
|
+
end
|
277
|
+
|
278
|
+
it "should get only the same object types if discriminator is part of scope" do
|
279
|
+
c1 = CatD21.create(scope)
|
280
|
+
c2 = CatD21.create(scope)
|
281
|
+
c3 = CatD22.create(scope2)
|
282
|
+
c4 = CatD22.create(scope2)
|
283
|
+
Discrim2.roots(scope.merge(:type => 'CatD21')).size.should eql(2)
|
284
|
+
Discrim2.roots(scope2.merge(:type => 'CatD22')).size.should eql(2)
|
285
|
+
end
|
286
|
+
|
243
287
|
end
|
244
288
|
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
289
|
+
describe "with active DM Identity Map" do
|
290
|
+
|
291
|
+
it "puts itself as the last root in the defined scope on initial save when using the identity map" do
|
292
|
+
repository do
|
293
|
+
c1 = Category.create(scope)
|
294
|
+
c2 = Category.create(scope)
|
295
|
+
c1.pos.should eql([1,2])
|
296
|
+
c2.pos.should eql([3,4])
|
297
|
+
|
298
|
+
c3 = Category.create(scope2)
|
299
|
+
c4 = Category.create(scope2)
|
300
|
+
c3.pos.should eql([1,2])
|
301
|
+
c4.pos.should eql([3,4])
|
302
|
+
end
|
303
|
+
end
|
304
|
+
|
305
|
+
it "moves itself into a parent when using the identity map" do
|
306
|
+
repository do
|
307
|
+
c1 = Category.create(scope)
|
308
|
+
c2 = Category.create(scope)
|
309
|
+
c3 = Category.create(scope)
|
310
|
+
c2.move(:into => c1)
|
311
|
+
|
312
|
+
[c1,c2,c3].each { |c| c.reload }
|
313
|
+
c1.pos.should eql([1,4])
|
314
|
+
c2.pos.should eql([2,3])
|
315
|
+
c3.pos.should eql([5,6])
|
316
|
+
|
317
|
+
|
318
|
+
c2.move(:into => c3)
|
319
|
+
[c1,c2,c3].each { |c| c.reload }
|
320
|
+
c1.pos.should eql([1,2])
|
321
|
+
c3.pos.should eql([3,6])
|
322
|
+
c2.pos.should eql([4,5])
|
323
|
+
|
324
|
+
# This is to ensure that
|
325
|
+
c4 = Category.new
|
326
|
+
c4.move(:into => c1)
|
327
|
+
[c1,c2,c3, c4].each { |c| c.reload }
|
328
|
+
c4.sco.should eql(c1.sco)
|
329
|
+
c1.pos.should eql([1,4])
|
330
|
+
c4.pos.should eql([2,3])
|
331
|
+
c3.pos.should eql([5,8])
|
332
|
+
c2.pos.should eql([6,7])
|
333
|
+
end
|
334
|
+
end
|
335
|
+
|
336
|
+
it "moves around properly when using the identity map" do
|
337
|
+
repository do
|
338
|
+
c1 = Category.create(scope)
|
339
|
+
c2 = Category.create(scope)
|
340
|
+
c3 = Category.create(scope)
|
341
|
+
c4 = Category.new(scope)
|
342
|
+
|
343
|
+
c2.move(:to => 1)
|
344
|
+
[c1,c2,c3].each { |c| c.reload }
|
345
|
+
c2.pos.should eql([1,2])
|
346
|
+
c1.pos.should eql([3,4])
|
347
|
+
c3.pos.should eql([5,6])
|
348
|
+
|
349
|
+
c3.move(:higher)
|
350
|
+
[c1,c2,c3].each { |c| c.reload }
|
351
|
+
c2.pos.should eql([1,2])
|
352
|
+
c3.pos.should eql([3,4])
|
353
|
+
c1.pos.should eql([5,6])
|
354
|
+
|
355
|
+
c3.move(:lower)
|
356
|
+
[c1,c2,c3].each { |c| c.reload }
|
357
|
+
c2.pos.should eql([1,2])
|
358
|
+
c1.pos.should eql([3,4])
|
359
|
+
c3.pos.should eql([5,6])
|
360
|
+
|
361
|
+
c1.move(:lowest)
|
362
|
+
[c1,c2,c3].each { |c| c.reload }
|
363
|
+
c2.pos.should eql([1,2])
|
364
|
+
c3.pos.should eql([3,4])
|
365
|
+
c1.pos.should eql([5,6])
|
366
|
+
|
367
|
+
c1.move(:highest)
|
368
|
+
[c1,c2,c3].each { |c| c.reload }
|
369
|
+
c1.pos.should eql([1,2])
|
370
|
+
c2.pos.should eql([3,4])
|
371
|
+
c3.pos.should eql([5,6])
|
372
|
+
|
373
|
+
c4.move(:highest)
|
374
|
+
[c1,c2,c3].each { |c| c.reload }
|
375
|
+
|
376
|
+
c4.pos.should eql([1,2])
|
377
|
+
c1.pos.should eql([3,4])
|
378
|
+
c2.pos.should eql([5,6])
|
379
|
+
c3.pos.should eql([7,8])
|
380
|
+
end
|
381
|
+
end
|
382
|
+
|
383
|
+
it "puts in proper places for above and below with scope when using the identity map" do
|
384
|
+
repository do
|
385
|
+
c1 = Category.create(scope)
|
386
|
+
c2 = Category.create(scope)
|
387
|
+
c3 = Category.create(scope)
|
388
|
+
|
389
|
+
c2.move(:into => c1)
|
390
|
+
[c1,c2,c3].each { |c| c.reload }
|
391
|
+
c1.pos.should eql([1,4])
|
392
|
+
c2.pos.should eql([2,3])
|
393
|
+
c3.pos.should eql([5,6])
|
394
|
+
|
395
|
+
|
396
|
+
c3.move(:above => c2)
|
397
|
+
[c1,c2,c3].each { |c| c.reload }
|
398
|
+
c1.pos.should eql([1,6])
|
399
|
+
c2.pos.should eql([4,5])
|
400
|
+
c3.pos.should eql([2,3])
|
401
|
+
|
402
|
+
c3.move(:below => c1)
|
403
|
+
[c1,c2,c3].each { |c| c.reload }
|
404
|
+
c1.pos.should eql([1,4])
|
405
|
+
c2.pos.should eql([2,3])
|
406
|
+
c3.pos.should eql([5,6])
|
407
|
+
|
408
|
+
c2.move(:below => c1)
|
409
|
+
[c1,c2,c3].each { |c| c.reload }
|
410
|
+
c1.pos.should eql([1,2])
|
411
|
+
c2.pos.should eql([3,4])
|
412
|
+
c3.pos.should eql([5,6])
|
413
|
+
end
|
414
|
+
end
|
415
|
+
|
416
|
+
it "puts in proper places for above and below without scope when using the identity map" do
|
417
|
+
repository do
|
418
|
+
c1 = Category.create
|
419
|
+
c2 = Category.create
|
420
|
+
c3 = Category.create
|
421
|
+
|
422
|
+
c2.move(:into => c1)
|
423
|
+
[c1,c2,c3].each { |c| c.reload }
|
424
|
+
c1.pos.should eql([1,4])
|
425
|
+
c2.pos.should eql([2,3])
|
426
|
+
c3.pos.should eql([5,6])
|
427
|
+
|
428
|
+
|
429
|
+
c3.move(:above => c2)
|
430
|
+
[c1,c2,c3].each { |c| c.reload }
|
431
|
+
c1.pos.should eql([1,6])
|
432
|
+
c2.pos.should eql([4,5])
|
433
|
+
c3.pos.should eql([2,3])
|
434
|
+
|
435
|
+
c3.move(:below => c1)
|
436
|
+
[c1,c2,c3].each { |c| c.reload }
|
437
|
+
c1.pos.should eql([1,4])
|
438
|
+
c2.pos.should eql([2,3])
|
439
|
+
c3.pos.should eql([5,6])
|
440
|
+
|
441
|
+
c2.move(:below => c1)
|
442
|
+
[c1,c2,c3].each { |c| c.reload }
|
443
|
+
c1.pos.should eql([1,2])
|
444
|
+
c2.pos.should eql([3,4])
|
445
|
+
c3.pos.should eql([5,6])
|
446
|
+
end
|
447
|
+
end
|
448
|
+
|
449
|
+
it "gets the parent when using the identity map" do
|
450
|
+
repository do
|
451
|
+
c1 = Category.create(scope)
|
452
|
+
c2 = Category.create(scope)
|
453
|
+
c2.move(:into => c1)
|
454
|
+
c2.parent.should_not be_nil
|
455
|
+
c2.parent.id.should eql(c1.id)
|
456
|
+
end
|
457
|
+
end
|
458
|
+
|
459
|
+
it "identifies the root when using the identity map" do
|
460
|
+
repository do
|
461
|
+
c1 = Category.create(scope)
|
462
|
+
c2 = Category.create(scope)
|
463
|
+
c3 = Category.create(scope)
|
464
|
+
c2.move :into => c1
|
465
|
+
c3.move :into => c2
|
466
|
+
c3.root.should_not be_nil
|
467
|
+
c3.root.id.should eql(c1.id)
|
468
|
+
end
|
469
|
+
end
|
470
|
+
|
471
|
+
it "gets all roots in the current scope when using the identity map" do
|
472
|
+
repository do
|
473
|
+
c1 = Category.create(scope)
|
474
|
+
c2 = Category.create(scope)
|
475
|
+
c2.roots.size.should eql(2)
|
476
|
+
|
477
|
+
c3 = Category.create(scope2)
|
478
|
+
c4 = Category.create(scope2)
|
479
|
+
c3.roots.size.should eql(2)
|
480
|
+
end
|
481
|
+
end
|
482
|
+
|
483
|
+
it "gets all ancestors when using the identity map" do
|
484
|
+
repository do
|
485
|
+
c1 = Category.create(scope)
|
486
|
+
c2 = Category.create(scope)
|
487
|
+
c3 = Category.create(scope)
|
488
|
+
|
489
|
+
c2.move(:into => c1)
|
490
|
+
c3.move(:into => c2)
|
491
|
+
c3.ancestors.size.should eql(2)
|
492
|
+
end
|
493
|
+
end
|
494
|
+
|
495
|
+
it "gets all siblings when using the identity map" do
|
496
|
+
repository do
|
497
|
+
c1 = Category.create(scope)
|
498
|
+
c2 = Category.create(scope)
|
499
|
+
c3 = Category.create(scope)
|
500
|
+
|
501
|
+
c2.move(:into => c1)
|
502
|
+
c3.move(:into => c1)
|
503
|
+
c3.siblings.size.should eql(1)
|
504
|
+
end
|
505
|
+
end
|
506
|
+
|
507
|
+
it "moves scope properly when using the identity map" do
|
508
|
+
repository do
|
509
|
+
c1 = Category.create(scope)
|
510
|
+
c2 = Category.create(scope)
|
511
|
+
c3 = Category.create(scope)
|
512
|
+
|
513
|
+
c4 = Category.create(scope2)
|
514
|
+
c5 = Category.create(scope2)
|
515
|
+
c6 = Category.create(scope2)
|
516
|
+
|
517
|
+
c1.move(:into => c4)
|
518
|
+
[c1,c2,c3,c4,c5,c6].each { |c| c.reload }
|
519
|
+
|
520
|
+
c1.sco.should eql(scope2)
|
521
|
+
|
522
|
+
c2.pos.should eql([1,2])
|
523
|
+
c3.pos.should eql([3,4])
|
524
|
+
|
525
|
+
c4.pos.should eql([1,4])
|
526
|
+
c1.pos.should eql([2,3])
|
527
|
+
c5.pos.should eql([5,6])
|
528
|
+
c6.pos.should eql([7,8])
|
529
|
+
|
530
|
+
c4.move(:into => c2)
|
531
|
+
[c1,c2,c3,c4,c5,c6].each { |c| c.reload }
|
532
|
+
c1.sco.should eql(scope)
|
533
|
+
c4.sco.should eql(scope)
|
534
|
+
|
535
|
+
c2.pos.should eql([1,6])
|
536
|
+
c4.pos.should eql([2,5])
|
537
|
+
c1.pos.should eql([3,4])
|
538
|
+
c3.pos.should eql([7,8])
|
539
|
+
|
540
|
+
|
541
|
+
c5.pos.should eql([1,2])
|
542
|
+
c6.pos.should eql([3,4])
|
543
|
+
|
544
|
+
# You can move into the root of a different scope by passing an object from that scope
|
545
|
+
# or a hash that represents that scope
|
546
|
+
c5.move(:root => scope)
|
547
|
+
[c1,c2,c3,c4,c5,c6].each { |c| c.reload }
|
548
|
+
c5.sco.should eql(scope)
|
549
|
+
|
550
|
+
c2.pos.should eql([1,6])
|
551
|
+
c4.pos.should eql([2,5])
|
552
|
+
c1.pos.should eql([3,4])
|
553
|
+
c3.pos.should eql([7,8])
|
554
|
+
c5.pos.should eql([9,10])
|
555
|
+
|
556
|
+
c6.pos.should eql([1,2])
|
557
|
+
end
|
558
|
+
end
|
559
|
+
|
560
|
+
it "should get all rows in the database if the discrimator is not part of scope when using the identity map" do
|
561
|
+
repository do
|
562
|
+
c1 = CatD11.create(scope)
|
563
|
+
c2 = CatD11.create(scope)
|
564
|
+
c3 = CatD12.create(scope)
|
565
|
+
c4 = CatD12.create(scope)
|
566
|
+
CatD12.roots(scope).size.should eql(4)
|
567
|
+
end
|
568
|
+
end
|
569
|
+
|
570
|
+
it "should get only the same object types if discriminator is part of scope when using the identity map" do
|
571
|
+
repository do
|
572
|
+
c1 = CatD21.create(scope)
|
573
|
+
c2 = CatD21.create(scope)
|
574
|
+
c3 = CatD22.create(scope2)
|
575
|
+
c4 = CatD22.create(scope2)
|
576
|
+
Discrim2.roots(scope.merge(:type => 'CatD21')).size.should eql(2)
|
577
|
+
Discrim2.roots(scope2.merge(:type => 'CatD22')).size.should eql(2)
|
578
|
+
end
|
579
|
+
end
|
252
580
|
|
253
581
|
end
|
254
582
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: snusnu-dm-is-awesome_set
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.10.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jeremy Nicoll
|
@@ -9,44 +9,38 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-
|
12
|
+
date: 2009-05-20 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: dm-core
|
17
|
+
type: :runtime
|
17
18
|
version_requirement:
|
18
19
|
version_requirements: !ruby/object:Gem::Requirement
|
19
20
|
requirements:
|
20
21
|
- - ">="
|
21
22
|
- !ruby/object:Gem::Version
|
22
|
-
version: 0.
|
23
|
+
version: 0.10.0
|
23
24
|
version:
|
24
25
|
- !ruby/object:Gem::Dependency
|
25
26
|
name: dm-adjust
|
27
|
+
type: :runtime
|
26
28
|
version_requirement:
|
27
29
|
version_requirements: !ruby/object:Gem::Requirement
|
28
30
|
requirements:
|
29
31
|
- - ">="
|
30
32
|
- !ruby/object:Gem::Version
|
31
|
-
version: 0.
|
33
|
+
version: 0.10.0
|
32
34
|
version:
|
33
35
|
- !ruby/object:Gem::Dependency
|
34
36
|
name: dm-aggregates
|
37
|
+
type: :runtime
|
35
38
|
version_requirement:
|
36
39
|
version_requirements: !ruby/object:Gem::Requirement
|
37
40
|
requirements:
|
38
41
|
- - ">="
|
39
42
|
- !ruby/object:Gem::Version
|
40
|
-
version: 0.
|
41
|
-
version:
|
42
|
-
- !ruby/object:Gem::Dependency
|
43
|
-
name: dm-validations
|
44
|
-
version_requirement:
|
45
|
-
version_requirements: !ruby/object:Gem::Requirement
|
46
|
-
requirements:
|
47
|
-
- - ">="
|
48
|
-
- !ruby/object:Gem::Version
|
49
|
-
version: 0.9.10
|
43
|
+
version: 0.10.0
|
50
44
|
version:
|
51
45
|
description: DataMapper nested set plugin that works
|
52
46
|
email: jnicoll@gnexp.com
|
@@ -69,7 +63,7 @@ files:
|
|
69
63
|
- lib/dm-is-awesome_set.rb
|
70
64
|
- spec/dm-is-awesome_set_spec.rb
|
71
65
|
- spec/spec_helper.rb
|
72
|
-
has_rdoc:
|
66
|
+
has_rdoc: false
|
73
67
|
homepage: http://gnexp.com/
|
74
68
|
post_install_message:
|
75
69
|
rdoc_options: []
|
@@ -90,10 +84,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
90
84
|
version:
|
91
85
|
requirements: []
|
92
86
|
|
93
|
-
rubyforge_project:
|
87
|
+
rubyforge_project: dm-is-awesome_set
|
94
88
|
rubygems_version: 1.2.0
|
95
89
|
signing_key:
|
96
|
-
specification_version:
|
90
|
+
specification_version: 3
|
97
91
|
summary: DataMapper nested set plugin that works
|
98
92
|
test_files: []
|
99
93
|
|