mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
parent
45095a817b
commit
c776b64708
3 changed files with 32 additions and 6 deletions
|
@ -1,3 +1,9 @@
|
||||||
|
* Allow irb options to be passed from `rails console` command.
|
||||||
|
|
||||||
|
Fixes #28988.
|
||||||
|
|
||||||
|
*Yuji Yaginuma*
|
||||||
|
|
||||||
* Added a shared section to config/database.yml that will be loaded for all environments.
|
* Added a shared section to config/database.yml that will be loaded for all environments.
|
||||||
|
|
||||||
*Pierre Schambacher*
|
*Pierre Schambacher*
|
||||||
|
|
|
@ -73,14 +73,26 @@ module Rails
|
||||||
class_option :environment, aliases: "-e", type: :string,
|
class_option :environment, aliases: "-e", type: :string,
|
||||||
desc: "Specifies the environment to run this console under (test/development/production)."
|
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
|
def perform
|
||||||
extract_environment_option_from_argument
|
extract_environment_option_from_argument
|
||||||
|
|
||||||
# RAILS_ENV needs to be set before config/application is required.
|
# RAILS_ENV needs to be set before config/application is required.
|
||||||
ENV["RAILS_ENV"] = options[:environment]
|
ENV["RAILS_ENV"] = options[:environment]
|
||||||
|
|
||||||
ARGV.clear # Clear ARGV so IRB doesn't freak.
|
|
||||||
|
|
||||||
require_application_and_environment!
|
require_application_and_environment!
|
||||||
Rails::Console.start(Rails.application, options)
|
Rails::Console.start(Rails.application, options)
|
||||||
end
|
end
|
||||||
|
|
|
@ -136,9 +136,9 @@ class FullStackConsoleTest < ActiveSupport::TestCase
|
||||||
assert_output "> "
|
assert_output "> "
|
||||||
end
|
end
|
||||||
|
|
||||||
def spawn_console
|
def spawn_console(options)
|
||||||
Process.spawn(
|
Process.spawn(
|
||||||
"#{app_path}/bin/rails console --sandbox",
|
"#{app_path}/bin/rails console #{options}",
|
||||||
in: @slave, out: @slave, err: @slave
|
in: @slave, out: @slave, err: @slave
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -146,18 +146,26 @@ class FullStackConsoleTest < ActiveSupport::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_sandbox
|
def test_sandbox
|
||||||
spawn_console
|
spawn_console("--sandbox")
|
||||||
|
|
||||||
write_prompt "Post.count", "=> 0"
|
write_prompt "Post.count", "=> 0"
|
||||||
write_prompt "Post.create"
|
write_prompt "Post.create"
|
||||||
write_prompt "Post.count", "=> 1"
|
write_prompt "Post.count", "=> 1"
|
||||||
@master.puts "quit"
|
@master.puts "quit"
|
||||||
|
|
||||||
spawn_console
|
spawn_console("--sandbox")
|
||||||
|
|
||||||
write_prompt "Post.count", "=> 0"
|
write_prompt "Post.count", "=> 0"
|
||||||
write_prompt "Post.transaction { Post.create; raise }"
|
write_prompt "Post.transaction { Post.create; raise }"
|
||||||
write_prompt "Post.count", "=> 0"
|
write_prompt "Post.count", "=> 0"
|
||||||
@master.puts "quit"
|
@master.puts "quit"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_environment_option_and_irb_option
|
||||||
|
spawn_console("test -- --verbose")
|
||||||
|
|
||||||
|
write_prompt "a = 1", "a = 1"
|
||||||
|
write_prompt "puts Rails.env", "puts Rails.env\r\ntest"
|
||||||
|
@master.puts "quit"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue