3 class ChangesetTest < ActiveSupport::TestCase
4 def test_from_xml_no_text
6 message_create = assert_raise(OSM::APIBadXMLError) do
7 Changeset.from_xml(no_text, true)
9 assert_match /Must specify a string with one or more characters/, message_create.message
10 message_update = assert_raise(OSM::APIBadXMLError) do
11 Changeset.from_xml(no_text, false)
13 assert_match /Must specify a string with one or more characters/, message_update.message
16 def test_from_xml_no_changeset
18 message_create = assert_raise(OSM::APIBadXMLError) do
19 Changeset.from_xml(nocs, true)
21 assert_match %r{XML doesn't contain an osm/changeset element}, message_create.message
22 message_update = assert_raise(OSM::APIBadXMLError) do
23 Changeset.from_xml(nocs, false)
25 assert_match %r{XML doesn't contain an osm/changeset element}, message_update.message
28 def test_from_xml_no_k_v
29 nokv = "<osm><changeset><tag /></changeset></osm>"
30 message_create = assert_raise(OSM::APIBadXMLError) do
31 Changeset.from_xml(nokv, true)
33 assert_match /tag is missing key/, message_create.message
34 message_update = assert_raise(OSM::APIBadXMLError) do
35 Changeset.from_xml(nokv, false)
37 assert_match /tag is missing key/, message_update.message
40 def test_from_xml_no_v
41 no_v = "<osm><changeset><tag k='key' /></changeset></osm>"
42 message_create = assert_raise(OSM::APIBadXMLError) do
43 Changeset.from_xml(no_v, true)
45 assert_match /tag is missing value/, message_create.message
46 message_update = assert_raise(OSM::APIBadXMLError) do
47 Changeset.from_xml(no_v, false)
49 assert_match /tag is missing value/, message_update.message
52 def test_from_xml_duplicate_k
53 dupk = "<osm><changeset><tag k='dup' v='test' /><tag k='dup' v='value' /></changeset></osm>"
54 message_create = assert_raise(OSM::APIDuplicateTagsError) do
55 Changeset.from_xml(dupk, true)
57 assert_equal "Element changeset/ has duplicate tags with key dup", message_create.message
58 message_update = assert_raise(OSM::APIDuplicateTagsError) do
59 Changeset.from_xml(dupk, false)
61 assert_equal "Element changeset/ has duplicate tags with key dup", message_update.message
64 def test_from_xml_valid
65 # Example taken from the Update section on the API_v0.6 docs on the wiki
66 xml = "<osm><changeset><tag k=\"comment\" v=\"Just adding some streetnames and a restaurant\"/></changeset></osm>"
67 assert_nothing_raised do
68 Changeset.from_xml(xml, false)
70 assert_nothing_raised do
71 Changeset.from_xml(xml, true)