]> source.dussan.org Git - redmine.git/commitdiff
svn propset svn:eol-style LF lib/plugins/awesome_nested_set/spec/*
authorToshi MARUYAMA <marutosijp2@yahoo.co.jp>
Mon, 20 Jan 2014 02:19:08 +0000 (02:19 +0000)
committerToshi MARUYAMA <marutosijp2@yahoo.co.jp>
Mon, 20 Jan 2014 02:19:08 +0000 (02:19 +0000)
git-svn-id: http://svn.redmine.org/redmine/trunk@12676 e93f8b46-1217-0410-a6f0-8f06a7374b81

lib/plugins/awesome_nested_set/spec/awesome_nested_set/helper_spec.rb
lib/plugins/awesome_nested_set/spec/awesome_nested_set_spec.rb
lib/plugins/awesome_nested_set/spec/db/database.yml
lib/plugins/awesome_nested_set/spec/db/schema.rb
lib/plugins/awesome_nested_set/spec/fixtures/brokens.yml
lib/plugins/awesome_nested_set/spec/fixtures/categories.yml
lib/plugins/awesome_nested_set/spec/fixtures/departments.yml
lib/plugins/awesome_nested_set/spec/fixtures/notes.yml
lib/plugins/awesome_nested_set/spec/fixtures/things.yml
lib/plugins/awesome_nested_set/spec/spec_helper.rb
lib/plugins/awesome_nested_set/spec/support/models.rb

index cc32a0d0a4e6a6ba574ba2006eef110263efcca8..1cca71ba873bdad32091c8857a01e6ab57cbf395 100644 (file)
@@ -1,67 +1,67 @@
-require 'spec_helper'\r
-\r
-describe "Helper" do\r
-  include CollectiveIdea::Acts::NestedSet::Helper\r
-\r
-  before(:all) do\r
-    self.class.fixtures :categories\r
-  end\r
-\r
-  describe "nested_set_options" do\r
-    it "test_nested_set_options" do\r
-      expected = [\r
-        [" Top Level", 1],\r
-        ["- Child 1", 2],\r
-        ['- Child 2', 3],\r
-        ['-- Child 2.1', 4],\r
-        ['- Child 3', 5],\r
-        [" Top Level 2", 6]\r
-      ]\r
-      actual = nested_set_options(Category) do |c|\r
-        "#{'-' * c.level} #{c.name}"\r
-      end\r
-      actual.should == expected\r
-    end\r
-\r
-    it "test_nested_set_options_with_mover" do\r
-      expected = [\r
-        [" Top Level", 1],\r
-        ["- Child 1", 2],\r
-        ['- Child 3', 5],\r
-        [" Top Level 2", 6]\r
-      ]\r
-      actual = nested_set_options(Category, categories(:child_2)) do |c|\r
-        "#{'-' * c.level} #{c.name}"\r
-      end\r
-      actual.should == expected\r
-    end\r
-\r
-    it "test_nested_set_options_with_array_as_argument_without_mover" do\r
-      expected = [\r
-        [" Top Level", 1],\r
-        ["- Child 1", 2],\r
-        ['- Child 2', 3],\r
-        ['-- Child 2.1', 4],\r
-        ['- Child 3', 5],\r
-        [" Top Level 2", 6]\r
-      ]\r
-      actual = nested_set_options(Category.all) do |c|\r
-        "#{'-' * c.level} #{c.name}"\r
-      end\r
-      actual.should == expected\r
-    end\r
-\r
-    it "test_nested_set_options_with_array_as_argument_with_mover" do\r
-      expected = [\r
-        [" Top Level", 1],\r
-        ["- Child 1", 2],\r
-        ['- Child 3', 5],\r
-        [" Top Level 2", 6]\r
-      ]\r
-      actual = nested_set_options(Category.all, categories(:child_2)) do |c|\r
-        "#{'-' * c.level} #{c.name}"\r
-      end\r
-      actual.should == expected\r
-    end\r
-  end\r
-end\r
+require 'spec_helper'
+
+describe "Helper" do
+  include CollectiveIdea::Acts::NestedSet::Helper
+
+  before(:all) do
+    self.class.fixtures :categories
+  end
+
+  describe "nested_set_options" do
+    it "test_nested_set_options" do
+      expected = [
+        [" Top Level", 1],
+        ["- Child 1", 2],
+        ['- Child 2', 3],
+        ['-- Child 2.1', 4],
+        ['- Child 3', 5],
+        [" Top Level 2", 6]
+      ]
+      actual = nested_set_options(Category) do |c|
+        "#{'-' * c.level} #{c.name}"
+      end
+      actual.should == expected
+    end
+
+    it "test_nested_set_options_with_mover" do
+      expected = [
+        [" Top Level", 1],
+        ["- Child 1", 2],
+        ['- Child 3', 5],
+        [" Top Level 2", 6]
+      ]
+      actual = nested_set_options(Category, categories(:child_2)) do |c|
+        "#{'-' * c.level} #{c.name}"
+      end
+      actual.should == expected
+    end
+
+    it "test_nested_set_options_with_array_as_argument_without_mover" do
+      expected = [
+        [" Top Level", 1],
+        ["- Child 1", 2],
+        ['- Child 2', 3],
+        ['-- Child 2.1', 4],
+        ['- Child 3', 5],
+        [" Top Level 2", 6]
+      ]
+      actual = nested_set_options(Category.all) do |c|
+        "#{'-' * c.level} #{c.name}"
+      end
+      actual.should == expected
+    end
+
+    it "test_nested_set_options_with_array_as_argument_with_mover" do
+      expected = [
+        [" Top Level", 1],
+        ["- Child 1", 2],
+        ['- Child 3', 5],
+        [" Top Level 2", 6]
+      ]
+      actual = nested_set_options(Category.all, categories(:child_2)) do |c|
+        "#{'-' * c.level} #{c.name}"
+      end
+      actual.should == expected
+    end
+  end
+end
index c1c0f7401dfab867cc1378806239ca551b386a9b..692b123a55e80b6d3abee9f198f79e9b87a53754 100644 (file)
-require 'spec_helper'\r
-\r
-describe "AwesomeNestedSet" do\r
-  before(:all) do\r
-    self.class.fixtures :categories, :departments, :notes, :things, :brokens\r
-  end\r
-\r
-  describe "defaults" do\r
-    it "should have left_column_default" do\r
-      Default.acts_as_nested_set_options[:left_column].should == 'lft'\r
-    end\r
-\r
-    it "should have right_column_default" do\r
-      Default.acts_as_nested_set_options[:right_column].should == 'rgt'\r
-    end\r
-\r
-    it "should have parent_column_default" do\r
-      Default.acts_as_nested_set_options[:parent_column].should == 'parent_id'\r
-    end\r
-\r
-    it "should have scope_default" do\r
-      Default.acts_as_nested_set_options[:scope].should be_nil\r
-    end\r
-\r
-    it "should have left_column_name" do\r
-      Default.left_column_name.should == 'lft'\r
-      Default.new.left_column_name.should == 'lft'\r
-      RenamedColumns.left_column_name.should == 'red'\r
-      RenamedColumns.new.left_column_name.should == 'red'\r
-    end\r
-\r
-    it "should have right_column_name" do\r
-      Default.right_column_name.should == 'rgt'\r
-      Default.new.right_column_name.should == 'rgt'\r
-      RenamedColumns.right_column_name.should == 'black'\r
-      RenamedColumns.new.right_column_name.should == 'black'\r
-    end\r
-\r
-    it "should have parent_column_name" do\r
-      Default.parent_column_name.should == 'parent_id'\r
-      Default.new.parent_column_name.should == 'parent_id'\r
-      RenamedColumns.parent_column_name.should == 'mother_id'\r
-      RenamedColumns.new.parent_column_name.should == 'mother_id'\r
-    end\r
-  end\r
-\r
-  it "creation_with_altered_column_names" do\r
-    lambda {\r
-      RenamedColumns.create!()\r
-    }.should_not raise_exception\r
-  end\r
-\r
-  it "creation when existing record has nil left column" do\r
-    assert_nothing_raised do\r
-      Broken.create!\r
-    end\r
-  end\r
-  \r
-  it "quoted_left_column_name" do\r
-    quoted = Default.connection.quote_column_name('lft')\r
-    Default.quoted_left_column_name.should == quoted\r
-    Default.new.quoted_left_column_name.should == quoted\r
-  end\r
-\r
-  it "quoted_right_column_name" do\r
-    quoted = Default.connection.quote_column_name('rgt')\r
-    Default.quoted_right_column_name.should == quoted\r
-    Default.new.quoted_right_column_name.should == quoted\r
-  end\r
-\r
-  it "left_column_protected_from_assignment" do\r
-    lambda {\r
-      Category.new.lft = 1\r
-    }.should raise_exception(ActiveRecord::ActiveRecordError)\r
-  end\r
-\r
-  it "right_column_protected_from_assignment" do\r
-    lambda {\r
-      Category.new.rgt = 1\r
-    }.should raise_exception(ActiveRecord::ActiveRecordError)\r
-  end\r
-\r
-  it "scoped_appends_id" do\r
-    ScopedCategory.acts_as_nested_set_options[:scope].should == :organization_id\r
-  end\r
-\r
-  it "roots_class_method" do\r
-    Category.roots.should == Category.find_all_by_parent_id(nil)\r
-  end\r
-\r
-  it "root_class_method" do\r
-    Category.root.should == categories(:top_level)\r
-  end\r
-\r
-  it "root" do\r
-    categories(:child_3).root.should == categories(:top_level)\r
-  end\r
-\r
-  it "root?" do\r
-    categories(:top_level).root?.should be_true\r
-    categories(:top_level_2).root?.should be_true\r
-  end\r
-\r
-  it "leaves_class_method" do\r
-    Category.find(:all, :conditions => "#{Category.right_column_name} - #{Category.left_column_name} = 1").should == Category.leaves\r
-    Category.leaves.count.should == 4\r
-    Category.leaves.should include(categories(:child_1))\r
-    Category.leaves.should include(categories(:child_2_1))\r
-    Category.leaves.should include(categories(:child_3))\r
-    Category.leaves.should include(categories(:top_level_2))\r
-  end\r
-\r
-  it "leaf" do\r
-    categories(:child_1).leaf?.should be_true\r
-    categories(:child_2_1).leaf?.should be_true\r
-    categories(:child_3).leaf?.should be_true\r
-    categories(:top_level_2).leaf?.should be_true\r
-\r
-    categories(:top_level).leaf?.should be_false\r
-    categories(:child_2).leaf?.should be_false\r
-    Category.new.leaf?.should be_false\r
-  end\r
-\r
-\r
-  it "parent" do\r
-    categories(:child_2_1).parent.should == categories(:child_2)\r
-  end\r
-\r
-  it "self_and_ancestors" do\r
-    child = categories(:child_2_1)\r
-    self_and_ancestors = [categories(:top_level), categories(:child_2), child]\r
-    self_and_ancestors.should == child.self_and_ancestors\r
-  end\r
-\r
-  it "ancestors" do\r
-    child = categories(:child_2_1)\r
-    ancestors = [categories(:top_level), categories(:child_2)]\r
-    ancestors.should == child.ancestors\r
-  end\r
-\r
-  it "self_and_siblings" do\r
-    child = categories(:child_2)\r
-    self_and_siblings = [categories(:child_1), child, categories(:child_3)]\r
-    self_and_siblings.should == child.self_and_siblings\r
-    lambda do\r
-      tops = [categories(:top_level), categories(:top_level_2)]\r
-      assert_equal tops, categories(:top_level).self_and_siblings\r
-    end.should_not raise_exception\r
-  end\r
-\r
-  it "siblings" do\r
-    child = categories(:child_2)\r
-    siblings = [categories(:child_1), categories(:child_3)]\r
-    siblings.should == child.siblings\r
-  end\r
-\r
-  it "leaves" do\r
-    leaves = [categories(:child_1), categories(:child_2_1), categories(:child_3)]\r
-    categories(:top_level).leaves.should == leaves\r
-  end\r
-\r
-  it "level" do\r
-    categories(:top_level).level.should == 0\r
-    categories(:child_1).level.should == 1\r
-    categories(:child_2_1).level.should == 2\r
-  end\r
-\r
-  it "has_children?" do\r
-    categories(:child_2_1).children.empty?.should be_true\r
-    categories(:child_2).children.empty?.should be_false\r
-    categories(:top_level).children.empty?.should be_false\r
-  end\r
-\r
-  it "self_and_descendents" do\r
-    parent = categories(:top_level)\r
-    self_and_descendants = [parent, categories(:child_1), categories(:child_2),\r
-      categories(:child_2_1), categories(:child_3)]\r
-    self_and_descendants.should == parent.self_and_descendants\r
-    self_and_descendants.count.should == parent.self_and_descendants.count\r
-  end\r
-\r
-  it "descendents" do\r
-    lawyers = Category.create!(:name => "lawyers")\r
-    us = Category.create!(:name => "United States")\r
-    us.move_to_child_of(lawyers)\r
-    patent = Category.create!(:name => "Patent Law")\r
-    patent.move_to_child_of(us)\r
-    lawyers.reload\r
-\r
-    lawyers.children.size.should == 1\r
-    us.children.size.should == 1\r
-    lawyers.descendants.size.should == 2\r
-  end\r
-\r
-  it "self_and_descendents" do\r
-    parent = categories(:top_level)\r
-    descendants = [categories(:child_1), categories(:child_2),\r
-      categories(:child_2_1), categories(:child_3)]\r
-    descendants.should == parent.descendants\r
-  end\r
-\r
-  it "children" do\r
-    category = categories(:top_level)\r
-    category.children.each {|c| category.id.should == c.parent_id }\r
-  end\r
-\r
-  it "order_of_children" do\r
-    categories(:child_2).move_left\r
-    categories(:child_2).should == categories(:top_level).children[0]\r
-    categories(:child_1).should == categories(:top_level).children[1]\r
-    categories(:child_3).should == categories(:top_level).children[2]\r
-  end\r
-\r
-  it "is_or_is_ancestor_of?" do\r
-    categories(:top_level).is_or_is_ancestor_of?(categories(:child_1)).should be_true\r
-    categories(:top_level).is_or_is_ancestor_of?(categories(:child_2_1)).should be_true\r
-    categories(:child_2).is_or_is_ancestor_of?(categories(:child_2_1)).should be_true\r
-    categories(:child_2_1).is_or_is_ancestor_of?(categories(:child_2)).should be_false\r
-    categories(:child_1).is_or_is_ancestor_of?(categories(:child_2)).should be_false\r
-    categories(:child_1).is_or_is_ancestor_of?(categories(:child_1)).should be_true\r
-  end\r
-\r
-  it "is_ancestor_of?" do\r
-    categories(:top_level).is_ancestor_of?(categories(:child_1)).should be_true\r
-    categories(:top_level).is_ancestor_of?(categories(:child_2_1)).should be_true\r
-    categories(:child_2).is_ancestor_of?(categories(:child_2_1)).should be_true\r
-    categories(:child_2_1).is_ancestor_of?(categories(:child_2)).should be_false\r
-    categories(:child_1).is_ancestor_of?(categories(:child_2)).should be_false\r
-    categories(:child_1).is_ancestor_of?(categories(:child_1)).should be_false\r
-  end\r
-\r
-  it "is_or_is_ancestor_of_with_scope" do\r
-    root = ScopedCategory.root\r
-    child = root.children.first\r
-    root.is_or_is_ancestor_of?(child).should be_true\r
-    child.update_attribute :organization_id, 'different'\r
-    root.is_or_is_ancestor_of?(child).should be_false\r
-  end\r
-\r
-  it "is_or_is_descendant_of?" do\r
-    categories(:child_1).is_or_is_descendant_of?(categories(:top_level)).should be_true\r
-    categories(:child_2_1).is_or_is_descendant_of?(categories(:top_level)).should be_true\r
-    categories(:child_2_1).is_or_is_descendant_of?(categories(:child_2)).should be_true\r
-    categories(:child_2).is_or_is_descendant_of?(categories(:child_2_1)).should be_false\r
-    categories(:child_2).is_or_is_descendant_of?(categories(:child_1)).should be_false\r
-    categories(:child_1).is_or_is_descendant_of?(categories(:child_1)).should be_true\r
-  end\r
-\r
-  it "is_descendant_of?" do\r
-    categories(:child_1).is_descendant_of?(categories(:top_level)).should be_true\r
-    categories(:child_2_1).is_descendant_of?(categories(:top_level)).should be_true\r
-    categories(:child_2_1).is_descendant_of?(categories(:child_2)).should be_true\r
-    categories(:child_2).is_descendant_of?(categories(:child_2_1)).should be_false\r
-    categories(:child_2).is_descendant_of?(categories(:child_1)).should be_false\r
-    categories(:child_1).is_descendant_of?(categories(:child_1)).should be_false\r
-  end\r
-\r
-  it "is_or_is_descendant_of_with_scope" do\r
-    root = ScopedCategory.root\r
-    child = root.children.first\r
-    child.is_or_is_descendant_of?(root).should be_true\r
-    child.update_attribute :organization_id, 'different'\r
-    child.is_or_is_descendant_of?(root).should be_false\r
-  end\r
-\r
-  it "same_scope?" do\r
-    root = ScopedCategory.root\r
-    child = root.children.first\r
-    child.same_scope?(root).should be_true\r
-    child.update_attribute :organization_id, 'different'\r
-    child.same_scope?(root).should be_false\r
-  end\r
-\r
-  it "left_sibling" do\r
-    categories(:child_1).should == categories(:child_2).left_sibling\r
-    categories(:child_2).should == categories(:child_3).left_sibling\r
-  end\r
-\r
-  it "left_sibling_of_root" do\r
-    categories(:top_level).left_sibling.should be_nil\r
-  end\r
-\r
-  it "left_sibling_without_siblings" do\r
-    categories(:child_2_1).left_sibling.should be_nil\r
-  end\r
-\r
-  it "left_sibling_of_leftmost_node" do\r
-    categories(:child_1).left_sibling.should be_nil\r
-  end\r
-\r
-  it "right_sibling" do\r
-    categories(:child_3).should == categories(:child_2).right_sibling\r
-    categories(:child_2).should == categories(:child_1).right_sibling\r
-  end\r
-\r
-  it "right_sibling_of_root" do\r
-    categories(:top_level_2).should == categories(:top_level).right_sibling\r
-    categories(:top_level_2).right_sibling.should be_nil\r
-  end\r
-\r
-  it "right_sibling_without_siblings" do\r
-    categories(:child_2_1).right_sibling.should be_nil\r
-  end\r
-\r
-  it "right_sibling_of_rightmost_node" do\r
-    categories(:child_3).right_sibling.should be_nil\r
-  end\r
-\r
-  it "move_left" do\r
-    categories(:child_2).move_left\r
-    categories(:child_2).left_sibling.should be_nil\r
-    categories(:child_1).should == categories(:child_2).right_sibling\r
-    Category.valid?.should be_true\r
-  end\r
-\r
-  it "move_right" do\r
-    categories(:child_2).move_right\r
-    categories(:child_2).right_sibling.should be_nil\r
-    categories(:child_3).should == categories(:child_2).left_sibling\r
-    Category.valid?.should be_true\r
-  end\r
-\r
-  it "move_to_left_of" do\r
-    categories(:child_3).move_to_left_of(categories(:child_1))\r
-    categories(:child_3).left_sibling.should be_nil\r
-    categories(:child_1).should == categories(:child_3).right_sibling\r
-    Category.valid?.should be_true\r
-  end\r
-\r
-  it "move_to_right_of" do\r
-    categories(:child_1).move_to_right_of(categories(:child_3))\r
-    categories(:child_1).right_sibling.should be_nil\r
-    categories(:child_3).should == categories(:child_1).left_sibling\r
-    Category.valid?.should be_true\r
-  end\r
-\r
-  it "move_to_root" do\r
-    categories(:child_2).move_to_root\r
-    categories(:child_2).parent.should be_nil\r
-    categories(:child_2).level.should == 0\r
-    categories(:child_2_1).level.should == 1\r
-    categories(:child_2).left.should == 1\r
-    categories(:child_2).right.should == 4\r
-    Category.valid?.should be_true\r
-  end\r
-\r
-  it "move_to_child_of" do\r
-    categories(:child_1).move_to_child_of(categories(:child_3))\r
-    categories(:child_3).id.should == categories(:child_1).parent_id\r
-    Category.valid?.should be_true\r
-  end\r
-\r
-  it "move_to_child_of_appends_to_end" do\r
-    child = Category.create! :name => 'New Child'\r
-    child.move_to_child_of categories(:top_level)\r
-    child.should == categories(:top_level).children.last\r
-  end\r
-\r
-  it "subtree_move_to_child_of" do\r
-    categories(:child_2).left.should == 4\r
-    categories(:child_2).right.should == 7\r
-\r
-    categories(:child_1).left.should == 2\r
-    categories(:child_1).right.should == 3\r
-\r
-    categories(:child_2).move_to_child_of(categories(:child_1))\r
-    Category.valid?.should be_true\r
-    categories(:child_1).id.should == categories(:child_2).parent_id\r
-\r
-    categories(:child_2).left.should == 3\r
-    categories(:child_2).right.should == 6\r
-    categories(:child_1).left.should == 2\r
-    categories(:child_1).right.should == 7\r
-  end\r
-\r
-  it "slightly_difficult_move_to_child_of" do\r
-    categories(:top_level_2).left.should == 11\r
-    categories(:top_level_2).right.should == 12\r
-\r
-    # create a new top-level node and move single-node top-level tree inside it.\r
-    new_top = Category.create(:name => 'New Top')\r
-    new_top.left.should == 13\r
-    new_top.right.should == 14\r
-\r
-    categories(:top_level_2).move_to_child_of(new_top)\r
-\r
-    Category.valid?.should be_true\r
-    new_top.id.should == categories(:top_level_2).parent_id\r
-\r
-    categories(:top_level_2).left.should == 12\r
-    categories(:top_level_2).right.should == 13\r
-    new_top.left.should == 11\r
-    new_top.right.should == 14\r
-  end\r
-\r
-  it "difficult_move_to_child_of" do\r
-    categories(:top_level).left.should == 1\r
-    categories(:top_level).right.should == 10\r
-    categories(:child_2_1).left.should == 5\r
-    categories(:child_2_1).right.should == 6\r
-\r
-    # create a new top-level node and move an entire top-level tree inside it.\r
-    new_top = Category.create(:name => 'New Top')\r
-    categories(:top_level).move_to_child_of(new_top)\r
-    categories(:child_2_1).reload\r
-    Category.valid?.should be_true\r
-    new_top.id.should == categories(:top_level).parent_id\r
-\r
-    categories(:top_level).left.should == 4\r
-    categories(:top_level).right.should == 13\r
-    categories(:child_2_1).left.should == 8\r
-    categories(:child_2_1).right.should == 9\r
-  end\r
-\r
-  #rebuild swaps the position of the 2 children when added using move_to_child twice onto same parent\r
-  it "move_to_child_more_than_once_per_parent_rebuild" do\r
-    root1 = Category.create(:name => 'Root1')\r
-    root2 = Category.create(:name => 'Root2')\r
-    root3 = Category.create(:name => 'Root3')\r
-\r
-    root2.move_to_child_of root1\r
-    root3.move_to_child_of root1\r
-\r
-    output = Category.roots.last.to_text\r
-    Category.update_all('lft = null, rgt = null')\r
-    Category.rebuild!\r
-\r
-    Category.roots.last.to_text.should == output\r
-  end\r
-\r
-  # doing move_to_child twice onto same parent from the furthest right first\r
-  it "move_to_child_more_than_once_per_parent_outside_in" do\r
-    node1 = Category.create(:name => 'Node-1')\r
-    node2 = Category.create(:name => 'Node-2')\r
-    node3 = Category.create(:name => 'Node-3')\r
-\r
-    node2.move_to_child_of node1\r
-    node3.move_to_child_of node1\r
-\r
-    output = Category.roots.last.to_text\r
-    Category.update_all('lft = null, rgt = null')\r
-    Category.rebuild!\r
-\r
-    Category.roots.last.to_text.should == output\r
-  end\r
-\r
-  it "should be able to rebuild without validating each record" do\r
-    root1 = Category.create(:name => 'Root1')\r
-    root2 = Category.create(:name => 'Root2')\r
-    root3 = Category.create(:name => 'Root3')\r
-\r
-    root2.move_to_child_of root1\r
-    root3.move_to_child_of root1\r
-\r
-    root2.name = nil\r
-    root2.save!(:validate => false)\r
-\r
-    output = Category.roots.last.to_text\r
-    Category.update_all('lft = null, rgt = null')\r
-    Category.rebuild!(false)\r
-\r
-    Category.roots.last.to_text.should == output\r
-  end\r
-\r
-  it "valid_with_null_lefts" do\r
-    Category.valid?.should be_true\r
-    Category.update_all('lft = null')\r
-    Category.valid?.should be_false\r
-  end\r
-\r
-  it "valid_with_null_rights" do\r
-    Category.valid?.should be_true\r
-    Category.update_all('rgt = null')\r
-    Category.valid?.should be_false\r
-  end\r
-\r
-  it "valid_with_missing_intermediate_node" do\r
-    # Even though child_2_1 will still exist, it is a sign of a sloppy delete, not an invalid tree.\r
-    Category.valid?.should be_true\r
-    Category.delete(categories(:child_2).id)\r
-    Category.valid?.should be_true\r
-  end\r
-\r
-  it "valid_with_overlapping_and_rights" do\r
-    Category.valid?.should be_true\r
-    categories(:top_level_2)['lft'] = 0\r
-    categories(:top_level_2).save\r
-    Category.valid?.should be_false\r
-  end\r
-\r
-  it "rebuild" do\r
-    Category.valid?.should be_true\r
-    before_text = Category.root.to_text\r
-    Category.update_all('lft = null, rgt = null')\r
-    Category.rebuild!\r
-    Category.valid?.should be_true\r
-    before_text.should == Category.root.to_text\r
-  end\r
-\r
-  it "move_possible_for_sibling" do\r
-    categories(:child_2).move_possible?(categories(:child_1)).should be_true\r
-  end\r
-\r
-  it "move_not_possible_to_self" do\r
-    categories(:top_level).move_possible?(categories(:top_level)).should be_false\r
-  end\r
-\r
-  it "move_not_possible_to_parent" do\r
-    categories(:top_level).descendants.each do |descendant|\r
-      categories(:top_level).move_possible?(descendant).should be_false\r
-      descendant.move_possible?(categories(:top_level)).should be_true\r
-    end\r
-  end\r
-\r
-  it "is_or_is_ancestor_of?" do\r
-    [:child_1, :child_2, :child_2_1, :child_3].each do |c|\r
-      categories(:top_level).is_or_is_ancestor_of?(categories(c)).should be_true\r
-    end\r
-    categories(:top_level).is_or_is_ancestor_of?(categories(:top_level_2)).should be_false\r
-  end\r
-\r
-  it "left_and_rights_valid_with_blank_left" do\r
-    Category.left_and_rights_valid?.should be_true\r
-    categories(:child_2)[:lft] = nil\r
-    categories(:child_2).save(:validate => false)\r
-    Category.left_and_rights_valid?.should be_false\r
-  end\r
-\r
-  it "left_and_rights_valid_with_blank_right" do\r
-    Category.left_and_rights_valid?.should be_true\r
-    categories(:child_2)[:rgt] = nil\r
-    categories(:child_2).save(:validate => false)\r
-    Category.left_and_rights_valid?.should be_false\r
-  end\r
-\r
-  it "left_and_rights_valid_with_equal" do\r
-    Category.left_and_rights_valid?.should be_true\r
-    categories(:top_level_2)[:lft] = categories(:top_level_2)[:rgt]\r
-    categories(:top_level_2).save(:validate => false)\r
-    Category.left_and_rights_valid?.should be_false\r
-  end\r
-\r
-  it "left_and_rights_valid_with_left_equal_to_parent" do\r
-    Category.left_and_rights_valid?.should be_true\r
-    categories(:child_2)[:lft] = categories(:top_level)[:lft]\r
-    categories(:child_2).save(:validate => false)\r
-    Category.left_and_rights_valid?.should be_false\r
-  end\r
-\r
-  it "left_and_rights_valid_with_right_equal_to_parent" do\r
-    Category.left_and_rights_valid?.should be_true\r
-    categories(:child_2)[:rgt] = categories(:top_level)[:rgt]\r
-    categories(:child_2).save(:validate => false)\r
-    Category.left_and_rights_valid?.should be_false\r
-  end\r
-\r
-  it "moving_dirty_objects_doesnt_invalidate_tree" do\r
-    r1 = Category.create :name => "Test 1"\r
-    r2 = Category.create :name => "Test 2"\r
-    r3 = Category.create :name => "Test 3"\r
-    r4 = Category.create :name => "Test 4"\r
-    nodes = [r1, r2, r3, r4]\r
-\r
-    r2.move_to_child_of(r1)\r
-    Category.valid?.should be_true\r
-\r
-    r3.move_to_child_of(r1)\r
-    Category.valid?.should be_true\r
-\r
-    r4.move_to_child_of(r2)\r
-    Category.valid?.should be_true\r
-  end\r
-\r
-  it "multi_scoped_no_duplicates_for_columns?" do\r
-    lambda {\r
-      Note.no_duplicates_for_columns?\r
-    }.should_not raise_exception\r
-  end\r
-\r
-  it "multi_scoped_all_roots_valid?" do\r
-    lambda {\r
-      Note.all_roots_valid?\r
-    }.should_not raise_exception\r
-  end\r
-\r
-  it "multi_scoped" do\r
-    note1 = Note.create!(:body => "A", :notable_id => 2, :notable_type => 'Category')\r
-    note2 = Note.create!(:body => "B", :notable_id => 2, :notable_type => 'Category')\r
-    note3 = Note.create!(:body => "C", :notable_id => 2, :notable_type => 'Default')\r
-\r
-    [note1, note2].should == note1.self_and_siblings\r
-    [note3].should == note3.self_and_siblings\r
-  end\r
-\r
-  it "multi_scoped_rebuild" do\r
-    root = Note.create!(:body => "A", :notable_id => 3, :notable_type => 'Category')\r
-    child1 = Note.create!(:body => "B", :notable_id => 3, :notable_type => 'Category')\r
-    child2 = Note.create!(:body => "C", :notable_id => 3, :notable_type => 'Category')\r
-\r
-    child1.move_to_child_of root\r
-    child2.move_to_child_of root\r
-\r
-    Note.update_all('lft = null, rgt = null')\r
-    Note.rebuild!\r
-\r
-    Note.roots.find_by_body('A').should == root\r
-    [child1, child2].should == Note.roots.find_by_body('A').children\r
-  end\r
-\r
-  it "same_scope_with_multi_scopes" do\r
-    lambda {\r
-      notes(:scope1).same_scope?(notes(:child_1))\r
-    }.should_not raise_exception\r
-    notes(:scope1).same_scope?(notes(:child_1)).should be_true\r
-    notes(:child_1).same_scope?(notes(:scope1)).should be_true\r
-    notes(:scope1).same_scope?(notes(:scope2)).should be_false\r
-  end\r
-\r
-  it "quoting_of_multi_scope_column_names" do\r
-    ["\"notable_id\"", "\"notable_type\""].should == Note.quoted_scope_column_names\r
-  end\r
-\r
-  it "equal_in_same_scope" do\r
-    notes(:scope1).should == notes(:scope1)\r
-    notes(:scope1).should_not == notes(:child_1)\r
-  end\r
-\r
-  it "equal_in_different_scopes" do\r
-    notes(:scope1).should_not == notes(:scope2)\r
-  end\r
-\r
-  it "delete_does_not_invalidate" do\r
-    Category.acts_as_nested_set_options[:dependent] = :delete\r
-    categories(:child_2).destroy\r
-    Category.valid?.should be_true\r
-  end\r
-\r
-  it "destroy_does_not_invalidate" do\r
-    Category.acts_as_nested_set_options[:dependent] = :destroy\r
-    categories(:child_2).destroy\r
-    Category.valid?.should be_true\r
-  end\r
-\r
-  it "destroy_multiple_times_does_not_invalidate" do\r
-    Category.acts_as_nested_set_options[:dependent] = :destroy\r
-    categories(:child_2).destroy\r
-    categories(:child_2).destroy\r
-    Category.valid?.should be_true\r
-  end\r
-\r
-  it "assigning_parent_id_on_create" do\r
-    category = Category.create!(:name => "Child", :parent_id => categories(:child_2).id)\r
-    categories(:child_2).should == category.parent\r
-    categories(:child_2).id.should == category.parent_id\r
-    category.left.should_not be_nil\r
-    category.right.should_not be_nil\r
-    Category.valid?.should be_true\r
-  end\r
-\r
-  it "assigning_parent_on_create" do\r
-    category = Category.create!(:name => "Child", :parent => categories(:child_2))\r
-    categories(:child_2).should == category.parent\r
-    categories(:child_2).id.should == category.parent_id\r
-    category.left.should_not be_nil\r
-    category.right.should_not be_nil\r
-    Category.valid?.should be_true\r
-  end\r
-\r
-  it "assigning_parent_id_to_nil_on_create" do\r
-    category = Category.create!(:name => "New Root", :parent_id => nil)\r
-    category.parent.should be_nil\r
-    category.parent_id.should be_nil\r
-    category.left.should_not be_nil\r
-    category.right.should_not be_nil\r
-    Category.valid?.should be_true\r
-  end\r
-\r
-  it "assigning_parent_id_on_update" do\r
-    category = categories(:child_2_1)\r
-    category.parent_id = categories(:child_3).id\r
-    category.save\r
-    category.reload\r
-    categories(:child_3).reload\r
-    categories(:child_3).should == category.parent\r
-    categories(:child_3).id.should == category.parent_id\r
-    Category.valid?.should be_true\r
-  end\r
-\r
-  it "assigning_parent_on_update" do\r
-    category = categories(:child_2_1)\r
-    category.parent = categories(:child_3)\r
-    category.save\r
-    category.reload\r
-    categories(:child_3).reload\r
-    categories(:child_3).should == category.parent\r
-    categories(:child_3).id.should ==  category.parent_id\r
-    Category.valid?.should be_true\r
-  end\r
-\r
-  it "assigning_parent_id_to_nil_on_update" do\r
-    category = categories(:child_2_1)\r
-    category.parent_id = nil\r
-    category.save\r
-    category.parent.should be_nil\r
-    category.parent_id.should be_nil\r
-    Category.valid?.should be_true\r
-  end\r
-\r
-  it "creating_child_from_parent" do\r
-    category = categories(:child_2).children.create!(:name => "Child")\r
-    categories(:child_2).should == category.parent\r
-    categories(:child_2).id.should == category.parent_id\r
-    category.left.should_not be_nil\r
-    category.right.should_not be_nil\r
-    Category.valid?.should be_true\r
-  end\r
-\r
-  def check_structure(entries, structure)\r
-    structure = structure.dup\r
-    Category.each_with_level(entries) do |category, level|\r
-      expected_level, expected_name = structure.shift\r
-      expected_name.should == category.name\r
-      expected_level.should == level\r
-    end\r
-  end\r
-\r
-  it "each_with_level" do\r
-    levels = [\r
-      [0, "Top Level"],\r
-      [1, "Child 1"],\r
-      [1, "Child 2"],\r
-      [2, "Child 2.1"],\r
-      [1, "Child 3" ]]\r
-\r
-    check_structure(Category.root.self_and_descendants, levels)\r
-\r
-    # test some deeper structures\r
-    category = Category.find_by_name("Child 1")\r
-    c1 = Category.new(:name => "Child 1.1")\r
-    c2 = Category.new(:name => "Child 1.1.1")\r
-    c3 = Category.new(:name => "Child 1.1.1.1")\r
-    c4 = Category.new(:name => "Child 1.2")\r
-    [c1, c2, c3, c4].each(&:save!)\r
-\r
-    c1.move_to_child_of(category)\r
-    c2.move_to_child_of(c1)\r
-    c3.move_to_child_of(c2)\r
-    c4.move_to_child_of(category)\r
-\r
-    levels = [\r
-      [0, "Top Level"],\r
-      [1, "Child 1"],\r
-      [2, "Child 1.1"],\r
-      [3, "Child 1.1.1"],\r
-      [4, "Child 1.1.1.1"],\r
-      [2, "Child 1.2"],\r
-      [1, "Child 2"],\r
-      [2, "Child 2.1"],\r
-      [1, "Child 3" ]]\r
-\r
-      check_structure(Category.root.self_and_descendants, levels)\r
-  end\r
-\r
-  it "should not error on a model with attr_accessible" do\r
-    model = Class.new(ActiveRecord::Base)\r
-    model.table_name = 'categories'\r
-    model.attr_accessible :name\r
-    lambda {\r
-      model.acts_as_nested_set\r
-      model.new(:name => 'foo')\r
-    }.should_not raise_exception\r
-  end\r
-\r
-  describe "before_move_callback" do\r
-    it "should fire the callback" do\r
-      categories(:child_2).should_receive(:custom_before_move)\r
-      categories(:child_2).move_to_root\r
-    end\r
-\r
-    it "should stop move when callback returns false" do\r
-      Category.test_allows_move = false\r
-      categories(:child_3).move_to_root.should be_false\r
-      categories(:child_3).root?.should be_false\r
-    end\r
-\r
-    it "should not halt save actions" do\r
-      Category.test_allows_move = false\r
-      categories(:child_3).parent_id = nil\r
-      categories(:child_3).save.should be_true\r
-    end\r
-  end\r
-\r
-  describe "counter_cache" do\r
-\r
-    it "should allow use of a counter cache for children" do\r
-      note1 = things(:parent1)\r
-      note1.children.count.should == 2\r
-    end\r
-\r
-    it "should increment the counter cache on create" do\r
-      note1 = things(:parent1)\r
-      note1.children.count.should == 2\r
-      note1[:children_count].should == 2\r
-      note1.children.create :body => 'Child 3'\r
-      note1.children.count.should == 3\r
-      note1.reload\r
-      note1[:children_count].should == 3\r
-    end\r
-\r
-    it "should decrement the counter cache on destroy" do\r
-      note1 = things(:parent1)\r
-      note1.children.count.should == 2\r
-      note1[:children_count].should == 2\r
-      note1.children.last.destroy\r
-      note1.children.count.should == 1\r
-      note1.reload\r
-      note1[:children_count].should == 1\r
-    end\r
-  end\r
-\r
-  describe "association callbacks on children" do\r
-    it "should call the appropriate callbacks on the children :has_many association " do\r
-      root = DefaultWithCallbacks.create\r
-      root.should_not be_new_record\r
-\r
-      child = root.children.build\r
-\r
-      root.before_add.should == child\r
-      root.after_add.should  == child\r
-\r
-      root.before_remove.should_not == child\r
-      root.after_remove.should_not  == child\r
-\r
-      child.save.should be_true\r
-      root.children.delete(child).should be_true\r
-\r
-      root.before_remove.should == child\r
-      root.after_remove.should  == child\r
-    end\r
-  end\r
-end\r
+require 'spec_helper'
+
+describe "AwesomeNestedSet" do
+  before(:all) do
+    self.class.fixtures :categories, :departments, :notes, :things, :brokens
+  end
+
+  describe "defaults" do
+    it "should have left_column_default" do
+      Default.acts_as_nested_set_options[:left_column].should == 'lft'
+    end
+
+    it "should have right_column_default" do
+      Default.acts_as_nested_set_options[:right_column].should == 'rgt'
+    end
+
+    it "should have parent_column_default" do
+      Default.acts_as_nested_set_options[:parent_column].should == 'parent_id'
+    end
+
+    it "should have scope_default" do
+      Default.acts_as_nested_set_options[:scope].should be_nil
+    end
+
+    it "should have left_column_name" do
+      Default.left_column_name.should == 'lft'
+      Default.new.left_column_name.should == 'lft'
+      RenamedColumns.left_column_name.should == 'red'
+      RenamedColumns.new.left_column_name.should == 'red'
+    end
+
+    it "should have right_column_name" do
+      Default.right_column_name.should == 'rgt'
+      Default.new.right_column_name.should == 'rgt'
+      RenamedColumns.right_column_name.should == 'black'
+      RenamedColumns.new.right_column_name.should == 'black'
+    end
+
+    it "should have parent_column_name" do
+      Default.parent_column_name.should == 'parent_id'
+      Default.new.parent_column_name.should == 'parent_id'
+      RenamedColumns.parent_column_name.should == 'mother_id'
+      RenamedColumns.new.parent_column_name.should == 'mother_id'
+    end
+  end
+
+  it "creation_with_altered_column_names" do
+    lambda {
+      RenamedColumns.create!()
+    }.should_not raise_exception
+  end
+
+  it "creation when existing record has nil left column" do
+    assert_nothing_raised do
+      Broken.create!
+    end
+  end
+  
+  it "quoted_left_column_name" do
+    quoted = Default.connection.quote_column_name('lft')
+    Default.quoted_left_column_name.should == quoted
+    Default.new.quoted_left_column_name.should == quoted
+  end
+
+  it "quoted_right_column_name" do
+    quoted = Default.connection.quote_column_name('rgt')
+    Default.quoted_right_column_name.should == quoted
+    Default.new.quoted_right_column_name.should == quoted
+  end
+
+  it "left_column_protected_from_assignment" do
+    lambda {
+      Category.new.lft = 1
+    }.should raise_exception(ActiveRecord::ActiveRecordError)
+  end
+
+  it "right_column_protected_from_assignment" do
+    lambda {
+      Category.new.rgt = 1
+    }.should raise_exception(ActiveRecord::ActiveRecordError)
+  end
+
+  it "scoped_appends_id" do
+    ScopedCategory.acts_as_nested_set_options[:scope].should == :organization_id
+  end
+
+  it "roots_class_method" do
+    Category.roots.should == Category.find_all_by_parent_id(nil)
+  end
+
+  it "root_class_method" do
+    Category.root.should == categories(:top_level)
+  end
+
+  it "root" do
+    categories(:child_3).root.should == categories(:top_level)
+  end
+
+  it "root?" do
+    categories(:top_level).root?.should be_true
+    categories(:top_level_2).root?.should be_true
+  end
+
+  it "leaves_class_method" do
+    Category.find(:all, :conditions => "#{Category.right_column_name} - #{Category.left_column_name} = 1").should == Category.leaves
+    Category.leaves.count.should == 4
+    Category.leaves.should include(categories(:child_1))
+    Category.leaves.should include(categories(:child_2_1))
+    Category.leaves.should include(categories(:child_3))
+    Category.leaves.should include(categories(:top_level_2))
+  end
+
+  it "leaf" do
+    categories(:child_1).leaf?.should be_true
+    categories(:child_2_1).leaf?.should be_true
+    categories(:child_3).leaf?.should be_true
+    categories(:top_level_2).leaf?.should be_true
+
+    categories(:top_level).leaf?.should be_false
+    categories(:child_2).leaf?.should be_false
+    Category.new.leaf?.should be_false
+  end
+
+
+  it "parent" do
+    categories(:child_2_1).parent.should == categories(:child_2)
+  end
+
+  it "self_and_ancestors" do
+    child = categories(:child_2_1)
+    self_and_ancestors = [categories(:top_level), categories(:child_2), child]
+    self_and_ancestors.should == child.self_and_ancestors
+  end
+
+  it "ancestors" do
+    child = categories(:child_2_1)
+    ancestors = [categories(:top_level), categories(:child_2)]
+    ancestors.should == child.ancestors
+  end
+
+  it "self_and_siblings" do
+    child = categories(:child_2)
+    self_and_siblings = [categories(:child_1), child, categories(:child_3)]
+    self_and_siblings.should == child.self_and_siblings
+    lambda do
+      tops = [categories(:top_level), categories(:top_level_2)]
+      assert_equal tops, categories(:top_level).self_and_siblings
+    end.should_not raise_exception
+  end
+
+  it "siblings" do
+    child = categories(:child_2)
+    siblings = [categories(:child_1), categories(:child_3)]
+    siblings.should == child.siblings
+  end
+
+  it "leaves" do
+    leaves = [categories(:child_1), categories(:child_2_1), categories(:child_3)]
+    categories(:top_level).leaves.should == leaves
+  end
+
+  it "level" do
+    categories(:top_level).level.should == 0
+    categories(:child_1).level.should == 1
+    categories(:child_2_1).level.should == 2
+  end
+
+  it "has_children?" do
+    categories(:child_2_1).children.empty?.should be_true
+    categories(:child_2).children.empty?.should be_false
+    categories(:top_level).children.empty?.should be_false
+  end
+
+  it "self_and_descendents" do
+    parent = categories(:top_level)
+    self_and_descendants = [parent, categories(:child_1), categories(:child_2),
+      categories(:child_2_1), categories(:child_3)]
+    self_and_descendants.should == parent.self_and_descendants
+    self_and_descendants.count.should == parent.self_and_descendants.count
+  end
+
+  it "descendents" do
+    lawyers = Category.create!(:name => "lawyers")
+    us = Category.create!(:name => "United States")
+    us.move_to_child_of(lawyers)
+    patent = Category.create!(:name => "Patent Law")
+    patent.move_to_child_of(us)
+    lawyers.reload
+
+    lawyers.children.size.should == 1
+    us.children.size.should == 1
+    lawyers.descendants.size.should == 2
+  end
+
+  it "self_and_descendents" do
+    parent = categories(:top_level)
+    descendants = [categories(:child_1), categories(:child_2),
+      categories(:child_2_1), categories(:child_3)]
+    descendants.should == parent.descendants
+  end
+
+  it "children" do
+    category = categories(:top_level)
+    category.children.each {|c| category.id.should == c.parent_id }
+  end
+
+  it "order_of_children" do
+    categories(:child_2).move_left
+    categories(:child_2).should == categories(:top_level).children[0]
+    categories(:child_1).should == categories(:top_level).children[1]
+    categories(:child_3).should == categories(:top_level).children[2]
+  end
+
+  it "is_or_is_ancestor_of?" do
+    categories(:top_level).is_or_is_ancestor_of?(categories(:child_1)).should be_true
+    categories(:top_level).is_or_is_ancestor_of?(categories(:child_2_1)).should be_true
+    categories(:child_2).is_or_is_ancestor_of?(categories(:child_2_1)).should be_true
+    categories(:child_2_1).is_or_is_ancestor_of?(categories(:child_2)).should be_false
+    categories(:child_1).is_or_is_ancestor_of?(categories(:child_2)).should be_false
+    categories(:child_1).is_or_is_ancestor_of?(categories(:child_1)).should be_true
+  end
+
+  it "is_ancestor_of?" do
+    categories(:top_level).is_ancestor_of?(categories(:child_1)).should be_true
+    categories(:top_level).is_ancestor_of?(categories(:child_2_1)).should be_true
+    categories(:child_2).is_ancestor_of?(categories(:child_2_1)).should be_true
+    categories(:child_2_1).is_ancestor_of?(categories(:child_2)).should be_false
+    categories(:child_1).is_ancestor_of?(categories(:child_2)).should be_false
+    categories(:child_1).is_ancestor_of?(categories(:child_1)).should be_false
+  end
+
+  it "is_or_is_ancestor_of_with_scope" do
+    root = ScopedCategory.root
+    child = root.children.first
+    root.is_or_is_ancestor_of?(child).should be_true
+    child.update_attribute :organization_id, 'different'
+    root.is_or_is_ancestor_of?(child).should be_false
+  end
+
+  it "is_or_is_descendant_of?" do
+    categories(:child_1).is_or_is_descendant_of?(categories(:top_level)).should be_true
+    categories(:child_2_1).is_or_is_descendant_of?(categories(:top_level)).should be_true
+    categories(:child_2_1).is_or_is_descendant_of?(categories(:child_2)).should be_true
+    categories(:child_2).is_or_is_descendant_of?(categories(:child_2_1)).should be_false
+    categories(:child_2).is_or_is_descendant_of?(categories(:child_1)).should be_false
+    categories(:child_1).is_or_is_descendant_of?(categories(:child_1)).should be_true
+  end
+
+  it "is_descendant_of?" do
+    categories(:child_1).is_descendant_of?(categories(:top_level)).should be_true
+    categories(:child_2_1).is_descendant_of?(categories(:top_level)).should be_true
+    categories(:child_2_1).is_descendant_of?(categories(:child_2)).should be_true
+    categories(:child_2).is_descendant_of?(categories(:child_2_1)).should be_false
+    categories(:child_2).is_descendant_of?(categories(:child_1)).should be_false
+    categories(:child_1).is_descendant_of?(categories(:child_1)).should be_false
+  end
+
+  it "is_or_is_descendant_of_with_scope" do
+    root = ScopedCategory.root
+    child = root.children.first
+    child.is_or_is_descendant_of?(root).should be_true
+    child.update_attribute :organization_id, 'different'
+    child.is_or_is_descendant_of?(root).should be_false
+  end
+
+  it "same_scope?" do
+    root = ScopedCategory.root
+    child = root.children.first
+    child.same_scope?(root).should be_true
+    child.update_attribute :organization_id, 'different'
+    child.same_scope?(root).should be_false
+  end
+
+  it "left_sibling" do
+    categories(:child_1).should == categories(:child_2).left_sibling
+    categories(:child_2).should == categories(:child_3).left_sibling
+  end
+
+  it "left_sibling_of_root" do
+    categories(:top_level).left_sibling.should be_nil
+  end
+
+  it "left_sibling_without_siblings" do
+    categories(:child_2_1).left_sibling.should be_nil
+  end
+
+  it "left_sibling_of_leftmost_node" do
+    categories(:child_1).left_sibling.should be_nil
+  end
+
+  it "right_sibling" do
+    categories(:child_3).should == categories(:child_2).right_sibling
+    categories(:child_2).should == categories(:child_1).right_sibling
+  end
+
+  it "right_sibling_of_root" do
+    categories(:top_level_2).should == categories(:top_level).right_sibling
+    categories(:top_level_2).right_sibling.should be_nil
+  end
+
+  it "right_sibling_without_siblings" do
+    categories(:child_2_1).right_sibling.should be_nil
+  end
+
+  it "right_sibling_of_rightmost_node" do
+    categories(:child_3).right_sibling.should be_nil
+  end
+
+  it "move_left" do
+    categories(:child_2).move_left
+    categories(:child_2).left_sibling.should be_nil
+    categories(:child_1).should == categories(:child_2).right_sibling
+    Category.valid?.should be_true
+  end
+
+  it "move_right" do
+    categories(:child_2).move_right
+    categories(:child_2).right_sibling.should be_nil
+    categories(:child_3).should == categories(:child_2).left_sibling
+    Category.valid?.should be_true
+  end
+
+  it "move_to_left_of" do
+    categories(:child_3).move_to_left_of(categories(:child_1))
+    categories(:child_3).left_sibling.should be_nil
+    categories(:child_1).should == categories(:child_3).right_sibling
+    Category.valid?.should be_true
+  end
+
+  it "move_to_right_of" do
+    categories(:child_1).move_to_right_of(categories(:child_3))
+    categories(:child_1).right_sibling.should be_nil
+    categories(:child_3).should == categories(:child_1).left_sibling
+    Category.valid?.should be_true
+  end
+
+  it "move_to_root" do
+    categories(:child_2).move_to_root
+    categories(:child_2).parent.should be_nil
+    categories(:child_2).level.should == 0
+    categories(:child_2_1).level.should == 1
+    categories(:child_2).left.should == 1
+    categories(:child_2).right.should == 4
+    Category.valid?.should be_true
+  end
+
+  it "move_to_child_of" do
+    categories(:child_1).move_to_child_of(categories(:child_3))
+    categories(:child_3).id.should == categories(:child_1).parent_id
+    Category.valid?.should be_true
+  end
+
+  it "move_to_child_of_appends_to_end" do
+    child = Category.create! :name => 'New Child'
+    child.move_to_child_of categories(:top_level)
+    child.should == categories(:top_level).children.last
+  end
+
+  it "subtree_move_to_child_of" do
+    categories(:child_2).left.should == 4
+    categories(:child_2).right.should == 7
+
+    categories(:child_1).left.should == 2
+    categories(:child_1).right.should == 3
+
+    categories(:child_2).move_to_child_of(categories(:child_1))
+    Category.valid?.should be_true
+    categories(:child_1).id.should == categories(:child_2).parent_id
+
+    categories(:child_2).left.should == 3
+    categories(:child_2).right.should == 6
+    categories(:child_1).left.should == 2
+    categories(:child_1).right.should == 7
+  end
+
+  it "slightly_difficult_move_to_child_of" do
+    categories(:top_level_2).left.should == 11
+    categories(:top_level_2).right.should == 12
+
+    # create a new top-level node and move single-node top-level tree inside it.
+    new_top = Category.create(:name => 'New Top')
+    new_top.left.should == 13
+    new_top.right.should == 14
+
+    categories(:top_level_2).move_to_child_of(new_top)
+
+    Category.valid?.should be_true
+    new_top.id.should == categories(:top_level_2).parent_id
+
+    categories(:top_level_2).left.should == 12
+    categories(:top_level_2).right.should == 13
+    new_top.left.should == 11
+    new_top.right.should == 14
+  end
+
+  it "difficult_move_to_child_of" do
+    categories(:top_level).left.should == 1
+    categories(:top_level).right.should == 10
+    categories(:child_2_1).left.should == 5
+    categories(:child_2_1).right.should == 6
+
+    # create a new top-level node and move an entire top-level tree inside it.
+    new_top = Category.create(:name => 'New Top')
+    categories(:top_level).move_to_child_of(new_top)
+    categories(:child_2_1).reload
+    Category.valid?.should be_true
+    new_top.id.should == categories(:top_level).parent_id
+
+    categories(:top_level).left.should == 4
+    categories(:top_level).right.should == 13
+    categories(:child_2_1).left.should == 8
+    categories(:child_2_1).right.should == 9
+  end
+
+  #rebuild swaps the position of the 2 children when added using move_to_child twice onto same parent
+  it "move_to_child_more_than_once_per_parent_rebuild" do
+    root1 = Category.create(:name => 'Root1')
+    root2 = Category.create(:name => 'Root2')
+    root3 = Category.create(:name => 'Root3')
+
+    root2.move_to_child_of root1
+    root3.move_to_child_of root1
+
+    output = Category.roots.last.to_text
+    Category.update_all('lft = null, rgt = null')
+    Category.rebuild!
+
+    Category.roots.last.to_text.should == output
+  end
+
+  # doing move_to_child twice onto same parent from the furthest right first
+  it "move_to_child_more_than_once_per_parent_outside_in" do
+    node1 = Category.create(:name => 'Node-1')
+    node2 = Category.create(:name => 'Node-2')
+    node3 = Category.create(:name => 'Node-3')
+
+    node2.move_to_child_of node1
+    node3.move_to_child_of node1
+
+    output = Category.roots.last.to_text
+    Category.update_all('lft = null, rgt = null')
+    Category.rebuild!
+
+    Category.roots.last.to_text.should == output
+  end
+
+  it "should be able to rebuild without validating each record" do
+    root1 = Category.create(:name => 'Root1')
+    root2 = Category.create(:name => 'Root2')
+    root3 = Category.create(:name => 'Root3')
+
+    root2.move_to_child_of root1
+    root3.move_to_child_of root1
+
+    root2.name = nil
+    root2.save!(:validate => false)
+
+    output = Category.roots.last.to_text
+    Category.update_all('lft = null, rgt = null')
+    Category.rebuild!(false)
+
+    Category.roots.last.to_text.should == output
+  end
+
+  it "valid_with_null_lefts" do
+    Category.valid?.should be_true
+    Category.update_all('lft = null')
+    Category.valid?.should be_false
+  end
+
+  it "valid_with_null_rights" do
+    Category.valid?.should be_true
+    Category.update_all('rgt = null')
+    Category.valid?.should be_false
+  end
+
+  it "valid_with_missing_intermediate_node" do
+    # Even though child_2_1 will still exist, it is a sign of a sloppy delete, not an invalid tree.
+    Category.valid?.should be_true
+    Category.delete(categories(:child_2).id)
+    Category.valid?.should be_true
+  end
+
+  it "valid_with_overlapping_and_rights" do
+    Category.valid?.should be_true
+    categories(:top_level_2)['lft'] = 0
+    categories(:top_level_2).save
+    Category.valid?.should be_false
+  end
+
+  it "rebuild" do
+    Category.valid?.should be_true
+    before_text = Category.root.to_text
+    Category.update_all('lft = null, rgt = null')
+    Category.rebuild!
+    Category.valid?.should be_true
+    before_text.should == Category.root.to_text
+  end
+
+  it "move_possible_for_sibling" do
+    categories(:child_2).move_possible?(categories(:child_1)).should be_true
+  end
+
+  it "move_not_possible_to_self" do
+    categories(:top_level).move_possible?(categories(:top_level)).should be_false
+  end
+
+  it "move_not_possible_to_parent" do
+    categories(:top_level).descendants.each do |descendant|
+      categories(:top_level).move_possible?(descendant).should be_false
+      descendant.move_possible?(categories(:top_level)).should be_true
+    end
+  end
+
+  it "is_or_is_ancestor_of?" do
+    [:child_1, :child_2, :child_2_1, :child_3].each do |c|
+      categories(:top_level).is_or_is_ancestor_of?(categories(c)).should be_true
+    end
+    categories(:top_level).is_or_is_ancestor_of?(categories(:top_level_2)).should be_false
+  end
+
+  it "left_and_rights_valid_with_blank_left" do
+    Category.left_and_rights_valid?.should be_true
+    categories(:child_2)[:lft] = nil
+    categories(:child_2).save(:validate => false)
+    Category.left_and_rights_valid?.should be_false
+  end
+
+  it "left_and_rights_valid_with_blank_right" do
+    Category.left_and_rights_valid?.should be_true
+    categories(:child_2)[:rgt] = nil
+    categories(:child_2).save(:validate => false)
+    Category.left_and_rights_valid?.should be_false
+  end
+
+  it "left_and_rights_valid_with_equal" do
+    Category.left_and_rights_valid?.should be_true
+    categories(:top_level_2)[:lft] = categories(:top_level_2)[:rgt]
+    categories(:top_level_2).save(:validate => false)
+    Category.left_and_rights_valid?.should be_false
+  end
+
+  it "left_and_rights_valid_with_left_equal_to_parent" do
+    Category.left_and_rights_valid?.should be_true
+    categories(:child_2)[:lft] = categories(:top_level)[:lft]
+    categories(:child_2).save(:validate => false)
+    Category.left_and_rights_valid?.should be_false
+  end
+
+  it "left_and_rights_valid_with_right_equal_to_parent" do
+    Category.left_and_rights_valid?.should be_true
+    categories(:child_2)[:rgt] = categories(:top_level)[:rgt]
+    categories(:child_2).save(:validate => false)
+    Category.left_and_rights_valid?.should be_false
+  end
+
+  it "moving_dirty_objects_doesnt_invalidate_tree" do
+    r1 = Category.create :name => "Test 1"
+    r2 = Category.create :name => "Test 2"
+    r3 = Category.create :name => "Test 3"
+    r4 = Category.create :name => "Test 4"
+    nodes = [r1, r2, r3, r4]
+
+    r2.move_to_child_of(r1)
+    Category.valid?.should be_true
+
+    r3.move_to_child_of(r1)
+    Category.valid?.should be_true
+
+    r4.move_to_child_of(r2)
+    Category.valid?.should be_true
+  end
+
+  it "multi_scoped_no_duplicates_for_columns?" do
+    lambda {
+      Note.no_duplicates_for_columns?
+    }.should_not raise_exception
+  end
+
+  it "multi_scoped_all_roots_valid?" do
+    lambda {
+      Note.all_roots_valid?
+    }.should_not raise_exception
+  end
+
+  it "multi_scoped" do
+    note1 = Note.create!(:body => "A", :notable_id => 2, :notable_type => 'Category')
+    note2 = Note.create!(:body => "B", :notable_id => 2, :notable_type => 'Category')
+    note3 = Note.create!(:body => "C", :notable_id => 2, :notable_type => 'Default')
+
+    [note1, note2].should == note1.self_and_siblings
+    [note3].should == note3.self_and_siblings
+  end
+
+  it "multi_scoped_rebuild" do
+    root = Note.create!(:body => "A", :notable_id => 3, :notable_type => 'Category')
+    child1 = Note.create!(:body => "B", :notable_id => 3, :notable_type => 'Category')
+    child2 = Note.create!(:body => "C", :notable_id => 3, :notable_type => 'Category')
+
+    child1.move_to_child_of root
+    child2.move_to_child_of root
+
+    Note.update_all('lft = null, rgt = null')
+    Note.rebuild!
+
+    Note.roots.find_by_body('A').should == root
+    [child1, child2].should == Note.roots.find_by_body('A').children
+  end
+
+  it "same_scope_with_multi_scopes" do
+    lambda {
+      notes(:scope1).same_scope?(notes(:child_1))
+    }.should_not raise_exception
+    notes(:scope1).same_scope?(notes(:child_1)).should be_true
+    notes(:child_1).same_scope?(notes(:scope1)).should be_true
+    notes(:scope1).same_scope?(notes(:scope2)).should be_false
+  end
+
+  it "quoting_of_multi_scope_column_names" do
+    ["\"notable_id\"", "\"notable_type\""].should == Note.quoted_scope_column_names
+  end
+
+  it "equal_in_same_scope" do
+    notes(:scope1).should == notes(:scope1)
+    notes(:scope1).should_not == notes(:child_1)
+  end
+
+  it "equal_in_different_scopes" do
+    notes(:scope1).should_not == notes(:scope2)
+  end
+
+  it "delete_does_not_invalidate" do
+    Category.acts_as_nested_set_options[:dependent] = :delete
+    categories(:child_2).destroy
+    Category.valid?.should be_true
+  end
+
+  it "destroy_does_not_invalidate" do
+    Category.acts_as_nested_set_options[:dependent] = :destroy
+    categories(:child_2).destroy
+    Category.valid?.should be_true
+  end
+
+  it "destroy_multiple_times_does_not_invalidate" do
+    Category.acts_as_nested_set_options[:dependent] = :destroy
+    categories(:child_2).destroy
+    categories(:child_2).destroy
+    Category.valid?.should be_true
+  end
+
+  it "assigning_parent_id_on_create" do
+    category = Category.create!(:name => "Child", :parent_id => categories(:child_2).id)
+    categories(:child_2).should == category.parent
+    categories(:child_2).id.should == category.parent_id
+    category.left.should_not be_nil
+    category.right.should_not be_nil
+    Category.valid?.should be_true
+  end
+
+  it "assigning_parent_on_create" do
+    category = Category.create!(:name => "Child", :parent => categories(:child_2))
+    categories(:child_2).should == category.parent
+    categories(:child_2).id.should == category.parent_id
+    category.left.should_not be_nil
+    category.right.should_not be_nil
+    Category.valid?.should be_true
+  end
+
+  it "assigning_parent_id_to_nil_on_create" do
+    category = Category.create!(:name => "New Root", :parent_id => nil)
+    category.parent.should be_nil
+    category.parent_id.should be_nil
+    category.left.should_not be_nil
+    category.right.should_not be_nil
+    Category.valid?.should be_true
+  end
+
+  it "assigning_parent_id_on_update" do
+    category = categories(:child_2_1)
+    category.parent_id = categories(:child_3).id
+    category.save
+    category.reload
+    categories(:child_3).reload
+    categories(:child_3).should == category.parent
+    categories(:child_3).id.should == category.parent_id
+    Category.valid?.should be_true
+  end
+
+  it "assigning_parent_on_update" do
+    category = categories(:child_2_1)
+    category.parent = categories(:child_3)
+    category.save
+    category.reload
+    categories(:child_3).reload
+    categories(:child_3).should == category.parent
+    categories(:child_3).id.should ==  category.parent_id
+    Category.valid?.should be_true
+  end
+
+  it "assigning_parent_id_to_nil_on_update" do
+    category = categories(:child_2_1)
+    category.parent_id = nil
+    category.save
+    category.parent.should be_nil
+    category.parent_id.should be_nil
+    Category.valid?.should be_true
+  end
+
+  it "creating_child_from_parent" do
+    category = categories(:child_2).children.create!(:name => "Child")
+    categories(:child_2).should == category.parent
+    categories(:child_2).id.should == category.parent_id
+    category.left.should_not be_nil
+    category.right.should_not be_nil
+    Category.valid?.should be_true
+  end
+
+  def check_structure(entries, structure)
+    structure = structure.dup
+    Category.each_with_level(entries) do |category, level|
+      expected_level, expected_name = structure.shift
+      expected_name.should == category.name
+      expected_level.should == level
+    end
+  end
+
+  it "each_with_level" do
+    levels = [
+      [0, "Top Level"],
+      [1, "Child 1"],
+      [1, "Child 2"],
+      [2, "Child 2.1"],
+      [1, "Child 3" ]]
+
+    check_structure(Category.root.self_and_descendants, levels)
+
+    # test some deeper structures
+    category = Category.find_by_name("Child 1")
+    c1 = Category.new(:name => "Child 1.1")
+    c2 = Category.new(:name => "Child 1.1.1")
+    c3 = Category.new(:name => "Child 1.1.1.1")
+    c4 = Category.new(:name => "Child 1.2")
+    [c1, c2, c3, c4].each(&:save!)
+
+    c1.move_to_child_of(category)
+    c2.move_to_child_of(c1)
+    c3.move_to_child_of(c2)
+    c4.move_to_child_of(category)
+
+    levels = [
+      [0, "Top Level"],
+      [1, "Child 1"],
+      [2, "Child 1.1"],
+      [3, "Child 1.1.1"],
+      [4, "Child 1.1.1.1"],
+      [2, "Child 1.2"],
+      [1, "Child 2"],
+      [2, "Child 2.1"],
+      [1, "Child 3" ]]
+
+      check_structure(Category.root.self_and_descendants, levels)
+  end
+
+  it "should not error on a model with attr_accessible" do
+    model = Class.new(ActiveRecord::Base)
+    model.table_name = 'categories'
+    model.attr_accessible :name
+    lambda {
+      model.acts_as_nested_set
+      model.new(:name => 'foo')
+    }.should_not raise_exception
+  end
+
+  describe "before_move_callback" do
+    it "should fire the callback" do
+      categories(:child_2).should_receive(:custom_before_move)
+      categories(:child_2).move_to_root
+    end
+
+    it "should stop move when callback returns false" do
+      Category.test_allows_move = false
+      categories(:child_3).move_to_root.should be_false
+      categories(:child_3).root?.should be_false
+    end
+
+    it "should not halt save actions" do
+      Category.test_allows_move = false
+      categories(:child_3).parent_id = nil
+      categories(:child_3).save.should be_true
+    end
+  end
+
+  describe "counter_cache" do
+
+    it "should allow use of a counter cache for children" do
+      note1 = things(:parent1)
+      note1.children.count.should == 2
+    end
+
+    it "should increment the counter cache on create" do
+      note1 = things(:parent1)
+      note1.children.count.should == 2
+      note1[:children_count].should == 2
+      note1.children.create :body => 'Child 3'
+      note1.children.count.should == 3
+      note1.reload
+      note1[:children_count].should == 3
+    end
+
+    it "should decrement the counter cache on destroy" do
+      note1 = things(:parent1)
+      note1.children.count.should == 2
+      note1[:children_count].should == 2
+      note1.children.last.destroy
+      note1.children.count.should == 1
+      note1.reload
+      note1[:children_count].should == 1
+    end
+  end
+
+  describe "association callbacks on children" do
+    it "should call the appropriate callbacks on the children :has_many association " do
+      root = DefaultWithCallbacks.create
+      root.should_not be_new_record
+
+      child = root.children.build
+
+      root.before_add.should == child
+      root.after_add.should  == child
+
+      root.before_remove.should_not == child
+      root.after_remove.should_not  == child
+
+      child.save.should be_true
+      root.children.delete(child).should be_true
+
+      root.before_remove.should == child
+      root.after_remove.should  == child
+    end
+  end
+end
index c8c0aeeac7277734c88baa98965d687d08c24772..eaa5ed3a0a07025e7af39ea2fe6680155d8137db 100644 (file)
@@ -1,18 +1,18 @@
-sqlite3:\r
-  adapter: <%= "jdbc" if defined? JRUBY_VERSION %>sqlite3\r
-  database: awesome_nested_set.sqlite3.db\r
-sqlite3mem:\r
-  adapter: <%= "jdbc" if defined? JRUBY_VERSION %>sqlite3\r
-  database: ":memory:"\r
-postgresql:\r
-  adapter: postgresql\r
-  username: postgres\r
-  password: postgres\r
-  database: awesome_nested_set_plugin_test\r
-  min_messages: ERROR\r
-mysql:\r
-  adapter: mysql2\r
-  host: localhost\r
-  username: root\r
-  password:\r
+sqlite3:
+  adapter: <%= "jdbc" if defined? JRUBY_VERSION %>sqlite3
+  database: awesome_nested_set.sqlite3.db
+sqlite3mem:
+  adapter: <%= "jdbc" if defined? JRUBY_VERSION %>sqlite3
+  database: ":memory:"
+postgresql:
+  adapter: postgresql
+  username: postgres
+  password: postgres
+  database: awesome_nested_set_plugin_test
+  min_messages: ERROR
+mysql:
+  adapter: mysql2
+  host: localhost
+  username: root
+  password:
   database: awesome_nested_set_plugin_test
\ No newline at end of file
index d3625fa3aafe3a0d12f4e2cc2a5a843be1a5ef31..dcdcde81437f0d0fe09947ee7cbe7cbf18dd2e0c 100644 (file)
@@ -1,45 +1,45 @@
-ActiveRecord::Schema.define(:version => 0) do\r
-\r
-  create_table :categories, :force => true do |t|\r
-    t.column :name, :string\r
-    t.column :parent_id, :integer\r
-    t.column :lft, :integer\r
-    t.column :rgt, :integer\r
-    t.column :organization_id, :integer\r
-  end\r
-\r
-  create_table :departments, :force => true do |t|\r
-    t.column :name, :string\r
-  end\r
-\r
-  create_table :notes, :force => true do |t|\r
-    t.column :body, :text\r
-    t.column :parent_id, :integer\r
-    t.column :lft, :integer\r
-    t.column :rgt, :integer\r
-    t.column :notable_id, :integer\r
-    t.column :notable_type, :string\r
-  end\r
-\r
-  create_table :renamed_columns, :force => true do |t|\r
-    t.column :name, :string\r
-    t.column :mother_id, :integer\r
-    t.column :red, :integer\r
-    t.column :black, :integer\r
-  end\r
-\r
-  create_table :things, :force => true do |t|\r
-    t.column :body, :text\r
-    t.column :parent_id, :integer\r
-    t.column :lft, :integer\r
-    t.column :rgt, :integer\r
-    t.column :children_count, :integer\r
-  end\r
-  \r
-  create_table :brokens, :force => true do |t|\r
-    t.column :name, :string\r
-    t.column :parent_id, :integer\r
-    t.column :lft, :integer\r
-    t.column :rgt, :integer\r
-  end\r
-end\r
+ActiveRecord::Schema.define(:version => 0) do
+
+  create_table :categories, :force => true do |t|
+    t.column :name, :string
+    t.column :parent_id, :integer
+    t.column :lft, :integer
+    t.column :rgt, :integer
+    t.column :organization_id, :integer
+  end
+
+  create_table :departments, :force => true do |t|
+    t.column :name, :string
+  end
+
+  create_table :notes, :force => true do |t|
+    t.column :body, :text
+    t.column :parent_id, :integer
+    t.column :lft, :integer
+    t.column :rgt, :integer
+    t.column :notable_id, :integer
+    t.column :notable_type, :string
+  end
+
+  create_table :renamed_columns, :force => true do |t|
+    t.column :name, :string
+    t.column :mother_id, :integer
+    t.column :red, :integer
+    t.column :black, :integer
+  end
+
+  create_table :things, :force => true do |t|
+    t.column :body, :text
+    t.column :parent_id, :integer
+    t.column :lft, :integer
+    t.column :rgt, :integer
+    t.column :children_count, :integer
+  end
+  
+  create_table :brokens, :force => true do |t|
+    t.column :name, :string
+    t.column :parent_id, :integer
+    t.column :lft, :integer
+    t.column :rgt, :integer
+  end
+end
index 45a8c098194d5676caaf6604b21b2eab4973840a..3cb6ce915478648bfdc61c0babf50a1018a80d82 100644 (file)
@@ -1,3 +1,3 @@
-one:\r
-  id: 1\r
+one:
+  id: 1
   name: One
\ No newline at end of file
index 6cf7f3f41a044430015e0b75f217dc95cc28c589..bc8e078e88e03a8e76c02e507930f3030439c6b6 100644 (file)
@@ -1,34 +1,34 @@
-top_level:\r
-  id: 1\r
-  name: Top Level\r
-  lft: 1\r
-  rgt: 10\r
-child_1:\r
-  id: 2\r
-  name: Child 1\r
-  parent_id: 1\r
-  lft: 2\r
-  rgt: 3\r
-child_2:\r
-  id: 3\r
-  name: Child 2\r
-  parent_id: 1\r
-  lft: 4\r
-  rgt: 7\r
-child_2_1:\r
-  id: 4\r
-  name: Child 2.1\r
-  parent_id: 3\r
-  lft: 5\r
-  rgt: 6\r
-child_3:\r
-  id: 5\r
-  name: Child 3\r
-  parent_id: 1\r
-  lft: 8\r
-  rgt: 9\r
-top_level_2:\r
-  id: 6\r
-  name: Top Level 2\r
-  lft: 11\r
-  rgt: 12\r
+top_level:
+  id: 1
+  name: Top Level
+  lft: 1
+  rgt: 10
+child_1:
+  id: 2
+  name: Child 1
+  parent_id: 1
+  lft: 2
+  rgt: 3
+child_2:
+  id: 3
+  name: Child 2
+  parent_id: 1
+  lft: 4
+  rgt: 7
+child_2_1:
+  id: 4
+  name: Child 2.1
+  parent_id: 3
+  lft: 5
+  rgt: 6
+child_3:
+  id: 5
+  name: Child 3
+  parent_id: 1
+  lft: 8
+  rgt: 9
+top_level_2:
+  id: 6
+  name: Top Level 2
+  lft: 11
+  rgt: 12
index 31d65624aac8471a9cf5b30b2349bd63ba3201d4..e50a944f13ed3be4eff1d407753ce9d440b3241e 100644 (file)
@@ -1,3 +1,3 @@
-top:\r
-  id: 1\r
+top:
+  id: 1
   name: Top
\ No newline at end of file
index cb7a48faf8e2e9e0b02766095e6b5fd1b6b2acab..004a5335a4a47deccdb4bf84ed334e3416e93738 100644 (file)
@@ -1,38 +1,38 @@
-scope1:\r
-  id: 1\r
-  body: Top Level\r
-  lft: 1\r
-  rgt: 10\r
-  notable_id: 1\r
-  notable_type: Category\r
-child_1:\r
-  id: 2\r
-  body: Child 1\r
-  parent_id: 1\r
-  lft: 2\r
-  rgt: 3\r
-  notable_id: 1\r
-  notable_type: Category\r
-child_2:\r
-  id: 3\r
-  body: Child 2\r
-  parent_id: 1\r
-  lft: 4\r
-  rgt: 7\r
-  notable_id: 1\r
-  notable_type: Category\r
-child_3:\r
-  id: 4\r
-  body: Child 3\r
-  parent_id: 1\r
-  lft: 8\r
-  rgt: 9\r
-  notable_id: 1\r
-  notable_type: Category\r
-scope2:\r
-  id: 5\r
-  body: Top Level 2\r
-  lft: 1\r
-  rgt: 2\r
-  notable_id: 1\r
-  notable_type: Departments\r
+scope1:
+  id: 1
+  body: Top Level
+  lft: 1
+  rgt: 10
+  notable_id: 1
+  notable_type: Category
+child_1:
+  id: 2
+  body: Child 1
+  parent_id: 1
+  lft: 2
+  rgt: 3
+  notable_id: 1
+  notable_type: Category
+child_2:
+  id: 3
+  body: Child 2
+  parent_id: 1
+  lft: 4
+  rgt: 7
+  notable_id: 1
+  notable_type: Category
+child_3:
+  id: 4
+  body: Child 3
+  parent_id: 1
+  lft: 8
+  rgt: 9
+  notable_id: 1
+  notable_type: Category
+scope2:
+  id: 5
+  body: Top Level 2
+  lft: 1
+  rgt: 2
+  notable_id: 1
+  notable_type: Departments
index b9c868831aaab1bd9157a27e7e704223890eb4be..207a682ed5a487c29b37268349caead49bde3544 100644 (file)
@@ -1,27 +1,27 @@
-parent1:\r
-  id: 1\r
-  body: Top Level\r
-  lft: 1\r
-  rgt: 10\r
-  children_count: 2\r
-child_1:\r
-  id: 2\r
-  body: Child 1\r
-  parent_id: 1\r
-  lft: 2\r
-  rgt: 3\r
-  children_count: 0\r
-child_2:\r
-  id: 3\r
-  body: Child 2\r
-  parent_id: 1\r
-  lft: 4\r
-  rgt: 7\r
-  children_count: 0\r
-child_2_1:\r
-  id: 4\r
-  body: Child 2.1\r
-  parent_id: 3\r
-  lft: 8\r
-  rgt: 9\r
-  children_count: 0\r
+parent1:
+  id: 1
+  body: Top Level
+  lft: 1
+  rgt: 10
+  children_count: 2
+child_1:
+  id: 2
+  body: Child 1
+  parent_id: 1
+  lft: 2
+  rgt: 3
+  children_count: 0
+child_2:
+  id: 3
+  body: Child 2
+  parent_id: 1
+  lft: 4
+  rgt: 7
+  children_count: 0
+child_2_1:
+  id: 4
+  body: Child 2.1
+  parent_id: 3
+  lft: 8
+  rgt: 9
+  children_count: 0
index 3fa1ba3ad100877c96381ed04a6a4dd9d023af99..c9cf43d88e8af7c3442e5e99b4a5348c3c0d0e59 100644 (file)
@@ -1,32 +1,32 @@
-$:.unshift(File.dirname(__FILE__) + '/../lib')\r
-plugin_test_dir = File.dirname(__FILE__)\r
-\r
-require 'rubygems'\r
-require 'bundler/setup'\r
-\r
-require 'rspec'\r
-require 'logger'\r
-\r
-require 'active_support'\r
-require 'active_model'\r
-require 'active_record'\r
-require 'action_controller'\r
-\r
-require 'awesome_nested_set'\r
-\r
-ActiveRecord::Base.logger = Logger.new(plugin_test_dir + "/debug.log")\r
-\r
-require 'yaml'\r
-require 'erb'\r
-ActiveRecord::Base.configurations = YAML::load(ERB.new(IO.read(plugin_test_dir + "/db/database.yml")).result)\r
-ActiveRecord::Base.establish_connection(ENV["DB"] || "sqlite3mem")\r
-ActiveRecord::Migration.verbose = false\r
-load(File.join(plugin_test_dir, "db", "schema.rb"))\r
-\r
-require 'support/models'\r
-\r
-require 'rspec/rails'\r
-RSpec.configure do |config|\r
-  config.fixture_path = "#{plugin_test_dir}/fixtures"\r
-  config.use_transactional_fixtures = true\r
-end\r
+$:.unshift(File.dirname(__FILE__) + '/../lib')
+plugin_test_dir = File.dirname(__FILE__)
+
+require 'rubygems'
+require 'bundler/setup'
+
+require 'rspec'
+require 'logger'
+
+require 'active_support'
+require 'active_model'
+require 'active_record'
+require 'action_controller'
+
+require 'awesome_nested_set'
+
+ActiveRecord::Base.logger = Logger.new(plugin_test_dir + "/debug.log")
+
+require 'yaml'
+require 'erb'
+ActiveRecord::Base.configurations = YAML::load(ERB.new(IO.read(plugin_test_dir + "/db/database.yml")).result)
+ActiveRecord::Base.establish_connection(ENV["DB"] || "sqlite3mem")
+ActiveRecord::Migration.verbose = false
+load(File.join(plugin_test_dir, "db", "schema.rb"))
+
+require 'support/models'
+
+require 'rspec/rails'
+RSpec.configure do |config|
+  config.fixture_path = "#{plugin_test_dir}/fixtures"
+  config.use_transactional_fixtures = true
+end
index bb87761323f723e4f67f981d6adf15b31be59898..fadb0dc0b5a5c67bc0d2539bb9e5aca69ff29ca5 100644 (file)
@@ -1,72 +1,72 @@
-class Note < ActiveRecord::Base\r
-  acts_as_nested_set :scope => [:notable_id, :notable_type]\r
-end\r
-\r
-class Default < ActiveRecord::Base\r
-  self.table_name = 'categories'\r
-  acts_as_nested_set\r
-end\r
-\r
-class ScopedCategory < ActiveRecord::Base\r
-  self.table_name = 'categories'\r
-  acts_as_nested_set :scope => :organization\r
-end\r
-\r
-class RenamedColumns < ActiveRecord::Base\r
-  acts_as_nested_set :parent_column => 'mother_id', :left_column => 'red', :right_column => 'black'\r
-end\r
-\r
-class Category < ActiveRecord::Base\r
-  acts_as_nested_set\r
-\r
-  validates_presence_of :name\r
-\r
-  # Setup a callback that we can switch to true or false per-test\r
-  set_callback :move, :before, :custom_before_move\r
-  cattr_accessor :test_allows_move\r
-  @@test_allows_move = true\r
-  def custom_before_move\r
-    @@test_allows_move\r
-  end\r
-\r
-  def to_s\r
-    name\r
-  end\r
-\r
-  def recurse &block\r
-    block.call self, lambda{\r
-      self.children.each do |child|\r
-        child.recurse &block\r
-      end\r
-    }\r
-  end\r
-end\r
-\r
-class Thing < ActiveRecord::Base\r
-  acts_as_nested_set :counter_cache => 'children_count'\r
-end\r
-\r
-class DefaultWithCallbacks < ActiveRecord::Base\r
-\r
-  self.table_name = 'categories'\r
-\r
-  attr_accessor :before_add, :after_add, :before_remove, :after_remove\r
-\r
-  acts_as_nested_set :before_add => :do_before_add_stuff,\r
-    :after_add     => :do_after_add_stuff,\r
-    :before_remove => :do_before_remove_stuff,\r
-    :after_remove  => :do_after_remove_stuff\r
-\r
-  private\r
-\r
-    [ :before_add, :after_add, :before_remove, :after_remove ].each do |hook_name|\r
-      define_method "do_#{hook_name}_stuff" do |child_node|\r
-        self.send("#{hook_name}=", child_node)\r
-      end\r
-    end\r
-\r
-end\r
-\r
-class Broken < ActiveRecord::Base\r
-  acts_as_nested_set\r
+class Note < ActiveRecord::Base
+  acts_as_nested_set :scope => [:notable_id, :notable_type]
+end
+
+class Default < ActiveRecord::Base
+  self.table_name = 'categories'
+  acts_as_nested_set
+end
+
+class ScopedCategory < ActiveRecord::Base
+  self.table_name = 'categories'
+  acts_as_nested_set :scope => :organization
+end
+
+class RenamedColumns < ActiveRecord::Base
+  acts_as_nested_set :parent_column => 'mother_id', :left_column => 'red', :right_column => 'black'
+end
+
+class Category < ActiveRecord::Base
+  acts_as_nested_set
+
+  validates_presence_of :name
+
+  # Setup a callback that we can switch to true or false per-test
+  set_callback :move, :before, :custom_before_move
+  cattr_accessor :test_allows_move
+  @@test_allows_move = true
+  def custom_before_move
+    @@test_allows_move
+  end
+
+  def to_s
+    name
+  end
+
+  def recurse &block
+    block.call self, lambda{
+      self.children.each do |child|
+        child.recurse &block
+      end
+    }
+  end
+end
+
+class Thing < ActiveRecord::Base
+  acts_as_nested_set :counter_cache => 'children_count'
+end
+
+class DefaultWithCallbacks < ActiveRecord::Base
+
+  self.table_name = 'categories'
+
+  attr_accessor :before_add, :after_add, :before_remove, :after_remove
+
+  acts_as_nested_set :before_add => :do_before_add_stuff,
+    :after_add     => :do_after_add_stuff,
+    :before_remove => :do_before_remove_stuff,
+    :after_remove  => :do_after_remove_stuff
+
+  private
+
+    [ :before_add, :after_add, :before_remove, :after_remove ].each do |hook_name|
+      define_method "do_#{hook_name}_stuff" do |child_node|
+        self.send("#{hook_name}=", child_node)
+      end
+    end
+
+end
+
+class Broken < ActiveRecord::Base
+  acts_as_nested_set
 end
\ No newline at end of file