Froze rails gems
[depot.git] / vendor / rails / activerecord / test / cases / column_definition_test.rb
1 require "cases/helper"
2
3 class ColumnDefinitionTest < ActiveRecord::TestCase
4 def setup
5 @adapter = ActiveRecord::ConnectionAdapters::AbstractAdapter.new(nil)
6 def @adapter.native_database_types
7 {:string => "varchar"}
8 end
9 end
10
11 # Avoid column definitions in create table statements like:
12 # `title` varchar(255) DEFAULT NULL
13 def test_should_not_include_default_clause_when_default_is_null
14 column = ActiveRecord::ConnectionAdapters::Column.new("title", nil, "varchar(20)")
15 column_def = ActiveRecord::ConnectionAdapters::ColumnDefinition.new(
16 @adapter, column.name, "string",
17 column.limit, column.precision, column.scale, column.default, column.null)
18 assert_equal "title varchar(20)", column_def.to_sql
19 end
20
21 def test_should_include_default_clause_when_default_is_present
22 column = ActiveRecord::ConnectionAdapters::Column.new("title", "Hello", "varchar(20)")
23 column_def = ActiveRecord::ConnectionAdapters::ColumnDefinition.new(
24 @adapter, column.name, "string",
25 column.limit, column.precision, column.scale, column.default, column.null)
26 assert_equal %Q{title varchar(20) DEFAULT 'Hello'}, column_def.to_sql
27 end
28
29 def test_should_specify_not_null_if_null_option_is_false
30 column = ActiveRecord::ConnectionAdapters::Column.new("title", "Hello", "varchar(20)", false)
31 column_def = ActiveRecord::ConnectionAdapters::ColumnDefinition.new(
32 @adapter, column.name, "string",
33 column.limit, column.precision, column.scale, column.default, column.null)
34 assert_equal %Q{title varchar(20) DEFAULT 'Hello' NOT NULL}, column_def.to_sql
35 end
36 end