From ecb2850a04adc6c6665f9a30a1d60ca73965ccfa Mon Sep 17 00:00:00 2001 From: Rasesh Patel Date: Wed, 24 May 2017 01:34:07 -0400 Subject: Show object ids in scaffold pages when displaying referenced objects Resolve Issue#29200 When scaffolding a model that references another model the generated show and index html pages display the object directly on the page. Basically, it just shows a memory address. That is not very helpful. In this commit we show the object's id rather than the memory address. This updates the scaffold templates and the json builder files. --- railties/CHANGELOG.md | 5 +++++ .../generators/erb/scaffold/templates/index.html.erb.tt | 2 +- .../generators/erb/scaffold/templates/show.html.erb.tt | 2 +- railties/test/generators/scaffold_generator_test.rb | 16 +++++++++++++--- 4 files changed, 20 insertions(+), 5 deletions(-) (limited to 'railties') diff --git a/railties/CHANGELOG.md b/railties/CHANGELOG.md index 1a415449d1..e581766c69 100644 --- a/railties/CHANGELOG.md +++ b/railties/CHANGELOG.md @@ -1,3 +1,8 @@ +* Use Ids instead of memory addresses when displaying references in scaffold views + Fixes #29200. + + *Rasesh Patel* + * Adds support for multiple databases to `rails db:migrate:status`. Subtasks are also added to get the status of individual databases (eg. `rails db:migrate:status:animals`). diff --git a/railties/lib/rails/generators/erb/scaffold/templates/index.html.erb.tt b/railties/lib/rails/generators/erb/scaffold/templates/index.html.erb.tt index e1ede7c713..2cf4e5c9d0 100644 --- a/railties/lib/rails/generators/erb/scaffold/templates/index.html.erb.tt +++ b/railties/lib/rails/generators/erb/scaffold/templates/index.html.erb.tt @@ -16,7 +16,7 @@ <%% @<%= plural_table_name %>.each do |<%= singular_table_name %>| %> <% attributes.reject(&:password_digest?).each do |attribute| -%> - <%%= <%= singular_table_name %>.<%= attribute.name %> %> + <%%= <%= singular_table_name %>.<%= attribute.column_name %> %> <% end -%> <%%= link_to 'Show', <%= model_resource_name %> %> <%%= link_to 'Edit', edit_<%= singular_route_name %>_path(<%= singular_table_name %>) %> diff --git a/railties/lib/rails/generators/erb/scaffold/templates/show.html.erb.tt b/railties/lib/rails/generators/erb/scaffold/templates/show.html.erb.tt index 5e634153be..7deba07926 100644 --- a/railties/lib/rails/generators/erb/scaffold/templates/show.html.erb.tt +++ b/railties/lib/rails/generators/erb/scaffold/templates/show.html.erb.tt @@ -3,7 +3,7 @@ <% attributes.reject(&:password_digest?).each do |attribute| -%>

<%= attribute.human_name %>: - <%%= @<%= singular_table_name %>.<%= attribute.name %> %> + <%%= @<%= singular_table_name %>.<%= attribute.column_name %> %>

