1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Invoke rails command inside the railties' test app with TestHelpers::Generation#rails

See #30520
This commit is contained in:
bogdanvlviv 2017-09-14 12:28:57 +03:00
parent ff67743fb2
commit 0eb2d6079a
No known key found for this signature in database
GPG key ID: E4ACD76A6DB6DFDD
3 changed files with 12 additions and 16 deletions

View file

@ -300,7 +300,7 @@ class LoadingTest < ActiveSupport::TestCase
end end
MIGRATION MIGRATION
Dir.chdir(app_path) { `rake db:migrate` } rails("db:migrate")
require "#{rails_root}/config/environment" require "#{rails_root}/config/environment"
get "/title" get "/title"
@ -314,7 +314,7 @@ class LoadingTest < ActiveSupport::TestCase
end end
MIGRATION MIGRATION
Dir.chdir(app_path) { `rake db:migrate` } rails("db:migrate")
get "/body" get "/body"
assert_equal "BODY", last_response.body assert_equal "BODY", last_response.body

View file

@ -101,6 +101,7 @@ module ApplicationTests
add_to_config <<-RUBY add_to_config <<-RUBY
rake_tasks do rake_tasks do
task do_nothing: :environment do task do_nothing: :environment do
puts 'There is nothing'
end end
end end
RUBY RUBY
@ -113,10 +114,8 @@ module ApplicationTests
raise 'should not be pre-required for rake even eager_load=true' raise 'should not be pre-required for rake even eager_load=true'
RUBY RUBY
Dir.chdir(app_path) do output = rails("do_nothing", "RAILS_ENV=production")
assert system("bin/rails do_nothing RAILS_ENV=production"), assert_match "There is nothing", output
"should not be pre-required for rake even eager_load=true"
end
end end
def test_code_statistics_sanity def test_code_statistics_sanity
@ -294,9 +293,8 @@ module ApplicationTests
def test_scaffold_tests_pass_by_default def test_scaffold_tests_pass_by_default
rails "generate", "scaffold", "user", "username:string", "password:string" rails "generate", "scaffold", "user", "username:string", "password:string"
output = Dir.chdir(app_path) do with_rails_env("test") { rails("db:migrate") }
`RAILS_ENV=test bin/rails db:migrate test` output = rails("test")
end
assert_match(/7 runs, 9 assertions, 0 failures, 0 errors/, output) assert_match(/7 runs, 9 assertions, 0 failures, 0 errors/, output)
assert_no_match(/Errors running/, output) assert_no_match(/Errors running/, output)
@ -313,9 +311,8 @@ module ApplicationTests
RUBY RUBY
rails "generate", "scaffold", "user", "username:string", "password:string" rails "generate", "scaffold", "user", "username:string", "password:string"
output = Dir.chdir(app_path) do with_rails_env("test") { rails("db:migrate") }
`RAILS_ENV=test bin/rails db:migrate test` output = rails("test")
end
assert_match(/5 runs, 7 assertions, 0 failures, 0 errors/, output) assert_match(/5 runs, 7 assertions, 0 failures, 0 errors/, output)
assert_no_match(/Errors running/, output) assert_no_match(/Errors running/, output)
@ -325,9 +322,8 @@ module ApplicationTests
rails "generate", "model", "Product" rails "generate", "model", "Product"
rails "generate", "model", "Cart" rails "generate", "model", "Cart"
rails "generate", "scaffold", "LineItems", "product:references", "cart:belongs_to" rails "generate", "scaffold", "LineItems", "product:references", "cart:belongs_to"
output = Dir.chdir(app_path) do with_rails_env("test") { rails("db:migrate") }
`RAILS_ENV=test bin/rails db:migrate test` output = rails("test")
end
assert_match(/7 runs, 9 assertions, 0 failures, 0 errors/, output) assert_match(/7 runs, 9 assertions, 0 failures, 0 errors/, output)
assert_no_match(/Errors running/, output) assert_no_match(/Errors running/, output)

View file

@ -42,7 +42,7 @@ module ApplicationTests
pid = Process.spawn("#{app_path}/bin/rails server -P tmp/dummy.pid", in: slave, out: slave, err: slave) pid = Process.spawn("#{app_path}/bin/rails server -P tmp/dummy.pid", in: slave, out: slave, err: slave)
assert_output("Listening", master) assert_output("Listening", master)
Dir.chdir(app_path) { system("bin/rails restart") } rails("restart")
assert_output("Restarting", master) assert_output("Restarting", master)
assert_output("Inherited", master) assert_output("Inherited", master)