diff options
author | Jamis Buck <jamis@37signals.com> | 2006-03-09 17:23:57 +0000 |
---|---|---|
committer | Jamis Buck <jamis@37signals.com> | 2006-03-09 17:23:57 +0000 |
commit | 87898badba211540d9c1d4dae0cd513a9d525554 (patch) | |
tree | 5423e8e10a2b0d9d48b845230d33028315e2d794 /activerecord/test | |
parent | 130001c377e7abf17ea2f4f856cab30882a60f92 (diff) | |
download | rails-87898badba211540d9c1d4dae0cd513a9d525554.tar.gz rails-87898badba211540d9c1d4dae0cd513a9d525554.tar.bz2 rails-87898badba211540d9c1d4dae0cd513a9d525554.zip |
Allow counter_cache to accept a column name
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@3825 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/test')
-rwxr-xr-x | activerecord/test/associations_test.rb | 22 | ||||
-rw-r--r-- | activerecord/test/fixtures/db_definitions/schema.rb | 20 | ||||
-rwxr-xr-x | activerecord/test/fixtures/reply.rb | 1 |
3 files changed, 32 insertions, 11 deletions
diff --git a/activerecord/test/associations_test.rb b/activerecord/test/associations_test.rb index f687d3781e..8616c4d4ad 100755 --- a/activerecord/test/associations_test.rb +++ b/activerecord/test/associations_test.rb @@ -917,7 +917,27 @@ class BelongsToAssociationsTest < Test::Unit::TestCase assert_not_nil computer.developer, ":foreign key == attribute didn't lock up" # ' end - def xtest_counter_cache + def test_counter_cache + topic = Topic.create :title => "Zoom-zoom-zoom" + assert_equal 0, topic[:replies_count] + + reply = Reply.create(:title => "re: zoom", :content => "speedy quick!") + reply.topic = topic + + assert_equal 1, topic.reload[:replies_count] + end + + def test_custom_counter_cache + reply = Reply.create(:title => "re: zoom", :content => "speedy quick!") + assert_equal 0, reply[:replies_count] + + silly = SillyReply.create(:title => "gaga", :content => "boo-boo") + silly.reply = reply + + assert_equal 1, reply.reload[:replies_count] + end + + def xtest_size_uses_counter_cache apple = Firm.create("name" => "Apple") final_cut = apple.clients.create("name" => "Final Cut") diff --git a/activerecord/test/fixtures/db_definitions/schema.rb b/activerecord/test/fixtures/db_definitions/schema.rb index f2e9eacb08..53aa7c1967 100644 --- a/activerecord/test/fixtures/db_definitions/schema.rb +++ b/activerecord/test/fixtures/db_definitions/schema.rb @@ -1,20 +1,20 @@ ActiveRecord::Schema.define do - create_table "taggings", :force => true do |t| - t.column "tag_id", :integer - t.column "taggable_type", :string - t.column "taggable_id", :integer + create_table :taggings, :force => true do |t| + t.column :tag_id, :integer + t.column :taggable_type, :string + t.column :taggable_id, :integer end - create_table "tags", :force => true do |t| - t.column "name", :string + create_table :tags, :force => true do |t| + t.column :name, :string t.column :taggings_count, :integer, :default => 0 end - create_table "categorizations", :force => true do |t| - t.column "category_id", :integer - t.column "post_id", :integer - t.column "author_id", :integer + create_table :categorizations, :force => true do |t| + t.column :category_id, :integer + t.column :post_id, :integer + t.column :author_id, :integer end add_column :posts, :taggings_count, :integer, :default => 0 diff --git a/activerecord/test/fixtures/reply.rb b/activerecord/test/fixtures/reply.rb index ed22deaa74..04a50e9322 100755 --- a/activerecord/test/fixtures/reply.rb +++ b/activerecord/test/fixtures/reply.rb @@ -33,4 +33,5 @@ class Reply < Topic end class SillyReply < Reply + belongs_to :reply, :foreign_key => "parent_id", :counter_cache => :replies_count end |