]> git.openstreetmap.org Git - rails.git/blob - test/models/old_way_test.rb
Replace changeset_tags fixtures with a factory.
[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_db_count
7     assert_equal 14, OldWay.count
8   end
9
10   def test_old_nodes
11     way = ways(:way_with_multiple_nodes_v1)
12     nodes = OldWay.find(way.id).old_nodes.order(:sequence_id)
13     assert_equal 2, nodes.count
14     assert_equal 2, nodes[0].node_id
15     assert_equal 6, nodes[1].node_id
16
17     way = ways(:way_with_multiple_nodes_v2)
18     nodes = OldWay.find(way.id).old_nodes.order(:sequence_id)
19     assert_equal 3, nodes.count
20     assert_equal 4, nodes[0].node_id
21     assert_equal 15, nodes[1].node_id
22     assert_equal 6, nodes[2].node_id
23   end
24
25   def test_nds
26     way = ways(:way_with_multiple_nodes_v1)
27     nodes = OldWay.find(way.id).nds
28     assert_equal 2, nodes.count
29     assert_equal 2, nodes[0]
30     assert_equal 6, nodes[1]
31
32     way = ways(:way_with_multiple_nodes_v2)
33     nodes = OldWay.find(way.id).nds
34     assert_equal 3, nodes.count
35     assert_equal 4, nodes[0]
36     assert_equal 15, nodes[1]
37     assert_equal 6, nodes[2]
38   end
39
40   def test_way_tags
41     way = ways(:way_with_versions_v1)
42     tags = OldWay.find(way.id).old_tags.order(:k)
43     assert_equal 0, tags.count
44
45     way = ways(:way_with_versions_v2)
46     tags = OldWay.find(way.id).old_tags.order(:k)
47     assert_equal 0, tags.count
48
49     way = ways(:way_with_versions_v3)
50     tags = OldWay.find(way.id).old_tags.order(:k)
51     assert_equal 3, tags.count
52     assert_equal "testing", tags[0].k
53     assert_equal "added in way version 3", tags[0].v
54     assert_equal "testing three", tags[1].k
55     assert_equal "added in way version 3", tags[1].v
56     assert_equal "testing two", tags[2].k
57     assert_equal "added in way version 3", tags[2].v
58
59     way = ways(:way_with_versions_v4)
60     tags = OldWay.find(way.id).old_tags.order(:k)
61     assert_equal 2, tags.count
62     assert_equal "testing", tags[0].k
63     assert_equal "added in way version 3", tags[0].v
64     assert_equal "testing two", tags[1].k
65     assert_equal "modified in way version 4", tags[1].v
66   end
67
68   def test_tags
69     way = ways(:way_with_versions_v1)
70     tags = OldWay.find(way.id).tags
71     assert_equal 0, tags.size
72
73     way = ways(:way_with_versions_v2)
74     tags = OldWay.find(way.id).tags
75     assert_equal 0, tags.size
76
77     way = ways(:way_with_versions_v3)
78     tags = OldWay.find(way.id).tags
79     assert_equal 3, tags.size
80     assert_equal "added in way version 3", tags["testing"]
81     assert_equal "added in way version 3", tags["testing two"]
82     assert_equal "added in way version 3", tags["testing three"]
83
84     way = ways(:way_with_versions_v4)
85     tags = OldWay.find(way.id).tags
86     assert_equal 2, tags.size
87     assert_equal "added in way version 3", tags["testing"]
88     assert_equal "modified in way version 4", tags["testing two"]
89   end
90
91   def test_get_nodes_undelete
92     way = ways(:way_with_versions_v3)
93     nodes = OldWay.find(way.id).get_nodes_undelete
94     assert_equal 2, nodes.size
95     assert_equal [1.0, 1.0, 15, 4, { "testing" => "added in node version 3", "testing two" => "modified in node version 4" }, true], nodes[0]
96     assert_equal [3.0, 3.0, 3, 1, { "test" => "yes" }, true], nodes[1]
97
98     way = ways(:way_with_redacted_versions_v2)
99     nodes = OldWay.find(way.id).get_nodes_undelete
100     assert_equal 2, nodes.size
101     assert_equal [3.0, 3.0, 3, 1, { "test" => "yes" }, true], nodes[0]
102     assert_equal [2.0, 2.0, 2, 1, { "testused" => "yes" }, false], nodes[1]
103   end
104 end