Permalink
Browse files

PostgreSQL, test cases to lock the current column types.

  • Loading branch information...
1 parent c81e4e6 commit 13b618f48d0c31184577c11cf8b89437b4bc1ce6 @senny senny committed Mar 28, 2014
View
3 activerecord/test/cases/adapters/postgresql/array_test.rb
@@ -25,8 +25,11 @@ def setup
def test_column
assert_equal :string, @column.type
+ assert_equal "character varying(255)", @column.sql_type
assert @column.array
assert_not @column.text?
+ assert_not @column.number?
+ assert_not @column.binary?
ratings_column = PgArray.columns_hash['ratings']
assert_equal :integer, ratings_column.type
View
15 activerecord/test/cases/adapters/postgresql/citext_test.rb
@@ -23,7 +23,6 @@ def setup
@connection.create_table('citexts') do |t|
t.citext 'cival'
end
- @column = Citext.columns_hash['cival']
end
teardown do
@@ -35,12 +34,14 @@ def test_citext_enabled
assert @connection.extension_enabled?('citext')
end
- def test_column_type
- assert_equal :citext, @column.type
- end
-
- def test_column_sql_type
- assert_equal 'citext', @column.sql_type
+ def test_column
+ column = Citext.columns_hash['cival']
+ assert_equal :citext, column.type
+ assert_equal 'citext', column.sql_type
+ assert_not column.text?
+ assert_not column.number?
+ assert_not column.binary?
+ assert_not column.array
end
def test_change_table_supports_json
View
11 activerecord/test/cases/adapters/postgresql/composite_test.rb
@@ -29,6 +29,17 @@ def setup
end
end
+ def test_column
+ column = PostgresqlComposite.columns_hash["address"]
+ # TODO: Composite columns should have a type
+ assert_nil column.type
+ assert_equal "full_address", column.sql_type
+ assert_not column.number?
+ assert_not column.text?
+ assert_not column.binary?
+ assert_not column.array
+ end
+
def test_composite_mapping
@connection.execute "INSERT INTO postgresql_composites VALUES (1, ROW('Paris', 'Champs-Élysées'));"
composite = PostgresqlComposite.first
View
11 activerecord/test/cases/adapters/postgresql/enum_test.rb
@@ -27,6 +27,17 @@ def setup
@connection.send(:reload_type_map)
end
+ def test_column
+ column = PostgresqlEnum.columns_hash["current_mood"]
+ # TODO: enum columns should be of type enum or string, not nil.
+ assert_nil column.type
+ assert_equal "mood", column.sql_type
+ assert_not column.number?
+ assert_not column.text?
+ assert_not column.binary?
+ assert_not column.array
+ end
+
def test_enum_mapping
@connection.execute "INSERT INTO postgresql_enums VALUES (1, 'sad');"
enum = PostgresqlEnum.first
View
5 activerecord/test/cases/adapters/postgresql/hstore_test.rb
@@ -54,6 +54,11 @@ def test_disable_enable_hstore
def test_column
assert_equal :hstore, @column.type
+ assert_equal "hstore", @column.sql_type
+ assert_not @column.number?
+ assert_not @column.text?
+ assert_not @column.binary?
+ assert_not @column.array
end
def test_change_table_supports_hstore
View
20 activerecord/test/cases/adapters/postgresql/json_test.rb
@@ -31,7 +31,13 @@ def setup
end
def test_column
- assert_equal :json, @column.type
+ column = JsonDataType.columns_hash["payload"]
+ assert_equal :json, column.type
+ assert_equal "json", column.sql_type
+ assert_not column.number?
+ assert_not column.text?
+ assert_not column.binary?
+ assert_not column.array
end
def test_change_table_supports_json
@@ -57,16 +63,16 @@ def test_cast_value_on_write
end
def test_type_cast_json
- assert @column
+ column = JsonDataType.columns_hash["payload"]
data = "{\"a_key\":\"a_value\"}"
- hash = @column.class.string_to_json data
+ hash = column.class.string_to_json data
assert_equal({'a_key' => 'a_value'}, hash)
- assert_equal({'a_key' => 'a_value'}, @column.type_cast(data))
+ assert_equal({'a_key' => 'a_value'}, column.type_cast(data))
- assert_equal({}, @column.type_cast("{}"))
- assert_equal({'key'=>nil}, @column.type_cast('{"key": null}'))
- assert_equal({'c'=>'}','"a"'=>'b "a b'}, @column.type_cast(%q({"c":"}", "\"a\"":"b \"a b"})))
+ assert_equal({}, column.type_cast("{}"))
+ assert_equal({'key'=>nil}, column.type_cast('{"key": null}'))
+ assert_equal({'c'=>'}','"a"'=>'b "a b'}, column.type_cast(%q({"c":"}", "\"a\"":"b \"a b"})))
end
def test_rewrite
View
10 activerecord/test/cases/adapters/postgresql/ltree_test.rb
@@ -10,6 +10,11 @@ class Ltree < ActiveRecord::Base
def setup
@connection = ActiveRecord::Base.connection
+
+ unless @connection.extension_enabled?('ltree')
+ @connection.enable_extension 'ltree'
+ end
+
@connection.transaction do
@connection.create_table('ltrees') do |t|
t.ltree 'path'
@@ -26,6 +31,11 @@ def setup
def test_column
column = Ltree.columns_hash['path']
assert_equal :ltree, column.type
+ assert_equal "ltree", column.sql_type
+ assert_not column.number?
+ assert_not column.text?
+ assert_not column.binary?
+ assert_not column.array
end
def test_write
View
8 activerecord/test/cases/adapters/postgresql/uuid_test.rb
@@ -41,7 +41,13 @@ class UUIDType < ActiveRecord::Base
end
def test_data_type_of_uuid_types
- assert_equal :uuid, UUIDType.columns_hash["guid"].type
+ column = UUIDType.columns_hash["guid"]
+ assert_equal :uuid, column.type
+ assert_equal "uuid", column.sql_type
+ assert_not column.number?
+ assert_not column.text?
+ assert_not column.binary?
+ assert_not column.array
end
def test_uuid_formats

0 comments on commit 13b618f

Please sign in to comment.