railties 6.0.4.3 → 6.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +234 -420
- data/MIT-LICENSE +1 -1
- data/RDOC_MAIN.rdoc +1 -1
- data/README.rdoc +1 -1
- data/lib/minitest/rails_plugin.rb +16 -1
- data/lib/rails/api/task.rb +1 -1
- data/lib/rails/application/bootstrap.rb +5 -5
- data/lib/rails/application/configuration.rb +72 -22
- data/lib/rails/application/default_middleware_stack.rb +5 -3
- data/lib/rails/application/finisher.rb +15 -2
- data/lib/rails/application/routes_reloader.rb +9 -2
- data/lib/rails/application.rb +45 -79
- data/lib/rails/backtrace_cleaner.rb +12 -7
- data/lib/rails/code_statistics.rb +3 -3
- data/lib/rails/code_statistics_calculator.rb +6 -6
- data/lib/rails/command/base.rb +1 -1
- data/lib/rails/command/behavior.rb +1 -1
- data/lib/rails/command/environment_argument.rb +1 -1
- data/lib/rails/command.rb +7 -1
- data/lib/rails/commands/credentials/USAGE +17 -2
- data/lib/rails/commands/credentials/credentials_command/diffing.rb +41 -0
- data/lib/rails/commands/credentials/credentials_command.rb +28 -4
- data/lib/rails/commands/db/system/change/change_command.rb +6 -1
- data/lib/rails/commands/dbconsole/dbconsole_command.rb +61 -58
- data/lib/rails/commands/encrypted/encrypted_command.rb +4 -4
- data/lib/rails/commands/generate/generate_command.rb +1 -1
- data/lib/rails/commands/notes/notes_command.rb +3 -13
- data/lib/rails/commands/rake/rake_command.rb +9 -8
- data/lib/rails/commands/secrets/USAGE +9 -3
- data/lib/rails/commands/server/server_command.rb +14 -41
- data/lib/rails/commands/test/test_command.rb +2 -2
- data/lib/rails/configuration.rb +40 -10
- data/lib/rails/engine/configuration.rb +1 -0
- data/lib/rails/engine/updater.rb +1 -1
- data/lib/rails/engine.rb +35 -32
- data/lib/rails/gem_version.rb +3 -3
- data/lib/rails/generators/actions/create_migration.rb +5 -0
- data/lib/rails/generators/actions.rb +50 -29
- data/lib/rails/generators/app_base.rb +39 -22
- data/lib/rails/generators/base.rb +14 -11
- data/lib/rails/generators/database.rb +3 -4
- data/lib/rails/generators/erb/scaffold/templates/_form.html.erb.tt +3 -3
- data/lib/rails/generators/generated_attribute.rb +3 -9
- data/lib/rails/generators/migration.rb +2 -1
- data/lib/rails/generators/model_helpers.rb +26 -2
- data/lib/rails/generators/named_base.rb +1 -1
- data/lib/rails/generators/rails/app/USAGE +2 -1
- data/lib/rails/generators/rails/app/app_generator.rb +89 -15
- data/lib/rails/generators/rails/app/templates/Gemfile.tt +11 -11
- data/lib/rails/generators/rails/app/templates/Rakefile.tt +1 -1
- data/lib/rails/generators/rails/app/templates/app/javascript/channels/consumer.js +1 -1
- data/lib/rails/generators/rails/app/templates/app/javascript/packs/application.js.tt +11 -11
- data/lib/rails/generators/rails/app/templates/app/views/layouts/application.html.erb.tt +2 -1
- data/lib/rails/generators/rails/app/templates/bin/rails.tt +5 -2
- data/lib/rails/generators/rails/app/templates/bin/rake.tt +5 -2
- data/lib/rails/generators/rails/app/templates/bin/setup.tt +4 -4
- data/lib/rails/generators/rails/app/templates/bin/spring.tt +13 -0
- data/lib/rails/generators/rails/app/templates/bin/yarn.tt +9 -3
- data/lib/rails/generators/rails/app/templates/config/application.rb.tt +14 -7
- data/lib/rails/generators/rails/app/templates/config/boot.rb.tt +2 -2
- data/lib/rails/generators/rails/app/templates/config/databases/jdbc.yml.tt +3 -4
- data/lib/rails/generators/rails/app/templates/config/databases/jdbcmysql.yml.tt +10 -9
- data/lib/rails/generators/rails/app/templates/config/databases/jdbcpostgresql.yml.tt +11 -10
- data/lib/rails/generators/rails/app/templates/config/databases/mysql.yml.tt +10 -9
- data/lib/rails/generators/rails/app/templates/config/databases/oracle.yml.tt +11 -10
- data/lib/rails/generators/rails/app/templates/config/databases/postgresql.yml.tt +11 -10
- data/lib/rails/generators/rails/app/templates/config/databases/sqlserver.yml.tt +10 -9
- data/lib/rails/generators/rails/app/templates/config/environment.rb.tt +1 -1
- data/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt +17 -3
- data/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt +15 -5
- data/lib/rails/generators/rails/app/templates/config/environments/test.rb.tt +12 -1
- data/lib/rails/generators/rails/app/templates/config/initializers/backtrace_silencers.rb.tt +4 -3
- data/lib/rails/generators/rails/app/templates/config/initializers/filter_parameter_logging.rb.tt +3 -1
- data/lib/rails/generators/rails/app/templates/config/initializers/new_framework_defaults_6_1.rb.tt +67 -0
- data/lib/rails/generators/rails/app/templates/config/initializers/permissions_policy.rb.tt +11 -0
- data/lib/rails/generators/rails/app/templates/config/puma.rb.tt +6 -1
- data/lib/rails/generators/rails/app/templates/config.ru.tt +2 -1
- data/lib/rails/generators/rails/app/templates/db/seeds.rb.tt +1 -1
- data/lib/rails/generators/rails/app/templates/gitattributes.tt +14 -0
- data/lib/rails/generators/rails/app/templates/gitignore.tt +0 -1
- data/lib/rails/generators/rails/app/templates/package.json.tt +1 -1
- data/lib/rails/generators/rails/app/templates/test/test_helper.rb.tt +5 -5
- data/lib/rails/generators/rails/assets/USAGE +2 -3
- data/lib/rails/generators/rails/benchmark/USAGE +19 -0
- data/lib/rails/generators/rails/benchmark/benchmark_generator.rb +29 -0
- data/lib/rails/generators/rails/benchmark/templates/benchmark.rb.tt +15 -0
- data/lib/rails/generators/rails/controller/USAGE +2 -2
- data/lib/rails/generators/rails/controller/controller_generator.rb +2 -40
- data/lib/rails/generators/rails/credentials/credentials_generator.rb +1 -1
- data/lib/rails/generators/rails/generator/USAGE +2 -2
- data/lib/rails/generators/rails/generator/templates/USAGE.tt +1 -1
- data/lib/rails/generators/rails/helper/USAGE +2 -3
- data/lib/rails/generators/rails/integration_test/USAGE +2 -2
- data/lib/rails/generators/rails/migration/USAGE +4 -4
- data/lib/rails/generators/rails/model/USAGE +15 -16
- data/lib/rails/generators/rails/plugin/plugin_generator.rb +25 -23
- data/lib/rails/generators/rails/plugin/templates/%name%.gemspec.tt +10 -19
- data/lib/rails/generators/rails/plugin/templates/Gemfile.tt +3 -10
- data/lib/rails/generators/rails/plugin/templates/Rakefile.tt +4 -18
- data/lib/rails/generators/rails/plugin/templates/app/controllers/%namespaced_name%/application_controller.rb.tt +0 -1
- data/lib/rails/generators/rails/plugin/templates/bin/rails.tt +3 -3
- data/lib/rails/generators/rails/plugin/templates/gitignore.tt +13 -11
- data/lib/rails/generators/rails/plugin/templates/lib/%namespaced_name%.rb.tt +1 -0
- data/lib/rails/generators/rails/plugin/templates/rails/boot.rb.tt +1 -1
- data/lib/rails/generators/rails/plugin/templates/test/%namespaced_name%_test.rb.tt +4 -4
- data/lib/rails/generators/rails/plugin/templates/test/integration/navigation_test.rb.tt +1 -1
- data/lib/rails/generators/rails/plugin/templates/test/test_helper.rb.tt +0 -3
- data/lib/rails/generators/rails/resource/USAGE +4 -4
- data/lib/rails/generators/rails/resource_route/resource_route_generator.rb +2 -27
- data/lib/rails/generators/rails/scaffold/USAGE +5 -5
- data/lib/rails/generators/rails/scaffold_controller/USAGE +2 -2
- data/lib/rails/generators/rails/scaffold_controller/scaffold_controller_generator.rb +6 -0
- data/lib/rails/generators/rails/scaffold_controller/templates/api_controller.rb.tt +1 -1
- data/lib/rails/generators/rails/scaffold_controller/templates/controller.rb.tt +1 -1
- data/lib/rails/generators/rails/system_test/USAGE +2 -2
- data/lib/rails/generators/rails/task/USAGE +3 -3
- data/lib/rails/generators/test_case.rb +1 -1
- data/lib/rails/generators/test_unit/controller/controller_generator.rb +2 -0
- data/lib/rails/generators/test_unit/controller/templates/functional_test.rb.tt +3 -3
- data/lib/rails/generators/test_unit/generator/templates/generator_test.rb.tt +2 -2
- data/lib/rails/generators/test_unit/integration/templates/integration_test.rb.tt +1 -1
- data/lib/rails/generators/test_unit/job/templates/unit_test.rb.tt +1 -1
- data/lib/rails/generators/test_unit/mailer/templates/functional_test.rb.tt +1 -1
- data/lib/rails/generators/test_unit/model/templates/fixtures.yml.tt +1 -1
- data/lib/rails/generators/test_unit/model/templates/unit_test.rb.tt +1 -1
- data/lib/rails/generators/test_unit/plugin/templates/%file_name%_test.rb.tt +1 -1
- data/lib/rails/generators/test_unit/plugin/templates/test_helper.rb +2 -2
- data/lib/rails/generators/test_unit/scaffold/templates/api_functional_test.rb.tt +1 -1
- data/lib/rails/generators/test_unit/scaffold/templates/functional_test.rb.tt +1 -1
- data/lib/rails/generators/testing/assertions.rb +2 -2
- data/lib/rails/generators/testing/behaviour.rb +1 -1
- data/lib/rails/generators.rb +29 -15
- data/lib/rails/info.rb +1 -1
- data/lib/rails/info_controller.rb +1 -1
- data/lib/rails/mailers_controller.rb +1 -0
- data/lib/rails/paths.rb +14 -6
- data/lib/rails/railtie/configuration.rb +3 -2
- data/lib/rails/railtie.rb +31 -10
- data/lib/rails/source_annotation_extractor.rb +1 -15
- data/lib/rails/tasks/engine.rake +1 -4
- data/lib/rails/tasks/framework.rake +7 -1
- data/lib/rails/tasks/misc.rake +1 -1
- data/lib/rails/tasks/statistics.rake +1 -1
- data/lib/rails/tasks/yarn.rake +14 -2
- data/lib/rails/tasks.rb +0 -4
- data/lib/rails/templates/rails/mailers/email.html.erb +1 -0
- data/lib/rails/templates/rails/welcome/index.html.erb +1 -1
- data/lib/rails/test_unit/reporter.rb +2 -1
- data/lib/rails/test_unit/runner.rb +12 -3
- data/lib/rails/test_unit/testing.rake +6 -0
- data/lib/rails.rb +5 -8
- metadata +24 -30
- data/lib/rails/generators/rails/app/templates/config/databases/frontbase.yml.tt +0 -50
- data/lib/rails/generators/rails/app/templates/config/databases/ibm_db.yml.tt +0 -86
- data/lib/rails/generators/rails/app/templates/config/initializers/new_framework_defaults_6_0.rb.tt +0 -45
- data/lib/rails/generators/rails/plugin/templates/rails/application.rb.tt +0 -23
- data/lib/rails/tasks/annotations.rake +0 -22
- data/lib/rails/tasks/dev.rake +0 -11
- data/lib/rails/tasks/initializers.rake +0 -9
- data/lib/rails/tasks/routes.rake +0 -9
@@ -1,14 +1,10 @@
|
|
1
|
-
|
1
|
+
require_relative "lib/<%= namespaced_name %>/version"
|
2
2
|
|
3
|
-
# Maintain your gem's version:
|
4
|
-
require "<%= namespaced_name %>/version"
|
5
|
-
|
6
|
-
# Describe your gem and declare its dependencies:
|
7
3
|
Gem::Specification.new do |spec|
|
8
|
-
spec.name =
|
4
|
+
spec.name = <%= name.inspect %>
|
9
5
|
spec.version = <%= camelized_modules %>::VERSION
|
10
|
-
spec.authors = [
|
11
|
-
spec.email = [
|
6
|
+
spec.authors = [<%= author.inspect %>]
|
7
|
+
spec.email = [<%= email.inspect %>]
|
12
8
|
spec.homepage = "TODO"
|
13
9
|
spec.summary = "TODO: Summary of <%= camelized_modules %>."
|
14
10
|
spec.description = "TODO: Description of <%= camelized_modules %>."
|
@@ -16,18 +12,13 @@ Gem::Specification.new do |spec|
|
|
16
12
|
|
17
13
|
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
18
14
|
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
19
|
-
|
20
|
-
spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
|
21
|
-
else
|
22
|
-
raise "RubyGems 2.0 or newer is required to protect against " \
|
23
|
-
"public gem pushes."
|
24
|
-
end
|
15
|
+
spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
|
25
16
|
|
26
|
-
spec.
|
17
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
18
|
+
spec.metadata["source_code_uri"] = "TODO: Put your gem's public repo URL here."
|
19
|
+
spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
|
27
20
|
|
28
|
-
|
29
|
-
<% unless options[:skip_active_record] -%>
|
21
|
+
spec.files = Dir["{app,config,db,lib}/**/*", "MIT-LICENSE", "Rakefile", "README.md"]
|
30
22
|
|
31
|
-
spec.
|
32
|
-
<% end -%>
|
23
|
+
<%= '# ' if options.dev? || options.edge? || options.master? -%>spec.add_dependency "rails", "<%= Array(rails_version_specifier).join('", "') %>"
|
33
24
|
end
|
@@ -2,23 +2,16 @@ source 'https://rubygems.org'
|
|
2
2
|
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
|
3
3
|
|
4
4
|
<% if options[:skip_gemspec] -%>
|
5
|
-
<%= '# ' if options.dev? || options.edge? -%>gem 'rails', '<%= Array(rails_version_specifier).join("', '") %>'
|
5
|
+
<%= '# ' if options.dev? || options.edge? || options.master? -%>gem 'rails', '<%= Array(rails_version_specifier).join("', '") %>'
|
6
6
|
<% else -%>
|
7
|
-
#
|
8
|
-
# Bundler will treat runtime dependencies like base dependencies, and
|
9
|
-
# development dependencies will be added by default to the :development group.
|
7
|
+
# Specify your gem's dependencies in <%= name %>.gemspec.
|
10
8
|
gemspec
|
11
9
|
<% end -%>
|
10
|
+
<% unless options[:skip_active_record] -%>
|
12
11
|
|
13
|
-
<% if options[:skip_gemspec] -%>
|
14
12
|
group :development do
|
15
13
|
gem '<%= gem_for_database[0] %>'
|
16
14
|
end
|
17
|
-
<% else -%>
|
18
|
-
# Declare any dependencies that are still in development here instead of in
|
19
|
-
# your gemspec. These might include edge Rails or gems from your path or
|
20
|
-
# Git. Remember to move these dependencies to your gemspec before releasing
|
21
|
-
# your gem to rubygems.org.
|
22
15
|
<% end -%>
|
23
16
|
|
24
17
|
<% if options.dev? || options.edge? -%>
|
@@ -1,28 +1,14 @@
|
|
1
|
-
|
2
|
-
require 'bundler/setup'
|
3
|
-
rescue LoadError
|
4
|
-
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
5
|
-
end
|
6
|
-
|
7
|
-
require 'rdoc/task'
|
8
|
-
|
9
|
-
RDoc::Task.new(:rdoc) do |rdoc|
|
10
|
-
rdoc.rdoc_dir = 'rdoc'
|
11
|
-
rdoc.title = '<%= camelized_modules %>'
|
12
|
-
rdoc.options << '--line-numbers'
|
13
|
-
rdoc.rdoc_files.include('README.md')
|
14
|
-
rdoc.rdoc_files.include('lib/**/*.rb')
|
15
|
-
end
|
1
|
+
require "bundler/setup"
|
16
2
|
<% if engine? && !options[:skip_active_record] && with_dummy_app? -%>
|
17
3
|
|
18
4
|
APP_RAKEFILE = File.expand_path("<%= dummy_path -%>/Rakefile", __dir__)
|
19
|
-
load
|
5
|
+
load "rails/tasks/engine.rake"
|
20
6
|
<% end -%>
|
21
7
|
<% if engine? -%>
|
22
8
|
|
23
|
-
load
|
9
|
+
load "rails/tasks/statistics.rake"
|
24
10
|
<% end -%>
|
25
11
|
<% unless options[:skip_gemspec] -%>
|
26
12
|
|
27
|
-
require
|
13
|
+
require "bundler/gem_tasks"
|
28
14
|
<% end -%>
|
@@ -9,10 +9,10 @@ APP_PATH = File.expand_path('../<%= dummy_path -%>/config/application', __dir__)
|
|
9
9
|
|
10
10
|
# Set up gems listed in the Gemfile.
|
11
11
|
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__)
|
12
|
-
require
|
12
|
+
require "bundler/setup" if File.exist?(ENV["BUNDLE_GEMFILE"])
|
13
13
|
|
14
14
|
<% if include_all_railties? -%>
|
15
|
-
require
|
15
|
+
require "rails/all"
|
16
16
|
<% else -%>
|
17
17
|
require "rails"
|
18
18
|
# Pick the frameworks you want:
|
@@ -27,4 +27,4 @@ require "action_view/railtie"
|
|
27
27
|
<%= comment_if :skip_sprockets %>require "sprockets/railtie"
|
28
28
|
<%= comment_if :skip_test %>require "rails/test_unit/railtie"
|
29
29
|
<% end -%>
|
30
|
-
require
|
30
|
+
require "rails/engine/commands"
|
@@ -1,19 +1,21 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
1
|
+
/.bundle/
|
2
|
+
/doc/
|
3
|
+
/log/*.log
|
4
|
+
/pkg/
|
5
|
+
/tmp/
|
4
6
|
<% if with_dummy_app? -%>
|
5
7
|
<% if sqlite3? -%>
|
6
|
-
|
7
|
-
|
8
|
-
<%= dummy_path %>/db/*.sqlite3-*
|
8
|
+
/<%= dummy_path %>/db/*.sqlite3
|
9
|
+
/<%= dummy_path %>/db/*.sqlite3-*
|
9
10
|
<% end -%>
|
10
|
-
|
11
|
+
/<%= dummy_path %>/log/*.log
|
11
12
|
<% unless options[:skip_javascript] -%>
|
12
|
-
|
13
|
-
|
13
|
+
/<%= dummy_path %>/node_modules/
|
14
|
+
/<%= dummy_path %>/yarn-error.log
|
14
15
|
<% end -%>
|
15
16
|
<% unless skip_active_storage? -%>
|
16
|
-
|
17
|
+
/<%= dummy_path %>/storage/
|
17
18
|
<% end -%>
|
18
|
-
|
19
|
+
/<%= dummy_path %>/tmp/
|
19
20
|
<% end -%>
|
21
|
+
.byebug_history
|
@@ -1,5 +1,5 @@
|
|
1
1
|
# Set up gems listed in the Gemfile.
|
2
2
|
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../../Gemfile', __dir__)
|
3
3
|
|
4
|
-
require
|
4
|
+
require "bundler/setup" if File.exist?(ENV["BUNDLE_GEMFILE"])
|
5
5
|
$LOAD_PATH.unshift File.expand_path('../../../lib', __dir__)
|
@@ -1,7 +1,7 @@
|
|
1
|
-
require
|
1
|
+
require "test_helper"
|
2
2
|
|
3
|
-
class <%= camelized_modules
|
4
|
-
test "
|
5
|
-
|
3
|
+
class <%= camelized_modules %>Test < ActiveSupport::TestCase
|
4
|
+
test "it has a version number" do
|
5
|
+
assert <%= camelized_modules %>::VERSION
|
6
6
|
end
|
7
7
|
end
|
@@ -10,9 +10,6 @@ ActiveRecord::Migrator.migrations_paths << File.expand_path('../db/migrate', __d
|
|
10
10
|
<% end -%>
|
11
11
|
require "rails/test_help"
|
12
12
|
|
13
|
-
# Filter out the backtrace from minitest while preserving the one from other libraries.
|
14
|
-
Minitest.backtrace_filter = Minitest::BacktraceFilter.new
|
15
|
-
|
16
13
|
<% unless engine? -%>
|
17
14
|
require "rails/test_unit/reporter"
|
18
15
|
Rails::TestUnitReporter.executable = 'bin/test'
|
@@ -1,5 +1,5 @@
|
|
1
1
|
Description:
|
2
|
-
|
2
|
+
Generates a new resource including an empty model and controller suitable
|
3
3
|
for a RESTful, resource-oriented application. Pass the singular model name,
|
4
4
|
either CamelCased or under_scored, as the first argument, and an optional
|
5
5
|
list of attribute pairs.
|
@@ -18,6 +18,6 @@ Description:
|
|
18
18
|
views or add any methods to the generated controller.
|
19
19
|
|
20
20
|
Examples:
|
21
|
-
`rails generate resource post` # no attributes
|
22
|
-
`rails generate resource post title:string body:text published:boolean`
|
23
|
-
`rails generate resource purchase order_id:integer amount:decimal`
|
21
|
+
`bin/rails generate resource post` # no attributes
|
22
|
+
`bin/rails generate resource post title:string body:text published:boolean`
|
23
|
+
`bin/rails generate resource purchase order_id:integer amount:decimal`
|
@@ -5,7 +5,7 @@ module Rails
|
|
5
5
|
class ResourceRouteGenerator < NamedBase # :nodoc:
|
6
6
|
# Properly nests namespaces passed into a generator
|
7
7
|
#
|
8
|
-
# $ rails generate resource admin/users/products
|
8
|
+
# $ bin/rails generate resource admin/users/products
|
9
9
|
#
|
10
10
|
# should give you
|
11
11
|
#
|
@@ -16,32 +16,7 @@ module Rails
|
|
16
16
|
# end
|
17
17
|
def add_resource_route
|
18
18
|
return if options[:actions].present?
|
19
|
-
|
20
|
-
depth = 0
|
21
|
-
lines = []
|
22
|
-
|
23
|
-
# Create 'namespace' ladder
|
24
|
-
# namespace :foo do
|
25
|
-
# namespace :bar do
|
26
|
-
regular_class_path.each do |ns|
|
27
|
-
lines << indent("namespace :#{ns} do\n", depth * 2)
|
28
|
-
depth += 1
|
29
|
-
end
|
30
|
-
|
31
|
-
# inserts the primary resource
|
32
|
-
# Create route
|
33
|
-
# resources 'products'
|
34
|
-
lines << indent(%{resources :#{file_name.pluralize}\n}, depth * 2)
|
35
|
-
|
36
|
-
# Create `end` ladder
|
37
|
-
# end
|
38
|
-
# end
|
39
|
-
until depth.zero?
|
40
|
-
depth -= 1
|
41
|
-
lines << indent("end\n", depth * 2)
|
42
|
-
end
|
43
|
-
|
44
|
-
route lines.join
|
19
|
+
route "resources :#{file_name.pluralize}", namespace: regular_class_path
|
45
20
|
end
|
46
21
|
end
|
47
22
|
end
|
@@ -32,10 +32,10 @@ Description:
|
|
32
32
|
in config/routes.rb.
|
33
33
|
|
34
34
|
If you want to remove all the generated files, run
|
35
|
-
'rails destroy scaffold ModelName'.
|
35
|
+
'bin/rails destroy scaffold ModelName'.
|
36
36
|
|
37
37
|
Examples:
|
38
|
-
`rails generate scaffold post`
|
39
|
-
`rails generate scaffold post title:string body:text published:boolean`
|
40
|
-
`rails generate scaffold purchase amount:decimal tracking_id:integer:uniq`
|
41
|
-
`rails generate scaffold user email:uniq password:digest`
|
38
|
+
`bin/rails generate scaffold post`
|
39
|
+
`bin/rails generate scaffold post title:string body:text published:boolean`
|
40
|
+
`bin/rails generate scaffold purchase amount:decimal tracking_id:integer:uniq`
|
41
|
+
`bin/rails generate scaffold user email:uniq password:digest`
|
@@ -1,5 +1,5 @@
|
|
1
1
|
Description:
|
2
|
-
|
2
|
+
Generates a scaffolded controller, its seven RESTful actions and related
|
3
3
|
views. Pass the model name, either CamelCased or under_scored. The
|
4
4
|
controller name is retrieved as a pluralized version of the model name.
|
5
5
|
|
@@ -10,7 +10,7 @@ Description:
|
|
10
10
|
template engine and test framework generators.
|
11
11
|
|
12
12
|
Example:
|
13
|
-
`rails generate scaffold_controller CreditCard`
|
13
|
+
`bin/rails generate scaffold_controller CreditCard`
|
14
14
|
|
15
15
|
Credit card controller with URLs like /credit_cards.
|
16
16
|
Controller: app/controllers/credit_cards_controller.rb
|
@@ -15,6 +15,8 @@ module Rails
|
|
15
15
|
class_option :api, type: :boolean,
|
16
16
|
desc: "Generates API controller"
|
17
17
|
|
18
|
+
class_option :skip_routes, type: :boolean, desc: "Don't add routes to config/routes.rb."
|
19
|
+
|
18
20
|
argument :attributes, type: :array, default: [], banner: "field:type field:type"
|
19
21
|
|
20
22
|
def create_controller_files
|
@@ -26,6 +28,10 @@ module Rails
|
|
26
28
|
invoke template_engine unless options.api?
|
27
29
|
end
|
28
30
|
|
31
|
+
hook_for :resource_route, required: true do |route|
|
32
|
+
invoke route unless options.skip_routes?
|
33
|
+
end
|
34
|
+
|
29
35
|
hook_for :test_framework, as: :scaffold
|
30
36
|
|
31
37
|
# Invoke the helper using the controller name (pluralized)
|
@@ -49,7 +49,7 @@ class <%= controller_class_name %>Controller < ApplicationController
|
|
49
49
|
@<%= singular_table_name %> = <%= orm_class.find(class_name, "params[:id]") %>
|
50
50
|
end
|
51
51
|
|
52
|
-
# Only allow a
|
52
|
+
# Only allow a list of trusted parameters through.
|
53
53
|
def <%= "#{singular_table_name}_params" %>
|
54
54
|
<%- if attributes_names.empty? -%>
|
55
55
|
params.fetch(:<%= singular_table_name %>, {})
|
@@ -56,7 +56,7 @@ class <%= controller_class_name %>Controller < ApplicationController
|
|
56
56
|
@<%= singular_table_name %> = <%= orm_class.find(class_name, "params[:id]") %>
|
57
57
|
end
|
58
58
|
|
59
|
-
# Only allow a
|
59
|
+
# Only allow a list of trusted parameters through.
|
60
60
|
def <%= "#{singular_table_name}_params" %>
|
61
61
|
<%- if attributes_names.empty? -%>
|
62
62
|
params.fetch(:<%= singular_table_name %>, {})
|
@@ -1,10 +1,10 @@
|
|
1
1
|
Description:
|
2
|
-
|
2
|
+
Generates a new system test. Pass the name of the test, either
|
3
3
|
CamelCased or under_scored, as an argument.
|
4
4
|
|
5
5
|
This generator invokes the current system tool, which defaults to
|
6
6
|
TestUnit.
|
7
7
|
|
8
8
|
Example:
|
9
|
-
`rails generate system_test GeneralStories` creates a GeneralStories
|
9
|
+
`bin/rails generate system_test GeneralStories` creates a GeneralStories
|
10
10
|
system test in test/system/general_stories_test.rb
|
@@ -1,9 +1,9 @@
|
|
1
1
|
Description:
|
2
|
-
|
2
|
+
Generates a new Rake task. Pass the namespace name, and a list of tasks as arguments.
|
3
3
|
|
4
4
|
This generates a task file in lib/tasks.
|
5
5
|
|
6
6
|
Example:
|
7
|
-
`rails generate task feeds fetch erase add`
|
7
|
+
`bin/rails generate task feeds fetch erase add`
|
8
8
|
|
9
|
-
Task: lib/tasks/feeds.rake
|
9
|
+
Task: lib/tasks/feeds.rake
|
@@ -11,7 +11,7 @@ module Rails
|
|
11
11
|
# Disable color in output. Easier to debug.
|
12
12
|
no_color!
|
13
13
|
|
14
|
-
# This class provides a TestCase for testing generators. To
|
14
|
+
# This class provides a TestCase for testing generators. To set up, you need
|
15
15
|
# just to configure the destination and set which generator is being tested:
|
16
16
|
#
|
17
17
|
# class AppGeneratorTest < Rails::Generators::TestCase
|
@@ -6,6 +6,8 @@ module TestUnit # :nodoc:
|
|
6
6
|
module Generators # :nodoc:
|
7
7
|
class ControllerGenerator < Base # :nodoc:
|
8
8
|
argument :actions, type: :array, default: [], banner: "action action"
|
9
|
+
class_option :skip_routes, type: :boolean
|
10
|
+
|
9
11
|
check_class_collision suffix: "ControllerTest"
|
10
12
|
|
11
13
|
def create_test_files
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require "test_helper"
|
2
2
|
|
3
3
|
<% module_namespacing do -%>
|
4
4
|
class <%= class_name %>ControllerTest < ActionDispatch::IntegrationTest
|
@@ -6,7 +6,7 @@ class <%= class_name %>ControllerTest < ActionDispatch::IntegrationTest
|
|
6
6
|
include Engine.routes.url_helpers
|
7
7
|
|
8
8
|
<% end -%>
|
9
|
-
<% if actions.empty? -%>
|
9
|
+
<% if actions.empty? || options[:skip_routes] -%>
|
10
10
|
# test "the truth" do
|
11
11
|
# assert true
|
12
12
|
# end
|
@@ -16,7 +16,7 @@ class <%= class_name %>ControllerTest < ActionDispatch::IntegrationTest
|
|
16
16
|
get <%= url_helper_prefix %>_<%= action %>_url
|
17
17
|
assert_response :success
|
18
18
|
end
|
19
|
-
|
19
|
+
<%= "\n" unless action == actions.last -%>
|
20
20
|
<% end -%>
|
21
21
|
<% end -%>
|
22
22
|
end
|
@@ -6,7 +6,7 @@
|
|
6
6
|
<%- if attribute.password_digest? -%>
|
7
7
|
password_digest: <%%= BCrypt::Password.create('secret') %>
|
8
8
|
<%- elsif attribute.reference? -%>
|
9
|
-
<%= yaml_key_value(attribute.column_name.
|
9
|
+
<%= yaml_key_value(attribute.column_name.delete_suffix("_id"), attribute.default || name) %>
|
10
10
|
<%- elsif !attribute.virtual? -%>
|
11
11
|
<%= yaml_key_value(attribute.column_name, attribute.default) %>
|
12
12
|
<%- end -%>
|
@@ -1,2 +1,2 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require "active_support/testing/autorun"
|
2
|
+
require "active_support"
|
@@ -27,7 +27,7 @@ module Rails
|
|
27
27
|
assert File.exist?(absolute), "Expected file #{relative.inspect} to exist, but does not"
|
28
28
|
|
29
29
|
read = File.read(absolute) if block_given? || !contents.empty?
|
30
|
-
yield read if block_given?
|
30
|
+
assert_nothing_raised { yield read } if block_given?
|
31
31
|
|
32
32
|
contents.each do |content|
|
33
33
|
case content
|
@@ -99,7 +99,7 @@ module Rails
|
|
99
99
|
# end
|
100
100
|
def assert_instance_method(method, content)
|
101
101
|
assert content =~ /(\s+)def #{method}(\(.+\))?(.*?)\n\1end/m, "Expected to have method #{method}"
|
102
|
-
yield $3.strip if block_given?
|
102
|
+
assert_nothing_raised { yield $3.strip } if block_given?
|
103
103
|
end
|
104
104
|
alias :assert_method :assert_instance_method
|
105
105
|
|
@@ -104,7 +104,7 @@ module Rails
|
|
104
104
|
|
105
105
|
def migration_file_name(relative)
|
106
106
|
absolute = File.expand_path(relative, destination_root)
|
107
|
-
dirname, file_name = File.dirname(absolute), File.basename(absolute).
|
107
|
+
dirname, file_name = File.dirname(absolute), File.basename(absolute).delete_suffix(".rb")
|
108
108
|
Dir.glob("#{dirname}/[0-9]*_*.rb").grep(/\d+_#{file_name}.rb$/).first
|
109
109
|
end
|
110
110
|
end
|
data/lib/rails/generators.rb
CHANGED
@@ -6,10 +6,8 @@ $:.unshift(activesupport_path) if File.directory?(activesupport_path) && !$:.inc
|
|
6
6
|
require "thor/group"
|
7
7
|
require "rails/command"
|
8
8
|
|
9
|
-
require "active_support"
|
10
|
-
require "active_support/core_ext/object/blank"
|
11
|
-
require "active_support/core_ext/kernel/singleton_class"
|
12
9
|
require "active_support/core_ext/array/extract_options"
|
10
|
+
require "active_support/core_ext/enumerable"
|
13
11
|
require "active_support/core_ext/hash/deep_merge"
|
14
12
|
require "active_support/core_ext/module/attribute_accessors"
|
15
13
|
require "active_support/core_ext/string/indent"
|
@@ -81,6 +79,7 @@ module Rails
|
|
81
79
|
templates_path.concat config.templates
|
82
80
|
templates_path.uniq!
|
83
81
|
hide_namespaces(*config.hidden_namespaces)
|
82
|
+
after_generate_callbacks.replace config.after_generate_callbacks
|
84
83
|
end
|
85
84
|
|
86
85
|
def templates_path #:nodoc:
|
@@ -95,6 +94,10 @@ module Rails
|
|
95
94
|
@options ||= DEFAULT_OPTIONS.dup
|
96
95
|
end
|
97
96
|
|
97
|
+
def after_generate_callbacks # :nodoc:
|
98
|
+
@after_generate_callbacks ||= []
|
99
|
+
end
|
100
|
+
|
98
101
|
# Hold configured generators fallbacks. If a plugin developer wants a
|
99
102
|
# generator group to fallback to another group in case of missing generators,
|
100
103
|
# they can add a fallback.
|
@@ -125,14 +128,8 @@ module Rails
|
|
125
128
|
template_engine: nil
|
126
129
|
)
|
127
130
|
|
128
|
-
|
129
|
-
|
130
|
-
end
|
131
|
-
end
|
132
|
-
|
133
|
-
# Remove the color from output.
|
134
|
-
def no_color!
|
135
|
-
Thor::Base.shell = Thor::Shell::Basic
|
131
|
+
options[:mailer] ||= {}
|
132
|
+
options[:mailer][:template_engine] ||= :erb
|
136
133
|
end
|
137
134
|
|
138
135
|
# Returns an array of generator namespaces that are hidden.
|
@@ -167,7 +164,9 @@ module Rails
|
|
167
164
|
"#{css}:scaffold",
|
168
165
|
"#{css}:assets",
|
169
166
|
"css:assets",
|
170
|
-
"css:scaffold"
|
167
|
+
"css:scaffold",
|
168
|
+
"action_text:install",
|
169
|
+
"action_mailbox:install"
|
171
170
|
]
|
172
171
|
end
|
173
172
|
end
|
@@ -214,7 +213,7 @@ module Rails
|
|
214
213
|
end
|
215
214
|
|
216
215
|
rails = groups.delete("rails")
|
217
|
-
rails.map! { |n| n.
|
216
|
+
rails.map! { |n| n.delete_prefix("rails:") }
|
218
217
|
rails.delete("app")
|
219
218
|
rails.delete("plugin")
|
220
219
|
rails.delete("encrypted_secrets")
|
@@ -257,7 +256,7 @@ module Rails
|
|
257
256
|
|
258
257
|
lookup(lookups)
|
259
258
|
|
260
|
-
namespaces =
|
259
|
+
namespaces = subclasses.index_by(&:namespace)
|
261
260
|
lookups.each do |namespace|
|
262
261
|
klass = namespaces[namespace]
|
263
262
|
return klass if klass
|
@@ -274,6 +273,7 @@ module Rails
|
|
274
273
|
if klass = find_by_namespace(names.pop, names.any? && names.join(":"))
|
275
274
|
args << "--help" if args.empty? && klass.arguments.any?(&:required?)
|
276
275
|
klass.start(args, config)
|
276
|
+
run_after_generate_callback if config[:behavior] == :invoke
|
277
277
|
else
|
278
278
|
options = sorted_groups.flat_map(&:last)
|
279
279
|
suggestion = Rails::Command::Spellchecker.suggest(namespace.to_s, from: options)
|
@@ -281,11 +281,16 @@ module Rails
|
|
281
281
|
|
282
282
|
puts <<~MSG
|
283
283
|
Could not find generator '#{namespace}'. #{suggestion_msg}
|
284
|
-
Run `rails generate --help` for more options.
|
284
|
+
Run `bin/rails generate --help` for more options.
|
285
285
|
MSG
|
286
286
|
end
|
287
287
|
end
|
288
288
|
|
289
|
+
def add_generated_file(file) # :nodoc:
|
290
|
+
(@@generated_files ||= []) << file
|
291
|
+
file
|
292
|
+
end
|
293
|
+
|
289
294
|
private
|
290
295
|
def print_list(base, namespaces) # :doc:
|
291
296
|
namespaces = namespaces.reject { |n| hidden_namespaces.include?(n) }
|
@@ -319,6 +324,15 @@ module Rails
|
|
319
324
|
def file_lookup_paths # :doc:
|
320
325
|
@file_lookup_paths ||= [ "{#{lookup_paths.join(',')}}", "**", "*_generator.rb" ]
|
321
326
|
end
|
327
|
+
|
328
|
+
def run_after_generate_callback
|
329
|
+
if defined?(@@generated_files) && !@@generated_files.empty?
|
330
|
+
@after_generate_callbacks.each do |callback|
|
331
|
+
callback.call(@@generated_files)
|
332
|
+
end
|
333
|
+
@@generated_files = []
|
334
|
+
end
|
335
|
+
end
|
322
336
|
end
|
323
337
|
end
|
324
338
|
end
|