]> git.openstreetmap.org Git - rails.git/blobdiff - test/functional/changeset_controller_test.rb
Some more tests
[rails.git] / test / functional / changeset_controller_test.rb
index df18256e69e88aa2196bb142dff551303e1c9609..91b89cdba932f3b54caecaca550fd3c6dbbc28c5 100644 (file)
@@ -95,6 +95,15 @@ class ChangesetControllerTest < ActionController::TestCase
     assert_select "osm>changeset[id=#{changeset_id}]", 1
   end
   
+  ##
+  # check that a changeset that doesn't exist returns an appropriate message
+  def test_read_not_found
+    [0, -32, 233455644, "afg", "213"].each do |id|
+      get :read, :id => id
+      assert_response :not_found, "should get a not found"
+    end
+  end
+  
   ##
   # test that the user who opened a change can close it
   def test_close
@@ -131,6 +140,38 @@ class ChangesetControllerTest < ActionController::TestCase
     assert_response :conflict
     assert_equal "The user doesn't own that changeset", @response.body
   end
+  
+  ##
+  # test that you can't close using another method
+  def test_close_method_invalid
+    basic_authorization users(:public_user).email, "test"
+    
+    cs_id = changesets(:public_user_first_change).id
+    get :close, :id => cs_id
+    assert_response :method_not_allowed
+    
+    post :close, :id => cs_id
+    assert_response :method_not_allowed
+  end
+  
+  ##
+  # check that you can't close a changeset that isn't found
+  def test_close_not_found
+    cs_ids = [0, -132, "123"]
+    
+    # First try to do it with no auth
+    cs_ids.each do |id|
+      put :close, :id => id
+      assert_response :unauthorized, "Shouldn't be able close the non-existant changeset #{id}, when not authorized"
+    end
+    
+    # Now try with auth
+    basic_authorization users(:public_user).email, "test"
+    cs_ids.each do |id|
+      put :close, :id => id
+      assert_response :not_found, "The changeset #{id} doesn't exist, so can't be closed"
+    end
+  end
 
   ##
   # upload something simple, but valid and check that it can 
@@ -308,14 +349,22 @@ EOF
     diff.root = XML::Node.new "osmChange"
     delete = XML::Node.new "delete"
     diff.root << delete
-    delete << current_relations(:public_visible_relation).to_xml_node
-    delete << current_relations(:public_used_relation).to_xml_node
+    delete << current_relations(:visible_relation).to_xml_node
+    delete << current_relations(:used_relation).to_xml_node
     delete << current_ways(:used_way).to_xml_node
     delete << current_nodes(:node_used_by_relationship).to_xml_node
 
+    # update the changeset to one that this user owns
+    changeset_id = changesets(:public_user_first_change).id
+    ["node", "way", "relation"].each do |type|
+      delete.find("//osmChange/delete/#{type}").each do |n| 
+        n['changeset'] = changeset_id.to_s 
+      end
+    end
+
     # upload it
     content diff
-    post :upload, :id => changesets(:public_user_first_change).id
+    post :upload, :id => changeset_id
     assert_response :success, 
       "can't upload a deletion diff to changeset: #{@response.body}"
 
@@ -389,6 +438,7 @@ EOF
     post :upload, :id => 2
     assert_response :precondition_failed, 
       "shouldn't be able to upload a invalid deletion diff: #{@response.body}"
+    assert_equal "Precondition failed: Way 3 still used by relation 1.", @response.body
 
     # check that nothing was, in fact, deleted
     assert_equal true, Node.find(current_nodes(:node_used_by_relationship).id).visible