collectiveidea-awesome_nested_set 1.3.0 → 1.4.0

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.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.3.0
1
+ 1.4.0
@@ -2,11 +2,11 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{awesome_nested_set}
5
- s.version = "1.3.0"
5
+ s.version = "1.4.0"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Brandon Keepers", "Daniel Morrison"]
9
- s.date = %q{2009-08-11}
9
+ s.date = %q{2009-09-03}
10
10
  s.description = %q{An awesome nested set implementation for Active Record}
11
11
  s.email = %q{info@collectiveidea.com}
12
12
  s.extra_rdoc_files = [
@@ -15,24 +15,11 @@ module CollectiveIdea #:nodoc:
15
15
  #
16
16
  # == API
17
17
  #
18
- # Methods names are aligned with acts_as_tree as much as possible, to make replacment from one
19
- # by another easier, except for the creation:
18
+ # Methods names are aligned with acts_as_tree as much as possible to make replacment from one
19
+ # by another easier.
20
20
  #
21
- # in acts_as_tree:
22
21
  # item.children.create(:name => "child1")
23
22
  #
24
- # in acts_as_nested_set:
25
- # # adds a new item at the "end" of the tree, i.e. with child.left = max(tree.right)+1
26
- # child = MyClass.new(:name => "child1")
27
- # child.save
28
- # # now move the item to its right place
29
- # child.move_to_child_of my_item
30
- #
31
- # You can pass an id or an object to:
32
- # * <tt>#move_to_child_of</tt>
33
- # * <tt>#move_to_right_of</tt>
34
- # * <tt>#move_to_left_of</tt>
35
- #
36
23
  module SingletonMethods
37
24
  # Configuration options are:
38
25
  #
@@ -75,6 +62,8 @@ module CollectiveIdea #:nodoc:
75
62
 
76
63
  belongs_to :parent, :class_name => self.base_class.class_name,
77
64
  :foreign_key => parent_column_name
65
+ has_many :children, :class_name => self.base_class.class_name,
66
+ :foreign_key => parent_column_name
78
67
 
79
68
  attr_accessor :skip_before_destroy
80
69
 
@@ -261,7 +250,7 @@ module CollectiveIdea #:nodoc:
261
250
  end
262
251
 
263
252
  def leaf?
264
- right - left == 1
253
+ !new_record? && right - left == 1
265
254
  end
266
255
 
267
256
  # Returns true is this is a child node
@@ -332,11 +321,6 @@ module CollectiveIdea #:nodoc:
332
321
  without_self self_and_descendants
333
322
  end
334
323
 
335
- # Returns a set of only this entry's immediate children
336
- def children
337
- nested_set_scope.scoped :conditions => {parent_column_name => self}
338
- end
339
-
340
324
  def is_descendant_of?(other)
341
325
  other.left < self.left && self.left < other.right && same_scope?(other)
342
326
  end
@@ -3,18 +3,17 @@ require 'test_helper'
3
3
  class Note < ActiveRecord::Base
4
4
  acts_as_nested_set :scope => [:notable_id, :notable_type]
5
5
  end
6
+ class Default < ActiveRecord::Base
7
+ acts_as_nested_set
8
+ set_table_name 'categories'
9
+ end
10
+ class ScopedCategory < ActiveRecord::Base
11
+ acts_as_nested_set :scope => :organization
12
+ set_table_name 'categories'
13
+ end
6
14
 
7
15
  class AwesomeNestedSetTest < TestCaseClass
8
16
 
9
- class Default < ActiveRecord::Base
10
- acts_as_nested_set
11
- set_table_name 'categories'
12
- end
13
- class Scoped < ActiveRecord::Base
14
- acts_as_nested_set :scope => :organization
15
- set_table_name 'categories'
16
- end
17
-
18
17
  def test_left_column_default
19
18
  assert_equal 'lft', Default.acts_as_nested_set_options[:left_column]
20
19
  end
@@ -73,7 +72,7 @@ class AwesomeNestedSetTest < TestCaseClass
73
72
  end
74
73
 
75
74
  def test_scoped_appends_id
76
- assert_equal :organization_id, Scoped.acts_as_nested_set_options[:scope]
75
+ assert_equal :organization_id, ScopedCategory.acts_as_nested_set_options[:scope]
77
76
  end
78
77
 
79
78
  def test_roots_class_method
@@ -110,7 +109,9 @@ class AwesomeNestedSetTest < TestCaseClass
110
109
 
111
110
  assert !categories(:top_level).leaf?
112
111
  assert !categories(:child_2).leaf?
112
+ assert !Category.new.leaf?
113
113
  end
114
+
114
115
 
115
116
  def test_parent
116
117
  assert_equal categories(:child_2), categories(:child_2_1).parent
@@ -213,7 +214,7 @@ class AwesomeNestedSetTest < TestCaseClass
213
214
  end
214
215
 
215
216
  def test_is_or_is_ancestor_of_with_scope
216
- root = Scoped.root
217
+ root = ScopedCategory.root
217
218
  child = root.children.first
218
219
  assert root.is_or_is_ancestor_of?(child)
219
220
  child.update_attribute :organization_id, 'different'
@@ -239,7 +240,7 @@ class AwesomeNestedSetTest < TestCaseClass
239
240
  end
240
241
 
241
242
  def test_is_or_is_descendant_of_with_scope
242
- root = Scoped.root
243
+ root = ScopedCategory.root
243
244
  child = root.children.first
244
245
  assert child.is_or_is_descendant_of?(root)
245
246
  child.update_attribute :organization_id, 'different'
@@ -247,7 +248,7 @@ class AwesomeNestedSetTest < TestCaseClass
247
248
  end
248
249
 
249
250
  def test_same_scope?
250
- root = Scoped.root
251
+ root = ScopedCategory.root
251
252
  child = root.children.first
252
253
  assert child.same_scope?(root)
253
254
  child.update_attribute :organization_id, 'different'
@@ -668,4 +669,13 @@ class AwesomeNestedSetTest < TestCaseClass
668
669
  assert Category.valid?
669
670
  end
670
671
 
672
+ def test_creating_child_from_parent
673
+ category = categories(:child_2).children.create!(:name => "Child")
674
+ assert_equal categories(:child_2), category.parent
675
+ assert_equal categories(:child_2).id, category.parent_id
676
+ assert_not_nil category.left
677
+ assert_not_nil category.right
678
+ assert Category.valid?
679
+ end
680
+
671
681
  end
data/test/test_helper.rb CHANGED
@@ -20,7 +20,6 @@ load(File.join(plugin_test_dir, "db", "schema.rb"))
20
20
 
21
21
  Dir["#{plugin_test_dir}/fixtures/*.rb"].each {|file| require file }
22
22
 
23
-
24
23
  class TestCaseClass #:nodoc:
25
24
  self.fixture_path = File.dirname(__FILE__) + "/fixtures/"
26
25
  self.use_transactional_fixtures = true
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: collectiveidea-awesome_nested_set
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0
4
+ version: 1.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brandon Keepers
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2009-08-11 00:00:00 -07:00
13
+ date: 2009-09-03 00:00:00 -07:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -55,7 +55,6 @@ files:
55
55
  - test/test_helper.rb
56
56
  has_rdoc: false
57
57
  homepage: http://github.com/collectiveidea/awesome_nested_set
58
- licenses:
59
58
  post_install_message:
60
59
  rdoc_options:
61
60
  - --main
@@ -79,7 +78,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
79
78
  requirements: []
80
79
 
81
80
  rubyforge_project:
82
- rubygems_version: 1.3.5
81
+ rubygems_version: 1.2.0
83
82
  signing_key:
84
83
  specification_version: 3
85
84
  summary: An awesome nested set implementation for Active Record