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 expect(output).to match(/') end end it 'it supports deprecated html_with_opengraph' do capture_warning do expect(@template.opengraph_html).to eq(@template.html_with_opengraph) end end it 'deprecates html_with_opengraph' do warning = capture_warning do @template.html_with_opengraph end expect(warning).to eq("html_with_opengraph has been deprecated, use opengraph_html instead.\n") 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') expect(@template.opengraph).to include('') end end context "as an array" do it "generates a site admin tag" do @template.opengraph(:admins => [123, 124]) expect(@template.opengraph).to include('') end end end context "app_id when configured" do it "generates an app_id meta tag" do @template.opengraph(:app_id => 'MyApp') expect(@template.opengraph).to include('') end end context "additional open graph properties" do it "generates opengraph meta tags" do @template.opengraph { |og| og.title 'The Great Gatsby' } expect(@template.opengraph).to include('') end it "allows use of the tag 'type'" do @template.opengraph { |og| og.type 'sports_team' } expect(@template.opengraph).to 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 expect(output).to include('') expect(output).to 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 expect(output).to include('') expect(output).to include('') expect(output).to 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 expect(output).to include('') expect(output).to include('') expect(output).to include('') expect(output).to 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]) expect(output).to include('') expect(output).to include('') expect(output).to include('') expect(output).to 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 expect(output).to include('') expect(output).to include('') expect(output).to include('') expect(output).to include('') expect(output).to include('') end end end