nested_set 1.6.7 → 1.6.8

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -4,7 +4,7 @@ gem "railties", ">= 3.0.0"
4
4
  gem "activerecord", ">= 3.0.0"
5
5
 
6
6
  group :development, :test do
7
- gem "sqlite3-ruby"
7
+ gem "sqlite3"
8
8
  gem "actionpack", ">= 3.0.0"
9
9
  gem "bench_press", ">= 0.3.1"
10
10
  gem "jeweler"
@@ -52,7 +52,7 @@ GEM
52
52
  rake (>= 0.8.7)
53
53
  thor (~> 0.14.4)
54
54
  rake (0.8.7)
55
- sqlite3-ruby (1.3.2)
55
+ sqlite3 (1.3.4)
56
56
  thor (0.14.6)
57
57
  tzinfo (0.3.23)
58
58
 
@@ -65,4 +65,4 @@ DEPENDENCIES
65
65
  bench_press (>= 0.3.1)
66
66
  jeweler
67
67
  railties (>= 3.0.0)
68
- sqlite3-ruby
68
+ sqlite3
data/README.md CHANGED
@@ -92,10 +92,11 @@ Benchmark tests
92
92
 
93
93
  You can learn more about nested sets at:
94
94
 
95
- [1](http://www.dbmsmag.com/9603d06.html)
96
- [2](http://threebit.net/tutorials/nestedset/tutorial1.html)
97
- [3](http://api.rubyonrails.com/classes/ActiveRecord/Acts/NestedSet/ClassMethods.html)
98
- [4](http://opensource.symetrie.com/trac/better_nested_set/)
95
+ [1](http://en.wikipedia.org/wiki/Nested_set_model)
96
+ [2](http://www.ibase.ru/devinfo/DBMSTrees/9603d06.html)
97
+ [3](http://threebit.net/tutorials/nestedset/tutorial1.html)
98
+ [4](http://rdoc.info/github/rails/acts_as_nested_set/master/ActiveRecord/Acts/NestedSet/ClassMethods)
99
+ [5](http://agilewebdevelopment.com/plugins/betternestedset)
99
100
 
100
101
  ## How to contribute
101
102
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.6.7
1
+ 1.6.8
@@ -222,7 +222,7 @@ module CollectiveIdea #:nodoc:
222
222
  nodes_for_rebuild(node, node_scope).each{ |n| set_left_and_rights.call(n) }
223
223
  # set right
224
224
  node[right_column_name] = indices[node_scope] += 1
225
- node.save!
225
+ node.save(:validate => false)
226
226
  end
227
227
 
228
228
  # Find root node(s)
@@ -478,6 +478,11 @@ module CollectiveIdea #:nodoc:
478
478
  siblings.where("#{q_left} > ?", left).first
479
479
  end
480
480
 
481
+ # Lock rows whose lfts and rgts are to be updated
482
+ def lock_check(cond=nil)
483
+ nested_set_scope.select(primary_key_column_name).where(cond).lock
484
+ end
485
+
481
486
  # Shorthand method for finding the left sibling and moving to the left of it.
482
487
  def move_left
483
488
  move_to_left_of left_sibling
@@ -576,16 +581,19 @@ module CollectiveIdea #:nodoc:
576
581
  # back to the left so the counts still work.
577
582
  def destroy_descendants
578
583
  return if right.nil? || left.nil? || skip_before_destroy
579
- reload_nested_set
580
-
581
584
  self.class.base_class.transaction do
582
- if acts_as_nested_set_options[:dependent] == :destroy
583
- descendants.each do |model|
584
- model.skip_before_destroy = true
585
- model.destroy
586
- end
587
- else
588
- nested_set_scope.delete_all(["#{q_left} > ? AND #{q_right} < ?", left, right])
585
+ lock_check(["#{quoted_right_column_name} > ?", right])
586
+ reload_nested_set
587
+ case destroy_method
588
+ when :delete_all then
589
+ nested_set_scope.delete_all(["#{q_left} > ? AND #{q_right} < ?", left, right])
590
+
591
+ else
592
+ descendants.each do |model|
593
+ model.skip_before_destroy = true
594
+ model.respond_to?(destroy_method) ? model.send(destroy_method) : raise(NoMethodError, "#{model} does not have a method #{destroy_method}")
595
+ end
596
+
589
597
  end
590
598
 
591
599
  # update lefts and rights for remaining nodes
@@ -604,6 +612,11 @@ module CollectiveIdea #:nodoc:
604
612
  end
605
613
  end
606
614
 
615
+ # just a shortcut
616
+ def destroy_method
617
+ acts_as_nested_set_options[:dependent]
618
+ end
619
+
607
620
  # reload left, right, and parent
608
621
  def reload_nested_set
609
622
  reload(:select => "#{quoted_left_column_name}, " +
@@ -650,11 +663,8 @@ module CollectiveIdea #:nodoc:
650
663
  a, b, c, d = [self[left_column_name], self[right_column_name], bound, other_bound].sort
651
664
 
652
665
  # select the rows in the model between a and d, and apply a lock
653
- self.class.base_class.find(:all,
654
- :select => primary_key_column_name,
655
- :conditions => ["#{quoted_left_column_name} >= :a and #{quoted_right_column_name} <= :d", {:a => a, :d => d}],
656
- :lock => true
657
- )
666
+ cond = ["#{quoted_left_column_name} >= :a and #{quoted_right_column_name} <= :d", { :a => a, :d => d }]
667
+ lock_check(cond)
658
668
 
659
669
  new_parent = case position
660
670
  when :child; target.id
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{nested_set}
8
- s.version = "1.6.7"
8
+ s.version = "1.6.8"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Brandon Keepers", "Daniel Morrison"]
12
- s.date = %q{2011-06-20}
12
+ s.date = %q{2011-08-31}
13
13
  s.description = %q{An awesome nested set implementation for Active Record}
14
14
  s.email = %q{info@collectiveidea.com}
15
15
  s.extra_rdoc_files = [
@@ -62,14 +62,14 @@ Gem::Specification.new do |s|
62
62
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
63
63
  s.add_runtime_dependency(%q<railties>, [">= 3.0.0"])
64
64
  s.add_runtime_dependency(%q<activerecord>, [">= 3.0.0"])
65
- s.add_development_dependency(%q<sqlite3-ruby>, [">= 0"])
65
+ s.add_development_dependency(%q<sqlite3>, [">= 0"])
66
66
  s.add_development_dependency(%q<actionpack>, [">= 3.0.0"])
67
67
  s.add_development_dependency(%q<bench_press>, [">= 0.3.1"])
68
68
  s.add_development_dependency(%q<jeweler>, [">= 0"])
69
69
  else
70
70
  s.add_dependency(%q<railties>, [">= 3.0.0"])
71
71
  s.add_dependency(%q<activerecord>, [">= 3.0.0"])
72
- s.add_dependency(%q<sqlite3-ruby>, [">= 0"])
72
+ s.add_dependency(%q<sqlite3>, [">= 0"])
73
73
  s.add_dependency(%q<actionpack>, [">= 3.0.0"])
74
74
  s.add_dependency(%q<bench_press>, [">= 0.3.1"])
75
75
  s.add_dependency(%q<jeweler>, [">= 0"])
@@ -77,7 +77,7 @@ Gem::Specification.new do |s|
77
77
  else
78
78
  s.add_dependency(%q<railties>, [">= 3.0.0"])
79
79
  s.add_dependency(%q<activerecord>, [">= 3.0.0"])
80
- s.add_dependency(%q<sqlite3-ruby>, [">= 0"])
80
+ s.add_dependency(%q<sqlite3>, [">= 0"])
81
81
  s.add_dependency(%q<actionpack>, [">= 3.0.0"])
82
82
  s.add_dependency(%q<bench_press>, [">= 0.3.1"])
83
83
  s.add_dependency(%q<jeweler>, [">= 0"])
@@ -24,3 +24,13 @@ end
24
24
  class Category_DefaultScope < Category
25
25
  default_scope order('categories.id ASC')
26
26
  end
27
+
28
+ class Category_WithCustomDestroy < ActiveRecord::Base
29
+ set_table_name 'categories'
30
+ acts_as_nested_set
31
+
32
+ private :destroy
33
+ def custom_destroy
34
+ destroy
35
+ end
36
+ end
@@ -118,7 +118,7 @@ class HelperTest < ActionView::TestCase
118
118
  ['Child 2', 3],
119
119
  ['Child 2.1', 4]
120
120
  ]
121
- actual = nested_set_options Category_NoToArray.find(3) do |c|
121
+ actual = nested_set_options Category_NoToArray.find(3) do |c, l|
122
122
  c.name
123
123
  end
124
124
  assert_equal expected, actual
@@ -684,6 +684,17 @@ class NestedSetTest < ActiveSupport::TestCase
684
684
  assert Category.valid?
685
685
  end
686
686
 
687
+ def test_custom_destroy_method_does_not_invalidate
688
+ Category_WithCustomDestroy.acts_as_nested_set_options[:dependent] = :custom_destroy
689
+ Category_WithCustomDestroy.find_by_name('Child 2').custom_destroy
690
+ assert Category_WithCustomDestroy.valid?
691
+ end
692
+
693
+ def test_custom_destroy_raises_an_error_if_method_does_not_exist
694
+ Category.acts_as_nested_set_options[:dependent] = :custom_destroy
695
+ assert_raise(NoMethodError) { categories(:child_2).destroy }
696
+ end
697
+
687
698
  def test_assigning_parent_id_on_create
688
699
  category = Category.create!(:name => "Child", :parent_id => categories(:child_2).id)
689
700
  assert_equal categories(:child_2), category.parent
metadata CHANGED
@@ -1,94 +1,91 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: nested_set
3
- version: !ruby/object:Gem::Version
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.6.8
4
5
  prerelease:
5
- version: 1.6.7
6
6
  platform: ruby
7
- authors:
7
+ authors:
8
8
  - Brandon Keepers
9
9
  - Daniel Morrison
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
-
14
- date: 2011-06-20 00:00:00 +04:00
13
+ date: 2011-08-31 00:00:00.000000000 +04:00
15
14
  default_executable:
16
- dependencies:
17
- - !ruby/object:Gem::Dependency
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
18
17
  name: railties
19
- requirement: &id001 !ruby/object:Gem::Requirement
18
+ requirement: &27660600 !ruby/object:Gem::Requirement
20
19
  none: false
21
- requirements:
22
- - - ">="
23
- - !ruby/object:Gem::Version
20
+ requirements:
21
+ - - ! '>='
22
+ - !ruby/object:Gem::Version
24
23
  version: 3.0.0
25
24
  type: :runtime
26
25
  prerelease: false
27
- version_requirements: *id001
28
- - !ruby/object:Gem::Dependency
26
+ version_requirements: *27660600
27
+ - !ruby/object:Gem::Dependency
29
28
  name: activerecord
30
- requirement: &id002 !ruby/object:Gem::Requirement
29
+ requirement: &27660100 !ruby/object:Gem::Requirement
31
30
  none: false
32
- requirements:
33
- - - ">="
34
- - !ruby/object:Gem::Version
31
+ requirements:
32
+ - - ! '>='
33
+ - !ruby/object:Gem::Version
35
34
  version: 3.0.0
36
35
  type: :runtime
37
36
  prerelease: false
38
- version_requirements: *id002
39
- - !ruby/object:Gem::Dependency
40
- name: sqlite3-ruby
41
- requirement: &id003 !ruby/object:Gem::Requirement
37
+ version_requirements: *27660100
38
+ - !ruby/object:Gem::Dependency
39
+ name: sqlite3
40
+ requirement: &27659600 !ruby/object:Gem::Requirement
42
41
  none: false
43
- requirements:
44
- - - ">="
45
- - !ruby/object:Gem::Version
46
- version: "0"
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
47
46
  type: :development
48
47
  prerelease: false
49
- version_requirements: *id003
50
- - !ruby/object:Gem::Dependency
48
+ version_requirements: *27659600
49
+ - !ruby/object:Gem::Dependency
51
50
  name: actionpack
52
- requirement: &id004 !ruby/object:Gem::Requirement
51
+ requirement: &27659120 !ruby/object:Gem::Requirement
53
52
  none: false
54
- requirements:
55
- - - ">="
56
- - !ruby/object:Gem::Version
53
+ requirements:
54
+ - - ! '>='
55
+ - !ruby/object:Gem::Version
57
56
  version: 3.0.0
58
57
  type: :development
59
58
  prerelease: false
60
- version_requirements: *id004
61
- - !ruby/object:Gem::Dependency
59
+ version_requirements: *27659120
60
+ - !ruby/object:Gem::Dependency
62
61
  name: bench_press
63
- requirement: &id005 !ruby/object:Gem::Requirement
62
+ requirement: &27658640 !ruby/object:Gem::Requirement
64
63
  none: false
65
- requirements:
66
- - - ">="
67
- - !ruby/object:Gem::Version
64
+ requirements:
65
+ - - ! '>='
66
+ - !ruby/object:Gem::Version
68
67
  version: 0.3.1
69
68
  type: :development
70
69
  prerelease: false
71
- version_requirements: *id005
72
- - !ruby/object:Gem::Dependency
70
+ version_requirements: *27658640
71
+ - !ruby/object:Gem::Dependency
73
72
  name: jeweler
74
- requirement: &id006 !ruby/object:Gem::Requirement
73
+ requirement: &27658160 !ruby/object:Gem::Requirement
75
74
  none: false
76
- requirements:
77
- - - ">="
78
- - !ruby/object:Gem::Version
79
- version: "0"
75
+ requirements:
76
+ - - ! '>='
77
+ - !ruby/object:Gem::Version
78
+ version: '0'
80
79
  type: :development
81
80
  prerelease: false
82
- version_requirements: *id006
81
+ version_requirements: *27658160
83
82
  description: An awesome nested set implementation for Active Record
84
83
  email: info@collectiveidea.com
85
84
  executables: []
86
-
87
85
  extensions: []
88
-
89
- extra_rdoc_files:
86
+ extra_rdoc_files:
90
87
  - README.md
91
- files:
88
+ files:
92
89
  - .autotest
93
90
  - Gemfile
94
91
  - Gemfile.lock
@@ -118,35 +115,32 @@ files:
118
115
  has_rdoc: true
119
116
  homepage: http://github.com/skyeagle/nested_set
120
117
  licenses: []
121
-
122
118
  post_install_message:
123
119
  rdoc_options: []
124
-
125
- require_paths:
120
+ require_paths:
126
121
  - lib
127
- required_ruby_version: !ruby/object:Gem::Requirement
122
+ required_ruby_version: !ruby/object:Gem::Requirement
128
123
  none: false
129
- requirements:
130
- - - ">="
131
- - !ruby/object:Gem::Version
132
- hash: 2412843186330894320
133
- segments:
124
+ requirements:
125
+ - - ! '>='
126
+ - !ruby/object:Gem::Version
127
+ version: '0'
128
+ segments:
134
129
  - 0
135
- version: "0"
136
- required_rubygems_version: !ruby/object:Gem::Requirement
130
+ hash: -14733230779459134
131
+ required_rubygems_version: !ruby/object:Gem::Requirement
137
132
  none: false
138
- requirements:
139
- - - ">="
140
- - !ruby/object:Gem::Version
141
- version: "0"
133
+ requirements:
134
+ - - ! '>='
135
+ - !ruby/object:Gem::Version
136
+ version: '0'
142
137
  requirements: []
143
-
144
138
  rubyforge_project:
145
139
  rubygems_version: 1.6.2
146
140
  signing_key:
147
141
  specification_version: 3
148
142
  summary: An awesome nested set implementation for Active Record
149
- test_files:
143
+ test_files:
150
144
  - test/benchmarks.rb
151
145
  - test/db/schema.rb
152
146
  - test/fixtures/category.rb