require 'test_helper'
class HelperMethodsTest < 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 "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 "open graph" do
meta title: "Test Title",
og: {
image: {
url: "http://test.com/image.jpg",
type: "image/png"
}
}
assert_equal %{Test Title\n\n},
metamagic
end
test "twitter cards" do
meta title: "Test Title",
twitter: {
card: :summary,
site: "@flickr"
}
assert_equal %{Test Title\n\n},
metamagic
end
test "custom tags" do
Metamagic::Renderer.register_tag_type :custom, ->(key, value) { tag(:custom_tag, one: key, two: value) }
meta title: "Test Title",
custom: {
first: "This is the first",
second: "This is the second"
}
assert_equal %{Test Title\n\n},
metamagic
end
test "shortcut helpers" do
title "My Title"
description "My description"
keywords %w{one two three}
og image: "http://test.com/img.jpg"
twitter card: :summary, site: "@flickr"
meta bla: "Test"
assert_equal %{My Title\n\n\n\n\n\n},
metamagic
end
test "property helper" do
meta property: { one: "Property One", two: "Property Two", "og:image" => "http://test.com/image.png", nested: { a: "Nested A" } }
property two: "Property Two second", three: "Property Three", nested: { a: "Nested A second", b: "Nested B" }
og title: "My Title", image: "http://test.com/image2.png"
assert_equal %{\n\n\n\n\n\n},
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
end