Sha256: f22b97a0a57e7282949e14bf8915f5aafa1b2b6e1002809a16fec356b9b13435

Contents?: true

Size: 1.73 KB

Versions: 11

Compression:

Stored size: 1.73 KB

Contents

require 'jdbc_common'
require 'db/h2'

class H2ChangeColumnTest < Test::Unit::TestCase

  class Person < ActiveRecord::Base; end

  class CreatePeopleTable < ActiveRecord::Migration
    def self.up
      create_table :people do |t|
        t.integer :phone
      end
    end

    def self.down
      drop_table :people
    end
  end

  def setup
    CreatePeopleTable.up
  end

  def teardown
    CreatePeopleTable.down
  end

  def test_should_change_column_type
    ActiveRecord::Migration.change_column :people, :phone, :string
    Person.reset_column_information

    p = Person.create!(:phone => 'ABC')
    assert_equal 'ABC', p.phone
  end

  def test_sets_defaults_on_column
    ActiveRecord::Migration.change_column :people, :phone, :string, :default => '123456'
    Person.reset_column_information

    p = Person.create!
    assert_equal '123456', p.phone
  end

  def test_should_change_column_default_value
    ActiveRecord::Migration.add_column    :people, :email, :string, :default => 'foo@example.com'
    ActiveRecord::Migration.change_column :people, :email, :string, :default => 'bar@example.com'
    Person.reset_column_information

    p = Person.create!
    assert_equal 'bar@example.com', p.email
  end

  def test_should_set_non_null_restriction
    ActiveRecord::Migration.change_column :people, :phone, :string, :null => false
    Person.reset_column_information
    assert_raises(ActiveRecord::StatementInvalid) { Person.create! }
  end

  def test_should_set_null_restriction_with_default
    p = Person.create!
    ActiveRecord::Migration.change_column :people, :phone, :string, :null => true, :default => '123456'
    Person.reset_column_information

    assert_nil p.reload.phone
    assert_equal '123456', Person.create!.phone
  end
end

Version data entries

11 entries across 11 versions & 4 rubygems

Version Path
cmoran92-activerecord-jdbc-adapter-1.2.1.2 test/h2_change_column_test.rb
tgbyte-activerecord-jdbc-adapter-1.2.2.5 test/h2_change_column_test.rb
tgbyte-activerecord-jdbc-adapter-1.2.2.4 test/h2_change_column_test.rb
tgbyte-activerecord-jdbc-adapter-1.2.2.3 test/h2_change_column_test.rb
tgbyte-activerecord-jdbc-adapter-1.2.2.2 test/h2_change_column_test.rb
activerecord-jdbc-adapter-1.2.2.1 test/h2_change_column_test.rb
activerecord-jdbc-adapter-onsite-1.2.2 test/h2_change_column_test.rb
cmoran92-activerecord-jdbc-adapter-1.2.1.1 test/h2_change_column_test.rb
activerecord-jdbc-adapter-1.2.2 test/h2_change_column_test.rb
cmoran92-activerecord-jdbc-adapter-1.2.1 test/h2_change_column_test.rb
activerecord-jdbc-adapter-1.2.1 test/h2_change_column_test.rb