require "changeset_controller"
class ChangesetControllerTest < ActionController::TestCase
- api_fixtures
-
##
# test all routes which lead to this controller
def test_routes
# simple diff to change a node, way and relation by removing
# their tags
- diff = <<EOF
-<osmChange>
- <modify>
- <node id='#{node.id}' lon='0' lat='0' changeset='#{changeset_id}' version='1'/>
- <way id='#{way.id}' changeset='#{changeset_id}' version='1'>
- <nd ref='#{node.id}'/>
- </way>
- </modify>
- <modify>
- <relation id='#{relation.id}' changeset='#{changeset_id}' version='1'>
- <member type='way' role='some' ref='#{way.id}'/>
- <member type='node' role='some' ref='#{node.id}'/>
- <member type='relation' role='some' ref='#{other_relation.id}'/>
- </relation>
- </modify>
-</osmChange>
+ diff = <<EOF.strip_heredoc
+ <osmChange>
+ <modify>
+ <node id='#{node.id}' lon='0' lat='0' changeset='#{changeset_id}' version='1'/>
+ <way id='#{way.id}' changeset='#{changeset_id}' version='1'>
+ <nd ref='#{node.id}'/>
+ </way>
+ </modify>
+ <modify>
+ <relation id='#{relation.id}' changeset='#{changeset_id}' version='1'>
+ <member type='way' role='some' ref='#{way.id}'/>
+ <member type='node' role='some' ref='#{node.id}'/>
+ <member type='relation' role='some' ref='#{other_relation.id}'/>
+ </relation>
+ </modify>
+ </osmChange>
EOF
# upload it
# simple diff to change a node, way and relation by removing
# their tags
- diff = <<EOF
-<osmChange>
- <modify>
- <node id='#{node.id}' lon='0' lat='0' changeset='#{changeset_id}' version='1'/>
- <way id='#{way.id}' changeset='#{changeset_id}' version='1'>
- <nd ref='#{node.id}'/>
- </way>
- </modify>
- <modify>
- <relation id='#{relation.id}' changeset='#{changeset_id}' version='1'>
- <member type='way' role='some' ref='#{way.id}'/>
- <member type='node' role='some' ref='#{node.id}'/>
- <member type='relation' role='some' ref='#{other_relation.id}'/>
- </relation>
- </modify>
-</osmChange>
+ diff = <<EOF.strip_heredoc
+ <osmChange>
+ <modify>
+ <node id='#{node.id}' lon='0' lat='0' changeset='#{changeset_id}' version='1'/>
+ <way id='#{way.id}' changeset='#{changeset_id}' version='1'>
+ <nd ref='#{node.id}'/>
+ </way>
+ </modify>
+ <modify>
+ <relation id='#{relation.id}' changeset='#{changeset_id}' version='1'>
+ <member type='way' role='some' ref='#{way.id}'/>
+ <member type='node' role='some' ref='#{node.id}'/>
+ <member type='relation' role='some' ref='#{other_relation.id}'/>
+ </relation>
+ </modify>
+ </osmChange>
EOF
# upload it
# simple diff to change a node, way and relation by removing
# their tags
- diff = <<EOF
-<osmChange>
- <modify>
- <node id='#{node.id}' lon='0' lat='0' changeset='#{changeset_id}' version='1'/>
- <way id='#{way.id}' changeset='#{changeset_id}' version='1'>
- <nd ref='#{node.id}'/>
- </way>
- </modify>
- <modify>
- <relation id='#{relation.id}' changeset='#{changeset_id}' version='1'>
- <member type='way' role='some' ref='#{way.id}'/>
- <member type='node' role='some' ref='#{node.id}'/>
- <member type='relation' role='some' ref='#{other_relation.id}'/>
- </relation>
- </modify>
-</osmChange>
+ diff = <<EOF.strip_heredoc
+ <osmChange>
+ <modify>
+ <node id='#{node.id}' lon='0' lat='0' changeset='#{changeset_id}' version='1'/>
+ <way id='#{way.id}' changeset='#{changeset_id}' version='1'>
+ <nd ref='#{node.id}'/>
+ </way>
+ </modify>
+ <modify>
+ <relation id='#{relation.id}' changeset='#{changeset_id}' version='1'>
+ <member type='way' role='some' ref='#{way.id}'/>
+ <member type='node' role='some' ref='#{node.id}'/>
+ <member type='relation' role='some' ref='#{other_relation.id}'/>
+ </relation>
+ </modify>
+ </osmChange>
EOF
# upload it
def test_upload_create_valid
user = create(:user)
changeset = create(:changeset, :user => user)
+ node = create(:node)
+ way = create(:way_with_nodes, :nodes_count => 2)
+ relation = create(:relation)
basic_authorization user.email, "test"
# simple diff to create a node way and relation using placeholders
- diff = <<EOF
-<osmChange>
- <create>
- <node id='-1' lon='0' lat='0' changeset='#{changeset.id}'>
- <tag k='foo' v='bar'/>
- <tag k='baz' v='bat'/>
- </node>
- <way id='-1' changeset='#{changeset.id}'>
- <nd ref='3'/>
- </way>
- </create>
- <create>
- <relation id='-1' changeset='#{changeset.id}'>
- <member type='way' role='some' ref='3'/>
- <member type='node' role='some' ref='5'/>
- <member type='relation' role='some' ref='3'/>
- </relation>
- </create>
-</osmChange>
+ diff = <<EOF.strip_heredoc
+ <osmChange>
+ <create>
+ <node id='-1' lon='0' lat='0' changeset='#{changeset.id}'>
+ <tag k='foo' v='bar'/>
+ <tag k='baz' v='bat'/>
+ </node>
+ <way id='-1' changeset='#{changeset.id}'>
+ <nd ref='#{node.id}'/>
+ </way>
+ </create>
+ <create>
+ <relation id='-1' changeset='#{changeset.id}'>
+ <member type='way' role='some' ref='#{way.id}'/>
+ <member type='node' role='some' ref='#{node.id}'/>
+ <member type='relation' role='some' ref='#{relation.id}'/>
+ </relation>
+ </create>
+ </osmChange>
EOF
# upload it
delete << used_node.to_xml_node
# update the changeset to one that this user owns
- %w(node way relation).each do |type|
+ %w[node way relation].each do |type|
delete.find("//osmChange/delete/#{type}").each do |n|
n["changeset"] = changeset.id.to_s
end
# upload some widely-spaced nodes, spiralling positive and negative to cause
# largest bbox over-expansion possible.
- diff = <<EOF
-<osmChange>
- <create>
- <node id='-1' lon='-20' lat='-10' changeset='#{changeset_id}'/>
- <node id='-10' lon='20' lat='10' changeset='#{changeset_id}'/>
- <node id='-2' lon='-40' lat='-20' changeset='#{changeset_id}'/>
- <node id='-11' lon='40' lat='20' changeset='#{changeset_id}'/>
- <node id='-3' lon='-60' lat='-30' changeset='#{changeset_id}'/>
- <node id='-12' lon='60' lat='30' changeset='#{changeset_id}'/>
- <node id='-4' lon='-80' lat='-40' changeset='#{changeset_id}'/>
- <node id='-13' lon='80' lat='40' changeset='#{changeset_id}'/>
- <node id='-5' lon='-100' lat='-50' changeset='#{changeset_id}'/>
- <node id='-14' lon='100' lat='50' changeset='#{changeset_id}'/>
- <node id='-6' lon='-120' lat='-60' changeset='#{changeset_id}'/>
- <node id='-15' lon='120' lat='60' changeset='#{changeset_id}'/>
- <node id='-7' lon='-140' lat='-70' changeset='#{changeset_id}'/>
- <node id='-16' lon='140' lat='70' changeset='#{changeset_id}'/>
- <node id='-8' lon='-160' lat='-80' changeset='#{changeset_id}'/>
- <node id='-17' lon='160' lat='80' changeset='#{changeset_id}'/>
- <node id='-9' lon='-179.9' lat='-89.9' changeset='#{changeset_id}'/>
- <node id='-18' lon='179.9' lat='89.9' changeset='#{changeset_id}'/>
- </create>
-</osmChange>
+ diff = <<EOF.strip_heredoc
+ <osmChange>
+ <create>
+ <node id='-1' lon='-20' lat='-10' changeset='#{changeset_id}'/>
+ <node id='-10' lon='20' lat='10' changeset='#{changeset_id}'/>
+ <node id='-2' lon='-40' lat='-20' changeset='#{changeset_id}'/>
+ <node id='-11' lon='40' lat='20' changeset='#{changeset_id}'/>
+ <node id='-3' lon='-60' lat='-30' changeset='#{changeset_id}'/>
+ <node id='-12' lon='60' lat='30' changeset='#{changeset_id}'/>
+ <node id='-4' lon='-80' lat='-40' changeset='#{changeset_id}'/>
+ <node id='-13' lon='80' lat='40' changeset='#{changeset_id}'/>
+ <node id='-5' lon='-100' lat='-50' changeset='#{changeset_id}'/>
+ <node id='-14' lon='100' lat='50' changeset='#{changeset_id}'/>
+ <node id='-6' lon='-120' lat='-60' changeset='#{changeset_id}'/>
+ <node id='-15' lon='120' lat='60' changeset='#{changeset_id}'/>
+ <node id='-7' lon='-140' lat='-70' changeset='#{changeset_id}'/>
+ <node id='-16' lon='140' lat='70' changeset='#{changeset_id}'/>
+ <node id='-8' lon='-160' lat='-80' changeset='#{changeset_id}'/>
+ <node id='-17' lon='160' lat='80' changeset='#{changeset_id}'/>
+ <node id='-9' lon='-179.9' lat='-89.9' changeset='#{changeset_id}'/>
+ <node id='-18' lon='179.9' lat='89.9' changeset='#{changeset_id}'/>
+ </create>
+ </osmChange>
EOF
# upload it, which used to cause an error like "PGError: ERROR:
delete << used_node.to_xml_node
# update the changeset to one that this user owns
- %w(node way relation).each do |type|
+ %w[node way relation].each do |type|
delete.find("//osmChange/delete/#{type}").each do |n|
n["changeset"] = changeset.id.to_s
end
delete << used_node.to_xml_node
# update the changeset to one that this user owns
- %w(node way relation).each do |type|
+ %w[node way relation].each do |type|
delete.find("//osmChange/delete/#{type}").each do |n|
n["changeset"] = changeset.id.to_s
end
basic_authorization changeset.user.email, "test"
# simple diff to create a node way and relation using placeholders
- diff = <<EOF
-<osmChange>
- <create>
- <node id='-1' lon='0' lat='0' changeset='#{changeset.id}'>
- <tag k='foo' v='#{'x' * 256}'/>
- </node>
- </create>
-</osmChange>
+ diff = <<EOF.strip_heredoc
+ <osmChange>
+ <create>
+ <node id='-1' lon='0' lat='0' changeset='#{changeset.id}'>
+ <tag k='foo' v='#{'x' * 256}'/>
+ </node>
+ </create>
+ </osmChange>
EOF
# upload it
basic_authorization changeset.user.email, "test"
# simple diff to create a node way and relation using placeholders
- diff = <<EOF
-<osmChange>
- <create>
- <node id='-1' lon='0' lat='0' changeset='#{changeset.id}'>
- <tag k='foo' v='bar'/>
- <tag k='baz' v='bat'/>
- </node>
- </create>
- <modify>
- <way id='#{way.id}' changeset='#{changeset.id}' version='1'>
- <nd ref='-1'/>
- <nd ref='#{node.id}'/>
- </way>
- <relation id='#{relation.id}' changeset='#{changeset.id}' version='1'>
- <member type='way' role='some' ref='#{way.id}'/>
- <member type='node' role='some' ref='-1'/>
- <member type='relation' role='some' ref='#{relation.id}'/>
- </relation>
- </modify>
-</osmChange>
+ diff = <<EOF.strip_heredoc
+ <osmChange>
+ <create>
+ <node id='-1' lon='0' lat='0' changeset='#{changeset.id}'>
+ <tag k='foo' v='bar'/>
+ <tag k='baz' v='bat'/>
+ </node>
+ </create>
+ <modify>
+ <way id='#{way.id}' changeset='#{changeset.id}' version='1'>
+ <nd ref='-1'/>
+ <nd ref='#{node.id}'/>
+ </way>
+ <relation id='#{relation.id}' changeset='#{changeset.id}' version='1'>
+ <member type='way' role='some' ref='#{way.id}'/>
+ <member type='node' role='some' ref='-1'/>
+ <member type='relation' role='some' ref='#{relation.id}'/>
+ </relation>
+ </modify>
+ </osmChange>
EOF
# upload it
basic_authorization changeset.user.email, "test"
# simple diff to create a node way and relation using placeholders
- diff = <<EOF
-<osmChange>
- <modify>
- <node id='#{node.id}' lon='0' lat='0' changeset='#{changeset.id}' version='1'/>
- <way id='#{way.id}' changeset='#{changeset.id}' version='1'>
- <nd ref='#{node.id}'/>
- </way>
- </modify>
- <modify>
- <relation id='#{relation.id}' changeset='#{changeset.id}' version='1'>
- <member type='way' role='some' ref='#{way.id}'/>
- <member type='node' role='some' ref='#{node.id}'/>
- <member type='relation' role='some' ref='#{other_relation.id}'/>
- </relation>
- </modify>
- <create>
- <node id='-1' lon='0' lat='0' changeset='#{other_changeset.id}'>
- <tag k='foo' v='bar'/>
- <tag k='baz' v='bat'/>
- </node>
- </create>
-</osmChange>
+ diff = <<EOF.strip_heredoc
+ <osmChange>
+ <modify>
+ <node id='#{node.id}' lon='0' lat='0' changeset='#{changeset.id}' version='1'/>
+ <way id='#{way.id}' changeset='#{changeset.id}' version='1'>
+ <nd ref='#{node.id}'/>
+ </way>
+ </modify>
+ <modify>
+ <relation id='#{relation.id}' changeset='#{changeset.id}' version='1'>
+ <member type='way' role='some' ref='#{way.id}'/>
+ <member type='node' role='some' ref='#{node.id}'/>
+ <member type='relation' role='some' ref='#{other_relation.id}'/>
+ </relation>
+ </modify>
+ <create>
+ <node id='-1' lon='0' lat='0' changeset='#{other_changeset.id}'>
+ <tag k='foo' v='bar'/>
+ <tag k='baz' v='bat'/>
+ </node>
+ </create>
+ </osmChange>
EOF
# upload it
##
# upload multiple versions of the same element in the same diff.
def test_upload_multiple_valid
+ node = create(:node)
changeset = create(:changeset)
basic_authorization changeset.user.email, "test"
# change the location of a node multiple times, each time referencing
# the last version. doesn't this depend on version numbers being
# sequential?
- diff = <<EOF
-<osmChange>
- <modify>
- <node id='1' lon='0' lat='0' changeset='#{changeset.id}' version='1'/>
- <node id='1' lon='1' lat='0' changeset='#{changeset.id}' version='2'/>
- <node id='1' lon='1' lat='1' changeset='#{changeset.id}' version='3'/>
- <node id='1' lon='1' lat='2' changeset='#{changeset.id}' version='4'/>
- <node id='1' lon='2' lat='2' changeset='#{changeset.id}' version='5'/>
- <node id='1' lon='3' lat='2' changeset='#{changeset.id}' version='6'/>
- <node id='1' lon='3' lat='3' changeset='#{changeset.id}' version='7'/>
- <node id='1' lon='9' lat='9' changeset='#{changeset.id}' version='8'/>
- </modify>
-</osmChange>
+ diff = <<EOF.strip_heredoc
+ <osmChange>
+ <modify>
+ <node id='#{node.id}' lon='0' lat='0' changeset='#{changeset.id}' version='1'/>
+ <node id='#{node.id}' lon='1' lat='0' changeset='#{changeset.id}' version='2'/>
+ <node id='#{node.id}' lon='1' lat='1' changeset='#{changeset.id}' version='3'/>
+ <node id='#{node.id}' lon='1' lat='2' changeset='#{changeset.id}' version='4'/>
+ <node id='#{node.id}' lon='2' lat='2' changeset='#{changeset.id}' version='5'/>
+ <node id='#{node.id}' lon='3' lat='2' changeset='#{changeset.id}' version='6'/>
+ <node id='#{node.id}' lon='3' lat='3' changeset='#{changeset.id}' version='7'/>
+ <node id='#{node.id}' lon='9' lat='9' changeset='#{changeset.id}' version='8'/>
+ </modify>
+ </osmChange>
EOF
# upload it
# upload multiple versions of the same element in the same diff, but
# keep the version numbers the same.
def test_upload_multiple_duplicate
+ node = create(:node)
changeset = create(:changeset)
basic_authorization changeset.user.email, "test"
- diff = <<EOF
-<osmChange>
- <modify>
- <node id='1' lon='0' lat='0' changeset='#{changeset.id}' version='1'/>
- <node id='1' lon='1' lat='1' changeset='#{changeset.id}' version='1'/>
- </modify>
-</osmChange>
+ diff = <<EOF.strip_heredoc
+ <osmChange>
+ <modify>
+ <node id='#{node.id}' lon='0' lat='0' changeset='#{changeset.id}' version='1'/>
+ <node id='#{node.id}' lon='1' lat='1' changeset='#{changeset.id}' version='1'/>
+ </modify>
+ </osmChange>
EOF
# upload it
basic_authorization changeset.user.email, "test"
- diff = <<EOF
-<osmChange>
- <modify>
- <node id='1' lon='1' lat='1' changeset='#{changeset.id}'/>
- </modify>
-</osmChange>
+ diff = <<EOF.strip_heredoc
+ <osmChange>
+ <modify>
+ <node id='1' lon='1' lat='1' changeset='#{changeset.id}'/>
+ </modify>
+ </osmChange>
EOF
# upload it
basic_authorization changeset.user.email, "test"
- diff = <<EOF
-<osmChange>
- <ping>
- <node id='1' lon='1' lat='1' changeset='#{changeset.id}' />
- </ping>
-</osmChange>
+ diff = <<EOF.strip_heredoc
+ <osmChange>
+ <ping>
+ <node id='1' lon='1' lat='1' changeset='#{changeset.id}' />
+ </ping>
+ </osmChange>
EOF
content diff
post :upload, :id => changeset.id
basic_authorization changeset.user.email, "test"
- diff = <<EOF
-<osmChange>
- <modify><node id='#{node.id}' lon='0' lat='0' changeset='#{changeset.id}'
- version='1'></node>
- <node id='#{node.id}' lon='1' lat='1' changeset='#{changeset.id}' version='2'><tag k='k' v='v'/></node></modify>
- <modify>
- <relation id='#{relation.id}' changeset='#{changeset.id}' version='1'><member
- type='way' role='some' ref='#{way.id}'/><member
- type='node' role='some' ref='#{node.id}'/>
- <member type='relation' role='some' ref='#{other_relation.id}'/>
- </relation>
- </modify></osmChange>
+ diff = <<EOF.strip_heredoc
+ <osmChange>
+ <modify><node id='#{node.id}' lon='0' lat='0' changeset='#{changeset.id}'
+ version='1'></node>
+ <node id='#{node.id}' lon='1' lat='1' changeset='#{changeset.id}' version='2'><tag k='k' v='v'/></node></modify>
+ <modify>
+ <relation id='#{relation.id}' changeset='#{changeset.id}' version='1'><member
+ type='way' role='some' ref='#{way.id}'/><member
+ type='node' role='some' ref='#{node.id}'/>
+ <member type='relation' role='some' ref='#{other_relation.id}'/>
+ </relation>
+ </modify></osmChange>
EOF
# upload it
basic_authorization changeset.user.email, "test"
- diff = <<EOF
-<osmChange>
- <create>
- <node id='-1' lon='0' lat='0' changeset='#{changeset.id}'>
- <tag k="foo" v="bar"/>
- </node>
- </create>
- <modify>
- <node id='-1' lon='1' lat='1' changeset='#{changeset.id}' version='1'/>
- </modify>
- <delete>
- <node id='-1' lon='2' lat='2' changeset='#{changeset.id}' version='2'/>
- </delete>
-</osmChange>
+ diff = <<EOF.strip_heredoc
+ <osmChange>
+ <create>
+ <node id='-1' lon='0' lat='0' changeset='#{changeset.id}'>
+ <tag k="foo" v="bar"/>
+ </node>
+ </create>
+ <modify>
+ <node id='-1' lon='1' lat='1' changeset='#{changeset.id}' version='1'/>
+ </modify>
+ <delete>
+ <node id='-1' lon='2' lat='2' changeset='#{changeset.id}' version='2'/>
+ </delete>
+ </osmChange>
EOF
# upload it
basic_authorization changeset.user.email, "test"
- diff = <<EOF
-<osmChange>
- <create>
- <node id='-1' lon='0' lat='0' changeset='#{changeset.id}' version='1'/>
- <node id='-1' lon='1' lat='1' changeset='#{changeset.id}' version='1'/>
- <node id='-1' lon='2' lat='2' changeset='#{changeset.id}' version='2'/>
- </create>
-</osmChange>
+ diff = <<EOF.strip_heredoc
+ <osmChange>
+ <create>
+ <node id='-1' lon='0' lat='0' changeset='#{changeset.id}' version='1'/>
+ <node id='-1' lon='1' lat='1' changeset='#{changeset.id}' version='1'/>
+ <node id='-1' lon='2' lat='2' changeset='#{changeset.id}' version='2'/>
+ </create>
+ </osmChange>
EOF
# upload it
basic_authorization changeset.user.email, "test"
- diff = <<EOF
-<osmChange>
- <create>
- <node id="-1" lon="0" lat="0" changeset="#{changeset.id}" version="1"/>
- <node id="-2" lon="1" lat="1" changeset="#{changeset.id}" version="1"/>
- <node id="-3" lon="2" lat="2" changeset="#{changeset.id}" version="1"/>
- <way id="-1" changeset="#{changeset.id}" version="1">
- <nd ref="-1"/>
- <nd ref="-2"/>
- <nd ref="-3"/>
- <nd ref="-4"/>
- </way>
- </create>
-</osmChange>
+ diff = <<EOF.strip_heredoc
+ <osmChange>
+ <create>
+ <node id="-1" lon="0" lat="0" changeset="#{changeset.id}" version="1"/>
+ <node id="-2" lon="1" lat="1" changeset="#{changeset.id}" version="1"/>
+ <node id="-3" lon="2" lat="2" changeset="#{changeset.id}" version="1"/>
+ <way id="-1" changeset="#{changeset.id}" version="1">
+ <nd ref="-1"/>
+ <nd ref="-2"/>
+ <nd ref="-3"/>
+ <nd ref="-4"/>
+ </way>
+ </create>
+ </osmChange>
EOF
# upload it
assert_equal "Placeholder node not found for reference -4 in way -1", @response.body
# the same again, but this time use an existing way
- diff = <<EOF
-<osmChange>
- <create>
- <node id="-1" lon="0" lat="0" changeset="#{changeset.id}" version="1"/>
- <node id="-2" lon="1" lat="1" changeset="#{changeset.id}" version="1"/>
- <node id="-3" lon="2" lat="2" changeset="#{changeset.id}" version="1"/>
- <way id="#{way.id}" changeset="#{changeset.id}" version="1">
- <nd ref="-1"/>
- <nd ref="-2"/>
- <nd ref="-3"/>
- <nd ref="-4"/>
- </way>
- </create>
-</osmChange>
+ diff = <<EOF.strip_heredoc
+ <osmChange>
+ <create>
+ <node id="-1" lon="0" lat="0" changeset="#{changeset.id}" version="1"/>
+ <node id="-2" lon="1" lat="1" changeset="#{changeset.id}" version="1"/>
+ <node id="-3" lon="2" lat="2" changeset="#{changeset.id}" version="1"/>
+ <way id="#{way.id}" changeset="#{changeset.id}" version="1">
+ <nd ref="-1"/>
+ <nd ref="-2"/>
+ <nd ref="-3"/>
+ <nd ref="-4"/>
+ </way>
+ </create>
+ </osmChange>
EOF
# upload it
basic_authorization changeset.user.email, "test"
- diff = <<EOF
-<osmChange>
- <create>
- <node id="-1" lon="0" lat="0" changeset="#{changeset.id}" version="1"/>
- <node id="-2" lon="1" lat="1" changeset="#{changeset.id}" version="1"/>
- <node id="-3" lon="2" lat="2" changeset="#{changeset.id}" version="1"/>
- <relation id="-1" changeset="#{changeset.id}" version="1">
- <member type="node" role="foo" ref="-1"/>
- <member type="node" role="foo" ref="-2"/>
- <member type="node" role="foo" ref="-3"/>
- <member type="node" role="foo" ref="-4"/>
- </relation>
- </create>
-</osmChange>
+ diff = <<EOF.strip_heredoc
+ <osmChange>
+ <create>
+ <node id="-1" lon="0" lat="0" changeset="#{changeset.id}" version="1"/>
+ <node id="-2" lon="1" lat="1" changeset="#{changeset.id}" version="1"/>
+ <node id="-3" lon="2" lat="2" changeset="#{changeset.id}" version="1"/>
+ <relation id="-1" changeset="#{changeset.id}" version="1">
+ <member type="node" role="foo" ref="-1"/>
+ <member type="node" role="foo" ref="-2"/>
+ <member type="node" role="foo" ref="-3"/>
+ <member type="node" role="foo" ref="-4"/>
+ </relation>
+ </create>
+ </osmChange>
EOF
# upload it
assert_equal "Placeholder Node not found for reference -4 in relation -1.", @response.body
# the same again, but this time use an existing relation
- diff = <<EOF
-<osmChange>
- <create>
- <node id="-1" lon="0" lat="0" changeset="#{changeset.id}" version="1"/>
- <node id="-2" lon="1" lat="1" changeset="#{changeset.id}" version="1"/>
- <node id="-3" lon="2" lat="2" changeset="#{changeset.id}" version="1"/>
- <relation id="#{relation.id}" changeset="#{changeset.id}" version="1">
- <member type="node" role="foo" ref="-1"/>
- <member type="node" role="foo" ref="-2"/>
- <member type="node" role="foo" ref="-3"/>
- <member type="way" role="bar" ref="-1"/>
- </relation>
- </create>
-</osmChange>
+ diff = <<EOF.strip_heredoc
+ <osmChange>
+ <create>
+ <node id="-1" lon="0" lat="0" changeset="#{changeset.id}" version="1"/>
+ <node id="-2" lon="1" lat="1" changeset="#{changeset.id}" version="1"/>
+ <node id="-3" lon="2" lat="2" changeset="#{changeset.id}" version="1"/>
+ <relation id="#{relation.id}" changeset="#{changeset.id}" version="1">
+ <member type="node" role="foo" ref="-1"/>
+ <member type="node" role="foo" ref="-2"/>
+ <member type="node" role="foo" ref="-3"/>
+ <member type="way" role="bar" ref="-1"/>
+ </relation>
+ </create>
+ </osmChange>
EOF
# upload it
# when we make some simple changes we get the same changes back from the
# diff download.
def test_diff_download_simple
+ node = create(:node)
+
## First try with a non-public user, which should get a forbidden
basic_authorization(create(:user, :data_public => false).email, "test")
changeset_id = @response.body.to_i
# add a diff to it
- diff = <<EOF
-<osmChange>
- <modify>
- <node id='1' lon='0' lat='0' changeset='#{changeset_id}' version='1'/>
- <node id='1' lon='1' lat='0' changeset='#{changeset_id}' version='2'/>
- <node id='1' lon='1' lat='1' changeset='#{changeset_id}' version='3'/>
- <node id='1' lon='1' lat='2' changeset='#{changeset_id}' version='4'/>
- <node id='1' lon='2' lat='2' changeset='#{changeset_id}' version='5'/>
- <node id='1' lon='3' lat='2' changeset='#{changeset_id}' version='6'/>
- <node id='1' lon='3' lat='3' changeset='#{changeset_id}' version='7'/>
- <node id='1' lon='9' lat='9' changeset='#{changeset_id}' version='8'/>
- </modify>
-</osmChange>
+ diff = <<EOF.strip_heredoc
+ <osmChange>
+ <modify>
+ <node id='#{node.id}' lon='0' lat='0' changeset='#{changeset_id}' version='1'/>
+ <node id='#{node.id}' lon='1' lat='0' changeset='#{changeset_id}' version='2'/>
+ <node id='#{node.id}' lon='1' lat='1' changeset='#{changeset_id}' version='3'/>
+ <node id='#{node.id}' lon='1' lat='2' changeset='#{changeset_id}' version='4'/>
+ <node id='#{node.id}' lon='2' lat='2' changeset='#{changeset_id}' version='5'/>
+ <node id='#{node.id}' lon='3' lat='2' changeset='#{changeset_id}' version='6'/>
+ <node id='#{node.id}' lon='3' lat='3' changeset='#{changeset_id}' version='7'/>
+ <node id='#{node.id}' lon='9' lat='9' changeset='#{changeset_id}' version='8'/>
+ </modify>
+ </osmChange>
EOF
# upload it
assert_response :success
changeset_id = @response.body.to_i
- diff = <<OSMFILE
-<osmChange version="0.6" generator="JOSM">
-<create version="0.6" generator="JOSM">
- <node id='-1' visible='true' changeset='#{changeset_id}' lat='51.49619982187321' lon='-0.18722061869438314' />
- <node id='-2' visible='true' changeset='#{changeset_id}' lat='51.496359883909605' lon='-0.18653093576241928' />
- <node id='-3' visible='true' changeset='#{changeset_id}' lat='51.49598132358285' lon='-0.18719613290981638' />
- <node id='-4' visible='true' changeset='#{changeset_id}' lat='51.4961591711078' lon='-0.18629015888084607' />
- <node id='-5' visible='true' changeset='#{changeset_id}' lat='51.49582126021711' lon='-0.18708186591517145' />
- <node id='-6' visible='true' changeset='#{changeset_id}' lat='51.49591018437858' lon='-0.1861432441734455' />
- <node id='-7' visible='true' changeset='#{changeset_id}' lat='51.49560784152179' lon='-0.18694719410005425' />
- <node id='-8' visible='true' changeset='#{changeset_id}' lat='51.49567389979617' lon='-0.1860289771788006' />
- <node id='-9' visible='true' changeset='#{changeset_id}' lat='51.49543761398892' lon='-0.186820684213126' />
- <way id='-10' action='modiy' visible='true' changeset='#{changeset_id}'>
- <nd ref='-1' />
- <nd ref='-2' />
- <nd ref='-3' />
- <nd ref='-4' />
- <nd ref='-5' />
- <nd ref='-6' />
- <nd ref='-7' />
- <nd ref='-8' />
- <nd ref='-9' />
- <tag k='highway' v='residential' />
- <tag k='name' v='Foobar Street' />
- </way>
-</create>
-</osmChange>
+ diff = <<OSMFILE.strip_heredoc
+ <osmChange version="0.6" generator="JOSM">
+ <create version="0.6" generator="JOSM">
+ <node id='-1' visible='true' changeset='#{changeset_id}' lat='51.49619982187321' lon='-0.18722061869438314' />
+ <node id='-2' visible='true' changeset='#{changeset_id}' lat='51.496359883909605' lon='-0.18653093576241928' />
+ <node id='-3' visible='true' changeset='#{changeset_id}' lat='51.49598132358285' lon='-0.18719613290981638' />
+ <node id='-4' visible='true' changeset='#{changeset_id}' lat='51.4961591711078' lon='-0.18629015888084607' />
+ <node id='-5' visible='true' changeset='#{changeset_id}' lat='51.49582126021711' lon='-0.18708186591517145' />
+ <node id='-6' visible='true' changeset='#{changeset_id}' lat='51.49591018437858' lon='-0.1861432441734455' />
+ <node id='-7' visible='true' changeset='#{changeset_id}' lat='51.49560784152179' lon='-0.18694719410005425' />
+ <node id='-8' visible='true' changeset='#{changeset_id}' lat='51.49567389979617' lon='-0.1860289771788006' />
+ <node id='-9' visible='true' changeset='#{changeset_id}' lat='51.49543761398892' lon='-0.186820684213126' />
+ <way id='-10' action='modiy' visible='true' changeset='#{changeset_id}'>
+ <nd ref='-1' />
+ <nd ref='-2' />
+ <nd ref='-3' />
+ <nd ref='-4' />
+ <nd ref='-5' />
+ <nd ref='-6' />
+ <nd ref='-7' />
+ <nd ref='-8' />
+ <nd ref='-9' />
+ <tag k='highway' v='residential' />
+ <tag k='name' v='Foobar Street' />
+ </way>
+ </create>
+ </osmChange>
OSMFILE
# upload it
# when we make some complex changes we get the same changes back from the
# diff download.
def test_diff_download_complex
+ node = create(:node)
+ node2 = create(:node)
+ way = create(:way)
basic_authorization(create(:user).email, "test")
# create a temporary changeset
changeset_id = @response.body.to_i
# add a diff to it
- diff = <<EOF
-<osmChange>
- <delete>
- <node id='1' lon='0' lat='0' changeset='#{changeset_id}' version='1'/>
- </delete>
- <create>
- <node id='-1' lon='9' lat='9' changeset='#{changeset_id}' version='0'/>
- <node id='-2' lon='8' lat='9' changeset='#{changeset_id}' version='0'/>
- <node id='-3' lon='7' lat='9' changeset='#{changeset_id}' version='0'/>
- </create>
- <modify>
- <node id='3' lon='20' lat='15' changeset='#{changeset_id}' version='1'/>
- <way id='1' changeset='#{changeset_id}' version='1'>
- <nd ref='3'/>
- <nd ref='-1'/>
- <nd ref='-2'/>
- <nd ref='-3'/>
- </way>
- </modify>
-</osmChange>
+ diff = <<EOF.strip_heredoc
+ <osmChange>
+ <delete>
+ <node id='#{node.id}' lon='0' lat='0' changeset='#{changeset_id}' version='1'/>
+ </delete>
+ <create>
+ <node id='-1' lon='9' lat='9' changeset='#{changeset_id}' version='0'/>
+ <node id='-2' lon='8' lat='9' changeset='#{changeset_id}' version='0'/>
+ <node id='-3' lon='7' lat='9' changeset='#{changeset_id}' version='0'/>
+ </create>
+ <modify>
+ <node id='#{node2.id}' lon='20' lat='15' changeset='#{changeset_id}' version='1'/>
+ <way id='#{way.id}' changeset='#{changeset_id}' version='1'>
+ <nd ref='#{node2.id}'/>
+ <nd ref='-1'/>
+ <nd ref='-2'/>
+ <nd ref='-3'/>
+ </way>
+ </modify>
+ </osmChange>
EOF
# upload it
# get the bounding box back from the changeset
get :read, :id => changeset_id
assert_response :success, "Couldn't read back changeset."
- assert_select "osm>changeset[min_lon='1.0']", 1
- assert_select "osm>changeset[max_lon='1.0']", 1
- assert_select "osm>changeset[min_lat='2.0']", 1
- assert_select "osm>changeset[max_lat='2.0']", 1
+ assert_select "osm>changeset[min_lon='1.0000000']", 1
+ assert_select "osm>changeset[max_lon='1.0000000']", 1
+ assert_select "osm>changeset[min_lat='2.0000000']", 1
+ assert_select "osm>changeset[max_lat='2.0000000']", 1
# add another node to it
with_controller(NodeController.new) do
# get the bounding box back from the changeset
get :read, :id => changeset_id
assert_response :success, "Couldn't read back changeset for the second time."
- assert_select "osm>changeset[min_lon='1.0']", 1
- assert_select "osm>changeset[max_lon='2.0']", 1
- assert_select "osm>changeset[min_lat='1.0']", 1
- assert_select "osm>changeset[max_lat='2.0']", 1
+ assert_select "osm>changeset[min_lon='1.0000000']", 1
+ assert_select "osm>changeset[max_lon='2.0000000']", 1
+ assert_select "osm>changeset[min_lat='1.0000000']", 1
+ assert_select "osm>changeset[max_lat='2.0000000']", 1
# add (delete) a way to it, which contains a point at (3,3)
with_controller(WayController.new) do
get :read, :id => changeset_id
assert_response :success, "Couldn't read back changeset for the third time."
# note that the 3.1 here is because of the bbox overexpansion
- assert_select "osm>changeset[min_lon='1.0']", 1
- assert_select "osm>changeset[max_lon='3.1']", 1
- assert_select "osm>changeset[min_lat='1.0']", 1
- assert_select "osm>changeset[max_lat='3.1']", 1
+ assert_select "osm>changeset[min_lon='1.0000000']", 1
+ assert_select "osm>changeset[max_lon='3.1000000']", 1
+ assert_select "osm>changeset[min_lat='1.0000000']", 1
+ assert_select "osm>changeset[max_lat='3.1000000']", 1
end
##
user = create(:user)
changeset = create(:changeset, :user => user)
closed_changeset = create(:changeset, :closed, :user => user, :created_at => Time.utc(2008, 1, 1, 0, 0, 0), :closed_at => Time.utc(2008, 1, 2, 0, 0, 0))
+ changeset2 = create(:changeset, :min_lat => 5 * GeoRecord::SCALE, :min_lon => 5 * GeoRecord::SCALE, :max_lat => 15 * GeoRecord::SCALE, :max_lon => 15 * GeoRecord::SCALE)
+ changeset3 = create(:changeset, :min_lat => 4.5 * GeoRecord::SCALE, :min_lon => 4.5 * GeoRecord::SCALE, :max_lat => 5 * GeoRecord::SCALE, :max_lon => 5 * GeoRecord::SCALE)
get :query, :bbox => "-10,-10, 10, 10"
assert_response :success, "can't get changesets in bbox"
- assert_changesets [1, 4, 6]
+ assert_changesets [changeset2, changeset3]
get :query, :bbox => "4.5,4.5,4.6,4.6"
assert_response :success, "can't get changesets in bbox"
- assert_changesets [1]
+ assert_changesets [changeset3]
# not found when looking for changesets of non-existing users
get :query, :user => User.maximum(:id) + 1
basic_authorization private_user.email, "test"
get :query, :user => private_user.id
assert_response :success, "can't get changesets by user ID"
- assert_changesets [private_user_changeset.id, private_user_closed_changeset.id]
+ assert_changesets [private_user_changeset, private_user_closed_changeset]
get :query, :display_name => private_user.display_name
assert_response :success, "can't get changesets by user name"
- assert_changesets [private_user_changeset.id, private_user_closed_changeset.id]
+ assert_changesets [private_user_changeset, private_user_closed_changeset]
# check that the correct error is given when we provide both UID and name
get :query, :user => private_user.id, :display_name => private_user.display_name
get :query, :user => private_user.id, :open => true
assert_response :success, "can't get changesets by user and open"
- assert_changesets [private_user_changeset.id]
+ assert_changesets [private_user_changeset]
get :query, :time => "2007-12-31"
assert_response :success, "can't get changesets by time-since"
- assert_changesets [1, 2, 4, 5, 6, private_user_changeset.id, private_user_closed_changeset.id, changeset.id, closed_changeset.id]
+ assert_changesets [private_user_changeset, private_user_closed_changeset, changeset, closed_changeset, changeset2, changeset3]
get :query, :time => "2008-01-01T12:34Z"
assert_response :success, "can't get changesets by time-since with hour"
- assert_changesets [1, 2, 4, 5, 6, private_user_changeset.id, private_user_closed_changeset.id, changeset.id, closed_changeset.id]
+ assert_changesets [private_user_changeset, private_user_closed_changeset, changeset, closed_changeset, changeset2, changeset3]
get :query, :time => "2007-12-31T23:59Z,2008-01-02T00:01Z"
assert_response :success, "can't get changesets by time-range"
- assert_changesets [1, 5, 6, closed_changeset.id]
+ assert_changesets [closed_changeset]
get :query, :open => "true"
assert_response :success, "can't get changesets by open-ness"
- assert_changesets [1, 2, 4, private_user_changeset.id, changeset.id]
+ assert_changesets [private_user_changeset, changeset, changeset2, changeset3]
get :query, :closed => "true"
assert_response :success, "can't get changesets by closed-ness"
- assert_changesets [3, 5, 6, 7, 8, 9, private_user_closed_changeset.id, closed_changeset.id]
+ assert_changesets [private_user_closed_changeset, closed_changeset]
get :query, :closed => "true", :user => private_user.id
assert_response :success, "can't get changesets by closed-ness and user"
- assert_changesets [private_user_closed_changeset.id]
+ assert_changesets [private_user_closed_changeset]
get :query, :closed => "true", :user => user.id
assert_response :success, "can't get changesets by closed-ness and user"
- assert_changesets [closed_changeset.id]
+ assert_changesets [closed_changeset]
get :query, :changesets => "#{private_user_changeset.id},#{changeset.id},#{closed_changeset.id}"
assert_response :success, "can't get changesets by id (as comma-separated string)"
- assert_changesets [private_user_changeset.id, changeset.id, closed_changeset.id]
+ assert_changesets [private_user_changeset, changeset, closed_changeset]
get :query, :changesets => ""
assert_response :bad_request, "should be a bad request since changesets is empty"
end
##
- # This should display the last 20 changesets closed
+ # This should display the last 20 non-empty changesets
def test_feed
changeset = create(:changeset, :num_changes => 1)
+ closed_changeset = create(:changeset, :closed, :num_changes => 1)
_empty_changeset = create(:changeset, :num_changes => 0)
get :feed, :format => :atom
assert_template "list"
assert_equal "application/atom+xml", response.content_type
- check_feed_result([changeset])
+ check_feed_result([changeset, closed_changeset])
end
##
##
# boilerplate for checking that certain changesets exist in the
# output.
- def assert_changesets(ids)
- assert_select "osm>changeset", ids.size
- ids.each do |id|
- assert_select "osm>changeset[id='#{id}']", 1
+ def assert_changesets(changesets)
+ assert_select "osm>changeset", changesets.size
+ changesets.each do |changeset|
+ assert_select "osm>changeset[id='#{changeset.id}']", 1
end
end