forked from openstreetmap/openstreetmap-website
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6820d53
commit 3b96bbc
Showing
2 changed files
with
76 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,18 @@ | ||
require 'test_helper' | ||
require "test_helper" | ||
require "minitest/mock" | ||
|
||
class TraceDestroyerJobTest < ActiveJob::TestCase | ||
# test "the truth" do | ||
# assert true | ||
# end | ||
def test_destroy_called | ||
trace = Minitest::Mock.new | ||
|
||
# Tiny little bit of mocking to make activejob happy | ||
trace.expect :is_a?, false, [TraceDestroyerJob] | ||
|
||
# Check that trace.destroy is called | ||
trace.expect :destroy, true | ||
|
||
TraceDestroyerJob.perform_now(trace) | ||
|
||
assert_mock trace | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,64 @@ | ||
require 'test_helper' | ||
require "test_helper" | ||
require "minitest/mock" | ||
|
||
class TraceImporterJobTest < ActiveJob::TestCase | ||
# test "the truth" do | ||
# assert true | ||
# end | ||
def test_success_notification | ||
# Check that the user gets a success notification when the trace has valid points | ||
trace = create(:trace) | ||
|
||
gpx = Minitest::Mock.new | ||
def gpx.actual_points | ||
5 | ||
end | ||
|
||
trace.stub(:import, gpx) do | ||
perform_enqueued_jobs do | ||
TraceImporterJob.perform_now(trace) | ||
end | ||
end | ||
|
||
assert_performed_jobs 1 | ||
|
||
email = ActionMailer::Base.deliveries.last | ||
assert_equal trace.user.email, email.to[0] | ||
assert_match(/success/, email.subject) | ||
end | ||
|
||
def test_failure_notification | ||
# Check that the user gets a failure notification when the trace has no valid points | ||
trace = create(:trace) | ||
|
||
gpx = Minitest::Mock.new | ||
def gpx.actual_points | ||
0 | ||
end | ||
|
||
trace.stub(:import, gpx) do | ||
perform_enqueued_jobs do | ||
TraceImporterJob.perform_now(trace) | ||
end | ||
end | ||
|
||
assert_performed_jobs 1 | ||
|
||
email = ActionMailer::Base.deliveries.last | ||
assert_equal trace.user.email, email.to[0] | ||
assert_match(/failure/, email.subject) | ||
end | ||
|
||
def test_error_notification | ||
# Check that the user gets a failure notification when something goes badly wrong | ||
trace = create(:trace) | ||
trace.stub(:import, -> { raise }) do | ||
perform_enqueued_jobs do | ||
TraceImporterJob.perform_now(trace) | ||
end | ||
end | ||
|
||
assert_performed_jobs 1 | ||
|
||
email = ActionMailer::Base.deliveries.last | ||
assert_equal trace.user.email, email.to[0] | ||
assert_match(/failure/, email.subject) | ||
end | ||
end |