3 class BrowseControllerTest < ActionDispatch::IntegrationTest
5 # test all routes which lead to this controller
8 { :path => "/node/1", :method => :get },
9 { :controller => "browse", :action => "node", :id => "1" }
12 { :path => "/node/1/history", :method => :get },
13 { :controller => "browse", :action => "node_history", :id => "1" }
16 { :path => "/way/1", :method => :get },
17 { :controller => "browse", :action => "way", :id => "1" }
20 { :path => "/way/1/history", :method => :get },
21 { :controller => "browse", :action => "way_history", :id => "1" }
24 { :path => "/relation/1", :method => :get },
25 { :controller => "browse", :action => "relation", :id => "1" }
28 { :path => "/relation/1/history", :method => :get },
29 { :controller => "browse", :action => "relation_history", :id => "1" }
32 { :path => "/query", :method => :get },
33 { :controller => "browse", :action => "query" }
37 def test_read_relation
38 relation = create(:relation)
39 sidebar_browse_check :relation_path, relation.id, "browse/feature"
40 assert_select "h4", /^Version/ do
41 assert_select "a[href='#{old_relation_path relation, 1}']", :text => "1", :count => 1
43 assert_select ".secondary-actions a[href='#{api_relation_path relation}']", :count => 1
44 assert_select ".secondary-actions a[href='#{relation_history_path relation}']", :count => 1
45 assert_select ".secondary-actions a[href='#{old_relation_path relation, 1}']", :count => 0
48 def test_multiple_version_relation_links
49 relation = create(:relation, :with_history, :version => 2)
50 sidebar_browse_check :relation_path, relation.id, "browse/feature"
51 assert_select ".secondary-actions a[href='#{relation_history_path relation}']", :count => 1
52 assert_select ".secondary-actions a[href='#{old_relation_path relation, 1}']", :count => 1
53 assert_select ".secondary-actions a[href='#{old_relation_path relation, 2}']", :count => 1
56 def test_read_relation_history
57 relation = create(:relation, :with_history)
58 sidebar_browse_check :relation_history_path, relation.id, "browse/history"
59 assert_select "h4", /^Version/ do
60 assert_select "a[href='#{old_relation_path relation, 1}']", :text => "1", :count => 1
66 sidebar_browse_check :way_path, way.id, "browse/feature"
67 assert_select "h4", /^Version/ do
68 assert_select "a[href='#{old_way_path way, 1}']", :text => "1", :count => 1
70 assert_select ".secondary-actions a[href='#{api_way_path way}']", :count => 1
71 assert_select ".secondary-actions a[href='#{way_history_path way}']", :count => 1
72 assert_select ".secondary-actions a[href='#{old_way_path way, 1}']", :count => 0
75 def test_multiple_version_way_links
76 way = create(:way, :with_history, :version => 2)
77 sidebar_browse_check :way_path, way.id, "browse/feature"
78 assert_select ".secondary-actions a[href='#{way_history_path way}']", :count => 1
79 assert_select ".secondary-actions a[href='#{old_way_path way, 1}']", :count => 1
80 assert_select ".secondary-actions a[href='#{old_way_path way, 2}']", :count => 1
83 def test_read_way_history
84 way = create(:way, :with_history)
85 sidebar_browse_check :way_history_path, way.id, "browse/history"
86 assert_select "h4", /^Version/ do
87 assert_select "a[href='#{old_way_path way, 1}']", :text => "1", :count => 1
93 sidebar_browse_check :node_path, node.id, "browse/feature"
94 assert_select "h4", /^Version/ do
95 assert_select "a[href='#{old_node_path node, 1}']", :text => "1", :count => 1
97 assert_select ".secondary-actions a[href='#{api_node_path node}']", :count => 1
98 assert_select ".secondary-actions a[href='#{node_history_path node}']", :count => 1
99 assert_select ".secondary-actions a[href='#{old_node_path node, 1}']", :count => 0
102 def test_multiple_version_node_links
103 node = create(:node, :with_history, :version => 2)
104 sidebar_browse_check :node_path, node.id, "browse/feature"
105 assert_select ".secondary-actions a[href='#{node_history_path node}']", :count => 1
106 assert_select ".secondary-actions a[href='#{old_node_path node, 1}']", :count => 1
107 assert_select ".secondary-actions a[href='#{old_node_path node, 2}']", :count => 1
110 def test_read_deleted_node
111 node = create(:node, :visible => false)
112 sidebar_browse_check :node_path, node.id, "browse/feature"
113 assert_select "h4", /^Version/ do
114 assert_select "a[href='#{old_node_path node, 1}']", :text => "1", :count => 1
116 assert_select "a[href='#{api_node_path node}']", :count => 0
119 def test_read_node_history
120 node = create(:node, :with_history)
121 sidebar_browse_check :node_history_path, node.id, "browse/history"
122 assert_select "h4", /^Version/ do
123 assert_select "a[href='#{old_node_path node, 1}']", :text => "1", :count => 1
128 # Methods to check redaction.
130 # note that these are presently highly reliant on the structure of the
131 # page for the selection tests, which doesn't work out particularly
132 # well if that structure changes. so... if you change the page layout
133 # then please make it more easily (and robustly) testable!
135 def test_redacted_node
136 node = create(:node, :with_history, :deleted, :version => 2)
137 node_v1 = node.old_nodes.find_by(:version => 1)
138 node_v1.redact!(create(:redaction))
140 get node_path(:id => node)
141 assert_response :success
142 assert_template "feature"
144 # check that we don't show lat/lon for a redacted node.
145 assert_select ".browse-section", 1
146 assert_select ".browse-section.browse-node", 1
147 assert_select ".browse-section.browse-node .latitude", 0
148 assert_select ".browse-section.browse-node .longitude", 0
151 def test_redacted_node_history
152 node = create(:node, :with_history, :deleted, :version => 2)
153 node_v1 = node.old_nodes.find_by(:version => 1)
154 node_v1.redact!(create(:redaction))
156 get node_history_path(:id => node)
157 assert_response :success
158 assert_template "browse/history"
160 # there are 2 revisions of the redacted node, but only one
161 # should be showing details here.
162 assert_select ".browse-section", 2
163 assert_select ".browse-section.browse-redacted", 1
164 assert_select ".browse-section.browse-node", 1
165 assert_select ".browse-section.browse-node .latitude", 0
166 assert_select ".browse-section.browse-node .longitude", 0
169 def test_redacted_way_history
170 way = create(:way, :with_history, :version => 4)
171 way_v1 = way.old_ways.find_by(:version => 1)
172 way_v1.redact!(create(:redaction))
173 way_v3 = way.old_ways.find_by(:version => 3)
174 way_v3.redact!(create(:redaction))
176 get way_history_path(:id => way)
177 assert_response :success
178 assert_template "browse/history"
180 # there are 4 revisions of the redacted way, but only 2
181 # should be showing details here.
182 assert_select ".browse-section", 4
183 assert_select ".browse-section.browse-redacted", 2
184 assert_select ".browse-section.browse-way", 2
187 def test_redacted_relation_history
188 relation = create(:relation, :with_history, :version => 4)
189 relation_v1 = relation.old_relations.find_by(:version => 1)
190 relation_v1.redact!(create(:redaction))
191 relation_v3 = relation.old_relations.find_by(:version => 3)
192 relation_v3.redact!(create(:redaction))
194 get relation_history_path(:id => relation)
195 assert_response :success
196 assert_template "browse/history"
198 # there are 4 revisions of the redacted relation, but only 2
199 # should be showing details here.
200 assert_select ".browse-section", 4
201 assert_select ".browse-section.browse-redacted", 2
202 assert_select ".browse-section.browse-relation", 2
207 assert_response :success
208 assert_template "browse/query"