padrino-gen 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +10 -6
- data/Rakefile +1 -0
- data/VERSION +1 -1
- data/bin/padrino-gen +1 -0
- data/lib/generators/components/actions.rb +68 -1
- data/lib/generators/components/orms/activerecord_gen.rb +41 -22
- data/lib/generators/components/orms/couchrest_gen.rb +8 -5
- data/lib/generators/components/orms/datamapper_gen.rb +39 -20
- data/lib/generators/components/orms/mongomapper_gen.rb +8 -4
- data/lib/generators/components/orms/sequel_gen.rb +37 -19
- data/lib/generators/components/tests/bacon_test_gen.rb +1 -1
- data/lib/generators/components/tests/riot_test_gen.rb +1 -1
- data/lib/generators/components/tests/rspec_test_gen.rb +1 -1
- data/lib/generators/components/tests/shoulda_test_gen.rb +1 -1
- data/lib/generators/components/tests/testspec_test_gen.rb +1 -1
- data/lib/generators/controller.rb +3 -0
- data/lib/generators/migration.rb +34 -0
- data/lib/generators/model.rb +1 -1
- data/lib/generators/skeleton/tmp/{.emptydirectory → .empty_directory} +0 -0
- data/lib/generators/templates/controller.rb.tt +2 -0
- data/lib/padrino-gen.rb +1 -1
- data/padrino-gen.gemspec +7 -3
- data/test/test_controller_generator.rb +25 -5
- data/test/test_migration_generator.rb +143 -2
- data/test/test_model_generator.rb +66 -40
- data/test/test_skeleton_generator.rb +6 -0
- metadata +14 -3
data/README.rdoc
CHANGED
@@ -46,15 +46,15 @@ setup performed for the default components.
|
|
46
46
|
|
47
47
|
You can also define specific components to be used:
|
48
48
|
|
49
|
-
$ padrino-gen demo_app . --test
|
49
|
+
$ padrino-gen demo_app . --test rspec --renderer haml --mock rr --script jquery --orm datamapper
|
50
50
|
|
51
51
|
There is also support for aliases for each component within the command:
|
52
52
|
|
53
|
-
$ padrino-gen demo_app . -t
|
53
|
+
$ padrino-gen demo_app . -t rspec -r haml -m rr -s jquery -d datamapper
|
54
54
|
|
55
55
|
You can also instruct the generator to skip a certain component to avoid using one at all (or to use your own):
|
56
56
|
|
57
|
-
$ padrino-gen demo_app . --test
|
57
|
+
$ padrino-gen demo_app . --test none --renderer none
|
58
58
|
|
59
59
|
The available components and their default options are listed below:
|
60
60
|
|
@@ -142,11 +142,15 @@ Using the controller generator is as simple as:
|
|
142
142
|
|
143
143
|
You can also specify desired actions to be added to your controller:
|
144
144
|
|
145
|
-
$ padrino-gen controller Admin :index
|
145
|
+
$ padrino-gen controller Admin get:index get:new post:create
|
146
146
|
|
147
147
|
The controller generator will then construct the controller file within <tt>app/controllers/admin.rb</tt>
|
148
148
|
and also a controller test file at <tt>test/controllers/admin_controller_test.rb</tt> according to the
|
149
|
-
test framework chosen during app generation.
|
149
|
+
test framework chosen during app generation. A default route will also be generated mapping to name of the controller and the route name. For example:
|
150
|
+
|
151
|
+
$ padrino-gen controller User get:index
|
152
|
+
|
153
|
+
will create a url route for :index mapping to "/user/index"
|
150
154
|
|
151
155
|
=== Mailer Generator ===
|
152
156
|
|
@@ -166,4 +170,4 @@ The mailer generator will then construct the mailer file within <tt>app/mailers/
|
|
166
170
|
|
167
171
|
== Copyright
|
168
172
|
|
169
|
-
Copyright (c) 2009 Padrino. See LICENSE for details.
|
173
|
+
Copyright (c) 2009 Padrino. See LICENSE for details.
|
data/Rakefile
CHANGED
@@ -20,6 +20,7 @@ begin
|
|
20
20
|
gem.add_development_dependency "mocha", ">= 0.9.7"
|
21
21
|
gem.add_development_dependency "rack-test", ">= 0.5.0"
|
22
22
|
gem.add_development_dependency "webrat", ">= 0.5.1"
|
23
|
+
gem.add_development_dependency "fakeweb", ">= 1.2.3"
|
23
24
|
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
24
25
|
end
|
25
26
|
Jeweler::GemcutterTasks.new
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.1
|
data/bin/padrino-gen
CHANGED
@@ -5,6 +5,7 @@ require File.dirname(__FILE__) + "/../lib/padrino-gen"
|
|
5
5
|
generator_mappings = SupportLite::OrderedHash.new
|
6
6
|
generator_mappings[:app] = Padrino::Generators::Skeleton
|
7
7
|
generator_mappings[:model] = Padrino::Generators::Model
|
8
|
+
generator_mappings[:migration] = Padrino::Generators::Migration
|
8
9
|
generator_mappings[:controller] = Padrino::Generators::Controller
|
9
10
|
generator_mappings[:mailer] = Padrino::Generators::Mailer
|
10
11
|
|
@@ -27,15 +27,62 @@ module Padrino
|
|
27
27
|
inject_into_file('Gemfile', options[:content], :after => options[:after])
|
28
28
|
end
|
29
29
|
|
30
|
+
# For orm database components
|
31
|
+
# Generates the model migration file created when generating a new model
|
32
|
+
# options => { :base => "....text...", :up => "..text...",
|
33
|
+
# :down => "..text...", column_format => "t.column :#{field}, :#{kind}" }
|
34
|
+
def output_model_migration(filename, name, columns, options={})
|
35
|
+
model_name = name.to_s.pluralize
|
36
|
+
field_tuples = fields.collect { |value| value.split(":") }
|
37
|
+
field_tuples.collect! { |field, kind| kind =~ /datetime/i ? [field, 'DateTime'] : [field, kind] } # fix datetime
|
38
|
+
column_declarations = field_tuples.collect(&options[:column_format]).join("\n ")
|
39
|
+
contents = options[:base].dup.gsub(/\s{4}!UP!\n/m, options[:up]).gsub(/!DOWN!\n/m, options[:down])
|
40
|
+
contents = contents.gsub(/!NAME!/, model_name.camelize).gsub(/!TABLE!/, model_name.underscore)
|
41
|
+
contents = contents.gsub(/!FILENAME!/, filename.underscore).gsub(/!FILECLASS!/, filename.camelize)
|
42
|
+
current_migration_number = Dir[app_root_path('db/migrate/*.rb')].map { |f|
|
43
|
+
File.basename(f).match(/^(\d+)/)[0].to_i }.max.to_i || 0
|
44
|
+
contents = contents.gsub(/!FIELDS!/, column_declarations).gsub(/!VERSION!/, (current_migration_number + 1).to_s)
|
45
|
+
migration_filename = "#{format("%03d", current_migration_number+1)}_#{filename.underscore}.rb"
|
46
|
+
create_file(app_root_path('db/migrate/', migration_filename), contents)
|
47
|
+
end
|
48
|
+
|
49
|
+
# For orm database components
|
50
|
+
# Generates a standalone migration file based on the given options and columns
|
51
|
+
# options => { :base "...text...", :change_format => "...text...",
|
52
|
+
# :add => lambda { |field, kind| "add_column :#{table_name}, :#{field}, :#{kind}" },
|
53
|
+
# :remove => lambda { |field, kind| "remove_column :#{table_name}, :#{field}" }
|
54
|
+
def output_migration_file(filename, name, columns, options={})
|
55
|
+
change_format = options[:change_format]
|
56
|
+
migration_scan = filename.camelize.scan(/(Add|Remove)(?:.*?)(?:To|From)(.*?)$/).flatten
|
57
|
+
direction, table_name = migration_scan[0].downcase, migration_scan[1].downcase.pluralize if migration_scan.any?
|
58
|
+
tuples = direction ? columns.collect { |value| value.split(":") } : []
|
59
|
+
tuples.collect! { |field, kind| kind =~ /datetime/i ? [field, 'DateTime'] : [field, kind] } # fix datetime
|
60
|
+
add_columns = tuples.collect(&options[:add]).join("\n ")
|
61
|
+
remove_columns = tuples.collect(&options[:remove]).join("\n ")
|
62
|
+
forward_text = change_format.gsub(/!TABLE!/, table_name).gsub(/!COLUMNS!/, add_columns) if tuples.any?
|
63
|
+
back_text = change_format.gsub(/!TABLE!/, table_name).gsub(/!COLUMNS!/, remove_columns) if tuples.any?
|
64
|
+
contents = options[:base].dup.gsub(/\s{4}!UP!\n/m, (direction == 'add' ? forward_text.to_s : back_text.to_s))
|
65
|
+
contents.gsub!(/\s{4}!DOWN!\n/m, (direction == 'add' ? back_text.to_s : forward_text.to_s))
|
66
|
+
contents = contents.gsub(/!FILENAME!/, filename.underscore).gsub(/!FILECLASS!/, filename.camelize)
|
67
|
+
current_migration_number = Dir[app_root_path('db/migrate/*.rb')].map { |f|
|
68
|
+
File.basename(f).match(/^(\d+)/)[0].to_i }.max.to_i || 0
|
69
|
+
contents.gsub!(/!VERSION!/, (current_migration_number + 1).to_s)
|
70
|
+
migration_filename = "#{format("%03d", current_migration_number+1)}_#{filename.underscore}.rb"
|
71
|
+
# migration_filename = "#{Time.now.strftime("%Y%m%d%H%M%S")}_#{filename.underscore}.rb"
|
72
|
+
create_file(app_root_path('db/migrate/', migration_filename), contents)
|
73
|
+
end
|
74
|
+
|
75
|
+
# For testing components
|
30
76
|
# Injects the test class text into the test_config file for setting up the test gen
|
31
77
|
# insert_test_suite_setup('...CLASS_NAME...')
|
32
|
-
# => inject_into_file("test/test_config.rb", TEST.gsub(/CLASS_NAME/, @class_name), :after => "set :environment, :test
|
78
|
+
# => inject_into_file("test/test_config.rb", TEST.gsub(/CLASS_NAME/, @class_name), :after => "set :environment, :test")
|
33
79
|
def insert_test_suite_setup(suite_text, options={})
|
34
80
|
test_helper_text = [BASE_TEST_HELPER, suite_text.gsub(/CLASS_NAME/, @class_name)].join("\n")
|
35
81
|
options.reverse_merge!(:path => "test/test_config.rb")
|
36
82
|
create_file(options[:path], test_helper_text)
|
37
83
|
end
|
38
84
|
|
85
|
+
# For mocking components
|
39
86
|
# Injects the mock library include into the test class in test_config for setting up mock gen
|
40
87
|
# insert_mock_library_include('Mocha::API')
|
41
88
|
# => inject_into_file("test/test_config.rb", " include Mocha::API\n", :after => /class.*?\n/)
|
@@ -51,6 +98,26 @@ module Padrino
|
|
51
98
|
def indent_spaces(count)
|
52
99
|
' ' * count
|
53
100
|
end
|
101
|
+
|
102
|
+
# For Controller action generation
|
103
|
+
# Takes in fields for routes in the form of get:index post:test delete:yada and such
|
104
|
+
def controller_actions(fields)
|
105
|
+
field_tuples = fields.collect { |value| value.split(":") }
|
106
|
+
action_declarations = field_tuples.collect do |request, name|
|
107
|
+
"#{request} :#{name} do\n end\n"
|
108
|
+
end.join("\n ")
|
109
|
+
end
|
110
|
+
|
111
|
+
# For controller route generation
|
112
|
+
# Takes in the fields and maps out an appropriate default route.
|
113
|
+
# where controller is user and route is get:test, will add map(:test).to("/user/test")
|
114
|
+
def controller_routes(name,fields)
|
115
|
+
field_tuples = fields.collect { |value| value.split(":") }
|
116
|
+
routes = "\n" + field_tuples.collect do |request, route|
|
117
|
+
" map(:#{route}).to(\"/#{name}/#{route}\")"
|
118
|
+
end.join("\n") + "\n"
|
119
|
+
end
|
120
|
+
|
54
121
|
end
|
55
122
|
end
|
56
123
|
end
|
@@ -8,24 +8,25 @@ module Padrino
|
|
8
8
|
AR = (<<-AR).gsub(/^ {10}/, '')
|
9
9
|
module DatabaseSetup
|
10
10
|
def self.registered(app)
|
11
|
+
app.configure { ActiveRecord::Base.logger = logger }
|
11
12
|
app.configure :development do
|
12
13
|
ActiveRecord::Base.establish_connection(
|
13
14
|
:adapter => 'sqlite3',
|
14
|
-
:database =>
|
15
|
+
:database => "your_dev_db_here"
|
15
16
|
)
|
16
17
|
end
|
17
18
|
|
18
19
|
app.configure :production do
|
19
20
|
ActiveRecord::Base.establish_connection(
|
20
21
|
:adapter => 'sqlite3',
|
21
|
-
:database =>
|
22
|
+
:database => "your_production_db_here"
|
22
23
|
)
|
23
24
|
end
|
24
25
|
|
25
26
|
app.configure :test do
|
26
27
|
ActiveRecord::Base.establish_connection(
|
27
28
|
:adapter => 'sqlite3',
|
28
|
-
:database =>
|
29
|
+
:database => "your_test_db_here"
|
29
30
|
)
|
30
31
|
end
|
31
32
|
end
|
@@ -39,10 +40,11 @@ module Padrino
|
|
39
40
|
namespace :db do
|
40
41
|
desc "Migrate the database"
|
41
42
|
task(:migrate) do
|
42
|
-
load 'config/boot.rb'
|
43
|
+
load File.dirname(__FILE__) + '/config/boot.rb'
|
44
|
+
APP_CLASS.new
|
43
45
|
ActiveRecord::Base.logger = Logger.new(STDOUT)
|
44
46
|
ActiveRecord::Migration.verbose = true
|
45
|
-
ActiveRecord::Migrator.migrate("db/migrate")
|
47
|
+
ActiveRecord::Migrator.migrate( File.dirname(__FILE__) + "/db/migrate")
|
46
48
|
end
|
47
49
|
end
|
48
50
|
RAKE
|
@@ -51,7 +53,7 @@ module Padrino
|
|
51
53
|
def setup_orm
|
52
54
|
require_dependencies 'activerecord'
|
53
55
|
create_file("config/database.rb", AR)
|
54
|
-
create_file("Rakefile", RAKE)
|
56
|
+
create_file("Rakefile", RAKE.gsub(/APP_CLASS/, @class_name))
|
55
57
|
empty_directory('app/models')
|
56
58
|
end
|
57
59
|
|
@@ -69,30 +71,47 @@ module Padrino
|
|
69
71
|
end
|
70
72
|
|
71
73
|
AR_MIGRATION = (<<-MIGRATION).gsub(/^ {10}/, '')
|
72
|
-
class !
|
74
|
+
class !FILECLASS! < ActiveRecord::Migration
|
73
75
|
def self.up
|
74
|
-
|
75
|
-
# t.column <name>, <type>
|
76
|
-
# t.column :age, :integer
|
77
|
-
!FIELDS!
|
78
|
-
end
|
76
|
+
!UP!
|
79
77
|
end
|
80
78
|
|
81
79
|
def self.down
|
82
|
-
|
80
|
+
!DOWN!
|
83
81
|
end
|
84
82
|
end
|
85
83
|
MIGRATION
|
86
84
|
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
85
|
+
AR_MODEL_UP_MG = (<<-MIGRATION).gsub(/^ {6}/, '')
|
86
|
+
create_table :!TABLE! do |t|
|
87
|
+
# t.column <name>, <type>
|
88
|
+
# t.column :age, :integer
|
89
|
+
!FIELDS!
|
90
|
+
end
|
91
|
+
MIGRATION
|
92
|
+
|
93
|
+
AR_MODEL_DOWN_MG = (<<-MIGRATION).gsub(/^ {10}/, '')
|
94
|
+
drop_table :!TABLE!
|
95
|
+
MIGRATION
|
96
|
+
|
97
|
+
def create_model_migration(migration_name, name, columns)
|
98
|
+
output_model_migration(migration_name, name, columns,
|
99
|
+
:base => AR_MIGRATION,
|
100
|
+
:column_format => lambda { |field, kind| "t.column :#{field}, :#{kind.underscore.gsub(/_/, '')}" },
|
101
|
+
:up => AR_MODEL_UP_MG, :down => AR_MODEL_DOWN_MG)
|
102
|
+
end
|
103
|
+
|
104
|
+
AR_CHANGE_MG = (<<-MIGRATION).gsub(/^ {6}/, '')
|
105
|
+
change_table :!TABLE! do |t|
|
106
|
+
!COLUMNS!
|
107
|
+
end
|
108
|
+
MIGRATION
|
109
|
+
|
110
|
+
def create_migration_file(migration_name, name, columns)
|
111
|
+
output_migration_file(migration_name, name, columns,
|
112
|
+
:base => AR_MIGRATION, :change_format => AR_CHANGE_MG,
|
113
|
+
:add => lambda { |field, kind| "t.column :#{field}, :#{kind.underscore.gsub(/_/, '')}" },
|
114
|
+
:remove => lambda { |field, kind| "t.remove :#{field}" })
|
96
115
|
end
|
97
116
|
|
98
117
|
end
|
@@ -8,14 +8,13 @@ module Padrino
|
|
8
8
|
COUCHREST = (<<-COUCHREST).gsub(/^ {10}/, '')
|
9
9
|
module DatabaseSetup
|
10
10
|
def self.registered(app)
|
11
|
-
app.configure(:development) { set :couchdb, CouchRest.database!(
|
12
|
-
app.configure(:production) { set :couchdb, CouchRest.database!(
|
13
|
-
app.configure(:test) { set :couchdb, CouchRest.database!(
|
11
|
+
app.configure(:development) { set :couchdb, CouchRest.database!("your_dev_db_here") }
|
12
|
+
app.configure(:production) { set :couchdb, CouchRest.database!("your_production_db_here") }
|
13
|
+
app.configure(:test) { set :couchdb, CouchRest.database!("your_test_db_here") }
|
14
14
|
end
|
15
15
|
end
|
16
16
|
COUCHREST
|
17
17
|
|
18
|
-
|
19
18
|
def setup_orm
|
20
19
|
require_dependencies 'couchrest'
|
21
20
|
create_file("config/database.rb", COUCHREST)
|
@@ -44,7 +43,11 @@ module Padrino
|
|
44
43
|
create_file(model_path, model_contents)
|
45
44
|
end
|
46
45
|
|
47
|
-
def
|
46
|
+
def create_model_migration(filename, name, fields)
|
47
|
+
# NO MIGRATION NEEDED
|
48
|
+
end
|
49
|
+
|
50
|
+
def create_migration_file(migration_name, name, columns)
|
48
51
|
# NO MIGRATION NEEDED
|
49
52
|
end
|
50
53
|
end
|
@@ -7,11 +7,12 @@ module Padrino
|
|
7
7
|
DM = (<<-DM).gsub(/^ {10}/, '')
|
8
8
|
module DatabaseSetup
|
9
9
|
def self.registered(app)
|
10
|
-
app.configure
|
11
|
-
app.configure(:
|
12
|
-
app.configure(:
|
10
|
+
app.configure { DataMapper.logger = logger }
|
11
|
+
app.configure(:development) { DataMapper.setup(:default, "sqlite3://your_dev_db_here") }
|
12
|
+
app.configure(:production) { DataMapper.setup(:default, "sqlite3://your_production_db_here") }
|
13
|
+
app.configure(:test) { DataMapper.setup(:default, "sqlite3://your_test_db_here") }
|
13
14
|
rescue ArgumentError => e
|
14
|
-
|
15
|
+
logger.error "Database options need to be configured within 'config/database.rb'!" if app.logging?
|
15
16
|
end
|
16
17
|
end
|
17
18
|
DM
|
@@ -27,7 +28,7 @@ module Padrino
|
|
27
28
|
include DataMapper::Resource
|
28
29
|
|
29
30
|
# property <name>, <type>
|
30
|
-
|
31
|
+
property :id, Serial
|
31
32
|
!FIELDS!
|
32
33
|
end
|
33
34
|
MODEL
|
@@ -37,35 +38,53 @@ module Padrino
|
|
37
38
|
return false if File.exist?(model_path)
|
38
39
|
model_contents = DM_MODEL.gsub(/!NAME!/, name.to_s.downcase.camelize)
|
39
40
|
field_tuples = fields.collect { |value| value.split(":") }
|
41
|
+
field_tuples.collect! { |field, kind| kind =~ /datetime/i ? [field, 'DateTime'] : [field, kind] } # fix datetime
|
40
42
|
column_declarations = field_tuples.collect { |field, kind|"property :#{field}, #{kind.camelize}" }.join("\n ")
|
41
43
|
model_contents.gsub!(/!FIELDS!/, column_declarations)
|
42
44
|
create_file(model_path, model_contents)
|
43
45
|
end
|
44
46
|
|
45
47
|
DM_MIGRATION = (<<-MIGRATION).gsub(/^ {10}/, '')
|
46
|
-
migration
|
48
|
+
migration !VERSION!, :!FILENAME! do
|
47
49
|
up do
|
48
|
-
|
49
|
-
column(:id, Integer, :serial => true)
|
50
|
-
!FIELDS!
|
51
|
-
end
|
50
|
+
!UP!
|
52
51
|
end
|
53
52
|
|
54
53
|
down do
|
55
|
-
|
54
|
+
!DOWN!
|
56
55
|
end
|
57
56
|
end
|
58
57
|
MIGRATION
|
59
58
|
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
59
|
+
DM_MODEL_UP_MG = (<<-MIGRATION).gsub(/^ {6}/, '')
|
60
|
+
create_table :!TABLE! do
|
61
|
+
column :id, Integer, :serial => true
|
62
|
+
!FIELDS!
|
63
|
+
end
|
64
|
+
MIGRATION
|
65
|
+
|
66
|
+
DM_MODEL_DOWN_MG = (<<-MIGRATION).gsub(/^ {10}/, '')
|
67
|
+
drop_table :!TABLE!
|
68
|
+
MIGRATION
|
69
|
+
|
70
|
+
def create_model_migration(migration_name, name, columns)
|
71
|
+
output_model_migration(migration_name, name, columns,
|
72
|
+
:column_format => lambda { |field, kind| "column :#{field}, #{kind.camelize}" },
|
73
|
+
:base => DM_MIGRATION, :up => DM_MODEL_UP_MG, :down => DM_MODEL_DOWN_MG)
|
74
|
+
end
|
75
|
+
|
76
|
+
DM_CHANGE_MG = (<<-MIGRATION).gsub(/^ {6}/, '')
|
77
|
+
modify_table :!TABLE! do
|
78
|
+
!COLUMNS!
|
79
|
+
end
|
80
|
+
MIGRATION
|
81
|
+
|
82
|
+
def create_migration_file(migration_name, name, columns)
|
83
|
+
output_migration_file(migration_name, name, columns,
|
84
|
+
:base => DM_MIGRATION, :change_format => DM_CHANGE_MG,
|
85
|
+
:add => lambda { |field, kind| "add_column :#{field}, #{kind.camelize}" },
|
86
|
+
:remove => lambda { |field, kind| "drop_column :#{field}" }
|
87
|
+
)
|
69
88
|
end
|
70
89
|
end
|
71
90
|
|
@@ -11,17 +11,17 @@ module Padrino
|
|
11
11
|
module DatabaseSetup
|
12
12
|
def self.registered(app)
|
13
13
|
app.configure :development do
|
14
|
-
MongoMapper.connection = Mongo::Connection.new('localhost')
|
14
|
+
MongoMapper.connection = Mongo::Connection.new('localhost', nil, :logger => logger)
|
15
15
|
MongoMapper.database = 'your_dev_db_here'
|
16
16
|
end
|
17
17
|
|
18
18
|
app.configure :production do
|
19
|
-
MongoMapper.connection = Mongo::Connection.new('localhost')
|
19
|
+
MongoMapper.connection = Mongo::Connection.new('localhost', nil, :logger => logger)
|
20
20
|
MongoMapper.database = 'your_production_db_here'
|
21
21
|
end
|
22
22
|
|
23
23
|
app.configure :test do
|
24
|
-
MongoMapper.connection = Mongo::Connection.new('localhost')
|
24
|
+
MongoMapper.connection = Mongo::Connection.new('localhost', nil, :logger => logger)
|
25
25
|
MongoMapper.database = 'your_test_db_here'
|
26
26
|
end
|
27
27
|
end
|
@@ -53,7 +53,11 @@ module Padrino
|
|
53
53
|
create_file(model_path, model_contents)
|
54
54
|
end
|
55
55
|
|
56
|
-
def
|
56
|
+
def create_model_migration(filename, name, fields)
|
57
|
+
# NO MIGRATION NEEDED
|
58
|
+
end
|
59
|
+
|
60
|
+
def create_migration_file(migration_name, name, columns)
|
57
61
|
# NO MIGRATION NEEDED
|
58
62
|
end
|
59
63
|
end
|
@@ -9,9 +9,9 @@ module Padrino
|
|
9
9
|
module DatabaseSetup
|
10
10
|
def self.registered(app)
|
11
11
|
Sequel::Model.plugin(:schema)
|
12
|
-
app.configure(:development) { Sequel.connect(
|
13
|
-
app.configure(:production) { Sequel.connect(
|
14
|
-
app.configure(:test) { Sequel.connect(
|
12
|
+
app.configure(:development) { Sequel.connect("sqlite://your_dev_db_here", :loggers => [logger]) }
|
13
|
+
app.configure(:production) { Sequel.connect("sqlite://your_production_db_here", :loggers => [logger]) }
|
14
|
+
app.configure(:test) { Sequel.connect("sqlite://your_test_db_here", :loggers => [logger]) }
|
15
15
|
end
|
16
16
|
end
|
17
17
|
SEQUEL
|
@@ -36,30 +36,48 @@ module Padrino
|
|
36
36
|
end
|
37
37
|
|
38
38
|
SQ_MIGRATION = (<<-MIGRATION).gsub(/^ {10}/, '')
|
39
|
-
class !
|
39
|
+
class !FILECLASS! < Sequel::Migration
|
40
40
|
def up
|
41
|
-
|
42
|
-
primary_key :id
|
43
|
-
# <type> <name>
|
44
|
-
!FIELDS!
|
45
|
-
end
|
41
|
+
!UP!
|
46
42
|
end
|
47
43
|
|
48
44
|
def down
|
49
|
-
|
45
|
+
!DOWN!
|
50
46
|
end
|
51
47
|
end
|
52
48
|
MIGRATION
|
53
49
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
50
|
+
|
51
|
+
SQ_MODEL_UP_MG = (<<-MIGRATION).gsub(/^ {6}/, '')
|
52
|
+
create_table :!TABLE! do
|
53
|
+
primary_key :id
|
54
|
+
# <type> <name>
|
55
|
+
!FIELDS!
|
56
|
+
end
|
57
|
+
MIGRATION
|
58
|
+
|
59
|
+
SQ_MODEL_DOWN_MG = (<<-MIGRATION).gsub(/^ {10}/, '')
|
60
|
+
drop_table :!TABLE!
|
61
|
+
MIGRATION
|
62
|
+
|
63
|
+
def create_model_migration(migration_name, name, columns)
|
64
|
+
output_model_migration(migration_name, name, columns,
|
65
|
+
:column_format => lambda { |field, kind| "#{kind.camelize} :#{field}" },
|
66
|
+
:base => SQ_MIGRATION, :up => SQ_MODEL_UP_MG, :down => SQ_MODEL_DOWN_MG)
|
67
|
+
end
|
68
|
+
|
69
|
+
SQ_CHANGE_MG = (<<-MIGRATION).gsub(/^ {6}/, '')
|
70
|
+
alter_table :!TABLE! do
|
71
|
+
!COLUMNS!
|
72
|
+
end
|
73
|
+
MIGRATION
|
74
|
+
|
75
|
+
def create_migration_file(migration_name, name, columns)
|
76
|
+
output_migration_file(migration_name, name, columns,
|
77
|
+
:base => SQ_MIGRATION, :change_format => SQ_CHANGE_MG,
|
78
|
+
:add => lambda { |field, kind| "add_column :#{field}, #{kind.camelize}" },
|
79
|
+
:remove => lambda { |field, kind| "drop_column :#{field}" }
|
80
|
+
)
|
63
81
|
end
|
64
82
|
end
|
65
83
|
|
@@ -50,7 +50,7 @@ module Padrino
|
|
50
50
|
|
51
51
|
def generate_model_test(name)
|
52
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
|
53
|
+
create_file app_root_path("test/models/#{name.to_s.downcase}_test.rb"), bacon_contents
|
54
54
|
end
|
55
55
|
|
56
56
|
end
|
@@ -49,7 +49,7 @@ module Padrino
|
|
49
49
|
|
50
50
|
def generate_model_test(name)
|
51
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
|
52
|
+
create_file app_root_path("test/models/#{name.to_s.downcase}_test.rb"), riot_contents
|
53
53
|
end
|
54
54
|
|
55
55
|
end
|
@@ -51,7 +51,7 @@ module Padrino
|
|
51
51
|
|
52
52
|
def generate_model_test(name)
|
53
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
|
54
|
+
create_file app_root_path("test/models/#{name.to_s.downcase}_spec.rb"), rspec_contents
|
55
55
|
end
|
56
56
|
|
57
57
|
end
|
@@ -56,7 +56,7 @@ module Padrino
|
|
56
56
|
|
57
57
|
def generate_model_test(name)
|
58
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
|
59
|
+
create_file app_root_path("test/models/#{name.to_s.downcase}_test.rb"), shoulda_contents
|
60
60
|
end
|
61
61
|
|
62
62
|
end
|
@@ -49,7 +49,7 @@ module Padrino
|
|
49
49
|
|
50
50
|
def generate_model_test(name)
|
51
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
|
52
|
+
create_file app_root_path("test/models/#{name.to_s.downcase}_test.rb"), tests_contents
|
53
53
|
end
|
54
54
|
|
55
55
|
end
|
@@ -16,12 +16,15 @@ module Padrino
|
|
16
16
|
desc "Description:\n\n\tpadrino-gen controller generates a new Padrino controller"
|
17
17
|
|
18
18
|
argument :name, :desc => "The name of your padrino controller"
|
19
|
+
argument :fields, :desc => "The fields for the controller", :type => :array, :default => []
|
19
20
|
class_option :root, :aliases => '-r', :default => nil, :type => :string
|
20
21
|
|
21
22
|
# Copies over the base sinatra starting project
|
22
23
|
def create_controller
|
23
24
|
if in_app_root?(options[:root])
|
24
25
|
@app_name = fetch_app_name(options[:root])
|
26
|
+
@actions = controller_actions(fields)
|
27
|
+
inject_into_file app_root_path("config/urls.rb"), controller_routes(name,fields), :after => "urls do\n"
|
25
28
|
template "templates/controller.rb.tt", app_root_path("app/controllers", "#{name}.rb")
|
26
29
|
template "templates/helper.rb.tt", app_root_path("app/helpers", "#{name}_helper.rb")
|
27
30
|
empty_directory app_root_path("app/views/#{name}")
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'thor'
|
2
|
+
|
3
|
+
module Padrino
|
4
|
+
module Generators
|
5
|
+
|
6
|
+
class Migration < 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 migration [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 migration generates a new migration file"
|
17
|
+
|
18
|
+
argument :name, :desc => "The name of your padrino migration"
|
19
|
+
argument :columns, :desc => "The columns for the migration", :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
|
+
include_component_module_for(:orm, options[:root])
|
26
|
+
create_migration_file(name, name, columns)
|
27
|
+
else
|
28
|
+
say "You are not at the root of a Padrino application! (config/boot.rb not found)" and return unless in_app_root?
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
end
|
data/lib/generators/model.rb
CHANGED
@@ -27,7 +27,7 @@ module Padrino
|
|
27
27
|
migration_name = "create_#{name.pluralize.underscore}"
|
28
28
|
model_success = create_model_file(name, fields)
|
29
29
|
generate_model_test(name) if model_success
|
30
|
-
model_success ?
|
30
|
+
model_success ? create_model_migration(migration_name, name, fields) :
|
31
31
|
say("'#{name}' model has already been generated!")
|
32
32
|
else
|
33
33
|
say "You are not at the root of a Padrino application! (config/boot.rb not found)" and return unless in_app_root?
|
File without changes
|
data/lib/padrino-gen.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
1
|
require 'padrino-core/support_lite'
|
2
2
|
Dir[File.dirname(__FILE__) + "/generators/{components}/**/*.rb"].each { |lib| require lib }
|
3
3
|
require File.dirname(__FILE__) + "/generators/actions.rb"
|
4
|
-
Dir[File.dirname(__FILE__) + "/generators/{skeleton,mailer,controller,model}.rb"].each { |lib| require lib }
|
4
|
+
Dir[File.dirname(__FILE__) + "/generators/{skeleton,mailer,controller,model,migration}.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.2.
|
8
|
+
s.version = "0.2.1"
|
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-30}
|
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}
|
@@ -46,6 +46,7 @@ Gem::Specification.new do |s|
|
|
46
46
|
"lib/generators/components/tests/testspec_test_gen.rb",
|
47
47
|
"lib/generators/controller.rb",
|
48
48
|
"lib/generators/mailer.rb",
|
49
|
+
"lib/generators/migration.rb",
|
49
50
|
"lib/generators/model.rb",
|
50
51
|
"lib/generators/skeleton.rb",
|
51
52
|
"lib/generators/skeleton/.gitignore",
|
@@ -65,7 +66,7 @@ Gem::Specification.new do |s|
|
|
65
66
|
"lib/generators/skeleton/public/images/.empty_directory",
|
66
67
|
"lib/generators/skeleton/public/javascripts/.empty_directory",
|
67
68
|
"lib/generators/skeleton/public/stylesheets/.empty_directory",
|
68
|
-
"lib/generators/skeleton/tmp/.
|
69
|
+
"lib/generators/skeleton/tmp/.empty_directory",
|
69
70
|
"lib/generators/templates/controller.rb.tt",
|
70
71
|
"lib/generators/templates/helper.rb.tt",
|
71
72
|
"lib/generators/templates/mailer.rb.tt",
|
@@ -99,6 +100,7 @@ Gem::Specification.new do |s|
|
|
99
100
|
s.add_development_dependency(%q<mocha>, [">= 0.9.7"])
|
100
101
|
s.add_development_dependency(%q<rack-test>, [">= 0.5.0"])
|
101
102
|
s.add_development_dependency(%q<webrat>, [">= 0.5.1"])
|
103
|
+
s.add_development_dependency(%q<fakeweb>, [">= 1.2.3"])
|
102
104
|
else
|
103
105
|
s.add_dependency(%q<sinatra>, [">= 0.9.2"])
|
104
106
|
s.add_dependency(%q<padrino-core>, [">= 0.1.1"])
|
@@ -109,6 +111,7 @@ Gem::Specification.new do |s|
|
|
109
111
|
s.add_dependency(%q<mocha>, [">= 0.9.7"])
|
110
112
|
s.add_dependency(%q<rack-test>, [">= 0.5.0"])
|
111
113
|
s.add_dependency(%q<webrat>, [">= 0.5.1"])
|
114
|
+
s.add_dependency(%q<fakeweb>, [">= 1.2.3"])
|
112
115
|
end
|
113
116
|
else
|
114
117
|
s.add_dependency(%q<sinatra>, [">= 0.9.2"])
|
@@ -120,6 +123,7 @@ Gem::Specification.new do |s|
|
|
120
123
|
s.add_dependency(%q<mocha>, [">= 0.9.7"])
|
121
124
|
s.add_dependency(%q<rack-test>, [">= 0.5.0"])
|
122
125
|
s.add_dependency(%q<webrat>, [">= 0.5.1"])
|
126
|
+
s.add_dependency(%q<fakeweb>, [">= 1.2.3"])
|
123
127
|
end
|
124
128
|
end
|
125
129
|
|
@@ -5,6 +5,9 @@ class TestControllerGenerator < Test::Unit::TestCase
|
|
5
5
|
def setup
|
6
6
|
@skeleton = Padrino::Generators::Skeleton.dup
|
7
7
|
@contgen = Padrino::Generators::Controller.dup
|
8
|
+
@controller_path = '/tmp/sample_app/app/controllers/demo_items.rb'
|
9
|
+
@controller_test_path = '/tmp/sample_app/test/controllers/demo_items_controller_test.rb'
|
10
|
+
@route_path = '/tmp/sample_app/config/urls.rb'
|
8
11
|
`rm -rf /tmp/sample_app`
|
9
12
|
end
|
10
13
|
|
@@ -18,7 +21,7 @@ class TestControllerGenerator < Test::Unit::TestCase
|
|
18
21
|
should "generate controller within existing application" do
|
19
22
|
silence_logger { @skeleton.start(['sample_app', '/tmp', '--script=none', '-t=bacon']) }
|
20
23
|
silence_logger { @contgen.start(['demo_items', '-r=/tmp/sample_app']) }
|
21
|
-
assert_match_in_file(/SampleApp.controllers do/m,
|
24
|
+
assert_match_in_file(/SampleApp.controllers do/m, @controller_path)
|
22
25
|
assert_match_in_file(/SampleApp.helpers do/m, '/tmp/sample_app/app/helpers/demo_items_helper.rb')
|
23
26
|
assert_file_exists('/tmp/sample_app/app/views/demo_items')
|
24
27
|
end
|
@@ -26,19 +29,19 @@ class TestControllerGenerator < Test::Unit::TestCase
|
|
26
29
|
should "generate controller test for bacon" do
|
27
30
|
silence_logger { @skeleton.start(['sample_app', '/tmp', '--script=none', '-t=bacon']) }
|
28
31
|
silence_logger { @contgen.start(['demo_items', '-r=/tmp/sample_app']) }
|
29
|
-
assert_match_in_file(/describe "DemoItemsController" do/m,
|
32
|
+
assert_match_in_file(/describe "DemoItemsController" do/m, @controller_test_path)
|
30
33
|
end
|
31
34
|
|
32
35
|
should "generate controller test for riot" do
|
33
36
|
silence_logger { @skeleton.start(['sample_app', '/tmp', '--script=none', '-t=riot']) }
|
34
37
|
silence_logger { @contgen.start(['demo_items', '-r=/tmp/sample_app']) }
|
35
|
-
assert_match_in_file(/context "DemoItemsController" do/m,
|
38
|
+
assert_match_in_file(/context "DemoItemsController" do/m, @controller_test_path)
|
36
39
|
end
|
37
40
|
|
38
41
|
should "generate controller test for testspec" do
|
39
42
|
silence_logger { @skeleton.start(['sample_app', '/tmp', '--script=none', '-t=testspec']) }
|
40
43
|
silence_logger { @contgen.start(['demo_items', '-r=/tmp/sample_app']) }
|
41
|
-
assert_match_in_file(/context "DemoItemsController" do/m,
|
44
|
+
assert_match_in_file(/context "DemoItemsController" do/m, @controller_test_path)
|
42
45
|
end
|
43
46
|
|
44
47
|
should "generate controller test for rspec" do
|
@@ -51,7 +54,24 @@ class TestControllerGenerator < Test::Unit::TestCase
|
|
51
54
|
silence_logger { @skeleton.start(['sample_app', '/tmp', '--script=none', '-t=shoulda']) }
|
52
55
|
silence_logger { @contgen.start(['demo_items', '-r=/tmp/sample_app']) }
|
53
56
|
expected_pattern = /class DemoItemsControllerTest < Test::Unit::TestCase/m
|
54
|
-
assert_match_in_file(expected_pattern,
|
57
|
+
assert_match_in_file(expected_pattern, @controller_test_path)
|
55
58
|
end
|
59
|
+
|
60
|
+
# Controller action generation
|
61
|
+
|
62
|
+
should "generate actions for get:test post:yada" do
|
63
|
+
silence_logger { @skeleton.start(['sample_app', '/tmp', '--script=none', '-t=shoulda'])}
|
64
|
+
silence_logger { @contgen.start(['demo_items', "get:test","post:yada",'-r=/tmp/sample_app']) }
|
65
|
+
assert_match_in_file(/get :test do\n end\n/m,@controller_path)
|
66
|
+
assert_match_in_file(/post :yada do\n end\n/m,@controller_path)
|
67
|
+
end
|
68
|
+
|
69
|
+
should "generate url routes for get:yoda post:yada" do
|
70
|
+
silence_logger { @skeleton.start(['sample_app', '/tmp', '--script=none', '-t=shoulda'])}
|
71
|
+
silence_logger { @contgen.start(['demo_items', "get:yoda","post:yada",'-r=/tmp/sample_app']) }
|
72
|
+
assert_match_in_file(/map\(\:yoda\).to\(\"\/demo_items\/yoda\"\)/m,@route_path)
|
73
|
+
assert_match_in_file(/map\(\:yada\).to\(\"\/demo_items\/yada\"\)/m,@route_path)
|
74
|
+
end
|
75
|
+
|
56
76
|
end
|
57
77
|
end
|
@@ -4,14 +4,155 @@ require 'thor'
|
|
4
4
|
class TestMigrationGenerator < Test::Unit::TestCase
|
5
5
|
def setup
|
6
6
|
@skeleton = Padrino::Generators::Skeleton.dup
|
7
|
-
|
7
|
+
@mig_gen = Padrino::Generators::Migration.dup
|
8
8
|
`rm -rf /tmp/sample_app`
|
9
9
|
end
|
10
10
|
|
11
11
|
context 'the migration generator' do
|
12
|
-
should "
|
12
|
+
should "fail outside app root" do
|
13
|
+
output = silence_logger { @mig_gen.start(['add_email_to_users', '-r=/tmp']) }
|
14
|
+
assert_match(/not at the root/, output)
|
15
|
+
assert_no_file_exists('/tmp/db/migration')
|
16
|
+
end
|
17
|
+
|
18
|
+
should "generate migration inside app root" do
|
19
|
+
silence_logger { @skeleton.start(['sample_app', '/tmp', '--script=none', '-t=bacon', '-d=activerecord']) }
|
20
|
+
response_success = silence_logger { @mig_gen.start(['AddEmailToUsers', '-r=/tmp/sample_app']) }
|
21
|
+
migration_file_path = "/tmp/sample_app/db/migrate/001_add_email_to_users.rb"
|
22
|
+
assert_match_in_file(/class AddEmailToUser/m, migration_file_path)
|
23
|
+
end
|
13
24
|
|
25
|
+
should "generate migration inside app root with lowercase migration argument" do
|
26
|
+
silence_logger { @skeleton.start(['sample_app', '/tmp', '--script=none', '-t=bacon', '-d=activerecord']) }
|
27
|
+
response_success = silence_logger { @mig_gen.start(['add_email_to_users', '-r=/tmp/sample_app']) }
|
28
|
+
migration_file_path = "/tmp/sample_app/db/migrate/001_add_email_to_users.rb"
|
29
|
+
assert_match_in_file(/class AddEmailToUsers/m, migration_file_path)
|
30
|
+
end
|
31
|
+
|
32
|
+
should "generate migration inside app root with singular table" do
|
33
|
+
silence_logger { @skeleton.start(['sample_app', '/tmp', '--script=none', '-t=bacon', '-d=activerecord']) }
|
34
|
+
silence_logger { @mig_gen.start(['add_email_to_user', "email:string", '-r=/tmp/sample_app']) }
|
35
|
+
migration_file_path = "/tmp/sample_app/db/migrate/001_add_email_to_user.rb"
|
36
|
+
assert_match_in_file(/class AddEmailToUser/m, migration_file_path)
|
37
|
+
assert_match_in_file(/t.column :email, :string/, migration_file_path)
|
38
|
+
assert_match_in_file(/t.remove :email/, migration_file_path)
|
39
|
+
end
|
40
|
+
should "properly calculate version number" do
|
41
|
+
silence_logger { @skeleton.start(['sample_app', '/tmp', '--script=none', '-t=bacon', '-d=sequel']) }
|
42
|
+
silence_logger { @mig_gen.start(['add_email_to_person', "email:string", '-r=/tmp/sample_app']) }
|
43
|
+
silence_logger { @mig_gen.start(['add_name_to_person', "email:string", '-r=/tmp/sample_app']) }
|
44
|
+
silence_logger { @mig_gen.start(['add_age_to_user', "email:string", '-r=/tmp/sample_app']) }
|
45
|
+
assert_match_in_file(/class AddEmailToPerson/m, "/tmp/sample_app/db/migrate/001_add_email_to_person.rb")
|
46
|
+
assert_match_in_file(/class AddNameToPerson/m, "/tmp/sample_app/db/migrate/002_add_name_to_person.rb")
|
47
|
+
assert_match_in_file(/class AddAgeToUser/m, "/tmp/sample_app/db/migrate/003_add_age_to_user.rb")
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
context 'the migration generator for activerecord' do
|
52
|
+
should "generate migration for generic needs" do
|
53
|
+
silence_logger { @skeleton.start(['sample_app', '/tmp', '--script=none', '-t=bacon', '-d=activerecord']) }
|
54
|
+
response_success = silence_logger { @mig_gen.start(['ModifyUserFields', '-r=/tmp/sample_app']) }
|
55
|
+
migration_file_path = "/tmp/sample_app/db/migrate/001_modify_user_fields.rb"
|
56
|
+
assert_match_in_file(/class ModifyUserFields/m, migration_file_path)
|
57
|
+
assert_match_in_file(/def self\.up\s+end/m, migration_file_path)
|
58
|
+
assert_match_in_file(/def self\.down\s+end/m, migration_file_path)
|
59
|
+
end
|
60
|
+
should "generate migration for adding columns" do
|
61
|
+
silence_logger { @skeleton.start(['sample_app', '/tmp', '--script=none', '-t=bacon', '-d=activerecord']) }
|
62
|
+
migration_params = ['AddEmailToUsers', "email:string", "age:integer", '-r=/tmp/sample_app']
|
63
|
+
response_success = silence_logger { @mig_gen.start(migration_params) }
|
64
|
+
migration_file_path = "/tmp/sample_app/db/migrate/001_add_email_to_users.rb"
|
65
|
+
assert_match_in_file(/class AddEmailToUsers/m, migration_file_path)
|
66
|
+
assert_match_in_file(/change_table :users.*?t\.column :email, :string/m, migration_file_path)
|
67
|
+
assert_match_in_file(/t\.column :age, :integer/m, migration_file_path)
|
68
|
+
assert_match_in_file(/change_table :users.*?t\.remove :email/m, migration_file_path)
|
69
|
+
assert_match_in_file(/t\.remove :age/m, migration_file_path)
|
70
|
+
end
|
71
|
+
should "generate migration for removing columns" do
|
72
|
+
silence_logger { @skeleton.start(['sample_app', '/tmp', '--script=none', '-t=bacon', '-d=activerecord']) }
|
73
|
+
migration_params = ['RemoveEmailFromUsers', "email:string", "age:integer", '-r=/tmp/sample_app']
|
74
|
+
response_success = silence_logger { @mig_gen.start(migration_params) }
|
75
|
+
migration_file_path = "/tmp/sample_app/db/migrate/001_remove_email_from_users.rb"
|
76
|
+
assert_match_in_file(/class RemoveEmailFromUsers/m, migration_file_path)
|
77
|
+
assert_match_in_file(/change_table :users.*?t\.remove :email/m, migration_file_path)
|
78
|
+
assert_match_in_file(/t\.remove :age/m, migration_file_path)
|
79
|
+
assert_match_in_file(/change_table :users.*?t\.column :email, :string/m, migration_file_path)
|
80
|
+
assert_match_in_file(/t\.column :age, :integer/m, migration_file_path)
|
14
81
|
end
|
15
82
|
end
|
16
83
|
|
84
|
+
context 'the migration generator for datamapper' do
|
85
|
+
should "generate migration for generic needs" do
|
86
|
+
silence_logger { @skeleton.start(['sample_app', '/tmp', '--script=none', '-t=bacon', '-d=datamapper']) }
|
87
|
+
response_success = silence_logger { @mig_gen.start(['ModifyUserFields', '-r=/tmp/sample_app']) }
|
88
|
+
migration_file_path = "/tmp/sample_app/db/migrate/001_modify_user_fields.rb"
|
89
|
+
assert_match_in_file(/migration\s1.*?:modify_user_fields/m, migration_file_path)
|
90
|
+
assert_match_in_file(/up\sdo\s+end/m, migration_file_path)
|
91
|
+
assert_match_in_file(/down\sdo\s+end/m, migration_file_path)
|
92
|
+
end
|
93
|
+
should "generate migration for adding columns" do
|
94
|
+
silence_logger { @skeleton.start(['sample_app', '/tmp', '--script=none', '-t=bacon', '-d=datamapper']) }
|
95
|
+
migration_params = ['AddEmailToUsers', "email:string", "age:integer", '-r=/tmp/sample_app']
|
96
|
+
response_success = silence_logger { @mig_gen.start(migration_params) }
|
97
|
+
migration_file_path = "/tmp/sample_app/db/migrate/001_add_email_to_users.rb"
|
98
|
+
assert_match_in_file(/migration\s1.*?:add_email_to_users/m, migration_file_path)
|
99
|
+
assert_match_in_file(/modify_table :users.*?add_column :email, String/m, migration_file_path)
|
100
|
+
assert_match_in_file(/add_column :age, Integer/m, migration_file_path)
|
101
|
+
assert_match_in_file(/modify_table :users.*?drop_column :email/m, migration_file_path)
|
102
|
+
assert_match_in_file(/drop_column :age/m, migration_file_path)
|
103
|
+
end
|
104
|
+
should "generate migration for removing columns" do
|
105
|
+
silence_logger { @skeleton.start(['sample_app', '/tmp', '--script=none', '-t=bacon', '-d=datamapper']) }
|
106
|
+
migration_params = ['RemoveEmailFromUsers', "email:string", "age:integer", '-r=/tmp/sample_app']
|
107
|
+
response_success = silence_logger { @mig_gen.start(migration_params) }
|
108
|
+
migration_file_path = "/tmp/sample_app/db/migrate/001_remove_email_from_users.rb"
|
109
|
+
assert_match_in_file(/migration\s1.*?:remove_email_from_users/m, migration_file_path)
|
110
|
+
assert_match_in_file(/modify_table :users.*?drop_column :email/m, migration_file_path)
|
111
|
+
assert_match_in_file(/drop_column :age/m, migration_file_path)
|
112
|
+
assert_match_in_file(/modify_table :users.*?add_column :email, String/m, migration_file_path)
|
113
|
+
assert_match_in_file(/add_column :age, Integer/m, migration_file_path)
|
114
|
+
end
|
115
|
+
should "properly version migration files" do
|
116
|
+
silence_logger { @skeleton.start(['sample_app', '/tmp', '--script=none', '-t=bacon', '-d=datamapper']) }
|
117
|
+
response_success = silence_logger { @mig_gen.start(['ModifyUserFields', '-r=/tmp/sample_app']) }
|
118
|
+
response_success = silence_logger { @mig_gen.start(['ModifyUserFields2', '-r=/tmp/sample_app']) }
|
119
|
+
response_success = silence_logger { @mig_gen.start(['ModifyUserFields3', '-r=/tmp/sample_app']) }
|
120
|
+
assert_match_in_file(/migration\s1.*?:modify_user_fields/m, "/tmp/sample_app/db/migrate/001_modify_user_fields.rb")
|
121
|
+
assert_match_in_file(/migration\s2.*?:modify_user_fields2/m, "/tmp/sample_app/db/migrate/002_modify_user_fields2.rb")
|
122
|
+
assert_match_in_file(/migration\s3.*?:modify_user_fields3/m, "/tmp/sample_app/db/migrate/003_modify_user_fields3.rb")
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
context 'the migration generator for sequel' do
|
127
|
+
should "generate migration for generic needs" do
|
128
|
+
silence_logger { @skeleton.start(['sample_app', '/tmp', '--script=none', '-t=bacon', '-d=sequel']) }
|
129
|
+
response_success = silence_logger { @mig_gen.start(['ModifyUserFields', '-r=/tmp/sample_app']) }
|
130
|
+
migration_file_path = "/tmp/sample_app/db/migrate/001_modify_user_fields.rb"
|
131
|
+
assert_match_in_file(/class ModifyUserFields/m, migration_file_path)
|
132
|
+
assert_match_in_file(/def\sup\s+end/m, migration_file_path)
|
133
|
+
assert_match_in_file(/def\sdown\s+end/m, migration_file_path)
|
134
|
+
end
|
135
|
+
should "generate migration for adding columns" do
|
136
|
+
silence_logger { @skeleton.start(['sample_app', '/tmp', '--script=none', '-t=bacon', '-d=sequel']) }
|
137
|
+
migration_params = ['AddEmailToUsers', "email:string", "age:integer", '-r=/tmp/sample_app']
|
138
|
+
response_success = silence_logger { @mig_gen.start(migration_params) }
|
139
|
+
migration_file_path = "/tmp/sample_app/db/migrate/001_add_email_to_users.rb"
|
140
|
+
assert_match_in_file(/class AddEmailToUsers/m, migration_file_path)
|
141
|
+
assert_match_in_file(/alter_table :users.*?add_column :email, String/m, migration_file_path)
|
142
|
+
assert_match_in_file(/add_column :age, Integer/m, migration_file_path)
|
143
|
+
assert_match_in_file(/alter_table :users.*?drop_column :email/m, migration_file_path)
|
144
|
+
assert_match_in_file(/drop_column :age/m, migration_file_path)
|
145
|
+
end
|
146
|
+
should "generate migration for removing columns" do
|
147
|
+
silence_logger { @skeleton.start(['sample_app', '/tmp', '--script=none', '-t=bacon', '-d=sequel']) }
|
148
|
+
migration_params = ['RemoveEmailFromUsers', "email:string", "age:integer", '-r=/tmp/sample_app']
|
149
|
+
response_success = silence_logger { @mig_gen.start(migration_params) }
|
150
|
+
migration_file_path = "/tmp/sample_app/db/migrate/001_remove_email_from_users.rb"
|
151
|
+
assert_match_in_file(/class RemoveEmailFromUsers/m, migration_file_path)
|
152
|
+
assert_match_in_file(/alter_table :users.*?drop_column :email/m, migration_file_path)
|
153
|
+
assert_match_in_file(/drop_column :age/m, migration_file_path)
|
154
|
+
assert_match_in_file(/alter_table :users.*?add_column :email, String/m, migration_file_path)
|
155
|
+
assert_match_in_file(/add_column :age, Integer/m, migration_file_path)
|
156
|
+
end
|
157
|
+
end
|
17
158
|
end
|
@@ -22,6 +22,16 @@ class TestModelGenerator < Test::Unit::TestCase
|
|
22
22
|
assert_match_in_file(/class User < ActiveRecord::Base/m, '/tmp/sample_app/app/models/user.rb')
|
23
23
|
assert_match /'user' model has already been generated!/, response_duplicate
|
24
24
|
end
|
25
|
+
|
26
|
+
should "generate migration file versions properly" do
|
27
|
+
silence_logger { @skeleton.start(['sample_app', '/tmp', '--script=none', '-t=bacon', '-d=activerecord']) }
|
28
|
+
silence_logger { @model_gen.start(['user', '-r=/tmp/sample_app']) }
|
29
|
+
silence_logger { @model_gen.start(['account', '-r=/tmp/sample_app']) }
|
30
|
+
silence_logger { @model_gen.start(['bank', '-r=/tmp/sample_app']) }
|
31
|
+
assert_file_exists('/tmp/sample_app/db/migrate/001_create_users.rb')
|
32
|
+
assert_file_exists('/tmp/sample_app/db/migrate/002_create_accounts.rb')
|
33
|
+
assert_file_exists('/tmp/sample_app/db/migrate/003_create_banks.rb')
|
34
|
+
end
|
25
35
|
end
|
26
36
|
|
27
37
|
# ACTIVERECORD
|
@@ -33,26 +43,28 @@ class TestModelGenerator < Test::Unit::TestCase
|
|
33
43
|
end
|
34
44
|
|
35
45
|
should "generate migration file with no fields" do
|
36
|
-
current_time = stop_time_for_test
|
46
|
+
current_time = stop_time_for_test.strftime("%Y%m%d%H%M%S")
|
37
47
|
silence_logger { @skeleton.start(['sample_app', '/tmp', '--script=none', '-t=bacon', '-d=activerecord']) }
|
38
48
|
silence_logger { @model_gen.start(['user', '-r=/tmp/sample_app']) }
|
39
|
-
migration_file_path = "/tmp/sample_app/db/migrate
|
49
|
+
migration_file_path = "/tmp/sample_app/db/migrate/001_create_users.rb"
|
40
50
|
assert_match_in_file(/class CreateUsers < ActiveRecord::Migration/m, migration_file_path)
|
41
51
|
assert_match_in_file(/create_table :users/m, migration_file_path)
|
42
52
|
assert_match_in_file(/# t.column :age, :integer[\n\s]+?end/m, migration_file_path)
|
53
|
+
assert_match_in_file(/drop_table :users/m, migration_file_path)
|
43
54
|
end
|
44
55
|
|
45
56
|
should "generate migration file with given fields" do
|
46
|
-
current_time = stop_time_for_test
|
57
|
+
current_time = stop_time_for_test.strftime("%Y%m%d%H%M%S")
|
47
58
|
silence_logger { @skeleton.start(['sample_app', '/tmp', '--script=none', '-t=bacon', '-d=activerecord']) }
|
48
59
|
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
|
60
|
+
migration_file_path = "/tmp/sample_app/db/migrate/001_create_people.rb"
|
50
61
|
assert_match_in_file(/class CreatePeople < ActiveRecord::Migration/m, migration_file_path)
|
51
62
|
assert_match_in_file(/create_table :people/m, migration_file_path)
|
52
63
|
assert_match_in_file(/# t.column :age, :integer/m, migration_file_path)
|
53
64
|
assert_match_in_file(/t.column :name, :string/m, migration_file_path)
|
54
65
|
assert_match_in_file(/t.column :age, :integer/m, migration_file_path)
|
55
66
|
assert_match_in_file(/t.column :email, :string/m, migration_file_path)
|
67
|
+
assert_match_in_file(/drop_table :people/m, migration_file_path)
|
56
68
|
end
|
57
69
|
end
|
58
70
|
|
@@ -81,31 +93,44 @@ class TestModelGenerator < Test::Unit::TestCase
|
|
81
93
|
context "model generator using datamapper" do
|
82
94
|
should "generate model file with fields" do
|
83
95
|
silence_logger { @skeleton.start(['sample_app', '/tmp', '--script=none', '-d=datamapper']) }
|
84
|
-
silence_logger { @model_gen.start(['user', "name:string", "age:integer", "
|
96
|
+
silence_logger { @model_gen.start(['user', "name:string", "age:integer", "created_at:datetime", '-r=/tmp/sample_app']) }
|
85
97
|
assert_match_in_file(/class User\n\s+include DataMapper::Resource/m, '/tmp/sample_app/app/models/user.rb')
|
86
98
|
assert_match_in_file(/property :name, String/m, '/tmp/sample_app/app/models/user.rb')
|
87
99
|
assert_match_in_file(/property :age, Integer/m, '/tmp/sample_app/app/models/user.rb')
|
88
|
-
assert_match_in_file(/property :
|
100
|
+
assert_match_in_file(/property :created_at, DateTime/m, '/tmp/sample_app/app/models/user.rb')
|
101
|
+
end
|
102
|
+
|
103
|
+
should "properly generate version numbers" do
|
104
|
+
silence_logger { @skeleton.start(['sample_app', '/tmp', '--script=none', '-d=datamapper']) }
|
105
|
+
silence_logger { @model_gen.start(['user', "name:string", "age:integer", "created_at:datetime", '-r=/tmp/sample_app']) }
|
106
|
+
silence_logger { @model_gen.start(['person', "name:string", "age:integer", "created_at:datetime", '-r=/tmp/sample_app']) }
|
107
|
+
silence_logger { @model_gen.start(['account', "name:string", "age:integer", "created_at:datetime", '-r=/tmp/sample_app']) }
|
108
|
+
assert_match_in_file(/class User\n\s+include DataMapper::Resource/m, '/tmp/sample_app/app/models/user.rb')
|
109
|
+
assert_match_in_file(/migration 1, :create_users do/m, "/tmp/sample_app/db/migrate/001_create_users.rb")
|
110
|
+
assert_match_in_file(/class Person\n\s+include DataMapper::Resource/m, '/tmp/sample_app/app/models/person.rb')
|
111
|
+
assert_match_in_file(/migration 2, :create_people do/m, "/tmp/sample_app/db/migrate/002_create_people.rb")
|
112
|
+
assert_match_in_file(/class Account\n\s+include DataMapper::Resource/m, '/tmp/sample_app/app/models/account.rb')
|
113
|
+
assert_match_in_file(/migration 3, :create_accounts do/m, "/tmp/sample_app/db/migrate/003_create_accounts.rb")
|
89
114
|
end
|
90
115
|
|
91
116
|
should "generate migration with given fields" do
|
92
|
-
current_time = stop_time_for_test
|
117
|
+
current_time = stop_time_for_test.strftime("%Y%m%d%H%M%S")
|
93
118
|
silence_logger { @skeleton.start(['sample_app', '/tmp', '--script=none', '-d=datamapper']) }
|
94
|
-
silence_logger { @model_gen.start(['person', "name:string", "
|
119
|
+
silence_logger { @model_gen.start(['person', "name:string", "created_at:datetime", "email:string", '-r=/tmp/sample_app']) }
|
95
120
|
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
|
97
|
-
assert_match_in_file(/migration
|
98
|
-
assert_match_in_file(/create_table
|
99
|
-
assert_match_in_file(/column
|
100
|
-
assert_match_in_file(/column
|
101
|
-
assert_match_in_file(/column
|
102
|
-
assert_match_in_file(/drop_table
|
121
|
+
migration_file_path = "/tmp/sample_app/db/migrate/001_create_people.rb"
|
122
|
+
assert_match_in_file(/migration 1, :create_people do/m, migration_file_path)
|
123
|
+
assert_match_in_file(/create_table :people do/m, migration_file_path)
|
124
|
+
assert_match_in_file(/column :name, String/m, migration_file_path)
|
125
|
+
assert_match_in_file(/column :created_at, DateTime/m, migration_file_path)
|
126
|
+
assert_match_in_file(/column :email, String/m, migration_file_path)
|
127
|
+
assert_match_in_file(/drop_table :people/m, migration_file_path)
|
103
128
|
end
|
104
129
|
end
|
105
130
|
|
106
131
|
# MONGOMAPPER
|
107
132
|
context "model generator using mongomapper" do
|
108
|
-
should "generate
|
133
|
+
should "generate model file with no properties" do
|
109
134
|
silence_logger { @skeleton.start(['sample_app', '/tmp', '--script=none', '-d=mongomapper']) }
|
110
135
|
silence_logger { @model_gen.start(['person', '-r=/tmp/sample_app']) }
|
111
136
|
assert_match_in_file(/class Person\n\s+include MongoMapper::Document/m, '/tmp/sample_app/app/models/person.rb')
|
@@ -126,21 +151,22 @@ class TestModelGenerator < Test::Unit::TestCase
|
|
126
151
|
context "model generator using sequel" do
|
127
152
|
should "generate model file with given properties" do
|
128
153
|
silence_logger { @skeleton.start(['sample_app', '/tmp', '--script=none', '-d=sequel']) }
|
129
|
-
silence_logger { @model_gen.start(['user', "name:string", "age:integer", "
|
154
|
+
silence_logger { @model_gen.start(['user', "name:string", "age:integer", "created:datetime", '-r=/tmp/sample_app']) }
|
130
155
|
assert_match_in_file(/class User < Sequel::Model/m, '/tmp/sample_app/app/models/user.rb')
|
131
156
|
end
|
132
157
|
|
133
158
|
should "generate migration file with given properties" do
|
134
|
-
current_time = stop_time_for_test
|
159
|
+
current_time = stop_time_for_test.strftime("%Y%m%d%H%M%S")
|
135
160
|
silence_logger { @skeleton.start(['sample_app', '/tmp', '--script=none', '-d=sequel']) }
|
136
|
-
silence_logger { @model_gen.start(['person', "name:string", "age:integer", "
|
137
|
-
migration_file_path = "/tmp/sample_app/db/migrate
|
161
|
+
silence_logger { @model_gen.start(['person', "name:string", "age:integer", "created:datetime", '-r=/tmp/sample_app']) }
|
162
|
+
migration_file_path = "/tmp/sample_app/db/migrate/001_create_people.rb"
|
138
163
|
assert_match_in_file(/class Person < Sequel::Model/m, '/tmp/sample_app/app/models/person.rb')
|
139
164
|
assert_match_in_file(/class CreatePeople < Sequel::Migration/m, migration_file_path)
|
140
165
|
assert_match_in_file(/create_table :people/m, migration_file_path)
|
141
|
-
assert_match_in_file(/
|
142
|
-
assert_match_in_file(/
|
143
|
-
assert_match_in_file(/
|
166
|
+
assert_match_in_file(/String :name/m, migration_file_path)
|
167
|
+
assert_match_in_file(/Integer :age/m, migration_file_path)
|
168
|
+
assert_match_in_file(/DateTime :created/m, migration_file_path)
|
169
|
+
assert_match_in_file(/drop_table :people/m, migration_file_path)
|
144
170
|
end
|
145
171
|
end
|
146
172
|
|
@@ -149,46 +175,46 @@ class TestModelGenerator < Test::Unit::TestCase
|
|
149
175
|
should "generate test file for bacon" do
|
150
176
|
silence_logger { @skeleton.start(['sample_app', '/tmp', '--script=none', '-t=bacon', '-d=activerecord']) }
|
151
177
|
silence_logger { @model_gen.start(['User', '-r=/tmp/sample_app']) }
|
152
|
-
assert_match_in_file(/describe "User Model"/m, '/tmp/sample_app/test/models/
|
153
|
-
assert_match_in_file(/@user = User.new/m, '/tmp/sample_app/test/models/
|
154
|
-
assert_match_in_file(/@user\.should\.not\.be\.nil/m, '/tmp/sample_app/test/models/
|
178
|
+
assert_match_in_file(/describe "User Model"/m, '/tmp/sample_app/test/models/user_test.rb')
|
179
|
+
assert_match_in_file(/@user = User.new/m, '/tmp/sample_app/test/models/user_test.rb')
|
180
|
+
assert_match_in_file(/@user\.should\.not\.be\.nil/m, '/tmp/sample_app/test/models/user_test.rb')
|
155
181
|
end
|
156
182
|
|
157
183
|
# RIOT
|
158
184
|
should "generate test file for riot" do
|
159
185
|
silence_logger { @skeleton.start(['sample_app', '/tmp', '--script=none', '-t=riot', '-d=activerecord']) }
|
160
186
|
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/
|
162
|
-
assert_match_in_file(/@user = User.new/m, '/tmp/sample_app/test/models/
|
163
|
-
assert_match_in_file(/asserts\("that record is not nil"\) \{ \!@user.nil\? \}/m, '/tmp/sample_app/test/models/
|
187
|
+
assert_match_in_file(/context "User Model" do/m, '/tmp/sample_app/test/models/user_test.rb')
|
188
|
+
assert_match_in_file(/@user = User.new/m, '/tmp/sample_app/test/models/user_test.rb')
|
189
|
+
assert_match_in_file(/asserts\("that record is not nil"\) \{ \!@user.nil\? \}/m, '/tmp/sample_app/test/models/user_test.rb')
|
164
190
|
end
|
165
191
|
|
166
192
|
# RSPEC
|
167
193
|
should "generate test file for rspec" do
|
168
194
|
silence_logger { @skeleton.start(['sample_app', '/tmp', '--script=none', '-t=rspec', '-d=activerecord']) }
|
169
195
|
silence_logger { @model_gen.start(['User', '-r=/tmp/sample_app']) }
|
170
|
-
assert_match_in_file(/describe "User Model"/m, '/tmp/sample_app/test/models/
|
171
|
-
assert_match_in_file(/@user = User.new/m, '/tmp/sample_app/test/models/
|
172
|
-
assert_match_in_file(/@user\.should\.not\.be\snil/m, '/tmp/sample_app/test/models/
|
196
|
+
assert_match_in_file(/describe "User Model"/m, '/tmp/sample_app/test/models/user_spec.rb')
|
197
|
+
assert_match_in_file(/@user = User.new/m, '/tmp/sample_app/test/models/user_spec.rb')
|
198
|
+
assert_match_in_file(/@user\.should\.not\.be\snil/m, '/tmp/sample_app/test/models/user_spec.rb')
|
173
199
|
end
|
174
200
|
|
175
201
|
# SHOULDA
|
176
202
|
should "generate test file for shoulda" do
|
177
203
|
silence_logger { @skeleton.start(['sample_app', '/tmp', '--script=none', '-t=shoulda', '-d=activerecord']) }
|
178
|
-
silence_logger { @model_gen.start(['
|
179
|
-
assert_match_in_file(/class
|
180
|
-
assert_match_in_file(/context "
|
181
|
-
assert_match_in_file(/@
|
182
|
-
assert_match_in_file(/assert_not_nil @
|
204
|
+
silence_logger { @model_gen.start(['Person', '-r=/tmp/sample_app']) }
|
205
|
+
assert_match_in_file(/class PersonControllerTest < Test::Unit::TestCase/m, '/tmp/sample_app/test/models/person_test.rb')
|
206
|
+
assert_match_in_file(/context "Person Model"/m, '/tmp/sample_app/test/models/person_test.rb')
|
207
|
+
assert_match_in_file(/@person = Person.new/m, '/tmp/sample_app/test/models/person_test.rb')
|
208
|
+
assert_match_in_file(/assert_not_nil @person/m, '/tmp/sample_app/test/models/person_test.rb')
|
183
209
|
end
|
184
210
|
|
185
211
|
# TESTSPEC
|
186
212
|
should "generate test file for testspec" do
|
187
213
|
silence_logger { @skeleton.start(['sample_app', '/tmp', '--script=none', '-t=testspec', '-d=activerecord']) }
|
188
214
|
silence_logger { @model_gen.start(['User', '-r=/tmp/sample_app']) }
|
189
|
-
assert_match_in_file(/context "User Model"/m, '/tmp/sample_app/test/models/
|
190
|
-
assert_match_in_file(/@user = User.new/m, '/tmp/sample_app/test/models/
|
191
|
-
assert_match_in_file(/@user\.should\.not\.be\.nil/m, '/tmp/sample_app/test/models/
|
215
|
+
assert_match_in_file(/context "User Model"/m, '/tmp/sample_app/test/models/user_test.rb')
|
216
|
+
assert_match_in_file(/@user = User.new/m, '/tmp/sample_app/test/models/user_test.rb')
|
217
|
+
assert_match_in_file(/@user\.should\.not\.be\.nil/m, '/tmp/sample_app/test/models/user_test.rb')
|
192
218
|
end
|
193
219
|
end
|
194
220
|
|
@@ -1,8 +1,14 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/helper'
|
2
2
|
require 'thor'
|
3
|
+
require 'fakeweb'
|
3
4
|
|
4
5
|
class TestSkeletonGenerator < Test::Unit::TestCase
|
5
6
|
def setup
|
7
|
+
FakeWeb.allow_net_connect = false
|
8
|
+
FakeWeb.register_uri(:get, "http://prototypejs.org/assets/2009/8/31/prototype.js", :body => "prototype")
|
9
|
+
FakeWeb.register_uri(:get, "http://github.com/nesquena/lowpro/raw/master/dist/lowpro.js", :body => "lowpro")
|
10
|
+
FakeWeb.register_uri(:get, "http://jqueryjs.googlecode.com/files/jquery-1.3.2.min.js", :body => "jquery")
|
11
|
+
FakeWeb.register_uri(:get, "http://rightjs.org/builds/current/right-min.js", :body => "rightjs")
|
6
12
|
`rm -rf /tmp/sample_app`
|
7
13
|
@skeleton = Padrino::Generators::Skeleton.dup
|
8
14
|
end
|
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.2.
|
4
|
+
version: 0.2.1
|
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-30 00:00:00 -08:00
|
16
16
|
default_executable: padrino-gen
|
17
17
|
dependencies:
|
18
18
|
- !ruby/object:Gem::Dependency
|
@@ -105,6 +105,16 @@ dependencies:
|
|
105
105
|
- !ruby/object:Gem::Version
|
106
106
|
version: 0.5.1
|
107
107
|
version:
|
108
|
+
- !ruby/object:Gem::Dependency
|
109
|
+
name: fakeweb
|
110
|
+
type: :development
|
111
|
+
version_requirement:
|
112
|
+
version_requirements: !ruby/object:Gem::Requirement
|
113
|
+
requirements:
|
114
|
+
- - ">="
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
version: 1.2.3
|
117
|
+
version:
|
108
118
|
description: Generators for easily creating and building padrino applications from the console
|
109
119
|
email: nesquena@gmail.com
|
110
120
|
executables:
|
@@ -142,6 +152,7 @@ files:
|
|
142
152
|
- lib/generators/components/tests/testspec_test_gen.rb
|
143
153
|
- lib/generators/controller.rb
|
144
154
|
- lib/generators/mailer.rb
|
155
|
+
- lib/generators/migration.rb
|
145
156
|
- lib/generators/model.rb
|
146
157
|
- lib/generators/skeleton.rb
|
147
158
|
- lib/generators/skeleton/.gitignore
|
@@ -161,7 +172,7 @@ files:
|
|
161
172
|
- lib/generators/skeleton/public/images/.empty_directory
|
162
173
|
- lib/generators/skeleton/public/javascripts/.empty_directory
|
163
174
|
- lib/generators/skeleton/public/stylesheets/.empty_directory
|
164
|
-
- lib/generators/skeleton/tmp/.
|
175
|
+
- lib/generators/skeleton/tmp/.empty_directory
|
165
176
|
- lib/generators/templates/controller.rb.tt
|
166
177
|
- lib/generators/templates/helper.rb.tt
|
167
178
|
- lib/generators/templates/mailer.rb.tt
|