)
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 },
)
assert_routing(
{ :path => "/api/0.6/relations", :method => :get },
- { :controller => "relations", :action => "relations" }
+ { :controller => "relations", :action => "index" }
)
assert_routing(
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
##
# test fetching multiple relations
- def test_relations
+ def test_index
relation1 = create(:relation)
relation2 = create(:relation, :deleted)
relation3 = create(:relation, :with_history, :version => 2)
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
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
basic_authorization private_user.email, "test"
# create an relation without members
- content "<osm><relation changeset='#{private_changeset.id}'><tag k='test' v='yes' /></relation></osm>"
- put :create
+ xml = "<osm><relation changeset='#{private_changeset.id}'><tag k='test' v='yes' /></relation></osm>"
+ put :create, :body => xml
# hope for forbidden, due to user
assert_response :forbidden,
"relation upload should have failed with forbidden"
###
# create an relation with a node as member
# This time try with a role attribute in the relation
- content "<osm><relation changeset='#{private_changeset.id}'>" \
- "<member ref='#{node.id}' type='node' role='some'/>" \
- "<tag k='test' v='yes' /></relation></osm>"
- put :create
+ xml = "<osm><relation changeset='#{private_changeset.id}'>" \
+ "<member ref='#{node.id}' type='node' role='some'/>" \
+ "<tag k='test' v='yes' /></relation></osm>"
+ 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 node as member, this time test that we don't
# need a role attribute to be included
- content "<osm><relation changeset='#{private_changeset.id}'>" \
- "<member ref='#{node.id}' type='node'/>" + "<tag k='test' v='yes' /></relation></osm>"
- put :create
+ xml = "<osm><relation changeset='#{private_changeset.id}'>" \
+ "<member ref='#{node.id}' type='node'/>" + "<tag k='test' v='yes' /></relation></osm>"
+ 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 "<osm><relation changeset='#{private_changeset.id}'>" \
- "<member type='node' ref='#{node.id}' role='some'/>" \
- "<member type='way' ref='#{way.id}' role='other'/>" \
- "<tag k='test' v='yes' /></relation></osm>"
- put :create
+ xml = "<osm><relation changeset='#{private_changeset.id}'>" \
+ "<member type='node' ref='#{node.id}' role='some'/>" \
+ "<member type='way' ref='#{way.id}' role='other'/>" \
+ "<tag k='test' v='yes' /></relation></osm>"
+ put :create, :body => xml
# hope for forbidden, due to user
assert_response :forbidden,
"relation upload did not return success status"
basic_authorization user.email, "test"
# create an relation without members
- content "<osm><relation changeset='#{changeset.id}'><tag k='test' v='yes' /></relation></osm>"
- put :create
+ xml = "<osm><relation changeset='#{changeset.id}'><tag k='test' v='yes' /></relation></osm>"
+ put :create, :body => xml
# hope for success
assert_response :success,
"relation upload did not return success status"
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 "<osm><relation changeset='#{changeset.id}'>" \
- "<member ref='#{node.id}' type='node' role='some'/>" \
- "<tag k='test' v='yes' /></relation></osm>"
- put :create
+ xml = "<osm><relation changeset='#{changeset.id}'>" \
+ "<member ref='#{node.id}' type='node' role='some'/>" \
+ "<tag k='test' v='yes' /></relation></osm>"
+ put :create, :body => xml
# hope for success
assert_response :success,
"relation upload did not return success status"
"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 "<osm><relation changeset='#{changeset.id}'>" \
- "<member ref='#{node.id}' type='node'/>" + "<tag k='test' v='yes' /></relation></osm>"
- put :create
+ xml = "<osm><relation changeset='#{changeset.id}'>" \
+ "<member ref='#{node.id}' type='node'/>" + "<tag k='test' v='yes' /></relation></osm>"
+ put :create, :body => xml
# hope for success
assert_response :success,
"relation upload did not return success status"
"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 "<osm><relation changeset='#{changeset.id}'>" \
- "<member type='node' ref='#{node.id}' role='some'/>" \
- "<member type='way' ref='#{way.id}' role='other'/>" \
- "<tag k='test' v='yes' /></relation></osm>"
- put :create
+ xml = "<osm><relation changeset='#{changeset.id}'>" \
+ "<member type='node' ref='#{node.id}' role='some'/>" \
+ "<member type='way' ref='#{way.id}' role='other'/>" \
+ "<tag k='test' v='yes' /></relation></osm>"
+ put :create, :body => xml
# hope for success
assert_response :success,
"relation upload did not return success status"
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
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
basic_authorization user.email, "test"
# create a relation with non-existing node as member
- content "<osm><relation changeset='#{changeset.id}'>" \
- "<member type='node' ref='0'/><tag k='test' v='yes' />" \
- "</relation></osm>"
- put :create
+ xml = "<osm><relation changeset='#{changeset.id}'>" \
+ "<member type='node' ref='0'/><tag k='test' v='yes' />" \
+ "</relation></osm>"
+ put :create, :body => xml
# expect failure
assert_response :precondition_failed,
"relation upload with invalid node did not return 'precondition failed'"
basic_authorization user.email, "test"
# create some xml that should return an error
- content "<osm><relation changeset='#{changeset.id}'>" \
- "<member type='type' ref='#{node.id}' role=''/>" \
- "<tag k='tester' v='yep'/></relation></osm>"
- put :create
+ xml = "<osm><relation changeset='#{changeset.id}'>" \
+ "<member type='type' ref='#{node.id}' role=''/>" \
+ "<tag k='tester' v='yep'/></relation></osm>"
+ put :create, :body => xml
# expect failure
assert_response :bad_request
assert_match(/Cannot parse valid relation from xml string/, @response.body)
assert_response :forbidden
# try to delete without specifying a changeset
- content "<osm><relation id='#{relation.id}'/></osm>"
- delete :delete, :params => { :id => relation.id }
+ xml = "<osm><relation id='#{relation.id}'/></osm>"
+ 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
assert_response :bad_request
# try to delete without specifying a changeset
- content "<osm><relation id='#{relation.id}' version='#{relation.version}' /></osm>"
- delete :delete, :params => { :id => relation.id }
+ xml = "<osm><relation id='#{relation.id}' version='#{relation.version}' /></osm>"
+ 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
"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})"
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
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
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
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)
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)
# check the ordering in the history tables:
- with_controller(OldRelationController.new) do
+ with_controller(OldRelationsController.new) do
get :version, :params => { :id => relation_id, :version => 2 }
assert_response :success, "can't read back version 2 of the relation #{relation_id}"
check_ordering(doc, @response.body)
## 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
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)
# check the ordering in the history tables:
- with_controller(OldRelationController.new) do
+ with_controller(OldRelationsController.new) do
get :version, :params => { :id => relation_id, :version => 1 }
assert_response :success, "can't read back version 1 of the relation: #{@response.body}"
check_ordering(doc, @response.body)
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,
# create a new changeset for this operation, so we are assured
# that the bounding box will be newly-generated.
- changeset_id = with_controller(ChangesetController.new) do
- content "<osm><changeset/></osm>"
- put :create
+ changeset_id = with_controller(ChangesetsController.new) do
+ xml = "<osm><changeset/></osm>"
+ put :create, :body => xml
assert_response :forbidden, "shouldn't be able to create changeset for modify test, as should get forbidden"
end
# create a new changeset for this operation, so we are assured
# that the bounding box will be newly-generated.
- changeset_id = with_controller(ChangesetController.new) do
- content "<osm><changeset/></osm>"
- put :create
+ changeset_id = with_controller(ChangesetsController.new) do
+ xml = "<osm><changeset/></osm>"
+ put :create, :body => xml
assert_response :success, "couldn't create changeset for modify test"
@response.body.to_i
end
yield changeset_id
# now download the changeset to check its bounding box
- with_controller(ChangesetController.new) do
- get :read, :params => { :id => changeset_id }
+ with_controller(ChangesetsController.new) do
+ 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}"
# 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(OldRelationController.new) do
+ with_controller(OldRelationsController.new) do
get :version, :params => { :id => id, :version => ver }
end
end
# 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)
cs_id = rel.find("//osm/relation").first["changeset"].to_i
version = nil
- with_controller(ChangesetController.new) do
+ with_controller(ChangesetsController.new) do
doc = OSM::API.new.get_xml_doc
change = XML::Node.new "osmChange"
doc.root = change
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)