engine/spec/lib/locomotive/liquid/tags/seo_metadata_spec.rb

81 lines
3.2 KiB
Ruby
Raw Normal View History

2011-02-13 13:40:55 +00:00
require 'spec_helper'
describe Locomotive::Liquid::Tags::SEOMetadata do
2011-06-23 08:14:36 +00:00
let(:site) do
Factory.build(:site, :meta_description => 'A short site description', :meta_keywords => 'test only cat dog')
2011-02-13 13:40:55 +00:00
end
describe 'rendering' do
2011-06-23 08:14:36 +00:00
2011-02-13 13:40:55 +00:00
it 'renders a a meta description tag' do
render_seo_metadata.should include '<meta name="description" content="A short site description" />'
end
it 'strips and removes quote characters from the description' do
site.meta_description = ' String with " " quotes '
2011-02-13 13:40:55 +00:00
render_seo_metadata.should include '<meta name="description" content="String with quotes" />'
end
it 'renders a meta keywords tag' do
render_seo_metadata.should include '<meta name="keywords" content="test only cat dog" />'
end
it 'strips and removes quote characters from the keywords' do
site.meta_keywords = ' one " two " three '
2011-02-13 13:40:55 +00:00
render_seo_metadata.should include '<meta name="keywords" content="one two three" />'
end
2011-06-23 08:14:36 +00:00
it 'renders an empty string if no meta' do
site.meta_keywords = nil
render_seo_metadata.should include '<meta name="keywords" content="" />'
end
context "when page" do
2011-06-23 08:14:36 +00:00
context "has metadata" do
let(:page) { site.pages.build(:meta_keywords => 'hulk,gamma', :meta_description => "Bruce Banner") }
subject { render_seo_metadata('page' => page) }
it { should include(%Q[<meta name="keywords" content="#{page.meta_keywords}" />]) }
it { should include(%Q[<meta name="description" content="#{page.meta_description}" />]) }
end
context "does not have metadata" do
2011-06-23 08:14:36 +00:00
let(:page) { site.pages.build }
subject { render_seo_metadata('page' => page) }
it { should include(%Q[<meta name="keywords" content="#{site.meta_keywords}" />]) }
it { should include(%Q[<meta name="description" content="#{site.meta_description}" />]) }
end
end
2011-06-23 08:14:36 +00:00
context "when content instance" do
2011-06-23 08:14:36 +00:00
let(:content_type) do
Factory.build(:content_type, :site => site).tap do |ct|
ct.content_custom_fields.build :label => 'anything', :kind => 'String'
end
end
2011-02-13 13:40:55 +00:00
context "has metadata" do
let(:content) { content_type.contents.build(:meta_keywords => 'Libidinous, Angsty', :meta_description => "Quite the combination.") }
subject { render_seo_metadata('content_instance' => content) }
it { should include(%Q[<meta name="keywords" content="#{content.meta_keywords}" />]) }
it { should include(%Q[<meta name="description" content="#{content.meta_description}" />]) }
end
context "does not have metadata" do
let(:content) { content_type.contents.build }
subject { render_seo_metadata('content_instance' => content) }
it { should include(%Q[<meta name="keywords" content="#{site.meta_keywords}" />]) }
it { should include(%Q[<meta name="description" content="#{site.meta_description}" />]) }
end
end
2011-02-13 13:40:55 +00:00
end
2011-06-23 08:14:36 +00:00
def render_seo_metadata(assigns = {})
registers = { :site => site }
liquid_context = ::Liquid::Context.new({}, assigns, registers)
2011-02-13 13:40:55 +00:00
output = Liquid::Template.parse("{% seo_metadata %}").render(liquid_context)
end
end