padrino-gen 0.13.1 → 0.13.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (35) hide show
  1. checksums.yaml +4 -4
  2. data/lib/padrino-gen/generators/actions.rb +16 -4
  3. data/lib/padrino-gen/generators/app/app.rb.tt +2 -1
  4. data/lib/padrino-gen/generators/components/actions.rb +2 -2
  5. data/lib/padrino-gen/generators/components/orms/activerecord.rb +1 -1
  6. data/lib/padrino-gen/generators/components/orms/mongoid.rb +19 -38
  7. data/lib/padrino-gen/generators/components/stylesheets/compass.rb +4 -15
  8. data/lib/padrino-gen/generators/components/tests/bacon.rb +2 -0
  9. data/lib/padrino-gen/generators/components/tests/minitest.rb +2 -0
  10. data/lib/padrino-gen/generators/components/tests/riot.rb +2 -0
  11. data/lib/padrino-gen/generators/components/tests/rspec.rb +2 -0
  12. data/lib/padrino-gen/generators/components/tests/shoulda.rb +2 -0
  13. data/lib/padrino-gen/generators/components/tests/steak.rb +2 -0
  14. data/lib/padrino-gen/generators/components/tests/testunit.rb +2 -0
  15. data/lib/padrino-gen/generators/controller.rb +1 -0
  16. data/lib/padrino-gen/generators/helper.rb +1 -0
  17. data/lib/padrino-gen/generators/mailer.rb +1 -0
  18. data/lib/padrino-gen/generators/migration.rb +1 -0
  19. data/lib/padrino-gen/generators/plugin.rb +1 -1
  20. data/lib/padrino-gen/generators/project/config/boot.rb +7 -0
  21. data/lib/padrino-gen/generators/project.rb +2 -1
  22. data/lib/padrino-gen/generators/task.rb +1 -0
  23. data/lib/padrino-gen/generators/templates/Gemfile.tt +10 -0
  24. data/lib/padrino-gen/generators/templates/Rakefile.tt +2 -0
  25. data/lib/padrino-gen/padrino-tasks/activerecord.rb +6 -0
  26. data/test/helper.rb +14 -1
  27. data/test/test_controller_generator.rb +5 -0
  28. data/test/test_helper_generator.rb +5 -0
  29. data/test/test_mailer_generator.rb +5 -0
  30. data/test/test_migration_generator.rb +5 -0
  31. data/test/test_model_generator.rb +24 -24
  32. data/test/test_plugin_generator.rb +4 -0
  33. data/test/test_project_generator.rb +6 -6
  34. data/test/test_task_generator.rb +5 -0
  35. metadata +16 -16
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ffd35b1d91f0fae811dc120c23aaa1e79e95895a
4
- data.tar.gz: 145252cb719e477feb79942d12557d853653c6a8
3
+ metadata.gz: 1f8ab7a90610830c747530e9eac64e54a8448461
4
+ data.tar.gz: f312d806fb6dc5a75457005f929afa3573e62c22
5
5
  SHA512:
6
- metadata.gz: e9f450584438e351b0d5210a4f009b00971aefffdbe6c3a2dd6088384ae6358713f35e246e60e230780b98cd9cac23c0d7df170b0f9c1c3a171de59bfae55479
7
- data.tar.gz: 44e0973081ea1543b52045ee2765fceb90aa4e96f1077d4090555a9b7bf7d97614190182095db7757a5e3a45ffc3924fbb53a8b7a14cc7ad4330a27d66377f84
6
+ metadata.gz: 04cc205b2b510cd07a67c4390864ac27a727f5dceb5657a4985bad59c91a6708f7279198ce5c2c68448d8462b22de1363da5082faa4f75e718138f159abe3d69
7
+ data.tar.gz: 5658e955f42db155d572f671686d8c75e35790ff4c5ed840346125ad4d2d5b6f6f8acb4bb57f56ee01c3d784e5082706b4ff1e14330ed69c8dc7cae35191ebbd
@@ -377,9 +377,9 @@ WARNING
377
377
  #
378
378
  def initializer(name, data=nil)
379
379
  @_init_name, @_init_data = name, data
380
- register = data.present? ? " register #{name.to_s.underscore.camelize}Initializer\n" : " register #{name}\n"
380
+ register = data ? " register #{name.to_s.underscore.camelize}Initializer\n" : " register #{name}\n"
381
381
  inject_into_file destination_root("/app/app.rb"), register, :after => "Padrino::Application\n"
382
- template "templates/initializer.rb.tt", destination_root("/lib/#{name}_initializer.rb") if data.present?
382
+ template "templates/initializer.rb.tt", destination_root("/config/initializers/#{name}.rb") if data
383
383
  end
384
384
 
385
385
  ##
@@ -520,12 +520,24 @@ WARNING
520
520
  #
521
521
  def valid_constant?(name)
522
522
  if name =~ /^\d/
523
- raise ::NameError, "Project name #{name} cannot start with numbers"
523
+ fail ::NameError, "Constant name #{name} cannot start with numbers"
524
524
  elsif name =~ /^\W/
525
- raise ::NameError, "Project name #{name} cannot start with non-word character"
525
+ fail ::NameError, "Constant name #{name} cannot start with non-word character"
526
526
  end
527
527
  end
528
528
 
529
+ ##
530
+ # Validates namespace name (controller name, etc.) or fails with an error.
531
+ #
532
+ # @example
533
+ # validate_namespace 'Project_One1' #=> pass
534
+ # validate_namespace 'Erroneous/name' #=> fail
535
+ #
536
+ def validate_namespace(name)
537
+ valid_constant? name
538
+ name.match(/^[[:alnum:]_]+$/) || fail(::NameError, "Namespace '#{name}' must consist only of alphanumeric characters or '_'")
539
+ end
540
+
529
541
  ##
