diff options
author | Will Bryant <will.bryant@gmail.com> | 2009-03-06 22:29:36 +0000 |
---|---|---|
committer | Pratik Naik <pratiknaik@gmail.com> | 2009-03-06 22:29:53 +0000 |
commit | 7fb7b48a1f771e50896a82d749a70922a18afae7 (patch) | |
tree | 6e583256462d9da5431098ddd351e432723b5df3 /activerecord/test | |
parent | 3ca5a0f9fd7b7921bca970859da8637011b22dd1 (diff) | |
download | rails-7fb7b48a1f771e50896a82d749a70922a18afae7.tar.gz rails-7fb7b48a1f771e50896a82d749a70922a18afae7.tar.bz2 rails-7fb7b48a1f771e50896a82d749a70922a18afae7.zip |
Allow :having conditions to be sanitized like regular :condition. [#2158 state:resolved]
Signed-off-by: Pratik Naik <pratiknaik@gmail.com>
Diffstat (limited to 'activerecord/test')
-rw-r--r-- | activerecord/test/cases/calculations_test.rb | 8 | ||||
-rw-r--r-- | activerecord/test/cases/finder_test.rb | 7 |
2 files changed, 15 insertions, 0 deletions
diff --git a/activerecord/test/cases/calculations_test.rb b/activerecord/test/cases/calculations_test.rb index 5a4ed429b6..c158706645 100644 --- a/activerecord/test/cases/calculations_test.rb +++ b/activerecord/test/cases/calculations_test.rb @@ -92,6 +92,14 @@ class CalculationsTest < ActiveRecord::TestCase assert_equal 60, c[2] end + def test_should_group_by_summed_field_having_sanitized_condition + c = Account.sum(:credit_limit, :group => :firm_id, + :having => ['sum(credit_limit) > ?', 50]) + assert_nil c[1] + assert_equal 105, c[6] + assert_equal 60, c[2] + end + def test_should_group_by_summed_association c = Account.sum(:credit_limit, :group => :firm) assert_equal 50, c[companies(:first_firm)] diff --git a/activerecord/test/cases/finder_test.rb b/activerecord/test/cases/finder_test.rb index 9d444a92ae..375b9a849c 100644 --- a/activerecord/test/cases/finder_test.rb +++ b/activerecord/test/cases/finder_test.rb @@ -191,6 +191,13 @@ class FinderTest < ActiveRecord::TestCase assert developers.all? { |developer| developer.salary > 10000 } end + def test_find_with_group_and_sanitized_having + developers = Developer.find(:all, :group => "salary", :having => ["sum(salary) > ?", 10000], :select => "salary") + assert_equal 3, developers.size + assert_equal 3, developers.map(&:salary).uniq.size + assert developers.all? { |developer| developer.salary > 10000 } + end + def test_find_with_entire_select_statement topics = Topic.find_by_sql "SELECT * FROM topics WHERE author_name = 'Mary'" |