[openstreetmap/openstreetmap-website] Replace trace-related fixtures with factories. (#1347)

Tom Hughes notifications at github.com
Sun Oct 30 19:58:42 UTC 2016


tomhughes requested changes on this pull request.

I'm really confused by all the stubbing as there doesn't seem to be any obvious need to stub things that just return strings like `large_picture_name`?

I got the impression it was related to the mime ype stuff but as the files exist I don't see any reason why that wouldn't work in the test environment?

>      get :view, { :display_name => users(:public_user).display_name, :id => 0 }, { :user => users(:public_user).id }
     assert_response :redirect
     assert_redirected_to :action => :list
 
-    # And finally we should be able to do it with the owner of the trace
-    get :view, { :display_name => users(:public_user).display_name, :id => 5 }, { :user => users(:public_user).id }
+    # And finally we should not be able to view a deleted trace
+    deleted_trace_file = create(:trace, :deleted)

This should be created at the start of the method or the previous tests aren't really testing what they are supposed to test.

>      assert_response :redirect
     assert_redirected_to :action => :list
   end
 
   # Test downloading a trace
   def test_data
-    # First with no auth, which should work since the trace is public
-    get :data, :display_name => users(:normal_user).display_name, :id => gpx_files(:public_trace_file).id
-    check_trace_data gpx_files(:public_trace_file)
-
-    # Now with some other user, which should work since the trace is public
-    get :data, { :display_name => users(:normal_user).display_name, :id => gpx_files(:public_trace_file).id }, { :user => users(:public_user).id }
-    check_trace_data gpx_files(:public_trace_file)
-
-    # And finally we should be able to do it with the owner of the trace
-    get :data, { :display_name => users(:normal_user).display_name, :id => gpx_files(:public_trace_file).id }, { :user => users(:normal_user).id }
-    check_trace_data gpx_files(:public_trace_file)
+    public_trace_file = create(:trace, :visibility => "public", :user => users(:normal_user))
+    Trace.stub_any_instance :trace_name, "#{GPX_TRACE_DIR}/1.gpx" do

Don't we need to replace `1.gpx` here with whatever trace ID the factory allocated? That is what `check_trace_data` expects?

> @@ -353,38 +367,45 @@ def test_data_not_found
     assert_response :not_found
 
     # Now with a trace that has been deleted
-    get :data, { :display_name => users(:public_user).display_name, :id => 5 }, { :user => users(:public_user).id }
+    deleted_trace_file = create(:trace, :deleted)

As before this needs to go at the start of the method.

> -    assert_not_equal "trackable", users(:public_user).preferences.where(:k => "gps.trace.visibility").first.v
-    post :create, { :trace => { :gpx_file => file, :description => "New Trace", :tagstring => "new,trace", :visibility => "trackable" } }, { :user => users(:public_user).id }
-    assert_response :redirect
-    assert_redirected_to :action => :list, :display_name => users(:public_user).display_name
-    assert_match /file has been uploaded/, flash[:notice]
-    trace = Trace.order(:id => :desc).first
-    assert_equal "1.gpx", trace.name
-    assert_equal "New Trace", trace.description
-    assert_equal %w(new trace), trace.tags.order(:tag).collect(&:tag)
-    assert_equal "trackable", trace.visibility
-    assert_equal false, trace.inserted
-    assert_equal File.new(gpx_files(:public_trace_file).trace_name).read, File.new(trace.trace_name).read
-    trace.destroy
-    assert_equal "trackable", users(:public_user).preferences.where(:k => "gps.trace.visibility").first.v
+    public_trace_file = create(:trace, :visibility => "public")
+    public_trace_file.stub :trace_name, "#{GPX_TRACE_DIR}/1.gpx" do

This seems different to the way other ones are stubbed?

> -    # Now authenticated, with the legacy private flag
-    assert_nil users(:second_public_user).preferences.where(:k => "gps.trace.visibility").first
-    basic_authorization(users(:second_public_user).display_name, "test")
-    post :api_create, :file => file, :description => "New Trace", :tags => "new,trace", :public => 0
-    assert_response :success
-    trace = Trace.find(response.body.to_i)
-    assert_equal "1.gpx", trace.name
-    assert_equal "New Trace", trace.description
-    assert_equal %w(new trace), trace.tags.order(:tag).collect(&:tag)
-    assert_equal "private", trace.visibility
-    assert_equal false, trace.inserted
-    assert_equal File.new(gpx_files(:public_trace_file).trace_name).read, File.new(trace.trace_name).read
-    trace.destroy
-    assert_equal "private", users(:second_public_user).preferences.where(:k => "gps.trace.visibility").first.v
+    public_trace_file = create(:trace, :visibility => "public", :user => users(:normal_user))
+    public_trace_file.stub :trace_name, "#{GPX_TRACE_DIR}/1.gpx" do

Another one where the stubbing is different.

-- 
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/1347#pullrequestreview-6369996
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openstreetmap.org/pipermail/rails-dev/attachments/20161030/704e0af0/attachment-0001.html>


More information about the rails-dev mailing list