530
542
  # Recognizes the path of application.
531
543
  #
@@ -1,8 +1,9 @@
1
1
  module <%= @project_name %>
2
2
  class <%= @app_name %> < Padrino::Application
3
+ <% unless options.api? -%>
3
4
  register Padrino::Mailer
4
5
  register Padrino::Helpers
5
-
6
+ <% end -%>
6
7
  enable :sessions
7
8
 
8
9
  ##
@@ -144,7 +144,7 @@ module Padrino
144
144
  # => inject_into_file("test/test_config.rb", TEST.gsub(/CLASS_NAME/, @app_name), :after => "set :environment, :test")
145
145
  #
146
146
  def insert_test_suite_setup(suite_text, options={})
147
- options.reverse_merge!(:path => "test/test_config.rb")
147
+ options = { :path => "test/test_config.rb" }.update(options)
148
148
  create_file(options[:path], suite_text.gsub(/CLASS_NAME/, "#{@project_name}::#{@app_name}"))
149
149
  end
150
150
 
@@ -161,7 +161,7 @@ module Padrino
161
161
  # => inject_into_file("test/test_config.rb", " include Mocha::API\n", :after => /class.*?\n/)
162
162
  #
163
163
  def insert_mocking_include(library_name, options={})
164
- options.reverse_merge!(:indent => 2, :after => /class.*?\n/, :path => "test/test_config.rb")
164
+ options = { :indent => 2, :after => /class.*?\n/, :path => "test/test_config.rb" }.update(options)
165
165
  return unless File.exist?(destination_root(options[:path]))
166
166
  include_text = indent_spaces(2) + "include #{library_name}\n"
167
167
  inject_into_file(options[:path], include_text, :after => options[:after])
@@ -168,7 +168,7 @@ MIGRATION
168
168
  AR_MODEL_UP_MG = (<<-MIGRATION).gsub(/^/,' ') unless defined?(AR_MODEL_UP_MG)
169
169
  create_table :!TABLE! do |t|
170
170
  !FIELDS!
171
- t.timestamps
171
+ t.timestamps null: false
172
172
  end
173
173
  MIGRATION
174
174
 
@@ -1,31 +1,4 @@
1
1
  MONGOID = (<<-MONGO) unless defined?(MONGOID)
2
- # Connection.new takes host and port
3
- host = 'localhost'
4
- port = Mongo::Connection::DEFAULT_PORT
5
-
6
- database_name = case Padrino.env
7
- when :development then '!NAME!_development'
8
- when :production then '!NAME!_production'
9
- when :test then '!NAME!_test'
10
- end
11
-
12
- Mongoid.database = Mongo::Connection.new(host, port).db(database_name)
13
-
14
- # You can also configure Mongoid this way:
15
- # Mongoid.configure do |config|
16
- # name = @settings["database"]
17
- # host = @settings["host"]
18
- # config.master = Mongo::Connection.new.db(name)
19
- # config.slaves = [
20
- # Mongo::Connection.new(host, @settings["slave_one"]["port"], :slave_ok => true).db(name),
21
- # Mongo::Connection.new(host, @settings["slave_two"]["port"], :slave_ok => true).db(name)
22
- # ]
23
- # end
24
- #
25
- # More installation and setup notes are on http://mongoid.org/.
26
- MONGO
27
-
28
- MONGOID3 = (<<-MONGO) unless defined?(MONGOID3)
29
2
  # Connection.new takes host and port.
30
3
 
31
4
  host = 'localhost'
@@ -38,12 +11,18 @@ database_name = case Padrino.env
38
11
  end
39
12
 
40
13
  # Use MONGO_URI if it's set as an environmental variable.
41
- Mongoid::Config.sessions =
42
- if ENV['MONGO_URI']
43
- {default: {uri: ENV['MONGO_URI'] }}
44
- else
45
- {default: {hosts: ["#\{host\}:#\{port\}"], database: database_name}}
46
- end
14
+ database_settings = if ENV['MONGO_URI']
15
+ {default: {uri: ENV['MONGO_URI'] }}
16
+ else
17
+ {default: {hosts: ["#\{host\}:#\{port\}"], database: database_name}}
18
+ end
19
+
20
+ case Mongoid::VERSION
21
+ when /^(3|4)/
22
+ Mongoid::Config.sessions = database_settings
23
+ else
24
+ Mongoid::Config.load_configuration :clients => database_settings
25
+ end
47
26
 
48
27
  # If you want to use a YML file for config, use this instead:
49
28
  #
@@ -51,31 +30,33 @@ Mongoid::Config.sessions =
51
30
  #
52
31
  # And add a config/database.yml file like this:
53
32
  # development:
54
- # sessions:
33
+ # clients: #Replace clients with sessions to work with Mongoid version 3.x or 4.x
55
34
  # default:
56
35
  # database: !NAME!_development
57
36
  # hosts:
58
37
  # - localhost:27017
38
+ #
59
39
  # production:
60
- # sessions:
40
+ # clients: #Replace clients with sessions to work with Mongoid version 3.x or 4.x
61
41
  # default:
62
42
  # database: !NAME!_production
63
43
  # hosts:
64
44
  # - localhost:27017
45
+ #
65
46
  # test:
66
- # sessions:
47
+ # clients: #Replace clients with sessions to work with Mongoid version 3.x or 4.x
67
48
  # default:
68
49
  # database: !NAME!_test
69
50
  # hosts:
70
51
  # - localhost:27017
71
52
  #
72
53
  #
73
- # More installation and setup notes are on http://mongoid.org/en/mongoid/docs/installation.html#configuration
54
+ # More installation and setup notes are on https://docs.mongodb.org/ecosystem/tutorial/mongoid-installation/
74
55
  MONGO
