require 'abstract_unit' require 'active_support/ordered_options' class FakeController attr_accessor :request def config @config ||= ActiveSupport::InheritableOptions.new(ActionController::Base.config) end end class AssetTagHelperTest < ActionView::TestCase tests ActionView::Helpers::AssetTagHelper def setup super silence_warnings do ActionView::Helpers::AssetTagHelper.send( :const_set, :JAVASCRIPTS_DIR, File.dirname(__FILE__) + "/../fixtures/public/javascripts" ) ActionView::Helpers::AssetTagHelper.send( :const_set, :STYLESHEETS_DIR, File.dirname(__FILE__) + "/../fixtures/public/stylesheets" ) ActionView::Helpers::AssetTagHelper.send( :const_set, :ASSETS_DIR, File.dirname(__FILE__) + "/../fixtures/public" ) end @controller = Class.new(BasicController) do def url_for(*args) "http://www.example.com" end end.new @request = Class.new do def protocol() 'http://' end def ssl?() false end def host_with_port() 'localhost' end end.new @controller.request = @request ActionView::Helpers::AssetTagHelper::reset_javascript_include_default end def teardown config.perform_caching = false ENV.delete('RAILS_ASSET_ID') end AutoDiscoveryToTag = { %(auto_discovery_link_tag) => %(), %(auto_discovery_link_tag(:rss)) => %(), %(auto_discovery_link_tag(:atom)) => %(), %(auto_discovery_link_tag(:xml)) => %(), %(auto_discovery_link_tag(:rss, :action => "feed")) => %(), %(auto_discovery_link_tag(:rss, "http://localhost/feed")) => %(), %(auto_discovery_link_tag(:rss, {:action => "feed"}, {:title => "My RSS"})) => %(), %(auto_discovery_link_tag(:rss, {}, {:title => "My RSS"})) => %(), %(auto_discovery_link_tag(nil, {}, {:type => "text/html"})) => %(), %(auto_discovery_link_tag(nil, {}, {:title => "No stream.. really", :type => "text/html"})) => %(), %(auto_discovery_link_tag(:rss, {}, {:title => "My RSS", :type => "text/html"})) => %(), %(auto_discovery_link_tag(:atom, {}, {:rel => "Not so alternate"})) => %(), } JavascriptPathToTag = { %(javascript_path("xmlhr")) => %(/javascripts/xmlhr.js), %(javascript_path("super/xmlhr")) => %(/javascripts/super/xmlhr.js), %(javascript_path("/super/xmlhr.js")) => %(/super/xmlhr.js) } PathToJavascriptToTag = { %(path_to_javascript("xmlhr")) => %(/javascripts/xmlhr.js), %(path_to_javascript("super/xmlhr")) => %(/javascripts/super/xmlhr.js), %(path_to_javascript("/super/xmlhr.js")) => %(/super/xmlhr.js) } JavascriptIncludeToTag = { %(javascript_include_tag("bank")) => %(), %(javascript_include_tag("bank.js")) => %(), %(javascript_include_tag("bank", :lang => "vbscript")) => %(), %(javascript_include_tag("common.javascript", "/elsewhere/cools")) => %(\n), %(javascript_include_tag(:defaults)) => %(\n\n\n\n\n), %(javascript_include_tag(:all)) => %(\n\n\n\n\n\n\n), %(javascript_include_tag(:all, :recursive => true)) => %(\n\n\n\n\n\n\n\n), %(javascript_include_tag(:defaults, "bank")) => %(\n\n\n\n\n\n), %(javascript_include_tag("bank", :defaults)) => %(\n\n\n\n\n\n), %(javascript_include_tag("http://example.com/all")) => %(), %(javascript_include_tag("http://example.com/all.js")) => %(), } StylePathToTag = { %(stylesheet_path("bank")) => %(/stylesheets/bank.css), %(stylesheet_path("bank.css")) => %(/stylesheets/bank.css), %(stylesheet_path('subdir/subdir')) => %(/stylesheets/subdir/subdir.css), %(stylesheet_path('/subdir/subdir.css')) => %(/subdir/subdir.css) } PathToStyleToTag = { %(path_to_stylesheet("style")) => %(/stylesheets/style.css), %(path_to_stylesheet("style.css")) => %(/stylesheets/style.css), %(path_to_stylesheet('dir/file')) => %(/stylesheets/dir/file.css), %(path_to_stylesheet('/dir/file.rcss')) => %(/dir/file.rcss) } StyleLinkToTag = { %(stylesheet_link_tag("bank")) => %(), %(stylesheet_link_tag("bank.css")) => %(), %(stylesheet_link_tag("/elsewhere/file")) => %(), %(stylesheet_link_tag("subdir/subdir")) => %(), %(stylesheet_link_tag("bank", :media => "all")) => %(), %(stylesheet_link_tag(:all)) => %(\n\n), %(stylesheet_link_tag(:all, :recursive => true)) => %(\n\n\n), %(stylesheet_link_tag(:all, :media => "all")) => %(\n\n), %(stylesheet_link_tag("random.styles", "/elsewhere/file")) => %(\n), %(stylesheet_link_tag("http://www.example.com/styles/style")) => %(), %(stylesheet_link_tag("http://www.example.com/styles/style.css")) => %(), } ImagePathToTag = { %(image_path("xml")) => %(/images/xml), %(image_path("xml.png")) => %(/images/xml.png), %(image_path("dir/xml.png")) => %(/images/dir/xml.png), %(image_path("/dir/xml.png")) => %(/dir/xml.png) } PathToImageToTag = { %(path_to_image("xml")) => %(/images/xml), %(path_to_image("xml.png")) => %(/images/xml.png), %(path_to_image("dir/xml.png")) => %(/images/dir/xml.png), %(path_to_image("/dir/xml.png")) => %(/dir/xml.png) } ImageLinkToTag = { %(image_tag("xml.png")) => %(Xml), %(image_tag("rss.gif", :alt => "rss syndication")) => %(rss syndication), %(image_tag("gold.png", :size => "45x70")) => %(Gold), %(image_tag("gold.png", "size" => "45x70")) => %(Gold), %(image_tag("error.png", "size" => "45")) => %(Error), %(image_tag("error.png", "size" => "45 x 70")) => %(Error), %(image_tag("error.png", "size" => "x")) => %(Error), %(image_tag("google.com.png")) => %(Google.com), %(image_tag("slash..png")) => %(Slash.), %(image_tag(".pdf.png")) => %(.pdf), %(image_tag("http://www.rubyonrails.com/images/rails.png")) => %(Rails), %(image_tag("mouse.png", :mouseover => "/images/mouse_over.png")) => %(Mouse), %(image_tag("mouse.png", :mouseover => image_path("mouse_over.png"))) => %(Mouse) } VideoPathToTag = { %(video_path("xml")) => %(/videos/xml), %(video_path("xml.ogg")) => %(/videos/xml.ogg), %(video_path("dir/xml.ogg")) => %(/videos/dir/xml.ogg), %(video_path("/dir/xml.ogg")) => %(/dir/xml.ogg) } PathToVideoToTag = { %(path_to_video("xml")) => %(/videos/xml), %(path_to_video("xml.ogg")) => %(/videos/xml.ogg), %(path_to_video("dir/xml.ogg")) => %(/videos/dir/xml.ogg), %(path_to_video("/dir/xml.ogg")) => %(/dir/xml.ogg) } VideoLinkToTag = { %(video_tag("xml.ogg")) => %(