aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--activerecord/lib/active_record/relation.rb2
-rw-r--r--activerecord/lib/active_record/relation/merger.rb5
-rw-r--r--activerecord/test/cases/relation_test.rb4
3 files changed, 11 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/relation.rb b/activerecord/lib/active_record/relation.rb
index 88fb0e9dda..5fccf3a43d 100644
--- a/activerecord/lib/active_record/relation.rb
+++ b/activerecord/lib/active_record/relation.rb
@@ -13,6 +13,8 @@ module ActiveRecord
SINGLE_VALUE_METHODS = [:limit, :offset, :lock, :readonly, :from, :reordering,
:reverse_order, :uniq, :create_with]
+ VALUE_METHODS = MULTI_VALUE_METHODS + SINGLE_VALUE_METHODS
+
include FinderMethods, Calculations, SpawnMethods, QueryMethods, Batches, Explain, Delegation
attr_reader :table, :klass, :loaded
diff --git a/activerecord/lib/active_record/relation/merger.rb b/activerecord/lib/active_record/relation/merger.rb
index 23629eedf6..77bfe82a83 100644
--- a/activerecord/lib/active_record/relation/merger.rb
+++ b/activerecord/lib/active_record/relation/merger.rb
@@ -1,3 +1,6 @@
+require 'active_support/core_ext/object/blank'
+require 'active_support/core_ext/hash/keys'
+
module ActiveRecord
class Relation
class Merger
@@ -32,6 +35,8 @@ module ActiveRecord
attr_reader :relation, :values
def initialize(relation, values)
+ values.assert_valid_keys(*Relation::VALUE_METHODS)
+
@relation = relation
@values = values
end
diff --git a/activerecord/test/cases/relation_test.rb b/activerecord/test/cases/relation_test.rb
index a38255eda6..31236cae15 100644
--- a/activerecord/test/cases/relation_test.rb
+++ b/activerecord/test/cases/relation_test.rb
@@ -145,6 +145,10 @@ module ActiveRecord
test 'merging an empty hash into a relation' do
assert_equal [], Relation.new(:a, :b).merge({}).where_values
end
+
+ test 'merging a hash with unknown keys raises' do
+ assert_raises(ArgumentError) { Relation::HashMerger.new(nil, omg: 'lol') }
+ end
end
class RelationMutationTest < ActiveSupport::TestCase