post "changeset/comment/:id/hide" => "changeset_comments#destroy", :as => :changeset_comment_hide, :id => /\d+/
post "changeset/comment/:id/unhide" => "changeset_comments#restore", :as => :changeset_comment_unhide, :id => /\d+/
- put "node/create" => "nodes#create"
get "node/:id/ways" => "ways#ways_for_node", :as => :node_ways, :id => /\d+/
get "node/:id/relations" => "relations#relations_for_node", :as => :node_relations, :id => /\d+/
get "node/:id/history" => "old_nodes#history", :as => :api_node_history, :id => /\d+/
get "node/:id" => "nodes#show", :as => :api_node, :id => /\d+/
put "node/:id" => "nodes#update", :id => /\d+/
delete "node/:id" => "nodes#delete", :id => /\d+/
- get "nodes" => "nodes#index"
- put "way/create" => "ways#create"
get "way/:id/history" => "old_ways#history", :as => :api_way_history, :id => /\d+/
get "way/:id/full" => "ways#full", :as => :way_full, :id => /\d+/
get "way/:id/relations" => "relations#relations_for_way", :as => :way_relations, :id => /\d+/
get "way/:id" => "ways#show", :as => :api_way, :id => /\d+/
put "way/:id" => "ways#update", :id => /\d+/
delete "way/:id" => "ways#delete", :id => /\d+/
- get "ways" => "ways#index"
- put "relation/create" => "relations#create"
get "relation/:id/relations" => "relations#relations_for_relation", :as => :relation_relations, :id => /\d+/
get "relation/:id/history" => "old_relations#history", :as => :api_relation_history, :id => /\d+/
get "relation/:id/full" => "relations#full", :as => :relation_full, :id => /\d+/
get "relation/:id" => "relations#show", :as => :api_relation, :id => /\d+/
put "relation/:id" => "relations#update", :id => /\d+/
delete "relation/:id" => "relations#delete", :id => /\d+/
- get "relations" => "relations#index"
end
namespace :api, :path => "api/0.6" do
+ resources :nodes, :only => [:index, :create]
+ put "node/create" => "nodes#create", :as => nil
+
+ resources :ways, :only => [:index, :create]
+ put "way/create" => "ways#create", :as => nil
+
+ resources :relations, :only => [:index, :create]
+ put "relation/create" => "relations#create", :as => nil
+
resource :map, :only => :show
resources :tracepoints, :path => "trackpoints", :only => :index
# add a single node to it
with_controller(NodesController.new) do
xml = "<osm><node lon='0.1' lat='0.2' changeset='#{changeset_id}'/></osm>"
- put node_create_path, :params => xml, :headers => auth_header
+ post api_nodes_path, :params => xml, :headers => auth_header
assert_response :success, "Couldn't create node."
end
# add another node to it
with_controller(NodesController.new) do
xml = "<osm><node lon='0.2' lat='0.1' changeset='#{changeset_id}'/></osm>"
- put node_create_path, :params => xml, :headers => auth_header
+ post api_nodes_path, :params => xml, :headers => auth_header
assert_response :success, "Couldn't create second node."
end
with_controller(NodesController.new) do
# create a new node
xml = "<osm><node changeset='#{cs_id}' lat='0.0' lon='0.0'/></osm>"
- put node_create_path, :params => xml, :headers => auth_header
+ post api_nodes_path, :params => xml, :headers => auth_header
assert_response :success, "can't create a new node"
node_id = @response.body.to_i
# test all routes which lead to this controller
def test_routes
assert_routing(
- { :path => "/api/0.6/node/create", :method => :put },
+ { :path => "/api/0.6/nodes", :method => :get },
+ { :controller => "api/nodes", :action => "index" }
+ )
+ assert_routing(
+ { :path => "/api/0.6/nodes.json", :method => :get },
+ { :controller => "api/nodes", :action => "index", :format => "json" }
+ )
+ assert_routing(
+ { :path => "/api/0.6/nodes", :method => :post },
{ :controller => "api/nodes", :action => "create" }
)
assert_routing(
{ :path => "/api/0.6/node/1", :method => :delete },
{ :controller => "api/nodes", :action => "delete", :id => "1" }
)
- assert_routing(
- { :path => "/api/0.6/nodes", :method => :get },
- { :controller => "api/nodes", :action => "index" }
- )
- assert_routing(
- { :path => "/api/0.6/nodes.json", :method => :get },
- { :controller => "api/nodes", :action => "index", :format => "json" }
+
+ assert_recognizes(
+ { :controller => "api/nodes", :action => "create" },
+ { :path => "/api/0.6/node/create", :method => :put }
)
end
+ ##
+ # test fetching multiple nodes
+ def test_index
+ node1 = create(:node)
+ node2 = create(:node, :deleted)
+ node3 = create(:node)
+ node4 = create(:node, :with_history, :version => 2)
+ node5 = create(:node, :deleted, :with_history, :version => 2)
+
+ # check error when no parameter provided
+ get api_nodes_path
+ assert_response :bad_request
+
+ # check error when no parameter value provided
+ get api_nodes_path(:nodes => "")
+ assert_response :bad_request
+
+ # test a working call
+ get api_nodes_path(:nodes => "#{node1.id},#{node2.id},#{node3.id},#{node4.id},#{node5.id}")
+ assert_response :success
+ assert_select "osm" do
+ assert_select "node", :count => 5
+ assert_select "node[id='#{node1.id}'][visible='true']", :count => 1
+ assert_select "node[id='#{node2.id}'][visible='false']", :count => 1
+ assert_select "node[id='#{node3.id}'][visible='true']", :count => 1
+ assert_select "node[id='#{node4.id}'][visible='true']", :count => 1
+ assert_select "node[id='#{node5.id}'][visible='false']", :count => 1
+ end
+
+ # test a working call with json format
+ get api_nodes_path(:nodes => "#{node1.id},#{node2.id},#{node3.id},#{node4.id},#{node5.id}", :format => "json")
+
+ js = ActiveSupport::JSON.decode(@response.body)
+ assert_not_nil js
+ assert_equal 5, js["elements"].count
+ assert_equal 5, (js["elements"].count { |a| a["type"] == "node" })
+ assert_equal 1, (js["elements"].count { |a| a["id"] == node1.id && a["visible"].nil? })
+ assert_equal 1, (js["elements"].count { |a| a["id"] == node2.id && a["visible"] == false })
+ assert_equal 1, (js["elements"].count { |a| a["id"] == node3.id && a["visible"].nil? })
+ assert_equal 1, (js["elements"].count { |a| a["id"] == node4.id && a["visible"].nil? })
+ assert_equal 1, (js["elements"].count { |a| a["id"] == node5.id && a["visible"] == false })
+
+ # check error when a non-existent node is included
+ get api_nodes_path(:nodes => "#{node1.id},#{node2.id},#{node3.id},#{node4.id},#{node5.id},0")
+ assert_response :not_found
+ end
+
def test_create
private_user = create(:user, :data_public => false)
private_changeset = create(:changeset, :user => private_user)
# create a minimal xml file
xml = "<osm><node lat='#{lat}' lon='#{lon}' changeset='#{changeset.id}'/></osm>"
assert_difference("OldNode.count", 0) do
- put node_create_path, :params => xml
+ post api_nodes_path, :params => xml
end
# hope for unauthorized
assert_response :unauthorized, "node upload did not return unauthorized status"
# create a minimal xml file
xml = "<osm><node lat='#{lat}' lon='#{lon}' changeset='#{private_changeset.id}'/></osm>"
assert_difference("Node.count", 0) do
- put node_create_path, :params => xml, :headers => auth_header
+ post api_nodes_path, :params => xml, :headers => auth_header
end
# hope for success
assert_require_public_data "node create did not return forbidden status"
# create a minimal xml file
xml = "<osm><node lat='#{lat}' lon='#{lon}' changeset='#{changeset.id}'/></osm>"
- put node_create_path, :params => xml, :headers => auth_header
+ post api_nodes_path, :params => xml, :headers => auth_header
# hope for success
assert_response :success, "node upload did not return success status"
# test that the upload is rejected when xml is valid, but osm doc isn't
xml = "<create/>"
- put node_create_path, :params => xml, :headers => auth_header
+ post api_nodes_path, :params => xml, :headers => auth_header
assert_response :bad_request, "node upload did not return bad_request status"
assert_equal "Cannot parse valid node from xml string <create/>. XML doesn't contain an osm/node element.", @response.body
# test that the upload is rejected when no lat is supplied
# create a minimal xml file
xml = "<osm><node lon='#{lon}' changeset='#{changeset.id}'/></osm>"
- put node_create_path, :params => xml, :headers => auth_header
+ post api_nodes_path, :params => xml, :headers => auth_header
# hope for success
assert_response :bad_request, "node upload did not return bad_request status"
assert_equal "Cannot parse valid node from xml string <node lon=\"3.23\" changeset=\"#{changeset.id}\"/>. lat missing", @response.body
# test that the upload is rejected when no lon is supplied
# create a minimal xml file
xml = "<osm><node lat='#{lat}' changeset='#{changeset.id}'/></osm>"
- put node_create_path, :params => xml, :headers => auth_header
+ post api_nodes_path, :params => xml, :headers => auth_header
# hope for success
assert_response :bad_request, "node upload did not return bad_request status"
assert_equal "Cannot parse valid node from xml string <node lat=\"3.434\" changeset=\"#{changeset.id}\"/>. lon missing", @response.body
# test that the upload is rejected when lat is non-numeric
# create a minimal xml file
xml = "<osm><node lat='abc' lon='#{lon}' changeset='#{changeset.id}'/></osm>"
- put node_create_path, :params => xml, :headers => auth_header
+ post api_nodes_path, :params => xml, :headers => auth_header
# hope for success
assert_response :bad_request, "node upload did not return bad_request status"
assert_equal "Cannot parse valid node from xml string <node lat=\"abc\" lon=\"#{lon}\" changeset=\"#{changeset.id}\"/>. lat not a number", @response.body
# test that the upload is rejected when lon is non-numeric
# create a minimal xml file
xml = "<osm><node lat='#{lat}' lon='abc' changeset='#{changeset.id}'/></osm>"
- put node_create_path, :params => xml, :headers => auth_header
+ post api_nodes_path, :params => xml, :headers => auth_header
# hope for success
assert_response :bad_request, "node upload did not return bad_request status"
assert_equal "Cannot parse valid node from xml string <node lat=\"#{lat}\" lon=\"abc\" changeset=\"#{changeset.id}\"/>. lon not a number", @response.body
# test that the upload is rejected when we have a tag which is too long
xml = "<osm><node lat='#{lat}' lon='#{lon}' changeset='#{changeset.id}'><tag k='foo' v='#{'x' * 256}'/></node></osm>"
- put node_create_path, :params => xml, :headers => auth_header
+ post api_nodes_path, :params => xml, :headers => auth_header
assert_response :bad_request, "node upload did not return bad_request status"
assert_match(/ v: is too long \(maximum is 255 characters\) /, @response.body)
end
assert_response :success, "a valid update request failed"
end
- ##
- # test fetching multiple nodes
- def test_index
- node1 = create(:node)
- node2 = create(:node, :deleted)
- node3 = create(:node)
- node4 = create(:node, :with_history, :version => 2)
- node5 = create(:node, :deleted, :with_history, :version => 2)
-
- # check error when no parameter provided
- get nodes_path
- assert_response :bad_request
-
- # check error when no parameter value provided
- get nodes_path(:nodes => "")
- assert_response :bad_request
-
- # test a working call
- get nodes_path(:nodes => "#{node1.id},#{node2.id},#{node3.id},#{node4.id},#{node5.id}")
- assert_response :success
- assert_select "osm" do
- assert_select "node", :count => 5
- assert_select "node[id='#{node1.id}'][visible='true']", :count => 1
- assert_select "node[id='#{node2.id}'][visible='false']", :count => 1
- assert_select "node[id='#{node3.id}'][visible='true']", :count => 1
- assert_select "node[id='#{node4.id}'][visible='true']", :count => 1
- assert_select "node[id='#{node5.id}'][visible='false']", :count => 1
- end
-
- # test a working call with json format
- get nodes_path(:nodes => "#{node1.id},#{node2.id},#{node3.id},#{node4.id},#{node5.id}", :format => "json")
-
- js = ActiveSupport::JSON.decode(@response.body)
- assert_not_nil js
- assert_equal 5, js["elements"].count
- assert_equal 5, (js["elements"].count { |a| a["type"] == "node" })
- assert_equal 1, (js["elements"].count { |a| a["id"] == node1.id && a["visible"].nil? })
- assert_equal 1, (js["elements"].count { |a| a["id"] == node2.id && a["visible"] == false })
- assert_equal 1, (js["elements"].count { |a| a["id"] == node3.id && a["visible"].nil? })
- assert_equal 1, (js["elements"].count { |a| a["id"] == node4.id && a["visible"].nil? })
- assert_equal 1, (js["elements"].count { |a| a["id"] == node5.id && a["visible"] == false })
-
- # check error when a non-existent node is included
- get nodes_path(:nodes => "#{node1.id},#{node2.id},#{node3.id},#{node4.id},#{node5.id},0")
- assert_response :not_found
- end
-
##
# test adding tags to a node
def test_duplicate_tags
xml = "<osm><node lat='0' lon='0' changeset='#{private_changeset.id}'>" \
"<tag k='\#{@user.inspect}' v='0'/>" \
"</node></osm>"
- put node_create_path, :params => xml, :headers => auth_header
+ post api_nodes_path, :params => xml, :headers => auth_header
assert_require_public_data "Shouldn't be able to create with non-public user"
## Then try with the public data user
xml = "<osm><node lat='0' lon='0' changeset='#{changeset.id}'>" \
"<tag k='\#{@user.inspect}' v='0'/>" \
"</node></osm>"
- put node_create_path, :params => xml, :headers => auth_header
+ post api_nodes_path, :params => xml, :headers => auth_header
assert_response :success
nodeid = @response.body
# try creating a node
xml = "<osm><node lat='0' lon='0' changeset='#{changeset.id}'/></osm>"
- put node_create_path, :params => xml, :headers => auth_header
+ post api_nodes_path, :params => xml, :headers => auth_header
assert_response :success, "node create did not return success status"
# get the id of the node we created
# try creating a node, which should be rate limited
xml = "<osm><node lat='0' lon='0' changeset='#{changeset.id}'/></osm>"
- put node_create_path, :params => xml, :headers => auth_header
+ post api_nodes_path, :params => xml, :headers => auth_header
assert_response :too_many_requests, "node create did not hit rate limit"
end
# try creating a node
xml = "<osm><node lat='0' lon='0' changeset='#{changeset.id}'/></osm>"
- put node_create_path, :params => xml, :headers => auth_header
+ post api_nodes_path, :params => xml, :headers => auth_header
assert_response :success, "node create did not return success status"
# get the id of the node we created
# try creating a node, which should be rate limited
xml = "<osm><node lat='0' lon='0' changeset='#{changeset.id}'/></osm>"
- put node_create_path, :params => xml, :headers => auth_header
+ post api_nodes_path, :params => xml, :headers => auth_header
assert_response :too_many_requests, "node create did not hit rate limit"
end
# test all routes which lead to this controller
def test_routes
assert_routing(
- { :path => "/api/0.6/relation/create", :method => :put },
+ { :path => "/api/0.6/relations", :method => :get },
+ { :controller => "api/relations", :action => "index" }
+ )
+ assert_routing(
+ { :path => "/api/0.6/relations.json", :method => :get },
+ { :controller => "api/relations", :action => "index", :format => "json" }
+ )
+ assert_routing(
+ { :path => "/api/0.6/relations", :method => :post },
{ :controller => "api/relations", :action => "create" }
)
assert_routing(
{ :path => "/api/0.6/relation/1", :method => :delete },
{ :controller => "api/relations", :action => "delete", :id => "1" }
)
- assert_routing(
- { :path => "/api/0.6/relations", :method => :get },
- { :controller => "api/relations", :action => "index" }
- )
- assert_routing(
- { :path => "/api/0.6/relations.json", :method => :get },
- { :controller => "api/relations", :action => "index", :format => "json" }
- )
assert_routing(
{ :path => "/api/0.6/node/1/relations", :method => :get },
{ :path => "/api/0.6/relation/1/relations.json", :method => :get },
{ :controller => "api/relations", :action => "relations_for_relation", :id => "1", :format => "json" }
)
+
+ assert_recognizes(
+ { :controller => "api/relations", :action => "create" },
+ { :path => "/api/0.6/relation/create", :method => :put }
+ )
+ end
+
+ ##
+ # test fetching multiple relations
+ def test_index
+ relation1 = create(:relation)
+ relation2 = create(:relation, :deleted)
+ relation3 = create(:relation, :with_history, :version => 2)
+ relation4 = create(:relation, :with_history, :version => 2)
+ relation4.old_relations.find_by(:version => 1).redact!(create(:redaction))
+
+ # check error when no parameter provided
+ get api_relations_path
+ assert_response :bad_request
+
+ # check error when no parameter value provided
+ get api_relations_path(:relations => "")
+ assert_response :bad_request
+
+ # test a working call
+ get api_relations_path(:relations => "#{relation1.id},#{relation2.id},#{relation3.id},#{relation4.id}")
+ assert_response :success
+ assert_select "osm" do
+ assert_select "relation", :count => 4
+ assert_select "relation[id='#{relation1.id}'][visible='true']", :count => 1
+ assert_select "relation[id='#{relation2.id}'][visible='false']", :count => 1
+ assert_select "relation[id='#{relation3.id}'][visible='true']", :count => 1
+ assert_select "relation[id='#{relation4.id}'][visible='true']", :count => 1
+ end
+
+ # test a working call with json format
+ get api_relations_path(:relations => "#{relation1.id},#{relation2.id},#{relation3.id},#{relation4.id}", :format => "json")
+
+ js = ActiveSupport::JSON.decode(@response.body)
+ assert_not_nil js
+ assert_equal 4, js["elements"].count
+ assert_equal 4, (js["elements"].count { |a| a["type"] == "relation" })
+ assert_equal 1, (js["elements"].count { |a| a["id"] == relation1.id && a["visible"].nil? })
+ assert_equal 1, (js["elements"].count { |a| a["id"] == relation2.id && a["visible"] == false })
+ assert_equal 1, (js["elements"].count { |a| a["id"] == relation3.id && a["visible"].nil? })
+ assert_equal 1, (js["elements"].count { |a| a["id"] == relation4.id && a["visible"].nil? })
+
+ # check error when a non-existent relation is included
+ get api_relations_path(:relations => "#{relation1.id},#{relation2.id},#{relation3.id},#{relation4.id},0")
+ assert_response :not_found
end
# -------------------------------------
# FIXME: check whether this contains the stuff we want!
end
- ##
- # test fetching multiple relations
- def test_index
- relation1 = create(:relation)
- relation2 = create(:relation, :deleted)
- relation3 = create(:relation, :with_history, :version => 2)
- relation4 = create(:relation, :with_history, :version => 2)
- relation4.old_relations.find_by(:version => 1).redact!(create(:redaction))
-
- # check error when no parameter provided
- get relations_path
- assert_response :bad_request
-
- # check error when no parameter value provided
- get relations_path(:relations => "")
- assert_response :bad_request
-
- # test a working call
- get relations_path(:relations => "#{relation1.id},#{relation2.id},#{relation3.id},#{relation4.id}")
- assert_response :success
- assert_select "osm" do
- assert_select "relation", :count => 4
- assert_select "relation[id='#{relation1.id}'][visible='true']", :count => 1
- assert_select "relation[id='#{relation2.id}'][visible='false']", :count => 1
- assert_select "relation[id='#{relation3.id}'][visible='true']", :count => 1
- assert_select "relation[id='#{relation4.id}'][visible='true']", :count => 1
- end
-
- # test a working call with json format
- get relations_path(:relations => "#{relation1.id},#{relation2.id},#{relation3.id},#{relation4.id}", :format => "json")
-
- js = ActiveSupport::JSON.decode(@response.body)
- assert_not_nil js
- assert_equal 4, js["elements"].count
- assert_equal 4, (js["elements"].count { |a| a["type"] == "relation" })
- assert_equal 1, (js["elements"].count { |a| a["id"] == relation1.id && a["visible"].nil? })
- assert_equal 1, (js["elements"].count { |a| a["id"] == relation2.id && a["visible"] == false })
- assert_equal 1, (js["elements"].count { |a| a["id"] == relation3.id && a["visible"].nil? })
- assert_equal 1, (js["elements"].count { |a| a["id"] == relation4.id && a["visible"].nil? })
-
- # check error when a non-existent relation is included
- get relations_path(:relations => "#{relation1.id},#{relation2.id},#{relation3.id},#{relation4.id},0")
- assert_response :not_found
- end
-
# -------------------------------------
# Test simple relation creation.
# -------------------------------------
# create an relation without members
xml = "<osm><relation changeset='#{private_changeset.id}'><tag k='test' v='yes' /></relation></osm>"
- put relation_create_path, :params => xml, :headers => auth_header
+ post api_relations_path, :params => xml, :headers => auth_header
# hope for forbidden, due to user
assert_response :forbidden,
"relation upload should have failed with forbidden"
xml = "<osm><relation changeset='#{private_changeset.id}'>" \
"<member ref='#{node.id}' type='node' role='some'/>" \
"<tag k='test' v='yes' /></relation></osm>"
- put relation_create_path, :params => xml, :headers => auth_header
+ post api_relations_path, :params => xml, :headers => auth_header
# hope for forbidden due to user
assert_response :forbidden,
"relation upload did not return forbidden status"
# need a role attribute to be included
xml = "<osm><relation changeset='#{private_changeset.id}'>" \
"<member ref='#{node.id}' type='node'/><tag k='test' v='yes' /></relation></osm>"
- put relation_create_path, :params => xml, :headers => auth_header
+ post api_relations_path, :params => xml, :headers => auth_header
# hope for forbidden due to user
assert_response :forbidden,
"relation upload did not return forbidden status"
"<member type='node' ref='#{node.id}' role='some'/>" \
"<member type='way' ref='#{way.id}' role='other'/>" \
"<tag k='test' v='yes' /></relation></osm>"
- put relation_create_path, :params => xml, :headers => auth_header
+ post api_relations_path, :params => xml, :headers => auth_header
# hope for forbidden, due to user
assert_response :forbidden,
"relation upload did not return success status"
# create an relation without members
xml = "<osm><relation changeset='#{changeset.id}'><tag k='test' v='yes' /></relation></osm>"
- put relation_create_path, :params => xml, :headers => auth_header
+ post api_relations_path, :params => xml, :headers => auth_header
# hope for success
assert_response :success,
"relation upload did not return success status"
xml = "<osm><relation changeset='#{changeset.id}'>" \
"<member ref='#{node.id}' type='node' role='some'/>" \
"<tag k='test' v='yes' /></relation></osm>"
- put relation_create_path, :params => xml, :headers => auth_header
+ post api_relations_path, :params => xml, :headers => auth_header
# hope for success
assert_response :success,
"relation upload did not return success status"
# need a role attribute to be included
xml = "<osm><relation changeset='#{changeset.id}'>" \
"<member ref='#{node.id}' type='node'/><tag k='test' v='yes' /></relation></osm>"
- put relation_create_path, :params => xml, :headers => auth_header
+ post api_relations_path, :params => xml, :headers => auth_header
# hope for success
assert_response :success,
"relation upload did not return success status"
"<member type='node' ref='#{node.id}' role='some'/>" \
"<member type='way' ref='#{way.id}' role='other'/>" \
"<tag k='test' v='yes' /></relation></osm>"
- put relation_create_path, :params => xml, :headers => auth_header
+ post api_relations_path, :params => xml, :headers => auth_header
# hope for success
assert_response :success,
"relation upload did not return success status"
xml = "<osm><relation changeset='#{changeset.id}'>" \
"<member type='node' ref='0'/><tag k='test' v='yes' />" \
"</relation></osm>"
- put relation_create_path, :params => xml, :headers => auth_header
+ post api_relations_path, :params => xml, :headers => auth_header
# expect failure
assert_response :precondition_failed,
"relation upload with invalid node did not return 'precondition failed'"
xml = "<osm><relation changeset='#{changeset.id}'>" \
"<member type='type' ref='#{node.id}' role=''/>" \
"<tag k='tester' v='yep'/></relation></osm>"
- put relation_create_path, :params => xml, :headers => auth_header
+ post api_relations_path, :params => xml, :headers => auth_header
# expect failure
assert_response :bad_request
assert_match(/Cannot parse valid relation from xml string/, @response.body)
OSM
doc = XML::Parser.string(doc_str).parse
- put relation_create_path, :params => doc.to_s, :headers => auth_header
+ post api_relations_path, :params => doc.to_s, :headers => auth_header
assert_response :success, "can't create a relation: #{@response.body}"
relation_id = @response.body.to_i
## First try with the private user
auth_header = bearer_authorization_header private_user
- put relation_create_path, :params => doc.to_s, :headers => auth_header
+ post api_relations_path, :params => doc.to_s, :headers => auth_header
assert_response :forbidden
## Now try with the public user
auth_header = bearer_authorization_header user
- put relation_create_path, :params => doc.to_s, :headers => auth_header
+ post api_relations_path, :params => doc.to_s, :headers => auth_header
assert_response :success, "can't create a relation: #{@response.body}"
relation_id = @response.body.to_i
doc = XML::Parser.string(doc_str).parse
auth_header = bearer_authorization_header user
- put relation_create_path, :params => doc.to_s, :headers => auth_header
+ post api_relations_path, :params => doc.to_s, :headers => auth_header
assert_response :success, "can't create a relation: #{@response.body}"
relation_id = @response.body.to_i
"<member ref='#{node1.id}' type='node' role='some'/>" \
"<member ref='#{node2.id}' type='node' role='some'/>" \
"<tag k='test' v='yes' /></relation></osm>"
- put relation_create_path, :params => xml, :headers => auth_header
+ post api_relations_path, :params => xml, :headers => auth_header
assert_response :success, "relation create did not return success status"
# get the id of the relation we created
"<member ref='#{node1.id}' type='node' role='some'/>" \
"<member ref='#{node2.id}' type='node' role='some'/>" \
"<tag k='test' v='yes' /></relation></osm>"
- put relation_create_path, :params => xml, :headers => auth_header
+ post api_relations_path, :params => xml, :headers => auth_header
assert_response :too_many_requests, "relation create did not hit rate limit"
end
"<member ref='#{node1.id}' type='node' role='some'/>" \
"<member ref='#{node2.id}' type='node' role='some'/>" \
"<tag k='test' v='yes' /></relation></osm>"
- put relation_create_path, :params => xml, :headers => auth_header
+ post api_relations_path, :params => xml, :headers => auth_header
assert_response :success, "relation create did not return success status"
# get the id of the relation we created
"<member ref='#{node1.id}' type='node' role='some'/>" \
"<member ref='#{node2.id}' type='node' role='some'/>" \
"<tag k='test' v='yes' /></relation></osm>"
- put relation_create_path, :params => xml, :headers => auth_header
+ post api_relations_path, :params => xml, :headers => auth_header
assert_response :too_many_requests, "relation create did not hit rate limit"
end
# test all routes which lead to this controller
def test_routes
assert_routing(
- { :path => "/api/0.6/way/create", :method => :put },
+ { :path => "/api/0.6/ways", :method => :get },
+ { :controller => "api/ways", :action => "index" }
+ )
+ assert_routing(
+ { :path => "/api/0.6/ways.json", :method => :get },
+ { :controller => "api/ways", :action => "index", :format => "json" }
+ )
+ assert_routing(
+ { :path => "/api/0.6/ways", :method => :post },
{ :controller => "api/ways", :action => "create" }
)
assert_routing(
{ :path => "/api/0.6/way/1", :method => :delete },
{ :controller => "api/ways", :action => "delete", :id => "1" }
)
- assert_routing(
- { :path => "/api/0.6/ways", :method => :get },
- { :controller => "api/ways", :action => "index" }
- )
- assert_routing(
- { :path => "/api/0.6/ways.json", :method => :get },
- { :controller => "api/ways", :action => "index", :format => "json" }
+
+ assert_recognizes(
+ { :controller => "api/ways", :action => "create" },
+ { :path => "/api/0.6/way/create", :method => :put }
)
end
+ ##
+ # test fetching multiple ways
+ def test_index
+ way1 = create(:way)
+ way2 = create(:way, :deleted)
+ way3 = create(:way)
+ way4 = create(:way)
+
+ # check error when no parameter provided
+ get api_ways_path
+ assert_response :bad_request
+
+ # check error when no parameter value provided
+ get api_ways_path(:ways => "")
+ assert_response :bad_request
+
+ # test a working call
+ get api_ways_path(:ways => "#{way1.id},#{way2.id},#{way3.id},#{way4.id}")
+ assert_response :success
+ assert_select "osm" do
+ assert_select "way", :count => 4
+ assert_select "way[id='#{way1.id}'][visible='true']", :count => 1
+ assert_select "way[id='#{way2.id}'][visible='false']", :count => 1
+ assert_select "way[id='#{way3.id}'][visible='true']", :count => 1
+ assert_select "way[id='#{way4.id}'][visible='true']", :count => 1
+ end
+
+ # test a working call with json format
+ get api_ways_path(:ways => "#{way1.id},#{way2.id},#{way3.id},#{way4.id}", :format => "json")
+
+ js = ActiveSupport::JSON.decode(@response.body)
+ assert_not_nil js
+ assert_equal 4, js["elements"].count
+ assert_equal 4, (js["elements"].count { |a| a["type"] == "way" })
+ assert_equal 1, (js["elements"].count { |a| a["id"] == way1.id && a["visible"].nil? })
+ assert_equal 1, (js["elements"].count { |a| a["id"] == way2.id && a["visible"] == false })
+ assert_equal 1, (js["elements"].count { |a| a["id"] == way3.id && a["visible"].nil? })
+ assert_equal 1, (js["elements"].count { |a| a["id"] == way4.id && a["visible"].nil? })
+
+ # check error when a non-existent way is included
+ get api_ways_path(:ways => "#{way1.id},#{way2.id},#{way3.id},#{way4.id},0")
+ assert_response :not_found
+ end
+
# -------------------------------------
# Test showing ways.
# -------------------------------------
assert_response :gone
end
- ##
- # test fetching multiple ways
- def test_index
- way1 = create(:way)
- way2 = create(:way, :deleted)
- way3 = create(:way)
- way4 = create(:way)
-
- # check error when no parameter provided
- get ways_path
- assert_response :bad_request
-
- # check error when no parameter value provided
- get ways_path(:ways => "")
- assert_response :bad_request
-
- # test a working call
- get ways_path(:ways => "#{way1.id},#{way2.id},#{way3.id},#{way4.id}")
- assert_response :success
- assert_select "osm" do
- assert_select "way", :count => 4
- assert_select "way[id='#{way1.id}'][visible='true']", :count => 1
- assert_select "way[id='#{way2.id}'][visible='false']", :count => 1
- assert_select "way[id='#{way3.id}'][visible='true']", :count => 1
- assert_select "way[id='#{way4.id}'][visible='true']", :count => 1
- end
-
- # test a working call with json format
- get ways_path(:ways => "#{way1.id},#{way2.id},#{way3.id},#{way4.id}", :format => "json")
-
- js = ActiveSupport::JSON.decode(@response.body)
- assert_not_nil js
- assert_equal 4, js["elements"].count
- assert_equal 4, (js["elements"].count { |a| a["type"] == "way" })
- assert_equal 1, (js["elements"].count { |a| a["id"] == way1.id && a["visible"].nil? })
- assert_equal 1, (js["elements"].count { |a| a["id"] == way2.id && a["visible"] == false })
- assert_equal 1, (js["elements"].count { |a| a["id"] == way3.id && a["visible"].nil? })
- assert_equal 1, (js["elements"].count { |a| a["id"] == way4.id && a["visible"].nil? })
-
- # check error when a non-existent way is included
- get ways_path(:ways => "#{way1.id},#{way2.id},#{way3.id},#{way4.id},0")
- assert_response :not_found
- end
-
# -------------------------------------
# Test simple way creation.
# -------------------------------------
xml = "<osm><way changeset='#{changeset_id}'>" \
"<nd ref='#{node1.id}'/><nd ref='#{node2.id}'/>" \
"<tag k='test' v='yes' /></way></osm>"
- put way_create_path, :params => xml, :headers => auth_header
+ post api_ways_path, :params => xml, :headers => auth_header
# hope for failure
assert_response :forbidden,
"way upload did not return forbidden status"
xml = "<osm><way changeset='#{changeset_id}'>" \
"<nd ref='#{node1.id}'/><nd ref='#{node2.id}'/>" \
"<tag k='test' v='yes' /></way></osm>"
- put way_create_path, :params => xml, :headers => auth_header
+ post api_ways_path, :params => xml, :headers => auth_header
# hope for success
assert_response :success,
"way upload did not return success status"
# create a way with non-existing node
xml = "<osm><way changeset='#{private_open_changeset.id}'>" \
"<nd ref='0'/><tag k='test' v='yes' /></way></osm>"
- put way_create_path, :params => xml, :headers => auth_header
+ post api_ways_path, :params => xml, :headers => auth_header
# expect failure
assert_response :forbidden,
"way upload with invalid node using a private user did not return 'forbidden'"
# create a way with no nodes
xml = "<osm><way changeset='#{private_open_changeset.id}'>" \
"<tag k='test' v='yes' /></way></osm>"
- put way_create_path, :params => xml, :headers => auth_header
+ post api_ways_path, :params => xml, :headers => auth_header
# expect failure
assert_response :forbidden,
"way upload with no node using a private userdid not return 'forbidden'"
# create a way inside a closed changeset
xml = "<osm><way changeset='#{private_closed_changeset.id}'>" \
"<nd ref='#{node.id}'/></way></osm>"
- put way_create_path, :params => xml, :headers => auth_header
+ post api_ways_path, :params => xml, :headers => auth_header
# expect failure
assert_response :forbidden,
"way upload to closed changeset with a private user did not return 'forbidden'"
# create a way with non-existing node
xml = "<osm><way changeset='#{open_changeset.id}'>" \
"<nd ref='0'/><tag k='test' v='yes' /></way></osm>"
- put way_create_path, :params => xml, :headers => auth_header
+ post api_ways_path, :params => xml, :headers => auth_header
# expect failure
assert_response :precondition_failed,
"way upload with invalid node did not return 'precondition failed'"
# create a way with no nodes
xml = "<osm><way changeset='#{open_changeset.id}'>" \
"<tag k='test' v='yes' /></way></osm>"
- put way_create_path, :params => xml, :headers => auth_header
+ post api_ways_path, :params => xml, :headers => auth_header
# expect failure
assert_response :precondition_failed,
"way upload with no node did not return 'precondition failed'"
# create a way inside a closed changeset
xml = "<osm><way changeset='#{closed_changeset.id}'>" \
"<nd ref='#{node.id}'/></way></osm>"
- put way_create_path, :params => xml, :headers => auth_header
+ post api_ways_path, :params => xml, :headers => auth_header
# expect failure
assert_response :conflict,
"way upload to closed changeset did not return 'conflict'"
"<nd ref='#{node.id}'/>" \
"<tag k='foo' v='#{'x' * 256}'/>" \
"</way></osm>"
- put way_create_path, :params => xml, :headers => auth_header
+ post api_ways_path, :params => xml, :headers => auth_header
# expect failure
assert_response :bad_request,
"way upload to with too long tag did not return 'bad_request'"
way_str << "</way></osm>"
# try and upload it
- put way_create_path, :params => way_str, :headers => auth_header
+ post api_ways_path, :params => way_str, :headers => auth_header
assert_response :forbidden,
"adding new duplicate tags to a way with a non-public user should fail with 'forbidden'"
way_str << "</way></osm>"
# try and upload it
- put way_create_path, :params => way_str, :headers => auth_header
+ post api_ways_path, :params => way_str, :headers => auth_header
assert_response :bad_request,
"adding new duplicate tags to a way should fail with 'bad request'"
assert_equal "Element way/ has duplicate tags with key addr:housenumber", @response.body
xml = "<osm><way changeset='#{changeset.id}'>" \
"<nd ref='#{node1.id}'/><nd ref='#{node2.id}'/>" \
"<tag k='test' v='yes' /></way></osm>"
- put way_create_path, :params => xml, :headers => auth_header
+ post api_ways_path, :params => xml, :headers => auth_header
assert_response :success, "way create did not return success status"
# get the id of the way we created
xml = "<osm><way changeset='#{changeset.id}'>" \
"<nd ref='#{node1.id}'/><nd ref='#{node2.id}'/>" \
"<tag k='test' v='yes' /></way></osm>"
- put way_create_path, :params => xml, :headers => auth_header
+ post api_ways_path, :params => xml, :headers => auth_header
assert_response :too_many_requests, "way create did not hit rate limit"
end
xml = "<osm><way changeset='#{changeset.id}'>" \
"<nd ref='#{node1.id}'/><nd ref='#{node2.id}'/>" \
"<tag k='test' v='yes' /></way></osm>"
- put way_create_path, :params => xml, :headers => auth_header
+ post api_ways_path, :params => xml, :headers => auth_header
assert_response :success, "way create did not return success status"
# get the id of the way we created
xml = "<osm><way changeset='#{changeset.id}'>" \
"<nd ref='#{node1.id}'/><nd ref='#{node2.id}'/>" \
"<tag k='test' v='yes' /></way></osm>"
- put way_create_path, :params => xml, :headers => auth_header
+ post api_ways_path, :params => xml, :headers => auth_header
assert_response :too_many_requests, "way create did not hit rate limit"
end