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
radiant-0.7.2 vendor/rails/activerecord/test/cases/column_definition_test.rb
nbudin-castronaut-0.7.5 vendor/activerecord/test/cases/column_definition_test.rb
usher-0.7.0 spec/rails2_2/vendor/rails/vendor/rails/activerecord/test/cases/column_definition_test.rb
usher-0.7.0 spec/rails2_3/vendor/rails/vendor/rails/activerecord/pkg/activerecord-2.3.3/test/cases/column_definition_test.rb
usher-0.7.0 spec/rails2_3/vendor/rails/vendor/rails/activerecord/test/cases/column_definition_test.rb
usher-0.7.0 spec/rails2_2/vendor/rails/vendor/rails/activerecord/pkg/activerecord-2.2.2/test/cases/column_definition_test.rb
factorylabs-castronaut-0.7.5 vendor/activerecord/test/cases/column_definition_test.rb
activerecord-2.2.3 test/cases/column_definition_test.rb
webroar-0.2.2 src/admin_panel/vendor/rails/activerecord/test/cases/column_definition_test.rb
activerecord-2.3.3 test/cases/column_definition_test.rb
activerecord-2.1.2 test/cases/column_definition_test.rb
activerecord-2.3.2 test/cases/column_definition_test.rb
activerecord-2.2.2 test/cases/column_definition_test.rb
activerecord-2.1.1 test/cases/column_definition_test.rb
radiant-0.7.0 vendor/rails/activerecord/test/cases/column_definition_test.rb
radiant-0.7.1 vendor/rails/activerecord/test/cases/column_definition_test.rb
radiant-0.8.0 vendor/rails/activerecord/test/cases/column_definition_test.rb