padrino-gen 0.10.7 → 0.11.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (69) hide show
  1. checksums.yaml +7 -0
  2. data/lib/padrino-gen/generators/actions.rb +139 -102
  3. data/lib/padrino-gen/generators/app/app.rb.tt +55 -53
  4. data/lib/padrino-gen/generators/app.rb +16 -16
  5. data/lib/padrino-gen/generators/cli.rb +3 -3
  6. data/lib/padrino-gen/generators/components/actions.rb +1 -1
  7. data/lib/padrino-gen/generators/components/orms/activerecord.rb +22 -18
  8. data/lib/padrino-gen/generators/components/orms/couchrest.rb +1 -1
  9. data/lib/padrino-gen/generators/components/orms/datamapper.rb +2 -1
  10. data/lib/padrino-gen/generators/components/orms/{mini_record.rb → minirecord.rb} +9 -9
  11. data/lib/padrino-gen/generators/components/orms/mongoid.rb +60 -6
  12. data/lib/padrino-gen/generators/components/orms/mongomapper.rb +2 -2
  13. data/lib/padrino-gen/generators/components/orms/mongomatic.rb +2 -2
  14. data/lib/padrino-gen/generators/components/orms/ohm.rb +57 -10
  15. data/lib/padrino-gen/generators/components/orms/ripple.rb +1 -1
  16. data/lib/padrino-gen/generators/components/orms/sequel.rb +15 -6
  17. data/lib/padrino-gen/generators/components/stylesheets/compass.rb +1 -1
  18. data/lib/padrino-gen/generators/components/stylesheets/less.rb +1 -0
  19. data/lib/padrino-gen/generators/components/tests/bacon.rb +0 -2
  20. data/lib/padrino-gen/generators/components/tests/minitest.rb +0 -1
  21. data/lib/padrino-gen/generators/components/tests/riot.rb +0 -1
  22. data/lib/padrino-gen/generators/components/tests/rspec.rb +14 -15
  23. data/lib/padrino-gen/generators/components/tests/shoulda.rb +0 -1
  24. data/lib/padrino-gen/generators/components/tests/testspec.rb +0 -1
  25. data/lib/padrino-gen/generators/controller.rb +14 -11
  26. data/lib/padrino-gen/generators/mailer.rb +14 -11
  27. data/lib/padrino-gen/generators/migration.rb +5 -5
  28. data/lib/padrino-gen/generators/model.rb +8 -7
  29. data/lib/padrino-gen/generators/plugin.rb +15 -9
  30. data/lib/padrino-gen/generators/project/.gitignore +2 -1
  31. data/lib/padrino-gen/generators/project/config/apps.rb.tt +10 -8
  32. data/lib/padrino-gen/generators/project/config.ru +0 -0
  33. data/lib/padrino-gen/generators/project/public/favicon.ico +0 -0
  34. data/lib/padrino-gen/generators/project.rb +53 -25
  35. data/lib/padrino-gen/generators/runner.rb +1 -1
  36. data/lib/padrino-gen/generators/templates/Gemfile.tt +8 -3
  37. data/lib/padrino-gen/generators/templates/Rakefile.tt +8 -0
  38. data/lib/padrino-gen/generators/templates/controller.rb.tt +8 -9
  39. data/lib/padrino-gen/generators/templates/gem/README.md.tt +29 -0
  40. data/lib/padrino-gen/generators/templates/gem/gemspec.tt +19 -0
  41. data/lib/padrino-gen/generators/templates/gem/lib/libname/version.tt +3 -0
  42. data/lib/padrino-gen/generators/templates/gem/lib/libname.tt +6 -0
  43. data/lib/padrino-gen/generators/templates/helper.rb.tt +1 -1
  44. data/lib/padrino-gen/generators/templates/mailer.rb.tt +1 -1
  45. data/lib/padrino-gen/generators/templates/static/js/dojo.js +238 -1
  46. data/lib/padrino-gen/generators/templates/static/js/ext.js +38 -1
  47. data/lib/padrino-gen/generators/templates/static/js/jquery.js +4 -4
  48. data/lib/padrino-gen/generators/templates/static/js/mootools.js +335 -276
  49. data/lib/padrino-gen/generators/templates/static/js/protopak.js +1 -1
  50. data/lib/padrino-gen/generators/templates/static/js/right.js +7 -1
  51. data/lib/padrino-gen/generators/templates/static/ujs/jquery.js +76 -75
  52. data/lib/padrino-gen/padrino-tasks/activerecord.rb +8 -2
  53. data/lib/padrino-gen/padrino-tasks/database.rb +11 -0
  54. data/lib/padrino-gen/padrino-tasks/datamapper.rb +38 -12
  55. data/lib/padrino-gen/padrino-tasks/minirecord.rb +19 -0
  56. data/lib/padrino-gen/padrino-tasks/mongoid.rb +76 -18
  57. data/lib/padrino-gen/padrino-tasks/mongomapper.rb +9 -1
  58. data/lib/padrino-gen/padrino-tasks/sequel.rb +6 -1
  59. data/lib/padrino-gen.rb +2 -2
  60. data/padrino-gen.gemspec +0 -0
  61. data/test/helper.rb +1 -1
  62. data/test/test_app_generator.rb +23 -4
  63. data/test/test_controller_generator.rb +8 -8
  64. data/test/test_mailer_generator.rb +5 -5
  65. data/test/test_model_generator.rb +26 -23
  66. data/test/test_plugin_generator.rb +23 -0
  67. data/test/test_project_generator.rb +82 -47
  68. metadata +17 -17
  69. data/lib/padrino-gen/padrino-tasks/seed.rb +0 -5
