[openstreetmap/openstreetmap-website] Optional Trace import using ActiveJob (#2120)
Andy Allan
notifications at github.com
Thu Jan 24 21:02:12 UTC 2019
gravitystorm commented on this pull request.
> +
+class TraceImporterJobTest < ActiveJob::TestCase
+ 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
It's from minitest/mock.
https://www.rubydoc.info/gems/minitest/4.2.0/Object:stub
The stubbing takes a block, and the stub is only effective inside the block. So when we call `TraceImporterJob.perform_now(trace)`, the `trace.import` method has been overwritten to just return the (fake) gpx object and avoid doing anything else (parsing xml, creating images on disk etc).
I did all this before realising that I needed the FakeFS for other stuff anyway. So if you prefer, I could rework this to create a fully working `trace` object that actually runs `trace.import` for real, with suitable setup to put a valid xml file in the right place and clean up the side-effects of running the `.import` code. Or we can stick with mocking/stubbing, which is probably a better way to do it, but perhaps a bit impenetrable?
--
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/openstreetmap/openstreetmap-website/pull/2120#discussion_r250775195
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openstreetmap.org/pipermail/rails-dev/attachments/20190124/26f9d01d/attachment.html>
More information about the rails-dev
mailing list