diff options
author | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2013-02-26 05:15:14 -0800 |
---|---|---|
committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2013-02-26 05:15:14 -0800 |
commit | 8bc5e714f48af5ef94e4c884121ca55729013c7b (patch) | |
tree | d79d8bc784cfe968238cf88feccb56354331804f /activerecord/test | |
parent | 39394ab3dbc32d063adcf03390f36067d4e83a13 (diff) | |
parent | e0356990856abc9a84e6e038e7b06e2931502728 (diff) | |
download | rails-8bc5e714f48af5ef94e4c884121ca55729013c7b.tar.gz rails-8bc5e714f48af5ef94e4c884121ca55729013c7b.tar.bz2 rails-8bc5e714f48af5ef94e4c884121ca55729013c7b.zip |
Merge pull request #9414 from senny/9275_order_with_symbol_and_join
Expand order(:symbol) to "table".symbol to prevent broken queries on PG.
Diffstat (limited to 'activerecord/test')
-rw-r--r-- | activerecord/test/cases/associations/eager_test.rb | 5 | ||||
-rw-r--r-- | activerecord/test/cases/relation_test.rb | 17 |
2 files changed, 20 insertions, 2 deletions
diff --git a/activerecord/test/cases/associations/eager_test.rb b/activerecord/test/cases/associations/eager_test.rb index 6ed3cb7b58..1de7ee0846 100644 --- a/activerecord/test/cases/associations/eager_test.rb +++ b/activerecord/test/cases/associations/eager_test.rb @@ -1173,4 +1173,9 @@ class EagerAssociationTest < ActiveRecord::TestCase assert_no_queries { assert_equal 2, author.comments_with_order_and_conditions.size } assert_no_queries { assert_equal 5, author.posts.size, "should not cache a subset of the association" } end + + test "works in combination with order(:symbol)" do + author = Author.includes(:posts).references(:posts).order(:name).where('posts.title IS NOT NULL').first + assert_equal authors(:bob), author + end end diff --git a/activerecord/test/cases/relation_test.rb b/activerecord/test/cases/relation_test.rb index 92dc575d37..fd0b05cb77 100644 --- a/activerecord/test/cases/relation_test.rb +++ b/activerecord/test/cases/relation_test.rb @@ -180,19 +180,32 @@ module ActiveRecord class RelationMutationTest < ActiveSupport::TestCase class FakeKlass < Struct.new(:table_name, :name) + def quoted_table_name + %{"#{table_name}"} + end end def relation - @relation ||= Relation.new FakeKlass, :b + @relation ||= Relation.new FakeKlass.new('posts'), :b end - (Relation::MULTI_VALUE_METHODS - [:references, :extending]).each do |method| + (Relation::MULTI_VALUE_METHODS - [:references, :extending, :order]).each do |method| test "##{method}!" do assert relation.public_send("#{method}!", :foo).equal?(relation) assert_equal [:foo], relation.public_send("#{method}_values") end end + test "#order!" do + assert relation.order!('name ASC').equal?(relation) + assert_equal ['name ASC'], relation.order_values + end + + test "#order! with symbol prepends the table name" do + assert relation.order!(:name).equal?(relation) + assert_equal ['"posts".name ASC'], relation.order_values + end + test '#references!' do assert relation.references!(:foo).equal?(relation) assert relation.references_values.include?('foo') |