railties 6.1.6 → 7.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +626 -259
- data/MIT-LICENSE +1 -1
- data/RDOC_MAIN.md +99 -0
- data/README.rdoc +5 -6
- data/lib/minitest/rails_plugin.rb +64 -1
- data/lib/rails/all.rb +0 -1
- data/lib/rails/api/task.rb +35 -4
- data/lib/rails/app_updater.rb +9 -6
- data/lib/rails/application/bootstrap.rb +41 -7
- data/lib/rails/application/configuration.rb +262 -88
- data/lib/rails/application/default_middleware_stack.rb +29 -4
- data/lib/rails/application/dummy_config.rb +19 -0
- data/lib/rails/application/finisher.rb +89 -124
- data/lib/rails/application/routes_reloader.rb +8 -0
- data/lib/rails/application.rb +200 -125
- data/lib/rails/application_controller.rb +3 -3
- data/lib/rails/autoloaders/inflector.rb +21 -0
- data/lib/rails/autoloaders.rb +42 -42
- data/lib/rails/backtrace_cleaner.rb +1 -1
- data/lib/rails/cli.rb +5 -2
- data/lib/rails/code_statistics.rb +2 -2
- data/lib/rails/code_statistics_calculator.rb +10 -1
- data/lib/rails/command/actions.rb +10 -12
- data/lib/rails/command/base.rb +61 -45
- data/lib/rails/command/behavior.rb +1 -1
- data/lib/rails/command/environment_argument.rb +33 -17
- data/lib/rails/command/helpers/editor.rb +17 -12
- data/lib/rails/command.rb +90 -36
- data/lib/rails/commands/about/about_command.rb +14 -0
- data/lib/rails/commands/application/application_command.rb +2 -0
- data/lib/rails/commands/console/console_command.rb +17 -13
- data/lib/rails/commands/credentials/USAGE +53 -53
- data/lib/rails/commands/credentials/credentials_command/diffing.rb +31 -19
- data/lib/rails/commands/credentials/credentials_command.rb +67 -69
- data/lib/rails/commands/db/system/change/change_command.rb +2 -1
- data/lib/rails/commands/dbconsole/dbconsole_command.rb +26 -117
- data/lib/rails/commands/destroy/destroy_command.rb +3 -2
- data/lib/rails/commands/dev/dev_command.rb +1 -6
- data/lib/rails/commands/encrypted/USAGE +15 -20
- data/lib/rails/commands/encrypted/encrypted_command.rb +46 -35
- data/lib/rails/commands/gem_help/USAGE +16 -0
- data/lib/rails/commands/gem_help/gem_help_command.rb +13 -0
- data/lib/rails/commands/generate/generate_command.rb +2 -2
- data/lib/rails/commands/help/USAGE +15 -14
- data/lib/rails/commands/help/help_command.rb +21 -2
- data/lib/rails/commands/initializers/initializers_command.rb +1 -4
- data/lib/rails/commands/middleware/middleware_command.rb +17 -0
- data/lib/rails/commands/new/new_command.rb +2 -0
- data/lib/rails/commands/notes/notes_command.rb +2 -1
- data/lib/rails/commands/plugin/plugin_command.rb +2 -0
- data/lib/rails/commands/rake/rake_command.rb +25 -22
- data/lib/rails/commands/restart/restart_command.rb +14 -0
- data/lib/rails/commands/routes/routes_command.rb +13 -1
- data/lib/rails/commands/runner/USAGE +14 -12
- data/lib/rails/commands/runner/runner_command.rb +34 -21
- data/lib/rails/commands/secret/secret_command.rb +13 -0
- data/lib/rails/commands/secrets/USAGE +44 -49
- data/lib/rails/commands/secrets/secrets_command.rb +20 -38
- data/lib/rails/commands/server/server_command.rb +33 -30
- data/lib/rails/commands/test/USAGE +14 -0
- data/lib/rails/commands/test/test_command.rb +56 -14
- data/lib/rails/commands/unused_routes/unused_routes_command.rb +75 -0
- data/lib/rails/commands/version/version_command.rb +1 -0
- data/lib/rails/configuration.rb +23 -28
- data/lib/rails/console/app.rb +1 -4
- data/lib/rails/console/helpers.rb +2 -2
- data/lib/rails/deprecator.rb +7 -0
- data/lib/rails/engine/configuration.rb +53 -9
- data/lib/rails/engine.rb +63 -48
- data/lib/rails/gem_version.rb +3 -3
- data/lib/rails/generators/actions/create_migration.rb +2 -4
- data/lib/rails/generators/actions.rb +231 -73
- data/lib/rails/generators/active_model.rb +28 -14
- data/lib/rails/generators/app_base.rb +476 -176
- data/lib/rails/generators/app_name.rb +3 -14
- data/lib/rails/generators/base.rb +24 -20
- data/lib/rails/generators/database.rb +39 -1
- data/lib/rails/generators/erb/mailer/templates/layout.html.erb.tt +1 -1
- data/lib/rails/generators/erb/scaffold/scaffold_generator.rb +2 -0
- data/lib/rails/generators/erb/scaffold/templates/_form.html.erb.tt +8 -8
- data/lib/rails/generators/erb/scaffold/templates/edit.html.erb.tt +8 -4
- data/lib/rails/generators/erb/scaffold/templates/index.html.erb.tt +11 -28
- data/lib/rails/generators/erb/scaffold/templates/new.html.erb.tt +7 -3
- data/lib/rails/generators/erb/scaffold/templates/partial.html.erb.tt +17 -0
- data/lib/rails/generators/erb/scaffold/templates/show.html.erb.tt +8 -17
- data/lib/rails/generators/erb.rb +1 -1
- data/lib/rails/generators/generated_attribute.rb +57 -9
- data/lib/rails/generators/migration.rb +2 -7
- data/lib/rails/generators/model_helpers.rb +3 -2
- data/lib/rails/generators/named_base.rb +13 -13
- data/lib/rails/generators/rails/app/USAGE +22 -6
- data/lib/rails/generators/rails/app/app_generator.rb +113 -114
- data/lib/rails/generators/rails/app/templates/Dockerfile.tt +103 -0
- data/lib/rails/generators/rails/app/templates/Gemfile.tt +43 -53
- data/lib/rails/generators/rails/app/templates/app/assets/stylesheets/application.css.tt +2 -2
- data/lib/rails/generators/rails/app/templates/app/mailers/application_mailer.rb.tt +2 -2
- data/lib/rails/generators/rails/app/templates/app/models/application_record.rb.tt +1 -1
- data/lib/rails/generators/rails/app/templates/app/views/layouts/application.html.erb.tt +3 -9
- data/lib/rails/generators/rails/app/templates/app/views/layouts/mailer.html.erb.tt +1 -1
- data/lib/rails/generators/rails/app/templates/bin/rails.tt +1 -4
- data/lib/rails/generators/rails/app/templates/bin/rake.tt +0 -3
- data/lib/rails/generators/rails/app/templates/bin/setup.tt +16 -12
- data/lib/rails/generators/rails/app/templates/config/application.rb.tt +6 -18
- data/lib/rails/generators/rails/app/templates/config/boot.rb.tt +1 -1
- data/lib/rails/generators/rails/app/templates/config/databases/jdbc.yml.tt +2 -2
- data/lib/rails/generators/rails/app/templates/config/databases/jdbcmysql.yml.tt +3 -3
- data/lib/rails/generators/rails/app/templates/config/databases/jdbcpostgresql.yml.tt +7 -7
- data/lib/rails/generators/rails/app/templates/config/databases/jdbcsqlite3.yml.tt +5 -5
- data/lib/rails/generators/rails/app/templates/config/databases/mysql.yml.tt +3 -3
- data/lib/rails/generators/rails/app/templates/config/databases/oracle.yml.tt +2 -2
- data/lib/rails/generators/rails/app/templates/config/databases/postgresql.yml.tt +7 -9
- data/lib/rails/generators/rails/app/templates/config/databases/sqlite3.yml.tt +4 -4
- data/lib/rails/generators/rails/app/templates/config/databases/sqlserver.yml.tt +5 -5
- data/lib/rails/generators/rails/app/templates/config/databases/trilogy.yml.tt +59 -0
- data/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt +16 -12
- data/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt +38 -61
- data/lib/rails/generators/rails/app/templates/config/environments/test.rb.tt +14 -15
- data/lib/rails/generators/rails/app/templates/config/initializers/assets.rb.tt +3 -5
- data/lib/rails/generators/rails/app/templates/config/initializers/content_security_policy.rb.tt +21 -28
- data/lib/rails/generators/rails/app/templates/config/initializers/cors.rb.tt +3 -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/inflections.rb.tt +4 -4
- data/lib/rails/generators/rails/app/templates/config/initializers/new_framework_defaults_7_1.rb.tt +283 -0
- data/lib/rails/generators/rails/app/templates/config/initializers/permissions_policy.rb.tt +11 -9
- data/lib/rails/generators/rails/app/templates/config/locales/en.yml +13 -15
- data/lib/rails/generators/rails/app/templates/config/puma.rb.tt +12 -20
- data/lib/rails/generators/rails/app/templates/config/routes.rb.tt +8 -1
- data/lib/rails/generators/rails/app/templates/config/storage.yml.tt +5 -5
- data/lib/rails/generators/rails/app/templates/db/seeds.rb.tt +6 -4
- data/lib/rails/generators/rails/app/templates/docker-entrypoint.tt +10 -0
- data/lib/rails/generators/rails/app/templates/dockerignore.tt +43 -0
- data/lib/rails/generators/rails/app/templates/gitattributes.tt +0 -5
- data/lib/rails/generators/rails/app/templates/gitignore.tt +7 -9
- data/lib/rails/generators/rails/app/templates/node-version.tt +1 -0
- data/lib/rails/generators/rails/app/templates/test/channels/application_cable/connection_test.rb.tt +10 -8
- data/lib/rails/generators/rails/app/templates/test/test_helper.rb.tt +10 -8
- data/lib/rails/generators/rails/application_record/application_record_generator.rb +4 -0
- data/lib/rails/generators/rails/benchmark/benchmark_generator.rb +2 -1
- data/lib/rails/generators/rails/controller/USAGE +12 -4
- data/lib/rails/generators/rails/controller/controller_generator.rb +6 -2
- data/lib/rails/generators/rails/controller/templates/controller.rb.tt +1 -5
- data/lib/rails/generators/rails/credentials/credentials_generator.rb +29 -24
- data/lib/rails/generators/rails/credentials/templates/credentials.yml.tt +8 -0
- data/lib/rails/generators/rails/db/system/change/change_generator.rb +31 -1
- data/lib/rails/generators/rails/encryption_key_file/encryption_key_file_generator.rb +1 -2
- data/lib/rails/generators/rails/generator/templates/%file_name%_generator.rb.tt +1 -1
- data/lib/rails/generators/rails/migration/USAGE +21 -11
- data/lib/rails/generators/rails/model/model_generator.rb +4 -0
- data/lib/rails/generators/rails/plugin/USAGE +17 -6
- data/lib/rails/generators/rails/plugin/plugin_generator.rb +69 -30
- data/lib/rails/generators/rails/plugin/templates/%name%.gemspec.tt +7 -3
- data/lib/rails/generators/rails/plugin/templates/Gemfile.tt +9 -31
- data/lib/rails/generators/rails/plugin/templates/MIT-LICENSE.tt +1 -1
- data/lib/rails/generators/rails/plugin/templates/README.md.tt +1 -1
- data/lib/rails/generators/rails/plugin/templates/app/mailers/%namespaced_name%/application_mailer.rb.tt +2 -2
- data/lib/rails/generators/rails/plugin/templates/app/views/layouts/%namespaced_name%/application.html.erb.tt +0 -3
- data/lib/rails/generators/rails/plugin/templates/bin/rails.tt +5 -20
- data/lib/rails/generators/rails/plugin/templates/gitignore.tt +0 -7
- data/lib/rails/generators/rails/plugin/templates/lib/%namespaced_name%/engine.rb.tt +2 -2
- data/lib/rails/generators/rails/plugin/templates/lib/%namespaced_name%/version.rb.tt +1 -1
- data/lib/rails/generators/rails/plugin/templates/rails/boot.rb.tt +2 -2
- data/lib/rails/generators/rails/plugin/templates/test/test_helper.rb.tt +6 -11
- data/lib/rails/generators/rails/resource/resource_generator.rb +6 -0
- data/lib/rails/generators/rails/scaffold/scaffold_generator.rb +2 -20
- data/lib/rails/generators/rails/scaffold_controller/scaffold_controller_generator.rb +1 -1
- data/lib/rails/generators/rails/scaffold_controller/templates/api_controller.rb.tt +1 -5
- data/lib/rails/generators/rails/scaffold_controller/templates/controller.rb.tt +6 -10
- data/lib/rails/generators/resource_helpers.rb +2 -2
- data/lib/rails/generators/test_case.rb +2 -2
- data/lib/rails/generators/test_unit/generator/templates/generator_test.rb.tt +1 -1
- data/lib/rails/generators/test_unit/model/templates/fixtures.yml.tt +2 -2
- data/lib/rails/generators/test_unit/scaffold/scaffold_generator.rb +4 -4
- data/lib/rails/generators/test_unit/scaffold/templates/api_functional_test.rb.tt +5 -5
- data/lib/rails/generators/test_unit/scaffold/templates/functional_test.rb.tt +7 -7
- data/lib/rails/generators/test_unit/scaffold/templates/system_test.rb.tt +9 -11
- data/lib/rails/generators/testing/{behaviour.rb → behavior.rb} +7 -5
- data/lib/rails/generators.rb +14 -29
- data/lib/rails/health_controller.rb +55 -0
- data/lib/rails/info.rb +2 -2
- data/lib/rails/info_controller.rb +31 -13
- data/lib/rails/initializable.rb +1 -1
- data/lib/rails/mailers_controller.rb +17 -9
- data/lib/rails/paths.rb +14 -11
- data/lib/rails/rack/logger.rb +16 -15
- data/lib/rails/rackup/server.rb +15 -0
- data/lib/rails/railtie/configuration.rb +15 -3
- data/lib/rails/railtie.rb +54 -31
- data/lib/rails/ruby_version_check.rb +5 -3
- data/lib/rails/secrets.rb +10 -8
- data/lib/rails/source_annotation_extractor.rb +68 -19
- data/lib/rails/tasks/engine.rake +8 -8
- data/lib/rails/tasks/framework.rake +4 -12
- data/lib/rails/tasks/log.rake +1 -1
- data/lib/rails/tasks/misc.rake +3 -14
- data/lib/rails/tasks/statistics.rake +8 -5
- data/lib/rails/tasks/tmp.rake +13 -6
- data/lib/rails/tasks/yarn.rake +8 -9
- data/lib/rails/tasks/zeitwerk.rake +14 -42
- data/lib/rails/tasks.rb +0 -2
- data/lib/rails/templates/layouts/application.html.erb +15 -0
- data/lib/rails/templates/rails/mailers/email.html.erb +45 -11
- data/lib/rails/templates/rails/mailers/index.html.erb +14 -7
- data/lib/rails/templates/rails/mailers/mailer.html.erb +11 -5
- data/lib/rails/templates/rails/welcome/index.html.erb +65 -48
- data/lib/rails/test_help.rb +13 -14
- data/lib/rails/test_unit/line_filtering.rb +1 -1
- data/lib/rails/test_unit/railtie.rb +0 -4
- data/lib/rails/test_unit/reporter.rb +6 -2
- data/lib/rails/test_unit/runner.rb +45 -20
- data/lib/rails/test_unit/test_parser.rb +88 -0
- data/lib/rails/test_unit/testing.rake +18 -43
- data/lib/rails/testing/maintain_test_schema.rb +16 -0
- data/lib/rails/version.rb +1 -1
- data/lib/rails/welcome_controller.rb +1 -0
- data/lib/rails/zeitwerk_checker.rb +15 -0
- data/lib/rails.rb +26 -15
- metadata +74 -42
- data/RDOC_MAIN.rdoc +0 -97
- data/lib/rails/.DS_Store +0 -0
- data/lib/rails/application/dummy_erb_compiler.rb +0 -18
- data/lib/rails/command/spellchecker.rb +0 -57
- data/lib/rails/generators/css/assets/assets_generator.rb +0 -15
- data/lib/rails/generators/css/assets/templates/stylesheet.css +0 -4
- data/lib/rails/generators/css/scaffold/scaffold_generator.rb +0 -18
- data/lib/rails/generators/rails/app/templates/app/javascript/channels/consumer.js +0 -6
- data/lib/rails/generators/rails/app/templates/app/javascript/channels/index.js +0 -5
- data/lib/rails/generators/rails/app/templates/app/javascript/packs/application.js.tt +0 -23
- data/lib/rails/generators/rails/app/templates/bin/spring.tt +0 -13
- data/lib/rails/generators/rails/app/templates/bin/yarn.tt +0 -16
- data/lib/rails/generators/rails/app/templates/config/initializers/application_controller_renderer.rb.tt +0 -8
- data/lib/rails/generators/rails/app/templates/config/initializers/backtrace_silencers.rb.tt +0 -8
- data/lib/rails/generators/rails/app/templates/config/initializers/cookies_serializer.rb.tt +0 -5
- data/lib/rails/generators/rails/app/templates/config/initializers/mime_types.rb.tt +0 -4
- data/lib/rails/generators/rails/app/templates/config/initializers/new_framework_defaults_6_1.rb.tt +0 -67
- data/lib/rails/generators/rails/app/templates/config/initializers/wrap_parameters.rb.tt +0 -16
- data/lib/rails/generators/rails/app/templates/config/spring.rb.tt +0 -6
- data/lib/rails/generators/rails/app/templates/package.json.tt +0 -11
- data/lib/rails/generators/rails/assets/USAGE +0 -16
- data/lib/rails/generators/rails/assets/assets_generator.rb +0 -26
- data/lib/rails/generators/rails/assets/templates/stylesheet.css +0 -4
- data/lib/rails/generators/rails/model/USAGE +0 -113
- data/lib/rails/generators/rails/scaffold/templates/scaffold.css +0 -80
- data/lib/rails/tasks/middleware.rake +0 -9
- data/lib/rails/tasks/restart.rake +0 -9
@@ -16,11 +16,11 @@ class <%= controller_class_name %>ControllerTest < ActionDispatch::IntegrationTe
|
|
16
16
|
end
|
17
17
|
|
18
18
|
test "should create <%= singular_table_name %>" do
|
19
|
-
assert_difference(
|
19
|
+
assert_difference("<%= class_name %>.count") do
|
20
20
|
post <%= index_helper %>_url, params: { <%= "#{singular_table_name}: { #{attributes_string} }" %> }, as: :json
|
21
21
|
end
|
22
22
|
|
23
|
-
assert_response
|
23
|
+
assert_response :created
|
24
24
|
end
|
25
25
|
|
26
26
|
test "should show <%= singular_table_name %>" do
|
@@ -30,15 +30,15 @@ class <%= controller_class_name %>ControllerTest < ActionDispatch::IntegrationTe
|
|
30
30
|
|
31
31
|
test "should update <%= singular_table_name %>" do
|
32
32
|
patch <%= show_helper %>, params: { <%= "#{singular_table_name}: { #{attributes_string} }" %> }, as: :json
|
33
|
-
assert_response
|
33
|
+
assert_response :success
|
34
34
|
end
|
35
35
|
|
36
36
|
test "should destroy <%= singular_table_name %>" do
|
37
|
-
assert_difference(
|
37
|
+
assert_difference("<%= class_name %>.count", -1) do
|
38
38
|
delete <%= show_helper %>, as: :json
|
39
39
|
end
|
40
40
|
|
41
|
-
assert_response
|
41
|
+
assert_response :no_content
|
42
42
|
end
|
43
43
|
end
|
44
44
|
<% end -%>
|
@@ -11,7 +11,7 @@ class <%= controller_class_name %>ControllerTest < ActionDispatch::IntegrationTe
|
|
11
11
|
end
|
12
12
|
|
13
13
|
test "should get index" do
|
14
|
-
get <%= index_helper %>
|
14
|
+
get <%= index_helper(type: :url) %>
|
15
15
|
assert_response :success
|
16
16
|
end
|
17
17
|
|
@@ -21,11 +21,11 @@ class <%= controller_class_name %>ControllerTest < ActionDispatch::IntegrationTe
|
|
21
21
|
end
|
22
22
|
|
23
23
|
test "should create <%= singular_table_name %>" do
|
24
|
-
assert_difference(
|
25
|
-
post <%= index_helper
|
24
|
+
assert_difference("<%= class_name %>.count") do
|
25
|
+
post <%= index_helper(type: :url) %>, params: { <%= "#{singular_table_name}: { #{attributes_string} }" %> }
|
26
26
|
end
|
27
27
|
|
28
|
-
assert_redirected_to <%=
|
28
|
+
assert_redirected_to <%= show_helper("#{class_name}.last") %>
|
29
29
|
end
|
30
30
|
|
31
31
|
test "should show <%= singular_table_name %>" do
|
@@ -40,15 +40,15 @@ class <%= controller_class_name %>ControllerTest < ActionDispatch::IntegrationTe
|
|
40
40
|
|
41
41
|
test "should update <%= singular_table_name %>" do
|
42
42
|
patch <%= show_helper %>, params: { <%= "#{singular_table_name}: { #{attributes_string} }" %> }
|
43
|
-
assert_redirected_to <%=
|
43
|
+
assert_redirected_to <%= show_helper %>
|
44
44
|
end
|
45
45
|
|
46
46
|
test "should destroy <%= singular_table_name %>" do
|
47
|
-
assert_difference(
|
47
|
+
assert_difference("<%= class_name %>.count", -1) do
|
48
48
|
delete <%= show_helper %>
|
49
49
|
end
|
50
50
|
|
51
|
-
assert_redirected_to <%= index_helper %>
|
51
|
+
assert_redirected_to <%= index_helper(type: :url) %>
|
52
52
|
end
|
53
53
|
end
|
54
54
|
<% end -%>
|
@@ -8,12 +8,12 @@ class <%= class_name.pluralize %>Test < ApplicationSystemTestCase
|
|
8
8
|
|
9
9
|
test "visiting the index" do
|
10
10
|
visit <%= plural_table_name %>_url
|
11
|
-
assert_selector "h1", text: "<%=
|
11
|
+
assert_selector "h1", text: "<%= human_name.pluralize %>"
|
12
12
|
end
|
13
13
|
|
14
|
-
test "
|
14
|
+
test "should create <%= human_name.downcase %>" do
|
15
15
|
visit <%= plural_table_name %>_url
|
16
|
-
click_on "New <%=
|
16
|
+
click_on "New <%= human_name.downcase %>"
|
17
17
|
|
18
18
|
<%- attributes_hash.each do |attr, value| -%>
|
19
19
|
<%- if boolean?(attr) -%>
|
@@ -28,9 +28,9 @@ class <%= class_name.pluralize %>Test < ApplicationSystemTestCase
|
|
28
28
|
click_on "Back"
|
29
29
|
end
|
30
30
|
|
31
|
-
test "
|
32
|
-
visit <%=
|
33
|
-
click_on "Edit", match: :first
|
31
|
+
test "should update <%= human_name %>" do
|
32
|
+
visit <%= singular_table_name %>_url(@<%= singular_table_name %>)
|
33
|
+
click_on "Edit this <%= human_name.downcase %>", match: :first
|
34
34
|
|
35
35
|
<%- attributes_hash.each do |attr, value| -%>
|
36
36
|
<%- if boolean?(attr) -%>
|
@@ -45,11 +45,9 @@ class <%= class_name.pluralize %>Test < ApplicationSystemTestCase
|
|
45
45
|
click_on "Back"
|
46
46
|
end
|
47
47
|
|
48
|
-
test "
|
49
|
-
visit <%=
|
50
|
-
|
51
|
-
click_on "Destroy", match: :first
|
52
|
-
end
|
48
|
+
test "should destroy <%= human_name %>" do
|
49
|
+
visit <%= singular_table_name %>_url(@<%= singular_table_name %>)
|
50
|
+
click_on "Destroy this <%= human_name.downcase %>", match: :first
|
53
51
|
|
54
52
|
assert_text "<%= human_name %> was successfully destroyed"
|
55
53
|
end
|
@@ -11,7 +11,7 @@ require "rails/generators"
|
|
11
11
|
module Rails
|
12
12
|
module Generators
|
13
13
|
module Testing
|
14
|
-
module
|
14
|
+
module Behavior
|
15
15
|
extend ActiveSupport::Concern
|
16
16
|
include ActiveSupport::Testing::Stream
|
17
17
|
|
@@ -66,9 +66,8 @@ module Rails
|
|
66
66
|
# printed by the generator.
|
67
67
|
def run_generator(args = default_arguments, config = {})
|
68
68
|
capture(:stdout) do
|
69
|
-
args += ["--skip-bundle"] unless args.include? "--dev"
|
70
|
-
args
|
71
|
-
args |= ["--skip-webpack-install"] unless args.include? "--no-skip-webpack-install"
|
69
|
+
args += ["--skip-bundle"] unless args.include?("--no-skip-bundle") || args.include?("--dev")
|
70
|
+
args += ["--skip-bootsnap"] unless args.include?("--no-skip-bootsnap") || args.include?("--skip-bootsnap")
|
72
71
|
|
73
72
|
generator_class.start(args, config.reverse_merge(destination_root: destination_root))
|
74
73
|
end
|
@@ -82,7 +81,7 @@ module Rails
|
|
82
81
|
# Create a Rails::Generators::GeneratedAttribute by supplying the
|
83
82
|
# attribute type and, optionally, the attribute name:
|
84
83
|
#
|
85
|
-
# create_generated_attribute(:string,
|
84
|
+
# create_generated_attribute(:string, "name")
|
86
85
|
def create_generated_attribute(attribute_type, name = "test", index = nil)
|
87
86
|
Rails::Generators::GeneratedAttribute.parse([name, attribute_type, index].compact.join(":"))
|
88
87
|
end
|
@@ -108,6 +107,9 @@ module Rails
|
|
108
107
|
Dir.glob("#{dirname}/[0-9]*_*.rb").grep(/\d+_#{file_name}.rb$/).first
|
109
108
|
end
|
110
109
|
end
|
110
|
+
|
111
|
+
include ActiveSupport::Deprecation::DeprecatedConstantAccessor
|
112
|
+
deprecate_constant "Behaviour", "Rails::Generators::Testing::Behavior", deprecator: Rails.deprecator
|
111
113
|
end
|
112
114
|
end
|
113
115
|
end
|
data/lib/rails/generators.rb
CHANGED
@@ -1,8 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
activesupport_path = File.expand_path("../../../activesupport/lib", __dir__)
|
4
|
-
$:.unshift(activesupport_path) if File.directory?(activesupport_path) && !$:.include?(activesupport_path)
|
5
|
-
|
6
3
|
require "thor/group"
|
7
4
|
require "rails/command"
|
8
5
|
|
@@ -33,13 +30,10 @@ module Rails
|
|
33
30
|
rails: {
|
34
31
|
actions: "-a",
|
35
32
|
orm: "-o",
|
36
|
-
javascripts: "-j",
|
37
|
-
javascript_engine: "-je",
|
33
|
+
javascripts: ["-j", "--js"],
|
38
34
|
resource_controller: "-c",
|
39
35
|
scaffold_controller: "-c",
|
40
36
|
stylesheets: "-y",
|
41
|
-
stylesheet_engine: "-se",
|
42
|
-
scaffold_stylesheet: "-ss",
|
43
37
|
template_engine: "-e",
|
44
38
|
test_framework: "-t"
|
45
39
|
},
|
@@ -60,9 +54,6 @@ module Rails
|
|
60
54
|
resource_controller: :controller,
|
61
55
|
resource_route: true,
|
62
56
|
scaffold_controller: :scaffold_controller,
|
63
|
-
stylesheets: true,
|
64
|
-
stylesheet_engine: :css,
|
65
|
-
scaffold_stylesheet: true,
|
66
57
|
system_tests: nil,
|
67
58
|
test_framework: nil,
|
68
59
|
template_engine: :erb
|
@@ -70,7 +61,7 @@ module Rails
|
|
70
61
|
}
|
71
62
|
|
72
63
|
class << self
|
73
|
-
def configure!(config)
|
64
|
+
def configure!(config) # :nodoc:
|
74
65
|
api_only! if config.api_only
|
75
66
|
no_color! unless config.colorize_logging
|
76
67
|
aliases.deep_merge! config.aliases
|
@@ -82,15 +73,15 @@ module Rails
|
|
82
73
|
after_generate_callbacks.replace config.after_generate_callbacks
|
83
74
|
end
|
84
75
|
|
85
|
-
def templates_path
|
76
|
+
def templates_path # :nodoc:
|
86
77
|
@templates_path ||= []
|
87
78
|
end
|
88
79
|
|
89
|
-
def aliases
|
80
|
+
def aliases # :nodoc:
|
90
81
|
@aliases ||= DEFAULT_ALIASES.dup
|
91
82
|
end
|
92
83
|
|
93
|
-
def options
|
84
|
+
def options # :nodoc:
|
94
85
|
@options ||= DEFAULT_OPTIONS.dup
|
95
86
|
end
|
96
87
|
|
@@ -135,14 +126,12 @@ module Rails
|
|
135
126
|
# Returns an array of generator namespaces that are hidden.
|
136
127
|
# Generator namespaces may be hidden for a variety of reasons.
|
137
128
|
# Some are aliased such as "rails:migration" and can be
|
138
|
-
# invoked with the shorter "migration"
|
139
|
-
# such as "css:scaffold".
|
129
|
+
# invoked with the shorter "migration".
|
140
130
|
def hidden_namespaces
|
141
131
|
@hidden_namespaces ||= begin
|
142
132
|
orm = options[:rails][:orm]
|
143
133
|
test = options[:rails][:test_framework]
|
144
134
|
template = options[:rails][:template_engine]
|
145
|
-
css = options[:rails][:stylesheet_engine]
|
146
135
|
|
147
136
|
[
|
148
137
|
"rails",
|
@@ -161,10 +150,6 @@ module Rails
|
|
161
150
|
"#{template}:controller",
|
162
151
|
"#{template}:scaffold",
|
163
152
|
"#{template}:mailer",
|
164
|
-
"#{css}:scaffold",
|
165
|
-
"#{css}:assets",
|
166
|
-
"css:assets",
|
167
|
-
"css:scaffold",
|
168
153
|
"action_text:install",
|
169
154
|
"action_mailbox:install"
|
170
155
|
]
|
@@ -178,7 +163,8 @@ module Rails
|
|
178
163
|
|
179
164
|
# Show help message with available generators.
|
180
165
|
def help(command = "generate")
|
181
|
-
puts "Usage:
|
166
|
+
puts "Usage:"
|
167
|
+
puts " bin/rails #{command} GENERATOR [args] [options]"
|
182
168
|
puts
|
183
169
|
puts "General options:"
|
184
170
|
puts " -h, [--help] # Print generator's options and usage"
|
@@ -241,7 +227,7 @@ module Rails
|
|
241
227
|
#
|
242
228
|
# Notice that "rails:generators:webrat" could be loaded as well, what
|
243
229
|
# Rails looks for is the first and last parts of the namespace.
|
244
|
-
def find_by_namespace(name, base = nil, context = nil)
|
230
|
+
def find_by_namespace(name, base = nil, context = nil) # :nodoc:
|
245
231
|
lookups = []
|
246
232
|
lookups << "#{base}:#{name}" if base
|
247
233
|
lookups << "#{name}:#{context}" if context
|
@@ -265,8 +251,8 @@ module Rails
|
|
265
251
|
invoke_fallbacks_for(name, base) || invoke_fallbacks_for(context, name)
|
266
252
|
end
|
267
253
|
|
268
|
-
# Receives a namespace, arguments and the behavior to invoke the generator.
|
269
|
-
# It's used as the default entry point for generate, destroy and update
|
254
|
+
# Receives a namespace, arguments, and the behavior to invoke the generator.
|
255
|
+
# It's used as the default entry point for generate, destroy, and update
|
270
256
|
# commands.
|
271
257
|
def invoke(namespace, args = ARGV, config = {})
|
272
258
|
names = namespace.to_s.split(":")
|
@@ -275,12 +261,11 @@ module Rails
|
|
275
261
|
klass.start(args, config)
|
276
262
|
run_after_generate_callback if config[:behavior] == :invoke
|
277
263
|
else
|
278
|
-
options
|
279
|
-
|
280
|
-
suggestion_msg = "Maybe you meant #{suggestion.inspect}?" if suggestion
|
264
|
+
options = sorted_groups.flat_map(&:last)
|
265
|
+
error = Command::CorrectableNameError.new("Could not find generator '#{namespace}'.", namespace, options)
|
281
266
|
|
282
267
|
puts <<~MSG
|
283
|
-
|
268
|
+
#{error.detailed_message}
|
284
269
|
Run `bin/rails generate --help` for more options.
|
285
270
|
MSG
|
286
271
|
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Rails
|
4
|
+
# Built-in Health Check Endpoint
|
5
|
+
#
|
6
|
+
# \Rails also comes with a built-in health check endpoint that is reachable at
|
7
|
+
# the +/up+ path. This endpoint will return a 200 status code if the app has
|
8
|
+
# booted with no exceptions, and a 500 status code otherwise.
|
9
|
+
#
|
10
|
+
# In production, many applications are required to report their status upstream,
|
11
|
+
# whether it's to an uptime monitor that will page an engineer when things go
|
12
|
+
# wrong, or a load balancer or Kubernetes controller used to determine a pod's
|
13
|
+
# health. This health check is designed to be a one-size fits all that will work
|
14
|
+
# in many situations.
|
15
|
+
#
|
16
|
+
# While any newly generated \Rails applications will have the health check at
|
17
|
+
# +/up+, you can configure the path to be anything you'd like in your
|
18
|
+
# <tt>"config/routes.rb"</tt>:
|
19
|
+
#
|
20
|
+
# Rails.application.routes.draw do
|
21
|
+
# get "healthz" => "rails/health#show", as: :rails_health_check
|
22
|
+
# end
|
23
|
+
#
|
24
|
+
# The health check will now be accessible via the +/healthz+ path.
|
25
|
+
#
|
26
|
+
# NOTE: This endpoint does not reflect the status of all of your application's
|
27
|
+
# dependencies, such as the database or redis cluster. Replace
|
28
|
+
# <tt>"rails/health#show"</tt> with your own controller action if you have
|
29
|
+
# application specific needs.
|
30
|
+
#
|
31
|
+
# Think carefully about what you want to check as it can lead to situations
|
32
|
+
# where your application is being restarted due to a third-party service going
|
33
|
+
# bad. Ideally, you should design your application to handle those outages
|
34
|
+
# gracefully.
|
35
|
+
class HealthController < ActionController::Base
|
36
|
+
rescue_from(Exception) { render_down }
|
37
|
+
|
38
|
+
def show
|
39
|
+
render_up
|
40
|
+
end
|
41
|
+
|
42
|
+
private
|
43
|
+
def render_up
|
44
|
+
render html: html_status(color: "green")
|
45
|
+
end
|
46
|
+
|
47
|
+
def render_down
|
48
|
+
render html: html_status(color: "red"), status: 500
|
49
|
+
end
|
50
|
+
|
51
|
+
def html_status(color:)
|
52
|
+
%(<!DOCTYPE html><html><body style="background-color: #{color}"></body></html>).html_safe
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
data/lib/rails/info.rb
CHANGED
@@ -4,7 +4,7 @@ require "cgi"
|
|
4
4
|
|
5
5
|
module Rails
|
6
6
|
# This module helps build the runtime properties that are displayed in
|
7
|
-
# Rails::InfoController responses. These include the active Rails version,
|
7
|
+
# Rails::InfoController responses. These include the active \Rails version,
|
8
8
|
# Ruby version, Rack version, and so on.
|
9
9
|
module Info
|
10
10
|
mattr_accessor :properties, default: []
|
@@ -21,7 +21,7 @@ module Rails
|
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
24
|
-
class << self
|
24
|
+
class << self # :nodoc:
|
25
25
|
def property(name, value = nil)
|
26
26
|
value ||= yield
|
27
27
|
properties << [name, value] if value
|
@@ -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::DebugView::
|
7
|
+
prepend_view_path ActionDispatch::DebugView::RESCUES_TEMPLATE_PATHS
|
8
8
|
layout -> { request.xhr? ? false : "application" }
|
9
9
|
|
10
10
|
before_action :require_local!
|
@@ -19,12 +19,12 @@ class Rails::InfoController < Rails::ApplicationController # :nodoc:
|
|
19
19
|
end
|
20
20
|
|
21
21
|
def routes
|
22
|
-
if
|
23
|
-
|
24
|
-
|
22
|
+
if query = params[:query]
|
23
|
+
query = URI::DEFAULT_PARSER.escape query
|
24
|
+
|
25
25
|
render json: {
|
26
|
-
exact:
|
27
|
-
fuzzy:
|
26
|
+
exact: matching_routes(query: query, exact_match: true),
|
27
|
+
fuzzy: matching_routes(query: query, exact_match: false)
|
28
28
|
}
|
29
29
|
else
|
30
30
|
@routes_inspector = ActionDispatch::Routing::RoutesInspector.new(_routes.routes)
|
@@ -33,13 +33,31 @@ class Rails::InfoController < Rails::ApplicationController # :nodoc:
|
|
33
33
|
end
|
34
34
|
|
35
35
|
private
|
36
|
-
def
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
36
|
+
def matching_routes(query:, exact_match:)
|
37
|
+
return [] if query.blank?
|
38
|
+
|
39
|
+
normalized_path = ("/" + query).squeeze("/")
|
40
|
+
query_without_url_or_path_suffix = query.gsub(/(\w)(_path$)/, '\1').gsub(/(\w)(_url$)/, '\1')
|
41
|
+
|
42
|
+
_routes.routes.filter_map do |route|
|
43
|
+
route_wrapper = ActionDispatch::Routing::RouteWrapper.new(route)
|
44
|
+
|
45
|
+
if exact_match
|
46
|
+
match = route.path.match(normalized_path)
|
47
|
+
match ||= (query_without_url_or_path_suffix === route_wrapper.name)
|
48
|
+
else
|
49
|
+
match = route_wrapper.path.match(query)
|
50
|
+
match ||= route_wrapper.name.include?(query_without_url_or_path_suffix)
|
51
|
+
end
|
52
|
+
|
53
|
+
match ||= (query === route_wrapper.verb)
|
54
|
+
|
55
|
+
unless match
|
56
|
+
controller_action = URI::DEFAULT_PARSER.escape(route_wrapper.reqs)
|
57
|
+
match = exact_match ? (query === controller_action) : controller_action.include?(query)
|
58
|
+
end
|
41
59
|
|
42
|
-
|
43
|
-
|
60
|
+
route_wrapper.path if match
|
61
|
+
end
|
44
62
|
end
|
45
63
|
end
|
data/lib/rails/initializable.rb
CHANGED
@@ -3,10 +3,10 @@
|
|
3
3
|
require "rails/application_controller"
|
4
4
|
|
5
5
|
class Rails::MailersController < Rails::ApplicationController # :nodoc:
|
6
|
-
prepend_view_path ActionDispatch::DebugView::
|
6
|
+
prepend_view_path ActionDispatch::DebugView::RESCUES_TEMPLATE_PATHS
|
7
7
|
|
8
|
-
around_action :set_locale, only: :preview
|
9
|
-
before_action :find_preview, only: :preview
|
8
|
+
around_action :set_locale, only: [:preview, :download]
|
9
|
+
before_action :find_preview, only: [:preview, :download]
|
10
10
|
before_action :require_local!, unless: :show_previews?
|
11
11
|
|
12
12
|
helper_method :part_query, :locale_query
|
@@ -15,12 +15,22 @@ class Rails::MailersController < Rails::ApplicationController # :nodoc:
|
|
15
15
|
|
16
16
|
def index
|
17
17
|
@previews = ActionMailer::Preview.all
|
18
|
-
@page_title = "Mailer Previews"
|
18
|
+
@page_title = "Action Mailer Previews"
|
19
|
+
end
|
20
|
+
|
21
|
+
def download
|
22
|
+
@email_action = File.basename(params[:path])
|
23
|
+
if @preview.email_exists?(@email_action)
|
24
|
+
@email = @preview.call(@email_action, params)
|
25
|
+
send_data @email.to_s, filename: "#{@email_action}.eml"
|
26
|
+
else
|
27
|
+
raise AbstractController::ActionNotFound, "Email '#{@email_action}' not found in #{@preview.name}"
|
28
|
+
end
|
19
29
|
end
|
20
30
|
|
21
31
|
def preview
|
22
32
|
if params[:path] == @preview.preview_name
|
23
|
-
@page_title = "Mailer Previews for #{@preview.preview_name}"
|
33
|
+
@page_title = "Action Mailer Previews for #{@preview.preview_name}"
|
24
34
|
render action: "mailer"
|
25
35
|
else
|
26
36
|
@email_action = File.basename(params[:path])
|
@@ -93,9 +103,7 @@ class Rails::MailersController < Rails::ApplicationController # :nodoc:
|
|
93
103
|
request.query_parameters.merge(locale: locale).to_query
|
94
104
|
end
|
95
105
|
|
96
|
-
def set_locale
|
97
|
-
I18n.with_locale(params[:locale] || I18n.default_locale)
|
98
|
-
yield
|
99
|
-
end
|
106
|
+
def set_locale(&block)
|
107
|
+
I18n.with_locale(params[:locale] || I18n.default_locale, &block)
|
100
108
|
end
|
101
109
|
end
|
data/lib/rails/paths.rb
CHANGED
@@ -4,21 +4,22 @@ require "pathname"
|
|
4
4
|
|
5
5
|
module Rails
|
6
6
|
module Paths
|
7
|
-
# This object is an extended hash that behaves as root of the
|
7
|
+
# This object is an extended hash that behaves as root of the Rails::Paths system.
|
8
8
|
# It allows you to collect information about how you want to structure your application
|
9
|
-
# paths through a Hash-like API. It requires you to give a physical path on initialization.
|
9
|
+
# paths through a Hash-like \API. It requires you to give a physical path on initialization.
|
10
10
|
#
|
11
11
|
# root = Root.new "/rails"
|
12
12
|
# root.add "app/controllers", eager_load: true
|
13
13
|
#
|
14
14
|
# The above command creates a new root object and adds "app/controllers" as a path.
|
15
|
-
# This means we can get a
|
15
|
+
# This means we can get a Rails::Paths::Path object back like below:
|
16
16
|
#
|
17
17
|
# path = root["app/controllers"]
|
18
18
|
# path.eager_load? # => true
|
19
19
|
# path.is_a?(Rails::Paths::Path) # => true
|
20
20
|
#
|
21
|
-
# The
|
21
|
+
# The Path[rdoc-ref:Rails::Paths::Path] object is simply an enumerable and
|
22
|
+
# allows you to easily add extra paths:
|
22
23
|
#
|
23
24
|
# path.is_a?(Enumerable) # => true
|
24
25
|
# path.to_ary.inspect # => ["app/controllers"]
|
@@ -26,17 +27,19 @@ module Rails
|
|
26
27
|
# path << "lib/controllers"
|
27
28
|
# path.to_ary.inspect # => ["app/controllers", "lib/controllers"]
|
28
29
|
#
|
29
|
-
# Notice that when you add a path using
|
30
|
-
#
|
31
|
-
#
|
30
|
+
# Notice that when you add a path using #add, the
|
31
|
+
# Path[rdoc-ref:Rails::Paths::Path] object created already contains the path
|
32
|
+
# with the same path value given to #add. In some situations, you may not
|
33
|
+
# want this behavior, so you can give <tt>:with</tt> as option.
|
32
34
|
#
|
33
35
|
# root.add "config/routes", with: "config/routes.rb"
|
34
36
|
# root["config/routes"].inspect # => ["config/routes.rb"]
|
35
37
|
#
|
36
|
-
# The
|
37
|
-
# eager_load
|
38
|
+
# The #add method accepts the following options as arguments:
|
39
|
+
# +eager_load+, +autoload+, +autoload_once+, and +glob+.
|
38
40
|
#
|
39
|
-
# Finally, the
|
41
|
+
# Finally, the Path[rdoc-ref:Rails::Paths::Path] object also provides a few
|
42
|
+
# helpers:
|
40
43
|
#
|
41
44
|
# root = Root.new "/rails"
|
42
45
|
# root.add "app/controllers"
|
@@ -44,7 +47,7 @@ module Rails
|
|
44
47
|
# root["app/controllers"].expanded # => ["/rails/app/controllers"]
|
45
48
|
# root["app/controllers"].existent # => ["/rails/app/controllers"]
|
46
49
|
#
|
47
|
-
# Check the
|
50
|
+
# Check the Rails::Paths::Path documentation for more information.
|
48
51
|
class Root
|
49
52
|
attr_accessor :path
|
50
53
|
|
data/lib/rails/rack/logger.rb
CHANGED
@@ -1,9 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require "active_support/core_ext/time/conversions"
|
4
|
-
require "active_support/core_ext/object/blank"
|
5
4
|
require "active_support/log_subscriber"
|
6
|
-
require "action_dispatch/http/request"
|
7
5
|
require "rack/body_proxy"
|
8
6
|
|
9
7
|
module Rails
|
@@ -23,7 +21,7 @@ module Rails
|
|
23
21
|
request = ActionDispatch::Request.new(env)
|
24
22
|
|
25
23
|
if logger.respond_to?(:tagged)
|
26
|
-
logger.tagged(compute_tags(request)) { call_app(request, env) }
|
24
|
+
logger.tagged(*compute_tags(request)) { call_app(request, env) }
|
27
25
|
else
|
28
26
|
call_app(request, env)
|
29
27
|
end
|
@@ -32,13 +30,21 @@ module Rails
|
|
32
30
|
private
|
33
31
|
def call_app(request, env) # :doc:
|
34
32
|
instrumenter = ActiveSupport::Notifications.instrumenter
|
35
|
-
instrumenter.
|
33
|
+
handle = instrumenter.build_handle("request.action_dispatch", { request: request })
|
34
|
+
handle.start
|
35
|
+
|
36
36
|
logger.info { started_request_message(request) }
|
37
|
-
status, headers, body = @app.call(env)
|
38
|
-
body = ::Rack::BodyProxy.new(body
|
39
|
-
|
37
|
+
status, headers, body = response = @app.call(env)
|
38
|
+
body = ::Rack::BodyProxy.new(body, &handle.method(:finish))
|
39
|
+
|
40
|
+
if response.frozen?
|
41
|
+
[status, headers, body]
|
42
|
+
else
|
43
|
+
response[2] = body
|
44
|
+
response
|
45
|
+
end
|
40
46
|
rescue Exception
|
41
|
-
finish
|
47
|
+
handle.finish
|
42
48
|
raise
|
43
49
|
ensure
|
44
50
|
ActiveSupport::LogSubscriber.flush_all!
|
@@ -46,11 +52,11 @@ module Rails
|
|
46
52
|
|
47
53
|
# Started GET "/session/new" for 127.0.0.1 at 2012-09-26 14:51:42 -0700
|
48
54
|
def started_request_message(request) # :doc:
|
49
|
-
'Started %s "%s" for %s at %s'
|
55
|
+
sprintf('Started %s "%s" for %s at %s',
|
50
56
|
request.raw_request_method,
|
51
57
|
request.filtered_path,
|
52
58
|
request.remote_ip,
|
53
|
-
Time.now
|
59
|
+
Time.now)
|
54
60
|
end
|
55
61
|
|
56
62
|
def compute_tags(request) # :doc:
|
@@ -66,11 +72,6 @@ module Rails
|
|
66
72
|
end
|
67
73
|
end
|
68
74
|
|
69
|
-
def finish(request)
|
70
|
-
instrumenter = ActiveSupport::Notifications.instrumenter
|
71
|
-
instrumenter.finish "request.action_dispatch", request: request
|
72
|
-
end
|
73
|
-
|
74
75
|
def logger
|
75
76
|
Rails.logger
|
76
77
|
end
|