|
3 | 3 |
|
4 | 4 | class MigrationTestSQLServer < ActiveRecord::TestCase |
5 | 5 |
|
6 | | - setup do |
7 | | - @connection = ActiveRecord::Base.connection |
8 | | - end |
9 | | - |
10 | | - context 'For transactions' do |
| 6 | + describe 'For transactions' do |
11 | 7 |
|
12 | | - setup do |
| 8 | + before do |
13 | 9 | @trans_test_table1 = 'sqlserver_trans_table1' |
14 | 10 | @trans_test_table2 = 'sqlserver_trans_table2' |
15 | 11 | @trans_tables = [@trans_test_table1,@trans_test_table2] |
16 | 12 | end |
17 | 13 |
|
18 | | - teardown do |
| 14 | + after do |
19 | 15 | @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) |
21 | 17 | end |
22 | 18 | end |
23 | 19 |
|
24 | | - should 'not create a tables if error in migrations' do |
| 20 | + it 'not create a tables if error in migrations' do |
25 | 21 | begin |
26 | 22 | migrations_dir = File.join ARTest::SQLServer.migrations_root, 'transaction_table' |
27 | | - ActiveRecord::Migrator.up(migrations_dir) |
| 23 | + quietly { ActiveRecord::Migrator.up(migrations_dir) } |
28 | 24 | rescue Exception => e |
29 | 25 | assert_match %r|this and all later migrations canceled|, e.message |
30 | 26 | 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 |
33 | 29 | end |
34 | 30 |
|
35 | 31 | end |
36 | 32 |
|
37 | | - context 'For changing column' do |
| 33 | + describe 'For changing column' do |
38 | 34 |
|
39 | | - should 'not raise exception when column contains default constraint' do |
| 35 | + it 'not raise exception when column contains default constraint' do |
40 | 36 | lock_version_column = Person.columns_hash['lock_version'] |
41 | 37 | assert_equal :integer, lock_version_column.type |
42 | 38 | 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 } |
44 | 40 | Person.reset_column_information |
45 | 41 | lock_version_column = Person.columns_hash['lock_version'] |
46 | 42 | assert_equal :string, lock_version_column.type |
47 | 43 | assert lock_version_column.default.nil? |
48 | 44 | end |
49 | 45 |
|
50 | | - should 'not drop the default contraint if just renaming' do |
| 46 | + it 'not drop the default contraint if just renaming' do |
51 | 47 | 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| |
53 | 49 | row['constraint_type'] == "DEFAULT on column decimal_number" |
54 | 50 | end.last |
55 | 51 | end |
56 | 52 | 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 |
58 | 54 | default_after = find_default.call |
59 | 55 | assert default_after |
60 | 56 | assert_equal default_before['constraint_keys'], default_after['constraint_keys'] |
61 | 57 | end |
62 | 58 |
|
63 | 59 | end |
64 | 60 |
|
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 |
76 | 61 |
|
| 62 | + def quietly |
| 63 | + silence_stream(STDOUT) { silence_stream(STDERR) { yield } } |
77 | 64 | end |
| 65 | + |
78 | 66 | end |
0 commit comments