Skip to content

Commit

Permalink
Calculations don't modify their options hash. References [5931], [542…
Browse files Browse the repository at this point in the history
…6], closes #6929.

git-svn-id: http://svn-commit.rubyonrails.org/rails/branches/1-2-pre-release@5932 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information
jeremy committed Jan 14, 2007
1 parent 2d5bf4b commit 5385859
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
3 changes: 3 additions & 0 deletions activerecord/lib/active_record/calculations.rb
Expand Up @@ -157,6 +157,9 @@ def construct_count_options_from_legacy_args(*args)
end end


def construct_calculation_sql(operation, column_name, options) #:nodoc: def construct_calculation_sql(operation, column_name, options) #:nodoc:
operation = operation.to_s.downcase
options = options.symbolize_keys

scope = scope(:find) scope = scope(:find)
merged_includes = merge_includes(scope ? scope[:include] : [], options[:include]) merged_includes = merge_includes(scope ? scope[:include] : [], options[:include])
aggregate_alias = column_alias_for(operation, column_name) aggregate_alias = column_alias_for(operation, column_name)
Expand Down
8 changes: 8 additions & 0 deletions activerecord/test/calculations_test.rb
Expand Up @@ -131,6 +131,14 @@ def test_should_calculate_grouped_association_with_invalid_field
assert_equal 2, c[companies(:rails_core)] assert_equal 2, c[companies(:rails_core)]
assert_equal 1, c[companies(:first_client)] assert_equal 1, c[companies(:first_client)]
end end

def test_should_not_modify_options_when_using_includes
options = {:conditions => 'companies.id > 1', :include => :firm}
options_copy = options.dup

Account.count(:all, options)
assert_equal options_copy, options
end


def test_should_calculate_grouped_by_function def test_should_calculate_grouped_by_function
c = Company.count(:all, :group => "UPPER(#{QUOTED_TYPE})") c = Company.count(:all, :group => "UPPER(#{QUOTED_TYPE})")
Expand Down

0 comments on commit 5385859

Please sign in to comment.