require 'test_helper'
class MetamagicTest < ActionView::TestCase
include Metamagic::ViewHelper
test "meta tags generation" do
meta title: "My Title",
description: "My description.",
keywords: ["One", "Two", "Three"]
assert_equal %{
My Title\n\n},
metamagic
end
test "default meta tags" do
meta title: "Test Title",
test: "Test tag"
assert_equal %{Test Title\n\n},
metamagic(title: "Default Title", description: "Default description", test: "Default test")
end
test "default meta tags containing colons" do
meta title: "Test Title",
test: "Test tag"
assert_equal %{Test Title\n\n},
metamagic(title: "Default:Title", description: "Default\n:something", test: "Default test")
end
test "not adding existing meta tags" do
meta title: "Test Title",
description: "Test description."
meta title: "Second Title",
description: "Second description."
assert_equal %{Test Title\n},
metamagic
end
test "not adding existing meta tags by shortcut helpers" do
meta title: "Test Title",
description: "Test description."
title "Second Title"
description "Second description."
assert_equal %{Test Title\n},
metamagic
end
test "shortcut helpers" do
title "My Title"
description "My description"
keywords %w{one two three}
assert_equal %{My Title\n\n},
metamagic
end
test "shortcut helper returns value" do
assert_equal "My Title", title("My Title")
assert_equal "My Description", description("My Description")
assert_equal %w{one two three}, keywords(%w{one two three})
end
test "not adding templates from views" do
title "This is a :nonexistent_key"
assert_equal %{This is a :nonexistent_key},
metamagic
end
test "sorting tags" do
twitter card: :summary
og image: "http://test.com/image.png"
description "My description."
keywords %w{one two three}
title "My Title"
assert_equal %{My Title\n\n\n\n},
metamagic
end
test "duplicating tags" do
og image: "http://test.com/image.png",
description: "My description."
assert_equal %{\n\n\n\n\n\n},
metamagic(og: { image: [:value, "http://test.com/default.png"] }, twitter: { card: "summary", image: :og_image, description: :og_description, other: :og_nonexisting })
end
end