diff options
author | Jeremy Kemper <jeremy@bitsweat.net> | 2006-09-26 17:02:45 +0000 |
---|---|---|
committer | Jeremy Kemper <jeremy@bitsweat.net> | 2006-09-26 17:02:45 +0000 |
commit | a0bf0195a5c27c8c8493b1a44987154a9dc0d526 (patch) | |
tree | 9c48753be9e25512a3dd58fde92af218fb0f5db7 /activerecord/test | |
parent | c554a9cabaa3c8bbed5a0dccb381fdc6d516972d (diff) | |
download | rails-a0bf0195a5c27c8c8493b1a44987154a9dc0d526.tar.gz rails-a0bf0195a5c27c8c8493b1a44987154a9dc0d526.tar.bz2 rails-a0bf0195a5c27c8c8493b1a44987154a9dc0d526.zip |
Deprecation: count class method should be called with an options hash rather than two args for conditions and joins. Closes #6287.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@5192 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/test')
-rwxr-xr-x | activerecord/test/associations_test.rb | 4 | ||||
-rwxr-xr-x | activerecord/test/base_test.rb | 2 | ||||
-rw-r--r-- | activerecord/test/calculations_test.rb | 12 | ||||
-rwxr-xr-x | activerecord/test/deprecated_finder_test.rb | 6 | ||||
-rw-r--r-- | activerecord/test/finder_test.rb | 6 | ||||
-rw-r--r-- | activerecord/test/method_scoping_test.rb | 4 |
6 files changed, 24 insertions, 10 deletions
diff --git a/activerecord/test/associations_test.rb b/activerecord/test/associations_test.rb index 5e9a39873d..b843f5bdf5 100755 --- a/activerecord/test/associations_test.rb +++ b/activerecord/test/associations_test.rb @@ -395,7 +395,9 @@ class HasManyAssociationsTest < Test::Unit::TestCase end def test_counting_with_single_conditions - assert_equal 2, Firm.find(:first).plain_clients.count('1=1') + assert_deprecated 'count' do + assert_equal 2, Firm.find(:first).plain_clients.count('1=1') + end end def test_counting_with_single_hash diff --git a/activerecord/test/base_test.rb b/activerecord/test/base_test.rb index c1dc89a611..055f5e8670 100755 --- a/activerecord/test/base_test.rb +++ b/activerecord/test/base_test.rb @@ -1159,7 +1159,7 @@ class BasicsTest < Test::Unit::TestCase def test_count_with_join res = Post.count_by_sql "SELECT COUNT(*) FROM posts LEFT JOIN comments ON posts.id=comments.post_id WHERE posts.#{QUOTED_TYPE} = 'Post'" res2 = nil - assert_nothing_raised do + assert_deprecated 'count' do res2 = Post.count("posts.#{QUOTED_TYPE} = 'Post'", "LEFT JOIN comments ON posts.id=comments.post_id") end diff --git a/activerecord/test/calculations_test.rb b/activerecord/test/calculations_test.rb index 397b7a9026..23c45f8637 100644 --- a/activerecord/test/calculations_test.rb +++ b/activerecord/test/calculations_test.rb @@ -196,4 +196,16 @@ class CalculationsTest < Test::Unit::TestCase assert_equal 6, Account.count(:distinct => true, :include => :firm) assert_equal 4, Account.count(:distinct => true, :include => :firm, :select => :credit_limit) end + + def test_deprecated_count_with_string_parameters + assert_deprecated('count') { Account.count('credit_limit > 50') } + end + + def test_count_with_no_parameters_isnt_deprecated + assert_not_deprecated { Account.count } + end + + def test_count_with_too_many_parameters_raises + assert_raise(ArgumentError) { Account.count(1, 2, 3) } + end end diff --git a/activerecord/test/deprecated_finder_test.rb b/activerecord/test/deprecated_finder_test.rb index fa56e8ee04..796e46f8c2 100755 --- a/activerecord/test/deprecated_finder_test.rb +++ b/activerecord/test/deprecated_finder_test.rb @@ -88,9 +88,9 @@ class DeprecatedFinderTest < Test::Unit::TestCase end def test_count - assert_equal(0, Entrant.count("id > 3")) - assert_equal(1, Entrant.count(["id > ?", 2])) - assert_equal(2, Entrant.count(["id > ?", 1])) + assert_equal(0, Entrant.count(:conditions => "id > 3")) + assert_equal(1, Entrant.count(:conditions => ["id > ?", 2])) + assert_equal(2, Entrant.count(:conditions => ["id > ?", 1])) end def test_count_by_sql diff --git a/activerecord/test/finder_test.rb b/activerecord/test/finder_test.rb index bd72348916..ebc21b5e0c 100644 --- a/activerecord/test/finder_test.rb +++ b/activerecord/test/finder_test.rb @@ -249,9 +249,9 @@ class FinderTest < Test::Unit::TestCase end def test_count - assert_equal(0, Entrant.count("id > 3")) - assert_equal(1, Entrant.count(["id > ?", 2])) - assert_equal(2, Entrant.count(["id > ?", 1])) + assert_equal(0, Entrant.count(:conditions => "id > 3")) + assert_equal(1, Entrant.count(:conditions => ["id > ?", 2])) + assert_equal(2, Entrant.count(:conditions => ["id > ?", 1])) end def test_count_by_sql diff --git a/activerecord/test/method_scoping_test.rb b/activerecord/test/method_scoping_test.rb index bceb3869a6..ee4a52df1d 100644 --- a/activerecord/test/method_scoping_test.rb +++ b/activerecord/test/method_scoping_test.rb @@ -57,7 +57,7 @@ class MethodScopingTest < Test::Unit::TestCase Developer.with_scope(:find => { :conditions => 'salary = 100000' }) do assert_equal 8, Developer.count - assert_equal 1, Developer.count("name LIKE 'fixture_1%'") + assert_equal 1, Developer.count(:conditions => "name LIKE 'fixture_1%'") end end @@ -74,7 +74,7 @@ class MethodScopingTest < Test::Unit::TestCase def test_scoped_count_include # with the include, will retrieve only developers for the given project Developer.with_scope(:find => { :include => :projects }) do - assert_equal 1, Developer.count('projects.id = 2') + assert_equal 1, Developer.count(:conditions => 'projects.id = 2') end end |