@@ -1,9 +1,67 @@
1
- if defined?(Mongoid)
1
+ if PadrinoTasks.load?(:mongoid, defined?(Mongoid))
2
+ require 'mongoid' # eagerly load mongoid for version check
3
+
2
4
  namespace :mi do
3
5
 
6
+ if Mongoid::VERSION =~ /^[012]\./
7
+ # Mongoid 2 API
8
+ def mongoid_collections
9
+ Mongoid.master.collections
10
+ end
11
+
12
+ def mongoid_collection(name)
13
+ Mongoid.master.collection(name)
14
+ end
15
+
16
+ def mongoid_new_collection(collection, name)
17
+ collection.db.collection(name)
18
+ end
19
+
20
+ def enum_mongoid_documents(collection)
21
+ collection.find({}, :timeout => false, :sort => "_id") do |cursor|
22
+ cursor.each do |doc|
23
+ yield doc
24
+ end
25
+ end
26
+ end
27
+
28
+ def rename_mongoid_collection(collection, new_name)
29
+ collection.rename(new_name)
30
+ end
31
+ else
32
+ # Mongoid 3+ API
33
+ def mongoid_collections
34
+ Mongoid.default_session.collections
35
+ end
36
+
37
+ def mongoid_collection(name)
38
+ Mongoid.default_session[name]
39
+ end
40
+
41
+ def mongoid_new_collection(collection, name)
42
+ Mongoid.default_session[name]
43
+ end
44
+
45
+ def enum_mongoid_documents(collection)
46
+ collection.find.sort(:_id => 1).each do |doc|
47
+ yield doc
48
+ end
49
+ end
50
+
51
+ def rename_mongoid_collection(collection, new_name)
52
+ db_name = collection.database.name
53
+ collection.database.session.with(:database => :admin) do |admin|
54
+ admin.command(
55
+ :renameCollection => "#{db_name}.#{collection.name}",
56
+ :to => "#{db_name}.#{new_name}",
57
+ :dropTarget => true)
58
+ end
59
+ end
60
+ end
61
+
4
62
  desc 'Drops all the collections for the database for the current Padrino.env'
5
63
  task :drop => :environment do
6
- Mongoid.master.collections.select {|c| c.name !~ /system/ }.each(&:drop)
64
+ mongoid_collections.select {|c| c.name !~ /system/ }.each(&:drop)
7
65
  end
8
66
 
9
67
  # Helper to retrieve a list of models.
@@ -33,7 +91,7 @@ if defined?(Mongoid)
33
91
 
34
92
  def convert_ids(obj)
35
93
  if obj.is_a?(String) && obj =~ /^[a-f0-9]{24}$/
36
- BSON::ObjectId(obj)
94
+ defined?(Moped) ? Moped::BSON::ObjectId.from_string(obj) : BSON::ObjectId(obj)
37
95
  elsif obj.is_a?(Array)
38
96
  obj.map do |v|
39
97
  convert_ids(v)
@@ -57,18 +115,16 @@ if defined?(Mongoid)
57
115
  puts "Converting #{collection_name} to use ObjectIDs"
58
116
 
59
117
  # get old collection
60
- collection = Mongoid.master.collection(collection_name)
118
+ collection = mongoid_collection(collection_name)
61
119
 
62
120
  # get new collection (a clean one)
63
- collection.db["#{collection_name}_new"].drop
64
- new_collection = collection.db["#{collection_name}_new"]
121
+ mongoid_collection("#{collection_name}_new").drop
122
+ new_collection = mongoid_new_collection(collection, "#{collection_name}_new")
65
123
 
66
124
  # convert collection documents
67
- collection.find({}, :timeout => false, :sort => "_id") do |cursor|
68
- cursor.each do |doc|
69
- new_doc = convert_ids(doc)
70
- new_collection.insert(new_doc, :safe => true)
71
- end
125
+ enum_mongoid_documents(collection) do |doc|
126
+ new_doc = convert_ids(doc)
127
+ new_collection.insert(new_doc, :safe => true)
72
128
  end
