aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/CHANGELOG.md7
-rw-r--r--activerecord/lib/active_record/aggregations.rb6
-rw-r--r--activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb2
-rw-r--r--activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb2
-rw-r--r--activerecord/lib/active_record/errors.rb4
-rw-r--r--activerecord/test/cases/adapters/mysql2/transaction_test.rb4
-rw-r--r--activerecord/test/cases/adapters/postgresql/transaction_test.rb4
-rw-r--r--activerecord/test/cases/aggregations_test.rb5
-rw-r--r--activerecord/test/models/customer.rb1
9 files changed, 25 insertions, 10 deletions
diff --git a/activerecord/CHANGELOG.md b/activerecord/CHANGELOG.md
index 14a6c3c9f7..dfd9a07997 100644
--- a/activerecord/CHANGELOG.md
+++ b/activerecord/CHANGELOG.md
@@ -1,3 +1,10 @@
+* Hashes can once again be passed to setters of `composed_of`, if all of the
+ mapping methods are methods implemented on `Hash`.
+
+ Fixes #25978.
+
+ *Sean Griffin*
+
* Fix the SELECT statement in `#table_comment` for MySQL.
*Takeshi Akima*
diff --git a/activerecord/lib/active_record/aggregations.rb b/activerecord/lib/active_record/aggregations.rb
index 8bed5bca28..9f965052c5 100644
--- a/activerecord/lib/active_record/aggregations.rb
+++ b/activerecord/lib/active_record/aggregations.rb
@@ -261,8 +261,10 @@ module ActiveRecord
part = converter.respond_to?(:call) ? converter.call(part) : klass.send(converter, part)
end
- if part.is_a?(Hash)
- raise ArgumentError unless part.size == part.keys.max
+ hash_from_multiparameter_assignment = part.is_a?(Hash) &&
+ part.each_key.all? { |k| k.is_a?(Integer) }
+ if hash_from_multiparameter_assignment
+ raise ArgumentError unless part.size == part.each_key.max
part = klass.new(*part.sort.map(&:last))
end
diff --git a/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb b/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb
index acc21866f1..5e9705e02f 100644
--- a/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb
+++ b/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb
@@ -753,7 +753,7 @@ module ActiveRecord
when ER_DATA_TOO_LONG
ValueTooLong.new(message)
when ER_LOCK_DEADLOCK
- DeadlockDetected.new(message)
+ Deadlocked.new(message)
else
super
end
diff --git a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
index e213c991c8..8a1fdc9f92 100644
--- a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
+++ b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
@@ -422,7 +422,7 @@ module ActiveRecord
when SERIALIZATION_FAILURE
SerializationFailure.new(message)
when DEADLOCK_DETECTED
- DeadlockDetected.new(message)
+ Deadlocked.new(message)
else
super
end
diff --git a/activerecord/lib/active_record/errors.rb b/activerecord/lib/active_record/errors.rb
index 3f75ce4099..03e6e1eee3 100644
--- a/activerecord/lib/active_record/errors.rb
+++ b/activerecord/lib/active_record/errors.rb
@@ -300,9 +300,9 @@ module ActiveRecord
class SerializationFailure < TransactionRollbackError
end
- # DeadlockDetected will be raised when a transaction is rolled
+ # Deadlocked will be raised when a transaction is rolled
# back by the database when a deadlock is encountered.
- class DeadlockDetected < TransactionRollbackError
+ class Deadlocked < TransactionRollbackError
end
# IrreversibleOrderError is raised when a relation's order is too complex for
diff --git a/activerecord/test/cases/adapters/mysql2/transaction_test.rb b/activerecord/test/cases/adapters/mysql2/transaction_test.rb
index 1a88b9cbca..5d8765d63a 100644
--- a/activerecord/test/cases/adapters/mysql2/transaction_test.rb
+++ b/activerecord/test/cases/adapters/mysql2/transaction_test.rb
@@ -27,8 +27,8 @@ module ActiveRecord
@connection.drop_table 'samples', if_exists: true
end
- test "raises DeadlockDetected when a deadlock is encountered" do
- assert_raises(ActiveRecord::DeadlockDetected) do
+ test "raises Deadlocked when a deadlock is encountered" do
+ assert_raises(ActiveRecord::Deadlocked) do
s1 = Sample.create value: 1
s2 = Sample.create value: 2
diff --git a/activerecord/test/cases/adapters/postgresql/transaction_test.rb b/activerecord/test/cases/adapters/postgresql/transaction_test.rb
index 87d1fffe19..8dea92c785 100644
--- a/activerecord/test/cases/adapters/postgresql/transaction_test.rb
+++ b/activerecord/test/cases/adapters/postgresql/transaction_test.rb
@@ -58,9 +58,9 @@ module ActiveRecord
end
end
- test "raises DeadlockDetected when a deadlock is encountered" do
+ test "raises Deadlocked when a deadlock is encountered" do
with_warning_suppression do
- assert_raises(ActiveRecord::DeadlockDetected) do
+ assert_raises(ActiveRecord::Deadlocked) do
s1 = Sample.create value: 1
s2 = Sample.create value: 2
diff --git a/activerecord/test/cases/aggregations_test.rb b/activerecord/test/cases/aggregations_test.rb
index 8a728902a8..4e865264c7 100644
--- a/activerecord/test/cases/aggregations_test.rb
+++ b/activerecord/test/cases/aggregations_test.rb
@@ -143,6 +143,11 @@ class AggregationsTest < ActiveRecord::TestCase
customers(:barney).fullname = { first: "Barney", last: "Stinson" }
assert_equal "Barney STINSON", customers(:barney).name
end
+
+ def test_assigning_hash_without_custom_converter
+ customers(:barney).fullname_no_converter = { first: "Barney", last: "Stinson" }
+ assert_equal({ first: "Barney", last: "Stinson" }.to_s, customers(:barney).name)
+ end
end
class OverridingAggregationsTest < ActiveRecord::TestCase
diff --git a/activerecord/test/models/customer.rb b/activerecord/test/models/customer.rb
index 3338aaf7e1..d464759430 100644
--- a/activerecord/test/models/customer.rb
+++ b/activerecord/test/models/customer.rb
@@ -7,6 +7,7 @@ class Customer < ActiveRecord::Base
composed_of :non_blank_gps_location, :class_name => "GpsLocation", :allow_nil => true, :mapping => %w(gps_location gps_location),
:converter => lambda { |gps| self.gps_conversion_was_run = true; gps.blank? ? nil : GpsLocation.new(gps)}
composed_of :fullname, :mapping => %w(name to_s), :constructor => Proc.new { |name| Fullname.parse(name) }, :converter => :parse
+ composed_of :fullname_no_converter, :mapping => %w(name to_s), class_name: "Fullname"
end
class Address