From 7663376f0708118694874c2670f0053c4143bc3f Mon Sep 17 00:00:00 2001 From: Jake Worth Date: Mon, 12 Oct 2015 23:28:26 -0500 Subject: `where` raises ArgumentError on unsupported types. [#20473] --- activerecord/CHANGELOG.md | 6 ++++++ activerecord/lib/active_record/relation/query_methods.rb | 2 ++ activerecord/test/cases/relation/where_test.rb | 6 ++++++ 3 files changed, 14 insertions(+) (limited to 'activerecord') diff --git a/activerecord/CHANGELOG.md b/activerecord/CHANGELOG.md index 41f6ab5342..9e44131fa9 100644 --- a/activerecord/CHANGELOG.md +++ b/activerecord/CHANGELOG.md @@ -1,3 +1,9 @@ +* `where` raises ArgumentError on unsupported types. + + Fixes #20473. + + *Jake Worth* + * Add an immutable string type to help reduce memory usage for apps which do not need mutation detection on Strings. diff --git a/activerecord/lib/active_record/relation/query_methods.rb b/activerecord/lib/active_record/relation/query_methods.rb index 55fd0e0b52..0dcecbd42d 100644 --- a/activerecord/lib/active_record/relation/query_methods.rb +++ b/activerecord/lib/active_record/relation/query_methods.rb @@ -552,6 +552,8 @@ module ActiveRecord WhereChain.new(spawn) elsif opts.blank? self + elsif !opts.is_a?(String) && !opts.respond_to?(:to_h) + raise ArgumentError, "Unsupported argument type: #{opts} (#{opts.class})" else spawn.where!(opts, *rest) end diff --git a/activerecord/test/cases/relation/where_test.rb b/activerecord/test/cases/relation/where_test.rb index c3a1471205..399a4dbbf1 100644 --- a/activerecord/test/cases/relation/where_test.rb +++ b/activerecord/test/cases/relation/where_test.rb @@ -302,5 +302,11 @@ module ActiveRecord assert_raises(ActiveModel::ForbiddenAttributesError) { Author.where(params) } assert_equal author, Author.where(params.permit!).first end + + def test_where_with_unsupported_arguments + author = authors(:david) + + assert_raises(ArgumentError) { Author.where(42) } + end end end -- cgit v1.2.3