@@ -7,47 +7,76 @@ module Drafting
7
7
root_dir = File . expand_path ( "../../../../../../tmp" , __FILE__ )
8
8
destination root_dir
9
9
10
- describe 'new app' do
11
- before :each do
12
- prepare_destination
13
- run_generator
14
- end
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
21
+ before :each do
22
+ ActiveRecord ::Base . timestamped_migrations = test_suite [ :timestamped_migrations ]
23
+ end
15
24
16
- it "creates two installation db migration" do
17
- migration_files =
18
- Dir . glob ( "#{ root_dir } /db/migrate/*drafting*.rb" ) . sort
25
+ describe 'new app' do
26
+ before :each do
27
+ prepare_destination
28
+ run_generator
29
+ end
19
30
20
- assert_file migration_files [ 0 ] ,
21
- /class DraftingMigration < Drafting::MIGRATION_BASE_CLASS/
22
- assert_file migration_files [ 1 ] ,
23
- /class NonUserDraftingMigration < Drafting::MIGRATION_BASE_CLASS/
24
- end
25
- end
31
+ it "creates two installation db migration" do
32
+ migration_files =
33
+ Dir . glob ( "#{ root_dir } /db/migrate/*drafting*.rb" ) . sort
26
34
27
- describe 'existing app' do
28
- before :each do
29
- prepare_destination
30
- run_generator
31
- FileUtils . rm Dir . glob ( "#{ root_dir } /db/migrate/*non_user_drafting_migration.rb" )
35
+ assert_equal migration_files . count , 2
32
36
33
- migration_files =
34
- Dir . glob ( " #{ root_dir } /db/migrate/*drafting*.rb" ) . sort
35
- expect ( migration_files . count ) . to eq 1
36
- assert_file migration_files [ 0 ] ,
37
- /class DraftingMigration < Drafting::MIGRATION_BASE_CLASS/
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
38
42
39
- run_generator
40
- end
43
+ it "creates migration files of different timestamp" do
44
+ migration_files =
45
+ Dir . glob ( "#{ root_dir } /db/migrate/*drafting*.rb" ) . sort
46
+
47
+ migration_no1 = File . basename ( migration_files [ 0 ] ) . split ( "_" ) . first
48
+ migration_no2 = File . basename ( migration_files [ 1 ] ) . split ( "_" ) . first
49
+
50
+ assert_not_equal migration_no1 , migration_no2
51
+ end
52
+ end
53
+
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" )
59
+
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/
65
+
66
+ run_generator
67
+ end
41
68
42
- it "creates only one more db migration" do
43
- migration_files =
44
- Dir . glob ( "#{ root_dir } /db/migrate/*drafting*.rb" ) . sort
45
- expect ( migration_files . count ) . to eq 2
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
46
73
47
- assert_file migration_files [ 0 ] ,
48
- /class DraftingMigration < Drafting::MIGRATION_BASE_CLASS/
49
- assert_file migration_files [ 1 ] ,
50
- /class NonUserDraftingMigration < Drafting::MIGRATION_BASE_CLASS/
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
79
+ end
51
80
end
52
81
end
53
82
end
0 commit comments