From aafa00f4c10a6791e6470112f0f1fbe5f2c3f649 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Mendon=C3=A7a=20Fran=C3=A7a?= Date: Sun, 1 Jul 2012 12:57:48 -0300 Subject: Unify the collation API for the database adpters --- activerecord/CHANGELOG.md | 4 ++-- .../lib/active_record/connection_adapters/postgresql_adapter.rb | 8 ++++---- activerecord/lib/active_record/tasks/postgresql_database_tasks.rb | 2 +- activerecord/test/cases/adapters/postgresql/active_schema_test.rb | 4 ++-- activerecord/test/cases/adapters/postgresql/connection_test.rb | 4 ++-- activerecord/test/cases/tasks/postgresql_rake_test.rb | 8 ++++---- 6 files changed, 15 insertions(+), 15 deletions(-) diff --git a/activerecord/CHANGELOG.md b/activerecord/CHANGELOG.md index 73f9212371..84fffb3d17 100644 --- a/activerecord/CHANGELOG.md +++ b/activerecord/CHANGELOG.md @@ -16,7 +16,7 @@ *Brian Cardarella* -* Add `collate` and `ctype` support to PostgreSQL. These are available for PostgreSQL 8.4 or later. +* Add `collation` and `ctype` support to PostgreSQL. These are available for PostgreSQL 8.4 or later. Example: development: @@ -26,7 +26,7 @@ username: foo password: bar encoding: UTF8 - collate: ja_JP.UTF8 + collation: ja_JP.UTF8 ctype: ja_JP.UTF8 *kennyj* diff --git a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb index 507e937c3e..7b263fd62d 100644 --- a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb @@ -916,7 +916,7 @@ module ActiveRecord end # Create a new PostgreSQL database. Options include :owner, :template, - # :encoding, :collate, :ctype, + # :encoding, :collation, :ctype, # :tablespace, and :connection_limit (note that MySQL uses # :charset while PostgreSQL uses :encoding). # @@ -934,7 +934,7 @@ module ActiveRecord " TEMPLATE = \"#{value}\"" when :encoding " ENCODING = '#{value}'" - when :collate + when :collation " LC_COLLATE = '#{value}'" when :ctype " LC_CTYPE = '#{value}'" @@ -1064,8 +1064,8 @@ module ActiveRecord end_sql end - # Returns the current database collate. - def collate + # Returns the current database collation. + def collation query(<<-end_sql, 'SCHEMA')[0][0] SELECT pg_database.datcollate FROM pg_database WHERE pg_database.datname LIKE '#{current_database}' end_sql diff --git a/activerecord/lib/active_record/tasks/postgresql_database_tasks.rb b/activerecord/lib/active_record/tasks/postgresql_database_tasks.rb index 4139460273..ea5cb888fb 100644 --- a/activerecord/lib/active_record/tasks/postgresql_database_tasks.rb +++ b/activerecord/lib/active_record/tasks/postgresql_database_tasks.rb @@ -30,7 +30,7 @@ module ActiveRecord end def collation - connection.collate + connection.collation end def purge diff --git a/activerecord/test/cases/adapters/postgresql/active_schema_test.rb b/activerecord/test/cases/adapters/postgresql/active_schema_test.rb index 148584214e..113c27b194 100644 --- a/activerecord/test/cases/adapters/postgresql/active_schema_test.rb +++ b/activerecord/test/cases/adapters/postgresql/active_schema_test.rb @@ -21,8 +21,8 @@ class PostgresqlActiveSchemaTest < ActiveRecord::TestCase assert_equal %(CREATE DATABASE "aimonetti" ENCODING = 'latin1'), create_database(:aimonetti, :encoding => :latin1) end - def test_create_database_with_collate_and_ctype - assert_equal %(CREATE DATABASE "aimonetti" ENCODING = 'UTF8' LC_COLLATE = 'ja_JP.UTF8' LC_CTYPE = 'ja_JP.UTF8'), create_database(:aimonetti, :encoding => :"UTF8", :collate => :"ja_JP.UTF8", :ctype => :"ja_JP.UTF8") + def test_create_database_with_collation_and_ctype + assert_equal %(CREATE DATABASE "aimonetti" ENCODING = 'UTF8' LC_COLLATE = 'ja_JP.UTF8' LC_CTYPE = 'ja_JP.UTF8'), create_database(:aimonetti, :encoding => :"UTF8", :collation => :"ja_JP.UTF8", :ctype => :"ja_JP.UTF8") end def test_add_index diff --git a/activerecord/test/cases/adapters/postgresql/connection_test.rb b/activerecord/test/cases/adapters/postgresql/connection_test.rb index 9b5c5eb72f..f823ce33d8 100644 --- a/activerecord/test/cases/adapters/postgresql/connection_test.rb +++ b/activerecord/test/cases/adapters/postgresql/connection_test.rb @@ -21,8 +21,8 @@ module ActiveRecord assert_not_nil @connection.encoding end - def test_collate - assert_not_nil @connection.collate + def test_collation + assert_not_nil @connection.collation end def test_ctype diff --git a/activerecord/test/cases/tasks/postgresql_rake_test.rb b/activerecord/test/cases/tasks/postgresql_rake_test.rb index df1075d816..62acd53003 100644 --- a/activerecord/test/cases/tasks/postgresql_rake_test.rb +++ b/activerecord/test/cases/tasks/postgresql_rake_test.rb @@ -38,12 +38,12 @@ module ActiveRecord merge('encoding' => 'latin') end - def test_creates_database_with_given_collate_and_ctype + def test_creates_database_with_given_collation_and_ctype @connection.expects(:create_database). - with('my-app-db', @configuration.merge('encoding' => 'utf8', 'collate' => 'ja_JP.UTF8', 'ctype' => 'ja_JP.UTF8')) + with('my-app-db', @configuration.merge('encoding' => 'utf8', 'collation' => 'ja_JP.UTF8', 'ctype' => 'ja_JP.UTF8')) ActiveRecord::Tasks::DatabaseTasks.create @configuration. - merge('collate' => 'ja_JP.UTF8', 'ctype' => 'ja_JP.UTF8') + merge('collation' => 'ja_JP.UTF8', 'ctype' => 'ja_JP.UTF8') end def test_establishes_connection_to_new_database @@ -172,7 +172,7 @@ module ActiveRecord end def test_db_retrieves_collation - @connection.expects(:collate) + @connection.expects(:collation) ActiveRecord::Tasks::DatabaseTasks.collation @configuration end end -- cgit v1.2.3