diff options
author | Matthew Draper <matthew@trebex.net> | 2018-02-11 19:37:10 +1030 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-02-11 19:37:10 +1030 |
commit | a2a752d1026346e3a348682551dfc952f7cf3a58 (patch) | |
tree | 9cf65b124d5c56360346ae7d3b27626c0507aaa6 | |
parent | d0192e0c2daa03048a8c4d0d3b94763dbbfec4c1 (diff) | |
parent | ccbba229386bdc629be5f5f4ef765ab5e29e7da7 (diff) | |
download | rails-a2a752d1026346e3a348682551dfc952f7cf3a58.tar.gz rails-a2a752d1026346e3a348682551dfc952f7cf3a58.tar.bz2 rails-a2a752d1026346e3a348682551dfc952f7cf3a58.zip |
Merge pull request #31133 from mohsen-alizadeh/sanitize_empty_and_nil_parameters_passed_to_select
sanitize empty and nil parameters to select #31059
-rw-r--r-- | activerecord/lib/active_record/relation/query_methods.rb | 1 | ||||
-rw-r--r-- | activerecord/test/cases/relation/select_test.rb | 15 |
2 files changed, 16 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/relation/query_methods.rb b/activerecord/lib/active_record/relation/query_methods.rb index 86882c7ce7..3afa368575 100644 --- a/activerecord/lib/active_record/relation/query_methods.rb +++ b/activerecord/lib/active_record/relation/query_methods.rb @@ -231,6 +231,7 @@ module ActiveRecord end def _select!(*fields) # :nodoc: + fields.reject!(&:blank?) fields.flatten! fields.map! do |field| klass.attribute_alias?(field) ? klass.attribute_alias(field).to_sym : field diff --git a/activerecord/test/cases/relation/select_test.rb b/activerecord/test/cases/relation/select_test.rb new file mode 100644 index 0000000000..0577e6bfdb --- /dev/null +++ b/activerecord/test/cases/relation/select_test.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +require "cases/helper" +require "models/post" + +module ActiveRecord + class SelectTest < ActiveRecord::TestCase + fixtures :posts + + def test_select_with_nil_agrument + expected = Post.select(:title).to_sql + assert_equal expected, Post.select(nil).select(:title).to_sql + end + end +end |