aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/calculations_test.rb
diff options
context:
space:
mode:
authorJeremy Kemper <jeremy@bitsweat.net>2007-06-01 03:26:51 +0000
committerJeremy Kemper <jeremy@bitsweat.net>2007-06-01 03:26:51 +0000
commitb05fc40b5d096695dad5b3282664512d7509a529 (patch)
treee6e9ceec2d693df0f952947c05f63e24022137db /activerecord/test/calculations_test.rb
parent6435ecc68ab76ed73b5a0ae84bb325e7d7cd486d (diff)
downloadrails-b05fc40b5d096695dad5b3282664512d7509a529.tar.gz
rails-b05fc40b5d096695dad5b3282664512d7509a529.tar.bz2
rails-b05fc40b5d096695dad5b3282664512d7509a529.zip
Calculations support non-numeric foreign keys. Closes #8154.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@6919 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/test/calculations_test.rb')
-rw-r--r--activerecord/test/calculations_test.rb20
1 files changed, 20 insertions, 0 deletions
diff --git a/activerecord/test/calculations_test.rb b/activerecord/test/calculations_test.rb
index 22ef78ce40..bf34beb702 100644
--- a/activerecord/test/calculations_test.rb
+++ b/activerecord/test/calculations_test.rb
@@ -139,6 +139,26 @@ class CalculationsTest < Test::Unit::TestCase
assert_equal 2, c[companies(:rails_core)]
assert_equal 1, c[companies(:first_client)]
end
+
+ uses_mocha 'group_by_non_numeric_foreign_key_association' do
+ def test_should_group_by_association_with_non_numeric_foreign_key
+ ActiveRecord::Base.connection.expects(:select_all).returns([{"count_all" => 1, "firm_id" => "ABC"}])
+
+ firm = mock()
+ firm.expects(:id).returns("ABC")
+ firm.expects(:class).returns(Firm)
+ Company.expects(:find).with(["ABC"]).returns([firm])
+
+ column = mock()
+ column.expects(:name).at_least_once.returns(:firm_id)
+ column.expects(:type_cast).with("ABC").returns("ABC")
+ Account.expects(:columns).at_least_once.returns([column])
+
+ c = Account.count(:all, :group => :firm)
+ assert_equal Firm, c.first.first.class
+ assert_equal 1, c.first.last
+ end
+ end
def test_should_not_modify_options_when_using_includes
options = {:conditions => 'companies.id > 1', :include => :firm}