提交 f52253cb 编写于 作者: J Jon Leighton

assert valid keys

上级 0183193a
......@@ -13,6 +13,8 @@ class Relation
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
......
require 'active_support/core_ext/object/blank'
require 'active_support/core_ext/hash/keys'
module ActiveRecord
class Relation
class Merger
......@@ -32,6 +35,8 @@ class HashMerger
attr_reader :relation, :values
def initialize(relation, values)
values.assert_valid_keys(*Relation::VALUE_METHODS)
@relation = relation
@values = values
end
......
......@@ -145,6 +145,10 @@ def test_apply_finder_options_takes_references
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
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册