padrino-gen 0.11.0 → 0.11.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -78,9 +78,9 @@ module Padrino
78
78
  contents = options[:base].dup.gsub(/\s{4}!UP!\n/m, (direction == 'add' ? forward_text.to_s : back_text.to_s))
79
79
  contents.gsub!(/\s{4}!DOWN!\n/m, (direction == 'add' ? back_text.to_s : forward_text.to_s))
80
80
  contents = contents.gsub(/!FILENAME!/, filename.underscore).gsub(/!FILECLASS!/, filename.underscore.camelize)
81
- current_migration_number = return_last_migration_number
82
- contents.gsub!(/!VERSION!/, (current_migration_number + 1).to_s)
83
- migration_filename = "#{format("%03d", current_migration_number+1)}_#{filename.underscore}.rb"
81
+ migration_number = current_migration_number
82
+ contents.gsub!(/!VERSION!/, migration_number)
83
+ migration_filename = "#{format("%03d", migration_number)}_#{filename.underscore}.rb"
84
84
  create_file(destination_root('db/migrate/', migration_filename), contents, :skip => true)
85
85
  end
86
86
  end
@@ -95,6 +95,19 @@ module Padrino
95
95
  }.max.to_i || 0
96
96
  end
97
97
 
98
+ # For migration files
99
+ # returns the number of the migration that is being created
100
+ # returna timestamp instead if :migration_format: in .components is "timestamp"
101
+ #
102
+ # @api private
103
+ def current_migration_number
104
+ if fetch_component_choice(:migration_format).to_s == 'timestamp'
105
+ Time.now.utc.strftime("%Y%m%d%H%M%S")
106
+ else
107
+ return_last_migration_number + 1
108
+ end.to_s
109
+ end
110
+
98
111
  # Return true if the migration already exist
99
112
  #
100
113
  # @param [String] filename
@@ -185,9 +198,9 @@ module Padrino
185
198
  def controller_actions(fields)
186
199
  field_tuples = fields.map { |value| value.split(":") }
187
200
  action_declarations = field_tuples.map do |request, name|
188
- "#{request} :#{name} do\n end\n"
201
+ "#{request} :#{name} do\n\nend\n"
189
202
  end
190
- action_declarations.join("\n ")
203
+ action_declarations.join("\n").gsub(/^/, " " * 2).gsub(/^\s*$/, "")
191
204
  end
192
205
  end # Actions
193
206
  end # Components
@@ -8,6 +8,6 @@ def setup_mock
8
8
  when 'minitest'
9
9
  insert_mocking_include "RR::Adapters::MiniTest", :path => "test/test_config.rb"
10
10
  else # default include
11
- insert_mocking_include "RR::Adapters::RRMethods", :path => "test/test_config.rb"
11
+ insert_mocking_include "RR::Adapters::TestUnit", :path => "test/test_config.rb"
12
12
  end
13
13
  end
@@ -149,7 +149,7 @@ class !FILECLASS! < ActiveRecord::Migration
149
149
  end
150
150
  MIGRATION
151
151
 
152
- AR_MODEL_UP_MG = (<<-MIGRATION) unless defined?(AR_MODEL_UP_MG)
152
+ AR_MODEL_UP_MG = (<<-MIGRATION).gsub(/^/,' ') unless defined?(AR_MODEL_UP_MG)
153
153
  create_table :!TABLE! do |t|
154
154
  !FIELDS!
155
155
  t.timestamps
@@ -2,6 +2,8 @@ SHOULDA_SETUP = (<<-TEST).gsub(/^ {10}/, '') unless defined?(SHOULDA_SETUP)
2
2
  PADRINO_ENV = 'test' unless defined?(PADRINO_ENV)
3
3
  require File.expand_path(File.dirname(__FILE__) + "/../config/boot")
4
4
 
5
+ require "test/unit"
6
+
5
7
  class Test::Unit::TestCase
6
8
  include Rack::Test::Methods
7
9
 
@@ -63,9 +65,6 @@ def setup_test
63
65
  require_dependencies 'rack-test', :require => 'rack/test', :group => 'test'
64
66
  require_dependencies 'shoulda', :group => 'test'
65
67
  insert_test_suite_setup SHOULDA_SETUP
66
- if options[:orm] == "activerecord"
67
- inject_into_file destination_root("test/test_config.rb"), "require 'shoulda/active_record'\n\n", :before => /class.*?\n/
68
- end
69
68
  create_file destination_root("test/test.rake"), SHOULDA_RAKE
70
69
  end
71
70
 
@@ -26,6 +26,9 @@ module Padrino
26
26
  class_option :app, :desc => 'The application destination path', :aliases => '-a', :default => '/app', :type => :string
