1 # frozen_string_literal: true
5 class OldNodeTest < ActiveSupport::TestCase
6 def test_node_too_far_north
7 node = build(:old_node, :latitude => 90.01 * OldNode::SCALE)
9 assert_includes node.errors.full_messages, "Node is not in the world"
12 def test_node_north_limit
13 node = build(:old_node, :latitude => 90 * OldNode::SCALE)
15 assert_not_includes node.errors.full_messages, "Node is not in the world"
18 def test_node_too_far_south
19 node = build(:old_node, :latitude => -90.01 * OldNode::SCALE)
21 assert_includes node.errors.full_messages, "Node is not in the world"
24 def test_node_south_limit
25 node = build(:old_node, :latitude => -90 * OldNode::SCALE)
27 assert_not_includes node.errors.full_messages, "Node is not in the world"
30 def test_node_too_far_west
31 node = build(:old_node, :longitude => -180.01 * OldNode::SCALE)
33 assert_includes node.errors.full_messages, "Node is not in the world"
36 def test_node_west_limit
37 node = build(:old_node, :longitude => -180 * OldNode::SCALE)
39 assert_not_includes node.errors.full_messages, "Node is not in the world"
42 def test_node_too_far_east
43 node = build(:old_node, :longitude => 180.01 * OldNode::SCALE)
45 assert_includes node.errors.full_messages, "Node is not in the world"
48 def test_node_east_limit
49 node = build(:old_node, :longitude => 180 * OldNode::SCALE)
51 assert_not_includes node.errors.full_messages, "Node is not in the world"
54 def test_totally_wrong
55 node = build(:old_node, :latitude => 200 * OldNode::SCALE, :longitude => 200 * OldNode::SCALE)
57 assert_includes node.errors.full_messages, "Node is not in the world"
61 node = build(:old_node, :latitude => 12.345 * OldNode::SCALE, :longitude => 34.567 * OldNode::SCALE)
63 assert_in_delta 12.345, node.lat, 0.0000001
64 assert_in_delta 34.567, node.lon, 0.0000001
69 assert_in_delta 54.321 * OldNode::SCALE, node.latitude, 0.000001
70 assert_in_delta 76.543 * OldNode::SCALE, node.longitude, 0.000001
74 node_v1 = create(:old_node, :version => 1)
75 node_v2 = create(:old_node, :node_id => node_v1.node_id, :version => 2)
76 node_v3 = create(:old_node, :node_id => node_v1.node_id, :version => 3)
77 node_v4 = create(:old_node, :node_id => node_v1.node_id, :version => 4)
78 taglist_v3 = create_list(:old_node_tag, 3, :old_node => node_v3)
79 taglist_v4 = create_list(:old_node_tag, 2, :old_node => node_v4)
82 tags = OldNode.find(node.id).old_tags.order(:k)
83 assert_equal 0, tags.count
86 tags = OldNode.find(node.id).old_tags.order(:k)
87 assert_equal 0, tags.count
90 tags = OldNode.find(node.id).old_tags.order(:k)
91 assert_equal taglist_v3.count, tags.count
92 taglist_v3.sort_by!(&:k).each_index do |i|
93 assert_equal taglist_v3[i].k, tags[i].k
94 assert_equal taglist_v3[i].v, tags[i].v
98 tags = OldNode.find(node.id).old_tags.order(:k)
99 assert_equal taglist_v4.count, tags.count
100 taglist_v4.sort_by!(&:k).each_index do |i|
101 assert_equal taglist_v4[i].k, tags[i].k
102 assert_equal taglist_v4[i].v, tags[i].v
107 node_v1 = create(:old_node, :version => 1)
108 node_v2 = create(:old_node, :node_id => node_v1.node_id, :version => 2)
109 node_v3 = create(:old_node, :node_id => node_v1.node_id, :version => 3)
110 node_v4 = create(:old_node, :node_id => node_v1.node_id, :version => 4)
111 taglist_v3 = create_list(:old_node_tag, 3, :old_node => node_v3)
112 taglist_v4 = create_list(:old_node_tag, 2, :old_node => node_v4)
115 tags = OldNode.find(node.id).tags
116 assert_equal 0, tags.size
119 tags = OldNode.find(node.id).tags
120 assert_equal 0, tags.size
123 tags = OldNode.find(node.id).tags
124 assert_equal taglist_v3.count, tags.count
125 taglist_v3.each do |tag|
126 assert_equal tag.v, tags[tag.k]
130 tags = OldNode.find(node.id).tags
131 assert_equal taglist_v4.count, tags.count
132 taglist_v4.each do |tag|
133 assert_equal tag.v, tags[tag.k]