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

Changeset 4493

Show
Ignore:
Timestamp:
06/25/06 17:49:24 (2 years ago)
Author:
ulysses
Message:

Add AssociationCollection#sum since the method_missing invokation has been shadowed by Enumerable#sum. Closes #5500.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/activerecord/CHANGELOG

    r4473 r4493  
    11*SVN* 
     2 
     3* Add AssociationCollection#sum since the method_missing invokation has been shadowed by Enumerable#sum. 
    24 
    35* Added find_or_initialize_by_X which works like find_or_create_by_X but doesn't save the newly instantiated record. [Sam Stephenson] 
  • trunk/activerecord/lib/active_record/associations/association_collection.rb

    r4355 r4493  
    4141        delete(@target) 
    4242        reset_target! 
     43      end 
     44 
     45      # Calculate sum using SQL, not Enumerable 
     46      def sum(*args, &block) 
     47        calculate(:sum, *args, &block) 
    4348      end 
    4449 
  • trunk/activerecord/test/calculations_test.rb

    r4420 r4493  
    148148    assert_equal 2, c['FIRM'] 
    149149  end 
     150   
     151  def test_should_not_overshadow_enumerable_sum 
     152    assert_equal 6, [1, 2, 3].sum(&:abs) 
     153  end 
    150154 
    151155  def test_should_sum_scoped_field