padrino-gen 0.12.8.1 → 0.12.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. checksums.yaml +13 -5
  2. data/Rakefile +1 -4
  3. data/lib/padrino-gen/generators/actions.rb +17 -5
  4. data/lib/padrino-gen/generators/app/app.rb.tt +3 -2
  5. data/lib/padrino-gen/generators/components/mocks/mocha.rb +1 -1
  6. data/lib/padrino-gen/generators/components/orms/activerecord.rb +14 -14
  7. data/lib/padrino-gen/generators/components/orms/datamapper.rb +16 -0
  8. data/lib/padrino-gen/generators/components/orms/mongoid.rb +20 -39
  9. data/lib/padrino-gen/generators/components/orms/mongomapper.rb +1 -0
  10. data/lib/padrino-gen/generators/components/orms/sequel.rb +3 -3
  11. data/lib/padrino-gen/generators/components/stylesheets/compass.rb +5 -16
  12. data/lib/padrino-gen/generators/components/tests/bacon.rb +2 -0
  13. data/lib/padrino-gen/generators/components/tests/minitest.rb +2 -0
  14. data/lib/padrino-gen/generators/components/tests/riot.rb +2 -0
  15. data/lib/padrino-gen/generators/components/tests/rspec.rb +5 -1
  16. data/lib/padrino-gen/generators/components/tests/shoulda.rb +3 -0
  17. data/lib/padrino-gen/generators/components/tests/steak.rb +2 -0
  18. data/lib/padrino-gen/generators/components/tests/testunit.rb +112 -0
  19. data/lib/padrino-gen/generators/controller.rb +1 -0
  20. data/lib/padrino-gen/generators/helper.rb +1 -0
  21. data/lib/padrino-gen/generators/mailer.rb +1 -0
  22. data/lib/padrino-gen/generators/migration.rb +1 -0
  23. data/lib/padrino-gen/generators/plugin.rb +1 -1
  24. data/lib/padrino-gen/generators/project/config/boot.rb +16 -2
  25. data/lib/padrino-gen/generators/project.rb +2 -1
  26. data/lib/padrino-gen/generators/runner.rb +1 -0
  27. data/lib/padrino-gen/generators/task.rb +1 -0
  28. data/lib/padrino-gen/generators/templates/Gemfile.tt +13 -0
  29. data/lib/padrino-gen/generators/templates/Rakefile.tt +2 -0
  30. data/lib/padrino-gen/generators/templates/controller.rb.tt +1 -1
  31. data/lib/padrino-gen/generators/templates/project_bin.tt +0 -1
  32. data/lib/padrino-gen/padrino-tasks/activerecord.rb +38 -33
  33. data/lib/padrino-gen/padrino-tasks/datamapper.rb +4 -2
  34. data/lib/padrino-gen/padrino-tasks/mongoid.rb +42 -0
  35. data/lib/padrino-gen/padrino-tasks/sequel.rb +13 -4
  36. data/test/helper.rb +3 -60
  37. data/test/test_app_generator.rb +15 -15
  38. data/test/test_controller_generator.rb +19 -6
  39. data/test/test_helper_generator.rb +13 -0
  40. data/test/test_mailer_generator.rb +5 -0
  41. data/test/test_migration_generator.rb +5 -0
  42. data/test/test_model_generator.rb +30 -24
  43. data/test/test_project_generator.rb +31 -17
  44. data/test/test_task_generator.rb +5 -0
  45. metadata +18 -17
checksums.yaml CHANGED
@@ -1,7 +1,15 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 2fa106970ea0dd40076b49b7cf090ddb8b29e488
4
- data.tar.gz: aad0beed2605f8a8afb1b4b0114be340dfb2ecfb
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ Y2ZmNDEwYTE1NmE2NGNjZjA5NmZhNTRmYjE0NTdiMjhjYTAyMmE2OA==
5
+ data.tar.gz: !binary |-
6
+ ODQ1NWVjOGU4MTE0MWI3MmI2NGQ3MTA1YzU3NDRiOTIzMzc0MmJkNQ==
5
7
  SHA512:
6
- metadata.gz: b843036661f2da3d55596bb0a7a14e2cd83c25f011948855f599e522155a475dd5e2a21122a4442bef4ca469f6fcda6bb53e7445c1eb5f1b7517dfd01d986f57
7
- data.tar.gz: b6087de11ecc4cf8abe35a73d1d18e0e1ede4619ccb05c446461de5d069a52833072fcf45d4cc1e2e89a29978bc60f1b719fddbb6d1040be68b0b4c1e114e55e
8
+ metadata.gz: !binary |-
9
+ OTI4MjIxMmNjNjI5ZDlmMjhkZmViYzM0Y2Q1YmEyNjAzOGM3N2VhOWVmZTdi
10
+ Mjg0YWE5OWMyMzE2MDExZjc4YTExMWU1OGQwMGE4YTQ5NDBhNzUyNDgyN2Q2
11
+ ZTBhYjQxYzUwZWNhOThiN2RjNTI1ZjMzMjA3ODgyY2MyZGE4NWQ=
12
+ data.tar.gz: !binary |-
13
+ NTNiMzQyNDQwZmI0NGE4ZjZmOTgwMWM1M2I5NmY4MGZiMTVlNDE3ZTYyYzYw
14
+ ZDkxMDAxODhlZjZlZmI3MmEwYmQyYmM5YjQ0Y2M0MDhjNWY2N2Y0NDlkOTY0
15
+ OGE1MjM1ODc4OTNjOWNhZTE1NGE4OTAyNDc4ZjRmZDA2MjE2Mjc=
data/Rakefile CHANGED
@@ -1,4 +1 @@
1
- # coding:utf-8
2
- RAKE_ROOT = __FILE__
3
- require 'rubygems'
4
- require File.expand_path(File.dirname(__FILE__) + '/../gem_rake_helper')
1
+ require File.expand_path(File.dirname(__FILE__) + '/../gem_rake_helper')
@@ -308,7 +308,7 @@ WARNING
308
308
  #
309
309
  def require_dependencies(*gem_names)
310
310
  options = gem_names.extract_options!
311
- gem_names.reverse.each { |lib| insert_into_gemfile(lib, options) }
311
+ gem_names.reverse_each { |lib| insert_into_gemfile(lib, options) }
312
312
  end
313
313
 
314
314
  ##
@@ -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
  ##
@@ -15,7 +16,7 @@ module <%= @project_name %>
15
16
  #
16
17
  # set :cache, Padrino::Cache.new(:LRUHash) # Keeps cached values in memory
17
18
  # set :cache, Padrino::Cache.new(:Memcached) # Uses default server at localhost
18
- # set :cache, Padrino::Cache.new(:Memcached, '127.0.0.1:11211', :exception_retry_limit => 1)
19
+ # set :cache, Padrino::Cache.new(:Memcached, :server => '127.0.0.1:11211', :exception_retry_limit => 1)
19
20
  # set :cache, Padrino::Cache.new(:Memcached, :backend => memcached_or_dalli_instance)
20
21
  # set :cache, Padrino::Cache.new(:Redis) # Uses default server at localhost
21
22
  # set :cache, Padrino::Cache.new(:Redis, :host => '127.0.0.1', :port => 6379, :db => 0)
@@ -4,7 +4,7 @@ def setup_mock
4
4
  when 'rspec'
5
5
  inject_into_file 'spec/spec_helper.rb', " conf.mock_with :mocha\n", :after => "RSpec.configure do |conf|\n"
6
6
  else
7
- inject_into_file 'test/test_config.rb', "require 'mocha/api'", :after => "require File.expand_path(File.dirname(__FILE__) + \"/../config/boot\")\n"
7
+ inject_into_file 'test/test_config.rb', "require 'mocha/api'\n", :after => "require File.expand_path(File.dirname(__FILE__) + \"/../config/boot\")\n"
8
8
  insert_mocking_include "Mocha::API"
9
9
  end
10
10
  end
@@ -114,24 +114,24 @@ def setup_orm
114
114
  # We're now defaulting to mysql2 since mysql is deprecated
115
115
  case options[:adapter]
