railties 7.0.0.rc3 → 7.0.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (35) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +46 -0
  3. data/MIT-LICENSE +1 -1
  4. data/lib/rails/application/configuration.rb +13 -4
  5. data/lib/rails/application/finisher.rb +0 -1
  6. data/lib/rails/application.rb +4 -1
  7. data/lib/rails/autoloaders/inflector.rb +1 -1
  8. data/lib/rails/autoloaders.rb +40 -36
  9. data/lib/rails/commands/dbconsole/dbconsole_command.rb +10 -7
  10. data/lib/rails/gem_version.rb +2 -2
  11. data/lib/rails/generators/actions.rb +30 -13
  12. data/lib/rails/generators/app_base.rb +77 -54
  13. data/lib/rails/generators/erb/scaffold/templates/edit.html.erb.tt +2 -2
  14. data/lib/rails/generators/erb/scaffold/templates/index.html.erb.tt +7 -2
  15. data/lib/rails/generators/erb/scaffold/templates/new.html.erb.tt +1 -1
  16. data/lib/rails/generators/erb/scaffold/templates/partial.html.erb.tt +0 -3
  17. data/lib/rails/generators/erb/scaffold/templates/show.html.erb.tt +3 -3
  18. data/lib/rails/generators/generated_attribute.rb +2 -2
  19. data/lib/rails/generators/named_base.rb +10 -10
  20. data/lib/rails/generators/rails/app/app_generator.rb +14 -0
  21. data/lib/rails/generators/rails/app/templates/Gemfile.tt +10 -14
  22. data/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt +0 -31
  23. data/lib/rails/generators/rails/app/templates/config/environments/test.rb.tt +1 -1
  24. data/lib/rails/generators/rails/app/templates/config/initializers/filter_parameter_logging.rb.tt +3 -1
  25. data/lib/rails/generators/rails/app/templates/config/initializers/new_framework_defaults_7_0.rb.tt +0 -4
  26. data/lib/rails/generators/rails/plugin/plugin_generator.rb +39 -16
  27. data/lib/rails/generators/rails/plugin/templates/%name%.gemspec.tt +1 -1
  28. data/lib/rails/generators/rails/plugin/templates/Gemfile.tt +8 -30
  29. data/lib/rails/generators/rails/plugin/templates/test/test_helper.rb.tt +0 -5
  30. data/lib/rails/generators/test_unit/scaffold/templates/functional_test.rb.tt +5 -5
  31. data/lib/rails/generators/testing/behaviour.rb +2 -2
  32. data/lib/rails/tasks/framework.rake +5 -1
  33. data/lib/rails/templates/rails/welcome/index.html.erb +62 -49
  34. data/lib/rails.rb +1 -2
  35. metadata +14 -14
@@ -123,8 +123,8 @@ module Rails
123
123
  when :integer then 1
124
124
  when :float then 1.5
125
125
  when :decimal then "9.99"
126
- when :datetime, :timestamp, :time then Time.now.to_formatted_s(:db)
127
- when :date then Date.today.to_formatted_s(:db)
126
+ when :datetime, :timestamp, :time then Time.now.to_fs(:db)
127
+ when :date then Date.today.to_fs(:db)
128
128
  when :string then name == "type" ? "" : "MyString"
129
129
  when :text then "MyText"
130
130
  when :boolean then false
@@ -94,20 +94,20 @@ module Rails
94
94
  singular_name == plural_name
95
95
  end
96
96
 
97
- def index_helper # :doc:
98
- uncountable? ? "#{plural_route_name}_index" : plural_route_name
97
+ def index_helper(type: nil) # :doc:
98
+ [plural_route_name, ("index" if uncountable?), type].compact.join("_")
99
99
  end
100
100
 
101
- def show_helper # :doc:
102
- "#{singular_route_name}_url(@#{singular_table_name})"
101
+ def show_helper(arg = "@#{singular_table_name}", type: :url) # :doc:
102
+ "#{singular_route_name}_#{type}(#{arg})"
103
103
  end
104
104
 
105
- def edit_helper # :doc:
106
- "edit_#{show_helper}"
105
+ def edit_helper(...) # :doc:
106
+ "edit_#{show_helper(...)}"
107
107
  end
108
108
 
109
- def new_helper # :doc:
110
- "new_#{singular_route_name}_url"
109
+ def new_helper(type: :url) # :doc:
110
+ "new_#{singular_route_name}_#{type}"
111
111
  end
112
112
 
113
113
  def singular_table_name # :doc:
@@ -147,8 +147,8 @@ module Rails
147
147
  model_resource_name(prefix: "@")
148
148
  end
149
149
 
150
- def model_resource_name(prefix: "") # :doc:
151
- resource_name = "#{prefix}#{singular_table_name}"
150
+ def model_resource_name(base_name = singular_table_name, prefix: "") # :doc:
151
+ resource_name = "#{prefix}#{base_name}"
152
152
  if options[:model_name]
153
153
  "[#{controller_class_path.map { |name| ":" + name }.join(", ")}, #{resource_name}]"
154
154
  else
@@ -193,6 +193,14 @@ module Rails
193
193
  directory "db"
194
194
  end
195
195
 
196
+ def db_when_updating
197
+ path = File.expand_path("db/schema.rb", destination_root)
198
+
199
+ if File.exist?(path)
200
+ gsub_file("db/schema.rb", /ActiveRecord::Schema\.define/, "ActiveRecord::Schema[6.1].define")
201
+ end
202
+ end
203
+
196
204
  def lib
197
205
  empty_directory "lib"
198
206
  empty_directory_with_keep_file "lib/tasks"
@@ -303,6 +311,7 @@ module Rails
303
311
 
304
312
  public_task :set_default_accessors!
305
313
  public_task :create_root
314
+ public_task :target_rails_prerelease
306
315
 
307
316
  def create_root_files
308
317
  build(:readme)
@@ -332,6 +341,11 @@ module Rails
332
341
  end
333
342
  remove_task :update_bin_files
334
343
 
344
+ def update_db_schema
345
+ build(:db_when_updating)
346
+ end
347
+ remove_task :update_db_schema
348
+
335
349
  def update_active_storage
336
350
  unless skip_active_storage?
337
351
  rails_command "active_storage:update", inline: true
@@ -2,14 +2,10 @@ source "https://rubygems.org"
2
2
  git_source(:github) { |repo| "https://github.com/#{repo}.git" }
3
3
 
4
4
  ruby <%= "\"#{RUBY_VERSION}\"" -%>
5
- <% gemfile_entries.each do |gem| -%>
6
- <% if gem.comment %>
7
5
 
8
- # <%= gem.comment %>
6
+ <% gemfile_entries.each do |gemfile_entry| %>
7
+ <%= gemfile_entry %>
9
8
  <% end -%>
10
- <%= gem.commented_out ? "# " : "" %>gem "<%= gem.name %>"<%= %(, "#{gem.version}") if gem.version -%>
11
- <% if gem.options.any? -%>, <%= gem.options.map { |k,v| "#{k}: #{v.inspect}" }.join(", ") %><% end -%>
12
- <% end %>
13
9
  <% unless options.minimal? -%>
14
10
 
15
11
  # Use Kredis to get higher-level data types in Redis [https://github.com/rails/kredis]
@@ -24,12 +20,12 @@ gem "tzinfo-data", platforms: %i[ mingw mswin x64_mingw jruby ]
24
20
  <% if depend_on_bootsnap? -%>
25
21
 
26
22
  # Reduces boot times through caching; required in config/boot.rb
27
- gem "bootsnap", ">= 1.4.4", require: false
23
+ gem "bootsnap", require: false
28
24
  <% end -%>
29
25
  <% unless skip_sprockets? || options.minimal? -%>
30
26
 
31
27
  # Use Sass to process CSS
