Skip to content
This repository
Fetching contributors…

Cannot retrieve contributors at this time

file 53 lines (41 sloc) 1.204 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
require 'spec_helper'
require 'high_voltage/page_finder'

describe HighVoltage::PageFinder do
  it 'produces the name of an existing template' do
    find('existing').should == 'pages/existing'
  end

  it 'produces the name of a nested template' do
    find('dir/nested').should == 'pages/dir/nested'
  end

  it 'uses a custom content path' do
    with_content_path('other_pages/') do
      find('also_exists').should == 'other_pages/also_exists'
    end
  end

  it 'exposes the content path' do
    with_content_path('another_thing/') do
      page_finder.content_path.should == 'another_thing/'
    end
  end

  it 'provides the page_id' do
    subclass = Class.new(HighVoltage::PageFinder) do
      def page_name
        "the page is #{page_id}"
      end
    end

    subclass.new('sweet page').page_name.should == 'the page is sweet page'
  end

  private

  def find(page_id)
    page_finder(page_id).find
  end

  def page_finder(page_id = 'whatever')
    HighVoltage::PageFinder.new(page_id)
  end

  def with_content_path(path)
    original_content_path = HighVoltage.content_path
    HighVoltage.content_path = path

    yield

    HighVoltage.content_path = original_content_path
  end
end
Something went wrong with that request. Please try again.