# Copyright (c) 2006 Michael Fellinger m.fellinger@gmail.com
# All files in this distribution are subject to the terms of the Ruby license.
require 'spec/helper'
require 'ramaze/helper/link'
class TCLink < Ramaze::Controller
map '/'
def index; end
end
class TCLink2 < Ramaze::Controller
map '/2'
def index; end
end
ramaze
describe "A" do
extend Ramaze::LinkHelper
before do
# initialize Ramaze::Controller.current for Rs()
Ramaze::Controller.handle('/')
end
it 'should build links' do
A('title', :href => '/').should == %(title)
A('title', :href => '/foo').should == %(title)
A('title', :href => '/foo?x=y').should == %{title}
A('/foo?x=y').should == %{/foo?x=y}
a = A('title', :href => '/foo', :class => :none)
a.should =~ /class="none"/
a.should =~ /href="\/foo"/
end
it 'should build position independend links' do
A(TCLink, :foo).should == %(foo)
end
end
describe 'R' do
extend Ramaze::LinkHelper
it 'should build urls' do
R(TCLink).should == '/'
R(TCLink, :foo).should == '/foo'
R(TCLink, :foo, :bar).should == '/foo/bar'
R(TCLink, :foo, :bar => :baz).should == '/foo?bar=baz'
end
end
describe 'Rs' do
extend Ramaze::LinkHelper
it 'should build links for current controller' do
Ramaze::Controller.handle('/2')
Rs(:index).should == '/2/index'
Ramaze::Controller.handle('/')
Rs(:index).should == '/index'
end
it 'should treat Rs() like R() when Controller given' do
Ramaze::Controller.handle('/2')
Rs(TCLink, :index).should == '/2/index'
end
end
describe 'breadcrumbs' do
extend Ramaze::LinkHelper
it 'should lay out breadcrumbs' do
breadcrumbs('/file/dir/listing/is/cool').
should == [
"file",
"dir",
"listing",
"is",
"cool"
].join('/')
end
it 'should lay out breadcrumbs with href prefix' do
breadcrumbs('/file/dir/listing/is/cool', '/', '/', '/prefix/path').
should == [
"file",
"dir",
"listing",
"is",
"cool"
].join('/')
end
end