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, :create => 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, :create => 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, :create => 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, :create => 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, :create => true)
33 assert_match(/tag is missing key/, message_create.message)
34 message_update = assert_raise(OSM::APIBadXMLError) do
35 Changeset.from_xml(nokv, :create => 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, :create => 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, :create => 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, :create => 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, :create => 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, :create => false)
70 assert_nothing_raised do
71 Changeset.from_xml(xml, :create => true)
76 changeset = create(:changeset)
79 assert_not changeset.subscribed?(user)
81 changeset.subscribe(user)
82 assert changeset.subscribed?(user)
84 changeset.unsubscribe(changeset.subscribers.first)
85 assert_not changeset.subscribed?(user)