require 'spec_helper'
describe TopHat::OpenGraphHelper do
before(:each) do
@template = ActionView::Base.new
end
describe 'opengraph_html' do
context 'default style' do
it 'renders an html tag with namespace' do
output = @template.opengraph_html
output.should =~ /')
end
end
it 'it supports deprecated html_with_opengraph' do
@template.opengraph_html.should eq(@template.html_with_opengraph)
end
end
context "site admins when configured" do
context "as a string" do
it "generates a site admin tag" do
@template.opengraph(:admins => '123,124')
@template.opengraph.should be_dom_equivalent_to('\n')
end
end
context "as an array" do
it "generates a site admin tag" do
@template.opengraph(:admins => [123, 124])
@template.opengraph.should be_dom_equivalent_to('\n')
end
end
end
context "app_id when configured" do
it "generates an app_id meta tag" do
@template.opengraph(:app_id => 'MyApp')
@template.opengraph.should be_dom_equivalent_to('\n')
end
end
context "additional open graph properties" do
it "generates opengraph meta tags" do
@template.opengraph { title 'The Great Gatsby' }
@template.opengraph.should be_dom_equivalent_to('')
end
it "allows use of the tag 'type'" do
@template.opengraph { type 'sports_team' }
@template.opengraph.should be_dom_equivalent_to('')
end
it "supports multiple tags" do
@template.opengraph {
title 'Austin Powers: International Man of Mystery'
type 'movie'
}
@template.opengraph.should be_dom_equivalent_to('\n\n')
end
end
context "combined usage" do
it "generates all tags when app_id and admins passed as part of definition" do
@template.opengraph(:app_id => 'MyApp', :admins => [123, 1234]) {
title 'Rain Man'
type 'movie'
}
@template.opengraph.should be_dom_equivalent_to('\n\n\n\n')
end
it "generates all tags when app_id and admins passed as part of rendering" do
@template.opengraph {
title 'Rain Man'
type 'movie'
}
@template.opengraph(:app_id => 'MyApp', :admins => [123, 1234]).should be_dom_equivalent_to('\n\n\n\n')
end
end
context 'deprecated support' do
it 'generates multiple tags' do
@template.opengraph { |graph|
graph.title 'Rain Man'
graph.type 'movie'
}
@template.opengraph.should be_dom_equivalent_to('\n\n')
end
end
end