From 449f195fd1cff3d9681ce442dc2d53a7fc158030 Mon Sep 17 00:00:00 2001 From: Alan Da Costa Date: Wed, 13 May 2009 19:56:44 -0700 Subject: [PATCH] Fixed mixed case column calculations --- activerecord/lib/active_record/calculations.rb | 2 +- activerecord/test/cases/calculations_test.rb | 4 ++++ activerecord/test/fixtures/accounts.yml | 5 +++++ activerecord/test/schema/schema.rb | 1 + 4 files changed, 11 insertions(+), 1 deletions(-) diff --git a/activerecord/lib/active_record/calculations.rb b/activerecord/lib/active_record/calculations.rb index 7afa7c4..98bd97e 100644 --- a/activerecord/lib/active_record/calculations.rb +++ b/activerecord/lib/active_record/calculations.rb @@ -173,7 +173,7 @@ module ActiveRecord scope = scope(:find) merged_includes = merge_includes(scope ? scope[:include] : [], options[:include]) aggregate_alias = column_alias_for(operation, column_name) - column_name = "#{connection.quote_table_name(table_name)}.#{column_name}" if column_names.include?(column_name.to_s) + column_name = "#{connection.quote_table_name(table_name)}.#{connection.quote_column_name(column_name)}" if column_names.include?(column_name.to_s) if operation == 'count' if merged_includes.any? diff --git a/activerecord/test/cases/calculations_test.rb b/activerecord/test/cases/calculations_test.rb index fd455e0..7b9e832 100644 --- a/activerecord/test/cases/calculations_test.rb +++ b/activerecord/test/cases/calculations_test.rb @@ -16,6 +16,10 @@ class CalculationsTest < ActiveRecord::TestCase assert_equal 318, Account.sum(:credit_limit) end + def test_should_sum_mixed_case_field + assert_equal 50, Account.sum(:Balance) + end + def test_should_average_field value = Account.average(:credit_limit) assert_kind_of BigDecimal, value diff --git a/activerecord/test/fixtures/accounts.yml b/activerecord/test/fixtures/accounts.yml index b2d0191..d867e3c 100644 --- a/activerecord/test/fixtures/accounts.yml +++ b/activerecord/test/fixtures/accounts.yml @@ -2,6 +2,7 @@ signals37: id: 1 firm_id: 1 credit_limit: 50 + Balance: 10 unknown: id: 2 @@ -11,18 +12,22 @@ rails_core_account: id: 3 firm_id: 6 credit_limit: 50 + Balance: 10 last_account: id: 4 firm_id: 2 credit_limit: 60 + Balance: 10 rails_core_account_2: id: 5 firm_id: 6 credit_limit: 55 + Balance: 10 odegy_account: id: 6 firm_id: 9 credit_limit: 53 + Balance: 10 diff --git a/activerecord/test/schema/schema.rb b/activerecord/test/schema/schema.rb index a776cd9..5b67f4e 100644 --- a/activerecord/test/schema/schema.rb +++ b/activerecord/test/schema/schema.rb @@ -24,6 +24,7 @@ ActiveRecord::Schema.define do create_table :accounts, :force => true do |t| t.integer :firm_id t.integer :credit_limit + t.integer :Balance end create_table :audit_logs, :force => true do |t| -- 1.5.6.3