X-Git-Url: https://git.openstreetmap.org./rails.git/blobdiff_plain/dd302f4f2c56d1e9f1a2e39a54670f6f5a9bbd34..4543e85441b758edaf7b4a8f7ed589ca428a9be7:/test/controllers/relations_controller_test.rb?ds=sidebyside diff --git a/test/controllers/relations_controller_test.rb b/test/controllers/relations_controller_test.rb index 224caa642..a8b0ed2df 100644 --- a/test/controllers/relations_controller_test.rb +++ b/test/controllers/relations_controller_test.rb @@ -14,7 +14,7 @@ class RelationsControllerTest < ActionController::TestCase ) assert_routing( { :path => "/api/0.6/relation/1", :method => :get }, - { :controller => "relations", :action => "read", :id => "1" } + { :controller => "relations", :action => "show", :id => "1" } ) assert_routing( { :path => "/api/0.6/relation/1", :method => :put }, @@ -26,7 +26,7 @@ class RelationsControllerTest < ActionController::TestCase ) assert_routing( { :path => "/api/0.6/relations", :method => :get }, - { :controller => "relations", :action => "relations" } + { :controller => "relations", :action => "index" } ) assert_routing( @@ -44,20 +44,20 @@ class RelationsControllerTest < ActionController::TestCase end # ------------------------------------- - # Test reading relations. + # Test showing relations. # ------------------------------------- - def test_read + def test_show # check that a visible relation is returned properly - get :read, :params => { :id => create(:relation).id } + get :show, :params => { :id => create(:relation).id } assert_response :success # check that an invisible relation is not returned - get :read, :params => { :id => create(:relation, :deleted).id } + get :show, :params => { :id => create(:relation, :deleted).id } assert_response :gone # check chat a non-existent relation is not returned - get :read, :params => { :id => 0 } + get :show, :params => { :id => 0 } assert_response :not_found end @@ -160,7 +160,7 @@ class RelationsControllerTest < ActionController::TestCase ## # test fetching multiple relations - def test_relations + def test_index relation1 = create(:relation) relation2 = create(:relation, :deleted) relation3 = create(:relation, :with_history, :version => 2) @@ -168,15 +168,15 @@ class RelationsControllerTest < ActionController::TestCase relation4.old_relations.find_by(:version => 1).redact!(create(:redaction)) # check error when no parameter provided - get :relations + get :index assert_response :bad_request # check error when no parameter value provided - get :relations, :params => { :relations => "" } + get :index, :params => { :relations => "" } assert_response :bad_request # test a working call - get :relations, :params => { :relations => "#{relation1.id},#{relation2.id},#{relation3.id},#{relation4.id}" } + get :index, :params => { :relations => "#{relation1.id},#{relation2.id},#{relation3.id},#{relation4.id}" } assert_response :success assert_select "osm" do assert_select "relation", :count => 4 @@ -187,7 +187,7 @@ class RelationsControllerTest < ActionController::TestCase end # check error when a non-existent relation is included - get :relations, :params => { :relations => "#{relation1.id},#{relation2.id},#{relation3.id},#{relation4.id},0" } + get :index, :params => { :relations => "#{relation1.id},#{relation2.id},#{relation3.id},#{relation4.id},0" } assert_response :not_found end @@ -206,8 +206,8 @@ class RelationsControllerTest < ActionController::TestCase basic_authorization private_user.email, "test" # create an relation without members - content "" - put :create + xml = "" + put :create, :body => xml # hope for forbidden, due to user assert_response :forbidden, "relation upload should have failed with forbidden" @@ -215,10 +215,10 @@ class RelationsControllerTest < ActionController::TestCase ### # create an relation with a node as member # This time try with a role attribute in the relation - content "" \ - "" \ - "" - put :create + xml = "" \ + "" \ + "" + put :create, :body => xml # hope for forbidden due to user assert_response :forbidden, "relation upload did not return forbidden status" @@ -226,20 +226,20 @@ class RelationsControllerTest < ActionController::TestCase ### # create an relation with a node as member, this time test that we don't # need a role attribute to be included - content "" \ - "" + "" - put :create + xml = "" \ + "" + "" + put :create, :body => xml # hope for forbidden due to user assert_response :forbidden, "relation upload did not return forbidden status" ### # create an relation with a way and a node as members - content "" \ - "" \ - "" \ - "" - put :create + xml = "" \ + "" \ + "" \ + "" + put :create, :body => xml # hope for forbidden, due to user assert_response :forbidden, "relation upload did not return success status" @@ -248,8 +248,8 @@ class RelationsControllerTest < ActionController::TestCase basic_authorization user.email, "test" # create an relation without members - content "" - put :create + xml = "" + put :create, :body => xml # hope for success assert_response :success, "relation upload did not return success status" @@ -270,16 +270,16 @@ class RelationsControllerTest < ActionController::TestCase assert_equal true, checkrelation.visible, "saved relation is not visible" # ok the relation is there but can we also retrieve it? - get :read, :params => { :id => relationid } + get :show, :params => { :id => relationid } assert_response :success ### # create an relation with a node as member # This time try with a role attribute in the relation - content "" \ - "" \ - "" - put :create + xml = "" \ + "" \ + "" + put :create, :body => xml # hope for success assert_response :success, "relation upload did not return success status" @@ -301,15 +301,15 @@ class RelationsControllerTest < ActionController::TestCase "saved relation is not visible" # ok the relation is there but can we also retrieve it? - get :read, :params => { :id => relationid } + get :show, :params => { :id => relationid } assert_response :success ### # create an relation with a node as member, this time test that we don't # need a role attribute to be included - content "" \ - "" + "" - put :create + xml = "" \ + "" + "" + put :create, :body => xml # hope for success assert_response :success, "relation upload did not return success status" @@ -331,16 +331,16 @@ class RelationsControllerTest < ActionController::TestCase "saved relation is not visible" # ok the relation is there but can we also retrieve it? - get :read, :params => { :id => relationid } + get :show, :params => { :id => relationid } assert_response :success ### # create an relation with a way and a node as members - content "" \ - "" \ - "" \ - "" - put :create + xml = "" \ + "" \ + "" \ + "" + put :create, :body => xml # hope for success assert_response :success, "relation upload did not return success status" @@ -361,7 +361,7 @@ class RelationsControllerTest < ActionController::TestCase assert_equal true, checkrelation.visible, "saved relation is not visible" # ok the relation is there but can we also retrieve it? - get :read, :params => { :id => relationid } + get :show, :params => { :id => relationid } assert_response :success end @@ -443,8 +443,7 @@ class RelationsControllerTest < ActionController::TestCase basic_authorization user.email, "test" with_relation(relation.id) do |rel| update_changeset(rel, changeset.id) - content rel - put :update, :params => { :id => other_relation.id } + put :update, :params => { :id => other_relation.id }, :body => rel.to_s assert_response :bad_request end end @@ -460,10 +459,10 @@ class RelationsControllerTest < ActionController::TestCase basic_authorization user.email, "test" # create a relation with non-existing node as member - content "" \ - "" \ - "" - put :create + xml = "" \ + "" \ + "" + put :create, :body => xml # expect failure assert_response :precondition_failed, "relation upload with invalid node did not return 'precondition failed'" @@ -481,10 +480,10 @@ class RelationsControllerTest < ActionController::TestCase basic_authorization user.email, "test" # create some xml that should return an error - content "" \ - "" \ - "" - put :create + xml = "" \ + "" \ + "" + put :create, :body => xml # expect failure assert_response :bad_request assert_match(/Cannot parse valid relation from xml string/, @response.body) @@ -520,34 +519,34 @@ class RelationsControllerTest < ActionController::TestCase assert_response :forbidden # try to delete without specifying a changeset - content "" - delete :delete, :params => { :id => relation.id } + xml = "" + delete :delete, :params => { :id => relation.id }, :body => xml.to_s assert_response :forbidden # try to delete with an invalid (closed) changeset - content update_changeset(relation.to_xml, - private_user_closed_changeset.id) - delete :delete, :params => { :id => relation.id } + xml = update_changeset(relation.to_xml, + private_user_closed_changeset.id) + delete :delete, :params => { :id => relation.id }, :body => xml.to_s assert_response :forbidden # try to delete with an invalid (non-existent) changeset - content update_changeset(relation.to_xml, 0) - delete :delete, :params => { :id => relation.id } + xml = update_changeset(relation.to_xml, 0) + delete :delete, :params => { :id => relation.id }, :body => xml.to_s assert_response :forbidden # this won't work because the relation is in-use by another relation - content(used_relation.to_xml) - delete :delete, :params => { :id => used_relation.id } + xml = used_relation.to_xml + delete :delete, :params => { :id => used_relation.id }, :body => xml.to_s assert_response :forbidden # this should work when we provide the appropriate payload... - content(relation.to_xml) - delete :delete, :params => { :id => relation.id } + xml = relation.to_xml + delete :delete, :params => { :id => relation.id }, :body => xml.to_s assert_response :forbidden # this won't work since the relation is already deleted - content(deleted_relation.to_xml) - delete :delete, :params => { :id => deleted_relation.id } + xml = deleted_relation.to_xml + delete :delete, :params => { :id => deleted_relation.id }, :body => xml.to_s assert_response :forbidden # this won't work since the relation never existed @@ -562,43 +561,43 @@ class RelationsControllerTest < ActionController::TestCase assert_response :bad_request # try to delete without specifying a changeset - content "" - delete :delete, :params => { :id => relation.id } + xml = "" + delete :delete, :params => { :id => relation.id }, :body => xml.to_s assert_response :bad_request assert_match(/Changeset id is missing/, @response.body) # try to delete with an invalid (closed) changeset - content update_changeset(relation.to_xml, - closed_changeset.id) - delete :delete, :params => { :id => relation.id } + xml = update_changeset(relation.to_xml, + closed_changeset.id) + delete :delete, :params => { :id => relation.id }, :body => xml.to_s assert_response :conflict # try to delete with an invalid (non-existent) changeset - content update_changeset(relation.to_xml, 0) - delete :delete, :params => { :id => relation.id } + xml = update_changeset(relation.to_xml, 0) + delete :delete, :params => { :id => relation.id }, :body => xml.to_s assert_response :conflict # this won't work because the relation is in a changeset owned by someone else - content update_changeset(relation.to_xml, create(:changeset).id) - delete :delete, :params => { :id => relation.id } + xml = update_changeset(relation.to_xml, create(:changeset).id) + delete :delete, :params => { :id => relation.id }, :body => xml.to_s assert_response :conflict, "shouldn't be able to delete a relation in a changeset owned by someone else (#{@response.body})" # this won't work because the relation in the payload is different to that passed - content update_changeset(relation.to_xml, changeset.id) - delete :delete, :params => { :id => create(:relation).id } + xml = update_changeset(relation.to_xml, changeset.id) + delete :delete, :params => { :id => create(:relation).id }, :body => xml.to_s assert_response :bad_request, "shouldn't be able to delete a relation when payload is different to the url" # this won't work because the relation is in-use by another relation - content update_changeset(used_relation.to_xml, changeset.id) - delete :delete, :params => { :id => used_relation.id } + xml = update_changeset(used_relation.to_xml, changeset.id) + delete :delete, :params => { :id => used_relation.id }, :body => xml.to_s assert_response :precondition_failed, "shouldn't be able to delete a relation used in a relation (#{@response.body})" assert_equal "Precondition failed: The relation #{used_relation.id} is used in relation #{super_relation.id}.", @response.body # this should work when we provide the appropriate payload... - content update_changeset(multi_tag_relation.to_xml, changeset.id) - delete :delete, :params => { :id => multi_tag_relation.id } + xml = update_changeset(multi_tag_relation.to_xml, changeset.id) + delete :delete, :params => { :id => multi_tag_relation.id }, :body => xml.to_s assert_response :success # valid delete should return the new version number, which should @@ -607,19 +606,19 @@ class RelationsControllerTest < ActionController::TestCase "delete request should return a new version number for relation" # this won't work since the relation is already deleted - content update_changeset(deleted_relation.to_xml, changeset.id) - delete :delete, :params => { :id => deleted_relation.id } + xml = update_changeset(deleted_relation.to_xml, changeset.id) + delete :delete, :params => { :id => deleted_relation.id }, :body => xml.to_s assert_response :gone # Public visible relation needs to be deleted - content update_changeset(super_relation.to_xml, changeset.id) - delete :delete, :params => { :id => super_relation.id } + xml = update_changeset(super_relation.to_xml, changeset.id) + delete :delete, :params => { :id => super_relation.id }, :body => xml.to_s assert_response :success # this works now because the relation which was using this one # has been deleted. - content update_changeset(used_relation.to_xml, changeset.id) - delete :delete, :params => { :id => used_relation.id } + xml = update_changeset(used_relation.to_xml, changeset.id) + delete :delete, :params => { :id => used_relation.id }, :body => xml.to_s assert_response :success, "should be able to delete a relation used in an old relation (#{@response.body})" @@ -654,8 +653,7 @@ class RelationsControllerTest < ActionController::TestCase update_changeset(relation_xml, changeset_id) # upload the change - content relation_xml - put :update, :params => { :id => relation.id } + put :update, :params => { :id => relation.id }, :body => relation_xml.to_s assert_response :success, "can't update relation for tag/bbox test" end end @@ -688,12 +686,11 @@ class RelationsControllerTest < ActionController::TestCase update_changeset(relation_xml, changeset_id) # upload the change - content relation_xml - put :update, :params => { :id => relation.id } + put :update, :params => { :id => relation.id }, :body => relation_xml.to_s assert_response :success, "can't update relation for add #{element.class}/bbox test: #{@response.body}" # get it back and check the ordering - get :read, :params => { :id => relation.id } + get :show, :params => { :id => relation.id } assert_response :success, "can't read back the relation: #{@response.body}" check_ordering(relation_xml, @response.body) end @@ -721,8 +718,7 @@ class RelationsControllerTest < ActionController::TestCase update_changeset(relation_xml, changeset_id) # upload the change - content relation_xml - put :update, :params => { :id => relation.id } + put :update, :params => { :id => relation.id }, :body => relation_xml.to_s assert_response :success, "can't update relation for remove node/bbox test" end end @@ -752,13 +748,12 @@ class RelationsControllerTest < ActionController::TestCase OSM doc = XML::Parser.string(doc_str).parse - content doc - put :create + put :create, :body => doc.to_s assert_response :success, "can't create a relation: #{@response.body}" relation_id = @response.body.to_i # get it back and check the ordering - get :read, :params => { :id => relation_id } + get :show, :params => { :id => relation_id } assert_response :success, "can't read back the relation: #{@response.body}" check_ordering(doc, @response.body) @@ -773,13 +768,12 @@ OSM doc.find("//osm/relation").first["version"] = 1.to_s # upload the next version of the relation - content doc - put :update, :params => { :id => relation_id } + put :update, :params => { :id => relation_id }, :body => doc.to_s assert_response :success, "can't update relation: #{@response.body}" assert_equal 2, @response.body.to_i # get it back again and check the ordering again - get :read, :params => { :id => relation_id } + get :show, :params => { :id => relation_id } assert_response :success, "can't read back the relation: #{@response.body}" check_ordering(doc, @response.body) @@ -815,20 +809,18 @@ OSM ## First try with the private user basic_authorization private_user.email, "test" - content doc - put :create + put :create, :body => doc.to_s assert_response :forbidden ## Now try with the public user basic_authorization user.email, "test" - content doc - put :create + put :create, :body => doc.to_s assert_response :success, "can't create a relation: #{@response.body}" relation_id = @response.body.to_i # get it back and check the ordering - get :read, :params => { :id => relation_id } + get :show, :params => { :id => relation_id } assert_response :success, "can't read back the relation: #{relation_id}" check_ordering(doc, @response.body) end @@ -856,13 +848,12 @@ OSM doc = XML::Parser.string(doc_str).parse basic_authorization user.email, "test" - content doc - put :create + put :create, :body => doc.to_s assert_response :success, "can't create a relation: #{@response.body}" relation_id = @response.body.to_i # check the ordering in the current tables: - get :read, :params => { :id => relation_id } + get :show, :params => { :id => relation_id } assert_response :success, "can't read back the relation: #{@response.body}" check_ordering(doc, @response.body) @@ -896,8 +887,7 @@ OSM update_changeset(relation_xml, changeset_id) # upload the change - content relation_xml - put :update, :params => { :id => relation.id } + put :update, :params => { :id => relation.id }, :body => relation_xml.to_s assert_response :success, "can't update relation for remove all members test" checkrelation = Relation.find(relation.id) assert_not_nil(checkrelation, @@ -940,8 +930,8 @@ OSM # create a new changeset for this operation, so we are assured # that the bounding box will be newly-generated. changeset_id = with_controller(ChangesetsController.new) do - content "" - put :create + xml = "" + put :create, :body => xml assert_response :forbidden, "shouldn't be able to create changeset for modify test, as should get forbidden" end @@ -951,8 +941,8 @@ OSM # create a new changeset for this operation, so we are assured # that the bounding box will be newly-generated. changeset_id = with_controller(ChangesetsController.new) do - content "" - put :create + xml = "" + put :create, :body => xml assert_response :success, "couldn't create changeset for modify test" @response.body.to_i end @@ -962,7 +952,7 @@ OSM # now download the changeset to check its bounding box with_controller(ChangesetsController.new) do - get :read, :params => { :id => changeset_id } + get :show, :params => { :id => changeset_id } 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}" @@ -979,7 +969,7 @@ OSM # doc is returned. def with_relation(id, ver = nil) if ver.nil? - get :read, :params => { :id => id } + get :show, :params => { :id => id } else with_controller(OldRelationsController.new) do get :version, :params => { :id => id, :version => ver } @@ -995,13 +985,12 @@ OSM # the parsed XML doc is retured. def with_update(rel) rel_id = rel.find("//osm/relation").first["id"].to_i - content rel - put :update, :params => { :id => rel_id } + put :update, :params => { :id => rel_id }, :body => rel.to_s assert_response :success, "can't update relation: #{@response.body}" version = @response.body.to_i # now get the new version - get :read, :params => { :id => rel_id } + get :show, :params => { :id => rel_id } assert_response :success new_rel = xml_parse(@response.body) @@ -1027,14 +1016,13 @@ OSM change << modify modify << doc.import(rel.find("//osm/relation").first) - content doc.to_s - post :upload, :params => { :id => cs_id } + post :upload, :params => { :id => cs_id }, :body => doc.to_s assert_response :success, "can't upload diff relation: #{@response.body}" version = xml_parse(@response.body).find("//diffResult/relation").first["new_version"].to_i end # now get the new version - get :read, :params => { :id => rel_id } + get :show, :params => { :id => rel_id } assert_response :success new_rel = xml_parse(@response.body)