require 'spec_helper'
describe TopHat::TitleHelper do
before(:each) do
@template = ActionView::Base.new
end
context "saving a title" do
it "should save the title" do
@template.title('Kind of Blue').should == 'Kind of Blue'
end
end
context "displaying a title" do
it "uses the website name if title is empty" do
@template.title(:site => "Miles Davis").should == "
Miles Davis"
end
it "displays the title if no website was specified" do
save_basic_title
@template.title().should == 'Kind of Blue'
end
it "uses website before page by default" do
save_basic_title
@template.title(:site => "Miles Davis", :separator => '|').should == "Miles Davis | Kind of Blue"
end
it "only uses markup in titles in the view" do
save_basic_title("Kind of Blue").should == "Kind of Blue"
@template.title(:site => "Miles Davis", :separator => '|').should == "Miles Davis | Kind of Blue"
end
it "uses page before website if :reverse" do
save_basic_title
@template.title(:site => "Miles Davis", :reverse => true, :separator => '|').should == "Kind of Blue | Miles Davis"
end
it "uses website before page if :reverse and :reverse_on_default" do
@template.title(:site => "John Coltrane", :default => "My Favorite Things", :reverse => true, :reverse_on_default => false, :separator => '|').should == "John Coltrane | My Favorite Things"
end
it "lowercases the title if :lowercase" do
save_basic_title
@template.title(:site => "Miles Davis", :lowercase => true, :separator => '|').should == "miles davis | kind of blue"
end
it "uppercases the title if :uppercase" do
save_basic_title
@template.title(:site => "Miles Davis", :uppercase => true, :separator => '|').should == "MILES DAVIS | KIND OF BLUE"
end
it "uses a custom separator if :separator" do
save_basic_title
@template.title(:site => "Miles Davis", :separator => "-").should == "Miles Davis - Kind of Blue"
@template.title(:site => "Miles Davis", :separator => ":").should == "Miles Davis : Kind of Blue"
@template.title(:site => "Miles Davis", :separator => "—").should == "Miles Davis — Kind of Blue"
end
it "uses custom prefix and suffix if available" do
save_basic_title
@template.title(:site => "Miles Davis", :prefix => " |", :suffix => "| ", :separator => '|').should == "Miles Davis ||| Kind of Blue"
end
it "collapses prefix if false" do
save_basic_title
@template.title(:site => "Miles Davis", :prefix => false, :separator => ":").should == "Miles Davis: Kind of Blue"
end
it "collapses suffix if false" do
save_basic_title
@template.title(:site => "Miles Davis", :suffix => false, :separator => "~").should == "Miles Davis ~Kind of Blue"
end
it "uses all custom options if available" do
save_basic_title
custom_options = { :site => "Miles Davis", :prefix => " ", :suffix => " ", :separator => "-", :lowercase => true, :reverse => true }
@template.title(custom_options).should == "kind of blue - miles davis"
end
it "uses the default title if title is not present or blank" do
save_basic_title("")
@template.title(:site => "Miles Davis", :default => "Round About Midnight", :separator => '|').should == "Miles Davis | Round About Midnight"
end
it "allows custom options per title" do
save_custom_title
@template.title(:site => "Freddie Freeloader", :separator => '|').should == "Kind of Blue | Freddie Freeloader"
end
it "accepts an array of strings as the title" do
@template.title(['My', 'Favorite', 'Things'])
@template.title(:site => "Freddie Freeloader", :separator => '|').should == "Freddie Freeloader | My | Favorite | Things"
end
end
def save_basic_title(title='Kind of Blue')
@template.title(title)
end
def save_custom_title(title='Kind of Blue')
@template.title(title, { :reverse => true })
end
end