]> git.openstreetmap.org Git - rails.git/commitdiff
Some improvements to the error messages that are returned by the api.
authorShaun McDonald <shaun@shaunmcdonald.me.uk>
Tue, 25 Nov 2008 18:59:35 +0000 (18:59 +0000)
committerShaun McDonald <shaun@shaunmcdonald.me.uk>
Tue, 25 Nov 2008 18:59:35 +0000 (18:59 +0000)
app/controllers/changeset_controller.rb
app/controllers/relation_controller.rb
app/models/relation.rb
test/functional/relation_controller_test.rb

index 5e538c721c09527737d9578b3b33feea5990ab23..d7764d995cce4b2139c679cdbb6c0af53b843af2 100644 (file)
@@ -294,6 +294,7 @@ class ChangesetController < ApplicationController
     render ex.render_opts
   end
 
     render ex.render_opts
   end
 
+private
   #------------------------------------------------------------
   # utility functions below.
   #------------------------------------------------------------  
   #------------------------------------------------------------
   # utility functions below.
   #------------------------------------------------------------  
index 575cca419941efc42635b75899e91ce0079ee9b9..93573b95f88f943e5e2b2b36b48a1aeb3ec3928b 100644 (file)
@@ -64,7 +64,6 @@ class RelationController < ApplicationController
   end
 
   def delete
   end
 
   def delete
-#XXX check if member somewhere!
     begin
       relation = Relation.find(params[:id])
       new_relation = Relation.from_xml(request.raw_post)
     begin
       relation = Relation.find(params[:id])
       new_relation = Relation.from_xml(request.raw_post)
@@ -143,8 +142,7 @@ class RelationController < ApplicationController
         render :text => doc.to_s, :content_type => "text/xml"
 
       else
         render :text => doc.to_s, :content_type => "text/xml"
 
       else
-
-        render :text => "", :status => :gone
+        render :nothing => true, :status => :gone
       end
 
     rescue ActiveRecord::RecordNotFound
       end
 
     rescue ActiveRecord::RecordNotFound
@@ -167,8 +165,10 @@ class RelationController < ApplicationController
 
       render :text => doc.to_s, :content_type => "text/xml"
     else
 
       render :text => doc.to_s, :content_type => "text/xml"
     else
-      render :nothing => true, :status => :bad_request
+      render :text => "You need to supply a comma separated list of ids.", :status => :bad_request
     end
     end
+  rescue ActiveRecord::RecordNotFound
+    render :text => "Could not find one of the relations", :status => :not_found
   end
 
   def relations_for_way
   end
 
   def relations_for_way
index 19548f20ceed02e0d1c62f8afbff51ee53f353c7..0159c60b875d791ccb7b690ea12a263d436f78d2 100644 (file)
@@ -35,7 +35,6 @@ class Relation < ActiveRecord::Base
         return Relation.from_xml_node(pt, create)
       end
     rescue LibXML::XML::Error => ex
         return Relation.from_xml_node(pt, create)
       end
     rescue LibXML::XML::Error => ex
-      #return nil
       raise OSM::APIBadXMLError.new("relation", xml, ex.message)
     end
   end
       raise OSM::APIBadXMLError.new("relation", xml, ex.message)
     end
   end
@@ -47,16 +46,18 @@ class Relation < ActiveRecord::Base
       relation.id = pt['id'].to_i
     end
 
       relation.id = pt['id'].to_i
     end
 
-    relation.version = pt['version']
+    raise OSM::APIBadXMLError.new("relation", pt, "You are missing the required changeset in the relation") if pt['changeset'].nil?
     relation.changeset_id = pt['changeset']
 
     if create
       relation.timestamp = Time.now
       relation.visible = true
     relation.changeset_id = pt['changeset']
 
     if create
       relation.timestamp = Time.now
       relation.visible = true
+      relation.version = 0
     else
       if pt['timestamp']
         relation.timestamp = Time.parse(pt['timestamp'])
       end
     else
       if pt['timestamp']
         relation.timestamp = Time.parse(pt['timestamp'])
       end
+      relation.version = pt['version']
     end
 
     pt.find('tag').each do |tag|
     end
 
     pt.find('tag').each do |tag|
@@ -348,15 +349,15 @@ class Relation < ActiveRecord::Base
   def delete_with_history!(new_relation, user)
     if self.visible
       check_consistency(self, new_relation, user)
   def delete_with_history!(new_relation, user)
     if self.visible
       check_consistency(self, new_relation, user)
+      # This will check to see if this relation is used by another relation
       if RelationMember.find(:first, :joins => "INNER JOIN current_relations ON current_relations.id=current_relation_members.id", :conditions => [ "visible = ? AND member_type='relation' and member_id=? ", true, self.id ])
       if RelationMember.find(:first, :joins => "INNER JOIN current_relations ON current_relations.id=current_relation_members.id", :conditions => [ "visible = ? AND member_type='relation' and member_id=? ", true, self.id ])
-        raise OSM::APIPreconditionFailedError.new
-      else
-        self.changeset_id = new_relation.changeset_id
-        self.tags = {}
-        self.members = []
-        self.visible = false
-        save_with_history!
+        raise OSM::APIPreconditionFailedError.new("The relation #{new_relation.id} is a used in another relation")
       end
       end
+      self.changeset_id = new_relation.changeset_id
+      self.tags = {}
+      self.members = []
+      self.visible = false
+      save_with_history!
     else
       raise OSM::APIAlreadyDeletedError.new
     end
     else
       raise OSM::APIAlreadyDeletedError.new
     end
index b8d15e5294f43f0c17d20ef9708cc05e9c175bd9..4ace316a4e96ab479abf152b9a669d1e4fa13d5f 100644 (file)
@@ -276,7 +276,8 @@ class RelationControllerTest < ActionController::TestCase
     # try to delete without specifying a changeset
     content "<osm><relation id='#{current_relations(:visible_relation).id}'/></osm>"
     delete :delete, :id => current_relations(:visible_relation).id
     # try to delete without specifying a changeset
     content "<osm><relation id='#{current_relations(:visible_relation).id}'/></osm>"
     delete :delete, :id => current_relations(:visible_relation).id
-    assert_response :conflict
+    assert_response :bad_request
+    assert_match(/You are missing the required changeset in the relation/, @response.body)
 
     # try to delete with an invalid (closed) changeset
     content update_changeset(current_relations(:visible_relation).to_xml,
 
     # try to delete with an invalid (closed) changeset
     content update_changeset(current_relations(:visible_relation).to_xml,