Permalink
Browse files

Merge pull request #29010 from y-yagi/fix_28988

Allow irb options to be passed from `rails console` command
  • Loading branch information...
guilleiguaran authored and y-yagi committed May 14, 2017
1 parent 80ddd68 commit b53a8469e8c7571c3e06e07addc1fa57efa31973
View
@@ -1,3 +1,9 @@
* Allow irb options to be passed from `rails console` command.
Fixes #28988.
*Yuji Yaginuma*
## Rails 5.1.3 (August 03, 2017) ##
* No changes.
@@ -73,14 +73,26 @@ class ConsoleCommand < Base # :nodoc:
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
@@ -136,28 +136,36 @@ def write_prompt(command, expected_output = nil)
assert_output "> "
end
def spawn_console
def spawn_console(options)
Process.spawn(
"#{app_path}/bin/rails console --sandbox",
"#{app_path}/bin/rails console #{options}",
in: @slave, out: @slave, err: @slave
)
assert_output "> ", 30
end
def test_sandbox
spawn_console
spawn_console("--sandbox")
write_prompt "Post.count", "=> 0"
write_prompt "Post.create"
write_prompt "Post.count", "=> 1"
@master.puts "quit"
spawn_console
spawn_console("--sandbox")
write_prompt "Post.count", "=> 0"
write_prompt "Post.transaction { Post.create; raise }"
write_prompt "Post.count", "=> 0"
@master.puts "quit"
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

0 comments on commit b53a846

Please sign in to comment.