32
- # gem "sassc-rails", "~> 2.1"
28
+ # gem "sassc-rails"
33
29
  <% end -%>
34
30
  <% unless skip_active_storage? -%>
35
31
 
@@ -44,18 +40,18 @@ gem "bootsnap", ">= 1.4.4", require: false
44
40
  <% if RUBY_ENGINE == "ruby" -%>
45
41
 
46
42
  group :development, :test do
47
- # See https://edgeguides.rubyonrails.org/debugging_rails_applications.html#debugging-with-the-debug-gem
48
- gem "debug", ">= 1.0.0", platforms: %i[ mri mingw x64_mingw ]
43
+ # See https://guides.rubyonrails.org/debugging_rails_applications.html#debugging-with-the-debug-gem
44
+ gem "debug", platforms: %i[ mri mingw x64_mingw ]
49
45
  end
50
46
  <% end -%>
51
47
 
52
48
  group :development do
53
49
  <%- unless options.api? || options.skip_dev_gems? -%>
54
50
  # Use console on exceptions pages [https://github.com/rails/web-console]
55
- gem "web-console", ">= 4.1.0"
51
+ gem "web-console"
56
52
 
57
53
  # Add speed badges [https://github.com/MiniProfiler/rack-mini-profiler]
58
- # gem "rack-mini-profiler", ">= 2.3.3"
54
+ # gem "rack-mini-profiler"
59
55
 
60
56
  <%- end -%>
61
57
  # Speed up commands on slow machines / big apps [https://github.com/rails/spring]
@@ -65,8 +61,8 @@ end
65
61
  <%- if depends_on_system_test? -%>
66
62
  group :test do
67
63
  # Use system testing [https://guides.rubyonrails.org/testing.html#system-testing]
68
- gem "capybara", ">= 3.26"
69
- gem "selenium-webdriver", ">= 4.0.0"
64
+ gem "capybara"
65
+ gem "selenium-webdriver"
70
66
  gem "webdrivers"
71
67
  end
72
68
  <%- end -%>
@@ -104,35 +104,4 @@ Rails.application.configure do
104
104
  # Do not dump schema after migrations.
105
105
  config.active_record.dump_schema_after_migration = false
106
106
  <%- end -%>
107
-
108
- # Inserts middleware to perform automatic connection switching.
109
- # The `database_selector` hash is used to pass options to the DatabaseSelector
110
- # middleware. The `delay` is used to determine how long to wait after a write
111
- # to send a subsequent read to the primary.
112
- #
113
- # The `database_resolver` class is used by the middleware to determine which
114
- # database is appropriate to use based on the time delay.
115
- #
116
- # The `database_resolver_context` class is used by the middleware to set
117
- # timestamps for the last write to the primary. The resolver uses the context
118
- # class timestamps to determine how long to wait before reading from the
119
- # replica.
120
- #
121
- # By default Rails will store a last write timestamp in the session. The
122
- # DatabaseSelector middleware is designed as such you can define your own
123
- # strategy for connection switching and pass that into the middleware through
124
- # these configuration options.
125
- # config.active_record.database_selector = { delay: 2.seconds }
126
- # config.active_record.database_resolver = ActiveRecord::Middleware::DatabaseSelector::Resolver
127
- # config.active_record.database_resolver_context = ActiveRecord::Middleware::DatabaseSelector::Resolver::Session
128
-
129
- # Inserts middleware to perform automatic shard swapping. The `shard_selector` hash
130
- # can be used to pass options to the `ShardSelector` middleware. The `lock` option is
131
- # used to determine whether shard swapping should be prohibited for the request.
132
- #
133
- # The `shard_resolver` option is used by the middleware to determine which shard
134
- # to switch to. The application must provide a mechanism for finding the shard name
135
- # in a proc. See guides for an example.
136
- # config.active_record.shard_selector = { lock: true }
137
- # config.active_record.shard_resolver = ->(request) { Tenant.find_by!(host: request.host).shard }
138
107
  end
