railties 5.2.0 → 6.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +293 -89
- data/MIT-LICENSE +1 -1
- data/RDOC_MAIN.rdoc +39 -33
- data/README.rdoc +3 -3
- data/lib/minitest/rails_plugin.rb +24 -13
- data/lib/rails/all.rb +4 -0
- data/lib/rails/api/generator.rb +2 -1
- data/lib/rails/api/task.rb +17 -0
- data/lib/rails/app_loader.rb +2 -2
- data/lib/rails/app_updater.rb +4 -1
- data/lib/rails/application/bootstrap.rb +9 -17
- data/lib/rails/application/configuration.rb +177 -27
- data/lib/rails/application/default_middleware_stack.rb +7 -3
- data/lib/rails/application/dummy_erb_compiler.rb +18 -0
- data/lib/rails/application/finisher.rb +69 -2
- data/lib/rails/application/routes_reloader.rb +9 -19
- data/lib/rails/application.rb +96 -66
- data/lib/rails/application_controller.rb +0 -1
- data/lib/rails/autoloaders.rb +48 -0
- data/lib/rails/backtrace_cleaner.rb +14 -21
- data/lib/rails/code_statistics.rb +8 -6
- data/lib/rails/code_statistics_calculator.rb +6 -6
- data/lib/rails/command/actions.rb +10 -0
- data/lib/rails/command/base.rb +17 -5
- data/lib/rails/command/behavior.rb +8 -49
- data/lib/rails/command/environment_argument.rb +9 -16
- data/lib/rails/command/spellchecker.rb +57 -0
- data/lib/rails/command.rb +18 -11
- data/lib/rails/commands/console/console_command.rb +6 -0
- data/lib/rails/commands/credentials/USAGE +33 -0
- data/lib/rails/commands/credentials/credentials_command/diffing.rb +41 -0
- data/lib/rails/commands/credentials/credentials_command.rb +78 -21
- data/lib/rails/commands/db/system/change/change_command.rb +25 -0
- data/lib/rails/commands/dbconsole/dbconsole_command.rb +66 -51
- data/lib/rails/commands/dev/dev_command.rb +19 -0
- data/lib/rails/commands/encrypted/USAGE +28 -0
- data/lib/rails/commands/encrypted/encrypted_command.rb +5 -4
- data/lib/rails/commands/generate/generate_command.rb +1 -1
- data/lib/rails/commands/help/help_command.rb +1 -1
- data/lib/rails/commands/initializers/initializers_command.rb +23 -0
- data/lib/rails/commands/new/new_command.rb +2 -2
- data/lib/rails/commands/notes/notes_command.rb +29 -0
- data/lib/rails/commands/plugin/plugin_command.rb +1 -1
- data/lib/rails/commands/rake/rake_command.rb +9 -8
- data/lib/rails/commands/routes/routes_command.rb +37 -0
- data/lib/rails/commands/runner/runner_command.rb +13 -9
- data/lib/rails/commands/secrets/USAGE +6 -0
- data/lib/rails/commands/secrets/secrets_command.rb +3 -3
- data/lib/rails/commands/server/server_command.rb +92 -56
- data/lib/rails/commands/test/test_command.rb +2 -2
- data/lib/rails/configuration.rb +48 -19
- data/lib/rails/engine/configuration.rb +6 -2
- data/lib/rails/engine/updater.rb +1 -1
- data/lib/rails/engine.rb +63 -35
- data/lib/rails/gem_version.rb +2 -2
- data/lib/rails/generators/actions/create_migration.rb +5 -1
- data/lib/rails/generators/actions.rb +89 -56
- data/lib/rails/generators/app_base.rb +80 -108
- data/lib/rails/generators/app_name.rb +50 -0
- data/lib/rails/generators/base.rb +19 -12
- data/lib/rails/generators/database.rb +57 -0
- data/lib/rails/generators/erb/mailer/mailer_generator.rb +1 -2
- data/lib/rails/generators/erb/scaffold/scaffold_generator.rb +0 -1
- data/lib/rails/generators/erb/scaffold/templates/_form.html.erb.tt +7 -4
- data/lib/rails/generators/erb/scaffold/templates/index.html.erb.tt +1 -1
- data/lib/rails/generators/erb/scaffold/templates/show.html.erb.tt +9 -1
- data/lib/rails/generators/erb.rb +0 -1
- data/lib/rails/generators/generated_attribute.rb +50 -31
- data/lib/rails/generators/migration.rb +3 -3
- data/lib/rails/generators/model_helpers.rb +33 -2
- data/lib/rails/generators/named_base.rb +3 -7
- data/lib/rails/generators/rails/app/USAGE +2 -1
- data/lib/rails/generators/rails/app/app_generator.rb +127 -84
- data/lib/rails/generators/rails/app/templates/Gemfile.tt +18 -21
- data/lib/rails/generators/rails/app/templates/Rakefile.tt +1 -1
- data/lib/rails/generators/rails/app/templates/app/assets/config/manifest.js.tt +0 -3
- data/lib/rails/generators/rails/app/templates/app/javascript/channels/consumer.js +6 -0
- data/lib/rails/generators/rails/app/templates/app/javascript/channels/index.js +5 -0
- data/lib/rails/generators/rails/app/templates/app/javascript/packs/application.js.tt +23 -0
- data/lib/rails/generators/rails/app/templates/app/jobs/application_job.rb.tt +5 -0
- data/lib/rails/generators/rails/app/templates/app/views/layouts/application.html.erb.tt +6 -5
- 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 +9 -9
- data/lib/rails/generators/rails/app/templates/bin/spring.tt +9 -0
- data/lib/rails/generators/rails/app/templates/bin/yarn.tt +11 -3
- data/lib/rails/generators/rails/app/templates/config/application.rb.tt +16 -7
- data/lib/rails/generators/rails/app/templates/config/boot.rb.tt +2 -2
- data/lib/rails/generators/rails/app/templates/config/cable.yml.tt +1 -1
- data/lib/rails/generators/rails/app/templates/config/databases/jdbc.yml.tt +4 -5
- data/lib/rails/generators/rails/app/templates/config/databases/jdbcmysql.yml.tt +12 -11
- data/lib/rails/generators/rails/app/templates/config/databases/jdbcpostgresql.yml.tt +13 -12
- data/lib/rails/generators/rails/app/templates/config/databases/jdbcsqlite3.yml.tt +1 -1
- data/lib/rails/generators/rails/app/templates/config/databases/mysql.yml.tt +13 -12
- data/lib/rails/generators/rails/app/templates/config/databases/oracle.yml.tt +12 -11
- data/lib/rails/generators/rails/app/templates/config/databases/postgresql.yml.tt +16 -15
- data/lib/rails/generators/rails/app/templates/config/databases/sqlite3.yml.tt +1 -1
- data/lib/rails/generators/rails/app/templates/config/databases/sqlserver.yml.tt +11 -10
- 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 +22 -5
- data/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt +43 -17
- data/lib/rails/generators/rails/app/templates/config/environments/test.rb.tt +26 -7
- data/lib/rails/generators/rails/app/templates/config/initializers/assets.rb.tt +1 -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/content_security_policy.rb.tt +7 -0
- 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 +63 -0
- data/lib/rails/generators/rails/app/templates/config/initializers/permissions_policy.rb.tt +11 -0
- data/lib/rails/generators/rails/app/templates/config/locales/en.yml +1 -1
- data/lib/rails/generators/rails/app/templates/config/puma.rb.tt +13 -4
- data/lib/rails/generators/rails/app/templates/config/routes.rb.tt +1 -1
- data/lib/rails/generators/rails/app/templates/config/spring.rb.tt +6 -6
- 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 +10 -7
- data/lib/rails/generators/rails/app/templates/package.json.tt +8 -2
- data/lib/rails/generators/rails/app/templates/public/robots.txt +1 -1
- data/lib/rails/generators/rails/app/templates/ruby-version.tt +1 -1
- data/lib/rails/generators/rails/app/templates/test/channels/application_cable/connection_test.rb.tt +11 -0
- data/lib/rails/generators/rails/app/templates/test/test_helper.rb.tt +9 -2
- data/lib/rails/generators/rails/assets/USAGE +3 -7
- data/lib/rails/generators/rails/assets/assets_generator.rb +0 -1
- 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 +10 -39
- data/lib/rails/generators/rails/credentials/credentials_generator.rb +6 -7
- data/lib/rails/generators/rails/db/system/change/change_generator.rb +65 -0
- data/lib/rails/generators/rails/encrypted_file/encrypted_file_generator.rb +10 -7
- data/lib/rails/generators/rails/encryption_key_file/encryption_key_file_generator.rb +1 -0
- data/lib/rails/generators/rails/generator/USAGE +2 -2
- data/lib/rails/generators/rails/generator/generator_generator.rb +0 -1
- 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/helper/helper_generator.rb +5 -0
- 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 +32 -56
- data/lib/rails/generators/rails/plugin/templates/%name%.gemspec.tt +18 -18
- 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 +1 -2
- data/lib/rails/generators/rails/plugin/templates/app/helpers/%namespaced_name%/application_helper.rb.tt +1 -1
- data/lib/rails/generators/rails/plugin/templates/app/jobs/%namespaced_name%/application_job.rb.tt +1 -1
- data/lib/rails/generators/rails/plugin/templates/app/mailers/%namespaced_name%/application_mailer.rb.tt +1 -1
- data/lib/rails/generators/rails/plugin/templates/app/models/%namespaced_name%/application_record.rb.tt +1 -1
- data/lib/rails/generators/rails/plugin/templates/bin/rails.tt +3 -3
- data/lib/rails/generators/rails/plugin/templates/gitignore.tt +14 -11
- data/lib/rails/generators/rails/plugin/templates/lib/%namespaced_name%/engine.rb.tt +1 -1
- data/lib/rails/generators/rails/plugin/templates/lib/%namespaced_name%/railtie.rb.tt +1 -1
- 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 -4
- 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 +19 -0
- data/lib/rails/generators/rails/scaffold_controller/templates/api_controller.rb.tt +2 -2
- data/lib/rails/generators/rails/scaffold_controller/templates/controller.rb.tt +2 -2
- data/lib/rails/generators/rails/system_test/USAGE +2 -2
- data/lib/rails/generators/rails/task/USAGE +3 -3
- data/lib/rails/generators/resource_helpers.rb +1 -6
- 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/generator_generator.rb +0 -1
- data/lib/rails/generators/test_unit/generator/templates/generator_test.rb.tt +2 -2
- data/lib/rails/generators/test_unit/integration/integration_generator.rb +5 -0
- data/lib/rails/generators/test_unit/integration/templates/integration_test.rb.tt +1 -1
- data/lib/rails/generators/test_unit/job/job_generator.rb +5 -0
- data/lib/rails/generators/test_unit/job/templates/unit_test.rb.tt +1 -1
- data/lib/rails/generators/test_unit/mailer/mailer_generator.rb +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 +3 -3
- 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/scaffold_generator.rb +12 -3
- 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/test_unit/scaffold/templates/system_test.rb.tt +10 -2
- data/lib/rails/generators/test_unit/system/system_generator.rb +5 -0
- data/lib/rails/generators/testing/assertions.rb +2 -2
- data/lib/rails/generators/testing/behaviour.rb +4 -2
- data/lib/rails/generators.rb +38 -24
- data/lib/rails/info.rb +4 -4
- data/lib/rails/info_controller.rb +2 -3
- data/lib/rails/mailers_controller.rb +10 -4
- data/lib/rails/paths.rb +26 -10
- data/lib/rails/rack/logger.rb +5 -6
- data/lib/rails/railtie/configurable.rb +0 -1
- data/lib/rails/railtie/configuration.rb +3 -3
- data/lib/rails/railtie.rb +33 -13
- data/lib/rails/ruby_version_check.rb +3 -3
- data/lib/rails/secrets.rb +0 -1
- data/lib/rails/source_annotation_extractor.rb +124 -117
- data/lib/rails/tasks/engine.rake +1 -4
- data/lib/rails/tasks/framework.rake +13 -3
- data/lib/rails/tasks/log.rake +0 -1
- data/lib/rails/tasks/misc.rake +1 -1
- data/lib/rails/tasks/statistics.rake +5 -1
- data/lib/rails/tasks/yarn.rake +14 -1
- data/lib/rails/tasks/zeitwerk.rake +69 -0
- data/lib/rails/tasks.rb +1 -4
- data/lib/rails/templates/rails/mailers/email.html.erb +11 -7
- data/lib/rails/templates/rails/welcome/index.html.erb +3 -3
- data/lib/rails/test_help.rb +11 -9
- data/lib/rails/test_unit/reporter.rb +3 -2
- data/lib/rails/test_unit/runner.rb +25 -8
- data/lib/rails/test_unit/testing.rake +7 -1
- data/lib/rails.rb +10 -8
- metadata +45 -39
- data/lib/rails/generators/js/assets/assets_generator.rb +0 -15
- data/lib/rails/generators/js/assets/templates/javascript.js +0 -2
- data/lib/rails/generators/rails/app/templates/app/assets/javascripts/application.js.tt +0 -22
- data/lib/rails/generators/rails/app/templates/app/assets/javascripts/cable.js.tt +0 -13
- data/lib/rails/generators/rails/app/templates/bin/bundle.tt +0 -2
- data/lib/rails/generators/rails/app/templates/bin/update.tt +0 -34
- 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_5_2.rb.tt +0 -35
- data/lib/rails/generators/rails/assets/templates/javascript.js +0 -2
- 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 -10
- data/lib/rails/tasks/initializers.rake +0 -8
- data/lib/rails/tasks/routes.rake +0 -31
@@ -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
|
@@ -25,13 +25,8 @@ module Rails
|
|
25
25
|
assign_controller_names!(controller_name.pluralize)
|
26
26
|
end
|
27
27
|
|
28
|
-
# TODO Change this to private once we've dropped Ruby 2.2 support.
|
29
|
-
# Workaround for Ruby 2.2 "private attribute?" warning.
|
30
|
-
protected
|
31
|
-
|
32
|
-
attr_reader :controller_name, :controller_file_name
|
33
|
-
|
34
28
|
private
|
29
|
+
attr_reader :controller_name, :controller_file_name
|
35
30
|
|
36
31
|
def controller_class_path
|
37
32
|
if options[:model_name]
|
@@ -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
|
@@ -10,6 +10,11 @@ module TestUnit # :nodoc:
|
|
10
10
|
def create_test_files
|
11
11
|
template "integration_test.rb", File.join("test/integration", class_path, "#{file_name}_test.rb")
|
12
12
|
end
|
13
|
+
|
14
|
+
private
|
15
|
+
def file_name
|
16
|
+
@_file_name ||= super.sub(/_test\z/i, "")
|
17
|
+
end
|
13
18
|
end
|
14
19
|
end
|
15
20
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
# Read about fixtures at
|
1
|
+
# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
|
2
2
|
<% unless attributes.empty? -%>
|
3
3
|
<% %w(one two).each do |name| %>
|
4
4
|
<%= name %>:
|
@@ -6,8 +6,8 @@
|
|
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.
|
10
|
-
<%-
|
9
|
+
<%= yaml_key_value(attribute.column_name.delete_suffix("_id"), attribute.default || name) %>
|
10
|
+
<%- elsif !attribute.virtual? -%>
|
11
11
|
<%= yaml_key_value(attribute.column_name, attribute.default) %>
|
12
12
|
<%- end -%>
|
13
13
|
<%- if attribute.polymorphic? -%>
|
@@ -1,2 +1,2 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require "active_support/testing/autorun"
|
2
|
+
require "active_support"
|
@@ -38,7 +38,6 @@ module TestUnit # :nodoc:
|
|
38
38
|
end
|
39
39
|
|
40
40
|
private
|
41
|
-
|
42
41
|
def attributes_string
|
43
42
|
attributes_hash.map { |k, v| "#{k}: #{v}" }.join(", ")
|
44
43
|
end
|
@@ -49,10 +48,20 @@ module TestUnit # :nodoc:
|
|
49
48
|
attributes_names.map do |name|
|
50
49
|
if %w(password password_confirmation).include?(name) && attributes.any?(&:password_digest?)
|
51
50
|
["#{name}", "'secret'"]
|
52
|
-
|
51
|
+
elsif !virtual?(name)
|
53
52
|
["#{name}", "@#{singular_table_name}.#{name}"]
|
54
53
|
end
|
55
|
-
end.sort.to_h
|
54
|
+
end.compact.sort.to_h
|
55
|
+
end
|
56
|
+
|
57
|
+
def boolean?(name)
|
58
|
+
attribute = attributes.find { |attr| attr.name == name }
|
59
|
+
attribute&.type == :boolean
|
60
|
+
end
|
61
|
+
|
62
|
+
def virtual?(name)
|
63
|
+
attribute = attributes.find { |attr| attr.name == name }
|
64
|
+
attribute&.virtual?
|
56
65
|
end
|
57
66
|
end
|
58
67
|
end
|
@@ -16,7 +16,11 @@ class <%= class_name.pluralize %>Test < ApplicationSystemTestCase
|
|
16
16
|
click_on "New <%= class_name.titleize %>"
|
17
17
|
|
18
18
|
<%- attributes_hash.each do |attr, value| -%>
|
19
|
-
|
19
|
+
<%- if boolean?(attr) -%>
|
20
|
+
check "<%= attr.humanize %>" if <%= value %>
|
21
|
+
<%- else -%>
|
22
|
+
fill_in "<%= attr.humanize %>", with: <%= value %>
|
23
|
+
<%- end -%>
|
20
24
|
<%- end -%>
|
21
25
|
click_on "Create <%= human_name %>"
|
22
26
|
|
@@ -29,7 +33,11 @@ class <%= class_name.pluralize %>Test < ApplicationSystemTestCase
|
|
29
33
|
click_on "Edit", match: :first
|
30
34
|
|
31
35
|
<%- attributes_hash.each do |attr, value| -%>
|
32
|
-
|
36
|
+
<%- if boolean?(attr) -%>
|
37
|
+
check "<%= attr.humanize %>" if <%= value %>
|
38
|
+
<%- else -%>
|
39
|
+
fill_in "<%= attr.humanize %>", with: <%= value %>
|
40
|
+
<%- end -%>
|
33
41
|
<%- end -%>
|
34
42
|
click_on "Update <%= human_name %>"
|
35
43
|
|
@@ -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
|
|
@@ -67,6 +67,9 @@ module Rails
|
|
67
67
|
def run_generator(args = default_arguments, config = {})
|
68
68
|
capture(:stdout) do
|
69
69
|
args += ["--skip-bundle"] unless args.include? "--dev"
|
70
|
+
args |= ["--skip-bootsnap"] unless args.include? "--no-skip-bootsnap"
|
71
|
+
args |= ["--skip-webpack-install"] unless args.include? "--no-skip-webpack-install"
|
72
|
+
|
70
73
|
generator_class.start(args, config.reverse_merge(destination_root: destination_root))
|
71
74
|
end
|
72
75
|
end
|
@@ -85,7 +88,6 @@ module Rails
|
|
85
88
|
end
|
86
89
|
|
87
90
|
private
|
88
|
-
|
89
91
|
def destination_root_is_set?
|
90
92
|
raise "You need to configure your Rails::Generators::TestCase destination root." unless destination_root
|
91
93
|
end
|
@@ -102,7 +104,7 @@ module Rails
|
|
102
104
|
|
103
105
|
def migration_file_name(relative)
|
104
106
|
absolute = File.expand_path(relative, destination_root)
|
105
|
-
dirname, file_name = File.dirname(absolute), File.basename(absolute).
|
107
|
+
dirname, file_name = File.dirname(absolute), File.basename(absolute).delete_suffix(".rb")
|
106
108
|
Dir.glob("#{dirname}/[0-9]*_*.rb").grep(/\d+_#{file_name}.rb$/).first
|
107
109
|
end
|
108
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"
|
@@ -23,6 +21,8 @@ module Rails
|
|
23
21
|
autoload :ActiveModel, "rails/generators/active_model"
|
24
22
|
autoload :Base, "rails/generators/base"
|
25
23
|
autoload :Migration, "rails/generators/migration"
|
24
|
+
autoload :Database, "rails/generators/database"
|
25
|
+
autoload :AppName, "rails/generators/app_name"
|
26
26
|
autoload :NamedBase, "rails/generators/named_base"
|
27
27
|
autoload :ResourceHelpers, "rails/generators/resource_helpers"
|
28
28
|
autoload :TestCase, "rails/generators/test_case"
|
@@ -56,8 +56,6 @@ module Rails
|
|
56
56
|
force_plural: false,
|
57
57
|
helper: true,
|
58
58
|
integration_tool: nil,
|
59
|
-
javascripts: true,
|
60
|
-
javascript_engine: :js,
|
61
59
|
orm: false,
|
62
60
|
resource_controller: :controller,
|
63
61
|
resource_route: true,
|
@@ -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")
|
@@ -222,6 +221,7 @@ module Rails
|
|
222
221
|
rails.delete("encryption_key_file")
|
223
222
|
rails.delete("master_key")
|
224
223
|
rails.delete("credentials")
|
224
|
+
rails.delete("db:system:change")
|
225
225
|
|
226
226
|
hidden_namespaces.each { |n| groups.delete(n.to_s) }
|
227
227
|
|
@@ -256,9 +256,8 @@ module Rails
|
|
256
256
|
|
257
257
|
lookup(lookups)
|
258
258
|
|
259
|
-
namespaces =
|
259
|
+
namespaces = subclasses.index_by(&:namespace)
|
260
260
|
lookups.each do |namespace|
|
261
|
-
|
262
261
|
klass = namespaces[namespace]
|
263
262
|
return klass if klass
|
264
263
|
end
|
@@ -274,19 +273,25 @@ 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
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
279
|
+
suggestion = Rails::Command::Spellchecker.suggest(namespace.to_s, from: options)
|
280
|
+
suggestion_msg = "Maybe you meant #{suggestion.inspect}?" if suggestion
|
281
|
+
|
282
|
+
puts <<~MSG
|
283
|
+
Could not find generator '#{namespace}'. #{suggestion_msg}
|
284
|
+
Run `bin/rails generate --help` for more options.
|
285
|
+
MSG
|
285
286
|
end
|
286
287
|
end
|
287
288
|
|
288
|
-
|
289
|
+
def add_generated_file(file) # :nodoc:
|
290
|
+
(@@generated_files ||= []) << file
|
291
|
+
file
|
292
|
+
end
|
289
293
|
|
294
|
+
private
|
290
295
|
def print_list(base, namespaces) # :doc:
|
291
296
|
namespaces = namespaces.reject { |n| hidden_namespaces.include?(n) }
|
292
297
|
super
|
@@ -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
|
data/lib/rails/info.rb
CHANGED
@@ -41,7 +41,7 @@ module Rails
|
|
41
41
|
alias inspect to_s
|
42
42
|
|
43
43
|
def to_html
|
44
|
-
"<table>".
|
44
|
+
(+"<table>").tap do |table|
|
45
45
|
properties.each do |(name, value)|
|
46
46
|
table << %(<tr><td class="name">#{CGI.escapeHTML(name.to_s)}</td>)
|
47
47
|
formatted_value = if value.kind_of?(Array)
|
@@ -63,12 +63,12 @@ module Rails
|
|
63
63
|
|
64
64
|
# The Ruby version and platform, e.g. "2.0.0-p247 (x86_64-darwin12.4.0)".
|
65
65
|
property "Ruby version" do
|
66
|
-
|
66
|
+
RUBY_DESCRIPTION
|
67
67
|
end
|
68
68
|
|
69
69
|
# The RubyGems version, if it's installed.
|
70
70
|
property "RubyGems version" do
|
71
|
-
Gem::
|
71
|
+
Gem::VERSION
|
72
72
|
end
|
73
73
|
|
74
74
|
property "Rack version" do
|
@@ -95,7 +95,7 @@ module Rails
|
|
95
95
|
|
96
96
|
# The name of the database adapter for the current environment.
|
97
97
|
property "Database adapter" do
|
98
|
-
ActiveRecord::Base.
|
98
|
+
ActiveRecord::Base.connection.pool.db_config.adapter
|
99
99
|
end
|
100
100
|
|
101
101
|
property "Database schema version" do
|
@@ -4,7 +4,7 @@ require "rails/application_controller"
|
|
4
4
|
require "action_dispatch/routing/inspector"
|
5
5
|
|
6
6
|
class Rails::InfoController < Rails::ApplicationController # :nodoc:
|
7
|
-
prepend_view_path ActionDispatch::
|
7
|
+
prepend_view_path ActionDispatch::DebugView::RESCUES_TEMPLATE_PATH
|
8
8
|
layout -> { request.xhr? ? false : "application" }
|
9
9
|
|
10
10
|
before_action :require_local!
|
@@ -20,7 +20,7 @@ class Rails::InfoController < Rails::ApplicationController # :nodoc:
|
|
20
20
|
|
21
21
|
def routes
|
22
22
|
if path = params[:path]
|
23
|
-
path = URI.
|
23
|
+
path = URI::DEFAULT_PARSER.escape path
|
24
24
|
normalized_path = with_leading_slash path
|
25
25
|
render json: {
|
26
26
|
exact: match_route { |it| it.match normalized_path },
|
@@ -33,7 +33,6 @@ class Rails::InfoController < Rails::ApplicationController # :nodoc:
|
|
33
33
|
end
|
34
34
|
|
35
35
|
private
|
36
|
-
|
37
36
|
def match_route
|
38
37
|
_routes.routes.select { |route|
|
39
38
|
yield route.path
|
@@ -3,13 +3,16 @@
|
|
3
3
|
require "rails/application_controller"
|
4
4
|
|
5
5
|
class Rails::MailersController < Rails::ApplicationController # :nodoc:
|
6
|
-
prepend_view_path ActionDispatch::
|
6
|
+
prepend_view_path ActionDispatch::DebugView::RESCUES_TEMPLATE_PATH
|
7
7
|
|
8
|
+
around_action :set_locale, only: :preview
|
9
|
+
before_action :find_preview, only: :preview
|
8
10
|
before_action :require_local!, unless: :show_previews?
|
9
|
-
before_action :find_preview, :set_locale, only: :preview
|
10
11
|
|
11
12
|
helper_method :part_query, :locale_query
|
12
13
|
|
14
|
+
content_security_policy(false)
|
15
|
+
|
13
16
|
def index
|
14
17
|
@previews = ActionMailer::Preview.all
|
15
18
|
@page_title = "Mailer Previews"
|
@@ -23,6 +26,7 @@ class Rails::MailersController < Rails::ApplicationController # :nodoc:
|
|
23
26
|
@email_action = File.basename(params[:path])
|
24
27
|
|
25
28
|
if @preview.email_exists?(@email_action)
|
29
|
+
@page_title = "Mailer Preview for #{@preview.preview_name}##{@email_action}"
|
26
30
|
@email = @preview.call(@email_action, params)
|
27
31
|
|
28
32
|
if params[:part]
|
@@ -36,7 +40,7 @@ class Rails::MailersController < Rails::ApplicationController # :nodoc:
|
|
36
40
|
end
|
37
41
|
else
|
38
42
|
@part = find_preferred_part(request.format, Mime[:html], Mime[:text])
|
39
|
-
render action: "email", layout: false, formats:
|
43
|
+
render action: "email", layout: false, formats: [:html]
|
40
44
|
end
|
41
45
|
else
|
42
46
|
raise AbstractController::ActionNotFound, "Email '#{@email_action}' not found in #{@preview.name}"
|
@@ -90,6 +94,8 @@ class Rails::MailersController < Rails::ApplicationController # :nodoc:
|
|
90
94
|
end
|
91
95
|
|
92
96
|
def set_locale
|
93
|
-
I18n.
|
97
|
+
I18n.with_locale(params[:locale] || I18n.default_locale) do
|
98
|
+
yield
|
99
|
+
end
|
94
100
|
end
|
95
101
|
end
|