Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Split huge meta_tags_spec into multiple smaller specs
- Loading branch information
Showing
13 changed files
with
632 additions
and
581 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
require 'spec_helper' | ||
|
||
describe MetaTags::ViewHelper, 'displaying charset' do | ||
subject { ActionView::Base.new } | ||
|
||
it 'should not display charset if blank' do | ||
subject.display_meta_tags.should eq('') | ||
subject.display_meta_tags(:charset => '').should eq('') | ||
end | ||
|
||
it 'should display charset' do | ||
subject.display_meta_tags(:charset => 'UTF-8').should eq('<meta charset="UTF-8" />') | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
require 'spec_helper' | ||
|
||
describe MetaTags::ViewHelper do | ||
subject { ActionView::Base.new } | ||
|
||
context 'display any named meta tag that you want to' do | ||
it 'should display testing meta tag' do | ||
subject.display_meta_tags(:testing => 'this is a test').should eq('<meta content="this is a test" name="testing" />') | ||
end | ||
|
||
it 'should support Array values' do | ||
subject.display_meta_tags(:testing => ['test1', 'test2']).should eq("<meta content=\"test1\" name=\"testing\" />\n<meta content=\"test2\" name=\"testing\" />") | ||
end | ||
|
||
it 'should support Hash values' do | ||
subject.display_meta_tags(:testing => { :tag => 'value' }).should eq('<meta content="value" name="testing:tag" />') | ||
end | ||
|
||
it 'should support symbolic references in Hash values' do | ||
subject.display_meta_tags(:title => 'my title', :testing => { :tag => :title }).should include('<meta content="my title" name="testing:tag" />') | ||
end | ||
|
||
it 'should not render when value is nil' do | ||
subject.display_meta_tags(:testing => nil).should eq('') | ||
end | ||
|
||
it 'should display meta tags with hashes and arrays' do | ||
subject.set_meta_tags(:foo => { | ||
:bar => "lorem", | ||
:baz => { | ||
:qux => ["lorem", "ipsum"] | ||
}, | ||
:quux => [ | ||
{ | ||
:corge => "lorem", | ||
:grault => "ipsum" | ||
}, | ||
{ | ||
:corge => "dolor", | ||
:grault => "sit" | ||
} | ||
] | ||
}) | ||
subject.display_meta_tags(:site => 'someSite').tap do |content| | ||
content.should include('<meta content="lorem" name="foo:bar" />') | ||
content.should include('<meta content="lorem" name="foo:baz:qux" />') | ||
content.should include('<meta content="ipsum" name="foo:baz:qux" />') | ||
content.should include('<meta content="lorem" name="foo:quux:corge"') | ||
content.should include('<meta content="ipsum" name="foo:quux:grault"') | ||
content.should include('<meta content="dolor" name="foo:quux:corge"') | ||
content.should include('<meta content="sit" name="foo:quux:grault"') | ||
content.should_not include('name="foo:quux"') | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
require 'spec_helper' | ||
|
||
describe MetaTags::ViewHelper, 'displaying description' do | ||
subject { ActionView::Base.new } | ||
|
||
it 'should not display description if blank' do | ||
subject.description('') | ||
subject.display_meta_tags.should eq('') | ||
end | ||
|
||
it 'should display description when "description" used' do | ||
subject.description('someDescription') | ||
subject.display_meta_tags(:site => 'someSite').should include('<meta content="someDescription" name="description" />') | ||
end | ||
|
||
it 'should display description when "set_meta_tags" used' do | ||
subject.set_meta_tags(:description => 'someDescription') | ||
subject.display_meta_tags(:site => 'someSite').should include('<meta content="someDescription" name="description" />') | ||
end | ||
|
||
it 'should display default description' do | ||
subject.display_meta_tags(:site => 'someSite', :description => 'someDescription').should include('<meta content="someDescription" name="description" />') | ||
end | ||
|
||
it 'should use custom description if given' do | ||
subject.description('someDescription') | ||
subject.display_meta_tags(:site => 'someSite', :description => 'defaultDescription').should include('<meta content="someDescription" name="description" />') | ||
end | ||
|
||
it 'should strip multiple spaces' do | ||
subject.display_meta_tags(:site => 'someSite', :description => "some \n\r\t description").should include('<meta content="some description" name="description" />') | ||
end | ||
|
||
it 'should strip HTML' do | ||
subject.display_meta_tags(:site => 'someSite', :description => "<p>some <b>description</b></p>").should include('<meta content="some description" name="description" />') | ||
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('<meta content="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 dol..." name="description" />') | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
require 'spec_helper' | ||
|
||
describe MetaTags::ViewHelper, 'displaying keywords' do | ||
subject { ActionView::Base.new } | ||
|
||
it 'should not display keywords if blank' do | ||
subject.keywords('') | ||
subject.display_meta_tags.should eq('') | ||
|
||
subject.keywords([]) | ||
subject.display_meta_tags.should eq('') | ||
end | ||
|
||
it 'should display keywords when "keywords" used' do | ||
subject.keywords('some-keywords') | ||
subject.display_meta_tags(:site => 'someSite').should include('<meta content="some-keywords" name="keywords" />') | ||
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('<meta content="some-keywords" name="keywords" />') | ||
end | ||
|
||
it 'should display default keywords' do | ||
subject.display_meta_tags(:site => 'someSite', :keywords => 'some-keywords').should include('<meta content="some-keywords" name="keywords" />') | ||
end | ||
|
||
it 'should use custom keywords if given' do | ||
subject.keywords('some-keywords') | ||
subject.display_meta_tags(:site => 'someSite', :keywords => 'default_keywords').should include('<meta content="some-keywords" name="keywords" />') | ||
end | ||
|
||
it 'should lowercase keywords' do | ||
subject.display_meta_tags(:site => 'someSite', :keywords => 'someKeywords').should include('<meta content="somekeywords" name="keywords" />') | ||
end | ||
|
||
it 'should join keywords from Array' do | ||
subject.display_meta_tags(:site => 'someSite', :keywords => %w(keyword1 keyword2)).should include('<meta content="keyword1, keyword2" name="keywords" />') | ||
end | ||
|
||
it 'should join keywords from nested Arrays' do | ||
subject.display_meta_tags(:site => 'someSite', :keywords => [%w(keyword1 keyword2), 'keyword3']).should include('<meta content="keyword1, keyword2, keyword3" name="keywords" />') | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
require 'spec_helper' | ||
|
||
describe MetaTags::ViewHelper do | ||
subject { ActionView::Base.new } | ||
|
||
context 'displaying canonical url' do | ||
it 'should not display canonical url by default' do | ||
subject.display_meta_tags(:site => 'someSite').should_not include('<link href="http://example.com/base/url" rel="canonical" />') | ||
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('<link href="http://example.com/base/url" rel="canonical" />') | ||
end | ||
|
||
it 'should display default canonical url' do | ||
subject.display_meta_tags(:site => 'someSite', :canonical => 'http://example.com/base/url').should include('<link href="http://example.com/base/url" rel="canonical" />') | ||
end | ||
end | ||
|
||
context 'displaying alternate url' do | ||
it 'should not display alternate url by default' do | ||
subject.display_meta_tags(:site => 'someSite').should_not include('<link href="http://example.fr/base/url" hreflang="fr" rel="alternate" />') | ||
end | ||
|
||
it 'should display alternate url when "set_meta_tags" used' do | ||
subject.set_meta_tags(:alternate => { 'fr' => 'http://example.fr/base/url' }) | ||
subject.display_meta_tags(:site => 'someSite').should include('<link href="http://example.fr/base/url" hreflang="fr" rel="alternate" />') | ||
end | ||
|
||
it 'should display default alternate url' do | ||
subject.display_meta_tags(:site => 'someSite', :alternate => { 'fr' => 'http://example.fr/base/url' }).should include('<link href="http://example.fr/base/url" hreflang="fr" rel="alternate" />') | ||
end | ||
|
||
it "should not display alternate without content" do | ||
subject.display_meta_tags(:site => 'someSite', :alternate => {'zh-Hant' => ''}).should_not include('<link href="" hreflang="zh-Hant" rel="alternate" />') | ||
end | ||
end | ||
|
||
context 'displaying author link' do | ||
it 'should display author link when "set_meta_tags" used' do | ||
subject.set_meta_tags(:author => 'http://plus.google.com/profile/url') | ||
subject.display_meta_tags(:site => 'someSite').should include('<link href="http://plus.google.com/profile/url" rel="author" />') | ||
end | ||
end | ||
|
||
context 'displaying publisher link' do | ||
it 'should display publisher link when "set_meta_tags" used' do | ||
subject.set_meta_tags(:publisher => 'http://plus.google.com/myprofile_url') | ||
subject.display_meta_tags(:site => 'someSite').should include('<link href="http://plus.google.com/myprofile_url" rel="publisher" />') | ||
end | ||
end | ||
|
||
context 'displaying prev url' do | ||
it 'should not display prev url by default' do | ||
subject.display_meta_tags(:site => 'someSite').should_not include('<link href="http://example.com/base/url" rel="prev" />') | ||
end | ||
|
||
it 'should display prev url when "set_meta_tags" used' do | ||
subject.set_meta_tags(:prev => 'http://example.com/base/url') | ||
subject.display_meta_tags(:site => 'someSite').should include('<link href="http://example.com/base/url" rel="prev" />') | ||
end | ||
|
||
it 'should display default prev url' do | ||
subject.display_meta_tags(:site => 'someSite', :prev => 'http://example.com/base/url').should include('<link href="http://example.com/base/url" rel="prev" />') | ||
end | ||
end | ||
|
||
context 'displaying next url' do | ||
it 'should not display next url by default' do | ||
subject.display_meta_tags(:site => 'someSite').should_not include('<link href="http://example.com/base/url" rel="next" />') | ||
end | ||
|
||
it 'should display next url when "set_meta_tags" used' do | ||
subject.set_meta_tags(:next => 'http://example.com/base/url') | ||
subject.display_meta_tags(:site => 'someSite').should include('<link href="http://example.com/base/url" rel="next" />') | ||
end | ||
|
||
it 'should display default next url' do | ||
subject.display_meta_tags(:site => 'someSite', :next => 'http://example.com/base/url').should include('<link href="http://example.com/base/url" rel="next" />') | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
require 'spec_helper' | ||
|
||
describe MetaTags::ViewHelper, 'module' do | ||
subject { ActionView::Base.new } | ||
|
||
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
require 'spec_helper' | ||
|
||
describe MetaTags::ViewHelper do | ||
subject { ActionView::Base.new } | ||
|
||
context 'displaying noindex' do | ||
it 'should display noindex when "noindex" used' do | ||
subject.noindex(true) | ||
subject.display_meta_tags(:site => 'someSite').should include('<meta content="noindex" name="robots" />') | ||
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('<meta content="noindex" name="robots" />') | ||
end | ||
|
||
it 'should use custom noindex if given' do | ||
subject.noindex('some-noindex') | ||
subject.display_meta_tags(:site => 'someSite').should include('<meta content="noindex" name="some-noindex" />') | ||
end | ||
|
||
it 'should display nothing by default' do | ||
subject.display_meta_tags(:site => 'someSite').should_not include('<meta content="noindex"') | ||
end | ||
|
||
it "should display nothing if given false" do | ||
subject.set_meta_tags(:noindex => false) | ||
subject.display_meta_tags(:site => 'someSite').should_not include('<meta content="robots"') | ||
subject.display_meta_tags(:site => 'someSite').should_not include('<meta content="noindex"') | ||
end | ||
end | ||
|
||
context 'displaying nofollow' do | ||
it 'should display nofollow when "nofollow" used' do | ||
subject.nofollow(true) | ||
subject.display_meta_tags(:site => 'someSite').should include('<meta content="nofollow" name="robots" />') | ||
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('<meta content="nofollow" name="robots" />') | ||
end | ||
|
||
it 'should use custom nofollow if given' do | ||
subject.nofollow('some-nofollow') | ||
subject.display_meta_tags(:site => 'someSite').should include('<meta content="nofollow" name="some-nofollow" />') | ||
end | ||
|
||
it 'should display nothing by default' do | ||
subject.display_meta_tags(:site => 'someSite').should_not include('<meta content="nofollow"') | ||
end | ||
end | ||
|
||
context 'displaying both nofollow and noindex' do | ||
it 'should be displayed when set using helpers' do | ||
subject.noindex(true) | ||
subject.nofollow(true) | ||
subject.display_meta_tags(:site => 'someSite').should include('<meta content="noindex, nofollow" name="robots" />') | ||
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('<meta content="noindex, nofollow" name="robots" />') | ||
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('<meta content="noindex, nofollow" name="some-name" />') | ||
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('<meta content="noindex" name="some-noindex" />') | ||
content.should include('<meta content="nofollow" name="some-nofollow" />') | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.