73
129
 
74
130
  puts "Done! Converted collection is in #{new_collection.name}\n\n"
@@ -76,15 +132,15 @@ if defined?(Mongoid)
76
132
 
77
133
  # no errors. great! now rename _new to collection_name
78
134
  collection_names.each do |collection_name|
79
- collection = Mongoid.master.collection(collection_name)
80
- new_collection = collection.db["#{collection_name}_new"]
135
+ collection = mongoid_collection(collection_name)
136
+ new_collection = mongoid_new_collection(collection, "#{collection_name}_new")
81
137
 
82
138
  # swap collection to _old
83
139
  puts "Moving #{collection.name} to #{collection_name}_old"
84
- collection.db["#{collection_name}_old"].drop
140
+ mongoid_new_collection(collection, "#{collection_name}_old").drop
85
141
 
86
142
  begin
87
- collection.rename("#{collection_name}_old")
143
+ rename_mongoid_collection(collection, "#{collection_name}_old")
88
144
  rescue StandardError => e
89
145
  puts "Unable to rename database #{collection_name} to #{collection_name}_old"
90
146
  puts "reason: #{e.message}\n\n"
@@ -94,7 +150,7 @@ if defined?(Mongoid)
94
150
  puts "Moving #{new_collection.name} to #{collection_name}\n\n"
95
151
 
96
152
  begin
97
- new_collection.rename(collection_name)
153
+ rename_mongoid_collection(new_collection, collection_name)
98
154
  rescue StandardError => e
99
155
  puts "Unable to rename database #{new_collection.name} to #{collection_name}"
100
156
  puts "reason: #{e.message}\n\n"
@@ -107,9 +163,11 @@ if defined?(Mongoid)
107
163
  desc "Clean up old collections backed up by objectid_convert"
108
164
  task :cleanup_old_collections => :environment do
109
165
  collection_names.each do |collection_name|
110
- collection = Mongoid.master.collection(collection_name)
111
- collection.db["#{collection.name}_old"].drop
166
+ collection = mongoid_collection(collection_name)
167
+ mongoid_new_collection(collection, "#{collection.name}_old").drop
112
168
  end
113
169
  end
114
170
  end
171
+
172
+ task 'db:drop' => 'mi:drop'
115
173
  end
@@ -1,6 +1,12 @@
1
1
  if defined?(MongoMapper)
2
+ begin
3
+ require 'i18n'
4
+ rescue LoadError
5
+ # only do this for I18n check later
6
+ end
7
+
2
8
  namespace :mm do
3
- desc 'Drops all the collections for the database for the current Rails.env'
9
+ desc 'Drops all the collections for the database for the current Padrino.env'
4
10
  task :drop => :environment do
5
11
  MongoMapper.database.collections.select {|c| c.name !~ /system/ }.each(&:drop)
6
12
  end
@@ -47,4 +53,6 @@ if defined?(MongoMapper)
47
53
  end
48
54
  end
49
55
  end
56
+
57
+ task 'db:drop' => 'mm:drop'
50
58
  end
@@ -1,4 +1,4 @@
1
- if defined?(Sequel)
1
+ if PadrinoTasks.load?(:sequel, defined?(Sequel))
2
2
  namespace :sq do
3
3
  namespace :migrate do
4
4
 
@@ -33,5 +33,10 @@ if defined?(Sequel)
33
33
  puts "<= sq:migrate:down executed"
34
34
  end
35
35
  end
36
+
37
+ desc "Perform migration up to latest migration available"
38
+ task :migrate => 'sq:migrate:up'
36
39
  end
40
+
41
+ task 'db:migrate' => 'sq:migrate'
37
42
  end
data/lib/padrino-gen.rb CHANGED
@@ -40,7 +40,7 @@ module Padrino
40
40
  end
41
41
 
42
42
  ##
43
- # Gloabl add a new generator class to +padrino-gen+
43
+ # Global add a new generator class to +padrino-gen+
44
44
  #
45
45
  # @param [Symbol] name
46
46
  # key name for generator mapping
@@ -72,7 +72,7 @@ module Padrino
72
72
  end # Padrino
73
73
 
74
74
  ##
75
- # We add our generators to Padrino::Genererator
75
+ # We add our generators to Padrino::Generators
76
76
  #
77
77
  Padrino::Generators.load_paths << Dir[File.dirname(__FILE__) + '/padrino-gen/generators/{project,app,mailer,controller,model,migration,plugin}.rb']
78
78
 
