1 require File.dirname(__FILE__) + '/../test_helper'
3 class RelationTest < ActiveSupport::TestCase
6 def test_relation_count
7 assert_equal 6, Relation.count
10 def test_from_xml_no_id
11 noid = "<osm><relation version='12' changeset='23' /></osm>"
12 assert_nothing_raised(OSM::APIBadXMLError) {
13 Relation.from_xml(noid, true)
15 message = assert_raise(OSM::APIBadXMLError) {
16 Relation.from_xml(noid, false)
18 assert_match /ID is required when updating/, message.message
21 def test_from_xml_no_changeset_id
22 nocs = "<osm><relation id='123' version='12' /></osm>"
23 message_create = assert_raise(OSM::APIBadXMLError) {
24 Relation.from_xml(nocs, true)
26 assert_match /Changeset id is missing/, message_create.message
27 message_update = assert_raise(OSM::APIBadXMLError) {
28 Relation.from_xml(nocs, false)
30 assert_match /Changeset id is missing/, message_update.message
33 def test_from_xml_no_version
34 no_version = "<osm><relation id='123' changeset='23' /></osm>"
35 assert_nothing_raised(OSM::APIBadXMLError) {
36 Relation.from_xml(no_version, true)
38 message_update = assert_raise(OSM::APIBadXMLError) {
39 Relation.from_xml(no_version, false)
41 assert_match /Version is required when updating/, message_update.message
44 def test_from_xml_id_zero
45 id_list = ["", "0", "00", "0.0", "a"]
47 zero_id = "<osm><relation id='#{id}' changeset='332' version='23' /></osm>"
48 assert_nothing_raised(OSM::APIBadUserInput) {
49 Relation.from_xml(zero_id, true)
51 message_update = assert_raise(OSM::APIBadUserInput) {
52 Relation.from_xml(zero_id, false)
54 assert_match /ID of relation cannot be zero when updating/, message_update.message
58 def test_from_xml_no_text
60 message_create = assert_raise(OSM::APIBadXMLError) {
61 Relation.from_xml(no_text, true)
63 assert_match /Must specify a string with one or more characters/, message_create.message
64 message_update = assert_raise(OSM::APIBadXMLError) {
65 Relation.from_xml(no_text, false)
67 assert_match /Must specify a string with one or more characters/, message_update.message
70 def test_from_xml_no_k_v
71 nokv = "<osm><relation id='23' changeset='23' version='23'><tag /></relation></osm>"
72 message_create = assert_raise(OSM::APIBadXMLError) {
73 Relation.from_xml(nokv, true)
75 assert_match /tag is missing key/, message_create.message
76 message_update = assert_raise(OSM::APIBadXMLError) {
77 Relation.from_xml(nokv, false)
79 assert_match /tag is missing key/, message_update.message
82 def test_from_xml_no_v
83 no_v = "<osm><relation id='23' changeset='23' version='23'><tag k='key' /></relation></osm>"
84 message_create = assert_raise(OSM::APIBadXMLError) {
85 Relation.from_xml(no_v, true)
87 assert_match /tag is missing value/, message_create.message
88 message_update = assert_raise(OSM::APIBadXMLError) {
89 Relation.from_xml(no_v, false)
91 assert_match /tag is missing value/, message_update.message
94 def test_from_xml_duplicate_k
95 dupk = "<osm><relation id='23' changeset='23' version='23'><tag k='dup' v='test'/><tag k='dup' v='tester'/></relation></osm>"
96 message_create = assert_raise(OSM::APIDuplicateTagsError) {
97 Relation.from_xml(dupk, true)
99 assert_equal "Element relation/ has duplicate tags with key dup", message_create.message
100 message_update = assert_raise(OSM::APIDuplicateTagsError) {
101 Relation.from_xml(dupk, false)
103 assert_equal "Element relation/23 has duplicate tags with key dup", message_update.message