]> git.openstreetmap.org Git - rails.git/blobdiff - test/jobs/trace_importer_job_test.rb
Use fenced code blocks
[rails.git] / test / jobs / trace_importer_job_test.rb
index 73c8cebbe507685dd4013c5345319ba7aa483b74..c6d44ecce22185fc3269db737261ba86625b3993 100644 (file)
@@ -12,16 +12,14 @@ class TraceImporterJobTest < ActiveJob::TestCase
     end
 
     trace.stub(:import, gpx) do
-      perform_enqueued_jobs do
-        TraceImporterJob.perform_now(trace)
-      end
+      TraceImporterJob.perform_now(trace)
     end
 
-    assert_performed_jobs 1
-
     email = ActionMailer::Base.deliveries.last
     assert_equal trace.user.email, email.to[0]
     assert_match(/success/, email.subject)
+
+    ActionMailer::Base.deliveries.clear
   end
 
   def test_failure_notification
@@ -34,31 +32,59 @@ class TraceImporterJobTest < ActiveJob::TestCase
     end
 
     trace.stub(:import, gpx) do
-      perform_enqueued_jobs do
-        TraceImporterJob.perform_now(trace)
-      end
+      TraceImporterJob.perform_now(trace)
     end
 
-    assert_performed_jobs 1
-
     email = ActionMailer::Base.deliveries.last
     assert_equal trace.user.email, email.to[0]
     assert_match(/failure/, email.subject)
+
+    ActionMailer::Base.deliveries.clear
   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
+      TraceImporterJob.perform_now(trace)
+    end
+
+    email = ActionMailer::Base.deliveries.last
+    assert_equal trace.user.email, email.to[0]
+    assert_match(/failure/, email.subject)
+    assert_no_match(/Start tag expected/, email.text_part.body.to_s, "should not include parser error")
+    assert_match(%r{jobs/trace_importer_job\.rb}, email.text_part.body.to_s, "should include stack backtrace")
+
+    ActionMailer::Base.deliveries.clear
+  end
+
+  def test_parse_error_notification
+    trace = create(:trace, :inserted => false, :fixture => "jpg")
+    Rails.logger.silence do
+      TraceImporterJob.perform_now(trace)
     end
 
-    assert_performed_jobs 1
+    email = ActionMailer::Base.deliveries.last
+    assert_equal trace.user.email, email.to[0]
+    assert_match(/failure/, email.subject)
+    assert_match(/Start tag expected/, email.text_part.body.to_s, "should include parser error")
+    assert_no_match(%r{jobs/trace_importer_job\.rb}, email.text_part.body.to_s, "should not include stack backtrace")
+
+    ActionMailer::Base.deliveries.clear
+  end
+
+  def test_gz_parse_error_notification
+    trace = create(:trace, :inserted => false, :fixture => "jpg.gz")
+    Rails.logger.silence do
+      TraceImporterJob.perform_now(trace)
+    end
 
     email = ActionMailer::Base.deliveries.last
     assert_equal trace.user.email, email.to[0]
     assert_match(/failure/, email.subject)
+    assert_match(/Start tag expected/, email.text_part.body.to_s, "should include parser error")
+    assert_no_match(%r{jobs/trace_importer_job\.rb}, email.text_part.body.to_s, "should not include stack backtrace")
+
+    ActionMailer::Base.deliveries.clear
   end
 end