From 1aff7725c7a04cde202cca906208560a55409e6a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Mendon=C3=A7a=20Fran=C3=A7a?= Date: Sun, 13 May 2012 19:49:24 -0300 Subject: [PATCH] Deprecate `:mouseover` options for `image_tag` helper. --- actionpack/CHANGELOG.md | 2 + .../action_view/helpers/asset_tag_helper.rb | 2 + .../test/template/asset_tag_helper_test.rb | 48 +++++++++++++++---- 3 files changed, 44 insertions(+), 8 deletions(-) diff --git a/actionpack/CHANGELOG.md b/actionpack/CHANGELOG.md index 4acd39eb7251a..815810c05accf 100644 --- a/actionpack/CHANGELOG.md +++ b/actionpack/CHANGELOG.md @@ -1,5 +1,7 @@ ## Rails 3.2.4 (unreleased) ## +* Deprecate `:mouseover` options for `image_tag` helper. *Rafael Mendonça França* + * Deprecate `button_to_function` and `link_to_function` helpers. *Rafael Mendonça França* diff --git a/actionpack/lib/action_view/helpers/asset_tag_helper.rb b/actionpack/lib/action_view/helpers/asset_tag_helper.rb index 4ee7d7c9c99f9..ccba30eaa44d3 100644 --- a/actionpack/lib/action_view/helpers/asset_tag_helper.rb +++ b/actionpack/lib/action_view/helpers/asset_tag_helper.rb @@ -367,6 +367,8 @@ def image_tag(source, options = {}) end if mouseover = options.delete(:mouseover) + ActiveSupport::Deprecation.warn ":mouseover options is deprecated and will be removed from Rails 4.0" + options[:onmouseover] = "this.src='#{path_to_image(mouseover)}'" options[:onmouseout] = "this.src='#{src}'" end diff --git a/actionpack/test/template/asset_tag_helper_test.rb b/actionpack/test/template/asset_tag_helper_test.rb index cb56090d79677..adc13f0be6784 100644 --- a/actionpack/test/template/asset_tag_helper_test.rb +++ b/actionpack/test/template/asset_tag_helper_test.rb @@ -162,8 +162,6 @@ def teardown %(image_tag(".pdf.png")) => %(.pdf), %(image_tag("http://www.rubyonrails.com/images/rails.png")) => %(Rails), %(image_tag("//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), %(image_tag("mouse.png", :alt => nil)) => %(), %(image_tag("data:image/gif;base64,R0lGODlhAQABAID/AMDAwAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==", :alt => nil)) => %(), } @@ -442,6 +440,22 @@ def test_image_tag ImageLinkToTag.each { |method, tag| assert_dom_equal(tag, eval(method)) } end + def test_image_tag_with_mouseover + assert_deprecated ":mouseover options is deprecated and will be removed from Rails 4.0" do + assert_dom_equal( + %(Mouse), + image_tag("mouse.png", :mouseover => "/images/mouse_over.png") + ) + end + + assert_deprecated ":mouseover options is deprecated and will be removed from Rails 4.0" do + assert_dom_equal( + %(Mouse), + image_tag("mouse.png", :mouseover => image_path("mouse_over.png")) + ) + end + end + def test_favicon_link_tag FaviconLinkToTag.each { |method, tag| assert_dom_equal(tag, eval(method)) } end @@ -1096,8 +1110,14 @@ def test_should_compute_proper_path assert_dom_equal(%(/collaboration/hieraki/javascripts/xmlhr.js), javascript_path("xmlhr")) assert_dom_equal(%(/collaboration/hieraki/stylesheets/style.css), stylesheet_path("style")) assert_dom_equal(%(/collaboration/hieraki/images/xml.png), image_path("xml.png")) - assert_dom_equal(%(Mouse), image_tag("mouse.png", :mouseover => "/images/mouse_over.png")) - assert_dom_equal(%(Mouse2), image_tag("mouse2.png", :mouseover => image_path("mouse_over2.png"))) + + assert_deprecated ":mouseover options is deprecated and will be removed from Rails 4.0" do + assert_dom_equal(%(Mouse), image_tag("mouse.png", :mouseover => "/images/mouse_over.png")) + end + + assert_deprecated ":mouseover options is deprecated and will be removed from Rails 4.0" do + assert_dom_equal(%(Mouse2), image_tag("mouse2.png", :mouseover => image_path("mouse_over2.png"))) + end end def test_should_ignore_relative_root_path_on_complete_url @@ -1110,8 +1130,14 @@ def test_should_compute_proper_path_with_asset_host assert_dom_equal(%(gopher://assets.example.com/collaboration/hieraki/javascripts/xmlhr.js), javascript_path("xmlhr")) assert_dom_equal(%(gopher://assets.example.com/collaboration/hieraki/stylesheets/style.css), stylesheet_path("style")) assert_dom_equal(%(gopher://assets.example.com/collaboration/hieraki/images/xml.png), image_path("xml.png")) - assert_dom_equal(%(Mouse), image_tag("mouse.png", :mouseover => "/images/mouse_over.png")) - assert_dom_equal(%(Mouse2), image_tag("mouse2.png", :mouseover => image_path("mouse_over2.png"))) + + assert_deprecated ":mouseover options is deprecated and will be removed from Rails 4.0" do + assert_dom_equal(%(Mouse), image_tag("mouse.png", :mouseover => "/images/mouse_over.png")) + end + + assert_deprecated ":mouseover options is deprecated and will be removed from Rails 4.0" do + assert_dom_equal(%(Mouse2), image_tag("mouse2.png", :mouseover => image_path("mouse_over2.png"))) + end end def test_should_compute_proper_path_with_asset_host_and_default_protocol @@ -1120,8 +1146,14 @@ def test_should_compute_proper_path_with_asset_host_and_default_protocol assert_dom_equal(%(gopher://assets.example.com/collaboration/hieraki/javascripts/xmlhr.js), javascript_path("xmlhr")) assert_dom_equal(%(gopher://assets.example.com/collaboration/hieraki/stylesheets/style.css), stylesheet_path("style")) assert_dom_equal(%(gopher://assets.example.com/collaboration/hieraki/images/xml.png), image_path("xml.png")) - assert_dom_equal(%(Mouse), image_tag("mouse.png", :mouseover => "/images/mouse_over.png")) - assert_dom_equal(%(Mouse2), image_tag("mouse2.png", :mouseover => image_path("mouse_over2.png"))) + + assert_deprecated ":mouseover options is deprecated and will be removed from Rails 4.0" do + assert_dom_equal(%(Mouse), image_tag("mouse.png", :mouseover => "/images/mouse_over.png")) + end + + assert_deprecated ":mouseover options is deprecated and will be removed from Rails 4.0" do + assert_dom_equal(%(Mouse2), image_tag("mouse2.png", :mouseover => image_path("mouse_over2.png"))) + end end def test_should_ignore_asset_host_on_complete_url