75
56
 
76
57
  def setup_orm
77
58
  require_dependencies 'mongoid', :version => '>= 3.0.0'
78
- create_file('config/database.rb', MONGOID3.gsub(/!NAME!/, @project_name.underscore))
59
+ create_file('config/database.rb', MONGOID.gsub(/!NAME!/, @project_name.underscore))
79
60
  end
80
61
 
81
62
  MONGOID_MODEL = (<<-MODEL) unless defined?(MONGOID_MODEL)
@@ -1,10 +1,7 @@
1
1
  COMPASS_INIT = <<-COMPASS unless defined?(COMPASS_INIT)
2
- # Enables support for Compass, a stylesheet authoring framework based on SASS.
3
- # See http://compass-style.org/ for more details.
4
- # Store Compass/SASS files (by default) within 'app/stylesheets'.
5
-
6
- module CompassInitializer
7
- def self.registered(app)
2
+ # Enables support for Compass, a stylesheet authoring framework based on SASS.
3
+ # See http://compass-style.org/ for more details.
4
+ # Store Compass/SASS files (by default) within 'app/stylesheets'.
8
5
  require 'sass/plugin/rack'
9
6
 
10
7
  Compass.configuration do |config|
@@ -22,18 +19,10 @@ module CompassInitializer
22
19
  Compass.handle_configuration_change!
23
20
 
24
21
  app.use Sass::Plugin::Rack
25
- end
26
- end
27
22
  COMPASS
28
23
 
29
- COMPASS_REGISTER = <<-COMPASSR unless defined?(COMPASS_REGISTER)
30
- register CompassInitializer\n
31
- COMPASSR
32
-
33
24
  def setup_stylesheet
34
25
  require_dependencies 'compass-blueprint'
35
- create_file destination_root('/lib/compass_plugin.rb'), COMPASS_INIT
36
- inject_into_file destination_root('/app/app.rb'), COMPASS_REGISTER, :after => "register Padrino::Helpers\n"
37
-
26
+ initializer :compass, COMPASS_INIT.chomp
38
27
  directory "components/stylesheets/compass/", destination_root('/app/stylesheets')
39
28
  end
@@ -47,6 +47,8 @@ end
47
47
 
48
48
  desc "Run application test suite"
49
49
  task 'test' => test_tasks.map { |f| "test:\#{f}" }
50
+
51
+ task :default => :test
50
52
  TEST
51
53
 
52
54
  BACON_MODEL_TEST = (<<-TEST).gsub(/^ {10}/, '') unless defined?(BACON_MODEL_TEST)
@@ -36,6 +36,8 @@ end
36
36
 
37
37
  desc "Run application test suite"
38
38
  task 'test' => test_tasks.map { |f| "test:\#{f}" }
39
+
40
+ task :default => :test
39
41
  TEST
40
42
 
41
43
  MINITEST_CONTROLLER_TEST = (<<-TEST).gsub(/^ {10}/, '') unless defined?(MINITEST_CONTROLLER_TEST)
@@ -59,6 +59,8 @@ end
59
59
 
60
60
  desc "Run application test suite"
61
61
  task 'test' => test_tasks.map { |f| "test:\#{f}" }
62
+
63
+ task :default => :test
62
64
  TEST
63
65
 
64
66
  RIOT_MODEL_TEST = (<<-TEST).gsub(/^ {10}/, '') unless defined?(RIOT_MODEL_TEST)
@@ -61,6 +61,8 @@ rescue LoadError
61
61
  puts "RSpec is not part of this bundle, skip specs."
62
62
  end
63
63
  end
64
+
65
+ task :default => :spec
64
66
  TEST
65
67
 
66
68
  RSPEC_MODEL_TEST = (<<-TEST).gsub(/^ {12}/, '') unless defined?(RSPEC_MODEL_TEST)
@@ -54,6 +54,8 @@ end
54
54
 
55
55
  desc "Run application test suite"
56
56
  task 'test' => test_tasks.map { |f| "test:\#{f}" }
57
+
58
+ task :default => :test
57
59
  TEST
58
60
 
59
61
  SHOULDA_MODEL_TEST = (<<-TEST).gsub(/^ {10}/, '') unless defined?(SHOULDA_MODEL_TEST)
@@ -60,6 +60,8 @@ end
60
60
 
61
61
  desc "Run complete application spec suite"
62
62
  task 'spec' => spec_tasks.map { |f| "spec:\#{f}" }
63
+
64
+ task :default => :spec
63
65
  TEST
64
66
 
65
67
  STEAK_MODEL_TEST = (<<-TEST).gsub(/^ {12}/, '') unless defined?(STEAK_MODEL_TEST)
@@ -36,6 +36,8 @@ end
36
36
 
37
37
  desc "Run application test suite"
38
38
  task 'test' => test_tasks.map { |f| "test:\#{f}" }
39
+
40
+ task :default => :test
39
41
  TEST
40
42
 
41
43
  TESTUNIT_CONTROLLER_TEST = (<<-TEST).gsub(/^ {10}/, '') unless defined?(TESTUNIT_CONTROLLER_TEST)
@@ -36,6 +36,7 @@ module Padrino
36
36
  # Execute controller generation
37
37
  #
38
38
  def create_controller
39
+ validate_namespace name
39
40
  self.destination_root = options[:root]
40
41
  if in_app_root?
41
42
  app = options[:app]
@@ -30,6 +30,7 @@ module Padrino
30
30
  # Execute helper generation
31
31
  #
32
32
  def create_helper
33
+ validate_namespace name
33
34
  self.destination_root = options[:root]
34
35
  if in_app_root?
35
36
  app = options[:app]
