class AssetTagHelperTest

Constants

AssetPathToTag
AudioLinkToTag
AudioPathToTag
AudioUrlToTag
AutoDiscoveryToTag
FaviconLinkToTag
FontPathToTag
ImageLinkToTag
ImagePathToTag
ImageUrlToTag
JavascriptIncludeToTag
JavascriptPathToTag
JavascriptUrlToTag
PathToAudioToTag
PathToImageToTag
PathToJavascriptToTag
PathToStyleToTag
PathToVideoToTag
StyleLinkToTag
StylePathToTag
StyleUrlToTag
UrlToAudioToTag
UrlToImageToTag
UrlToJavascriptToTag
UrlToStyleToTag
UrlToVideoToTag
VideoLinkToTag
VideoPathToTag
VideoUrlToTag

Attributes

request[R]

Public Instance Methods

base_url() click to toggle source
# File actionview/test/template/asset_tag_helper_test.rb, line 21
def base_url() "http://www.example.com" end
host_with_port() click to toggle source
# File actionview/test/template/asset_tag_helper_test.rb, line 20
def host_with_port() "localhost" end
protocol() click to toggle source
# File actionview/test/template/asset_tag_helper_test.rb, line 18
def protocol() "http://" end
setup() click to toggle source
Calls superclass method
# File actionview/test/template/asset_tag_helper_test.rb, line 11
def setup
  super

  @controller = BasicController.new

  @request = Class.new do
    attr_accessor :script_name
    def protocol() "http://" end
    def ssl?() false end
    def host_with_port() "localhost" end
    def base_url() "http://www.example.com" end
  end.new

  @controller.request = @request
end
ssl?() click to toggle source
# File actionview/test/template/asset_tag_helper_test.rb, line 19
def ssl?() false end
test_asset_path_tag() click to toggle source
# File actionview/test/template/asset_tag_helper_test.rb, line 320
def test_asset_path_tag
  AssetPathToTag.each { |method, tag| assert_dom_equal(tag, eval(method)) }
end
test_asset_path_tag_raises_an_error_for_nil_source() click to toggle source
# File actionview/test/template/asset_tag_helper_test.rb, line 324
def test_asset_path_tag_raises_an_error_for_nil_source
  e = assert_raise(ArgumentError) { asset_path(nil) }
  assert_equal("nil is not a valid asset source", e.message)
end
test_asset_path_tag_to_not_create_duplicate_slashes() click to toggle source
# File actionview/test/template/asset_tag_helper_test.rb, line 329
def test_asset_path_tag_to_not_create_duplicate_slashes
  @controller.config.asset_host = "host/"
  assert_dom_equal("http://host/foo", asset_path("foo"))

  @controller.config.relative_url_root = "/some/root/"
  assert_dom_equal("http://host/some/root/foo", asset_path("foo"))
end
test_audio_path() click to toggle source
# File actionview/test/template/asset_tag_helper_test.rb, line 526
def test_audio_path
  AudioPathToTag.each { |method, tag| assert_dom_equal(tag, eval(method)) }
end
test_audio_tag() click to toggle source
# File actionview/test/template/asset_tag_helper_test.rb, line 542
def test_audio_tag
  AudioLinkToTag.each { |method, tag| assert_dom_equal(tag, eval(method)) }
end
test_audio_url() click to toggle source
# File actionview/test/template/asset_tag_helper_test.rb, line 534
def test_audio_url
  AudioUrlToTag.each { |method, tag| assert_dom_equal(tag, eval(method)) }
end
test_caching_image_path_with_caching_and_proc_asset_host_using_request() click to toggle source
# File actionview/test/template/asset_tag_helper_test.rb, line 601
def test_caching_image_path_with_caching_and_proc_asset_host_using_request
  @controller.config.asset_host = Proc.new do |source, request|
    if request.ssl?
      "#{request.protocol}#{request.host_with_port}"
    else
      "#{request.protocol}assets#{source.length}.example.com"
    end
  end

  @controller.request.stub(:ssl?, false) do
    assert_equal "http://assets15.example.com/images/xml.png", image_path("xml.png")
  end

  @controller.request.stub(:ssl?, true) do
    assert_equal "http://localhost/images/xml.png", image_path("xml.png")
  end
