mirror of
https://github.com/github/rails.git
synced 2026-04-26 03:00:59 -04:00
Backport #3232 to 3-1-stable.
Use the schema_search_path in prepared statements in postgres.
Only the tests are backported, the fix was already included by
commit 818d285305.
This commit is contained in:
@@ -1,5 +1,10 @@
|
||||
## Rails 3.1.2 (unreleased) ##
|
||||
|
||||
* Fix problem with prepared statements and PostgreSQL when multiple schemas are used.
|
||||
*GH #3232*
|
||||
|
||||
*Juan M. Cuello*
|
||||
|
||||
* Fix bug with PostgreSQLAdapter#indexes. When the search path has multiple schemas, spaces
|
||||
were not being stripped from the schema names after the first.
|
||||
|
||||
|
||||
@@ -37,6 +37,10 @@ class SchemaTest < ActiveRecord::TestCase
|
||||
set_table_name 'test_schema."Things"'
|
||||
end
|
||||
|
||||
class Thing5 < ActiveRecord::Base
|
||||
set_table_name 'things'
|
||||
end
|
||||
|
||||
def setup
|
||||
@connection = ActiveRecord::Base.connection
|
||||
@connection.execute "CREATE SCHEMA #{SCHEMA_NAME} CREATE TABLE #{TABLE_NAME} (#{COLUMNS.join(',')})"
|
||||
@@ -178,6 +182,21 @@ class SchemaTest < ActiveRecord::TestCase
|
||||
ActiveRecord::Base.connection.schema_search_path = "public"
|
||||
end
|
||||
|
||||
def test_prepared_statements_with_multiple_schemas
|
||||
|
||||
@connection.schema_search_path = SCHEMA_NAME
|
||||
Thing5.create(:id => 1, :name => "thing inside #{SCHEMA_NAME}", :email => "thing1@localhost", :moment => Time.now)
|
||||
|
||||
@connection.schema_search_path = SCHEMA2_NAME
|
||||
Thing5.create(:id => 1, :name => "thing inside #{SCHEMA2_NAME}", :email => "thing1@localhost", :moment => Time.now)
|
||||
|
||||
@connection.schema_search_path = SCHEMA_NAME
|
||||
assert_equal 1, Thing5.count
|
||||
|
||||
@connection.schema_search_path = SCHEMA2_NAME
|
||||
assert_equal 1, Thing5.count
|
||||
end
|
||||
|
||||
private
|
||||
def columns(table_name)
|
||||
@connection.send(:column_definitions, table_name).map do |name, type, default|
|
||||
|
||||
Reference in New Issue
Block a user