@@ -30,6 +30,7 @@ module Padrino
30
30
  # Execute mailer generation.
31
31
  #
32
32
  def create_mailer
33
+ validate_namespace name
33
34
  self.destination_root = options[:root]
34
35
  if in_app_root?
35
36
  app = options[:app]
@@ -25,6 +25,7 @@ module Padrino
25
25
 
26
26
  # Creates the migration file within a Padrino project.
27
27
  def create_migration
28
+ validate_namespace name
28
29
  self.destination_root = options[:root]
29
30
  if in_app_root?
30
31
  self.behavior = :revoke if options[:destroy]
@@ -55,7 +55,7 @@ module Padrino
55
55
  http.verify_mode = OpenSSL::SSL::VERIFY_NONE
56
56
  http.start do
57
57
  http.request_get(uri.path) do |res|
58
- plugins = res.body.scan(%r{/plugins/(\w+)_plugin.rb}).uniq
58
+ plugins = res.body.scan(%r{/plugins/(\w+-\w+)_plugin.rb}).uniq
59
59
  end
60
60
  end
61
61
  say "Available plugins:", :green
@@ -34,8 +34,15 @@ Bundler.require(:default, RACK_ENV)
34
34
  # include Padrino::Helpers::TranslationHelpers
35
35
  # end
36
36
 
37
+ ##
38
+ # Require initializers before all other dependencies.
39
+ # Dependencies from 'config' folder are NOT re-required on reload.
40
+ #
41
+ Padrino.dependency_paths.unshift Padrino.root('config/initializers/*.rb')
42
+
37
43
  ##
38
44
  # Add your before (RE)load hooks here
45
+ # These hooks are run before any dependencies are required.
39
46
  #
40
47
  Padrino.before_load do
41
48
  end
@@ -27,10 +27,11 @@ module Padrino
27
27
  class_option :dev, :desc => 'Use padrino from a git checkout', :default => false, :type => :boolean
28
28
  class_option :tiny, :desc => 'Generate tiny app skeleton', :aliases => '-i', :default => false, :type => :boolean
29
29
  class_option :lean, :desc => 'Generate lean project without apps', :aliases => '-l', :default => false, :type => :boolean
30
- class_option :adapter, :desc => 'SQL adapter for ORM (sqlite, mysql, mysql2, mysql-gem, postgres)', :aliases => '-a', :default => 'sqlite', :type => :string
30
+ class_option :api, :desc => 'Generate minimal project for APIs', :default => false, :type => :boolean
31
31
  class_option :template, :desc => 'Generate project from template', :aliases => '-p', :default => nil, :type => :string
32
32
  class_option :gem, :desc => 'Generate project as a gem', :aliases => '-g', :default => false, :type => :boolean
33
33
  class_option :migration_format, :desc => 'Filename format for migrations (number, timestamp)', :default => 'number', :type => :string
34
+ class_option :adapter, :desc => 'SQL adapter for ORM (sqlite, mysql, mysql2, mysql-gem, postgres)', :aliases => '-a', :default => 'sqlite', :type => :string
34
35
 
35
36
  # Definitions for the available customizable components.
36
37
  defines_component_options
@@ -26,6 +26,7 @@ module Padrino
26
26
  require_arguments!
27
27
 
28
28
  def create_task
29
+ validate_namespace name
29
30
  self.destination_root = options[:root]
30
31
  if in_app_root?
31
32
  app = options[:app]
@@ -20,6 +20,15 @@ gem 'rake'
20
20
 
21
21
  # Test requirements
22
22
 
23
+ <% if options.api? -%>
24
+ <% if options.dev? -%>
25
+ gem 'padrino-core', :path => '<%= Padrino::Generators::DEV_PATH %>/padrino-core'
26
+ gem 'padrino-gen', :path => '<%= Padrino::Generators::DEV_PATH %>/padrino-gen'
27
+ <% else -%>
28
+ gem 'padrino-core', '<%= Padrino.version %>'
29
+ gem 'padrino-gen', '<%= Padrino.version %>'
30
+ <% end -%>
31
+ <% else -%>
23
32
  # Padrino Stable Gem
24
33
  <% if options.dev? %># <% end %>gem 'padrino', '<%= Padrino.version %>'
25
34
 
@@ -30,3 +39,4 @@ gem 'rake'
30
39
  <% unless options.dev? %># <% end %>%w(core support gen helpers cache mailer admin).each do |g|
31
40
  <% unless options.dev? %># <% end %> gem 'padrino-' + g, <% if options.dev? %>:path => '<%= Padrino::Generators::DEV_PATH %>/padrino-' + g<% else %>'<%= Padrino.version %>'<% end %>
32
41
  <% unless options.dev? %># <% end %>end
42
+ <% end -%>
@@ -6,3 +6,5 @@ PadrinoTasks.use(:database)
6
6
  PadrinoTasks.use(<%= options[:orm].to_sym.inspect %>)
7
7
  <%- end -%>
8
8
  PadrinoTasks.init
9
+
10
+ task :default => :test
@@ -309,6 +309,12 @@ if PadrinoTasks.load?(:activerecord, defined?(ActiveRecord))
309
309
  puts
310
310
  end
311
311
  end
312
+
313
+ task :seed => :environment do
314
+ missing_model_features = Padrino.send(:default_dependency_paths) - Padrino.send(:dependency_paths)
315
+ Padrino.require_dependencies(missing_model_features)
316
+ Rake::Task['db:seed'].invoke
317
+ end
312
318
  end
313
319
 
314
320
  def drop_database(config)
data/test/helper.rb CHANGED
@@ -14,6 +14,19 @@ require 'ext/minitest-spec'
14
14
 
15
15
  Padrino::Generators.load_components!
16
16
 
