require File.dirname(__FILE__) + '/spec_helper' describe MetaTags::ViewHelper do before :each do @view = ActionView::Base.new end context 'module' do it 'should be mixed into ActionView::Base' do ActionView::Base.included_modules.should include(MetaTags::ViewHelper) end it 'should respond to "title" helper' do @view.should respond_to(:title) end it 'should respond to "description" helper' do @view.should respond_to(:description) end it 'should respond to "keywords" helper' do @view.should respond_to(:keywords) end it 'should respond to "noindex" helper' do @view.should respond_to(:noindex) end it 'should respond to "nofollow" helper' do @view.should respond_to(:nofollow) end it 'should respond to "set_meta_tags" helper' do @view.should respond_to(:set_meta_tags) end it 'should respond to "display_meta_tags" helper' do @view.should respond_to(:display_meta_tags) end end context 'returning values' do it 'should return title' do @view.title('some-title').should == 'some-title' end it 'should return headline if specified' do @view.title('some-title', 'some-headline').should == 'some-headline' end it 'should return description' do @view.description('some-description').should == 'some-description' end it 'should return keywords' do @view.keywords('some-keywords').should == 'some-keywords' end it 'should return noindex' do @view.noindex('some-noindex').should == 'some-noindex' end it 'should return nofollow' do @view.noindex('some-nofollow').should == 'some-nofollow' end end context 'title' do it 'should use website name if title is empty' do @view.display_meta_tags(:site => 'someSite').should == 'someSite' end it 'should display title when "title" used' do @view.title('someTitle') @view.display_meta_tags(:site => 'someSite').should == 'someSite | someTitle' end it 'should display title when "set_meta_tags" used' do @view.set_meta_tags(:title => 'someTitle') @view.display_meta_tags(:site => 'someSite').should == 'someSite | someTitle' end it 'should display custom title if given' do @view.title('someTitle') @view.display_meta_tags(:site => 'someSite', :title => 'defaultTitle').should == 'someSite | someTitle' end it 'should use website before page by default' do @view.display_meta_tags(:site => 'someSite', :title => 'someTitle').should == 'someSite | someTitle' end it 'should only use markup in titles in the view' do @view.title('someTitle').should == 'someTitle' @view.display_meta_tags(:site => 'someSite').should == 'someSite | someTitle' end it 'should use page before website if :reverse' do @view.display_meta_tags(:site => 'someSite', :title => 'someTitle', :reverse => true).should == 'someTitle | someSite' end it 'should be lowercase if :lowercase' do @view.display_meta_tags(:site => 'someSite', :title => 'someTitle', :lowercase => true).should == 'someSite | sometitle' end it 'should use custom separator if :separator' do @view.title('someTitle') @view.display_meta_tags(:site => 'someSite', :separator => '-').should == 'someSite - someTitle' @view.display_meta_tags(:site => 'someSite', :separator => ':').should == 'someSite : someTitle' @view.display_meta_tags(:site => 'someSite', :separator => '—').should == 'someSite — someTitle' end it 'should use custom prefix and suffix if available' do @view.display_meta_tags(:site => 'someSite', :title => 'someTitle', :prefix => ' -', :suffix => '- ').should == 'someSite -|- someTitle' end it 'should collapse prefix if false' do @view.display_meta_tags(:site => 'someSite', :title => 'someTitle', :prefix => false).should == 'someSite| someTitle' end it 'should collapse suffix if false' do @view.display_meta_tags(:site => 'someSite', :title => 'someTitle', :suffix => false).should == 'someSite |someTitle' end it 'should use all custom options if available' do @view.display_meta_tags(:site => 'someSite', :title => 'someTitle', :prefix => ' -', :suffix => '+ ', :separator => ':', :lowercase => true, :reverse => true).should == 'sometitle -:+ someSite' end it 'shold allow Arrays in title' do @view.display_meta_tags(:site => 'someSite', :title => ['someTitle', 'anotherTitle']).should == 'someSite | someTitle | anotherTitle' end it 'shold build title in reverse order if :reverse' do @view.display_meta_tags(:site => 'someSite', :title => ['someTitle', 'anotherTitle'], :prefix => ' -', :suffix => '+ ', :separator => ':', :reverse => true).should == 'anotherTitle -:+ someTitle -:+ someSite' end end context 'displaying description' do it 'should display description when "description" used' do @view.description('someDescription') @view.display_meta_tags(:site => 'someSite').should include('') end it 'should display description when "set_meta_tags" used' do @view.set_meta_tags(:description => 'someDescription') @view.display_meta_tags(:site => 'someSite').should include('') end it 'should display default description' do @view.display_meta_tags(:site => 'someSite', :description => 'someDescription').should include('') end it 'should use custom description if given' do @view.description('someDescription') @view.display_meta_tags(:site => 'someSite', :description => 'defaultDescription').should include('') end it 'should strip multiple spaces' do @view.display_meta_tags(:site => 'someSite', :description => "some \n\r\t description").should include('') end it 'should strip HTML' do @view.display_meta_tags(:site => 'someSite', :description => "

some description

").should include('') end end context 'displaying keywords' do it 'should display keywords when "keywords" used' do @view.keywords('some-keywords') @view.display_meta_tags(:site => 'someSite').should include('') end it 'should display keywords when "set_meta_tags" used' do @view.set_meta_tags(:keywords => 'some-keywords') @view.display_meta_tags(:site => 'someSite').should include('') end it 'should display default keywords' do @view.display_meta_tags(:site => 'someSite', :keywords => 'some-keywords').should include('') end it 'should use custom keywords if given' do @view.keywords('some-keywords') @view.display_meta_tags(:site => 'someSite', :keywords => 'default_keywords').should include('') end it 'should lowercase keywords' do @view.display_meta_tags(:site => 'someSite', :keywords => 'someKeywords').should include('') end it 'should join keywords from Array' do @view.display_meta_tags(:site => 'someSite', :keywords => %w(keyword1 keyword2)).should include('') end it 'should join keywords from nested Arrays' do @view.display_meta_tags(:site => 'someSite', :keywords => [%w(keyword1 keyword2), 'keyword3']).should include('') end end context 'displaying noindex' do it 'should display noindex when "noindex" used' do @view.noindex(true) @view.display_meta_tags(:site => 'someSite').should include('') end it 'should display noindex when "set_meta_tags" used' do @view.set_meta_tags(:noindex => true) @view.display_meta_tags(:site => 'someSite').should include('') end it 'should use custom noindex if given' do @view.noindex('some-noindex') @view.display_meta_tags(:site => 'someSite').should include('') end it 'should display nothing by default' do @view.display_meta_tags(:site => 'someSite').should_not include(' 'someSite').should include('') end it 'should display nofollow when "set_meta_tags" used' do @view.set_meta_tags(:nofollow => true) @view.display_meta_tags(:site => 'someSite').should include('') end it 'should use custom nofollow if given' do @view.nofollow('some-nofollow') @view.display_meta_tags(:site => 'someSite').should include('') end it 'should display nothing by default' do @view.display_meta_tags(:site => 'someSite').should_not include(' 'someSite').should include('') end it 'should be displayed when "set_meta_tags" used' do @view.set_meta_tags(:nofollow => true, :noindex => true) @view.display_meta_tags(:site => 'someSite').should include('') end it 'should use custom name if string is used' do @view.noindex('some-name') @view.nofollow('some-name') @view.display_meta_tags(:site => 'someSite').should include('') end it 'should display two meta tags when different names used' do @view.noindex('some-noindex') @view.nofollow('some-nofollow') content = @view.display_meta_tags(:site => 'someSite') content.should include('') content.should include('') end end end