diff options
Diffstat (limited to 'activerecord/test/cases/finder_test.rb')
-rw-r--r-- | activerecord/test/cases/finder_test.rb | 40 |
1 files changed, 20 insertions, 20 deletions
diff --git a/activerecord/test/cases/finder_test.rb b/activerecord/test/cases/finder_test.rb index d8bc917e7f..65ebfcd989 100644 --- a/activerecord/test/cases/finder_test.rb +++ b/activerecord/test/cases/finder_test.rb @@ -239,19 +239,19 @@ class FinderTest < ActiveRecord::TestCase # Ensure +exists?+ runs without an error by excluding order value. def test_exists_with_order - assert_equal true, Topic.order("invalid sql here").exists? + assert_equal true, Topic.order(Arel.sql("invalid sql here")).exists? end def test_exists_with_joins - assert_equal true, Topic.joins(:replies).where(replies_topics: { approved: true }).order("replies_topics.created_at DESC").exists? + assert_equal true, Topic.joins(:replies).where(replies_topics: { approved: true }).order(Arel.sql("replies_topics.created_at DESC")).exists? end def test_exists_with_left_joins - assert_equal true, Topic.left_joins(:replies).where(replies_topics: { approved: true }).order("replies_topics.created_at DESC").exists? + assert_equal true, Topic.left_joins(:replies).where(replies_topics: { approved: true }).order(Arel.sql("replies_topics.created_at DESC")).exists? end def test_exists_with_eager_load - assert_equal true, Topic.eager_load(:replies).where(replies_topics: { approved: true }).order("replies_topics.created_at DESC").exists? + assert_equal true, Topic.eager_load(:replies).where(replies_topics: { approved: true }).order(Arel.sql("replies_topics.created_at DESC")).exists? end def test_exists_with_includes_limit_and_empty_result @@ -267,8 +267,8 @@ class FinderTest < ActiveRecord::TestCase def test_exists_with_distinct_association_includes_limit_and_order author = Author.first - assert_equal false, author.unique_categorized_posts.includes(:special_comments).order("comments.tags_count DESC").limit(0).exists? - assert_equal true, author.unique_categorized_posts.includes(:special_comments).order("comments.tags_count DESC").limit(1).exists? + assert_equal false, author.unique_categorized_posts.includes(:special_comments).order(Arel.sql("comments.tags_count DESC")).limit(0).exists? + assert_equal true, author.unique_categorized_posts.includes(:special_comments).order(Arel.sql("comments.tags_count DESC")).limit(1).exists? end def test_exists_should_reference_correct_aliases_while_joining_tables_of_has_many_through_association @@ -652,7 +652,7 @@ class FinderTest < ActiveRecord::TestCase def test_last_with_irreversible_order assert_raises(ActiveRecord::IrreversibleOrderError) do - Topic.order("coalesce(author_name, title)").last + Topic.order(Arel.sql("coalesce(author_name, title)")).last end end @@ -813,9 +813,9 @@ class FinderTest < ActiveRecord::TestCase end def test_hash_condition_find_with_array - p1, p2 = Post.limit(2).order("id asc").to_a - assert_equal [p1, p2], Post.where(id: [p1, p2]).order("id asc").to_a - assert_equal [p1, p2], Post.where(id: [p1, p2.id]).order("id asc").to_a + p1, p2 = Post.limit(2).order(Arel.sql("id asc")).to_a + assert_equal [p1, p2], Post.where(id: [p1, p2]).order(Arel.sql("id asc")).to_a + assert_equal [p1, p2], Post.where(id: [p1, p2.id]).order(Arel.sql("id asc")).to_a end def test_hash_condition_find_with_nil @@ -1013,7 +1013,7 @@ class FinderTest < ActiveRecord::TestCase end def test_find_by_one_attribute_with_several_options - assert_equal accounts(:unknown), Account.order("id DESC").where("id != ?", 3).find_by_credit_limit(50) + assert_equal accounts(:unknown), Account.order(Arel.sql("id DESC")).where("id != ?", 3).find_by_credit_limit(50) end def test_find_by_one_missing_attribute @@ -1041,7 +1041,7 @@ class FinderTest < ActiveRecord::TestCase assert_equal devs[2], Developer.offset(2).first assert_equal devs[-3], Developer.offset(2).last - assert_equal devs[-3], Developer.offset(2).order("id DESC").first + assert_equal devs[-3], Developer.offset(2).order(Arel.sql("id DESC")).first end def test_find_by_nil_attribute @@ -1094,9 +1094,9 @@ class FinderTest < ActiveRecord::TestCase end def test_find_by_records - p1, p2 = Post.limit(2).order("id asc").to_a - assert_equal [p1, p2], Post.where(["id in (?)", [p1, p2]]).order("id asc") - assert_equal [p1, p2], Post.where(["id in (?)", [p1, p2.id]]).order("id asc") + p1, p2 = Post.limit(2).order(Arel.sql("id asc")).to_a + assert_equal [p1, p2], Post.where(["id in (?)", [p1, p2]]).order(Arel.sql("id asc")) + assert_equal [p1, p2], Post.where(["id in (?)", [p1, p2.id]]).order(Arel.sql("id asc")) end def test_select_value @@ -1125,18 +1125,18 @@ class FinderTest < ActiveRecord::TestCase def test_find_with_order_on_included_associations_with_construct_finder_sql_for_association_limiting_and_is_distinct assert_equal 2, Post.includes(authors: :author_address). where.not(author_addresses: { id: nil }). - order("author_addresses.id DESC").limit(2).to_a.size + order(Arel.sql("author_addresses.id DESC")).limit(2).to_a.size assert_equal 3, Post.includes(author: :author_address, authors: :author_address). where.not(author_addresses_authors: { id: nil }). - order("author_addresses_authors.id DESC").limit(3).to_a.size + order(Arel.sql("author_addresses_authors.id DESC")).limit(3).to_a.size end def test_find_with_nil_inside_set_passed_for_one_attribute client_of = Company. where(client_of: [2, 1, nil], name: ["37signals", "Summit", "Microsoft"]). - order("client_of DESC"). + order(Arel.sql("client_of DESC")). map(&:client_of) assert_includes client_of, nil @@ -1146,7 +1146,7 @@ class FinderTest < ActiveRecord::TestCase def test_find_with_nil_inside_set_passed_for_attribute client_of = Company. where(client_of: [nil]). - order("client_of DESC"). + order(Arel.sql("client_of DESC")). map(&:client_of) assert_equal [], client_of.compact @@ -1155,7 +1155,7 @@ class FinderTest < ActiveRecord::TestCase def test_with_limiting_with_custom_select posts = Post.references(:authors).merge( includes: :author, select: 'posts.*, authors.id as "author_id"', - limit: 3, order: "posts.id" + limit: 3, order: Arel.sql("posts.id") ).to_a assert_equal 3, posts.size assert_equal [0, 1, 1], posts.map(&:author_id).sort |