17
+ # register fake URL to avoid downloading static files every time tests run
18
+ fake_uri_base = "https://raw.github.com/padrino/padrino-static/master/"
19
+ %W[
20
+ js/dojo.js ujs/dojo.js
21
+ js/ext.js ujs/ext.js
22
+ js/jquery.js ujs/jquery.js
23
+ js/mootools.js ujs/mootools.js
24
+ js/right.js ujs/right.js
25
+ js/protopak.js js/lowpro.js ujs/prototype.js
26
+ ].each do |suffix|
27
+ FakeWeb.register_uri(:get, fake_uri_base + suffix, :body => '')
28
+ end
29
+
17
30
  class MiniTest::Spec
18
31
  include Webrat::Methods
19
32
  include Webrat::Matchers
@@ -79,7 +92,7 @@ class MiniTest::Spec
79
92
  # expects_initializer :test, "# Example"
80
93
  def expects_initializer(name, body,options={})
81
94
  #options.reverse_merge!(:root => "/tmp/sample_project")
82
- path = File.join(options[:root],'lib',"#{name}_initializer.rb")
95
+ path = File.join(options[:root],'config/initializers',"#{name}.rb")
83
96
  instance = mock
84
97
  instance.expects(:invoke!).at_least_once
85
98
  include_text = " register #{name.to_s.camelize}Initializer\n"
@@ -22,6 +22,11 @@ describe "ControllerGenerator" do
22
22
  assert_no_file_exists("#{@apptmp}/app/controllers/demo.rb")
23
23
  end
24
24
 
25
+ it 'should fail with NameError if given invalid namespace names' do
26
+ capture_io { generate(:project, "sample", "--root=#{@apptmp}") }
27
+ assert_raises(::NameError) { capture_io { generate(:controller, "wrong/name", "--root=#{@apptmp}/sample") } }
28
+ end
29
+
25
30
  it 'should generate controller within existing project' do
26
31
  capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=bacon') }
27
32
  capture_io { generate(:controller, 'DemoItems', "-r=#{@apptmp}/sample_project") }
@@ -19,6 +19,11 @@ describe "HelperGenerator" do
19
19
  assert_no_file_exists("#{@apptmp}/app/helpers/demo_helper.rb")
20
20
  end
21
21
 
22
+ it 'should fail with NameError if given invalid namespace names' do
23
+ capture_io { generate(:project, "sample", "--root=#{@apptmp}") }
24
+ assert_raises(::NameError) { capture_io { generate(:helper, "wrong/name", "--root=#{@apptmp}/sample") } }
25
+ end
26
+
22
27
  it 'should generate helper within existing project' do
23
28
  capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=bacon') }
24
29
  capture_io { generate(:helper, 'DemoItems', "-r=#{@apptmp}/sample_project") }
@@ -17,6 +17,11 @@ describe "MailerGenerator" do
17
17
  assert_no_file_exists('/tmp/app/mailers/demo_mailer.rb')
18
18
  end
19
19
 
20
+ it 'should fail with NameError if given invalid namespace names' do
21
+ capture_io { generate(:project, "sample", "--root=#{@apptmp}") }
22
+ assert_raises(::NameError) { capture_io { generate(:mailer, "wrong/name", "--root=#{@apptmp}/sample") } }
23
+ end
24
+
20
25
  it 'should generate mailer in specified app' do
21
26
  capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=bacon') }
22
27
  capture_io { generate(:app, 'subby', "-r=#{@apptmp}/sample_project") }
@@ -17,6 +17,11 @@ describe "MigrationGenerator" do
17
17
  assert_no_file_exists("#{@apptmp}/db/migrate")
18
18
  end
19
19
 
20
+ it 'should fail with NameError if given invalid namespace names' do
21
+ capture_io { generate(:project, "sample", "--root=#{@apptmp}") }
22
+ assert_raises(::NameError) { capture_io { generate(:migration, "wrong/name", "--root=#{@apptmp}/sample") } }
23
+ end
24
+
20
25
  it 'should fail if we do not use an adapter' do
21
26
  capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=bacon') }
22
27
  assert_raises(SystemExit) { capture_io { generate(:migration, 'AddEmailToUsers', "-r=#{@apptmp}/sample_project") } }
@@ -79,14 +79,14 @@ describe "ModelGenerator" do
79
79
  it 'should generate a default type value for fields' do
80
80
  current_time = stop_time_for_test.strftime("%Y%m%d%H%M%S")
81
81
  capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=bacon', '-d=activerecord') }
82
- capture_io { generate(:model, 'person', "name", "age:integer", "email", "-r=#{@apptmp}/sample_project") }
83
- migration_file_path = "#{@apptmp}/sample_project/db/migrate/001_create_people.rb"
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)
82
+ capture_io { generate(:model, 'friend', "name", "age:integer", "email", "-r=#{@apptmp}/sample_project") }
83
+ migration_file_path = "#{@apptmp}/sample_project/db/migrate/001_create_friends.rb"
84
+ assert_match_in_file(/class CreateFriends < ActiveRecord::Migration/m, migration_file_path)
85
+ assert_match_in_file(/ create_table :friends/m, migration_file_path)
86
86
  assert_match_in_file(/ t.string :name/m, migration_file_path)
87
87
  assert_match_in_file(/ t.integer :age/m, migration_file_path)
88
88
  assert_match_in_file(/ t.string :email/m, migration_file_path)
89
- assert_match_in_file(/ drop_table :people/m, migration_file_path)
89
+ assert_match_in_file(/ drop_table :friends/m, migration_file_path)
90
90
  end
91
91
 
92
92
  it 'should abort if model name already exists' do
@@ -149,14 +149,14 @@ describe "ModelGenerator" do
149
149
  it 'should generate migration file with given fields' do
