require 'spec_helper' describe MetaTags::ViewHelper do subject { ActionView::Base.new } 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 subject.should respond_to(:title) end it 'should respond to "description" helper' do subject.should respond_to(:description) end it 'should respond to "keywords" helper' do subject.should respond_to(:keywords) end it 'should respond to "noindex" helper' do subject.should respond_to(:noindex) end it 'should respond to "nofollow" helper' do subject.should respond_to(:nofollow) end it 'should respond to "set_meta_tags" helper' do subject.should respond_to(:set_meta_tags) end it 'should respond to "display_meta_tags" helper' do subject.should respond_to(:display_meta_tags) end it 'should respond to "display_title" helper' do subject.should respond_to(:display_title) end end context 'returning values' do it 'should return title' do subject.title('some-title').should == 'some-title' end it 'should return headline if specified' do subject.title('some-title', 'some-headline').should == 'some-headline' end it 'should return title' do subject.title('some-title').should == 'some-title' subject.title.should == 'some-title' end it 'should return description' do subject.description('some-description').should == 'some-description' end it 'should return keywords' do subject.keywords('some-keywords').should == 'some-keywords' end it 'should return noindex' do subject.noindex('some-noindex').should == 'some-noindex' end it 'should return nofollow' do subject.noindex('some-nofollow').should == 'some-nofollow' end end context 'displaying title' do it 'should not display title if blank' do subject.display_meta_tags.should == '' subject.title('') subject.display_meta_tags.should == '' end it 'should use website name if title is empty' do subject.display_meta_tags(:site => 'someSite').should == '
some description
").should include('') end it 'should truncate correctly' do subject.display_meta_tags(:site => 'someSite', :description => "Lorem ipsum dolor sit amet, consectetuer sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.").should include('') end end context 'displaying keywords' do it 'should not display keywords if blank' do subject.keywords('') subject.display_meta_tags.should == '' subject.keywords([]) subject.display_meta_tags.should == '' end it 'should display keywords when "keywords" used' do subject.keywords('some-keywords') subject.display_meta_tags(:site => 'someSite').should include('') end it 'should display keywords when "set_meta_tags" used' do subject.set_meta_tags(:keywords => 'some-keywords') subject.display_meta_tags(:site => 'someSite').should include('') end it 'should display default keywords' do subject.display_meta_tags(:site => 'someSite', :keywords => 'some-keywords').should include('') end it 'should use custom keywords if given' do subject.keywords('some-keywords') subject.display_meta_tags(:site => 'someSite', :keywords => 'default_keywords').should include('') end it 'should lowercase keywords' do subject.display_meta_tags(:site => 'someSite', :keywords => 'someKeywords').should include('') end it 'should join keywords from Array' do subject.display_meta_tags(:site => 'someSite', :keywords => %w(keyword1 keyword2)).should include('') end it 'should join keywords from nested Arrays' do subject.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 subject.noindex(true) subject.display_meta_tags(:site => 'someSite').should include('') end it 'should display noindex when "set_meta_tags" used' do subject.set_meta_tags(:noindex => true) subject.display_meta_tags(:site => 'someSite').should include('') end it 'should use custom noindex if given' do subject.noindex('some-noindex') subject.display_meta_tags(:site => 'someSite').should include('') end it 'should display nothing by default' do subject.display_meta_tags(:site => 'someSite').should_not include(' false) subject.display_meta_tags(:site => 'someSite').should_not include(' 'someSite').should_not include(' 'someSite').should include('') end it 'should display nofollow when "set_meta_tags" used' do subject.set_meta_tags(:nofollow => true) subject.display_meta_tags(:site => 'someSite').should include('') end it 'should use custom nofollow if given' do subject.nofollow('some-nofollow') subject.display_meta_tags(:site => 'someSite').should include('') end it 'should display nothing by default' do subject.display_meta_tags(:site => 'someSite').should_not include(' 'someSite').should include('') end it 'should be displayed when "set_meta_tags" used' do subject.set_meta_tags(:nofollow => true, :noindex => true) subject.display_meta_tags(:site => 'someSite').should include('') end it 'should use custom name if string is used' do subject.noindex('some-name') subject.nofollow('some-name') subject.display_meta_tags(:site => 'someSite').should include('') end it 'should display two meta tags when different names used' do subject.noindex('some-noindex') subject.nofollow('some-nofollow') subject.display_meta_tags(:site => 'someSite').tap do |content| content.should include('') content.should include('') end end end context 'displaying canonical url' do it 'should not display canonical url by default' do subject.display_meta_tags(:site => 'someSite').should_not include('') end it 'should display canonical url when "set_meta_tags" used' do subject.set_meta_tags(:canonical => 'http://example.com/base/url') subject.display_meta_tags(:site => 'someSite').should include('') end it 'should display default canonical url' do subject.display_meta_tags(:site => 'someSite', :canonical => 'http://example.com/base/url').should include('') end end context 'displaying Open Graph meta tags' do it 'should display meta tags specified with :open_graph' do subject.set_meta_tags(:open_graph => { :title => 'Facebook Share Title', :description => 'Facebook Share Description' }) subject.display_meta_tags(:site => 'someSite').tap do |content| content.should include('') content.should include('') end end it 'should display meta tags specified with :og' do subject.set_meta_tags(:og => { :title => 'Facebook Share Title', :description => 'Facebook Share Description' }) subject.display_meta_tags(:site => 'someSite').tap do |content| content.should include('') content.should include('') end end it 'should display meta tags with hashes and arrays' do subject.set_meta_tags(:foo => { :bar => "lorem", :baz => { :qux => ["lorem", "ipsum"] } }) subject.display_meta_tags(:site => 'someSite').tap do |content| content.should include('') content.should include('') content.should include('') end end it 'should use deep merge when displaying open graph meta tags' do subject.set_meta_tags(:og => { :title => 'Facebook Share Title' }) subject.display_meta_tags(:og => { :description => 'Facebook Share Description' }).tap do |content| content.should include('') content.should include('') end end it "should not display meta tags without content" do subject.set_meta_tags(:open_graph => { :title => '', :description => '' }) subject.display_meta_tags(:site => 'someSite').tap do |content| content.should_not include('') content.should_not include('') end end end context 'while handling string meta tag names' do it 'should work with common parameters' do subject.display_meta_tags('site' => 'someSite', 'title' => 'someTitle').should == '