acts_as_ordered_tree 1.1.8 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,15 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 02d7e5c8d5d4f188a28d709689a5b549c34893ce
4
- data.tar.gz: 687a430993d957a16afc33398cf8c18d0068b231
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ ODI4NmU4NzcxYzdlNDY3ZTlmMTQ1ZGMyOWQ3MjhjYzc2OTVmZjZlZQ==
5
+ data.tar.gz: !binary |-
6
+ YzU5ZDA3YTU5NzIxOWIwYjFiZmE3ZTljYjE2OTkzYTM1NDJmNWEyNw==
5
7
  SHA512:
6
- metadata.gz: d3694d0b00dc899e89c91e0d240b7b1cc525f5417236b2a01d4562142589e1e45f7d14311779225a250bd292c6a1f9cb8cb9e7a285a0e5d4359aef71fd8e5771
7
- data.tar.gz: 9a5b0b6614b3119962b7e49fc60582d5f912e681f23ddfa3cb1b9ad6061b85ff3c1369fcb0f41db32addce28b7d2011b2c91a1cea3ecc6cfccf7be075cded612
8
+ metadata.gz: !binary |-
9
+ NjkyMzE1NzIzNjNhNTZiNWJlZDA5OTg4MDE4NjZiZGVlOWE3OGE1M2QwYjQy
10
+ ZjYwMWI4ZmRjMjhlNWYyMDRiYWUzMjU4OTU5YjE2YjEwNjhmMjRlZDFjZjlk
11
+ MjhmM2NhNDNlZTAyOWNiZDA0M2FmZDc0Nzc0ZmRlYjAxOGQzYzM=
12
+ data.tar.gz: !binary |-
13
+ YzlmNjMxYTZkYWEzMjE0ZGZlZjQ4ODQ3ZmIxNmVlZjc0MDczYzEwMmFiNTcw
14
+ ZDhhODgzZWFhNjM2MWIyYTUzOWU4YTlmN2U2MWY4OWNlMWIzYWRiMmI2MjE5
15
+ ZDc3MzdkM2M4ZjBlZjE5MzUyZDMwNDNkZjg3YzliZmQxYThiY2E=
@@ -227,16 +227,6 @@ module ActsAsOrderedTree
227
227
  end
228
228
 
229
229
  private
230
- # reloads relevant ordered_tree columns
231
- def reload_node #:nodoc:
232
- reload(
233
- :select => [parent_column,
234
- position_column,
235
- depth_column,
236
- children_counter_cache_column].compact,
237
- :lock => true
238
- )
239
- end
240
230
 
241
231
  def compute_level #:nodoc:
242
232
  ancestors.count
@@ -283,10 +273,7 @@ module ActsAsOrderedTree
283
273
  # This method do real node movements
284
274
  def move_to(target, pos) #:nodoc:
285
275
  tenacious_transaction do
286
- if target.is_a? self.class.base_class
287
- # lock obtained here
288
- target.send(:reload_node)
289
- elsif pos != :root && target
276
+ if pos != :root && target
290
277
  # load object if node is not an object
291
278
  target = self.class.lock(true).find(target)
292
279
  elsif pos == :root
@@ -324,7 +311,7 @@ module ActsAsOrderedTree
324
311
  reorder!(parent_id, position_was, position)
325
312
  end
326
313
 
327
- reload_node
314
+ reload
328
315
  end
329
316
 
330
317
  if move_kind
@@ -332,6 +319,7 @@ module ActsAsOrderedTree
332
319
  else
333
320
  update.call
334
321
  end
322
+
335
323
  end
336
324
  end
337
325
 
@@ -376,13 +364,14 @@ module ActsAsOrderedTree
376
364
  arel[parent_column].eq(parent_id)
377
365
  )
378
366
 
