1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Keep to_formatted_s working as before and add tests for it

This commit is contained in:
Rafael Mendonça França 2022-02-08 16:22:35 +00:00
parent d61ab614c2
commit 0dfcd54052
No known key found for this signature in database
GPG key ID: FC23B6D0F1EEE948
13 changed files with 21 additions and 21 deletions

View file

@ -87,7 +87,7 @@ module ActiveRecord
delegate :to_xml, :encode_with, :length, :each, :join, delegate :to_xml, :encode_with, :length, :each, :join,
:[], :&, :|, :+, :-, :sample, :reverse, :rotate, :compact, :in_groups, :in_groups_of, :[], :&, :|, :+, :-, :sample, :reverse, :rotate, :compact, :in_groups, :in_groups_of,
:to_sentence, :to_fs, :as_json, :to_sentence, :to_fs, :to_formatted_s, :as_json,
:shuffle, :split, :slice, :index, :rindex, to: :records :shuffle, :split, :slice, :index, :rindex, to: :records
delegate :primary_key, :connection, to: :klass delegate :primary_key, :connection, to: :klass

View file

@ -13,7 +13,7 @@ module ActiveRecord
:map, :none?, :one?, :partition, :reject, :reverse, :rotate, :map, :none?, :one?, :partition, :reject, :reverse, :rotate,
:sample, :second, :sort, :sort_by, :slice, :third, :index, :rindex, :sample, :second, :sort, :sort_by, :slice, :third, :index, :rindex,
:to_ary, :to_set, :to_xml, :to_yaml, :join, :to_ary, :to_set, :to_xml, :to_yaml, :join,
:in_groups, :in_groups_of, :to_sentence, :to_fs, :as_json :in_groups, :in_groups_of, :to_sentence, :to_formatted_s, :to_fs, :as_json
] ]
ARRAY_DELEGATES.each do |method| ARRAY_DELEGATES.each do |method|

View file

@ -26,8 +26,8 @@ class Date
# #
# date = Date.new(2007, 11, 10) # => Sat, 10 Nov 2007 # date = Date.new(2007, 11, 10) # => Sat, 10 Nov 2007
# #
# date.to_fs(:db) # => "2007-11-10"
# date.to_fs(:db) # => "2007-11-10" # date.to_fs(:db) # => "2007-11-10"
# date.to_formatted_s(:db) # => "2007-11-10"
# #
# date.to_fs(:short) # => "10 Nov" # date.to_fs(:short) # => "10 Nov"
# date.to_fs(:number) # => "20071110" # date.to_fs(:number) # => "20071110"

View file

@ -15,7 +15,7 @@ class DateTime
# datetime = DateTime.civil(2007, 12, 4, 0, 0, 0, 0) # => Tue, 04 Dec 2007 00:00:00 +0000 # datetime = DateTime.civil(2007, 12, 4, 0, 0, 0, 0) # => Tue, 04 Dec 2007 00:00:00 +0000
# #
# datetime.to_fs(:db) # => "2007-12-04 00:00:00" # datetime.to_fs(:db) # => "2007-12-04 00:00:00"
# datetime.to_fs(:db) # => "2007-12-04 00:00:00" # datetime.to_formatted_s(:db) # => "2007-12-04 00:00:00"
# datetime.to_fs(:number) # => "20071204000000" # datetime.to_fs(:number) # => "20071204000000"
# datetime.to_fs(:short) # => "04 Dec 00:00" # datetime.to_fs(:short) # => "04 Dec 00:00"
# datetime.to_fs(:long) # => "December 04, 2007 00:00" # datetime.to_fs(:long) # => "December 04, 2007 00:00"

View file

@ -31,8 +31,8 @@ class Time
# #
# time = Time.now # => 2007-01-18 06:10:17 -06:00 # time = Time.now # => 2007-01-18 06:10:17 -06:00
# #
# time.to_fs(:time) # => "06:10"
# time.to_fs(:time) # => "06:10" # time.to_fs(:time) # => "06:10"
# time.to_formatted_s(:time) # => "06:10"
# #
# time.to_fs(:db) # => "2007-01-18 06:10:17" # time.to_fs(:db) # => "2007-01-18 06:10:17"
# time.to_fs(:number) # => "20070118061017" # time.to_fs(:number) # => "20070118061017"

