diff options
author | Vipul A M <vipulnsward@gmail.com> | 2016-04-25 23:35:36 +0530 |
---|---|---|
committer | Vipul A M <vipulnsward@gmail.com> | 2016-04-25 23:35:36 +0530 |
commit | 2af2d6b0571fb10d165ad60395b43d86d8cb34c0 (patch) | |
tree | 5e1b6ce1f8e654c234b568c364d10629c49358a2 | |
parent | e007afd3cd7255c752fe8ab7fa24b59526ab95cb (diff) | |
download | rails-2af2d6b0571fb10d165ad60395b43d86d8cb34c0.tar.gz rails-2af2d6b0571fb10d165ad60395b43d86d8cb34c0.tar.bz2 rails-2af2d6b0571fb10d165ad60395b43d86d8cb34c0.zip |
Dont simply assume a type is a valid database type. This is only always true in the case of sqlite.
Others adapters need to perform a check for validity.
Add coverage for mysql2 db type validation
3 files changed, 16 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb b/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb index 86de8f1ca0..373c082f65 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb @@ -154,7 +154,7 @@ module ActiveRecord end def valid_type?(type) - true + false end def schema_creation diff --git a/activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb b/activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb index 1d7ce92b29..e3793e6c77 100644 --- a/activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb @@ -154,6 +154,10 @@ module ActiveRecord true end + def valid_type?(type) + true + end + # Returns 62. SQLite supports index names up to 64 # characters. The rest is used by rails internally to perform # temporary rename operations diff --git a/activerecord/test/cases/adapters/mysql2/mysql2_adapter_test.rb b/activerecord/test/cases/adapters/mysql2/mysql2_adapter_test.rb index 00d23740b6..61dd0828d0 100644 --- a/activerecord/test/cases/adapters/mysql2/mysql2_adapter_test.rb +++ b/activerecord/test/cases/adapters/mysql2/mysql2_adapter_test.rb @@ -17,6 +17,17 @@ class Mysql2AdapterTest < ActiveRecord::Mysql2TestCase end end + def test_valid_column + with_example_table do + column = @conn.columns('ex').find { |col| col.name == 'id' } + assert @conn.valid_type?(column.type) + end + end + + def test_invalid_column + assert_not @conn.valid_type?(:foobar) + end + def test_columns_for_distinct_zero_orders assert_equal "posts.id", @conn.columns_for_distinct("posts.id", []) |