]> git.openstreetmap.org Git - rails.git/blob - test/models/old_way_test.rb
Create an old_way factory, and start using it for tests.
[rails.git] / test / models / old_way_test.rb
1 require "test_helper"
2
3 class OldWayTest < ActiveSupport::TestCase
4   api_fixtures
5
6   def test_old_nodes
7     way = ways(:way_with_multiple_nodes_v1)
8     nodes = OldWay.find(way.id).old_nodes.order(:sequence_id)
9     assert_equal 2, nodes.count
10     assert_equal 2, nodes[0].node_id
11     assert_equal 6, nodes[1].node_id
12
13     way = ways(:way_with_multiple_nodes_v2)
14     nodes = OldWay.find(way.id).old_nodes.order(:sequence_id)
15     assert_equal 3, nodes.count
16     assert_equal 4, nodes[0].node_id
17     assert_equal 15, nodes[1].node_id
18     assert_equal 6, nodes[2].node_id
19   end
20
21   def test_nds
22     way = ways(:way_with_multiple_nodes_v1)
23     nodes = OldWay.find(way.id).nds
24     assert_equal 2, nodes.count
25     assert_equal 2, nodes[0]
26     assert_equal 6, nodes[1]
27
28     way = ways(:way_with_multiple_nodes_v2)
29     nodes = OldWay.find(way.id).nds
30     assert_equal 3, nodes.count
31     assert_equal 4, nodes[0]
32     assert_equal 15, nodes[1]
33     assert_equal 6, nodes[2]
34   end
35
36   def test_way_tags
37     old_way_v1 = create(:old_way, :version => 1)
38     old_way_v2 = create(:old_way, :current_way => old_way_v1.current_way, :version => 2)
39     old_way_v3 = create(:old_way, :current_way => old_way_v1.current_way, :version => 3)
40     old_way_v4 = create(:old_way, :current_way => old_way_v1.current_way, :version => 4)
41     taglist_v3 = create_list(:old_way_tag, 3, :old_way => old_way_v3)
42     taglist_v4 = create_list(:old_way_tag, 2, :old_way => old_way_v4)
43
44     tags = OldWay.find(old_way_v1.id).old_tags.order(:k)
45     assert_equal 0, tags.count
46
47     tags = OldWay.find(old_way_v2.id).old_tags.order(:k)
48     assert_equal 0, tags.count
49
50     tags = OldWay.find(old_way_v3.id).old_tags.order(:k)
51     assert_equal taglist_v3.count, tags.count
52     taglist_v3.sort_by!(&:k).each_index do |i|
53       assert_equal taglist_v3[i].k, tags[i].k
54       assert_equal taglist_v3[i].v, tags[i].v
55     end
56
57     tags = OldWay.find(old_way_v4.id).old_tags.order(:k)
58     assert_equal taglist_v4.count, tags.count
59     taglist_v4.sort_by!(&:k).each_index do |i|
60       assert_equal taglist_v4[i].k, tags[i].k
61       assert_equal taglist_v4[i].v, tags[i].v
62     end
63   end
64
65   def test_tags
66     old_way_v1 = create(:old_way, :version => 1)
67     old_way_v2 = create(:old_way, :current_way => old_way_v1.current_way, :version => 2)
68     old_way_v3 = create(:old_way, :current_way => old_way_v1.current_way, :version => 3)
69     old_way_v4 = create(:old_way, :current_way => old_way_v1.current_way, :version => 4)
70     taglist_v3 = create_list(:old_way_tag, 3, :old_way => old_way_v3)
71     taglist_v4 = create_list(:old_way_tag, 2, :old_way => old_way_v4)
72
73     tags = OldWay.find(old_way_v1.id).tags
74     assert_equal 0, tags.size
75
76     tags = OldWay.find(old_way_v2.id).tags
77     assert_equal 0, tags.size
78
79     tags = OldWay.find(old_way_v3.id).tags
80     assert_equal taglist_v3.count, tags.count
81     taglist_v3.each do |tag|
82       assert_equal tag.v, tags[tag.k]
83     end
84
85     tags = OldWay.find(old_way_v4.id).tags
86     assert_equal taglist_v4.count, tags.count
87     taglist_v4.each do |tag|
88       assert_equal tag.v, tags[tag.k]
89     end
90   end
91
92   def test_get_nodes_undelete
93     way = ways(:way_with_versions_v3)
94     node_tag = create(:node_tag, :node => current_nodes(:node_with_versions))
95     node_tag2 = create(:node_tag, :node => current_nodes(:used_node_1))
96     nodes = OldWay.find(way.id).get_nodes_undelete
97     assert_equal 2, nodes.size
98     assert_equal [1.0, 1.0, 15, 4, { node_tag.k => node_tag.v }, true], nodes[0]
99     assert_equal [3.0, 3.0, 3, 1, { node_tag2.k => node_tag2.v }, true], nodes[1]
100
101     way = ways(:way_with_redacted_versions_v2)
102     node_tag3 = create(:node_tag, :node => current_nodes(:invisible_node))
103     nodes = OldWay.find(way.id).get_nodes_undelete
104     assert_equal 2, nodes.size
105     assert_equal [3.0, 3.0, 3, 1, { node_tag2.k => node_tag2.v }, true], nodes[0]
106     assert_equal [2.0, 2.0, 2, 1, { node_tag3.k => node_tag3.v }, false], nodes[1]
107   end
108 end