end
test_compute_asset_public_path() click to toggle source
# File actionview/test/template/asset_tag_helper_test.rb, line 337
def test_compute_asset_public_path
  assert_equal "/robots.txt", compute_asset_path("robots.txt")
  assert_equal "/robots.txt", compute_asset_path("/robots.txt")
  assert_equal "/javascripts/foo.js", compute_asset_path("foo.js", type: :javascript)
  assert_equal "/javascripts/foo.js", compute_asset_path("/foo.js", type: :javascript)
  assert_equal "/stylesheets/foo.css", compute_asset_path("foo.css", type: :stylesheet)
end
test_font_path() click to toggle source
# File actionview/test/template/asset_tag_helper_test.rb, line 546
def test_font_path
  FontPathToTag.each { |method, tag| assert_dom_equal(tag, eval(method)) }
end
test_image_alt() click to toggle source
# File actionview/test/template/asset_tag_helper_test.rb, line 464
def test_image_alt
  [nil, "/", "/foo/bar/", "foo/bar/"].each do |prefix|
    assert_deprecated do
      assert_equal "Quails", image_alt("#{prefix}quails.png")
    end
    assert_deprecated do
      assert_equal "Quails", image_alt("#{prefix}quails-9c0a079bdd7701d7e729bd956823d153.png")
    end
    assert_deprecated do
      assert_equal "Quails", image_alt("#{prefix}quails-f56ef62bc41b040664e801a38f068082a75d506d9048307e8096737463503d0b.png")
    end
    assert_deprecated do
      assert_equal "Long file name with hyphens", image_alt("#{prefix}long-file-name-with-hyphens.png")
    end
    assert_deprecated do
      assert_equal "Long file name with underscores", image_alt("#{prefix}long_file_name_with_underscores.png")
    end
  end
end
test_image_path() click to toggle source
# File actionview/test/template/asset_tag_helper_test.rb, line 448
def test_image_path
  ImagePathToTag.each { |method, tag| assert_dom_equal(tag, eval(method)) }
end
test_image_path_with_asset_host_proc_returning_nil() click to toggle source
# File actionview/test/template/asset_tag_helper_test.rb, line 582
def test_image_path_with_asset_host_proc_returning_nil
  @controller.config.asset_host = Proc.new do |source|
    unless source.end_with?("tiff")
      "cdn.example.com"
    end
  end

  assert_equal "/images/file.tiff", image_path("file.tiff")
  assert_equal "http://cdn.example.com/images/file.png", image_path("file.png")
end
test_image_path_with_blank_placeholder() click to toggle source
# File actionview/test/template/asset_tag_helper_test.rb, line 578
def test_image_path_with_blank_placeholder
  assert_equal "/images/no-image-yet.png", image_path(PlaceholderImage.new)
end
test_image_tag() click to toggle source
# File actionview/test/template/asset_tag_helper_test.rb, line 484
def test_image_tag
  ImageLinkToTag.each { |method, tag| assert_dom_equal(tag, eval(method)) }
end
test_image_tag_does_not_modify_options() click to toggle source
# File actionview/test/template/asset_tag_helper_test.rb, line 488
def test_image_tag_does_not_modify_options
  options = { size: "16x10" }
  image_tag("icon", options)
  assert_equal({ size: "16x10" }, options)
end
test_image_tag_interpreting_email_adding_optional_alt_tag() click to toggle source
# File actionview/test/template/asset_tag_helper_test.rb, line 563
def test_image_tag_interpreting_email_adding_optional_alt_tag
  assert_equal '<img alt="Image" src="cid:thi%25%25sis@acontentid" />', image_tag("cid:thi%25%25sis@acontentid", alt: "Image")
end
test_image_tag_interpreting_email_cid_correctly() click to toggle source
# File actionview/test/template/asset_tag_helper_test.rb, line 558
def test_image_tag_interpreting_email_cid_correctly
  # An inline image has no need for an alt tag to be automatically generated from the cid:
  assert_equal '<img src="cid:thi%25%25sis@acontentid" />', image_tag("cid:thi%25%25sis@acontentid")
