diff options
Diffstat (limited to 'railties/test/commands/dbconsole_test.rb')
-rw-r--r-- | railties/test/commands/dbconsole_test.rb | 61 |
1 files changed, 43 insertions, 18 deletions
diff --git a/railties/test/commands/dbconsole_test.rb b/railties/test/commands/dbconsole_test.rb index 85a7edfacd..d45bdaabf5 100644 --- a/railties/test/commands/dbconsole_test.rb +++ b/railties/test/commands/dbconsole_test.rb @@ -10,35 +10,37 @@ class Rails::DBConsoleTest < ActiveSupport::TestCase Rails::DBConsole.const_set(:APP_PATH, "erb") app_config({}) - capture_abort { Rails::DBConsole.config } + capture_abort { Rails::DBConsole.new.config } assert aborted - assert_match /No database is configured for the environment '\w+'/, output + assert_match(/No database is configured for the environment '\w+'/, output) app_config(test: "with_init") - assert_equal Rails::DBConsole.config, "with_init" + assert_equal Rails::DBConsole.new.config, "with_init" app_db_file("test:\n without_init") - assert_equal Rails::DBConsole.config, "without_init" + assert_equal Rails::DBConsole.new.config, "without_init" app_db_file("test:\n <%= Rails.something_app_specific %>") - assert_equal Rails::DBConsole.config, "with_init" + assert_equal Rails::DBConsole.new.config, "with_init" app_db_file("test:\n\ninvalid") - assert_equal Rails::DBConsole.config, "with_init" + assert_equal Rails::DBConsole.new.config, "with_init" end def test_env - assert_equal Rails::DBConsole.env, "test" + assert_equal Rails::DBConsole.new.environment, "test" + + ENV['RAILS_ENV'] = nil + ENV['RACK_ENV'] = nil Rails.stubs(:respond_to?).with(:env).returns(false) - assert_equal Rails::DBConsole.env, "test" + assert_equal Rails::DBConsole.new.environment, "development" - ENV['RAILS_ENV'] = nil ENV['RACK_ENV'] = "rack_env" - assert_equal Rails::DBConsole.env, "rack_env" + assert_equal Rails::DBConsole.new.environment, "rack_env" ENV['RAILS_ENV'] = "rails_env" - assert_equal Rails::DBConsole.env, "rails_env" + assert_equal Rails::DBConsole.new.environment, "rails_env" ensure ENV['RAILS_ENV'] = "test" end @@ -92,20 +94,25 @@ class Rails::DBConsoleTest < ActiveSupport::TestCase end def test_sqlite3 - dbconsole.expects(:find_cmd_and_exec).with('sqlite3', 'db') - start(adapter: 'sqlite3', database: 'db') + dbconsole.expects(:find_cmd_and_exec).with('sqlite3', Rails.root.join('db.sqlite3').to_s) + start(adapter: 'sqlite3', database: 'db.sqlite3') assert !aborted end def test_sqlite3_mode - dbconsole.expects(:find_cmd_and_exec).with('sqlite3', '-html', 'db') - start({adapter: 'sqlite3', database: 'db'}, ['--mode', 'html']) + dbconsole.expects(:find_cmd_and_exec).with('sqlite3', '-html', Rails.root.join('db.sqlite3').to_s) + start({adapter: 'sqlite3', database: 'db.sqlite3'}, ['--mode', 'html']) assert !aborted end def test_sqlite3_header - dbconsole.expects(:find_cmd_and_exec).with('sqlite3', '-header', 'db') - start({adapter: 'sqlite3', database: 'db'}, ['--header']) + dbconsole.expects(:find_cmd_and_exec).with('sqlite3', '-header', Rails.root.join('db.sqlite3').to_s) + start({adapter: 'sqlite3', database: 'db.sqlite3'}, ['--header']) + end + + def test_sqlite3_db_absolute_path + dbconsole.expects(:find_cmd_and_exec).with('sqlite3', '/tmp/db.sqlite3') + start(adapter: 'sqlite3', database: '/tmp/db.sqlite3') assert !aborted end @@ -124,7 +131,25 @@ class Rails::DBConsoleTest < ActiveSupport::TestCase def test_unknown_command_line_client start(adapter: 'unknown', database: 'db') assert aborted - assert_match /Unknown command-line client for db/, output + assert_match(/Unknown command-line client for db/, output) + end + + def test_print_help_short + stdout = capture(:stdout) do + start({}, ['-h']) + end + assert aborted + assert_equal '', output + assert_match(/Usage:.*dbconsole/, stdout) + end + + def test_print_help_long + stdout = capture(:stdout) do + start({}, ['--help']) + end + assert aborted + assert_equal '', output + assert_match(/Usage:.*dbconsole/, stdout) end private |