From e1e5f3005705b3028ca3a09c61444a8c21398273 Mon Sep 17 00:00:00 2001 From: Vitor Baptista Date: Tue, 15 Jan 2013 23:19:02 -0300 Subject: Don't rely on Hash key's ordering If we set encoding latin1 for a PostgreSQL database, it calls PostgreSQLAdapter::create_database with options that have, among other things: { 'encoding' => 'latin1' } Then, we use reverse_merge(:encoding => "utf8") to setup the default encoding. In the end, the hash looks like: { :encoding => 'utf8', 'encoding' => 'latin1' } The call to options.symbolize_keys calls to_sym on each_key of this Hash. It usually means that the encoding passed overwrites the default utf8, but it's not guaranteed. So, we shouldn't rely on it. The same was happening in ActiveRecord::ConnectionHandling. --- activerecord/test/cases/adapters/postgresql/active_schema_test.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'activerecord/test/cases/adapters') diff --git a/activerecord/test/cases/adapters/postgresql/active_schema_test.rb b/activerecord/test/cases/adapters/postgresql/active_schema_test.rb index 1b4f4a5fc9..01c3e6b49b 100644 --- a/activerecord/test/cases/adapters/postgresql/active_schema_test.rb +++ b/activerecord/test/cases/adapters/postgresql/active_schema_test.rb @@ -16,6 +16,7 @@ class PostgresqlActiveSchemaTest < ActiveRecord::TestCase def test_create_database_with_encoding assert_equal %(CREATE DATABASE "matt" ENCODING = 'utf8'), create_database(:matt) assert_equal %(CREATE DATABASE "aimonetti" ENCODING = 'latin1'), create_database(:aimonetti, :encoding => :latin1) + assert_equal %(CREATE DATABASE "aimonetti" ENCODING = 'latin1'), create_database(:aimonetti, 'encoding' => :latin1) end def test_create_database_with_collation_and_ctype -- cgit v1.2.3