3 class OldNodeTest < ActiveSupport::TestCase
 
   4   def test_node_too_far_north
 
   5     node = build(:old_node, :latitude => 90.01 * OldNode::SCALE)
 
   7     assert_includes node.errors.full_messages, "Node is not in the world"
 
  10   def test_node_north_limit
 
  11     node = build(:old_node, :latitude => 90 * OldNode::SCALE)
 
  13     assert_not_includes node.errors.full_messages, "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_includes node.errors.full_messages, "Node is not in the world"
 
  22   def test_node_south_limit
 
  23     node = build(:old_node, :latitude => -90 * OldNode::SCALE)
 
  25     assert_not_includes node.errors.full_messages, "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_includes node.errors.full_messages, "Node is not in the world"
 
  34   def test_node_west_limit
 
  35     node = build(:old_node, :longitude => -180 * OldNode::SCALE)
 
  37     assert_not_includes node.errors.full_messages, "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_includes node.errors.full_messages, "Node is not in the world"
 
  46   def test_node_east_limit
 
  47     node = build(:old_node, :longitude => 180 * OldNode::SCALE)
 
  49     assert_not_includes node.errors.full_messages, "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_includes node.errors.full_messages, "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
 
  72     node_v1 = create(:old_node, :version => 1)
 
  73     node_v2 = create(:old_node, :node_id => node_v1.node_id, :version => 2)
 
  74     node_v3 = create(:old_node, :node_id => node_v1.node_id, :version => 3)
 
  75     node_v4 = create(:old_node, :node_id => node_v1.node_id, :version => 4)
 
  76     taglist_v3 = create_list(:old_node_tag, 3, :old_node => node_v3)
 
  77     taglist_v4 = create_list(:old_node_tag, 2, :old_node => node_v4)
 
  80     tags = OldNode.find(node.id).old_tags.order(:k)
 
  81     assert_equal 0, tags.count
 
  84     tags = OldNode.find(node.id).old_tags.order(:k)
 
  85     assert_equal 0, tags.count
 
  88     tags = OldNode.find(node.id).old_tags.order(:k)
 
  89     assert_equal taglist_v3.count, tags.count
 
  90     taglist_v3.sort_by!(&:k).each_index do |i|
 
  91       assert_equal taglist_v3[i].k, tags[i].k
 
  92       assert_equal taglist_v3[i].v, tags[i].v
 
  96     tags = OldNode.find(node.id).old_tags.order(:k)
 
  97     assert_equal taglist_v4.count, tags.count
 
  98     taglist_v4.sort_by!(&:k).each_index do |i|
 
  99       assert_equal taglist_v4[i].k, tags[i].k
 
 100       assert_equal taglist_v4[i].v, tags[i].v
 
 105     node_v1 = create(:old_node, :version => 1)
 
 106     node_v2 = create(:old_node, :node_id => node_v1.node_id, :version => 2)
 
 107     node_v3 = create(:old_node, :node_id => node_v1.node_id, :version => 3)
 
 108     node_v4 = create(:old_node, :node_id => node_v1.node_id, :version => 4)
 
 109     taglist_v3 = create_list(:old_node_tag, 3, :old_node => node_v3)
 
 110     taglist_v4 = create_list(:old_node_tag, 2, :old_node => node_v4)
 
 113     tags = OldNode.find(node.id).tags
 
 114     assert_equal 0, tags.size
 
 117     tags = OldNode.find(node.id).tags
 
 118     assert_equal 0, tags.size
 
 121     tags = OldNode.find(node.id).tags
 
 122     assert_equal taglist_v3.count, tags.count
 
 123     taglist_v3.each do |tag|
 
 124       assert_equal tag.v, tags[tag.k]
 
 128     tags = OldNode.find(node.id).tags
 
 129     assert_equal taglist_v4.count, tags.count
 
 130     taglist_v4.each do |tag|
 
 131       assert_equal tag.v, tags[tag.k]