27
27
  class_option :destroy, :aliases => '-d', :default => false, :type => :boolean
28
28
  class_option :namespace, :desc => 'The name space of your padrino project', :aliases => '-n', :default => '', :type => :string
29
+ class_option :layout, :desc => 'The layout for the controller', :aliases => '-l', :default => '', :type => :string
30
+ class_option :parent, :desc => 'The parent of the controller', :aliases => '-p', :default => '', :type => :string
31
+ class_option :provides, :desc => 'the formats provided by the controller', :aliases => '-f', :default => '', :type => :string
29
32
 
30
33
  # Show help if no argv given
31
34
  require_arguments!
@@ -43,6 +46,13 @@ module Padrino
43
46
  @app_name = fetch_app_name(app)
44
47
  @actions = controller_actions(fields)
45
48
  @controller = name.to_s.underscore
49
+ @layout = options[:layout] if options[:layout] && !options[:layout].empty?
50
+
51
+ block_opts = []
52
+ block_opts << ":parent => :#{options[:parent]}" if options[:parent] && !options[:parent].empty?
53
+ block_opts << ":provides => [#{options[:provides]}]" if options[:provides] && !options[:provides].empty?
54
+ @block_opts_string = block_opts.join(', ') unless block_opts.empty?
55
+
46
56
  self.behavior = :revoke if options[:destroy]
47
57
  template 'templates/controller.rb.tt', destination_root(app, 'controllers', "#{name.to_s.underscore}.rb")
48
58
  template 'templates/helper.rb.tt', destination_root(app, 'helpers', "#{name.to_s.underscore}_helper.rb")
@@ -39,9 +39,9 @@ module Padrino
39
39
  if options[:list] || plugin_file.nil? # list method ran here
40
40
  list_plugins
41
41
  else # executing the plugin instructions
42
+ self.destination_root = options[:root]
42
43
  if in_app_root?
43
44
  self.behavior = :revoke if options[:destroy]
44
- self.destination_root = options[:root]
45
45
  execute_runner(:plugin, plugin_file)
46
46
  else
47
47
  say "You are not at the root of a Padrino application! (config/boot.rb not found)"
@@ -26,14 +26,15 @@ module Padrino
26
26
 
27
27
  argument :name, :desc => 'The name of your padrino project'
28
28
 
29
- class_option :app , :desc => 'The application name', :aliases => '-n', :default => nil, :type => :string
30
- class_option :bundle, :desc => 'Run bundle install', :aliases => '-b', :default => false, :type => :boolean
31
- class_option :root, :desc => 'The root destination', :aliases => '-r', :default => '.', :type => :string
32
- class_option :dev, :desc => 'Use padrino from a git checkout', :default => false, :type => :boolean
33
- class_option :tiny, :desc => 'Generate tiny app skeleton', :aliases => '-i', :default => false, :type => :boolean
34
- class_option :adapter, :desc => 'SQL adapter for ORM (sqlite, mysql, mysql2, mysql-gem, postgres)', :aliases => '-a', :default => 'sqlite', :type => :string
35
- class_option :template, :desc => 'Generate project from template', :aliases => '-p', :default => nil, :type => :string
36
- class_option :gem, :desc => 'Generate project as a gem', :aliases => '-g', :default => false, :type => :boolean
29
+ class_option :app , :desc => 'The application name', :aliases => '-n', :default => nil, :type => :string
30
+ class_option :bundle, :desc => 'Run bundle install', :aliases => '-b', :default => false, :type => :boolean
31
+ class_option :root, :desc => 'The root destination', :aliases => '-r', :default => '.', :type => :string
32
+ class_option :dev, :desc => 'Use padrino from a git checkout', :default => false, :type => :boolean
33
+ class_option :tiny, :desc => 'Generate tiny app skeleton', :aliases => '-i', :default => false, :type => :boolean
34
+ class_option :adapter, :desc => 'SQL adapter for ORM (sqlite, mysql, mysql2, mysql-gem, postgres)', :aliases => '-a', :default => 'sqlite', :type => :string
35
+ class_option :template, :desc => 'Generate project from template', :aliases => '-p', :default => nil, :type => :string
36
+ class_option :gem, :desc => 'Generate project as a gem', :aliases => '-g', :default => false, :type => :boolean
37
+ class_option :migration_format, :desc => 'Filename format for migrations (number, timestamp)', :default => 'number', :type => :string
37
38
 
38
39
  # Definitions for the available customizable components