data/padrino-gen.gemspec CHANGED
File without changes
data/test/helper.rb CHANGED
@@ -100,7 +100,7 @@ class MiniTest::Spec
100
100
  path = File.join(options[:root],'lib',"#{name}_init.rb")
101
101
  instance = mock
102
102
  instance.expects(:invoke!).at_least_once
103
- include_text = " register #{name.to_s.camelize}Initializer\n"
103
+ include_text = " register #{name.to_s.camelize}Initializer\n"
104
104
  Thor::Actions::InjectIntoFile.expects(:new).with(anything,anything, include_text, anything).returns(instance)
105
105
  Thor::Actions::CreateFile.expects(:new).with(anything, path, kind_of(Proc), anything).returns(instance)
106
106
  end
@@ -28,12 +28,31 @@ describe "AppGenerator" do
28
28
  assert_file_exists("#{@apptmp}/sample_project/demo/views")
29
29
  assert_file_exists("#{@apptmp}/sample_project/demo/views/layouts")
30
30
  assert_dir_exists("#{@apptmp}/sample_project/public/demo")
31
- assert_match_in_file('Padrino.mount("Demo").to("/demo")', "#{@apptmp}/sample_project/config/apps.rb")
31
+ assert_match_in_file("Padrino.mount('SampleProject::Demo', :app_file => Padrino.root('demo/app.rb')).to('/demo')", "#{@apptmp}/sample_project/config/apps.rb")
32
+ assert_match_in_file('module SampleProject', "#{@apptmp}/sample_project/demo/app.rb")
32
33
  assert_match_in_file('class Demo < Padrino::Application', "#{@apptmp}/sample_project/demo/app.rb")
33
34
  assert_match_in_file(/Padrino.configure_apps do/, "#{@apptmp}/sample_project/config/apps.rb")
34
35
  assert_match_in_file(/set :session_secret, '[0-9A-z]*'/, "#{@apptmp}/sample_project/config/apps.rb")
35
36
  end
36
37
 
38
+ should "create correctly a new padrino application with an underscore name" do
39
+ capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}") }
40
+ capture_io { generate(:app, 'demo_app', "--root=#{@apptmp}/sample_project") }
41
+ assert_file_exists("#{@apptmp}/sample_project")
42
+ assert_file_exists("#{@apptmp}/sample_project/demo_app")
43
+ assert_file_exists("#{@apptmp}/sample_project/demo_app/app.rb")
44
+ assert_file_exists("#{@apptmp}/sample_project/demo_app/controllers")
45
+ assert_file_exists("#{@apptmp}/sample_project/demo_app/helpers")
46
+ assert_file_exists("#{@apptmp}/sample_project/demo_app/views")
47
+ assert_file_exists("#{@apptmp}/sample_project/demo_app/views/layouts")
48
+ assert_dir_exists("#{@apptmp}/sample_project/public/demo_app")
49
+ assert_match_in_file("Padrino.mount('SampleProject::DemoApp', :app_file => Padrino.root('demo_app/app.rb')).to('/demo_app')", "#{@apptmp}/sample_project/config/apps.rb")
50
+ assert_match_in_file('module SampleProject', "#{@apptmp}/sample_project/demo_app/app.rb")
51
+ assert_match_in_file('class DemoApp < Padrino::Application', "#{@apptmp}/sample_project/demo_app/app.rb")
52
+ assert_match_in_file(/Padrino.configure_apps do/, "#{@apptmp}/sample_project/config/apps.rb")
53
+ assert_match_in_file(/set :session_secret, '[0-9A-z]*'/, "#{@apptmp}/sample_project/config/apps.rb")
54
+ end
55
+
37
56
  should "generate tiny app skeleton" do
38
57
  capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}") }
39
58
  capture_io { generate(:app, 'demo','--tiny',"--root=#{@apptmp}/sample_project") }
@@ -52,15 +71,15 @@ describe "AppGenerator" do
52
71
  capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}") }
53
72
  capture_io { generate(:app, 'demo', "--root=#{@apptmp}/sample_project") }
54
73
  capture_io { generate(:controller, 'demo_items', "-r=#{@apptmp}/sample_project", '-a=demo') }
55
- assert_match_in_file(/Demo.controllers :demo_items do/m, "#{@apptmp}/sample_project/demo/controllers/demo_items.rb")
56
- assert_match_in_file(/Demo.helpers do/m, "#{@apptmp}/sample_project/demo/helpers/demo_items_helper.rb")
74
+ assert_match_in_file(/SampleProject::Demo.controllers :demo_items do/m, "#{@apptmp}/sample_project/demo/controllers/demo_items.rb")
75
+ assert_match_in_file(/SampleProject::Demo.helpers do/m, "#{@apptmp}/sample_project/demo/helpers/demo_items_helper.rb")
57
76
  assert_file_exists("#{@apptmp}/sample_project/demo/views/demo_items")
