Actually the changeset doesn't need an id attribute in the xml. It is simply fetched as a parameter in the url. Thanks for pointing it out Frederik. We really need more tests so that things like this are thought about more before committing potentially significant changes.

This commit is contained in:
Shaun McDonald 2009-12-15 23:53:19 +00:00
parent 1fb6325630
commit 094855be22
2 changed files with 41 additions and 50 deletions

View file

@ -74,12 +74,6 @@ class Changeset < ActiveRecord::Base
cs.closed_at = cs.created_at + IDLE_TIMEOUT cs.closed_at = cs.created_at + IDLE_TIMEOUT
# initially we have no changes in a changeset # initially we have no changes in a changeset
cs.num_changes = 0 cs.num_changes = 0
else
raise OSM::APIBadXMLError.new("changeset", pt, "ID is required when updating.") if pt['id'].nil?
cs.id = pt['id'].to_i
# .to_i will return 0 if there is no number that can be parsed.
# We want to make sure that there is no id with zero anyway.
raise OSM::APIBadUserInput.new("ID of changeset cannot be zero when updating.") if cs.id == 0
end end
pt.find('tag').each do |tag| pt.find('tag').each do |tag|
@ -106,9 +100,9 @@ class Changeset < ActiveRecord::Base
# returns area of the changset bbox as a rough comparitive quantity for use of changset displays # returns area of the changset bbox as a rough comparitive quantity for use of changset displays
def area def area
if has_valid_bbox? if has_valid_bbox?
(max_lon - min_lon) * (max_lat - min_lat) (max_lon - min_lon) * (max_lat - min_lat)
else else
0 0
end end
end end

View file

@ -7,20 +7,6 @@ class ChangesetTest < ActiveSupport::TestCase
assert_equal 7, Changeset.count assert_equal 7, Changeset.count
end end
def test_xml_from_id_zero
id_list = ["", "0", "00", "0.0", "a"]
id_list.each do |id|
zero_id = "<osm><changeset id='#{id}' /></osm>"
assert_nothing_raised(OSM::APIBadUserInput) {
Changeset.from_xml(zero_id, true)
}
message_update = assert_raise(OSM::APIBadUserInput) {
Changeset.from_xml(zero_id, false)
}
assert_match /ID of changeset cannot be zero when updating/, message_update.message
end
end
def test_from_xml_no_text def test_from_xml_no_text
no_text = "" no_text = ""
message_create = assert_raise(OSM::APIBadXMLError) { message_create = assert_raise(OSM::APIBadXMLError) {
@ -58,7 +44,7 @@ class ChangesetTest < ActiveSupport::TestCase
end end
def test_from_xml_no_v def test_from_xml_no_v
no_v = "<osm><changeset id='1'><tag k='key' /></changeset></osm>" no_v = "<osm><changeset><tag k='key' /></changeset></osm>"
message_create = assert_raise(OSM::APIBadXMLError) { message_create = assert_raise(OSM::APIBadXMLError) {
Changeset.from_xml(no_v, true) Changeset.from_xml(no_v, true)
} }
@ -70,7 +56,7 @@ class ChangesetTest < ActiveSupport::TestCase
end end
def test_from_xml_duplicate_k def test_from_xml_duplicate_k
dupk = "<osm><changeset id='1'><tag k='dup' v='test' /><tag k='dup' v='value' /></changeset></osm>" dupk = "<osm><changeset><tag k='dup' v='test' /><tag k='dup' v='value' /></changeset></osm>"
message_create = assert_raise(OSM::APIDuplicateTagsError) { message_create = assert_raise(OSM::APIDuplicateTagsError) {
Changeset.from_xml(dupk, true) Changeset.from_xml(dupk, true)
} }
@ -78,6 +64,17 @@ class ChangesetTest < ActiveSupport::TestCase
message_update = assert_raise(OSM::APIDuplicateTagsError) { message_update = assert_raise(OSM::APIDuplicateTagsError) {
Changeset.from_xml(dupk, false) Changeset.from_xml(dupk, false)
} }
assert_equal "Element changeset/1 has duplicate tags with key dup", message_update.message assert_equal "Element changeset/ has duplicate tags with key dup", message_update.message
end
def test_from_xml_valid
# Example taken from the Update section on the API_v0.6 docs on the wiki
xml = "<osm><changeset><tag k=\"comment\" v=\"Just adding some streetnames and a restaurant\"/></changeset></osm>"
assert_nothing_raised(OSM::APIBadXMLError) {
Changeset.from_xml(xml, false)
}
assert_nothing_raised(OSM::APIBadXMLError) {
Changeset.from_xml(xml, true)
}
end end
end end