railties 4.1.0 → 4.2.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +229 -197
- data/RDOC_MAIN.rdoc +1 -1
- data/README.rdoc +6 -2
- data/lib/rails/all.rb +1 -0
- data/lib/rails/api/task.rb +7 -0
- data/lib/rails/app_rails_loader.rb +5 -3
- data/lib/rails/application/bootstrap.rb +15 -1
- data/lib/rails/application/configuration.rb +65 -8
- data/lib/rails/application/default_middleware_stack.rb +6 -2
- data/lib/rails/application/finisher.rb +0 -2
- data/lib/rails/application.rb +119 -24
- data/lib/rails/backtrace_cleaner.rb +9 -4
- data/lib/rails/code_statistics.rb +3 -4
- data/lib/rails/commands/commands_tasks.rb +2 -7
- data/lib/rails/commands/console.rb +24 -12
- data/lib/rails/commands/dbconsole.rb +20 -5
- data/lib/rails/commands/destroy.rb +2 -0
- data/lib/rails/commands/generate.rb +2 -0
- data/lib/rails/commands/plugin.rb +1 -1
- data/lib/rails/commands/server.rb +32 -21
- data/lib/rails/configuration.rb +2 -2
- data/lib/rails/engine/configuration.rb +1 -1
- data/lib/rails/engine.rb +15 -12
- data/lib/rails/gem_version.rb +2 -2
- data/lib/rails/generators/actions/create_migration.rb +4 -3
- data/lib/rails/generators/actions.rb +33 -12
- data/lib/rails/generators/app_base.rb +63 -55
- data/lib/rails/generators/base.rb +2 -2
- data/lib/rails/generators/erb/mailer/mailer_generator.rb +25 -2
- data/lib/rails/generators/erb/mailer/templates/layout.html.erb +5 -0
- data/lib/rails/generators/erb/mailer/templates/layout.text.erb +1 -0
- data/lib/rails/generators/erb/scaffold/templates/_form.html.erb +1 -6
- data/lib/rails/generators/erb/scaffold/templates/edit.html.erb +1 -1
- data/lib/rails/generators/erb/scaffold/templates/index.html.erb +3 -1
- data/lib/rails/generators/erb/scaffold/templates/new.html.erb +1 -1
- data/lib/rails/generators/generated_attribute.rb +28 -4
- data/lib/rails/generators/model_helpers.rb +28 -0
- data/lib/rails/generators/named_base.rb +10 -1
- data/lib/rails/generators/rails/app/app_generator.rb +34 -2
- data/lib/rails/generators/rails/app/templates/Gemfile +22 -7
- data/lib/rails/generators/rails/app/templates/app/assets/javascripts/application.js.tt +2 -2
- data/lib/rails/generators/rails/app/templates/app/assets/stylesheets/application.css +1 -1
- data/lib/rails/generators/rails/app/templates/bin/rails +1 -1
- data/lib/rails/generators/rails/app/templates/bin/setup +28 -0
- data/lib/rails/generators/rails/app/templates/config/application.rb +8 -1
- data/lib/rails/generators/rails/app/templates/config/boot.rb +1 -2
- data/lib/rails/generators/rails/app/templates/config/databases/ibm_db.yml +1 -3
- data/lib/rails/generators/rails/app/templates/config/databases/oracle.yml +1 -1
- data/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt +4 -0
- data/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt +14 -20
- data/lib/rails/generators/rails/app/templates/config/environments/test.rb.tt +5 -2
- data/lib/rails/generators/rails/app/templates/config/initializers/assets.rb.tt +11 -0
- data/lib/rails/generators/rails/app/templates/config/initializers/cookies_serializer.rb +1 -1
- data/lib/rails/generators/rails/app/templates/config/initializers/to_time_preserves_timezone.rb +10 -0
- data/lib/rails/generators/rails/app/templates/config.ru +1 -1
- data/lib/rails/generators/rails/app/templates/gitignore +4 -1
- data/lib/rails/generators/rails/app/templates/test/test_helper.rb +0 -3
- data/lib/rails/generators/rails/controller/USAGE +0 -1
- data/lib/rails/generators/rails/controller/controller_generator.rb +8 -4
- data/lib/rails/generators/rails/helper/USAGE +0 -4
- data/lib/rails/generators/rails/model/USAGE +12 -3
- data/lib/rails/generators/rails/model/model_generator.rb +4 -0
- data/lib/rails/generators/rails/plugin/plugin_generator.rb +23 -1
- data/lib/rails/generators/rails/plugin/templates/%name%.gemspec +3 -3
- data/lib/rails/generators/rails/plugin/templates/Gemfile +14 -6
- data/lib/rails/generators/rails/plugin/templates/MIT-LICENSE +1 -1
- data/lib/rails/generators/rails/plugin/templates/Rakefile +4 -0
- data/lib/rails/generators/rails/plugin/templates/app/controllers/%name%/application_controller.rb.tt +1 -0
- data/lib/rails/generators/rails/plugin/templates/rails/application.rb +1 -1
- data/lib/rails/generators/rails/plugin/templates/rails/javascripts.js +2 -2
- data/lib/rails/generators/rails/plugin/templates/rails/stylesheets.css +1 -1
- data/lib/rails/generators/rails/plugin/templates/test/integration/navigation_test.rb +0 -4
- data/lib/rails/generators/rails/plugin/templates/test/test_helper.rb +13 -3
- data/lib/rails/generators/rails/resource_route/resource_route_generator.rb +4 -2
- data/lib/rails/generators/rails/scaffold/USAGE +7 -1
- data/lib/rails/generators/rails/scaffold_controller/scaffold_controller_generator.rb +1 -0
- data/lib/rails/generators/rails/scaffold_controller/templates/controller.rb +1 -1
- data/lib/rails/generators/resource_helpers.rb +2 -11
- data/lib/rails/generators/test_unit/controller/templates/functional_test.rb +6 -0
- data/lib/rails/generators/test_unit/helper/helper_generator.rb +1 -5
- data/lib/rails/generators/test_unit/job/job_generator.rb +13 -0
- data/lib/rails/generators/test_unit/job/templates/unit_test.rb.erb +9 -0
- data/lib/rails/generators/test_unit/scaffold/scaffold_generator.rb +9 -0
- data/lib/rails/generators/test_unit/scaffold/templates/functional_test.rb +4 -1
- data/lib/rails/generators/testing/assertions.rb +3 -1
- data/lib/rails/generators/testing/behaviour.rb +18 -1
- data/lib/rails/generators.rb +66 -15
- data/lib/rails/info.rb +8 -24
- data/lib/rails/info_controller.rb +1 -1
- data/lib/rails/mailers_controller.rb +20 -14
- data/lib/rails/paths.rb +3 -3
- data/lib/rails/rack/log_tailer.rb +4 -0
- data/lib/rails/rack/logger.rb +1 -1
- data/lib/rails/rack.rb +1 -1
- data/lib/rails/railtie.rb +3 -3
- data/lib/rails/ruby_version_check.rb +1 -1
- data/lib/rails/source_annotation_extractor.rb +25 -19
- data/lib/rails/tasks/framework.rake +2 -2
- data/lib/rails/tasks/statistics.rake +9 -2
- data/lib/rails/tasks.rb +3 -2
- data/lib/rails/templates/rails/mailers/email.html.erb +22 -4
- data/lib/rails/templates/rails/mailers/index.html.erb +2 -2
- data/lib/rails/templates/rails/mailers/mailer.html.erb +1 -1
- data/lib/rails/templates/rails/welcome/index.html.erb +23 -7
- data/lib/rails/test_help.rb +1 -0
- data/lib/rails/test_unit/sub_test_task.rb +2 -2
- data/lib/rails/test_unit/testing.rake +23 -5
- data/lib/rails.rb +7 -1
- metadata +17 -12
- data/lib/rails/commands/update.rb +0 -9
- data/lib/rails/generators/test_unit/helper/templates/helper_test.rb +0 -6
- data/lib/rails/rubyprof_ext.rb +0 -35
@@ -6,6 +6,11 @@ Description:
|
|
6
6
|
model's attributes. Timestamps are added by default, so you don't have to
|
7
7
|
specify them by hand as 'created_at:datetime updated_at:datetime'.
|
8
8
|
|
9
|
+
As a special case, specifying 'password:digest' will generate a
|
10
|
+
password_digest field of string type, and configure your generated model and
|
11
|
+
tests for use with ActiveModel has_secure_password (assuming the default ORM
|
12
|
+
and test framework are being used).
|
13
|
+
|
9
14
|
You don't have to think up every attribute up front, but it helps to
|
10
15
|
sketch out a few so you can start working with the model immediately.
|
11
16
|
|
@@ -17,7 +22,7 @@ Description:
|
|
17
22
|
|
18
23
|
If you pass a namespaced model name (e.g. admin/account or Admin::Account)
|
19
24
|
then the generator will create a module with a table_name_prefix method
|
20
|
-
to prefix the model's table name with the module name (e.g.
|
25
|
+
to prefix the model's table name with the module name (e.g. admin_accounts)
|
21
26
|
|
22
27
|
Available field types:
|
23
28
|
|
@@ -27,7 +32,8 @@ Available field types:
|
|
27
32
|
`rails generate model post title:string body:text`
|
28
33
|
|
29
34
|
will generate a title column with a varchar type and a body column with a text
|
30
|
-
type.
|
35
|
+
type. If no type is specified the string type will be used by default.
|
36
|
+
You can use the following types:
|
31
37
|
|
32
38
|
integer
|
33
39
|
primary_key
|
@@ -40,7 +46,6 @@ Available field types:
|
|
40
46
|
date
|
41
47
|
time
|
42
48
|
datetime
|
43
|
-
timestamp
|
44
49
|
|
45
50
|
You can also consider `references` as a kind of type. For instance, if you run:
|
46
51
|
|
@@ -73,6 +78,10 @@ Available field types:
|
|
73
78
|
`rails generate model user username:string{30}:uniq`
|
74
79
|
`rails generate model product supplier:references{polymorphic}:index`
|
75
80
|
|
81
|
+
If you require a `password_digest` string column for use with
|
82
|
+
has_secure_password, you should specify `password:digest`:
|
83
|
+
|
84
|
+
`rails generate model user password:digest`
|
76
85
|
|
77
86
|
Examples:
|
78
87
|
`rails generate model account`
|
@@ -1,6 +1,10 @@
|
|
1
|
+
require 'rails/generators/model_helpers'
|
2
|
+
|
1
3
|
module Rails
|
2
4
|
module Generators
|
3
5
|
class ModelGenerator < NamedBase # :nodoc:
|
6
|
+
include Rails::Generators::ModelHelpers
|
7
|
+
|
4
8
|
argument :attributes, type: :array, default: [], banner: "field[:type][:index] field[:type][:index]"
|
5
9
|
hook_for :orm, required: true
|
6
10
|
end
|
@@ -241,7 +241,7 @@ task default: :test
|
|
241
241
|
build(:leftovers)
|
242
242
|
end
|
243
243
|
|
244
|
-
public_task :apply_rails_template
|
244
|
+
public_task :apply_rails_template
|
245
245
|
|
246
246
|
def name
|
247
247
|
@name ||= begin
|
@@ -288,6 +288,10 @@ task default: :test
|
|
288
288
|
options[:mountable]
|
289
289
|
end
|
290
290
|
|
291
|
+
def skip_git?
|
292
|
+
options[:skip_git]
|
293
|
+
end
|
294
|
+
|
291
295
|
def with_dummy_app?
|
292
296
|
options[:skip_test_unit].blank? || options[:dummy_path] != 'test/dummy'
|
293
297
|
end
|
@@ -304,6 +308,24 @@ task default: :test
|
|
304
308
|
@camelized ||= name.gsub(/\W/, '_').squeeze('_').camelize
|
305
309
|
end
|
306
310
|
|
311
|
+
def author
|
312
|
+
default = "TODO: Write your name"
|
313
|
+
if skip_git?
|
314
|
+
@author = default
|
315
|
+
else
|
316
|
+
@author = `git config user.name`.chomp rescue default
|
317
|
+
end
|
318
|
+
end
|
319
|
+
|
320
|
+
def email
|
321
|
+
default = "TODO: Write your email address"
|
322
|
+
if skip_git?
|
323
|
+
@email = default
|
324
|
+
else
|
325
|
+
@email = `git config user.email`.chomp rescue default
|
326
|
+
end
|
327
|
+
end
|
328
|
+
|
307
329
|
def valid_const?
|
308
330
|
if original_name =~ /[^0-9a-zA-Z_]+/
|
309
331
|
raise Error, "Invalid plugin name #{original_name}. Please give a name which use only alphabetic or numeric or \"_\" characters."
|
@@ -7,8 +7,8 @@ require "<%= name %>/version"
|
|
7
7
|
Gem::Specification.new do |s|
|
8
8
|
s.name = "<%= name %>"
|
9
9
|
s.version = <%= camelized %>::VERSION
|
10
|
-
s.authors = ["
|
11
|
-
s.email = ["
|
10
|
+
s.authors = ["<%= author %>"]
|
11
|
+
s.email = ["<%= email %>"]
|
12
12
|
s.homepage = "TODO"
|
13
13
|
s.summary = "TODO: Summary of <%= camelized %>."
|
14
14
|
s.description = "TODO: Description of <%= camelized %>."
|
@@ -22,6 +22,6 @@ Gem::Specification.new do |s|
|
|
22
22
|
<%= '# ' if options.dev? || options.edge? -%>s.add_dependency "rails", "~> <%= Rails::VERSION::STRING %>"
|
23
23
|
<% unless options[:skip_active_record] -%>
|
24
24
|
|
25
|
-
s.add_development_dependency "<%= gem_for_database %>"
|
25
|
+
s.add_development_dependency "<%= gem_for_database[0] %>"
|
26
26
|
<% end -%>
|
27
27
|
end
|
@@ -1,7 +1,7 @@
|
|
1
|
-
source
|
1
|
+
source 'https://rubygems.org'
|
2
2
|
|
3
3
|
<% if options[:skip_gemspec] -%>
|
4
|
-
<%= '# ' if options.dev? || options.edge? -%>gem
|
4
|
+
<%= '# ' if options.dev? || options.edge? -%>gem 'rails', '~> <%= Rails::VERSION::STRING %>'
|
5
5
|
<% else -%>
|
6
6
|
# Declare your gem's dependencies in <%= name %>.gemspec.
|
7
7
|
# Bundler will treat runtime dependencies like base dependencies, and
|
@@ -11,7 +11,7 @@ gemspec
|
|
11
11
|
|
12
12
|
<% if options[:skip_gemspec] -%>
|
13
13
|
group :development do
|
14
|
-
gem
|
14
|
+
gem '<%= gem_for_database[0] %>'
|
15
15
|
end
|
16
16
|
<% else -%>
|
17
17
|
# Declare any dependencies that are still in development here instead of in
|
@@ -31,13 +31,21 @@ end
|
|
31
31
|
<% end -%>
|
32
32
|
<%= gem.commented_out ? '# ' : '' %>gem '<%= gem.name %>'<%= %(, '#{gem.version}') if gem.version -%>
|
33
33
|
<% if gem.options.any? -%>
|
34
|
-
|
34
|
+
, <%= gem.options.map { |k,v|
|
35
35
|
"#{k}: #{v.inspect}" }.join(', ') %>
|
36
36
|
<% end -%>
|
37
37
|
<% end -%>
|
38
38
|
|
39
39
|
<% end -%>
|
40
40
|
<% unless defined?(JRUBY_VERSION) -%>
|
41
|
-
# To use debugger
|
42
|
-
|
41
|
+
# To use a debugger
|
42
|
+
<%- if RUBY_VERSION < '2.0.0' -%>
|
43
|
+
# gem 'debugger', group: [:development, :test]
|
44
|
+
<%- else -%>
|
45
|
+
# gem 'byebug', group: [:development, :test]
|
46
|
+
<%- end -%>
|
47
|
+
<% end -%>
|
48
|
+
|
49
|
+
<% if RUBY_PLATFORM.match(/bccwin|cygwin|emx|mingw|mswin|wince|java/) -%>
|
50
|
+
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
|
43
51
|
<% end -%>
|
@@ -19,6 +19,10 @@ APP_RAKEFILE = File.expand_path("../<%= dummy_path -%>/Rakefile", __FILE__)
|
|
19
19
|
load 'rails/tasks/engine.rake'
|
20
20
|
<% end %>
|
21
21
|
|
22
|
+
<% if engine? -%>
|
23
|
+
load 'rails/tasks/statistics.rake'
|
24
|
+
<% end %>
|
25
|
+
|
22
26
|
<% unless options[:skip_gemspec] -%>
|
23
27
|
|
24
28
|
Bundler::GemHelper.install_tasks
|
@@ -7,7 +7,7 @@ require 'rails/all'
|
|
7
7
|
<%= comment_if :skip_active_record %>require "active_record/railtie"
|
8
8
|
require "action_controller/railtie"
|
9
9
|
require "action_mailer/railtie"
|
10
|
-
|
10
|
+
require "action_view/railtie"
|
11
11
|
<%= comment_if :skip_sprockets %>require "sprockets/railtie"
|
12
12
|
<%= comment_if :skip_test_unit %>require "rails/test_unit/railtie"
|
13
13
|
<% end -%>
|
@@ -2,12 +2,12 @@
|
|
2
2
|
// listed below.
|
3
3
|
//
|
4
4
|
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
|
5
|
-
// or vendor/assets/javascripts
|
5
|
+
// or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
|
6
6
|
//
|
7
7
|
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
|
8
8
|
// compiled file.
|
9
9
|
//
|
10
|
-
// Read Sprockets README (https://github.com/
|
10
|
+
// Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
|
11
11
|
// about supported directives.
|
12
12
|
//
|
13
13
|
//= require_tree .
|
@@ -3,7 +3,7 @@
|
|
3
3
|
* listed below.
|
4
4
|
*
|
5
5
|
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
|
6
|
-
* or vendor/assets/stylesheets
|
6
|
+
* or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
|
7
7
|
*
|
8
8
|
* You're free to add application-wide styles to this file and they'll appear at the bottom of the
|
9
9
|
* compiled file so the styles you add here take precedence over styles defined in any styles
|
@@ -1,15 +1,25 @@
|
|
1
1
|
# Configure Rails Environment
|
2
2
|
ENV["RAILS_ENV"] = "test"
|
3
3
|
|
4
|
-
require File.expand_path("
|
4
|
+
require File.expand_path("../../<%= options[:dummy_path] -%>/config/environment.rb", __FILE__)
|
5
|
+
<% unless options[:skip_active_record] -%>
|
6
|
+
ActiveRecord::Migrator.migrations_paths = [File.expand_path("../../<%= options[:dummy_path] -%>/db/migrate", __FILE__)]
|
7
|
+
<% if options[:mountable] -%>
|
8
|
+
ActiveRecord::Migrator.migrations_paths << File.expand_path('../../db/migrate', __FILE__)
|
9
|
+
<% end -%>
|
10
|
+
<% end -%>
|
5
11
|
require "rails/test_help"
|
6
12
|
|
7
|
-
|
13
|
+
# Filter out Minitest backtrace while allowing backtrace from other libraries
|
14
|
+
# to be shown.
|
15
|
+
Minitest.backtrace_filter = Minitest::BacktraceFilter.new
|
8
16
|
|
9
17
|
# Load support files
|
10
18
|
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
|
11
19
|
|
12
20
|
# Load fixtures from the engine
|
13
|
-
if ActiveSupport::TestCase.
|
21
|
+
if ActiveSupport::TestCase.respond_to?(:fixture_path=)
|
14
22
|
ActiveSupport::TestCase.fixture_path = File.expand_path("../fixtures", __FILE__)
|
23
|
+
ActionDispatch::IntegrationTest.fixture_path = ActiveSupport::TestCase.fixture_path
|
24
|
+
ActiveSupport::TestCase.fixtures :all
|
15
25
|
end
|
@@ -29,8 +29,10 @@ module Rails
|
|
29
29
|
write("end", route_length - index)
|
30
30
|
end
|
31
31
|
|
32
|
-
# route prepends two spaces onto the front of the string that is passed, this corrects that
|
33
|
-
route
|
32
|
+
# route prepends two spaces onto the front of the string that is passed, this corrects that.
|
33
|
+
# Also it adds a \n to the end of each line, as route already adds that
|
34
|
+
# we need to correct that too.
|
35
|
+
route route_string[2..-2]
|
34
36
|
end
|
35
37
|
|
36
38
|
private
|
@@ -9,11 +9,16 @@ Description:
|
|
9
9
|
|
10
10
|
Attributes are field arguments specifying the model's attributes. You can
|
11
11
|
optionally pass the type and an index to each field. For instance:
|
12
|
-
|
12
|
+
'title body:text tracking_id:integer:uniq' will generate a title field of
|
13
13
|
string type, a body with text type and a tracking_id as an integer with an
|
14
14
|
unique index. "index" could also be given instead of "uniq" if one desires
|
15
15
|
a non unique index.
|
16
16
|
|
17
|
+
As a special case, specifying 'password:digest' will generate a
|
18
|
+
password_digest field of string type, and configure your generated model,
|
19
|
+
controller, views, and test suite for use with ActiveModel
|
20
|
+
has_secure_password (assuming they are using Rails defaults).
|
21
|
+
|
17
22
|
Timestamps are added by default, so you don't have to specify them by hand
|
18
23
|
as 'created_at:datetime updated_at:datetime'.
|
19
24
|
|
@@ -33,3 +38,4 @@ Examples:
|
|
33
38
|
`rails generate scaffold post`
|
34
39
|
`rails generate scaffold post title body:text published:boolean`
|
35
40
|
`rails generate scaffold purchase amount:decimal tracking_id:integer:uniq`
|
41
|
+
`rails generate scaffold user email:uniq password:digest`
|
@@ -1,14 +1,14 @@
|
|
1
1
|
require 'rails/generators/active_model'
|
2
|
+
require 'rails/generators/model_helpers'
|
2
3
|
|
3
4
|
module Rails
|
4
5
|
module Generators
|
5
6
|
# Deal with controller names on scaffold and add some helpers to deal with
|
6
7
|
# ActiveModel.
|
7
8
|
module ResourceHelpers # :nodoc:
|
8
|
-
mattr_accessor :skip_warn
|
9
9
|
|
10
10
|
def self.included(base) #:nodoc:
|
11
|
-
base.
|
11
|
+
base.send :include, Rails::Generators::ModelHelpers
|
12
12
|
base.class_option :model_name, type: :string, desc: "ModelName to be used"
|
13
13
|
end
|
14
14
|
|
@@ -21,15 +21,6 @@ module Rails
|
|
21
21
|
assign_names!(self.name)
|
22
22
|
end
|
23
23
|
|
24
|
-
if name == name.pluralize && name.singularize != name.pluralize && !options[:force_plural]
|
25
|
-
unless ResourceHelpers.skip_warn
|
26
|
-
say "Plural version of the model detected, using singularized version. Override with --force-plural."
|
27
|
-
ResourceHelpers.skip_warn = true
|
28
|
-
end
|
29
|
-
name.replace name.singularize
|
30
|
-
assign_names!(name)
|
31
|
-
end
|
32
|
-
|
33
24
|
assign_controller_names!(controller_name.pluralize)
|
34
25
|
end
|
35
26
|
|
@@ -2,6 +2,12 @@ require 'test_helper'
|
|
2
2
|
|
3
3
|
<% module_namespacing do -%>
|
4
4
|
class <%= class_name %>ControllerTest < ActionController::TestCase
|
5
|
+
<% if mountable_engine? -%>
|
6
|
+
setup do
|
7
|
+
@routes = Engine.routes
|
8
|
+
end
|
9
|
+
|
10
|
+
<% end -%>
|
5
11
|
<% if actions.empty? -%>
|
6
12
|
# test "the truth" do
|
7
13
|
# assert true
|
@@ -3,11 +3,7 @@ require 'rails/generators/test_unit'
|
|
3
3
|
module TestUnit # :nodoc:
|
4
4
|
module Generators # :nodoc:
|
5
5
|
class HelperGenerator < Base # :nodoc:
|
6
|
-
|
7
|
-
|
8
|
-
def create_helper_files
|
9
|
-
template 'helper_test.rb', File.join('test/helpers', class_path, "#{file_name}_helper_test.rb")
|
10
|
-
end
|
6
|
+
# Rails does not generate anything here.
|
11
7
|
end
|
12
8
|
end
|
13
9
|
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'rails/generators/test_unit'
|
2
|
+
|
3
|
+
module TestUnit # :nodoc:
|
4
|
+
module Generators # :nodoc:
|
5
|
+
class JobGenerator < Base # :nodoc:
|
6
|
+
check_class_collision suffix: 'JobTest'
|
7
|
+
|
8
|
+
def create_test_file
|
9
|
+
template 'unit_test.rb.erb', File.join('test/jobs', class_path, "#{file_name}_job_test.rb")
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -15,6 +15,15 @@ module TestUnit # :nodoc:
|
|
15
15
|
File.join("test/controllers", controller_class_path, "#{controller_file_name}_controller_test.rb")
|
16
16
|
end
|
17
17
|
|
18
|
+
def fixture_name
|
19
|
+
@fixture_name ||=
|
20
|
+
if mountable_engine?
|
21
|
+
"%s_%s" % [namespaced_path, table_name]
|
22
|
+
else
|
23
|
+
table_name
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
18
27
|
private
|
19
28
|
|
20
29
|
def attributes_hash
|
@@ -3,7 +3,10 @@ require 'test_helper'
|
|
3
3
|
<% module_namespacing do -%>
|
4
4
|
class <%= controller_class_name %>ControllerTest < ActionController::TestCase
|
5
5
|
setup do
|
6
|
-
@<%= singular_table_name %> = <%=
|
6
|
+
@<%= singular_table_name %> = <%= fixture_name %>(:one)
|
7
|
+
<% if mountable_engine? -%>
|
8
|
+
@routes = Engine.routes
|
9
|
+
<% end -%>
|
7
10
|
end
|
8
11
|
|
9
12
|
test "should get index" do
|
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'shellwords'
|
2
|
+
|
1
3
|
module Rails
|
2
4
|
module Generators
|
3
5
|
module Testing
|
@@ -21,7 +23,7 @@ module Rails
|
|
21
23
|
# end
|
22
24
|
# end
|
23
25
|
def assert_file(relative, *contents)
|
24
|
-
absolute = File.expand_path(relative, destination_root)
|
26
|
+
absolute = File.expand_path(relative, destination_root)
|
25
27
|
assert File.exist?(absolute), "Expected file #{relative.inspect} to exist, but does not"
|
26
28
|
|
27
29
|
read = File.read(absolute) if block_given? || !contents.empty?
|
@@ -50,7 +50,7 @@ module Rails
|
|
50
50
|
# class AppGeneratorTest < Rails::Generators::TestCase
|
51
51
|
# tests AppGenerator
|
52
52
|
# destination File.expand_path("../tmp", File.dirname(__FILE__))
|
53
|
-
#
|
53
|
+
# setup :prepare_destination
|
54
54
|
#
|
55
55
|
# test "database.yml is not created when skipping Active Record" do
|
56
56
|
# run_generator %w(myapp --skip-active-record)
|
@@ -100,6 +100,23 @@ module Rails
|
|
100
100
|
dirname, file_name = File.dirname(absolute), File.basename(absolute).sub(/\.rb$/, '')
|
101
101
|
Dir.glob("#{dirname}/[0-9]*_*.rb").grep(/\d+_#{file_name}.rb$/).first
|
102
102
|
end
|
103
|
+
|
104
|
+
def capture(stream)
|
105
|
+
stream = stream.to_s
|
106
|
+
captured_stream = Tempfile.new(stream)
|
107
|
+
stream_io = eval("$#{stream}")
|
108
|
+
origin_stream = stream_io.dup
|
109
|
+
stream_io.reopen(captured_stream)
|
110
|
+
|
111
|
+
yield
|
112
|
+
|
113
|
+
stream_io.rewind
|
114
|
+
return captured_stream.read
|
115
|
+
ensure
|
116
|
+
captured_stream.close
|
117
|
+
captured_stream.unlink
|
118
|
+
stream_io.reopen(origin_stream)
|
119
|
+
end
|
103
120
|
end
|
104
121
|
end
|
105
122
|
end
|
data/lib/rails/generators.rb
CHANGED
@@ -156,10 +156,20 @@ module Rails
|
|
156
156
|
args << "--help" if args.empty? && klass.arguments.any? { |a| a.required? }
|
157
157
|
klass.start(args, config)
|
158
158
|
else
|
159
|
-
|
159
|
+
options = sorted_groups.map(&:last).flatten
|
160
|
+
suggestions = options.sort_by {|suggested| levenshtein_distance(namespace.to_s, suggested) }.first(3)
|
161
|
+
msg = "Could not find generator '#{namespace}'. "
|
162
|
+
msg << "Maybe you meant #{ suggestions.map {|s| "'#{s}'"}.to_sentence(last_word_connector: " or ") }\n"
|
163
|
+
msg << "Run `rails generate --help` for more options."
|
164
|
+
puts msg
|
160
165
|
end
|
161
166
|
end
|
162
167
|
|
168
|
+
# Returns an array of generator namespaces that are hidden.
|
169
|
+
# Generator namespaces may be hidden for a variety of reasons.
|
170
|
+
# Some are aliased such as "rails:migration" and can be
|
171
|
+
# invoked with the shorter "migration", others are private to other generators
|
172
|
+
# such as "css:scaffold".
|
163
173
|
def self.hidden_namespaces
|
164
174
|
@hidden_namespaces ||= begin
|
165
175
|
orm = options[:rails][:orm]
|
@@ -199,17 +209,6 @@ module Rails
|
|
199
209
|
|
200
210
|
# Show help message with available generators.
|
201
211
|
def self.help(command = 'generate')
|
202
|
-
lookup!
|
203
|
-
|
204
|
-
namespaces = subclasses.map{ |k| k.namespace }
|
205
|
-
namespaces.sort!
|
206
|
-
|
207
|
-
groups = Hash.new { |h,k| h[k] = [] }
|
208
|
-
namespaces.each do |namespace|
|
209
|
-
base = namespace.split(':').first
|
210
|
-
groups[base] << namespace
|
211
|
-
end
|
212
|
-
|
213
212
|
puts "Usage: rails #{command} GENERATOR [args] [options]"
|
214
213
|
puts
|
215
214
|
puts "General options:"
|
@@ -222,20 +221,72 @@ module Rails
|
|
222
221
|
puts "Please choose a generator below."
|
223
222
|
puts
|
224
223
|
|
225
|
-
|
224
|
+
print_generators
|
225
|
+
end
|
226
|
+
|
227
|
+
def self.public_namespaces
|
228
|
+
lookup!
|
229
|
+
subclasses.map { |k| k.namespace }
|
230
|
+
end
|
231
|
+
|
232
|
+
def self.print_generators
|
233
|
+
sorted_groups.each { |b, n| print_list(b, n) }
|
234
|
+
end
|
235
|
+
|
236
|
+
def self.sorted_groups
|
237
|
+
namespaces = public_namespaces
|
238
|
+
namespaces.sort!
|
239
|
+
groups = Hash.new { |h,k| h[k] = [] }
|
240
|
+
namespaces.each do |namespace|
|
241
|
+
base = namespace.split(':').first
|
242
|
+
groups[base] << namespace
|
243
|
+
end
|
226
244
|
rails = groups.delete("rails")
|
227
245
|
rails.map! { |n| n.sub(/^rails:/, '') }
|
228
246
|
rails.delete("app")
|
229
247
|
rails.delete("plugin")
|
230
|
-
print_list("rails", rails)
|
231
248
|
|
232
249
|
hidden_namespaces.each { |n| groups.delete(n.to_s) }
|
233
250
|
|
234
|
-
groups.sort.
|
251
|
+
[["rails", rails]] + groups.sort.to_a
|
235
252
|
end
|
236
253
|
|
237
254
|
protected
|
238
255
|
|
256
|
+
# This code is based directly on the Text gem implementation
|
257
|
+
# Returns a value representing the "cost" of transforming str1 into str2
|
258
|
+
def self.levenshtein_distance str1, str2
|
259
|
+
s = str1
|
260
|
+
t = str2
|
261
|
+
n = s.length
|
262
|
+
m = t.length
|
263
|
+
|
264
|
+
return m if (0 == n)
|
265
|
+
return n if (0 == m)
|
266
|
+
|
267
|
+
d = (0..m).to_a
|
268
|
+
x = nil
|
269
|
+
|
270
|
+
str1.each_char.each_with_index do |char1,i|
|
271
|
+
e = i+1
|
272
|
+
|
273
|
+
str2.each_char.each_with_index do |char2,j|
|
274
|
+
cost = (char1 == char2) ? 0 : 1
|
275
|
+
x = [
|
276
|
+
d[j+1] + 1, # insertion
|
277
|
+
e + 1, # deletion
|
278
|
+
d[j] + cost # substitution
|
279
|
+
].min
|
280
|
+
d[j] = e
|
281
|
+
e = x
|
282
|
+
end
|
283
|
+
|
284
|
+
d[m] = x
|
285
|
+
end
|
286
|
+
|
287
|
+
return x
|
288
|
+
end
|
289
|
+
|
239
290
|
# Prints a list of generators.
|
240
291
|
def self.print_list(base, namespaces) #:nodoc:
|
241
292
|
namespaces = namespaces.reject do |n|
|