View file

@ -33,7 +33,7 @@ module ActiveSupport
# t.dst? # => true # t.dst? # => true
# t.utc_offset # => -14400 # t.utc_offset # => -14400
# t.zone # => "EDT" # t.zone # => "EDT"
# t.to_fs(:rfc822) # => "Sun, 18 May 2008 13:27:25 -0400" # t.to_fs(:rfc822) # => "Sun, 18 May 2008 13:27:25 -0400"
# t + 1.day # => Mon, 19 May 2008 13:27:25.031505668 EDT -04:00 # t + 1.day # => Mon, 19 May 2008 13:27:25.031505668 EDT -04:00
# t.beginning_of_year # => Tue, 01 Jan 2008 00:00:00.000000000 EST -05:00 # t.beginning_of_year # => Tue, 01 Jan 2008 00:00:00.000000000 EST -05:00
# t > Time.utc(1999) # => true # t > Time.utc(1999) # => true

View file

@ -116,8 +116,8 @@ class ToSTest < ActiveSupport::TestCase
assert_equal "null", [].to_fs(:db) assert_equal "null", [].to_fs(:db)
assert_equal "1,2,3", collection.to_fs(:db) assert_equal "1,2,3", collection.to_fs(:db)
assert_equal "null", [].to_fs(:db) assert_equal "null", [].to_formatted_s(:db)
assert_equal "4,5,6", collection.to_fs(:db) assert_equal "4,5,6", collection.to_formatted_s(:db)
end end
end end

View file

@ -88,7 +88,7 @@ class DateExtCalculationsTest < ActiveSupport::TestCase
assert_equal "2005-02-21", date.to_fs(:inspect) assert_equal "2005-02-21", date.to_fs(:inspect)
assert_equal "21 Feb 2005", date.to_fs(:rfc822) assert_equal "21 Feb 2005", date.to_fs(:rfc822)
assert_equal "2005-02-21", date.to_fs(:iso8601) assert_equal "2005-02-21", date.to_fs(:iso8601)
assert_equal "21 Feb", date.to_fs(:short) assert_equal "21 Feb", date.to_formatted_s(:short)
end end
def test_to_fs_with_single_digit_day def test_to_fs_with_single_digit_day

View file

@ -72,7 +72,7 @@ class DateTimeExtCalculationsTest < ActiveSupport::TestCase
assert_equal "2009-02-05T14:30:05+00:00", DateTime.civil(2009, 2, 5, 14, 30, 5).to_fs(:iso8601) assert_equal "2009-02-05T14:30:05+00:00", DateTime.civil(2009, 2, 5, 14, 30, 5).to_fs(:iso8601)
end end
assert_equal "2005-02-21 14:30:00", datetime.to_fs(:db) assert_equal "2005-02-21 14:30:00", datetime.to_formatted_s(:db)
end end
def test_readable_inspect def test_readable_inspect

View file

