padrino-gen 0.9.10 → 0.9.11
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +2 -2
- data/Rakefile +4 -53
- data/bin/padrino-gen +2 -4
- data/lib/padrino-gen/command.rb +12 -0
- data/lib/padrino-gen/generators/actions.rb +25 -5
- data/lib/padrino-gen/generators/app/app.rb.tt +17 -19
- data/lib/padrino-gen/generators/app.rb +7 -6
- data/lib/padrino-gen/generators/cli.rb +3 -2
- data/lib/padrino-gen/generators/components/actions.rb +4 -4
- data/lib/padrino-gen/generators/components/mocks/rr.rb +1 -1
- data/lib/padrino-gen/generators/components/orms/activerecord.rb +58 -16
- data/lib/padrino-gen/generators/components/orms/couchrest.rb +6 -5
- data/lib/padrino-gen/generators/components/orms/datamapper.rb +41 -17
- data/lib/padrino-gen/generators/components/orms/mongoid.rb +7 -6
- data/lib/padrino-gen/generators/components/orms/mongomapper.rb +6 -5
- data/lib/padrino-gen/generators/components/orms/sequel.rb +34 -15
- data/lib/padrino-gen/generators/components/scripts/dojo.rb +4 -0
- data/lib/padrino-gen/generators/components/stylesheets/compass/application.scss +43 -0
- data/lib/padrino-gen/generators/components/stylesheets/compass/partials/_base.scss +10 -0
- data/lib/padrino-gen/generators/components/stylesheets/compass.rb +39 -0
- data/lib/padrino-gen/generators/components/stylesheets/less.rb +2 -2
- data/lib/padrino-gen/generators/components/stylesheets/sass.rb +2 -2
- data/lib/padrino-gen/generators/components/tests/bacon.rb +2 -1
- data/lib/padrino-gen/generators/components/tests/cucumber.rb +26 -4
- data/lib/padrino-gen/generators/components/tests/riot.rb +45 -9
- data/lib/padrino-gen/generators/components/tests/rspec.rb +2 -1
- data/lib/padrino-gen/generators/components/tests/shoulda.rb +2 -1
- data/lib/padrino-gen/generators/components/tests/testspec.rb +2 -1
- data/lib/padrino-gen/generators/controller.rb +2 -2
- data/lib/padrino-gen/generators/mailer.rb +6 -8
- data/lib/padrino-gen/generators/model.rb +9 -1
- data/lib/padrino-gen/generators/project/config/apps.rb.tt +24 -26
- data/lib/padrino-gen/generators/project/config/boot.rb +2 -2
- data/lib/padrino-gen/generators/project.rb +23 -16
- data/lib/padrino-gen/generators/templates/Gemfile.tt +1 -1
- data/lib/padrino-gen/generators/templates/controller.rb.tt +2 -2
- data/lib/padrino-gen/generators/templates/mailer.rb.tt +36 -17
- data/lib/padrino-gen/generators/templates/scripts/dojo.js +16 -0
- data/lib/padrino-gen/generators/templates/scripts/mootools-core.js +120 -1
- data/lib/padrino-gen/generators/templates/scripts/right.js +1 -12
- data/lib/padrino-gen/padrino-tasks/activerecord.rb +40 -34
- data/lib/padrino-gen/padrino-tasks/datamapper.rb +39 -24
- data/lib/padrino-gen/padrino-tasks/mongomapper.rb +1 -1
- data/lib/padrino-gen.rb +2 -1
- data/padrino-gen.gemspec +17 -132
- data/test/helper.rb +3 -11
- data/test/test_app_generator.rb +19 -7
- data/test/test_controller_generator.rb +11 -1
- data/test/test_mailer_generator.rb +18 -15
- data/test/test_migration_generator.rb +4 -4
- data/test/test_model_generator.rb +30 -9
- data/test/test_project_generator.rb +163 -33
- metadata +70 -48
- data/lib/padrino-gen/generators/app/controllers/.empty_directory +0 -0
- data/lib/padrino-gen/generators/app/helpers/.empty_directory +0 -0
- data/lib/padrino-gen/generators/app/views/.empty_directory +0 -0
- data/lib/padrino-gen/generators/app/views/layouts/.emptydirectory +0 -0
- data/lib/padrino-gen/generators/project/.gitignore +0 -7
- data/lib/padrino-gen/generators/project/public/images/.empty_directory +0 -0
- data/lib/padrino-gen/generators/project/public/javascripts/.empty_directory +0 -0
- data/lib/padrino-gen/generators/project/public/stylesheets/.empty_directory +0 -0
- data/lib/padrino-gen/generators/project/tmp/.empty_directory +0 -0
- data/lib/padrino-gen/generators/templates/mailer_initializer.rb.tt +0 -19
data/padrino-gen.gemspec
CHANGED
@@ -1,139 +1,24 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
# -*- encoding: utf-8 -*-
|
1
|
+
require File.expand_path("../../padrino-core/lib/padrino-core/version.rb", __FILE__)
|
2
|
+
require 'rubygems'
|
3
|
+
require 'bundler'
|
5
4
|
|
6
5
|
Gem::Specification.new do |s|
|
7
6
|
s.name = %q{padrino-gen}
|
8
|
-
s.
|
9
|
-
|
10
|
-
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
7
|
+
s.rubyforge_project = %q{padrino-gen}
|
11
8
|
s.authors = ["Padrino Team", "Nathan Esquenazi", "Davide D'Agostino", "Arthur Chiu"]
|
12
|
-
s.date = %q{2010-04-22}
|
13
|
-
s.default_executable = %q{padrino-gen}
|
14
|
-
s.description = %q{Generators for easily creating and building padrino applications from the console}
|
15
9
|
s.email = %q{padrinorb@gmail.com}
|
16
|
-
s.
|
17
|
-
s.extra_rdoc_files = [
|
18
|
-
"README.rdoc"
|
19
|
-
]
|
20
|
-
s.files = [
|
21
|
-
".document",
|
22
|
-
".gitignore",
|
23
|
-
"LICENSE",
|
24
|
-
"README.rdoc",
|
25
|
-
"Rakefile",
|
26
|
-
"bin/padrino-gen",
|
27
|
-
"lib/padrino-gen.rb",
|
28
|
-
"lib/padrino-gen/generators/actions.rb",
|
29
|
-
"lib/padrino-gen/generators/app.rb",
|
30
|
-
"lib/padrino-gen/generators/app/app.rb.tt",
|
31
|
-
"lib/padrino-gen/generators/app/controllers/.empty_directory",
|
32
|
-
"lib/padrino-gen/generators/app/helpers/.empty_directory",
|
33
|
-
"lib/padrino-gen/generators/app/views/.empty_directory",
|
34
|
-
"lib/padrino-gen/generators/app/views/layouts/.emptydirectory",
|
35
|
-
"lib/padrino-gen/generators/cli.rb",
|
36
|
-
"lib/padrino-gen/generators/components/actions.rb",
|
37
|
-
"lib/padrino-gen/generators/components/mocks/mocha.rb",
|
38
|
-
"lib/padrino-gen/generators/components/mocks/rr.rb",
|
39
|
-
"lib/padrino-gen/generators/components/orms/activerecord.rb",
|
40
|
-
"lib/padrino-gen/generators/components/orms/couchrest.rb",
|
41
|
-
"lib/padrino-gen/generators/components/orms/datamapper.rb",
|
42
|
-
"lib/padrino-gen/generators/components/orms/mongoid.rb",
|
43
|
-
"lib/padrino-gen/generators/components/orms/mongomapper.rb",
|
44
|
-
"lib/padrino-gen/generators/components/orms/sequel.rb",
|
45
|
-
"lib/padrino-gen/generators/components/renderers/erb.rb",
|
46
|
-
"lib/padrino-gen/generators/components/renderers/haml.rb",
|
47
|
-
"lib/padrino-gen/generators/components/scripts/extcore.rb",
|
48
|
-
"lib/padrino-gen/generators/components/scripts/jquery.rb",
|
49
|
-
"lib/padrino-gen/generators/components/scripts/mootools.rb",
|
50
|
-
"lib/padrino-gen/generators/components/scripts/prototype.rb",
|
51
|
-
"lib/padrino-gen/generators/components/scripts/rightjs.rb",
|
52
|
-
"lib/padrino-gen/generators/components/stylesheets/less.rb",
|
53
|
-
"lib/padrino-gen/generators/components/stylesheets/sass.rb",
|
54
|
-
"lib/padrino-gen/generators/components/tests/bacon.rb",
|
55
|
-
"lib/padrino-gen/generators/components/tests/cucumber.rb",
|
56
|
-
"lib/padrino-gen/generators/components/tests/riot.rb",
|
57
|
-
"lib/padrino-gen/generators/components/tests/rspec.rb",
|
58
|
-
"lib/padrino-gen/generators/components/tests/shoulda.rb",
|
59
|
-
"lib/padrino-gen/generators/components/tests/testspec.rb",
|
60
|
-
"lib/padrino-gen/generators/controller.rb",
|
61
|
-
"lib/padrino-gen/generators/mailer.rb",
|
62
|
-
"lib/padrino-gen/generators/migration.rb",
|
63
|
-
"lib/padrino-gen/generators/model.rb",
|
64
|
-
"lib/padrino-gen/generators/project.rb",
|
65
|
-
"lib/padrino-gen/generators/project/.gitignore",
|
66
|
-
"lib/padrino-gen/generators/project/config.ru",
|
67
|
-
"lib/padrino-gen/generators/project/config/apps.rb.tt",
|
68
|
-
"lib/padrino-gen/generators/project/config/boot.rb",
|
69
|
-
"lib/padrino-gen/generators/project/public/favicon.ico",
|
70
|
-
"lib/padrino-gen/generators/project/public/images/.empty_directory",
|
71
|
-
"lib/padrino-gen/generators/project/public/javascripts/.empty_directory",
|
72
|
-
"lib/padrino-gen/generators/project/public/stylesheets/.empty_directory",
|
73
|
-
"lib/padrino-gen/generators/project/tmp/.empty_directory",
|
74
|
-
"lib/padrino-gen/generators/templates/Gemfile.tt",
|
75
|
-
"lib/padrino-gen/generators/templates/controller.rb.tt",
|
76
|
-
"lib/padrino-gen/generators/templates/helper.rb.tt",
|
77
|
-
"lib/padrino-gen/generators/templates/mailer.rb.tt",
|
78
|
-
"lib/padrino-gen/generators/templates/mailer_initializer.rb.tt",
|
79
|
-
"lib/padrino-gen/generators/templates/scripts/ext-core.js",
|
80
|
-
"lib/padrino-gen/generators/templates/scripts/jquery.js",
|
81
|
-
"lib/padrino-gen/generators/templates/scripts/lowpro.js",
|
82
|
-
"lib/padrino-gen/generators/templates/scripts/mootools-core.js",
|
83
|
-
"lib/padrino-gen/generators/templates/scripts/protopak.js",
|
84
|
-
"lib/padrino-gen/generators/templates/scripts/right.js",
|
85
|
-
"lib/padrino-gen/padrino-tasks/activerecord.rb",
|
86
|
-
"lib/padrino-gen/padrino-tasks/datamapper.rb",
|
87
|
-
"lib/padrino-gen/padrino-tasks/mongomapper.rb",
|
88
|
-
"lib/padrino-gen/padrino-tasks/seed.rb",
|
89
|
-
"lib/padrino-gen/padrino-tasks/sequel.rb",
|
90
|
-
"padrino-gen.gemspec",
|
91
|
-
"test/helper.rb",
|
92
|
-
"test/test_app_generator.rb",
|
93
|
-
"test/test_cli.rb",
|
94
|
-
"test/test_controller_generator.rb",
|
95
|
-
"test/test_generator.rb",
|
96
|
-
"test/test_mailer_generator.rb",
|
97
|
-
"test/test_migration_generator.rb",
|
98
|
-
"test/test_model_generator.rb",
|
99
|
-
"test/test_project_generator.rb"
|
100
|
-
]
|
10
|
+
s.summary = %q{Generators for easily creating and building padrino applications}
|
101
11
|
s.homepage = %q{http://github.com/padrino/padrino-framework/tree/master/padrino-gen}
|
12
|
+
s.description = %q{Generators for easily creating and building padrino applications from the console}
|
13
|
+
s.default_executable = %q{padrino-gen}
|
14
|
+
s.executables = ["padrino-gen"]
|
15
|
+
s.required_rubygems_version = ">= 1.3.6"
|
16
|
+
s.version = Padrino.version
|
17
|
+
s.date = Time.now.strftime("%Y-%m-%d")
|
18
|
+
s.extra_rdoc_files = Dir["*.rdoc"]
|
19
|
+
s.files = %w(.document .gitignore LICENSE README.rdoc Rakefile padrino-gen.gemspec) + Dir.glob("{bin,lib,test}/**/*")
|
102
20
|
s.rdoc_options = ["--charset=UTF-8"]
|
103
|
-
s.
|
104
|
-
s.
|
105
|
-
s.
|
106
|
-
|
107
|
-
|
108
|
-
if s.respond_to? :specification_version then
|
109
|
-
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
110
|
-
s.specification_version = 3
|
111
|
-
|
112
|
-
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
113
|
-
s.add_runtime_dependency(%q<padrino-core>, ["= 0.9.10"])
|
114
|
-
s.add_development_dependency(%q<haml>, [">= 2.2.1"])
|
115
|
-
s.add_development_dependency(%q<shoulda>, [">= 2.10.3"])
|
116
|
-
s.add_development_dependency(%q<mocha>, [">= 0.9.7"])
|
117
|
-
s.add_development_dependency(%q<rack-test>, [">= 0.5.0"])
|
118
|
-
s.add_development_dependency(%q<webrat>, [">= 0.5.1"])
|
119
|
-
s.add_development_dependency(%q<fakeweb>, [">= 1.2.3"])
|
120
|
-
else
|
121
|
-
s.add_dependency(%q<padrino-core>, ["= 0.9.10"])
|
122
|
-
s.add_dependency(%q<haml>, [">= 2.2.1"])
|
123
|
-
s.add_dependency(%q<shoulda>, [">= 2.10.3"])
|
124
|
-
s.add_dependency(%q<mocha>, [">= 0.9.7"])
|
125
|
-
s.add_dependency(%q<rack-test>, [">= 0.5.0"])
|
126
|
-
s.add_dependency(%q<webrat>, [">= 0.5.1"])
|
127
|
-
s.add_dependency(%q<fakeweb>, [">= 1.2.3"])
|
128
|
-
end
|
129
|
-
else
|
130
|
-
s.add_dependency(%q<padrino-core>, ["= 0.9.10"])
|
131
|
-
s.add_dependency(%q<haml>, [">= 2.2.1"])
|
132
|
-
s.add_dependency(%q<shoulda>, [">= 2.10.3"])
|
133
|
-
s.add_dependency(%q<mocha>, [">= 0.9.7"])
|
134
|
-
s.add_dependency(%q<rack-test>, [">= 0.5.0"])
|
135
|
-
s.add_dependency(%q<webrat>, [">= 0.5.1"])
|
136
|
-
s.add_dependency(%q<fakeweb>, [">= 1.2.3"])
|
137
|
-
end
|
138
|
-
end
|
139
|
-
|
21
|
+
s.require_path = 'lib'
|
22
|
+
s.add_runtime_dependency(%q<padrino-core>, ["= #{Padrino.version}"])
|
23
|
+
s.add_bundler_dependencies :gen, :development
|
24
|
+
end
|
data/test/helper.rb
CHANGED
@@ -1,20 +1,12 @@
|
|
1
|
-
require '
|
1
|
+
require File.expand_path('../../../load_paths', __FILE__)
|
2
2
|
require 'test/unit'
|
3
3
|
require 'shoulda'
|
4
4
|
require 'mocha'
|
5
5
|
require 'rack/test'
|
6
6
|
require 'webrat'
|
7
7
|
require 'thor/group'
|
8
|
-
|
9
|
-
# We try to load the vendored padrino-core if exist
|
10
|
-
%w(core).each do |lib|
|
11
|
-
if File.exist?(File.dirname(__FILE__) + "/../../padrino-#{lib}/lib")
|
12
|
-
$:.unshift File.dirname(__FILE__) + "/../../padrino-#{lib}/lib"
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
8
|
require 'padrino-gen'
|
17
|
-
require 'padrino-core/support_lite'
|
9
|
+
require 'padrino-core/support_lite' unless defined?(SupportLite)
|
18
10
|
|
19
11
|
Padrino::Generators.load_components!
|
20
12
|
|
@@ -32,7 +24,7 @@ class Test::Unit::TestCase
|
|
32
24
|
Time.stubs(:now).returns(time)
|
33
25
|
return time
|
34
26
|
end
|
35
|
-
|
27
|
+
|
36
28
|
# generate(:controller, 'DemoItems', '-r=/tmp/sample_project')
|
37
29
|
def generate(name, *params)
|
38
30
|
"Padrino::Generators::#{name.to_s.camelize}".constantize.start(params)
|
data/test/test_app_generator.rb
CHANGED
@@ -26,6 +26,20 @@ class TestAppGenerator < Test::Unit::TestCase
|
|
26
26
|
assert_match_in_file 'class Demo < Padrino::Application', '/tmp/sample_project/demo/app.rb'
|
27
27
|
end
|
28
28
|
|
29
|
+
should "generate tiny app skeleton" do
|
30
|
+
assert_nothing_raised { silence_logger { generate(:project, 'sample_project', '--root=/tmp') } }
|
31
|
+
assert_nothing_raised { silence_logger { generate(:app,'demo','--tiny','--root=/tmp/sample_project') } }
|
32
|
+
assert_file_exists('/tmp/sample_project')
|
33
|
+
assert_file_exists('/tmp/sample_project/demo')
|
34
|
+
assert_file_exists('/tmp/sample_project/demo/helpers.rb')
|
35
|
+
assert_file_exists('/tmp/sample_project/demo/controllers.rb')
|
36
|
+
assert_file_exists('/tmp/sample_project/demo/mailers.rb')
|
37
|
+
assert_dir_exists('/tmp/sample_project/demo/views/mailers')
|
38
|
+
assert_match_in_file(/:notifier/,'/tmp/sample_project/demo/mailers.rb')
|
39
|
+
assert_no_file_exists('/tmp/sample_project/demo/helpers')
|
40
|
+
assert_no_file_exists('/tmp/sample_project/demo/controllers')
|
41
|
+
end
|
42
|
+
|
29
43
|
should "correctly create a new controller inside a padrino application" do
|
30
44
|
silence_logger { generate(:project, 'sample_project', '--root=/tmp') }
|
31
45
|
silence_logger { generate(:app, 'demo', '--root=/tmp/sample_project') }
|
@@ -37,12 +51,10 @@ class TestAppGenerator < Test::Unit::TestCase
|
|
37
51
|
|
38
52
|
should "correctly create a new mailer inside a padrino application" do
|
39
53
|
silence_logger { generate(:project, 'sample_project', '--root=/tmp', '--script=none', '-t=bacon') }
|
40
|
-
silence_logger { generate(:app, '
|
41
|
-
silence_logger { generate(:mailer, 'demo', '-r=/tmp/sample_project', '-a=
|
42
|
-
assert_match_in_file(/
|
43
|
-
|
44
|
-
assert_match_in_file(/register MailerInitializer/,'/tmp/sample_project/demo/app.rb')
|
45
|
-
assert_file_exists('/tmp/sample_project/demo/views/demo_mailer')
|
54
|
+
silence_logger { generate(:app, 'demo_app', '--root=/tmp/sample_project') }
|
55
|
+
silence_logger { generate(:mailer, 'demo', '-r=/tmp/sample_project', '-a=demo_app') }
|
56
|
+
assert_match_in_file(/DemoApp.mailer :demo/m, '/tmp/sample_project/demo_app/mailers/demo.rb')
|
57
|
+
assert_dir_exists('/tmp/sample_project/demo_app/views/mailers/demo')
|
46
58
|
end
|
47
59
|
end
|
48
|
-
end
|
60
|
+
end
|
@@ -14,6 +14,16 @@ class TestControllerGenerator < Test::Unit::TestCase
|
|
14
14
|
assert_no_file_exists('/tmp/app/controllers/demo.rb')
|
15
15
|
end
|
16
16
|
|
17
|
+
should "generate controller in specified app" do
|
18
|
+
silence_logger { generate(:project, 'sample_project', '--root=/tmp', '--script=none', '-t=bacon') }
|
19
|
+
silence_logger { generate(:app, 'subby', '-r=/tmp/sample_project') }
|
20
|
+
silence_logger { generate(:controller, 'DemoItems','-a=/subby', '-r=/tmp/sample_project') }
|
21
|
+
assert_match_in_file(/Subby.controllers :demo_items do/m, @controller_path.gsub('app','subby'))
|
22
|
+
assert_match_in_file(/Subby.helpers do/m, '/tmp/sample_project/subby/helpers/demo_items_helper.rb')
|
23
|
+
assert_file_exists('/tmp/sample_project/subby/views/demo_items')
|
24
|
+
assert_match_in_file(/describe "DemoItemsController" do/m, @controller_test_path.gsub('app','subby'))
|
25
|
+
end
|
26
|
+
|
17
27
|
should 'not fail if we don\'t have test component' do
|
18
28
|
silence_logger { generate(:project, 'sample_project', '--root=/tmp', '--test=none') }
|
19
29
|
silence_logger { generate(:controller, 'DemoItems', '-r=/tmp/sample_project') }
|
@@ -107,4 +117,4 @@ class TestControllerGenerator < Test::Unit::TestCase
|
|
107
117
|
assert_no_file_exists('/tmp/sample_project/spec/controllers/demo_items_controller_spec.rb')
|
108
118
|
end
|
109
119
|
end
|
110
|
-
end
|
120
|
+
end
|
@@ -12,29 +12,33 @@ class TestMailerGenerator < Test::Unit::TestCase
|
|
12
12
|
assert_no_file_exists('/tmp/app/mailers/demo_mailer.rb')
|
13
13
|
end
|
14
14
|
|
15
|
+
should "generate mailer in specified app" do
|
16
|
+
silence_logger { generate(:project, 'sample_project', '--root=/tmp', '--script=none', '-t=bacon') }
|
17
|
+
silence_logger { generate(:app, 'subby', '-r=/tmp/sample_project') }
|
18
|
+
silence_logger { generate(:mailer, 'demo', '-a=/subby', '-r=/tmp/sample_project') }
|
19
|
+
assert_match_in_file(/Subby.mailer :demo/m, '/tmp/sample_project/subby/mailers/demo.rb')
|
20
|
+
assert_dir_exists('/tmp/sample_project/subby/views/mailers/demo')
|
21
|
+
end
|
22
|
+
|
15
23
|
should "support generating a new mailer extended from base" do
|
16
24
|
silence_logger { generate(:project, 'sample_project', '--root=/tmp', '--script=none', '-t=bacon') }
|
17
25
|
silence_logger { generate(:mailer, 'demo', '-r=/tmp/sample_project') }
|
18
|
-
assert_match_in_file(/
|
19
|
-
|
20
|
-
assert_match_in_file(/register MailerInitializer/m, '/tmp/sample_project/app/app.rb')
|
21
|
-
assert_file_exists('/tmp/sample_project/app/views/demo_mailer')
|
26
|
+
assert_match_in_file(/SampleProject.mailer :demo/m, '/tmp/sample_project/app/mailers/demo.rb')
|
27
|
+
assert_dir_exists('/tmp/sample_project/app/views/mailers/demo')
|
22
28
|
end
|
23
29
|
|
24
30
|
should "support generating a new mailer extended from base with long name" do
|
25
31
|
silence_logger { generate(:project, 'sample_project', '--root=/tmp', '--script=none', '-t=bacon') }
|
26
|
-
silence_logger { generate(:mailer, '
|
27
|
-
assert_match_in_file(/
|
28
|
-
|
29
|
-
assert_file_exists('/tmp/sample_project/app/views/user_notice_mailer')
|
32
|
+
silence_logger { generate(:mailer, 'UserNotice', '-r=/tmp/sample_project') }
|
33
|
+
assert_match_in_file(/SampleProject.mailer :user_notice/m, '/tmp/sample_project/app/mailers/user_notice.rb')
|
34
|
+
assert_dir_exists('/tmp/sample_project/app/views/mailers/user_notice')
|
30
35
|
end
|
31
36
|
|
32
37
|
should "support generating a new mailer extended from base with capitalized name" do
|
33
38
|
silence_logger { generate(:project, 'sample_project', '--root=/tmp', '--script=none', '-t=bacon') }
|
34
39
|
silence_logger { generate(:mailer, 'DEMO', '-r=/tmp/sample_project') }
|
35
|
-
assert_match_in_file(/
|
36
|
-
|
37
|
-
assert_file_exists('/tmp/sample_project/app/views/demo_mailer')
|
40
|
+
assert_match_in_file(/SampleProject.mailer :demo/m, '/tmp/sample_project/app/mailers/demo.rb')
|
41
|
+
assert_dir_exists('/tmp/sample_project/app/views/mailers/demo')
|
38
42
|
end
|
39
43
|
end
|
40
44
|
|
@@ -43,9 +47,8 @@ class TestMailerGenerator < Test::Unit::TestCase
|
|
43
47
|
silence_logger { generate(:project, 'sample_project', '--root=/tmp', '--script=none', '-t=bacon') }
|
44
48
|
silence_logger { generate(:mailer, 'demo', '-r=/tmp/sample_project') }
|
45
49
|
silence_logger { generate(:mailer, 'demo', '-r=/tmp/sample_project','-d') }
|
46
|
-
assert_no_dir_exists('/tmp/sample_project/app/views/
|
47
|
-
assert_no_file_exists('/tmp/sample_project/app/mailers/
|
48
|
-
assert_no_file_exists('/tmp/sample_project/lib/mailer.rb')
|
50
|
+
assert_no_dir_exists('/tmp/sample_project/app/views/demo')
|
51
|
+
assert_no_file_exists('/tmp/sample_project/app/mailers/demo.rb')
|
49
52
|
end
|
50
53
|
end
|
51
|
-
end
|
54
|
+
end
|
@@ -102,8 +102,8 @@ class TestMigrationGenerator < Test::Unit::TestCase
|
|
102
102
|
response_success = silence_logger { generate(:migration, *migration_params) }
|
103
103
|
migration_file_path = "/tmp/sample_project/db/migrate/001_add_email_to_users.rb"
|
104
104
|
assert_match_in_file(/migration\s1.*?:add_email_to_users/m, migration_file_path)
|
105
|
-
assert_match_in_file(/modify_table :users.*?add_column :email, String/m, migration_file_path)
|
106
|
-
assert_match_in_file(/add_column :age, Integer/m, migration_file_path)
|
105
|
+
assert_match_in_file(/modify_table :users.*?add_column :email, DataMapper::Property::String/m, migration_file_path)
|
106
|
+
assert_match_in_file(/add_column :age, DataMapper::Property::Integer/m, migration_file_path)
|
107
107
|
assert_match_in_file(/modify_table :users.*?drop_column :email/m, migration_file_path)
|
108
108
|
assert_match_in_file(/drop_column :age/m, migration_file_path)
|
109
109
|
end
|
@@ -116,8 +116,8 @@ class TestMigrationGenerator < Test::Unit::TestCase
|
|
116
116
|
assert_match_in_file(/migration\s1.*?:remove_email_from_users/m, migration_file_path)
|
117
117
|
assert_match_in_file(/modify_table :users.*?drop_column :email/m, migration_file_path)
|
118
118
|
assert_match_in_file(/drop_column :age/m, migration_file_path)
|
119
|
-
assert_match_in_file(/modify_table :users.*?add_column :email, String/m, migration_file_path)
|
120
|
-
assert_match_in_file(/add_column :age, Integer/m, migration_file_path)
|
119
|
+
assert_match_in_file(/modify_table :users.*?add_column :email, DataMapper::Property::String/m, migration_file_path)
|
120
|
+
assert_match_in_file(/add_column :age, DataMapper::Property::Integer/m, migration_file_path)
|
121
121
|
end
|
122
122
|
|
123
123
|
should "properly version migration files" do
|
@@ -18,18 +18,40 @@ class TestModelGenerator < Test::Unit::TestCase
|
|
18
18
|
assert_file_exists('/tmp/sample_project/app/models/demo_item.rb')
|
19
19
|
end
|
20
20
|
|
21
|
+
should "fail if field name is not acceptable" do
|
22
|
+
silence_logger { generate(:project, 'sample_project', '--root=/tmp', '--script=none', '-t=bacon', '-d=couchrest') }
|
23
|
+
output = silence_logger { generate(:model, 'DemoItem', "re@l$ly:string","display-name:string", "age&year:datetime", "email_two:string", '-r=/tmp/sample_project') }
|
24
|
+
assert_match(/Invalid field name:/, output)
|
25
|
+
assert_match(/display-name:string/, output)
|
26
|
+
assert_match(/age&year:datetime/, output)
|
27
|
+
assert_match(/re@l\$ly:string/, output)
|
28
|
+
assert_no_match(/email_two:string/, output)
|
29
|
+
assert_no_match(/apply/, output)
|
30
|
+
assert_no_file_exists('/tmp/sample_project/app/models/demo_item.rb')
|
31
|
+
end
|
32
|
+
|
21
33
|
should "fail if we don't use an adapter" do
|
22
34
|
silence_logger { generate(:project, 'sample_project', '--root=/tmp', '--script=none', '-t=bacon') }
|
23
35
|
assert_raise(SystemExit) { silence_logger { generate(:model, 'user', '-r=/tmp/sample_project') } }
|
24
36
|
end
|
25
37
|
|
26
|
-
should
|
38
|
+
should "not fail if we don't have test component" do
|
27
39
|
silence_logger { generate(:project, 'sample_project', '--root=/tmp', '--test=none', '-d=activerecord') }
|
28
40
|
response_success = silence_logger { generate(:model, 'user', '-r=/tmp/sample_project') }
|
29
41
|
assert_match_in_file(/class User < ActiveRecord::Base/m, '/tmp/sample_project/app/models/user.rb')
|
30
42
|
assert_no_file_exists('/tmp/sample_project/test')
|
31
43
|
end
|
32
44
|
|
45
|
+
should "generate model in specified app" do
|
46
|
+
silence_logger { generate(:project, 'sample_project', '--root=/tmp', '-d=datamapper', '--script=none', '-t=bacon') }
|
47
|
+
silence_logger { generate(:app, 'subby', '-r=/tmp/sample_project') }
|
48
|
+
silence_logger { generate(:model, 'Post', "body:string", '-a=/subby', '-r=/tmp/sample_project') }
|
49
|
+
assert_match_in_file(/class Post\n\s+include DataMapper::Resource/m, '/tmp/sample_project/subby/models/post.rb')
|
50
|
+
assert_match_in_file(/property :body, String/m, '/tmp/sample_project/subby/models/post.rb')
|
51
|
+
assert_match_in_file(/migration 1, :create_posts do/m, "/tmp/sample_project/db/migrate/001_create_posts.rb")
|
52
|
+
assert_match_in_file(/gem 'data_mapper'/m,'/tmp/sample_project/Gemfile')
|
53
|
+
end
|
54
|
+
|
33
55
|
should "generate only generate model once" do
|
34
56
|
silence_logger { generate(:project, 'sample_project', '--root=/tmp', '--script=none', '-t=bacon', '-d=activerecord') }
|
35
57
|
response_success = silence_logger { generate(:model, 'user', '-r=/tmp/sample_project') }
|
@@ -109,7 +131,7 @@ class TestModelGenerator < Test::Unit::TestCase
|
|
109
131
|
should "generate gemfile gem" do
|
110
132
|
silence_logger { generate(:project, 'sample_project', '--root=/tmp', '--script=none', '-d=datamapper') }
|
111
133
|
silence_logger { generate(:model, 'user', "name:string", "age:integer", "created_at:datetime", '-r=/tmp/sample_project') }
|
112
|
-
assert_match_in_file(/gem '
|
134
|
+
assert_match_in_file(/gem 'data_mapper'/m,'/tmp/sample_project/Gemfile')
|
113
135
|
end
|
114
136
|
|
115
137
|
should "generate model file with fields" do
|
@@ -119,7 +141,6 @@ class TestModelGenerator < Test::Unit::TestCase
|
|
119
141
|
assert_match_in_file(/property :name, String/m, '/tmp/sample_project/app/models/user.rb')
|
120
142
|
assert_match_in_file(/property :age, Integer/m, '/tmp/sample_project/app/models/user.rb')
|
121
143
|
assert_match_in_file(/property :created_at, DateTime/m, '/tmp/sample_project/app/models/user.rb')
|
122
|
-
assert_match_in_file(/gem 'datamapper'/m,'/tmp/sample_project/Gemfile')
|
123
144
|
end
|
124
145
|
|
125
146
|
should "properly generate version numbers" do
|
@@ -138,14 +159,14 @@ class TestModelGenerator < Test::Unit::TestCase
|
|
138
159
|
should "generate migration with given fields" do
|
139
160
|
current_time = stop_time_for_test.strftime("%Y%m%d%H%M%S")
|
140
161
|
silence_logger { generate(:project, 'sample_project', '--root=/tmp', '--script=none', '-d=datamapper') }
|
141
|
-
silence_logger { generate(:model, 'person', "name:string", "created_at:
|
162
|
+
silence_logger { generate(:model, 'person', "name:string", "created_at:date_time", "email:string", '-r=/tmp/sample_project') }
|
142
163
|
assert_match_in_file(/class Person\n\s+include DataMapper::Resource/m, '/tmp/sample_project/app/models/person.rb')
|
143
164
|
migration_file_path = "/tmp/sample_project/db/migrate/001_create_people.rb"
|
144
165
|
assert_match_in_file(/migration 1, :create_people do/m, migration_file_path)
|
145
166
|
assert_match_in_file(/create_table :people do/m, migration_file_path)
|
146
|
-
assert_match_in_file(/column :name,
|
147
|
-
assert_match_in_file(/column :created_at,
|
148
|
-
assert_match_in_file(/column :email,
|
167
|
+
assert_match_in_file(/column :name, DataMapper::Property::String/m, migration_file_path)
|
168
|
+
assert_match_in_file(/column :created_at, DataMapper::Property::DateTime/m, migration_file_path)
|
169
|
+
assert_match_in_file(/column :email, DataMapper::Property::String/m, migration_file_path)
|
149
170
|
assert_match_in_file(/drop_table :people/m, migration_file_path)
|
150
171
|
end
|
151
172
|
end
|
@@ -227,8 +248,8 @@ class TestModelGenerator < Test::Unit::TestCase
|
|
227
248
|
silence_logger { generate(:project, 'sample_project', '--root=/tmp', '--script=none', '-t=riot', '-d=activerecord') }
|
228
249
|
silence_logger { generate(:model, 'SomeUser', '-r=/tmp/sample_project') }
|
229
250
|
assert_match_in_file(/context "SomeUser Model" do/m, '/tmp/sample_project/test/models/some_user_test.rb')
|
230
|
-
assert_match_in_file(
|
231
|
-
assert_match_in_file(/asserts\("that record is not nil"\) \{
|
251
|
+
assert_match_in_file(/SomeUser.new/m, '/tmp/sample_project/test/models/some_user_test.rb')
|
252
|
+
assert_match_in_file(/asserts\("that record is not nil"\) \{ \!topic.nil\? \}/m, '/tmp/sample_project/test/models/some_user_test.rb')
|
232
253
|
end
|
233
254
|
|
234
255
|
# RSPEC
|