Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Fixed that create database statements would always include "DEFAULT N…
…ULL" (Nick Sieger) [#334 status:committed]
- Loading branch information
Showing
3 changed files
with
42 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
require "cases/helper" | ||
|
||
class ColumnDefinitionTest < ActiveRecord::TestCase | ||
def setup | ||
@adapter = ActiveRecord::ConnectionAdapters::AbstractAdapter.new(nil) | ||
def @adapter.native_database_types | ||
{:string => "varchar"} | ||
end | ||
end | ||
|
||
# Avoid column definitions in create table statements like: | ||
# `title` varchar(255) DEFAULT NULL NULL | ||
def test_should_not_include_default_clause_when_default_is_null | ||
column = ActiveRecord::ConnectionAdapters::Column.new("title", nil, "varchar(20)") | ||
column_def = ActiveRecord::ConnectionAdapters::ColumnDefinition.new( | ||
@adapter, column.name, "string", | ||
column.limit, column.precision, column.scale, column.default, column.null) | ||
assert_equal "title varchar(20) NULL", column_def.to_sql | ||
end | ||
|
||
def test_should_include_default_clause_when_default_is_present | ||
column = ActiveRecord::ConnectionAdapters::Column.new("title", "Hello", "varchar(20)") | ||
column_def = ActiveRecord::ConnectionAdapters::ColumnDefinition.new( | ||
@adapter, column.name, "string", | ||
column.limit, column.precision, column.scale, column.default, column.null) | ||
assert_equal %Q{title varchar(20) DEFAULT 'Hello' NULL}, column_def.to_sql | ||
end | ||
|
||
def test_should_specify_not_null_if_null_option_is_false | ||
column = ActiveRecord::ConnectionAdapters::Column.new("title", "Hello", "varchar(20)", false) | ||
column_def = ActiveRecord::ConnectionAdapters::ColumnDefinition.new( | ||
@adapter, column.name, "string", | ||
column.limit, column.precision, column.scale, column.default, column.null) | ||
assert_equal %Q{title varchar(20) DEFAULT 'Hello' NOT NULL}, column_def.to_sql | ||
end | ||
end |