diff --git a/config/routes.rb b/config/routes.rb
index 19dfc9a77..2ba9bdb93 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -30,7 +30,6 @@ OpenStreetMap::Application.routes.draw do
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+/
@@ -39,9 +38,7 @@ OpenStreetMap::Application.routes.draw do
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+/
@@ -50,9 +47,7 @@ OpenStreetMap::Application.routes.draw do
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+/
@@ -61,10 +56,18 @@ OpenStreetMap::Application.routes.draw do
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
diff --git a/test/controllers/api/changesets_controller_test.rb b/test/controllers/api/changesets_controller_test.rb
index 5c0e7c9c2..39b1f3cf8 100644
--- a/test/controllers/api/changesets_controller_test.rb
+++ b/test/controllers/api/changesets_controller_test.rb
@@ -2130,7 +2130,7 @@ module Api
# add a single node to it
with_controller(NodesController.new) do
xml = ""
- 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
@@ -2145,7 +2145,7 @@ module Api
# add another node to it
with_controller(NodesController.new) do
xml = ""
- 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
@@ -2515,7 +2515,7 @@ module Api
with_controller(NodesController.new) do
# create a new node
xml = ""
- 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
diff --git a/test/controllers/api/nodes_controller_test.rb b/test/controllers/api/nodes_controller_test.rb
index 9896c34a5..04120dace 100644
--- a/test/controllers/api/nodes_controller_test.rb
+++ b/test/controllers/api/nodes_controller_test.rb
@@ -6,7 +6,15 @@ module Api
# 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(
@@ -25,16 +33,60 @@ module Api
{ :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)
@@ -49,7 +101,7 @@ module Api
# create a minimal xml file
xml = ""
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"
@@ -60,7 +112,7 @@ module Api
# create a minimal xml file
xml = ""
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"
@@ -70,7 +122,7 @@ module Api
# create a minimal xml file
xml = ""
- 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"
@@ -98,14 +150,14 @@ module Api
# test that the upload is rejected when xml is valid, but osm doc isn't
xml = ""
- 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 . 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 = ""
- 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 . lat missing", @response.body
@@ -113,7 +165,7 @@ module Api
# test that the upload is rejected when no lon is supplied
# create a minimal xml file
xml = ""
- 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 . lon missing", @response.body
@@ -121,7 +173,7 @@ module Api
# test that the upload is rejected when lat is non-numeric
# create a minimal xml file
xml = ""
- 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 . lat not a number", @response.body
@@ -129,14 +181,14 @@ module Api
# test that the upload is rejected when lon is non-numeric
# create a minimal xml file
xml = ""
- 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 . lon not a number", @response.body
# test that the upload is rejected when we have a tag which is too long
xml = ""
- 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
@@ -424,53 +476,6 @@ module Api
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
@@ -510,7 +515,7 @@ module Api
xml = "" \
"" \
""
- 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
@@ -521,7 +526,7 @@ module Api
xml = "" \
"" \
""
- put node_create_path, :params => xml, :headers => auth_header
+ post api_nodes_path, :params => xml, :headers => auth_header
assert_response :success
nodeid = @response.body
@@ -556,7 +561,7 @@ module Api
# try creating a node
xml = ""
- 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
@@ -574,7 +579,7 @@ module Api
# try creating a node, which should be rate limited
xml = ""
- 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
@@ -603,7 +608,7 @@ module Api
# try creating a node
xml = ""
- 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
@@ -621,7 +626,7 @@ module Api
# try creating a node, which should be rate limited
xml = ""
- 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
diff --git a/test/controllers/api/relations_controller_test.rb b/test/controllers/api/relations_controller_test.rb
index 5fb62d29f..5147d851f 100644
--- a/test/controllers/api/relations_controller_test.rb
+++ b/test/controllers/api/relations_controller_test.rb
@@ -6,7 +6,15 @@ module Api
# 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(
@@ -33,14 +41,6 @@ module Api
{ :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 },
@@ -66,6 +66,56 @@ module Api
{ :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
# -------------------------------------
@@ -164,51 +214,6 @@ module Api
# 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.
# -------------------------------------
@@ -225,7 +230,7 @@ module Api
# create an relation without members
xml = ""
- 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"
@@ -236,7 +241,7 @@ module Api
xml = "" \
"" \
""
- 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"
@@ -246,7 +251,7 @@ module Api
# need a role attribute to be included
xml = "" \
""
- 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"
@@ -257,7 +262,7 @@ module Api
"" \
"" \
""
- 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"
@@ -267,7 +272,7 @@ module Api
# create an relation without members
xml = ""
- 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"
@@ -295,7 +300,7 @@ module Api
xml = "" \
"" \
""
- 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"
@@ -323,7 +328,7 @@ module Api
# need a role attribute to be included
xml = "" \
""
- 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"
@@ -352,7 +357,7 @@ module Api
"" \
"" \
""
- 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"
@@ -472,7 +477,7 @@ module Api
xml = "" \
"" \
""
- 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'"
@@ -493,7 +498,7 @@ module Api
xml = "" \
"" \
""
- 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)
@@ -757,7 +762,7 @@ module Api
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
@@ -818,13 +823,13 @@ module Api
## 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
@@ -857,7 +862,7 @@ module Api
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
@@ -929,7 +934,7 @@ module Api
"" \
"" \
""
- 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
@@ -953,7 +958,7 @@ module Api
"" \
"" \
""
- 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
@@ -989,7 +994,7 @@ module Api
"" \
"" \
""
- 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
@@ -1013,7 +1018,7 @@ module Api
"" \
"" \
""
- 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
diff --git a/test/controllers/api/ways_controller_test.rb b/test/controllers/api/ways_controller_test.rb
index 6aa4bdfa5..e81b49b81 100644
--- a/test/controllers/api/ways_controller_test.rb
+++ b/test/controllers/api/ways_controller_test.rb
@@ -6,7 +6,15 @@ module Api
# 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(
@@ -33,16 +41,57 @@ module Api
{ :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.
# -------------------------------------
@@ -89,50 +138,6 @@ module Api
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.
# -------------------------------------
@@ -155,7 +160,7 @@ module Api
xml = "" \
"" \
""
- 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"
@@ -170,7 +175,7 @@ module Api
xml = "" \
"" \
""
- 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"
@@ -213,7 +218,7 @@ module Api
# create a way with non-existing node
xml = "" \
""
- 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'"
@@ -221,7 +226,7 @@ module Api
# create a way with no nodes
xml = "" \
""
- 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'"
@@ -229,7 +234,7 @@ module Api
# create a way inside a closed changeset
xml = "" \
""
- 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'"
@@ -241,7 +246,7 @@ module Api
# create a way with non-existing node
xml = "" \
""
- 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'"
@@ -250,7 +255,7 @@ module Api
# create a way with no nodes
xml = "" \
""
- 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'"
@@ -259,7 +264,7 @@ module Api
# create a way inside a closed changeset
xml = "" \
""
- 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'"
@@ -269,7 +274,7 @@ module Api
"" \
"" \
""
- 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'"
@@ -696,7 +701,7 @@ module Api
way_str << ""
# 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'"
@@ -711,7 +716,7 @@ module Api
way_str << ""
# 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
@@ -775,7 +780,7 @@ module Api
xml = "" \
"" \
""
- 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
@@ -797,7 +802,7 @@ module Api
xml = "" \
"" \
""
- 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
@@ -832,7 +837,7 @@ module Api
xml = "" \
"" \
""
- 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
@@ -854,7 +859,7 @@ module Api
xml = "" \
"" \
""
- 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