Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Verify that creating a has_many through record where there is a defau…

…lt_scope on the join model works correctly (creates the join record with the default scope applied)
  • Loading branch information...
commit a04e1036691ca98579dd8b8b6cb19ffb23f85c72 1 parent 16e93f2
@jonleighton jonleighton authored tenderlove committed
View
7 activerecord/test/cases/associations/has_many_through_associations_test.rb
@@ -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
View
4 activerecord/test/models/author.rb
@@ -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
View
11 activerecord/test/models/categorization.rb
@@ -2,4 +2,13 @@ class Categorization < ActiveRecord::Base
belongs_to :post
belongs_to :category
belongs_to :author
-end
+end
+
+class SpecialCategorization < ActiveRecord::Base
+ self.table_name = 'categorizations'
+
+ default_scope where(:special => true)
+
+ belongs_to :author
+ belongs_to :category
+end
View
1  activerecord/test/schema/schema.rb
@@ -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|
Please sign in to comment.
Something went wrong with that request. Please try again.