Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Ticket #5863: select_option_for_find_should_accept_array.patch

File select_option_for_find_should_accept_array.patch, 1.4 kB (added by rubyonrails@beautifulpixel.com, 2 years ago)
  • activerecord/lib/active_record/base.rb

    old new  
    10611061        end 
    10621062 
    10631063        def construct_finder_sql(options) 
    1064           scope = scope(:find) 
     1064          scope = scope(:find) 
     1065          options[:select] = options[:select].join(', ') if options[:select].respond_to?(:join) 
    10651066          sql  = "SELECT #{(scope && scope[:select]) || options[:select] || '*'} " 
    10661067          sql << "FROM #{(scope && scope[:from]) || options[:from] || table_name} " 
    10671068 
  • activerecord/test/base_test.rb

    old new  
    13951395  def test_to_param_should_return_string 
    13961396    assert_kind_of String, Client.find(:first).to_param 
    13971397  end 
    1398  
     1398   
     1399  def test_select_option_for_find_should_accept_array 
     1400    retrieved_columns = Post.find(1, :select => %w{ id title }).attributes.keys 
     1401    assert_equal 2, retrieved_columns.size 
     1402    assert retrieved_columns.include?('id') 
     1403    assert retrieved_columns.include?('title') 
     1404  end 
     1405   
    13991406  # FIXME: this test ought to run, but it needs to run sandboxed so that it 
    14001407  # doesn't b0rk the current test environment by undefing everything. 
    14011408  #