116
116
  when 'mysql-gem'
117
- ar.gsub! /!DB_DEVELOPMENT!/, MYSQL.gsub(/!DB_NAME!/,"'#{db}_development'")
118
- ar.gsub! /!DB_PRODUCTION!/, MYSQL.gsub(/!DB_NAME!/,"'#{db}_production'")
119
- ar.gsub! /!DB_TEST!/, MYSQL.gsub(/!DB_NAME!/,"'#{db}_test'")
117
+ ar.sub! /!DB_DEVELOPMENT!/, MYSQL.sub(/!DB_NAME!/,"'#{db}_development'")
118
+ ar.sub! /!DB_PRODUCTION!/, MYSQL.sub(/!DB_NAME!/,"'#{db}_production'")
119
+ ar.sub! /!DB_TEST!/, MYSQL.sub(/!DB_NAME!/,"'#{db}_test'")
120
120
  require_dependencies 'mysql', :version => "~> 2.8.1"
121
121
  when 'mysql', 'mysql2'
122
- ar.gsub! /!DB_DEVELOPMENT!/, MYSQL2.gsub(/!DB_NAME!/,"'#{db}_development'")
123
- ar.gsub! /!DB_PRODUCTION!/, MYSQL2.gsub(/!DB_NAME!/,"'#{db}_production'")
124
- ar.gsub! /!DB_TEST!/, MYSQL2.gsub(/!DB_NAME!/,"'#{db}_test'")
122
+ ar.sub! /!DB_DEVELOPMENT!/, MYSQL2.sub(/!DB_NAME!/,"'#{db}_development'")
123
+ ar.sub! /!DB_PRODUCTION!/, MYSQL2.sub(/!DB_NAME!/,"'#{db}_production'")
124
+ ar.sub! /!DB_TEST!/, MYSQL2.sub(/!DB_NAME!/,"'#{db}_test'")
125
125
  require_dependencies 'mysql2'
126
126
  when 'postgres'
127
- ar.gsub! /!DB_DEVELOPMENT!/, POSTGRES.gsub(/!DB_NAME!/,"'#{db}_development'")
128
- ar.gsub! /!DB_PRODUCTION!/, POSTGRES.gsub(/!DB_NAME!/,"'#{db}_production'")
129
- ar.gsub! /!DB_TEST!/, POSTGRES.gsub(/!DB_NAME!/,"'#{db}_test'")
127
+ ar.sub! /!DB_DEVELOPMENT!/, POSTGRES.sub(/!DB_NAME!/,"'#{db}_development'")
128
+ ar.sub! /!DB_PRODUCTION!/, POSTGRES.sub(/!DB_NAME!/,"'#{db}_production'")
129
+ ar.sub! /!DB_TEST!/, POSTGRES.sub(/!DB_NAME!/,"'#{db}_test'")
130
130
  require_dependencies 'pg'
131
131
  else
132
- ar.gsub! /!DB_DEVELOPMENT!/, SQLITE.gsub(/!DB_NAME!/,"Padrino.root('db', '#{db}_development.db')")
133
- ar.gsub! /!DB_PRODUCTION!/, SQLITE.gsub(/!DB_NAME!/,"Padrino.root('db', '#{db}_production.db')")
134
- ar.gsub! /!DB_TEST!/, SQLITE.gsub(/!DB_NAME!/,"Padrino.root('db', '#{db}_test.db')")
132
+ ar.sub! /!DB_DEVELOPMENT!/, SQLITE.sub(/!DB_NAME!/,"Padrino.root('db', '#{db}_development.db')")
133
+ ar.sub! /!DB_PRODUCTION!/, SQLITE.sub(/!DB_NAME!/,"Padrino.root('db', '#{db}_production.db')")
134
+ ar.sub! /!DB_TEST!/, SQLITE.sub(/!DB_NAME!/,"Padrino.root('db', '#{db}_test.db')")
135
135
  require_dependencies 'sqlite3'
136
136
  end
137
137
  require_dependencies 'activerecord', :require => 'active_record', :version => ">= 3.1"
