Permalink
Browse files

more specs

  • Loading branch information...
1 parent 03d0511 commit 33514ef065edec7983af0f39a90b41682fd45bdd Paweł Kondzior committed Jan 9, 2009
Showing with 45 additions and 52 deletions.
  1. +1 −1 Rakefile
  2. +2 −3 TODO
  3. +8 −9 lib/sequel_nested_set.rb
  4. +34 −39 spec/nested_set_spec.rb
View
@@ -3,7 +3,7 @@
##############################################################################
PluginName = "sequel_nested_set"
-Version = "0.5"
+Version = "0.9"
Title = "Nested Set Sequel Plugin"
Summary = "Sequel Nested Set Plugin"
Authors = "Brian Cooke"
View
5 TODO
@@ -1,4 +1,3 @@
-- Add configuration options
-- Add move, rebuild! and integration check methods, and specs for methods + full code covarage
- Do more specs for scoped nested_set
-- Add move hooks (before_,after_)
+- Add move hooks (before_,after_)
+- Add documentation
View
@@ -125,21 +125,20 @@ def valid?
def left_and_rights_valid?
self.left_outer_join(Client.implicit_table_name.as(:parent), self.qualified_parent_column => "parent__#{self.primary_key}".to_sym).
- filter(({ self.qualified_left_column => nil } |
+ filter({ self.qualified_left_column => nil } |
{ self.qualified_right_column => nil } |
- (self.qualified_left_column >= self.qualified_right_column)) |
- ({ self.qualified_parent_column => nil } & (self.qualified_left_column <= self.qualified_left_column(:parent)) |
- (self.qualified_right_column >= self.qualified_right_column(:parent)))).count == 0
+ (self.qualified_left_column >= self.qualified_right_column) |
+ (~{ self.qualified_parent_column => nil } & ((self.qualified_left_column <= self.qualified_left_column(:parent)) |
+ (self.qualified_right_column >= self.qualified_right_column(:parent))))).count == 0
end
def left_and_rights_valid_dataset?
self.left_outer_join(Client.implicit_table_name.as(:parent), self.qualified_parent_column => "parent__#{self.primary_key}".to_sym).
- filter(({ self.qualified_left_column => nil } |
+ filter({ self.qualified_left_column => nil } |
{ self.qualified_right_column => nil } |
- { self.qualified_parent_column => nil } |
- (self.qualified_right_column >= self.qualified_right_column)) |
- ((self.qualified_left_column <= self.qualified_left_column(:parent)) &
- (self.qualified_right_column >= self.qualified_right_column(:parent))))
+ (self.qualified_left_column >= self.qualified_right_column) |
+ (~{ self.qualified_parent_column => nil } & ((self.qualified_left_column <= self.qualified_left_column(:parent)) |
+ (self.qualified_right_column >= self.qualified_right_column(:parent)))))
end
def no_duplicates_for_columns?
View
@@ -462,45 +462,40 @@
Client.left_and_rights_valid?.should be_false
end
-#
-# def test_left_and_rights_valid_with_equal
-# assert Category.left_and_rights_valid?
-# categories(:top_level_2)[:lft] = categories(:top_level_2)[:rgt]
-# categories(:top_level_2).save(false)
-# assert !Category.left_and_rights_valid?
-# end
-#
-# def test_left_and_rights_valid_with_left_equal_to_parent
-# assert Category.left_and_rights_valid?
-# categories(:child_2)[:lft] = categories(:top_level)[:lft]
-# categories(:child_2).save(false)
-# assert !Category.left_and_rights_valid?
-# end
-#
-# def test_left_and_rights_valid_with_right_equal_to_parent
-# assert Category.left_and_rights_valid?
-# categories(:child_2)[:rgt] = categories(:top_level)[:rgt]
-# categories(:child_2).save(false)
-# assert !Category.left_and_rights_valid?
-# end
-#
-# def test_moving_dirty_objects_doesnt_invalidate_tree
-# r1 = Category.create
-# r2 = Category.create
-# r3 = Category.create
-# r4 = Category.create
-# nodes = [r1, r2, r3, r4]
-#
-# r2.move_to_child_of(r1)
-# assert Category.valid?
-#
-# r3.move_to_child_of(r1)
-# assert Category.valid?
-#
-# r4.move_to_child_of(r2)
-# assert Category.valid?
-# end
-#
+ it "should return true for left_and_rights_valid? when node lft is equal for root lft" do
+ Client.left_and_rights_valid?.should be_true
+ @node2[:lft] = @root[:lft]
+ @node2.save
+ Client.left_and_rights_valid?.should be_false
+ end
+
+ it "should return true for left_and_rights_valid? when node rgt is equal for root rgt" do
+ Client.left_and_rights_valid?.should be_true
+ @node2[:rgt] = @root[:rgt]
+ @node2.save
+ Client.left_and_rights_valid?.should be_false
+ end
+
+ it "should be valid after moving dirty nodes" do
+ n1 = Client.create
+ n2 = Client.create
+ n3 = Client.create
+ n4 = Client.create
+
+ n2.move_to_child_of(n1)
+ Client.valid?.should be_true
+
+ n3.move_to_child_of(n1)
+ Client.valid?.should be_true
+
+ n4.move_to_child_of(n2)
+ Client.valid?.should be_true
+ end
+
+ it "should be no duplicates for different scope" do
+
+ end
+
# def test_multi_scoped_no_duplicates_for_columns?
# assert_nothing_raised do
# Note.no_duplicates_for_columns?

0 comments on commit 33514ef

Please sign in to comment.