diff options
author | miloops <miloops@gmail.com> | 2008-06-26 13:46:33 -0300 |
---|---|---|
committer | Jeremy Kemper <jeremy@bitsweat.net> | 2008-07-15 16:21:11 -0700 |
commit | 459e5817a513b95741b77af26771a6252a13d01f (patch) | |
tree | cc581c6fb6e67df99e75eaf8e3ccc4120ecc1d4f /activerecord/test/cases | |
parent | 1edb5c85b58653a6fdc73ae1c6c63e317b466b27 (diff) | |
download | rails-459e5817a513b95741b77af26771a6252a13d01f.tar.gz rails-459e5817a513b95741b77af26771a6252a13d01f.tar.bz2 rails-459e5817a513b95741b77af26771a6252a13d01f.zip |
update_counters should update nil values.
This allows counter columns with default null instead of requiring default 0.
[#493 state:resolved]
Diffstat (limited to 'activerecord/test/cases')
-rwxr-xr-x | activerecord/test/cases/base_test.rb | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/activerecord/test/cases/base_test.rb b/activerecord/test/cases/base_test.rb index a4be629fbd..9e4f268db7 100755 --- a/activerecord/test/cases/base_test.rb +++ b/activerecord/test/cases/base_test.rb @@ -19,6 +19,7 @@ require 'models/warehouse_thing' require 'rexml/document' class Category < ActiveRecord::Base; end +class Categorization < ActiveRecord::Base; end class Smarts < ActiveRecord::Base; end class CreditCard < ActiveRecord::Base class PinNumber < ActiveRecord::Base @@ -75,7 +76,7 @@ class TopicWithProtectedContentAndAccessibleAuthorName < ActiveRecord::Base end class BasicsTest < ActiveRecord::TestCase - fixtures :topics, :companies, :developers, :projects, :computers, :accounts, :minimalistics, 'warehouse-things', :authors + fixtures :topics, :companies, :developers, :projects, :computers, :accounts, :minimalistics, 'warehouse-things', :authors, :categorizations def test_table_exists assert !NonExistentTable.table_exists? @@ -130,7 +131,7 @@ class BasicsTest < ActiveRecord::TestCase def test_read_attributes_before_type_cast category = Category.new({:name=>"Test categoty", :type => nil}) - category_attrs = {"name"=>"Test categoty", "type" => nil} + category_attrs = {"name"=>"Test categoty", "type" => nil, "categorizations_count" => nil} assert_equal category_attrs , category.attributes_before_type_cast end @@ -614,6 +615,22 @@ class BasicsTest < ActiveRecord::TestCase assert_equal -2, Topic.find(2).replies_count end + def test_update_counter + category = Category.first + assert_nil category.categorizations_count + assert_equal 2, category.categorizations.count + + Category.update_counters(category.id, "categorizations_count" => category.categorizations.count) + category.reload + assert_not_nil category.categorizations_count + assert_equal 2, category.categorizations_count + + Category.update_counters(category.id, "categorizations_count" => category.categorizations.count) + category.reload + assert_not_nil category.categorizations_count + assert_equal 4, category.categorizations_count + end + def test_update_all assert_equal Topic.count, Topic.update_all("content = 'bulk updated!'") assert_equal "bulk updated!", Topic.find(1).content |