1 require File.dirname(__FILE__) + '/../test_helper'
3 class WayTest < ActiveSupport::TestCase
6 # Check that we have the correct number of currnet ways in the db
7 # This will need to updated whenever the current_ways.yml is updated
9 assert_equal 4, Way.count
13 node = current_nodes(:used_node_1)
16 :used_way ].each do |way_symbol|
17 way = current_ways(way_symbol)
18 assert_equal node.bbox, way.bbox
22 # Check that the preconditions fail when you are over the defined limit of
23 # the maximum number of nodes in each way.
24 def test_max_nodes_per_way_limit
25 # Take one of the current ways and add nodes to it until we are near the limit
26 way = Way.find(current_ways(:visible_way).id)
28 # it already has 1 node
29 1.upto((APP_CONFIG['max_number_of_way_nodes']) / 2) {
30 way.add_nd_num(current_nodes(:used_node_1).id)
31 way.add_nd_num(current_nodes(:used_node_2).id)
36 way.add_nd_num(current_nodes(:visible_node).id)
40 def test_from_xml_no_id
41 noid = "<osm><way version='12' changeset='23' /></osm>"
42 assert_nothing_raised(OSM::APIBadXMLError) {
43 Way.from_xml(noid, true)
45 message = assert_raise(OSM::APIBadXMLError) {
46 Way.from_xml(noid, false)
48 assert_match /ID is required when updating/, message.message
51 def test_from_xml_no_changeset_id
52 nocs = "<osm><way id='123' version='23' /></osm>"
53 message_create = assert_raise(OSM::APIBadXMLError) {
54 Way.from_xml(nocs, true)
56 assert_match /Changeset id is missing/, message_create.message
57 message_update = assert_raise(OSM::APIBadXMLError) {
58 Way.from_xml(nocs, false)
60 assert_match /Changeset id is missing/, message_update.message
63 def test_from_xml_no_version
64 no_version = "<osm><way id='123' changeset='23' /></osm>"
65 assert_nothing_raised(OSM::APIBadXMLError) {
66 Way.from_xml(no_version, true)
68 message_update = assert_raise(OSM::APIBadXMLError) {
69 Way.from_xml(no_version, false)
71 assert_match /Version is required when updating/, message_update.message
74 def test_from_xml_id_zero
75 id_list = ["", "0", "00", "0.0", "a"]
77 zero_id = "<osm><way id='#{id}' changeset='33' version='23' /></osm>"
78 assert_nothing_raised(OSM::APIBadUserInput) {
79 Way.from_xml(zero_id, true)
81 message_update = assert_raise(OSM::APIBadUserInput) {
82 Way.from_xml(zero_id, false)
84 assert_match /ID of way cannot be zero when updating/, message_update.message
88 def test_from_xml_no_text
90 message_create = assert_raise(OSM::APIBadXMLError) {
91 Way.from_xml(no_text, true)
93 assert_match /Must specify a string with one or more characters/, message_create.message
94 message_update = assert_raise(OSM::APIBadXMLError) {
95 Way.from_xml(no_text, false)
97 assert_match /Must specify a string with one or more characters/, message_update.message
100 def test_from_xml_no_k_v
101 nokv = "<osm><way id='23' changeset='23' version='23'><tag /></way></osm>"
102 message_create = assert_raise(OSM::APIBadXMLError) {
103 Way.from_xml(nokv, true)
105 assert_match /tag is missing key/, message_create.message
106 message_update = assert_raise(OSM::APIBadXMLError) {
107 Way.from_xml(nokv, false)
109 assert_match /tag is missing key/, message_update.message
112 def test_from_xml_no_v
113 no_v = "<osm><way id='23' changeset='23' version='23'><tag k='key' /></way></osm>"
114 message_create = assert_raise(OSM::APIBadXMLError) {
115 Way.from_xml(no_v, true)
117 assert_match /tag is missing value/, message_create.message
118 message_update = assert_raise(OSM::APIBadXMLError) {
119 Way.from_xml(no_v, false)
121 assert_match /tag is missing value/, message_update.message
124 def test_from_xml_duplicate_k
125 dupk = "<osm><way id='23' changeset='23' version='23'><tag k='dup' v='test' /><tag k='dup' v='tester' /></way></osm>"
126 message_create = assert_raise(OSM::APIDuplicateTagsError) {
127 Way.from_xml(dupk, true)
129 assert_equal "Element way/ has duplicate tags with key dup", message_create.message
130 message_update = assert_raise(OSM::APIDuplicateTagsError) {
131 Way.from_xml(dupk, false)
133 assert_equal "Element way/23 has duplicate tags with key dup", message_update.message