Methods
S
T
Instance Public methods
setup()
# File railties/test/commands/dbconsole_test.rb, line 8
def setup
  Rails::DBConsole.const_set('APP_PATH', 'rails/all')
end
teardown()
# File railties/test/commands/dbconsole_test.rb, line 12
def teardown
  Rails::DBConsole.send(:remove_const, 'APP_PATH')
  %w[PGUSER PGHOST PGPORT PGPASSWORD DATABASE_URL].each{|key| ENV.delete(key)}
end
test_config_choose_database_url_if_exists()
# File railties/test/commands/dbconsole_test.rb, line 61
def test_config_choose_database_url_if_exists
  host = "database-url-host.com"
  ENV['DATABASE_URL'] = "postgresql://foo:bar@#{host}:9000/foo_test?pool=5&timeout=3000"
  sample_config = {
    "test" => {
      "adapter"  => "postgresql",
      "host"     => "not-the-#{host}",
      "port"     => 9000,
      "database" => "foo_test",
      "username" => "foo",
      "password" => "bar",
      "pool"     => "5",
      "timeout"  => "3000"
    }
  }
  app_db_config(sample_config) do
    assert_equal host, Rails::DBConsole.new.config["host"]
  end
end
test_config_with_database_url_only()
# File railties/test/commands/dbconsole_test.rb, line 43
def test_config_with_database_url_only
  ENV['DATABASE_URL'] = 'postgresql://foo:bar@localhost:9000/foo_test?pool=5&timeout=3000'
  expected = {
    "adapter"  => "postgresql",
    "host"     => "localhost",
    "port"     => 9000,
    "database" => "foo_test",
    "username" => "foo",
    "password" => "bar",
    "pool"     => "5",
    "timeout"  => "3000"
  }.sort

  app_db_config(nil) do
    assert_equal expected, Rails::DBConsole.new.config.sort
  end
end
test_config_with_db_config_only()
# File railties/test/commands/dbconsole_test.rb, line 17
def test_config_with_db_config_only
  config_sample = {
    "test"=> {
      "adapter"=> "sqlite3",
      "host"=> "localhost",
      "port"=> "9000",
      "database"=> "foo_test",
      "user"=> "foo",
      "password"=> "bar",
      "pool"=> "5",
      "timeout"=> "3000"
    }
  }
  app_db_config(config_sample) do
    assert_equal config_sample["test"], Rails::DBConsole.new.config
  end
end
test_config_with_no_db_config()
# File railties/test/commands/dbconsole_test.rb, line 35
def test_config_with_no_db_config
  app_db_config(nil) do
    assert_raise(ActiveRecord::AdapterNotSpecified) {
      Rails::DBConsole.new.config
    }
  end
end
test_env()
# File railties/test/commands/dbconsole_test.rb, line 81
def test_env
  assert_equal "test", Rails::DBConsole.new.environment

  ENV['RAILS_ENV'] = nil
  ENV['RACK_ENV'] = nil

  Rails.stub(:respond_to?, false) do
    assert_equal "development", Rails::DBConsole.new.environment

    ENV['RACK_ENV'] = "rack_env"
    assert_equal "rack_env", Rails::DBConsole.new.environment

    ENV['RAILS_ENV'] = "rails_env"
    assert_equal "rails_env", Rails::DBConsole.new.environment
  end
ensure
  ENV['RAILS_ENV'] = "test"
  ENV['RACK_ENV'] = nil
end
test_mysql()
# File railties/test/commands/dbconsole_test.rb, line 115
def test_mysql
  start(adapter: 'mysql2', database: 'db')
  assert !aborted
  assert_equal [%w[mysql mysql5], 'db'], dbconsole.find_cmd_and_exec_args
end
test_mysql_full()
# File railties/test/commands/dbconsole_test.rb, line 121
def test_mysql_full
  start(adapter: 'mysql2', database: 'db', host: 'locahost', port: 1234, socket: 'socket', username: 'user', password: 'qwerty', encoding: 'UTF-8')
  assert !aborted
  assert_equal [%w[mysql mysql5], '--host=locahost', '--port=1234', '--socket=socket', '--user=user', '--default-character-set=UTF-8', '-p', 'db'], dbconsole.find_cmd_and_exec_args
end
test_mysql_include_password()
# File railties/test/commands/dbconsole_test.rb, line 127
def test_mysql_include_password
  start({adapter: 'mysql2', database: 'db', username: 'user', password: 'qwerty'}, ['-p'])
  assert !aborted
  assert_equal [%w[mysql mysql5], '--user=user', '--password=qwerty', 'db'], dbconsole.find_cmd_and_exec_args
end
test_oracle()
# File railties/test/commands/dbconsole_test.rb, line 188
def test_oracle
  start(adapter: 'oracle', database: 'db', username: 'user', password: 'secret')
  assert !aborted
  assert_equal ['sqlplus', 'user@db'], dbconsole.find_cmd_and_exec_args
