2017-08-14 13:08:09 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-08-06 13:16:09 -04:00
|
|
|
require "isolation/abstract_unit"
|
2017-08-07 00:31:14 -04:00
|
|
|
require "env_helpers"
|
2016-02-08 05:47:25 -05:00
|
|
|
|
|
|
|
module ApplicationTests
|
|
|
|
class IntegrationTestCaseTest < ActiveSupport::TestCase
|
2017-08-07 00:31:14 -04:00
|
|
|
include ActiveSupport::Testing::Isolation, EnvHelpers
|
2016-02-08 05:47:25 -05:00
|
|
|
|
|
|
|
setup do
|
|
|
|
build_app
|
|
|
|
end
|
|
|
|
|
|
|
|
teardown do
|
|
|
|
teardown_app
|
|
|
|
end
|
|
|
|
|
|
|
|
test "resets Action Mailer test deliveries" do
|
2017-09-03 12:55:26 -04:00
|
|
|
rails "generate", "mailer", "BaseMailer", "welcome"
|
2016-02-08 05:47:25 -05:00
|
|
|
|
2016-08-06 13:16:09 -04:00
|
|
|
app_file "test/integration/mailer_integration_test.rb", <<-RUBY
|
2020-03-29 19:30:52 -04:00
|
|
|
require "test_helper"
|
2016-02-08 05:47:25 -05:00
|
|
|
|
|
|
|
class MailerIntegrationTest < ActionDispatch::IntegrationTest
|
|
|
|
setup do
|
|
|
|
@old_delivery_method = ActionMailer::Base.delivery_method
|
|
|
|
ActionMailer::Base.delivery_method = :test
|
|
|
|
end
|
|
|
|
|
|
|
|
teardown do
|
|
|
|
ActionMailer::Base.delivery_method = @old_delivery_method
|
|
|
|
end
|
|
|
|
|
|
|
|
2.times do |i|
|
|
|
|
define_method "test_resets_deliveries_\#{i}" do
|
|
|
|
BaseMailer.welcome.deliver_now
|
|
|
|
assert_equal 1, ActionMailer::Base.deliveries.count
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
RUBY
|
|
|
|
|
2017-08-07 00:31:14 -04:00
|
|
|
with_rails_env("test") { rails("db:migrate") }
|
2017-09-03 12:55:26 -04:00
|
|
|
output = rails("test")
|
2016-02-28 17:59:32 -05:00
|
|
|
assert_match(/0 failures, 0 errors/, output)
|
2016-02-08 05:47:25 -05:00
|
|
|
end
|
|
|
|
end
|
2016-07-26 21:02:38 -04:00
|
|
|
|
|
|
|
class IntegrationTestDefaultApp < ActiveSupport::TestCase
|
2017-08-07 00:31:14 -04:00
|
|
|
include ActiveSupport::Testing::Isolation, EnvHelpers
|
2016-07-26 21:02:38 -04:00
|
|
|
|
|
|
|
setup do
|
|
|
|
build_app
|
|
|
|
end
|
|
|
|
|
|
|
|
teardown do
|
|
|
|
teardown_app
|
|
|
|
end
|
|
|
|
|
|
|
|
test "app method of integration tests returns test_app by default" do
|
2016-08-06 13:16:09 -04:00
|
|
|
app_file "test/integration/default_app_test.rb", <<-RUBY
|
2020-03-29 19:30:52 -04:00
|
|
|
require "test_helper"
|
2016-07-26 21:02:38 -04:00
|
|
|
|
|
|
|
class DefaultAppIntegrationTest < ActionDispatch::IntegrationTest
|
|
|
|
def test_app_returns_action_dispatch_test_app_by_default
|
|
|
|
assert_equal ActionDispatch.test_app, app
|
|
|
|
end
|
|
|
|
end
|
|
|
|
RUBY
|
|
|
|
|
2017-08-07 00:31:14 -04:00
|
|
|
with_rails_env("test") { rails("db:migrate") }
|
2017-09-03 12:55:26 -04:00
|
|
|
output = rails("test")
|
2016-07-26 21:02:38 -04:00
|
|
|
assert_match(/0 failures, 0 errors/, output)
|
|
|
|
end
|
|
|
|
end
|
2016-02-08 05:47:25 -05:00
|
|
|
end
|