Sha256: 0046a3713de889f0b2c36fe7b819c5e1a4efb04a02f16d27dc9c7253ae9f8aa8

Contents?: true

Size: 1.96 KB

Versions: 12

Compression:

Stored size: 1.96 KB

Contents

require 'spec_helper'

describe MenuItem do

  it "should create valid menu item" do
    MenuItem.create!(:name=>"item",:url=>"/")
  end

  describe "recognize active item" do

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

    let(:request){
      mock_obj = mock(Object)
      mock_obj.stub!(:params).and_return({})
      mock_obj
    }

    it "should recognize full paths" do
      item = menu.append(MenuItem.create!(:name => "Name", :url => "http://google.lv"))
      request.stub!(:url).and_return("http://google.lv")
      item.active?(request).should be_true
    end

    it "should recognize relative paths" do
      item = menu.append(MenuItem.create!(:name => "Name", :url => "/posts"))
      request.stub!(:path).and_return("/posts?page=1")
      item.active?(request).should be_true
    end

    it "should recognize relative paths with arguments" do
      item = menu.append(MenuItem.create!(:name => "Name", :url => "/:whoes/posts"))
      request.stub!(:path).and_return("/my/posts?page=1")
      request.stub!(:params).and_return({:whoes => "my"})
      item.active?(request).should be_true
    end
  end

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

    it "should append" do
      root=MenuItem.create!
      item=MenuItem.create!(:name=>"child",:url=>"/")
      root.append(item)
      item.reload
      item.parent.should == root
    end

  end

  describe "getting by possitions" do

    let(:menu){Menu.create!(:name=>"menu")}
    let(:item){MenuItem.create!(:name=>"child",:url=>"/")}

    it "should find children" do
      menu.append(item)
      menu.root.children.should have(1).item
      menu.root.children.first == item
    end

    it "should find parent" do
      menu.append(item)
      item.reload
      item.parent.should == menu.root
    end

    it "should find root for any item" do
      menu.append(item)
      item.reload
      item.root.should == menu.root
      menu.root.root.should == menu.root
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

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