150
150
  current_time = stop_time_for_test.strftime("%Y%m%d%H%M%S")
151
151
  capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=bacon', '-d=activerecord') }
152
- capture_io { generate(:model, 'person', "name:string", "age:integer", "email:string", "-r=#{@apptmp}/sample_project") }
153
- migration_file_path = "#{@apptmp}/sample_project/db/migrate/001_create_people.rb"
154
- assert_match_in_file(/class CreatePeople < ActiveRecord::Migration/m, migration_file_path)
155
- assert_match_in_file(/ create_table :people/m, migration_file_path)
152
+ capture_io { generate(:model, 'friend', "name:string", "age:integer", "email:string", "-r=#{@apptmp}/sample_project") }
153
+ migration_file_path = "#{@apptmp}/sample_project/db/migrate/001_create_friends.rb"
154
+ assert_match_in_file(/class CreateFriends < ActiveRecord::Migration/m, migration_file_path)
155
+ assert_match_in_file(/ create_table :friends/m, migration_file_path)
156
156
  assert_match_in_file(/ t.string :name/m, migration_file_path)
157
157
  assert_match_in_file(/ t.integer :age/m, migration_file_path)
158
158
  assert_match_in_file(/ t.string :email/m, migration_file_path)
159
- assert_match_in_file(/ drop_table :people/m, migration_file_path)
159
+ assert_match_in_file(/ drop_table :friends/m, migration_file_path)
160
160
  end
161
161
  end
162
162
 
@@ -239,12 +239,12 @@ describe "ModelGenerator" do
239
239
  it 'should properly generate version numbers' do
240
240
  capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-d=datamapper') }
241
241
  capture_io { generate(:model, 'user', "name:string", "age:integer", "created_at:datetime", "-r=#{@apptmp}/sample_project") }
242
- capture_io { generate(:model, 'person', "name:string", "age:integer", "created_at:datetime", "-r=#{@apptmp}/sample_project") }
242
+ capture_io { generate(:model, 'friend', "name:string", "age:integer", "created_at:datetime", "-r=#{@apptmp}/sample_project") }
243
243
  capture_io { generate(:model, 'account', "name:string", "age:integer", "created_at:datetime", "-r=#{@apptmp}/sample_project") }
244
244
  assert_match_in_file(/class User\n\s+include DataMapper::Resource/m, "#{@apptmp}/sample_project/models/user.rb")
245
245
  assert_match_in_file(/migration 1, :create_users do/m, "#{@apptmp}/sample_project/db/migrate/001_create_users.rb")
246
- assert_match_in_file(/class Person\n\s+include DataMapper::Resource/m, "#{@apptmp}/sample_project/models/person.rb")
247
- assert_match_in_file(/migration 2, :create_people do/m, "#{@apptmp}/sample_project/db/migrate/002_create_people.rb")
246
+ assert_match_in_file(/class Friend\n\s+include DataMapper::Resource/m, "#{@apptmp}/sample_project/models/friend.rb")
247
+ assert_match_in_file(/migration 2, :create_friends do/m, "#{@apptmp}/sample_project/db/migrate/002_create_friends.rb")
248
248
  assert_match_in_file(/class Account\n\s+include DataMapper::Resource/m, "#{@apptmp}/sample_project/models/account.rb")
249
249
  assert_match_in_file(/migration 3, :create_accounts do/m, "#{@apptmp}/sample_project/db/migrate/003_create_accounts.rb")
250
250
  end
@@ -252,15 +252,15 @@ describe "ModelGenerator" do
252
252
  it 'should generate migration with given fields' do
253
253
  current_time = stop_time_for_test.strftime("%Y%m%d%H%M%S")
254
254
  capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-d=datamapper') }
255
- capture_io { generate(:model, 'person', "name:string", "created_at:date_time", "email:string", "-r=#{@apptmp}/sample_project") }
256
- assert_match_in_file(/class Person\n\s+include DataMapper::Resource/m, "#{@apptmp}/sample_project/models/person.rb")
257
- migration_file_path = "#{@apptmp}/sample_project/db/migrate/001_create_people.rb"
258
- assert_match_in_file(/migration 1, :create_people do/m, migration_file_path)
259
- assert_match_in_file(/create_table :people do/m, migration_file_path)
255
+ capture_io { generate(:model, 'friend', "name:string", "created_at:date_time", "email:string", "-r=#{@apptmp}/sample_project") }
256
+ assert_match_in_file(/class Friend\n\s+include DataMapper::Resource/m, "#{@apptmp}/sample_project/models/friend.rb")
257
+ migration_file_path = "#{@apptmp}/sample_project/db/migrate/001_create_friends.rb"
258
+ assert_match_in_file(/migration 1, :create_friends do/m, migration_file_path)
259
+ assert_match_in_file(/create_table :friends do/m, migration_file_path)
260
260
  assert_match_in_file(/column :name, DataMapper::Property::String/m, migration_file_path)
261
261
  assert_match_in_file(/column :created_at, DataMapper::Property::DateTime/m, migration_file_path)
262
262
  assert_match_in_file(/column :email, DataMapper::Property::String/m, migration_file_path)
263
- assert_match_in_file(/drop_table :people/m, migration_file_path)
263
+ assert_match_in_file(/drop_table :friends/m, migration_file_path)
264
264
  end
265
265
  end
266
266
 
@@ -282,15 +282,15 @@ describe "ModelGenerator" do
282
282
  it 'should generate migration file with given properties' do
283
283
  current_time = stop_time_for_test.strftime("%Y%m%d%H%M%S")
284
284
  capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-d=sequel') }
