From 2af2d6b0571fb10d165ad60395b43d86d8cb34c0 Mon Sep 17 00:00:00 2001 From: Vipul A M Date: Mon, 25 Apr 2016 23:35:36 +0530 Subject: 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 --- .../lib/active_record/connection_adapters/abstract_adapter.rb | 2 +- .../lib/active_record/connection_adapters/sqlite3_adapter.rb | 4 ++++ .../test/cases/adapters/mysql2/mysql2_adapter_test.rb | 11 +++++++++++ 3 files changed, 16 insertions(+), 1 deletion(-) (limited to 'activerecord') 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", []) -- cgit v1.2.3