Sha256: 68d6d0d0338977a4c0d93105f1e33f530dc489fadf75ba4fe6d14997b854a834

Contents?: true

Size: 1.6 KB

Versions: 2

Compression:

Stored size: 1.6 KB

Contents

require 'spec_helper'

describe Navi::Renderers::SimpleNavigation::GeneratesUri do

  describe '.execute' do
    subject { described_class.execute(template, item) }
    let(:template) { OpenStruct.new }
    let(:item) { OpenStruct.new(url: url) }

    context 'navigation item url is a string' do
      let(:url) { '/a/string' }
      it { should == '/a/string' }
    end

    context 'navigation item is not a string' do
      let(:url) { OpenStruct.new }

      context 'without a namespace' do
        before do
          template.stub(:polymorphic_path).with([url]) { '/generated/path' }
        end

        it 'should build the URL using the template polymorphic path' do
          expect(subject).to eq('/generated/path')
        end
      end

      context 'given a single namespace' do
        subject { described_class.execute(template, item, namespace: :admin) }

        before do
          template.stub(:polymorphic_path).with([:admin, url]) { '/admin/generated/path' }
        end

        it 'should build the URL using the template polymorphic path' do
          expect(subject).to eq('/admin/generated/path')
        end
      end

      context 'given multiple namespaces' do
        subject do
          described_class.execute(template, item, namespace: [:super, :admin])
        end

        before do
          template.stub(:polymorphic_path).with([:super, :admin, url]).
            and_return('/super/admin/generated/path')
        end

        it 'should build the URL using the template polymorphic path' do
          expect(subject).to eq('/super/admin/generated/path')
        end
      end
    end
  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
navi-0.2.1 spec/navi/renderers/simple_navigation/generates_uri_spec.rb
navi-0.2.0 spec/navi/renderers/simple_navigation/generates_uri_spec.rb