@ -162,7 +162,7 @@ class NumericExtFormattingTest < ActiveSupport::TestCase
assert_equal("555-1234", 5551234.to_s(:phone)) assert_equal("555-1234", 5551234.to_s(:phone))
end end
assert_equal("555-1234", 5551234.to_fs(:phone)) assert_equal("555-1234", 5551234.to_fs(:phone))
assert_equal("555-1234", 5551234.to_fs(:phone)) assert_equal("555-1234", 5551234.to_formatted_s(:phone))
assert_equal("800-555-1212", 8005551212.to_fs(:phone)) assert_equal("800-555-1212", 8005551212.to_fs(:phone))
assert_equal("(800) 555-1212", 8005551212.to_fs(:phone, area_code: true)) assert_equal("(800) 555-1212", 8005551212.to_fs(:phone, area_code: true))
assert_equal("800 555 1212", 8005551212.to_fs(:phone, delimiter: " ")) assert_equal("800 555 1212", 8005551212.to_fs(:phone, delimiter: " "))
@ -180,7 +180,7 @@ class NumericExtFormattingTest < ActiveSupport::TestCase
assert_equal("$1,234,567,890.50", 1234567890.50.to_s(:currency)) assert_equal("$1,234,567,890.50", 1234567890.50.to_s(:currency))
end end
assert_equal("$1,234,567,890.50", 1234567890.50.to_fs(:currency)) assert_equal("$1,234,567,890.50", 1234567890.50.to_fs(:currency))
assert_equal("$1,234,567,890.50", 1234567890.50.to_fs(:currency)) assert_equal("$1,234,567,890.50", 1234567890.50.to_formatted_s(:currency))
assert_equal("$1,234,567,890.51", 1234567890.506.to_fs(:currency)) assert_equal("$1,234,567,890.51", 1234567890.506.to_fs(:currency))
assert_equal("-$1,234,567,890.50", -1234567890.50.to_fs(:currency)) assert_equal("-$1,234,567,890.50", -1234567890.50.to_fs(:currency))
assert_equal("-$ 1,234,567,890.50", -1234567890.50.to_fs(:currency, format: "%u %n")) assert_equal("-$ 1,234,567,890.50", -1234567890.50.to_fs(:currency, format: "%u %n"))
@ -196,7 +196,7 @@ class NumericExtFormattingTest < ActiveSupport::TestCase
assert_equal("-111.235", -111.2346.to_s(:rounded)) assert_equal("-111.235", -111.2346.to_s(:rounded))
end end
assert_equal("-111.235", -111.2346.to_fs(:rounded)) assert_equal("-111.235", -111.2346.to_fs(:rounded))
assert_equal("-111.235", -111.2346.to_fs(:rounded)) assert_equal("-111.235", -111.2346.to_formatted_s(:rounded))
assert_equal("111.235", 111.2346.to_fs(:rounded)) assert_equal("111.235", 111.2346.to_fs(:rounded))
assert_equal("31.83", 31.825.to_fs(:rounded, precision: 2)) assert_equal("31.83", 31.825.to_fs(:rounded, precision: 2))
assert_equal("31.82", 31.825.to_fs(:rounded, precision: 2, round_mode: :down)) assert_equal("31.82", 31.825.to_fs(:rounded, precision: 2, round_mode: :down))
@ -259,7 +259,7 @@ class NumericExtFormattingTest < ActiveSupport::TestCase
assert_equal("100.000%", 100.to_s(:percentage)) assert_equal("100.000%", 100.to_s(:percentage))
end end
assert_equal("100.000%", 100.to_fs(:percentage)) assert_equal("100.000%", 100.to_fs(:percentage))
assert_equal("100.000%", 100.to_fs(:percentage)) assert_equal("100.000%", 100.to_formatted_s(:percentage))
assert_equal("100%", 100.to_fs(:percentage, precision: 0)) assert_equal("100%", 100.to_fs(:percentage, precision: 0))
assert_equal("302.06%", 302.0574.to_fs(:percentage, precision: 2)) assert_equal("302.06%", 302.0574.to_fs(:percentage, precision: 2))
assert_equal("302.05%", 302.0574.to_fs(:percentage, precision: 2, round_mode: :down)) assert_equal("302.05%", 302.0574.to_fs(:percentage, precision: 2, round_mode: :down))
@ -273,7 +273,7 @@ class NumericExtFormattingTest < ActiveSupport::TestCase
assert_equal("12,345,678", 12345678.to_s(:delimited)) assert_equal("12,345,678", 12345678.to_s(:delimited))
end end
assert_equal("12,345,678", 12345678.to_fs(:delimited)) assert_equal("12,345,678", 12345678.to_fs(:delimited))
assert_equal("12,345,678", 12345678.to_fs(:delimited)) assert_equal("12,345,678", 12345678.to_formatted_s(:delimited))
assert_equal("0", 0.to_fs(:delimited)) assert_equal("0", 0.to_fs(:delimited))
assert_equal("123", 123.to_fs(:delimited)) assert_equal("123", 123.to_fs(:delimited))
assert_equal("123,456", 123456.to_fs(:delimited)) assert_equal("123,456", 123456.to_fs(:delimited))
@ -348,7 +348,7 @@ class NumericExtFormattingTest < ActiveSupport::TestCase
assert_equal "-123", -123.to_s(:human) assert_equal "-123", -123.to_s(:human)
end end
assert_equal "-123", -123.to_fs(:human) assert_equal "-123", -123.to_fs(:human)
assert_equal "-123", -123.to_fs(:human) assert_equal "-123", -123.to_formatted_s(:human)
assert_equal "-0.5", -0.5.to_fs(:human) assert_equal "-0.5", -0.5.to_fs(:human)
assert_equal "0", 0.to_fs(:human) assert_equal "0", 0.to_fs(:human)
assert_equal "0.5", 0.5.to_fs(:human) assert_equal "0.5", 0.5.to_fs(:human)
@ -420,7 +420,7 @@ class NumericExtFormattingTest < ActiveSupport::TestCase
assert_equal "123", 123.to_s(:invalid) assert_equal "123", 123.to_s(:invalid)
end end
assert_equal "123", 123.to_fs(:invalid) assert_equal "123", 123.to_fs(:invalid)
assert_equal "123", 123.to_fs(:invalid) assert_equal "123", 123.to_formatted_s(:invalid)
assert_equal "2.5", 2.5.to_fs(:invalid) assert_equal "2.5", 2.5.to_fs(:invalid)
assert_equal "100000000000000000000", (100**10).to_fs(:invalid) assert_equal "100000000000000000000", (100**10).to_fs(:invalid)
assert_equal "1000010.0", BigDecimal("1000010").to_fs(:invalid) assert_equal "1000010.0", BigDecimal("1000010").to_fs(:invalid)
@ -429,7 +429,7 @@ class NumericExtFormattingTest < ActiveSupport::TestCase
def test_default_to_fs def test_default_to_fs
assert_equal "123", 123.to_s assert_equal "123", 123.to_s
assert_equal "123", 123.to_fs assert_equal "123", 123.to_fs
assert_equal "123", 123.to_fs assert_equal "123", 123.to_formatted_s
assert_equal "1111011", 123.to_s(2) assert_equal "1111011", 123.to_s(2)
assert_equal "1111011", 123.to_fs(2) assert_equal "1111011", 123.to_fs(2)

