From 8b77d8e387079da2d5d4cf2f6fcc4864195852bc Mon Sep 17 00:00:00 2001 From: Prathamesh Sonpatki Date: Sun, 20 Nov 2016 11:28:03 +0530 Subject: 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. --- .../prepared_statements_disabled_test.rb | 25 ++++++++++++++++++++++ .../postgresql/prepared_statements_test.rb | 22 ------------------- 2 files changed, 25 insertions(+), 22 deletions(-) create mode 100644 activerecord/test/cases/adapters/postgresql/prepared_statements_disabled_test.rb delete mode 100644 activerecord/test/cases/adapters/postgresql/prepared_statements_test.rb (limited to 'activerecord/test/cases') 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 -- cgit v1.2.3