<% end -%> diff --git a/railties/test/generators/scaffold_generator_test.rb b/railties/test/generators/scaffold_generator_test.rb index 21b5013484..3cffdddd38 100644 --- a/railties/test/generators/scaffold_generator_test.rb +++ b/railties/test/generators/scaffold_generator_test.rb @@ -435,8 +435,8 @@ class ScaffoldGeneratorTest < Rails::Generators::TestCase end end - def test_scaffold_generator_belongs_to - run_generator ["account", "name", "currency:belongs_to"] + def test_scaffold_generator_belongs_to_and_references + run_generator ["account", "name", "currency:belongs_to", "user:references"] assert_file "app/models/account.rb", /belongs_to :currency/ @@ -449,7 +449,7 @@ class ScaffoldGeneratorTest < Rails::Generators::TestCase assert_file "app/controllers/accounts_controller.rb" do |content| assert_instance_method :account_params, content do |m| - assert_match(/permit\(:name, :currency_id\)/, m) + assert_match(/permit\(:name, :currency_id, :user_id\)/, m) end end @@ -457,6 +457,16 @@ class ScaffoldGeneratorTest < Rails::Generators::TestCase assert_match(/^\W{4}<%= form\.text_field :name %>/, content) assert_match(/^\W{4}<%= form\.text_field :currency_id %>/, content) end + + assert_file "app/views/accounts/index.html.erb" do |content| + assert_match(/^\W{8}<%= account\.name %><\/td>/, content) + assert_match(/^\W{8}<%= account\.user_id %><\/td>/, content) + end + + assert_file "app/views/accounts/show.html.erb" do |content| + assert_match(/^\W{2}<%= @account\.name %>/, content) + assert_match(/^\W{2}<%= @account\.user_id %>/, content) + end end def test_scaffold_generator_database -- cgit v1.2.3 From 4f1295129b22f435641c4d63a15bfd4395db98ca Mon Sep 17 00:00:00 2001 From: bogdanvlviv Date: Tue, 16 Oct 2018 01:42:15 +0300 Subject: Unify changelog entries related to `database` option of Rails generators [ci skip] `migrations_paths` option was added to migration generator, with changelog entry, in #33760. Also `migrations_paths` option was added to model generator, with changelog entry, in #33994. Then `migrations_paths` was renamed to `database` and aliased as `db` in #34021, and was added new changelog entry. I think we should edit existed changelog entries instead adding new about changing the name of the option from `migrations_paths` to `database` since Rails 6.0 hasn't been released yet, and since It might confuse readers of the changelog file in case if they've read changelog enty about adding `migrations_paths` option but haven't read the entry about change the name of that option to `database`. @eileencodes, @gmcgibbon, @rafaelfranca Does it make sense? --- railties/CHANGELOG.md | 32 ++++++++------------------------ 1 file changed, 8 insertions(+), 24 deletions(-) (limited to 'railties') diff --git a/railties/CHANGELOG.md b/railties/CHANGELOG.md index 1a415449d1..f82b080f12 100644 --- a/railties/CHANGELOG.md +++ b/railties/CHANGELOG.md @@ -11,34 +11,18 @@ *DHH*, *Lachlan Sylvester* -* Refactors `migrations_paths` command option in generators - to `database` (aliased as `db`). Now, the migrations paths - will be read from the specified database configuration in the - current environment. +* Add `database` (aliased as `db`) option to model generator to allow + setting the database. This is useful for applications that use + multiple databases and put migrations per database in their own directories. ``` - bin/rails g model Chair brand:string --database=kingston - invoke active_record - create db/kingston_migrate/20180830151055_create_chairs.rb - ``` - - `--database` can be used with the migration, model, and scaffold generators. - - *Gannon McGibbon* - -* Adds an option to the model generator to allow setting the - migrations paths for that migration. This is useful for - applications that use multiple databases and put migrations - per database in their own directories. - - ``` - bin/rails g model Room capacity:integer --migrations-paths=db/kingston_migrate + bin/rails g model Room capacity:integer --database=kingston invoke active_record create db/kingston_migrate/20180830151055_create_rooms.rb ``` Because rails scaffolding uses the model generator, you can - also specify migrations paths with the scaffold generator. + also specify a database with the scaffold generator. *Gannon McGibbon* @@ -66,15 +50,15 @@ *Yoshiyuki Kinjo* -* Add `--migrations_paths` option to migration generator. +* Add `database` (aliased as `db`) option to migration generator. If you're using multiple databases and have a folder for each database for migrations (ex db/migrate and db/new_db_migrate) you can now pass the - `--migrations_paths` option to the generator to make sure the the migration + `--database` option to the generator to make sure the the migration is inserted into the correct folder. ``` - rails g migration CreateHouses --migrations_paths=db/kingston_migrate + rails g migration CreateHouses --database=kingston invoke active_record create db/kingston_migrate/20180830151055_create_houses.rb ``` -- cgit v1.2.3 From 60e6269598b9ac01fc73517e03e786a5470772cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Rodr=C3=ADguez?= Date: Wed, 17 Oct 2018 12:51:23 -0300 Subject: Fix generated Gemfile missing gems on jruby --- railties/lib/rails/generators/rails/app/templates/Gemfile.tt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties') diff --git a/railties/lib/rails/generators/rails/app/templates/Gemfile.tt b/railties/lib/rails/generators/rails/app/templates/Gemfile.tt index 1567333023..fb264935bd 100644 --- a/railties/lib/rails/generators/rails/app/templates/Gemfile.tt +++ b/railties/lib/rails/generators/rails/app/templates/Gemfile.tt @@ -45,6 +45,7 @@ group :development, :test do gem 'byebug', platforms: [:mri, :mingw, :x64_mingw] end +<% end -%> group :development do <%- unless options.api? -%> # Access an interactive console on exception pages or by calling 'console' anywhere in the code. @@ -75,7 +76,6 @@ group :test do gem 'chromedriver-helper' end <%- end -%> -<% end -%> # Windows does not include zoneinfo files, so bundle the tzinfo-data gem gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby] -- cgit v1.2.3 From 32b03b46150b0161eba2321ccac7678511e3d58e Mon Sep 17 00:00:00 2001 From: Yoshiyuki Kinjo Date: Tue, 9 Oct 2018 16:14:51 +0900 Subject: Implement AR#inspect using ParamterFilter. AR instance support `filter_parameters` since #33756. Though Regex or Proc is valid as `filter_parameters`, they are not supported as AR#inspect. I also add :mask option and #filter_params to `ActiveSupport::ParameterFilter#new` to implement this. --- railties/test/application/configuration_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties') diff --git a/railties/test/application/configuration_test.rb b/railties/test/application/configuration_test.rb index 9b01d42b1e..fa418f564b 100644 --- a/railties/test/application/configuration_test.rb +++ b/railties/test/application/configuration_test.rb @@ -2109,7 +2109,7 @@ module ApplicationTests RUBY app "development" assert_equal [ :password, :credit_card_number ], Rails.application.config.filter_parameters - assert_equal [ "password", "credit_card_number" ].to_set, ActiveRecord::Base.filter_attributes + assert_equal [ :password, :credit_card_number ], ActiveRecord::Base.filter_attributes end test "ActiveStorage.routes_prefix can be configured via config.active_storage.routes_prefix" do -- cgit v1.2.3 From 86a12b6f2932ba1a3b5f0417688ffe34ea6bab25 Mon Sep 17 00:00:00 2001 From: "yuuji.yaginuma" Date: Fri, 19 Oct 2018 17:56:09 +0900 Subject: Avoid running bundler on tests that don't need it If the dev option is specified, Gemfile contains gem which specifies GitHub. This will take time to execute, so should avoid it in unnecessary tests. --- railties/test/generators/app_generator_test.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'railties') diff --git a/railties/test/generators/app_generator_test.rb b/railties/test/generators/app_generator_test.rb index be97abfa52..e47d180809 100644 --- a/railties/test/generators/app_generator_test.rb +++ b/railties/test/generators/app_generator_test.rb @@ -710,7 +710,7 @@ class AppGeneratorTest < Rails::Generators::TestCase end def test_web_console_with_dev_option - run_generator [destination_root, "--dev"] + run_generator [destination_root, "--dev", "--skip-bundle"] assert_file "Gemfile" do |content| assert_match(/gem 'web-console',\s+github: 'rails\/web-console'/, content) @@ -780,7 +780,7 @@ class AppGeneratorTest < Rails::Generators::TestCase end def test_spring_with_dev_option - run_generator [destination_root, "--dev"] + run_generator [destination_root, "--dev", "--skip-bundle"] assert_no_gem "spring" end @@ -878,7 +878,7 @@ class AppGeneratorTest < Rails::Generators::TestCase end def test_bootsnap_with_dev_option - run_generator [destination_root, "--dev"] + run_generator [destination_root, "--dev", "--skip-bundle"] assert_no_gem "bootsnap" assert_file "config/boot.rb" do |content| -- cgit v1.2.3 From 264152af2b0c210b4c2e4865e337eaa07836c948 Mon Sep 17 00:00:00 2001 From: Mauro Berlanda Date: Fri, 19 Oct 2018 14:37:06 +0200 Subject: chore: implement config_for as ActiveSupport::OrderedOptions --- railties/lib/rails/application.rb | 8 ++- railties/test/application/configuration_test.rb | 80 +++++++++++++++++-------- 2 files changed, 59 insertions(+), 29 deletions(-) (limited to 'railties') diff --git a/railties/lib/rails/application.rb b/railties/lib/rails/application.rb index 656786246d..acd97b64bf 100644 --- a/railties/lib/rails/application.rb +++ b/railties/lib/rails/application.rb @@ -232,10 +232,12 @@ module Rails if yaml.exist? require "erb" - require "active_support/ordered_options" + config = YAML.load(ERB.new(yaml.read).result) || {} + config = (config["shared"] || {}).merge(config[env] || {}) - config = (YAML.load(ERB.new(yaml.read).result) || {})[env] || {} - ActiveSupport::InheritableOptions.new(config.deep_symbolize_keys) + ActiveSupport::OrderedOptions.new.tap do |config_as_ordered_options| + config_as_ordered_options.update(config.deep_symbolize_keys) + end else raise "Could not load configuration. No such file - #{yaml}" end diff --git a/railties/test/application/configuration_test.rb b/railties/test/application/configuration_test.rb index 9b01d42b1e..9c640a289a 100644 --- a/railties/test/application/configuration_test.rb +++ b/railties/test/application/configuration_test.rb @@ -1728,21 +1728,6 @@ module ApplicationTests assert_equal true, Rails.application.config.action_mailer.show_previews end - test "config_for loads custom configuration from yaml files" do - app_file "config/custom.yml", <<-RUBY - development: - foo: 'bar' - RUBY - - add_to_config <<-RUBY - config.my_custom_config = config_for('custom') - RUBY - - app "development" - - assert_equal "bar", Rails.application.config.my_custom_config["foo"] - end - test "config_for loads custom configuration from yaml accessible as symbol" do app_file "config/custom.yml", <<-RUBY development: @@ -1758,10 +1743,12 @@ module ApplicationTests assert_equal "bar", Rails.application.config.my_custom_config[:foo] end - test "config_for loads custom configuration from yaml accessible as method" do + test "config_for loads nested custom configuration from yaml as symbol keys" do app_file "config/custom.yml", <<-RUBY development: - foo: 'bar' + foo: + bar: + baz: 1 RUBY add_to_config <<-RUBY @@ -1770,15 +1757,15 @@ module ApplicationTests app "development" - assert_equal "bar", Rails.application.config.my_custom_config.foo + assert_equal 1, Rails.application.config.my_custom_config[:foo][:bar][:baz] end - test "config_for loads nested custom configuration from yaml as symbol keys" do + test "config_for makes all hash methods available" do app_file "config/custom.yml", <<-RUBY development: - foo: - bar: - baz: 1 + foo: 0 + bar: + baz: 1 RUBY add_to_config <<-RUBY @@ -1787,7 +1774,14 @@ module ApplicationTests app "development" - assert_equal 1, Rails.application.config.my_custom_config.foo[:bar][:baz] + actual = Rails.application.config.my_custom_config + + assert_equal actual, foo: 0, bar: { baz: 1 } + assert_equal actual.keys, [ :foo, :bar ] + assert_equal actual.values, [ 0, baz: 1] + assert_equal actual.to_h, foo: 0, bar: { baz: 1 } + assert_equal actual[:foo], 0 + assert_equal actual[:bar], baz: 1 end test "config_for uses the Pathname object if it is provided" do @@ -1802,7 +1796,7 @@ module ApplicationTests app "development" - assert_equal "custom key", Rails.application.config.my_custom_config["key"] + assert_equal "custom key", Rails.application.config.my_custom_config[:key] end test "config_for raises an exception if the file does not exist" do @@ -1832,6 +1826,40 @@ module ApplicationTests assert_equal({}, Rails.application.config.my_custom_config) end + test "config_for implements shared configuration as secrets case found" do + app_file "config/custom.yml", <<-RUBY + shared: + foo: :bar + test: + foo: :baz + RUBY + + add_to_config <<-RUBY + config.my_custom_config = config_for('custom') + RUBY + + app "test" + + assert_equal(:baz, Rails.application.config.my_custom_config[:foo]) + end + + test "config_for implements shared configuration as secrets case not found" do + app_file "config/custom.yml", <<-RUBY + shared: + foo: :bar + test: + foo: :baz + RUBY + + add_to_config <<-RUBY + config.my_custom_config = config_for('custom') + RUBY + + app "development" + + assert_equal(:bar, Rails.application.config.my_custom_config[:foo]) + end + test "config_for with empty file returns an empty hash" do app_file "config/custom.yml", <<-RUBY RUBY @@ -1901,7 +1929,7 @@ module ApplicationTests app "development" - assert_equal "custom key", Rails.application.config.my_custom_config["key"] + assert_equal "custom key", Rails.application.config.my_custom_config[:key] end test "config_for with syntax error show a more descriptive exception" do @@ -1934,7 +1962,7 @@ module ApplicationTests RUBY require "#{app_path}/config/environment" - assert_equal "unicorn", Rails.application.config.my_custom_config["key"] + assert_equal "unicorn", Rails.application.config.my_custom_config[:key] end test "api_only is false by default" do -- cgit v1.2.3 From 0f7655c32565fe263c2401c98573b4cce49ecb4f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Francesco=20Rodr=C3=ADguez?= Date: Fri, 19 Oct 2018 15:56:27 +0200 Subject: Remove unnecessary escape character --- .../generators/rails/app/templates/app/javascript/channels/index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'railties') diff --git a/railties/lib/rails/generators/rails/app/templates/app/javascript/channels/index.js b/railties/lib/rails/generators/rails/app/templates/app/javascript/channels/index.js index 5da1ce2dce..0cfcf74919 100644 --- a/railties/lib/rails/generators/rails/app/templates/app/javascript/channels/index.js +++ b/railties/lib/rails/generators/rails/app/templates/app/javascript/channels/index.js @@ -1,5 +1,5 @@ -// Load all the channels within this directory and all subdirectories. +// Load all the channels within this directory and all subdirectories. // Channel files must be named *_channel.js. -const channels = require.context('.', true, /\_channel\.js$/) +const channels = require.context('.', true, /_channel\.js$/) channels.keys().forEach(channels) -- cgit v1.2.3 From 931120d37d8f204f0e8c2aabbe4caa68347ee7b9 Mon Sep 17 00:00:00 2001 From: "yuuji.yaginuma" Date: Sat, 20 Oct 2018 14:16:29 +0900 Subject: Avoid running `webpacker:install` on tests that don't need it If use `run_generator` to run the generator, `--skip-webpack-install` is specified automatically. https://github.com/rails/rails/blob/3101a4136bd62787e252d2658eee23001036fa0f/railties/lib/rails/generators/testing/behaviour.rb#L71 However, when executing the generator independently (for example, to use stub), `webpacker:install` was executed. Since this includes `yarn install`, it should be avoided in unnecessary testing. --- railties/test/generators/app_generator_test.rb | 12 ++++++++---- railties/test/generators/shared_generator_tests.rb | 4 ++-- 2 files changed, 10 insertions(+), 6 deletions(-) (limited to 'railties') diff --git a/railties/test/generators/app_generator_test.rb b/railties/test/generators/app_generator_test.rb index e47d180809..e282c82faf 100644 --- a/railties/test/generators/app_generator_test.rb +++ b/railties/test/generators/app_generator_test.rb @@ -104,7 +104,7 @@ class AppGeneratorTest < Rails::Generators::TestCase end def test_skip_bundle - assert_not_called(generator([destination_root], skip_bundle: true), :bundle_command) do + assert_not_called(generator([destination_root], skip_bundle: true, skip_webpack_install: true), :bundle_command) do quietly { generator.invoke_all } # skip_bundle is only about running bundle install, ensure the Gemfile is still # generated. @@ -728,13 +728,13 @@ class AppGeneratorTest < Rails::Generators::TestCase end def test_generation_runs_bundle_install - generator([destination_root], {}) + generator([destination_root], skip_webpack_install: true) assert_bundler_command_called("install") end def test_dev_option - generator([destination_root], dev: true) + generator([destination_root], dev: true, skip_webpack_install: true) assert_bundler_command_called("install") rails_path = File.expand_path("../../..", Rails.root) @@ -742,7 +742,7 @@ class AppGeneratorTest < Rails::Generators::TestCase end def test_edge_option - generator([destination_root], edge: true) + generator([destination_root], edge: true, skip_webpack_install: true) assert_bundler_command_called("install") assert_file "Gemfile", %r{^gem\s+["']rails["'],\s+github:\s+["']#{Regexp.escape("rails/rails")}["']$} @@ -754,12 +754,16 @@ class AppGeneratorTest < Rails::Generators::TestCase end def test_bundler_binstub + generator([destination_root], skip_webpack_install: true) + assert_bundler_command_called("binstubs bundler") end def test_spring_binstubs jruby_skip "spring doesn't run on JRuby" + generator([destination_root], skip_webpack_install: true) + assert_bundler_command_called("exec spring binstub --all") end diff --git a/railties/test/generators/shared_generator_tests.rb b/railties/test/generators/shared_generator_tests.rb index fc654e867b..d61545a7b5 100644 --- a/railties/test/generators/shared_generator_tests.rb +++ b/railties/test/generators/shared_generator_tests.rb @@ -91,7 +91,7 @@ module SharedGeneratorTests template end - generator([destination_root], template: path).stub(:open, check_open, template) do + generator([destination_root], template: path, skip_webpack_install: true).stub(:open, check_open, template) do generator.stub :bundle_command, nil do quietly { assert_match(/It works!/, capture(:stdout) { generator.invoke_all }) } end @@ -99,7 +99,7 @@ module SharedGeneratorTests end def test_skip_gemfile - assert_not_called(generator([destination_root], skip_gemfile: true), :bundle_command) do + assert_not_called(generator([destination_root], skip_gemfile: true, skip_webpack_install: true), :bundle_command) do quietly { generator.invoke_all } assert_no_file "Gemfile" end -- cgit v1.2.3 From b004e767e03f11eb7e13828a5efbe030eb861cb0 Mon Sep 17 00:00:00 2001 From: Bogdan Date: Sun, 21 Oct 2018 20:29:58 +0300 Subject: Correct some tests related to changes in #33079 (#34272) * Fix assertions of auto-generated ActiveStorage JS Since #33079 * Correct message on the `assert_equal` failure Related to #33079 * Test ActionCable's js files This commit adds `app/javascript/channels/consumer.js`, and `app/javascript/channels/index.js` to `DEFAULT_APP_FILES` in order to assert their existance in `test_skeleton_is_created`. Related to #33079 * Assert no match `javascript_pack_tag` in `application.html.erb` Since #33079 `rails new` generates `application.html.erb` file with `javascript_pack_tag` instead of `javascript_include_tag`. Note that there some tests that asserting no matching `javascript_include_tag` in the `application.html.erb` file for newly generated rails plugins. It is related to #34009 and shouldn't be changed right now. --- railties/test/generators/app_generator_test.rb | 6 ++++-- railties/test/generators/shared_generator_tests.rb | 4 ++-- 2 files changed, 6 insertions(+), 4 deletions(-) (limited to 'railties') diff --git a/railties/test/generators/app_generator_test.rb b/railties/test/generators/app_generator_test.rb index e282c82faf..f5356a358f 100644 --- a/railties/test/generators/app_generator_test.rb +++ b/railties/test/generators/app_generator_test.rb @@ -15,6 +15,8 @@ DEFAULT_APP_FILES = %w( app/assets/images app/javascript app/javascript/channels + app/javascript/channels/consumer.js + app/javascript/channels/index.js app/javascript/packs/application.js app/assets/stylesheets app/assets/stylesheets/application.css @@ -608,7 +610,7 @@ class AppGeneratorTest < Rails::Generators::TestCase assert_file "app/views/layouts/application.html.erb" do |contents| assert_match(/stylesheet_link_tag\s+'application', media: 'all' %>/, contents) - assert_no_match(/javascript_include_tag\s+'application' \%>/, contents) + assert_no_match(/javascript_pack_tag\s+'application'/, contents) end end @@ -794,7 +796,7 @@ class AppGeneratorTest < Rails::Generators::TestCase @called ||= 0 if command == "webpacker:install" @called += 1 - assert_equal 0, @called, "webpacker:install expected not to be called once, but was called #{@called} times." + assert_equal 0, @called, "webpacker:install expected not to be called, but was called #{@called} times." end end diff --git a/railties/test/generators/shared_generator_tests.rb b/railties/test/generators/shared_generator_tests.rb index d61545a7b5..398466aa22 100644 --- a/railties/test/generators/shared_generator_tests.rb +++ b/railties/test/generators/shared_generator_tests.rb @@ -231,7 +231,7 @@ module SharedGeneratorTests assert_file "#{application_path}/config/application.rb", /#\s+require\s+["']active_storage\/engine["']/ assert_file "#{application_path}/app/javascript/packs/application.js" do |content| - assert_no_match(/^\/\/= require activestorage/, content) + assert_no_match(/activestorage/, content) end assert_file "#{application_path}/config/environments/development.rb" do |content| @@ -261,7 +261,7 @@ module SharedGeneratorTests assert_file "#{application_path}/config/application.rb", /#\s+require\s+["']active_storage\/engine["']/ assert_file "#{application_path}/app/javascript/packs/application.js" do |content| - assert_no_match(/^import * as ActiveStorage from "activestorage"\nActiveStorage.start()/, content) + assert_no_match(/^import * as ActiveStorage from "activestorage"\nActiveStorage.start\(\)/, content) end assert_file "#{application_path}/config/environments/development.rb" do |content| -- cgit v1.2.3 From 9629354abbb5e96142834497f80d267e96536ced Mon Sep 17 00:00:00 2001 From: bogdanvlviv Date: Sun, 21 Oct 2018 22:40:01 +0300 Subject: Remove yarn's files from `.gitignore` template for new rails app Webpacker already does it, see https://github.com/rails/webpacker/blob/895d2cfc15eda2edae9e667c642a02523d958f53/lib/install/template.rb#L25-L33 I also opened PR https://github.com/rails/webpacker/pull/1765 in order to make it add `/yarn-error.log` file too. --- railties/lib/rails/generators/rails/app/templates/gitignore.tt | 7 +------ railties/test/generators/shared_generator_tests.rb | 10 ---------- 2 files changed, 1 insertion(+), 16 deletions(-) (limited to 'railties') diff --git a/railties/lib/rails/generators/rails/app/templates/gitignore.tt b/railties/lib/rails/generators/rails/app/templates/gitignore.tt index 4e114fb1d9..38c3ab1319 100644 --- a/railties/lib/rails/generators/rails/app/templates/gitignore.tt +++ b/railties/lib/rails/generators/rails/app/templates/gitignore.tt @@ -27,14 +27,9 @@ <% if keeps? -%> !/storage/.keep <% end -%> -<% end -%> - -<% unless options.skip_yarn? -%> -/node_modules -/yarn-error.log - <% end -%> <% unless options.api? -%> + /public/assets <% end -%> .byebug_history diff --git a/railties/test/generators/shared_generator_tests.rb b/railties/test/generators/shared_generator_tests.rb index 398466aa22..9b980bd52b 100644 --- a/railties/test/generators/shared_generator_tests.rb +++ b/railties/test/generators/shared_generator_tests.rb @@ -339,11 +339,6 @@ module SharedGeneratorTests run_generator assert_file "#{application_path}/package.json", /dependencies/ assert_file "#{application_path}/config/initializers/assets.rb", /node_modules/ - - assert_file ".gitignore" do |content| - assert_match(/node_modules/, content) - assert_match(/yarn-error\.log/, content) - end end def test_generator_for_yarn_skipped @@ -354,10 +349,5 @@ module SharedGeneratorTests assert_file "#{application_path}/config/initializers/assets.rb" do |content| assert_no_match(/node_modules/, content) end - - assert_file ".gitignore" do |content| - assert_no_match(/node_modules/, content) - assert_no_match(/yarn-error\.log/, content) - end end end -- cgit v1.2.3 From 7093ee8ec5250545ba904a2cb1fcd67c5138cc3b Mon Sep 17 00:00:00 2001 From: bogdanvlviv Date: Mon, 22 Oct 2018 00:00:32 +0300 Subject: Remove `:javascript` from `Rails::PluginBuilder::PASSTHROUGH_OPTIONS` `--javascript` option was removed by 42198064c35ff3b701496309f90df2abc229efbe --- railties/lib/rails/generators/rails/plugin/plugin_generator.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties') diff --git a/railties/lib/rails/generators/rails/plugin/plugin_generator.rb b/railties/lib/rails/generators/rails/plugin/plugin_generator.rb index a018a98c53..532278f215 100644 --- a/railties/lib/rails/generators/rails/plugin/plugin_generator.rb +++ b/railties/lib/rails/generators/rails/plugin/plugin_generator.rb @@ -88,7 +88,7 @@ task default: :test PASSTHROUGH_OPTIONS = [ :skip_active_record, :skip_active_storage, :skip_action_mailer, :skip_javascript, :skip_action_cable, :skip_sprockets, :database, - :javascript, :skip_yarn, :api, :quiet, :pretend, :skip + :skip_yarn, :api, :quiet, :pretend, :skip ] def generate_test_dummy(force = false) -- cgit v1.2.3 From 24367edbe6dae8fa1878423254d445177540e739 Mon Sep 17 00:00:00 2001 From: bogdanvlviv Date: Mon, 22 Oct 2018 00:12:15 +0300 Subject: Remove `javascripts` and `javascript_engine` options for generators It is unused since #33079 --- railties/lib/rails/generators.rb | 2 -- 1 file changed, 2 deletions(-) (limited to 'railties') diff --git a/railties/lib/rails/generators.rb b/railties/lib/rails/generators.rb index cd8f16e247..5e8cebc50a 100644 --- a/railties/lib/rails/generators.rb +++ b/railties/lib/rails/generators.rb @@ -54,8 +54,6 @@ module Rails force_plural: false, helper: true, integration_tool: nil, - javascripts: true, - javascript_engine: :js, orm: false, resource_controller: :controller, resource_route: true, -- cgit v1.2.3 From 2593ee3f49d03f70799cc77e64f4c27954c908c8 Mon Sep 17 00:00:00 2001 From: bogdanvlviv Date: Mon, 22 Oct 2018 01:33:10 +0300 Subject: Remove extra call `remove_file` on `rails new` with `--skip_action_cable` There is no need to remove this file since the line below removes entire directory in which that file is placed. --- railties/lib/rails/generators/rails/app/app_generator.rb | 1 - 1 file changed, 1 deletion(-) (limited to 'railties') diff --git a/railties/lib/rails/generators/rails/app/app_generator.rb b/railties/lib/rails/generators/rails/app/app_generator.rb index b118ea989b..1c7cf1a951 100644 --- a/railties/lib/rails/generators/rails/app/app_generator.rb +++ b/railties/lib/rails/generators/rails/app/app_generator.rb @@ -438,7 +438,6 @@ module Rails def delete_action_cable_files_skipping_action_cable if options[:skip_action_cable] - remove_file "app/javascript/channels/consumer.js" remove_dir "app/javascript/channels" remove_dir "app/channels" end -- cgit v1.2.3 From 2e37fb655d44e29ea68c28957bfa047f40469aeb Mon Sep 17 00:00:00 2001 From: bogdanvlviv Date: Sun, 21 Oct 2018 23:08:43 +0300 Subject: Remove `--skip-yarn` in favor of `--skip-javascript` Since #33079 Webpacker the default JavaScript compiler for Rails. Webpacker uses `yarn` so seems like it doesn't make sense for Rails to keep `--skip-yarn` option. --- railties/lib/rails/app_updater.rb | 2 +- railties/lib/rails/generators/app_base.rb | 3 --- railties/lib/rails/generators/rails/app/app_generator.rb | 10 +++++----- railties/lib/rails/generators/rails/app/templates/bin/setup.tt | 4 ++-- .../lib/rails/generators/rails/app/templates/bin/update.tt | 4 ++-- .../rails/app/templates/config/initializers/assets.rb.tt | 2 +- railties/lib/rails/generators/rails/plugin/plugin_generator.rb | 2 +- .../lib/rails/generators/rails/plugin/templates/gitignore.tt | 2 +- railties/test/generators/app_generator_test.rb | 4 ++-- railties/test/generators/shared_generator_tests.rb | 3 ++- 10 files changed, 17 insertions(+), 19 deletions(-) (limited to 'railties') diff --git a/railties/lib/rails/app_updater.rb b/railties/lib/rails/app_updater.rb index a243968a39..19d136e041 100644 --- a/railties/lib/rails/app_updater.rb +++ b/railties/lib/rails/app_updater.rb @@ -21,7 +21,7 @@ module Rails private def generator_options options = { api: !!Rails.application.config.api_only, update: true } - options[:skip_yarn] = !File.exist?(Rails.root.join("bin", "yarn")) + options[:skip_javascript] = !File.exist?(Rails.root.join("bin", "yarn")) options[:skip_active_record] = !defined?(ActiveRecord::Railtie) options[:skip_active_storage] = !defined?(ActiveStorage::Engine) || !defined?(ActiveRecord::Railtie) options[:skip_action_mailer] = !defined?(ActionMailer::Railtie) diff --git a/railties/lib/rails/generators/app_base.rb b/railties/lib/rails/generators/app_base.rb index 2e4797e5bb..4dc4d27a46 100644 --- a/railties/lib/rails/generators/app_base.rb +++ b/railties/lib/rails/generators/app_base.rb @@ -31,9 +31,6 @@ module Rails class_option :database, type: :string, aliases: "-d", default: "sqlite3", desc: "Preconfigure for selected database (options: #{DATABASES.join('/')})" - class_option :skip_yarn, type: :boolean, default: false, - desc: "Don't use Yarn for managing JavaScript dependencies" - class_option :skip_gemfile, type: :boolean, default: false, desc: "Don't create a Gemfile" diff --git a/railties/lib/rails/generators/rails/app/app_generator.rb b/railties/lib/rails/generators/rails/app/app_generator.rb index 1c7cf1a951..f56f79b8d4 100644 --- a/railties/lib/rails/generators/rails/app/app_generator.rb +++ b/railties/lib/rails/generators/rails/app/app_generator.rb @@ -95,7 +95,7 @@ module Rails def bin_when_updating bin - if options[:skip_yarn] + if options[:skip_javascript] remove_file "bin/yarn" end end @@ -274,7 +274,7 @@ module Rails # Force sprockets and yarn to be skipped when generating API only apps. # Can't modify options hash as it's frozen by default. if options[:api] - self.options = options.merge(skip_sprockets: true, skip_javascript: true, skip_yarn: true).freeze + self.options = options.merge(skip_sprockets: true, skip_javascript: true).freeze end end @@ -289,7 +289,7 @@ module Rails build(:gitignore) unless options[:skip_git] build(:gemfile) unless options[:skip_gemfile] build(:version_control) - build(:package_json) unless options[:skip_yarn] + build(:package_json) unless options[:skip_javascript] end def create_app_files @@ -462,8 +462,8 @@ module Rails end end - def delete_bin_yarn_if_skip_yarn_option - remove_file "bin/yarn" if options[:skip_yarn] + def delete_bin_yarn + remove_file "bin/yarn" if options[:skip_javascript] end def finish_template diff --git a/railties/lib/rails/generators/rails/app/templates/bin/setup.tt b/railties/lib/rails/generators/rails/app/templates/bin/setup.tt index 955a424878..a18e03e7db 100644 --- a/railties/lib/rails/generators/rails/app/templates/bin/setup.tt +++ b/railties/lib/rails/generators/rails/app/templates/bin/setup.tt @@ -14,9 +14,9 @@ FileUtils.chdir APP_ROOT do puts '== Installing dependencies ==' system! 'gem install bundler --conservative' system('bundle check') || system!('bundle install') -<% unless options.skip_yarn? -%> +<% unless options.skip_javascript? -%> - # Install JavaScript dependencies if using Yarn + # Install JavaScript dependencies # system('bin/yarn') <% end -%> <% unless options.skip_active_record? -%> diff --git a/railties/lib/rails/generators/rails/app/templates/bin/update.tt b/railties/lib/rails/generators/rails/app/templates/bin/update.tt index ed17959e1d..03b77d0d46 100644 --- a/railties/lib/rails/generators/rails/app/templates/bin/update.tt +++ b/railties/lib/rails/generators/rails/app/templates/bin/update.tt @@ -14,9 +14,9 @@ FileUtils.chdir APP_ROOT do puts '== Installing dependencies ==' system! 'gem install bundler --conservative' system('bundle check') || system!('bundle install') -<% unless options.skip_yarn? -%> +<% unless options.skip_javascript? -%> - # Install JavaScript dependencies if using Yarn + # Install JavaScript dependencies # system('bin/yarn') <% end -%> <% unless options.skip_active_record? -%> diff --git a/railties/lib/rails/generators/rails/app/templates/config/initializers/assets.rb.tt b/railties/lib/rails/generators/rails/app/templates/config/initializers/assets.rb.tt index 51196ae743..e92382f2d9 100644 --- a/railties/lib/rails/generators/rails/app/templates/config/initializers/assets.rb.tt +++ b/railties/lib/rails/generators/rails/app/templates/config/initializers/assets.rb.tt @@ -5,7 +5,7 @@ Rails.application.config.assets.version = '1.0' # Add additional assets to the asset load path. # Rails.application.config.assets.paths << Emoji.images_path -<%- unless options[:skip_yarn] -%> +<%- unless options[:skip_javascript] -%> # Add Yarn node_modules folder to the asset load path. Rails.application.config.assets.paths << Rails.root.join('node_modules') <%- end -%> diff --git a/railties/lib/rails/generators/rails/plugin/plugin_generator.rb b/railties/lib/rails/generators/rails/plugin/plugin_generator.rb index 532278f215..239b3a5739 100644 --- a/railties/lib/rails/generators/rails/plugin/plugin_generator.rb +++ b/railties/lib/rails/generators/rails/plugin/plugin_generator.rb @@ -88,7 +88,7 @@ task default: :test PASSTHROUGH_OPTIONS = [ :skip_active_record, :skip_active_storage, :skip_action_mailer, :skip_javascript, :skip_action_cable, :skip_sprockets, :database, - :skip_yarn, :api, :quiet, :pretend, :skip + :api, :quiet, :pretend, :skip ] def generate_test_dummy(force = false) diff --git a/railties/lib/rails/generators/rails/plugin/templates/gitignore.tt b/railties/lib/rails/generators/rails/plugin/templates/gitignore.tt index 7a68da5c4b..0aabf09252 100644 --- a/railties/lib/rails/generators/rails/plugin/templates/gitignore.tt +++ b/railties/lib/rails/generators/rails/plugin/templates/gitignore.tt @@ -7,7 +7,7 @@ pkg/ <%= dummy_path %>/db/*.sqlite3-journal <% end -%> <%= dummy_path %>/log/*.log -<% unless options[:skip_yarn] -%> +<% unless options[:skip_javascript] -%> <%= dummy_path %>/node_modules/ <%= dummy_path %>/yarn-error.log <% end -%> diff --git a/railties/test/generators/app_generator_test.rb b/railties/test/generators/app_generator_test.rb index f5356a358f..bb3aaa9d14 100644 --- a/railties/test/generators/app_generator_test.rb +++ b/railties/test/generators/app_generator_test.rb @@ -300,10 +300,10 @@ class AppGeneratorTest < Rails::Generators::TestCase def test_app_update_does_not_generate_yarn_contents_when_bin_yarn_is_not_used app_root = File.join(destination_root, "myapp") - run_generator [app_root, "--skip-yarn"] + run_generator [app_root, "--skip-javascript"] stub_rails_application(app_root) do - generator = Rails::Generators::AppGenerator.new ["rails"], { update: true, skip_yarn: true }, { destination_root: app_root, shell: @shell } + generator = Rails::Generators::AppGenerator.new ["rails"], { update: true, skip_javascript: true }, { destination_root: app_root, shell: @shell } generator.send(:app_const) quietly { generator.send(:update_bin_files) } diff --git a/railties/test/generators/shared_generator_tests.rb b/railties/test/generators/shared_generator_tests.rb index 9b980bd52b..a40ad158af 100644 --- a/railties/test/generators/shared_generator_tests.rb +++ b/railties/test/generators/shared_generator_tests.rb @@ -336,13 +336,14 @@ module SharedGeneratorTests end def test_generator_for_yarn + skip "#34009 disabled JS by default for plugins" if generator_class.name == "Rails::Generators::PluginGenerator" run_generator assert_file "#{application_path}/package.json", /dependencies/ assert_file "#{application_path}/config/initializers/assets.rb", /node_modules/ end def test_generator_for_yarn_skipped - run_generator([destination_root, "--skip-yarn"]) + run_generator([destination_root, "--skip-javascript"]) assert_no_file "#{application_path}/package.json" assert_no_file "#{application_path}/bin/yarn" -- cgit v1.2.3 From 1a5b353961a374ecbd80c31d338f75b4d55dbe6d Mon Sep 17 00:00:00 2001 From: Jochem Schulenklopper Date: Mon, 22 Oct 2018 21:14:12 +0200 Subject: Add missing dot in comment in .gitignore template My submission for the tiniest commit and PR contest: add a missing dot in a comment line in the generator template for .gitignore. (I just noticed this missing; consistency is king :-) --- railties/lib/rails/generators/rails/app/templates/gitignore.tt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties') diff --git a/railties/lib/rails/generators/rails/app/templates/gitignore.tt b/railties/lib/rails/generators/rails/app/templates/gitignore.tt index 38c3ab1319..860baa1595 100644 --- a/railties/lib/rails/generators/rails/app/templates/gitignore.tt +++ b/railties/lib/rails/generators/rails/app/templates/gitignore.tt @@ -22,7 +22,7 @@ <% end -%> <% unless skip_active_storage? -%> -# Ignore uploaded files in development +# Ignore uploaded files in development. /storage/* <% if keeps? -%> !/storage/.keep -- cgit v1.2.3 From 129f8ac6ffcafb2e6e13c9ef13dda4cc47f5af0d Mon Sep 17 00:00:00 2001 From: bogdanvlviv Date: Mon, 22 Oct 2018 17:04:40 +0300 Subject: Remove node_modules path from assets load paths since we use webpack by default Related to #33079 --- .../generators/rails/app/templates/config/initializers/assets.rb.tt | 4 ---- railties/test/generators/shared_generator_tests.rb | 6 +----- 2 files changed, 1 insertion(+), 9 deletions(-) (limited to 'railties') diff --git a/railties/lib/rails/generators/rails/app/templates/config/initializers/assets.rb.tt b/railties/lib/rails/generators/rails/app/templates/config/initializers/assets.rb.tt index e92382f2d9..fe48fc34ee 100644 --- a/railties/lib/rails/generators/rails/app/templates/config/initializers/assets.rb.tt +++ b/railties/lib/rails/generators/rails/app/templates/config/initializers/assets.rb.tt @@ -5,10 +5,6 @@ Rails.application.config.assets.version = '1.0' # Add additional assets to the asset load path. # Rails.application.config.assets.paths << Emoji.images_path -<%- unless options[:skip_javascript] -%> -# Add Yarn node_modules folder to the asset load path. -Rails.application.config.assets.paths << Rails.root.join('node_modules') -<%- end -%> # Precompile additional assets. # application.js, application.css, and all non-JS/CSS in the app/assets diff --git a/railties/test/generators/shared_generator_tests.rb b/railties/test/generators/shared_generator_tests.rb index a40ad158af..2dda856f25 100644 --- a/railties/test/generators/shared_generator_tests.rb +++ b/railties/test/generators/shared_generator_tests.rb @@ -339,16 +339,12 @@ module SharedGeneratorTests skip "#34009 disabled JS by default for plugins" if generator_class.name == "Rails::Generators::PluginGenerator" run_generator assert_file "#{application_path}/package.json", /dependencies/ - assert_file "#{application_path}/config/initializers/assets.rb", /node_modules/ + assert_file "#{application_path}/bin/yarn" end def test_generator_for_yarn_skipped run_generator([destination_root, "--skip-javascript"]) assert_no_file "#{application_path}/package.json" assert_no_file "#{application_path}/bin/yarn" - - assert_file "#{application_path}/config/initializers/assets.rb" do |content| - assert_no_match(/node_modules/, content) - end end end -- cgit v1.2.3 From 8cdb5df7c5c966495730587470295ac2ab3ce7fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Mendon=C3=A7a=20Fran=C3=A7a?= Date: Tue, 23 Oct 2018 18:00:28 -0400 Subject: Do not need to mention the method that is being called in the exception What is important to tell is that the database configuration could not be loaded. Fixes #34296. --- railties/lib/rails/application/configuration.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties') diff --git a/railties/lib/rails/application/configuration.rb b/railties/lib/rails/application/configuration.rb index eae902a938..d6f8c4f47c 100644 --- a/railties/lib/rails/application/configuration.rb +++ b/railties/lib/rails/application/configuration.rb @@ -202,7 +202,7 @@ module Rails "Please note that YAML must be consistently indented using spaces. Tabs are not allowed. " \ "Error: #{e.message}" rescue => e - raise e, "Cannot load `Rails.application.database_configuration`:\n#{e.message}", e.backtrace + raise e, "Cannot load database configuration:\n#{e.message}", e.backtrace end def colorize_logging -- cgit v1.2.3 From ee9fc120242b83c64bf77af1b72082ac76319332 Mon Sep 17 00:00:00 2001 From: Kir Shatrov Date: Wed, 26 Sep 2018 17:25:20 +0100 Subject: Make AJ::Base#enqueue return false if the job wasn't enqueued --- .../app/templates/config/initializers/new_framework_defaults_6_0.rb.tt | 3 +++ 1 file changed, 3 insertions(+) (limited to 'railties') diff --git a/railties/lib/rails/generators/rails/app/templates/config/initializers/new_framework_defaults_6_0.rb.tt b/railties/lib/rails/generators/rails/app/templates/config/initializers/new_framework_defaults_6_0.rb.tt index 54eb0cb1d2..5cca8ae570 100644 --- a/railties/lib/rails/generators/rails/app/templates/config/initializers/new_framework_defaults_6_0.rb.tt +++ b/railties/lib/rails/generators/rails/app/templates/config/initializers/new_framework_defaults_6_0.rb.tt @@ -15,3 +15,6 @@ # This option is not backwards compatible with earlier Rails versions. # It's best enabled when your entire app is migrated and stable on 6.0. # Rails.application.config.action_dispatch.use_cookies_with_metadata = true + +# Return false instead of self when #enqueue method was aborted from the callback +Rails.application.config.active_job.return_false_on_aborted_enqueue = true -- cgit v1.2.3 From 639f8fd9e51e6aa0405ac8cebdced8abe9bedaf3 Mon Sep 17 00:00:00 2001 From: Yasuo Honda Date: Tue, 30 Oct 2018 12:17:48 +0000 Subject: Restore `encoding: utf8mb4` in database.yml rails/rails#33853 and rails/rails#33929 removed `encoding: utf8mb4` from database.yml since at that time MySQL 5.1 is supported with the master branch. Since MySQL 5.1 has been dropped, we can restore `encoding: utf8mb4` in database.yml --- .../rails/generators/rails/app/templates/config/databases/mysql.yml.tt | 1 + 1 file changed, 1 insertion(+) (limited to 'railties') diff --git a/railties/lib/rails/generators/rails/app/templates/config/databases/mysql.yml.tt b/railties/lib/rails/generators/rails/app/templates/config/databases/mysql.yml.tt index 5860563908..b6c2e7448a 100644 --- a/railties/lib/rails/generators/rails/app/templates/config/databases/mysql.yml.tt +++ b/railties/lib/rails/generators/rails/app/templates/config/databases/mysql.yml.tt @@ -11,6 +11,7 @@ # default: &default adapter: mysql2 + encoding: utf8mb4 pool: <%%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %> username: root password: -- cgit v1.2.3 From caad9e1080e5b98bc8b3c40c0f2d226a3a9e859a Mon Sep 17 00:00:00 2001 From: "yuuji.yaginuma" Date: Sun, 4 Nov 2018 10:00:19 +0900 Subject: Keep new line after the last dependency If add a package with `yarn`, it will have a newline after the last dependency so let's match with that. --- railties/lib/rails/generators/rails/app/templates/package.json.tt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties') diff --git a/railties/lib/rails/generators/rails/app/templates/package.json.tt b/railties/lib/rails/generators/rails/app/templates/package.json.tt index a654cba39c..7174116989 100644 --- a/railties/lib/rails/generators/rails/app/templates/package.json.tt +++ b/railties/lib/rails/generators/rails/app/templates/package.json.tt @@ -5,7 +5,7 @@ "rails-ujs": ">=5.2.1"<% unless options[:skip_turbolinks] %>, "turbolinks": "5.1.1"<% end -%><% unless skip_active_storage? %>, "activestorage": ">=5.2.1"<% end -%><% unless options[:skip_action_cable] %>, - "actioncable": ">=5.2.1"<% end -%> + "actioncable": ">=5.2.1"<% end %> }, "version": "0.1.0" } -- cgit v1.2.3 From fd30a3237c572fc9727a4dc59edbb08b6569a761 Mon Sep 17 00:00:00 2001 From: "yuuji.yaginuma" Date: Fri, 12 Oct 2018 18:14:48 +0900 Subject: Add `connect_src` example to content security policy initializer If want to use `webpack-dev-server` with CSP enabled, need to specify `connect-src`. Related to: https://github.com/rails/webpacker/commit/cd7ecf4d48496341aecd81c0c2f69fe4e50a7cd4 This is a matter of `webpacker`. But since `webpacker` is now used by default, to prevent user confusion, I think that better to include an example of `connect-src.` --- .../config/initializers/content_security_policy.rb.tt | 4 ++++ railties/test/generators/app_generator_test.rb | 11 +++++++++++ 2 files changed, 15 insertions(+) (limited to 'railties') diff --git a/railties/lib/rails/generators/rails/app/templates/config/initializers/content_security_policy.rb.tt b/railties/lib/rails/generators/rails/app/templates/config/initializers/content_security_policy.rb.tt index d3bcaa5ec8..c517b0f96b 100644 --- a/railties/lib/rails/generators/rails/app/templates/config/initializers/content_security_policy.rb.tt +++ b/railties/lib/rails/generators/rails/app/templates/config/initializers/content_security_policy.rb.tt @@ -11,6 +11,10 @@ # policy.object_src :none # policy.script_src :self, :https # policy.style_src :self, :https +<%- unless options[:skip_javascript] -%> +# # If you are using webpack-dev-server then specify webpack-dev-server host +# policy.connect_src :self, :https, "http://localhost:3035", "ws://localhost:3035" if Rails.env.development? +<%- end -%> # # Specify URI for violation reports # # policy.report_uri "/csp-violation-report-endpoint" diff --git a/railties/test/generators/app_generator_test.rb b/railties/test/generators/app_generator_test.rb index bb3aaa9d14..32d00f3157 100644 --- a/railties/test/generators/app_generator_test.rb +++ b/railties/test/generators/app_generator_test.rb @@ -230,6 +230,14 @@ class AppGeneratorTest < Rails::Generators::TestCase assert_equal "false\n", output end + def test_csp_initializer_include_connect_src_example + run_generator + + assert_file "config/initializers/content_security_policy.rb" do |content| + assert_match(/# policy\.connect_src/, content) + end + end + def test_app_update_keep_the_cookie_serializer_if_it_is_already_configured app_root = File.join(destination_root, "myapp") run_generator [app_root] @@ -807,6 +815,9 @@ class AppGeneratorTest < Rails::Generators::TestCase end assert_no_gem "webpacker" + assert_file "config/initializers/content_security_policy.rb" do |content| + assert_no_match(/policy\.connect_src/, content) + end end def test_webpack_option_with_js_framework -- cgit v1.2.3 From 1c11688b5624394c3792d1bb37599fd1e3452c9c Mon Sep 17 00:00:00 2001 From: Gannon McGibbon Date: Tue, 6 Nov 2018 14:17:23 -0500 Subject: Add CVE note to security guide and gemspecs [ci skip] --- railties/railties.gemspec | 3 +++ 1 file changed, 3 insertions(+) (limited to 'railties') diff --git a/railties/railties.gemspec b/railties/railties.gemspec index 6fdb4648c2..98155a35e3 100644 --- a/railties/railties.gemspec +++ b/railties/railties.gemspec @@ -2,6 +2,9 @@ version = File.read(File.expand_path("../RAILS_VERSION", __dir__)).strip +# NOTE: There's no need to update dependencies for CVEs in minor +# releases when users can simply run `bundle update vulnerable_gem`. + Gem::Specification.new do |s| s.platform = Gem::Platform::RUBY s.name = "railties" -- cgit v1.2.3 From e74fdbe00cd0f403d34f2bc83eb09e7a5bc56109 Mon Sep 17 00:00:00 2001 From: Gannon McGibbon Date: Tue, 6 Nov 2018 18:05:40 -0500 Subject: Amend CVE note and security guide section wordings Reword first sentence of dep management and CVE section of security guide. Also, reword and move gemspec notes above deps. [ci skip] --- railties/railties.gemspec | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'railties') diff --git a/railties/railties.gemspec b/railties/railties.gemspec index 98155a35e3..4e4a504c97 100644 --- a/railties/railties.gemspec +++ b/railties/railties.gemspec @@ -2,9 +2,6 @@ version = File.read(File.expand_path("../RAILS_VERSION", __dir__)).strip -# NOTE: There's no need to update dependencies for CVEs in minor -# releases when users can simply run `bundle update vulnerable_gem`. - Gem::Specification.new do |s| s.platform = Gem::Platform::RUBY s.name = "railties" @@ -33,6 +30,9 @@ Gem::Specification.new do |s| "changelog_uri" => "https://github.com/rails/rails/blob/v#{version}/railties/CHANGELOG.md" } + # NOTE: Please read our dependency guidelines before updating versions: + # https://edgeguides.rubyonrails.org/security.html#dependency-management-and-cves + s.add_dependency "activesupport", version s.add_dependency "actionpack", version -- cgit v1.2.3 From b6e4305c3bca4c673996d0af9db0f4cfbf50215e Mon Sep 17 00:00:00 2001 From: Yoshiyuki Hirano Date: Tue, 6 Nov 2018 23:20:56 +0900 Subject: Add JSON support to rails properties route (`/rails/info/properties`). Added json format, like this: { "Rails version": "6.0.0.alpha", "Ruby version": "2.5.1-p57 (x86_64-darwin17)", "RubyGems version": "2.7.6", "Rack version": "2.0.6", "JavaScript Runtime": "Node.js (V8)", "Middleware": ["Rack::Sendfile", "ActionDispatch::Static", "ActionDispatch::Executor", "ActiveSupport::Cache::Strategy::LocalCache::Middleware", "Rack::Runtime", "Rack::MethodOverride", "ActionDispatch::RequestId", "ActionDispatch::RemoteIp", "Sprockets::Rails::QuietAssets", "Rails::Rack::Logger", "ActionDispatch::ShowExceptions", "WebConsole::Middleware", "ActionDispatch::DebugExceptions", "ActionDispatch::Reloader", "ActionDispatch::Callbacks", "ActiveRecord::Migration::CheckPending", "ActionDispatch::Cookies", "ActionDispatch::Session::CookieStore", "ActionDispatch::Flash", "ActionDispatch::ContentSecurityPolicy::Middleware", "Rack::Head", "Rack::ConditionalGet", "Rack::ETag", "Rack::TempfileReaper"], "Application root": "/path/to/app", "Environment": "development", "Database adapter": "sqlite3", "Database schema version": 0 } --- railties/CHANGELOG.md | 6 ++++++ railties/lib/rails/info.rb | 4 ++++ railties/lib/rails/info_controller.rb | 12 ++++++++++-- railties/test/rails_info_controller_test.rb | 5 +++++ railties/test/rails_info_test.rb | 12 ++++++++++++ 5 files changed, 37 insertions(+), 2 deletions(-) (limited to 'railties') diff --git a/railties/CHANGELOG.md b/railties/CHANGELOG.md index f94b67a0ac..65dccbb3be 100644 --- a/railties/CHANGELOG.md +++ b/railties/CHANGELOG.md @@ -1,3 +1,9 @@ +* Add JSON support to rails properties route (`/rails/info/properties`). + + Now, `Rails::Info` properties may be accessed in JSON format at `/rails/info/properties.json`. + + *Yoshiyuki Hirano* + * Use Ids instead of memory addresses when displaying references in scaffold views. Fixes #29200. diff --git a/railties/lib/rails/info.rb b/railties/lib/rails/info.rb index 3df36efc4c..b8173c8d11 100644 --- a/railties/lib/rails/info.rb +++ b/railties/lib/rails/info.rb @@ -54,6 +54,10 @@ module Rails table << "" end end + + def to_json + Hash[properties].to_json + end end # The Rails version. diff --git a/railties/lib/rails/info_controller.rb b/railties/lib/rails/info_controller.rb index b4f4a5922a..50fe176946 100644 --- a/railties/lib/rails/info_controller.rb +++ b/railties/lib/rails/info_controller.rb @@ -14,8 +14,16 @@ class Rails::InfoController < Rails::ApplicationController # :nodoc: end def properties - @info = Rails::Info.to_html - @page_title = "Properties" + respond_to do |format| + format.html do + @info = Rails::Info.to_html + @page_title = "Properties" + end + + format.json do + render json: Rails::Info.to_json + end + end end def routes diff --git a/railties/test/rails_info_controller_test.rb b/railties/test/rails_info_controller_test.rb index 878a238f8d..6ab68f8333 100644 --- a/railties/test/rails_info_controller_test.rb +++ b/railties/test/rails_info_controller_test.rb @@ -50,6 +50,11 @@ class InfoControllerTest < ActionController::TestCase assert_select "table" end + test "info controller renders json with properties" do + get :properties, format: :json + assert_equal Rails::Info.to_json, response.body + end + test "info controller renders with routes" do get :routes assert_response :success diff --git a/railties/test/rails_info_test.rb b/railties/test/rails_info_test.rb index 50522c1be6..d167a86e56 100644 --- a/railties/test/rails_info_test.rb +++ b/railties/test/rails_info_test.rb @@ -43,6 +43,18 @@ class InfoTest < ActiveSupport::TestCase end end + def test_json_includes_middleware + Rails::Info.module_eval do + property "Middleware", ["Rack::Lock", "Rack::Static"] + end + + hash = JSON.parse(Rails::Info.to_json) + assert_includes hash.keys, "Middleware" + properties.value_for("Middleware").each do |value| + assert_includes hash["Middleware"], value + end + end + private def properties Rails::Info.properties -- cgit v1.2.3 From ac18bda92d87ee5a426e5bcbe60c0499ea53995e Mon Sep 17 00:00:00 2001 From: Gannon McGibbon Date: Fri, 5 Oct 2018 16:06:10 -0400 Subject: Add multi-db support to schema cache dump and clear Adds support for multiple databases to `rails db:schema:cache:dump` and `rails db:schema:cache:clear`. --- railties/test/application/rake/multi_dbs_test.rb | 31 ++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'railties') diff --git a/railties/test/application/rake/multi_dbs_test.rb b/railties/test/application/rake/multi_dbs_test.rb index 6478e06250..52f4a5fa3c 100644 --- a/railties/test/application/rake/multi_dbs_test.rb +++ b/railties/test/application/rake/multi_dbs_test.rb @@ -65,6 +65,27 @@ module ApplicationTests end end + def db_migrate_and_schema_cache_dump + Dir.chdir(app_path) do + generate_models_for_animals + rails "db:migrate" + rails "db:schema:cache:dump" + assert File.exist?("db/schema_cache.yml") + assert File.exist?("db/animals_schema_cache.yml") + end + end + + def db_migrate_and_schema_cache_dump_and_schema_cache_clear + Dir.chdir(app_path) do + generate_models_for_animals + rails "db:migrate" + rails "db:schema:cache:dump" + rails "db:schema:cache:clear" + assert_not File.exist?("db/schema_cache.yml") + assert_not File.exist?("db/animals_schema_cache.yml") + end + end + def db_migrate_and_schema_dump_and_load(format) Dir.chdir(app_path) do generate_models_for_animals @@ -194,6 +215,16 @@ module ApplicationTests db_migrate_status_namespaced db_config.spec_name, db_config.config["database"] end end + + test "db:schema:cache:dump works on all databases" do + require "#{app_path}/config/environment" + db_migrate_and_schema_cache_dump + end + + test "db:schema:cache:clear works on all databases" do + require "#{app_path}/config/environment" + db_migrate_and_schema_cache_dump_and_schema_cache_clear + end end end end -- cgit v1.2.3 From 7f7e7e8b39f56d35993bec4247ac0295cd0c943e Mon Sep 17 00:00:00 2001 From: "yuuji.yaginuma" Date: Thu, 8 Nov 2018 12:21:25 +0900 Subject: Compile packs for test `Webpacker` handles testing / development packs separately by default. If do not specify `RAILS_ENV`, there is no merit to precompile. --- railties/test/application/rake_test.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'railties') diff --git a/railties/test/application/rake_test.rb b/railties/test/application/rake_test.rb index a0cdae898b..c38b91ef03 100644 --- a/railties/test/application/rake_test.rb +++ b/railties/test/application/rake_test.rb @@ -189,8 +189,10 @@ module ApplicationTests rails "generate", "model", "Product" rails "generate", "model", "Cart" rails "generate", "scaffold", "LineItems", "product:references", "cart:belongs_to" - with_rails_env("test") { rails("db:migrate") } - rails("webpacker:compile") + with_rails_env("test") do + rails("db:migrate") + rails("webpacker:compile") + end output = rails("test") assert_match(/7 runs, 9 assertions, 0 failures, 0 errors/, output) -- cgit v1.2.3 From a444bae3f29ffc09231e31526631bcb35fa2bfa0 Mon Sep 17 00:00:00 2001 From: bogdanvlviv Date: Thu, 8 Nov 2018 16:03:44 +0200 Subject: Remove unused argument `expected_database` This argument was added in fa5a028ed9f, and #34137 but hasn't been used. --- railties/test/application/rake/multi_dbs_test.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'railties') diff --git a/railties/test/application/rake/multi_dbs_test.rb b/railties/test/application/rake/multi_dbs_test.rb index 52f4a5fa3c..ef99365e75 100644 --- a/railties/test/application/rake/multi_dbs_test.rb +++ b/railties/test/application/rake/multi_dbs_test.rb @@ -113,7 +113,7 @@ module ApplicationTests end end - def db_migrate_namespaced(namespace, expected_database) + def db_migrate_namespaced(namespace) Dir.chdir(app_path) do generate_models_for_animals output = rails("db:migrate:#{namespace}") @@ -125,7 +125,7 @@ module ApplicationTests end end - def db_migrate_status_namespaced(namespace, expected_database) + def db_migrate_status_namespaced(namespace) Dir.chdir(app_path) do generate_models_for_animals output = rails("db:migrate:status:#{namespace}") @@ -199,7 +199,7 @@ module ApplicationTests test "db:migrate:namespace works" do require "#{app_path}/config/environment" ActiveRecord::Base.configurations.configs_for(env_name: Rails.env).each do |db_config| - db_migrate_namespaced db_config.spec_name, db_config.config["database"] + db_migrate_namespaced db_config.spec_name end end @@ -211,8 +211,8 @@ module ApplicationTests test "db:migrate:status:namespace works" do require "#{app_path}/config/environment" ActiveRecord::Base.configurations.configs_for(env_name: Rails.env).each do |db_config| - db_migrate_namespaced db_config.spec_name, db_config.config["database"] - db_migrate_status_namespaced db_config.spec_name, db_config.config["database"] + db_migrate_namespaced db_config.spec_name + db_migrate_status_namespaced db_config.spec_name end end -- cgit v1.2.3 From 0712dfd6ae1423269af1512c3403ee1145f27de1 Mon Sep 17 00:00:00 2001 From: Gannon McGibbon Date: Thu, 8 Nov 2018 10:59:52 -0500 Subject: Windows support for parallelization and instrumenter Add Windows support for `ActiveSupport::Testing::Parallelization` and `ActiveSupport::Notifications::Instrumenter`. --- .../lib/rails/generators/rails/app/templates/test/test_helper.rb.tt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties') diff --git a/railties/lib/rails/generators/rails/app/templates/test/test_helper.rb.tt b/railties/lib/rails/generators/rails/app/templates/test/test_helper.rb.tt index c918b57eca..c06cd525d7 100644 --- a/railties/lib/rails/generators/rails/app/templates/test/test_helper.rb.tt +++ b/railties/lib/rails/generators/rails/app/templates/test/test_helper.rb.tt @@ -4,7 +4,7 @@ require 'rails/test_help' class ActiveSupport::TestCase # Run tests in parallel with specified workers -<% if defined?(JRUBY_VERSION) -%> +<% if defined?(JRUBY_VERSION) || Gem.win_platform? -%> parallelize(workers: 2, with: :threads) <%- else -%> parallelize(workers: 2) -- cgit v1.2.3 From 9bd5fc84ccaa59bd9ca8e81145e5ce15fbac75d2 Mon Sep 17 00:00:00 2001 From: "yuuji.yaginuma" Date: Fri, 9 Nov 2018 18:25:26 +0900 Subject: Add test for parallel tests with unmarshable exception Follow up #34131. --- railties/test/application/test_runner_test.rb | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'railties') diff --git a/railties/test/application/test_runner_test.rb b/railties/test/application/test_runner_test.rb index 5c34b205c9..0046fec062 100644 --- a/railties/test/application/test_runner_test.rb +++ b/railties/test/application/test_runner_test.rb @@ -562,6 +562,30 @@ module ApplicationTests assert_no_match "create_table(:users)", output end + def test_run_in_parallel_with_unmarshable_exception + file = app_file "test/fail_test.rb", <<-RUBY + require "test_helper" + class FailTest < ActiveSupport::TestCase + class BadError < StandardError + def initialize + super + @proc = ->{ } + end + end + + test "fail" do + raise BadError + assert true + end + end + RUBY + + output = run_test_command(file) + + assert_match "DRb::DRbRemoteError: FailTest::BadError", output + assert_match "1 runs, 0 assertions, 0 failures, 1 errors", output + end + def test_raise_error_when_specified_file_does_not_exist error = capture(:stderr) { run_test_command("test/not_exists.rb", stderr: true) } assert_match(%r{cannot load such file.+test/not_exists\.rb}, error) -- cgit v1.2.3 From cffbf73a4761816d894a49fbec7f070f27ebbff4 Mon Sep 17 00:00:00 2001 From: Gannon McGibbon Date: Wed, 7 Nov 2018 18:12:17 -0500 Subject: Remove asset paths from eager_load_paths and autoload_paths Remove `app/assets` and `app/javascript` from `eager_load_paths` and `autoload_paths`. --- railties/CHANGELOG.md | 4 ++++ railties/lib/rails/engine/configuration.rb | 4 +++- railties/lib/rails/paths.rb | 28 +++++++++++++++++-------- railties/test/application/configuration_test.rb | 8 +++++++ 4 files changed, 34 insertions(+), 10 deletions(-) (limited to 'railties') diff --git a/railties/CHANGELOG.md b/railties/CHANGELOG.md index 65dccbb3be..448fd48f10 100644 --- a/railties/CHANGELOG.md +++ b/railties/CHANGELOG.md @@ -1,3 +1,7 @@ +* Remove `app/assets` and `app/javascript` from `eager_load_paths` and `autoload_paths`. + + *Gannon McGibbon* + * Add JSON support to rails properties route (`/rails/info/properties`). Now, `Rails::Info` properties may be accessed in JSON format at `/rails/info/properties.json`. diff --git a/railties/lib/rails/engine/configuration.rb b/railties/lib/rails/engine/configuration.rb index 6bf0406b21..4143b3c881 100644 --- a/railties/lib/rails/engine/configuration.rb +++ b/railties/lib/rails/engine/configuration.rb @@ -38,7 +38,9 @@ module Rails @paths ||= begin paths = Rails::Paths::Root.new(@root) - paths.add "app", eager_load: true, glob: "{*,*/concerns}" + paths.add "app", eager_load: true, + glob: "{*,*/concerns}", + exclude: %w(assets javascript) paths.add "app/assets", glob: "*" paths.add "app/controllers", eager_load: true paths.add "app/channels", eager_load: true, glob: "**/*_channel.rb" diff --git a/railties/lib/rails/paths.rb b/railties/lib/rails/paths.rb index 87222563fd..8367ac8980 100644 --- a/railties/lib/rails/paths.rb +++ b/railties/lib/rails/paths.rb @@ -113,10 +113,11 @@ module Rails attr_accessor :glob def initialize(root, current, paths, options = {}) - @paths = paths - @current = current - @root = root - @glob = options[:glob] + @paths = paths + @current = current + @root = root + @glob = options[:glob] + @exclude = options[:exclude] options[:autoload_once] ? autoload_once! : skip_autoload_once! options[:eager_load] ? eager_load! : skip_eager_load! @@ -189,13 +190,11 @@ module Rails raise "You need to set a path root" unless @root.path result = [] - each do |p| - path = File.expand_path(p, @root.path) + each do |path| + path = File.expand_path(path, @root.path) if @glob && File.directory?(path) - Dir.chdir(path) do - result.concat(Dir.glob(@glob).map { |file| File.join path, file }.sort) - end + result.concat files_in(path) else result << path end @@ -222,6 +221,17 @@ module Rails end alias to_a expanded + + private + + def files_in(path) + Dir.chdir(path) do + files = Dir.glob(@glob) + files -= @exclude if @exclude + files.map! { |file| File.join(path, file) } + files.sort + end + end end end end diff --git a/railties/test/application/configuration_test.rb b/railties/test/application/configuration_test.rb index fa418f564b..b8a0434432 100644 --- a/railties/test/application/configuration_test.rb +++ b/railties/test/application/configuration_test.rb @@ -1663,6 +1663,14 @@ module ApplicationTests assert_kind_of Hash, Rails.application.config.database_configuration end + test "autoload paths do not include asset paths" do + app "development" + ActiveSupport::Dependencies.autoload_paths.each do |path| + assert_not_operator path, :ends_with?, "app/assets" + assert_not_operator path, :ends_with?, "app/javascript" + end + end + test "raises with proper error message if no database configuration found" do FileUtils.rm("#{app_path}/config/database.yml") err = assert_raises RuntimeError do -- cgit v1.2.3 From 59895db44b73b9a333387eee2078fda8feec9ce5 Mon Sep 17 00:00:00 2001 From: Maxim Perepelitsa Date: Fri, 9 Nov 2018 01:03:04 +0700 Subject: Reset sessions on failed system test screenshot Reset Capybara sessions if `take_failed_screenshot` raise exception in system test `after_teardown`. --- railties/test/application/test_runner_test.rb | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'railties') diff --git a/railties/test/application/test_runner_test.rb b/railties/test/application/test_runner_test.rb index 5c34b205c9..e98a41fb26 100644 --- a/railties/test/application/test_runner_test.rb +++ b/railties/test/application/test_runner_test.rb @@ -703,6 +703,31 @@ module ApplicationTests end end + def test_reset_sessions_on_failed_system_test_screenshot + app_file "test/system/reset_sessions_on_failed_system_test_screenshot_test.rb", <<~RUBY + require "application_system_test_case" + + class ResetSessionsOnFailedSystemTestScreenshotTest < ApplicationSystemTestCase + ActionDispatch::SystemTestCase.class_eval do + def take_failed_screenshot + raise Capybara::CapybaraError + end + end + + Capybara.instance_eval do + def reset_sessions! + puts "Capybara.reset_sessions! called" + end + end + + test "dummy" do + end + end + RUBY + output = run_test_command("test/system/reset_sessions_on_failed_system_test_screenshot_test.rb") + assert_match "Capybara.reset_sessions! called", output + end + def test_system_tests_are_not_run_with_the_default_test_command app_file "test/system/dummy_test.rb", <<-RUBY require "application_system_test_case" -- cgit v1.2.3 From 8ac839625976be543be758d41767120d714bf30c Mon Sep 17 00:00:00 2001 From: Yasuo Honda Date: Tue, 13 Nov 2018 11:19:03 +0000 Subject: Ignore warnings such as `Psych.safe_load is deprecated` Addressing warnings are important but it should be out of this test scope. https://travis-ci.org/rails/rails/jobs/454145524#L4122-L4131 ``` .F Failure: ApplicationTests::BinSetupTest#test_bin_setup_output [test/application/bin_setup_test.rb:49]: --- expected +++ actual @@ -1,4 +1,5 @@ "== Installing dependencies == +warning: Passing permitted_classes with the 2nd argument of Psych.safe_load is deprecated. Use keyword argument like Psych.safe_load(yaml, permitted_classes: ...) instead. The Gemfile's dependencies are satisfied == Preparing database == rails test test/application/bin_setup_test.rb:38 ``` --- railties/test/application/bin_setup_test.rb | 2 ++ 1 file changed, 2 insertions(+) (limited to 'railties') diff --git a/railties/test/application/bin_setup_test.rb b/railties/test/application/bin_setup_test.rb index d02100d94c..a952d2466b 100644 --- a/railties/test/application/bin_setup_test.rb +++ b/railties/test/application/bin_setup_test.rb @@ -45,6 +45,8 @@ module ApplicationTests output.sub!(/^Resolving dependencies\.\.\.\n/, "") # Suppress Bundler platform warnings from output output.gsub!(/^The dependency .* will be unused .*\.\n/, "") + # Ignore warnings such as `Psych.safe_load is deprecated` + output.gsub!(/^warning:\s.*\n/, "") assert_equal(<<~OUTPUT, output) == Installing dependencies == -- cgit v1.2.3 From 0d90d1e019bd0cfb9dbb9c7e463de32bf87387d6 Mon Sep 17 00:00:00 2001 From: Alessandro Rodi Date: Tue, 13 Nov 2018 16:06:42 +0100 Subject: add a nice alias for the --webpack option --- railties/lib/rails/generators/rails/app/app_generator.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'railties') diff --git a/railties/lib/rails/generators/rails/app/app_generator.rb b/railties/lib/rails/generators/rails/app/app_generator.rb index f56f79b8d4..33002790d4 100644 --- a/railties/lib/rails/generators/rails/app/app_generator.rb +++ b/railties/lib/rails/generators/rails/app/app_generator.rb @@ -258,8 +258,8 @@ module Rails class_option :skip_bundle, type: :boolean, aliases: "-B", default: false, desc: "Don't run bundle install" - class_option :webpack, type: :string, default: nil, - desc: "Preconfigure Webpack with a particular framework (options: #{WEBPACKS.join('/')})" + class_option :webpack, type: :string, aliases: "--webpacker", default: nil, + desc: "Preconfigure Webpack with a particular framework (options: #{WEBPACKS.join(", ")})" class_option :skip_webpack_install, type: :boolean, default: false, desc: "Don't run Webpack install" -- cgit v1.2.3 From 667274edacabcfc7318832ed3048d8e118d6e3be Mon Sep 17 00:00:00 2001 From: Nihad Abbasov Date: Thu, 15 Nov 2018 18:17:35 +0400 Subject: Fix a method call in bin/setup file Follow up to a725539de677adbea0ced19d65647e975dbd3f84 --- railties/lib/rails/generators/rails/app/templates/bin/setup.tt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties') diff --git a/railties/lib/rails/generators/rails/app/templates/bin/setup.tt b/railties/lib/rails/generators/rails/app/templates/bin/setup.tt index a18e03e7db..3f73bae3da 100644 --- a/railties/lib/rails/generators/rails/app/templates/bin/setup.tt +++ b/railties/lib/rails/generators/rails/app/templates/bin/setup.tt @@ -23,7 +23,7 @@ FileUtils.chdir APP_ROOT do # puts "\n== Copying sample files ==" # unless File.exist?('config/database.yml') - # cp 'config/database.yml.sample', 'config/database.yml' + # FileUtils.cp 'config/database.yml.sample', 'config/database.yml' # end puts "\n== Preparing database ==" -- cgit v1.2.3 From 90266a7f1eff7c873cba7044fa0a4487b2a6ff84 Mon Sep 17 00:00:00 2001 From: "yuuji.yaginuma" Date: Fri, 16 Nov 2018 21:25:14 +0900 Subject: Correctly handle unknown object in parallel tests DRb wraps in `DRbUnknown` if the data contains a type that can not be resolved locally. This can happen if an error occurs in the test and the error class can not be resolved on the server side. When this happens, an instance of `DRbUnknown` is passed to the `result` of `Server#record`. This causes another error(undefined method assertions for # (NoMethodError)) in `reporter.record`. This can confirm by the following steps. ``` $ rails new app -B --dev; cd app $ rails g scaffold user name:string $ edit `config.action_controller.allow_forgery_protection = true` in environments/test.rb $ bin/rails t ``` In the case of `DRbUnknown` occurs, can't resolve error exception. So wrap exception with `DRbRemoteError` in the same way as an unmarshalled object. --- railties/test/application/test_runner_test.rb | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'railties') diff --git a/railties/test/application/test_runner_test.rb b/railties/test/application/test_runner_test.rb index 0d7645e794..140703e118 100644 --- a/railties/test/application/test_runner_test.rb +++ b/railties/test/application/test_runner_test.rb @@ -586,6 +586,20 @@ module ApplicationTests assert_match "1 runs, 0 assertions, 0 failures, 1 errors", output end + def test_run_in_parallel_with_unknown_object + create_scaffold + app_file "config/environments/test.rb", <<-RUBY + Rails.application.configure do + config.action_controller.allow_forgery_protection = true + config.action_dispatch.show_exceptions = false + end + RUBY + + output = run_test_command("-n test_should_create_user") + + assert_match "ActionController::InvalidAuthenticityToken", output + end + def test_raise_error_when_specified_file_does_not_exist error = capture(:stderr) { run_test_command("test/not_exists.rb", stderr: true) } assert_match(%r{cannot load such file.+test/not_exists\.rb}, error) -- cgit v1.2.3 From 218e50ce59c3abfa5ffdfac253cdeb2f74602da0 Mon Sep 17 00:00:00 2001 From: "yuuji.yaginuma" Date: Sun, 18 Nov 2018 09:46:41 +0900 Subject: Fix test name to match the test behavior These tests are for testing the `rake` method. --- railties/test/generators/actions_test.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'railties') diff --git a/railties/test/generators/actions_test.rb b/railties/test/generators/actions_test.rb index 6d53230eab..a2b35124c5 100644 --- a/railties/test/generators/actions_test.rb +++ b/railties/test/generators/actions_test.rb @@ -308,7 +308,7 @@ class ActionsTest < Rails::Generators::TestCase end end - def test_rails_should_run_rake_command_with_default_env + def test_rake_should_run_rake_command_with_default_env assert_called_with(generator, :run, ["rake log:clear RAILS_ENV=development", verbose: false]) do with_rails_env nil do action :rake, "log:clear" @@ -316,13 +316,13 @@ class ActionsTest < Rails::Generators::TestCase end end - def test_rails_with_env_option_should_run_rake_command_in_env + def test_rake_with_env_option_should_run_rake_command_in_env assert_called_with(generator, :run, ["rake log:clear RAILS_ENV=production", verbose: false]) do action :rake, "log:clear", env: "production" end end - test "rails command with RAILS_ENV variable should run rake command in env" do + test "rake with RAILS_ENV variable should run rake command in env" do assert_called_with(generator, :run, ["rake log:clear RAILS_ENV=production", verbose: false]) do with_rails_env "production" do action :rake, "log:clear" @@ -338,7 +338,7 @@ class ActionsTest < Rails::Generators::TestCase end end - test "rails command with sudo option should run rake command with sudo" do + test "rake with sudo option should run rake command with sudo" do assert_called_with(generator, :run, ["sudo rake log:clear RAILS_ENV=development", verbose: false]) do with_rails_env nil do action :rake, "log:clear", sudo: true -- cgit v1.2.3 From f553be8908325d54674c4989d45e8d80a89bae8f Mon Sep 17 00:00:00 2001 From: Alberto Almagro Date: Fri, 5 Oct 2018 00:55:57 +0200 Subject: Homogenize rails help output In commit 6567464bedd1e39ee7390da9484ba0caa7eb3e07 we homogenized rails commands with former rake tasks. We decided to display all commands at the same level and merged the list of commands displayed by `rails help`. We however forgot to actually merge the output in the command itself. This commit fixes that. --- railties/lib/rails/command.rb | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) (limited to 'railties') diff --git a/railties/lib/rails/command.rb b/railties/lib/rails/command.rb index 6d99ac9936..f09aa3ae0d 100644 --- a/railties/lib/rails/command.rb +++ b/railties/lib/rails/command.rb @@ -83,20 +83,21 @@ module Rails end def print_commands # :nodoc: - sorted_groups.each { |b, n| print_list(b, n) } + commands.each { |command| puts(" #{command}") } end - def sorted_groups # :nodoc: - lookup! + private + COMMANDS_IN_USAGE = %w(generate console server test test:system dbconsole new) + private_constant :COMMANDS_IN_USAGE - groups = (subclasses - hidden_commands).group_by { |c| c.namespace.split(":").first } - groups.transform_values! { |commands| commands.flat_map(&:printing_commands).sort } + def commands + lookup! - rails = groups.delete("rails") - [[ "rails", rails ]] + groups.sort.to_a - end + visible_commands = (subclasses - hidden_commands).flat_map(&:printing_commands) + + (visible_commands - COMMANDS_IN_USAGE).sort + end - private def command_type # :doc: @command_type ||= "command" end -- cgit v1.2.3 From 6d854f9d077b34b846de7a2f998423a6aa66b1e4 Mon Sep 17 00:00:00 2001 From: "yuuji.yaginuma" Date: Thu, 22 Nov 2018 18:20:28 +0900 Subject: Compile packs before run test Sometimes `test_scaffold_tests_pass_by_default` test fails in CI. https://travis-ci.org/rails/rails/jobs/457621750#L2095-L2120 It seems `manifest.json` was broken. `webpacker` will compile automatically if packs is not compiled. If parallel test is enabled, it seems that this compilation process is executed simultaneously in multiple processes, and it may become an inconsistent state. In order to avoid this, compile before running the test. --- railties/test/application/rake_test.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'railties') diff --git a/railties/test/application/rake_test.rb b/railties/test/application/rake_test.rb index c38b91ef03..44e3b0f66b 100644 --- a/railties/test/application/rake_test.rb +++ b/railties/test/application/rake_test.rb @@ -160,7 +160,10 @@ module ApplicationTests def test_scaffold_tests_pass_by_default rails "generate", "scaffold", "user", "username:string", "password:string" - with_rails_env("test") { rails("db:migrate") } + with_rails_env("test") do + rails("db:migrate") + rails("webpacker:compile") + end output = rails("test") assert_match(/7 runs, 9 assertions, 0 failures, 0 errors/, output) -- cgit v1.2.3 From 6fb128d14427019b10e1ac5205f48f72feffe767 Mon Sep 17 00:00:00 2001 From: Yasuo Honda Date: Sun, 23 Sep 2018 04:45:19 +0000 Subject: Bump the minimum version of PostgreSQL to 9.3 https://www.postgresql.org/support/versioning/ - 9.1 EOLed on September 2016. - 9.2 EOLed on September 2017. 9.3 is also not supported since Nov 8, 2018. https://www.postgresql.org/about/news/1905/ I think it may be a little bit early to drop PostgreSQL 9.3 yet. * Deprecated `supports_ranges?` since no other databases support range data type * Add `supports_materialized_views?` to abstract adapter Materialized views itself is supported by other databases, other connection adapters may support them * Remove `with_manual_interventions` It was only necessary for PostgreSQL 9.1 or earlier * Drop CI against PostgreSQL 9.2 --- .../rails/app/templates/config/databases/jdbcpostgresql.yml.tt | 2 +- .../generators/rails/app/templates/config/databases/postgresql.yml.tt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'railties') diff --git a/railties/lib/rails/generators/rails/app/templates/config/databases/jdbcpostgresql.yml.tt b/railties/lib/rails/generators/rails/app/templates/config/databases/jdbcpostgresql.yml.tt index df8a6ad627..2383fe97d3 100644 --- a/railties/lib/rails/generators/rails/app/templates/config/databases/jdbcpostgresql.yml.tt +++ b/railties/lib/rails/generators/rails/app/templates/config/databases/jdbcpostgresql.yml.tt @@ -1,4 +1,4 @@ -# PostgreSQL. Versions 9.1 and up are supported. +# PostgreSQL. Versions 9.3 and up are supported. # # Configure Using Gemfile # gem 'activerecord-jdbcpostgresql-adapter' diff --git a/railties/lib/rails/generators/rails/app/templates/config/databases/postgresql.yml.tt b/railties/lib/rails/generators/rails/app/templates/config/databases/postgresql.yml.tt index dcd57425e2..2f51030756 100644 --- a/railties/lib/rails/generators/rails/app/templates/config/databases/postgresql.yml.tt +++ b/railties/lib/rails/generators/rails/app/templates/config/databases/postgresql.yml.tt @@ -1,4 +1,4 @@ -# PostgreSQL. Versions 9.1 and up are supported. +# PostgreSQL. Versions 9.3 and up are supported. # # Install the pg driver: # gem install pg -- cgit v1.2.3 From 884310fdd031ed8121944f9ea07c8b7723c4e6b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Mendon=C3=A7a=20Fran=C3=A7a?= Date: Wed, 5 Dec 2018 13:37:48 -0500 Subject: Improve deprecation message for enqueue returning false And make sure new applications in Rails 6.0 has this config enabled. Also, improve test coverage and add a CHANGELOG entry. --- railties/lib/rails/application/configuration.rb | 4 ++++ railties/test/application/configuration_test.rb | 27 +++++++++++++++++++++++++ 2 files changed, 31 insertions(+) (limited to 'railties') diff --git a/railties/lib/rails/application/configuration.rb b/railties/lib/rails/application/configuration.rb index d6f8c4f47c..f30e5d2a0f 100644 --- a/railties/lib/rails/application/configuration.rb +++ b/railties/lib/rails/application/configuration.rb @@ -127,6 +127,10 @@ module Rails if respond_to?(:action_dispatch) action_dispatch.use_cookies_with_metadata = true end + + if respond_to?(:active_job) + active_job.return_false_on_aborted_enqueue = true + end else raise "Unknown version #{target_version.to_s.inspect}" end diff --git a/railties/test/application/configuration_test.rb b/railties/test/application/configuration_test.rb index 3635de7162..9fff764eca 100644 --- a/railties/test/application/configuration_test.rb +++ b/railties/test/application/configuration_test.rb @@ -2139,6 +2139,33 @@ module ApplicationTests assert_equal false, ActionView::Template.finalize_compiled_template_methods end + test "ActiveJob::Base.return_false_on_aborted_enqueue is true by default" do + app "development" + + assert_equal true, ActiveJob::Base.return_false_on_aborted_enqueue + end + + test "ActiveJob::Base.return_false_on_aborted_enqueue is false in the 5.x defaults" do + remove_from_config '.*config\.load_defaults.*\n' + add_to_config 'config.load_defaults "5.2"' + + app "development" + + assert_equal false, ActiveJob::Base.return_false_on_aborted_enqueue + end + + test "ActiveJob::Base.return_false_on_aborted_enqueue can be configured in the new framework defaults" do + remove_from_config '.*config\.load_defaults.*\n' + + app_file "config/initializers/new_framework_defaults_6_0.rb", <<-RUBY + Rails.application.config.active_job.return_false_on_aborted_enqueue = true + RUBY + + app "development" + + assert_equal true, ActiveJob::Base.return_false_on_aborted_enqueue + end + test "ActiveRecord::Base.filter_attributes should equal to filter_parameters" do app_file "config/initializers/filter_parameters_logging.rb", <<-RUBY Rails.application.config.filter_parameters += [ :password, :credit_card_number ] -- cgit v1.2.3 From f173ec77fc35ce57e94398310308e868689366bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Rodr=C3=ADguez?= Date: Fri, 7 Dec 2018 07:01:32 +0100 Subject: Abort early if generator command fails (#34420) * No need to go through ruby * Abort early if a generator command fails * Reuse `rails_command` method * Bump thor minimum dependency to 0.20.3 * Add some minimal docs * Add a changelog entry * Restore original logging --- railties/CHANGELOG.md | 6 ++++++ railties/lib/rails/generators/actions.rb | 5 ++++- railties/railties.gemspec | 2 +- railties/test/generators/actions_test.rb | 16 ++++++++++++++-- 4 files changed, 25 insertions(+), 4 deletions(-) (limited to 'railties') diff --git a/railties/CHANGELOG.md b/railties/CHANGELOG.md index 448fd48f10..91fa3aa8be 100644 --- a/railties/CHANGELOG.md +++ b/railties/CHANGELOG.md @@ -1,3 +1,9 @@ +* Add an `abort_on_failure` boolean option to the generator method that shell + out (`generate`, `rake`, `rails_command`) to abort the generator if the + command fails. + + *David Rodríguez* + * Remove `app/assets` and `app/javascript` from `eager_load_paths` and `autoload_paths`. *Gannon McGibbon* diff --git a/railties/lib/rails/generators/actions.rb b/railties/lib/rails/generators/actions.rb index 78d2471890..4646a55316 100644 --- a/railties/lib/rails/generators/actions.rb +++ b/railties/lib/rails/generators/actions.rb @@ -221,9 +221,11 @@ module Rails # generate(:authenticated, "user session") def generate(what, *args) log :generate, what + + options = args.extract_options! argument = args.flat_map(&:to_s).join(" ") - in_root { run_ruby_script("bin/rails generate #{what} #{argument}", verbose: false) } + execute_command :rails, "generate #{what} #{argument}", options end # Runs the supplied rake task (invoked with 'rake ...') @@ -307,6 +309,7 @@ module Rails config = { verbose: false } config[:capture] = options[:capture] if options[:capture] + config[:abort_on_failure] = options[:abort_on_failure] if options[:abort_on_failure] in_root { run("#{sudo}#{extify(executor)} #{command} RAILS_ENV=#{env}", config) } end diff --git a/railties/railties.gemspec b/railties/railties.gemspec index 4e4a504c97..91407ee1ae 100644 --- a/railties/railties.gemspec +++ b/railties/railties.gemspec @@ -37,7 +37,7 @@ Gem::Specification.new do |s| s.add_dependency "actionpack", version s.add_dependency "rake", ">= 0.8.7" - s.add_dependency "thor", ">= 0.19.0", "< 2.0" + s.add_dependency "thor", ">= 0.20.3", "< 2.0" s.add_dependency "method_source" s.add_development_dependency "actionview", version diff --git a/railties/test/generators/actions_test.rb b/railties/test/generators/actions_test.rb index a2b35124c5..af475400a1 100644 --- a/railties/test/generators/actions_test.rb +++ b/railties/test/generators/actions_test.rb @@ -303,9 +303,21 @@ class ActionsTest < Rails::Generators::TestCase end def test_generate_should_run_script_generate_with_argument_and_options - assert_called_with(generator, :run_ruby_script, ["bin/rails generate model MyModel", verbose: false]) do - action :generate, "model", "MyModel" + run_generator + action :generate, "model", "MyModel" + assert_file "app/models/my_model.rb", /MyModel/ + end + + def test_generate_aborts_when_subprocess_fails_if_requested + run_generator + content = capture(:stderr) do + assert_raises SystemExit do + action :generate, "model", "MyModel:ADsad", abort_on_failure: true + action :generate, "model", "MyModel" + end end + assert_match(/wrong constant name MyModel:aDsad/, content) + assert_no_file "app/models/my_model.rb" end def test_rake_should_run_rake_command_with_default_env -- cgit v1.2.3 From bad1041b82df941d588ae2565f62424d88104933 Mon Sep 17 00:00:00 2001 From: "yuuji.yaginuma" Date: Sun, 9 Dec 2018 15:00:01 +0900 Subject: Add test for reads environment credential file with environment variable key --- railties/test/credentials_test.rb | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'railties') diff --git a/railties/test/credentials_test.rb b/railties/test/credentials_test.rb index 03370e0fc7..11765b0de5 100644 --- a/railties/test/credentials_test.rb +++ b/railties/test/credentials_test.rb @@ -1,9 +1,10 @@ # frozen_string_literal: true require "isolation/abstract_unit" +require "env_helpers" class Rails::CredentialsTest < ActiveSupport::TestCase - include ActiveSupport::Testing::Isolation + include ActiveSupport::Testing::Isolation, EnvHelpers setup :build_app teardown :teardown_app @@ -38,6 +39,21 @@ class Rails::CredentialsTest < ActiveSupport::TestCase end end + test "reads credentials using environment variable key" do + with_credentials do |content, key| + Dir.chdir(app_path) do + Dir.mkdir("config/credentials") + File.write("config/credentials/production.yml.enc", content) + end + + switch_env("RAILS_MASTER_KEY", key) do + app("production") + + assert_equal "revealed", Rails.application.credentials.mystery + end + end + end + private def with_credentials key = "2117e775dc2024d4f49ddf3aeb585919" -- cgit v1.2.3