View file

@ -9,7 +9,7 @@ class RangeTest < ActiveSupport::TestCase
def test_to_fs_from_dates def test_to_fs_from_dates
date_range = Date.new(2005, 12, 10)..Date.new(2005, 12, 12) date_range = Date.new(2005, 12, 10)..Date.new(2005, 12, 12)
assert_equal "BETWEEN '2005-12-10' AND '2005-12-12'", date_range.to_fs(:db) assert_equal "BETWEEN '2005-12-10' AND '2005-12-12'", date_range.to_fs(:db)
assert_equal "BETWEEN '2005-12-10' AND '2005-12-12'", date_range.to_fs(:db) assert_equal "BETWEEN '2005-12-10' AND '2005-12-12'", date_range.to_formatted_s(:db)
end end
def test_to_fs_from_times def test_to_fs_from_times

View file

@ -667,7 +667,7 @@ class TimeExtCalculationsTest < ActiveSupport::TestCase
assert_equal "2008-06-09 04:05:01.000000000 -0500", Time.local(2008, 6, 9, 4, 5, 1).to_fs(:inspect) assert_equal "2008-06-09 04:05:01.000000000 -0500", Time.local(2008, 6, 9, 4, 5, 1).to_fs(:inspect)
end end
assert_equal "2005-02-21 17:44:30", time.to_fs(:db) assert_equal "2005-02-21 17:44:30", time.to_formatted_s(:db)
end end
def test_to_s_custom_date_format def test_to_s_custom_date_format

View file

@ -139,7 +139,7 @@ class TimeWithZoneTest < ActiveSupport::TestCase
def test_to_fs_db def test_to_fs_db
assert_equal "2000-01-01 00:00:00", @twz.to_fs(:db) assert_equal "2000-01-01 00:00:00", @twz.to_fs(:db)
assert_equal "2000-01-01 00:00:00", @twz.to_fs(:db) assert_equal "2000-01-01 00:00:00", @twz.to_formatted_s(:db)
end end
def test_to_fs_inspect def test_to_fs_inspect