]> 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 a6eeaeeebd7911f02ae1c383a2e355af91bbc671..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 
@@ -397,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