@@ -8,7 +8,7 @@ require "active_support/core_ext/integer/time"
8
8
  Rails.application.configure do
9
9
  # Settings specified here will take precedence over those in config/application.rb.
10
10
 
11
- # Turn false under Spring and add config.action_view.cache_template_loading = true
11
+ # Turn false under Spring and add config.action_view.cache_template_loading = true.
12
12
  config.cache_classes = true
13
13
 
14
14
  # Eager loading loads your whole application. When running a single test locally,
@@ -1,6 +1,8 @@
1
1
  # Be sure to restart your server when you modify this file.
2
2
 
3
- # Configure sensitive parameters which will be filtered from the log file.
3
+ # Configure parameters to be filtered from the log file. Use this to limit dissemination of
4
+ # sensitive information. See the ActiveSupport::ParameterFilter documentation for supported
5
+ # notations and behaviors.
4
6
  Rails.application.config.filter_parameters += [
5
7
  :passw, :secret, :token, :_key, :crypt, :salt, :certificate, :otp, :ssn
6
8
  ]
@@ -9,10 +9,6 @@
9
9
  # Read the Guide for Upgrading Ruby on Rails for more info on each option.
10
10
  # https://guides.rubyonrails.org/upgrading_ruby_on_rails.html
11
11
 
12
- # Raise an error when trying to use forgery protection without a working
13
- # session.
14
- # Rails.application.config.action_controller.silence_disabled_session_errors = false
15
-
16
12
  # `button_to` view helper will render `<button>` element, regardless of whether
17
13
  # or not the content is passed as the first argument or as a block.
18
14
  # Rails.application.config.action_view.button_to_generates_button_tag = true
@@ -94,10 +94,6 @@ module Rails
94
94
  def test
95
95
  template "test/test_helper.rb"
96
96
  template "test/%namespaced_name%_test.rb"
97
- append_file "Rakefile", <<~EOF
98
- #{rakefile_test_tasks}
99
- task default: :test
100
- EOF
101
97
 
102
98
  if engine?
103
99
  empty_directory_with_keep_file "test/fixtures/files"
@@ -230,11 +226,19 @@ module Rails
230
226
  def initialize(*args)
231
227
  @dummy_path = nil
232
228
  super
229
+
230
+ if !engine? || !with_dummy_app?
231
+ self.options = options.merge(skip_asset_pipeline: true).freeze
232
+ end
233
233
  end
234
234
 
235
235
  public_task :set_default_accessors!
236
236
  public_task :create_root
237
237
 
238
+ def target_rails_prerelease
239
+ super("plugin new")
240
+ end
241
+
238
242
  def create_root_files
239
243
  build(:readme)
240
244
  build(:rakefile)
@@ -309,6 +313,33 @@ module Rails
309
313
  end
310
314
 
311
315
  private
316
+ def gemfile_entries
317
+ [
318
+ rails_gemfile_entry,
319
+ simplify_gemfile_entries(
320
+ database_gemfile_entry,
321
+ asset_pipeline_gemfile_entry,
322
+ ),
323
+ ].flatten.compact
324
+ end
325
+
326
+ def rails_gemfile_entry
327
+ if options[:skip_gemspec]
328
+ super
329
+ elsif rails_prerelease?
330
+ super.dup.tap do |entry|
331
+ entry.comment = <<~COMMENT
332
+ Your gem is dependent on a prerelease version of Rails. Once you can lock this
333
+ dependency down to a specific version, move it to your gemspec.
334
+ COMMENT
335
+ end
336
+ end
337
+ end
338
+
339
+ def simplify_gemfile_entries(*gemfile_entries)
340
+ gemfile_entries.flatten.compact.map { |entry| GemfileEntry.floats(entry.name) }
341
+ end
342
+
312
343
  def create_dummy_app(path = nil)
313
344
  dummy_path(path) if path
314
345
 
@@ -398,6 +429,10 @@ module Rails
398
429
  end
399
430
  end
400
431
 
