fix time_tag helper and update tests to not rely on dynamically generated values
Before `time_tag Date.today` will return `<time datetime="2013-02-14T00:00:00+00:00">February 14, 2013</time>`. This commit fixes time_tag helper to use RFC-3339 full-date format (Y-m-d) in datetime attribute.
This commit is contained in:
parent
c3f1b1d3cd
commit
e8e92c7264
|
@ -651,7 +651,7 @@ module ActionView
|
|||
options = args.extract_options!
|
||||
format = options.delete(:format) || :long
|
||||
content = args.first || I18n.l(date_or_time, :format => format)
|
||||
datetime = date_or_time.acts_like?(:time) ? date_or_time.xmlschema : date_or_time.rfc3339
|
||||
datetime = date_or_time.acts_like?(:time) ? date_or_time.xmlschema : date_or_time.iso8601
|
||||
|
||||
content_tag(:time, content, options.reverse_merge(:datetime => datetime), &block)
|
||||
end
|
||||
|
|
|
@ -3160,14 +3160,14 @@ class DateHelperTest < ActionView::TestCase
|
|||
end
|
||||
|
||||
def test_time_tag_with_date
|
||||
date = Date.today
|
||||
expected = "<time datetime=\"#{date.rfc3339}\">#{I18n.l(date, :format => :long)}</time>"
|
||||
date = Date.new(2013, 2, 20)
|
||||
expected = '<time datetime="2013-02-20">February 20, 2013</time>'
|
||||
assert_equal expected, time_tag(date)
|
||||
end
|
||||
|
||||
def test_time_tag_with_time
|
||||
time = Time.now
|
||||
expected = "<time datetime=\"#{time.xmlschema}\">#{I18n.l(time, :format => :long)}</time>"
|
||||
time = Time.new(2013, 2, 20, 0, 0, 0, '+00:00')
|
||||
expected = '<time datetime="2013-02-20T00:00:00+00:00">February 20, 2013 00:00</time>'
|
||||
assert_equal expected, time_tag(time)
|
||||
end
|
||||
|
||||
|
@ -3184,8 +3184,8 @@ class DateHelperTest < ActionView::TestCase
|
|||
end
|
||||
|
||||
def test_time_tag_with_different_format
|
||||
time = Time.now
|
||||
expected = "<time datetime=\"#{time.xmlschema}\">#{I18n.l(time, :format => :short)}</time>"
|
||||
time = Time.new(2013, 2, 20, 0, 0, 0, '+00:00')
|
||||
expected = '<time datetime="2013-02-20T00:00:00+00:00">20 Feb 00:00</time>'
|
||||
assert_equal expected, time_tag(time, :format => :short)
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue