Skip to content

Commit

Permalink
test-case to regressions on uniq hmt with default_scope order.
Browse files Browse the repository at this point in the history
  • Loading branch information
senny committed Feb 8, 2013
1 parent bcf0e08 commit a0ec3c4
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -901,4 +901,9 @@ def test_has_many_through_with_polymorphic_source
readers(:michael_authorless).update(first_post_id: 1) readers(:michael_authorless).update(first_post_id: 1)
assert_equal [posts(:thinking)], person.reload.first_posts assert_equal [posts(:thinking)], person.reload.first_posts
end end

test "has many through with default order scope on the target" do
author = authors(:bob)
assert_equal [posts(:misc_by_bob)], author.unique_categorized_posts_with_default_sort
end
end end
2 changes: 2 additions & 0 deletions activerecord/test/models/author.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ class Author < ActiveRecord::Base
has_many :unchangable_posts, :class_name => "Post", :before_add => :raise_exception, :after_add => :log_after_adding has_many :unchangable_posts, :class_name => "Post", :before_add => :raise_exception, :after_add => :log_after_adding


has_many :categorizations has_many :categorizations
has_many :ordered_categorizations, :class_name => 'OrderedCategorization'
has_many :categories, :through => :categorizations has_many :categories, :through => :categorizations
has_many :named_categories, :through => :categorizations has_many :named_categories, :through => :categorizations


Expand All @@ -79,6 +80,7 @@ class Author < ActiveRecord::Base


has_many :categorized_posts, :through => :categorizations, :source => :post has_many :categorized_posts, :through => :categorizations, :source => :post
has_many :unique_categorized_posts, -> { uniq }, :through => :categorizations, :source => :post has_many :unique_categorized_posts, -> { uniq }, :through => :categorizations, :source => :post
has_many :unique_categorized_posts_with_default_sort, -> { uniq }, through: :ordered_categorizations, source: :default_scope_post


has_many :nothings, :through => :kateggorisatons, :class_name => 'Category' has_many :nothings, :through => :kateggorisatons, :class_name => 'Category'


Expand Down
8 changes: 8 additions & 0 deletions activerecord/test/models/categorization.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -17,3 +17,11 @@ class SpecialCategorization < ActiveRecord::Base
belongs_to :author belongs_to :author
belongs_to :category belongs_to :category
end end

class OrderedCategorization < ActiveRecord::Base
self.table_name = 'categorizations'
default_scope { order('categorizations.category_id') }

belongs_to :default_scope_post, foreign_key: :post_id, class_name: 'PostWithDefaultScope'
belongs_to :author
end

0 comments on commit a0ec3c4

Please sign in to comment.