end
test_image_tag_raises_an_error_for_competing_size_arguments() click to toggle source
# File actionview/test/template/asset_tag_helper_test.rb, line 494
def test_image_tag_raises_an_error_for_competing_size_arguments
  exception = assert_raise(ArgumentError) do
    image_tag("gold.png", height: "100", width: "200", size: "45x70")
  end

  assert_equal("Cannot pass a :size option with a :height or :width option", exception.message)
end
test_image_url() click to toggle source
# File actionview/test/template/asset_tag_helper_test.rb, line 456
def test_image_url
  ImageUrlToTag.each { |method, tag| assert_dom_equal(tag, eval(method)) }
end
test_image_url_with_asset_host_proc_returning_nil() click to toggle source
# File actionview/test/template/asset_tag_helper_test.rb, line 593
def test_image_url_with_asset_host_proc_returning_nil
  @controller.config.asset_host = Proc.new { nil }
  @controller.request = Struct.new(:base_url, :script_name).new("http://www.example.com", nil)

  assert_equal "/images/quails.png", image_path("quails.png")
  assert_equal "http://www.example.com/images/quails.png", image_url("quails.png")
end
test_javascript_include_tag() click to toggle source
# File actionview/test/template/asset_tag_helper_test.rb, line 365
def test_javascript_include_tag
  JavascriptIncludeToTag.each { |method, tag| assert_dom_equal(tag, eval(method)) }
end
test_javascript_include_tag_default_protocol() click to toggle source
# File actionview/test/template/asset_tag_helper_test.rb, line 388
def test_javascript_include_tag_default_protocol
  @controller.config.asset_host = "assets.example.com"
  @controller.config.default_asset_host_protocol = :relative
  assert_dom_equal %(<script src="//assets.example.com/javascripts/prototype.js"></script>), javascript_include_tag("prototype")
end
test_javascript_include_tag_is_html_safe() click to toggle source
# File actionview/test/template/asset_tag_helper_test.rb, line 379
def test_javascript_include_tag_is_html_safe
  assert javascript_include_tag("prototype").html_safe?
end
test_javascript_include_tag_relative_protocol() click to toggle source
# File actionview/test/template/asset_tag_helper_test.rb, line 383
def test_javascript_include_tag_relative_protocol
  @controller.config.asset_host = "assets.example.com"
  assert_dom_equal %(<script src="//assets.example.com/javascripts/prototype.js"></script>), javascript_include_tag("prototype", protocol: :relative)
end
test_javascript_include_tag_with_missing_source() click to toggle source
# File actionview/test/template/asset_tag_helper_test.rb, line 369
def test_javascript_include_tag_with_missing_source
  assert_nothing_raised {
    javascript_include_tag("missing_security_guard")
  }

  assert_nothing_raised {
    javascript_include_tag("http://example.com/css/missing_security_guard")
  }
end
test_javascript_path() click to toggle source
# File actionview/test/template/asset_tag_helper_test.rb, line 349
def test_javascript_path
  JavascriptPathToTag.each { |method, tag| assert_dom_equal(tag, eval(method)) }
end
test_javascript_url() click to toggle source
# File actionview/test/template/asset_tag_helper_test.rb, line 357
def test_javascript_url
  JavascriptUrlToTag.each { |method, tag| assert_dom_equal(tag, eval(method)) }
end
test_path_to_audio_alias_for_audio_path() click to toggle source
# File actionview/test/template/asset_tag_helper_test.rb, line 530
def test_path_to_audio_alias_for_audio_path
  PathToAudioToTag.each { |method, tag| assert_dom_equal(tag, eval(method)) }
end
test_path_to_image_alias_for_image_path() click to toggle source
# File actionview/test/template/asset_tag_helper_test.rb, line 452
def test_path_to_image_alias_for_image_path
  PathToImageToTag.each { |method, tag| assert_dom_equal(tag, eval(method)) }
end
test_path_to_javascript_alias_for_javascript_path() click to toggle source
# File actionview/test/template/asset_tag_helper_test.rb, line 353
def test_path_to_javascript_alias_for_javascript_path
  PathToJavascriptToTag.each { |method, tag| assert_dom_equal(tag, eval(method)) }
