aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test
diff options
context:
space:
mode:
authorAdam Cooper <adam.cooper@gmail.com>2008-12-31 01:43:13 -0800
committerPratik Naik <pratiknaik@gmail.com>2009-03-06 22:05:18 +0000
commit3ca5a0f9fd7b7921bca970859da8637011b22dd1 (patch)
tree43a05f30708106cb98cab1e51dda07c8acd3352b /activerecord/test
parent984bc7a614852944808739fae09a654b6e62872e (diff)
downloadrails-3ca5a0f9fd7b7921bca970859da8637011b22dd1.tar.gz
rails-3ca5a0f9fd7b7921bca970859da8637011b22dd1.tar.bz2
rails-3ca5a0f9fd7b7921bca970859da8637011b22dd1.zip
Ensure belongs_to association with a counter cache in name spaced model works [#1678 state:resolved]
Signed-off-by: Pratik Naik <pratiknaik@gmail.com>
Diffstat (limited to 'activerecord/test')
-rw-r--r--activerecord/test/cases/associations/belongs_to_associations_test.rb17
-rw-r--r--activerecord/test/models/reply.rb6
-rw-r--r--activerecord/test/models/topic.rb6
3 files changed, 29 insertions, 0 deletions
diff --git a/activerecord/test/cases/associations/belongs_to_associations_test.rb b/activerecord/test/cases/associations/belongs_to_associations_test.rb
index 92ed465ae7..78b90121b4 100644
--- a/activerecord/test/cases/associations/belongs_to_associations_test.rb
+++ b/activerecord/test/cases/associations/belongs_to_associations_test.rb
@@ -154,6 +154,23 @@ class BelongsToAssociationsTest < ActiveRecord::TestCase
assert_equal 0, Topic.find(t2.id).replies.size
end
+ def test_belongs_to_reassign_with_namespaced_models_and_counters
+ t1 = Web::Topic.create("title" => "t1")
+ t2 = Web::Topic.create("title" => "t2")
+ r1 = Web::Reply.new("title" => "r1", "content" => "r1")
+ r1.topic = t1
+
+ assert r1.save
+ assert_equal 1, Web::Topic.find(t1.id).replies.size
+ assert_equal 0, Web::Topic.find(t2.id).replies.size
+
+ r1.topic = Web::Topic.find(t2.id)
+
+ assert r1.save
+ assert_equal 0, Web::Topic.find(t1.id).replies.size
+ assert_equal 1, Web::Topic.find(t2.id).replies.size
+ end
+
def test_belongs_to_counter_after_save
topic = Topic.create!(:title => "monday night")
topic.replies.create!(:title => "re: monday night", :content => "football")
diff --git a/activerecord/test/models/reply.rb b/activerecord/test/models/reply.rb
index 812bc1f535..1c990acab6 100644
--- a/activerecord/test/models/reply.rb
+++ b/activerecord/test/models/reply.rb
@@ -37,3 +37,9 @@ end
class SillyReply < Reply
belongs_to :reply, :foreign_key => "parent_id", :counter_cache => :replies_count
end
+
+module Web
+ class Reply < Web::Topic
+ belongs_to :topic, :foreign_key => "parent_id", :counter_cache => true, :class_name => 'Web::Topic'
+ end
+end \ No newline at end of file
diff --git a/activerecord/test/models/topic.rb b/activerecord/test/models/topic.rb
index 2fe846db48..f1b7bbae3b 100644
--- a/activerecord/test/models/topic.rb
+++ b/activerecord/test/models/topic.rb
@@ -71,3 +71,9 @@ class Topic < ActiveRecord::Base
end
end
end
+
+module Web
+ class Topic < ActiveRecord::Base
+ has_many :replies, :dependent => :destroy, :foreign_key => "parent_id", :class_name => 'Web::Reply'
+ end
+end \ No newline at end of file