acts_as_ordered_tree 1.1.4 → 1.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -243,6 +243,8 @@ module ActsAsOrderedTree
|
|
243
243
|
end
|
244
244
|
|
245
245
|
def compute_ordered_tree_columns(target, pos) #:nodoc:
|
246
|
+
position_was = send("#{position_column}_was")
|
247
|
+
|
246
248
|
case pos
|
247
249
|
when :root then
|
248
250
|
parent_id = nil
|
@@ -256,12 +258,12 @@ module ActsAsOrderedTree
|
|
256
258
|
when :left then
|
257
259
|
parent_id = target[parent_column]
|
258
260
|
position = target[position_column]
|
259
|
-
position -= 1 if target[parent_column] == send("#{parent_column}_was") && target[position_column] > position_was # right
|
261
|
+
position -= 1 if position_was && target[parent_column] == send("#{parent_column}_was") && target[position_column] > position_was # right
|
260
262
|
depth = target.level
|
261
263
|
when :right then
|
262
264
|
parent_id = target[parent_column]
|
263
265
|
position = target[position_column]
|
264
|
-
position += 1 if target[parent_column] != send("#{parent_column}_was") || target[position_column] < position_was # left
|
266
|
+
position += 1 if target[parent_column] != send("#{parent_column}_was") || position_was.blank? || target[position_column] < position_was # left
|
265
267
|
depth = target.level
|
266
268
|
when :child then
|
267
269
|
parent_id = target.id
|
@@ -299,8 +301,8 @@ module ActsAsOrderedTree
|
|
299
301
|
raise ActiveRecord::ActiveRecordError, "Impossible move"
|
300
302
|
end
|
301
303
|
|
302
|
-
position_was = send
|
303
|
-
parent_id_was = send
|
304
|
+
position_was = send("#{position_column}_was")
|
305
|
+
parent_id_was = send("#{parent_column}_was")
|
304
306
|
parent_id, position, depth = compute_ordered_tree_columns(target, pos)
|
305
307
|
|
306
308
|
# nothing changed - quit
|
@@ -875,6 +875,13 @@ describe ActsAsOrderedTree, :transactional do
|
|
875
875
|
it "should not throw error" do
|
876
876
|
expect{ create :default, :position => 22 }.not_to raise_error
|
877
877
|
end
|
878
|
+
|
879
|
+
it "should be saved at proper position" do
|
880
|
+
root = create :default
|
881
|
+
|
882
|
+
node = create :default, :position => 2
|
883
|
+
node.position.should eq 2
|
884
|
+
end
|
878
885
|
end
|
879
886
|
end
|
880
887
|
end
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: acts_as_ordered_tree
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 1.1.
|
5
|
+
version: 1.1.5
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Alexei Mikhailov
|
@@ -162,7 +162,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
162
162
|
- !ruby/object:Gem::Version
|
163
163
|
segments:
|
164
164
|
- 0
|
165
|
-
hash:
|
165
|
+
hash: -3132185917960313730
|
166
166
|
version: '0'
|
167
167
|
none: false
|
168
168
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
@@ -171,7 +171,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
171
171
|
- !ruby/object:Gem::Version
|
172
172
|
segments:
|
173
173
|
- 0
|
174
|
-
hash:
|
174
|
+
hash: -3132185917960313730
|
175
175
|
version: '0'
|
176
176
|
none: false
|
177
177
|
requirements: []
|