Skip to content

Commit dc4ca14

Browse files
Lairton Léliswpolicarpo
authored andcommitted
Add test cases for change_column_null bug
1 parent 3fdaa10 commit dc4ca14

File tree

2 files changed

+65
-0
lines changed

2 files changed

+65
-0
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
require 'cases/helper_sqlserver'
2+
require 'migrations/create_clients_and_change_column_null'
3+
4+
class ChangeColumnNullTestSqlServer < ActiveRecord::TestCase
5+
before do
6+
@old_verbose = ActiveRecord::Migration.verbose
7+
ActiveRecord::Migration.verbose = false
8+
CreateClientsAndChangeColumnNull.new.up
9+
end
10+
11+
after do
12+
CreateClientsAndChangeColumnNull.new.down
13+
ActiveRecord::Migration.verbose = @old_verbose
14+
end
15+
16+
def find_column(table, name)
17+
table.find { |column| column.name == name }
18+
end
19+
20+
let(:clients_table) { connection.columns('clients') }
21+
let(:name_column) { find_column(clients_table, 'name') }
22+
let(:code_column) { find_column(clients_table, 'code') }
23+
let(:value_column) { find_column(clients_table, 'value') }
24+
25+
describe '#change_column_null' do
26+
it 'does not change the column limit' do
27+
name_column.limit.must_equal 15
28+
end
29+
30+
it 'does not change the column default' do
31+
code_column.default.must_equal 'n/a'
32+
end
33+
34+
it 'does not change the column precision' do
35+
value_column.precision.must_equal 32
36+
end
37+
38+
it 'does not change the column scale' do
39+
value_column.scale.must_equal 8
40+
end
41+
end
42+
end
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
class CreateClientsAndChangeColumnNull < ActiveRecord::Migration[5.2]
2+
def up
3+
create_table :clients do |t|
4+
t.string :name
5+
t.string :code
6+
t.decimal :value
7+
8+
t.timestamps
9+
end
10+
11+
change_column :clients, :name, :string, limit: 15
12+
change_column :clients, :code, :string, default: 'n/a'
13+
change_column :clients, :value, :decimal, precision: 32, scale: 8
14+
15+
change_column_null :clients, :name, false
16+
change_column_null :clients, :code, false
17+
change_column_null :clients, :value, false
18+
end
19+
20+
def down
21+
drop_table :clients
22+
end
23+
end

0 commit comments

Comments
 (0)