@@ -148,7 +148,7 @@ MODEL
148
148
  # options => { :fields => ["title:string", "body:string"], :app => 'app' }
149
149
  def create_model_file(name, options={})
150
150
  model_path = destination_root(options[:app], 'models', "#{name.to_s.underscore}.rb")
151
- model_contents = AR_MODEL.gsub(/!NAME!/, name.to_s.underscore.camelize)
151
+ model_contents = AR_MODEL.sub(/!NAME!/, name.to_s.underscore.camelize)
152
152
  create_file(model_path, model_contents,:skip => true)
153
153
  end
154
154
 
@@ -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
 
@@ -41,6 +41,21 @@ case Padrino.env
41
41
  end
42
42
  DM
43
43
 
44
+ IDENTITY_MAP_MIDDLEWARE = <<-MIDDLEWARE
45
+ class IdentityMap
46
+ def initialize(app, name = :default)
47
+ @app = app
48
+ @name = name.to_sym
49
+ end
50
+
51
+ def call(env)
52
+ ::DataMapper.repository(@name) do
53
+ @app.call(env)
54
+ end
55
+ end
56
+ end
57
+ MIDDLEWARE
58
+
44
59
  def setup_orm
45
60
  dm = DM
46
61
  db = @project_name.underscore
@@ -73,6 +88,7 @@ def setup_orm
73
88
 
74
89
  create_file("config/database.rb", dm)
75
90
  insert_hook("DataMapper.finalize", :after_load)
91
+ middleware :identity_map, IDENTITY_MAP_MIDDLEWARE
76
92
  end
77
93
 
78
94
  DM_MODEL = (<<-MODEL) unless defined?(DM_MODEL)
@@ -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
- require_dependencies 'mongoid', :version => '~>3.0.0'
78
- create_file('config/database.rb', MONGOID3.gsub(/!NAME!/, @project_name.underscore))
58
+ require_dependencies 'mongoid', :version => '>= 3.0.0'
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)
@@ -11,6 +11,7 @@ MONGO
11
11
  def setup_orm
12
12
  require_dependencies 'mongo_mapper'
13
13
  require_dependencies 'bson_ext', :require => 'mongo'
14
+ require_dependencies 'activemodel', :version => '< 5'
14
15
  create_file("config/database.rb", MONGO.gsub(/!NAME!/, @project_name.underscore))
15
16
  end
16
17
 
@@ -32,9 +32,9 @@ def setup_orm
32
32
  require_dependencies 'pg'
33
33
  'pg'
34
34
  else
35
- sequel.gsub!(/!DB_DEVELOPMENT!/,"\"sqlite:///\" + Padrino.root('db', \"#{db}_development.db\")")
36
- sequel.gsub!(/!DB_PRODUCTION!/,"\"sqlite:///\" + Padrino.root('db', \"#{db}_production.db\")")
37
- sequel.gsub!(/!DB_TEST!/,"\"sqlite:///\" + Padrino.root('db', \"#{db}_test.db\")")
35
+ sequel.gsub!(/!DB_DEVELOPMENT!/,"\"sqlite://db/#{db}_development.db\"")
36
+ sequel.gsub!(/!DB_PRODUCTION!/, "\"sqlite://db/#{db}_production.db\"")
37
+ sequel.gsub!(/!DB_TEST!/, "\"sqlite://db/#{db}_test.db\"")
38
38
  require_dependencies 'sqlite3'
39
39
  'sqlite3'
40
40
  end
@@ -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
- require_dependencies 'compass'
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
-
25
+ require_dependencies 'compass-blueprint'
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)
@@ -57,8 +57,12 @@ begin
57
57
  desc "Run complete application spec suite"
58
58
  task 'spec' => spec_tasks.map { |f| "spec:\#{f}" }
59
59
  rescue LoadError
60
- puts "RSpec is not part of this bundle, skip specs."
60
+ task :spec do
61
+ puts "RSpec is not part of this bundle, skip specs."
62
+ end
61
63
  end
64
+
65
+ task :default => :spec
62
66
  TEST
63
67
 
64
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)
@@ -89,6 +91,7 @@ TEST
89
91
  def setup_test
