Sha256: 1270762540d4ffd6c051bbc168e8f1cfc32cef0a211e27db319dd98c9c27afa3

Contents?: true

Size: 1.59 KB

Versions: 37

Compression:

Stored size: 1.59 KB

Contents

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
  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)", 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'}, 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

Version data entries

37 entries across 34 versions & 10 rubygems

Version Path
3mix-castronaut-0.5.0.2 vendor/activerecord/test/cases/column_definition_test.rb
masover-castronaut-0.4.4.4 vendor/activerecord/test/cases/column_definition_test.rb
masover-castronaut-0.4.4.5 vendor/activerecord/test/cases/column_definition_test.rb
masover-castronaut-0.5.0.1 vendor/activerecord/test/cases/column_definition_test.rb
p8-castronaut-0.6.1.1 vendor/activerecord/test/cases/column_definition_test.rb
relevance-castronaut-0.4.1 vendor/activerecord/test/cases/column_definition_test.rb
relevance-castronaut-0.4.2 vendor/activerecord/test/cases/column_definition_test.rb
relevance-castronaut-0.4.3 vendor/activerecord/test/cases/column_definition_test.rb
relevance-castronaut-0.4.4 vendor/activerecord/test/cases/column_definition_test.rb
relevance-castronaut-0.4.5 vendor/activerecord/test/cases/column_definition_test.rb
relevance-castronaut-0.4.6 vendor/activerecord/test/cases/column_definition_test.rb
relevance-castronaut-0.5.0 vendor/activerecord/test/cases/column_definition_test.rb
relevance-castronaut-0.5.1 vendor/activerecord/test/cases/column_definition_test.rb
relevance-castronaut-0.5.2 vendor/activerecord/test/cases/column_definition_test.rb
relevance-castronaut-0.5.3 vendor/activerecord/test/cases/column_definition_test.rb
relevance-castronaut-0.5.4 vendor/activerecord/test/cases/column_definition_test.rb
relevance-castronaut-0.6.0 vendor/activerecord/test/cases/column_definition_test.rb
relevance-castronaut-0.6.1 vendor/activerecord/test/cases/column_definition_test.rb
relevance-castronaut-0.7.4 vendor/activerecord/test/cases/column_definition_test.rb
relevance-castronaut-0.7.5 vendor/activerecord/test/cases/column_definition_test.rb