]> git.openstreetmap.org Git - rails.git/commitdiff
Adding an extra test to make sure that the correct response is returned when an inval...
authorShaun McDonald <shaun@shaunmcdonald.me.uk>
Mon, 3 Nov 2008 18:54:19 +0000 (18:54 +0000)
committerShaun McDonald <shaun@shaunmcdonald.me.uk>
Mon, 3 Nov 2008 18:54:19 +0000 (18:54 +0000)
lib/diff_reader.rb
lib/osm.rb
test/functional/changeset_controller_test.rb

index eca6d438c642722912227235370b528d47eb0343..165e30e20fa94840f70c2d3bff9365eee4f8faba 100644 (file)
@@ -156,7 +156,7 @@ class DiffReader
 
       else
         # no other actions to choose from, so it must be the users fault!
-        raise "Unknown action #{action_name}, choices are create, modify, delete."
+        raise OSM::APIChangesetActionInvalid.new(action_name)
       end
     end
 
index b002ebbe899b824fdb3d2f818681bb961d80b310..223e351f4c60a0e4790a6d45ee89f36541ede7f9 100644 (file)
@@ -66,6 +66,19 @@ module OSM
         "#{@allowed} is allowed.", :status => :conflict }
     end
   end
+  
+  # Raised when a diff upload has an unknown action. You can only have create,
+  # modify, or delete
+  class APIChangesetActionInvalid < APIError
+    def initialize(provided)
+      @provided = provided
+    end
+    
+    def render_opts
+      { :text => "Unknown action #{@provided}, choices are create, modify, delete.",
+      :status => :bad_request }
+    end
+  end
 
   # Raised when bad XML is encountered which stops things parsing as
   # they should.
index 5e26c20716b9b44464e7854e07777d1ff80492ee..31ade9fce5e3f05000e2ae497f7c2d222be1ddda 100644 (file)
@@ -233,7 +233,7 @@ EOF
       "can't upload a complex diff to changeset: #{@response.body}"
 
     # check the returned payload
-    assert_select "osm[version=#{API_VERSION}][generator=\"OpenStreetMap server\"]", 1
+    assert_select "osm[version=#{API_VERSION}][generator=\"#{GENERATOR}\"]", 1
     assert_select "osm>node", 1
     assert_select "osm>way", 1
     assert_select "osm>relation", 1
@@ -369,6 +369,24 @@ EOF
     assert_response :bad_request, 
       "shouldn't be able to upload an element without version: #{@response.body}"
   end
+  
+  ##
+  # try to upload with commands other than create, modify, or delete
+  def test_action_upload_invalid
+    basic_authorization "test@openstreetmap.org", "test"
+    
+    diff = <<EOF
+<osmChange>
+  <ping>
+    <node id='1' lon='1' lat='1' changeset='1' />
+  </ping>
+</osmChange>
+EOF
+  content diff
+  post :upload, :id => 1
+  assert_response :bad_request, "Shouldn't be able to upload a diff with the action ping"
+  assert_equal @response.body, "Unknown action ping, choices are create, modify, delete."
+  end
 
   ##
   # when we make some simple changes we get the same changes back from the