379
- binds = {:parent_id_was => parent_id_was,
367
+ binds = {:id => id,
368
+ :parent_id_was => parent_id_was,
380
369
  :parent_id => parent_id,
381
370
  :position_was => position_was,
382
371
  :position => position,
383
372
  :depth => depth}
384
373
 
385
- update_changed_attributes! conditions, assignments, binds
374
+ ordered_tree_scope.where(conditions).update_all([assignments.compact.join(', '), binds])
386
375
  end
387
376
 
388
377
  # Internal
@@ -414,23 +403,9 @@ module ActsAsOrderedTree
414
403
  ]
415
404
 
416
405
  conditions = arel[parent_column].eq(parent_id)
417
- binds = {:position_was => position_was, :position => position}
418
-
419
- update_changed_attributes! conditions, assignments, binds
420
- end
421
-
422
- def update_changed_attributes!(scope_conditions, assignments, binds)
423
- # add assignments for externally changed attributes
424
- internal_attributes = [parent_column.to_s, position_column.to_s, depth_column.to_s, self.class.primary_key]
425
- external_changed_attrs = changed - internal_attributes
426
- unless external_changed_attrs.empty?
427
- external_changed_attrs.each do |attr|
428
- assignments << "#{attr} = CASE WHEN #{self.class.primary_key} = :id THEN :#{attr} ELSE #{attr} END"
429
- binds[attr.to_sym] = self[attr]
430
- end
431
- end
406
+ binds = {:id => id, :position_was => position_was, :position => position}
432
407
 
433
- ordered_tree_scope.where(scope_conditions).update_all([assignments.compact.join(', '), {:id => id}.merge(binds)])
408
+ ordered_tree_scope.where(conditions).update_all([assignments.compact.join(', '), binds])
434
409
  end
435
410
 
436
411
  # recursively load descendants
@@ -1,3 +1,3 @@
1
1
  module ActsAsOrderedTree
2
- VERSION = '1.1.8'
2
+ VERSION = '1.2.0'
3
3
  end
@@ -415,26 +415,6 @@ describe ActsAsOrderedTree, :transactional do
415
415
  end
416
416
  end
417
417
 
418
- describe "#reload_node" do
419
- let!(:node) { create :default }
420
-
421
- before do
422
- node.name = 'changed'
423
- node.parent_id = 200
424
- node.position = 1000
425
- end
426
-
427
- subject { node.send :reload_node }
428
-
429
- if ActiveRecord::VERSION::STRING >= '4.0.0'
430
- xit 'ActiveRecord::Persistence#reload method ignores :select option since rails-4.0.0'
431
- else
432
- its(:name) { should eq 'changed' }
433
- end
434
- its(:parent_id) { should be_nil }
435
- its(:position) { should eq 1 }
436
- end
437
-
438
418
  describe "move actions" do
439
419
  let!(:root) { create :default_with_counter_cache, :name => 'root' }
440
420
  let!(:child_1) { create :default_with_counter_cache, :parent => root, :name => 'child_1' }
@@ -796,11 +776,12 @@ describe ActsAsOrderedTree, :transactional do
796
776
  end
797
777
 
798
778
  context "changed attributes" do
799
- specify "changed attributes should be saved" do
800
- child_2.name = 'name100'
779
+ before do
780
+ child_2.name = 'changed_100'
801
781
  child_2.move_to_left_of child_1
802
- child_2.reload.name.should eq 'name100'
803
782
  end
783
+
784
+ it { child_2.reload.name.should eq 'child_2' }
804
785
  end
805
786
 
806
787
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: acts_as_ordered_tree
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.8
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexei Mikhailov
@@ -9,76 +9,76 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-12-01 00:00:00.000000000 Z
12
+ date: 2013-12-03 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activerecord
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  requirements:
18
- - - '>='
18
+ - - ! '>='
19
19
  - !ruby/object:Gem::Version
20
20
  version: 3.0.0
21
21
  type: :runtime
22
22
  prerelease: false
23
23
  version_requirements: !ruby/object:Gem::Requirement
24
24
  requirements:
25
- - - '>='
25
+ - - ! '>='
26
26
  - !ruby/object:Gem::Version
