diff options
author | Kuldeep Aggarwal <kd.engineer@yahoo.co.in> | 2013-12-30 01:53:02 +0530 |
---|---|---|
committer | Kuldeep Aggarwal <kd.engineer@yahoo.co.in> | 2013-12-30 01:53:02 +0530 |
commit | a2985e206709f7947ef427a527d72ff89824931a (patch) | |
tree | 9c42b2f69bb69ed07820f7bb9d9a0eb98acd19c6 /activerecord | |
parent | 15e2eb42a7b1c251defd088ac65a89f152a307f6 (diff) | |
download | rails-a2985e206709f7947ef427a527d72ff89824931a.tar.gz rails-a2985e206709f7947ef427a527d72ff89824931a.tar.bz2 rails-a2985e206709f7947ef427a527d72ff89824931a.zip |
raise `ArgumentError` exception if `Model.where.not` is called with `nil` argument
Diffstat (limited to 'activerecord')
-rw-r--r-- | activerecord/lib/active_record/relation/query_methods.rb | 2 | ||||
-rw-r--r-- | activerecord/test/cases/relation/where_chain_test.rb | 6 |
2 files changed, 8 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/relation/query_methods.rb b/activerecord/lib/active_record/relation/query_methods.rb index 3d0709266a..78da6a83ec 100644 --- a/activerecord/lib/active_record/relation/query_methods.rb +++ b/activerecord/lib/active_record/relation/query_methods.rb @@ -37,6 +37,8 @@ module ActiveRecord def not(opts, *rest) where_value = @scope.send(:build_where, opts, rest).map do |rel| case rel + when NilClass + raise ArgumentError, 'Invalid argument for .where.not(), got nil.' when Arel::Nodes::In Arel::Nodes::NotIn.new(rel.left, rel.right) when Arel::Nodes::Equality diff --git a/activerecord/test/cases/relation/where_chain_test.rb b/activerecord/test/cases/relation/where_chain_test.rb index d44b4dfe3d..fd2420cb88 100644 --- a/activerecord/test/cases/relation/where_chain_test.rb +++ b/activerecord/test/cases/relation/where_chain_test.rb @@ -23,6 +23,12 @@ module ActiveRecord assert_equal([expected], relation.where_values) end + def test_not_with_nil + assert_raise ArgumentError do + Post.where.not(nil) + end + end + def test_not_in expected = Arel::Nodes::NotIn.new(Post.arel_table[@name], %w[hello goodbye]) relation = Post.where.not(title: %w[hello goodbye]) |