1 require File.dirname(__FILE__) + '/../test_helper'
3 class ChangesetTest < ActiveSupport::TestCase
6 def test_changeset_count
7 assert_equal 7, Changeset.count
10 def test_xml_from_id_zero
11 id_list = ["", "0", "00", "0.0", "a"]
13 zero_id = "<osm><changeset id='#{id}' /></osm>"
14 assert_nothing_raised(OSM::APIBadUserInput) {
15 Changeset.from_xml(zero_id, true)
17 message_update = assert_raise(OSM::APIBadUserInput) {
18 Changeset.from_xml(zero_id, false)
20 assert_match /ID of changeset cannot be zero when updating/, message_update.message
24 def test_from_xml_no_text
26 message_create = assert_raise(OSM::APIBadXMLError) {
27 Changeset.from_xml(no_text, true)
29 assert_match /Must specify a string with one or more characters/, message_create.message
30 message_update = assert_raise(OSM::APIBadXMLError) {
31 Changeset.from_xml(no_text, false)
33 assert_match /Must specify a string with one or more characters/, message_update.message
36 def test_from_xml_no_changeset
38 message_create = assert_raise(OSM::APIBadXMLError) {
39 Changeset.from_xml(nocs, true)
41 assert_match /XML doesn't contain an osm\/changeset element/, message_create.message
42 message_update = assert_raise(OSM::APIBadXMLError) {
43 Changeset.from_xml(nocs, false)
45 assert_match /XML doesn't contain an osm\/changeset element/, message_update.message
48 def test_from_xml_no_k_v
49 nokv = "<osm><changeset><tag /></changeset></osm>"
50 message_create = assert_raise(OSM::APIBadXMLError) {
51 Changeset.from_xml(nokv, true)
53 assert_match /tag is missing key/, message_create.message
54 message_update = assert_raise(OSM::APIBadXMLError) {
55 Changeset.from_xml(nokv, false)
57 assert_match /tag is missing key/, message_create.message
60 def test_from_xml_no_v
61 no_v = "<osm><changeset id='1'><tag k='key' /></changeset></osm>"
62 message_create = assert_raise(OSM::APIBadXMLError) {
63 Changeset.from_xml(no_v, true)
65 assert_match /tag is missing value/, message_create.message
66 message_update = assert_raise(OSM::APIBadXMLError) {
67 Changeset.from_xml(no_v, false)
69 assert_match /tag is missing value/, message_update.message
72 def test_from_xml_duplicate_k
73 dupk = "<osm><changeset id='1'><tag k='dup' v='test' /><tag k='dup' v='value' /></changeset></osm>"
74 message_create = assert_raise(OSM::APIDuplicateTagsError) {
75 Changeset.from_xml(dupk, true)
77 assert_equal "Element changeset/ has duplicate tags with key dup", message_create.message
78 message_update = assert_raise(OSM::APIDuplicateTagsError) {
79 Changeset.from_xml(dupk, false)
81 assert_equal "Element changeset/1 has duplicate tags with key dup", message_update.message