From 54ee15a203d7463534c2188141c6fb0090c9dc44 Mon Sep 17 00:00:00 2001 From: "yuuji.yaginuma" Date: Sun, 26 Feb 2017 21:05:13 +0900 Subject: Show correct commands in help Currently rails' help shows only namespace. However, the secrets command needs to specify command. Therefore, I fixed the command to display in help. --- railties/lib/rails/commands/destroy/destroy_command.rb | 6 ++++-- railties/lib/rails/commands/generate/generate_command.rb | 10 ++++++---- railties/lib/rails/commands/new/new_command.rb | 6 ++++-- railties/lib/rails/commands/runner/runner_command.rb | 8 +++++--- railties/lib/rails/commands/secrets/secrets_command.rb | 10 ++++++---- railties/lib/rails/commands/test/test_command.rb | 6 ++++-- 6 files changed, 29 insertions(+), 17 deletions(-) (limited to 'railties/lib/rails/commands') diff --git a/railties/lib/rails/commands/destroy/destroy_command.rb b/railties/lib/rails/commands/destroy/destroy_command.rb index 5b552b2070..c802910b5d 100644 --- a/railties/lib/rails/commands/destroy/destroy_command.rb +++ b/railties/lib/rails/commands/destroy/destroy_command.rb @@ -3,8 +3,10 @@ require "rails/generators" module Rails module Command class DestroyCommand < Base # :nodoc: - def help - Rails::Generators.help self.class.command_name + no_commands do + def help + Rails::Generators.help self.class.command_name + end end def perform(*) diff --git a/railties/lib/rails/commands/generate/generate_command.rb b/railties/lib/rails/commands/generate/generate_command.rb index 2718b453a8..9dd7ad1012 100644 --- a/railties/lib/rails/commands/generate/generate_command.rb +++ b/railties/lib/rails/commands/generate/generate_command.rb @@ -3,11 +3,13 @@ require "rails/generators" module Rails module Command class GenerateCommand < Base # :nodoc: - def help - require_application_and_environment! - load_generators + no_commands do + def help + require_application_and_environment! + load_generators - Rails::Generators.help self.class.command_name + Rails::Generators.help self.class.command_name + end end def perform(*) diff --git a/railties/lib/rails/commands/new/new_command.rb b/railties/lib/rails/commands/new/new_command.rb index 74d1fa5021..207dd5d995 100644 --- a/railties/lib/rails/commands/new/new_command.rb +++ b/railties/lib/rails/commands/new/new_command.rb @@ -1,8 +1,10 @@ module Rails module Command class NewCommand < Base # :nodoc: - def help - Rails::Command.invoke :application, [ "--help" ] + no_commands do + def help + Rails::Command.invoke :application, [ "--help" ] + end end def perform(*) diff --git a/railties/lib/rails/commands/runner/runner_command.rb b/railties/lib/rails/commands/runner/runner_command.rb index 4989a7837d..056ad980b9 100644 --- a/railties/lib/rails/commands/runner/runner_command.rb +++ b/railties/lib/rails/commands/runner/runner_command.rb @@ -5,9 +5,11 @@ module Rails default: Rails::Command.environment.dup, desc: "The environment for the runner to operate under (test/development/production)" - def help - super - puts self.class.desc + no_commands do + def help + super + puts self.class.desc + end end def self.banner(*) diff --git a/railties/lib/rails/commands/secrets/secrets_command.rb b/railties/lib/rails/commands/secrets/secrets_command.rb index 3ba8c0c85b..c6d9ec0008 100644 --- a/railties/lib/rails/commands/secrets/secrets_command.rb +++ b/railties/lib/rails/commands/secrets/secrets_command.rb @@ -4,10 +4,12 @@ require "rails/secrets" module Rails module Command class SecretsCommand < Rails::Command::Base # :nodoc: - def help - say "Usage:\n #{self.class.banner}" - say "" - say self.class.desc + no_commands do + def help + say "Usage:\n #{self.class.banner}" + say "" + say self.class.desc + end end def setup diff --git a/railties/lib/rails/commands/test/test_command.rb b/railties/lib/rails/commands/test/test_command.rb index 629fb5b425..65e16900ba 100644 --- a/railties/lib/rails/commands/test/test_command.rb +++ b/railties/lib/rails/commands/test/test_command.rb @@ -4,8 +4,10 @@ require "rails/test_unit/minitest_plugin" module Rails module Command class TestCommand < Base # :nodoc: - def help - perform # Hand over help printing to minitest. + no_commands do + def help + perform # Hand over help printing to minitest. + end end def perform(*) -- cgit v1.2.3 From b16dcc872bb3c094cf1f1d890bdd302593acbbe8 Mon Sep 17 00:00:00 2001 From: Kasper Timm Hansen Date: Thu, 9 Mar 2017 20:19:58 +0100 Subject: [ci skip] Document read_encrypted_secrets config. Mostly just that it's there. Closes #28193. --- railties/lib/rails/commands/secrets/USAGE | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'railties/lib/rails/commands') diff --git a/railties/lib/rails/commands/secrets/USAGE b/railties/lib/rails/commands/secrets/USAGE index 4b7deb4e2a..96e322fe91 100644 --- a/railties/lib/rails/commands/secrets/USAGE +++ b/railties/lib/rails/commands/secrets/USAGE @@ -40,6 +40,14 @@ be encrypted. A `shared:` top level key is also supported such that any keys there is merged into the other environments. +Additionally, Rails won't read encrypted secrets out of the box even if you have +the key. Add this: + + config.read_encrypted_secrets = true + +to the environment you'd like to read encrypted secrets. `bin/rails secrets:setup` +inserts this into the production environment by default. + === Editing Secrets After `bin/rails secrets:setup`, run `bin/rails secrets:edit`. -- cgit v1.2.3 From bc35e63909ef922a0031728350c227ab8e9326fe Mon Sep 17 00:00:00 2001 From: "yuuji.yaginuma" Date: Tue, 14 Mar 2017 16:46:19 +0900 Subject: Make destroy command work within engines Instead of calling methods of Rails.application directly, we need to use a method that is considered for the rails engine. --- railties/lib/rails/commands/destroy/destroy_command.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'railties/lib/rails/commands') diff --git a/railties/lib/rails/commands/destroy/destroy_command.rb b/railties/lib/rails/commands/destroy/destroy_command.rb index c802910b5d..794673851d 100644 --- a/railties/lib/rails/commands/destroy/destroy_command.rb +++ b/railties/lib/rails/commands/destroy/destroy_command.rb @@ -14,9 +14,9 @@ module Rails return help unless generator require_application_and_environment! - Rails.application.load_generators + load_generators - Rails::Generators.invoke generator, args, behavior: :revoke, destination_root: Rails.root + Rails::Generators.invoke generator, args, behavior: :revoke, destination_root: Rails::Command.root end end end -- cgit v1.2.3 From d0accc23b3d01a7d35e73c5dc901014d883ef5f7 Mon Sep 17 00:00:00 2001 From: Jon Moss Date: Tue, 21 Mar 2017 19:07:40 -0400 Subject: CLI arg "host" has precedence over ENV var "host" This is a regression from when the server command switched to its own argument parser, as opposed to Rack's. Rack's argument parser, when provided with a "host" argument, gives that value precedence over environment variables. --- railties/lib/rails/commands/server/server_command.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'railties/lib/rails/commands') diff --git a/railties/lib/rails/commands/server/server_command.rb b/railties/lib/rails/commands/server/server_command.rb index 7e8c86fb49..278fe63c51 100644 --- a/railties/lib/rails/commands/server/server_command.rb +++ b/railties/lib/rails/commands/server/server_command.rb @@ -188,10 +188,12 @@ module Rails end def host - unless (default_host = options[:binding]) + if options[:binding] + options[:binding] + else default_host = environment == "development" ? "localhost" : "0.0.0.0" + ENV.fetch("HOST", default_host) end - ENV.fetch("HOST", default_host) end def environment -- cgit v1.2.3 From a06a643e0572b8c983738c068ae637d020188c97 Mon Sep 17 00:00:00 2001 From: Robert Thau Date: Tue, 21 Mar 2017 23:07:07 -0400 Subject: Correctly reset ARGV for "rails runner `CODE' arg arg arg..." The code itself should not be in the ARGV vector. Fixes #28515 --- railties/lib/rails/commands/runner/runner_command.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'railties/lib/rails/commands') diff --git a/railties/lib/rails/commands/runner/runner_command.rb b/railties/lib/rails/commands/runner/runner_command.rb index 056ad980b9..6864a9726b 100644 --- a/railties/lib/rails/commands/runner/runner_command.rb +++ b/railties/lib/rails/commands/runner/runner_command.rb @@ -16,7 +16,7 @@ module Rails "#{super} [<'Some.ruby(code)'> | ]" end - def perform(code_or_file = nil, *file_argv) + def perform(code_or_file = nil, *command_argv) unless code_or_file help exit 1 @@ -27,9 +27,10 @@ module Rails require_application_and_environment! Rails.application.load_runner + ARGV.replace(command_argv) + if File.exist?(code_or_file) $0 = code_or_file - ARGV.replace(file_argv) Kernel.load code_or_file else begin -- cgit v1.2.3 From 9a0ad3f5efd34983baf873235356517c680860ee Mon Sep 17 00:00:00 2001 From: "yuuji.yaginuma" Date: Mon, 27 Mar 2017 08:29:20 +0900 Subject: Do not show hidden namespaces in destroy commnad help --- railties/lib/rails/commands/destroy/destroy_command.rb | 3 +++ 1 file changed, 3 insertions(+) (limited to 'railties/lib/rails/commands') diff --git a/railties/lib/rails/commands/destroy/destroy_command.rb b/railties/lib/rails/commands/destroy/destroy_command.rb index 794673851d..281732a936 100644 --- a/railties/lib/rails/commands/destroy/destroy_command.rb +++ b/railties/lib/rails/commands/destroy/destroy_command.rb @@ -5,6 +5,9 @@ module Rails class DestroyCommand < Base # :nodoc: no_commands do def help + require_application_and_environment! + load_generators + Rails::Generators.help self.class.command_name end end -- cgit v1.2.3 From c4a11171da2e56a46d7c2e1ee3ba82cca9a72a5f Mon Sep 17 00:00:00 2001 From: "yuuji.yaginuma" Date: Wed, 5 Apr 2017 18:01:34 +0900 Subject: Use appropriate type to `header` option The `header` option checks only whether it is specified or not. https://github.com/rails/rails/blob/e8c33349bfabca28996ac74d344d69c7aaffec50/railties/lib/rails/commands/dbconsole/dbconsole_command.rb#L52 --- railties/lib/rails/commands/dbconsole/dbconsole_command.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties/lib/rails/commands') diff --git a/railties/lib/rails/commands/dbconsole/dbconsole_command.rb b/railties/lib/rails/commands/dbconsole/dbconsole_command.rb index 588fb06b15..5bfbe58d97 100644 --- a/railties/lib/rails/commands/dbconsole/dbconsole_command.rb +++ b/railties/lib/rails/commands/dbconsole/dbconsole_command.rb @@ -140,7 +140,7 @@ module Rails class_option :mode, enum: %w( html list line column ), type: :string, desc: "Automatically put the sqlite3 database in the specified mode (html, list, line, column)." - class_option :header, type: :string + class_option :header, type: :boolean class_option :environment, aliases: "-e", type: :string, desc: "Specifies the environment to run this console under (test/development/production)." -- cgit v1.2.3 From c0928831697306c0a92d5e71f35e8e060a59907b Mon Sep 17 00:00:00 2001 From: koshigoe Date: Mon, 1 May 2017 17:05:49 +0900 Subject: CLI arg `--port` has precedence over env `PORT`. --- railties/lib/rails/commands/server/server_command.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'railties/lib/rails/commands') diff --git a/railties/lib/rails/commands/server/server_command.rb b/railties/lib/rails/commands/server/server_command.rb index 278fe63c51..cf3903f3ae 100644 --- a/railties/lib/rails/commands/server/server_command.rb +++ b/railties/lib/rails/commands/server/server_command.rb @@ -95,10 +95,11 @@ module Rails module Command class ServerCommand < Base # :nodoc: + DEFAULT_PORT = 3000 DEFAULT_PID_PATH = "tmp/pids/server.pid".freeze class_option :port, aliases: "-p", type: :numeric, - desc: "Runs Rails on the specified port.", banner: :port, default: 3000 + desc: "Runs Rails on the specified port - defaults to 3000.", banner: :port class_option :binding, aliases: "-b", type: :string, desc: "Binds Rails to the specified IP - defaults to 'localhost' in development and '0.0.0.0' in other environments'.", banner: :IP @@ -184,7 +185,7 @@ module Rails end def port - ENV.fetch("PORT", options[:port]).to_i + options[:port] || ENV.fetch("PORT", DEFAULT_PORT).to_i end def host -- cgit v1.2.3 From c776b6470875fd40885b181ff8467a2c2cc3ec70 Mon Sep 17 00:00:00 2001 From: "yuuji.yaginuma" Date: Fri, 5 May 2017 15:54:38 +0900 Subject: Allow irb options to be passed from `rails console` command Fixes #28988 --- railties/lib/rails/commands/console/console_command.rb | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'railties/lib/rails/commands') diff --git a/railties/lib/rails/commands/console/console_command.rb b/railties/lib/rails/commands/console/console_command.rb index 62e3aa19df..ec58540923 100644 --- a/railties/lib/rails/commands/console/console_command.rb +++ b/railties/lib/rails/commands/console/console_command.rb @@ -73,14 +73,26 @@ module Rails class_option :environment, aliases: "-e", type: :string, desc: "Specifies the environment to run this console under (test/development/production)." + def initialize(args = [], local_options = {}, config = {}) + console_options = [] + + # For the same behavior as OptionParser, leave only options after "--" in ARGV. + termination = local_options.find_index("--") + if termination + console_options = local_options[termination + 1..-1] + local_options = local_options[0...termination] + end + + ARGV.replace(console_options) + super(args, local_options, config) + end + def perform extract_environment_option_from_argument # RAILS_ENV needs to be set before config/application is required. ENV["RAILS_ENV"] = options[:environment] - ARGV.clear # Clear ARGV so IRB doesn't freak. - require_application_and_environment! Rails::Console.start(Rails.application, options) end -- cgit v1.2.3 From 5bb1ab4adee636e1accaeedcfc7c9aad5a3b2fa1 Mon Sep 17 00:00:00 2001 From: eileencodes Date: Fri, 28 Apr 2017 08:38:29 -0700 Subject: Update system test runner docs It wasn't clear that system tests don't run with the rest of the test suite and are part of a separate command. This documents the `test:system` command as well as update the Rails runner help documentation to make it clearer that system tests are run via their own command by default. --- railties/lib/rails/commands/help/USAGE | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) (limited to 'railties/lib/rails/commands') diff --git a/railties/lib/rails/commands/help/USAGE b/railties/lib/rails/commands/help/USAGE index c5f8ab72bb..8eb98319d2 100644 --- a/railties/lib/rails/commands/help/USAGE +++ b/railties/lib/rails/commands/help/USAGE @@ -1,13 +1,14 @@ The most common rails commands are: - generate Generate new code (short-cut alias: "g") - console Start the Rails console (short-cut alias: "c") - server Start the Rails server (short-cut alias: "s") - test Run tests (short-cut alias: "t") - dbconsole Start a console for the database specified in config/database.yml - (short-cut alias: "db") + generate Generate new code (short-cut alias: "g") + console Start the Rails console (short-cut alias: "c") + server Start the Rails server (short-cut alias: "s") + test Run tests except system tests (short-cut alias: "t") + test:system Run system tests + dbconsole Start a console for the database specified in config/database.yml + (short-cut alias: "db") <% unless engine? %> - new Create a new Rails application. "rails new my_app" creates a - new application called MyApp in "./my_app" + new Create a new Rails application. "rails new my_app" creates a + new application called MyApp in "./my_app" <% end %> All commands can be run with -h (or --help) for more information. -- cgit v1.2.3 From f50471751942730e3311f8c04ae4d97365ab3243 Mon Sep 17 00:00:00 2001 From: Kasper Timm Hansen Date: Tue, 23 May 2017 21:48:05 +0200 Subject: Remove needless waiting message. Needed back when we attempted to wait for editors, but now we expect users to pass a -w flag to their $EDITOR. --- railties/lib/rails/commands/secrets/secrets_command.rb | 1 - 1 file changed, 1 deletion(-) (limited to 'railties/lib/rails/commands') diff --git a/railties/lib/rails/commands/secrets/secrets_command.rb b/railties/lib/rails/commands/secrets/secrets_command.rb index 03a640bd65..76e13a6e49 100644 --- a/railties/lib/rails/commands/secrets/secrets_command.rb +++ b/railties/lib/rails/commands/secrets/secrets_command.rb @@ -34,7 +34,6 @@ module Rails require_application_and_environment! Rails::Secrets.read_for_editing do |tmp_path| - say "Waiting for secrets file to be saved. Abort with Ctrl-C." system("\$EDITOR #{tmp_path}") end -- cgit v1.2.3 From 7a154ab380501050e6ce20463de8f702353bceb0 Mon Sep 17 00:00:00 2001 From: "yuuji.yaginuma" Date: Fri, 19 May 2017 15:13:05 +0900 Subject: Correctly set user_supplied_options when there is no whitespace in option specification Current `user_supplied_options` method can not set the value correctly if there is no space between option and value (e.g., `-p9000`). This makes it possible to set the value correctly in the case like the above. Fixes #29138 --- railties/lib/rails/commands/server/server_command.rb | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'railties/lib/rails/commands') diff --git a/railties/lib/rails/commands/server/server_command.rb b/railties/lib/rails/commands/server/server_command.rb index cf3903f3ae..ebb4ae795a 100644 --- a/railties/lib/rails/commands/server/server_command.rb +++ b/railties/lib/rails/commands/server/server_command.rb @@ -155,9 +155,16 @@ module Rails def user_supplied_options @user_supplied_options ||= begin # Convert incoming options array to a hash of flags - # ["-p", "3001", "-c", "foo"] # => {"-p" => true, "-c" => true} + # ["-p3001", "-C", "--binding", "127.0.0.1"] # => {"-p"=>true, "-C"=>true, "--binding"=>true} user_flag = {} - @original_options.each_with_index { |command, i| user_flag[command] = true if i.even? } + @original_options.each do |command| + if command.to_s.start_with?("--") + option = command.split("=")[0] + user_flag[option] = true + elsif command =~ /\A(-.)/ + user_flag[Regexp.last_match[0]] = true + end + end # Collect all options that the user has explicitly defined so we can # differentiate them from defaults -- cgit v1.2.3 From 0338c81dc2ab6ef35fe68461e39c0bad0af5bb95 Mon Sep 17 00:00:00 2001 From: Kasper Timm Hansen Date: Tue, 23 May 2017 21:54:01 +0200 Subject: Reorder first secrets edit flow. Setup config/secrets.yml.enc with template contents for people to edit. Then generate encryption key and encrypt the initial secrets. --- .../lib/rails/commands/secrets/secrets_command.rb | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) (limited to 'railties/lib/rails/commands') diff --git a/railties/lib/rails/commands/secrets/secrets_command.rb b/railties/lib/rails/commands/secrets/secrets_command.rb index 76e13a6e49..651411d444 100644 --- a/railties/lib/rails/commands/secrets/secrets_command.rb +++ b/railties/lib/rails/commands/secrets/secrets_command.rb @@ -13,10 +13,7 @@ module Rails end def setup - require "rails/generators" - require "rails/generators/rails/encrypted_secrets/encrypted_secrets_generator" - - Rails::Generators::EncryptedSecretsGenerator.start + generator.start end def edit @@ -42,7 +39,22 @@ module Rails say "Aborted changing encrypted secrets: nothing saved." rescue Rails::Secrets::MissingKeyError => error say error.message + rescue Errno::ENOENT => error + raise unless error.message =~ /secrets\.yml\.enc/ + + Rails::Secrets.read_template_for_editing do |tmp_path| + system("\$EDITOR #{tmp_path}") + generator.skip_secrets_file { setup } + end end + + private + def generator + require "rails/generators" + require "rails/generators/rails/encrypted_secrets/encrypted_secrets_generator" + + Rails::Generators::EncryptedSecretsGenerator + end end end end -- cgit v1.2.3 From f81f840c02cff34c169e6fca348fab9a372c8372 Mon Sep 17 00:00:00 2001 From: Kasper Timm Hansen Date: Sun, 11 Jun 2017 12:22:39 +0200 Subject: Access EDITOR through Ruby's cross-platform ENV. Fix the mistake of not using Ruby's ENV hash from the get go and get windows support. --- railties/lib/rails/commands/secrets/secrets_command.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'railties/lib/rails/commands') diff --git a/railties/lib/rails/commands/secrets/secrets_command.rb b/railties/lib/rails/commands/secrets/secrets_command.rb index 651411d444..5f077a5bcb 100644 --- a/railties/lib/rails/commands/secrets/secrets_command.rb +++ b/railties/lib/rails/commands/secrets/secrets_command.rb @@ -31,7 +31,7 @@ module Rails require_application_and_environment! Rails::Secrets.read_for_editing do |tmp_path| - system("\$EDITOR #{tmp_path}") + system("#{ENV["EDITOR"]} #{tmp_path}") end say "New secrets encrypted and saved." @@ -43,7 +43,7 @@ module Rails raise unless error.message =~ /secrets\.yml\.enc/ Rails::Secrets.read_template_for_editing do |tmp_path| - system("\$EDITOR #{tmp_path}") + system("#{ENV["EDITOR"]} #{tmp_path}") generator.skip_secrets_file { setup } end end -- cgit v1.2.3 From f36115207b18fba3a44bdff5b345cdc28ed2d33e Mon Sep 17 00:00:00 2001 From: Edouard CHIN Date: Fri, 16 Jun 2017 13:40:34 -0400 Subject: Add the `/test` dir to the `$LOAD_PATH` as a string: - [Rails <= 5.0](https://github.com/rails/rails/blob/5-0-stable/railties/lib/rails/commands/test.rb#L6) used to add the `/test` as a string; this behaviour changed in rails 5.1, it's appending a `Pathname` object --- railties/lib/rails/commands/test/test_command.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties/lib/rails/commands') diff --git a/railties/lib/rails/commands/test/test_command.rb b/railties/lib/rails/commands/test/test_command.rb index 65e16900ba..dce85cf12d 100644 --- a/railties/lib/rails/commands/test/test_command.rb +++ b/railties/lib/rails/commands/test/test_command.rb @@ -11,7 +11,7 @@ module Rails end def perform(*) - $LOAD_PATH << Rails::Command.root.join("test") + $LOAD_PATH << Rails::Command.root.join("test").to_s Minitest.run_via = :rails -- cgit v1.2.3 From 618268b4b9382f4bcf004a945fe2d85c0bd03e32 Mon Sep 17 00:00:00 2001 From: Akira Matsuda Date: Fri, 30 Jun 2017 13:55:31 +0900 Subject: [Railties] require => require_relative --- railties/lib/rails/commands/application/application_command.rb | 4 ++-- railties/lib/rails/commands/console/console_command.rb | 2 +- railties/lib/rails/commands/dbconsole/dbconsole_command.rb | 2 +- railties/lib/rails/commands/destroy/destroy_command.rb | 2 +- railties/lib/rails/commands/generate/generate_command.rb | 2 +- railties/lib/rails/commands/plugin/plugin_command.rb | 4 ++-- railties/lib/rails/commands/secrets/secrets_command.rb | 6 +++--- railties/lib/rails/commands/server/server_command.rb | 2 +- railties/lib/rails/commands/test/test_command.rb | 4 ++-- 9 files changed, 14 insertions(+), 14 deletions(-) (limited to 'railties/lib/rails/commands') diff --git a/railties/lib/rails/commands/application/application_command.rb b/railties/lib/rails/commands/application/application_command.rb index 7675d3b3d1..e92daf9be6 100644 --- a/railties/lib/rails/commands/application/application_command.rb +++ b/railties/lib/rails/commands/application/application_command.rb @@ -1,5 +1,5 @@ -require "rails/generators" -require "rails/generators/rails/app/app_generator" +require_relative "../../generators" +require_relative "../../generators/rails/app/app_generator" module Rails module Generators diff --git a/railties/lib/rails/commands/console/console_command.rb b/railties/lib/rails/commands/console/console_command.rb index ec58540923..1da1e331f1 100644 --- a/railties/lib/rails/commands/console/console_command.rb +++ b/railties/lib/rails/commands/console/console_command.rb @@ -1,7 +1,7 @@ require "irb" require "irb/completion" -require "rails/command/environment_argument" +require_relative "../../command/environment_argument" module Rails class Console diff --git a/railties/lib/rails/commands/dbconsole/dbconsole_command.rb b/railties/lib/rails/commands/dbconsole/dbconsole_command.rb index 5bfbe58d97..5db588b66a 100644 --- a/railties/lib/rails/commands/dbconsole/dbconsole_command.rb +++ b/railties/lib/rails/commands/dbconsole/dbconsole_command.rb @@ -1,4 +1,4 @@ -require "rails/command/environment_argument" +require_relative "../../command/environment_argument" module Rails class DBConsole diff --git a/railties/lib/rails/commands/destroy/destroy_command.rb b/railties/lib/rails/commands/destroy/destroy_command.rb index 281732a936..8a6fe67f77 100644 --- a/railties/lib/rails/commands/destroy/destroy_command.rb +++ b/railties/lib/rails/commands/destroy/destroy_command.rb @@ -1,4 +1,4 @@ -require "rails/generators" +require_relative "../../generators" module Rails module Command diff --git a/railties/lib/rails/commands/generate/generate_command.rb b/railties/lib/rails/commands/generate/generate_command.rb index 9dd7ad1012..c2089dbcb7 100644 --- a/railties/lib/rails/commands/generate/generate_command.rb +++ b/railties/lib/rails/commands/generate/generate_command.rb @@ -1,4 +1,4 @@ -require "rails/generators" +require_relative "../../generators" module Rails module Command diff --git a/railties/lib/rails/commands/plugin/plugin_command.rb b/railties/lib/rails/commands/plugin/plugin_command.rb index b40ab006af..e915a24e5b 100644 --- a/railties/lib/rails/commands/plugin/plugin_command.rb +++ b/railties/lib/rails/commands/plugin/plugin_command.rb @@ -34,8 +34,8 @@ module Rails private def run_plugin_generator(plugin_args) - require "rails/generators" - require "rails/generators/rails/plugin/plugin_generator" + require_relative "../../generators" + require_relative "../../generators/rails/plugin/plugin_generator" Rails::Generators::PluginGenerator.start plugin_args end end diff --git a/railties/lib/rails/commands/secrets/secrets_command.rb b/railties/lib/rails/commands/secrets/secrets_command.rb index 5f077a5bcb..9e530f5e23 100644 --- a/railties/lib/rails/commands/secrets/secrets_command.rb +++ b/railties/lib/rails/commands/secrets/secrets_command.rb @@ -1,5 +1,5 @@ require "active_support" -require "rails/secrets" +require_relative "../../secrets" module Rails module Command @@ -50,8 +50,8 @@ module Rails private def generator - require "rails/generators" - require "rails/generators/rails/encrypted_secrets/encrypted_secrets_generator" + require_relative "../../generators" + require_relative "../../generators/rails/encrypted_secrets/encrypted_secrets_generator" Rails::Generators::EncryptedSecretsGenerator end diff --git a/railties/lib/rails/commands/server/server_command.rb b/railties/lib/rails/commands/server/server_command.rb index ebb4ae795a..b607a63176 100644 --- a/railties/lib/rails/commands/server/server_command.rb +++ b/railties/lib/rails/commands/server/server_command.rb @@ -2,7 +2,7 @@ require "fileutils" require "optparse" require "action_dispatch" require "rails" -require "rails/dev_caching" +require_relative "../../dev_caching" module Rails class Server < ::Rack::Server diff --git a/railties/lib/rails/commands/test/test_command.rb b/railties/lib/rails/commands/test/test_command.rb index dce85cf12d..ca0b6c00fe 100644 --- a/railties/lib/rails/commands/test/test_command.rb +++ b/railties/lib/rails/commands/test/test_command.rb @@ -1,5 +1,5 @@ -require "rails/command" -require "rails/test_unit/minitest_plugin" +require_relative "../../command" +require_relative "../../test_unit/minitest_plugin" module Rails module Command -- cgit v1.2.3 From af5368eeff693bcb8e64b96df93691ded8908f1c Mon Sep 17 00:00:00 2001 From: "yuuji.yaginuma" Date: Thu, 6 Jul 2017 21:40:33 +0900 Subject: Add `rails secrets:show` command When secrets confirmed with the `secrets:edit` command, `secrets.yml.enc` will change without updating the secrets. Therefore, even if only want to check secrets, the difference will come out. This is a little inconvenient. In order to solve this problem, added the `secrets:show` command. If just want to check secrets, no difference will occur use this command. --- railties/lib/rails/commands/secrets/secrets_command.rb | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'railties/lib/rails/commands') diff --git a/railties/lib/rails/commands/secrets/secrets_command.rb b/railties/lib/rails/commands/secrets/secrets_command.rb index 9e530f5e23..45e02fa730 100644 --- a/railties/lib/rails/commands/secrets/secrets_command.rb +++ b/railties/lib/rails/commands/secrets/secrets_command.rb @@ -48,6 +48,10 @@ module Rails end end + def show + say Rails::Secrets.read + end + private def generator require_relative "../../generators" -- cgit v1.2.3 From e12715bfd55831a84e9398280fb294d9136ede2e Mon Sep 17 00:00:00 2001 From: "yuuji.yaginuma" Date: Sun, 9 Jul 2017 10:13:11 +0900 Subject: Load environment file in `dbconsole` command Currently the environment file is not loaded in `dbconsole` command. Therefore, for example, if use encrypted secrets values in database.yml, `read_encrypted_secrets` will not be true, so the value can not be used correctly. Fixes #29717 --- railties/lib/rails/commands/dbconsole/dbconsole_command.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'railties/lib/rails/commands') diff --git a/railties/lib/rails/commands/dbconsole/dbconsole_command.rb b/railties/lib/rails/commands/dbconsole/dbconsole_command.rb index 5db588b66a..b3df5191c6 100644 --- a/railties/lib/rails/commands/dbconsole/dbconsole_command.rb +++ b/railties/lib/rails/commands/dbconsole/dbconsole_command.rb @@ -148,6 +148,7 @@ module Rails def perform extract_environment_option_from_argument + require_application_and_environment! Rails::DBConsole.start(options) end end -- cgit v1.2.3 From 0d72489b2a08487f71dd4230846c01a5d99ef35f Mon Sep 17 00:00:00 2001 From: Kasper Timm Hansen Date: Sun, 25 Jun 2017 19:08:26 +0200 Subject: * Don't eagerly require Rails' minitest plugin. By making the Rails minitest behave like a standard minitest plugin we're much more likely to not break when people use other minitest plugins. Like minitest-focus and pride. To do this, we need to behave like minitest: require files up front and then perform the plugin behavior via the at_exit hook. This also saves us a fair bit of wrangling with test file loading. Finally, since the environment and warnings options have to be applied as early as possible, and since minitest loads plugins at_exit, they have to be moved to the test command. * Don't expect the root method. It's likely this worked because we eagerly loaded the Rails minitest plugin and that somehow defined a root method on `Rails`. * Assign a backtrace to failed exceptions. Otherwise Minitest pukes when attempting to filter the backtrace (which Rails' backtrace cleaner then removes). Means the exception message test has to be revised too. This is likely caused by the rails minitest plugin now being loaded for these tests and assigning a default backtrace cleaner. --- railties/lib/rails/commands/test/test_command.rb | 30 ++++++++++++++++++++---- 1 file changed, 25 insertions(+), 5 deletions(-) (limited to 'railties/lib/rails/commands') diff --git a/railties/lib/rails/commands/test/test_command.rb b/railties/lib/rails/commands/test/test_command.rb index ca0b6c00fe..5852f51a62 100644 --- a/railties/lib/rails/commands/test/test_command.rb +++ b/railties/lib/rails/commands/test/test_command.rb @@ -1,21 +1,41 @@ require_relative "../../command" -require_relative "../../test_unit/minitest_plugin" +require_relative "../../test_unit/runner" module Rails module Command class TestCommand < Base # :nodoc: no_commands do def help - perform # Hand over help printing to minitest. + require "optparse" + require "minitest/rails_plugin" + + opts = OptionParser.new + opts.banner = "Usage: #{Rails::TestUnitReporter.executable} [options] [files or directories]" + opts.separator "" + opts.separator "You can run a single test by appending a line number to a filename:" + opts.separator "" + opts.separator " #{Rails::TestUnitReporter.executable} test/models/user_test.rb:27" + opts.separator "" + opts.separator "You can run multiple files and directories at the same time:" + opts.separator "" + opts.separator " #{Rails::TestUnitReporter.executable} test/controllers test/integration/login_test.rb" + opts.separator "" + opts.separator "By default test failures and errors are reported inline during a run." + opts.separator "" + + opts.separator "Rails options:" + Rails::TestUnit::Runner.options(opts) + Minitest.plugin_rails_options(opts, {}) + + say opts end end def perform(*) $LOAD_PATH << Rails::Command.root.join("test").to_s - Minitest.run_via = :rails - - require "active_support/testing/autorun" + Rails::TestUnit::Runner.parse_options(ARGV) + Rails::TestUnit::Runner.run(ARGV) end end end -- cgit v1.2.3 From 1acd9a6464668d4d54ab30d016829f60b70dbbeb Mon Sep 17 00:00:00 2001 From: Robin Dupret Date: Mon, 5 Jun 2017 23:19:00 +0200 Subject: Allow to pass a connection to the `dbconsole` command Since 0a4f6009, it's possible to specify a 3-level database configuration to gather connections by environment. The `dbconsole` command will try to look for a database configuration which points to the current environment but with such flavour, the environment key is flushed out so let's add the ability to specify the connection and pick `primary` by default to be consistent with Active Record. --- .../lib/rails/commands/dbconsole/dbconsole_command.rb | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'railties/lib/rails/commands') diff --git a/railties/lib/rails/commands/dbconsole/dbconsole_command.rb b/railties/lib/rails/commands/dbconsole/dbconsole_command.rb index b3df5191c6..383149eb81 100644 --- a/railties/lib/rails/commands/dbconsole/dbconsole_command.rb +++ b/railties/lib/rails/commands/dbconsole/dbconsole_command.rb @@ -87,10 +87,15 @@ module Rails def config @config ||= begin - if configurations[environment].blank? + # We need to check whether the user passed the connection the + # first time around to show a consistent error message to people + # relying on 2-level database configuration. + if @options["connection"] && configurations[connection].blank? + raise ActiveRecord::AdapterNotSpecified, "'#{connection}' connection is not configured. Available configuration: #{configurations.inspect}" + elsif configurations[environment].blank? && configurations[connection].blank? raise ActiveRecord::AdapterNotSpecified, "'#{environment}' database is not configured. Available configuration: #{configurations.inspect}" else - configurations[environment] + configurations[environment].presence || configurations[connection] end end end @@ -99,6 +104,10 @@ module Rails Rails.respond_to?(:env) ? Rails.env : Rails::Command.environment end + def connection + @options.fetch(:connection, "primary") + end + private def configurations # :doc: require APP_PATH @@ -145,6 +154,9 @@ module Rails class_option :environment, aliases: "-e", type: :string, desc: "Specifies the environment to run this console under (test/development/production)." + class_option :connection, aliases: "-c", type: :string, + desc: "Specifies the connection to use." + def perform extract_environment_option_from_argument -- cgit v1.2.3 From 3777701f1380f3814bd5313b225586dec64d4104 Mon Sep 17 00:00:00 2001 From: Robin Dupret Date: Sun, 16 Jul 2017 14:54:04 +0200 Subject: Properly expand the environment's name Running the `console` and `dbconsole` commands with a regular argument as the environment's name automatically expand it to match an existing environment (e.g. dev for development). This feature wasn't available using the `--environment` (a.k.a `-e`) option. --- railties/lib/rails/commands/console/console_command.rb | 3 --- railties/lib/rails/commands/dbconsole/dbconsole_command.rb | 3 --- 2 files changed, 6 deletions(-) (limited to 'railties/lib/rails/commands') diff --git a/railties/lib/rails/commands/console/console_command.rb b/railties/lib/rails/commands/console/console_command.rb index 1da1e331f1..6f9a1f022b 100644 --- a/railties/lib/rails/commands/console/console_command.rb +++ b/railties/lib/rails/commands/console/console_command.rb @@ -70,9 +70,6 @@ module Rails class_option :sandbox, aliases: "-s", type: :boolean, default: false, desc: "Rollback database modifications on exit." - class_option :environment, aliases: "-e", type: :string, - desc: "Specifies the environment to run this console under (test/development/production)." - def initialize(args = [], local_options = {}, config = {}) console_options = [] diff --git a/railties/lib/rails/commands/dbconsole/dbconsole_command.rb b/railties/lib/rails/commands/dbconsole/dbconsole_command.rb index 383149eb81..a66eb16421 100644 --- a/railties/lib/rails/commands/dbconsole/dbconsole_command.rb +++ b/railties/lib/rails/commands/dbconsole/dbconsole_command.rb @@ -151,9 +151,6 @@ module Rails class_option :header, type: :boolean - class_option :environment, aliases: "-e", type: :string, - desc: "Specifies the environment to run this console under (test/development/production)." - class_option :connection, aliases: "-c", type: :string, desc: "Specifies the connection to use." -- cgit v1.2.3 From 8be50181d3fbe0f727a68de33ec856efdf772487 Mon Sep 17 00:00:00 2001 From: "yuuji.yaginuma" Date: Mon, 17 Jul 2017 09:11:21 +0900 Subject: Set `RAILS_ENV` before load application file Since #29725, load application file when `dbconsole` command is executed. However, if do not set `RAILS_ENV` before reading the application file, can not connect to the env specified in option, so added the setting of `RAILS_ENV`. --- railties/lib/rails/commands/dbconsole/dbconsole_command.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'railties/lib/rails/commands') diff --git a/railties/lib/rails/commands/dbconsole/dbconsole_command.rb b/railties/lib/rails/commands/dbconsole/dbconsole_command.rb index a66eb16421..71b3455473 100644 --- a/railties/lib/rails/commands/dbconsole/dbconsole_command.rb +++ b/railties/lib/rails/commands/dbconsole/dbconsole_command.rb @@ -11,7 +11,7 @@ module Rails end def start - ENV["RAILS_ENV"] = @options[:environment] || environment + ENV["RAILS_ENV"] ||= @options[:environment] || environment case config["adapter"] when /^(jdbc)?mysql/ @@ -157,6 +157,9 @@ module Rails def perform extract_environment_option_from_argument + # RAILS_ENV needs to be set before config/application is required. + ENV["RAILS_ENV"] = options[:environment] + require_application_and_environment! Rails::DBConsole.start(options) end -- cgit v1.2.3