aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPrathamesh Sonpatki <csonpatki@gmail.com>2016-11-20 11:28:03 +0530
committerPrathamesh Sonpatki <csonpatki@gmail.com>2016-11-20 14:20:35 +0530
commit8b77d8e387079da2d5d4cf2f6fcc4864195852bc (patch)
treeb6a44f43c03216802039e0b2250b4fa3372f6f8f
parent9008a60dc5c24b0fe884087095900797ace6263a (diff)
downloadrails-8b77d8e387079da2d5d4cf2f6fcc4864195852bc.tar.gz
rails-8b77d8e387079da2d5d4cf2f6fcc4864195852bc.tar.bz2
rails-8b77d8e387079da2d5d4cf2f6fcc4864195852bc.zip
Fix prepared statements disabled test again
- Due to `assert_nothing_raised` this test was not really testing anything. - So updated it to assert that the query gives expected result. - Also in general we can use `connection.unprepared_statement` for testing queries w/o prepared statements but it can't be used in this case. This test cases was added because when prepared_statements config is set to false, then DetermineIfPreparableVisitor module does not extended by Arel visitor resulting into an error. Ref: https://github.com/rails/rails/pull/22748. - Because DetermineIfPreparableVisitor module does not get added to the visitor chain only if prepared_statements is false while **setting up connection**, not when `unprepared_statement` is used. - I have also added an assertion for making sure that prepared_config is set to false from the start, so that nobody accidentally removes the connection setup using `arunit_without_prepared_statements` and replaces it with stubs or unprepared_statement.
-rw-r--r--activerecord/test/cases/adapters/postgresql/prepared_statements_disabled_test.rb25
-rw-r--r--activerecord/test/cases/adapters/postgresql/prepared_statements_test.rb22
2 files changed, 25 insertions, 22 deletions
diff --git a/activerecord/test/cases/adapters/postgresql/prepared_statements_disabled_test.rb b/activerecord/test/cases/adapters/postgresql/prepared_statements_disabled_test.rb
new file mode 100644
index 0000000000..8c62690866
--- /dev/null
+++ b/activerecord/test/cases/adapters/postgresql/prepared_statements_disabled_test.rb
@@ -0,0 +1,25 @@
+require "cases/helper"
+require "models/computer"
+require "models/developer"
+
+class PreparedStatementsDisabledTest < ActiveRecord::PostgreSQLTestCase
+ fixtures :developers
+
+ def setup
+ @conn = ActiveRecord::Base.establish_connection :arunit_without_prepared_statements
+ end
+
+ def teardown
+ @conn.release_connection
+ ActiveRecord::Base.establish_connection :arunit
+ end
+
+ def test_select_query_works_even_when_prepared_statements_are_disabled
+ assert_not Developer.connection.prepared_statements
+
+ david = developers(:david)
+
+ assert_equal david, Developer.where(name: "David").last # With Binds
+ assert_operator Developer.count, :>, 0 # Without Binds
+ end
+end
diff --git a/activerecord/test/cases/adapters/postgresql/prepared_statements_test.rb b/activerecord/test/cases/adapters/postgresql/prepared_statements_test.rb
deleted file mode 100644
index b469e66507..0000000000
--- a/activerecord/test/cases/adapters/postgresql/prepared_statements_test.rb
+++ /dev/null
@@ -1,22 +0,0 @@
-require "cases/helper"
-require "models/computer"
-require "models/developer"
-
-class PreparedStatementsTest < ActiveRecord::PostgreSQLTestCase
- fixtures :developers
-
- def setup
- @conn = ActiveRecord::Base.establish_connection :arunit_without_prepared_statements
- end
-
- def teardown
- @conn.release_connection
- ActiveRecord::Base.establish_connection :arunit
- end
-
- def test_nothing_raised_with_falsy_prepared_statements
- assert_nothing_raised do
- Developer.where(id: 1).to_a
- end
- end
-end