padrino-gen 0.12.8.1 → 0.12.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +13 -5
- data/Rakefile +1 -4
- data/lib/padrino-gen/generators/actions.rb +17 -5
- data/lib/padrino-gen/generators/app/app.rb.tt +3 -2
- data/lib/padrino-gen/generators/components/mocks/mocha.rb +1 -1
- data/lib/padrino-gen/generators/components/orms/activerecord.rb +14 -14
- data/lib/padrino-gen/generators/components/orms/datamapper.rb +16 -0
- data/lib/padrino-gen/generators/components/orms/mongoid.rb +20 -39
- data/lib/padrino-gen/generators/components/orms/mongomapper.rb +1 -0
- data/lib/padrino-gen/generators/components/orms/sequel.rb +3 -3
- data/lib/padrino-gen/generators/components/stylesheets/compass.rb +5 -16
- data/lib/padrino-gen/generators/components/tests/bacon.rb +2 -0
- data/lib/padrino-gen/generators/components/tests/minitest.rb +2 -0
- data/lib/padrino-gen/generators/components/tests/riot.rb +2 -0
- data/lib/padrino-gen/generators/components/tests/rspec.rb +5 -1
- data/lib/padrino-gen/generators/components/tests/shoulda.rb +3 -0
- data/lib/padrino-gen/generators/components/tests/steak.rb +2 -0
- data/lib/padrino-gen/generators/components/tests/testunit.rb +112 -0
- data/lib/padrino-gen/generators/controller.rb +1 -0
- data/lib/padrino-gen/generators/helper.rb +1 -0
- data/lib/padrino-gen/generators/mailer.rb +1 -0
- data/lib/padrino-gen/generators/migration.rb +1 -0
- data/lib/padrino-gen/generators/plugin.rb +1 -1
- data/lib/padrino-gen/generators/project/config/boot.rb +16 -2
- data/lib/padrino-gen/generators/project.rb +2 -1
- data/lib/padrino-gen/generators/runner.rb +1 -0
- data/lib/padrino-gen/generators/task.rb +1 -0
- data/lib/padrino-gen/generators/templates/Gemfile.tt +13 -0
- data/lib/padrino-gen/generators/templates/Rakefile.tt +2 -0
- data/lib/padrino-gen/generators/templates/controller.rb.tt +1 -1
- data/lib/padrino-gen/generators/templates/project_bin.tt +0 -1
- data/lib/padrino-gen/padrino-tasks/activerecord.rb +38 -33
- data/lib/padrino-gen/padrino-tasks/datamapper.rb +4 -2
- data/lib/padrino-gen/padrino-tasks/mongoid.rb +42 -0
- data/lib/padrino-gen/padrino-tasks/sequel.rb +13 -4
- data/test/helper.rb +3 -60
- data/test/test_app_generator.rb +15 -15
- data/test/test_controller_generator.rb +19 -6
- data/test/test_helper_generator.rb +13 -0
- data/test/test_mailer_generator.rb +5 -0
- data/test/test_migration_generator.rb +5 -0
- data/test/test_model_generator.rb +30 -24
- data/test/test_project_generator.rb +31 -17
- data/test/test_task_generator.rb +5 -0
- metadata +18 -17
@@ -1,5 +1,8 @@
|
|
1
1
|
source 'https://rubygems.org'
|
2
2
|
|
3
|
+
# Padrino supports Ruby version 1.9 and later
|
4
|
+
# ruby '<%= RUBY_VERSION.to_s %>'
|
5
|
+
|
3
6
|
# Distribute your app as a gem
|
4
7
|
<% unless options.gem? %># <% end %>gemspec
|
5
8
|
|
@@ -17,6 +20,15 @@ gem 'rake'
|
|
17
20
|
|
18
21
|
# Test requirements
|
19
22
|
|
23
|
+
<% if options.api? -%>
|
24
|
+
<% if options.dev? -%>
|
25
|
+
gem 'padrino-core', :path => '<%= Padrino::Generators::DEV_PATH %>/padrino-core'
|
26
|
+
gem 'padrino-gen', :path => '<%= Padrino::Generators::DEV_PATH %>/padrino-gen'
|
27
|
+
<% else -%>
|
28
|
+
gem 'padrino-core', '<%= Padrino.version %>'
|
29
|
+
gem 'padrino-gen', '<%= Padrino.version %>'
|
30
|
+
<% end -%>
|
31
|
+
<% else -%>
|
20
32
|
# Padrino Stable Gem
|
21
33
|
<% if options.dev? %># <% end %>gem 'padrino', '<%= Padrino.version %>'
|
22
34
|
|
@@ -27,3 +39,4 @@ gem 'rake'
|
|
27
39
|
<% unless options.dev? %># <% end %>%w(core support gen helpers cache mailer admin).each do |g|
|
28
40
|
<% unless options.dev? %># <% end %> gem 'padrino-' + g, <% if options.dev? %>:path => '<%= Padrino::Generators::DEV_PATH %>/padrino-' + g<% else %>'<%= Padrino.version %>'<% end %>
|
29
41
|
<% unless options.dev? %># <% end %>end
|
42
|
+
<% end -%>
|
@@ -11,7 +11,7 @@ if PadrinoTasks.load?(:activerecord, defined?(ActiveRecord))
|
|
11
11
|
namespace :ar do
|
12
12
|
namespace :create do
|
13
13
|
desc 'Create all the local databases defined in config/database.yml'
|
14
|
-
task :all => :
|
14
|
+
task :all => :skeleton do
|
15
15
|
ActiveRecord::Base.configurations.each_value do |config|
|
16
16
|
# Skip entries that don't have a database key, such as the first entry here:
|
17
17
|
#
|
@@ -32,8 +32,8 @@ if PadrinoTasks.load?(:activerecord, defined?(ActiveRecord))
|
|
32
32
|
end
|
33
33
|
|
34
34
|
desc 'Create the database defined in config/database.yml for the current Padrino.env'
|
35
|
-
task :create => :
|
36
|
-
create_database(ActiveRecord::Base.configurations[Padrino.env])
|
35
|
+
task :create => :skeleton do
|
36
|
+
create_database(ActiveRecord::Base.configurations.with_indifferent_access[Padrino.env])
|
37
37
|
end
|
38
38
|
|
39
39
|
def create_database(config)
|
@@ -44,7 +44,7 @@ if PadrinoTasks.load?(:activerecord, defined?(ActiveRecord))
|
|
44
44
|
else
|
45
45
|
begin
|
46
46
|
# Create the SQLite database
|
47
|
-
|
47
|
+
FileUtils.mkdir_p File.dirname(config[:database]) unless File.exist?(File.dirname(config[:database]))
|
48
48
|
ActiveRecord::Base.establish_connection(config)
|
49
49
|
ActiveRecord::Base.connection
|
50
50
|
rescue StandardError => e
|
@@ -89,7 +89,7 @@ if PadrinoTasks.load?(:activerecord, defined?(ActiveRecord))
|
|
89
89
|
|
90
90
|
namespace :drop do
|
91
91
|
desc 'Drops all the local databases defined in config/database.yml'
|
92
|
-
task :all => :
|
92
|
+
task :all => :skeleton do
|
93
93
|
ActiveRecord::Base.configurations.each_value do |config|
|
94
94
|
# Skip entries that don't have a database key
|
95
95
|
next unless config[:database]
|
@@ -104,8 +104,8 @@ if PadrinoTasks.load?(:activerecord, defined?(ActiveRecord))
|
|
104
104
|
end
|
105
105
|
|
106
106
|
desc 'Drops the database for the current Padrino.env'
|
107
|
-
task :drop => :
|
108
|
-
config = ActiveRecord::Base.configurations[Padrino.env || :development]
|
107
|
+
task :drop => :skeleton do
|
108
|
+
config = ActiveRecord::Base.configurations.with_indifferent_access[Padrino.env || :development]
|
109
109
|
begin
|
110
110
|
drop_database(config)
|
111
111
|
rescue StandardError => e
|
@@ -121,17 +121,17 @@ if PadrinoTasks.load?(:activerecord, defined?(ActiveRecord))
|
|
121
121
|
end
|
122
122
|
end
|
123
123
|
|
124
|
-
desc "Migrate the database through scripts in db/migrate and update db/schema.rb by invoking ar:schema:dump. Target specific version with
|
125
|
-
task :migrate => :
|
124
|
+
desc "Migrate the database through scripts in db/migrate and update db/schema.rb by invoking ar:schema:dump. Target specific version with MIGRATION_VERSION=x. Turn off output with VERBOSE=false."
|
125
|
+
task :migrate => :skeleton do
|
126
126
|
ActiveRecord::Migration.verbose = ENV["VERBOSE"] ? ENV["VERBOSE"] == "true" : true
|
127
|
-
ActiveRecord::Migrator.migrate("db/migrate/",
|
127
|
+
ActiveRecord::Migrator.migrate("db/migrate/", env_migration_version)
|
128
128
|
Rake::Task["ar:schema:dump"].invoke if ActiveRecord::Base.schema_format == :ruby
|
129
129
|
end
|
130
130
|
|
131
131
|
namespace :migrate do
|
132
|
-
desc 'Rollbacks the database one migration and re migrate up. If you want to rollback more than one step, define STEP=x. Target specific version with
|
133
|
-
task :redo => :
|
134
|
-
if
|
132
|
+
desc 'Rollbacks the database one migration and re migrate up. If you want to rollback more than one step, define STEP=x. Target specific version with MIGRATION_VERSION=x.'
|
133
|
+
task :redo => :skeleton do
|
134
|
+
if env_migration_version
|
135
135
|
Rake::Task["ar:migrate:down"].invoke
|
136
136
|
Rake::Task["ar:migrate:up"].invoke
|
137
137
|
else
|
@@ -143,25 +143,25 @@ if PadrinoTasks.load?(:activerecord, defined?(ActiveRecord))
|
|
143
143
|
desc 'Resets your database using your migrations for the current environment'
|
144
144
|
task :reset => ["ar:drop", "ar:create", "ar:migrate"]
|
145
145
|
|
146
|
-
desc 'Runs the "up" for a given
|
147
|
-
task(:up => :
|
146
|
+
desc 'Runs the "up" for a given MIGRATION_VERSION.'
|
147
|
+
task(:up => :skeleton){ migrate_as(:up) }
|
148
148
|
|
149
|
-
desc 'Runs the "down" for a given
|
150
|
-
task(:down => :
|
149
|
+
desc 'Runs the "down" for a given MIGRATION_VERSION.'
|
150
|
+
task(:down => :skeleton){ migrate_as(:down) }
|
151
151
|
end
|
152
152
|
|
153
153
|
desc 'Rolls the schema back to the previous version. Specify the number of steps with STEP=n'
|
154
|
-
task(:rollback => :
|
154
|
+
task(:rollback => :skeleton){ move_as(:rollback) }
|
155
155
|
|
156
156
|
desc 'Pushes the schema to the next version. Specify the number of steps with STEP=n'
|
157
|
-
task(:forward => :
|
157
|
+
task(:forward => :skeleton){ move_as(:forward) }
|
158
158
|
|
159
159
|
desc 'Drops and recreates the database from db/schema.rb for the current environment and loads the seeds.'
|
160
160
|
task :reset => [ 'ar:drop', 'ar:setup' ]
|
161
161
|
|
162
162
|
desc "Retrieves the charset for the current environment's database"
|
163
|
-
task :charset => :
|
164
|
-
config = ActiveRecord::Base.configurations[Padrino.env || :development]
|
163
|
+
task :charset => :skeleton do
|
164
|
+
config = ActiveRecord::Base.configurations.with_indifferent_access[Padrino.env || :development]
|
165
165
|
case config[:adapter]
|
166
166
|
when 'mysql', 'mysql2', 'em_mysql2', 'jdbcmysql'
|
167
167
|
ActiveRecord::Base.establish_connection(config)
|
@@ -175,8 +175,8 @@ if PadrinoTasks.load?(:activerecord, defined?(ActiveRecord))
|
|
175
175
|
end
|
176
176
|
|
177
177
|
desc "Retrieves the collation for the current environment's database"
|
178
|
-
task :collation => :
|
179
|
-
config = ActiveRecord::Base.configurations[Padrino.env || :development]
|
178
|
+
task :collation => :skeleton do
|
179
|
+
config = ActiveRecord::Base.configurations.with_indifferent_access[Padrino.env || :development]
|
180
180
|
case config[:adapter]
|
181
181
|
when 'mysql', 'mysql2', 'em_mysql2', 'jdbcmysql'
|
182
182
|
ActiveRecord::Base.establish_connection(config)
|
@@ -187,12 +187,12 @@ if PadrinoTasks.load?(:activerecord, defined?(ActiveRecord))
|
|
187
187
|
end
|
188
188
|
|
189
189
|
desc "Retrieves the current schema version number"
|
190
|
-
task :version => :
|
190
|
+
task :version => :skeleton do
|
191
191
|
puts "Current version: #{ActiveRecord::Migrator.current_version}"
|
192
192
|
end
|
193
193
|
|
194
194
|
desc "Raises an error if there are pending migrations"
|
195
|
-
task :abort_if_pending_migrations => :
|
195
|
+
task :abort_if_pending_migrations => :skeleton do
|
196
196
|
if defined? ActiveRecord
|
197
197
|
pending_migrations = ActiveRecord::Migrator.open(ActiveRecord::Migrator.migrations_paths).pending_migrations
|
198
198
|
|
@@ -211,7 +211,7 @@ if PadrinoTasks.load?(:activerecord, defined?(ActiveRecord))
|
|
211
211
|
|
212
212
|
namespace :schema do
|
213
213
|
desc "Create a db/schema.rb file that can be portably used against any DB supported by AR"
|
214
|
-
task :dump => :
|
214
|
+
task :dump => :skeleton do
|
215
215
|
require 'active_record/schema_dumper'
|
216
216
|
File.open(ENV['SCHEMA'] || Padrino.root("db", "schema.rb"), "w") do |file|
|
217
217
|
ActiveRecord::SchemaDumper.dump(ActiveRecord::Base.connection, file)
|
@@ -220,7 +220,7 @@ if PadrinoTasks.load?(:activerecord, defined?(ActiveRecord))
|
|
220
220
|
end
|
221
221
|
|
222
222
|
desc "Load a schema.rb file into the database"
|
223
|
-
task :load => :
|
223
|
+
task :load => :skeleton do
|
224
224
|
file = ENV['SCHEMA'] || Padrino.root("db", "schema.rb")
|
225
225
|
if File.exist?(file)
|
226
226
|
load(file)
|
@@ -232,9 +232,8 @@ if PadrinoTasks.load?(:activerecord, defined?(ActiveRecord))
|
|
232
232
|
|
233
233
|
namespace :structure do
|
234
234
|
desc "Dump the database structure to a SQL file"
|
235
|
-
task :dump => :
|
236
|
-
|
237
|
-
config = abcs[Padrino.env]
|
235
|
+
task :dump => :skeleton do
|
236
|
+
config = ActiveRecord::Base.configurations.with_indifferent_access[Padrino.env]
|
238
237
|
case config[:adapter]
|
239
238
|
when "mysql", "mysql2", 'em_mysql2', "oci", "oracle", 'jdbcmysql'
|
240
239
|
config = config.inject({}){|result, (key, value)| result[key.to_s] = value; result }
|
@@ -247,7 +246,7 @@ if PadrinoTasks.load?(:activerecord, defined?(ActiveRecord))
|
|
247
246
|
unless search_path.blank?
|
248
247
|
search_path = search_path.split(",").map{|search_path| "--schema=#{search_path.strip}" }.join(" ")
|
249
248
|
end
|
250
|
-
`pg_dump -
|
249
|
+
`pg_dump -U "#{config[:username]}" -s -x -O -f db/#{Padrino.env}_structure.sql #{search_path} #{config[:database]}`
|
251
250
|
raise "Error dumping database" if $?.exitstatus == 1
|
252
251
|
when "sqlite", "sqlite3"
|
253
252
|
dbfile = config[:database] || config[:dbfile]
|
@@ -310,6 +309,12 @@ if PadrinoTasks.load?(:activerecord, defined?(ActiveRecord))
|
|
310
309
|
puts
|
311
310
|
end
|
312
311
|
end
|
312
|
+
|
313
|
+
task :seed => :environment do
|
314
|
+
missing_model_features = Padrino.send(:default_dependency_paths) - Padrino.send(:dependency_paths)
|
315
|
+
Padrino.require_dependencies(missing_model_features)
|
316
|
+
Rake::Task['db:seed'].invoke
|
317
|
+
end
|
313
318
|
end
|
314
319
|
|
315
320
|
def drop_database(config)
|
@@ -350,8 +355,8 @@ if PadrinoTasks.load?(:activerecord, defined?(ActiveRecord))
|
|
350
355
|
end
|
351
356
|
|
352
357
|
def migrate_as(type)
|
353
|
-
version =
|
354
|
-
|
358
|
+
version = env_migration_version
|
359
|
+
fail "MIGRATION_VERSION is required" unless version
|
355
360
|
ActiveRecord::Migrator.run(type, "db/migrate/", version)
|
356
361
|
dump_schema
|
357
362
|
end
|
@@ -24,14 +24,14 @@ if PadrinoTasks.load?(:datamapper, defined?(DataMapper))
|
|
24
24
|
|
25
25
|
desc "Migrate up using migrations"
|
26
26
|
task :up, [:version] => :load do |t, args|
|
27
|
-
version = args[:version] ||
|
27
|
+
version = args[:version] || env_migration_version
|
28
28
|
migrate_up!(version)
|
29
29
|
puts "<= dm:migrate:up #{version} executed"
|
30
30
|
end
|
31
31
|
|
32
32
|
desc "Migrate down using migrations"
|
33
33
|
task :down, [:version] => :load do |t, args|
|
34
|
-
version = args[:version] ||
|
34
|
+
version = args[:version] || env_migration_version
|
35
35
|
migrate_down!(version)
|
36
36
|
puts "<= dm:migrate:down #{version} executed"
|
37
37
|
end
|
@@ -86,6 +86,8 @@ if PadrinoTasks.load?(:datamapper, defined?(DataMapper))
|
|
86
86
|
task :setup => [:create, :migrate, :seed]
|
87
87
|
end
|
88
88
|
|
89
|
+
task 'db:migrate:down' => 'dm:migrate:down'
|
90
|
+
task 'db:migrate:up' => 'dm:migrate:up'
|
89
91
|
task 'db:migrate' => 'dm:migrate'
|
90
92
|
task 'db:create' => 'dm:create'
|
91
93
|
task 'db:drop' => 'dm:drop'
|
@@ -167,6 +167,48 @@ if PadrinoTasks.load?(:mongoid, defined?(Mongoid))
|
|
167
167
|
mongoid_new_collection(collection, "#{collection.name}_old").drop
|
168
168
|
end
|
169
169
|
end
|
170
|
+
|
171
|
+
desc "Generates .yml files for I18n translations"
|
172
|
+
task :translate => :environment do
|
173
|
+
models = Dir["#{Padrino.root}/{app,}/models/**/*.rb"].map { |m| File.basename(m, ".rb") }
|
174
|
+
|
175
|
+
models.each do |m|
|
176
|
+
# Get the model class.
|
177
|
+
klass = m.camelize.constantize
|
178
|
+
|
179
|
+
# Avoid non Mongoid models.
|
180
|
+
next unless klass.ancestors.include?(Mongoid::Document)
|
181
|
+
|
182
|
+
# Init the processing.
|
183
|
+
print "Processing #{m.humanize}: "
|
184
|
+
FileUtils.mkdir_p("#{Padrino.root}/app/locale/models/#{m}")
|
185
|
+
langs = Array(I18n.locale)
|
186
|
+
|
187
|
+
# Create models for it and en locales.
|
188
|
+
langs.each do |lang|
|
189
|
+
filename = "#{Padrino.root}/app/locale/models/#{m}/#{lang}.yml"
|
190
|
+
columns = klass.fields.values.map(&:name).reject { |name| name =~ /id/i }
|
191
|
+
# If the lang file already exist we need to check it.
|
192
|
+
if File.exist?(filename)
|
193
|
+
locale = File.open(filename).read
|
194
|
+
columns.each do |c|
|
195
|
+
locale += "\n #{c}: #{c.humanize}" unless locale.include?("#{c}:")
|
196
|
+
end
|
197
|
+
print "Lang #{lang.to_s.upcase} already exist ... "; $stdout.flush
|
198
|
+
else
|
199
|
+
locale = "#{lang}:" + "\n" +
|
200
|
+
" models:" + "\n" +
|
201
|
+
" #{m}:" + "\n" +
|
202
|
+
" name: #{klass.name}" + "\n" +
|
203
|
+
" attributes:" + "\n" +
|
204
|
+
columns.map { |c| " #{c}: #{c.humanize}" }.join("\n")
|
205
|
+
print "created a new for #{lang.to_s.upcase} Lang ... "; $stdout.flush
|
206
|
+
end
|
207
|
+
File.open(filename, "w") { |f| f.puts locale }
|
208
|
+
end
|
209
|
+
puts
|
210
|
+
end
|
211
|
+
end
|
170
212
|
end
|
171
213
|
|
172
214
|
task 'db:drop' => 'mi:drop'
|
@@ -9,11 +9,11 @@ if PadrinoTasks.load?(:sequel, defined?(Sequel))
|
|
9
9
|
puts "<= sq:migrate:auto executed"
|
10
10
|
end
|
11
11
|
|
12
|
-
desc "Perform migration up/down to
|
12
|
+
desc "Perform migration up/down to MIGRATION_VERSION"
|
13
13
|
task :to, [:version] => :skeleton do |t, args|
|
14
|
-
version = (args[:version] ||
|
14
|
+
version = (args[:version] || env_migration_version).to_s.strip
|
15
15
|
::Sequel.extension :migration
|
16
|
-
|
16
|
+
fail "No MIGRATION_VERSION was provided" if version.empty?
|
17
17
|
::Sequel::Migrator.apply(Sequel::Model.db, "db/migrate", version.to_i)
|
18
18
|
puts "<= sq:migrate:to[#{version}] executed"
|
19
19
|
end
|
@@ -70,8 +70,17 @@ if PadrinoTasks.load?(:sequel, defined?(Sequel))
|
|
70
70
|
puts "<= sq:drop executed"
|
71
71
|
end
|
72
72
|
|
73
|
+
desc 'Drop the database, migrate from scratch and initialize with the seed data'
|
74
|
+
task :reset => ['drop', 'create', 'migrate', 'seed']
|
75
|
+
|
76
|
+
task :seed => :environment do
|
77
|
+
missing_model_features = Padrino.send(:default_dependency_paths) - Padrino.send(:dependency_paths)
|
78
|
+
Padrino.require_dependencies(missing_model_features)
|
79
|
+
Rake::Task['db:seed'].invoke
|
80
|
+
end
|
73
81
|
end
|
74
82
|
|
83
|
+
task 'db:create' => 'sq:create'
|
75
84
|
task 'db:migrate' => 'sq:migrate'
|
76
|
-
task 'db:reset' =>
|
85
|
+
task 'db:reset' => 'sq:reset'
|
77
86
|
end
|
data/test/helper.rb
CHANGED
@@ -1,10 +1,7 @@
|
|
1
|
-
require File.expand_path('../../../load_paths', __FILE__)
|
2
1
|
require 'minitest/autorun'
|
3
2
|
require 'minitest/pride'
|
4
3
|
require 'mocha/setup'
|
5
4
|
require 'rack/test'
|
6
|
-
require 'rack'
|
7
|
-
require 'webrat'
|
8
5
|
require 'fakeweb'
|
9
6
|
require 'thor/group'
|
10
7
|
require 'padrino-gen'
|
@@ -12,6 +9,8 @@ require 'padrino-core'
|
|
12
9
|
require 'padrino-mailer'
|
13
10
|
require 'padrino-helpers'
|
14
11
|
|
12
|
+
require 'ext/minitest-spec'
|
13
|
+
|
15
14
|
Padrino::Generators.load_components!
|
16
15
|
|
17
16
|
# register fake URL to avoid downloading static files every time tests run
|
@@ -28,14 +27,6 @@ fake_uri_base = "https://raw.github.com/padrino/padrino-static/master/"
|
|
28
27
|
end
|
29
28
|
|
30
29
|
class MiniTest::Spec
|
31
|
-
include Rack::Test::Methods
|
32
|
-
include Webrat::Methods
|
33
|
-
include Webrat::Matchers
|
34
|
-
|
35
|
-
Webrat.configure do |config|
|
36
|
-
config.mode = :rack
|
37
|
-
end
|
38
|
-
|
39
30
|
def stop_time_for_test
|
40
31
|
time = Time.now
|
41
32
|
Time.stubs(:now).returns(time)
|
@@ -67,46 +58,6 @@ class MiniTest::Spec
|
|
67
58
|
(Object.constants - constants).each{|constant| Object.instance_eval{ remove_const(constant) }}
|
68
59
|
end
|
69
60
|
|
70
|
-
# assert_has_tag(:h1, :content => "yellow") { "<h1>yellow</h1>" }
|
71
|
-
# In this case, block is the html to evaluate
|
72
|
-
def assert_has_tag(name, attributes = {})
|
73
|
-
html = yield if block_given?
|
74
|
-
matcher = HaveSelector.new(name, attributes)
|
75
|
-
raise "Please specify a block!" if html.blank?
|
76
|
-
assert matcher.matches?(html), matcher.failure_message
|
77
|
-
end
|
78
|
-
|
79
|
-
# assert_has_no_tag, tag(:h1, :content => "yellow") { "<h1>green</h1>" }
|
80
|
-
# In this case, block is the html to evaluate
|
81
|
-
def assert_has_no_tag(name, attributes = {})
|
82
|
-
html = yield if block_given?
|
83
|
-
attributes.merge!(:count => 0)
|
84
|
-
matcher = HaveSelector.new(name, attributes)
|
85
|
-
raise "Please specify a block!" if html.blank?
|
86
|
-
assert matcher.matches?(html), matcher.failure_message
|
87
|
-
end
|
88
|
-
|
89
|
-
# assert_file_exists('/tmp/app')
|
90
|
-
def assert_file_exists(file_path)
|
91
|
-
assert File.exist?(file_path), "File at path '#{file_path}' does not exist!"
|
92
|
-
end
|
93
|
-
alias :assert_dir_exists :assert_file_exists
|
94
|
-
|
95
|
-
# assert_no_file_exists('/tmp/app')
|
96
|
-
def assert_no_file_exists(file_path)
|
97
|
-
assert !File.exist?(file_path), "File should not exist at path '#{file_path}' but was found!"
|
98
|
-
end
|
99
|
-
alias :assert_no_dir_exists :assert_no_file_exists
|
100
|
-
|
101
|
-
# Asserts that a file matches the pattern
|
102
|
-
def assert_match_in_file(pattern, file)
|
103
|
-
File.exist?(file) ? assert_match(pattern, File.read(file)) : assert_file_exists(file)
|
104
|
-
end
|
105
|
-
|
106
|
-
def assert_no_match_in_file(pattern, file)
|
107
|
-
File.exist?(file) ? refute_match(pattern, File.read(file)) : assert_file_exists(file)
|
108
|
-
end
|
109
|
-
|
110
61
|
# expects_generated :model, "post title:string body:text"
|
111
62
|
def expects_generated(generator, params="")
|
112
63
|
Padrino.expects(:bin_gen).with(generator, *params.split(' ')).returns(true)
|
@@ -133,7 +84,7 @@ class MiniTest::Spec
|
|
133
84
|
# expects_initializer :test, "# Example"
|
134
85
|
def expects_initializer(name, body,options={})
|
135
86
|
#options.reverse_merge!(:root => "/tmp/sample_project")
|
136
|
-
path = File.join(options[:root],'
|
87
|
+
path = File.join(options[:root],'config/initializers',"#{name}.rb")
|
137
88
|
instance = mock
|
138
89
|
instance.expects(:invoke!).at_least_once
|
139
90
|
include_text = " register #{name.to_s.camelize}Initializer\n"
|
@@ -147,11 +98,3 @@ class MiniTest::Spec
|
|
147
98
|
Padrino.expects(:bin).with("rake", command, "-c=#{options[:root]}").returns(true)
|
148
99
|
end
|
149
100
|
end
|
150
|
-
|
151
|
-
module Webrat
|
152
|
-
module Logging
|
153
|
-
def logger # # @private
|
154
|
-
@logger = nil
|
155
|
-
end
|
156
|
-
end
|
157
|
-
end
|
data/test/test_app_generator.rb
CHANGED
@@ -20,13 +20,13 @@ describe "AppGenerator" do
|
|
20
20
|
it 'should create correctly a new padrino application' do
|
21
21
|
capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}") }
|
22
22
|
capture_io { generate(:app, 'demo', "--root=#{@apptmp}/sample_project") }
|
23
|
-
|
24
|
-
|
23
|
+
assert_dir_exists("#{@apptmp}/sample_project")
|
24
|
+
assert_dir_exists("#{@apptmp}/sample_project/demo")
|
25
25
|
assert_file_exists("#{@apptmp}/sample_project/demo/app.rb")
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
26
|
+
assert_dir_exists("#{@apptmp}/sample_project/demo/controllers")
|
27
|
+
assert_dir_exists("#{@apptmp}/sample_project/demo/helpers")
|
28
|
+
assert_dir_exists("#{@apptmp}/sample_project/demo/views")
|
29
|
+
assert_dir_exists("#{@apptmp}/sample_project/demo/views/layouts")
|
30
30
|
assert_dir_exists("#{@apptmp}/sample_project/public/demo")
|
31
31
|
assert_match_in_file("Padrino.mount('SampleProject::Demo', :app_file => Padrino.root('demo/app.rb')).to('/demo')", "#{@apptmp}/sample_project/config/apps.rb")
|
32
32
|
assert_match_in_file('module SampleProject', "#{@apptmp}/sample_project/demo/app.rb")
|
@@ -38,13 +38,13 @@ describe "AppGenerator" do
|
|
38
38
|
it 'should create correctly a new padrino application with an underscore name' do
|
39
39
|
capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}") }
|
40
40
|
capture_io { generate(:app, 'demo_app', "--root=#{@apptmp}/sample_project") }
|
41
|
-
|
42
|
-
|
41
|
+
assert_dir_exists("#{@apptmp}/sample_project")
|
42
|
+
assert_dir_exists("#{@apptmp}/sample_project/demo_app")
|
43
43
|
assert_file_exists("#{@apptmp}/sample_project/demo_app/app.rb")
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
44
|
+
assert_dir_exists("#{@apptmp}/sample_project/demo_app/controllers")
|
45
|
+
assert_dir_exists("#{@apptmp}/sample_project/demo_app/helpers")
|
46
|
+
assert_dir_exists("#{@apptmp}/sample_project/demo_app/views")
|
47
|
+
assert_dir_exists("#{@apptmp}/sample_project/demo_app/views/layouts")
|
48
48
|
assert_dir_exists("#{@apptmp}/sample_project/public/demo_app")
|
49
49
|
assert_match_in_file("Padrino.mount('SampleProject::DemoApp', :app_file => Padrino.root('demo_app/app.rb')).to('/demo_app')", "#{@apptmp}/sample_project/config/apps.rb")
|
50
50
|
assert_match_in_file('module SampleProject', "#{@apptmp}/sample_project/demo_app/app.rb")
|
@@ -56,8 +56,8 @@ describe "AppGenerator" do
|
|
56
56
|
it 'should generate tiny app skeleton' do
|
57
57
|
capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}") }
|
58
58
|
capture_io { generate(:app, 'demo','--tiny',"--root=#{@apptmp}/sample_project") }
|
59
|
-
|
60
|
-
|
59
|
+
assert_dir_exists("#{@apptmp}/sample_project")
|
60
|
+
assert_dir_exists("#{@apptmp}/sample_project/demo")
|
61
61
|
assert_file_exists("#{@apptmp}/sample_project/demo/helpers.rb")
|
62
62
|
assert_file_exists("#{@apptmp}/sample_project/demo/controllers.rb")
|
63
63
|
assert_file_exists("#{@apptmp}/sample_project/demo/mailers.rb")
|
@@ -75,7 +75,7 @@ describe "AppGenerator" do
|
|
75
75
|
capture_io { generate(:controller, 'demo_items', "-r=#{@apptmp}/sample_project", '-a=demo') }
|
76
76
|
assert_match_in_file(/SampleProject::Demo.controllers :demo_items do/m, "#{@apptmp}/sample_project/demo/controllers/demo_items.rb")
|
77
77
|
assert_match_in_file(/helpers DemoItemsHelper/m, "#{@apptmp}/sample_project/demo/helpers/demo_items_helper.rb")
|
78
|
-
|
78
|
+
assert_dir_exists("#{@apptmp}/sample_project/demo/views/demo_items")
|
79
79
|
end
|
80
80
|
|
81
81
|
it 'should correctly create a new mailer inside a padrino application' do
|
@@ -22,12 +22,17 @@ describe "ControllerGenerator" do
|
|
22
22
|
assert_no_file_exists("#{@apptmp}/app/controllers/demo.rb")
|
23
23
|
end
|
24
24
|
|
25
|
+
it 'should fail with NameError if given invalid namespace names' do
|
26
|
+
capture_io { generate(:project, "sample", "--root=#{@apptmp}") }
|
27
|
+
assert_raises(::NameError) { capture_io { generate(:controller, "wrong/name", "--root=#{@apptmp}/sample") } }
|
28
|
+
end
|
29
|
+
|
25
30
|
it 'should generate controller within existing project' do
|
26
31
|
capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=bacon') }
|
27
32
|
capture_io { generate(:controller, 'DemoItems', "-r=#{@apptmp}/sample_project") }
|
28
33
|
assert_match_in_file(/SampleProject::App.controllers :demo_items do/m, @controller_path)
|
29
34
|
assert_match_in_file(/helpers DemoItemsHelper/, @helper_path)
|
30
|
-
|
35
|
+
assert_dir_exists("#{@apptmp}/sample_project/app/views/demo_items")
|
31
36
|
assert_file_exists(@controller_test_path)
|
32
37
|
end
|
33
38
|
|
@@ -47,7 +52,7 @@ describe "ControllerGenerator" do
|
|
47
52
|
capture_io { generate(:controller, 'DemoItems', "-r=#{@apptmp}/warepedia") }
|
48
53
|
assert_match_in_file(/Warepedia::App.controllers :demo_items do/m, "#{@apptmp}/warepedia/app/controllers/demo_items.rb")
|
49
54
|
assert_match_in_file(/helpers DemoItemsHelper/, "#{@apptmp}/warepedia/app/helpers/demo_items_helper.rb")
|
50
|
-
|
55
|
+
assert_dir_exists("#{@apptmp}/warepedia/app/views/demo_items")
|
51
56
|
end
|
52
57
|
|
53
58
|
it 'should generate controller in specified app' do
|
@@ -56,7 +61,7 @@ describe "ControllerGenerator" do
|
|
56
61
|
capture_io { generate(:controller, 'DemoItems','-a=/subby', "-r=#{@apptmp}/sample_project") }
|
57
62
|
assert_match_in_file(/SampleProject::Subby.controllers :demo_items do/m, @controller_path.gsub('app','subby'))
|
58
63
|
assert_match_in_file(/helpers DemoItemsHelper/m, "#{@apptmp}/sample_project/subby/helpers/demo_items_helper.rb")
|
59
|
-
|
64
|
+
assert_dir_exists("#{@apptmp}/sample_project/subby/views/demo_items")
|
60
65
|
assert_match_in_file(/describe "\/demo_items" do/m, @controller_test_path.gsub('app','subby'))
|
61
66
|
assert_match_in_file(/get "\/demo_items"/m, @controller_test_path.gsub('app','subby'))
|
62
67
|
end
|
@@ -104,7 +109,7 @@ describe "ControllerGenerator" do
|
|
104
109
|
capture_io { generate(:controller, 'DemoItems', "-r=#{@apptmp}/sample_project") }
|
105
110
|
assert_match_in_file(/SampleProject::App.controllers :demo_items do/m, @controller_path)
|
106
111
|
assert_match_in_file(/helpers DemoItemsHelper/m, "#{@apptmp}/sample_project/app/helpers/demo_items_helper.rb")
|
107
|
-
|
112
|
+
assert_dir_exists("#{@apptmp}/sample_project/app/views/demo_items")
|
108
113
|
assert_no_file_exists("#{@apptmp}/sample_project/test")
|
109
114
|
end
|
110
115
|
|
@@ -200,10 +205,18 @@ describe "ControllerGenerator" do
|
|
200
205
|
assert_match_in_file(/Capybara.app = /, "#{@apptmp}/sample_project/features/support/env.rb")
|
201
206
|
end
|
202
207
|
|
208
|
+
it "should generate controller test for testunit" do
|
209
|
+
capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=testunit') }
|
210
|
+
capture_io { generate(:app, 'subby', "-r=#{@apptmp}/sample_project") }
|
211
|
+
capture_io { generate(:controller, 'DemoItems','-a=/subby', "-r=#{@apptmp}/sample_project") }
|
212
|
+
assert_match_in_file(/class DemoItemsControllerTest < Test::Unit::TestCase/m, "#{@apptmp}/sample_project/test/subby/controllers/demo_items_controller_test.rb")
|
213
|
+
end
|
214
|
+
|
215
|
+
|
203
216
|
it 'should correctly generate file names' do
|
204
217
|
capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=rspec') }
|
205
218
|
capture_io { generate(:controller, 'DemoItems', "-r=#{@apptmp}/sample_project") }
|
206
|
-
|
219
|
+
assert_dir_exists("#{@apptmp}/sample_project/app/views/demo_items")
|
207
220
|
assert_file_exists("#{@apptmp}/sample_project/app/controllers/demo_items.rb")
|
208
221
|
assert_file_exists("#{@apptmp}/sample_project/app/helpers/demo_items_helper.rb")
|
209
222
|
assert_file_exists("#{@apptmp}/sample_project/spec/app/controllers/demo_items_controller_spec.rb")
|
@@ -222,7 +235,7 @@ describe "ControllerGenerator" do
|
|
222
235
|
it 'should not generate helper within existing project' do
|
223
236
|
capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=rspec') }
|
224
237
|
capture_io { generate(:controller, 'DemoItems', "-r=#{@apptmp}/sample_project", '--no-helper') }
|
225
|
-
|
238
|
+
assert_dir_exists("#{@apptmp}/sample_project/app/views/demo_items")
|
226
239
|
assert_file_exists("#{@apptmp}/sample_project/app/controllers/demo_items.rb")
|
227
240
|
assert_file_exists("#{@apptmp}/sample_project/spec/app/controllers/demo_items_controller_spec.rb")
|
228
241
|
assert_no_file_exists("#{@apptmp}/sample_project/app/helpers/demo_items_helper.rb")
|
@@ -19,6 +19,11 @@ describe "HelperGenerator" do
|
|
19
19
|
assert_no_file_exists("#{@apptmp}/app/helpers/demo_helper.rb")
|
20
20
|
end
|
21
21
|
|
22
|
+
it 'should fail with NameError if given invalid namespace names' do
|
23
|
+
capture_io { generate(:project, "sample", "--root=#{@apptmp}") }
|
24
|
+
assert_raises(::NameError) { capture_io { generate(:helper, "wrong/name", "--root=#{@apptmp}/sample") } }
|
25
|
+
end
|
26
|
+
|
22
27
|
it 'should generate helper within existing project' do
|
23
28
|
capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=bacon') }
|
24
29
|
capture_io { generate(:helper, 'DemoItems', "-r=#{@apptmp}/sample_project") }
|
@@ -95,6 +100,14 @@ describe "HelperGenerator" do
|
|
95
100
|
assert_match_in_file(/describe "SampleProject::Subby::DemoItemsHelper" do/m, "#{@apptmp}/sample_project/spec/subby/helpers/demo_items_helper_spec.rb")
|
96
101
|
end
|
97
102
|
|
103
|
+
it "should generate helper test for testunit" do
|
104
|
+
capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--test=testunit', '--script=none') }
|
105
|
+
capture_io { generate(:app, 'subby', "-r=#{@apptmp}/sample_project") }
|
106
|
+
capture_io { generate(:helper, 'DemoItems','-a=/subby', "-r=#{@apptmp}/sample_project") }
|
107
|
+
assert_match_in_file(/class DemoItemsHelperTest < Test::Unit::TestCase/m, "#{@apptmp}/sample_project/test/subby/helpers/demo_items_helper_test.rb")
|
108
|
+
assert_match_in_file(/@helpers\.extend SampleProject::Subby::DemoItemsHelper/m, "#{@apptmp}/sample_project/test/subby/helpers/demo_items_helper_test.rb")
|
109
|
+
end
|
110
|
+
|
98
111
|
it 'should correctly generate file names' do
|
99
112
|
capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=rspec') }
|
100
113
|
capture_io { generate(:helper, 'DemoItems', "-r=#{@apptmp}/sample_project") }
|
@@ -17,6 +17,11 @@ describe "MailerGenerator" do
|
|
17
17
|
assert_no_file_exists('/tmp/app/mailers/demo_mailer.rb')
|
18
18
|
end
|
19
19
|
|
20
|
+
it 'should fail with NameError if given invalid namespace names' do
|
21
|
+
capture_io { generate(:project, "sample", "--root=#{@apptmp}") }
|
22
|
+
assert_raises(::NameError) { capture_io { generate(:mailer, "wrong/name", "--root=#{@apptmp}/sample") } }
|
23
|
+
end
|
24
|
+
|
20
25
|
it 'should generate mailer in specified app' do
|
21
26
|
capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=bacon') }
|
22
27
|
capture_io { generate(:app, 'subby', "-r=#{@apptmp}/sample_project") }
|
@@ -17,6 +17,11 @@ describe "MigrationGenerator" do
|
|
17
17
|
assert_no_file_exists("#{@apptmp}/db/migrate")
|
18
18
|
end
|
19
19
|
|
20
|
+
it 'should fail with NameError if given invalid namespace names' do
|
21
|
+
capture_io { generate(:project, "sample", "--root=#{@apptmp}") }
|
22
|
+
assert_raises(::NameError) { capture_io { generate(:migration, "wrong/name", "--root=#{@apptmp}/sample") } }
|
23
|
+
end
|
24
|
+
|
20
25
|
it 'should fail if we do not use an adapter' do
|
21
26
|
capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=bacon') }
|
22
27
|
assert_raises(SystemExit) { capture_io { generate(:migration, 'AddEmailToUsers', "-r=#{@apptmp}/sample_project") } }
|