39
40
  component_option :orm, 'database engine', :aliases => '-d', :choices => [:activerecord, :minirecord, :datamapper, :mongomapper, :mongoid, :sequel, :couchrest, :ohm, :mongomatic, :ripple], :default => :none
@@ -89,6 +90,7 @@ module Padrino
89
90
  end
90
91
  store_component_config('.components')
91
92
  store_component_choice(:namespace, @project_name)
93
+ store_component_choice(:migration_format, options[:migration_format])
92
94
  end
93
95
 
94
96
  # Bundle all required components using bundler and Gemfile
@@ -1,7 +1,7 @@
1
1
  require 'bundler/setup'
2
2
  require 'padrino-core/cli/rake'
3
3
 
4
- <%- if options[:orm] -%>
4
+ <%- if options[:orm] && options[:orm] != :none -%>
5
5
  PadrinoTasks.use(:database)
6
6
  PadrinoTasks.use(<%= options[:orm].to_sym.inspect %>)
7
7
  <%- end -%>
@@ -1,4 +1,5 @@
1
- <%= @project_name %>::<%= @app_name %>.controllers <%= ":#{@controller}" if @controller %> do
1
+ <%= @project_name %>::<%= @app_name %>.controllers <%= ":#{@controller}" if @controller %><%= ", #{@block_opts_string}" if @block_opts_string %> do
2
+ <%= "layout :#{@layout}" if @layout %>
2
3
  # get :index, :map => '/foo/bar' do
3
4
  # session[:foo] = 'bar'
4
5
  # render 'index'
@@ -2,5 +2,5 @@ require 'padrino-core'
2
2
 
3
3
  module <%=name.camelcase%>
4
4
  extend Padrino::Module
5
- gem! <%=name.inspect%>
5
+ gem! <%=name.downcase.inspect%>
6
6
  end
@@ -8,16 +8,18 @@
8
8
  **/
9
9
 
