Skip to content

Commit 10c1a1e

Browse files
committed
Migrations test.
1 parent aaea46c commit 10c1a1e

File tree

3 files changed

+30
-29
lines changed

3 files changed

+30
-29
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
require 'cases/helper_sqlserver'
2+
require 'models/person'
3+
4+
class MigrationTest < ActiveRecord::TestCase
5+
COERCED_TESTS = [:test_migrator_db_has_no_schema_migrations_table]
6+
include ARTest::SQLServer::CoercedTest
7+
8+
# TODO: put a real test here
9+
def test_coerced_test_migrator_db_has_no_schema_migrations_table
10+
assert true
11+
end
12+
13+
end

test/cases/migration_test_sqlserver.rb

Lines changed: 17 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -3,76 +3,64 @@
33

44
class MigrationTestSQLServer < ActiveRecord::TestCase
55

6-
setup do
7-
@connection = ActiveRecord::Base.connection
8-
end
9-
10-
context 'For transactions' do
6+
describe 'For transactions' do
117

12-
setup do
8+
before do
139
@trans_test_table1 = 'sqlserver_trans_table1'
1410
@trans_test_table2 = 'sqlserver_trans_table2'
1511
@trans_tables = [@trans_test_table1,@trans_test_table2]
1612
end
1713

18-
teardown do
14+
after do
1915
@trans_tables.each do |table_name|
20-
ActiveRecord::Migration.drop_table(table_name) if @connection.tables.include?(table_name)
16+
ActiveRecord::Migration.drop_table(table_name) if connection.tables.include?(table_name)
2117
end
2218
end
2319

24-
should 'not create a tables if error in migrations' do
20+
it 'not create a tables if error in migrations' do
2521
begin
2622
migrations_dir = File.join ARTest::SQLServer.migrations_root, 'transaction_table'
27-
ActiveRecord::Migrator.up(migrations_dir)
23+
quietly { ActiveRecord::Migrator.up(migrations_dir) }
2824
rescue Exception => e
2925
assert_match %r|this and all later migrations canceled|, e.message
3026
end
31-
@connection.tables.wont_include @trans_test_table1
32-
@connection.tables.wont_include @trans_test_table2
27+
connection.tables.wont_include @trans_test_table1
28+
connection.tables.wont_include @trans_test_table2
3329
end
3430

3531
end
3632

37-
context 'For changing column' do
33+
describe 'For changing column' do
3834

39-
should 'not raise exception when column contains default constraint' do
35+
it 'not raise exception when column contains default constraint' do
4036
lock_version_column = Person.columns_hash['lock_version']
4137
assert_equal :integer, lock_version_column.type
4238
assert lock_version_column.default.present?
43-
assert_nothing_raised { @connection.change_column 'people', 'lock_version', :string }
39+
assert_nothing_raised { connection.change_column 'people', 'lock_version', :string }
4440
Person.reset_column_information
4541
lock_version_column = Person.columns_hash['lock_version']
4642
assert_equal :string, lock_version_column.type
4743
assert lock_version_column.default.nil?
4844
end
4945

50-
should 'not drop the default contraint if just renaming' do
46+
it 'not drop the default contraint if just renaming' do
5147
find_default = lambda do
52-
@connection.execute_procedure(:sp_helpconstraint, 'defaults', 'nomsg').select do |row|
48+
connection.execute_procedure(:sp_helpconstraint, 'defaults', 'nomsg').select do |row|
5349
row['constraint_type'] == "DEFAULT on column decimal_number"
5450
end.last
5551
end
5652
default_before = find_default.call
57-
@connection.change_column :defaults, :decimal_number, :decimal, precision: 4
53+
connection.change_column :defaults, :decimal_number, :decimal, precision: 4
5854
default_after = find_default.call
5955
assert default_after
6056
assert_equal default_before['constraint_keys'], default_after['constraint_keys']
6157
end
6258

6359
end
6460

65-
end
66-
67-
if ActiveRecord::TestCase.sqlserver_azure?
68-
class MigrationTest < ActiveRecord::TestCase
69-
COERCED_TESTS = [:test_migrator_db_has_no_schema_migrations_table]
70-
include ARTest::SQLServer::CoercedTest
71-
72-
# TODO: put a real test here
73-
def test_coerced_test_migrator_db_has_no_schema_migrations_table
74-
assert true
75-
end
7661

62+
def quietly
63+
silence_stream(STDOUT) { silence_stream(STDERR) { yield } }
7764
end
65+
7866
end

0 commit comments

Comments
 (0)