/
h2_change_column_test.rb
67 lines (51 loc) · 1.71 KB
/
h2_change_column_test.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
require 'jdbc_common'
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