padrino-gen 0.12.3 → 0.12.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/padrino-gen/generators/actions.rb +19 -1
- data/lib/padrino-gen/generators/app.rb +3 -2
- data/lib/padrino-gen/generators/component.rb +1 -1
- data/lib/padrino-gen/generators/components/actions.rb +9 -0
- data/lib/padrino-gen/generators/components/orms/activerecord.rb +12 -1
- data/lib/padrino-gen/generators/components/orms/minirecord.rb +12 -1
- data/lib/padrino-gen/generators/components/tests/bacon.rb +4 -4
- data/lib/padrino-gen/generators/components/tests/minitest.rb +4 -4
- data/lib/padrino-gen/generators/components/tests/riot.rb +4 -4
- data/lib/padrino-gen/generators/components/tests/rspec.rb +4 -4
- data/lib/padrino-gen/generators/components/tests/shoulda.rb +1 -1
- data/lib/padrino-gen/generators/components/tests/steak.rb +7 -7
- data/lib/padrino-gen/generators/controller.rb +13 -5
- data/lib/padrino-gen/generators/helper.rb +50 -0
- data/lib/padrino-gen/generators/project.rb +2 -2
- data/lib/padrino-gen/generators/runner.rb +2 -2
- data/lib/padrino-gen/padrino-tasks/sql-helpers.rb +2 -2
- data/lib/padrino-gen.rb +1 -1
- data/test/helper.rb +4 -4
- data/test/test_app_generator.rb +10 -0
- data/test/test_controller_generator.rb +40 -8
- data/test/test_generator.rb +1 -1
- data/test/test_helper_generator.rb +133 -0
- data/test/test_model_generator.rb +5 -3
- data/test/test_project_generator.rb +7 -0
- metadata +11 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 43525aa97d6393ef5a26c11c10175e364614e93f
|
4
|
+
data.tar.gz: 1a4b6ba46e45b2addcb9db5b191f552ab9dc8a89
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 85ee1b0c4113edfdb9498d969a03a713becd206a77908f086795397b3b23f489c7cd221fb91b1823867b35a6975551fb1117267a33330bb72f65857a7336ad23
|
7
|
+
data.tar.gz: cb407d264809b4856bfee6a0780865ba24c3926201418ba4e0aa3ef75e5713a985e4a7c8e74f48a5793d03418321b8ad8fc778aeb4ee521269acabeb1e1ced03
|
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'pathname'
|
2
|
+
|
1
3
|
module Padrino
|
2
4
|
module Generators
|
3
5
|
# Raised when an application does not have a resolved root path.
|
@@ -17,7 +19,7 @@ module Padrino
|
|
17
19
|
# Avoids editing destination file if it does not exist.
|
18
20
|
#
|
19
21
|
def inject_into_file(destination, *args, &block)
|
20
|
-
destination_path = destination.
|
22
|
+
destination_path = Pathname.new(destination).absolute? ? destination : destination_root(destination)
|
21
23
|
return unless File.exist?(destination_path)
|
22
24
|
super
|
23
25
|
end
|
@@ -380,6 +382,22 @@ WARNING
|
|
380
382
|
template "templates/initializer.rb.tt", destination_root("/lib/#{name}_initializer.rb") if data.present?
|
381
383
|
end
|
382
384
|
|
385
|
+
##
|
386
|
+
# Creates and inserts middleware.
|
387
|
+
# @param [Symbol, String] name
|
388
|
+
# Name of the middleware.
|
389
|
+
# @param [String] source
|
390
|
+
# Text to generate into the middleware file.
|
391
|
+
#
|
392
|
+
# @example
|
393
|
+
# middleware(:hello, "class Hello\nend")
|
394
|
+
# #=> generates 'lib/hello_middleware.rb'
|
395
|
+
#
|
396
|
+
def middleware(name, source)
|
397
|
+
create_file destination_root("lib/#{name}_middleware.rb"), source
|
398
|
+
insert_middleware name.to_s.underscore.camelize
|
399
|
+
end
|
400
|
+
|
383
401
|
##
|
384
402
|
# Insert the regired gem and add in boot.rb custom contribs.
|
385
403
|
#
|
@@ -31,8 +31,9 @@ module Padrino
|
|
31
31
|
#
|
32
32
|
def create_app
|
33
33
|
self.destination_root = options[:root]
|
34
|
-
|
35
|
-
@
|
34
|
+
underscore_name = name.gsub(/\W/, '_')
|
35
|
+
@app_folder = underscore_name.underscore
|
36
|
+
@app_name = underscore_name.camelize
|
36
37
|
if in_app_root?
|
37
38
|
@project_name = options[:namespace].underscore.camelize
|
38
39
|
@project_name = fetch_project_name(@app_folder) if @project_name.empty?
|
@@ -30,7 +30,7 @@ module Padrino
|
|
30
30
|
self.destination_root = options[:root]
|
31
31
|
if in_app_root?
|
32
32
|
@_components = options.dup.slice(*self.class.component_types)
|
33
|
-
@app_name = (options[:app] || "App").gsub(/\W/, '_').
|
33
|
+
@app_name = (options[:app] || "App").gsub(/\W/, '_').camelize
|
34
34
|
if @_components.values.delete_if(&:blank?).empty?
|
35
35
|
self.class.start(["-h"])
|
36
36
|
say
|
@@ -193,6 +193,15 @@ module Padrino
|
|
193
193
|
end
|
194
194
|
action_declarations.join("\n").gsub(/^/, " " * 2).gsub(/^\s*$/, "")
|
195
195
|
end
|
196
|
+
|
197
|
+
def create_helper_files(app, name)
|
198
|
+
@helper_name = "#{name.to_s.underscore.camelize}Helper"
|
199
|
+
template 'templates/helper.rb.tt', destination_root(app, 'helpers', "#{name.to_s.underscore}_helper.rb")
|
200
|
+
if test?
|
201
|
+
include_component_module_for(:test)
|
202
|
+
generate_helper_test(@helper_name, @project_name, @app_name)
|
203
|
+
end
|
204
|
+
end
|
196
205
|
end
|
197
206
|
end
|
198
207
|
end
|
@@ -96,6 +96,17 @@ SQLITE = (<<-SQLITE) unless defined?(SQLITE)
|
|
96
96
|
:database => !DB_NAME!
|
97
97
|
SQLITE
|
98
98
|
|
99
|
+
CONNECTION_POOL_MIDDLEWARE = <<-MIDDLEWARE
|
100
|
+
class ConnectionPoolManagement
|
101
|
+
def initialize(app)
|
102
|
+
@app = app
|
103
|
+
end
|
104
|
+
|
105
|
+
def call(env)
|
106
|
+
ActiveRecord::Base.connection_pool.with_connection { @app.call(env) }
|
107
|
+
end
|
108
|
+
end
|
109
|
+
MIDDLEWARE
|
99
110
|
|
100
111
|
def setup_orm
|
101
112
|
ar = AR
|
@@ -124,8 +135,8 @@ def setup_orm
|
|
124
135
|
require_dependencies 'sqlite3'
|
125
136
|
end
|
126
137
|
require_dependencies 'activerecord', :require => 'active_record', :version => ">= 3.1"
|
127
|
-
insert_middleware 'ActiveRecord::ConnectionAdapters::ConnectionManagement'
|
128
138
|
create_file("config/database.rb", ar)
|
139
|
+
middleware :connection_pool_management, CONNECTION_POOL_MIDDLEWARE
|
129
140
|
end
|
130
141
|
|
131
142
|
AR_MODEL = (<<-MODEL) unless defined?(AR_MODEL)
|
@@ -96,6 +96,17 @@ SQLITE = (<<-SQLITE) unless defined?(SQLITE)
|
|
96
96
|
:database => !DB_NAME!
|
97
97
|
SQLITE
|
98
98
|
|
99
|
+
CONNECTION_POOL_MIDDLEWARE = <<-MIDDLEWARE
|
100
|
+
class ConnectionPoolManagement
|
101
|
+
def initialize(app)
|
102
|
+
@app = app
|
103
|
+
end
|
104
|
+
|
105
|
+
def call(env)
|
106
|
+
ActiveRecord::Base.connection_pool.with_connection { @app.call(env) }
|
107
|
+
end
|
108
|
+
end
|
109
|
+
MIDDLEWARE
|
99
110
|
|
100
111
|
def setup_orm
|
101
112
|
ar = MR
|
@@ -125,7 +136,7 @@ def setup_orm
|
|
125
136
|
require_dependencies 'mini_record'
|
126
137
|
create_file('config/database.rb', ar)
|
127
138
|
insert_hook('ActiveRecord::Base.auto_upgrade!', :after_load)
|
128
|
-
|
139
|
+
middleware :connection_pool_management, CONNECTION_POOL_MIDDLEWARE
|
129
140
|
end
|
130
141
|
|
131
142
|
MR_MODEL = (<<-MODEL) unless defined?(MR_MODEL)
|
@@ -25,9 +25,9 @@ TEST
|
|
25
25
|
BACON_CONTROLLER_TEST = (<<-TEST).gsub(/^ {10}/, '') unless defined?(BACON_CONTROLLER_TEST)
|
26
26
|
require File.expand_path(File.dirname(__FILE__) + '/../../test_config.rb')
|
27
27
|
|
28
|
-
describe "!
|
28
|
+
describe "!PATH!" do
|
29
29
|
it 'returns text at root' do
|
30
|
-
get "
|
30
|
+
get "!EXPANDED_PATH!"
|
31
31
|
last_response.body.should == "some text"
|
32
32
|
end
|
33
33
|
end
|
@@ -82,8 +82,8 @@ def setup_test
|
|
82
82
|
create_file destination_root("test/test.rake"), BACON_RAKE
|
83
83
|
end
|
84
84
|
|
85
|
-
def generate_controller_test(name)
|
86
|
-
bacon_contents = BACON_CONTROLLER_TEST.gsub(/!
|
85
|
+
def generate_controller_test(name, path)
|
86
|
+
bacon_contents = BACON_CONTROLLER_TEST.gsub(/!PATH!/, path).gsub(/!EXPANDED_PATH!/, path.gsub(/:\w+?_id/, "1"))
|
87
87
|
controller_test_path = File.join('test',options[:app],'controllers',"#{name.to_s.underscore}_controller_test.rb")
|
88
88
|
create_file destination_root(controller_test_path), bacon_contents, :skip => true
|
89
89
|
end
|
@@ -41,9 +41,9 @@ TEST
|
|
41
41
|
MINITEST_CONTROLLER_TEST = (<<-TEST).gsub(/^ {10}/, '') unless defined?(MINITEST_CONTROLLER_TEST)
|
42
42
|
require File.expand_path(File.dirname(__FILE__) + '/../../test_config.rb')
|
43
43
|
|
44
|
-
describe "!
|
44
|
+
describe "!PATH!" do
|
45
45
|
before do
|
46
|
-
get
|
46
|
+
get "!EXPANDED_PATH!"
|
47
47
|
end
|
48
48
|
|
49
49
|
it "should return hello world text" do
|
@@ -89,8 +89,8 @@ def setup_test
|
|
89
89
|
create_file destination_root("test/test.rake"), MINITEST_RAKE
|
90
90
|
end
|
91
91
|
|
92
|
-
def generate_controller_test(name)
|
93
|
-
minitest_contents = MINITEST_CONTROLLER_TEST.gsub(/!
|
92
|
+
def generate_controller_test(name, path)
|
93
|
+
minitest_contents = MINITEST_CONTROLLER_TEST.gsub(/!PATH!/, path).gsub(/!EXPANDED_PATH!/, path.gsub(/:\w+?_id/, "1"))
|
94
94
|
controller_test_path = File.join('test',options[:app],'controllers',"#{name.to_s.underscore}_controller_test.rb")
|
95
95
|
create_file destination_root(controller_test_path), minitest_contents, :skip => true
|
96
96
|
end
|
@@ -34,10 +34,10 @@ TEST
|
|
34
34
|
RIOT_CONTROLLER_TEST = (<<-TEST).gsub(/^ {10}/, '') unless defined?(RIOT_CONTROLLER_TEST)
|
35
35
|
require File.expand_path(File.dirname(__FILE__) + '/../../test_config.rb')
|
36
36
|
|
37
|
-
context "!
|
37
|
+
context "!PATH!" do
|
38
38
|
context "description here" do
|
39
39
|
setup do
|
40
|
-
get "
|
40
|
+
get "!EXPANDED_PATH!"
|
41
41
|
end
|
42
42
|
|
43
43
|
asserts("the response body") { last_response.body }.equals "Hello World"
|
@@ -96,8 +96,8 @@ def setup_test
|
|
96
96
|
create_file destination_root("test/test.rake"), RIOT_RAKE
|
97
97
|
end
|
98
98
|
|
99
|
-
def generate_controller_test(name)
|
100
|
-
riot_contents = RIOT_CONTROLLER_TEST.gsub(/!
|
99
|
+
def generate_controller_test(name, path)
|
100
|
+
riot_contents = RIOT_CONTROLLER_TEST.gsub(/!PATH!/, path).gsub(/!EXPANDED_PATH!/, path.gsub(/:\w+?_id/, "1"))
|
101
101
|
controller_test_path = File.join('test',options[:app],'controllers',"#{name.to_s.underscore}_controller_test.rb")
|
102
102
|
create_file destination_root(controller_test_path), riot_contents, :skip => true
|
103
103
|
end
|
@@ -25,10 +25,10 @@ TEST
|
|
25
25
|
RSPEC_CONTROLLER_TEST = (<<-TEST).gsub(/^ {12}/, '') unless defined?(RSPEC_CONTROLLER_TEST)
|
26
26
|
require 'spec_helper'
|
27
27
|
|
28
|
-
RSpec.describe "!
|
28
|
+
RSpec.describe "!PATH!" do
|
29
29
|
pending "add some examples to \#{__FILE__}" do
|
30
30
|
before do
|
31
|
-
get "
|
31
|
+
get "!EXPANDED_PATH!"
|
32
32
|
end
|
33
33
|
|
34
34
|
it "returns hello world" do
|
@@ -92,8 +92,8 @@ def setup_test
|
|
92
92
|
create_file destination_root("spec/spec.rake"), RSPEC_RAKE
|
93
93
|
end
|
94
94
|
|
95
|
-
def generate_controller_test(name)
|
96
|
-
rspec_contents = RSPEC_CONTROLLER_TEST.gsub(/!
|
95
|
+
def generate_controller_test(name, path)
|
96
|
+
rspec_contents = RSPEC_CONTROLLER_TEST.gsub(/!PATH!/, path).gsub(/!EXPANDED_PATH!/, path.gsub(/:\w+?_id/, "1"))
|
97
97
|
controller_spec_path = File.join('spec',options[:app],'controllers',"#{name.to_s.underscore}_controller_spec.rb")
|
98
98
|
create_file destination_root(controller_spec_path), rspec_contents, :skip => true
|
99
99
|
end
|
@@ -93,7 +93,7 @@ def setup_test
|
|
93
93
|
create_file destination_root("test/test.rake"), SHOULDA_RAKE
|
94
94
|
end
|
95
95
|
|
96
|
-
def generate_controller_test(name)
|
96
|
+
def generate_controller_test(name, path = nil)
|
97
97
|
shoulda_contents = SHOULDA_CONTROLLER_TEST.gsub(/!NAME!/, name.to_s.underscore.camelize)
|
98
98
|
controller_test_path = File.join('test',options[:app],'controllers',"#{name.to_s.underscore}_controller_test.rb")
|
99
99
|
create_file destination_root(controller_test_path), shoulda_contents, :skip => true
|
@@ -21,9 +21,9 @@ TEST
|
|
21
21
|
STEAK_CONTROLLER_TEST = (<<-TEST).gsub(/^ {12}/, '') unless defined?(STEAK_CONTROLLER_TEST)
|
22
22
|
require 'spec_helper'
|
23
23
|
|
24
|
-
describe "!
|
24
|
+
describe "!PATH!" do
|
25
25
|
before do
|
26
|
-
get "
|
26
|
+
get "!EXPANDED_PATH!"
|
27
27
|
end
|
28
28
|
|
29
29
|
it "returns hello world" do
|
@@ -35,9 +35,9 @@ TEST
|
|
35
35
|
STEAK_CONTROLLER_ACCEPTANCE_TEST = (<<-TEST).gsub(/^ {12}/, '') unless defined?(STEAK_CONTROLLER_ACCEPTANCE_TEST)
|
36
36
|
require 'spec_helper'
|
37
37
|
|
38
|
-
feature "!
|
38
|
+
feature "!PATH!" do
|
39
39
|
background do
|
40
|
-
visit "
|
40
|
+
visit "!EXPANDED_PATH!"
|
41
41
|
end
|
42
42
|
|
43
43
|
scenario "returns hello world" do
|
@@ -91,12 +91,12 @@ def setup_test
|
|
91
91
|
end
|
92
92
|
|
93
93
|
# Generates a controller test given the controllers name
|
94
|
-
def generate_controller_test(name)
|
95
|
-
spec_contents = STEAK_CONTROLLER_TEST.gsub(/!
|
94
|
+
def generate_controller_test(name, path)
|
95
|
+
spec_contents = STEAK_CONTROLLER_TEST.gsub(/!PATH!/, path).gsub(/!EXPANDED_PATH!/, path.gsub(/:\w+?_id/, "1"))
|
96
96
|
controller_spec_path = File.join('spec',options[:app],'controllers',"#{name.to_s.underscore}_controller_spec.rb")
|
97
97
|
create_file destination_root(controller_spec_path), spec_contents, :skip => true
|
98
98
|
|
99
|
-
acceptance_contents = STEAK_CONTROLLER_ACCEPTANCE_TEST.gsub(/!
|
99
|
+
acceptance_contents = STEAK_CONTROLLER_ACCEPTANCE_TEST.gsub(/!PATH!/, path).gsub(/!EXPANDED_PATH!/, path.gsub(/:\w+?_id/, "1"))
|
100
100
|
controller_acceptance_path = File.join('spec',options[:app],'acceptance','controllers',"#{name.to_s.underscore}_controller_spec.rb")
|
101
101
|
create_file destination_root(controller_acceptance_path), acceptance_contents, :skip => true
|
102
102
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'padrino-core/application' unless defined?(Padrino::Application)
|
2
|
+
|
1
3
|
module Padrino
|
2
4
|
module Generators
|
3
5
|
##
|
@@ -43,7 +45,6 @@ module Padrino
|
|
43
45
|
@app_name = fetch_app_name(app)
|
44
46
|
@actions = controller_actions(fields)
|
45
47
|
@controller = name.to_s.underscore
|
46
|
-
@helper_name = "#{@controller.camelize}Helper"
|
47
48
|
@layout = options[:layout] if options[:layout] && !options[:layout].empty?
|
48
49
|
|
49
50
|
block_opts = []
|
@@ -53,13 +54,20 @@ module Padrino
|
|
53
54
|
|
54
55
|
self.behavior = :revoke if options[:destroy]
|
55
56
|
template 'templates/controller.rb.tt', destination_root(app, 'controllers', "#{name.to_s.underscore}.rb")
|
56
|
-
template 'templates/helper.rb.tt', destination_root(app, 'helpers', "#{name.to_s.underscore}_helper.rb") unless options[:'no-helper']
|
57
57
|
empty_directory destination_root(app, "/views/#{name.to_s.underscore}")
|
58
|
-
|
58
|
+
|
59
59
|
if test?
|
60
|
-
|
61
|
-
|
60
|
+
include_component_module_for(:test)
|
61
|
+
path = @controller
|
62
|
+
|
63
|
+
if options[:parent] && !options[:parent].empty?
|
64
|
+
path = Application.process_path_for_parent_params(path, [options[:parent]]).prepend("/")
|
65
|
+
end
|
66
|
+
path.prepend("/") unless path.start_with?("/")
|
67
|
+
generate_controller_test(name, path)
|
62
68
|
end
|
69
|
+
|
70
|
+
create_helper_files(app, name) unless options[:'no-helper']
|
63
71
|
else
|
64
72
|
say 'You are not at the root of a Padrino application! (config/boot.rb not found)'
|
65
73
|
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
module Padrino
|
2
|
+
module Generators
|
3
|
+
##
|
4
|
+
# Responsible for generating route helpers and associated tests within a Padrino application.
|
5
|
+
#
|
6
|
+
class Helper < Thor::Group
|
7
|
+
|
8
|
+
Padrino::Generators.add_generator(:helper, self)
|
9
|
+
|
10
|
+
def self.source_root; File.expand_path(File.dirname(__FILE__)); end
|
11
|
+
def self.banner; "padrino-gen helper [name]"; end
|
12
|
+
|
13
|
+
include Thor::Actions
|
14
|
+
include Padrino::Generators::Actions
|
15
|
+
include Padrino::Generators::Components::Actions
|
16
|
+
|
17
|
+
desc "Description:\n\n\tpadrino-gen helper generates a new Padrino helper"
|
18
|
+
|
19
|
+
argument :name, :desc => 'The name of your padrino helper'
|
20
|
+
argument :fields, :desc => 'The fields for the helper', :default => [], :type => :array
|
21
|
+
class_option :root, :desc => 'The root destination', :aliases => '-r', :default => '.', :type => :string
|
22
|
+
class_option :app, :desc => 'The application destination path', :aliases => '-a', :default => '/app', :type => :string
|
23
|
+
class_option :destroy, :aliases => '-d', :default => false, :type => :boolean
|
24
|
+
class_option :namespace, :desc => 'The name space of your padrino project', :aliases => '-n', :default => '', :type => :string
|
25
|
+
|
26
|
+
# Show help if no ARGV given
|
27
|
+
require_arguments!
|
28
|
+
|
29
|
+
##
|
30
|
+
# Execute helper generation
|
31
|
+
#
|
32
|
+
def create_helper
|
33
|
+
self.destination_root = options[:root]
|
34
|
+
if in_app_root?
|
35
|
+
app = options[:app]
|
36
|
+
check_app_existence(app)
|
37
|
+
@project_name = options[:namespace].underscore.camelize
|
38
|
+
@project_name = fetch_project_name(app) if @project_name.empty?
|
39
|
+
@app_name = fetch_app_name(app)
|
40
|
+
|
41
|
+
self.behavior = :revoke if options[:destroy]
|
42
|
+
|
43
|
+
create_helper_files(app, name)
|
44
|
+
else
|
45
|
+
say 'You are not at the root of a Padrino application! (config/boot.rb not found)'
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -46,7 +46,7 @@ module Padrino
|
|
46
46
|
app = (options[:app] || "App")
|
47
47
|
|
48
48
|
@project_name = name.gsub(/\W/, '_').underscore.camelize
|
49
|
-
@app_name = app.gsub(/\W/, '_').
|
49
|
+
@app_name = app.gsub(/\W/, '_').camelize
|
50
50
|
self.destination_root = File.join(options[:root], name)
|
51
51
|
if options[:template]
|
52
52
|
execute_runner(:template, options[:template])
|
@@ -103,7 +103,7 @@ module Padrino
|
|
103
103
|
helper_template_name = "#{uppercase_test_component}_HELPER_TEST"
|
104
104
|
return unless defined?(controller_template_name)
|
105
105
|
|
106
|
-
controller_content = instance_eval(controller_template_name).gsub(/!NAME!/, "")
|
106
|
+
controller_content = instance_eval(controller_template_name).gsub(/!PATH!/, "Controller").gsub(/!NAME!/, "").gsub(/!EXPANDED_PATH!/, "/")
|
107
107
|
helper_content = instance_eval(helper_template_name).gsub(/!NAME!/, "#{@project_name}::#{@app_name}::#{DEFAULT_HELPER_NAME}")
|
108
108
|
|
109
109
|
proc{|*args| args.map{|str| str.gsub!(/!PATH!/, recognize_path)} }.call(controller_content, helper_content)
|
@@ -70,12 +70,12 @@ module Padrino
|
|
70
70
|
# generate :model, "posts title:string" # generate a model inside of subapp
|
71
71
|
# end
|
72
72
|
#
|
73
|
-
def app(name
|
73
|
+
def app(name)
|
74
74
|
say "=> Executing: padrino-gen app #{name} -r=#{destination_root}", :magenta
|
75
75
|
Padrino.bin_gen(:app, name.to_s, "-r=#{destination_root}")
|
76
76
|
if block_given?
|
77
77
|
@_app_name = name
|
78
|
-
|
78
|
+
yield
|
79
79
|
@_app_name = nil
|
80
80
|
end
|
81
81
|
end
|
@@ -16,7 +16,7 @@ module Padrino
|
|
16
16
|
arguments << database
|
17
17
|
|
18
18
|
Process.wait Process.spawn(environment, 'createdb', *arguments)
|
19
|
-
when 'mysql'
|
19
|
+
when 'mysql', 'mysql2'
|
20
20
|
environment = {}
|
21
21
|
environment['MYSQL_PWD'] = password unless password.blank?
|
22
22
|
|
@@ -49,7 +49,7 @@ module Padrino
|
|
49
49
|
arguments << database
|
50
50
|
|
51
51
|
Process.wait Process.spawn(environment, 'dropdb', *arguments)
|
52
|
-
when 'mysql'
|
52
|
+
when 'mysql', 'mysql2'
|
53
53
|
environment = {}
|
54
54
|
environment['MYSQL_PWD'] = password unless password.blank?
|
55
55
|
|
data/lib/padrino-gen.rb
CHANGED
@@ -67,7 +67,7 @@ module Padrino
|
|
67
67
|
end
|
68
68
|
|
69
69
|
# Add our generators to Padrino::Generators.
|
70
|
-
Padrino::Generators.load_paths << Dir[File.dirname(__FILE__) + '/padrino-gen/generators/{project,app,mailer,controller,model,migration,plugin,component,task}.rb']
|
70
|
+
Padrino::Generators.load_paths << Dir[File.dirname(__FILE__) + '/padrino-gen/generators/{project,app,mailer,controller,helper,model,migration,plugin,component,task}.rb']
|
71
71
|
|
72
72
|
# Add our tasks to padrino-core.
|
73
73
|
Padrino::Tasks.files << Dir[File.dirname(__FILE__) + "/padrino-gen/padrino-tasks/**/*.rb"]
|
data/test/helper.rb
CHANGED
@@ -56,8 +56,8 @@ class MiniTest::Spec
|
|
56
56
|
|
57
57
|
# assert_has_tag(:h1, :content => "yellow") { "<h1>yellow</h1>" }
|
58
58
|
# In this case, block is the html to evaluate
|
59
|
-
def assert_has_tag(name, attributes = {}
|
60
|
-
html =
|
59
|
+
def assert_has_tag(name, attributes = {})
|
60
|
+
html = yield if block_given?
|
61
61
|
matcher = HaveSelector.new(name, attributes)
|
62
62
|
raise "Please specify a block!" if html.blank?
|
63
63
|
assert matcher.matches?(html), matcher.failure_message
|
@@ -65,8 +65,8 @@ class MiniTest::Spec
|
|
65
65
|
|
66
66
|
# assert_has_no_tag, tag(:h1, :content => "yellow") { "<h1>green</h1>" }
|
67
67
|
# In this case, block is the html to evaluate
|
68
|
-
def assert_has_no_tag(name, attributes = {}
|
69
|
-
html =
|
68
|
+
def assert_has_no_tag(name, attributes = {})
|
69
|
+
html = yield if block_given?
|
70
70
|
attributes.merge!(:count => 0)
|
71
71
|
matcher = HaveSelector.new(name, attributes)
|
72
72
|
raise "Please specify a block!" if html.blank?
|
data/test/test_app_generator.rb
CHANGED
@@ -128,5 +128,15 @@ describe "AppGenerator" do
|
|
128
128
|
assert_dir_exists("#{@apptmp}/sample_project/kernel/helpers")
|
129
129
|
assert_file_exists("#{@apptmp}/sample_project/kernel/app.rb")
|
130
130
|
end
|
131
|
+
|
132
|
+
it 'should allow to pass upcased name as the app name' do
|
133
|
+
capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}") }
|
134
|
+
out, err = capture_io { generate(:app, 'API', "--root=#{@apptmp}/sample_project", "--force") }
|
135
|
+
assert_dir_exists("#{@apptmp}/sample_project/public/api")
|
136
|
+
assert_dir_exists("#{@apptmp}/sample_project/api/controllers")
|
137
|
+
assert_dir_exists("#{@apptmp}/sample_project/api/helpers")
|
138
|
+
assert_file_exists("#{@apptmp}/sample_project/api/app.rb")
|
139
|
+
assert_match_in_file(/class API < Padrino::Application/, "#{@apptmp}/sample_project/api/app.rb")
|
140
|
+
end
|
131
141
|
end
|
132
142
|
end
|
@@ -6,6 +6,7 @@ describe "ControllerGenerator" do
|
|
6
6
|
`mkdir -p #{@apptmp}`
|
7
7
|
@controller_path = "#{@apptmp}/sample_project/app/controllers/demo_items.rb"
|
8
8
|
@controller_test_path = "#{@apptmp}/sample_project/test/app/controllers/demo_items_controller_test.rb"
|
9
|
+
@controller_with_parent_test_path = "#{@apptmp}/sample_project/test/app/controllers/user_items_controller_test.rb"
|
9
10
|
@helper_path = "#{@apptmp}/sample_project/app/helpers/demo_items_helper.rb"
|
10
11
|
@helper_test_path = "#{@apptmp}/sample_project/test/app/helpers/demo_items_helper_test.rb"
|
11
12
|
end
|
@@ -56,7 +57,8 @@ describe "ControllerGenerator" do
|
|
56
57
|
assert_match_in_file(/SampleProject::Subby.controllers :demo_items do/m, @controller_path.gsub('app','subby'))
|
57
58
|
assert_match_in_file(/helpers DemoItemsHelper/m, "#{@apptmp}/sample_project/subby/helpers/demo_items_helper.rb")
|
58
59
|
assert_file_exists("#{@apptmp}/sample_project/subby/views/demo_items")
|
59
|
-
assert_match_in_file(/describe "
|
60
|
+
assert_match_in_file(/describe "\/demo_items" do/m, @controller_test_path.gsub('app','subby'))
|
61
|
+
assert_match_in_file(/get "\/demo_items"/m, @controller_test_path.gsub('app','subby'))
|
60
62
|
end
|
61
63
|
|
62
64
|
it 'should generate controller with specified layout' do
|
@@ -75,6 +77,8 @@ describe "ControllerGenerator" do
|
|
75
77
|
capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=bacon') }
|
76
78
|
capture_io { generate(:controller, 'DemoItems', "-r=#{@apptmp}/sample_project", '-p=user') }
|
77
79
|
assert_match_in_file(/SampleProject::App.controllers :demo_items, :parent => :user do/m, @controller_path)
|
80
|
+
assert_match_in_file(/describe "\/user\/:user_id\/demo_items" do/, @controller_test_path)
|
81
|
+
assert_match_in_file(/get "\/user\/1\/demo_items"/, @controller_test_path)
|
78
82
|
end
|
79
83
|
|
80
84
|
it 'should generate controller without specified parent' do
|
@@ -108,8 +112,12 @@ describe "ControllerGenerator" do
|
|
108
112
|
capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=bacon') }
|
109
113
|
capture_io { generate(:app, 'subby', "-r=#{@apptmp}/sample_project") }
|
110
114
|
capture_io { generate(:controller, 'DemoItems','-a=/subby', "-r=#{@apptmp}/sample_project") }
|
115
|
+
capture_io { generate(:controller, 'UserItems','-a=/subby', "-r=#{@apptmp}/sample_project", "-p=user") }
|
111
116
|
assert_match_in_file(/(\/\.\.){2}/m, @controller_test_path.gsub('app','subby'))
|
112
|
-
assert_match_in_file(/describe "
|
117
|
+
assert_match_in_file(/describe "\/demo_items" do/m, @controller_test_path.gsub('app','subby'))
|
118
|
+
assert_match_in_file(/describe "\/user\/:user_id\/user_items"/, @controller_with_parent_test_path.gsub('app','subby'))
|
119
|
+
assert_match_in_file(/get "\/demo_items"/m, @controller_test_path.gsub('app','subby'))
|
120
|
+
assert_match_in_file(/get "\/user\/1\/user_items"/m, @controller_with_parent_test_path.gsub('app','subby'))
|
113
121
|
assert_match_in_file(/describe "SampleProject::Subby::DemoItemsHelper" do/m, @helper_test_path.gsub('app','subby'))
|
114
122
|
end
|
115
123
|
|
@@ -117,8 +125,12 @@ describe "ControllerGenerator" do
|
|
117
125
|
capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=riot') }
|
118
126
|
capture_io { generate(:app, 'subby', "-r=#{@apptmp}/sample_project") }
|
119
127
|
capture_io { generate(:controller, 'DemoItems','-a=/subby', "-r=#{@apptmp}/sample_project") }
|
128
|
+
capture_io { generate(:controller, 'UserItems','-a=/subby', "-r=#{@apptmp}/sample_project", "-p=user") }
|
120
129
|
assert_match_in_file(/(\/\.\.){2}/m, @controller_test_path.gsub('app','subby'))
|
121
|
-
assert_match_in_file(/context "
|
130
|
+
assert_match_in_file(/context "\/demo_items" do/m, @controller_test_path.gsub('app','subby'))
|
131
|
+
assert_match_in_file(/context "\/user\/:user_id\/user_items"/, @controller_with_parent_test_path.gsub('app','subby'))
|
132
|
+
assert_match_in_file(/get "\/demo_items"/m, @controller_test_path.gsub('app','subby'))
|
133
|
+
assert_match_in_file(/get "\/user\/1\/user_items"/m, @controller_with_parent_test_path.gsub('app','subby'))
|
122
134
|
assert_match_in_file(/describe "SampleProject::Subby::DemoItemsHelper" do/m, @helper_test_path.gsub('app','subby'))
|
123
135
|
end
|
124
136
|
|
@@ -126,8 +138,12 @@ describe "ControllerGenerator" do
|
|
126
138
|
capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=minitest') }
|
127
139
|
capture_io { generate(:app, 'subby', "-r=#{@apptmp}/sample_project") }
|
128
140
|
capture_io { generate(:controller, 'DemoItems','-a=/subby', "-r=#{@apptmp}/sample_project") }
|
141
|
+
capture_io { generate(:controller, 'UserItems','-a=/subby', "-r=#{@apptmp}/sample_project", "-p=user") }
|
129
142
|
assert_match_in_file(/(\/\.\.){2}/m, @controller_test_path.gsub('app', 'subby'))
|
130
|
-
assert_match_in_file(/describe "
|
143
|
+
assert_match_in_file(/describe "\/demo_items" do/m, @controller_test_path.gsub('app', 'subby'))
|
144
|
+
assert_match_in_file(/describe "\/user\/:user_id\/user_items"/, @controller_with_parent_test_path.gsub('app','subby'))
|
145
|
+
assert_match_in_file(/get "\/demo_items"/m, @controller_test_path.gsub('app','subby'))
|
146
|
+
assert_match_in_file(/get "\/user\/1\/user_items"/m, @controller_with_parent_test_path.gsub('app','subby'))
|
131
147
|
assert_match_in_file(/describe "SampleProject::Subby::DemoItemsHelper" do/m, @helper_test_path.gsub('app','subby'))
|
132
148
|
end
|
133
149
|
|
@@ -135,7 +151,11 @@ describe "ControllerGenerator" do
|
|
135
151
|
capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=rspec') }
|
136
152
|
capture_io { generate(:app, 'subby', "-r=#{@apptmp}/sample_project") }
|
137
153
|
capture_io { generate(:controller, 'DemoItems','-a=/subby', "-r=#{@apptmp}/sample_project") }
|
138
|
-
|
154
|
+
capture_io { generate(:controller, 'UserItems','-a=/subby', "-r=#{@apptmp}/sample_project", "-p=user") }
|
155
|
+
assert_match_in_file(/describe "\/demo_items" do/m, "#{@apptmp}/sample_project/spec/subby/controllers/demo_items_controller_spec.rb")
|
156
|
+
assert_match_in_file(/describe "\/user\/:user_id\/user_items"/,"#{@apptmp}/sample_project/spec/subby/controllers/user_items_controller_spec.rb")
|
157
|
+
assert_match_in_file(/get "\/demo_items"/m, "#{@apptmp}/sample_project/spec/subby/controllers/demo_items_controller_spec.rb")
|
158
|
+
assert_match_in_file(/get "\/user\/1\/user_items"/m, "#{@apptmp}/sample_project/spec/subby/controllers/user_items_controller_spec.rb")
|
139
159
|
assert_match_in_file(/describe "SampleProject::Subby::DemoItemsHelper" do/m, "#{@apptmp}/sample_project/spec/subby/helpers/demo_items_helper_spec.rb")
|
140
160
|
end
|
141
161
|
|
@@ -143,9 +163,12 @@ describe "ControllerGenerator" do
|
|
143
163
|
capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=shoulda') }
|
144
164
|
capture_io { generate(:app, 'subby', "-r=#{@apptmp}/sample_project") }
|
145
165
|
capture_io { generate(:controller, 'DemoItems','-a=/subby', "-r=#{@apptmp}/sample_project") }
|
166
|
+
capture_io { generate(:controller, 'UserItems','-a=/subby', "-r=#{@apptmp}/sample_project", "-p=user") }
|
146
167
|
expected_pattern = /class DemoItemsControllerTest < Test::Unit::TestCase/m
|
168
|
+
expected_pattern2 = /class UserItemsControllerTest < Test::Unit::TestCase/m
|
147
169
|
assert_match_in_file(expected_pattern, @controller_test_path.gsub('app','subby'))
|
148
170
|
assert_match_in_file(/(\/\.\.){2}/m, @controller_test_path.gsub('app','subby'))
|
171
|
+
assert_match_in_file(expected_pattern2, @controller_with_parent_test_path.gsub('app','subby'))
|
149
172
|
assert_match_in_file(/context "SampleProject::Subby::DemoItemsHelper" do/m, @helper_test_path.gsub('app','subby'))
|
150
173
|
assert_file_exists(@helper_test_path.gsub('app','subby'))
|
151
174
|
assert_file_exists("#{@apptmp}/sample_project/test/subby/helpers/demo_items_helper_test.rb")
|
@@ -155,8 +178,13 @@ describe "ControllerGenerator" do
|
|
155
178
|
capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=steak') }
|
156
179
|
capture_io { generate(:app, 'subby', "-r=#{@apptmp}/sample_project") }
|
157
180
|
capture_io { generate(:controller, 'DemoItems','-a=/subby', "-r=#{@apptmp}/sample_project") }
|
158
|
-
|
159
|
-
assert_match_in_file(/
|
181
|
+
capture_io { generate(:controller, 'UserItems','-a=/subby', "-r=#{@apptmp}/sample_project", "-p=user") }
|
182
|
+
assert_match_in_file(/describe "\/demo_items" do/m, "#{@apptmp}/sample_project/spec/subby/controllers/demo_items_controller_spec.rb")
|
183
|
+
assert_match_in_file(/feature "\/demo_items" do/m, "#{@apptmp}/sample_project/spec/subby/acceptance/controllers/demo_items_controller_spec.rb")
|
184
|
+
assert_match_in_file(/describe "\/user\/:user_id\/user_items" do/m, "#{@apptmp}/sample_project/spec/subby/controllers/user_items_controller_spec.rb")
|
185
|
+
assert_match_in_file(/get "\/demo_items"/m, "#{@apptmp}/sample_project/spec/subby/controllers/demo_items_controller_spec.rb")
|
186
|
+
assert_match_in_file(/get "\/user\/1\/user_items"/m, "#{@apptmp}/sample_project/spec/subby/controllers/user_items_controller_spec.rb")
|
187
|
+
assert_match_in_file(/feature "\/user\/:user_id\/user_items" do/m, "#{@apptmp}/sample_project/spec/subby/acceptance/controllers/user_items_controller_spec.rb")
|
160
188
|
assert_match_in_file(/describe "SampleProject::Subby::DemoItemsHelper" do/m, "#{@apptmp}/sample_project/spec/subby/helpers/demo_items_helper_spec.rb")
|
161
189
|
end
|
162
190
|
|
@@ -164,7 +192,11 @@ describe "ControllerGenerator" do
|
|
164
192
|
capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=cucumber') }
|
165
193
|
capture_io { generate(:app, 'subby', "-r=#{@apptmp}/sample_project") }
|
166
194
|
capture_io { generate(:controller, 'DemoItems','-a=/subby', "-r=#{@apptmp}/sample_project") }
|
167
|
-
|
195
|
+
capture_io { generate(:controller, 'UserItems','-a=/subby', "-r=#{@apptmp}/sample_project", "-p=user") }
|
196
|
+
assert_match_in_file(/describe "\/demo_items" do/m, "#{@apptmp}/sample_project/spec/subby/controllers/demo_items_controller_spec.rb")
|
197
|
+
assert_match_in_file(/describe "\/user\/:user_id\/user_items"/, "#{@apptmp}/sample_project/spec/subby/controllers/user_items_controller_spec.rb")
|
198
|
+
assert_match_in_file(/get "\/demo_items"/m, "#{@apptmp}/sample_project/spec/subby/controllers/demo_items_controller_spec.rb")
|
199
|
+
assert_match_in_file(/get "\/user\/1\/user_items"/m, "#{@apptmp}/sample_project/spec/subby/controllers/user_items_controller_spec.rb")
|
168
200
|
assert_match_in_file(/Capybara.app = /, "#{@apptmp}/sample_project/features/support/env.rb")
|
169
201
|
end
|
170
202
|
|
data/test/test_generator.rb
CHANGED
@@ -3,7 +3,7 @@ require File.expand_path(File.dirname(__FILE__) + '/helper')
|
|
3
3
|
describe "Generator" do
|
4
4
|
describe "the generator" do
|
5
5
|
it 'should have default generators' do
|
6
|
-
%w{controller mailer migration model app plugin component task}.each do |gen|
|
6
|
+
%w{controller mailer migration model app plugin component task helper}.each do |gen|
|
7
7
|
assert Padrino::Generators.mappings.has_key?(gen.to_sym)
|
8
8
|
assert_equal "Padrino::Generators::#{gen.camelize}", Padrino::Generators.mappings[gen.to_sym].name
|
9
9
|
assert Padrino::Generators.mappings[gen.to_sym].respond_to?(:start)
|
@@ -0,0 +1,133 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/helper')
|
2
|
+
|
3
|
+
describe "HelperGenerator" do
|
4
|
+
def setup
|
5
|
+
@apptmp = "#{Dir.tmpdir}/padrino-tests/#{SecureRandom.hex}"
|
6
|
+
`mkdir -p #{@apptmp}`
|
7
|
+
@helper_path = "#{@apptmp}/sample_project/app/helpers/demo_items_helper.rb"
|
8
|
+
@helper_test_path = "#{@apptmp}/sample_project/test/app/helpers/demo_items_helper_test.rb"
|
9
|
+
end
|
10
|
+
|
11
|
+
def teardown
|
12
|
+
`rm -rf #{@apptmp}`
|
13
|
+
end
|
14
|
+
|
15
|
+
describe 'the helper generator' do
|
16
|
+
it 'should fail outside app root' do
|
17
|
+
out, err = capture_io { generate(:helper, 'demo', "-r=#{@apptmp}") }
|
18
|
+
assert_match(/not at the root/, out)
|
19
|
+
assert_no_file_exists("#{@apptmp}/app/helpers/demo_helper.rb")
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'should generate helper within existing project' do
|
23
|
+
capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=bacon') }
|
24
|
+
capture_io { generate(:helper, 'DemoItems', "-r=#{@apptmp}/sample_project") }
|
25
|
+
assert_match_in_file(/module SampleProject/, @helper_path)
|
26
|
+
assert_match_in_file(/class App/, @helper_path)
|
27
|
+
assert_match_in_file(/module DemoItemsHelper/, @helper_path)
|
28
|
+
assert_match_in_file(/helpers DemoItemsHelper/, @helper_path)
|
29
|
+
assert_file_exists(@helper_path)
|
30
|
+
assert_file_exists(@helper_test_path)
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'should generate helper within existing project with weird name' do
|
34
|
+
capture_io { generate(:project, 'warepedia', "--root=#{@apptmp}", '--script=none', '-t=bacon') }
|
35
|
+
capture_io { generate(:helper, 'DemoItems', "-r=#{@apptmp}/warepedia") }
|
36
|
+
assert_match_in_file(/helpers DemoItemsHelper/, "#{@apptmp}/warepedia/app/helpers/demo_items_helper.rb")
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'should generate helper in specified app' do
|
40
|
+
capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=bacon') }
|
41
|
+
capture_io { generate(:app, 'subby', "-r=#{@apptmp}/sample_project") }
|
42
|
+
capture_io { generate(:helper, 'DemoItems','-a=/subby', "-r=#{@apptmp}/sample_project") }
|
43
|
+
assert_match_in_file(/helpers DemoItemsHelper/m, "#{@apptmp}/sample_project/subby/helpers/demo_items_helper.rb")
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'should not fail if we do not have test component' do
|
47
|
+
capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--test=none') }
|
48
|
+
capture_io { generate(:helper, 'DemoItems', "-r=#{@apptmp}/sample_project") }
|
49
|
+
assert_match_in_file(/helpers DemoItemsHelper/m, "#{@apptmp}/sample_project/app/helpers/demo_items_helper.rb")
|
50
|
+
assert_no_file_exists("#{@apptmp}/sample_project/test")
|
51
|
+
end
|
52
|
+
|
53
|
+
it 'should generate helper test for bacon' do
|
54
|
+
capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=bacon') }
|
55
|
+
capture_io { generate(:app, 'subby', "-r=#{@apptmp}/sample_project") }
|
56
|
+
capture_io { generate(:helper, 'DemoItems','-a=/subby', "-r=#{@apptmp}/sample_project") }
|
57
|
+
assert_match_in_file(/describe "SampleProject::Subby::DemoItemsHelper" do/m, @helper_test_path.gsub('app','subby'))
|
58
|
+
end
|
59
|
+
|
60
|
+
it 'should generate helper test for riot' do
|
61
|
+
capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=riot') }
|
62
|
+
capture_io { generate(:app, 'subby', "-r=#{@apptmp}/sample_project") }
|
63
|
+
capture_io { generate(:helper, 'DemoItems','-a=/subby', "-r=#{@apptmp}/sample_project") }
|
64
|
+
assert_match_in_file(/describe "SampleProject::Subby::DemoItemsHelper" do/m, @helper_test_path.gsub('app','subby'))
|
65
|
+
end
|
66
|
+
|
67
|
+
it 'should generate helper test for minitest' do
|
68
|
+
capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=minitest') }
|
69
|
+
capture_io { generate(:app, 'subby', "-r=#{@apptmp}/sample_project") }
|
70
|
+
capture_io { generate(:helper, 'DemoItems','-a=/subby', "-r=#{@apptmp}/sample_project") }
|
71
|
+
assert_match_in_file(/describe "SampleProject::Subby::DemoItemsHelper" do/m, @helper_test_path.gsub('app','subby'))
|
72
|
+
end
|
73
|
+
|
74
|
+
it 'should generate helper test for rspec' do
|
75
|
+
capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=rspec') }
|
76
|
+
capture_io { generate(:app, 'subby', "-r=#{@apptmp}/sample_project") }
|
77
|
+
capture_io { generate(:helper, 'DemoItems','-a=/subby', "-r=#{@apptmp}/sample_project") }
|
78
|
+
assert_match_in_file(/describe "SampleProject::Subby::DemoItemsHelper" do/m, "#{@apptmp}/sample_project/spec/subby/helpers/demo_items_helper_spec.rb")
|
79
|
+
end
|
80
|
+
|
81
|
+
it 'should generate helper test for shoulda' do
|
82
|
+
capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=shoulda') }
|
83
|
+
capture_io { generate(:app, 'subby', "-r=#{@apptmp}/sample_project") }
|
84
|
+
capture_io { generate(:helper, 'DemoItems','-a=/subby', "-r=#{@apptmp}/sample_project") }
|
85
|
+
expected_pattern = /class DemoItemsHelperTest < Test::Unit::TestCase/m
|
86
|
+
assert_match_in_file(/context "SampleProject::Subby::DemoItemsHelper" do/m, @helper_test_path.gsub('app','subby'))
|
87
|
+
assert_file_exists(@helper_test_path.gsub('app','subby'))
|
88
|
+
assert_file_exists("#{@apptmp}/sample_project/test/subby/helpers/demo_items_helper_test.rb")
|
89
|
+
end
|
90
|
+
|
91
|
+
it 'should generate helper test for steak' do
|
92
|
+
capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=steak') }
|
93
|
+
capture_io { generate(:app, 'subby', "-r=#{@apptmp}/sample_project") }
|
94
|
+
capture_io { generate(:helper, 'DemoItems','-a=/subby', "-r=#{@apptmp}/sample_project") }
|
95
|
+
assert_match_in_file(/describe "SampleProject::Subby::DemoItemsHelper" do/m, "#{@apptmp}/sample_project/spec/subby/helpers/demo_items_helper_spec.rb")
|
96
|
+
end
|
97
|
+
|
98
|
+
it 'should correctly generate file names' do
|
99
|
+
capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=rspec') }
|
100
|
+
capture_io { generate(:helper, 'DemoItems', "-r=#{@apptmp}/sample_project") }
|
101
|
+
assert_file_exists("#{@apptmp}/sample_project/app/helpers/demo_items_helper.rb")
|
102
|
+
assert_file_exists("#{@apptmp}/sample_project/spec/app/helpers/demo_items_helper_spec.rb")
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
describe "the helper destroy option" do
|
107
|
+
it 'should destroy helper files' do
|
108
|
+
capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=bacon') }
|
109
|
+
capture_io { generate(:helper, 'demo_items',"-r=#{@apptmp}/sample_project") }
|
110
|
+
capture_io { generate(:helper, 'demo_items',"-r=#{@apptmp}/sample_project",'-d') }
|
111
|
+
assert_no_file_exists(@helper_path)
|
112
|
+
assert_no_file_exists(@helper_test_path)
|
113
|
+
assert_no_file_exists("#{@apptmp}/sample_project/app/helpers/demo_items_helper.rb")
|
114
|
+
end
|
115
|
+
|
116
|
+
it 'should destroy helper files with rspec' do
|
117
|
+
capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=rspec') }
|
118
|
+
capture_io { generate(:helper, 'demo_items',"-r=#{@apptmp}/sample_project") }
|
119
|
+
capture_io { generate(:helper, 'demo_items',"-r=#{@apptmp}/sample_project",'-d') }
|
120
|
+
assert_no_file_exists(@helper_path)
|
121
|
+
assert_no_file_exists("#{@apptmp}/sample_project/app/helpers/demo_items_helper.rb")
|
122
|
+
assert_no_file_exists("#{@apptmp}/sample_project/spec/app/helpers/demo_items_helper_spec.rb")
|
123
|
+
end
|
124
|
+
|
125
|
+
it 'should destroy helper files in sub apps' do
|
126
|
+
capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=bacon') }
|
127
|
+
capture_io { generate(:app, 'subby', "-r=#{@apptmp}/sample_project") }
|
128
|
+
capture_io { generate(:helper, 'demo_items',"-a=/subby","-r=#{@apptmp}/sample_project") }
|
129
|
+
capture_io { generate(:helper, 'demo_items',"-a=/subby","-r=#{@apptmp}/sample_project",'-d') }
|
130
|
+
assert_no_file_exists("#{@apptmp}/sample_project/app/helpers/demo_items_helper.rb")
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|
@@ -119,7 +119,8 @@ describe "ModelGenerator" do
|
|
119
119
|
describe "model generator using activerecord" do
|
120
120
|
it 'should add activerecord middleware' do
|
121
121
|
capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-d=activerecord') }
|
122
|
-
assert_match_in_file(/ use
|
122
|
+
assert_match_in_file(/ use ConnectionPoolManagement/m, "#{@apptmp}/sample_project/app/app.rb")
|
123
|
+
assert_file_exists("#{@apptmp}/sample_project/lib/connection_pool_management_middleware.rb")
|
123
124
|
end
|
124
125
|
|
125
126
|
it 'should generate model file' do
|
@@ -170,8 +171,9 @@ describe "ModelGenerator" do
|
|
170
171
|
end
|
171
172
|
|
172
173
|
it 'should add activerecord middleware' do
|
173
|
-
capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-d=
|
174
|
-
assert_match_in_file(/ use
|
174
|
+
capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-d=minirecord') }
|
175
|
+
assert_match_in_file(/ use ConnectionPoolManagement/m, "#{@apptmp}/sample_project/app/app.rb")
|
176
|
+
assert_file_exists("#{@apptmp}/sample_project/lib/connection_pool_management_middleware.rb")
|
175
177
|
end
|
176
178
|
|
177
179
|
it 'should generate model file' do
|
@@ -208,6 +208,12 @@ describe "ProjectGenerator" do
|
|
208
208
|
assert_file_exists("#{@apptmp}/sample_project/tmp/.keep")
|
209
209
|
assert_file_exists("#{@apptmp}/sample_project/log/.keep")
|
210
210
|
end
|
211
|
+
|
212
|
+
it 'should allow to pass upcased name as the app name' do
|
213
|
+
capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", "--app=API") }
|
214
|
+
assert_file_exists("#{@apptmp}/sample_project/app/app.rb")
|
215
|
+
assert_match_in_file(/class API < Padrino::Application/, "#{@apptmp}/sample_project/app/app.rb")
|
216
|
+
end
|
211
217
|
end
|
212
218
|
|
213
219
|
describe "a generator for mock component" do
|
@@ -684,6 +690,7 @@ describe "ProjectGenerator" do
|
|
684
690
|
assert_file_exists("#{@apptmp}/sample_project/spec/app/helpers/helpers_spec.rb")
|
685
691
|
assert_match_in_file(/Dir\[File\.expand_path\(File\.dirname\(__FILE__\) \+ "\/\.\.\/app\/helpers\.rb"\)\]\.each\(&method\(:require\)\)/, "#{@apptmp}/sample_project/spec/spec_helper.rb")
|
686
692
|
assert_match_in_file(/RSpec\.describe "Controller" do/, "#{@apptmp}/sample_project/spec/app/controllers/controllers_spec.rb")
|
693
|
+
assert_match_in_file(/get "\/"/, "#{@apptmp}/sample_project/spec/app/controllers/controllers_spec.rb")
|
687
694
|
assert_match_in_file(/RSpec.describe "SampleProject::App::Helper" do/, "#{@apptmp}/sample_project/spec/app/helpers/helpers_spec.rb")
|
688
695
|
end
|
689
696
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: padrino-gen
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.12.
|
4
|
+
version: 0.12.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Padrino Team
|
@@ -11,7 +11,7 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date: 2014-
|
14
|
+
date: 2014-10-19 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: padrino-core
|
@@ -19,14 +19,14 @@ dependencies:
|
|
19
19
|
requirements:
|
20
20
|
- - '='
|
21
21
|
- !ruby/object:Gem::Version
|
22
|
-
version: 0.12.
|
22
|
+
version: 0.12.4
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
25
|
version_requirements: !ruby/object:Gem::Requirement
|
26
26
|
requirements:
|
27
27
|
- - '='
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
version: 0.12.
|
29
|
+
version: 0.12.4
|
30
30
|
- !ruby/object:Gem::Dependency
|
31
31
|
name: bundler
|
32
32
|
requirement: !ruby/object:Gem::Requirement
|
@@ -47,28 +47,28 @@ dependencies:
|
|
47
47
|
requirements:
|
48
48
|
- - '='
|
49
49
|
- !ruby/object:Gem::Version
|
50
|
-
version: 0.12.
|
50
|
+
version: 0.12.4
|
51
51
|
type: :development
|
52
52
|
prerelease: false
|
53
53
|
version_requirements: !ruby/object:Gem::Requirement
|
54
54
|
requirements:
|
55
55
|
- - '='
|
56
56
|
- !ruby/object:Gem::Version
|
57
|
-
version: 0.12.
|
57
|
+
version: 0.12.4
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: padrino-mailer
|
60
60
|
requirement: !ruby/object:Gem::Requirement
|
61
61
|
requirements:
|
62
62
|
- - '='
|
63
63
|
- !ruby/object:Gem::Version
|
64
|
-
version: 0.12.
|
64
|
+
version: 0.12.4
|
65
65
|
type: :development
|
66
66
|
prerelease: false
|
67
67
|
version_requirements: !ruby/object:Gem::Requirement
|
68
68
|
requirements:
|
69
69
|
- - '='
|
70
70
|
- !ruby/object:Gem::Version
|
71
|
-
version: 0.12.
|
71
|
+
version: 0.12.4
|
72
72
|
description: Generators for easily creating and building padrino applications from
|
73
73
|
the console
|
74
74
|
email: padrinorb@gmail.com
|
@@ -130,6 +130,7 @@ files:
|
|
130
130
|
- lib/padrino-gen/generators/components/tests/shoulda.rb
|
131
131
|
- lib/padrino-gen/generators/components/tests/steak.rb
|
132
132
|
- lib/padrino-gen/generators/controller.rb
|
133
|
+
- lib/padrino-gen/generators/helper.rb
|
133
134
|
- lib/padrino-gen/generators/mailer.rb
|
134
135
|
- lib/padrino-gen/generators/migration.rb
|
135
136
|
- lib/padrino-gen/generators/model.rb
|
@@ -174,6 +175,7 @@ files:
|
|
174
175
|
- test/test_component_generator.rb
|
175
176
|
- test/test_controller_generator.rb
|
176
177
|
- test/test_generator.rb
|
178
|
+
- test/test_helper_generator.rb
|
177
179
|
- test/test_mailer_generator.rb
|
178
180
|
- test/test_migration_generator.rb
|
179
181
|
- test/test_model_generator.rb
|
@@ -231,6 +233,7 @@ test_files:
|
|
231
233
|
- test/test_component_generator.rb
|
232
234
|
- test/test_controller_generator.rb
|
233
235
|
- test/test_generator.rb
|
236
|
+
- test/test_helper_generator.rb
|
234
237
|
- test/test_mailer_generator.rb
|
235
238
|
- test/test_migration_generator.rb
|
236
239
|
- test/test_model_generator.rb
|