mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Merge pull request #25296 from kamipo/use_inspect_for_type_cast_for_schema
Use `inspect` in `type_cast_for_schema` for date/time and decimal values
This commit is contained in:
commit
77d3550f60
4 changed files with 14 additions and 9 deletions
|
@ -12,7 +12,7 @@ module ActiveModel
|
|||
end
|
||||
|
||||
def type_cast_for_schema(value)
|
||||
"'#{value.to_s(:db)}'"
|
||||
value.to_s(:db).inspect
|
||||
end
|
||||
|
||||
private
|
||||
|
|
|
@ -38,7 +38,7 @@ module ActiveModel
|
|||
end
|
||||
|
||||
def type_cast_for_schema(value)
|
||||
"'#{value.to_s(:db)}'"
|
||||
value.to_s(:db).inspect
|
||||
end
|
||||
|
||||
def user_input_in_time_zone(value)
|
||||
|
|
|
@ -4,6 +4,10 @@ module ActiveRecord
|
|||
def type
|
||||
:decimal
|
||||
end
|
||||
|
||||
def type_cast_for_schema(value)
|
||||
value.to_s.inspect
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -422,11 +422,12 @@ class SchemaDumperDefaultsTest < ActiveRecord::TestCase
|
|||
|
||||
setup do
|
||||
@connection = ActiveRecord::Base.connection
|
||||
@connection.create_table :defaults, force: true do |t|
|
||||
@connection.create_table :dump_defaults, force: true do |t|
|
||||
t.string :string_with_default, default: "Hello!"
|
||||
t.date :date_with_default, default: "2014-06-05"
|
||||
t.datetime :datetime_with_default, default: "2014-06-05 07:17:04"
|
||||
t.time :time_with_default, default: "07:17:04"
|
||||
t.decimal :decimal_with_default, default: "1234567890.0123456789", precision: 20, scale: 10
|
||||
end
|
||||
|
||||
if current_adapter?(:PostgreSQLAdapter)
|
||||
|
@ -438,17 +439,17 @@ class SchemaDumperDefaultsTest < ActiveRecord::TestCase
|
|||
end
|
||||
|
||||
teardown do
|
||||
return unless @connection
|
||||
@connection.drop_table "defaults", if_exists: true
|
||||
@connection.drop_table "dump_defaults", if_exists: true
|
||||
end
|
||||
|
||||
def test_schema_dump_defaults_with_universally_supported_types
|
||||
output = dump_table_schema("defaults")
|
||||
output = dump_table_schema("dump_defaults")
|
||||
|
||||
assert_match %r{t\.string\s+"string_with_default",.*?default: "Hello!"}, output
|
||||
assert_match %r{t\.date\s+"date_with_default",\s+default: '2014-06-05'}, output
|
||||
assert_match %r{t\.datetime\s+"datetime_with_default",\s+default: '2014-06-05 07:17:04'}, output
|
||||
assert_match %r{t\.time\s+"time_with_default",\s+default: '2000-01-01 07:17:04'}, output
|
||||
assert_match %r{t\.date\s+"date_with_default",\s+default: "2014-06-05"}, output
|
||||
assert_match %r{t\.datetime\s+"datetime_with_default",\s+default: "2014-06-05 07:17:04"}, output
|
||||
assert_match %r{t\.time\s+"time_with_default",\s+default: "2000-01-01 07:17:04"}, output
|
||||
assert_match %r{t\.decimal\s+"decimal_with_default",\s+precision: 20,\s+scale: 10,\s+default: "1234567890.0123456789"}, output
|
||||
end
|
||||
|
||||
def test_schema_dump_with_float_column_infinity_default
|
||||
|
|
Loading…
Reference in a new issue