Sha256: 5bfed6cfc80bb2c07747df7256a4224504e093b9a3385b78843b939ea6e315e6

Contents?: true

Size: 1.81 KB

Versions: 14

Compression:

Stored size: 1.81 KB

Contents

require 'spec_helper'

describe Menu do

   describe "save whole tree" do

    it "should save tree for menu when array given" do
      menu=Menu.create!(:name=>"menu")
      root=menu.root
      items=[]
      1.upto(3) do |index|
        item=MenuItem.create!(:name=>"item-#{index}")
        items << menu.append(item)
      end

      new_positions={
        :"0"=>{
          :item_id=>"root",
          :parent_id=>"none",
          :depth=>"0",
          :left => "1",
          :right => "8"
        },
        :"1"=>{
          :item_id => "#{items[0].id}",
          :parent_id => "root",
          :depth => "1",
          :left => "2",
          :right => "7"
        },
        :"2"=>{
          :item_id => "#{items[1].id}",
          :parent_id => "#{items[0].id}",
          :depth => "2",
          :left => "3",
          :right=> "6"
        },
        :"3"=>{
          :item_id => "#{items[2].id}",
          :parent_id => "#{items[1].id}",
          :depth => "3",
          :left => "4",
          :right=> "5"
        }
      }
      
      menu.update_whole_tree(new_positions)
      
      menu.children.should have(1).item
      menu.children.first.children.should have(1).item
      menu.children.first.children.first.children.should have(1).item
    end
  end

  it "should create new menu item with name" do
    Menu.create!(:name=>"my menu").name.should == "my menu"
  end

  it "should not create menu without name" do
    lambda{
      Menu.create!
    }.should raise_error
  end

  describe "menu items" do

    let(:menu){Menu.create!(:name=>"new menu")}

    it "should create root item on create" do
      menu.root.should_not be_nil
    end

    it "should add new item to menu" do
      item=MenuItem.create!(:name=>"item",:url=>"/")
      menu.append(item)
      menu.items.should have(2).items
    end
 end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
lolita-menu-0.1.6 spec/models/menu_spec.rb
lolita-menu-0.1.5 spec/models/menu_spec.rb
lolita-menu-0.1.4 spec/models/menu_spec.rb
lolita-menu-0.1.1 spec/models/menu_spec.rb
lolita-menu-0.1.0 spec/models/menu_spec.rb
lolita-menu-0.0.15 spec/models/menu_spec.rb
lolita-menu-0.0.14 spec/models/menu_spec.rb
lolita-menu-0.0.13 spec/models/menu_spec.rb
lolita-menu-0.0.12 spec/models/menu_spec.rb
lolita-menu-0.0.11 spec/models/menu_spec.rb
lolita-menu-0.0.10 spec/models/menu_spec.rb
lolita-menu-0.0.9 spec/models/menu_spec.rb
lolita-menu-0.0.8 spec/models/menu_spec.rb
lolita-menu-0.0.6 spec/models/menu_spec.rb