90
92
  require_dependencies 'rack-test', :require => 'rack/test', :group => 'test'
91
93
  require_dependencies 'shoulda', :group => 'test'
94
+ require_dependencies 'test-unit', :group => 'test'
92
95
  insert_test_suite_setup SHOULDA_SETUP
93
96
  create_file destination_root("test/test.rake"), SHOULDA_RAKE
94
97
  end
@@ -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)
@@ -0,0 +1,112 @@
1
+ TESTUNIT_SETUP = (<<-TEST).gsub(/^ {10}/, '') unless defined?(TESTUNIT_SETUP)
2
+ RACK_ENV = 'test' unless defined?(RACK_ENV)
3
+ require File.expand_path(File.dirname(__FILE__) + "/../config/boot")
4
+ Dir[File.expand_path(File.dirname(__FILE__) + "/../app/helpers/**/*.rb")].each(&method(:require))
5
+
6
+ class Test::Unit::TestCase
7
+ include Rack::Test::Methods
8
+
9
+ # You can use this method to custom specify a Rack app
10
+ # you want rack-test to invoke:
11
+ #
12
+ # app CLASS_NAME
13
+ # app CLASS_NAME.tap { |a| }
14
+ # app(CLASS_NAME) do
15
+ # set :foo, :bar
16
+ # end
17
+ #
18
+ def app(app = nil, &blk)
19
+ @app ||= block_given? ? app.instance_eval(&blk) : app
20
+ @app ||= Padrino.application
21
+ end
22
+ end
23
+ TEST
24
+
25
+ TESTUNIT_RAKE = (<<-TEST).gsub(/^ {10}/, '') unless defined?(TESTUNIT_RAKE)
26
+ require 'rake/testtask'
27
+
28
+ test_tasks = Dir['test/*/'].map { |d| File.basename(d) }
29
+
30
+ test_tasks.each do |folder|
31
+ Rake::TestTask.new("test:\#{folder}") do |test|
32
+ test.pattern = "test/\#{folder}/**/*_test.rb"
33
+ test.verbose = true
34
+ end
35
+ end
36
+
37
+ desc "Run application test suite"
38
+ task 'test' => test_tasks.map { |f| "test:\#{f}" }
39
+
40
+ task :default => :test
41
+ TEST
42
+
43
+ TESTUNIT_CONTROLLER_TEST = (<<-TEST).gsub(/^ {10}/, '') unless defined?(TESTUNIT_CONTROLLER_TEST)
44
+ require File.expand_path(File.dirname(__FILE__) + '/../../test_config.rb')
45
+
46
+ class !NAME!ControllerTest < Test::Unit::TestCase
47
+ def setup
48
+ get "/"
49
+ end
50
+
51
+ def test_returns_hello_world_text
52
+ assert_equal "Hello World", last_response.body
53
+ end
54
+ end
55
+ TEST
56
+
57
+ TESTUNIT_MODEL_TEST = (<<-TEST).gsub(/^ {10}/, '') unless defined?(TESTUNIT_MODEL_TEST)
58
+ require File.expand_path(File.dirname(__FILE__) + '!PATH!/test_config.rb')
59
+
60
+ class !NAME!Test < Test::Unit::TestCase
61
+ def test_constructs_a_new_instance
62
+ @!DNAME! = !NAME!.new
63
+ refute_nil @!DNAME!
64
+ end
65
+ end
66
+ TEST
67
+
68
+ TESTUNIT_HELPER_TEST = (<<-TEST) unless defined?(TESTUNIT_HELPER_TEST)
69
+ require File.expand_path(File.dirname(__FILE__) + '!PATH!/test_config.rb')
70
+
71
+ class !NAME!Test < Test::Unit::TestCase
72
+ def self.setup
73
+ @helpers = Class.new
74
+ @helpers.extend !CONSTANT_NAME!
75
+ end
76
+
77
+ def helpers
78
+ @helpers
79
+ end
80
+
81
+ def test_foo_helper
82
+ assert_equal nil, helpers.foo
83
+ end
84
+ end
85
+ TEST
86
+
87
+ def setup_test
88
+ require_dependencies 'rack-test', :require => 'rack/test', :group => 'test'
89
+ require_dependencies 'test-unit', :require => 'test/unit', :group => 'test'
90
+ insert_test_suite_setup TESTUNIT_SETUP
91
+ create_file destination_root("test/test.rake"), TESTUNIT_RAKE
92
+ end
93
+
94
+ def generate_controller_test(name, path)
95
+ test_unit_contents = TESTUNIT_CONTROLLER_TEST.gsub(/!NAME!/, name.to_s.underscore.camelize)
96
+ controller_test_path = File.join('test',options[:app],'controllers',"#{name.to_s.underscore}_controller_test.rb")
97
+ create_file destination_root(controller_test_path), test_unit_contents, :skip => true
98
+ end
99
+
100
+ def generate_model_test(name)
101
+ test_unit_contents = TESTUNIT_MODEL_TEST.gsub(/!NAME!/, name.to_s.underscore.camelize).gsub(/!DNAME!/, name.to_s.underscore)
102
+ test_unit_contents.gsub!(/!PATH!/, recognize_path)
103
+ model_test_path = File.join('test',options[:app],'models',"#{name.to_s.underscore}_test.rb")
104
+ create_file destination_root(model_test_path), test_unit_contents, :skip => true
105
+ end
106
+
107
+ def generate_helper_test(name, project_name, app_name)
108
+ test_unit_contents = TESTUNIT_HELPER_TEST.gsub(/!NAME!/, name).gsub(/!CONSTANT_NAME!/, "#{project_name}::#{app_name}::#{name}")
109
+ test_unit_contents.gsub!(/!PATH!/, recognize_path)
110
+ helper_spec_path = File.join('test', options[:app], 'helpers', "#{name.underscore}_test.rb")
111
+ create_file destination_root(helper_spec_path), test_unit_contents, :skip => true
112
+ end
@@ -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
@@ -1,9 +1,8 @@
1
1
  # Defines our constants