432
+ def rails_version_specifier(gem_version = Rails.gem_version)
433
+ [">= #{gem_version}"]
434
+ end
435
+
401
436
  def valid_const?
402
437
  if /-\d/.match?(original_name)
403
438
  raise Error, "Invalid plugin name #{original_name}. Please give a name which does not contain a namespace starting with numeric characters."
@@ -418,18 +453,6 @@ module Rails
418
453
  defined?(::PluginBuilder) ? ::PluginBuilder : Rails::PluginBuilder
419
454
  end
420
455
 
421
- def rakefile_test_tasks
422
- <<-RUBY
423
- require "rake/testtask"
424
-
425
- Rake::TestTask.new(:test) do |t|
426
- t.libs << "test"
427
- t.pattern = "test/**/*_test.rb"
428
- t.verbose = false
429
- end
430
- RUBY
431
- end
432
-
433
456
  def dummy_path(path = nil)
434
457
  @dummy_path = path if path
435
458
  @dummy_path || options[:dummy_path]
@@ -24,5 +24,5 @@ Gem::Specification.new do |spec|
24
24
  Dir["{app,config,db,lib}/**/*", "MIT-LICENSE", "Rakefile", "README.md"]
25
25
  end
26
26
 
27
- <%= "# " if options.dev? || options.edge? || options.main? -%>spec.add_dependency "rails", "<%= Array(rails_version_specifier).join('", "') %>"
27
+ <%= "# " if rails_prerelease? -%>spec.add_dependency "rails", "<%= Array(rails_version_specifier).join('", "') %>"
28
28
  end
@@ -1,41 +1,19 @@
1
1
  source "https://rubygems.org"
2
2
  git_source(:github) { |repo| "https://github.com/#{repo}.git" }
3
+ <% unless options[:skip_gemspec] -%>
3
4
 
4
- <% if options[:skip_gemspec] -%>
5
- <%= "# " if options.dev? || options.edge? || options.main? -%>gem "rails", "<%= Array(rails_version_specifier).join("', '") %>"
6
- <% else -%>
7
5
  # Specify your gem's dependencies in <%= name %>.gemspec.
8
6
  gemspec
9
7
  <% end -%>
10
- <% unless options[:skip_active_record] -%>
11
-
12
- group :development do
13
- gem "<%= gem_for_database[0] %>"
14
- end
15
- <% end -%>
16
-
17
- <% if options.dev? || options.edge? -%>
18
- # Your gem is dependent on dev or edge Rails. Once you can lock this
19
- # dependency down to a specific version, move it to your gemspec.
20
- <% max_width = gemfile_entries.map { |g| g.name.length }.max -%>
21
- <% gemfile_entries.each do |gem| -%>
22
- <% if gem.comment -%>
23
-
24
- # <%= gem.comment %>
25
- <% end -%>
26
- <%= gem.commented_out ? "# " : "" %>gem "<%= gem.name %>"<%= %(, "#{gem.version}") if gem.version -%>
27
- <% if gem.options.any? -%>
28
- , <%= gem.options.map { |k,v|
29
- "#{k}: #{v.inspect}" }.join(", ") %>
30
- <% end -%>
31
- <% end -%>
32
-
8
+ <% gemfile_entries.each do |gemfile_entry| %>
9
+ <%= gemfile_entry %>
33
10
  <% end -%>
34
11
  <% if RUBY_ENGINE == "ruby" -%>
35
- # Start debugger with binding.b -- Read more: https://github.com/ruby/debug
36
- # gem "debug", ">= 1.0.0", group: %i[ development test ]
12
+
13
+ # Start debugger with binding.b [https://github.com/ruby/debug]
14
+ # gem "debug", ">= 1.0.0"
37
15
  <% end -%>
38
- <% if RUBY_PLATFORM.match(/bccwin|cygwin|emx|mingw|mswin|wince|java/) -%>
16
+ <% if RUBY_PLATFORM.match?(/bccwin|cygwin|emx|mingw|mswin|wince|java/) -%>
39
17
 
