2017-08-14 13:08:09 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-08-06 13:16:09 -04:00
|
|
|
require "isolation/abstract_unit"
|
2015-05-06 04:32:38 -04:00
|
|
|
|
|
|
|
module ApplicationTests
|
|
|
|
class BinSetupTest < ActiveSupport::TestCase
|
|
|
|
include ActiveSupport::Testing::Isolation
|
|
|
|
|
|
|
|
def setup
|
|
|
|
build_app
|
|
|
|
end
|
|
|
|
|
|
|
|
def teardown
|
|
|
|
teardown_app
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_bin_setup
|
|
|
|
Dir.chdir(app_path) do
|
2016-08-06 13:16:09 -04:00
|
|
|
app_file "db/schema.rb", <<-RUBY
|
2015-05-06 04:32:38 -04:00
|
|
|
ActiveRecord::Schema.define(version: 20140423102712) do
|
|
|
|
create_table(:articles) {}
|
|
|
|
end
|
|
|
|
RUBY
|
|
|
|
|
2017-09-03 12:55:26 -04:00
|
|
|
list_tables = lambda { rails("runner", "p ActiveRecord::Base.connection.tables").strip }
|
2015-12-09 14:46:38 -05:00
|
|
|
File.write("log/test.log", "zomg!")
|
2015-05-06 04:32:38 -04:00
|
|
|
|
2016-08-06 13:16:09 -04:00
|
|
|
assert_equal "[]", list_tables.call
|
2015-12-09 14:46:38 -05:00
|
|
|
assert_equal 5, File.size("log/test.log")
|
2015-05-06 04:32:38 -04:00
|
|
|
assert_not File.exist?("tmp/restart.txt")
|
|
|
|
`bin/setup 2>&1`
|
2015-12-09 14:46:38 -05:00
|
|
|
assert_equal 0, File.size("log/test.log")
|
2016-01-11 20:51:54 -05:00
|
|
|
assert_equal '["articles", "schema_migrations", "ar_internal_metadata"]', list_tables.call
|
2015-05-06 04:32:38 -04:00
|
|
|
assert File.exist?("tmp/restart.txt")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_bin_setup_output
|
|
|
|
Dir.chdir(app_path) do
|
2016-08-06 13:16:09 -04:00
|
|
|
app_file "db/schema.rb", ""
|
2015-05-06 04:32:38 -04:00
|
|
|
|
|
|
|
output = `bin/setup 2>&1`
|
2017-01-23 12:49:16 -05:00
|
|
|
|
|
|
|
# Ignore line that's only output by Bundler < 1.14
|
2017-01-25 17:39:10 -05:00
|
|
|
output.sub!(/^Resolving dependencies\.\.\.\n/, "")
|
2018-10-05 13:41:59 -04:00
|
|
|
# Suppress Bundler platform warnings from output
|
|
|
|
output.gsub!(/^The dependency .* will be unused .*\.\n/, "")
|
2018-11-13 06:19:03 -05:00
|
|
|
# Ignore warnings such as `Psych.safe_load is deprecated`
|
|
|
|
output.gsub!(/^warning:\s.*\n/, "")
|
2017-01-23 12:49:16 -05:00
|
|
|
|
2018-10-05 13:41:59 -04:00
|
|
|
assert_equal(<<~OUTPUT, output)
|
|
|
|
== Installing dependencies ==
|
|
|
|
The Gemfile's dependencies are satisfied
|
2015-05-06 04:32:38 -04:00
|
|
|
|
2018-10-05 13:41:59 -04:00
|
|
|
== Preparing database ==
|
|
|
|
Created database 'db/development.sqlite3'
|
|
|
|
Created database 'db/test.sqlite3'
|
2015-05-06 04:32:38 -04:00
|
|
|
|
2018-10-05 13:41:59 -04:00
|
|
|
== Removing old logs and tempfiles ==
|
2015-05-06 04:32:38 -04:00
|
|
|
|
2018-10-05 13:41:59 -04:00
|
|
|
== Restarting application server ==
|
2015-05-06 04:32:38 -04:00
|
|
|
OUTPUT
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|