0
require 'models/company'
0
Company.has_many :accounts
0
@@ -274,4 +275,49 @@ class CalculationsTest < ActiveRecord::TestCase
0
def test_should_sum_expression
0
assert_equal 636, Account.sum("2 * credit_limit")
0
+ def test_count_with_from_option
0
+ assert_equal Company.count(:all), Company.count(:all, :from => 'companies')
0
+ assert_equal Account.count(:all, :conditions => "credit_limit = 50"),
0
+ Account.count(:all, :from => 'accounts', :conditions => "credit_limit = 50")
0
+ assert_equal Company.count(:type, :conditions => {:type => "Firm"}),
0
+ Company.count(:type, :conditions => {:type => "Firm"}, :from => 'companies')
0
+ def test_sum_with_from_option
0
+ assert_equal Account.sum(:credit_limit), Account.sum(:credit_limit, :from => 'accounts')
0
+ assert_equal Account.sum(:credit_limit, :conditions => "credit_limit > 50"),
0
+ Account.sum(:credit_limit, :from => 'accounts', :conditions => "credit_limit > 50")
0
+ def test_average_with_from_option
0
+ assert_equal Account.average(:credit_limit), Account.average(:credit_limit, :from => 'accounts')
0
+ assert_equal Account.average(:credit_limit, :conditions => "credit_limit > 50"),
0
+ Account.average(:credit_limit, :from => 'accounts', :conditions => "credit_limit > 50")
0
+ def test_minimum_with_from_option
0
+ assert_equal Account.minimum(:credit_limit), Account.minimum(:credit_limit, :from => 'accounts')
0
+ assert_equal Account.minimum(:credit_limit, :conditions => "credit_limit > 50"),
0
+ Account.minimum(:credit_limit, :from => 'accounts', :conditions => "credit_limit > 50")
0
+ def test_maximum_with_from_option
0
+ assert_equal Account.maximum(:credit_limit), Account.maximum(:credit_limit, :from => 'accounts')
0
+ assert_equal Account.maximum(:credit_limit, :conditions => "credit_limit > 50"),
0
+ Account.maximum(:credit_limit, :from => 'accounts', :conditions => "credit_limit > 50")
0
+ def test_from_option_with_specified_index
0
+ if Edge.connection.adapter_name == 'MySQL'
0
+ assert_equal Edge.count(:all), Edge.count(:all, :from => 'edges USE INDEX(unique_edge_index)')
0
+ assert_equal Edge.count(:all, :conditions => 'sink_id < 5'),
0
+ Edge.count(:all, :from => 'edges USE INDEX(unique_edge_index)', :conditions => 'sink_id < 5')
0
+ def test_from_option_with_table_different_than_class
0
+ assert_equal Account.count(:all), Company.count(:all, :from => 'accounts')