提交 a04e1036 编写于 作者: J Jon Leighton 提交者: Aaron Patterson

Verify that creating a has_many through record where there is a default_scope...

Verify that creating a has_many through record where there is a default_scope on the join model works correctly (creates the join record with the default scope applied)
上级 16e93f2c
......@@ -17,6 +17,8 @@
require 'models/subscriber'
require 'models/book'
require 'models/subscription'
require 'models/categorization'
require 'models/category'
class HasManyThroughAssociationsTest < ActiveRecord::TestCase
fixtures :posts, :readers, :people, :comments, :authors,
......@@ -466,4 +468,9 @@ def test_size_of_through_association_should_increase_correctly_when_has_many_ass
def test_has_many_through_with_default_scope_on_join_model
assert_equal posts(:welcome).comments, authors(:david).comments_on_first_posts
end
def test_create_has_many_through_with_default_scope_on_join_model
category = authors(:david).special_categories.create(:name => "Foo")
assert_equal 1, category.categorizations.where(:special => true).count
end
end
......@@ -77,6 +77,10 @@ def testing_proxy_target
has_many :categorizations
has_many :categories, :through => :categorizations
has_many :special_categorizations
has_many :special_categories, :through => :special_categorizations, :source => :category
has_one :special_category, :through => :special_categorizations, :source => :category
has_many :categories_like_general, :through => :categorizations, :source => :category, :class_name => 'Category', :conditions => { :name => 'General' }
has_many :categorized_posts, :through => :categorizations, :source => :post
......
......@@ -2,4 +2,13 @@ class Categorization < ActiveRecord::Base
belongs_to :post
belongs_to :category
belongs_to :author
end
\ No newline at end of file
end
class SpecialCategorization < ActiveRecord::Base
self.table_name = 'categorizations'
default_scope where(:special => true)
belongs_to :author
belongs_to :category
end
......@@ -112,6 +112,7 @@ def create_table(*args, &block)
t.column :category_id, :integer
t.column :post_id, :integer
t.column :author_id, :integer
t.column :special, :boolean
end
create_table :citations, :force => true do |t|
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册