mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Fixed tag_helper data-attribute bug with BigDecimals
This commit is contained in:
parent
6ada771a08
commit
56aabfd559
2 changed files with 5 additions and 4 deletions
|
@ -154,8 +154,9 @@ module ActionView
|
|||
|
||||
def data_tag_option(key, value, escape)
|
||||
key = "data-#{key.to_s.dasherize}"
|
||||
value = value.to_json if !value.is_a?(String) && !value.is_a?(Symbol)
|
||||
|
||||
unless value.is_a?(String) || value.is_a?(Symbol) || value.is_a?(BigDecimal)
|
||||
value = value.to_json
|
||||
end
|
||||
tag_option(key, value, escape)
|
||||
end
|
||||
|
||||
|
|
|
@ -118,8 +118,8 @@ class TagHelperTest < ActionView::TestCase
|
|||
|
||||
def test_data_attributes
|
||||
['data', :data].each { |data|
|
||||
assert_dom_equal '<a data-a-number="1" data-array="[1,2,3]" data-hash="{"key":"value"}" 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="{"key":"value"}" 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
|
||||
|
|
Loading…
Reference in a new issue