Sha256: 5c143f0ccf7a617570228ef7d87a862eacea849cddc7e0ef51b630577dedaeb2

Contents?: true

Size: 1.23 KB

Versions: 4

Compression:

Stored size: 1.23 KB

Contents

# frozen_string_literal: true

require "cases/helper"

module ActiveRecord
  module ConnectionAdapters
    class ColumnDefinitionTest < ActiveRecord::TestCase
      def setup
        @adapter = AbstractAdapter.new(nil)
        def @adapter.native_database_types
          { string: "varchar" }
        end
        @viz = @adapter.send(:schema_creation)
      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_def = ColumnDefinition.new("title", "string", limit: 20)
        assert_equal "title varchar(20)", @viz.accept(column_def)
      end

      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

      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
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
ibm_db-5.5.0-x86-mingw32 test/cases/column_definition_test.rb
ibm_db-5.4.1-x86-mingw32 test/cases/column_definition_test.rb
ibm_db-5.4.0-x86-mingw32 test/cases/column_definition_test.rb
ibm_db-5.3.2-x86-mingw32 test/cases/column_definition_test.rb