Skip to content

Commit

Permalink
Merge pull request #3633 from Juanmcuello/3-1-stable
Browse files Browse the repository at this point in the history
Backport #3232 to 3-1-stable
  • Loading branch information
jonleighton committed Nov 15, 2011
1 parent 5ea132b commit ffd1519
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
5 changes: 5 additions & 0 deletions activerecord/CHANGELOG.md
@@ -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.

Expand Down
19 changes: 19 additions & 0 deletions activerecord/test/cases/adapters/postgresql/schema_test.rb
Expand Up @@ -37,6 +37,10 @@ class Thing4 < ActiveRecord::Base
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(',')})"
Expand Down Expand Up @@ -178,6 +182,21 @@ def test_with_uppercase_index_name
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|
Expand Down

0 comments on commit ffd1519

Please sign in to comment.