3 class ChangesetTest < ActiveSupport::TestCase
6 def test_changeset_count
7 assert_equal 8, Changeset.count
10 def test_from_xml_no_text
12 message_create = assert_raise(OSM::APIBadXMLError) do
13 Changeset.from_xml(no_text, true)
15 assert_match /Must specify a string with one or more characters/, message_create.message
16 message_update = assert_raise(OSM::APIBadXMLError) do
17 Changeset.from_xml(no_text, false)
19 assert_match /Must specify a string with one or more characters/, message_update.message
22 def test_from_xml_no_changeset
24 message_create = assert_raise(OSM::APIBadXMLError) do
25 Changeset.from_xml(nocs, true)
27 assert_match /XML doesn't contain an osm\/changeset element/, message_create.message
28 message_update = assert_raise(OSM::APIBadXMLError) do
29 Changeset.from_xml(nocs, false)
31 assert_match /XML doesn't contain an osm\/changeset element/, message_update.message
34 def test_from_xml_no_k_v
35 nokv = "<osm><changeset><tag /></changeset></osm>"
36 message_create = assert_raise(OSM::APIBadXMLError) do
37 Changeset.from_xml(nokv, true)
39 assert_match /tag is missing key/, message_create.message
40 message_update = assert_raise(OSM::APIBadXMLError) do
41 Changeset.from_xml(nokv, false)
43 assert_match /tag is missing key/, message_create.message
46 def test_from_xml_no_v
47 no_v = "<osm><changeset><tag k='key' /></changeset></osm>"
48 message_create = assert_raise(OSM::APIBadXMLError) do
49 Changeset.from_xml(no_v, true)
51 assert_match /tag is missing value/, message_create.message
52 message_update = assert_raise(OSM::APIBadXMLError) do
53 Changeset.from_xml(no_v, false)
55 assert_match /tag is missing value/, message_update.message
58 def test_from_xml_duplicate_k
59 dupk = "<osm><changeset><tag k='dup' v='test' /><tag k='dup' v='value' /></changeset></osm>"
60 message_create = assert_raise(OSM::APIDuplicateTagsError) do
61 Changeset.from_xml(dupk, true)
63 assert_equal "Element changeset/ has duplicate tags with key dup", message_create.message
64 message_update = assert_raise(OSM::APIDuplicateTagsError) do
65 Changeset.from_xml(dupk, false)
67 assert_equal "Element changeset/ has duplicate tags with key dup", message_update.message
70 def test_from_xml_valid
71 # Example taken from the Update section on the API_v0.6 docs on the wiki
72 xml = "<osm><changeset><tag k=\"comment\" v=\"Just adding some streetnames and a restaurant\"/></changeset></osm>"
73 assert_nothing_raised(OSM::APIBadXMLError) do
74 Changeset.from_xml(xml, false)
76 assert_nothing_raised(OSM::APIBadXMLError) do
77 Changeset.from_xml(xml, true)