end
test_path_to_stylesheet_alias_for_stylesheet_path() click to toggle source
# File actionview/test/template/asset_tag_helper_test.rb, line 398
def test_path_to_stylesheet_alias_for_stylesheet_path
  PathToStyleToTag.each { |method, tag| assert_dom_equal(tag, eval(method)) }
end
test_path_to_video_alias_for_video_path() click to toggle source
# File actionview/test/template/asset_tag_helper_test.rb, line 510
def test_path_to_video_alias_for_video_path
  PathToVideoToTag.each { |method, tag| assert_dom_equal(tag, eval(method)) }
end
test_should_not_modify_source_string() click to toggle source
# File actionview/test/template/asset_tag_helper_test.rb, line 567
def test_should_not_modify_source_string
  source = "/images/quails.png"
  copy = source.dup
  image_tag(source)
  assert_equal copy, source
end
test_stylesheet_path() click to toggle source
# File actionview/test/template/asset_tag_helper_test.rb, line 394
def test_stylesheet_path
  StylePathToTag.each { |method, tag| assert_dom_equal(tag, eval(method)) }
end
test_stylesheet_url() click to toggle source
# File actionview/test/template/asset_tag_helper_test.rb, line 402
def test_stylesheet_url
  StyleUrlToTag.each { |method, tag| assert_dom_equal(tag, eval(method)) }
end
test_url_to_audio_alias_for_audio_url() click to toggle source
# File actionview/test/template/asset_tag_helper_test.rb, line 538
def test_url_to_audio_alias_for_audio_url
  UrlToAudioToTag.each { |method, tag| assert_dom_equal(tag, eval(method)) }
end
test_url_to_image_alias_for_image_url() click to toggle source
# File actionview/test/template/asset_tag_helper_test.rb, line 460
def test_url_to_image_alias_for_image_url
  UrlToImageToTag.each { |method, tag| assert_dom_equal(tag, eval(method)) }
end
test_url_to_javascript_alias_for_javascript_url() click to toggle source
# File actionview/test/template/asset_tag_helper_test.rb, line 361
def test_url_to_javascript_alias_for_javascript_url
  UrlToJavascriptToTag.each { |method, tag| assert_dom_equal(tag, eval(method)) }
end
test_url_to_stylesheet_alias_for_stylesheet_url() click to toggle source
# File actionview/test/template/asset_tag_helper_test.rb, line 406
def test_url_to_stylesheet_alias_for_stylesheet_url
  UrlToStyleToTag.each { |method, tag| assert_dom_equal(tag, eval(method)) }
end
test_url_to_video_alias_for_video_url() click to toggle source
# File actionview/test/template/asset_tag_helper_test.rb, line 518
def test_url_to_video_alias_for_video_url
  UrlToVideoToTag.each { |method, tag| assert_dom_equal(tag, eval(method)) }
end
test_video_audio_tag_does_not_modify_options() click to toggle source
# File actionview/test/template/asset_tag_helper_test.rb, line 550
def test_video_audio_tag_does_not_modify_options
  options = { autoplay: true }
  video_tag("video", options)
  assert_equal({ autoplay: true }, options)
  audio_tag("audio", options)
  assert_equal({ autoplay: true }, options)
end
test_video_path() click to toggle source
# File actionview/test/template/asset_tag_helper_test.rb, line 506
def test_video_path
  VideoPathToTag.each { |method, tag| assert_dom_equal(tag, eval(method)) }
end
test_video_tag() click to toggle source
# File actionview/test/template/asset_tag_helper_test.rb, line 522
def test_video_tag
  VideoLinkToTag.each { |method, tag| assert_dom_equal(tag, eval(method)) }
end
test_video_url() click to toggle source
# File actionview/test/template/asset_tag_helper_test.rb, line 514
def test_video_url
  VideoUrlToTag.each { |method, tag| assert_dom_equal(tag, eval(method)) }
end
url_for(*args) click to toggle source
# File actionview/test/template/asset_tag_helper_test.rb, line 27
def url_for(*args)
  "http://www.example.com"
end