aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/calculations_test.rb
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2012-10-17 15:51:17 -0700
committerAaron Patterson <aaron.patterson@gmail.com>2012-10-17 15:51:17 -0700
commite06c06d460c21b4a4828e629247baf6dd8f8f1fe (patch)
tree07d2bbd09ff272730bcf21048e2ff85938bfde02 /activerecord/test/cases/calculations_test.rb
parent01149dd4f9b297b9f878c3ed752262d2ece37689 (diff)
downloadrails-e06c06d460c21b4a4828e629247baf6dd8f8f1fe.tar.gz
rails-e06c06d460c21b4a4828e629247baf6dd8f8f1fe.tar.bz2
rails-e06c06d460c21b4a4828e629247baf6dd8f8f1fe.zip
use columns hash to look up the column for the count field
Diffstat (limited to 'activerecord/test/cases/calculations_test.rb')
-rw-r--r--activerecord/test/cases/calculations_test.rb19
1 files changed, 6 insertions, 13 deletions
diff --git a/activerecord/test/cases/calculations_test.rb b/activerecord/test/cases/calculations_test.rb
index de4902f89a..000d86d104 100644
--- a/activerecord/test/cases/calculations_test.rb
+++ b/activerecord/test/cases/calculations_test.rb
@@ -6,6 +6,8 @@ require 'models/edge'
require 'models/organization'
require 'models/possession'
require 'models/topic'
+require 'models/minivan'
+require 'models/speedometer'
Company.has_many :accounts
@@ -239,21 +241,12 @@ class CalculationsTest < ActiveRecord::TestCase
end
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 = Speedometer.create! id: 'ABC'
+ mv = Minivan.create! id: 'OMG', speedometer_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.group(:firm).count(:all)
+ c = Minivan.group(:speedometer).count(:all)
first_key = c.keys.first
- assert_equal Firm, first_key.class
+ assert_equal Speedometer, first_key.class
assert_equal 1, c[first_key]
end