58
77
  end
59
78
 
60
79
  should "correctly create a new mailer inside a padrino application" do
61
80
  capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=bacon') }
62
81
  capture_io { generate(:app, 'demo_app', "--root=#{@apptmp}/sample_project") }
63
- capture_io { generate(:mailer, 'demo', "-r=#{@apptmp}/sample_project", '-a=demoapp') }
82
+ capture_io { generate(:mailer, 'demo', "-r=#{@apptmp}/sample_project", '-a=demo_app') }
64
83
  end
65
84
 
66
85
  # only destroys what it generated.
@@ -22,8 +22,8 @@ describe "ControllerGenerator" do
22
22
  should "generate controller within existing project" do
23
23
  capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=bacon') }
24
24
  capture_io { generate(:controller, 'DemoItems', "-r=#{@apptmp}/sample_project") }
25
- assert_match_in_file(/SampleProject.controllers :demo_items do/m, @controller_path)
26
- assert_match_in_file(/SampleProject.helpers do/m, "#{@apptmp}/sample_project/app/helpers/demo_items_helper.rb")
25
+ assert_match_in_file(/SampleProject::App.controllers :demo_items do/m, @controller_path)
26
+ assert_match_in_file(/SampleProject::App.helpers do/m, "#{@apptmp}/sample_project/app/helpers/demo_items_helper.rb")
27
27
  assert_file_exists("#{@apptmp}/sample_project/app/views/demo_items")
28
28
  assert_file_exists(@controller_test_path)
29
29
  end
@@ -31,8 +31,8 @@ describe "ControllerGenerator" do
31
31
  should "generate controller within existing project with weird name" do
32
32
  capture_io { generate(:project, 'warepedia', "--root=#{@apptmp}", '--script=none', '-t=bacon') }
33
33
  capture_io { generate(:controller, 'DemoItems', "-r=#{@apptmp}/warepedia") }
34
- assert_match_in_file(/Warepedia.controllers :demo_items do/m, "#{@apptmp}/warepedia/app/controllers/demo_items.rb")
35
- assert_match_in_file(/Warepedia.helpers do/m, "#{@apptmp}/warepedia/app/helpers/demo_items_helper.rb")
34
+ assert_match_in_file(/Warepedia::App.controllers :demo_items do/m, "#{@apptmp}/warepedia/app/controllers/demo_items.rb")
35
+ assert_match_in_file(/Warepedia::App.helpers do/m, "#{@apptmp}/warepedia/app/helpers/demo_items_helper.rb")
36
36
  assert_file_exists("#{@apptmp}/warepedia/app/views/demo_items")
37
37
  end
38
38
 
@@ -40,8 +40,8 @@ describe "ControllerGenerator" do
40
40
  capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=bacon') }
41
41
  capture_io { generate(:app, 'subby', "-r=#{@apptmp}/sample_project") }
42
42
  capture_io { generate(:controller, 'DemoItems','-a=/subby', "-r=#{@apptmp}/sample_project") }
43
- assert_match_in_file(/Subby.controllers :demo_items do/m, @controller_path.gsub('app','subby'))
44
- assert_match_in_file(/Subby.helpers do/m, "#{@apptmp}/sample_project/subby/helpers/demo_items_helper.rb")
43
+ assert_match_in_file(/SampleProject::Subby.controllers :demo_items do/m, @controller_path.gsub('app','subby'))
44
+ assert_match_in_file(/SampleProject::Subby.helpers do/m, "#{@apptmp}/sample_project/subby/helpers/demo_items_helper.rb")
45
45
  assert_file_exists("#{@apptmp}/sample_project/subby/views/demo_items")
46
46
  assert_match_in_file(/describe "DemoItemsController" do/m, @controller_test_path.gsub('app','subby'))
47
47
  end
@@ -49,8 +49,8 @@ describe "ControllerGenerator" do
49
49
  should 'not fail if we don\'t have test component' do
50
50
  capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--test=none') }
51
51
  capture_io { generate(:controller, 'DemoItems', "-r=#{@apptmp}/sample_project") }
52
- assert_match_in_file(/SampleProject.controllers :demo_items do/m, @controller_path)
53
- assert_match_in_file(/SampleProject.helpers do/m, "#{@apptmp}/sample_project/app/helpers/demo_items_helper.rb")
52
+ assert_match_in_file(/SampleProject::App.controllers :demo_items do/m, @controller_path)
53
+ assert_match_in_file(/SampleProject::App.helpers do/m, "#{@apptmp}/sample_project/app/helpers/demo_items_helper.rb")
54
54
  assert_file_exists("#{@apptmp}/sample_project/app/views/demo_items")
55
55
  assert_no_file_exists("#{@apptmp}/sample_project/test")