2
- RACK_ENV = ENV['RACK_ENV'] ||= 'development' unless defined?(RACK_ENV)
2
+ RACK_ENV = ENV['RACK_ENV'] ||= 'development' unless defined?(RACK_ENV)
3
3
  PADRINO_ROOT = File.expand_path('../..', __FILE__) unless defined?(PADRINO_ROOT)
4
4
 
5
5
  # Load our dependencies
6
- require 'rubygems' unless defined?(Gem)
7
6
  require 'bundler/setup'
8
7
  Bundler.require(:default, RACK_ENV)
9
8
 
@@ -13,6 +12,14 @@ Bundler.require(:default, RACK_ENV)
13
12
  # Padrino::Logger::Config[:development][:log_level] = :devel
14
13
  # Padrino::Logger::Config[:development][:log_static] = true
15
14
  #
15
+ # ## Configure Ruby to allow requiring features from your lib folder
16
+ #
17
+ # $LOAD_PATH.unshift Padrino.root('lib')
18
+ #
19
+ # ## Enable logging of source location
20
+ #
21
+ # Padrino::Logger::Config[:development][:source_location] = true
22
+ #
16
23
  # ## Configure your I18n
17
24
  #
18
25
  # I18n.default_locale = :en
@@ -31,8 +38,15 @@ Bundler.require(:default, RACK_ENV)
31
38
  # include Padrino::Helpers::TranslationHelpers
32
39
  # end
33
40
 
41
+ ##
42
+ # Require initializers before all other dependencies.
43
+ # Dependencies from 'config' folder are NOT re-required on reload.
44
+ #
45
+ Padrino.dependency_paths.unshift Padrino.root('config/initializers/*.rb')
46
+
34
47
  ##
35
48
  # Add your before (RE)load hooks here
49
+ # These hooks are run before any dependencies are required.
36
50
  #
37
51
  Padrino.before_load do
38
52
  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
@@ -1,4 +1,5 @@
1
1
  require 'fileutils'
2
+ require 'open-uri'
2
3
 
3
4
  module Padrino
4
5
  module Generators
@@ -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]