aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/CHANGELOG.md25
-rw-r--r--activerecord/lib/active_record/attribute_methods/time_zone_conversion.rb6
-rw-r--r--activerecord/lib/active_record/attributes.rb4
-rw-r--r--activerecord/lib/active_record/nested_attributes.rb3
-rw-r--r--activerecord/lib/active_record/railties/databases.rake4
-rw-r--r--activerecord/lib/active_record/tasks/database_tasks.rb41
-rw-r--r--activerecord/lib/active_record/type/numeric.rb2
-rw-r--r--activerecord/lib/active_record/type/value.rb4
-rw-r--r--activerecord/test/cases/date_time_test.rb10
-rw-r--r--activerecord/test/cases/type/decimal_test.rb8
-rw-r--r--activerecord/test/cases/type/integer_test.rb2
11 files changed, 78 insertions, 31 deletions
diff --git a/activerecord/CHANGELOG.md b/activerecord/CHANGELOG.md
index 6494c7374e..f282029d22 100644
--- a/activerecord/CHANGELOG.md
+++ b/activerecord/CHANGELOG.md
@@ -1,3 +1,26 @@
+* Add a `:foreign_key` option to `references` and associated migration
+ methods. The model and migration generators now use this option, rather than
+ the `add_foreign_key` form.
+
+ *Sean Griffin*
+
+* Don't raise when writing an attribute with an out-of-range datetime passed
+ by the user.
+
+ *Grey Baker*
+
+* Replace deprecated `ActiveRecord::Tasks::DatabaseTasks#load_schema` with
+ `ActiveRecord::Tasks::DatabaseTasks#load_schema_for`.
+
+ *Yves Senn*
+
+* Fixes bug with 'ActiveRecord::Type::Numeric' that causes negative values to
+ be marked as having changed when set to the same negative value.
+
+ Closes #18161.
+
+ *Daniel Fox*
+
* 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
@@ -13,7 +36,7 @@
*Yves Senn*
-* Fix undesirable RangeError by Type::Integer. Add Type::UnsignedInteger.
+* Fix undesirable RangeError by `Type::Integer`. Add `Type::UnsignedInteger`.
*Ryuta Kamizono*
diff --git a/activerecord/lib/active_record/attribute_methods/time_zone_conversion.rb b/activerecord/lib/active_record/attribute_methods/time_zone_conversion.rb
index 87274dd4e1..777f7ab4d7 100644
--- a/activerecord/lib/active_record/attribute_methods/time_zone_conversion.rb
+++ b/activerecord/lib/active_record/attribute_methods/time_zone_conversion.rb
@@ -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
diff --git a/activerecord/lib/active_record/attributes.rb b/activerecord/lib/active_record/attributes.rb
index 3288108a6a..08f274fd42 100644
--- a/activerecord/lib/active_record/attributes.rb
+++ b/activerecord/lib/active_record/attributes.rb
@@ -53,9 +53,9 @@ module ActiveRecord
# store_listing.price_in_cents # => 10
#
# Users may also define their own custom types, as long as they respond to the methods
- # defined on the value type. The `type_cast` method on your type object will be called
+ # defined on the value type. The +type_cast+ method on your type object will be called
# with values both from the database, and from your controllers. See
- # `ActiveRecord::Attributes::Type::Value` for the expected API. It is recommended that your
+ # +ActiveRecord::Attributes::Type::Value+ for the expected API. It is recommended that your
# type objects inherit from an existing type, or the base value type.
#
# class MoneyType < ActiveRecord::Type::Integer
diff --git a/activerecord/lib/active_record/nested_attributes.rb b/activerecord/lib/active_record/nested_attributes.rb
index 8a2a06f2ca..0f9b52f69f 100644
--- a/activerecord/lib/active_record/nested_attributes.rb
+++ b/activerecord/lib/active_record/nested_attributes.rb
@@ -81,6 +81,9 @@ module ActiveRecord
#
# Note that the model will _not_ be destroyed until the parent is saved.
#
+ # Also note that the model will not be destroyed unless you also specify
+ # its id in the updated hash.
+ #
# === One-to-many
#
# Consider a member that has a number of posts:
diff --git a/activerecord/lib/active_record/railties/databases.rake b/activerecord/lib/active_record/railties/databases.rake
index 4daf2a0e2b..04c2be045d 100644
--- a/activerecord/lib/active_record/railties/databases.rake
+++ b/activerecord/lib/active_record/railties/databases.rake
@@ -319,7 +319,7 @@ db_namespace = namespace :db do
begin
should_reconnect = ActiveRecord::Base.connection_pool.active_connection?
ActiveRecord::Schema.verbose = false
- ActiveRecord::Tasks::DatabaseTasks.load_schema_for ActiveRecord::Base.configurations['test'], :ruby, ENV['SCHEMA']
+ ActiveRecord::Tasks::DatabaseTasks.load_schema ActiveRecord::Base.configurations['test'], :ruby, ENV['SCHEMA']
ensure
if should_reconnect
ActiveRecord::Base.establish_connection(ActiveRecord::Base.configurations[ActiveRecord::Tasks::DatabaseTasks.env])
@@ -329,7 +329,7 @@ db_namespace = namespace :db do
# desc "Recreate the test database from an existent structure.sql file"
task :load_structure => %w(db:test:purge) do
- ActiveRecord::Tasks::DatabaseTasks.load_schema_for ActiveRecord::Base.configurations['test'], :sql, ENV['SCHEMA']
+ ActiveRecord::Tasks::DatabaseTasks.load_schema ActiveRecord::Base.configurations['test'], :sql, ENV['SCHEMA']
end
# desc "Recreate the test database from a fresh schema"
diff --git a/activerecord/lib/active_record/tasks/database_tasks.rb b/activerecord/lib/active_record/tasks/database_tasks.rb
index 6ed610e5f0..a3a2993220 100644
--- a/activerecord/lib/active_record/tasks/database_tasks.rb
+++ b/activerecord/lib/active_record/tasks/database_tasks.rb
@@ -188,27 +188,7 @@ module ActiveRecord
class_for_adapter(configuration['adapter']).new(*arguments).structure_load(filename)
end
- def load_schema(format = ActiveRecord::Base.schema_format, file = nil)
- ActiveSupport::Deprecation.warn(<<-MSG.squish)
- This method will act on a specific connection in the future.
- To act on the current connection, use `load_schema_current` instead.
- MSG
-
- load_schema_current(format, file)
- end
-
- def schema_file(format = ActiveSupport::Base.schema_format)
- case format
- when :ruby
- File.join(db_dir, "schema.rb")
- when :sql
- File.join(db_dir, "structure.sql")
- end
- end
-
- # This method is the successor of +load_schema+. We should rename it
- # after +load_schema+ went through a deprecation cycle. (Rails > 4.2)
- def load_schema_for(configuration, format = ActiveRecord::Base.schema_format, file = nil) # :nodoc:
+ def load_schema(configuration, format = ActiveRecord::Base.schema_format, file = nil) # :nodoc:
file ||= schema_file(format)
case format
@@ -224,6 +204,23 @@ module ActiveRecord
end
end
+ def load_schema_for(*args)
+ ActiveSupport::Deprecation.warn(<<-MSG.squish)
+ This method was renamed to `#load_schema` and will be removed in the future.
+ Use `#load_schema` instead.
+ MSG
+ load_schema *args
+ end
+
+ def schema_file(format = ActiveSupport::Base.schema_format)
+ case format
+ when :ruby
+ File.join(db_dir, "schema.rb")
+ when :sql
+ File.join(db_dir, "structure.sql")
+ end
+ end
+
def load_schema_current_if_exists(format = ActiveRecord::Base.schema_format, file = nil, environment = env)
if File.exist?(file || schema_file(format))
load_schema_current(format, file, environment)
@@ -232,7 +229,7 @@ module ActiveRecord
def load_schema_current(format = ActiveRecord::Base.schema_format, file = nil, environment = env)
each_current_configuration(environment) { |configuration|
- load_schema_for configuration, format, file
+ load_schema configuration, format, file
}
ActiveRecord::Base.establish_connection(environment.to_sym)
end
diff --git a/activerecord/lib/active_record/type/numeric.rb b/activerecord/lib/active_record/type/numeric.rb
index fa43266504..674f996f38 100644
--- a/activerecord/lib/active_record/type/numeric.rb
+++ b/activerecord/lib/active_record/type/numeric.rb
@@ -29,7 +29,7 @@ module ActiveRecord
# 'wibble'.to_i will give zero, we want to make sure
# that we aren't marking int zero to string zero as
# changed.
- value.to_s !~ /\A\d+\.?\d*\z/
+ value.to_s !~ /\A-?\d+\.?\d*\z/
end
end
end
diff --git a/activerecord/lib/active_record/type/value.rb b/activerecord/lib/active_record/type/value.rb
index 9456a4a56c..75679b8692 100644
--- a/activerecord/lib/active_record/type/value.rb
+++ b/activerecord/lib/active_record/type/value.rb
@@ -91,8 +91,8 @@ module ActiveRecord
# Convenience method for types which do not need separate type casting
# behavior for user and database inputs. Called by
- # `type_cast_from_database` and `type_cast_from_user` for all values
- # except `nil`.
+ # +type_cast_from_database+ and +type_cast_from_user+ for all values
+ # except +nil+.
def cast_value(value) # :doc:
value
end
diff --git a/activerecord/test/cases/date_time_test.rb b/activerecord/test/cases/date_time_test.rb
index c0491bbee5..c2ec92c40d 100644
--- a/activerecord/test/cases/date_time_test.rb
+++ b/activerecord/test/cases/date_time_test.rb
@@ -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 = ''
diff --git a/activerecord/test/cases/type/decimal_test.rb b/activerecord/test/cases/type/decimal_test.rb
index c028aa52af..34ed1d7b19 100644
--- a/activerecord/test/cases/type/decimal_test.rb
+++ b/activerecord/test/cases/type/decimal_test.rb
@@ -38,6 +38,14 @@ module ActiveRecord
type = Decimal.new
assert_equal BigDecimal("1"), type.type_cast_from_user(value)
end
+
+ def test_changed?
+ type = Decimal.new
+
+ assert type.changed?(5.0, 5.0, '5.0wibble')
+ assert_not type.changed?(5.0, 5.0, '5.0')
+ assert_not type.changed?(-5.0, -5.0, '-5.0')
+ end
end
end
end
diff --git a/activerecord/test/cases/type/integer_test.rb b/activerecord/test/cases/type/integer_test.rb
index 5942f77e18..af4d0b4642 100644
--- a/activerecord/test/cases/type/integer_test.rb
+++ b/activerecord/test/cases/type/integer_test.rb
@@ -47,6 +47,8 @@ module ActiveRecord
assert type.changed?(5, 5, '5wibble')
assert_not type.changed?(5, 5, '5')
assert_not type.changed?(5, 5, '5.0')
+ assert_not type.changed?(-5, -5, '-5')
+ assert_not type.changed?(-5, -5, '-5.0')
assert_not type.changed?(nil, nil, nil)
end