padrino-gen 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +102 -9
- data/VERSION +1 -1
- data/bin/padrino-gen +3 -1
- data/lib/generators/actions.rb +8 -1
- data/lib/generators/components/orms/activerecord_gen.rb +45 -4
- data/lib/generators/components/orms/couchrest_gen.rb +28 -3
- data/lib/generators/components/orms/datamapper_gen.rb +49 -3
- data/lib/generators/components/orms/mongomapper_gen.rb +26 -3
- data/lib/generators/components/orms/sequel_gen.rb +42 -1
- data/lib/generators/components/tests/bacon_test_gen.rb +20 -4
- data/lib/generators/components/tests/riot_test_gen.rb +16 -0
- data/lib/generators/components/tests/rspec_test_gen.rb +16 -0
- data/lib/generators/components/tests/shoulda_test_gen.rb +18 -0
- data/lib/generators/components/tests/testspec_test_gen.rb +16 -0
- data/lib/generators/controller.rb +3 -2
- data/lib/generators/mailer.rb +37 -0
- data/lib/generators/model.rb +40 -0
- data/lib/generators/skeleton/{app.rb.tt → app/app.rb.tt} +0 -0
- data/lib/generators/skeleton/config/urls.rb.tt +1 -1
- data/lib/generators/templates/controller.rb.tt +1 -1
- data/lib/generators/templates/helper.rb.tt +1 -1
- data/lib/generators/templates/mailer.rb.tt +19 -0
- data/lib/generators/templates/mailer_initializer.rb.tt +19 -0
- data/lib/padrino-gen.rb +1 -2
- data/padrino-gen.gemspec +10 -3
- data/test/test_controller_generator.rb +3 -2
- data/test/test_mailer_generator.rb +43 -0
- data/test/test_migration_generator.rb +17 -0
- data/test/test_model_generator.rb +195 -0
- data/test/test_skeleton_generator.rb +3 -3
- metadata +10 -3
data/README.rdoc
CHANGED
@@ -16,15 +16,31 @@ Thor gem (incidentally also used in the Rails 3 generators). These generators ar
|
|
16
16
|
generation both in creating new applications and building on existing ones. The generators have been built to be as
|
17
17
|
library-agnostic as possible, supporting a myriad of test frameworks, js libraries, mocking libraries, etc.
|
18
18
|
|
19
|
-
|
19
|
+
See the wiki article for additional information: <...WIKI...>
|
20
|
+
|
21
|
+
=== Application Generator ===
|
22
|
+
|
23
|
+
Padrino provides generator support for quickly creating new Padrino applications. This provides many benefits
|
24
|
+
such as constructing the recommended Padrino application structure, auto-generating a Gemfile listing
|
25
|
+
all starting dependencies and guidelines provided within the generated files to help orient a new user
|
26
|
+
to using Padrino.
|
27
|
+
|
28
|
+
One important feature of the generators is that they were built from the ground up to support a wide variety
|
29
|
+
of tools, libraries and gems for use within your padrino application.
|
30
|
+
|
31
|
+
This means that Padrino generators do *not* lock you into using any particular database, ORM, testing framework,
|
32
|
+
templating engine or javascript library. In fact, when generating an application you can actually tell
|
33
|
+
Padrino which components you would like to use!
|
20
34
|
|
21
|
-
|
35
|
+
The usage for the app generator is quite simple:
|
36
|
+
|
37
|
+
$ padrino-gen app <the_app_name> </path/to/create/app> --<component-name> <value>
|
22
38
|
|
23
39
|
The simplest possible command to generate a base application would be:
|
24
40
|
|
25
41
|
$ padrino-gen demo_app .
|
26
42
|
|
27
|
-
This would construct a
|
43
|
+
This would construct a Padrino application DemoApp (which extends from Padrino::Application)
|
28
44
|
inside the folder 'demo_app' at our current path. Inside the application there would be configuration and
|
29
45
|
setup performed for the default components.
|
30
46
|
|
@@ -58,14 +74,91 @@ This would be achieved through forking our project and reading through the code
|
|
58
74
|
the setup instructions inside the relevant files within <tt>/generators/components/</tt>. We are happy to accept pull requests
|
59
75
|
for additional component types not originally included (although helping us maintain them would also be appreciated).
|
60
76
|
|
61
|
-
|
77
|
+
=== Model Generator ===
|
62
78
|
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
* Migrations generation
|
79
|
+
Padrino provides generator support for quickly creating new models within your Padrino application. Note that
|
80
|
+
the models (and migrations) generated are specifically tailored towards the ORM component and testing framework
|
81
|
+
chosen during application generation.
|
67
82
|
|
68
|
-
|
83
|
+
Very important to note that model generators are intended primarily to work within applications
|
84
|
+
created through the Padrino application generator and that follow Padrino conventions. Using model generators
|
85
|
+
within an existing application not generated by Padrino will likely not work as expected.
|
86
|
+
|
87
|
+
Using the model generator is as simple as:
|
88
|
+
|
89
|
+
$ padrino-gen model User
|
90
|
+
|
91
|
+
You can also specify desired fields to be contained within your User model:
|
92
|
+
|
93
|
+
$ padrino-gen model User name:string age:integer email:string
|
94
|
+
|
95
|
+
The model generator will create multiple files within your application and based on your ORM component.
|
96
|
+
Usually the model file will generate files similar to the following:
|
97
|
+
|
98
|
+
* model definition file [app/models/user.rb]
|
99
|
+
* migration declaration [db/migrate/xxx_create_users.rb]
|
100
|
+
* model unit test file [test/models/user_test.rb]
|
101
|
+
|
102
|
+
You can define as many models as you would like in a Padrino application using this generator.
|
103
|
+
|
104
|
+
=== Migration Generator ===
|
105
|
+
|
106
|
+
Padrino provides generator for quickly generating new migrations to change or manipulate the database schema.
|
107
|
+
These migrations generated will be tailored towards the ORM chosen when generating the application.
|
108
|
+
|
109
|
+
Very important to note that migration generators are intended primarily to work within applications
|
110
|
+
created through the Padrino application generator and that follow Padrino conventions. Using migration generators
|
111
|
+
within an existing application not generated by Padrino will likely not work as expected.
|
112
|
+
|
113
|
+
Using the migration generator is as simple as:
|
114
|
+
|
115
|
+
$ padrino-gen migration AddFieldsToUsers
|
116
|
+
$ padrino-gen migration RemoveFieldsFromUsers
|
117
|
+
|
118
|
+
You can also specify desired columns to be added to the migration file:
|
119
|
+
|
120
|
+
$ padrino-gen migration AddFieldsToUsers last_login:datetime crypted_password:string
|
121
|
+
$ padrino-gen migration RemoveFieldsFromUsers password:string ip_address:string
|
122
|
+
|
123
|
+
The migration generator will then construct the migration file according to your ORM component chosen
|
124
|
+
within <tt>db/migrate/xxx_add_fields_to_users.rb</tt> including the columns specified in the command.
|
125
|
+
|
126
|
+
=== Controller Generator ===
|
127
|
+
|
128
|
+
Padrino provides generator support for quickly creating new controllers within your Padrino application. Note that
|
129
|
+
the controller tests are generated specifically tailored towards the testing framework chosen
|
130
|
+
during application generation.
|
131
|
+
|
132
|
+
Very important to note that controller generators are intended primarily to work within applications
|
133
|
+
created through the Padrino application generator and that follow Padrino conventions.
|
134
|
+
|
135
|
+
Using the controller generator is as simple as:
|
136
|
+
|
137
|
+
$ padrino-gen controller Admin
|
138
|
+
|
139
|
+
You can also specify desired actions to be added to your controller:
|
140
|
+
|
141
|
+
$ padrino-gen controller Admin :index [:admin, :index]
|
142
|
+
|
143
|
+
The controller generator will then construct the controller file within <tt>app/controllers/admin.rb</tt>
|
144
|
+
and also a controller test file at <tt>test/controllers/admin_controller_test.rb</tt> according to the
|
145
|
+
test framework chosen during app generation.
|
146
|
+
|
147
|
+
=== Mailer Generator ===
|
148
|
+
|
149
|
+
Padrino provides generator support for quickly creating new mailers within your Padrino application.
|
150
|
+
Very important to note that mailer generators are intended primarily to work within applications
|
151
|
+
created through the Padrino application generator and that follow Padrino conventions.
|
152
|
+
|
153
|
+
Using the mailer generator is as simple as:
|
154
|
+
|
155
|
+
$ padrino-gen mailer UserNotifier
|
156
|
+
|
157
|
+
You can also specify desired delivery actions to be added to the mailer:
|
158
|
+
|
159
|
+
$ padrino-gen mailer UserNotifier confirm_account welcome inactive_account
|
160
|
+
|
161
|
+
The mailer generator will then construct the mailer file within <tt>app/mailers/user_notifier.rb</tt>
|
69
162
|
|
70
163
|
== Copyright
|
71
164
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.3
|
data/bin/padrino-gen
CHANGED
@@ -3,8 +3,10 @@
|
|
3
3
|
require File.dirname(__FILE__) + "/../lib/padrino-gen"
|
4
4
|
|
5
5
|
generator_mappings = ActiveSupport::OrderedHash.new
|
6
|
-
generator_mappings[:app]
|
6
|
+
generator_mappings[:app] = Padrino::Generators::Skeleton
|
7
|
+
generator_mappings[:model] = Padrino::Generators::Model
|
7
8
|
generator_mappings[:controller] = Padrino::Generators::Controller
|
9
|
+
generator_mappings[:mailer] = Padrino::Generators::Mailer
|
8
10
|
|
9
11
|
generator_kind = ARGV.delete_at(0).to_s.downcase.to_sym if ARGV[0].present?
|
10
12
|
generator_class = generator_mappings[generator_kind]
|
data/lib/generators/actions.rb
CHANGED
@@ -79,9 +79,16 @@ module Padrino
|
|
79
79
|
|
80
80
|
# Returns the app_name for the application at root
|
81
81
|
def fetch_app_name(root=nil)
|
82
|
-
app_path = root ? File.join(root, 'app.rb') : 'app.rb'
|
82
|
+
app_path = root ? File.join(root, 'app/app.rb') : 'app/app.rb'
|
83
83
|
@app_name ||= File.read(app_path).scan(/class\s(.*?)\s</).flatten[0]
|
84
84
|
end
|
85
|
+
|
86
|
+
# Constructs a path from the specified app root
|
87
|
+
# build_target_path("app/mailers", "#{@mailer_basename}.rb")
|
88
|
+
def app_root_path(*paths)
|
89
|
+
settings = paths.extract_options!
|
90
|
+
File.join(settings[:root] || options[:root] || '.', *paths)
|
91
|
+
end
|
85
92
|
|
86
93
|
module ClassMethods
|
87
94
|
# Defines a class option to allow a component to be chosen and add to component type list
|
@@ -2,9 +2,9 @@ module Padrino
|
|
2
2
|
module Generators
|
3
3
|
module Components
|
4
4
|
module Orms
|
5
|
-
|
5
|
+
|
6
6
|
module ActiverecordGen
|
7
|
-
|
7
|
+
|
8
8
|
AR = (<<-AR).gsub(/^ {10}/, '')
|
9
9
|
module DatabaseSetup
|
10
10
|
def self.registered(app)
|
@@ -35,7 +35,7 @@ module Padrino
|
|
35
35
|
RAKE = (<<-RAKE).gsub(/^ {10}/, '')
|
36
36
|
require 'sinatra/base'
|
37
37
|
require 'active_record'
|
38
|
-
|
38
|
+
|
39
39
|
namespace :db do
|
40
40
|
desc "Migrate the database"
|
41
41
|
task(:migrate) do
|
@@ -53,8 +53,49 @@ module Padrino
|
|
53
53
|
create_file("config/database.rb", AR)
|
54
54
|
create_file("Rakefile", RAKE)
|
55
55
|
end
|
56
|
+
|
57
|
+
AR_MODEL = (<<-MODEL).gsub(/^ {10}/, '')
|
58
|
+
class !NAME! < ActiveRecord::Base
|
59
|
+
|
60
|
+
end
|
61
|
+
MODEL
|
62
|
+
|
63
|
+
def create_model_file(name, fields)
|
64
|
+
model_path = app_root_path('app/models/', "#{name.to_s.underscore}.rb")
|
65
|
+
return false if File.exist?(model_path)
|
66
|
+
model_contents = AR_MODEL.gsub(/!NAME!/, name.to_s.downcase.camelize)
|
67
|
+
create_file(model_path, model_contents)
|
68
|
+
end
|
69
|
+
|
70
|
+
AR_MIGRATION = (<<-MIGRATION).gsub(/^ {10}/, '')
|
71
|
+
class !FILENAME! < ActiveRecord::Migration
|
72
|
+
def self.up
|
73
|
+
create_table :!TABLE! do |t|
|
74
|
+
# t.column <name>, <type>
|
75
|
+
# t.column :age, :integer
|
76
|
+
!FIELDS!
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
def self.down
|
81
|
+
drop_table :users
|
82
|
+
end
|
83
|
+
end
|
84
|
+
MIGRATION
|
85
|
+
|
86
|
+
def create_migration_file(filename, name, fields)
|
87
|
+
model_name = name.to_s.pluralize
|
88
|
+
field_tuples = fields.collect { |value| value.split(":") }
|
89
|
+
column_declarations = field_tuples.collect { |field, kind| "t.column :#{field}, :#{kind}" }.join("\n ")
|
90
|
+
migration_contents = AR_MIGRATION.gsub(/!NAME!/, model_name.camelize).gsub(/!TABLE!/, model_name.underscore)
|
91
|
+
migration_contents.gsub!(/!FILENAME!/, filename.camelize)
|
92
|
+
migration_contents.gsub!(/!FIELDS!/, column_declarations)
|
93
|
+
migration_filename = "#{Time.now.to_i}_#{filename}.rb"
|
94
|
+
create_file(app_root_path('db/migrate/', migration_filename), migration_contents)
|
95
|
+
end
|
96
|
+
|
56
97
|
end
|
57
98
|
end
|
58
99
|
end
|
59
100
|
end
|
60
|
-
end
|
101
|
+
end
|
@@ -2,7 +2,7 @@ module Padrino
|
|
2
2
|
module Generators
|
3
3
|
module Components
|
4
4
|
module Orms
|
5
|
-
|
5
|
+
|
6
6
|
module CouchrestGen
|
7
7
|
|
8
8
|
COUCHREST = (<<-COUCHREST).gsub(/^ {10}/, '')
|
@@ -20,10 +20,35 @@ module Padrino
|
|
20
20
|
require_dependencies 'couchrest'
|
21
21
|
create_file("config/database.rb", COUCHREST)
|
22
22
|
end
|
23
|
+
|
24
|
+
CR_MODEL = (<<-MODEL).gsub(/^ {10}/, '')
|
25
|
+
class !NAME! < CouchRest::ExtendedDocument
|
26
|
+
include CouchRest::Validation
|
27
|
+
|
28
|
+
use_database app { couchdb }
|
29
|
+
|
30
|
+
unique_id :id
|
31
|
+
# property <name>
|
32
|
+
!FIELDS!
|
33
|
+
end
|
34
|
+
MODEL
|
35
|
+
|
36
|
+
def create_model_file(name, fields)
|
37
|
+
model_path = app_root_path('app/models/', "#{name.to_s.underscore}.rb")
|
38
|
+
return false if File.exist?(model_path)
|
39
|
+
field_tuples = fields.collect { |value| value.split(":") }
|
40
|
+
column_declarations = field_tuples.collect { |field, kind| "property :#{field}" }.join("\n ")
|
41
|
+
model_contents = CR_MODEL.gsub(/!NAME!/, name.to_s.camelize)
|
42
|
+
model_contents.gsub!(/!FIELDS!/, column_declarations)
|
43
|
+
create_file(model_path, model_contents)
|
44
|
+
end
|
45
|
+
|
46
|
+
def create_migration_file(filename, name, fields)
|
47
|
+
# NO MIGRATION NEEDED
|
48
|
+
end
|
23
49
|
end
|
24
|
-
|
50
|
+
|
25
51
|
end
|
26
52
|
end
|
27
53
|
end
|
28
54
|
end
|
29
|
-
|
@@ -2,7 +2,7 @@ module Padrino
|
|
2
2
|
module Generators
|
3
3
|
module Components
|
4
4
|
module Orms
|
5
|
-
|
5
|
+
|
6
6
|
module DatamapperGen
|
7
7
|
|
8
8
|
DM = (<<-DM).gsub(/^ {10}/, '')
|
@@ -19,9 +19,55 @@ module Padrino
|
|
19
19
|
require_dependencies 'dm-core', 'dm-validations'
|
20
20
|
create_file("config/database.rb", DM)
|
21
21
|
end
|
22
|
+
|
23
|
+
DM_MODEL = (<<-MODEL).gsub(/^ {10}/, '')
|
24
|
+
class !NAME!
|
25
|
+
include DataMapper::Resource
|
26
|
+
|
27
|
+
# property <name>, <type>
|
28
|
+
# property :id, Serial
|
29
|
+
!FIELDS!
|
30
|
+
end
|
31
|
+
MODEL
|
32
|
+
|
33
|
+
def create_model_file(name, fields)
|
34
|
+
model_path = app_root_path('app/models/', "#{name.to_s.underscore}.rb")
|
35
|
+
return false if File.exist?(model_path)
|
36
|
+
model_contents = DM_MODEL.gsub(/!NAME!/, name.to_s.downcase.camelize)
|
37
|
+
field_tuples = fields.collect { |value| value.split(":") }
|
38
|
+
column_declarations = field_tuples.collect { |field, kind|"property :#{field}, #{kind.camelize}" }.join("\n ")
|
39
|
+
model_contents.gsub!(/!FIELDS!/, column_declarations)
|
40
|
+
create_file(model_path, model_contents)
|
41
|
+
end
|
42
|
+
|
43
|
+
DM_MIGRATION = (<<-MIGRATION).gsub(/^ {10}/, '')
|
44
|
+
migration NUM, :!FILENAME! do
|
45
|
+
up do
|
46
|
+
create_table(:!TABLE!) do
|
47
|
+
column(:id, Integer, :serial => true)
|
48
|
+
!FIELDS!
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
down do
|
53
|
+
drop_table(:!TABLE!)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
MIGRATION
|
57
|
+
|
58
|
+
def create_migration_file(filename, name, fields)
|
59
|
+
model_name = name.to_s.pluralize
|
60
|
+
field_tuples = fields.collect { |value| value.split(":") }
|
61
|
+
column_declarations = field_tuples.collect { |field, kind|"column(:#{field}, #{kind.camelize})" }.join("\n ")
|
62
|
+
migration_contents = DM_MIGRATION.gsub(/!NAME!/, model_name.camelize).gsub(/!TABLE!/, model_name.underscore)
|
63
|
+
migration_contents.gsub!(/!FILENAME!/, filename)
|
64
|
+
migration_contents.gsub!(/!FIELDS!/, column_declarations)
|
65
|
+
migration_filename = "#{Time.now.to_i}_#{filename}.rb"
|
66
|
+
create_file(app_root_path('db/migrate/', migration_filename), migration_contents)
|
67
|
+
end
|
22
68
|
end
|
23
|
-
|
69
|
+
|
24
70
|
end
|
25
71
|
end
|
26
72
|
end
|
27
|
-
end
|
73
|
+
end
|
@@ -2,7 +2,7 @@ module Padrino
|
|
2
2
|
module Generators
|
3
3
|
module Components
|
4
4
|
module Orms
|
5
|
-
|
5
|
+
|
6
6
|
module MongomapperGen
|
7
7
|
|
8
8
|
MONGO = (<<-MONGO).gsub(/^ {10}/, '')
|
@@ -46,9 +46,32 @@ module Padrino
|
|
46
46
|
create_file("config/database.rb", MONGO)
|
47
47
|
create_file("lib/ext/mongo_mapper.rb", CONCERNED)
|
48
48
|
end
|
49
|
+
|
50
|
+
MM_MODEL = (<<-MODEL).gsub(/^ {10}/, '')
|
51
|
+
class !NAME!
|
52
|
+
include MongoMapper::Document
|
53
|
+
|
54
|
+
# key <name>, <type>
|
55
|
+
!FIELDS!
|
56
|
+
end
|
57
|
+
MODEL
|
58
|
+
|
59
|
+
def create_model_file(name, fields)
|
60
|
+
model_path = app_root_path('app/models/', "#{name.to_s.underscore}.rb")
|
61
|
+
return false if File.exist?(model_path)
|
62
|
+
field_tuples = fields.collect { |value| value.split(":") }
|
63
|
+
column_declarations = field_tuples.collect { |field, kind| "key :#{field}, #{kind.camelize}" }.join("\n ")
|
64
|
+
model_contents = MM_MODEL.gsub(/!NAME!/, name.to_s.camelize)
|
65
|
+
model_contents.gsub!(/!FIELDS!/, column_declarations)
|
66
|
+
create_file(model_path, model_contents)
|
67
|
+
end
|
68
|
+
|
69
|
+
def create_migration_file(filename, name, fields)
|
70
|
+
# NO MIGRATION NEEDED
|
71
|
+
end
|
49
72
|
end
|
50
|
-
|
73
|
+
|
51
74
|
end
|
52
75
|
end
|
53
76
|
end
|
54
|
-
end
|
77
|
+
end
|
@@ -2,7 +2,7 @@ module Padrino
|
|
2
2
|
module Generators
|
3
3
|
module Components
|
4
4
|
module Orms
|
5
|
-
|
5
|
+
|
6
6
|
module SequelGen
|
7
7
|
|
8
8
|
SEQUEL = (<<-SEQUEL).gsub(/^ {10}/, '')
|
@@ -20,6 +20,47 @@ module Padrino
|
|
20
20
|
require_dependencies 'sequel'
|
21
21
|
create_file("config/database.rb", SEQUEL)
|
22
22
|
end
|
23
|
+
|
24
|
+
SQ_MODEL = (<<-MODEL).gsub(/^ {10}/, '')
|
25
|
+
class !NAME! < Sequel::Model
|
26
|
+
|
27
|
+
end
|
28
|
+
MODEL
|
29
|
+
|
30
|
+
def create_model_file(name, fields)
|
31
|
+
model_path = app_root_path('app/models/', "#{name.to_s.underscore}.rb")
|
32
|
+
return false if File.exist?(model_path)
|
33
|
+
model_contents = SQ_MODEL.gsub(/!NAME!/, name.to_s.downcase.camelize)
|
34
|
+
create_file(model_path, model_contents)
|
35
|
+
end
|
36
|
+
|
37
|
+
SQ_MIGRATION = (<<-MIGRATION).gsub(/^ {10}/, '')
|
38
|
+
class !FILENAME! < Sequel::Migration
|
39
|
+
def up
|
40
|
+
create_table :!TABLE! do
|
41
|
+
primary_key :id
|
42
|
+
# <type> <name>
|
43
|
+
text :username, :unique => true, :null => false
|
44
|
+
!FIELDS!
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def down
|
49
|
+
drop_table :!TABLE!
|
50
|
+
end
|
51
|
+
end
|
52
|
+
MIGRATION
|
53
|
+
|
54
|
+
def create_migration_file(filename, name, fields)
|
55
|
+
model_name = name.to_s.pluralize
|
56
|
+
field_tuples = fields.collect { |value| value.split(":") }
|
57
|
+
column_declarations = field_tuples.collect { |field, kind| "#{kind} :#{field}" }.join("\n ")
|
58
|
+
migration_contents = SQ_MIGRATION.gsub(/!NAME!/, model_name.camelize).gsub(/!TABLE!/, model_name.underscore)
|
59
|
+
migration_contents.gsub!(/!FILENAME!/, filename.camelize)
|
60
|
+
migration_contents.gsub!(/!FIELDS!/, column_declarations)
|
61
|
+
migration_filename = "#{Time.now.to_i}_#{filename}.rb"
|
62
|
+
create_file(app_root_path('db/migrate/', migration_filename), migration_contents)
|
63
|
+
end
|
23
64
|
end
|
24
65
|
|
25
66
|
end
|
@@ -2,7 +2,7 @@ module Padrino
|
|
2
2
|
module Generators
|
3
3
|
module Components
|
4
4
|
module Tests
|
5
|
-
|
5
|
+
|
6
6
|
module BaconGen
|
7
7
|
BACON_SETUP = (<<-TEST).gsub(/^ {10}/, '')
|
8
8
|
class Bacon::Context
|
@@ -19,7 +19,7 @@ module Padrino
|
|
19
19
|
require_dependencies 'bacon', :env => :testing
|
20
20
|
insert_test_suite_setup BACON_SETUP
|
21
21
|
end
|
22
|
-
|
22
|
+
|
23
23
|
BACON_CONTROLLER_TEST = (<<-TEST).gsub(/^ {10}/, '')
|
24
24
|
require File.dirname(__FILE__) + '/../test_config.rb'
|
25
25
|
|
@@ -30,15 +30,31 @@ module Padrino
|
|
30
30
|
end
|
31
31
|
end
|
32
32
|
TEST
|
33
|
-
|
33
|
+
|
34
34
|
# Generates a controller test given the controllers name
|
35
35
|
def generate_controller_test(name, root)
|
36
36
|
bacon_contents = BACON_CONTROLLER_TEST.gsub(/!NAME!/, name.to_s.camelize)
|
37
37
|
create_file File.join(root, "test/controllers/#{name}_controller_test.rb"), bacon_contents
|
38
38
|
end
|
39
39
|
|
40
|
+
BACON_MODEL_TEST = (<<-TEST).gsub(/^ {10}/, '')
|
41
|
+
require File.dirname(__FILE__) + '/../test_config.rb'
|
42
|
+
|
43
|
+
describe "!NAME! Model" do
|
44
|
+
it 'can be created' do
|
45
|
+
@!DNAME! = !NAME!.new
|
46
|
+
@!DNAME!.should.not.be.nil
|
47
|
+
end
|
48
|
+
end
|
49
|
+
TEST
|
50
|
+
|
51
|
+
def generate_model_test(name)
|
52
|
+
bacon_contents = BACON_MODEL_TEST.gsub(/!NAME!/, name.to_s.camelize).gsub(/!DNAME!/, name.downcase.underscore)
|
53
|
+
create_file app_root_path("test/models/#{name.to_s.downcase}.rb"), bacon_contents
|
54
|
+
end
|
55
|
+
|
40
56
|
end
|
41
|
-
|
57
|
+
|
42
58
|
end
|
43
59
|
end
|
44
60
|
end
|
@@ -36,6 +36,22 @@ module Padrino
|
|
36
36
|
create_file File.join(root, "test/controllers/#{name}_controller_test.rb"), riot_contents
|
37
37
|
end
|
38
38
|
|
39
|
+
RIOT_MODEL_TEST = (<<-TEST).gsub(/^ {10}/, '')
|
40
|
+
require File.dirname(__FILE__) + '/../test_config.rb'
|
41
|
+
|
42
|
+
context "!NAME! Model" do
|
43
|
+
context 'can be created' do
|
44
|
+
setup { @!DNAME! = !NAME!.new }
|
45
|
+
asserts("that record is not nil") { !@!DNAME!.nil? }
|
46
|
+
end
|
47
|
+
end
|
48
|
+
TEST
|
49
|
+
|
50
|
+
def generate_model_test(name)
|
51
|
+
riot_contents = RIOT_MODEL_TEST.gsub(/!NAME!/, name.to_s.camelize).gsub(/!DNAME!/, name.downcase.underscore)
|
52
|
+
create_file app_root_path("test/models/#{name.to_s.downcase}.rb"), riot_contents
|
53
|
+
end
|
54
|
+
|
39
55
|
end
|
40
56
|
|
41
57
|
end
|
@@ -38,6 +38,22 @@ module Padrino
|
|
38
38
|
create_file File.join(root, "test/controllers/#{name}_controller_spec.rb"), rspec_contents
|
39
39
|
end
|
40
40
|
|
41
|
+
RSPEC_MODEL_TEST = (<<-TEST).gsub(/^ {10}/, '')
|
42
|
+
require File.dirname(__FILE__) + '/../test_config.rb'
|
43
|
+
|
44
|
+
describe "!NAME! Model" do
|
45
|
+
it 'can be created' do
|
46
|
+
@!DNAME! = !NAME!.new
|
47
|
+
@!DNAME!.should.not.be nil
|
48
|
+
end
|
49
|
+
end
|
50
|
+
TEST
|
51
|
+
|
52
|
+
def generate_model_test(name)
|
53
|
+
rspec_contents = RSPEC_MODEL_TEST.gsub(/!NAME!/, name.to_s.camelize).gsub(/!DNAME!/, name.downcase.underscore)
|
54
|
+
create_file app_root_path("test/models/#{name.to_s.downcase}.rb"), rspec_contents
|
55
|
+
end
|
56
|
+
|
41
57
|
end
|
42
58
|
end
|
43
59
|
end
|
@@ -41,6 +41,24 @@ module Padrino
|
|
41
41
|
create_file File.join(root, "test/controllers/#{name}_controller_test.rb"), shoulda_contents
|
42
42
|
end
|
43
43
|
|
44
|
+
SHOULDA_MODEL_TEST = (<<-TEST).gsub(/^ {10}/, '')
|
45
|
+
require File.dirname(__FILE__) + '/../test_config.rb'
|
46
|
+
|
47
|
+
class !NAME!ControllerTest < Test::Unit::TestCase
|
48
|
+
context "!NAME! Model" do
|
49
|
+
should 'construct new instance' do
|
50
|
+
@!DNAME! = !NAME!.new
|
51
|
+
assert_not_nil @!DNAME!
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
TEST
|
56
|
+
|
57
|
+
def generate_model_test(name)
|
58
|
+
shoulda_contents = SHOULDA_MODEL_TEST.gsub(/!NAME!/, name.to_s.camelize).gsub(/!DNAME!/, name.downcase.underscore)
|
59
|
+
create_file app_root_path("test/models/#{name.to_s.downcase}.rb"), shoulda_contents
|
60
|
+
end
|
61
|
+
|
44
62
|
end
|
45
63
|
|
46
64
|
end
|
@@ -36,6 +36,22 @@ module Padrino
|
|
36
36
|
create_file File.join(root, "test/controllers/#{name}_controller_test.rb"), testspec_contents
|
37
37
|
end
|
38
38
|
|
39
|
+
TESTSPEC_MODEL_TEST = (<<-TEST).gsub(/^ {10}/, '')
|
40
|
+
require File.dirname(__FILE__) + '/../test_config.rb'
|
41
|
+
|
42
|
+
context "!NAME! Model" do
|
43
|
+
specify 'can be created' do
|
44
|
+
@!DNAME! = !NAME!.new
|
45
|
+
@!DNAME!.should.not.be.nil
|
46
|
+
end
|
47
|
+
end
|
48
|
+
TEST
|
49
|
+
|
50
|
+
def generate_model_test(name)
|
51
|
+
tests_contents = TESTSPEC_MODEL_TEST.gsub(/!NAME!/, name.to_s.camelize).gsub(/!DNAME!/, name.downcase.underscore)
|
52
|
+
create_file app_root_path("test/models/#{name.to_s.downcase}.rb"), tests_contents
|
53
|
+
end
|
54
|
+
|
39
55
|
end
|
40
56
|
|
41
57
|
end
|
@@ -22,8 +22,9 @@ module Padrino
|
|
22
22
|
def create_controller
|
23
23
|
if in_app_root?(options[:root])
|
24
24
|
@app_name = fetch_app_name(options[:root])
|
25
|
-
template "templates/controller.rb.tt",
|
26
|
-
template "templates/helper.rb.tt",
|
25
|
+
template "templates/controller.rb.tt", app_root_path("app/controllers", "#{name}.rb")
|
26
|
+
template "templates/helper.rb.tt", app_root_path("app/helpers", "#{name}_helper.rb")
|
27
|
+
empty_directory app_root_path("app/views/#{name}")
|
27
28
|
include_component_module_for(:test, options[:root])
|
28
29
|
generate_controller_test(name, options[:root] || '.')
|
29
30
|
else
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'thor'
|
2
|
+
|
3
|
+
module Padrino
|
4
|
+
module Generators
|
5
|
+
|
6
|
+
class Mailer < Thor::Group
|
7
|
+
# Define the source template root
|
8
|
+
def self.source_root; File.expand_path(File.dirname(__FILE__)); end
|
9
|
+
def self.banner; "padrino-gen mailer [name]"; end
|
10
|
+
|
11
|
+
# Include related modules
|
12
|
+
include Thor::Actions
|
13
|
+
include Padrino::Generators::Actions
|
14
|
+
include Padrino::Generators::Components::Actions
|
15
|
+
|
16
|
+
desc "Description:\n\n\tpadrino-gen mailer generates a new Padrino mailer"
|
17
|
+
|
18
|
+
argument :name, :desc => "The name of your padrino mailer"
|
19
|
+
class_option :root, :aliases => '-r', :default => nil, :type => :string
|
20
|
+
|
21
|
+
# Copies over the base sinatra starting project
|
22
|
+
def create_mailer
|
23
|
+
if in_app_root?(options[:root])
|
24
|
+
simple_name = name.to_s.gsub(/mailer/i, '')
|
25
|
+
@mailer_basename = "#{simple_name.downcase.underscore}_mailer"
|
26
|
+
@mailer_klass = "#{simple_name.downcase.camelize}Mailer"
|
27
|
+
template "templates/mailer_initializer.rb.tt", app_root_path("config/initializers/mailer.rb"), :skip => true
|
28
|
+
template "templates/mailer.rb.tt", app_root_path("app/mailers", "#{@mailer_basename}.rb")
|
29
|
+
empty_directory app_root_path('app/views/', @mailer_basename)
|
30
|
+
else
|
31
|
+
say "You are not at the root of a Padrino application! (config/boot.rb not found)" and return unless in_app_root?
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'thor'
|
2
|
+
|
3
|
+
module Padrino
|
4
|
+
module Generators
|
5
|
+
|
6
|
+
class Model < Thor::Group
|
7
|
+
# Define the source template root
|
8
|
+
def self.source_root; File.expand_path(File.dirname(__FILE__)); end
|
9
|
+
def self.banner; "padrino-gen model [name] [fields]"; end
|
10
|
+
|
11
|
+
# Include related modules
|
12
|
+
include Thor::Actions
|
13
|
+
include Padrino::Generators::Actions
|
14
|
+
include Padrino::Generators::Components::Actions
|
15
|
+
|
16
|
+
desc "Description:\n\n\tpadrino-gen model generates a new model and migration files"
|
17
|
+
|
18
|
+
argument :name, :desc => "The name of your padrino model"
|
19
|
+
argument :fields, :desc => "The fields for the model", :type => :array, :default => []
|
20
|
+
class_option :root, :aliases => '-r', :default => nil, :type => :string
|
21
|
+
|
22
|
+
# Copies over the base sinatra starting project
|
23
|
+
def create_model
|
24
|
+
if in_app_root?(options[:root])
|
25
|
+
say "Name: #{name}, Fields: #{fields.inspect}"
|
26
|
+
include_component_module_for(:orm, options[:root])
|
27
|
+
include_component_module_for(:test, options[:root])
|
28
|
+
migration_name = "create_#{name.pluralize.underscore}"
|
29
|
+
model_success = create_model_file(name, fields)
|
30
|
+
generate_model_test(name) if model_success
|
31
|
+
model_success ? create_migration_file(migration_name, name, fields) :
|
32
|
+
say("'#{name}' model has already been generated!")
|
33
|
+
else
|
34
|
+
say "You are not at the root of a Padrino application! (config/boot.rb not found)" and return unless in_app_root?
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
end
|
File without changes
|
@@ -0,0 +1,19 @@
|
|
1
|
+
=begin
|
2
|
+
|
3
|
+
Mailer methods can be defined using the simple format:
|
4
|
+
|
5
|
+
def registration_email(name, user_email_address)
|
6
|
+
from 'admin@site.com'
|
7
|
+
to user_email_address
|
8
|
+
subject 'Welcome to the site!'
|
9
|
+
body :name => name
|
10
|
+
type 'html' # optional, defaults to plain/text
|
11
|
+
charset 'windows-1252' # optional, defaults to utf-8
|
12
|
+
via :sendmail # optional, to smtp if defined otherwise sendmail
|
13
|
+
end
|
14
|
+
|
15
|
+
=end
|
16
|
+
|
17
|
+
class <%= @mailer_klass %> < Padrino::Mailer::Base
|
18
|
+
# Mailer methods here...
|
19
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
=begin
|
2
|
+
|
3
|
+
By default, Padrino mailer uses the built-in sendmail binary functionality on the server.
|
4
|
+
However, smtp is also supported using the following configuration if needed:
|
5
|
+
|
6
|
+
=end
|
7
|
+
|
8
|
+
module MailerInitializer
|
9
|
+
def self.registered(app)
|
10
|
+
# Padrino::Mailer::Base.smtp_settings = {
|
11
|
+
# :host => 'smtp.gmail.com',
|
12
|
+
# :port => '587',
|
13
|
+
# :tls => true,
|
14
|
+
# :user => 'user',
|
15
|
+
# :pass => 'pass',
|
16
|
+
# :auth => :plain
|
17
|
+
# }
|
18
|
+
end
|
19
|
+
end
|
data/lib/padrino-gen.rb
CHANGED
@@ -1,4 +1,3 @@
|
|
1
1
|
Dir[File.dirname(__FILE__) + "/generators/{components}/**/*.rb"].each { |lib| require lib }
|
2
2
|
require File.dirname(__FILE__) + "/generators/actions.rb"
|
3
|
-
|
4
|
-
require File.dirname(__FILE__) + "/generators/controller.rb"
|
3
|
+
Dir[File.dirname(__FILE__) + "/generators/{skeleton,mailer,controller,model}.rb"].each { |lib| require lib }
|
data/padrino-gen.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{padrino-gen}
|
8
|
-
s.version = "0.1.
|
8
|
+
s.version = "0.1.3"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Padrino Team", "Nathan Esquenazi", "Davide D'Agostino", "Arthur Chiu"]
|
12
|
-
s.date = %q{2009-11-
|
12
|
+
s.date = %q{2009-11-20}
|
13
13
|
s.default_executable = %q{padrino-gen}
|
14
14
|
s.description = %q{Generators for easily creating and building padrino applications from the console}
|
15
15
|
s.email = %q{nesquena@gmail.com}
|
@@ -48,11 +48,13 @@ Gem::Specification.new do |s|
|
|
48
48
|
"lib/generators/components/tests/shoulda_test_gen.rb",
|
49
49
|
"lib/generators/components/tests/testspec_test_gen.rb",
|
50
50
|
"lib/generators/controller.rb",
|
51
|
+
"lib/generators/mailer.rb",
|
52
|
+
"lib/generators/model.rb",
|
51
53
|
"lib/generators/skeleton.rb",
|
52
54
|
"lib/generators/skeleton/.gitignore",
|
53
55
|
"lib/generators/skeleton/Gemfile",
|
54
|
-
"lib/generators/skeleton/app.rb.tt",
|
55
56
|
"lib/generators/skeleton/app/.empty_directory",
|
57
|
+
"lib/generators/skeleton/app/app.rb.tt",
|
56
58
|
"lib/generators/skeleton/app/controllers/.empty_directory",
|
57
59
|
"lib/generators/skeleton/app/helpers/.empty_directory",
|
58
60
|
"lib/generators/skeleton/app/models/.empty_directory",
|
@@ -72,11 +74,16 @@ Gem::Specification.new do |s|
|
|
72
74
|
"lib/generators/skeleton/vendor/gems/.empty_directory",
|
73
75
|
"lib/generators/templates/controller.rb.tt",
|
74
76
|
"lib/generators/templates/helper.rb.tt",
|
77
|
+
"lib/generators/templates/mailer.rb.tt",
|
78
|
+
"lib/generators/templates/mailer_initializer.rb.tt",
|
75
79
|
"lib/padrino-gen.rb",
|
76
80
|
"padrino-gen.gemspec",
|
77
81
|
"test/active_support_helpers.rb",
|
78
82
|
"test/helper.rb",
|
79
83
|
"test/test_controller_generator.rb",
|
84
|
+
"test/test_mailer_generator.rb",
|
85
|
+
"test/test_migration_generator.rb",
|
86
|
+
"test/test_model_generator.rb",
|
80
87
|
"test/test_skeleton_generator.rb"
|
81
88
|
]
|
82
89
|
s.homepage = %q{http://github.com/padrino/padrino-gen}
|
@@ -18,8 +18,9 @@ class TestControllerGenerator < Test::Unit::TestCase
|
|
18
18
|
should "generate controller within existing application" do
|
19
19
|
silence_logger { @skeleton.start(['sample_app', '/tmp', '--script=none', '-t=bacon']) }
|
20
20
|
silence_logger { @contgen.start(['demo_items', '-r=/tmp/sample_app']) }
|
21
|
-
assert_match_in_file(/SampleApp
|
22
|
-
assert_match_in_file(/SampleApp
|
21
|
+
assert_match_in_file(/SampleApp.controllers do/m, '/tmp/sample_app/app/controllers/demo_items.rb')
|
22
|
+
assert_match_in_file(/SampleApp.helpers do/m, '/tmp/sample_app/app/helpers/demo_items_helper.rb')
|
23
|
+
assert File.exist?('/tmp/sample_app/app/views/demo_items')
|
23
24
|
end
|
24
25
|
|
25
26
|
should "generate controller test for bacon" do
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/helper'
|
2
|
+
require 'thor'
|
3
|
+
|
4
|
+
class TestMailerGenerator < Test::Unit::TestCase
|
5
|
+
def setup
|
6
|
+
@skeleton = Padrino::Generators::Skeleton.dup
|
7
|
+
@mailgen = Padrino::Generators::Mailer.dup
|
8
|
+
`rm -rf /tmp/sample_app`
|
9
|
+
end
|
10
|
+
|
11
|
+
context 'the mailer generator' do
|
12
|
+
should "fail outside app root" do
|
13
|
+
output = silence_logger { @mailgen.start(['demo', '-r=/tmp']) }
|
14
|
+
assert_match(/not at the root/, output)
|
15
|
+
assert !File.exist?('/tmp/app/mailers/demo_mailer.rb')
|
16
|
+
end
|
17
|
+
|
18
|
+
should "support generating a new mailer extended from base" do
|
19
|
+
silence_logger { @skeleton.start(['sample_app', '/tmp', '--script=none', '-t=bacon']) }
|
20
|
+
silence_logger { @mailgen.start(['demo', '-r=/tmp/sample_app']) }
|
21
|
+
assert_match_in_file(/class DemoMailer < Padrino::Mailer::Base/m, '/tmp/sample_app/app/mailers/demo_mailer.rb')
|
22
|
+
assert_match_in_file(/Padrino::Mailer::Base.smtp_settings/m, '/tmp/sample_app/config/initializers/mailer.rb')
|
23
|
+
assert File.exist?('/tmp/sample_app/app/views/demo_mailer')
|
24
|
+
end
|
25
|
+
|
26
|
+
should "support generating a new mailer extended from base with long name" do
|
27
|
+
silence_logger { @skeleton.start(['sample_app', '/tmp', '--script=none', '-t=bacon']) }
|
28
|
+
silence_logger { @mailgen.start(['user_notice', '-r=/tmp/sample_app']) }
|
29
|
+
assert_match_in_file(/class UserNoticeMailer/m, '/tmp/sample_app/app/mailers/user_notice_mailer.rb')
|
30
|
+
assert_match_in_file(/Padrino::Mailer::Base.smtp_settings/m, '/tmp/sample_app/config/initializers/mailer.rb')
|
31
|
+
assert File.exist?('/tmp/sample_app/app/views/user_notice_mailer')
|
32
|
+
end
|
33
|
+
|
34
|
+
should "support generating a new mailer extended from base with capitalized name" do
|
35
|
+
silence_logger { @skeleton.start(['sample_app', '/tmp', '--script=none', '-t=bacon']) }
|
36
|
+
silence_logger { @mailgen.start(['DEMO', '-r=/tmp/sample_app']) }
|
37
|
+
assert_match_in_file(/class DemoMailer < Padrino::Mailer::Base/m, '/tmp/sample_app/app/mailers/demo_mailer.rb')
|
38
|
+
assert_match_in_file(/Padrino::Mailer::Base.smtp_settings/m, '/tmp/sample_app/config/initializers/mailer.rb')
|
39
|
+
assert File.exist?('/tmp/sample_app/app/views/demo_mailer')
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/helper'
|
2
|
+
require 'thor'
|
3
|
+
|
4
|
+
class TestMigrationGenerator < Test::Unit::TestCase
|
5
|
+
def setup
|
6
|
+
@skeleton = Padrino::Generators::Skeleton.dup
|
7
|
+
# @mig_gen = Padrino::Generators::Migration.dup
|
8
|
+
`rm -rf /tmp/sample_app`
|
9
|
+
end
|
10
|
+
|
11
|
+
context 'the migration generator' do
|
12
|
+
should "work" do
|
13
|
+
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
@@ -0,0 +1,195 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/helper'
|
2
|
+
require 'thor'
|
3
|
+
|
4
|
+
class TestModelGenerator < Test::Unit::TestCase
|
5
|
+
def setup
|
6
|
+
@skeleton = Padrino::Generators::Skeleton.dup
|
7
|
+
@model_gen = Padrino::Generators::Model.dup
|
8
|
+
`rm -rf /tmp/sample_app`
|
9
|
+
end
|
10
|
+
|
11
|
+
context 'the model generator' do
|
12
|
+
should "fail outside app root" do
|
13
|
+
output = silence_logger { @model_gen.start(['user', '-r=/tmp']) }
|
14
|
+
assert_match(/not at the root/, output)
|
15
|
+
assert !File.exist?('/tmp/app/models/user.rb')
|
16
|
+
end
|
17
|
+
|
18
|
+
should "generate only generate model once" do
|
19
|
+
silence_logger { @skeleton.start(['sample_app', '/tmp', '--script=none', '-t=bacon', '-d=activerecord']) }
|
20
|
+
response_success = silence_logger { @model_gen.start(['user', '-r=/tmp/sample_app']) }
|
21
|
+
response_duplicate = silence_logger { @model_gen.start(['user', '-r=/tmp/sample_app']) }
|
22
|
+
assert_match_in_file(/class User < ActiveRecord::Base/m, '/tmp/sample_app/app/models/user.rb')
|
23
|
+
assert_match /'user' model has already been generated!/, response_duplicate
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
# ACTIVERECORD
|
28
|
+
context "model generator using activerecord" do
|
29
|
+
should "generate model file" do
|
30
|
+
silence_logger { @skeleton.start(['sample_app', '/tmp', '--script=none', '-t=bacon', '-d=activerecord']) }
|
31
|
+
silence_logger { @model_gen.start(['user', '-r=/tmp/sample_app']) }
|
32
|
+
assert_match_in_file(/class User < ActiveRecord::Base/m, '/tmp/sample_app/app/models/user.rb')
|
33
|
+
end
|
34
|
+
|
35
|
+
should "generate migration file with no fields" do
|
36
|
+
current_time = stop_time_for_test
|
37
|
+
silence_logger { @skeleton.start(['sample_app', '/tmp', '--script=none', '-t=bacon', '-d=activerecord']) }
|
38
|
+
silence_logger { @model_gen.start(['user', '-r=/tmp/sample_app']) }
|
39
|
+
migration_file_path = "/tmp/sample_app/db/migrate/#{current_time.to_i}_create_users.rb"
|
40
|
+
assert_match_in_file(/class CreateUsers < ActiveRecord::Migration/m, migration_file_path)
|
41
|
+
assert_match_in_file(/create_table :users/m, migration_file_path)
|
42
|
+
assert_match_in_file(/# t.column :age, :integer[\n\s]+?end/m, migration_file_path)
|
43
|
+
end
|
44
|
+
|
45
|
+
should "generate migration file with given fields" do
|
46
|
+
current_time = stop_time_for_test
|
47
|
+
silence_logger { @skeleton.start(['sample_app', '/tmp', '--script=none', '-t=bacon', '-d=activerecord']) }
|
48
|
+
silence_logger { @model_gen.start(['person', "name:string", "age:integer", "email:string", '-r=/tmp/sample_app']) }
|
49
|
+
migration_file_path = "/tmp/sample_app/db/migrate/#{current_time.to_i}_create_people.rb"
|
50
|
+
assert_match_in_file(/class CreatePeople < ActiveRecord::Migration/m, migration_file_path)
|
51
|
+
assert_match_in_file(/create_table :people/m, migration_file_path)
|
52
|
+
assert_match_in_file(/# t.column :age, :integer/m, migration_file_path)
|
53
|
+
assert_match_in_file(/t.column :name, :string/m, migration_file_path)
|
54
|
+
assert_match_in_file(/t.column :age, :integer/m, migration_file_path)
|
55
|
+
assert_match_in_file(/t.column :email, :string/m, migration_file_path)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
# COUCHREST
|
60
|
+
context "model generator using couchrest" do
|
61
|
+
should "generate model file with no properties" do
|
62
|
+
silence_logger { @skeleton.start(['sample_app', '/tmp', '--script=none', '-t=bacon', '-d=couchrest']) }
|
63
|
+
silence_logger { @model_gen.start(['user', '-r=/tmp/sample_app']) }
|
64
|
+
assert_match_in_file(/class User < CouchRest::ExtendedDocument/m, '/tmp/sample_app/app/models/user.rb')
|
65
|
+
assert_match_in_file(/use_database app \{ couchdb \}/m, '/tmp/sample_app/app/models/user.rb')
|
66
|
+
assert_match_in_file(/# property <name>[\s\n]+?end/m, '/tmp/sample_app/app/models/user.rb')
|
67
|
+
end
|
68
|
+
|
69
|
+
should "generate model file with given fields" do
|
70
|
+
silence_logger { @skeleton.start(['sample_app', '/tmp', '--script=none', '-t=bacon', '-d=couchrest']) }
|
71
|
+
silence_logger { @model_gen.start(['person', "name:string", "age", "email:string", '-r=/tmp/sample_app']) }
|
72
|
+
assert_match_in_file(/class Person < CouchRest::ExtendedDocument/m, '/tmp/sample_app/app/models/person.rb')
|
73
|
+
assert_match_in_file(/use_database app \{ couchdb \}/m, '/tmp/sample_app/app/models/person.rb')
|
74
|
+
assert_match_in_file(/property :name/m, '/tmp/sample_app/app/models/person.rb')
|
75
|
+
assert_match_in_file(/property :age/m, '/tmp/sample_app/app/models/person.rb')
|
76
|
+
assert_match_in_file(/property :email/m, '/tmp/sample_app/app/models/person.rb')
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
# DATAMAPPER
|
81
|
+
context "model generator using datamapper" do
|
82
|
+
should "generate model file with fields" do
|
83
|
+
silence_logger { @skeleton.start(['sample_app', '/tmp', '--script=none', '-d=datamapper']) }
|
84
|
+
silence_logger { @model_gen.start(['user', "name:string", "age:integer", "email:string", '-r=/tmp/sample_app']) }
|
85
|
+
assert_match_in_file(/class User\n\s+include DataMapper::Resource/m, '/tmp/sample_app/app/models/user.rb')
|
86
|
+
assert_match_in_file(/property :name, String/m, '/tmp/sample_app/app/models/user.rb')
|
87
|
+
assert_match_in_file(/property :age, Integer/m, '/tmp/sample_app/app/models/user.rb')
|
88
|
+
assert_match_in_file(/property :email, String/m, '/tmp/sample_app/app/models/user.rb')
|
89
|
+
end
|
90
|
+
|
91
|
+
should "generate migration with given fields" do
|
92
|
+
current_time = stop_time_for_test
|
93
|
+
silence_logger { @skeleton.start(['sample_app', '/tmp', '--script=none', '-d=datamapper']) }
|
94
|
+
silence_logger { @model_gen.start(['person', "name:string", "age:integer", "email:string", '-r=/tmp/sample_app']) }
|
95
|
+
assert_match_in_file(/class Person\n\s+include DataMapper::Resource/m, '/tmp/sample_app/app/models/person.rb')
|
96
|
+
migration_file_path = "/tmp/sample_app/db/migrate/#{current_time.to_i}_create_people.rb"
|
97
|
+
assert_match_in_file(/migration NUM, :create_people do/m, migration_file_path)
|
98
|
+
assert_match_in_file(/create_table\(:people\) do/m, migration_file_path)
|
99
|
+
assert_match_in_file(/column\(:name, String\)/m, migration_file_path)
|
100
|
+
assert_match_in_file(/column\(:age, Integer\)/m, migration_file_path)
|
101
|
+
assert_match_in_file(/column\(:email, String\)/m, migration_file_path)
|
102
|
+
assert_match_in_file(/drop_table\(:people\)/m, migration_file_path)
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
# MONGOMAPPER
|
107
|
+
context "model generator using mongomapper" do
|
108
|
+
should "generate migration file with given fields" do
|
109
|
+
silence_logger { @skeleton.start(['sample_app', '/tmp', '--script=none', '-d=mongomapper']) }
|
110
|
+
silence_logger { @model_gen.start(['person', '-r=/tmp/sample_app']) }
|
111
|
+
assert_match_in_file(/class Person\n\s+include MongoMapper::Document/m, '/tmp/sample_app/app/models/person.rb')
|
112
|
+
assert_match_in_file(/# key <name>, <type>[\n\s]+end/m, '/tmp/sample_app/app/models/person.rb')
|
113
|
+
end
|
114
|
+
|
115
|
+
should "generate model file with given fields" do
|
116
|
+
silence_logger { @skeleton.start(['sample_app', '/tmp', '--script=none', '-d=mongomapper']) }
|
117
|
+
silence_logger { @model_gen.start(['user', "name:string", "age:integer", "email:string", '-r=/tmp/sample_app']) }
|
118
|
+
assert_match_in_file(/class User\n\s+include MongoMapper::Document/m, '/tmp/sample_app/app/models/user.rb')
|
119
|
+
assert_match_in_file(/key :name, String/m, '/tmp/sample_app/app/models/user.rb')
|
120
|
+
assert_match_in_file(/key :age, Integer/m, '/tmp/sample_app/app/models/user.rb')
|
121
|
+
assert_match_in_file(/key :email, String/m, '/tmp/sample_app/app/models/user.rb')
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
# SEQUEL
|
126
|
+
context "model generator using sequel" do
|
127
|
+
should "generate model file with given properties" do
|
128
|
+
silence_logger { @skeleton.start(['sample_app', '/tmp', '--script=none', '-d=sequel']) }
|
129
|
+
silence_logger { @model_gen.start(['user', "name:string", "age:integer", "email:string", '-r=/tmp/sample_app']) }
|
130
|
+
assert_match_in_file(/class User < Sequel::Model/m, '/tmp/sample_app/app/models/user.rb')
|
131
|
+
end
|
132
|
+
|
133
|
+
should "generate migration file with given properties" do
|
134
|
+
current_time = stop_time_for_test
|
135
|
+
silence_logger { @skeleton.start(['sample_app', '/tmp', '--script=none', '-d=sequel']) }
|
136
|
+
silence_logger { @model_gen.start(['person', "name:string", "age:integer", "email:string", '-r=/tmp/sample_app']) }
|
137
|
+
migration_file_path = "/tmp/sample_app/db/migrate/#{current_time.to_i}_create_people.rb"
|
138
|
+
assert_match_in_file(/class Person < Sequel::Model/m, '/tmp/sample_app/app/models/person.rb')
|
139
|
+
assert_match_in_file(/class CreatePeople < Sequel::Migration/m, migration_file_path)
|
140
|
+
assert_match_in_file(/create_table :people/m, migration_file_path)
|
141
|
+
assert_match_in_file(/string :name/m, migration_file_path)
|
142
|
+
assert_match_in_file(/integer :age/m, migration_file_path)
|
143
|
+
assert_match_in_file(/string :email/m, migration_file_path)
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
context "model generator testing files" do
|
148
|
+
# BACON
|
149
|
+
should "generate test file for bacon" do
|
150
|
+
silence_logger { @skeleton.start(['sample_app', '/tmp', '--script=none', '-t=bacon', '-d=activerecord']) }
|
151
|
+
silence_logger { @model_gen.start(['User', '-r=/tmp/sample_app']) }
|
152
|
+
assert_match_in_file(/describe "User Model"/m, '/tmp/sample_app/test/models/user.rb')
|
153
|
+
assert_match_in_file(/@user = User.new/m, '/tmp/sample_app/test/models/user.rb')
|
154
|
+
assert_match_in_file(/@user\.should\.not\.be\.nil/m, '/tmp/sample_app/test/models/user.rb')
|
155
|
+
end
|
156
|
+
|
157
|
+
# RIOT
|
158
|
+
should "generate test file for riot" do
|
159
|
+
silence_logger { @skeleton.start(['sample_app', '/tmp', '--script=none', '-t=riot', '-d=activerecord']) }
|
160
|
+
silence_logger { @model_gen.start(['User', '-r=/tmp/sample_app']) }
|
161
|
+
assert_match_in_file(/context "User Model" do/m, '/tmp/sample_app/test/models/user.rb')
|
162
|
+
assert_match_in_file(/@user = User.new/m, '/tmp/sample_app/test/models/user.rb')
|
163
|
+
assert_match_in_file(/asserts\("that record is not nil"\) \{ \!@user.nil\? \}/m, '/tmp/sample_app/test/models/user.rb')
|
164
|
+
end
|
165
|
+
|
166
|
+
# RSPEC
|
167
|
+
should "generate test file for rspec" do
|
168
|
+
silence_logger { @skeleton.start(['sample_app', '/tmp', '--script=none', '-t=rspec', '-d=activerecord']) }
|
169
|
+
silence_logger { @model_gen.start(['User', '-r=/tmp/sample_app']) }
|
170
|
+
assert_match_in_file(/describe "User Model"/m, '/tmp/sample_app/test/models/user.rb')
|
171
|
+
assert_match_in_file(/@user = User.new/m, '/tmp/sample_app/test/models/user.rb')
|
172
|
+
assert_match_in_file(/@user\.should\.not\.be\snil/m, '/tmp/sample_app/test/models/user.rb')
|
173
|
+
end
|
174
|
+
|
175
|
+
# SHOULDA
|
176
|
+
should "generate test file for shoulda" do
|
177
|
+
silence_logger { @skeleton.start(['sample_app', '/tmp', '--script=none', '-t=shoulda', '-d=activerecord']) }
|
178
|
+
silence_logger { @model_gen.start(['User', '-r=/tmp/sample_app']) }
|
179
|
+
assert_match_in_file(/class UserControllerTest < Test::Unit::TestCase/m, '/tmp/sample_app/test/models/user.rb')
|
180
|
+
assert_match_in_file(/context "User Model"/m, '/tmp/sample_app/test/models/user.rb')
|
181
|
+
assert_match_in_file(/@user = User.new/m, '/tmp/sample_app/test/models/user.rb')
|
182
|
+
assert_match_in_file(/assert_not_nil @user/m, '/tmp/sample_app/test/models/user.rb')
|
183
|
+
end
|
184
|
+
|
185
|
+
# TESTSPEC
|
186
|
+
should "generate test file for testspec" do
|
187
|
+
silence_logger { @skeleton.start(['sample_app', '/tmp', '--script=none', '-t=testspec', '-d=activerecord']) }
|
188
|
+
silence_logger { @model_gen.start(['User', '-r=/tmp/sample_app']) }
|
189
|
+
assert_match_in_file(/context "User Model"/m, '/tmp/sample_app/test/models/user.rb')
|
190
|
+
assert_match_in_file(/@user = User.new/m, '/tmp/sample_app/test/models/user.rb')
|
191
|
+
assert_match_in_file(/@user\.should\.not\.be\.nil/m, '/tmp/sample_app/test/models/user.rb')
|
192
|
+
end
|
193
|
+
end
|
194
|
+
|
195
|
+
end
|
@@ -17,9 +17,9 @@ class TestSkeletonGenerator < Test::Unit::TestCase
|
|
17
17
|
end
|
18
18
|
should "place app specific names into correct files" do
|
19
19
|
silence_logger { @skeleton.start(['sample_app', '/tmp', '--script=none']) }
|
20
|
-
assert_match_in_file(/class SampleApp < Padrino::Application/m, '/tmp/sample_app/app.rb')
|
20
|
+
assert_match_in_file(/class SampleApp < Padrino::Application/m, '/tmp/sample_app/app/app.rb')
|
21
21
|
assert_match_in_file(/Padrino.mount_core\(:app_class => "SampleApp"\)/m, '/tmp/sample_app/config/apps.rb')
|
22
|
-
assert_match_in_file(/SampleApp
|
22
|
+
assert_match_in_file(/SampleApp.urls do/m, '/tmp/sample_app/config/urls.rb')
|
23
23
|
end
|
24
24
|
should "create components file containing options chosen with defaults" do
|
25
25
|
silence_logger { @skeleton.start(['sample_app', '/tmp']) }
|
@@ -109,7 +109,7 @@ class TestSkeletonGenerator < Test::Unit::TestCase
|
|
109
109
|
buffer = silence_logger { @skeleton.start(['sample_app', '/tmp', '--orm=couchrest', '--script=none']) }
|
110
110
|
assert_match /Applying.*?couchrest.*?orm/, buffer
|
111
111
|
assert_match_in_file(/gem 'couchrest'/, '/tmp/sample_app/Gemfile')
|
112
|
-
assert_match_in_file(/CouchRest.database!/, '/tmp/sample_app/config/database.rb')
|
112
|
+
assert_match_in_file(/CouchRest.database!/, '/tmp/sample_app/config/database.rb')
|
113
113
|
end
|
114
114
|
end
|
115
115
|
|
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.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Padrino Team
|
@@ -12,7 +12,7 @@ autorequire:
|
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
14
|
|
15
|
-
date: 2009-11-
|
15
|
+
date: 2009-11-20 00:00:00 -08:00
|
16
16
|
default_executable: padrino-gen
|
17
17
|
dependencies:
|
18
18
|
- !ruby/object:Gem::Dependency
|
@@ -142,11 +142,13 @@ files:
|
|
142
142
|
- lib/generators/components/tests/shoulda_test_gen.rb
|
143
143
|
- lib/generators/components/tests/testspec_test_gen.rb
|
144
144
|
- lib/generators/controller.rb
|
145
|
+
- lib/generators/mailer.rb
|
146
|
+
- lib/generators/model.rb
|
145
147
|
- lib/generators/skeleton.rb
|
146
148
|
- lib/generators/skeleton/.gitignore
|
147
149
|
- lib/generators/skeleton/Gemfile
|
148
|
-
- lib/generators/skeleton/app.rb.tt
|
149
150
|
- lib/generators/skeleton/app/.empty_directory
|
151
|
+
- lib/generators/skeleton/app/app.rb.tt
|
150
152
|
- lib/generators/skeleton/app/controllers/.empty_directory
|
151
153
|
- lib/generators/skeleton/app/helpers/.empty_directory
|
152
154
|
- lib/generators/skeleton/app/models/.empty_directory
|
@@ -166,11 +168,16 @@ files:
|
|
166
168
|
- lib/generators/skeleton/vendor/gems/.empty_directory
|
167
169
|
- lib/generators/templates/controller.rb.tt
|
168
170
|
- lib/generators/templates/helper.rb.tt
|
171
|
+
- lib/generators/templates/mailer.rb.tt
|
172
|
+
- lib/generators/templates/mailer_initializer.rb.tt
|
169
173
|
- lib/padrino-gen.rb
|
170
174
|
- padrino-gen.gemspec
|
171
175
|
- test/active_support_helpers.rb
|
172
176
|
- test/helper.rb
|
173
177
|
- test/test_controller_generator.rb
|
178
|
+
- test/test_mailer_generator.rb
|
179
|
+
- test/test_migration_generator.rb
|
180
|
+
- test/test_model_generator.rb
|
174
181
|
- test/test_skeleton_generator.rb
|
175
182
|
has_rdoc: true
|
176
183
|
homepage: http://github.com/padrino/padrino-gen
|