1 require "application_system_test_case"
3 class ElementHistoryTest < ApplicationSystemTestCase
4 test "shows history of a node" do
5 node = create(:node, :with_history, :version => 2, :lat => 60, :lon => 30)
6 node_v1 = node.old_nodes.find_by(:version => 1)
7 node_v2 = node.old_nodes.find_by(:version => 2)
8 create(:old_node_tag, :old_node => node_v1, :k => "key", :v => "VALUE-ONE")
9 create(:old_node_tag, :old_node => node_v2, :k => "key", :v => "VALUE-TWO")
10 node_v1.update(:lat => 59, :lon => 29)
12 visit node_history_path(node)
15 v2_heading = find :element, "h4", :text => "Version #2"
16 v1_heading = find :element, "h4", :text => "Version #1", :below => v2_heading
18 assert_css "td", :text => "VALUE-TWO", :below => v2_heading, :above => v1_heading
19 assert_css "td", :text => "VALUE-ONE", :below => v1_heading
20 assert_text(/Location: 60\.\d+, 30\.\d+/)
21 assert_text(/Location: 59\.\d+, 29\.\d+/)
23 assert_link "View Details", :href => node_path(node)
24 assert_no_link "View History"
25 assert_no_link "View Unredacted History"
29 test "shows history of a node to a regular user" do
30 node = create(:node, :with_history)
32 visit node_history_path(node)
35 assert_link "View Details", :href => node_path(node)
36 assert_no_link "View History"
37 assert_no_link "View Unredacted History"
41 test "shows history of a node with one redacted version" do
42 node = create(:node, :with_history, :version => 2, :lat => 60, :lon => 30)
43 node_v1 = node.old_nodes.find_by(:version => 1)
44 node_v2 = node.old_nodes.find_by(:version => 2)
45 create(:old_node_tag, :old_node => node_v1, :k => "key", :v => "VALUE-ONE")
46 create(:old_node_tag, :old_node => node_v2, :k => "key", :v => "VALUE-TWO")
47 node_v1.update(:lat => 59, :lon => 29)
48 node_v1.redact!(create(:redaction))
50 visit node_history_path(node)
53 assert_css "h4", :text => "Version #2"
54 assert_css "td", :text => "VALUE-TWO"
55 assert_no_css "td", :text => "VALUE-ONE"
56 assert_text(/Location: 60\.\d+, 30\.\d+/)
57 assert_no_text(/Location: 59\.\d+, 29\.\d+/)
58 assert_text "Version 1 of this node cannot be shown"
60 assert_link "View Details", :href => node_path(node)
61 assert_no_link "View History"
62 assert_no_link "View Unredacted History"
66 test "shows history of a node with one redacted version to a moderator" do
67 node = create(:node, :with_history, :version => 2, :lat => 60, :lon => 30)
68 node_v1 = node.old_nodes.find_by(:version => 1)
69 node_v2 = node.old_nodes.find_by(:version => 2)
70 create(:old_node_tag, :old_node => node_v1, :k => "key", :v => "VALUE-ONE")
71 create(:old_node_tag, :old_node => node_v2, :k => "key", :v => "VALUE-TWO")
72 node_v1.update(:lat => 59, :lon => 29)
73 node_v1.redact!(create(:redaction))
75 sign_in_as(create(:moderator_user))
76 visit node_history_path(node)
79 assert_css "td", :text => "VALUE-TWO"
80 assert_no_css "td", :text => "VALUE-ONE"
81 assert_text(/Location: 60\.\d+, 30\.\d+/)
82 assert_no_text(/Location: 59\.\d+, 29\.\d+/)
83 assert_text "Version 1 of this node cannot be shown"
85 assert_link "View Details", :href => node_path(node)
86 assert_no_link "View History"
87 assert_link "View Unredacted History"
89 click_on "View Unredacted History"
91 assert_css "td", :text => "VALUE-TWO"
92 assert_css "td", :text => "VALUE-ONE"
93 assert_text(/Location: 60\.\d+, 30\.\d+/)
94 assert_text(/Location: 59\.\d+, 29\.\d+/)
95 assert_no_text "Version 1 of this node cannot be shown"
97 assert_link "View Details", :href => node_path(node)
98 assert_link "View History"
99 assert_no_link "View Unredacted History"
101 click_on "View History"
103 assert_text "Version 1 of this node cannot be shown"
107 test "can view node history pages" do
108 node = create(:node, :with_history, :version => 41)
110 visit node_path(node)
112 check_element_history_pages(->(v) { old_node_path(node, v) })
115 test "can view way history pages" do
116 way = create(:way, :with_history, :version => 41)
120 check_element_history_pages(->(v) { old_way_path(way, v) })
123 test "can view relation history pages" do
124 relation = create(:relation, :with_history, :version => 41)
126 visit relation_path(relation)
128 check_element_history_pages(->(v) { old_relation_path(relation, v) })
133 def check_element_history_pages(get_path)
135 click_on "View History"
138 assert_link v.to_s, :href => get_path.call(v)
141 click_on "Older Versions"
144 assert_link v.to_s, :href => get_path.call(v)
147 click_on "Older Versions"
150 assert_link v.to_s, :href => get_path.call(v)
153 assert_no_link "Older Versions"