From e5299c1ef693ef434f55811027a7da975cd55ba5 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Mon, 23 Sep 2013 15:58:34 -0700 Subject: hm:t preloading will respect order set on the RHS association --- .../associations/has_many_through_associations_test.rb | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'activerecord/test/cases') diff --git a/activerecord/test/cases/associations/has_many_through_associations_test.rb b/activerecord/test/cases/associations/has_many_through_associations_test.rb index dd8b426b25..99c71a1dd9 100644 --- a/activerecord/test/cases/associations/has_many_through_associations_test.rb +++ b/activerecord/test/cases/associations/has_many_through_associations_test.rb @@ -41,6 +41,21 @@ class HasManyThroughAssociationsTest < ActiveRecord::TestCase Class.new(ActiveRecord::Base) { define_singleton_method(:name) { name } } end + def test_ordered_habtm + person_prime = Class.new(ActiveRecord::Base) do + def self.name; 'Person'; end + + has_many :readers + has_many :posts, -> { order('posts.id DESC') }, :through => :readers + end + posts = person_prime.includes(:posts).first.posts + + assert_operator posts.length, :>, 1 + posts.each_cons(2) do |left,right| + assert_operator left.id, :>, right.id + end + end + def test_singleton_has_many_through book = make_model "Book" subscription = make_model "Subscription" -- cgit v1.2.3