Skip to content
This repository
Browse code

Fixed image_tag so an exception is not thrown just because the image …

…is missing and alt value can't be generated #1395 [Marcel]

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1434 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
commit 89e06ed4c6191aff7769aeea8842f45df85acf89 1 parent a32303e
David Heinemeier Hansson authored June 16, 2005
2  actionpack/CHANGELOG
... ...
@@ -1,5 +1,7 @@
1 1
 *SVN*
2 2
 
  3
+* Fixed image_tag so an exception is not thrown just because the image is missing and alt value can't be generated #1395 [Marcel]
  4
+
3 5
 * Added a third parameter to TextHelper#auto_link called href_options for specifying additional tag options on the links generated #1401 [tyler.kovacs@gmail.com]. Example: auto_link(text, :all, { :target => "_blank" }) to have all the generated links open in a new window.
4 6
 
5 7
 * Fixed TextHelper#highlight to return the text, not nil, if the phrase is blank #1409 [patrick@lenz.sh]
2  actionpack/lib/action_view/helpers/asset_tag_helper.rb
@@ -95,7 +95,7 @@ def image_tag(source, options = {})
95 95
         options.symbolize_keys
96 96
                 
97 97
         options[:src] = image_path(source)
98  
-        options[:alt] ||= source.split("/").last.split(".").first.capitalize
  98
+        options[:alt] ||= File.basename(options[:src], '.*').split('.').first.capitalize
99 99
         
100 100
         if options[:size]
101 101
           options[:width], options[:height] = options[:size].split("x")
8  actionpack/test/template/asset_tag_helper_test.rb
@@ -166,16 +166,14 @@ def test_style_link
166 166
     StyleLinkToTag.each { |method, tag| assert_equal(tag, eval(method)) }
167 167
   end
168 168
 
169  
-  def test_image_tag
170  
-    assert_equal %(<img alt="Gold" height="70" src="/calloboration/hieraki/images/gold.png" width="45" />), image_tag("gold", :size => "45x70")
171  
-  end
172  
-
173 169
   def test_image_path
174 170
     ImagePathToTag.each { |method, tag| assert_equal(tag, eval(method)) }
175 171
   end
176 172
   
177 173
   def test_image_tag
178 174
     ImageLinkToTag.each { |method, tag| assert_equal(tag, eval(method)) }
  175
+    # Assigning a default alt tag should not cause an exception to be raised
  176
+    assert_nothing_raised { image_tag('') }
179 177
   end
180 178
   
181  
-end
  179
+end

0 notes on commit 89e06ed

Please sign in to comment.
Something went wrong with that request. Please try again.