From 73d5e216086a9a3b0fd0efa6fab6f73bba3fa32e Mon Sep 17 00:00:00 2001 From: Ryuta Kamizono Date: Mon, 18 Mar 2019 01:48:20 +0900 Subject: Add test case for unscoping `:optimizer_hints` --- activerecord/test/cases/adapters/mysql2/optimizer_hints_test.rb | 6 ++++++ activerecord/test/cases/adapters/postgresql/optimizer_hints_test.rb | 6 ++++++ 2 files changed, 12 insertions(+) (limited to 'activerecord/test/cases') diff --git a/activerecord/test/cases/adapters/mysql2/optimizer_hints_test.rb b/activerecord/test/cases/adapters/mysql2/optimizer_hints_test.rb index 349de49b36..31a002e935 100644 --- a/activerecord/test/cases/adapters/mysql2/optimizer_hints_test.rb +++ b/activerecord/test/cases/adapters/mysql2/optimizer_hints_test.rb @@ -19,6 +19,12 @@ if supports_optimizer_hints? posts = posts.select(:id).where(author_id: [0, 1]) assert_includes posts.explain, "| index | index_posts_on_author_id | index_posts_on_author_id |" end + + assert_sql(%r{\ASELECT `posts`\.`id`}) do + posts = Post.optimizer_hints("/*+ NO_RANGE_OPTIMIZATION(posts index_posts_on_author_id) */") + posts = posts.select(:id).where(author_id: [0, 1]) + posts.unscope(:optimizer_hints).load + end end end end diff --git a/activerecord/test/cases/adapters/postgresql/optimizer_hints_test.rb b/activerecord/test/cases/adapters/postgresql/optimizer_hints_test.rb index 1bfa815cac..4fac7ffdc0 100644 --- a/activerecord/test/cases/adapters/postgresql/optimizer_hints_test.rb +++ b/activerecord/test/cases/adapters/postgresql/optimizer_hints_test.rb @@ -23,6 +23,12 @@ if supports_optimizer_hints? posts = posts.select(:id).where(author_id: [0, 1]) assert_includes posts.explain, "Seq Scan on posts" end + + assert_sql(%r{\ASELECT "posts"\."id"}) do + posts = Post.optimizer_hints("/*+ SeqScan(posts) */") + posts = posts.select(:id).where(author_id: [0, 1]) + posts.unscope(:optimizer_hints).load + end end end end -- cgit v1.2.3