Permalink
Browse files

Fixed tag_helper data-attribute bug with BigDecimals

  • Loading branch information...
1 parent 6ef9fda commit 39b9c943b7ec5181c19461d319d8c610ea1bf941 @Bodacious Bodacious committed May 20, 2012
Showing with 3 additions and 3 deletions.
  1. +1 −1 actionpack/lib/action_view/helpers/tag_helper.rb
  2. +2 −2 actionpack/test/template/tag_helper_test.rb
@@ -138,7 +138,7 @@ def tag_options(options, escape = true)
options.each_pair do |key, value|
if key.to_s == 'data' && value.is_a?(Hash)
value.each do |k, v|
- if !v.is_a?(String) && !v.is_a?(Symbol)
+ unless v.is_a?(String) || v.is_a?(Symbol) || v.is_a?(BigDecimal)
v = v.to_json
end
v = ERB::Util.html_escape(v) if escape
@@ -113,8 +113,8 @@ def test_disable_escaping
def test_data_attributes
['data', :data].each { |data|
- assert_dom_equal '<a data-a-number="1" data-array="[1,2,3]" data-hash="{&quot;key&quot;:&quot;value&quot;}" data-string="hello" data-symbol="foo" />',
- tag('a', { data => { :a_number => 1, :string => 'hello', :symbol => :foo, :array => [1, 2, 3], :hash => { :key => 'value'} } })
+ assert_dom_equal '<a data-a-float="3.14" data-a-big-decimal="-123.456" data-a-number="1" data-array="[1,2,3]" data-hash="{&quot;key&quot;:&quot;value&quot;}" data-string="hello" data-symbol="foo" />',
+ tag('a', { data => { :a_float => 3.14, :a_big_decimal => BigDecimal.new("-123.456"), :a_number => 1, :string => 'hello', :symbol => :foo, :array => [1, 2, 3], :hash => { :key => 'value'} } })
}
end
end

0 comments on commit 39b9c94

Please sign in to comment.