27
27
  version: 3.0.0
28
28
  - !ruby/object:Gem::Dependency
29
29
  name: rake
30
30
  requirement: !ruby/object:Gem::Requirement
31
31
  requirements:
32
- - - '>='
32
+ - - ! '>='
33
33
  - !ruby/object:Gem::Version
34
34
  version: 0.9.2
35
35
  type: :development
36
36
  prerelease: false
37
37
  version_requirements: !ruby/object:Gem::Requirement
38
38
  requirements:
39
- - - '>='
39
+ - - ! '>='
40
40
  - !ruby/object:Gem::Version
41
41
  version: 0.9.2
42
42
  - !ruby/object:Gem::Dependency
43
43
  name: bundler
44
44
  requirement: !ruby/object:Gem::Requirement
45
45
  requirements:
46
- - - '>='
46
+ - - ! '>='
47
47
  - !ruby/object:Gem::Version
48
48
  version: '1.0'
49
49
  type: :development
50
50
  prerelease: false
51
51
  version_requirements: !ruby/object:Gem::Requirement
52
52
  requirements:
53
- - - '>='
53
+ - - ! '>='
54
54
  - !ruby/object:Gem::Version
55
55
  version: '1.0'
56
56
  - !ruby/object:Gem::Dependency
57
57
  name: rspec
58
58
  requirement: !ruby/object:Gem::Requirement
59
59
  requirements:
60
- - - '>='
60
+ - - ! '>='
61
61
  - !ruby/object:Gem::Version
62
62
  version: '2.11'
63
63
  type: :development
64
64
  prerelease: false
65
65
  version_requirements: !ruby/object:Gem::Requirement
66
66
  requirements:
67
- - - '>='
67
+ - - ! '>='
68
68
  - !ruby/object:Gem::Version
69
69
  version: '2.11'
70
70
  - !ruby/object:Gem::Dependency
71
71
  name: shoulda-matchers
72
72
  requirement: !ruby/object:Gem::Requirement
73
73
  requirements:
74
- - - '>='
74
+ - - ! '>='
75
75
  - !ruby/object:Gem::Version
76
76
  version: 1.2.0
77
77
  type: :development
78
78
  prerelease: false
79
79
  version_requirements: !ruby/object:Gem::Requirement
80
80
  requirements:
81
- - - '>='
81
+ - - ! '>='
82
82
  - !ruby/object:Gem::Version
83
83
  version: 1.2.0
84
84
  - !ruby/object:Gem::Dependency
@@ -99,14 +99,14 @@ dependencies:
99
99
  name: appraisal
100
100
  requirement: !ruby/object:Gem::Requirement
101
101
  requirements:
102
- - - '>='
102
+ - - ! '>='
103
103
  - !ruby/object:Gem::Version
104
104
  version: 0.4.0
105
105
  type: :development
106
106
  prerelease: false
107
107
  version_requirements: !ruby/object:Gem::Requirement
108
108
  requirements:
109
- - - '>='
109
+ - - ! '>='
110
110
  - !ruby/object:Gem::Version
111
111
  version: 0.4.0
112
112
  description:
@@ -145,17 +145,17 @@ require_paths:
145
145
  - lib
146
146
  required_ruby_version: !ruby/object:Gem::Requirement
147
147
  requirements:
148
- - - '>='
148
+ - - ! '>='
149
149
  - !ruby/object:Gem::Version
150
150
  version: '0'
151
151
  required_rubygems_version: !ruby/object:Gem::Requirement
152
152
  requirements:
153
- - - '>='
153
+ - - ! '>='
154
154
  - !ruby/object:Gem::Version
155
155
  version: '0'
156
156
  requirements: []
157
157
  rubyforge_project: acts_as_ordered_tree
158
- rubygems_version: 2.1.11
158
+ rubygems_version: 2.1.3
159
159
  signing_key:
160
160
  specification_version: 4
161
161
  summary: ActiveRecord extension for sorted adjacency lists support