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.
This commit is contained in:
parent
9008a60dc5
commit
8b77d8e387
|
@ -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
|
|
@ -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
|
Loading…
Reference in New Issue