Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Dec 23, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions activerecord/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
* Don't raise when writing an attribute with an out-of-range datetime passed
by the user.

*Grey Baker*

* Fixes bug with 'ActiveRecord::Type::Numeric' that causes negative values to
be marked as having changed when set to the same negative value.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@ def type_cast_from_user(value)
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

Expand Down
10 changes: 10 additions & 0 deletions activerecord/test/cases/date_time_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
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
Expand All @@ -29,6 +31,14 @@ def test_assign_empty_date_time
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 = ''
Expand Down