diff options
author | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2017-08-01 17:34:14 -0400 |
---|---|---|
committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2017-08-01 17:34:14 -0400 |
commit | feb1ddae021c38174f9c22bbd1298c8b73431b45 (patch) | |
tree | 09a38695596cf80dc362dd4d93cf94d6f7415e7b /railties/test/application/dbconsole_test.rb | |
parent | 3540e60c385286f3517ff56270b31a91ed3024a3 (diff) | |
parent | f9a43f28c087f8ffd35ff7c33a60c938b60f2be2 (diff) | |
download | rails-feb1ddae021c38174f9c22bbd1298c8b73431b45.tar.gz rails-feb1ddae021c38174f9c22bbd1298c8b73431b45.tar.bz2 rails-feb1ddae021c38174f9c22bbd1298c8b73431b45.zip |
Merge remote-tracking branch 'origin/master' into unlock-minitest
Diffstat (limited to 'railties/test/application/dbconsole_test.rb')
-rw-r--r-- | railties/test/application/dbconsole_test.rb | 52 |
1 files changed, 31 insertions, 21 deletions
diff --git a/railties/test/application/dbconsole_test.rb b/railties/test/application/dbconsole_test.rb index 7e5e9ea8aa..5d89d0e44d 100644 --- a/railties/test/application/dbconsole_test.rb +++ b/railties/test/application/dbconsole_test.rb @@ -1,14 +1,14 @@ require "isolation/abstract_unit" -begin - require "pty" -rescue LoadError -end +require "console_helpers" module ApplicationTests class DBConsoleTest < ActiveSupport::TestCase include ActiveSupport::Testing::Isolation + include ConsoleHelpers def setup + skip "PTY unavailable" unless available_pty? + build_app end @@ -17,7 +17,6 @@ module ApplicationTests end def test_use_value_defined_in_environment_file_in_database_yml - skip "PTY unavailable" unless available_pty? Dir.chdir(app_path) do app_file "config/database.yml", <<-YAML development: @@ -41,26 +40,37 @@ module ApplicationTests master.puts ".exit" end - private - def spawn_dbconsole(fd) - Process.spawn("#{app_path}/bin/rails dbconsole", in: fd, out: fd, err: fd) - end - - def assert_output(expected, io, timeout = 5) - timeout = Time.now + timeout + def test_respect_environment_option + Dir.chdir(app_path) do + app_file "config/database.yml", <<-YAML + default: &default + adapter: sqlite3 + pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %> + timeout: 5000 - output = "" - until output.include?(expected) || Time.now > timeout - if IO.select([io], [], [], 0.1) - output << io.read(1) - end - end + development: + <<: *default + database: db/development.sqlite3 - assert_includes output, expected, "#{expected.inspect} expected, but got:\n\n#{output}" + production: + <<: *default + database: db/production.sqlite3 + YAML end - def available_pty? - defined?(PTY) && PTY.respond_to?(:open) + master, slave = PTY.open + spawn_dbconsole(slave, "-e production") + assert_output("sqlite>", master) + + master.puts "pragma database_list;" + assert_output("production.sqlite3", master) + ensure + master.puts ".exit" + end + + private + def spawn_dbconsole(fd, options = nil) + Process.spawn("#{app_path}/bin/rails dbconsole #{options}", in: fd, out: fd, err: fd) end end end |