Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Deprecate mime types lookup in auto_discovery_link_tag
Automatically handling mime types for things other than :rss and :atom
is not functionality that justifies dependency on Mime::Type from
actionpack.
  • Loading branch information
drogus committed Aug 28, 2012
1 parent 9e731f0 commit 7abc0c7
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
8 changes: 8 additions & 0 deletions actionpack/lib/action_view/helpers/asset_tag_helper.rb
Expand Up @@ -222,6 +222,14 @@ module AssetTagHelper
# auto_discovery_link_tag(:rss, "http://www.example.com/feed.rss", {:title => "Example RSS"})
# # => <link rel="alternate" type="application/rss+xml" title="Example RSS" href="http://www.example.com/feed" />
def auto_discovery_link_tag(type = :rss, url_options = {}, tag_options = {})
if !(type == :rss || type == :atom) && tag_options[:type].blank?
message = "You have passed type other than :rss or :atom to auto_discovery_link_tag and haven't supplied " +
"the :type option key. This behavior is deprecated and will be remove in Rails 4.1. You should pass " +
":type option explicitly if you want to use other types, for example: " +
"auto_discovery_link_tag(:xml, '/feed.xml', :type => 'application/xml')"
ActiveSupport::Deprecation.warn message
end

tag(
"link",
"rel" => tag_options[:rel] || "alternate",
Expand Down
11 changes: 10 additions & 1 deletion actionpack/test/template/asset_tag_helper_test.rb
Expand Up @@ -65,7 +65,6 @@ def teardown
%(auto_discovery_link_tag) => %(<link href="http://www.example.com" rel="alternate" title="RSS" type="application/rss+xml" />),
%(auto_discovery_link_tag(:rss)) => %(<link href="http://www.example.com" rel="alternate" title="RSS" type="application/rss+xml" />),
%(auto_discovery_link_tag(:atom)) => %(<link href="http://www.example.com" rel="alternate" title="ATOM" type="application/atom+xml" />),
%(auto_discovery_link_tag(:xml)) => %(<link href="http://www.example.com" rel="alternate" title="XML" type="application/xml" />),
%(auto_discovery_link_tag(:rss, :action => "feed")) => %(<link href="http://www.example.com" rel="alternate" title="RSS" type="application/rss+xml" />),
%(auto_discovery_link_tag(:rss, "http://localhost/feed")) => %(<link href="http://localhost/feed" rel="alternate" title="RSS" type="application/rss+xml" />),
%(auto_discovery_link_tag(:rss, "//localhost/feed")) => %(<link href="//localhost/feed" rel="alternate" title="RSS" type="application/rss+xml" />),
Expand Down Expand Up @@ -299,6 +298,16 @@ def teardown
%(audio_tag(["audio.mp3", "audio.ogg"], :autobuffer => true, :controls => true)) => %(<audio autobuffer="autobuffer" controls="controls"><source src="/audios/audio.mp3" /><source src="/audios/audio.ogg" /></audio>)
}

def test_autodiscovery_link_tag_deprecated_types
result = nil
assert_deprecated do
result = auto_discovery_link_tag(:xml)
end

expected = %(<link href="http://www.example.com" rel="alternate" title="XML" type="application/xml" />)
assert_equal expected, result
end

def test_auto_discovery_link_tag
AutoDiscoveryToTag.each { |method, tag| assert_dom_equal(tag, eval(method)) }
end
Expand Down

0 comments on commit 7abc0c7

Please sign in to comment.