285
- capture_io { generate(:model, 'person', "name:string", "age:integer", "created:datetime", "-r=#{@apptmp}/sample_project") }
286
- migration_file_path = "#{@apptmp}/sample_project/db/migrate/001_create_people.rb"
287
- assert_match_in_file(/class Person < Sequel::Model/m, "#{@apptmp}/sample_project/models/person.rb")
285
+ capture_io { generate(:model, 'friend', "name:string", "age:integer", "created:datetime", "-r=#{@apptmp}/sample_project") }
286
+ migration_file_path = "#{@apptmp}/sample_project/db/migrate/001_create_friends.rb"
287
+ assert_match_in_file(/class Friend < Sequel::Model/m, "#{@apptmp}/sample_project/models/friend.rb")
288
288
  assert_match_in_file(/Sequel\.migration do/m, migration_file_path)
289
- assert_match_in_file(/create_table :people/m, migration_file_path)
289
+ assert_match_in_file(/create_table :friends/m, migration_file_path)
290
290
  assert_match_in_file(/String :name/m, migration_file_path)
291
291
  assert_match_in_file(/Integer :age/m, migration_file_path)
292
292
  assert_match_in_file(/DateTime :created/m, migration_file_path)
293
- assert_match_in_file(/drop_table :people/m, migration_file_path)
293
+ assert_match_in_file(/drop_table :friends/m, migration_file_path)
294
294
  end
295
295
  end
296
296
 
@@ -54,6 +54,7 @@ describe "PluginGenerator" do
54
54
 
55
55
  it 'should resolve generic url properly' do
56
56
  template_file = 'http://www.example.com/test.rb'
57
+ FakeWeb.register_uri :get, template_file, :body => ''
57
58
  project_gen = Padrino::Generators::Project.new(['sample_project'], ["-p=#{template_file}", "-r=#{@apptmp}"], {})
58
59
  project_gen.expects(:apply).with(template_file).returns(true).once
59
60
  capture_io { project_gen.invoke_all }
@@ -71,6 +72,7 @@ describe "PluginGenerator" do
71
72
  it 'should resolve official template' do
72
73
  template_file = 'sampleblog'
73
74
  resolved_path = "https://raw.github.com/padrino/padrino-recipes/master/templates/sampleblog_template.rb"
75
+ FakeWeb.register_uri :get, resolved_path, :body => template_file
74
76
  project_gen = Padrino::Generators::Project.new(['sample_project'], ["-p=#{template_file}", "-r=#{@apptmp}"], {})
75
77
  project_gen.expects(:apply).with(resolved_path).returns(true).once
76
78
  capture_io { project_gen.invoke_all }
@@ -86,6 +88,7 @@ describe "PluginGenerator" do
86
88
  it 'should resolve official plugin' do
87
89
  template_file = 'hoptoad'
88
90
  resolved_path = "https://raw.github.com/padrino/padrino-recipes/master/plugins/hoptoad_plugin.rb"
91
+ FakeWeb.register_uri :get, resolved_path, :body => template_file
89
92
  plugin_gen = Padrino::Generators::Plugin.new([ template_file], ["-r=#{@apptmp}/sample_project"],{})
90
93
  plugin_gen.expects(:in_app_root?).returns(true).once
91
94
  plugin_gen.expects(:apply).with(resolved_path).returns(true).once
@@ -95,6 +98,7 @@ describe "PluginGenerator" do
95
98
  it 'should print a warning if template cannot be found' do
96
99
  template_file = 'hwat'
97
100
  resolved_path = "https://raw.github.com/padrino/padrino-recipes/master/plugins/hwat_plugin.rb"
101
+ FakeWeb.register_uri :get, resolved_path, :status => 404
98
102
  plugin_gen = Padrino::Generators::Plugin.new([ template_file], ["-r=#{@apptmp}/sample_project"],{})
99
103
  plugin_gen.expects(:in_app_root?).returns(true).once
100
104
  plugin_gen.expects(:say).with("The template at #{resolved_path} could not be found!", :red).returns(true).once
@@ -648,7 +648,7 @@ describe "ProjectGenerator" do
648
648
  it 'should properly generate for sass' do
649
649
  capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--renderer=haml','--script=none','--stylesheet=sass') }
650
650
  assert_match_in_file(/gem 'sass'/, "#{@apptmp}/sample_project/Gemfile")
651
- assert_match_in_file(/module SassInitializer.*Sass::Plugin::Rack/m, "#{@apptmp}/sample_project/lib/sass_initializer.rb")
651
+ assert_match_in_file(/module SassInitializer.*Sass::Plugin::Rack/m, "#{@apptmp}/sample_project/config/initializers/sass.rb")
652
652
  assert_match_in_file(/register SassInitializer/m, "#{@apptmp}/sample_project/app/app.rb")
653
653
  assert_dir_exists("#{@apptmp}/sample_project/app/stylesheets")
654
654
  end
@@ -656,7 +656,7 @@ describe "ProjectGenerator" do
656
656
  it 'should properly generate for less' do
657
657
  capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--renderer=haml','--script=none','--stylesheet=less') }
658
658
  assert_match_in_file(/gem 'rack-less'/, "#{@apptmp}/sample_project/Gemfile")
659
- assert_match_in_file(/module LessInitializer.*Rack::Less/m, "#{@apptmp}/sample_project/lib/less_initializer.rb")
659
+ assert_match_in_file(/module LessInitializer.*Rack::Less/m, "#{@apptmp}/sample_project/config/initializers/less.rb")
660
660
  assert_match_in_file(/register LessInitializer/m, "#{@apptmp}/sample_project/app/app.rb")
661
661
  assert_dir_exists("#{@apptmp}/sample_project/app/stylesheets")
662
662
  end
@@ -664,8 +664,8 @@ describe "ProjectGenerator" do
664
664
  it 'should properly generate for compass' do
