padrino-gen 0.9.15 → 0.9.16
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/padrino-gen/generators/components/orms/activerecord.rb +18 -1
- data/lib/padrino-gen/generators/components/tests/riot.rb +4 -2
- data/lib/padrino-gen/generators/components/tests/rspec.rb +3 -3
- data/lib/padrino-gen/generators/runner.rb +1 -1
- data/lib/padrino-gen/padrino-tasks/activerecord.rb +6 -6
- data/test/fixtures/example_template.rb +1 -1
- data/test/helper.rb +8 -6
- data/test/test_app_generator.rb +53 -48
- data/test/test_cli.rb +9 -4
- data/test/test_controller_generator.rb +63 -59
- data/test/test_mailer_generator.rb +37 -32
- data/test/test_migration_generator.rb +69 -64
- data/test/test_model_generator.rb +177 -172
- data/test/test_plugin_generator.rb +42 -37
- data/test/test_project_generator.rb +258 -248
- metadata +7 -7
@@ -2,63 +2,68 @@ require File.expand_path(File.dirname(__FILE__) + '/helper')
|
|
2
2
|
|
3
3
|
class TestMailerGenerator < Test::Unit::TestCase
|
4
4
|
def setup
|
5
|
-
|
5
|
+
@apptmp = "#{Dir.tmpdir}/padrino-tests/#{UUID.new.generate}"
|
6
|
+
`mkdir -p #{@apptmp}`
|
7
|
+
end
|
8
|
+
|
9
|
+
def teardown
|
10
|
+
`rm -rf #{@apptmp}`
|
6
11
|
end
|
7
12
|
|
8
13
|
context 'the mailer generator' do
|
9
14
|
should "fail outside app root" do
|
10
|
-
output = silence_logger { generate(:mailer, 'demo',
|
15
|
+
output = silence_logger { generate(:mailer, 'demo', "-r=#{@apptmp}") }
|
11
16
|
assert_match(/not at the root/, output)
|
12
17
|
assert_no_file_exists('/tmp/app/mailers/demo_mailer.rb')
|
13
18
|
end
|
14
19
|
|
15
20
|
should "generate mailer in specified app" do
|
16
|
-
silence_logger { generate(:project, 'sample_project',
|
17
|
-
silence_logger { generate(:app, 'subby',
|
18
|
-
silence_logger { generate(:mailer, 'demo', '-a=/subby',
|
19
|
-
assert_match_in_file(/Subby.mailer :demo/m,
|
20
|
-
assert_dir_exists(
|
21
|
+
silence_logger { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=bacon') }
|
22
|
+
silence_logger { generate(:app, 'subby', "-r=#{@apptmp}/sample_project") }
|
23
|
+
silence_logger { generate(:mailer, 'demo', '-a=/subby', "-r=#{@apptmp}/sample_project") }
|
24
|
+
assert_match_in_file(/Subby.mailer :demo/m, "#{@apptmp}/sample_project/subby/mailers/demo.rb")
|
25
|
+
assert_dir_exists("#{@apptmp}/sample_project/subby/views/mailers/demo")
|
21
26
|
end
|
22
27
|
|
23
28
|
should "generate mailer in specified app with actions" do
|
24
|
-
silence_logger { generate(:project, 'sample_project',
|
25
|
-
silence_logger { generate(:app, 'subby',
|
26
|
-
silence_logger { generate(:mailer, 'demo', 'action1', 'action2', '-a=/subby',
|
27
|
-
assert_match_in_file(/Subby.mailer :demo/m,
|
28
|
-
assert_match_in_file(/email :action1 do.*?end/m,
|
29
|
-
assert_match_in_file(/email :action2 do.*?end/m,
|
30
|
-
assert_dir_exists(
|
29
|
+
silence_logger { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=bacon') }
|
30
|
+
silence_logger { generate(:app, 'subby', "-r=#{@apptmp}/sample_project") }
|
31
|
+
silence_logger { generate(:mailer, 'demo', 'action1', 'action2', '-a=/subby', "-r=#{@apptmp}/sample_project") }
|
32
|
+
assert_match_in_file(/Subby.mailer :demo/m, "#{@apptmp}/sample_project/subby/mailers/demo.rb")
|
33
|
+
assert_match_in_file(/email :action1 do.*?end/m, "#{@apptmp}/sample_project/subby/mailers/demo.rb")
|
34
|
+
assert_match_in_file(/email :action2 do.*?end/m, "#{@apptmp}/sample_project/subby/mailers/demo.rb")
|
35
|
+
assert_dir_exists("#{@apptmp}/sample_project/subby/views/mailers/demo")
|
31
36
|
end
|
32
37
|
|
33
38
|
should "support generating a new mailer extended from base" do
|
34
|
-
silence_logger { generate(:project, 'sample_project',
|
35
|
-
silence_logger { generate(:mailer, 'demo',
|
36
|
-
assert_match_in_file(/SampleProject.mailer :demo/m,
|
37
|
-
assert_dir_exists(
|
39
|
+
silence_logger { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=bacon') }
|
40
|
+
silence_logger { generate(:mailer, 'demo', "-r=#{@apptmp}/sample_project") }
|
41
|
+
assert_match_in_file(/SampleProject.mailer :demo/m, "#{@apptmp}/sample_project/app/mailers/demo.rb")
|
42
|
+
assert_dir_exists("#{@apptmp}/sample_project/app/views/mailers/demo")
|
38
43
|
end
|
39
44
|
|
40
45
|
should "support generating a new mailer extended from base with long name" do
|
41
|
-
silence_logger { generate(:project, 'sample_project',
|
42
|
-
silence_logger { generate(:mailer, 'UserNotice',
|
43
|
-
assert_match_in_file(/SampleProject.mailer :user_notice/m,
|
44
|
-
assert_dir_exists(
|
46
|
+
silence_logger { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=bacon') }
|
47
|
+
silence_logger { generate(:mailer, 'UserNotice', "-r=#{@apptmp}/sample_project") }
|
48
|
+
assert_match_in_file(/SampleProject.mailer :user_notice/m, "#{@apptmp}/sample_project/app/mailers/user_notice.rb")
|
49
|
+
assert_dir_exists("#{@apptmp}/sample_project/app/views/mailers/user_notice")
|
45
50
|
end
|
46
51
|
|
47
52
|
should "support generating a new mailer extended from base with capitalized name" do
|
48
|
-
silence_logger { generate(:project, 'sample_project',
|
49
|
-
silence_logger { generate(:mailer, 'DEMO',
|
50
|
-
assert_match_in_file(/SampleProject.mailer :demo/m,
|
51
|
-
assert_dir_exists(
|
53
|
+
silence_logger { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=bacon') }
|
54
|
+
silence_logger { generate(:mailer, 'DEMO', "-r=#{@apptmp}/sample_project") }
|
55
|
+
assert_match_in_file(/SampleProject.mailer :demo/m, "#{@apptmp}/sample_project/app/mailers/demo.rb")
|
56
|
+
assert_dir_exists("#{@apptmp}/sample_project/app/views/mailers/demo")
|
52
57
|
end
|
53
58
|
end
|
54
59
|
|
55
60
|
context "the mailer destroy option" do
|
56
61
|
should "destroy mailer file" do
|
57
|
-
silence_logger { generate(:project, 'sample_project',
|
58
|
-
silence_logger { generate(:mailer, 'demo',
|
59
|
-
silence_logger { generate(:mailer, 'demo',
|
60
|
-
assert_no_dir_exists(
|
61
|
-
assert_no_file_exists(
|
62
|
+
silence_logger { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=bacon') }
|
63
|
+
silence_logger { generate(:mailer, 'demo', "-r=#{@apptmp}/sample_project") }
|
64
|
+
silence_logger { generate(:mailer, 'demo', "-r=#{@apptmp}/sample_project",'-d') }
|
65
|
+
assert_no_dir_exists("#{@apptmp}/sample_project/app/views/demo")
|
66
|
+
assert_no_file_exists("#{@apptmp}/sample_project/app/mailers/demo.rb")
|
62
67
|
end
|
63
68
|
end
|
64
|
-
end
|
69
|
+
end
|
@@ -2,70 +2,75 @@ require File.expand_path(File.dirname(__FILE__) + '/helper')
|
|
2
2
|
|
3
3
|
class TestMigrationGenerator < Test::Unit::TestCase
|
4
4
|
def setup
|
5
|
-
|
5
|
+
@apptmp = "#{Dir.tmpdir}/padrino-tests/#{UUID.new.generate}"
|
6
|
+
`mkdir -p #{@apptmp}`
|
7
|
+
end
|
8
|
+
|
9
|
+
def teardown
|
10
|
+
`rm -rf #{@apptmp}`
|
6
11
|
end
|
7
12
|
|
8
13
|
context 'the migration generator' do
|
9
14
|
should "fail outside app root" do
|
10
15
|
output = silence_logger { generate(:migration, 'add_email_to_users', '-r=/tmp') }
|
11
16
|
assert_match(/not at the root/, output)
|
12
|
-
assert_no_file_exists(
|
17
|
+
assert_no_file_exists("#{@apptmp}/db/migration")
|
13
18
|
end
|
14
19
|
|
15
20
|
should "fail if we don't use an adapter" do
|
16
|
-
silence_logger { generate(:project, 'sample_project',
|
17
|
-
assert_raise(SystemExit) { silence_logger { generate(:migration, 'AddEmailToUsers',
|
21
|
+
silence_logger { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=bacon') }
|
22
|
+
assert_raise(SystemExit) { silence_logger { generate(:migration, 'AddEmailToUsers', "-r=#{@apptmp}/sample_project") } }
|
18
23
|
end
|
19
24
|
|
20
25
|
should "generate migration inside app root" do
|
21
|
-
silence_logger { generate(:project, 'sample_project',
|
22
|
-
response_success = silence_logger { generate(:migration, 'AddEmailToUsers',
|
23
|
-
migration_file_path = "/
|
26
|
+
silence_logger { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=bacon', '-d=activerecord') }
|
27
|
+
response_success = silence_logger { generate(:migration, 'AddEmailToUsers', "-r=#{@apptmp}/sample_project") }
|
28
|
+
migration_file_path = "#{@apptmp}/sample_project/db/migrate/001_add_email_to_users.rb"
|
24
29
|
assert_match_in_file(/class AddEmailToUser/m, migration_file_path)
|
25
30
|
end
|
26
31
|
|
27
32
|
should "generate migration inside app root with lowercase migration argument" do
|
28
|
-
silence_logger { generate(:project, 'sample_project',
|
29
|
-
response_success = silence_logger { generate(:migration, 'add_email_to_users',
|
30
|
-
migration_file_path = "/
|
33
|
+
silence_logger { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=bacon', '-d=activerecord') }
|
34
|
+
response_success = silence_logger { generate(:migration, 'add_email_to_users', "-r=#{@apptmp}/sample_project") }
|
35
|
+
migration_file_path = "#{@apptmp}/sample_project/db/migrate/001_add_email_to_users.rb"
|
31
36
|
assert_match_in_file(/class AddEmailToUsers/m, migration_file_path)
|
32
37
|
end
|
33
38
|
|
34
39
|
should "generate migration inside app root with singular table" do
|
35
|
-
silence_logger { generate(:project, 'sample_project',
|
36
|
-
silence_logger { generate(:migration, 'add_email_to_user', "email:string",
|
37
|
-
migration_file_path = "/
|
40
|
+
silence_logger { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=bacon', '-d=activerecord') }
|
41
|
+
silence_logger { generate(:migration, 'add_email_to_user', "email:string", "-r=#{@apptmp}/sample_project") }
|
42
|
+
migration_file_path = "#{@apptmp}/sample_project/db/migrate/001_add_email_to_user.rb"
|
38
43
|
assert_match_in_file(/class AddEmailToUser/m, migration_file_path)
|
39
44
|
assert_match_in_file(/t.string :email/, migration_file_path)
|
40
45
|
assert_match_in_file(/t.remove :email/, migration_file_path)
|
41
46
|
end
|
42
47
|
|
43
48
|
should "properly calculate version number" do
|
44
|
-
silence_logger { generate(:project, 'sample_project',
|
45
|
-
silence_logger { generate(:migration, 'add_email_to_person', "email:string",
|
46
|
-
silence_logger { generate(:migration, 'add_name_to_person', "email:string",
|
47
|
-
silence_logger { generate(:migration, 'add_age_to_user', "email:string",
|
48
|
-
assert_match_in_file(/class AddEmailToPerson/m, "/
|
49
|
-
assert_match_in_file(/class AddNameToPerson/m, "/
|
50
|
-
assert_match_in_file(/class AddAgeToUser/m, "/
|
49
|
+
silence_logger { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=bacon', '-d=sequel') }
|
50
|
+
silence_logger { generate(:migration, 'add_email_to_person', "email:string", "-r=#{@apptmp}/sample_project") }
|
51
|
+
silence_logger { generate(:migration, 'add_name_to_person', "email:string", "-r=#{@apptmp}/sample_project") }
|
52
|
+
silence_logger { generate(:migration, 'add_age_to_user', "email:string", "-r=#{@apptmp}/sample_project") }
|
53
|
+
assert_match_in_file(/class AddEmailToPerson/m, "#{@apptmp}/sample_project/db/migrate/001_add_email_to_person.rb")
|
54
|
+
assert_match_in_file(/class AddNameToPerson/m, "#{@apptmp}/sample_project/db/migrate/002_add_name_to_person.rb")
|
55
|
+
assert_match_in_file(/class AddAgeToUser/m, "#{@apptmp}/sample_project/db/migrate/003_add_age_to_user.rb")
|
51
56
|
end
|
52
57
|
end
|
53
58
|
|
54
59
|
context 'the migration generator for activerecord' do
|
55
60
|
should "generate migration for generic needs" do
|
56
|
-
silence_logger { generate(:project, 'sample_project',
|
57
|
-
response_success = silence_logger { generate(:migration, 'ModifyUserFields',
|
58
|
-
migration_file_path = "/
|
61
|
+
silence_logger { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=bacon', '-d=activerecord') }
|
62
|
+
response_success = silence_logger { generate(:migration, 'ModifyUserFields', "-r=#{@apptmp}/sample_project") }
|
63
|
+
migration_file_path = "#{@apptmp}/sample_project/db/migrate/001_modify_user_fields.rb"
|
59
64
|
assert_match_in_file(/class ModifyUserFields/m, migration_file_path)
|
60
65
|
assert_match_in_file(/def self\.up\s+end/m, migration_file_path)
|
61
66
|
assert_match_in_file(/def self\.down\s+end/m, migration_file_path)
|
62
67
|
end
|
63
68
|
|
64
69
|
should "generate migration for adding columns" do
|
65
|
-
silence_logger { generate(:project, 'sample_project',
|
66
|
-
migration_params = ['AddEmailToUsers', "email:string", "age:integer",
|
70
|
+
silence_logger { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=bacon', '-d=activerecord') }
|
71
|
+
migration_params = ['AddEmailToUsers', "email:string", "age:integer", "-r=#{@apptmp}/sample_project"]
|
67
72
|
response_success = silence_logger { generate(:migration, *migration_params) }
|
68
|
-
migration_file_path = "/
|
73
|
+
migration_file_path = "#{@apptmp}/sample_project/db/migrate/001_add_email_to_users.rb"
|
69
74
|
assert_match_in_file(/class AddEmailToUsers/m, migration_file_path)
|
70
75
|
assert_match_in_file(/change_table :users.*?t\.string :email/m, migration_file_path)
|
71
76
|
assert_match_in_file(/t\.integer :age/m, migration_file_path)
|
@@ -74,10 +79,10 @@ class TestMigrationGenerator < Test::Unit::TestCase
|
|
74
79
|
end
|
75
80
|
|
76
81
|
should "generate migration for removing columns" do
|
77
|
-
silence_logger { generate(:project, 'sample_project',
|
78
|
-
migration_params = ['RemoveEmailFromUsers', "email:string", "age:integer",
|
82
|
+
silence_logger { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=bacon', '-d=activerecord') }
|
83
|
+
migration_params = ['RemoveEmailFromUsers', "email:string", "age:integer", "-r=#{@apptmp}/sample_project"]
|
79
84
|
response_success = silence_logger { generate(:migration, *migration_params) }
|
80
|
-
migration_file_path = "/
|
85
|
+
migration_file_path = "#{@apptmp}/sample_project/db/migrate/001_remove_email_from_users.rb"
|
81
86
|
assert_match_in_file(/class RemoveEmailFromUsers/m, migration_file_path)
|
82
87
|
assert_match_in_file(/change_table :users.*?t\.remove :email/m, migration_file_path)
|
83
88
|
assert_match_in_file(/t\.remove :age/m, migration_file_path)
|
@@ -88,19 +93,19 @@ class TestMigrationGenerator < Test::Unit::TestCase
|
|
88
93
|
|
89
94
|
context 'the migration generator for datamapper' do
|
90
95
|
should "generate migration for generic needs" do
|
91
|
-
silence_logger { generate(:project, 'sample_project',
|
92
|
-
response_success = silence_logger { generate(:migration, 'ModifyUserFields',
|
93
|
-
migration_file_path = "/
|
96
|
+
silence_logger { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=bacon', '-d=datamapper') }
|
97
|
+
response_success = silence_logger { generate(:migration, 'ModifyUserFields', "-r=#{@apptmp}/sample_project") }
|
98
|
+
migration_file_path = "#{@apptmp}/sample_project/db/migrate/001_modify_user_fields.rb"
|
94
99
|
assert_match_in_file(/migration\s1.*?:modify_user_fields/m, migration_file_path)
|
95
100
|
assert_match_in_file(/up\sdo\s+end/m, migration_file_path)
|
96
101
|
assert_match_in_file(/down\sdo\s+end/m, migration_file_path)
|
97
102
|
end
|
98
103
|
|
99
104
|
should "generate migration for adding columns" do
|
100
|
-
silence_logger { generate(:project, 'sample_project',
|
101
|
-
migration_params = ['AddEmailToUsers', "email:string", "age:integer",
|
105
|
+
silence_logger { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=bacon', '-d=datamapper') }
|
106
|
+
migration_params = ['AddEmailToUsers', "email:string", "age:integer", "-r=#{@apptmp}/sample_project"]
|
102
107
|
response_success = silence_logger { generate(:migration, *migration_params) }
|
103
|
-
migration_file_path = "/
|
108
|
+
migration_file_path = "#{@apptmp}/sample_project/db/migrate/001_add_email_to_users.rb"
|
104
109
|
assert_match_in_file(/migration\s1.*?:add_email_to_users/m, migration_file_path)
|
105
110
|
assert_match_in_file(/modify_table :users.*?add_column :email, DataMapper::Property::String/m, migration_file_path)
|
106
111
|
assert_match_in_file(/add_column :age, DataMapper::Property::Integer/m, migration_file_path)
|
@@ -109,10 +114,10 @@ class TestMigrationGenerator < Test::Unit::TestCase
|
|
109
114
|
end
|
110
115
|
|
111
116
|
should "generate migration for removing columns" do
|
112
|
-
silence_logger { generate(:project, 'sample_project',
|
113
|
-
migration_params = ['RemoveEmailFromUsers', "email:string", "age:integer",
|
117
|
+
silence_logger { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=bacon', '-d=datamapper') }
|
118
|
+
migration_params = ['RemoveEmailFromUsers', "email:string", "age:integer", "-r=#{@apptmp}/sample_project"]
|
114
119
|
response_success = silence_logger { generate(:migration, *migration_params) }
|
115
|
-
migration_file_path = "/
|
120
|
+
migration_file_path = "#{@apptmp}/sample_project/db/migrate/001_remove_email_from_users.rb"
|
116
121
|
assert_match_in_file(/migration\s1.*?:remove_email_from_users/m, migration_file_path)
|
117
122
|
assert_match_in_file(/modify_table :users.*?drop_column :email/m, migration_file_path)
|
118
123
|
assert_match_in_file(/drop_column :age/m, migration_file_path)
|
@@ -121,31 +126,31 @@ class TestMigrationGenerator < Test::Unit::TestCase
|
|
121
126
|
end
|
122
127
|
|
123
128
|
should "properly version migration files" do
|
124
|
-
silence_logger { generate(:project, 'sample_project',
|
125
|
-
response_success = silence_logger { generate(:migration, 'ModifyUserFields',
|
126
|
-
response_success = silence_logger { generate(:migration, 'ModifyUserFields2',
|
127
|
-
response_success = silence_logger { generate(:migration, 'ModifyUserFields3',
|
128
|
-
assert_match_in_file(/migration\s1.*?:modify_user_fields/m, "/
|
129
|
-
assert_match_in_file(/migration\s2.*?:modify_user_fields2/m, "/
|
130
|
-
assert_match_in_file(/migration\s3.*?:modify_user_fields3/m, "/
|
129
|
+
silence_logger { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=bacon', '-d=datamapper') }
|
130
|
+
response_success = silence_logger { generate(:migration, 'ModifyUserFields', "-r=#{@apptmp}/sample_project") }
|
131
|
+
response_success = silence_logger { generate(:migration, 'ModifyUserFields2', "-r=#{@apptmp}/sample_project") }
|
132
|
+
response_success = silence_logger { generate(:migration, 'ModifyUserFields3', "-r=#{@apptmp}/sample_project") }
|
133
|
+
assert_match_in_file(/migration\s1.*?:modify_user_fields/m, "#{@apptmp}/sample_project/db/migrate/001_modify_user_fields.rb")
|
134
|
+
assert_match_in_file(/migration\s2.*?:modify_user_fields2/m, "#{@apptmp}/sample_project/db/migrate/002_modify_user_fields2.rb")
|
135
|
+
assert_match_in_file(/migration\s3.*?:modify_user_fields3/m, "#{@apptmp}/sample_project/db/migrate/003_modify_user_fields3.rb")
|
131
136
|
end
|
132
137
|
end
|
133
138
|
|
134
139
|
context 'the migration generator for sequel' do
|
135
140
|
should "generate migration for generic needs" do
|
136
|
-
silence_logger { generate(:project, 'sample_project',
|
137
|
-
response_success = silence_logger { generate(:migration, 'ModifyUserFields',
|
138
|
-
migration_file_path = "/
|
141
|
+
silence_logger { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=bacon', '-d=sequel') }
|
142
|
+
response_success = silence_logger { generate(:migration, 'ModifyUserFields', "-r=#{@apptmp}/sample_project") }
|
143
|
+
migration_file_path = "#{@apptmp}/sample_project/db/migrate/001_modify_user_fields.rb"
|
139
144
|
assert_match_in_file(/class ModifyUserFields/m, migration_file_path)
|
140
145
|
assert_match_in_file(/def\sup\s+end/m, migration_file_path)
|
141
146
|
assert_match_in_file(/def\sdown\s+end/m, migration_file_path)
|
142
147
|
end
|
143
148
|
|
144
149
|
should "generate migration for adding columns" do
|
145
|
-
silence_logger { generate(:project, 'sample_project',
|
146
|
-
migration_params = ['AddEmailToUsers', "email:string", "age:integer",
|
150
|
+
silence_logger { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=bacon', '-d=sequel') }
|
151
|
+
migration_params = ['AddEmailToUsers', "email:string", "age:integer", "-r=#{@apptmp}/sample_project"]
|
147
152
|
response_success = silence_logger { generate(:migration, *migration_params) }
|
148
|
-
migration_file_path = "/
|
153
|
+
migration_file_path = "#{@apptmp}/sample_project/db/migrate/001_add_email_to_users.rb"
|
149
154
|
assert_match_in_file(/class AddEmailToUsers/m, migration_file_path)
|
150
155
|
assert_match_in_file(/alter_table :users.*?add_column :email, String/m, migration_file_path)
|
151
156
|
assert_match_in_file(/add_column :age, Integer/m, migration_file_path)
|
@@ -154,10 +159,10 @@ class TestMigrationGenerator < Test::Unit::TestCase
|
|
154
159
|
end
|
155
160
|
|
156
161
|
should "generate migration for removing columns" do
|
157
|
-
silence_logger { generate(:project, 'sample_project',
|
158
|
-
migration_params = ['RemoveEmailFromUsers', "email:string", "age:integer",
|
162
|
+
silence_logger { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=bacon', '-d=sequel') }
|
163
|
+
migration_params = ['RemoveEmailFromUsers', "email:string", "age:integer", "-r=#{@apptmp}/sample_project"]
|
159
164
|
response_success = silence_logger { generate(:migration, *migration_params) }
|
160
|
-
migration_file_path = "/
|
165
|
+
migration_file_path = "#{@apptmp}/sample_project/db/migrate/001_remove_email_from_users.rb"
|
161
166
|
assert_match_in_file(/class RemoveEmailFromUsers/m, migration_file_path)
|
162
167
|
assert_match_in_file(/alter_table :users.*?drop_column :email/m, migration_file_path)
|
163
168
|
assert_match_in_file(/drop_column :age/m, migration_file_path)
|
@@ -169,21 +174,21 @@ class TestMigrationGenerator < Test::Unit::TestCase
|
|
169
174
|
context "the migration destroy option" do
|
170
175
|
|
171
176
|
should "destroy the migration files" do
|
172
|
-
silence_logger { generate(:project, 'sample_project',
|
173
|
-
migration_params = ['RemoveEmailFromUsers', "email:string", "age:integer",
|
177
|
+
silence_logger { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=bacon', '-d=sequel') }
|
178
|
+
migration_params = ['RemoveEmailFromUsers', "email:string", "age:integer", "-r=#{@apptmp}/sample_project"]
|
174
179
|
silence_logger { generate(:migration, *migration_params) }
|
175
|
-
silence_logger { generate(:migration, 'RemoveEmailFromUsers',
|
176
|
-
assert_no_file_exists("/
|
180
|
+
silence_logger { generate(:migration, 'RemoveEmailFromUsers', "-r=#{@apptmp}/sample_project",'-d') }
|
181
|
+
assert_no_file_exists("#{@apptmp}/sample_project/db/migrate/001_remove_email_from_users.rb")
|
177
182
|
end
|
178
183
|
|
179
184
|
should "destroy the migration file regardless of number" do
|
180
|
-
silence_logger { generate(:project, 'sample_project',
|
181
|
-
migration_params = ['RemoveEmailFromUsers', "email:string", "age:integer",
|
182
|
-
migration_param2 = ['AddEmailFromUsers', "email:string", "age:integer",
|
185
|
+
silence_logger { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=bacon', '-d=sequel') }
|
186
|
+
migration_params = ['RemoveEmailFromUsers', "email:string", "age:integer", "-r=#{@apptmp}/sample_project"]
|
187
|
+
migration_param2 = ['AddEmailFromUsers', "email:string", "age:integer", "-r=#{@apptmp}/sample_project"]
|
183
188
|
silence_logger { generate(:migration, *migration_param2) }
|
184
189
|
silence_logger { generate(:migration, *migration_params) }
|
185
|
-
silence_logger { generate(:migration, 'RemoveEmailFromUsers',
|
186
|
-
assert_no_file_exists("/
|
190
|
+
silence_logger { generate(:migration, 'RemoveEmailFromUsers', "-r=#{@apptmp}/sample_project",'-d') }
|
191
|
+
assert_no_file_exists("#{@apptmp}/sample_project/db/migrate/002_remove_email_from_users.rb")
|
187
192
|
end
|
188
193
|
end
|
189
|
-
end
|
194
|
+
end
|
@@ -2,90 +2,95 @@ require File.expand_path(File.dirname(__FILE__) + '/helper')
|
|
2
2
|
|
3
3
|
class TestModelGenerator < Test::Unit::TestCase
|
4
4
|
def setup
|
5
|
-
|
5
|
+
@apptmp = "#{Dir.tmpdir}/padrino-tests/#{UUID.new.generate}"
|
6
|
+
`mkdir -p #{@apptmp}`
|
7
|
+
end
|
8
|
+
|
9
|
+
def teardown
|
10
|
+
`rm -rf #{@apptmp}`
|
6
11
|
end
|
7
12
|
|
8
13
|
context 'the model generator' do
|
9
14
|
should "fail outside app root" do
|
10
|
-
output = silence_logger { generate(:model, 'user',
|
15
|
+
output = silence_logger { generate(:model, 'user', "-r=#{@apptmp}") }
|
11
16
|
assert_match(/not at the root/, output)
|
12
17
|
assert_no_file_exists('/tmp/app/models/user.rb')
|
13
18
|
end
|
14
19
|
|
15
20
|
should "generate filename properly" do
|
16
|
-
silence_logger { generate(:project, 'sample_project',
|
17
|
-
silence_logger { generate(:model, 'DemoItem', "name:string", "age", "email:string",
|
18
|
-
assert_file_exists(
|
21
|
+
silence_logger { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=bacon', '-d=couchrest') }
|
22
|
+
silence_logger { generate(:model, 'DemoItem', "name:string", "age", "email:string", "-r=#{@apptmp}/sample_project") }
|
23
|
+
assert_file_exists("#{@apptmp}/sample_project/app/models/demo_item.rb")
|
19
24
|
end
|
20
25
|
|
21
26
|
should "fail if field name is not acceptable" do
|
22
|
-
silence_logger { generate(:project, 'sample_project',
|
23
|
-
output = silence_logger { generate(:model, 'DemoItem', "re@l$ly:string","display-name:string", "age&year:datetime", "email_two:string",
|
27
|
+
silence_logger { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=bacon', '-d=couchrest') }
|
28
|
+
output = silence_logger { generate(:model, 'DemoItem', "re@l$ly:string","display-name:string", "age&year:datetime", "email_two:string", "-r=#{@apptmp}/sample_project") }
|
24
29
|
assert_match(/Invalid field name:/, output)
|
25
30
|
assert_match(/display-name:string/, output)
|
26
31
|
assert_match(/age&year:datetime/, output)
|
27
32
|
assert_match(/re@l\$ly:string/, output)
|
28
33
|
assert_no_match(/email_two:string/, output)
|
29
34
|
assert_no_match(/apply/, output)
|
30
|
-
assert_no_file_exists(
|
35
|
+
assert_no_file_exists("#{@apptmp}/sample_project/app/models/demo_item.rb")
|
31
36
|
end
|
32
37
|
|
33
38
|
should "fail if we don't use an adapter" do
|
34
|
-
silence_logger { generate(:project, 'sample_project',
|
35
|
-
assert_raise(SystemExit) { silence_logger { generate(:model, 'user',
|
39
|
+
silence_logger { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=bacon') }
|
40
|
+
assert_raise(SystemExit) { silence_logger { generate(:model, 'user', "-r=#{@apptmp}/sample_project") } }
|
36
41
|
end
|
37
42
|
|
38
43
|
should "not fail if we don't have test component" do
|
39
|
-
silence_logger { generate(:project, 'sample_project',
|
40
|
-
response_success = silence_logger { generate(:model, 'user',
|
41
|
-
assert_match_in_file(/class User < ActiveRecord::Base/m,
|
42
|
-
assert_no_file_exists(
|
44
|
+
silence_logger { generate(:project, 'sample_project', "--root=#{@apptmp}", '--test=none', '-d=activerecord') }
|
45
|
+
response_success = silence_logger { generate(:model, 'user', "-r=#{@apptmp}/sample_project") }
|
46
|
+
assert_match_in_file(/class User < ActiveRecord::Base/m, "#{@apptmp}/sample_project/app/models/user.rb")
|
47
|
+
assert_no_file_exists("#{@apptmp}/sample_project/test")
|
43
48
|
end
|
44
49
|
|
45
50
|
should "generate model in specified app" do
|
46
|
-
silence_logger { generate(:project, 'sample_project',
|
47
|
-
silence_logger { generate(:app, 'subby',
|
48
|
-
silence_logger { generate(:model, 'Post', "body:string", '-a=/subby',
|
49
|
-
assert_match_in_file(/class Post\n\s+include DataMapper::Resource/m,
|
50
|
-
assert_match_in_file(/property :body, String/m,
|
51
|
-
assert_match_in_file(/migration 1, :create_posts do/m, "/
|
52
|
-
assert_match_in_file(/gem 'data_mapper'/m,
|
53
|
-
assert_match_in_file(/DataMapper.finalize/m,
|
51
|
+
silence_logger { generate(:project, 'sample_project', "--root=#{@apptmp}", '-d=datamapper', '--script=none', '-t=bacon') }
|
52
|
+
silence_logger { generate(:app, 'subby', "-r=#{@apptmp}/sample_project") }
|
53
|
+
silence_logger { generate(:model, 'Post', "body:string", '-a=/subby', "-r=#{@apptmp}/sample_project") }
|
54
|
+
assert_match_in_file(/class Post\n\s+include DataMapper::Resource/m, "#{@apptmp}/sample_project/subby/models/post.rb")
|
55
|
+
assert_match_in_file(/property :body, String/m, "#{@apptmp}/sample_project/subby/models/post.rb")
|
56
|
+
assert_match_in_file(/migration 1, :create_posts do/m, "#{@apptmp}/sample_project/db/migrate/001_create_posts.rb")
|
57
|
+
assert_match_in_file(/gem 'data_mapper'/m,"#{@apptmp}/sample_project/Gemfile")
|
58
|
+
assert_match_in_file(/DataMapper.finalize/m,"#{@apptmp}/sample_project/config/boot.rb")
|
54
59
|
end
|
55
60
|
|
56
61
|
should "generate only generate model once" do
|
57
|
-
silence_logger { generate(:project, 'sample_project',
|
58
|
-
response_success = silence_logger { generate(:model, 'user',
|
59
|
-
response_duplicate = silence_logger { generate(:model, 'user',
|
60
|
-
assert_match_in_file(/class User < ActiveRecord::Base/m,
|
62
|
+
silence_logger { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=bacon', '-d=activerecord') }
|
63
|
+
response_success = silence_logger { generate(:model, 'user', "-r=#{@apptmp}/sample_project") }
|
64
|
+
response_duplicate = silence_logger { generate(:model, 'user', "-r=#{@apptmp}/sample_project") }
|
65
|
+
assert_match_in_file(/class User < ActiveRecord::Base/m, "#{@apptmp}/sample_project/app/models/user.rb")
|
61
66
|
assert_match "identical\e[0m app/models/user.rb", response_duplicate
|
62
67
|
assert_match "identical\e[0m test/models/user_test.rb", response_duplicate
|
63
68
|
end
|
64
69
|
|
65
70
|
should "generate migration file versions properly" do
|
66
|
-
silence_logger { generate(:project, 'sample_project',
|
67
|
-
silence_logger { generate(:model, 'user',
|
68
|
-
silence_logger { generate(:model, 'account',
|
69
|
-
silence_logger { generate(:model, 'bank',
|
70
|
-
assert_file_exists(
|
71
|
-
assert_file_exists(
|
72
|
-
assert_file_exists(
|
71
|
+
silence_logger { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=bacon', '-d=activerecord') }
|
72
|
+
silence_logger { generate(:model, 'user', "-r=#{@apptmp}/sample_project") }
|
73
|
+
silence_logger { generate(:model, 'account', "-r=#{@apptmp}/sample_project") }
|
74
|
+
silence_logger { generate(:model, 'bank', "-r=#{@apptmp}/sample_project") }
|
75
|
+
assert_file_exists("#{@apptmp}/sample_project/db/migrate/001_create_users.rb")
|
76
|
+
assert_file_exists("#{@apptmp}/sample_project/db/migrate/002_create_accounts.rb")
|
77
|
+
assert_file_exists("#{@apptmp}/sample_project/db/migrate/003_create_banks.rb")
|
73
78
|
end
|
74
79
|
end
|
75
80
|
|
76
81
|
# ACTIVERECORD
|
77
82
|
context "model generator using activerecord" do
|
78
83
|
should "generate model file" do
|
79
|
-
silence_logger { generate(:project, 'sample_project',
|
80
|
-
silence_logger { generate(:model, 'user',
|
81
|
-
assert_match_in_file(/class User < ActiveRecord::Base/m,
|
84
|
+
silence_logger { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=bacon', '-d=activerecord') }
|
85
|
+
silence_logger { generate(:model, 'user', "-r=#{@apptmp}/sample_project") }
|
86
|
+
assert_match_in_file(/class User < ActiveRecord::Base/m, "#{@apptmp}/sample_project/app/models/user.rb")
|
82
87
|
end
|
83
88
|
|
84
89
|
should "generate migration file with no fields" do
|
85
90
|
current_time = stop_time_for_test.strftime("%Y%m%d%H%M%S")
|
86
|
-
silence_logger { generate(:project, 'sample_project',
|
87
|
-
silence_logger { generate(:model, 'user',
|
88
|
-
migration_file_path = "/
|
91
|
+
silence_logger { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=bacon', '-d=activerecord') }
|
92
|
+
silence_logger { generate(:model, 'user', "-r=#{@apptmp}/sample_project") }
|
93
|
+
migration_file_path = "#{@apptmp}/sample_project/db/migrate/001_create_users.rb"
|
89
94
|
assert_match_in_file(/class CreateUsers < ActiveRecord::Migration/m, migration_file_path)
|
90
95
|
assert_match_in_file(/create_table :users/m, migration_file_path)
|
91
96
|
assert_match_in_file(/drop_table :users/m, migration_file_path)
|
@@ -93,9 +98,9 @@ class TestModelGenerator < Test::Unit::TestCase
|
|
93
98
|
|
94
99
|
should "generate migration file with given fields" do
|
95
100
|
current_time = stop_time_for_test.strftime("%Y%m%d%H%M%S")
|
96
|
-
silence_logger { generate(:project, 'sample_project',
|
97
|
-
silence_logger { generate(:model, 'person', "name:string", "age:integer", "email:string",
|
98
|
-
migration_file_path = "/
|
101
|
+
silence_logger { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=bacon', '-d=activerecord') }
|
102
|
+
silence_logger { generate(:model, 'person', "name:string", "age:integer", "email:string", "-r=#{@apptmp}/sample_project") }
|
103
|
+
migration_file_path = "#{@apptmp}/sample_project/db/migrate/001_create_people.rb"
|
99
104
|
assert_match_in_file(/class CreatePeople < ActiveRecord::Migration/m, migration_file_path)
|
100
105
|
assert_match_in_file(/create_table :people/m, migration_file_path)
|
101
106
|
assert_match_in_file(/t.string :name/m, migration_file_path)
|
@@ -108,21 +113,21 @@ class TestModelGenerator < Test::Unit::TestCase
|
|
108
113
|
# COUCHREST
|
109
114
|
context "model generator using couchrest" do
|
110
115
|
should "generate model file with no properties" do
|
111
|
-
silence_logger { generate(:project, 'sample_project',
|
112
|
-
silence_logger { generate(:model, 'user',
|
113
|
-
assert_match_in_file(/class User < CouchRest::ExtendedDocument/m,
|
114
|
-
assert_match_in_file(/use_database COUCHDB/m,
|
115
|
-
assert_match_in_file(/# property <name>[\s\n]+?end/m,
|
116
|
+
silence_logger { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=bacon', '-d=couchrest') }
|
117
|
+
silence_logger { generate(:model, 'user', "-r=#{@apptmp}/sample_project") }
|
118
|
+
assert_match_in_file(/class User < CouchRest::ExtendedDocument/m, "#{@apptmp}/sample_project/app/models/user.rb")
|
119
|
+
assert_match_in_file(/use_database COUCHDB/m, "#{@apptmp}/sample_project/app/models/user.rb")
|
120
|
+
assert_match_in_file(/# property <name>[\s\n]+?end/m, "#{@apptmp}/sample_project/app/models/user.rb")
|
116
121
|
end
|
117
122
|
|
118
123
|
should "generate model file with given fields" do
|
119
|
-
silence_logger { generate(:project, 'sample_project',
|
120
|
-
silence_logger { generate(:model, 'person', "name:string", "age", "email:string",
|
121
|
-
assert_match_in_file(/class Person < CouchRest::ExtendedDocument/m,
|
122
|
-
assert_match_in_file(/use_database COUCHDB/m,
|
123
|
-
assert_match_in_file(/property :name/m,
|
124
|
-
assert_match_in_file(/property :age/m,
|
125
|
-
assert_match_in_file(/property :email/m,
|
124
|
+
silence_logger { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=bacon', '-d=couchrest') }
|
125
|
+
silence_logger { generate(:model, 'person', "name:string", "age", "email:string", "-r=#{@apptmp}/sample_project") }
|
126
|
+
assert_match_in_file(/class Person < CouchRest::ExtendedDocument/m, "#{@apptmp}/sample_project/app/models/person.rb")
|
127
|
+
assert_match_in_file(/use_database COUCHDB/m, "#{@apptmp}/sample_project/app/models/person.rb")
|
128
|
+
assert_match_in_file(/property :name/m, "#{@apptmp}/sample_project/app/models/person.rb")
|
129
|
+
assert_match_in_file(/property :age/m, "#{@apptmp}/sample_project/app/models/person.rb")
|
130
|
+
assert_match_in_file(/property :email/m, "#{@apptmp}/sample_project/app/models/person.rb")
|
126
131
|
end
|
127
132
|
end
|
128
133
|
|
@@ -130,39 +135,39 @@ class TestModelGenerator < Test::Unit::TestCase
|
|
130
135
|
context "model generator using datamapper" do
|
131
136
|
|
132
137
|
should "generate gemfile gem" do
|
133
|
-
silence_logger { generate(:project, 'sample_project',
|
134
|
-
silence_logger { generate(:model, 'user', "name:string", "age:integer", "created_at:datetime",
|
135
|
-
assert_match_in_file(/gem 'data_mapper'/m,
|
138
|
+
silence_logger { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-d=datamapper') }
|
139
|
+
silence_logger { generate(:model, 'user', "name:string", "age:integer", "created_at:datetime", "-r=#{@apptmp}/sample_project") }
|
140
|
+
assert_match_in_file(/gem 'data_mapper'/m,"#{@apptmp}/sample_project/Gemfile")
|
136
141
|
end
|
137
142
|
|
138
143
|
should "generate model file with fields" do
|
139
|
-
silence_logger { generate(:project, 'sample_project',
|
140
|
-
silence_logger { generate(:model, 'user', "name:string", "age:integer", "created_at:datetime",
|
141
|
-
assert_match_in_file(/class User\n\s+include DataMapper::Resource/m,
|
142
|
-
assert_match_in_file(/property :name, String/m,
|
143
|
-
assert_match_in_file(/property :age, Integer/m,
|
144
|
-
assert_match_in_file(/property :created_at, DateTime/m,
|
144
|
+
silence_logger { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-d=datamapper') }
|
145
|
+
silence_logger { generate(:model, 'user', "name:string", "age:integer", "created_at:datetime", "-r=#{@apptmp}/sample_project") }
|
146
|
+
assert_match_in_file(/class User\n\s+include DataMapper::Resource/m, "#{@apptmp}/sample_project/app/models/user.rb")
|
147
|
+
assert_match_in_file(/property :name, String/m, "#{@apptmp}/sample_project/app/models/user.rb")
|
148
|
+
assert_match_in_file(/property :age, Integer/m, "#{@apptmp}/sample_project/app/models/user.rb")
|
149
|
+
assert_match_in_file(/property :created_at, DateTime/m, "#{@apptmp}/sample_project/app/models/user.rb")
|
145
150
|
end
|
146
151
|
|
147
152
|
should "properly generate version numbers" do
|
148
|
-
silence_logger { generate(:project, 'sample_project',
|
149
|
-
silence_logger { generate(:model, 'user', "name:string", "age:integer", "created_at:datetime",
|
150
|
-
silence_logger { generate(:model, 'person', "name:string", "age:integer", "created_at:datetime",
|
151
|
-
silence_logger { generate(:model, 'account', "name:string", "age:integer", "created_at:datetime",
|
152
|
-
assert_match_in_file(/class User\n\s+include DataMapper::Resource/m,
|
153
|
-
assert_match_in_file(/migration 1, :create_users do/m, "/
|
154
|
-
assert_match_in_file(/class Person\n\s+include DataMapper::Resource/m,
|
155
|
-
assert_match_in_file(/migration 2, :create_people do/m, "/
|
156
|
-
assert_match_in_file(/class Account\n\s+include DataMapper::Resource/m,
|
157
|
-
assert_match_in_file(/migration 3, :create_accounts do/m, "/
|
153
|
+
silence_logger { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-d=datamapper') }
|
154
|
+
silence_logger { generate(:model, 'user', "name:string", "age:integer", "created_at:datetime", "-r=#{@apptmp}/sample_project") }
|
155
|
+
silence_logger { generate(:model, 'person', "name:string", "age:integer", "created_at:datetime", "-r=#{@apptmp}/sample_project") }
|
156
|
+
silence_logger { generate(:model, 'account', "name:string", "age:integer", "created_at:datetime", "-r=#{@apptmp}/sample_project") }
|
157
|
+
assert_match_in_file(/class User\n\s+include DataMapper::Resource/m, "#{@apptmp}/sample_project/app/models/user.rb")
|
158
|
+
assert_match_in_file(/migration 1, :create_users do/m, "#{@apptmp}/sample_project/db/migrate/001_create_users.rb")
|
159
|
+
assert_match_in_file(/class Person\n\s+include DataMapper::Resource/m, "#{@apptmp}/sample_project/app/models/person.rb")
|
160
|
+
assert_match_in_file(/migration 2, :create_people do/m, "#{@apptmp}/sample_project/db/migrate/002_create_people.rb")
|
161
|
+
assert_match_in_file(/class Account\n\s+include DataMapper::Resource/m, "#{@apptmp}/sample_project/app/models/account.rb")
|
162
|
+
assert_match_in_file(/migration 3, :create_accounts do/m, "#{@apptmp}/sample_project/db/migrate/003_create_accounts.rb")
|
158
163
|
end
|
159
164
|
|
160
165
|
should "generate migration with given fields" do
|
161
166
|
current_time = stop_time_for_test.strftime("%Y%m%d%H%M%S")
|
162
|
-
silence_logger { generate(:project, 'sample_project',
|
163
|
-
silence_logger { generate(:model, 'person', "name:string", "created_at:date_time", "email:string",
|
164
|
-
assert_match_in_file(/class Person\n\s+include DataMapper::Resource/m,
|
165
|
-
migration_file_path = "/
|
167
|
+
silence_logger { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-d=datamapper') }
|
168
|
+
silence_logger { generate(:model, 'person', "name:string", "created_at:date_time", "email:string", "-r=#{@apptmp}/sample_project") }
|
169
|
+
assert_match_in_file(/class Person\n\s+include DataMapper::Resource/m, "#{@apptmp}/sample_project/app/models/person.rb")
|
170
|
+
migration_file_path = "#{@apptmp}/sample_project/db/migrate/001_create_people.rb"
|
166
171
|
assert_match_in_file(/migration 1, :create_people do/m, migration_file_path)
|
167
172
|
assert_match_in_file(/create_table :people do/m, migration_file_path)
|
168
173
|
assert_match_in_file(/column :name, DataMapper::Property::String/m, migration_file_path)
|
@@ -175,17 +180,17 @@ class TestModelGenerator < Test::Unit::TestCase
|
|
175
180
|
# SEQUEL
|
176
181
|
context "model generator using sequel" do
|
177
182
|
should "generate model file with given properties" do
|
178
|
-
silence_logger { generate(:project, 'sample_project',
|
179
|
-
silence_logger { generate(:model, 'user', "name:string", "age:integer", "created:datetime",
|
180
|
-
assert_match_in_file(/class User < Sequel::Model/m,
|
183
|
+
silence_logger { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-d=sequel') }
|
184
|
+
silence_logger { generate(:model, 'user', "name:string", "age:integer", "created:datetime", "-r=#{@apptmp}/sample_project") }
|
185
|
+
assert_match_in_file(/class User < Sequel::Model/m, "#{@apptmp}/sample_project/app/models/user.rb")
|
181
186
|
end
|
182
187
|
|
183
188
|
should "generate migration file with given properties" do
|
184
189
|
current_time = stop_time_for_test.strftime("%Y%m%d%H%M%S")
|
185
|
-
silence_logger { generate(:project, 'sample_project',
|
186
|
-
silence_logger { generate(:model, 'person', "name:string", "age:integer", "created:datetime",
|
187
|
-
migration_file_path = "/
|
188
|
-
assert_match_in_file(/class Person < Sequel::Model/m,
|
190
|
+
silence_logger { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-d=sequel') }
|
191
|
+
silence_logger { generate(:model, 'person', "name:string", "age:integer", "created:datetime", "-r=#{@apptmp}/sample_project") }
|
192
|
+
migration_file_path = "#{@apptmp}/sample_project/db/migrate/001_create_people.rb"
|
193
|
+
assert_match_in_file(/class Person < Sequel::Model/m, "#{@apptmp}/sample_project/app/models/person.rb")
|
189
194
|
assert_match_in_file(/class CreatePeople < Sequel::Migration/m, migration_file_path)
|
190
195
|
assert_match_in_file(/create_table :people/m, migration_file_path)
|
191
196
|
assert_match_in_file(/String :name/m, migration_file_path)
|
@@ -198,157 +203,157 @@ class TestModelGenerator < Test::Unit::TestCase
|
|
198
203
|
# MONGODB
|
199
204
|
context "model generator using mongomapper" do
|
200
205
|
should "generate model file with no properties" do
|
201
|
-
silence_logger { generate(:project, 'sample_project',
|
202
|
-
silence_logger { generate(:model, 'person',
|
203
|
-
assert_match_in_file(/class Person\n\s+include MongoMapper::Document/m,
|
204
|
-
assert_match_in_file(/# key <name>, <type>/m,
|
205
|
-
assert_match_in_file(/timestamps![\n\s]+end/m,
|
206
|
+
silence_logger { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-d=mongomapper') }
|
207
|
+
silence_logger { generate(:model, 'person', "-r=#{@apptmp}/sample_project") }
|
208
|
+
assert_match_in_file(/class Person\n\s+include MongoMapper::Document/m, "#{@apptmp}/sample_project/app/models/person.rb")
|
209
|
+
assert_match_in_file(/# key <name>, <type>/m, "#{@apptmp}/sample_project/app/models/person.rb")
|
210
|
+
assert_match_in_file(/timestamps![\n\s]+end/m, "#{@apptmp}/sample_project/app/models/person.rb")
|
206
211
|
end
|
207
212
|
|
208
213
|
should "generate model file with given fields" do
|
209
|
-
silence_logger { generate(:project, 'sample_project',
|
210
|
-
silence_logger { generate(:model, 'user', "name:string", "age:integer", "email:string",
|
211
|
-
assert_match_in_file(/class User\n\s+include MongoMapper::Document/m,
|
212
|
-
assert_match_in_file(/key :name, String/m,
|
213
|
-
assert_match_in_file(/key :age, Integer/m,
|
214
|
-
assert_match_in_file(/key :email, String/m,
|
215
|
-
assert_match_in_file(/timestamps!/m,
|
214
|
+
silence_logger { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-d=mongomapper') }
|
215
|
+
silence_logger { generate(:model, 'user', "name:string", "age:integer", "email:string", "-r=#{@apptmp}/sample_project") }
|
216
|
+
assert_match_in_file(/class User\n\s+include MongoMapper::Document/m, "#{@apptmp}/sample_project/app/models/user.rb")
|
217
|
+
assert_match_in_file(/key :name, String/m, "#{@apptmp}/sample_project/app/models/user.rb")
|
218
|
+
assert_match_in_file(/key :age, Integer/m, "#{@apptmp}/sample_project/app/models/user.rb")
|
219
|
+
assert_match_in_file(/key :email, String/m, "#{@apptmp}/sample_project/app/models/user.rb")
|
220
|
+
assert_match_in_file(/timestamps!/m, "#{@apptmp}/sample_project/app/models/user.rb")
|
216
221
|
end
|
217
222
|
end
|
218
223
|
|
219
224
|
context "model generator using mongoid" do
|
220
225
|
should "generate model file with no properties" do
|
221
|
-
silence_logger { generate(:project, 'sample_project',
|
222
|
-
silence_logger { generate(:model, 'person',
|
223
|
-
assert_match_in_file(/class Person\n\s+include Mongoid::Document/m,
|
224
|
-
assert_match_in_file(/# field <name>, :type => <type>, :default => <value>/m,
|
226
|
+
silence_logger { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-d=mongoid') }
|
227
|
+
silence_logger { generate(:model, 'person', "-r=#{@apptmp}/sample_project") }
|
228
|
+
assert_match_in_file(/class Person\n\s+include Mongoid::Document/m, "#{@apptmp}/sample_project/app/models/person.rb")
|
229
|
+
assert_match_in_file(/# field <name>, :type => <type>, :default => <value>/m, "#{@apptmp}/sample_project/app/models/person.rb")
|
225
230
|
end
|
226
231
|
|
227
232
|
should "generate model file with given fields" do
|
228
|
-
silence_logger { generate(:project, 'sample_project',
|
229
|
-
silence_logger { generate(:model, 'user', "name:string", "age:integer", "email:string",
|
230
|
-
assert_match_in_file(/class User\n\s+include Mongoid::Document/m,
|
231
|
-
assert_match_in_file(/field :name, :type => String/m,
|
232
|
-
assert_match_in_file(/field :age, :type => Integer/m,
|
233
|
-
assert_match_in_file(/field :email, :type => String/m,
|
233
|
+
silence_logger { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-d=mongoid') }
|
234
|
+
silence_logger { generate(:model, 'user', "name:string", "age:integer", "email:string", "-r=#{@apptmp}/sample_project") }
|
235
|
+
assert_match_in_file(/class User\n\s+include Mongoid::Document/m, "#{@apptmp}/sample_project/app/models/user.rb")
|
236
|
+
assert_match_in_file(/field :name, :type => String/m, "#{@apptmp}/sample_project/app/models/user.rb")
|
237
|
+
assert_match_in_file(/field :age, :type => Integer/m, "#{@apptmp}/sample_project/app/models/user.rb")
|
238
|
+
assert_match_in_file(/field :email, :type => String/m, "#{@apptmp}/sample_project/app/models/user.rb")
|
234
239
|
end
|
235
240
|
end
|
236
241
|
|
237
242
|
# REDIS
|
238
243
|
context "model generator using ohm" do
|
239
244
|
should "generate model file with no properties" do
|
240
|
-
silence_logger { generate(:project, 'sample_project',
|
241
|
-
silence_logger { generate(:model, 'person',
|
242
|
-
assert_match_in_file(/class Person < Ohm::Model/,
|
243
|
-
assert_match_in_file(/include Ohm::Timestamping/,
|
244
|
-
assert_match_in_file(/include Ohm::Typecast/,
|
245
|
-
assert_match_in_file(/# attribute :name/m,
|
246
|
-
assert_match_in_file(/# reference :venue, Venue/m,
|
245
|
+
silence_logger { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-d=ohm') }
|
246
|
+
silence_logger { generate(:model, 'person', "-r=#{@apptmp}/sample_project") }
|
247
|
+
assert_match_in_file(/class Person < Ohm::Model/, "#{@apptmp}/sample_project/app/models/person.rb")
|
248
|
+
assert_match_in_file(/include Ohm::Timestamping/, "#{@apptmp}/sample_project/app/models/person.rb")
|
249
|
+
assert_match_in_file(/include Ohm::Typecast/, "#{@apptmp}/sample_project/app/models/person.rb")
|
250
|
+
assert_match_in_file(/# attribute :name/m, "#{@apptmp}/sample_project/app/models/person.rb")
|
251
|
+
assert_match_in_file(/# reference :venue, Venue/m, "#{@apptmp}/sample_project/app/models/person.rb")
|
247
252
|
end
|
248
253
|
|
249
254
|
should "generate model file with given fields" do
|
250
|
-
silence_logger { generate(:project, 'sample_project',
|
251
|
-
silence_logger { generate(:model, 'user', "name:string", "age:integer", "email:string",
|
252
|
-
assert_match_in_file(/class User < Ohm::Model/,
|
253
|
-
assert_match_in_file(/attribute :name, String/m,
|
254
|
-
assert_match_in_file(/attribute :age, Integer/m,
|
255
|
-
assert_match_in_file(/attribute :email, String/m,
|
255
|
+
silence_logger { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-d=ohm') }
|
256
|
+
silence_logger { generate(:model, 'user', "name:string", "age:integer", "email:string", "-r=#{@apptmp}/sample_project") }
|
257
|
+
assert_match_in_file(/class User < Ohm::Model/, "#{@apptmp}/sample_project/app/models/user.rb")
|
258
|
+
assert_match_in_file(/attribute :name, String/m, "#{@apptmp}/sample_project/app/models/user.rb")
|
259
|
+
assert_match_in_file(/attribute :age, Integer/m, "#{@apptmp}/sample_project/app/models/user.rb")
|
260
|
+
assert_match_in_file(/attribute :email, String/m, "#{@apptmp}/sample_project/app/models/user.rb")
|
256
261
|
end
|
257
262
|
end
|
258
263
|
|
259
264
|
# MONGOMATIC
|
260
265
|
context "model generator using mongomatic" do
|
261
266
|
should "generate model file with no properties" do
|
262
|
-
silence_logger { generate(:project, 'sample_project',
|
263
|
-
silence_logger { generate(:model, 'person',
|
264
|
-
assert_match_in_file(/class Person < Mongomatic::Base/,
|
265
|
-
assert_match_in_file(/include Mongomatic::Expectations::Helper/m,
|
267
|
+
silence_logger { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-d=mongomatic') }
|
268
|
+
silence_logger { generate(:model, 'person', "-r=#{@apptmp}/sample_project") }
|
269
|
+
assert_match_in_file(/class Person < Mongomatic::Base/, "#{@apptmp}/sample_project/app/models/person.rb")
|
270
|
+
assert_match_in_file(/include Mongomatic::Expectations::Helper/m, "#{@apptmp}/sample_project/app/models/person.rb")
|
266
271
|
end
|
267
272
|
|
268
273
|
should "generate model file with given fields" do
|
269
|
-
silence_logger { generate(:project, 'sample_project',
|
270
|
-
silence_logger { generate(:model, 'user', "name:string", "age:integer", "email:string",
|
271
|
-
assert_match_in_file(/class User < Mongomatic::Base/,
|
272
|
-
assert_match_in_file(/include Mongomatic::Expectations::Helper/,
|
273
|
-
assert_match_in_file(/be_present self\['name'\]/m,
|
274
|
-
assert_match_in_file(/be_present self\['age'\]/m,
|
275
|
-
assert_match_in_file(/be_present self\['email'\]/m,
|
276
|
-
assert_match_in_file(/be_a_number self\['age'\]/m,
|
274
|
+
silence_logger { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-d=mongomatic') }
|
275
|
+
silence_logger { generate(:model, 'user', "name:string", "age:integer", "email:string", "-r=#{@apptmp}/sample_project") }
|
276
|
+
assert_match_in_file(/class User < Mongomatic::Base/, "#{@apptmp}/sample_project/app/models/user.rb")
|
277
|
+
assert_match_in_file(/include Mongomatic::Expectations::Helper/, "#{@apptmp}/sample_project/app/models/user.rb")
|
278
|
+
assert_match_in_file(/be_present self\['name'\]/m, "#{@apptmp}/sample_project/app/models/user.rb")
|
279
|
+
assert_match_in_file(/be_present self\['age'\]/m, "#{@apptmp}/sample_project/app/models/user.rb")
|
280
|
+
assert_match_in_file(/be_present self\['email'\]/m, "#{@apptmp}/sample_project/app/models/user.rb")
|
281
|
+
assert_match_in_file(/be_a_number self\['age'\]/m, "#{@apptmp}/sample_project/app/models/user.rb")
|
277
282
|
end
|
278
283
|
end
|
279
284
|
|
280
285
|
context "model generator testing files" do
|
281
286
|
# BACON
|
282
287
|
should "generate test file for bacon" do
|
283
|
-
silence_logger { generate(:project, 'sample_project',
|
284
|
-
silence_logger { generate(:model, 'SomeUser',
|
285
|
-
assert_match_in_file(/describe "SomeUser Model"/m,
|
286
|
-
assert_match_in_file(/@some_user = SomeUser.new/m,
|
287
|
-
assert_match_in_file(/@some_user\.should\.not\.be\.nil/m,
|
288
|
+
silence_logger { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=bacon', '-d=activerecord') }
|
289
|
+
silence_logger { generate(:model, 'SomeUser', "-r=#{@apptmp}/sample_project") }
|
290
|
+
assert_match_in_file(/describe "SomeUser Model"/m, "#{@apptmp}/sample_project/test/models/some_user_test.rb")
|
291
|
+
assert_match_in_file(/@some_user = SomeUser.new/m, "#{@apptmp}/sample_project/test/models/some_user_test.rb")
|
292
|
+
assert_match_in_file(/@some_user\.should\.not\.be\.nil/m, "#{@apptmp}/sample_project/test/models/some_user_test.rb")
|
288
293
|
end
|
289
294
|
|
290
295
|
# RIOT
|
291
296
|
should "generate test file for riot" do
|
292
|
-
silence_logger { generate(:project, 'sample_project',
|
293
|
-
silence_logger { generate(:model, 'SomeUser',
|
294
|
-
assert_match_in_file(/context "SomeUser Model" do/m,
|
295
|
-
assert_match_in_file(/SomeUser.new/m,
|
296
|
-
assert_match_in_file(/asserts\("that record is not nil"\) \{ \!topic.nil\? \}/m,
|
297
|
+
silence_logger { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=riot', '-d=activerecord') }
|
298
|
+
silence_logger { generate(:model, 'SomeUser', "-r=#{@apptmp}/sample_project") }
|
299
|
+
assert_match_in_file(/context "SomeUser Model" do/m, "#{@apptmp}/sample_project/test/models/some_user_test.rb")
|
300
|
+
assert_match_in_file(/SomeUser.new/m, "#{@apptmp}/sample_project/test/models/some_user_test.rb")
|
301
|
+
assert_match_in_file(/asserts\("that record is not nil"\) \{ \!topic.nil\? \}/m, "#{@apptmp}/sample_project/test/models/some_user_test.rb")
|
297
302
|
end
|
298
303
|
|
299
304
|
# RSPEC
|
300
305
|
should "generate test file for rspec" do
|
301
|
-
silence_logger { generate(:project, 'sample_project',
|
302
|
-
silence_logger { generate(:model, 'SomeUser',
|
303
|
-
assert_match_in_file(/describe "SomeUser Model"/m,
|
304
|
-
assert_match_in_file(
|
305
|
-
assert_match_in_file(
|
306
|
+
silence_logger { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=rspec', '-d=activerecord') }
|
307
|
+
silence_logger { generate(:model, 'SomeUser', "-r=#{@apptmp}/sample_project") }
|
308
|
+
assert_match_in_file(/describe "SomeUser Model"/m, "#{@apptmp}/sample_project/spec/models/some_user_spec.rb")
|
309
|
+
assert_match_in_file(/let\(:some_user\) \{ SomeUser.new \}/m, "#{@apptmp}/sample_project/spec/models/some_user_spec.rb")
|
310
|
+
assert_match_in_file(/some_user\.should_not be_nil/m, "#{@apptmp}/sample_project/spec/models/some_user_spec.rb")
|
306
311
|
end
|
307
312
|
|
308
313
|
# SHOULDA
|
309
314
|
should "generate test file for shoulda" do
|
310
|
-
silence_logger { generate(:project, 'sample_project',
|
311
|
-
silence_logger { generate(:model, 'SomePerson',
|
312
|
-
assert_match_in_file(/class SomePersonControllerTest < Test::Unit::TestCase/m,
|
313
|
-
assert_match_in_file(/context "SomePerson Model"/m,
|
314
|
-
assert_match_in_file(/@some_person = SomePerson.new/m,
|
315
|
-
assert_match_in_file(/assert_not_nil @some_person/m,
|
315
|
+
silence_logger { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=shoulda', '-d=activerecord') }
|
316
|
+
silence_logger { generate(:model, 'SomePerson', "-r=#{@apptmp}/sample_project") }
|
317
|
+
assert_match_in_file(/class SomePersonControllerTest < Test::Unit::TestCase/m, "#{@apptmp}/sample_project/test/models/some_person_test.rb")
|
318
|
+
assert_match_in_file(/context "SomePerson Model"/m, "#{@apptmp}/sample_project/test/models/some_person_test.rb")
|
319
|
+
assert_match_in_file(/@some_person = SomePerson.new/m, "#{@apptmp}/sample_project/test/models/some_person_test.rb")
|
320
|
+
assert_match_in_file(/assert_not_nil @some_person/m, "#{@apptmp}/sample_project/test/models/some_person_test.rb")
|
316
321
|
end
|
317
322
|
|
318
323
|
# TESTSPEC
|
319
324
|
should "generate test file for testspec" do
|
320
|
-
silence_logger { generate(:project, 'sample_project',
|
321
|
-
silence_logger { generate(:model, 'SomeUser',
|
322
|
-
assert_match_in_file(/context "SomeUser Model"/m,
|
323
|
-
assert_match_in_file(/@some_user = SomeUser.new/m,
|
324
|
-
assert_match_in_file(/@some_user\.should\.not\.be\.nil/m,
|
325
|
+
silence_logger { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=testspec', '-d=activerecord') }
|
326
|
+
silence_logger { generate(:model, 'SomeUser', "-r=#{@apptmp}/sample_project") }
|
327
|
+
assert_match_in_file(/context "SomeUser Model"/m, "#{@apptmp}/sample_project/test/models/some_user_test.rb")
|
328
|
+
assert_match_in_file(/@some_user = SomeUser.new/m, "#{@apptmp}/sample_project/test/models/some_user_test.rb")
|
329
|
+
assert_match_in_file(/@some_user\.should\.not\.be\.nil/m, "#{@apptmp}/sample_project/test/models/some_user_test.rb")
|
325
330
|
end
|
326
331
|
end
|
327
332
|
|
328
333
|
context "the model destroy option" do
|
329
334
|
|
330
335
|
should "destroy the model file" do
|
331
|
-
silence_logger { generate(:project, 'sample_project',
|
332
|
-
silence_logger { generate(:model, 'User',
|
333
|
-
silence_logger { generate(:model, 'User',
|
334
|
-
assert_no_file_exists(
|
335
|
-
assert_no_file_exists(
|
336
|
-
assert_no_file_exists(
|
336
|
+
silence_logger { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=bacon', '-d=activerecord') }
|
337
|
+
silence_logger { generate(:model, 'User', "-r=#{@apptmp}/sample_project") }
|
338
|
+
silence_logger { generate(:model, 'User', "-r=#{@apptmp}/sample_project", '-d') }
|
339
|
+
assert_no_file_exists("#{@apptmp}/sample_project/app/models/user.rb")
|
340
|
+
assert_no_file_exists("#{@apptmp}/sample_project/test/models/user_test.rb")
|
341
|
+
assert_no_file_exists("#{@apptmp}/sample_project/db/migrate/001_create_users.rb")
|
337
342
|
end
|
338
343
|
|
339
344
|
should "destroy the model test file with rspec" do
|
340
|
-
silence_logger { generate(:project, 'sample_project',
|
341
|
-
silence_logger { generate(:model, 'User',
|
342
|
-
silence_logger { generate(:model, 'User',
|
343
|
-
assert_no_file_exists(
|
345
|
+
silence_logger { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=rspec', '-d=activerecord') }
|
346
|
+
silence_logger { generate(:model, 'User', "-r=#{@apptmp}/sample_project") }
|
347
|
+
silence_logger { generate(:model, 'User', "-r=#{@apptmp}/sample_project", '-d') }
|
348
|
+
assert_no_file_exists("#{@apptmp}/sample_project/spec/models/user_spec.rb")
|
344
349
|
end
|
345
350
|
|
346
351
|
should "destroy the model migration" do
|
347
|
-
silence_logger { generate(:project, 'sample_project',
|
348
|
-
silence_logger { generate(:model, 'Person',
|
349
|
-
silence_logger { generate(:model, 'User',
|
350
|
-
silence_logger { generate(:model, 'User',
|
351
|
-
assert_no_file_exists(
|
352
|
+
silence_logger { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=rspec', '-d=activerecord') }
|
353
|
+
silence_logger { generate(:model, 'Person', "-r=#{@apptmp}/sample_project") }
|
354
|
+
silence_logger { generate(:model, 'User', "-r=#{@apptmp}/sample_project") }
|
355
|
+
silence_logger { generate(:model, 'User', "-r=#{@apptmp}/sample_project", '-d') }
|
356
|
+
assert_no_file_exists("#{@apptmp}/sample_project/db/migrate/002_create_users.rb")
|
352
357
|
end
|
353
358
|
end
|
354
359
|
end
|