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

Don't raise on out-of-range datetimes passed by a user

This commit is contained in:
Grey Baker 2014-12-23 02:30:00 +00:00
parent d9d865aa40
commit d318badc26
3 changed files with 20 additions and 1 deletions

View file

@ -1,3 +1,8 @@
* Don't raise when writing an attribute with an out-of-range datetime passed
by the user.
*Grey Baker*
* Introduce `force: :cascade` option for `create_table`. Using this option
will recreate tables even if they have dependent objects (like foreign keys).
`db/schema.rb` now uses `force: :cascade`. This makes it possible to

View file

@ -12,7 +12,11 @@ module ActiveRecord
if value.is_a?(Array)
value.map { |v| type_cast_from_user(v) }
elsif value.respond_to?(:in_time_zone)
value.in_time_zone || super
begin
value.in_time_zone || super
rescue ArgumentError
nil
end
end
end

View file

@ -3,6 +3,8 @@ require 'models/topic'
require 'models/task'
class DateTimeTest < ActiveRecord::TestCase
include InTimeZone
def test_saves_both_date_and_time
with_env_tz 'America/New_York' do
with_timezone_config default: :utc do
@ -29,6 +31,14 @@ class DateTimeTest < ActiveRecord::TestCase
assert_nil task.ending
end
def test_assign_bad_date_time_with_timezone
in_time_zone "Pacific Time (US & Canada)" do
task = Task.new
task.starting = '2014-07-01T24:59:59GMT'
assert_nil task.starting
end
end
def test_assign_empty_date
topic = Topic.new
topic.last_read = ''