require 'test/unit'
require File.dirname(__FILE__) + '/../../lib/action_view/helpers/asset_tag_helper'
class AssetTagHelperTest < Test::Unit::TestCase
include ActionView::Helpers::TagHelper
include ActionView::Helpers::UrlHelper
include ActionView::Helpers::AssetTagHelper
def setup
@controller = Class.new do
def url_for(options, *parameters_for_method_reference)
"http://www.example.com"
end
end.new
@request = Class.new do
def relative_url_root
""
end
end.new
end
AutoDiscoveryToTag = {
%(auto_discovery_link_tag) => %(),
%(auto_discovery_link_tag(:atom)) => %(),
%(auto_discovery_link_tag(:rss, :action => "feed")) => %(),
}
JavascriptPathToTag = {
%(javascript_path("xmlhr")) => %(/javascripts/xmlhr.js),
}
JavascriptIncludeToTag = {
%(javascript_include_tag("xmlhr")) => %(),
%(javascript_include_tag("common.javascript", "/elsewhere/cools")) => %(\n),
}
StylePathToTag = {
%(stylesheet_path("style")) => %(/stylesheets/style.css),
}
StyleLinkToTag = {
%(stylesheet_link_tag("style")) => %(),
%(stylesheet_link_tag("random.styles", "/css/stylish")) => %(\n)
}
ImagePathToTag = {
%(image_path("xml")) => %(/images/xml.png),
}
ImageLinkToTag = {
%(image_tag("xml")) => %(
),
%(image_tag("rss", :alt => "rss syndication")) => %(
),
%(image_tag("gold", :size => "45x70")) => %(
),
}
def test_auto_discovery
AutoDiscoveryToTag.each { |method, tag| assert_equal(tag, eval(method)) }
end
def test_javascript_path
JavascriptPathToTag.each { |method, tag| assert_equal(tag, eval(method)) }
end
def test_javascript_include
JavascriptIncludeToTag.each { |method, tag| assert_equal(tag, eval(method)) }
end
def test_style_path
StylePathToTag.each { |method, tag| assert_equal(tag, eval(method)) }
end
def test_style_link
StyleLinkToTag.each { |method, tag| assert_equal(tag, eval(method)) }
end
def test_image_path
ImagePathToTag.each { |method, tag| assert_equal(tag, eval(method)) }
end
def test_image_tag
ImageLinkToTag.each { |method, tag| assert_equal(tag, eval(method)) }
end
end
class AssetTagHelperNonVhostTest < Test::Unit::TestCase
include ActionView::Helpers::TagHelper
include ActionView::Helpers::UrlHelper
include ActionView::Helpers::AssetTagHelper
def setup
@controller = Class.new do
def url_for(options, *parameters_for_method_reference)
"http://www.example.com/calloboration/hieraki"
end
end.new
@request = Class.new do
def relative_url_root
"/calloboration/hieraki"
end
end.new
end
AutoDiscoveryToTag = {
%(auto_discovery_link_tag(:rss, :action => "feed")) => %(),
%(auto_discovery_link_tag(:atom)) => %(),
%(auto_discovery_link_tag) => %(),
}
JavascriptPathToTag = {
%(javascript_path("xmlhr")) => %(/calloboration/hieraki/javascripts/xmlhr.js),
}
JavascriptIncludeToTag = {
%(javascript_include_tag("xmlhr")) => %(),
%(javascript_include_tag("common.javascript", "/elsewhere/cools")) => %(\n),
}
StylePathToTag = {
%(stylesheet_path("style")) => %(/calloboration/hieraki/stylesheets/style.css),
}
StyleLinkToTag = {
%(stylesheet_link_tag("style")) => %(),
%(stylesheet_link_tag("random.styles", "/css/stylish")) => %(\n)
}
ImagePathToTag = {
%(image_path("xml")) => %(/calloboration/hieraki/images/xml.png),
}
ImageLinkToTag = {
%(image_tag("xml")) => %(
),
%(image_tag("rss", :alt => "rss syndication")) => %(
),
%(image_tag("gold", :size => "45x70")) => %(
),
}
def test_auto_discovery
AutoDiscoveryToTag.each { |method, tag| assert_equal(tag, eval(method)) }
end
def test_javascript_path
JavascriptPathToTag.each { |method, tag| assert_equal(tag, eval(method)) }
end
def test_javascript_include
JavascriptIncludeToTag.each { |method, tag| assert_equal(tag, eval(method)) }
end
def test_style_path
StylePathToTag.each { |method, tag| assert_equal(tag, eval(method)) }
end
def test_style_link
StyleLinkToTag.each { |method, tag| assert_equal(tag, eval(method)) }
end
def test_image_tag
assert_equal %(
), image_tag("gold", :size => "45x70")
end
def test_image_path
ImagePathToTag.each { |method, tag| assert_equal(tag, eval(method)) }
end
def test_image_tag
ImageLinkToTag.each { |method, tag| assert_equal(tag, eval(method)) }
end
end