class ActiveRecord::ConnectionAdapters::ColumnDefinitionTest

Public Instance Methods

setup() click to toggle source
# File activerecord/test/cases/column_definition_test.rb, line 8
def setup
  @adapter = AbstractAdapter.new(nil)
  def @adapter.native_database_types
    { string: "varchar" }
  end
  @viz = @adapter.send(:schema_creation)
end
test_should_include_default_clause_when_default_is_present() click to toggle source
# File activerecord/test/cases/column_definition_test.rb, line 23
def test_should_include_default_clause_when_default_is_present
  column_def = ColumnDefinition.new("title", "string", limit: 20, default: "Hello")
  assert_equal "title varchar(20) DEFAULT 'Hello'", @viz.accept(column_def)
end
test_should_not_include_default_clause_when_default_is_null() click to toggle source

Avoid column definitions in create table statements like: `title` varchar(255) DEFAULT NULL

# File activerecord/test/cases/column_definition_test.rb, line 18
def test_should_not_include_default_clause_when_default_is_null
  column_def = ColumnDefinition.new("title", "string", limit: 20)
  assert_equal "title varchar(20)", @viz.accept(column_def)
end
test_should_specify_not_null_if_null_option_is_false() click to toggle source
# File activerecord/test/cases/column_definition_test.rb, line 28
def test_should_specify_not_null_if_null_option_is_false
  column_def = ColumnDefinition.new("title", "string", limit: 20, default: "Hello", null: false)
  assert_equal "title varchar(20) DEFAULT 'Hello' NOT NULL", @viz.accept(column_def)
end