# check boundary is sane and area within defined
# see /config/application.yml
begin
- bbox = BoundingBox.from_bbox_params(params)
- bbox.check_boundaries
- bbox.check_size
+ @bounds = BoundingBox.from_bbox_params(params)
+ @bounds.check_boundaries
+ @bounds.check_size
rescue StandardError => e
report_error(e.message)
return
end
- nodes = Node.bbox(bbox).where(:visible => true).includes(:node_tags).limit(Settings.max_number_of_nodes + 1)
+ nodes = Node.bbox(@bounds).where(:visible => true).includes(:node_tags).limit(Settings.max_number_of_nodes + 1)
node_ids = nodes.collect(&:id)
if node_ids.length > Settings.max_number_of_nodes
return
end
- doc = OSM::API.new.get_xml_doc
-
- # add bounds
- doc.root << bbox.add_bounds_to(XML::Node.new("bounds"))
-
# get ways
# find which ways are needed
ways = []
nodes += Node.includes(:node_tags).find(nodes_to_fetch) unless nodes_to_fetch.empty?
visible_nodes = {}
- changeset_cache = {}
- user_display_name_cache = {}
-
+ @nodes = []
nodes.each do |node|
if node.visible?
- doc.root << node.to_xml_node(changeset_cache, user_display_name_cache)
visible_nodes[node.id] = node
+ @nodes << node
end
end
+ @ways = []
way_ids = []
ways.each do |way|
if way.visible?
- doc.root << way.to_xml_node(visible_nodes, changeset_cache, user_display_name_cache)
way_ids << way.id
+ @ways << way
end
end
- relations = Relation.nodes(visible_nodes.keys).visible +
- Relation.ways(way_ids).visible
+ @relations = Relation.nodes(visible_nodes.keys).visible +
+ Relation.ways(way_ids).visible
# we do not normally return the "other" partners referenced by an relation,
# e.g. if we return a way A that is referenced by relation X, and there's
# another way B also referenced, that is not returned. But we do make
# an exception for cases where an relation references another *relation*;
# in that case we return that as well (but we don't go recursive here)
- relations += Relation.relations(relations.collect(&:id)).visible
+ @relations += Relation.relations(@relations.collect(&:id)).visible
# this "uniq" may be slightly inefficient; it may be better to first collect and output
# all node-related relations, then find the *not yet covered* way-related ones etc.
- relations.uniq.each do |relation|
- doc.root << relation.to_xml_node(changeset_cache, user_display_name_cache)
- end
+ @relations.uniq!
response.headers["Content-Disposition"] = "attachment; filename=\"map.osm\""
-
- render :xml => doc.to_s
+ # Render the result
+ respond_to do |format|
+ format.xml
+ end
end
end
end
# Dump the details on a node given in params[:id]
def show
- node = Node.find(params[:id])
+ @node = Node.find(params[:id])
- response.last_modified = node.timestamp
+ response.last_modified = @node.timestamp
- if node.visible
- render :xml => node.to_xml.to_s
+ if @node.visible
+ # Render the result
+ respond_to do |format|
+ format.xml
+ end
else
head :gone
end
raise OSM::APIBadUserInput, "No nodes were given to search for" if ids.empty?
- doc = OSM::API.new.get_xml_doc
+ @nodes = Node.find(ids)
- Node.find(ids).each do |node|
- doc.root << node.to_xml_node
+ # Render the result
+ respond_to do |format|
+ format.xml
end
-
- render :xml => doc.to_s
end
end
end
# to do that ourselves.
raise OSM::APINotFoundError if @elements.empty?
- doc = OSM::API.new.get_xml_doc
-
- visible_elements = if show_redactions?
- @elements
- else
- @elements.unredacted
- end
-
- visible_elements.each do |element|
- doc.root << element.to_xml_node
+ # determine visible elements
+ @elems = if show_redactions?
+ @elements
+ else
+ @elements.unredacted
+ end
+
+ # Render the result
+ respond_to do |format|
+ format.xml
end
-
- render :xml => doc.to_s
end
def version
else
response.last_modified = @old_element.timestamp
- doc = OSM::API.new.get_xml_doc
- doc.root << @old_element.to_xml_node
-
- render :xml => doc.to_s
+ # Render the result
+ respond_to do |format|
+ format.xml
+ end
end
end
end
def show
- relation = Relation.find(params[:id])
- response.last_modified = relation.timestamp
- if relation.visible
- render :xml => relation.to_xml.to_s
+ @relation = Relation.find(params[:id])
+ response.last_modified = @relation.timestamp
+ if @relation.visible
+ # Render the result
+ respond_to do |format|
+ format.xml
+ end
else
head :gone
end
node_ids += way_node_ids.flatten
nodes = Node.where(:id => node_ids.uniq).includes(:node_tags)
- # create XML.
- doc = OSM::API.new.get_xml_doc
visible_nodes = {}
- changeset_cache = {}
- user_display_name_cache = {}
+ @nodes = []
nodes.each do |node|
next unless node.visible? # should be unnecessary if data is consistent.
- doc.root << node.to_xml_node(changeset_cache, user_display_name_cache)
+ @nodes << node
visible_nodes[node.id] = node
end
+ @ways = []
ways.each do |way|
next unless way.visible? # should be unnecessary if data is consistent.
- doc.root << way.to_xml_node(visible_nodes, changeset_cache, user_display_name_cache)
+ @ways << way
end
+ @relations = []
relations.each do |rel|
next unless rel.visible? # should be unnecessary if data is consistent.
- doc.root << rel.to_xml_node(changeset_cache, user_display_name_cache)
+ @relations << rel
end
- # finally add self and output
- doc.root << relation.to_xml_node(changeset_cache, user_display_name_cache)
- render :xml => doc.to_s
+ # finally add self
+ @relations << relation
+ # Render the result
+ respond_to do |format|
+ format.xml
+ end
else
head :gone
end
raise OSM::APIBadUserInput, "No relations were given to search for" if ids.empty?
- doc = OSM::API.new.get_xml_doc
+ @relations = Relation.find(ids)
- Relation.find(ids).each do |relation|
- doc.root << relation.to_xml_node
+ # Render the result
+ respond_to do |format|
+ format.xml
end
-
- render :xml => doc.to_s
end
def relations_for_way
def relations_for_object(objtype)
relationids = RelationMember.where(:member_type => objtype, :member_id => params[:id]).collect(&:relation_id).uniq
- doc = OSM::API.new.get_xml_doc
+ @relations = []
Relation.find(relationids).each do |relation|
- doc.root << relation.to_xml_node if relation.visible
+ @relations << relation if relation.visible
end
- render :xml => doc.to_s
+ # Render the result
+ respond_to do |format|
+ format.xml
+ end
end
end
end
end
def show
- way = Way.find(params[:id])
+ @way = Way.find(params[:id])
- response.last_modified = way.timestamp
+ response.last_modified = @way.timestamp
- if way.visible
- render :xml => way.to_xml.to_s
+ if @way.visible
+ # Render the result
+ respond_to do |format|
+ format.xml
+ end
else
head :gone
end
end
def full
- way = Way.includes(:nodes => :node_tags).find(params[:id])
+ @way = Way.includes(:nodes => :node_tags).find(params[:id])
- if way.visible
+ if @way.visible
visible_nodes = {}
- changeset_cache = {}
- user_display_name_cache = {}
- doc = OSM::API.new.get_xml_doc
- way.nodes.uniq.each do |node|
+ @nodes = []
+
+ @way.nodes.uniq.each do |node|
if node.visible
- doc.root << node.to_xml_node(changeset_cache, user_display_name_cache)
+ @nodes << node
visible_nodes[node.id] = node
end
end
- doc.root << way.to_xml_node(visible_nodes, changeset_cache, user_display_name_cache)
- render :xml => doc.to_s
+ # Render the result
+ respond_to do |format|
+ format.xml
+ end
else
head :gone
end
raise OSM::APIBadUserInput, "No ways were given to search for" if ids.empty?
- doc = OSM::API.new.get_xml_doc
+ @ways = Way.find(ids)
- Way.find(ids).each do |way|
- doc.root << way.to_xml_node
+ # Render the result
+ respond_to do |format|
+ format.xml
end
-
- render :xml => doc.to_s
end
##
def ways_for_node
wayids = WayNode.where(:node_id => params[:id]).collect { |ws| ws.id[0] }.uniq
- doc = OSM::API.new.get_xml_doc
+ @ways = Way.where(:id => wayids, :visible => true)
- Way.find(wayids).each do |way|
- doc.root << way.to_xml_node if way.visible
+ # Render the result
+ respond_to do |format|
+ format.xml
end
-
- render :xml => doc.to_s
end
end
end
--- /dev/null
+attrs = {
+ "minlat" => format("%.7f", bounds.min_lat),
+ "minlon" => format("%.7f", bounds.min_lon),
+ "maxlat" => format("%.7f", bounds.max_lat),
+ "maxlon" => format("%.7f", bounds.max_lon)
+}
+
+xml.bounds(attrs)
--- /dev/null
+xml.instruct!
+
+xml.osm(OSM::API.new.xml_root_attributes) do |osm|
+ osm << (render(:partial => "bounds", :object => @bounds) || "")
+ osm << (render(@nodes) || "")
+ osm << (render(@ways) || "")
+ osm << (render(@relations) || "")
+end
--- /dev/null
+attrs = {
+ "id" => node.id,
+ "visible" => node.visible,
+ "version" => node.version,
+ "changeset" => node.changeset_id,
+ "timestamp" => node.timestamp.xmlschema,
+ "user" => node.changeset.user.display_name,
+ "uid" => node.changeset.user_id
+}
+
+if node.visible
+ attrs["lat"] = node.lat
+ attrs["lon"] = node.lon
+end
+
+if node.tags.empty?
+ xml.node(attrs)
+else
+ xml.node(attrs) do |nd|
+ node.tags.each do |k, v|
+ nd.tag(:k => k, :v => v)
+ end
+ end
+end
--- /dev/null
+xml.instruct!
+
+xml.osm(OSM::API.new.xml_root_attributes) do |osm|
+ osm << (render(@nodes) || "")
+end
--- /dev/null
+xml.instruct!
+
+xml.osm(OSM::API.new.xml_root_attributes) do |osm|
+ osm << (render(@node) || "")
+end
--- /dev/null
+attrs = {
+ "id" => old_node.node_id,
+ "visible" => old_node.visible,
+ "version" => old_node.version,
+ "changeset" => old_node.changeset_id,
+ "timestamp" => old_node.timestamp.xmlschema,
+ "user" => old_node.changeset.user.display_name,
+ "uid" => old_node.changeset.user_id
+}
+
+if old_node.visible
+ attrs["lat"] = old_node.lat
+ attrs["lon"] = old_node.lon
+end
+
+if old_node.tags.empty?
+ xml.node(attrs)
+else
+ xml.node(attrs) do |nd|
+ old_node.tags.each do |k, v|
+ nd.tag(:k => k, :v => v)
+ end
+ end
+end
--- /dev/null
+xml.instruct!
+
+xml.osm(OSM::API.new.xml_root_attributes) do |osm|
+ osm << (render(@elems) || "")
+end
--- /dev/null
+xml.instruct!
+
+xml.osm(OSM::API.new.xml_root_attributes) do |osm|
+ osm << (render(@old_element) || "")
+end
--- /dev/null
+attrs = {
+ "id" => old_relation.relation_id,
+ "visible" => old_relation.visible,
+ "version" => old_relation.version,
+ "changeset" => old_relation.changeset_id,
+ "timestamp" => old_relation.timestamp.xmlschema,
+ "user" => old_relation.changeset.user.display_name,
+ "uid" => old_relation.changeset.user_id
+}
+
+xml.relation(attrs) do |r|
+ old_relation.relation_members.each do |m|
+ r.member(:type => m.member_type.downcase, :ref => m.member_id, :role => m.member_role)
+ end
+
+ old_relation.tags.each do |k, v|
+ r.tag(:k => k, :v => v)
+ end
+end
--- /dev/null
+xml.instruct!
+
+xml.osm(OSM::API.new.xml_root_attributes) do |osm|
+ osm << (render(@elems) || "")
+end
--- /dev/null
+xml.instruct!
+
+xml.osm(OSM::API.new.xml_root_attributes) do |osm|
+ osm << (render(@old_element) || "")
+end
--- /dev/null
+attrs = {
+ "id" => old_way.way_id,
+ "visible" => old_way.visible,
+ "version" => old_way.version,
+ "changeset" => old_way.changeset_id,
+ "timestamp" => old_way.timestamp.xmlschema,
+ "user" => old_way.changeset.user.display_name,
+ "uid" => old_way.changeset.user_id
+}
+
+xml.way(attrs) do |w|
+ old_way.nds.each do |n|
+ w.nd(:ref => n)
+ end
+
+ old_way.tags.each do |k, v|
+ w.tag(:k => k, :v => v)
+ end
+end
--- /dev/null
+xml.instruct!
+
+xml.osm(OSM::API.new.xml_root_attributes) do |osm|
+ osm << (render(@elems) || "")
+end
--- /dev/null
+xml.instruct!
+
+xml.osm(OSM::API.new.xml_root_attributes) do |osm|
+ osm << (render(@old_element) || "")
+end
--- /dev/null
+attrs = {
+ "id" => relation.id,
+ "visible" => relation.visible,
+ "version" => relation.version,
+ "changeset" => relation.changeset_id,
+ "timestamp" => relation.timestamp.xmlschema,
+ "user" => relation.changeset.user.display_name,
+ "uid" => relation.changeset.user_id
+}
+
+xml.relation(attrs) do |r|
+ relation.relation_members.each do |m|
+ r.member(:type => m.member_type.downcase, :ref => m.member_id, :role => m.member_role)
+ end
+
+ relation.tags.each do |k, v|
+ r.tag(:k => k, :v => v)
+ end
+end
--- /dev/null
+xml.instruct!
+
+xml.osm(OSM::API.new.xml_root_attributes) do |osm|
+ osm << (render(@nodes) || "")
+ osm << (render(@ways) || "")
+ osm << (render(@relations) || "")
+end
--- /dev/null
+xml.instruct!
+
+xml.osm(OSM::API.new.xml_root_attributes) do |osm|
+ osm << (render(@relations) || "")
+end
--- /dev/null
+xml.instruct!
+
+xml.osm(OSM::API.new.xml_root_attributes) do |osm|
+ osm << (render(@relations) || "")
+end
--- /dev/null
+xml.instruct!
+
+xml.osm(OSM::API.new.xml_root_attributes) do |osm|
+ osm << (render(@relations) || "")
+end
--- /dev/null
+xml.instruct!
+
+xml.osm(OSM::API.new.xml_root_attributes) do |osm|
+ osm << (render(@relations) || "")
+end
--- /dev/null
+xml.instruct!
+
+xml.osm(OSM::API.new.xml_root_attributes) do |osm|
+ osm << (render(@relation) || "")
+end
--- /dev/null
+attrs = {
+ "id" => way.id,
+ "visible" => way.visible,
+ "version" => way.version,
+ "changeset" => way.changeset_id,
+ "timestamp" => way.timestamp.xmlschema,
+ "user" => way.changeset.user.display_name,
+ "uid" => way.changeset.user_id
+}
+
+xml.way(attrs) do |w|
+ way.nodes.each do |n|
+ w.nd(:ref => n.id)
+ end
+
+ way.tags.each do |k, v|
+ w.tag(:k => k, :v => v)
+ end
+end
--- /dev/null
+xml.instruct!
+
+xml.osm(OSM::API.new.xml_root_attributes) do |osm|
+ osm << (render(@nodes) || "")
+ osm << (render(@way) || "")
+end
--- /dev/null
+xml.instruct!
+
+xml.osm(OSM::API.new.xml_root_attributes) do |osm|
+ osm << (render(@ways) || "")
+end
--- /dev/null
+xml.instruct!
+
+xml.osm(OSM::API.new.xml_root_attributes) do |osm|
+ osm << (render(@way) || "")
+end
--- /dev/null
+xml.instruct!
+
+xml.osm(OSM::API.new.xml_root_attributes) do |osm|
+ osm << (render(@ways) || "")
+end
post "changeset/comment/:id/unhide" => "api/changeset_comments#restore", :as => :changeset_comment_unhide, :id => /\d+/
put "node/create" => "api/nodes#create"
- get "node/:id/ways" => "api/ways#ways_for_node", :id => /\d+/
- get "node/:id/relations" => "api/relations#relations_for_node", :id => /\d+/
- get "node/:id/history" => "api/old_nodes#history", :id => /\d+/
+ get "node/:id/ways" => "api/ways#ways_for_node", :id => /\d+/, :defaults => { :format => "xml" }
+ get "node/:id/relations" => "api/relations#relations_for_node", :id => /\d+/, :defaults => { :format => "xml" }
+ get "node/:id/history" => "api/old_nodes#history", :id => /\d+/, :defaults => { :format => "xml" }
post "node/:id/:version/redact" => "api/old_nodes#redact", :version => /\d+/, :id => /\d+/
- get "node/:id/:version" => "api/old_nodes#version", :id => /\d+/, :version => /\d+/
- get "node/:id" => "api/nodes#show", :id => /\d+/
+ get "node/:id/:version" => "api/old_nodes#version", :id => /\d+/, :version => /\d+/, :defaults => { :format => "xml" }
+ get "node/:id" => "api/nodes#show", :id => /\d+/, :defaults => { :format => "xml" }
put "node/:id" => "api/nodes#update", :id => /\d+/
delete "node/:id" => "api/nodes#delete", :id => /\d+/
- get "nodes" => "api/nodes#index"
+ get "nodes" => "api/nodes#index", :defaults => { :format => "xml" }
put "way/create" => "api/ways#create"
- get "way/:id/history" => "api/old_ways#history", :id => /\d+/
- get "way/:id/full" => "api/ways#full", :id => /\d+/
- get "way/:id/relations" => "api/relations#relations_for_way", :id => /\d+/
+ get "way/:id/history" => "api/old_ways#history", :id => /\d+/, :defaults => { :format => "xml" }
+ get "way/:id/full" => "api/ways#full", :id => /\d+/, :defaults => { :format => "xml" }
+ get "way/:id/relations" => "api/relations#relations_for_way", :id => /\d+/, :defaults => { :format => "xml" }
post "way/:id/:version/redact" => "api/old_ways#redact", :version => /\d+/, :id => /\d+/
- get "way/:id/:version" => "api/old_ways#version", :id => /\d+/, :version => /\d+/
- get "way/:id" => "api/ways#show", :id => /\d+/
+ get "way/:id/:version" => "api/old_ways#version", :id => /\d+/, :version => /\d+/, :defaults => { :format => "xml" }
+ get "way/:id" => "api/ways#show", :id => /\d+/, :defaults => { :format => "xml" }
put "way/:id" => "api/ways#update", :id => /\d+/
delete "way/:id" => "api/ways#delete", :id => /\d+/
- get "ways" => "api/ways#index"
+ get "ways" => "api/ways#index", :defaults => { :format => "xml" }
put "relation/create" => "api/relations#create"
- get "relation/:id/relations" => "api/relations#relations_for_relation", :id => /\d+/
- get "relation/:id/history" => "api/old_relations#history", :id => /\d+/
- get "relation/:id/full" => "api/relations#full", :id => /\d+/
+ get "relation/:id/relations" => "api/relations#relations_for_relation", :id => /\d+/, :defaults => { :format => "xml" }
+ get "relation/:id/history" => "api/old_relations#history", :id => /\d+/, :defaults => { :format => "xml" }
+ get "relation/:id/full" => "api/relations#full", :id => /\d+/, :defaults => { :format => "xml" }
post "relation/:id/:version/redact" => "api/old_relations#redact", :version => /\d+/, :id => /\d+/
- get "relation/:id/:version" => "api/old_relations#version", :id => /\d+/, :version => /\d+/
- get "relation/:id" => "api/relations#show", :id => /\d+/
+ get "relation/:id/:version" => "api/old_relations#version", :id => /\d+/, :version => /\d+/, :defaults => { :format => "xml" }
+ get "relation/:id" => "api/relations#show", :id => /\d+/, :defaults => { :format => "xml" }
put "relation/:id" => "api/relations#update", :id => /\d+/
delete "relation/:id" => "api/relations#delete", :id => /\d+/
- get "relations" => "api/relations#index"
+ get "relations" => "api/relations#index", :defaults => { :format => "xml" }
- get "map" => "api/map#index"
+ get "map" => "api/map#index", :defaults => { :format => "xml" }
get "trackpoints" => "api/tracepoints#index"
assert_response :success, "can't create a new node"
node_id = @response.body.to_i
- get :show, :params => { :id => node_id }
+ get :show, :params => { :id => node_id }, :format => "xml"
assert_response :success, "can't read back new node"
node_doc = XML::Parser.string(@response.body).parse
node_xml = node_doc.find("//osm/node").first
def test_routes
assert_routing(
{ :path => "/api/0.6/map", :method => :get },
- { :controller => "api/map", :action => "index" }
+ { :controller => "api/map", :action => "index", :format => "xml" }
)
end
maxlon = node.lon + 0.1
maxlat = node.lat + 0.1
bbox = "#{minlon},#{minlat},#{maxlon},#{maxlat}"
- get :index, :params => { :bbox => bbox }
+ get :index, :params => { :bbox => bbox }, :format => :xml
if $VERBOSE
print @request.to_yaml
print @response.body
relation = create(:relation_member, :member => node).relation
bbox = "#{node.lon},#{node.lat},#{node.lon},#{node.lat}"
- get :index, :params => { :bbox => bbox }
+ get :index, :params => { :bbox => bbox }, :format => :xml
assert_response :success, "The map call should have succeeded"
assert_select "osm[version='#{Settings.api_version}'][generator='#{Settings.generator}']", :count => 1 do
assert_select "bounds[minlon='#{node.lon}'][minlat='#{node.lat}'][maxlon='#{node.lon}'][maxlat='#{node.lat}']", :count => 1
relation = create(:relation_member, :member => way1).relation
bbox = "#{node.lon},#{node.lat},#{node.lon},#{node.lat}"
- get :index, :params => { :bbox => bbox }
+ get :index, :params => { :bbox => bbox }, :format => :xml
assert_response :success, "The map call should have succeeded"
assert_select "osm[version='#{Settings.api_version}'][generator='#{Settings.generator}']", :count => 1 do
assert_select "bounds[minlon='#{node.lon}'][minlat='#{node.lat}'][maxlon='#{node.lon}'][maxlat='#{node.lat}']", :count => 1
end
def test_map_empty
- get :index, :params => { :bbox => "179.998,89.998,179.999.1,89.999" }
+ get :index, :params => { :bbox => "179.998,89.998,179.999.1,89.999" }, :format => :xml
assert_response :success, "The map call should have succeeded"
assert_select "osm[version='#{Settings.api_version}'][generator='#{Settings.generator}']", :count => 1 do
assert_select "bounds[minlon='179.9980000'][minlat='89.9980000'][maxlon='179.9990000'][maxlat='89.9990000']", :count => 1
def test_bbox_too_big
@badbigbbox.each do |bbox|
- get :index, :params => { :bbox => bbox }
+ get :index, :params => { :bbox => bbox }, :format => :xml
assert_response :bad_request, "The bbox:#{bbox} was expected to be too big"
assert_equal "The maximum bbox size is #{Settings.max_request_area}, and your request was too large. Either request a smaller area, or use planet.osm", @response.body, "bbox: #{bbox}"
end
def test_bbox_malformed
@badmalformedbbox.each do |bbox|
- get :index, :params => { :bbox => bbox }
+ get :index, :params => { :bbox => bbox }, :format => :xml
assert_response :bad_request, "The bbox:#{bbox} was expected to be malformed"
assert_equal "The parameter bbox is required, and must be of the form min_lon,min_lat,max_lon,max_lat", @response.body, "bbox: #{bbox}"
end
def test_bbox_lon_mixedup
@badlonmixedbbox.each do |bbox|
- get :index, :params => { :bbox => bbox }
+ get :index, :params => { :bbox => bbox }, :format => :xml
assert_response :bad_request, "The bbox:#{bbox} was expected to have the longitude mixed up"
assert_equal "The minimum longitude must be less than the maximum longitude, but it wasn't", @response.body, "bbox: #{bbox}"
end
def test_bbox_lat_mixedup
@badlatmixedbbox.each do |bbox|
- get :index, :params => { :bbox => bbox }
+ get :index, :params => { :bbox => bbox }, :format => :xml
assert_response :bad_request, "The bbox:#{bbox} was expected to have the latitude mixed up"
assert_equal "The minimum latitude must be less than the maximum latitude, but it wasn't", @response.body, "bbox: #{bbox}"
end
)
assert_routing(
{ :path => "/api/0.6/node/1", :method => :get },
- { :controller => "api/nodes", :action => "show", :id => "1" }
+ { :controller => "api/nodes", :action => "show", :id => "1", :format => "xml" }
)
assert_routing(
{ :path => "/api/0.6/node/1", :method => :put },
)
assert_routing(
{ :path => "/api/0.6/nodes", :method => :get },
- { :controller => "api/nodes", :action => "index" }
+ { :controller => "api/nodes", :action => "index", :format => "xml" }
)
end
def test_show
# check that a visible node is returned properly
- get :show, :params => { :id => create(:node).id }
+ get :show, :params => { :id => create(:node).id }, :format => :xml
assert_response :success
# check that an deleted node is not returned
- get :show, :params => { :id => create(:node, :deleted).id }
+ get :show, :params => { :id => create(:node, :deleted).id }, :format => :xml
assert_response :gone
# check chat a non-existent node is not returned
- get :show, :params => { :id => 0 }
+ get :show, :params => { :id => 0 }, :format => :xml
assert_response :not_found
end
node5 = create(:node, :deleted, :with_history, :version => 2)
# check error when no parameter provided
- get :index
+ get :index, :format => :xml
assert_response :bad_request
# check error when no parameter value provided
- get :index, :params => { :nodes => "" }
+ get :index, :params => { :nodes => "" }, :format => :xml
assert_response :bad_request
# test a working call
- get :index, :params => { :nodes => "#{node1.id},#{node2.id},#{node3.id},#{node4.id},#{node5.id}" }
+ get :index, :params => { :nodes => "#{node1.id},#{node2.id},#{node3.id},#{node4.id},#{node5.id}" }, :format => :xml
assert_response :success
assert_select "osm" do
assert_select "node", :count => 5
end
# check error when a non-existent node is included
- get :index, :params => { :nodes => "#{node1.id},#{node2.id},#{node3.id},#{node4.id},#{node5.id},0" }
+ get :index, :params => { :nodes => "#{node1.id},#{node2.id},#{node3.id},#{node4.id},#{node5.id},0" }, :format => :xml
assert_response :not_found
end
assert_not_nil checknode, "node not found in data base after upload"
# and grab it using the api
- get :show, :params => { :id => nodeid }
+ get :show, :params => { :id => nodeid }, :format => :xml
assert_response :success
apinode = Node.from_xml(@response.body)
assert_not_nil apinode, "downloaded node is nil, but shouldn't be"
def test_routes
assert_routing(
{ :path => "/api/0.6/node/1/history", :method => :get },
- { :controller => "api/old_nodes", :action => "history", :id => "1" }
+ { :controller => "api/old_nodes", :action => "history", :id => "1", :format => "xml" }
)
assert_routing(
{ :path => "/api/0.6/node/1/2", :method => :get },
- { :controller => "api/old_nodes", :action => "version", :id => "1", :version => "2" }
+ { :controller => "api/old_nodes", :action => "version", :id => "1", :version => "2", :format => "xml" }
)
assert_routing(
{ :path => "/api/0.6/node/1/2/redact", :method => :post },
# check all the versions
versions.each_key do |key|
- get :version, :params => { :id => nodeid, :version => key.to_i }
+ get :version, :params => { :id => nodeid, :version => key.to_i }, :format => :xml
assert_response :success,
"couldn't get version #{key.to_i} of node #{nodeid}"
end
def check_not_found_id_version(id, version)
- get :version, :params => { :id => id, :version => version }
+ get :version, :params => { :id => id, :version => version }, :format => :xml
assert_response :not_found
rescue ActionController::UrlGenerationError => e
assert_match(/No route matches/, e.to_s)
node_v1 = node.old_nodes.find_by(:version => 1)
node_v1.redact!(create(:redaction))
- get :version, :params => { :id => node_v1.node_id, :version => node_v1.version }
+ get :version, :params => { :id => node_v1.node_id, :version => node_v1.version }, :format => :xml
assert_response :forbidden, "Redacted node shouldn't be visible via the version API."
# not even to a logged-in user
basic_authorization create(:user).email, "test"
- get :version, :params => { :id => node_v1.node_id, :version => node_v1.version }
+ get :version, :params => { :id => node_v1.node_id, :version => node_v1.version }, :format => :xml
assert_response :forbidden, "Redacted node shouldn't be visible via the version API, even when logged in."
end
node_v1 = node.old_nodes.find_by(:version => 1)
node_v1.redact!(create(:redaction))
- get :history, :params => { :id => node_v1.node_id }
+ get :history, :params => { :id => node_v1.node_id }, :format => :xml
assert_response :success, "Redaction shouldn't have stopped history working."
assert_select "osm node[id='#{node_v1.node_id}'][version='#{node_v1.version}']", 0, "redacted node #{node_v1.node_id} version #{node_v1.version} shouldn't be present in the history."
# not even to a logged-in user
basic_authorization create(:user).email, "test"
- get :history, :params => { :id => node_v1.node_id }
+ get :history, :params => { :id => node_v1.node_id }, :format => :xml
assert_response :success, "Redaction shouldn't have stopped history working."
assert_select "osm node[id='#{node_v1.node_id}'][version='#{node_v1.version}']", 0, "redacted node #{node_v1.node_id} version #{node_v1.version} shouldn't be present in the history, even when logged in."
end
# check moderator can still see the redacted data, when passing
# the appropriate flag
- get :version, :params => { :id => node_v3.node_id, :version => node_v3.version }
+ get :version, :params => { :id => node_v3.node_id, :version => node_v3.version }, :format => :xml
assert_response :forbidden, "After redaction, node should be gone for moderator, when flag not passed."
- get :version, :params => { :id => node_v3.node_id, :version => node_v3.version, :show_redactions => "true" }
+ get :version, :params => { :id => node_v3.node_id, :version => node_v3.version, :show_redactions => "true" }, :format => :xml
assert_response :success, "After redaction, node should not be gone for moderator, when flag passed."
# and when accessed via history
- get :history, :params => { :id => node_v3.node_id }
+ get :history, :params => { :id => node_v3.node_id }, :format => :xml
assert_response :success, "Redaction shouldn't have stopped history working."
assert_select "osm node[id='#{node_v3.node_id}'][version='#{node_v3.version}']", 0, "node #{node_v3.node_id} version #{node_v3.version} should not be present in the history for moderators when not passing flag."
- get :history, :params => { :id => node_v3.node_id, :show_redactions => "true" }
+ get :history, :params => { :id => node_v3.node_id, :show_redactions => "true" }, :format => :xml
assert_response :success, "Redaction shouldn't have stopped history working."
assert_select "osm node[id='#{node_v3.node_id}'][version='#{node_v3.version}']", 1, "node #{node_v3.node_id} version #{node_v3.version} should still be present in the history for moderators when passing flag."
end
basic_authorization create(:user).email, "test"
# check can't see the redacted data
- get :version, :params => { :id => node_v3.node_id, :version => node_v3.version }
+ get :version, :params => { :id => node_v3.node_id, :version => node_v3.version }, :format => :xml
assert_response :forbidden, "Redacted node shouldn't be visible via the version API."
# and when accessed via history
- get :history, :params => { :id => node_v3.node_id }
+ get :history, :params => { :id => node_v3.node_id }, :format => :xml
assert_response :success, "Redaction shouldn't have stopped history working."
assert_select "osm node[id='#{node_v3.node_id}'][version='#{node_v3.version}']", 0, "redacted node #{node_v3.node_id} version #{node_v3.version} shouldn't be present in the history."
end
# check moderator can now see the redacted data, when not
# passing the aspecial flag
- get :version, :params => { :id => node_v1.node_id, :version => node_v1.version }
+ get :version, :params => { :id => node_v1.node_id, :version => node_v1.version }, :format => :xml
assert_response :success, "After unredaction, node should not be gone for moderator."
# and when accessed via history
- get :history, :params => { :id => node_v1.node_id }
+ get :history, :params => { :id => node_v1.node_id }, :format => :xml
assert_response :success, "Unredaction shouldn't have stopped history working."
assert_select "osm node[id='#{node_v1.node_id}'][version='#{node_v1.version}']", 1, "node #{node_v1.node_id} version #{node_v1.version} should now be present in the history for moderators without passing flag."
basic_authorization create(:user).email, "test"
# check normal user can now see the redacted data
- get :version, :params => { :id => node_v1.node_id, :version => node_v1.version }
+ get :version, :params => { :id => node_v1.node_id, :version => node_v1.version }, :format => :xml
assert_response :success, "After unredaction, node should be visible to normal users."
# and when accessed via history
- get :history, :params => { :id => node_v1.node_id }
+ get :history, :params => { :id => node_v1.node_id }, :format => :xml
assert_response :success, "Unredaction shouldn't have stopped history working."
assert_select "osm node[id='#{node_v1.node_id}'][version='#{node_v1.version}']", 1, "node #{node_v1.node_id} version #{node_v1.version} should now be present in the history for normal users without passing flag."
end
private
def do_redact_node(node, redaction)
- get :version, :params => { :id => node.node_id, :version => node.version }
+ get :version, :params => { :id => node.node_id, :version => node.version }, :format => :xml
assert_response :success, "should be able to get version #{node.version} of node #{node.node_id}."
# now redact it
def check_current_version(node_id)
# get the current version of the node
current_node = with_controller(NodesController.new) do
- get :show, :params => { :id => node_id }
+ get :show, :params => { :id => node_id }, :format => :xml
assert_response :success, "cant get current node #{node_id}"
Node.from_xml(@response.body)
end
assert_not_nil current_node, "getting node #{node_id} returned nil"
# get the "old" version of the node from the old_node interface
- get :version, :params => { :id => node_id, :version => current_node.version }
+ get :version, :params => { :id => node_id, :version => current_node.version }, :format => :xml
assert_response :success, "cant get old node #{node_id}, v#{current_node.version}"
old_node = Node.from_xml(@response.body)
def test_routes
assert_routing(
{ :path => "/api/0.6/relation/1/history", :method => :get },
- { :controller => "api/old_relations", :action => "history", :id => "1" }
+ { :controller => "api/old_relations", :action => "history", :id => "1", :format => "xml" }
)
assert_routing(
{ :path => "/api/0.6/relation/1/2", :method => :get },
- { :controller => "api/old_relations", :action => "version", :id => "1", :version => "2" }
+ { :controller => "api/old_relations", :action => "version", :id => "1", :version => "2", :format => "xml" }
)
assert_routing(
{ :path => "/api/0.6/relation/1/2/redact", :method => :post },
# -------------------------------------
def test_history
# check that a visible relations is returned properly
- get :history, :params => { :id => create(:relation, :with_history).id }
+ get :history, :params => { :id => create(:relation, :with_history).id }, :format => :xml
assert_response :success
# check chat a non-existent relations is not returned
- get :history, :params => { :id => 0 }
+ get :history, :params => { :id => 0 }, :format => :xml
assert_response :not_found
end
relation_v1 = relation.old_relations.find_by(:version => 1)
relation_v1.redact!(create(:redaction))
- get :version, :params => { :id => relation_v1.relation_id, :version => relation_v1.version }
+ get :version, :params => { :id => relation_v1.relation_id, :version => relation_v1.version }, :format => :xml
assert_response :forbidden, "Redacted relation shouldn't be visible via the version API."
# not even to a logged-in user
basic_authorization create(:user).email, "test"
- get :version, :params => { :id => relation_v1.relation_id, :version => relation_v1.version }
+ get :version, :params => { :id => relation_v1.relation_id, :version => relation_v1.version }, :format => :xml
assert_response :forbidden, "Redacted relation shouldn't be visible via the version API, even when logged in."
end
relation_v1 = relation.old_relations.find_by(:version => 1)
relation_v1.redact!(create(:redaction))
- get :history, :params => { :id => relation_v1.relation_id }
+ get :history, :params => { :id => relation_v1.relation_id }, :format => :xml
assert_response :success, "Redaction shouldn't have stopped history working."
assert_select "osm relation[id='#{relation_v1.relation_id}'][version='#{relation_v1.version}']", 0, "redacted relation #{relation_v1.relation_id} version #{relation_v1.version} shouldn't be present in the history."
# not even to a logged-in user
basic_authorization create(:user).email, "test"
- get :version, :params => { :id => relation_v1.relation_id, :version => relation_v1.version }
- get :history, :params => { :id => relation_v1.relation_id }
+ get :version, :params => { :id => relation_v1.relation_id, :version => relation_v1.version }, :format => :xml
+ get :history, :params => { :id => relation_v1.relation_id }, :format => :xml
assert_response :success, "Redaction shouldn't have stopped history working."
assert_select "osm relation[id='#{relation_v1.relation_id}'][version='#{relation_v1.version}']", 0, "redacted relation #{relation_v1.relation_id} version #{relation_v1.version} shouldn't be present in the history, even when logged in."
end
# check moderator can still see the redacted data, when passing
# the appropriate flag
- get :version, :params => { :id => relation_v3.relation_id, :version => relation_v3.version }
+ get :version, :params => { :id => relation_v3.relation_id, :version => relation_v3.version }, :format => :xml
assert_response :forbidden, "After redaction, relation should be gone for moderator, when flag not passed."
- get :version, :params => { :id => relation_v3.relation_id, :version => relation_v3.version, :show_redactions => "true" }
+ get :version, :params => { :id => relation_v3.relation_id, :version => relation_v3.version, :show_redactions => "true" }, :format => :xml
assert_response :success, "After redaction, relation should not be gone for moderator, when flag passed."
# and when accessed via history
- get :history, :params => { :id => relation_v3.relation_id }
+ get :history, :params => { :id => relation_v3.relation_id }, :format => :xml
assert_response :success, "Redaction shouldn't have stopped history working."
assert_select "osm relation[id='#{relation_v3.relation_id}'][version='#{relation_v3.version}']", 0, "relation #{relation_v3.relation_id} version #{relation_v3.version} should not be present in the history for moderators when not passing flag."
- get :history, :params => { :id => relation_v3.relation_id, :show_redactions => "true" }
+ get :history, :params => { :id => relation_v3.relation_id, :show_redactions => "true" }, :format => :xml
assert_response :success, "Redaction shouldn't have stopped history working."
assert_select "osm relation[id='#{relation_v3.relation_id}'][version='#{relation_v3.version}']", 1, "relation #{relation_v3.relation_id} version #{relation_v3.version} should still be present in the history for moderators when passing flag."
end
basic_authorization create(:user).email, "test"
# check can't see the redacted data
- get :version, :params => { :id => relation_v3.relation_id, :version => relation_v3.version }
+ get :version, :params => { :id => relation_v3.relation_id, :version => relation_v3.version }, :format => :xml
assert_response :forbidden, "Redacted relation shouldn't be visible via the version API."
# and when accessed via history
- get :history, :params => { :id => relation_v3.relation_id }
+ get :history, :params => { :id => relation_v3.relation_id }, :format => :xml
assert_response :success, "Redaction shouldn't have stopped history working."
assert_select "osm relation[id='#{relation_v3.relation_id}'][version='#{relation_v3.version}']", 0, "redacted relation #{relation_v3.relation_id} version #{relation_v3.version} shouldn't be present in the history."
end
# check moderator can still see the redacted data, without passing
# the appropriate flag
- get :version, :params => { :id => relation_v1.relation_id, :version => relation_v1.version }
+ get :version, :params => { :id => relation_v1.relation_id, :version => relation_v1.version }, :format => :xml
assert_response :success, "After unredaction, relation should not be gone for moderator."
# and when accessed via history
- get :history, :params => { :id => relation_v1.relation_id }
+ get :history, :params => { :id => relation_v1.relation_id }, :format => :xml
assert_response :success, "Redaction shouldn't have stopped history working."
assert_select "osm relation[id='#{relation_v1.relation_id}'][version='#{relation_v1.version}']", 1, "relation #{relation_v1.relation_id} version #{relation_v1.version} should still be present in the history for moderators."
basic_authorization create(:user).email, "test"
# check normal user can now see the redacted data
- get :version, :params => { :id => relation_v1.relation_id, :version => relation_v1.version }
+ get :version, :params => { :id => relation_v1.relation_id, :version => relation_v1.version }, :format => :xml
assert_response :success, "After redaction, node should not be gone for normal user."
# and when accessed via history
- get :history, :params => { :id => relation_v1.relation_id }
+ get :history, :params => { :id => relation_v1.relation_id }, :format => :xml
assert_response :success, "Redaction shouldn't have stopped history working."
assert_select "osm relation[id='#{relation_v1.relation_id}'][version='#{relation_v1.version}']", 1, "relation #{relation_v1.relation_id} version #{relation_v1.version} should still be present in the history for normal users."
end
def check_current_version(relation_id)
# get the current version
current_relation = with_controller(RelationsController.new) do
- get :show, :params => { :id => relation_id }
+ get :show, :params => { :id => relation_id }, :format => :xml
assert_response :success, "can't get current relation #{relation_id}"
Relation.from_xml(@response.body)
end
assert_not_nil current_relation, "getting relation #{relation_id} returned nil"
# get the "old" version of the relation from the version method
- get :version, :params => { :id => relation_id, :version => current_relation.version }
+ get :version, :params => { :id => relation_id, :version => current_relation.version }, :format => :xml
assert_response :success, "can't get old relation #{relation_id}, v#{current_relation.version}"
old_relation = Relation.from_xml(@response.body)
# look at all the versions of the relation in the history and get each version from
# the versions call. check that they're the same.
def check_history_equals_versions(relation_id)
- get :history, :params => { :id => relation_id }
+ get :history, :params => { :id => relation_id }, :format => :xml
assert_response :success, "can't get relation #{relation_id} from API"
history_doc = XML::Parser.string(@response.body).parse
assert_not_nil history_doc, "parsing relation #{relation_id} history failed"
history_relation = Relation.from_xml_node(relation_doc)
assert_not_nil history_relation, "parsing relation #{relation_id} version failed"
- get :version, :params => { :id => relation_id, :version => history_relation.version }
+ get :version, :params => { :id => relation_id, :version => history_relation.version }, :format => :xml
assert_response :success, "couldn't get relation #{relation_id}, v#{history_relation.version}"
version_relation = Relation.from_xml(@response.body)
assert_not_nil version_relation, "failed to parse #{relation_id}, v#{history_relation.version}"
end
def do_redact_relation(relation, redaction)
- get :version, :params => { :id => relation.relation_id, :version => relation.version }
+ get :version, :params => { :id => relation.relation_id, :version => relation.version }, :format => :xml
assert_response :success, "should be able to get version #{relation.version} of relation #{relation.relation_id}."
# now redact it
def test_routes
assert_routing(
{ :path => "/api/0.6/way/1/history", :method => :get },
- { :controller => "api/old_ways", :action => "history", :id => "1" }
+ { :controller => "api/old_ways", :action => "history", :id => "1", :format => "xml" }
)
assert_routing(
{ :path => "/api/0.6/way/1/2", :method => :get },
- { :controller => "api/old_ways", :action => "version", :id => "1", :version => "2" }
+ { :controller => "api/old_ways", :action => "version", :id => "1", :version => "2", :format => "xml" }
)
assert_routing(
{ :path => "/api/0.6/way/1/2/redact", :method => :post },
def test_history_visible
# check that a visible way is returned properly
- get :history, :params => { :id => create(:way, :with_history).id }
+ get :history, :params => { :id => create(:way, :with_history).id }, :format => :xml
assert_response :success
end
def test_history_invisible
# check that an invisible way's history is returned properly
- get :history, :params => { :id => create(:way, :with_history, :deleted).id }
+ get :history, :params => { :id => create(:way, :with_history, :deleted).id }, :format => :xml
assert_response :success
end
def test_history_invalid
# check chat a non-existent way is not returned
- get :history, :params => { :id => 0 }
+ get :history, :params => { :id => 0 }, :format => :xml
assert_response :not_found
end
way_v1 = way.old_ways.find_by(:version => 1)
way_v1.redact!(create(:redaction))
- get :version, :params => { :id => way_v1.way_id, :version => way_v1.version }
+ get :version, :params => { :id => way_v1.way_id, :version => way_v1.version }, :format => :xml
assert_response :forbidden, "Redacted way shouldn't be visible via the version API."
# not even to a logged-in user
basic_authorization create(:user).email, "test"
- get :version, :params => { :id => way_v1.way_id, :version => way_v1.version }
+ get :version, :params => { :id => way_v1.way_id, :version => way_v1.version }, :format => :xml
assert_response :forbidden, "Redacted way shouldn't be visible via the version API, even when logged in."
end
way_v1 = way.old_ways.find_by(:version => 1)
way_v1.redact!(create(:redaction))
- get :history, :params => { :id => way_v1.way_id }
+ get :history, :params => { :id => way_v1.way_id }, :format => :xml
assert_response :success, "Redaction shouldn't have stopped history working."
assert_select "osm way[id='#{way_v1.way_id}'][version='#{way_v1.version}']", 0, "redacted way #{way_v1.way_id} version #{way_v1.version} shouldn't be present in the history."
# not even to a logged-in user
basic_authorization create(:user).email, "test"
- get :version, :params => { :id => way_v1.way_id, :version => way_v1.version }
- get :history, :params => { :id => way_v1.way_id }
+ get :version, :params => { :id => way_v1.way_id, :version => way_v1.version }, :format => :xml
+ get :history, :params => { :id => way_v1.way_id }, :format => :xml
assert_response :success, "Redaction shouldn't have stopped history working."
assert_select "osm way[id='#{way_v1.way_id}'][version='#{way_v1.version}']", 0, "redacted node #{way_v1.way_id} version #{way_v1.version} shouldn't be present in the history, even when logged in."
end
# check moderator can still see the redacted data, when passing
# the appropriate flag
- get :version, :params => { :id => way_v3.way_id, :version => way_v3.version }
+ get :version, :params => { :id => way_v3.way_id, :version => way_v3.version }, :format => :xml
assert_response :forbidden, "After redaction, node should be gone for moderator, when flag not passed."
- get :version, :params => { :id => way_v3.way_id, :version => way_v3.version, :show_redactions => "true" }
+ get :version, :params => { :id => way_v3.way_id, :version => way_v3.version, :show_redactions => "true" }, :format => :xml
assert_response :success, "After redaction, node should not be gone for moderator, when flag passed."
# and when accessed via history
- get :history, :params => { :id => way_v3.way_id }
+ get :history, :params => { :id => way_v3.way_id }, :format => :xml
assert_response :success, "Redaction shouldn't have stopped history working."
assert_select "osm way[id='#{way_v3.way_id}'][version='#{way_v3.version}']", 0, "way #{way_v3.way_id} version #{way_v3.version} should not be present in the history for moderators when not passing flag."
- get :history, :params => { :id => way_v3.way_id, :show_redactions => "true" }
+ get :history, :params => { :id => way_v3.way_id, :show_redactions => "true" }, :format => :xml
assert_response :success, "Redaction shouldn't have stopped history working."
assert_select "osm way[id='#{way_v3.way_id}'][version='#{way_v3.version}']", 1, "way #{way_v3.way_id} version #{way_v3.version} should still be present in the history for moderators when passing flag."
end
basic_authorization create(:user).email, "test"
# check can't see the redacted data
- get :version, :params => { :id => way_v3.way_id, :version => way_v3.version }
+ get :version, :params => { :id => way_v3.way_id, :version => way_v3.version }, :format => :xml
assert_response :forbidden, "Redacted node shouldn't be visible via the version API."
# and when accessed via history
- get :history, :params => { :id => way_v3.way_id }
+ get :history, :params => { :id => way_v3.way_id }, :format => :xml
assert_response :success, "Redaction shouldn't have stopped history working."
assert_select "osm way[id='#{way_v3.way_id}'][version='#{way_v3.version}']", 0, "redacted way #{way_v3.way_id} version #{way_v3.version} shouldn't be present in the history."
end
# check moderator can still see the unredacted data, without passing
# the appropriate flag
- get :version, :params => { :id => way_v1.way_id, :version => way_v1.version }
+ get :version, :params => { :id => way_v1.way_id, :version => way_v1.version }, :format => :xml
assert_response :success, "After unredaction, node should not be gone for moderator."
# and when accessed via history
- get :history, :params => { :id => way_v1.way_id }
+ get :history, :params => { :id => way_v1.way_id }, :format => :xml
assert_response :success, "Unredaction shouldn't have stopped history working."
assert_select "osm way[id='#{way_v1.way_id}'][version='#{way_v1.version}']", 1, "way #{way_v1.way_id} version #{way_v1.version} should still be present in the history for moderators."
basic_authorization create(:user).email, "test"
# check normal user can now see the unredacted data
- get :version, :params => { :id => way_v1.way_id, :version => way_v1.version }
+ get :version, :params => { :id => way_v1.way_id, :version => way_v1.version }, :format => :xml
assert_response :success, "After redaction, node should not be gone for moderator, when flag passed."
# and when accessed via history
- get :history, :params => { :id => way_v1.way_id }
+ get :history, :params => { :id => way_v1.way_id }, :format => :xml
assert_response :success, "Redaction shouldn't have stopped history working."
assert_select "osm way[id='#{way_v1.way_id}'][version='#{way_v1.version}']", 1, "way #{way_v1.way_id} version #{way_v1.version} should still be present in the history for normal users."
end
def check_current_version(way_id)
# get the current version
current_way = with_controller(WaysController.new) do
- get :show, :params => { :id => way_id }
+ get :show, :params => { :id => way_id }, :format => :xml
assert_response :success, "can't get current way #{way_id}"
Way.from_xml(@response.body)
end
assert_not_nil current_way, "getting way #{way_id} returned nil"
# get the "old" version of the way from the version method
- get :version, :params => { :id => way_id, :version => current_way.version }
+ get :version, :params => { :id => way_id, :version => current_way.version }, :format => :xml
assert_response :success, "can't get old way #{way_id}, v#{current_way.version}"
old_way = Way.from_xml(@response.body)
# look at all the versions of the way in the history and get each version from
# the versions call. check that they're the same.
def check_history_equals_versions(way_id)
- get :history, :params => { :id => way_id }
+ get :history, :params => { :id => way_id }, :format => :xml
assert_response :success, "can't get way #{way_id} from API"
history_doc = XML::Parser.string(@response.body).parse
assert_not_nil history_doc, "parsing way #{way_id} history failed"
history_way = Way.from_xml_node(way_doc)
assert_not_nil history_way, "parsing way #{way_id} version failed"
- get :version, :params => { :id => way_id, :version => history_way.version }
+ get :version, :params => { :id => way_id, :version => history_way.version }, :format => :xml
assert_response :success, "couldn't get way #{way_id}, v#{history_way.version}"
version_way = Way.from_xml(@response.body)
assert_not_nil version_way, "failed to parse #{way_id}, v#{history_way.version}"
end
def do_redact_way(way, redaction)
- get :version, :params => { :id => way.way_id, :version => way.version }
+ get :version, :params => { :id => way.way_id, :version => way.version }, :format => :xml
assert_response :success, "should be able to get version #{way.version} of way #{way.way_id}."
# now redact it
)
assert_routing(
{ :path => "/api/0.6/relation/1/full", :method => :get },
- { :controller => "api/relations", :action => "full", :id => "1" }
+ { :controller => "api/relations", :action => "full", :id => "1", :format => "xml" }
)
assert_routing(
{ :path => "/api/0.6/relation/1", :method => :get },
- { :controller => "api/relations", :action => "show", :id => "1" }
+ { :controller => "api/relations", :action => "show", :id => "1", :format => "xml" }
)
assert_routing(
{ :path => "/api/0.6/relation/1", :method => :put },
)
assert_routing(
{ :path => "/api/0.6/relations", :method => :get },
- { :controller => "api/relations", :action => "index" }
+ { :controller => "api/relations", :action => "index", :format => "xml" }
)
assert_routing(
{ :path => "/api/0.6/node/1/relations", :method => :get },
- { :controller => "api/relations", :action => "relations_for_node", :id => "1" }
+ { :controller => "api/relations", :action => "relations_for_node", :id => "1", :format => "xml" }
)
assert_routing(
{ :path => "/api/0.6/way/1/relations", :method => :get },
- { :controller => "api/relations", :action => "relations_for_way", :id => "1" }
+ { :controller => "api/relations", :action => "relations_for_way", :id => "1", :format => "xml" }
)
assert_routing(
{ :path => "/api/0.6/relation/1/relations", :method => :get },
- { :controller => "api/relations", :action => "relations_for_relation", :id => "1" }
+ { :controller => "api/relations", :action => "relations_for_relation", :id => "1", :format => "xml" }
)
end
def test_show
# check that a visible relation is returned properly
- get :show, :params => { :id => create(:relation).id }
+ get :show, :params => { :id => create(:relation).id }, :format => :xml
assert_response :success
# check that an invisible relation is not returned
- get :show, :params => { :id => create(:relation, :deleted).id }
+ get :show, :params => { :id => create(:relation, :deleted).id }, :format => :xml
assert_response :gone
# check chat a non-existent relation is not returned
- get :show, :params => { :id => 0 }
+ get :show, :params => { :id => 0 }, :format => :xml
assert_response :not_found
end
def check_relations_for_element(method, type, id, expected_relations)
# check the "relations for relation" mode
- get method, :params => { :id => id }
+ get method, :params => { :id => id }, :format => :xml
assert_response :success
# count one osm element
def test_full
# check the "full" mode
- get :full, :params => { :id => 999999 }
+ get :full, :params => { :id => 999999 }, :format => :xml
assert_response :not_found
- get :full, :params => { :id => create(:relation, :deleted).id }
+ get :full, :params => { :id => create(:relation, :deleted).id }, :format => :xml
assert_response :gone
- get :full, :params => { :id => create(:relation).id }
+ get :full, :params => { :id => create(:relation).id }, :format => :xml
assert_response :success
# FIXME: check whether this contains the stuff we want!
end
relation4.old_relations.find_by(:version => 1).redact!(create(:redaction))
# check error when no parameter provided
- get :index
+ get :index, :format => :xml
assert_response :bad_request
# check error when no parameter value provided
- get :index, :params => { :relations => "" }
+ get :index, :params => { :relations => "" }, :format => :xml
assert_response :bad_request
# test a working call
- get :index, :params => { :relations => "#{relation1.id},#{relation2.id},#{relation3.id},#{relation4.id}" }
+ get :index, :params => { :relations => "#{relation1.id},#{relation2.id},#{relation3.id},#{relation4.id}" }, :format => :xml
assert_response :success
assert_select "osm" do
assert_select "relation", :count => 4
end
# check error when a non-existent relation is included
- get :index, :params => { :relations => "#{relation1.id},#{relation2.id},#{relation3.id},#{relation4.id},0" }
+ get :index, :params => { :relations => "#{relation1.id},#{relation2.id},#{relation3.id},#{relation4.id},0" }, :format => :xml
assert_response :not_found
end
assert_equal true, checkrelation.visible,
"saved relation is not visible"
# ok the relation is there but can we also retrieve it?
- get :show, :params => { :id => relationid }
+ get :show, :params => { :id => relationid }, :format => :xml
assert_response :success
###
"saved relation is not visible"
# ok the relation is there but can we also retrieve it?
- get :show, :params => { :id => relationid }
+ get :show, :params => { :id => relationid }, :format => :xml
assert_response :success
###
"saved relation is not visible"
# ok the relation is there but can we also retrieve it?
- get :show, :params => { :id => relationid }
+ get :show, :params => { :id => relationid }, :format => :xml
assert_response :success
###
assert_equal true, checkrelation.visible,
"saved relation is not visible"
# ok the relation is there but can we also retrieve it?
- get :show, :params => { :id => relationid }
+ get :show, :params => { :id => relationid }, :format => :xml
assert_response :success
end
assert_response :success, "can't update relation for add #{element.class}/bbox test: #{@response.body}"
# get it back and check the ordering
- get :show, :params => { :id => relation.id }
+ get :show, :params => { :id => relation.id }, :format => :xml
assert_response :success, "can't read back the relation: #{@response.body}"
check_ordering(relation_xml, @response.body)
end
relation_id = @response.body.to_i
# get it back and check the ordering
- get :show, :params => { :id => relation_id }
+ get :show, :params => { :id => relation_id }, :format => :xml
assert_response :success, "can't read back the relation: #{@response.body}"
check_ordering(doc, @response.body)
assert_equal 2, @response.body.to_i
# get it back again and check the ordering again
- get :show, :params => { :id => relation_id }
+ get :show, :params => { :id => relation_id }, :format => :xml
assert_response :success, "can't read back the relation: #{@response.body}"
check_ordering(doc, @response.body)
# check the ordering in the history tables:
with_controller(OldRelationsController.new) do
- get :version, :params => { :id => relation_id, :version => 2 }
+ get :version, :params => { :id => relation_id, :version => 2 }, :format => :xml
assert_response :success, "can't read back version 2 of the relation #{relation_id}"
check_ordering(doc, @response.body)
end
relation_id = @response.body.to_i
# get it back and check the ordering
- get :show, :params => { :id => relation_id }
+ get :show, :params => { :id => relation_id }, :format => :xml
assert_response :success, "can't read back the relation: #{relation_id}"
check_ordering(doc, @response.body)
end
relation_id = @response.body.to_i
# check the ordering in the current tables:
- get :show, :params => { :id => relation_id }
+ get :show, :params => { :id => relation_id }, :format => :xml
assert_response :success, "can't read back the relation: #{@response.body}"
check_ordering(doc, @response.body)
# check the ordering in the history tables:
with_controller(OldRelationsController.new) do
- get :version, :params => { :id => relation_id, :version => 1 }
+ get :version, :params => { :id => relation_id, :version => 1 }, :format => :xml
assert_response :success, "can't read back version 1 of the relation: #{@response.body}"
check_ordering(doc, @response.body)
end
# now download the changeset to check its bounding box
with_controller(Api::ChangesetsController.new) do
- get :show, :params => { :id => changeset_id }
+ get :show, :params => { :id => changeset_id }, :format => :xml
assert_response :success, "can't re-read changeset for modify test"
assert_select "osm>changeset", 1, "Changeset element doesn't exist in #{@response.body}"
assert_select "osm>changeset[id='#{changeset_id}']", 1, "Changeset id=#{changeset_id} doesn't exist in #{@response.body}"
# doc is returned.
def with_relation(id, ver = nil)
if ver.nil?
- get :show, :params => { :id => id }
+ get :show, :params => { :id => id }, :format => :xml
else
with_controller(OldRelationsController.new) do
- get :version, :params => { :id => id, :version => ver }
+ get :version, :params => { :id => id, :version => ver }, :format => :xml
end
end
assert_response :success
version = @response.body.to_i
# now get the new version
- get :show, :params => { :id => rel_id }
+ get :show, :params => { :id => rel_id }, :format => :xml
assert_response :success
new_rel = xml_parse(@response.body)
end
# now get the new version
- get :show, :params => { :id => rel_id }
+ get :show, :params => { :id => rel_id }, :format => :xml
assert_response :success
new_rel = xml_parse(@response.body)
)
assert_routing(
{ :path => "/api/0.6/way/1/full", :method => :get },
- { :controller => "api/ways", :action => "full", :id => "1" }
+ { :controller => "api/ways", :action => "full", :id => "1", :format => "xml" }
)
assert_routing(
{ :path => "/api/0.6/way/1", :method => :get },
- { :controller => "api/ways", :action => "show", :id => "1" }
+ { :controller => "api/ways", :action => "show", :id => "1", :format => "xml" }
)
assert_routing(
{ :path => "/api/0.6/way/1", :method => :put },
)
assert_routing(
{ :path => "/api/0.6/ways", :method => :get },
- { :controller => "api/ways", :action => "index" }
+ { :controller => "api/ways", :action => "index", :format => "xml" }
)
end
def test_show
# check that a visible way is returned properly
- get :show, :params => { :id => create(:way).id }
+ get :show, :params => { :id => create(:way).id }, :format => :xml
assert_response :success
# check that an invisible way is not returned
- get :show, :params => { :id => create(:way, :deleted).id }
+ get :show, :params => { :id => create(:way, :deleted).id }, :format => :xml
assert_response :gone
# check chat a non-existent way is not returned
- get :show, :params => { :id => 0 }
+ get :show, :params => { :id => 0 }, :format => :xml
assert_response :not_found
end
way4 = create(:way)
# check error when no parameter provided
- get :index
+ get :index, :format => :xml
assert_response :bad_request
# check error when no parameter value provided
- get :index, :params => { :ways => "" }
+ get :index, :params => { :ways => "" }, :format => :xml
assert_response :bad_request
# test a working call
- get :index, :params => { :ways => "#{way1.id},#{way2.id},#{way3.id},#{way4.id}" }
+ get :index, :params => { :ways => "#{way1.id},#{way2.id},#{way3.id},#{way4.id}" }, :format => :xml
assert_response :success
assert_select "osm" do
assert_select "way", :count => 4
end
# check error when a non-existent way is included
- get :index, :params => { :ways => "#{way1.id},#{way2.id},#{way3.id},#{way4.id},0" }
+ get :index, :params => { :ways => "#{way1.id},#{way2.id},#{way3.id},#{way4.id},0" }, :format => :xml
assert_response :not_found
end
_way3_v2 = create(:old_way, :current_way => way3_v1.current_way, :version => 2)
create(:old_way_node, :old_way => way3_v1, :node => node)
- get :ways_for_node, :params => { :id => node.id }
+ get :ways_for_node, :params => { :id => node.id }, :format => :xml
assert_response :success
ways_xml = XML::Parser.string(@response.body).parse
assert_not_nil ways_xml, "failed to parse ways_for_node response"