From 8cbeec773ffce82dd521469ac37625630ed00701 Mon Sep 17 00:00:00 2001 From: Mike Stone Date: Mon, 2 Feb 2015 11:42:19 -0500 Subject: [PATCH] image_tag raises an error if size is passed with height and/or width --- actionview/lib/action_view/helpers/asset_tag_helper.rb | 7 +++++++ actionview/test/template/asset_tag_helper_test.rb | 8 ++++++++ 2 files changed, 15 insertions(+) diff --git a/actionview/lib/action_view/helpers/asset_tag_helper.rb b/actionview/lib/action_view/helpers/asset_tag_helper.rb index 60fc9ee1a2..e32f8e219e 100644 --- a/actionview/lib/action_view/helpers/asset_tag_helper.rb +++ b/actionview/lib/action_view/helpers/asset_tag_helper.rb @@ -207,6 +207,7 @@ def favicon_link_tag(source='favicon.ico', options={}) # # => Icon def image_tag(source, options={}) options = options.symbolize_keys + check_for_image_tag_errors(options) src = options[:src] = path_to_image(source) @@ -325,6 +326,12 @@ def extract_dimensions(size) [size, size] end end + + def check_for_image_tag_errors(options) + if options[:size] && (options[:height] || options[:width]) + raise ArgumentError, "Cannot pass a :size option with a :height or :width option" + end + end end end end diff --git a/actionview/test/template/asset_tag_helper_test.rb b/actionview/test/template/asset_tag_helper_test.rb index 02dce71496..6e6ce20924 100644 --- a/actionview/test/template/asset_tag_helper_test.rb +++ b/actionview/test/template/asset_tag_helper_test.rb @@ -464,6 +464,14 @@ def test_image_tag_does_not_modify_options assert_equal({:size => '16x10'}, options) end + 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 + def test_favicon_link_tag FaviconLinkToTag.each { |method, tag| assert_dom_equal(tag, eval(method)) } end