40
- gem "tzinfo-data", platforms: %i[ mingw mswin x64_mingw jruby]
18
+ gem "tzinfo-data", platforms: %i[ mingw mswin x64_mingw jruby ]
41
19
  <% end -%>
@@ -10,11 +10,6 @@ ActiveRecord::Migrator.migrations_paths << File.expand_path("../db/migrate", __d
10
10
  <% end -%>
11
11
  require "rails/test_help"
12
12
 
13
- <% unless engine? -%>
14
- require "rails/test_unit/reporter"
15
- Rails::TestUnitReporter.executable = "bin/test"
16
- <% end -%>
17
-
18
13
  <% unless options[:skip_active_record] -%>
19
14
  # Load fixtures from the engine
20
15
  if ActiveSupport::TestCase.respond_to?(:fixture_path=)
@@ -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 %>_url
14
+ get <%= index_helper(type: :url) %>
15
15
  assert_response :success
16
16
  end
17
17
 
@@ -22,10 +22,10 @@ class <%= controller_class_name %>ControllerTest < ActionDispatch::IntegrationTe
22
22
 
23
23
  test "should create <%= singular_table_name %>" do
24
24
  assert_difference("<%= class_name %>.count") do
25
- post <%= index_helper %>_url, params: { <%= "#{singular_table_name}: { #{attributes_string} }" %> }
25
+ post <%= index_helper(type: :url) %>, params: { <%= "#{singular_table_name}: { #{attributes_string} }" %> }
26
26
  end
27
27
 
28
- assert_redirected_to <%= singular_table_name %>_url(<%= class_name %>.last)
28
+ assert_redirected_to <%= show_helper("#{class_name}.last") %>
29
29
  end
30
30
 
31
31
  test "should show <%= singular_table_name %>" do
@@ -40,7 +40,7 @@ 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 <%= singular_table_name %>_url(<%= "@#{singular_table_name}" %>)
43
+ assert_redirected_to <%= show_helper %>
44
44
  end
45
45
 
46
46
  test "should destroy <%= singular_table_name %>" do
@@ -48,7 +48,7 @@ class <%= controller_class_name %>ControllerTest < ActionDispatch::IntegrationTe
48
48
  delete <%= show_helper %>
49
49
  end
50
50
 
51
- assert_redirected_to <%= index_helper %>_url
51
+ assert_redirected_to <%= index_helper(type: :url) %>
52
52
  end
53
53
  end
54
54
  <% end -%>
@@ -66,8 +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 |= ["--skip-bootsnap"] unless args.include? "--no-skip-bootsnap"
69
+ args += ["--skip-bundle"] unless args.include?("--no-skip-bundle") || args.include?("--dev")
70
+ args |= ["--skip-bootsnap"] unless args.include?("--no-skip-bootsnap")
71
71
 
72
72
  generator_class.start(args, config.reverse_merge(destination_root: destination_root))
73
73
  end
@@ -2,7 +2,7 @@
2
2
 
3
3
  namespace :app do
4
4
  desc "Update configs and some other initially generated files (or use just update:configs or update:bin)"
5
- task update: [ "update:configs", "update:bin", "update:active_storage", "update:upgrade_guide_info" ]
5
+ task update: [ "update:configs", "update:bin", "update:db", "update:active_storage", "update:upgrade_guide_info" ]
6
6
 
7
7
  desc "Applies the template supplied by LOCATION=(/path/to/template) or URL"
8
8
  task template: :environment do
@@ -51,6 +51,10 @@ namespace :app do
51
51
  Rails::AppUpdater.invoke_from_app_generator :update_bin_files
52
52
  end
53
53
 
54
+ task :db do
55
+ Rails::AppUpdater.invoke_from_app_generator :update_db_schema
56
+ end
57
+
54
58
  task :active_storage do
55
59
  Rails::AppUpdater.invoke_from_app_generator :update_active_storage
56
60
  end