railties 7.2.3 → 8.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +168 -256
- data/lib/minitest/rails_plugin.rb +8 -1
- data/lib/rails/application/bootstrap.rb +0 -1
- data/lib/rails/application/configuration.rb +17 -14
- data/lib/rails/application/default_middleware_stack.rb +4 -0
- data/lib/rails/application/finisher.rb +2 -3
- data/lib/rails/application/routes_reloader.rb +17 -3
- data/lib/rails/application.rb +10 -1
- data/lib/rails/application_controller.rb +2 -0
- data/lib/rails/backtrace_cleaner.rb +2 -2
- data/lib/rails/code_statistics.rb +128 -86
- data/lib/rails/code_statistics_calculator.rb +78 -76
- data/lib/rails/command/helpers/editor.rb +1 -1
- data/lib/rails/command.rb +0 -6
- data/lib/rails/commands/app/update_command.rb +5 -9
- data/lib/rails/commands/console/irb_console.rb +3 -6
- data/lib/rails/commands/credentials/USAGE +4 -4
- data/lib/rails/commands/credentials/credentials_command.rb +5 -1
- data/lib/rails/commands/dev/dev_command.rb +1 -1
- data/lib/rails/commands/devcontainer/devcontainer_command.rb +2 -1
- data/lib/rails/commands/stats/stats_command.rb +19 -0
- data/lib/rails/console/methods.rb +5 -21
- data/lib/rails/dev_caching.rb +2 -2
- data/lib/rails/engine/configuration.rb +3 -1
- data/lib/rails/engine/lazy_route_set.rb +111 -0
- data/lib/rails/engine.rb +10 -6
- data/lib/rails/gem_version.rb +3 -3
- data/lib/rails/generators/actions.rb +3 -3
- data/lib/rails/generators/app_base.rb +76 -56
- data/lib/rails/generators/base.rb +0 -4
- data/lib/rails/generators/bundle_helper.rb +34 -0
- data/lib/rails/generators/database.rb +101 -67
- data/lib/rails/generators/erb/authentication/authentication_generator.rb +15 -0
- data/lib/rails/generators/erb/authentication/templates/app/views/passwords/edit.html.erb +9 -0
- data/lib/rails/generators/erb/authentication/templates/app/views/passwords/new.html.erb +8 -0
- data/lib/rails/generators/erb/authentication/templates/app/views/sessions/new.html.erb +11 -0
- data/lib/rails/generators/generated_attribute.rb +16 -11
- data/lib/rails/generators/rails/app/app_generator.rb +30 -30
- data/lib/rails/generators/rails/app/templates/Dockerfile.tt +23 -6
- data/lib/rails/generators/rails/app/templates/Gemfile.tt +27 -12
- data/lib/rails/generators/rails/app/templates/app/assets/stylesheets/application.css.tt +6 -11
- data/lib/rails/generators/rails/app/templates/app/views/layouts/application.html.erb.tt +10 -3
- data/lib/rails/generators/rails/app/templates/bin/dev.tt +1 -0
- data/lib/rails/generators/rails/app/templates/bin/setup.tt +5 -8
- data/lib/rails/generators/rails/app/templates/bin/thrust.tt +4 -0
- data/lib/rails/generators/rails/app/templates/config/databases/mysql.yml.tt +24 -1
- data/lib/rails/generators/rails/app/templates/config/databases/postgresql.yml.tt +23 -0
- data/lib/rails/generators/rails/app/templates/config/databases/sqlite3.yml.tt +50 -0
- data/lib/rails/generators/rails/app/templates/config/databases/trilogy.yml.tt +30 -5
- data/lib/rails/generators/rails/app/templates/config/deploy.yml.tt +128 -0
- data/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt +12 -23
- data/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt +31 -51
- data/lib/rails/generators/rails/app/templates/config/environments/test.rb.tt +5 -19
- data/lib/rails/generators/rails/app/templates/config/initializers/assets.rb.tt +0 -7
- data/lib/rails/generators/rails/app/templates/config/initializers/filter_parameter_logging.rb.tt +1 -1
- data/lib/rails/generators/rails/app/templates/config/initializers/new_framework_defaults_8_0.rb.tt +30 -0
- data/lib/rails/generators/rails/app/templates/config/puma.rb.tt +11 -2
- data/lib/rails/generators/rails/app/templates/config/routes.rb.tt +3 -3
- data/lib/rails/generators/rails/app/templates/docker-entrypoint.tt +4 -3
- data/lib/rails/generators/rails/app/templates/dockerignore.tt +7 -2
- data/lib/rails/generators/rails/app/templates/github/ci.yml.tt +12 -6
- data/lib/rails/generators/rails/app/templates/gitignore.tt +1 -2
- data/lib/rails/generators/rails/app/templates/kamal-secrets.tt +17 -0
- data/lib/rails/generators/rails/app/templates/public/400.html +114 -0
- data/lib/rails/generators/rails/app/templates/public/404.html +113 -66
- data/lib/rails/generators/rails/app/templates/public/406-unsupported-browser.html +113 -65
- data/lib/rails/generators/rails/app/templates/public/422.html +113 -66
- data/lib/rails/generators/rails/app/templates/public/500.html +113 -65
- data/lib/rails/generators/rails/app/templates/public/icon.png +0 -0
- data/lib/rails/generators/rails/app/templates/public/icon.svg +2 -2
- data/lib/rails/generators/rails/app/templates/ruby-version.tt +1 -1
- data/lib/rails/generators/rails/authentication/USAGE +6 -0
- data/lib/rails/generators/rails/authentication/authentication_generator.rb +60 -0
- data/lib/rails/generators/rails/authentication/templates/app/channels/application_cable/connection.rb.tt +16 -0
- data/lib/rails/generators/rails/authentication/templates/app/controllers/concerns/authentication.rb.tt +52 -0
- data/lib/rails/generators/rails/authentication/templates/app/controllers/passwords_controller.rb.tt +33 -0
- data/lib/rails/generators/rails/authentication/templates/app/controllers/sessions_controller.rb.tt +21 -0
- data/lib/rails/generators/rails/authentication/templates/app/mailers/passwords_mailer.rb.tt +6 -0
- data/lib/rails/generators/rails/authentication/templates/app/models/current.rb.tt +4 -0
- data/lib/rails/generators/rails/authentication/templates/app/models/session.rb.tt +3 -0
- data/lib/rails/generators/rails/authentication/templates/app/models/user.rb.tt +6 -0
- data/lib/rails/generators/rails/authentication/templates/app/views/passwords_mailer/reset.html.erb.tt +4 -0
- data/lib/rails/generators/rails/authentication/templates/app/views/passwords_mailer/reset.text.erb.tt +2 -0
- data/lib/rails/generators/rails/credentials/templates/credentials.yml.tt +4 -0
- data/lib/rails/generators/rails/db/system/change/change_generator.rb +1 -1
- data/lib/rails/generators/rails/devcontainer/devcontainer_generator.rb +12 -2
- data/lib/rails/generators/rails/devcontainer/templates/devcontainer/Dockerfile.tt +1 -1
- data/lib/rails/generators/rails/devcontainer/templates/devcontainer/devcontainer.json.tt +5 -5
- data/lib/rails/generators/rails/plugin/plugin_generator.rb +7 -9
- data/lib/rails/generators/rails/plugin/templates/Gemfile.tt +1 -1
- data/lib/rails/generators/rails/plugin/templates/github/ci.yml.tt +3 -3
- 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 +3 -3
- data/lib/rails/generators/rails/script/USAGE +18 -0
- data/lib/rails/generators/rails/script/script_generator.rb +18 -0
- data/lib/rails/generators/rails/script/templates/script.rb.tt +3 -0
- data/lib/rails/generators/test_unit/authentication/authentication_generator.rb +18 -0
- data/lib/rails/generators/test_unit/authentication/templates/test/fixtures/users.yml.tt +9 -0
- data/lib/rails/generators/test_unit/authentication/templates/test/mailers/previews/passwords_mailer_preview.rb.tt +7 -0
- data/lib/rails/generators/test_unit/authentication/templates/test/models/user_test.rb.tt +7 -0
- data/lib/rails/generators.rb +1 -0
- data/lib/rails/health_controller.rb +2 -0
- data/lib/rails/info.rb +2 -1
- data/lib/rails/info_controller.rb +10 -4
- data/lib/rails/rack/silence_request.rb +33 -0
- data/lib/rails/rack.rb +1 -0
- data/lib/rails/source_annotation_extractor.rb +37 -16
- data/lib/rails/tasks/statistics.rake +13 -28
- data/lib/rails/templates/rails/info/notes.html.erb +65 -0
- data/lib/rails/templates/rails/mailers/email.html.erb +1 -1
- data/lib/rails/test_unit/line_filtering.rb +24 -3
- data/lib/rails/test_unit/reporter.rb +8 -4
- data/lib/rails/test_unit/runner.rb +1 -0
- metadata +46 -37
- data/lib/rails/console/app.rb +0 -8
- data/lib/rails/console/helpers.rb +0 -8
- data/lib/rails/generators/rails/app/templates/app/assets/config/manifest.js.tt +0 -2
- data/lib/rails/generators/rails/app/templates/app/channels/application_cable/channel.rb.tt +0 -4
- data/lib/rails/generators/rails/app/templates/app/channels/application_cable/connection.rb.tt +0 -4
- data/lib/rails/generators/rails/app/templates/config/initializers/new_framework_defaults_7_2.rb.tt +0 -70
- data/lib/rails/generators/rails/app/templates/config/initializers/permissions_policy.rb.tt +0 -13
- data/lib/rails/generators/rails/app/templates/test/channels/application_cable/connection_test.rb.tt +0 -13
- data/lib/rails/generators/rails/plugin/templates/rails/dummy_manifest.js.tt +0 -10
- data/lib/rails/generators/rails/plugin/templates/rails/engine_manifest.js.tt +0 -6
- data/lib/rails/generators/rails/plugin/templates/rails/javascripts.js.tt +0 -17
|
@@ -43,13 +43,13 @@ class <%= controller_class_name %>Controller < ApplicationController
|
|
|
43
43
|
# DELETE <%= route_url %>/1
|
|
44
44
|
def destroy
|
|
45
45
|
@<%= orm_instance.destroy %>
|
|
46
|
-
redirect_to <%= index_helper %>
|
|
46
|
+
redirect_to <%= index_helper %>_path, notice: <%= %("#{human_name} was successfully destroyed.") %>, status: :see_other
|
|
47
47
|
end
|
|
48
48
|
|
|
49
49
|
private
|
|
50
50
|
# Use callbacks to share common setup or constraints between actions.
|
|
51
51
|
def set_<%= singular_table_name %>
|
|
52
|
-
@<%= singular_table_name %> = <%= orm_class.find(class_name, "params
|
|
52
|
+
@<%= singular_table_name %> = <%= orm_class.find(class_name, "params.expect(:id)") %>
|
|
53
53
|
end
|
|
54
54
|
|
|
55
55
|
# Only allow a list of trusted parameters through.
|
|
@@ -57,7 +57,7 @@ class <%= controller_class_name %>Controller < ApplicationController
|
|
|
57
57
|
<%- if attributes_names.empty? -%>
|
|
58
58
|
params.fetch(:<%= singular_table_name %>, {})
|
|
59
59
|
<%- else -%>
|
|
60
|
-
params.
|
|
60
|
+
params.expect(<%= singular_table_name %>: [ <%= permitted_params %> ])
|
|
61
61
|
<%- end -%>
|
|
62
62
|
end
|
|
63
63
|
end
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
Description:
|
|
2
|
+
Generate a one-off or general purpose script, such as a data migration
|
|
3
|
+
script, cleanup script, etc.
|
|
4
|
+
|
|
5
|
+
Example:
|
|
6
|
+
`bin/rails generate script my_script`
|
|
7
|
+
|
|
8
|
+
This will create:
|
|
9
|
+
script/my_script.rb
|
|
10
|
+
|
|
11
|
+
You can run the script using:
|
|
12
|
+
`ruby script/my_script.rb`
|
|
13
|
+
|
|
14
|
+
You can specify a folder:
|
|
15
|
+
`bin/rails generate script cleanup/my_script`
|
|
16
|
+
|
|
17
|
+
This will create:
|
|
18
|
+
script/cleanup/my_script.rb
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "rails/generators/named_base"
|
|
4
|
+
|
|
5
|
+
module Rails
|
|
6
|
+
module Generators
|
|
7
|
+
class ScriptGenerator < NamedBase
|
|
8
|
+
def generate_script
|
|
9
|
+
template("script.rb.tt", "script/#{file_path}.rb")
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
private
|
|
13
|
+
def depth
|
|
14
|
+
class_path.size + 1
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "rails/generators/test_unit"
|
|
4
|
+
|
|
5
|
+
module TestUnit # :nodoc:
|
|
6
|
+
module Generators # :nodoc:
|
|
7
|
+
class AuthenticationGenerator < Rails::Generators::Base # :nodoc:
|
|
8
|
+
def create_user_test_files
|
|
9
|
+
template "test/fixtures/users.yml"
|
|
10
|
+
template "test/models/user_test.rb"
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def create_mailer_preview_files
|
|
14
|
+
template "test/mailers/previews/passwords_mailer_preview.rb" if defined?(ActionMailer::Railtie)
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
# Preview all emails at http://localhost:3000/rails/mailers/passwords_mailer
|
|
2
|
+
class PasswordsMailerPreview < ActionMailer::Preview
|
|
3
|
+
# Preview this email at http://localhost:3000/rails/mailers/passwords_mailer/reset
|
|
4
|
+
def reset
|
|
5
|
+
PasswordsMailer.reset(User.take)
|
|
6
|
+
end
|
|
7
|
+
end
|
data/lib/rails/generators.rb
CHANGED
data/lib/rails/info.rb
CHANGED
|
@@ -7,8 +7,6 @@ class Rails::InfoController < Rails::ApplicationController # :nodoc:
|
|
|
7
7
|
prepend_view_path ActionDispatch::DebugView::RESCUES_TEMPLATE_PATHS
|
|
8
8
|
layout -> { request.xhr? ? false : "application" }
|
|
9
9
|
|
|
10
|
-
RFC2396_PARSER = defined?(URI::RFC2396_PARSER) ? URI::RFC2396_PARSER : URI::RFC2396_Parser.new
|
|
11
|
-
|
|
12
10
|
before_action :require_local!
|
|
13
11
|
|
|
14
12
|
def index
|
|
@@ -22,7 +20,7 @@ class Rails::InfoController < Rails::ApplicationController # :nodoc:
|
|
|
22
20
|
|
|
23
21
|
def routes
|
|
24
22
|
if query = params[:query]
|
|
25
|
-
query = RFC2396_PARSER.escape query
|
|
23
|
+
query = URI::RFC2396_PARSER.escape query
|
|
26
24
|
|
|
27
25
|
render json: {
|
|
28
26
|
exact: matching_routes(query: query, exact_match: true),
|
|
@@ -34,6 +32,14 @@ class Rails::InfoController < Rails::ApplicationController # :nodoc:
|
|
|
34
32
|
end
|
|
35
33
|
end
|
|
36
34
|
|
|
35
|
+
def notes
|
|
36
|
+
@annotations = Rails::SourceAnnotationExtractor.new(
|
|
37
|
+
Rails::SourceAnnotationExtractor::Annotation.tags.join("|")
|
|
38
|
+
).find(
|
|
39
|
+
Rails::SourceAnnotationExtractor::Annotation.directories
|
|
40
|
+
)
|
|
41
|
+
end
|
|
42
|
+
|
|
37
43
|
private
|
|
38
44
|
def matching_routes(query:, exact_match:)
|
|
39
45
|
return [] if query.blank?
|
|
@@ -55,7 +61,7 @@ class Rails::InfoController < Rails::ApplicationController # :nodoc:
|
|
|
55
61
|
match ||= (query === route_wrapper.verb)
|
|
56
62
|
|
|
57
63
|
unless match
|
|
58
|
-
controller_action = RFC2396_PARSER.escape(route_wrapper.reqs)
|
|
64
|
+
controller_action = URI::RFC2396_PARSER.escape(route_wrapper.reqs)
|
|
59
65
|
match = exact_match ? (query === controller_action) : controller_action.include?(query)
|
|
60
66
|
end
|
|
61
67
|
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# :markup: markdown
|
|
4
|
+
|
|
5
|
+
require "active_support/logger_silence"
|
|
6
|
+
|
|
7
|
+
module Rails
|
|
8
|
+
module Rack
|
|
9
|
+
# Allows you to silence requests made to a specific path.
|
|
10
|
+
# This is useful for preventing recurring requests like health checks from clogging the logging.
|
|
11
|
+
# This middleware is used to do just that against the path /up in production by default.
|
|
12
|
+
#
|
|
13
|
+
# Example:
|
|
14
|
+
#
|
|
15
|
+
# config.middleware.insert_before \
|
|
16
|
+
# Rails::Rack::Logger, Rails::Rack::SilenceRequest, path: "/up"
|
|
17
|
+
#
|
|
18
|
+
# This middleware can also be configured using `config.silence_healthcheck_path = "/up"` in Rails.
|
|
19
|
+
class SilenceRequest
|
|
20
|
+
def initialize(app, path:)
|
|
21
|
+
@app, @path = app, path
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def call(env)
|
|
25
|
+
if env["PATH_INFO"] == @path
|
|
26
|
+
Rails.logger.silence { @app.call(env) }
|
|
27
|
+
else
|
|
28
|
+
@app.call(env)
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
data/lib/rails/rack.rb
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
begin
|
|
4
|
+
require "prism"
|
|
5
|
+
rescue LoadError
|
|
6
|
+
# If Prism isn't available (because of using an older Ruby version) then we'll
|
|
7
|
+
# define a fallback for the ParserExtractor using ripper.
|
|
8
|
+
require "ripper"
|
|
9
|
+
end
|
|
4
10
|
|
|
5
11
|
module Rails
|
|
6
12
|
# Implements the logic behind +Rails::Command::NotesCommand+. See <tt>rails notes --help</tt> for usage information.
|
|
@@ -16,24 +22,35 @@ module Rails
|
|
|
16
22
|
# Wraps a regular expression that will be tested against each of the source
|
|
17
23
|
# file's comments.
|
|
18
24
|
class ParserExtractor < Struct.new(:pattern)
|
|
19
|
-
|
|
20
|
-
|
|
25
|
+
if defined?(Prism)
|
|
26
|
+
def annotations(file)
|
|
27
|
+
result = Prism.parse_file(file)
|
|
28
|
+
return [] unless result.success?
|
|
21
29
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
@comments = []
|
|
30
|
+
result.comments.filter_map do |comment|
|
|
31
|
+
Annotation.new(comment.location.start_line, $1, $2) if comment.location.slice =~ pattern
|
|
32
|
+
end
|
|
26
33
|
end
|
|
34
|
+
else
|
|
35
|
+
class Parser < Ripper
|
|
36
|
+
attr_reader :comments, :pattern
|
|
37
|
+
|
|
38
|
+
def initialize(source, pattern:)
|
|
39
|
+
super(source)
|
|
40
|
+
@pattern = pattern
|
|
41
|
+
@comments = []
|
|
42
|
+
end
|
|
27
43
|
|
|
28
|
-
|
|
29
|
-
|
|
44
|
+
def on_comment(value)
|
|
45
|
+
@comments << Annotation.new(lineno, $1, $2) if value =~ pattern
|
|
46
|
+
end
|
|
30
47
|
end
|
|
31
|
-
end
|
|
32
48
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
49
|
+
def annotations(file)
|
|
50
|
+
contents = File.read(file, encoding: Encoding::BINARY)
|
|
51
|
+
parser = Parser.new(contents, pattern: pattern).tap(&:parse)
|
|
52
|
+
parser.error? ? [] : parser.comments
|
|
53
|
+
end
|
|
37
54
|
end
|
|
38
55
|
end
|
|
39
56
|
|
|
@@ -90,10 +107,14 @@ module Rails
|
|
|
90
107
|
PatternExtractor.new(/#\s*(#{tag}):?\s*(.*)$/)
|
|
91
108
|
end
|
|
92
109
|
|
|
93
|
-
register_extensions("
|
|
110
|
+
register_extensions("js") do |tag|
|
|
94
111
|
PatternExtractor.new(/\/\/\s*(#{tag}):?\s*(.*)$/)
|
|
95
112
|
end
|
|
96
113
|
|
|
114
|
+
register_extensions("css") do |tag|
|
|
115
|
+
PatternExtractor.new(/\/\*\s*(#{tag}):?\s*(.*?)(?:\*\/)?$/)
|
|
116
|
+
end
|
|
117
|
+
|
|
97
118
|
register_extensions("erb") do |tag|
|
|
98
119
|
PatternExtractor.new(/<%\s*#\s*(#{tag}):?\s*(.*?)\s*%>/)
|
|
99
120
|
end
|
|
@@ -188,7 +209,7 @@ module Rails
|
|
|
188
209
|
results.keys.sort.each do |file|
|
|
189
210
|
puts "#{file}:"
|
|
190
211
|
results[file].each do |note|
|
|
191
|
-
puts " * #{note.to_s(options)}"
|
|
212
|
+
puts " * #{note.to_s(options).strip}"
|
|
192
213
|
end
|
|
193
214
|
puts
|
|
194
215
|
end
|
|
@@ -1,32 +1,11 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
STATS_DIRECTORIES
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
%w(Jobs app/jobs),
|
|
10
|
-
%w(Models app/models),
|
|
11
|
-
%w(Mailers app/mailers),
|
|
12
|
-
%w(Mailboxes app/mailboxes),
|
|
13
|
-
%w(Channels app/channels),
|
|
14
|
-
%w(Views app/views),
|
|
15
|
-
%w(JavaScripts app/assets/javascripts),
|
|
16
|
-
%w(Stylesheets app/assets/stylesheets),
|
|
17
|
-
%w(JavaScript app/javascript),
|
|
18
|
-
%w(Libraries lib/),
|
|
19
|
-
%w(APIs app/apis),
|
|
20
|
-
%w(Controller\ tests test/controllers),
|
|
21
|
-
%w(Helper\ tests test/helpers),
|
|
22
|
-
%w(Job\ tests test/jobs),
|
|
23
|
-
%w(Model\ tests test/models),
|
|
24
|
-
%w(Mailer\ tests test/mailers),
|
|
25
|
-
%w(Mailbox\ tests test/mailboxes),
|
|
26
|
-
%w(Channel\ tests test/channels),
|
|
27
|
-
%w(Integration\ tests test/integration),
|
|
28
|
-
%w(System\ tests test/system),
|
|
29
|
-
]
|
|
3
|
+
require "rails/code_statistics"
|
|
4
|
+
STATS_DIRECTORIES = ActiveSupport::Deprecation::DeprecatedObjectProxy.new(
|
|
5
|
+
Rails::CodeStatistics::DIRECTORIES,
|
|
6
|
+
"`STATS_DIRECTORIES` is deprecated and will be removed in Rails 8.1! Use `Rails::CodeStatistics.register_directory('My Directory', 'path/to/dir)` instead.",
|
|
7
|
+
Rails.deprecator
|
|
8
|
+
)
|
|
30
9
|
|
|
31
10
|
desc "Report code statistics (KLOCs, etc) from the application or engine"
|
|
32
11
|
task :stats do
|
|
@@ -34,5 +13,11 @@ task :stats do
|
|
|
34
13
|
stat_directories = STATS_DIRECTORIES.collect do |name, dir|
|
|
35
14
|
[ name, "#{File.dirname(Rake.application.rakefile_location)}/#{dir}" ]
|
|
36
15
|
end.select { |name, dir| File.directory?(dir) }
|
|
37
|
-
|
|
16
|
+
|
|
17
|
+
$stderr.puts Rails.deprecator.warn(<<~MSG, caller_locations(0..1))
|
|
18
|
+
`bin/rake stats` has been deprecated and will be removed in Rails 8.1.
|
|
19
|
+
Please use `bin/rails stats` as Rails command instead.\n
|
|
20
|
+
MSG
|
|
21
|
+
|
|
22
|
+
Rails::CodeStatistics.new(*stat_directories).to_s
|
|
38
23
|
end
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
<style>
|
|
2
|
+
h2, p {
|
|
3
|
+
padding-left: 30px;
|
|
4
|
+
}
|
|
5
|
+
table {
|
|
6
|
+
margin: 0;
|
|
7
|
+
border-collapse: collapse;
|
|
8
|
+
word-wrap:break-word;
|
|
9
|
+
table-layout: fixed;
|
|
10
|
+
width:100%;
|
|
11
|
+
}
|
|
12
|
+
table thead tr {
|
|
13
|
+
border-bottom: 2px solid #ddd;
|
|
14
|
+
}
|
|
15
|
+
table th {
|
|
16
|
+
padding-left: 30px;
|
|
17
|
+
text-align: left;
|
|
18
|
+
}
|
|
19
|
+
table thead th.tag, table thead th.line-no {
|
|
20
|
+
width: 10%;
|
|
21
|
+
}
|
|
22
|
+
table tbody tr {
|
|
23
|
+
border-bottom: 1px solid #ddd;
|
|
24
|
+
}
|
|
25
|
+
table tbody tr:nth-child(odd) {
|
|
26
|
+
background: #f2f2f2;
|
|
27
|
+
}
|
|
28
|
+
table td {
|
|
29
|
+
padding: 4px 30px;
|
|
30
|
+
}
|
|
31
|
+
@media (prefers-color-scheme: dark) {
|
|
32
|
+
table tbody tr:nth-child(odd) {
|
|
33
|
+
background: #282828;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
</style>
|
|
37
|
+
|
|
38
|
+
<h2>
|
|
39
|
+
Notes
|
|
40
|
+
</h2>
|
|
41
|
+
|
|
42
|
+
<table id="route_table" class="table">
|
|
43
|
+
<thead>
|
|
44
|
+
<th>File Name</th>
|
|
45
|
+
<th class="line-no">Line No.</th>
|
|
46
|
+
<th class="tag">Tag</th>
|
|
47
|
+
<th>Description</th>
|
|
48
|
+
</thead>
|
|
49
|
+
<tbody>
|
|
50
|
+
<% @annotations.each do |file, annotations| %>
|
|
51
|
+
<% annotations.each.with_index do |annotation, index| %>
|
|
52
|
+
<tr>
|
|
53
|
+
<% if index == 0 %>
|
|
54
|
+
<th rowspan="<%= annotations.size %>">
|
|
55
|
+
<%= file %>
|
|
56
|
+
</th>
|
|
57
|
+
<% end %>
|
|
58
|
+
<td class="line-no"><%= annotation.line %></td>
|
|
59
|
+
<td class="tag"><%= annotation.tag %></td>
|
|
60
|
+
<td><%= annotation.text %></td>
|
|
61
|
+
</tr>
|
|
62
|
+
<% end %>
|
|
63
|
+
<% end %>
|
|
64
|
+
</tbody>
|
|
65
|
+
</table>
|
|
@@ -4,10 +4,31 @@ require "rails/test_unit/runner"
|
|
|
4
4
|
|
|
5
5
|
module Rails
|
|
6
6
|
module LineFiltering # :nodoc:
|
|
7
|
-
def
|
|
8
|
-
|
|
7
|
+
def self.extended(obj)
|
|
8
|
+
require "minitest"
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
case Minitest::VERSION
|
|
11
|
+
when /^5/ then
|
|
12
|
+
obj.extend MT5
|
|
13
|
+
when /^6/ then
|
|
14
|
+
obj.extend MT6
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
module MT5
|
|
19
|
+
def run(reporter, options = {})
|
|
20
|
+
options = options.merge(filter: Rails::TestUnit::Runner.compose_filter(self, options[:filter]))
|
|
21
|
+
|
|
22
|
+
super
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
module MT6
|
|
27
|
+
def run_suite(reporter, options = {})
|
|
28
|
+
options = options.merge(include: Rails::TestUnit::Runner.compose_filter(self, options[:include]))
|
|
29
|
+
|
|
30
|
+
super
|
|
31
|
+
end
|
|
11
32
|
end
|
|
12
33
|
end
|
|
13
34
|
end
|
|
@@ -5,8 +5,8 @@ require "minitest"
|
|
|
5
5
|
|
|
6
6
|
module Rails
|
|
7
7
|
class TestUnitReporter < Minitest::StatisticsReporter
|
|
8
|
-
class_attribute :app_root
|
|
9
|
-
class_attribute :executable, default: "bin/rails test"
|
|
8
|
+
class_attribute :app_root, default: ENV["RAILS_TEST_PWD"]
|
|
9
|
+
class_attribute :executable, default: ENV.fetch("RAILS_TEST_EXECUTABLE", "bin/rails test")
|
|
10
10
|
|
|
11
11
|
def prerecord(test_class, test_name)
|
|
12
12
|
super
|
|
@@ -60,7 +60,7 @@ module Rails
|
|
|
60
60
|
|
|
61
61
|
def relative_path_for(file)
|
|
62
62
|
if app_root
|
|
63
|
-
file.sub(/^#{app_root}\/?/, "")
|
|
63
|
+
File.expand_path(file).sub(/^#{app_root}\/?/, "")
|
|
64
64
|
else
|
|
65
65
|
file
|
|
66
66
|
end
|
|
@@ -91,10 +91,14 @@ module Rails
|
|
|
91
91
|
|
|
92
92
|
def app_root
|
|
93
93
|
@app_root ||= self.class.app_root ||
|
|
94
|
-
if
|
|
94
|
+
if ENV["RAILS_TEST_PWD"]
|
|
95
|
+
ENV["RAILS_TEST_PWD"]
|
|
96
|
+
elsif defined?(ENGINE_ROOT)
|
|
95
97
|
ENGINE_ROOT
|
|
96
98
|
elsif Rails.respond_to?(:root)
|
|
97
99
|
Rails.root
|
|
100
|
+
else
|
|
101
|
+
Dir.pwd
|
|
98
102
|
end
|
|
99
103
|
end
|
|
100
104
|
|
|
@@ -129,6 +129,7 @@ module Rails
|
|
|
129
129
|
def list_tests(patterns)
|
|
130
130
|
tests = Rake::FileList[patterns.any? ? patterns : default_test_glob]
|
|
131
131
|
tests.exclude(default_test_exclude_glob) if patterns.empty?
|
|
132
|
+
tests.exclude(%r{test/isolation/assets/node_modules})
|
|
132
133
|
tests
|
|
133
134
|
end
|
|
134
135
|
|