Skip to content

Commit

Permalink
assert valid keys
Browse files Browse the repository at this point in the history
  • Loading branch information
jonleighton committed Apr 13, 2012
1 parent 0183193 commit f52253c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
2 changes: 2 additions & 0 deletions activerecord/lib/active_record/relation.rb
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions 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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions activerecord/test/cases/relation_test.rb
Expand Up @@ -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
Expand Down

0 comments on commit f52253c

Please sign in to comment.