require 'spec_helper'
describe TopHat::OpenGraphHelper do
before(:all) do
@title = 'Rain Man'
@type = 'movie'
end
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 include('')
end
end
context "as an array" do
it "generates a site admin tag" do
@template.opengraph(:admins => [123, 124])
@template.opengraph.should include('')
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 include('')
end
end
context "additional open graph properties" do
it "generates opengraph meta tags" do
@template.opengraph { |og| og.title 'The Great Gatsby' }
@template.opengraph.should include('')
end
it "allows use of the tag 'type'" do
@template.opengraph { |og| og.type 'sports_team' }
@template.opengraph.should include('')
end
it "supports multiple tags" do
@template.opengraph do |og|
og.title 'Austin Powers: International Man of Mystery'
og.type 'movie'
end
output = @template.opengraph
output.should include('')
output.should include('')
end
it 'supports default tags' do
@template.opengraph do |og|
og.title @title
og.type @type
end
output = @template.opengraph do |og|
og.rating '5/10'
end
output.should include('')
output.should include('')
output.should include('')
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]) do |og|
og.title @title
og.type @type
end
output = @template.opengraph
output.should include('')
output.should include('')
output.should include('')
output.should include('')
end
it "generates all tags when app_id and admins passed as part of rendering" do
@template.opengraph do |og|
og.title @title
og.type @type
end
output = @template.opengraph(:app_id => 'MyApp', :admins => [123, 1234])
output.should include('')
output.should include('')
output.should include('')
output.should include('')
end
it 'supports default tags' do
@template.opengraph do |og|
og.title @title
og.type @type
end
output = @template.opengraph(:app_id => 'MyApp', :admins => [123, 1234]) do |og|
og.rating '5/10'
end
output.should include('')
output.should include('')
output.should include('')
output.should include('')
output.should include('')
end
end
end