Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Looks it can not work will #23

Open
huacnlee opened this issue Mar 11, 2013 · 1 comment
Open

Looks it can not work will #23

huacnlee opened this issue Mar 11, 2013 · 1 comment

Comments

@huacnlee
Copy link

There have wrong lft, rgt value.

And then, I clone lastest source from thinkwell/mongoid_nested_set, and try to write the test case like this graph:

class Comment
  include Mongoid::Document
  acts_as_nested_set :scope => :commentable

  field :body
  belongs_to :commentable, :polymorphic => true
end
context "test with polymorphic model" do
  it "should get right tree" do
    @node = Node.create(:name => 'Foo', :root_id => 0)
    food = Comment.create(:commentable => @node, :body => "Food")
      fruit = food.children.create(:commentable => @node, :body => "Fruit")
        red = fruit.children.create(:commentable => @node, :body => "Red")
          cherry = red.children.create(:commentable => @node, :body => "Cherry")
        yellow = fruit.children.create(:commentable => @node, :body => "Yellow")
          banana = yellow.children.create(:commentable => @node, :body => "Banana")
      meat = food.children.create(:commentable => @node, :body => "Meat")
        beef = meat.children.create(:commentable => @node, :body => "Beef")
        pork = meat.children.create(:commentable => @node, :body => "Pork")

    [food.lft,food.rgt].should == [1,18]
    [fruit.lft,fruit.rgt].should == [2,11]
    [red.lft,red.rgt].should == [3,6]
    [cherry.lft,cherry.rgt].should == [4,5]
    [yellow.lft,yellow.rgt].should == [7,10]
    [banana.lft,banana.rgt].should == [8,9]
    [meat.lft,meat.rgt].should == [12,17]
    [beef.lft,beef.rgt].should == [13,14]
    [pork.lft,pork.rgt].should == [15,16]
  end
end

It can not pass.

@huacnlee
Copy link
Author

I have looped the all of comments to see the datas in DB

Comment.each do |c|
  tl = "  "*c.depth
  nl = "#{c.body}"
  print tl, nl
  print "lft: #{c.lft}, rgt: #{c.rgt} ".rjust(80 - tl.length - nl.length)
  puts ""
end

Got this result:

Food                                                            lft: 1, rgt: 18
  Fruit                                                         lft: 2, rgt: 11
    Red                                                          lft: 3, rgt: 6
      Cherry                                                     lft: 4, rgt: 5
    Yellow                                                      lft: 7, rgt: 10
      Banana                                                     lft: 8, rgt: 9
  Meat                                                         lft: 12, rgt: 17
    Beef                                                       lft: 13, rgt: 14
    Pork                                                       lft: 15, rgt: 16

Look like the lft,rgt values in database is right.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant