padrino-gen 0.11.3 → 0.11.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.rdoc +1 -1
- data/lib/padrino-gen.rb +14 -22
- data/lib/padrino-gen/command.rb +4 -5
- data/lib/padrino-gen/generators/actions.rb +63 -48
- data/lib/padrino-gen/generators/app.rb +15 -17
- data/lib/padrino-gen/generators/app/app.rb.tt +2 -2
- data/lib/padrino-gen/generators/cli.rb +9 -9
- data/lib/padrino-gen/generators/component.rb +62 -0
- data/lib/padrino-gen/generators/components/actions.rb +48 -57
- data/lib/padrino-gen/generators/components/mocks/mocha.rb +2 -1
- data/lib/padrino-gen/generators/components/mocks/rr.rb +1 -1
- data/lib/padrino-gen/generators/components/orms/minirecord.rb +2 -2
- data/lib/padrino-gen/generators/components/orms/mongoid.rb +7 -7
- data/lib/padrino-gen/generators/components/orms/ohm.rb +3 -3
- data/lib/padrino-gen/generators/components/stylesheets/compass.rb +1 -1
- data/lib/padrino-gen/generators/components/stylesheets/compass/partials/_base.scss +5 -3
- data/lib/padrino-gen/generators/components/stylesheets/less.rb +1 -1
- data/lib/padrino-gen/generators/components/stylesheets/sass.rb +1 -1
- data/lib/padrino-gen/generators/components/stylesheets/scss.rb +1 -1
- data/lib/padrino-gen/generators/controller.rb +6 -10
- data/lib/padrino-gen/generators/mailer.rb +7 -11
- data/lib/padrino-gen/generators/migration.rb +4 -9
- data/lib/padrino-gen/generators/model.rb +6 -12
- data/lib/padrino-gen/generators/plugin.rb +9 -12
- data/lib/padrino-gen/generators/project.rb +18 -28
- data/lib/padrino-gen/generators/runner.rb +25 -25
- data/lib/padrino-gen/padrino-tasks/activerecord.rb +11 -12
- data/lib/padrino-gen/padrino-tasks/datamapper.rb +3 -3
- data/lib/padrino-gen/padrino-tasks/mongoid.rb +9 -9
- data/lib/padrino-gen/padrino-tasks/mongomapper.rb +4 -5
- data/lib/padrino-gen/padrino-tasks/sequel.rb +1 -2
- data/test/helper.rb +1 -1
- data/test/test_component_generator.rb +85 -0
- data/test/test_generator.rb +1 -1
- data/test/test_plugin_generator.rb +1 -1
- data/test/test_project_generator.rb +11 -4
- metadata +12 -15
@@ -3,19 +3,19 @@ require 'fileutils'
|
|
3
3
|
module Padrino
|
4
4
|
module Generators
|
5
5
|
##
|
6
|
-
# Responsible for executing plugin and template instructions including
|
6
|
+
# Responsible for executing plugin and template instructions including
|
7
|
+
# common actions for modifying a project or application.
|
7
8
|
#
|
8
9
|
module Runner
|
9
10
|
|
10
|
-
# Generates project scaffold based on a given template file
|
11
|
+
# Generates project scaffold based on a given template file.
|
11
12
|
#
|
12
13
|
# @param [Hash] options
|
13
|
-
# Options to use to generate the project
|
14
|
+
# Options to use to generate the project.
|
14
15
|
#
|
15
16
|
# @example
|
16
17
|
# project :test => :shoulda, :orm => :activerecord, :renderer => "haml"
|
17
18
|
#
|
18
|
-
# @api public
|
19
19
|
def project(options={})
|
20
20
|
components = options.sort_by { |k, v| k.to_s }.map { |component, value| "--#{component}=#{value}" }
|
21
21
|
params = [name, *components].push("-r=#{destination_root("../")}")
|
@@ -23,19 +23,19 @@ module Padrino
|
|
23
23
|
Padrino.bin_gen(*params.unshift("project"))
|
24
24
|
end
|
25
25
|
|
26
|
-
|
26
|
+
##
|
27
|
+
# Executes generator command for specified type with given arguments.
|
27
28
|
#
|
28
29
|
# @param [Symbol] type
|
29
|
-
# Type of component module
|
30
|
+
# Type of component module.
|
30
31
|
# @param [String] arguments
|
31
|
-
# Arguments to send to component generator
|
32
|
+
# Arguments to send to component generator.
|
32
33
|
#
|
33
34
|
# @example
|
34
35
|
# generate :model, "post title:string body:text"
|
35
36
|
# generate :controller, "posts get:index get:new post:new"
|
36
37
|
# generate :migration, "AddEmailToUser email:string"
|
37
38
|
#
|
38
|
-
# @api public
|
39
39
|
def generate(type, arguments="")
|
40
40
|
params = arguments.split(" ").push("-r=#{destination_root}")
|
41
41
|
params.push("--app=#{@_app_name}") if @_app_name
|
@@ -43,25 +43,26 @@ module Padrino
|
|
43
43
|
Padrino.bin_gen(*params.unshift(type))
|
44
44
|
end
|
45
45
|
|
46
|
-
|
46
|
+
##
|
47
|
+
# Executes rake command with given arguments.
|
47
48
|
#
|
48
49
|
# @param [String] command
|
49
|
-
# Rake tasks to execute
|
50
|
+
# Rake tasks to execute.
|
50
51
|
#
|
51
52
|
# @example
|
52
53
|
# rake "custom task1 task2"
|
53
54
|
#
|
54
|
-
# @api public
|
55
55
|
def rake(command)
|
56
56
|
Padrino.bin("rake", command, "-c=#{destination_root}")
|
57
57
|
end
|
58
58
|
|
59
|
+
##
|
59
60
|
# Executes App generator. Accepts an optional block allowing generation inside subapp.
|
60
61
|
#
|
61
62
|
# @param [Symbol] name
|
62
|
-
#
|
63
|
+
# Name of (sub)application to generate.
|
63
64
|
# @param [Proc] block
|
64
|
-
#
|
65
|
+
# Commands to execute in context of (sub)appliation directory.
|
65
66
|
#
|
66
67
|
# @example
|
67
68
|
# app :name
|
@@ -69,7 +70,6 @@ module Padrino
|
|
69
70
|
# generate :model, "posts title:string" # generate a model inside of subapp
|
70
71
|
# end
|
71
72
|
#
|
72
|
-
# @api public
|
73
73
|
def app(name, &block)
|
74
74
|
say "=> Executing: padrino-gen app #{name} -r=#{destination_root}", :magenta
|
75
75
|
Padrino.bin_gen(:app, name.to_s, "-r=#{destination_root}")
|
@@ -80,19 +80,19 @@ module Padrino
|
|
80
80
|
end
|
81
81
|
end
|
82
82
|
|
83
|
-
|
83
|
+
##
|
84
|
+
# Executes git commmands in project.
|
84
85
|
#
|
85
86
|
# @param [Symbol] action
|
86
|
-
# Git command to execute
|
87
|
+
# Git command to execute.
|
87
88
|
# @param [String] arguments
|
88
|
-
# Arguments to invoke on git command
|
89
|
+
# Arguments to invoke on git command.
|
89
90
|
#
|
90
91
|
# @example
|
91
92
|
# git :init
|
92
93
|
# git :add, "."
|
93
94
|
# git :commit, "hello world"
|
94
95
|
#
|
95
|
-
# @api public
|
96
96
|
def git(*args)
|
97
97
|
FileUtils.cd(destination_root) do
|
98
98
|
cmd = "git %s" % args.join(' ')
|
@@ -103,13 +103,14 @@ module Padrino
|
|
103
103
|
|
104
104
|
private
|
105
105
|
|
106
|
+
##
|
106
107
|
# Resolves the path to the plugin template
|
107
|
-
# given the project_name and the template_file
|
108
|
+
# given the project_name and the template_file.
|
108
109
|
#
|
109
110
|
# @param [Symbol] kind
|
110
|
-
# Context of template file to run, i.e :plugin, :template
|
111
|
+
# Context of template file to run, i.e :plugin, :template.
|
111
112
|
# @param [String] template_file
|
112
|
-
# Path to template file
|
113
|
+
# Path to template file.
|
113
114
|
#
|
114
115
|
# @example
|
115
116
|
# execute_runner(:plugin, 'path/to/local/file')
|
@@ -117,7 +118,6 @@ module Padrino
|
|
117
118
|
# execute_runner(:template, 'sampleblog')
|
118
119
|
# execute_runner(:template, 'https://gist.github.com/357045')
|
119
120
|
#
|
120
|
-
# @api private
|
121
121
|
def execute_runner(kind, template_file)
|
122
122
|
# Determine resolved template path
|
123
123
|
template_file = template_file.to_s
|
@@ -134,6 +134,6 @@ module Padrino
|
|
134
134
|
end
|
135
135
|
self.apply(template_path) rescue say("The template at #{template_path} could not be found!", :red)
|
136
136
|
end
|
137
|
-
end
|
138
|
-
end
|
139
|
-
end
|
137
|
+
end
|
138
|
+
end
|
139
|
+
end
|
@@ -60,7 +60,7 @@ if PadrinoTasks.load?(:activerecord, defined?(ActiveRecord))
|
|
60
60
|
end
|
61
61
|
rescue
|
62
62
|
case config[:adapter]
|
63
|
-
when 'mysql', 'mysql2', 'jdbcmysql'
|
63
|
+
when 'mysql', 'mysql2', 'em_mysql2', 'jdbcmysql'
|
64
64
|
@charset = ENV['CHARSET'] || 'utf8'
|
65
65
|
@collation = ENV['COLLATION'] || 'utf8_unicode_ci'
|
66
66
|
creation_options = {:charset => (config[:charset] || @charset), :collation => (config[:collation] || @collation)}
|
@@ -189,7 +189,7 @@ if PadrinoTasks.load?(:activerecord, defined?(ActiveRecord))
|
|
189
189
|
task :charset => :environment do
|
190
190
|
config = ActiveRecord::Base.configurations[Padrino.env || :development]
|
191
191
|
case config[:adapter]
|
192
|
-
when 'mysql', 'mysql2', 'jdbcmysql'
|
192
|
+
when 'mysql', 'mysql2', 'em_mysql2', 'jdbcmysql'
|
193
193
|
ActiveRecord::Base.establish_connection(config)
|
194
194
|
puts ActiveRecord::Base.connection.charset
|
195
195
|
when 'postgresql'
|
@@ -204,7 +204,7 @@ if PadrinoTasks.load?(:activerecord, defined?(ActiveRecord))
|
|
204
204
|
task :collation => :environment do
|
205
205
|
config = ActiveRecord::Base.configurations[Padrino.env || :development]
|
206
206
|
case config[:adapter]
|
207
|
-
when 'mysql', 'mysql2', 'jdbcmysql'
|
207
|
+
when 'mysql', 'mysql2', 'em_mysql2', 'jdbcmysql'
|
208
208
|
ActiveRecord::Base.establish_connection(config)
|
209
209
|
puts ActiveRecord::Base.connection.collation
|
210
210
|
else
|
@@ -261,7 +261,7 @@ if PadrinoTasks.load?(:activerecord, defined?(ActiveRecord))
|
|
261
261
|
task :dump => :environment do
|
262
262
|
abcs = ActiveRecord::Base.configurations
|
263
263
|
case abcs[Padrino.env][:adapter]
|
264
|
-
when "mysql", "mysql2", "oci", "oracle", 'jdbcmysql'
|
264
|
+
when "mysql", "mysql2", 'em_mysql2', "oci", "oracle", 'jdbcmysql'
|
265
265
|
ActiveRecord::Base.establish_connection(abcs[Padrino.env])
|
266
266
|
File.open("#{Padrino.root}/db/#{Padrino.env}_structure.sql", "w+") { |f| f << ActiveRecord::Base.connection.structure_dump }
|
267
267
|
when "postgresql"
|
@@ -299,29 +299,28 @@ if PadrinoTasks.load?(:activerecord, defined?(ActiveRecord))
|
|
299
299
|
models = Dir["#{Padrino.root}/{app,}/models/**/*.rb"].map { |m| File.basename(m, ".rb") }
|
300
300
|
|
301
301
|
models.each do |m|
|
302
|
-
# Get the model class
|
302
|
+
# Get the model class.
|
303
303
|
klass = m.camelize.constantize
|
304
304
|
|
305
|
-
# Avoid non ActiveRecord models
|
305
|
+
# Avoid non ActiveRecord models.
|
306
306
|
next unless klass.ancestors.include?(ActiveRecord::Base)
|
307
307
|
|
308
|
-
# Init the processing
|
308
|
+
# Init the processing.
|
309
309
|
print "Processing #{m.humanize}: "
|
310
310
|
FileUtils.mkdir_p("#{Padrino.root}/app/locale/models/#{m}")
|
311
|
-
langs = Array(I18n.locale)
|
311
|
+
langs = Array(I18n.locale)
|
312
312
|
|
313
|
-
# Create models for it and en locales
|
313
|
+
# Create models for it and en locales.
|
314
314
|
langs.each do |lang|
|
315
315
|
filename = "#{Padrino.root}/app/locale/models/#{m}/#{lang}.yml"
|
316
316
|
columns = klass.columns.map(&:name)
|
317
|
-
# If the lang file already exist we need to check it
|
317
|
+
# If the lang file already exist we need to check it.
|
318
318
|
if File.exist?(filename)
|
319
319
|
locale = File.open(filename).read
|
320
320
|
columns.each do |c|
|
321
321
|
locale += "\n #{c}: #{klass.human_attribute_name(c)}" unless locale.include?("#{c}:")
|
322
322
|
end
|
323
323
|
print "Lang #{lang.to_s.upcase} already exist ... "; $stdout.flush
|
324
|
-
# Do some ere
|
325
324
|
else
|
326
325
|
locale = "#{lang}:" + "\n" +
|
327
326
|
" models:" + "\n" +
|
@@ -340,7 +339,7 @@ if PadrinoTasks.load?(:activerecord, defined?(ActiveRecord))
|
|
340
339
|
|
341
340
|
def drop_database(config)
|
342
341
|
case config[:adapter]
|
343
|
-
when 'mysql', 'mysql2', 'jdbcmysql'
|
342
|
+
when 'mysql', 'mysql2', 'em_mysql2', 'jdbcmysql'
|
344
343
|
ActiveRecord::Base.establish_connection(config)
|
345
344
|
ActiveRecord::Base.connection.drop_database config[:database]
|
346
345
|
when /^sqlite/
|
@@ -1,13 +1,13 @@
|
|
1
1
|
if PadrinoTasks.load?(:datamapper, defined?(DataMapper))
|
2
2
|
namespace :dm do
|
3
3
|
namespace :auto do
|
4
|
-
desc "Perform
|
4
|
+
desc "Perform auto migration (reset your db data)"
|
5
5
|
task :migrate => :environment do
|
6
6
|
::DataMapper.repository.auto_migrate!
|
7
7
|
puts "<= dm:auto:migrate executed"
|
8
8
|
end
|
9
9
|
|
10
|
-
desc "Perform non destructive
|
10
|
+
desc "Perform non destructive auto migration"
|
11
11
|
task :upgrade => :environment do
|
12
12
|
::DataMapper.repository.auto_upgrade!
|
13
13
|
puts "<= dm:auto:upgrade executed"
|
@@ -61,7 +61,7 @@ if PadrinoTasks.load?(:datamapper, defined?(DataMapper))
|
|
61
61
|
DataMapper.setup(DataMapper.repository.name, config)
|
62
62
|
else
|
63
63
|
# require 'padrino-gen/padrino-tasks/sql-helpers'
|
64
|
-
Padrino::Generators::SqlHelpers.create_db(config[:adapter], user, password, host, database, charset, collation)
|
64
|
+
Padrino::Generators::SqlHelpers.create_db(config[:adapter], user, password, host, database, charset, collation)
|
65
65
|
end
|
66
66
|
puts "<= dm:create executed"
|
67
67
|
end
|
@@ -1,5 +1,5 @@
|
|
1
1
|
if PadrinoTasks.load?(:mongoid, defined?(Mongoid))
|
2
|
-
require 'mongoid'
|
2
|
+
require 'mongoid'
|
3
3
|
|
4
4
|
namespace :mi do
|
5
5
|
|
@@ -76,7 +76,7 @@ if PadrinoTasks.load?(:mongoid, defined?(Mongoid))
|
|
76
76
|
documents << klass
|
77
77
|
end
|
78
78
|
rescue => e
|
79
|
-
# Just for non-mongoid objects that
|
79
|
+
# Just for non-mongoid objects that don't have the embedded
|
80
80
|
# attribute at the class level.
|
81
81
|
end
|
82
82
|
end
|
@@ -86,7 +86,7 @@ if PadrinoTasks.load?(:mongoid, defined?(Mongoid))
|
|
86
86
|
|
87
87
|
desc 'Create the indexes defined on your mongoid models'
|
88
88
|
task :create_indexes => :environment do
|
89
|
-
get_mongoid_models.each
|
89
|
+
get_mongoid_models.each(&:create_indexes)
|
90
90
|
end
|
91
91
|
|
92
92
|
def convert_ids(obj)
|
@@ -114,14 +114,14 @@ if PadrinoTasks.load?(:mongoid, defined?(Mongoid))
|
|
114
114
|
collection_names.each do |collection_name|
|
115
115
|
puts "Converting #{collection_name} to use ObjectIDs"
|
116
116
|
|
117
|
-
#
|
117
|
+
# Get old collection.
|
118
118
|
collection = mongoid_collection(collection_name)
|
119
119
|
|
120
|
-
#
|
120
|
+
# Get new collection (a clean one).
|
121
121
|
mongoid_collection("#{collection_name}_new").drop
|
122
122
|
new_collection = mongoid_new_collection(collection, "#{collection_name}_new")
|
123
123
|
|
124
|
-
#
|
124
|
+
# Convert collection documents.
|
125
125
|
enum_mongoid_documents(collection) do |doc|
|
126
126
|
new_doc = convert_ids(doc)
|
127
127
|
new_collection.insert(new_doc, :safe => true)
|
@@ -130,12 +130,12 @@ if PadrinoTasks.load?(:mongoid, defined?(Mongoid))
|
|
130
130
|
puts "Done! Converted collection is in #{new_collection.name}\n\n"
|
131
131
|
end
|
132
132
|
|
133
|
-
#
|
133
|
+
# No errors. great! now rename _new to collection_name.
|
134
134
|
collection_names.each do |collection_name|
|
135
135
|
collection = mongoid_collection(collection_name)
|
136
136
|
new_collection = mongoid_new_collection(collection, "#{collection_name}_new")
|
137
137
|
|
138
|
-
#
|
138
|
+
# Swap collection to _old.
|
139
139
|
puts "Moving #{collection.name} to #{collection_name}_old"
|
140
140
|
mongoid_new_collection(collection, "#{collection_name}_old").drop
|
141
141
|
|
@@ -146,7 +146,7 @@ if PadrinoTasks.load?(:mongoid, defined?(Mongoid))
|
|
146
146
|
puts "reason: #{e.message}\n\n"
|
147
147
|
end
|
148
148
|
|
149
|
-
#
|
149
|
+
# Swap _new to collection.
|
150
150
|
puts "Moving #{new_collection.name} to #{collection_name}\n\n"
|
151
151
|
|
152
152
|
begin
|
@@ -2,7 +2,7 @@ if defined?(MongoMapper)
|
|
2
2
|
begin
|
3
3
|
require 'i18n'
|
4
4
|
rescue LoadError
|
5
|
-
#
|
5
|
+
# Only do this for I18n check later.
|
6
6
|
end
|
7
7
|
|
8
8
|
namespace :mm do
|
@@ -16,15 +16,15 @@ if defined?(MongoMapper)
|
|
16
16
|
models = Dir["#{Padrino.root}/{app,}/models/**/*.rb"].map { |m| File.basename(m, ".rb") }
|
17
17
|
|
18
18
|
models.each do |m|
|
19
|
-
# Get the model class
|
19
|
+
# Get the model class.
|
20
20
|
klass = m.camelize.constantize
|
21
21
|
|
22
22
|
# Init the processing
|
23
23
|
print "Processing #{m.humanize}: "
|
24
24
|
FileUtils.mkdir_p("#{Padrino.root}/app/locale/models/#{m}")
|
25
|
-
langs = Array(I18n.locale)
|
25
|
+
langs = Array(I18n.locale)
|
26
26
|
|
27
|
-
# Create models for it and en locales
|
27
|
+
# Create models for it and en locales.
|
28
28
|
langs.each do |lang|
|
29
29
|
filename = "#{Padrino.root}/app/locale/models/#{m}/#{lang}.yml"
|
30
30
|
columns = klass.keys.values.map(&:name).reject { |name| name =~ /id/i }
|
@@ -35,7 +35,6 @@ if defined?(MongoMapper)
|
|
35
35
|
locale += "\n #{c}: #{c.humanize}" unless locale.include?("#{c}:")
|
36
36
|
end
|
37
37
|
print "Lang #{lang.to_s.upcase} already exist ... "; $stdout.flush
|
38
|
-
# Do some ere
|
39
38
|
else
|
40
39
|
locale = "#{lang}:" + "\n" +
|
41
40
|
" models:" + "\n" +
|
@@ -1,7 +1,6 @@
|
|
1
1
|
if PadrinoTasks.load?(:sequel, defined?(Sequel))
|
2
2
|
namespace :sq do
|
3
3
|
namespace :migrate do
|
4
|
-
|
5
4
|
desc "Perform automigration (reset your db data)"
|
6
5
|
task :auto => :environment do
|
7
6
|
::Sequel.extension :migration
|
@@ -50,7 +49,7 @@ if PadrinoTasks.load?(:sequel, defined?(Sequel))
|
|
50
49
|
::Sequel.sqlite(database)
|
51
50
|
else
|
52
51
|
require 'padrino-gen/padrino-tasks/sql-helpers'
|
53
|
-
Padrino::Generators::SqlHelpers.create_db(config[:adapter], user, password, host, database, charset, collation)
|
52
|
+
Padrino::Generators::SqlHelpers.create_db(config[:adapter], user, password, host, database, charset, collation)
|
54
53
|
end
|
55
54
|
puts "<= sq:create executed"
|
56
55
|
end
|
data/test/helper.rb
CHANGED
@@ -97,7 +97,7 @@ class MiniTest::Spec
|
|
97
97
|
# expects_initializer :test, "# Example"
|
98
98
|
def expects_initializer(name, body,options={})
|
99
99
|
#options.reverse_merge!(:root => "/tmp/sample_project")
|
100
|
-
path = File.join(options[:root],'lib',"#{name}
|
100
|
+
path = File.join(options[:root],'lib',"#{name}_initializer.rb")
|
101
101
|
instance = mock
|
102
102
|
instance.expects(:invoke!).at_least_once
|
103
103
|
include_text = " register #{name.to_s.camelize}Initializer\n"
|
@@ -0,0 +1,85 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/helper')
|
2
|
+
|
3
|
+
describe "ComponentGenerator" do
|
4
|
+
def setup
|
5
|
+
@apptmp = "#{Dir.tmpdir}/padrino-tests/#{UUID.new.generate}"
|
6
|
+
`mkdir -p #{@apptmp}`
|
7
|
+
end
|
8
|
+
|
9
|
+
def teardown
|
10
|
+
`rm -rf #{@apptmp}`
|
11
|
+
end
|
12
|
+
|
13
|
+
context 'the controller generator' do
|
14
|
+
should "fail outside app root" do
|
15
|
+
out, err = capture_io { generate(:component, 'demo', "-r=#{@apptmp}") }
|
16
|
+
assert_match(/not at the root/, out)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
|
21
|
+
context "add components" do
|
22
|
+
should "properly generate default" do
|
23
|
+
capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}") }
|
24
|
+
out, err = capture_io { generate(:component, '--orm=activerecord', "-r=#{@apptmp}/sample_project") }
|
25
|
+
assert_match(/applying.*?activerecord.*?orm/, out)
|
26
|
+
assert_match_in_file(/gem 'activerecord', '>= 3.1', :require => 'active_record'/, "#{@apptmp}/sample_project/Gemfile")
|
27
|
+
assert_match_in_file(/gem 'sqlite3'/, "#{@apptmp}/sample_project/Gemfile")
|
28
|
+
assert_no_match(/Switch renderer to/, out)
|
29
|
+
components_chosen = YAML.load_file("#{@apptmp}/sample_project/.components")
|
30
|
+
assert_equal 'activerecord', components_chosen[:orm]
|
31
|
+
end
|
32
|
+
|
33
|
+
should "properly generate with adapter" do
|
34
|
+
capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}") }
|
35
|
+
out, err = capture_io { generate(:component, '--orm=sequel', '--adapter=postgres', "-r=#{@apptmp}/sample_project") }
|
36
|
+
assert_match_in_file(/gem 'pg'/, "#{@apptmp}/sample_project/Gemfile")
|
37
|
+
assert_no_match(/Switch renderer to/, out)
|
38
|
+
components_chosen = YAML.load_file("#{@apptmp}/sample_project/.components")
|
39
|
+
assert_equal 'sequel', components_chosen[:orm]
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
|
44
|
+
context "specified of same the component" do
|
45
|
+
should "does not change" do
|
46
|
+
capture_io { generate(:project, 'sample_project', '--script=jquery', "--root=#{@apptmp}") }
|
47
|
+
components_chosen = YAML.load_file("#{@apptmp}/sample_project/.components")
|
48
|
+
assert_equal 'jquery', components_chosen[:script]
|
49
|
+
out, err = capture_io { generate(:component, '--script=jquery', "-r=#{@apptmp}/sample_project") }
|
50
|
+
assert_match(/applying.*?jquery.*?script/, out)
|
51
|
+
assert_no_match(/Switch renderer to/, out)
|
52
|
+
components_chosen = YAML.load_file("#{@apptmp}/sample_project/.components")
|
53
|
+
assert_equal 'jquery', components_chosen[:script]
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
|
58
|
+
context "component changes" do
|
59
|
+
should "when allow changes, will be applied" do
|
60
|
+
capture_io { generate(:project, 'sample_project', '-renderer=slim', "--root=#{@apptmp}") }
|
61
|
+
components_chosen = YAML.load_file("#{@apptmp}/sample_project/.components")
|
62
|
+
assert_equal 'slim', components_chosen[:renderer]
|
63
|
+
$stdin.stub(:gets, 'yes') do
|
64
|
+
out, err = capture_io { generate(:component, '--renderer=haml', "-r=#{@apptmp}/sample_project") }
|
65
|
+
assert_match(/applying.*?haml.*?renderer/, out)
|
66
|
+
assert_match(/Switch renderer to/, out)
|
67
|
+
components_chosen = YAML.load_file("#{@apptmp}/sample_project/.components")
|
68
|
+
assert_equal 'haml', components_chosen[:renderer]
|
69
|
+
end
|
70
|
+
end
|
71
|
+
should "when deny changes, will not be applied" do
|
72
|
+
capture_io { generate(:project, 'sample_project', '-renderer=slim', "--root=#{@apptmp}") }
|
73
|
+
components_chosen = YAML.load_file("#{@apptmp}/sample_project/.components")
|
74
|
+
assert_equal 'slim', components_chosen[:renderer]
|
75
|
+
$stdin.stub(:gets, 'no') do
|
76
|
+
out, err = capture_io { generate(:component, '--renderer=haml', "-r=#{@apptmp}/sample_project") }
|
77
|
+
assert_no_match(/applying.*?haml.*?renderer/, out)
|
78
|
+
assert_match(/Switch renderer to/, out)
|
79
|
+
components_chosen = YAML.load_file("#{@apptmp}/sample_project/.components")
|
80
|
+
assert_equal 'slim', components_chosen[:renderer]
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
end
|