Add tests for trace#delete
authorTom Hughes <tom@compton.nu>
Mon, 14 Oct 2013 23:12:40 +0000 (00:12 +0100)
committerTom Hughes <tom@compton.nu>
Mon, 14 Oct 2013 23:12:40 +0000 (00:12 +0100)
test/functional/trace_controller_test.rb

index fe76cdabc9f41d8e36f3d9325ad65a4866cd652e..a5f3c5a3dd0fd6f512e62d7e6571f865510ca498 100644 (file)
@@ -341,6 +341,36 @@ class TraceControllerTest < ActionController::TestCase
     assert_equal new_details[:visibility], trace.visibility
   end
 
     assert_equal new_details[:visibility], trace.visibility
   end
 
+  # Test deleting a trace
+  def test_delete
+    # First with no auth
+    post :delete, {:display_name => users(:normal_user).display_name, :id => gpx_files(:public_trace_file).id,}
+    assert_response :forbidden
+
+    @request.cookies["_osm_username"] = users(:public_user).display_name
+
+    # Now with some other user, which should fail
+    post :delete, {:display_name => users(:normal_user).display_name, :id => gpx_files(:public_trace_file).id}, {:user => users(:public_user).id}
+    assert_response :forbidden
+
+    # Now with a trace which doesn't exist
+    post :delete, {:display_name => users(:public_user).display_name, :id => 0}, {:user => users(:public_user).id}
+    assert_response :not_found
+
+    # Now with a trace has already been deleted
+    post :delete, {:display_name => users(:public_user).display_name, :id => gpx_files(:deleted_trace_file).id}, {:user => users(:public_user).id}
+    assert_response :not_found
+
+    @request.cookies["_osm_username"] = users(:normal_user).display_name
+
+    # Finally with a trace that we are allowed to delete
+    post :delete, {:display_name => users(:normal_user).display_name, :id => gpx_files(:public_trace_file).id}, {:user => users(:normal_user).id}
+    assert_response :redirect
+    assert_redirected_to :action => :list, :display_name => users(:normal_user).display_name
+    trace = Trace.find(gpx_files(:public_trace_file).id)
+    assert_equal false, trace.visible
+  end
+
   # Check getting a specific trace through the api
   def test_api_read
     # First with no auth
   # Check getting a specific trace through the api
   def test_api_read
     # First with no auth