56
56
  end
@@ -21,7 +21,7 @@ describe "MailerGenerator" do
21
21
  capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=bacon') }
22
22
  capture_io { generate(:app, 'subby', "-r=#{@apptmp}/sample_project") }
23
23
  capture_io { generate(:mailer, 'demo', '-a=/subby', "-r=#{@apptmp}/sample_project") }
24
- assert_match_in_file(/Subby.mailer :demo/m, "#{@apptmp}/sample_project/subby/mailers/demo.rb")
24
+ assert_match_in_file(/SampleProject::Subby.mailer :demo/m, "#{@apptmp}/sample_project/subby/mailers/demo.rb")
25
25
  assert_dir_exists("#{@apptmp}/sample_project/subby/views/mailers/demo")
26
26
  end
27
27
 
@@ -29,7 +29,7 @@ describe "MailerGenerator" do
29
29
  capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=bacon') }
30
30
  capture_io { generate(:app, 'subby', "-r=#{@apptmp}/sample_project") }
31
31
  capture_io { generate(:mailer, 'demo', 'action1', 'action2', '-a=/subby', "-r=#{@apptmp}/sample_project") }
32
- assert_match_in_file(/Subby.mailer :demo/m, "#{@apptmp}/sample_project/subby/mailers/demo.rb")
32
+ assert_match_in_file(/SampleProject::Subby.mailer :demo/m, "#{@apptmp}/sample_project/subby/mailers/demo.rb")
33
33
  assert_match_in_file(/email :action1 do.*?end/m, "#{@apptmp}/sample_project/subby/mailers/demo.rb")
34
34
  assert_match_in_file(/email :action2 do.*?end/m, "#{@apptmp}/sample_project/subby/mailers/demo.rb")
35
35
  assert_dir_exists("#{@apptmp}/sample_project/subby/views/mailers/demo")
@@ -38,21 +38,21 @@ describe "MailerGenerator" do
38
38
  should "support generating a new mailer extended from base" do
39
39
  capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=bacon') }
40
40
  capture_io { generate(:mailer, 'demo', "-r=#{@apptmp}/sample_project") }
41
- assert_match_in_file(/SampleProject.mailer :demo/m, "#{@apptmp}/sample_project/app/mailers/demo.rb")
41
+ assert_match_in_file(/SampleProject::App.mailer :demo/m, "#{@apptmp}/sample_project/app/mailers/demo.rb")
42
42
  assert_dir_exists("#{@apptmp}/sample_project/app/views/mailers/demo")
43
43
  end
44
44
 
45
45
  should "support generating a new mailer extended from base with long name" do
46
46
  capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=bacon') }
47
47
  capture_io { generate(:mailer, 'UserNotice', "-r=#{@apptmp}/sample_project") }
48
- assert_match_in_file(/SampleProject.mailer :user_notice/m, "#{@apptmp}/sample_project/app/mailers/user_notice.rb")
48
+ assert_match_in_file(/SampleProject::App.mailer :user_notice/m, "#{@apptmp}/sample_project/app/mailers/user_notice.rb")
49
49
  assert_dir_exists("#{@apptmp}/sample_project/app/views/mailers/user_notice")
50
50
  end
51
51
 
52
52
  should "support generating a new mailer extended from base with capitalized name" do
53
53
  capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=bacon') }
54
54
  capture_io { generate(:mailer, 'DEMO', "-r=#{@apptmp}/sample_project") }
55
- assert_match_in_file(/SampleProject.mailer :demo/m, "#{@apptmp}/sample_project/app/mailers/demo.rb")
55
+ assert_match_in_file(/SampleProject::App.mailer :demo/m, "#{@apptmp}/sample_project/app/mailers/demo.rb")
56
56
  assert_dir_exists("#{@apptmp}/sample_project/app/views/mailers/demo")
57
57
  end
58
58
  end
@@ -54,7 +54,6 @@ describe "ModelGenerator" do
54
54
  assert_match_in_file(/class Post\n\s+include DataMapper::Resource/m, "#{@apptmp}/sample_project/subby/models/post.rb")
55
55
  assert_match_in_file(/property :body, String/m, "#{@apptmp}/sample_project/subby/models/post.rb")
56
56
  assert_match_in_file(/migration 1, :create_posts do/m, "#{@apptmp}/sample_project/db/migrate/001_create_posts.rb")
57
- assert_match_in_file(/gem 'dm-core'/m,"#{@apptmp}/sample_project/Gemfile")
58
57
  assert_match_in_file(/DataMapper.finalize/m,"#{@apptmp}/sample_project/config/boot.rb")
59
58
  end
60
59
 
@@ -76,6 +75,19 @@ describe "ModelGenerator" do
76
75
  assert_file_exists("#{@apptmp}/sample_project/db/migrate/002_create_accounts.rb")
