diff options
author | Jon Leighton <j@jonathanleighton.com> | 2012-04-13 12:15:43 +0100 |
---|---|---|
committer | Jon Leighton <j@jonathanleighton.com> | 2012-04-13 13:17:42 +0100 |
commit | f52253cbebf0124bb74925e91bcca75325eaa502 (patch) | |
tree | d75f134d4d46240a8258951bf30c9f188d0cf6c3 | |
parent | 0183193a6aecefb3b55a5abf20792aee6b57dcc1 (diff) | |
download | rails-f52253cbebf0124bb74925e91bcca75325eaa502.tar.gz rails-f52253cbebf0124bb74925e91bcca75325eaa502.tar.bz2 rails-f52253cbebf0124bb74925e91bcca75325eaa502.zip |
assert valid keys
-rw-r--r-- | activerecord/lib/active_record/relation.rb | 2 | ||||
-rw-r--r-- | activerecord/lib/active_record/relation/merger.rb | 5 | ||||
-rw-r--r-- | activerecord/test/cases/relation_test.rb | 4 |
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 |