提交 a3b16b95 编写于 作者: R Ryuta Kamizono

`valid_type?` should accept only supported types

`valid_type?` is used in schema dumper to determine if a type is
supported. So if `valid_type?(:foobar)` is true, it means that schema
dumper is allowed to create `t.foobar`. But it doesn't work. I think
that `valid_type?` should accept only supported types.

https://github.com/rails/rails/blob/v5.1.0.beta1/activerecord/lib/active_record/schema_dumper.rb#L135-L142

```ruby
  columns.each do |column|
    raise StandardError, "Unknown type '#{column.sql_type}' for column '#{column.name}'" unless @connection.valid_type?(column.type)
    next if column.name == pk
    type, colspec = @connection.column_spec(column)
    tbl.print "    t.#{type} #{column.name.inspect}"
    tbl.print ", #{format_colspec(colspec)}" if colspec.present?
    tbl.puts
  end
```
上级 d50380f4
......@@ -158,10 +158,6 @@ def supports_index_sort_order?
true
end
def valid_type?(type) # :nodoc:
true
end
# Returns 62. SQLite supports index names up to 64
# characters. The rest is used by Rails internally to perform
# temporary rename operations
......
......@@ -30,6 +30,16 @@ def test_create_record_with_pk_as_zero
assert_nothing_raised { Book.destroy(0) }
end
def test_valid_column
@connection.native_database_types.each_key do |type|
assert @connection.valid_type?(type)
end
end
def test_invalid_column
assert_not @connection.valid_type?(:foobar)
end
def test_tables
tables = @connection.tables
assert_includes tables, "accounts"
......
......@@ -17,17 +17,6 @@ def test_exec_query_nothing_raises_with_no_result_queries
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", [])
......
......@@ -21,17 +21,6 @@ def test_bad_connection
end
end
def test_valid_column
with_example_table do
column = @connection.columns("ex").find { |col| col.name == "id" }
assert @connection.valid_type?(column.type)
end
end
def test_invalid_column
assert_not @connection.valid_type?(:foobar)
end
def test_primary_key
with_example_table do
assert_equal "id", @connection.primary_key("ex")
......
......@@ -49,22 +49,6 @@ def test_connect_memory_with_url
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
# sqlite3 databases should be able to support any type and not just the
# ones mentioned in the native_database_types.
#
# Therefore test_invalid column should always return true even if the
# type is not valid.
def test_invalid_column
assert @conn.valid_type?(:foobar)
end
def test_column_types
owner = Owner.create!(name: "hello".encode("ascii-8bit"))
owner.reload
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册