Sha256: 812452f856b4ef92c70f9423ad151fd7179af1ff882d06a4fee985e6e40726f0

Contents?: true

Size: 1.76 KB

Versions: 11

Compression:

Stored size: 1.76 KB

Contents

require 'spec_helper'

describe NavItem do

  it "should be valid with minimum values" do
    NavItem.new(
      :kind => 'Primary',
      :url  => '/foo/',
      :link_text => 'Foo',
      :link_title => 'Foo page'
    ).should be_valid
  end

  describe 'organizes nav items into hierarchies' do

    before :all do
      Site.destroy_all
      @site = Site.make
      @parent = @site.nav_items.create(NavItem.make_unsaved.attributes)
      @child_1 = @site.nav_items.create(NavItem.make_unsaved.attributes.merge(:parent_id => @parent.id.to_s))
      @child_2 = @site.nav_items.create(NavItem.make_unsaved.attributes.merge(:parent_id => @parent.id.to_s))
    end

    it 'returns its children' do
      @parent.children.to_a.should have(2).items
    end

    it 'returns its parent nav itm' do
      @child_1.parent.should == @parent
    end

    it 'returns its siblings' do
      @child_1.siblings.should include @child_2
      @child_1.siblings.should have(1).item
    end

    it 'detects roots' do
      @parent.root?.should be_true
      @child_1.root?.should be_false
    end

    it 'detects sub nav items' do
      @parent.sub_nav_item?.should be_false
      @child_1.sub_nav_item?.should be_true
    end

  end

  describe 'url obfuscation' do

    before :all do
      @obf = NavItem.make_unsaved(:url => 'foo', :obfuscate => true)
      @clear = NavItem.make_unsaved(:url => 'bar')
    end

    it 'returns the URL for an unobfuscated nav item' do
      @clear.url.should == 'bar'
    end

    it 'returns the URL for an obfuscated nav item' do
      @obf.url.should_not == 'foo'
    end

    it 'obfuscates a URL using ROT13 encoding' do
      @obf.encoded_url.should == 'sbb'
    end

    it 'returns its undecoded URL' do
      @obf.decoded_url.should == 'foo'
    end

  end


end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
site_logic-1.9.13 spec/models/nav_item_spec.rb
site_logic-1.9.12 spec/models/nav_item_spec.rb
site_logic-1.9.11 spec/models/nav_item_spec.rb
site_logic-1.9.10 spec/models/nav_item_spec.rb
site_logic-1.9.9 spec/models/nav_item_spec.rb
site_logic-1.9.8 spec/models/nav_item_spec.rb
site_logic-1.9.7 spec/models/nav_item_spec.rb
site_logic-1.9.6 spec/models/nav_item_spec.rb
site_logic-1.9.5 spec/models/nav_item_spec.rb
site_logic-1.9.4 spec/models/nav_item_spec.rb
site_logic-1.9.3 spec/models/nav_item_spec.rb