Skip to content
This repository
Browse code

Unify the collation API for the database adpters

  • Loading branch information...
commit aafa00f4c10a6791e6470112f0f1fbe5f2c3f649 1 parent 36938b4
Rafael Mendonça França authored July 01, 2012
4  activerecord/CHANGELOG.md
Source Rendered
@@ -16,7 +16,7 @@
16 16
 
17 17
     *Brian Cardarella*
18 18
 
19  
-*   Add `collate` and `ctype` support to PostgreSQL. These are available for PostgreSQL 8.4 or later.
  19
+*   Add `collation` and `ctype` support to PostgreSQL. These are available for PostgreSQL 8.4 or later.
20 20
     Example:
21 21
 
22 22
       development:
@@ -26,7 +26,7 @@
26 26
         username: foo
27 27
         password: bar
28 28
         encoding: UTF8
29  
-        collate: ja_JP.UTF8
  29
+        collation: ja_JP.UTF8
30 30
         ctype: ja_JP.UTF8
31 31
 
32 32
     *kennyj*
8  activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
@@ -916,7 +916,7 @@ def recreate_database(name, options = {}) #:nodoc:
916 916
       end
917 917
 
918 918
       # Create a new PostgreSQL database. Options include <tt>:owner</tt>, <tt>:template</tt>,
919  
-      # <tt>:encoding</tt>, <tt>:collate</tt>, <tt>:ctype</tt>,
  919
+      # <tt>:encoding</tt>, <tt>:collation</tt>, <tt>:ctype</tt>,
920 920
       # <tt>:tablespace</tt>, and <tt>:connection_limit</tt> (note that MySQL uses
921 921
       # <tt>:charset</tt> while PostgreSQL uses <tt>:encoding</tt>).
922 922
       #
@@ -934,7 +934,7 @@ def create_database(name, options = {})
934 934
             " TEMPLATE = \"#{value}\""
935 935
           when :encoding
936 936
             " ENCODING = '#{value}'"
937  
-          when :collate
  937
+          when :collation
938 938
             " LC_COLLATE = '#{value}'"
939 939
           when :ctype
940 940
             " LC_CTYPE = '#{value}'"
@@ -1064,8 +1064,8 @@ def encoding
1064 1064
         end_sql
1065 1065
       end
1066 1066
 
1067  
-      # Returns the current database collate.
1068  
-      def collate
  1067
+      # Returns the current database collation.
  1068
+      def collation
1069 1069
         query(<<-end_sql, 'SCHEMA')[0][0]
1070 1070
           SELECT pg_database.datcollate FROM pg_database WHERE pg_database.datname LIKE '#{current_database}'
1071 1071
         end_sql
2  activerecord/lib/active_record/tasks/postgresql_database_tasks.rb
@@ -30,7 +30,7 @@ def charset
30 30
       end
31 31
 
32 32
       def collation
33  
-        connection.collate
  33
+        connection.collation
34 34
       end
35 35
 
36 36
       def purge
4  activerecord/test/cases/adapters/postgresql/active_schema_test.rb
@@ -21,8 +21,8 @@ def test_create_database_with_encoding
21 21
     assert_equal %(CREATE DATABASE "aimonetti" ENCODING = 'latin1'), create_database(:aimonetti, :encoding => :latin1)
22 22
   end
23 23
 
24  
-  def test_create_database_with_collate_and_ctype
25  
-    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")
  24
+  def test_create_database_with_collation_and_ctype
  25
+    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")
26 26
   end
27 27
 
28 28
   def test_add_index
4  activerecord/test/cases/adapters/postgresql/connection_test.rb
@@ -21,8 +21,8 @@ def test_encoding
21 21
       assert_not_nil @connection.encoding
22 22
     end
23 23
 
24  
-    def test_collate
25  
-      assert_not_nil @connection.collate
  24
+    def test_collation
  25
+      assert_not_nil @connection.collation
26 26
     end
27 27
 
28 28
     def test_ctype
8  activerecord/test/cases/tasks/postgresql_rake_test.rb
@@ -38,12 +38,12 @@ def test_creates_database_with_given_encoding
38 38
         merge('encoding' => 'latin')
39 39
     end
40 40
 
41  
-    def test_creates_database_with_given_collate_and_ctype
  41
+    def test_creates_database_with_given_collation_and_ctype
42 42
       @connection.expects(:create_database).
43  
-        with('my-app-db', @configuration.merge('encoding' => 'utf8', 'collate' => 'ja_JP.UTF8', 'ctype' => 'ja_JP.UTF8'))
  43
+        with('my-app-db', @configuration.merge('encoding' => 'utf8', 'collation' => 'ja_JP.UTF8', 'ctype' => 'ja_JP.UTF8'))
44 44
 
45 45
       ActiveRecord::Tasks::DatabaseTasks.create @configuration.
46  
-        merge('collate' => 'ja_JP.UTF8', 'ctype' => 'ja_JP.UTF8')
  46
+        merge('collation' => 'ja_JP.UTF8', 'ctype' => 'ja_JP.UTF8')
47 47
     end
48 48
 
49 49
     def test_establishes_connection_to_new_database
@@ -172,7 +172,7 @@ def setup
172 172
     end
173 173
 
174 174
     def test_db_retrieves_collation
175  
-      @connection.expects(:collate)
  175
+      @connection.expects(:collation)
176 176
       ActiveRecord::Tasks::DatabaseTasks.collation @configuration
177 177
     end
178 178
   end

0 notes on commit aafa00f

Please sign in to comment.
Something went wrong with that request. Please try again.