2017-07-09 13:41:28 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2011-06-06 14:17:44 -04:00
|
|
|
require "cases/helper"
|
2008-07-14 11:12:54 -04:00
|
|
|
|
2011-01-31 17:38:20 -05:00
|
|
|
module ActiveRecord
|
|
|
|
module ConnectionAdapters
|
|
|
|
class ColumnDefinitionTest < ActiveRecord::TestCase
|
|
|
|
def setup
|
|
|
|
@adapter = AbstractAdapter.new(nil)
|
|
|
|
def @adapter.native_database_types
|
2016-08-16 03:30:11 -04:00
|
|
|
{ string: "varchar" }
|
2011-01-31 17:38:20 -05:00
|
|
|
end
|
2017-02-17 08:58:52 -05:00
|
|
|
@viz = @adapter.send(:schema_creation)
|
2011-01-31 17:38:20 -05:00
|
|
|
end
|
2009-08-09 23:43:56 -04:00
|
|
|
|
2011-01-31 17:38:20 -05:00
|
|
|
# Avoid column definitions in create table statements like:
|
|
|
|
# `title` varchar(255) DEFAULT NULL
|
|
|
|
def test_should_not_include_default_clause_when_default_is_null
|
2017-02-02 18:50:46 -05:00
|
|
|
column_def = ColumnDefinition.new("title", "string", limit: 20)
|
2016-08-06 13:55:02 -04:00
|
|
|
assert_equal "title varchar(20)", @viz.accept(column_def)
|
2011-01-31 17:38:20 -05:00
|
|
|
end
|
2009-08-09 23:43:56 -04:00
|
|
|
|
2011-01-31 17:38:20 -05:00
|
|
|
def test_should_include_default_clause_when_default_is_present
|
2017-02-02 18:50:46 -05:00
|
|
|
column_def = ColumnDefinition.new("title", "string", limit: 20, default: "Hello")
|
2016-08-06 14:20:22 -04:00
|
|
|
assert_equal "title varchar(20) DEFAULT 'Hello'", @viz.accept(column_def)
|
2009-08-09 23:43:56 -04:00
|
|
|
end
|
|
|
|
|
2011-01-31 17:38:20 -05:00
|
|
|
def test_should_specify_not_null_if_null_option_is_false
|
2017-02-02 18:50:46 -05:00
|
|
|
column_def = ColumnDefinition.new("title", "string", limit: 20, default: "Hello", null: false)
|
2016-08-06 14:20:22 -04:00
|
|
|
assert_equal "title varchar(20) DEFAULT 'Hello' NOT NULL", @viz.accept(column_def)
|
2009-08-09 23:43:56 -04:00
|
|
|
end
|
2010-03-31 17:05:34 -04:00
|
|
|
end
|
|
|
|
end
|
2008-08-23 12:51:09 -04:00
|
|
|
end
|