|
4 | 4 |
|
5 | 5 | module Drafting |
6 | 6 | describe MigrationGenerator, type: :generator do |
7 | | - root_dir = File.expand_path("../../../../../../tmp", __FILE__) |
| 7 | + root_dir = File.expand_path('../../../../../../tmp', __FILE__) |
8 | 8 | destination root_dir |
9 | 9 |
|
10 | | - [ |
11 | | - { |
12 | | - configuration: 'timestamped migrations', |
13 | | - timestamped_migrations: true |
14 | | - }, |
15 | | - { |
16 | | - configuration: 'numeric prefix migrations', |
17 | | - timestamped_migrations: false |
18 | | - } |
19 | | - ].each do |test_suite| |
20 | | - describe test_suite[:configuration] do |
| 10 | + describe 'timestamped migrations' do |
| 11 | + describe 'new app' do |
21 | 12 | before :each do |
22 | | - ActiveRecord::Base.timestamped_migrations = test_suite[:timestamped_migrations] |
| 13 | + prepare_destination |
| 14 | + run_generator |
23 | 15 | end |
24 | 16 |
|
25 | | - describe 'new app' do |
26 | | - before :each do |
27 | | - prepare_destination |
28 | | - run_generator |
29 | | - end |
| 17 | + it 'creates two installation db migration' do |
| 18 | + migration_files = |
| 19 | + Dir.glob("#{root_dir}/db/migrate/*drafting*.rb").sort |
30 | 20 |
|
31 | | - it "creates two installation db migration" do |
32 | | - migration_files = |
33 | | - Dir.glob("#{root_dir}/db/migrate/*drafting*.rb").sort |
| 21 | + assert_equal migration_files.count, 2 |
34 | 22 |
|
35 | | - assert_equal migration_files.count, 2 |
36 | | - |
37 | | - assert_file migration_files[0], |
38 | | - /class DraftingMigration < Drafting::MIGRATION_BASE_CLASS/ |
39 | | - assert_file migration_files[1], |
40 | | - /class NonUserDraftingMigration < Drafting::MIGRATION_BASE_CLASS/ |
41 | | - end |
| 23 | + assert_file migration_files[0], |
| 24 | + /class DraftingMigration < Drafting::MIGRATION_BASE_CLASS/ |
| 25 | + assert_file migration_files[1], |
| 26 | + /class NonUserDraftingMigration < Drafting::MIGRATION_BASE_CLASS/ |
| 27 | + end |
42 | 28 |
|
43 | | - it "creates migration files of different timestamp" do |
44 | | - migration_files = |
45 | | - Dir.glob("#{root_dir}/db/migrate/*drafting*.rb").sort |
| 29 | + it 'creates migration files of different timestamp' do |
| 30 | + migration_files = |
| 31 | + Dir.glob("#{root_dir}/db/migrate/*drafting*.rb").sort |
46 | 32 |
|
47 | | - migration_no1 = File.basename(migration_files[0]).split("_").first |
48 | | - migration_no2 = File.basename(migration_files[1]).split("_").first |
| 33 | + migration_no1 = File.basename(migration_files[0]).split('_').first |
| 34 | + migration_no2 = File.basename(migration_files[1]).split('_').first |
49 | 35 |
|
50 | | - assert_not_equal migration_no1, migration_no2 |
51 | | - end |
| 36 | + assert_not_equal migration_no1, migration_no2 |
52 | 37 | end |
| 38 | + end |
53 | 39 |
|
54 | | - describe 'existing app' do |
55 | | - before :each do |
56 | | - prepare_destination |
57 | | - run_generator |
58 | | - FileUtils.rm Dir.glob("#{root_dir}/db/migrate/*non_user_drafting_migration.rb") |
| 40 | + describe 'existing app' do |
| 41 | + before :each do |
| 42 | + prepare_destination |
| 43 | + run_generator |
| 44 | + FileUtils.rm Dir.glob( |
| 45 | + "#{root_dir}/db/migrate/*non_user_drafting_migration.rb", |
| 46 | + ) |
59 | 47 |
|
60 | | - migration_files = |
61 | | - Dir.glob("#{root_dir}/db/migrate/*drafting*.rb").sort |
62 | | - expect(migration_files.count).to eq 1 |
63 | | - assert_file migration_files[0], |
64 | | - /class DraftingMigration < Drafting::MIGRATION_BASE_CLASS/ |
| 48 | + migration_files = |
| 49 | + Dir.glob("#{root_dir}/db/migrate/*drafting*.rb").sort |
| 50 | + expect(migration_files.count).to eq 1 |
| 51 | + assert_file migration_files[0], |
| 52 | + /class DraftingMigration < Drafting::MIGRATION_BASE_CLASS/ |
65 | 53 |
|
66 | | - run_generator |
67 | | - end |
| 54 | + run_generator |
| 55 | + end |
68 | 56 |
|
69 | | - it "creates only one more db migration" do |
70 | | - migration_files = |
71 | | - Dir.glob("#{root_dir}/db/migrate/*drafting*.rb").sort |
72 | | - expect(migration_files.count).to eq 2 |
| 57 | + it 'creates only one more db migration' do |
| 58 | + migration_files = |
| 59 | + Dir.glob("#{root_dir}/db/migrate/*drafting*.rb").sort |
| 60 | + expect(migration_files.count).to eq 2 |
73 | 61 |
|
74 | | - assert_file migration_files[0], |
75 | | - /class DraftingMigration < Drafting::MIGRATION_BASE_CLASS/ |
76 | | - assert_file migration_files[1], |
77 | | - /class NonUserDraftingMigration < Drafting::MIGRATION_BASE_CLASS/ |
78 | | - end |
| 62 | + assert_file migration_files[0], |
| 63 | + /class DraftingMigration < Drafting::MIGRATION_BASE_CLASS/ |
| 64 | + assert_file migration_files[1], |
| 65 | + /class NonUserDraftingMigration < Drafting::MIGRATION_BASE_CLASS/ |
79 | 66 | end |
80 | 67 | end |
81 | 68 | end |
|
0 commit comments