665
665
  capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--renderer=haml','--script=none','--stylesheet=compass') }
666
666
  assert_match_in_file(/gem 'compass-blueprint'/, "#{@apptmp}/sample_project/Gemfile")
667
- assert_match_in_file(/Compass.configure_sass_plugin\!/, "#{@apptmp}/sample_project/lib/compass_plugin.rb")
668
- assert_match_in_file(/module CompassInitializer.*Sass::Plugin::Rack/m, "#{@apptmp}/sample_project/lib/compass_plugin.rb")
667
+ assert_match_in_file(/Compass.configure_sass_plugin\!/, "#{@apptmp}/sample_project/config/initializers/compass.rb")
668
+ assert_match_in_file(/module CompassInitializer.*Sass::Plugin::Rack/m, "#{@apptmp}/sample_project/config/initializers/compass.rb")
669
669
  assert_match_in_file(/register CompassInitializer/m, "#{@apptmp}/sample_project/app/app.rb")
670
670
 
671
671
  assert_file_exists("#{@apptmp}/sample_project/app/stylesheets/application.scss")
@@ -675,8 +675,8 @@ describe "ProjectGenerator" do
675
675
  it 'should properly generate for scss' do
676
676
  capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--renderer=haml','--script=none','--stylesheet=scss') }
677
677
  assert_match_in_file(/gem 'haml'/, "#{@apptmp}/sample_project/Gemfile")
678
- assert_match_in_file(/module ScssInitializer.*Sass::Plugin::Rack/m, "#{@apptmp}/sample_project/lib/scss_initializer.rb")
679
- assert_match_in_file(/Sass::Plugin.options\[:syntax\] = :scss/m, "#{@apptmp}/sample_project/lib/scss_initializer.rb")
678
+ assert_match_in_file(/module ScssInitializer.*Sass::Plugin::Rack/m, "#{@apptmp}/sample_project/config/initializers/scss.rb")
679
+ assert_match_in_file(/Sass::Plugin.options\[:syntax\] = :scss/m, "#{@apptmp}/sample_project/config/initializers/scss.rb")
680
680
  assert_match_in_file(/register ScssInitializer/m, "#{@apptmp}/sample_project/app/app.rb")
681
681
  assert_dir_exists("#{@apptmp}/sample_project/app/stylesheets")
682
682
  end
@@ -17,6 +17,11 @@ describe "TaskGenerator" do
17
17
  assert_no_file_exists('/tmp/tasks/foo.rake')
18
18
  end
19
19
 
20
+ it 'should fail with NameError if given invalid namespace names' do
21
+ capture_io { generate(:project, "sample", "--root=#{@apptmp}") }
22
+ assert_raises(::NameError) { capture_io { generate(:task, "wrong/name", "--root=#{@apptmp}/sample") } }
23
+ end
24
+
20
25
  it 'should generate filename properly' do
21
26
  capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}") }
22
27
  capture_io { generate(:task, 'DemoTask', "--namespace=Sample", "--description='This is a sample'", "-r=#{@apptmp}/sample_project") }
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.13.1
4
+ version: 0.13.2
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: 2016-01-17 00:00:00.000000000 Z
14
+ date: 2016-05-09 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: padrino-core
@@ -19,26 +19,26 @@ dependencies:
19
19
  requirements:
20
20
  - - '='
21
21
  - !ruby/object:Gem::Version
22
- version: 0.13.1
22
+ version: 0.13.2
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.13.1
29
+ version: 0.13.2
30
30
  - !ruby/object:Gem::Dependency
31
31
  name: bundler
32
32
  requirement: !ruby/object:Gem::Requirement
33
33
  requirements:
34
- - - ~>
34
+ - - "~>"
35
35
  - !ruby/object:Gem::Version
36
36
  version: '1.0'
37
37
  type: :runtime
38
38
  prerelease: false
39
39
  version_requirements: !ruby/object:Gem::Requirement
40
40
  requirements:
41
- - - ~>
41
+ - - "~>"
42
42
  - !ruby/object:Gem::Version
43
43
  version: '1.0'
44
44
  - !ruby/object:Gem::Dependency
@@ -47,28 +47,28 @@ dependencies:
47
47
  requirements:
48
48
  - - '='
49
49
  - !ruby/object:Gem::Version
50
- version: 0.13.1
50
+ version: 0.13.2
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.13.1
57
+ version: 0.13.2
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.13.1
64
+ version: 0.13.2
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.13.1
71
+ version: 0.13.2
72
72
  description: Generators for easily creating and building padrino applications from
73
73
  the console
74
74
  email: padrinorb@gmail.com
@@ -78,9 +78,9 @@ extensions: []
78
78
  extra_rdoc_files:
79
79
  - README.rdoc
80
80
  files:
81
- - .document
82
- - .gitignore
83
- - .yardopts
81
+ - ".document"
82
+ - ".gitignore"
83
+ - ".yardopts"
84
84
  - LICENSE.txt
85
85
  - README.rdoc
86
86
  - Rakefile
@@ -203,17 +203,17 @@ licenses:
203
203
  metadata: {}
204
204
  post_install_message:
205
205
  rdoc_options:
206
- - --charset=UTF-8
206
+ - "--charset=UTF-8"
207
207
  require_paths:
208
208
  - lib
209
209
  required_ruby_version: !ruby/object:Gem::Requirement
210
210
  requirements:
211
- - - '>='
211
+ - - ">="
212
212
  - !ruby/object:Gem::Version
213
213
  version: '0'
214
214
  required_rubygems_version: !ruby/object:Gem::Requirement
215
215
  requirements:
216
- - - '>='
216
+ - - ">="
217
217
  - !ruby/object:Gem::Version
218
218
  version: 1.3.6
219
219
  requirements: []