From 89cd33b824ae9dc4567c326882331e3dffc07c5a Mon Sep 17 00:00:00 2001 From: Peter Jaros Date: Mon, 21 Oct 2013 18:12:45 -0400 Subject: [PATCH] Demonstrate bug: Rails 4 order hashes in has_many. --- .../adapters/active_record/relation_extensions_spec.rb | 9 +++++++++ spec/support/models.rb | 2 ++ 2 files changed, 11 insertions(+) diff --git a/spec/squeel/adapters/active_record/relation_extensions_spec.rb b/spec/squeel/adapters/active_record/relation_extensions_spec.rb index 2754316..90ea4a5 100644 --- a/spec/squeel/adapters/active_record/relation_extensions_spec.rb +++ b/spec/squeel/adapters/active_record/relation_extensions_spec.rb @@ -657,6 +657,15 @@ module ActiveRecord end end + it 'allows AR 4.0-style hash options inside an association' do + if activerecord_version_at_least '4.0.0' + block = Person.first.articles_with_order + block.to_sql.should match /ORDER BY "articles"\."title" DESC/ + else + pending 'Not required in AR versions < 4.0.0' + end + end + it 'allows ordering by an attributes of a joined table' do relation = Article.joins(:person).order { person.id.asc } relation.to_sql.should match /ORDER BY "people"\."id" ASC/ diff --git a/spec/support/models.rb b/spec/support/models.rb index 1fcc4df..6e51c9b 100644 --- a/spec/support/models.rb +++ b/spec/support/models.rb @@ -9,6 +9,8 @@ class Person < ActiveRecord::Base has_many :article_comments_with_first_post, lambda { where :body => 'first post' }, :through => :articles, :source => :comments + has_many :articles_with_order, lambda { order :title => :desc }, + :class_name => 'Article' else has_many :articles_with_condition, :conditions => {:title => 'Condition'}, :class_name => 'Article'