Skip to content

Commit 385f0ec

Browse files
authored
Merge branch 'rails:main' into patch-1
2 parents 0fdd5b5 + 1cb63d0 commit 385f0ec

File tree

13 files changed

+381
-21
lines changed

13 files changed

+381
-21
lines changed

activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,15 @@ def build_create_table_definition(table_name, id: :primary_key, primary_key: nil
345345
# # Creates a table called 'assemblies_parts' with no id.
346346
# create_join_table(:assemblies, :parts)
347347
#
348+
# # Creates a table called 'paper_boxes_papers' with no id.
349+
# create_join_table('papers', 'paper_boxes')
350+
#
351+
# A duplicate prefix is combined into a single prefix. This is useful for
352+
# namespaced models like Music::Artist and Music::Record:
353+
#
354+
# # Creates a table called 'music_artists_records' with no id.
355+
# create_join_table('music_artists', 'music_records')
356+
#
348357
# You can pass an +options+ hash which can include the following keys:
349358
# [<tt>:table_name</tt>]
350359
# Sets the table name, overriding the default.

railties/lib/rails/code_statistics.rb

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,18 @@ class CodeStatistics
4343
HEADERS = { lines: " Lines", code_lines: " LOC", classes: "Classes", methods: "Methods" }
4444

4545
class_attribute :directories, default: DIRECTORIES
46+
class_attribute :test_types, default: TEST_TYPES
4647

4748
# Add directories to the output of the `bin/rails stats` command.
4849
#
4950
# Rails::CodeStatistics.register_directory("My Directory", "path/to/dir")
50-
def self.register_directory(label, path)
51+
#
52+
# For directories that contain test code, set the `test_directory` argument to true.
53+
#
54+
# Rails::CodeStatistics.register_directory("Model specs", "spec/models", test_directory: true)
55+
def self.register_directory(label, path, test_directory: false)
5156
self.directories << [label, path]
57+
self.test_types << label
5258
end
5359

5460
def initialize(*pairs)
@@ -99,13 +105,13 @@ def calculate_total
99105

100106
def calculate_code
101107
code_loc = 0
102-
@statistics.each { |k, v| code_loc += v.code_lines unless TEST_TYPES.include? k }
108+
@statistics.each { |k, v| code_loc += v.code_lines unless test_types.include? k }
103109
code_loc
104110
end
105111

106112
def calculate_tests
107113
test_loc = 0
108-
@statistics.each { |k, v| test_loc += v.code_lines if TEST_TYPES.include? k }
114+
@statistics.each { |k, v| test_loc += v.code_lines if test_types.include? k }
109115
test_loc
110116
end
111117

railties/lib/rails/generators/rails/app/templates/bin/setup.tt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ FileUtils.chdir APP_ROOT do
1313
# Add necessary setup steps to this file.
1414

1515
puts "== Installing dependencies =="
16-
system! "gem install bundler --conservative"
1716
system("bundle check") || system!("bundle install")
1817
<% if using_node? -%>
1918

@@ -38,6 +37,9 @@ FileUtils.chdir APP_ROOT do
3837
puts "\n== Removing old logs and tempfiles =="
3938
system! "bin/rails log:clear tmp:clear"
4039

41-
puts "\n== Starting development server =="
42-
exec "bin/dev"
40+
unless ARGV.include?("--skip-server")
41+
puts "\n== Starting development server =="
42+
STDOUT.flush # flush the output before exec(2) so that it displays
43+
exec "bin/dev"
44+
end
4345
end

railties/lib/rails/generators/rails/devcontainer/devcontainer_generator.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,11 @@ def create_devcontainer
3838

3939
def update_application_system_test_case
4040
return unless options[:system_test]
41-
return unless File.exist?("test/application_system_test_case.rb")
4241

43-
gsub_file("test/application_system_test_case.rb", /^\s*driven_by\b.*/, system_test_configuration)
42+
system_test_case_path = File.expand_path "test/application_system_test_case.rb", destination_root
43+
return unless File.exist? system_test_case_path
44+
45+
gsub_file(system_test_case_path, /^\s*driven_by\b.*/, system_test_configuration)
4446
end
4547

4648
def update_database_yml

railties/lib/rails/generators/rails/devcontainer/templates/devcontainer/devcontainer.json.tt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,5 @@
3333
<%- end -%>
3434

3535
// Use 'postCreateCommand' to run commands after the container is created.
36-
"postCreateCommand": "bin/setup"
36+
"postCreateCommand": "bin/setup --skip-server"
3737
}