77
76
  assert_file_exists("#{@apptmp}/sample_project/db/migrate/003_create_banks.rb")
78
77
  end
78
+
79
+ should "generate a default type value for fields" do
80
+ current_time = stop_time_for_test.strftime("%Y%m%d%H%M%S")
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)
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
+ end
79
91
  end
80
92
 
81
93
  # ACTIVERECORD
@@ -123,9 +135,9 @@ describe "ModelGenerator" do
123
135
  end
124
136
 
125
137
  # MINIRECORD
126
- context "model generator using mini_record" do
138
+ context "model generator using minirecord" do
127
139
  should "generate hooks for auto upgrade" do
128
- capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=bacon', '-d=mini_record') }
140
+ capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=bacon', '-d=minirecord') }
129
141
  assert_match_in_file(
130
142
  "Padrino.after_load do\n ActiveRecord::Base.auto_upgrade!",
131
143
  "#{@apptmp}/sample_project/config/boot.rb"
@@ -138,7 +150,7 @@ describe "ModelGenerator" do
138
150
  end
139
151
 
140
152
  should "generate model file" do
141
- capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=bacon', '-d=mini_record') }
153
+ capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=bacon', '-d=minirecord') }
142
154
  capture_io { generate(:model, 'user', 'name:string', 'surname:string', 'age:integer', "-r=#{@apptmp}/sample_project") }
143
155
  assert_match_in_file(/class User < ActiveRecord::Base/m, "#{@apptmp}/sample_project/models/user.rb")
144
156
  assert_match_in_file(/field :name, :as => :string/m, "#{@apptmp}/sample_project/models/user.rb")
@@ -147,7 +159,7 @@ describe "ModelGenerator" do
147
159
  end
148
160
 
149
161
  should "generate model file with camelized name" do
150
- capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=bacon', '-d=mini_record') }
162
+ capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=bacon', '-d=minirecord') }
151
163
  capture_io { generate(:model, 'ChunkyBacon', "-r=#{@apptmp}/sample_project") }
152
164
  assert_match_in_file(/class ChunkyBacon < ActiveRecord::Base/m, "#{@apptmp}/sample_project/models/chunky_bacon.rb")
153
165
  assert_match_in_file(/ChunkyBacon Model/, "#{@apptmp}/sample_project/test/models/chunky_bacon_test.rb")
@@ -175,13 +187,6 @@ describe "ModelGenerator" do
175
187
 
176
188
  # DATAMAPPER
177
189
  context "model generator using datamapper" do
178
-
179
- should "generate gemfile gem" do
180
- capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-d=datamapper') }
181
- capture_io { generate(:model, 'user', "name:string", "age:integer", "created_at:datetime", "-r=#{@apptmp}/sample_project") }
182
- assert_match_in_file(/gem 'dm-core'/m,"#{@apptmp}/sample_project/Gemfile")
183
- end
184
-
185
190
  should "generate model file with camelized name" do
186
191
  capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=bacon', '-d=datamapper') }
187
192
  capture_io { generate(:model, 'ChunkyBacon', "-r=#{@apptmp}/sample_project") }
@@ -301,8 +306,6 @@ describe "ModelGenerator" do
301
306
  capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-d=ohm') }
302
307
  capture_io { generate(:model, 'person', "-r=#{@apptmp}/sample_project") }
303
308
  assert_match_in_file(/class Person < Ohm::Model/, "#{@apptmp}/sample_project/models/person.rb")
304
- assert_match_in_file(/include Ohm::Timestamping/, "#{@apptmp}/sample_project/models/person.rb")
305
- assert_match_in_file(/include Ohm::Typecast/, "#{@apptmp}/sample_project/models/person.rb")
306
309
  assert_match_in_file(/# attribute :name/m, "#{@apptmp}/sample_project/models/person.rb")
307
310
  assert_match_in_file(/# reference :venue, Venue/m, "#{@apptmp}/sample_project/models/person.rb")
308
311
  end
@@ -311,9 +314,9 @@ describe "ModelGenerator" do
311
314
  capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-d=ohm') }
312
315
  capture_io { generate(:model, 'user', "name:string", "age:integer", "email:string", "-r=#{@apptmp}/sample_project") }
313
316
  assert_match_in_file(/class User < Ohm::Model/, "#{@apptmp}/sample_project/models/user.rb")
314
- assert_match_in_file(/attribute :name, String/m, "#{@apptmp}/sample_project/models/user.rb")
315
- assert_match_in_file(/attribute :age, Integer/m, "#{@apptmp}/sample_project/models/user.rb")
316
- assert_match_in_file(/attribute :email, String/m, "#{@apptmp}/sample_project/models/user.rb")
317
+ assert_match_in_file(/attribute :name/m, "#{@apptmp}/sample_project/models/user.rb")
318
+ assert_match_in_file(/attribute :age/m, "#{@apptmp}/sample_project/models/user.rb")
319
+ assert_match_in_file(/attribute :email/m, "#{@apptmp}/sample_project/models/user.rb")
317
320
  end
318
321
  end
319
322
 
@@ -424,18 +427,18 @@ describe "ModelGenerator" do
424
427
  capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=rspec', '-d=activerecord') }
425
428
  capture_io { generate(:app, 'subby', "-r=#{@apptmp}/sample_project") }
426
429
  capture_io { generate(:model, 'SomeUser', "-r=#{@apptmp}/sample_project") }
427
- assert_match_in_file(/describe "SomeUser Model"/m, "#{@apptmp}/sample_project/spec/models/some_user_spec.rb")
428
- assert_match_in_file(/let\(:some_user\) \{ SomeUser.new \}/m, "#{@apptmp}/sample_project/spec/models/some_user_spec.rb")
429
- assert_match_in_file(/some_user\.should_not be_nil/m, "#{@apptmp}/sample_project/spec/models/some_user_spec.rb")
430
+ assert_match_in_file(/describe SomeUser do/m, "#{@apptmp}/sample_project/spec/models/some_user_spec.rb")
431
+ # assert_match_in_file(/let\(:some_user\) \{ SomeUser.new \}/m, "#{@apptmp}/sample_project/spec/models/some_user_spec.rb")
432
+ # assert_match_in_file(/some_user\.should_not be_nil/m, "#{@apptmp}/sample_project/spec/models/some_user_spec.rb")
430
433
  end
431
434
 
432
435
  should "generate test file for rspec in specified app" do
433
436
  capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=rspec', '-d=activerecord') }
434
437
  capture_io { generate(:app, 'subby', "-r=#{@apptmp}/sample_project") }
435
438
  capture_io { generate(:model, 'SomeUser', "-a=/subby", "-r=#{@apptmp}/sample_project") }
436
- assert_match_in_file(/describe "SomeUser Model"/m, "#{@apptmp}/sample_project/spec/subby/models/some_user_spec.rb")
437
- assert_match_in_file(/let\(:some_user\) \{ SomeUser.new \}/m, "#{@apptmp}/sample_project/spec/subby/models/some_user_spec.rb")
438
- assert_match_in_file(/some_user\.should_not be_nil/m, "#{@apptmp}/sample_project/spec/subby/models/some_user_spec.rb")
439
+ assert_match_in_file(/describe SomeUser do/m, "#{@apptmp}/sample_project/spec/subby/models/some_user_spec.rb")
440
+ # assert_match_in_file(/let\(:some_user\) \{ SomeUser.new \}/m, "#{@apptmp}/sample_project/spec/subby/models/some_user_spec.rb")
441
+ # assert_match_in_file(/some_user\.should_not be_nil/m, "#{@apptmp}/sample_project/spec/subby/models/some_user_spec.rb")
439
442
  end
440
443
 
441
444
  # SHOULDA
@@ -80,6 +80,29 @@ describe "PluginGenerator" do
80
80
  plugin_gen.expects(:apply).with(resolved_path).returns(true).once
81
81
  capture_io { plugin_gen.invoke_all }
82
82
  end
83
+
84
+ should "print a warning if template cannot be found" do
85
+ template_file = 'hwat'
86
+ resolved_path = "https://github.com/padrino/padrino-recipes/raw/master/plugins/hwat_plugin.rb"
87
+ plugin_gen = Padrino::Generators::Plugin.new([ template_file], ["-r=#{@apptmp}/sample_project"],{})
88
+ plugin_gen.expects(:in_app_root?).returns(true).once
89
+ plugin_gen.expects(:say).with("The template at #{resolved_path} could not be found!", :red).returns(true).once
90
+ capture_io { plugin_gen.invoke_all }
91
+ end
92
+ end
93
+
94
+ context "with list option" do
95
+ should "return a list of available plugins with no parameter" do
96
+ plugin_gen = Padrino::Generators::Plugin.new([], [],{})
97
+ plugin_gen.expects(:list_plugins).returns(true).once
98
+ capture_io { plugin_gen.invoke_all }
99
+ end
100
+
101
+ should "return a list of available plugins with list option" do
102
+ plugin_gen = Padrino::Generators::Plugin.new(['some_plugin'], ["-l", "-r=#{@apptmp}/sample_project"],{})
103
+ plugin_gen.expects(:list_plugins).returns(true).once
104
+ capture_io { plugin_gen.invoke_all }
105
+ end
83
106
  end
84
107
 
85
108
  context "with git commands" do