end
def delete
-#XXX check if member somewhere!
begin
relation = Relation.find(params[:id])
new_relation = Relation.from_xml(request.raw_post)
render :text => doc.to_s, :content_type => "text/xml"
else
-
- render :text => "", :status => :gone
+ render :nothing => true, :status => :gone
end
rescue ActiveRecord::RecordNotFound
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
+ rescue ActiveRecord::RecordNotFound
+ render :text => "Could not find one of the relations", :status => :not_found
end
def relations_for_way
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
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.version = 0
else
if pt['timestamp']
relation.timestamp = Time.parse(pt['timestamp'])
end
+ relation.version = pt['version']
end
pt.find('tag').each do |tag|
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 ])
- 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
+ self.changeset_id = new_relation.changeset_id
+ self.tags = {}
+ self.members = []
+ self.visible = false
+ save_with_history!
else
raise OSM::APIAlreadyDeletedError.new
end
# 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,