end
test_oracle_include_password()
# File railties/test/commands/dbconsole_test.rb, line 194
def test_oracle_include_password
  start({adapter: 'oracle', database: 'db', username: 'user', password: 'secret'}, ['-p'])
  assert !aborted
  assert_equal ['sqlplus', 'user/secret@db'], dbconsole.find_cmd_and_exec_args
end
test_postgresql()
# File railties/test/commands/dbconsole_test.rb, line 133
def test_postgresql
  start(adapter: 'postgresql', database: 'db')
  assert !aborted
  assert_equal ['psql', 'db'], dbconsole.find_cmd_and_exec_args
end
test_postgresql_full()
# File railties/test/commands/dbconsole_test.rb, line 139
def test_postgresql_full
  start(adapter: 'postgresql', database: 'db', username: 'user', password: 'q1w2e3', host: 'host', port: 5432)
  assert !aborted
  assert_equal ['psql', 'db'], dbconsole.find_cmd_and_exec_args
  assert_equal 'user', ENV['PGUSER']
  assert_equal 'host', ENV['PGHOST']
  assert_equal '5432', ENV['PGPORT']
  assert_not_equal 'q1w2e3', ENV['PGPASSWORD']
end
test_postgresql_include_password()
# File railties/test/commands/dbconsole_test.rb, line 149
def test_postgresql_include_password
  start({adapter: 'postgresql', database: 'db', username: 'user', password: 'q1w2e3'}, ['-p'])
  assert !aborted
  assert_equal ['psql', 'db'], dbconsole.find_cmd_and_exec_args
  assert_equal 'user', ENV['PGUSER']
  assert_equal 'q1w2e3', ENV['PGPASSWORD']
end
test_print_help_long()
# File railties/test/commands/dbconsole_test.rb, line 215
def test_print_help_long
  stdout = capture(:stdout) do
    start({}, ['--help'])
  end
  assert aborted
  assert_equal '', output
  assert_match(/Usage:.*dbconsole/, stdout)
end
test_print_help_short()
# File railties/test/commands/dbconsole_test.rb, line 206
def test_print_help_short
  stdout = capture(:stdout) do
    start({}, ['-h'])
  end
  assert aborted
  assert_equal '', output
  assert_match(/Usage:.*dbconsole/, stdout)
end
test_rails_env_is_dev_when_argument_is_dev_and_dev_env_is_present()
# File railties/test/commands/dbconsole_test.rb, line 108
def test_rails_env_is_dev_when_argument_is_dev_and_dev_env_is_present
  Rails::DBConsole.stub(:available_environments, ['dev']) do
    options = Rails::DBConsole.send(:parse_arguments, ['dev'])
    assert_match('dev', options[:environment])
  end
end
test_rails_env_is_development_when_argument_is_dev()
# File railties/test/commands/dbconsole_test.rb, line 101
def test_rails_env_is_development_when_argument_is_dev
  Rails::DBConsole.stub(:available_environments, ['development', 'test']) do
    options = Rails::DBConsole.send(:parse_arguments, ['dev'])
    assert_match('development', options[:environment])
  end
end
test_sqlite3()
# File railties/test/commands/dbconsole_test.rb, line 157
def test_sqlite3
  start(adapter: 'sqlite3', database: 'db.sqlite3')
  assert !aborted
  assert_equal ['sqlite3', Rails.root.join('db.sqlite3').to_s], dbconsole.find_cmd_and_exec_args
end
test_sqlite3_db_absolute_path()
# File railties/test/commands/dbconsole_test.rb, line 174
def test_sqlite3_db_absolute_path
  start(adapter: 'sqlite3', database: '/tmp/db.sqlite3')
  assert !aborted
  assert_equal ['sqlite3', '/tmp/db.sqlite3'], dbconsole.find_cmd_and_exec_args
end
test_sqlite3_db_without_defined_rails_root()
# File railties/test/commands/dbconsole_test.rb, line 180
def test_sqlite3_db_without_defined_rails_root
  Rails.stub(:respond_to?, false) do
    start(adapter: 'sqlite3', database: 'config/db.sqlite3')
    assert !aborted
    assert_equal ['sqlite3', Rails.root.join('../config/db.sqlite3').to_s], dbconsole.find_cmd_and_exec_args
  end
end
test_sqlite3_header()
# File railties/test/commands/dbconsole_test.rb, line 169
def test_sqlite3_header
  start({adapter: 'sqlite3', database: 'db.sqlite3'}, ['--header'])
  assert_equal ['sqlite3', '-header', Rails.root.join('db.sqlite3').to_s], dbconsole.find_cmd_and_exec_args
end
test_sqlite3_mode()
# File railties/test/commands/dbconsole_test.rb, line 163
def test_sqlite3_mode
  start({adapter: 'sqlite3', database: 'db.sqlite3'}, ['--mode', 'html'])
  assert !aborted
  assert_equal ['sqlite3', '-html', Rails.root.join('db.sqlite3').to_s], dbconsole.find_cmd_and_exec_args
end
test_unknown_command_line_client()
# File railties/test/commands/dbconsole_test.rb, line 200
def test_unknown_command_line_client
  start(adapter: 'unknown', database: 'db')
  assert aborted
  assert_match(/Unknown command-line client for db/, output)
end