10
10
  $(function(){
11
- $('form[data-remote=true]').on('submit', function(e) {
12
- e.preventDefault(); e.stopped = true;
11
+ $('form').on('submit', function(e) {
13
12
  var element = $(this), message = element.data('confirm');
14
13
  if (message && !confirm(message)) { return false; }
15
- JSAdapter.sendRequest(element, {
16
- verb: element.data('method') || element.attr('method') || 'post',
17
- url: element.attr('action'),
18
- dataType: element.data('type') || ($.ajaxSettings && $.ajaxSettings.dataType) || 'script',
19
- params: element.serializeArray()
20
- });
14
+ if (element.data('remote') == true) {
15
+ e.preventDefault(); e.stopped = true;
16
+ JSAdapter.sendRequest(element, {
17
+ verb: element.data('method') || element.attr('method') || 'post',
18
+ url: element.attr('action'),
19
+ dataType: element.data('type') || ($.ajaxSettings && $.ajaxSettings.dataType) || 'script',
20
+ params: element.serializeArray()
21
+ });
22
+ }
21
23
  });
22
24
 
23
25
  /* Confirmation Support
@@ -29,22 +31,22 @@ $(function(){
29
31
  if (!confirm(message)) { e.preventDefault(); e.stopped = true; }
30
32
  });
31
33
 
32
- /*
33
- * Link Remote Support
34
+ /*
35
+ * Link Remote Support
34
36
  * link_to 'add item', '/create', :remote => true
35
37
  **/
36
38
 
37
39
  $('a[data-remote=true]').on('click', function(e) {
38
- var element = $(this);
40
+ var element = $(this);
39
41
  if (e.stopped) return;
40
42
  e.preventDefault(); e.stopped = true;
41
- JSAdapter.sendRequest(element, {
42
- verb: element.data('method') || 'get',
43
+ JSAdapter.sendRequest(element, {
44
+ verb: element.data('method') || 'get',
43
45
  url: element.attr('href')
44
46
  });
45
47
  });
46
48
 
47
- /*
49
+ /*
48
50
  * Link Method Support
49
51
  * link_to 'delete item', '/destroy', :method => :delete
50
52
  **/
@@ -289,48 +289,46 @@ if PadrinoTasks.load?(:activerecord, defined?(ActiveRecord))
289
289
  end
290
290
  end
291
291
 
292
- if defined?(I18n)
293
- desc "Generates .yml files for I18n translations"
294
- task :translate => :environment do
295
- models = Dir["#{Padrino.root}/{app,}/models/**/*.rb"].map { |m| File.basename(m, ".rb") }
296
-
297
- models.each do |m|
298
- # Get the model class
299
- klass = m.camelize.constantize
300
-
301
- # Avoid non ActiveRecord models
302
- next unless klass.ancestors.include?(ActiveRecord::Base)
303
-
304
- # Init the processing
305
- print "Processing #{m.humanize}: "
306
- FileUtils.mkdir_p("#{Padrino.root}/app/locale/models/#{m}")
307
- langs = Array(I18n.locale) # for now we use only one
308
-
309
- # Create models for it and en locales
310
- langs.each do |lang|
311
- filename = "#{Padrino.root}/app/locale/models/#{m}/#{lang}.yml"
312
- columns = klass.columns.map(&:name)
313
- # If the lang file already exist we need to check it
314
- if File.exist?(filename)
315
- locale = File.open(filename).read
316
- columns.each do |c|
317
- locale += "\n #{c}: #{klass.human_attribute_name(c)}" unless locale.include?("#{c}:")
318
- end
319
- print "Lang #{lang.to_s.upcase} already exist ... "; $stdout.flush
320
- # Do some ere
321
- else
322
- locale = "#{lang}:" + "\n" +
323
- " models:" + "\n" +
324
- " #{m}:" + "\n" +
325
- " name: #{klass.model_name.human}" + "\n" +
326
- " attributes:" + "\n" +
327
- columns.map { |c| " #{c}: #{klass.human_attribute_name(c)}" }.join("\n")
328
- print "created a new for #{lang.to_s.upcase} Lang ... "; $stdout.flush
292
+ desc "Generates .yml files for I18n translations"
293
+ task :translate => :environment do
294
+ models = Dir["#{Padrino.root}/{app,}/models/**/*.rb"].map { |m| File.basename(m, ".rb") }
295
+
296
+ models.each do |m|
297
+ # Get the model class
298
+ klass = m.camelize.constantize
299
+
300
+ # Avoid non ActiveRecord models
301
+ next unless klass.ancestors.include?(ActiveRecord::Base)
302
+
303
+ # Init the processing
304
+ print "Processing #{m.humanize}: "
305
+ FileUtils.mkdir_p("#{Padrino.root}/app/locale/models/#{m}")
306
+ langs = Array(I18n.locale) # for now we use only one
307
+
308
+ # Create models for it and en locales
309
+ langs.each do |lang|
310
+ filename = "#{Padrino.root}/app/locale/models/#{m}/#{lang}.yml"
311
+ columns = klass.columns.map(&:name)
312
+ # If the lang file already exist we need to check it
313
+ if File.exist?(filename)
314
+ locale = File.open(filename).read
315
+ columns.each do |c|
316
+ locale += "\n #{c}: #{klass.human_attribute_name(c)}" unless locale.include?("#{c}:")
329
317
  end
330
- File.open(filename, "w") { |f| f.puts locale }
318
+ print "Lang #{lang.to_s.upcase} already exist ... "; $stdout.flush
319
+ # Do some ere
320
+ else
321
+ locale = "#{lang}:" + "\n" +
322
+ " models:" + "\n" +
323
+ " #{m}:" + "\n" +
324
+ " name: #{klass.model_name.human}" + "\n" +
325
+ " attributes:" + "\n" +
326
+ columns.map { |c| " #{c}: #{klass.human_attribute_name(c)}" }.join("\n")
327
+ print "created a new for #{lang.to_s.upcase} Lang ... "; $stdout.flush
331
328
  end
332
- puts
329
+ File.open(filename, "w") { |f| f.puts locale }
333
330
  end
331
+ puts
334
332
  end
335
333
  end
336
334
  end
@@ -11,45 +11,43 @@ if defined?(MongoMapper)
11
11
  MongoMapper.database.collections.select {|c| c.name !~ /system/ }.each(&:drop)
12
12
  end
13
13
 
14
- if defined?(I18n)
15
- desc "Generates .yml files for I18n translations"
16
- task :translate => :environment do
17
- models = Dir["#{Padrino.root}/{app,}/models/**/*.rb"].map { |m| File.basename(m, ".rb") }
14
+ desc "Generates .yml files for I18n translations"
15
+ task :translate => :environment do
16
+ models = Dir["#{Padrino.root}/{app,}/models/**/*.rb"].map { |m| File.basename(m, ".rb") }
18
17
 
19
- models.each do |m|
20
- # Get the model class
21
- klass = m.camelize.constantize
18
+ models.each do |m|
19
+ # Get the model class
20
+ klass = m.camelize.constantize
22
21
 
23
- # Init the processing
24
- print "Processing #{m.humanize}: "
25
- FileUtils.mkdir_p("#{Padrino.root}/app/locale/models/#{m}")
26
- langs = Array(I18n.locale) # for now we use only one
22
+ # Init the processing
23
+ print "Processing #{m.humanize}: "
24
+ FileUtils.mkdir_p("#{Padrino.root}/app/locale/models/#{m}")
25
+ langs = Array(I18n.locale) # for now we use only one
27
26
 
28
- # Create models for it and en locales
29
- langs.each do |lang|
30
- filename = "#{Padrino.root}/app/locale/models/#{m}/#{lang}.yml"
31
- columns = klass.keys.values.map(&:name).reject { |name| name =~ /id/i }
32
- # If the lang file already exist we need to check it
33
- if File.exist?(filename)
34
- locale = File.open(filename).read
35
- columns.each do |c|
36
- locale += "\n #{c}: #{c.humanize}" unless locale.include?("#{c}:")
37
- end
38
- print "Lang #{lang.to_s.upcase} already exist ... "; $stdout.flush
39
- # Do some ere
40
- else
41
- locale = "#{lang}:" + "\n" +
42
- " models:" + "\n" +
43
- " #{m}:" + "\n" +
44
- " name: #{klass.human_name}" + "\n" +
45
- " attributes:" + "\n" +
46
- columns.map { |c| " #{c}: #{c.humanize}" }.join("\n")
47
- print "created a new for #{lang.to_s.upcase} Lang ... "; $stdout.flush
27
+ # Create models for it and en locales
28
+ langs.each do |lang|
29
+ filename = "#{Padrino.root}/app/locale/models/#{m}/#{lang}.yml"
30
+ columns = klass.keys.values.map(&:name).reject { |name| name =~ /id/i }
31
+ # If the lang file already exist we need to check it
32
+ if File.exist?(filename)
33
+ locale = File.open(filename).read
34
+ columns.each do |c|
35
+ locale += "\n #{c}: #{c.humanize}" unless locale.include?("#{c}:")
48
36
  end
49
- File.open(filename, "w") { |f| f.puts locale }
37
+ print "Lang #{lang.to_s.upcase} already exist ... "; $stdout.flush
38
+ # Do some ere
39
+ else
40
+ locale = "#{lang}:" + "\n" +
41
+ " models:" + "\n" +
42
+ " #{m}:" + "\n" +
43
+ " name: #{klass.human_name}" + "\n" +
44
+ " attributes:" + "\n" +
45
+ columns.map { |c| " #{c}: #{c.humanize}" }.join("\n")
46
+ print "created a new for #{lang.to_s.upcase} Lang ... "; $stdout.flush
50
47
  end
51
- puts
48
+ File.open(filename, "w") { |f| f.puts locale }
52
49
  end
50
+ puts
53
51
  end
54
52
  end
55
53
  end
@@ -46,7 +46,43 @@ describe "ControllerGenerator" do
46
46
  assert_match_in_file(/describe "DemoItemsController" do/m, @controller_test_path.gsub('app','subby'))
47
47
  end
48
48
 
49
- should 'not fail if we don\'t have test component' do
49
+ should "generate controller with specified layout" do
50
+ capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=bacon') }
51
+ capture_io { generate(:controller, 'DemoItems', "-r=#{@apptmp}/sample_project", '-l=xyzlayout') }
52
+ assert_match_in_file(/layout :xyzlayout/m, @controller_path)
53
+ end
54
+
55
+ should "generate controller without specified layout if empty" do
56
+ capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=bacon') }
57
+ capture_io { generate(:controller, 'DemoItems', "-r=#{@apptmp}/sample_project", '-l=') }
58
+ assert_no_match_in_file(/layout/m, @controller_path)
59
+ end
60
+
61
+ should "generate controller with specified parent" do
62
+ capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=bacon') }
63
+ capture_io { generate(:controller, 'DemoItems', "-r=#{@apptmp}/sample_project", '-p=user') }
64
+ assert_match_in_file(/SampleProject::App.controllers :demo_items, :parent => :user do/m, @controller_path)
65
+ end
66
+
67
+ should "generate controller without specified parent" do
68
+ capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=bacon') }
69
+ capture_io { generate(:controller, 'DemoItems', "-r=#{@apptmp}/sample_project", '-p=') }
70
+ assert_match_in_file(/SampleProject::App.controllers :demo_items do/m, @controller_path)
71
+ end
72
+
73
+ should "generate controller with specified providers" do
74
+ capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=bacon') }
75
+ capture_io { generate(:controller, 'DemoItems', "-r=#{@apptmp}/sample_project", '-f=:html, :js') }
76
+ assert_match_in_file(/SampleProject::App.controllers :demo_items, :provides => \[:html, :js\] do/m, @controller_path)
77
+ end
78
+
79
+ should "generate controller without specified providers" do
80
+ capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=bacon') }
81
+ capture_io { generate(:controller, 'DemoItems', "-r=#{@apptmp}/sample_project", '-f=') }
82
+ assert_match_in_file(/SampleProject::App.controllers :demo_items do/m, @controller_path)
83
+ end
84
+
85
+ should "not fail if we don't have test component" do
50
86
  capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--test=none') }
51
87
  capture_io { generate(:controller, 'DemoItems', "-r=#{@apptmp}/sample_project") }
52
88
  assert_match_in_file(/SampleProject::App.controllers :demo_items do/m, @controller_path)
@@ -125,8 +161,8 @@ describe "ControllerGenerator" do
125
161
  should "generate actions for get:test post:yada" do
126
162
  capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=shoulda') }
127
163
  capture_io { generate(:controller, 'demo_items', "get:test", "post:yada","-r=#{@apptmp}/sample_project") }
128
- assert_match_in_file(/get :test do\n end\n/m, @controller_path)
129
- assert_match_in_file(/post :yada do\n end\n/m, @controller_path)
164
+ assert_match_in_file(/get :test do\n\n end\n/m, @controller_path)
165
+ assert_match_in_file(/post :yada do\n\n end\n/m, @controller_path)
130
166
  end
131
167
  end
132
168
 
@@ -45,14 +45,27 @@ describe "MigrationGenerator" do
45
45
  assert_match_in_file(/t.remove :email/, migration_file_path)
46
46
  end
47
47
 
48
- should "properly calculate version number" do
49
- capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=bacon', '-d=sequel') }
50
- capture_io { generate(:migration, 'add_email_to_person', "email:string", "-r=#{@apptmp}/sample_project") }
51
- capture_io { generate(:migration, 'add_name_to_person', "email:string", "-r=#{@apptmp}/sample_project") }
52
- capture_io { generate(:migration, 'add_age_to_user', "email:string", "-r=#{@apptmp}/sample_project") }
53
- assert_match_in_file(/Sequel\.migration do/m, "#{@apptmp}/sample_project/db/migrate/001_add_email_to_person.rb")
54
- assert_match_in_file(/Sequel\.migration do/m, "#{@apptmp}/sample_project/db/migrate/002_add_name_to_person.rb")
55
- assert_match_in_file(/Sequel\.migration do/m, "#{@apptmp}/sample_project/db/migrate/003_add_age_to_user.rb")
48
+ context "the default migration numbering" do
49
+ should "properly calculate version number" do
50
+ capture_io { generate(:project, 'sample_project', "--migration_format=number", "--root=#{@apptmp}", '--script=none', '-t=bacon', '-d=sequel') }
51
+ capture_io { generate(:migration, 'add_email_to_person', "email:string", "-r=#{@apptmp}/sample_project") }
52
+ capture_io { generate(:migration, 'add_name_to_person', "email:string", "-r=#{@apptmp}/sample_project") }
53
+ capture_io { generate(:migration, 'add_age_to_user', "email:string", "-r=#{@apptmp}/sample_project") }
54
+ assert_match_in_file(/Sequel\.migration do/m, "#{@apptmp}/sample_project/db/migrate/001_add_email_to_person.rb")
55
+ assert_match_in_file(/Sequel\.migration do/m, "#{@apptmp}/sample_project/db/migrate/002_add_name_to_person.rb")
56
+ assert_match_in_file(/Sequel\.migration do/m, "#{@apptmp}/sample_project/db/migrate/003_add_age_to_user.rb")
57
+ end
58
+ end
59
+
60
+ context "the timestamped migration numbering" do
61
+ should "properly calculate version number" do
62
+ capture_io { generate(:project, 'sample_project', "--migration_format=timestamp", "--root=#{@apptmp}", '--script=none', '-t=bacon', '-d=sequel') }
63
+
64
+ time = stop_time_for_test.utc.strftime("%Y%m%d%H%M%S")
65
+
66
+ capture_io { generate(:migration, 'add_gender_to_person', "gender:string", "-r=#{@apptmp}/sample_project") }
67
+ assert_match_in_file(/Sequel\.migration do/m, "#{@apptmp}/sample_project/db/migrate/#{time}_add_gender_to_person.rb")
68
+ end
56
69
  end
57
70
  end
58
71
 
@@ -82,11 +82,11 @@ describe "ModelGenerator" do
82
82
  capture_io { generate(:model, 'person', "name", "age:integer", "email", "-r=#{@apptmp}/sample_project") }
83
83
  migration_file_path = "#{@apptmp}/sample_project/db/migrate/001_create_people.rb"
84
84
  assert_match_in_file(/class CreatePeople < ActiveRecord::Migration/m, migration_file_path)
85
- assert_match_in_file(/create_table :people/m, migration_file_path)
86
- assert_match_in_file(/t.string :name/m, migration_file_path)
87
- assert_match_in_file(/t.integer :age/m, migration_file_path)
88
- assert_match_in_file(/t.string :email/m, migration_file_path)
89
- assert_match_in_file(/drop_table :people/m, migration_file_path)
85
+ assert_match_in_file(/ create_table :people/m, migration_file_path)
86
+ assert_match_in_file(/ t.string :name/m, migration_file_path)
87
+ assert_match_in_file(/ t.integer :age/m, migration_file_path)
88
+ assert_match_in_file(/ t.string :email/m, migration_file_path)
89
+ assert_match_in_file(/ drop_table :people/m, migration_file_path)
90
90
  end
91
91
  end
92
92
 
@@ -116,8 +116,8 @@ describe "ModelGenerator" do
116
116
  capture_io { generate(:model, 'user', "-r=#{@apptmp}/sample_project") }
117
117
  migration_file_path = "#{@apptmp}/sample_project/db/migrate/001_create_users.rb"
118
118
  assert_match_in_file(/class CreateUsers < ActiveRecord::Migration/m, migration_file_path)
119
- assert_match_in_file(/create_table :users/m, migration_file_path)
120
- assert_match_in_file(/drop_table :users/m, migration_file_path)
119
+ assert_match_in_file(/ create_table :users/m, migration_file_path)
120
+ assert_match_in_file(/ drop_table :users/m, migration_file_path)
121
121
  end
122
122
 
123
123
  should "generate migration file with given fields" do
@@ -126,11 +126,11 @@ describe "ModelGenerator" do
126
126
  capture_io { generate(:model, 'person', "name:string", "age:integer", "email:string", "-r=#{@apptmp}/sample_project") }
127
127
  migration_file_path = "#{@apptmp}/sample_project/db/migrate/001_create_people.rb"
128
128
  assert_match_in_file(/class CreatePeople < ActiveRecord::Migration/m, migration_file_path)
129
- assert_match_in_file(/create_table :people/m, migration_file_path)
130
- assert_match_in_file(/t.string :name/m, migration_file_path)
131
- assert_match_in_file(/t.integer :age/m, migration_file_path)
132
- assert_match_in_file(/t.string :email/m, migration_file_path)
133
- assert_match_in_file(/drop_table :people/m, migration_file_path)
129
+ assert_match_in_file(/ create_table :people/m, migration_file_path)
130
+ assert_match_in_file(/ t.string :name/m, migration_file_path)
131
+ assert_match_in_file(/ t.integer :age/m, migration_file_path)
132
+ assert_match_in_file(/ t.string :email/m, migration_file_path)
133
+ assert_match_in_file(/ drop_table :people/m, migration_file_path)
134
134
  end
135
135
  end
136
136
 
@@ -10,6 +10,15 @@ describe "PluginGenerator" do
10
10
  `rm -rf #{@apptmp}`
11
11
  end
12
12
 
13
+ context "the plugin generator" do
14
+ should "respect --root option" do
15
+ path = File.expand_path('../fixtures/plugin_template.rb', __FILE__)
16
+ capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}") }
17
+ out, err = capture_io { generate(:plugin, path, "--root=#{@apptmp}/sample_project") }
18
+ refute_match /You are not at the root/, out
19
+ end
20
+ end
21
+
13
22
  context "the plugin destroy option" do
14
23
  should "remove the plugin instance" do
15
24
  path = File.expand_path('../fixtures/plugin_template.rb', __FILE__)
@@ -62,6 +62,16 @@ describe "ProjectGenerator" do
62
62
  assert_file_exists("#{@apptmp}/sample_project/public/favicon.ico")
63
63
  end
64
64
 
65
+ should "add database's tasks to Rakefile if an ORM is defined" do
66
+ capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--app=base_app', '--orm=activerecord') }
67
+ assert_match_in_file('PadrinoTasks.use(:database)',"#{@apptmp}/sample_project/Rakefile")
68
+ end
69
+
70
+ should "avoid add database's tasks on Rakefile if no ORM is specified" do
71
+ capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--app=base_app') }
72
+ assert_no_match_in_file('PadrinoTasks.use(:database)',"#{@apptmp}/sample_project/Rakefile")
73
+ end
74
+
65
75
  should "generate tiny skeleton" do
66
76
  capture_io { generate(:project,'sample_project', '--tiny',"--root=#{@apptmp}") }
67
77
  assert_file_exists("#{@apptmp}/sample_project")
@@ -166,7 +176,7 @@ describe "ProjectGenerator" do
166
176
  out, err = capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--mock=rr', '--test=bacon', '--script=none') }
167
177
  assert_match(/applying.*?rr.*?mock/, out)
168
178
  assert_match_in_file(/gem 'rr'/, "#{@apptmp}/sample_project/Gemfile")
169
- assert_match_in_file(/include RR::Adapters::RRMethods/m, "#{@apptmp}/sample_project/test/test_config.rb")
179
+ assert_match_in_file(/include RR::Adapters::TestUnit/m, "#{@apptmp}/sample_project/test/test_config.rb")
170
180
  end
171
181
 
172
182
  should "properly generate for rr and rspec" do
metadata CHANGED
@@ -1,7 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: padrino-gen
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.11.0
4
+ version: 0.11.1
5
+ prerelease:
5
6
  platform: ruby
6
7
  authors:
7
8
  - Padrino Team
@@ -11,25 +12,28 @@ authors:
11
12
  autorequire:
12
13
  bindir: bin
13
14
  cert_chain: []
14
- date: 2013-03-22 00:00:00.000000000 Z
15
+ date: 2013-04-07 00:00:00.000000000 Z
15
16
  dependencies:
16
17
  - !ruby/object:Gem::Dependency
17
18
  name: padrino-core
18
19
  requirement: !ruby/object:Gem::Requirement
20
+ none: false
19
21
  requirements:
20
22
  - - '='
21
23
  - !ruby/object:Gem::Version
22
- version: 0.11.0
24
+ version: 0.11.1
23
25
  type: :runtime
24
26
  prerelease: false
25
27
  version_requirements: !ruby/object:Gem::Requirement
28
+ none: false
26
29
  requirements:
27
30
  - - '='
28
31
  - !ruby/object:Gem::Version
29
- version: 0.11.0
32
+ version: 0.11.1
30
33
  - !ruby/object:Gem::Dependency
31
34
  name: bundler
32
35
  requirement: !ruby/object:Gem::Requirement
36
+ none: false
33
37
  requirements:
34
38
  - - ~>
35
39
  - !ruby/object:Gem::Version
@@ -37,6 +41,7 @@ dependencies:
37
41
  type: :runtime
38
42
  prerelease: false
39
43
  version_requirements: !ruby/object:Gem::Requirement
44
+ none: false
40
45
  requirements:
41
46
  - - ~>
42
47
  - !ruby/object:Gem::Version
@@ -160,27 +165,31 @@ files:
160
165
  - lib/padrino-gen/generators/templates/static/ujs/right.js
161
166
  homepage: http://www.padrinorb.com
162
167
  licenses: []
163
- metadata: {}
164
168
  post_install_message:
165
169
  rdoc_options:
166
170
  - --charset=UTF-8
167
171
  require_paths:
168
172
  - lib
169
173
  required_ruby_version: !ruby/object:Gem::Requirement
174
+ none: false
170
175
  requirements:
171
- - - '>='
176
+ - - ! '>='
172
177
  - !ruby/object:Gem::Version
173
178
  version: '0'
179
+ segments:
180
+ - 0
181
+ hash: 1271294022320842473
174
182
  required_rubygems_version: !ruby/object:Gem::Requirement
183
+ none: false
175
184
  requirements:
176
- - - '>='
185
+ - - ! '>='
177
186
  - !ruby/object:Gem::Version
178
187
  version: 1.3.6
179
188
  requirements: []
180
189
  rubyforge_project: padrino-gen
181
- rubygems_version: 2.0.3
190
+ rubygems_version: 1.8.25
182
191
  signing_key:
183
- specification_version: 4
192
+ specification_version: 3
184
193
  summary: Generators for easily creating and building padrino applications
185
194
  test_files:
186
195
  - test/fixtures/admin_template.rb
checksums.yaml DELETED
@@ -1,7 +0,0 @@
1
- ---
2
- SHA1:
3
- metadata.gz: 7a6a1654d8ee352072e435cb364d88153983be16
4
- data.tar.gz: 42ca8996ee141fa779627859b7d95e454d5ef3b9
5
- SHA512:
6
- metadata.gz: 1ac55f683cba6782dc31abcb5e8732f45ced510600415b0ee2d0681b32cdfcd703526ff2136651bb2d70192db37dd47a02ebfa3624a956766b33fbcae27e2ff3
7
- data.tar.gz: 95d1e97c9a31b4d25290305f6fc45ca8ca14afe03e20949a14eecd203100fbdd1d3952238fea09a71d9e28f3637ed59641f0cda8e508c97d2fbecb7699fc716a