Sha256: 2a0a69866abc6f60283a1c5d918df1b38aa336851d434bfa19517148204a80af

Contents?: true

Size: 1.19 KB

Versions: 8

Compression:

Stored size: 1.19 KB

Contents

require 'cases/helper'

module ActiveRecord
  class Migration
    class PGChangeSchemaTest < ActiveRecord::PostgreSQLTestCase
      attr_reader :connection

      def setup
        super
        @connection = ActiveRecord::Base.connection
        connection.create_table(:strings) do |t|
          t.string :somedate
        end
      end

      def teardown
        connection.drop_table :strings
      end

      def test_change_string_to_date
        connection.change_column :strings, :somedate, :timestamp, using: 'CAST("somedate" AS timestamp)'
        assert_equal :datetime, connection.columns(:strings).find { |c| c.name == 'somedate' }.type
      end

      def test_change_type_with_symbol
        connection.change_column :strings, :somedate, :timestamp, cast_as: :timestamp
        assert_equal :datetime, connection.columns(:strings).find { |c| c.name == 'somedate' }.type
      end

      def test_change_type_with_array
        connection.change_column :strings, :somedate, :timestamp, array: true, cast_as: :timestamp
        column = connection.columns(:strings).find { |c| c.name == 'somedate' }
        assert_equal :datetime, column.type
        assert column.array?
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
ibm_db-5.2.0 test/cases/adapters/postgresql/change_schema_test.rb
ibm_db-5.1.0 test/cases/adapters/postgresql/change_schema_test.rb
ibm_db-5.0.5 test/cases/adapters/postgresql/change_schema_test.rb
ibm_db-5.0.4 test/cases/adapters/postgresql/change_schema_test.rb
ibm_db-5.0.3 test/cases/adapters/postgresql/change_schema_test.rb
ibm_db-5.0.2 test/cases/adapters/postgresql/change_schema_test.rb
ibm_db-4.0.0-x86-mingw32 test/cases/adapters/postgresql/change_schema_test.rb
ibm_db-4.0.0 test/cases/adapters/postgresql/change_schema_test.rb