3 class OldNodeTest < ActiveSupport::TestCase
4 def test_node_too_far_north
5 node = build(:old_node, :latitude => 90.01 * OldNode::SCALE)
7 assert node.errors.full_messages.include?("Node is not in the world")
10 def test_node_north_limit
11 node = build(:old_node, :latitude => 90 * OldNode::SCALE)
13 assert_equal false, node.errors.full_messages.include?("Node is not in the world")
16 def test_node_too_far_south
17 node = build(:old_node, :latitude => -90.01 * OldNode::SCALE)
19 assert node.errors.full_messages.include?("Node is not in the world")
22 def test_node_south_limit
23 node = build(:old_node, :latitude => -90 * OldNode::SCALE)
25 assert_equal false, node.errors.full_messages.include?("Node is not in the world")
28 def test_node_too_far_west
29 node = build(:old_node, :longitude => -180.01 * OldNode::SCALE)
31 assert node.errors.full_messages.include?("Node is not in the world")
34 def test_node_west_limit
35 node = build(:old_node, :longitude => -180 * OldNode::SCALE)
37 assert_equal false, node.errors.full_messages.include?("Node is not in the world")
40 def test_node_too_far_east
41 node = build(:old_node, :longitude => 180.01 * OldNode::SCALE)
43 assert node.errors.full_messages.include?("Node is not in the world")
46 def test_node_east_limit
47 node = build(:old_node, :longitude => 180 * OldNode::SCALE)
49 assert_equal false, node.errors.full_messages.include?("Node is not in the world")
52 def test_totally_wrong
53 node = build(:old_node, :latitude => 200 * OldNode::SCALE, :longitude => 200 * OldNode::SCALE)
55 assert node.errors.full_messages.include?("Node is not in the world")
59 node = build(:old_node, :latitude => 12.345 * OldNode::SCALE, :longitude => 34.567 * OldNode::SCALE)
61 assert_in_delta 12.345, node.lat, 0.0000001
62 assert_in_delta 34.567, node.lon, 0.0000001
67 assert_in_delta 54.321 * OldNode::SCALE, node.latitude, 0.000001
68 assert_in_delta 76.543 * OldNode::SCALE, node.longitude, 0.000001
71 # Ensure the lat/lon is formatted as a decimal e.g. not 4.0e-05
72 def test_lat_lon_xml_format
73 old_node = build(:old_node, :latitude => 0.00004 * OldNode::SCALE, :longitude => 0.00008 * OldNode::SCALE)
75 assert_match(/lat="0.0000400"/, old_node.to_xml.to_s)
76 assert_match(/lon="0.0000800"/, old_node.to_xml.to_s)
80 node_v1 = create(:old_node, :version => 1)
81 node_v2 = create(:old_node, :node_id => node_v1.node_id, :version => 2)
82 node_v3 = create(:old_node, :node_id => node_v1.node_id, :version => 3)
83 node_v4 = create(:old_node, :node_id => node_v1.node_id, :version => 4)
84 taglist_v3 = create_list(:old_node_tag, 3, :old_node => node_v3)
85 taglist_v4 = create_list(:old_node_tag, 2, :old_node => node_v4)
88 tags = OldNode.find(node.id).old_tags.order(:k)
89 assert_equal 0, tags.count
92 tags = OldNode.find(node.id).old_tags.order(:k)
93 assert_equal 0, tags.count
96 tags = OldNode.find(node.id).old_tags.order(:k)
97 assert_equal taglist_v3.count, tags.count
98 taglist_v3.sort_by!(&:k).each_index do |i|
99 assert_equal taglist_v3[i].k, tags[i].k
100 assert_equal taglist_v3[i].v, tags[i].v
104 tags = OldNode.find(node.id).old_tags.order(:k)
105 assert_equal taglist_v4.count, tags.count
106 taglist_v4.sort_by!(&:k).each_index do |i|
107 assert_equal taglist_v4[i].k, tags[i].k
108 assert_equal taglist_v4[i].v, tags[i].v
113 node_v1 = create(:old_node, :version => 1)
114 node_v2 = create(:old_node, :node_id => node_v1.node_id, :version => 2)
115 node_v3 = create(:old_node, :node_id => node_v1.node_id, :version => 3)
116 node_v4 = create(:old_node, :node_id => node_v1.node_id, :version => 4)
117 taglist_v3 = create_list(:old_node_tag, 3, :old_node => node_v3)
118 taglist_v4 = create_list(:old_node_tag, 2, :old_node => node_v4)
121 tags = OldNode.find(node.id).tags
122 assert_equal 0, tags.size
125 tags = OldNode.find(node.id).tags
126 assert_equal 0, tags.size
129 tags = OldNode.find(node.id).tags
130 assert_equal taglist_v3.count, tags.count
131 taglist_v3.each do |tag|
132 assert_equal tag.v, tags[tag.k]
136 tags = OldNode.find(node.id).tags
137 assert_equal taglist_v4.count, tags.count
138 taglist_v4.each do |tag|
139 assert_equal tag.v, tags[tag.k]