Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow irb options to be passed from rails console command #29010

Merged
merged 1 commit into from May 14, 2017
Merged
Changes from all commits
Commits
File filter
Filter file types
Jump to
Jump to file
Failed to load files.

Always

Just for now

@@ -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.

*Pierre Schambacher*
@@ -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
ProTip! Use n and p to navigate between commits in a pull request.