3 class RelationTest < ActiveSupport::TestCase
6 def test_relation_count
7 assert_equal 8, 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
106 def test_relation_members
107 relation = current_relations(:relation_with_versions)
108 members = Relation.find(relation.id).relation_members
109 assert_equal 3, members.count
110 assert_equal "some node", members[0].member_role
111 assert_equal "Node", members[0].member_type
112 assert_equal 15, members[0].member_id
113 assert_equal "some way", members[1].member_role
114 assert_equal "Way", members[1].member_type
115 assert_equal 4, members[1].member_id
116 assert_equal "some relation", members[2].member_role
117 assert_equal "Relation", members[2].member_type
118 assert_equal 7, members[2].member_id
122 relation = current_relations(:relation_with_versions)
123 members = Relation.find(relation.id).members
124 assert_equal 3, members.count
125 assert_equal ["Node", 15, "some node"], members[0]
126 assert_equal ["Way", 4, "some way"], members[1]
127 assert_equal ["Relation", 7, "some relation"], members[2]
130 def test_relation_tags
131 relation = current_relations(:relation_with_versions)
132 tags = Relation.find(relation.id).relation_tags.order(:k)
133 assert_equal 2, tags.count
134 assert_equal "testing", tags[0].k
135 assert_equal "added in relation version 3", tags[0].v
136 assert_equal "testing two", tags[1].k
137 assert_equal "modified in relation version 4", tags[1].v
141 relation = current_relations(:relation_with_versions)
142 tags = Relation.find(relation.id).tags
143 assert_equal 2, tags.size
144 assert_equal "added in relation version 3", tags["testing"]
145 assert_equal "modified in relation version 4", tags["testing two"]
148 def test_containing_relation_members
149 relation = current_relations(:used_relation)
150 crm = Relation.find(relation.id).containing_relation_members.order(:relation_id)
151 # assert_equal 1, crm.size
152 assert_equal 1, crm.first.relation_id
153 assert_equal "Relation", crm.first.member_type
154 assert_equal relation.id, crm.first.member_id
155 assert_equal 1, crm.first.relation.id
158 def test_containing_relations
159 relation = current_relations(:used_relation)
160 cr = Relation.find(relation.id).containing_relations.order(:id)
161 assert_equal 1, cr.size
162 assert_equal 1, cr.first.id