diff options
author | Sean Griffin <sean@thoughtbot.com> | 2014-05-17 12:24:13 -0600 |
---|---|---|
committer | Sean Griffin <sean@thoughtbot.com> | 2014-05-19 08:07:21 -0700 |
commit | 0b682e4b05c8f58c77c655650af6638c483ac903 (patch) | |
tree | e22d197ed7d828dad7f249d8878a8fb8cff1ebd2 /activerecord/test/cases/connection_adapters/type_lookup_test.rb | |
parent | a0eec57ef0fbbbb2910a46ca65bd5b565ca0534c (diff) | |
download | rails-0b682e4b05c8f58c77c655650af6638c483ac903.tar.gz rails-0b682e4b05c8f58c77c655650af6638c483ac903.tar.bz2 rails-0b682e4b05c8f58c77c655650af6638c483ac903.zip |
Delegate `Column#type` to the injected type object
The decision to wrap type registrations in a proc was made for two
reasons.
1. Some cases need to make an additional decision based on the type
(e.g. a `Decimal` with a 0 scale)
2. Aliased types are automatically updated if they type they point to is
updated later. If a user or another adapter decides to change the
object used for `decimal` columns, `numeric`, and `number` will
automatically point to the new type, without having to track what
types are aliased explicitly.
Everything else here should be pretty straightforward. PostgreSQL ranges
had to change slightly, since the `simplified_type` method is gone.
Diffstat (limited to 'activerecord/test/cases/connection_adapters/type_lookup_test.rb')
-rw-r--r-- | activerecord/test/cases/connection_adapters/type_lookup_test.rb | 100 |
1 files changed, 100 insertions, 0 deletions
diff --git a/activerecord/test/cases/connection_adapters/type_lookup_test.rb b/activerecord/test/cases/connection_adapters/type_lookup_test.rb new file mode 100644 index 0000000000..a5b01260d3 --- /dev/null +++ b/activerecord/test/cases/connection_adapters/type_lookup_test.rb @@ -0,0 +1,100 @@ +require "cases/helper" + +unless current_adapter?(:PostgreSQLAdapter) # PostgreSQL does not use type strigns for lookup +module ActiveRecord + module ConnectionAdapters + class TypeLookupTest < ActiveRecord::TestCase + setup do + @connection = ActiveRecord::Base.connection + end + + def test_boolean_types + assert_lookup_type :boolean, 'boolean' + assert_lookup_type :boolean, 'BOOLEAN' + end + + def test_string_types + assert_lookup_type :string, 'char' + assert_lookup_type :string, 'varchar' + assert_lookup_type :string, 'VARCHAR' + assert_lookup_type :string, 'varchar(255)' + assert_lookup_type :string, 'character varying' + end + + def test_binary_types + assert_lookup_type :binary, 'binary' + assert_lookup_type :binary, 'BINARY' + assert_lookup_type :binary, 'blob' + assert_lookup_type :binary, 'BLOB' + end + + def test_text_types + assert_lookup_type :text, 'text' + assert_lookup_type :text, 'TEXT' + assert_lookup_type :text, 'clob' + assert_lookup_type :text, 'CLOB' + end + + def test_date_types + assert_lookup_type :date, 'date' + assert_lookup_type :date, 'DATE' + end + + def test_time_types + assert_lookup_type :time, 'time' + assert_lookup_type :time, 'TIME' + end + + def test_timestamp_types + assert_lookup_type :timestamp, 'timestamp' + assert_lookup_type :timestamp, 'TIMESTAMP' + end + + def test_datetime_types + assert_lookup_type :datetime, 'datetime' + assert_lookup_type :datetime, 'DATETIME' + end + + def test_decimal_types + assert_lookup_type :decimal, 'decimal' + assert_lookup_type :decimal, 'decimal(2,8)' + assert_lookup_type :decimal, 'DECIMAL' + assert_lookup_type :decimal, 'numeric' + assert_lookup_type :decimal, 'numeric(2,8)' + assert_lookup_type :decimal, 'NUMERIC' + assert_lookup_type :decimal, 'number' + assert_lookup_type :decimal, 'number(2,8)' + assert_lookup_type :decimal, 'NUMBER' + end + + def test_float_types + assert_lookup_type :float, 'float' + assert_lookup_type :float, 'FLOAT' + assert_lookup_type :float, 'double' + assert_lookup_type :float, 'DOUBLE' + end + + def test_integer_types + assert_lookup_type :integer, 'integer' + assert_lookup_type :integer, 'INTEGER' + assert_lookup_type :integer, 'tinyint' + assert_lookup_type :integer, 'smallint' + assert_lookup_type :integer, 'bigint' + assert_lookup_type :integer, 'decimal(2)' + assert_lookup_type :integer, 'decimal(2,0)' + assert_lookup_type :integer, 'numeric(2)' + assert_lookup_type :integer, 'numeric(2,0)' + assert_lookup_type :integer, 'number(2)' + assert_lookup_type :integer, 'number(2,0)' + end + + private + + def assert_lookup_type(type, lookup) + cast_type = @connection.type_map.lookup(lookup) + assert_equal type, cast_type.type + end + end + end +end +end |