3 class OldNodeTest < ActiveSupport::TestCase
4 def test_node_too_far_north
5 node = build(:old_node, :latitude => 90.01 * OldNode::SCALE)
6 assert_equal false, node.valid?
9 def test_node_north_limit
10 node = build(:old_node, :latitude => 90 * OldNode::SCALE)
14 def test_node_too_far_south
15 node = build(:old_node, :latitude => -90.01 * OldNode::SCALE)
16 assert_equal false, node.valid?
19 def test_node_south_limit
20 node = build(:old_node, :latitude => -90 * OldNode::SCALE)
24 def test_node_too_far_west
25 node = build(:old_node, :longitude => -180.01 * OldNode::SCALE)
26 assert_equal false, node.valid?
29 def test_node_west_limit
30 node = build(:old_node, :longitude => -180 * OldNode::SCALE)
34 def test_node_too_far_east
35 node = build(:old_node, :longitude => 180.01 * OldNode::SCALE)
36 assert_equal false, node.valid?
39 def test_node_east_limit
40 node = build(:old_node, :longitude => 180 * OldNode::SCALE)
44 def test_totally_wrong
45 node = build(:old_node, :latitude => 200 * OldNode::SCALE, :longitude => 200 * OldNode::SCALE)
46 assert_equal false, node.valid?
50 node = build(:old_node, :latitude => 12.345 * OldNode::SCALE, :longitude => 34.567 * OldNode::SCALE)
52 assert_in_delta 12.345, node.lat, 0.0000001
53 assert_in_delta 34.567, node.lon, 0.0000001
58 assert_in_delta 54.321 * OldNode::SCALE, node.latitude, 0.000001
59 assert_in_delta 76.543 * OldNode::SCALE, node.longitude, 0.000001
62 # Ensure the lat/lon is formatted as a decimal e.g. not 4.0e-05
63 def test_lat_lon_xml_format
64 old_node = build(:old_node, :latitude => 0.00004 * OldNode::SCALE, :longitude => 0.00008 * OldNode::SCALE)
66 assert_match /lat="0.0000400"/, old_node.to_xml.to_s
67 assert_match /lon="0.0000800"/, old_node.to_xml.to_s
71 node_v1 = create(:old_node, :version => 1)
72 node_v2 = create(:old_node, :node_id => node_v1.node_id, :version => 2)
73 node_v3 = create(:old_node, :node_id => node_v1.node_id, :version => 3)
74 node_v4 = create(:old_node, :node_id => node_v1.node_id, :version => 4)
75 taglist_v3 = create_list(:old_node_tag, 3, :old_node => node_v3)
76 taglist_v4 = create_list(:old_node_tag, 2, :old_node => node_v4)
79 tags = OldNode.find(node.id).old_tags.order(:k)
80 assert_equal 0, tags.count
83 tags = OldNode.find(node.id).old_tags.order(:k)
84 assert_equal 0, tags.count
87 tags = OldNode.find(node.id).old_tags.order(:k)
88 assert_equal taglist_v3.count, tags.count
89 taglist_v3.sort_by!(&:k).each_index do |i|
90 assert_equal taglist_v3[i].k, tags[i].k
91 assert_equal taglist_v3[i].v, tags[i].v
95 tags = OldNode.find(node.id).old_tags.order(:k)
96 assert_equal taglist_v4.count, tags.count
97 taglist_v4.sort_by!(&:k).each_index do |i|
98 assert_equal taglist_v4[i].k, tags[i].k
99 assert_equal taglist_v4[i].v, tags[i].v
104 node_v1 = create(:old_node, :version => 1)
105 node_v2 = create(:old_node, :node_id => node_v1.node_id, :version => 2)
106 node_v3 = create(:old_node, :node_id => node_v1.node_id, :version => 3)
107 node_v4 = create(:old_node, :node_id => node_v1.node_id, :version => 4)
108 taglist_v3 = create_list(:old_node_tag, 3, :old_node => node_v3)
109 taglist_v4 = create_list(:old_node_tag, 2, :old_node => node_v4)
112 tags = OldNode.find(node.id).tags
113 assert_equal 0, tags.size
116 tags = OldNode.find(node.id).tags
117 assert_equal 0, tags.size
120 tags = OldNode.find(node.id).tags
121 assert_equal taglist_v3.count, tags.count
122 taglist_v3.each do |tag|
123 assert_equal tag.v, tags[tag.k]
127 tags = OldNode.find(node.id).tags
128 assert_equal taglist_v4.count, tags.count
129 taglist_v4.each do |tag|
130 assert_equal tag.v, tags[tag.k]