railties/lib/rails/generators/rails/scaffold_controller/templates/controller.rb.tt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class <%= controller_class_name %>Controller < ApplicationController
4343
# DELETE <%= route_url %>/1
4444
def destroy
4545
@<%= orm_instance.destroy %>
46-
redirect_to <%= index_helper %>_url, notice: <%= %("#{human_name} was successfully destroyed.") %>, status: :see_other
46+
redirect_to <%= index_helper %>_path, notice: <%= %("#{human_name} was successfully destroyed.") %>, status: :see_other
4747
end
4848

4949
private

railties/test/application/bin_setup_test.rb

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,9 @@ def test_bin_setup
2020
assert_equal 5, File.size("log/test.log")
2121
assert_not File.exist?("tmp/restart.txt")
2222

23-
`bin/setup 2>&1`
23+
`bin/setup --skip-server 2>&1`
2424
assert_equal 0, File.size("log/test.log")
2525
assert_equal '["ar_internal_metadata", "articles", "schema_migrations"]', list_tables.call
26-
assert File.exist?("tmp/restart.txt")
2726
end
2827
end
2928

@@ -35,7 +34,7 @@ def test_bin_setup_output
3534

3635
app_file "db/schema.rb", ""
3736

38-
output = `bin/setup 2>&1`
37+
output = `bin/setup --skip-server 2>&1`
3938

4039
# Ignore line that's only output by Bundler < 1.14
4140
output.sub!(/^Resolving dependencies\.\.\.\n/, "")
@@ -58,8 +57,6 @@ def test_bin_setup_output
5857
Created database 'app_test'
5958
6059
== Removing old logs and tempfiles ==
61-
62-
== Restarting application server ==
6360
OUTPUT
6461
end
6562
end

railties/test/code_statistics_test.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,20 @@ def teardown
1414
FileUtils.rm_rf(@tmp_path)
1515
end
1616

17+
test "register directories" do
18+
Rails::CodeStatistics.register_directory("My Directory", "path/to/dir")
19+
assert Rails::CodeStatistics.directories.include?(["My Directory", "path/to/dir"])
20+
ensure
21+
Rails::CodeStatistics.directories.delete(["My Directory", "path/to/dir"])
22+
end
23+
24+
test "register test directories" do
25+
Rails::CodeStatistics.register_directory("Model specs", "spec/models", test_directory: true)
26+
assert Rails::CodeStatistics.test_types.include?("Model specs")
27+
ensure
28+
Rails::CodeStatistics.test_types.delete("Model specs")
29+
end
30+
1731
test "ignores directories that happen to have source files extensions" do
1832
assert_nothing_raised do
1933
@code_statistics = Rails::CodeStatistics.new(["tmp dir", @tmp_path])

railties/test/fixtures/.devcontainer/devcontainer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,5 @@
2727
// "remoteUser": "root",
2828

2929
// Use 'postCreateCommand' to run commands after the container is created.
30-
"postCreateCommand": "bin/setup"
30+
"postCreateCommand": "bin/setup --skip-server"
3131
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# frozen_string_literal: true
2+
3+
require "test_helper"
4+
5+
class ApplicationSystemTestCase < ActionDispatch::SystemTestCase
6+
driven_by :selenium, using: :headless_chrome, screen_size: [ 1400, 1400 ]
7+
end

0 commit comments

Comments
 (0)