2 require "browse_controller"
4 class BrowseControllerTest < ActionController::TestCase
8 # test all routes which lead to this controller
11 { :path => "/node/1", :method => :get },
12 { :controller => "browse", :action => "node", :id => "1" }
15 { :path => "/node/1/history", :method => :get },
16 { :controller => "browse", :action => "node_history", :id => "1" }
19 { :path => "/way/1", :method => :get },
20 { :controller => "browse", :action => "way", :id => "1" }
23 { :path => "/way/1/history", :method => :get },
24 { :controller => "browse", :action => "way_history", :id => "1" }
27 { :path => "/relation/1", :method => :get },
28 { :controller => "browse", :action => "relation", :id => "1" }
31 { :path => "/relation/1/history", :method => :get },
32 { :controller => "browse", :action => "relation_history", :id => "1" }
35 { :path => "/changeset/1", :method => :get },
36 { :controller => "browse", :action => "changeset", :id => "1" }
39 { :path => "/note/1", :method => :get },
40 { :controller => "browse", :action => "note", :id => "1" }
43 { :path => "/note/new", :method => :get },
44 { :controller => "browse", :action => "new_note" }
48 def test_read_relation
49 browse_check "relation", relations(:visible_relation).relation_id, "browse/feature"
52 def test_read_relation_history
53 browse_check "relation_history", relations(:visible_relation).relation_id, "browse/history"
57 browse_check "way", ways(:visible_way).way_id, "browse/feature"
60 def test_read_way_history
61 browse_check "way_history", ways(:visible_way).way_id, "browse/history"
65 browse_check "node", create(:node).id, "browse/feature"
68 def test_read_node_history
69 browse_check "node_history", create(:node, :with_history).id, "browse/history"
72 def test_read_changeset
73 private_changeset = create(:changeset, :user => create(:user, :data_public => false))
74 changeset = create(:changeset)
75 browse_check "changeset", private_changeset.id, "browse/changeset"
76 browse_check "changeset", changeset.id, "browse/changeset"
79 def test_read_changeset_hidden_comments
80 changeset = create(:changeset)
81 create_list(:changeset_comment, 3, :changeset => changeset)
82 create(:changeset_comment, :visible => false, :changeset => changeset)
84 browse_check "changeset", changeset.id, "browse/changeset"
85 assert_select "div.changeset-comments ul li", :count => 3
87 session[:user] = create(:moderator_user).id
89 browse_check "changeset", changeset.id, "browse/changeset"
90 assert_select "div.changeset-comments ul li", :count => 4
94 open_note = create(:note_with_comments)
96 browse_check "note", open_note.id, "browse/note"
99 def test_read_hidden_note
100 hidden_note_with_comment = create(:note_with_comments, :status => "hidden")
102 get :note, :id => hidden_note_with_comment.id
103 assert_response :not_found
104 assert_template "browse/not_found"
105 assert_template :layout => "map"
107 xhr :get, :note, :id => hidden_note_with_comment.id
108 assert_response :not_found
109 assert_template "browse/not_found"
110 assert_template :layout => "xhr"
112 session[:user] = create(:moderator_user).id
114 browse_check "note", hidden_note_with_comment.id, "browse/note"
117 def test_read_note_hidden_comments
118 note_with_hidden_comment = create(:note_with_comments, :comments_count => 2) do |note|
119 create(:note_comment, :note => note, :visible => false)
122 browse_check "note", note_with_hidden_comment.id, "browse/note"
123 assert_select "div.note-comments ul li", :count => 1
125 session[:user] = create(:moderator_user).id
127 browse_check "note", note_with_hidden_comment.id, "browse/note"
128 assert_select "div.note-comments ul li", :count => 2
132 # Methods to check redaction.
134 # note that these are presently highly reliant on the structure of the
135 # page for the selection tests, which doesn't work out particularly
136 # well if that structure changes. so... if you change the page layout
137 # then please make it more easily (and robustly) testable!
139 def test_redacted_node
140 node = create(:node, :with_history, :deleted, :version => 2)
141 node_v1 = node.old_nodes.find_by(:version => 1)
142 node_v1.redact!(create(:redaction))
144 get :node, :id => node.id
145 assert_response :success
146 assert_template "feature"
148 # check that we don't show lat/lon for a redacted node.
149 assert_select ".browse-section", 1
150 assert_select ".browse-section.browse-node", 1
151 assert_select ".browse-section.browse-node .latitude", 0
152 assert_select ".browse-section.browse-node .longitude", 0
155 def test_redacted_node_history
156 node = create(:node, :with_history, :deleted, :version => 2)
157 node_v1 = node.old_nodes.find_by(:version => 1)
158 node_v1.redact!(create(:redaction))
160 get :node_history, :id => node.id
161 assert_response :success
162 assert_template "browse/history"
164 # there are 2 revisions of the redacted node, but only one
165 # should be showing details here.
166 assert_select ".browse-section", 2
167 assert_select ".browse-section.browse-redacted", 1
168 assert_select ".browse-section.browse-node", 1
169 assert_select ".browse-section.browse-node .latitude", 0
170 assert_select ".browse-section.browse-node .longitude", 0
173 def test_redacted_way_history
174 get :way_history, :id => ways(:way_with_redacted_versions_v1).way_id
175 assert_response :success
176 assert_template "browse/history"
178 # there are 4 revisions of the redacted way, but only 2
179 # should be showing details here.
180 assert_select ".browse-section", 4
181 assert_select ".browse-section.browse-redacted", 2
182 assert_select ".browse-section.browse-way", 2
185 def test_redacted_relation_history
186 get :relation_history, :id => relations(:relation_with_redacted_versions_v1).relation_id
187 assert_response :success
188 assert_template "browse/history"
190 # there are 4 revisions of the redacted relation, but only 2
191 # should be showing details here.
192 assert_select ".browse-section", 4
193 assert_select ".browse-section.browse-redacted", 2
194 assert_select ".browse-section.browse-relation", 2
199 # This is a convenience method for most of the above checks
200 # First we check that when we don't have an id, it will correctly return a 404
201 # then we check that we get the correct 404 when a non-existant id is passed
202 # then we check that it will get a successful response, when we do pass an id
203 def browse_check(type, id, template)
204 assert_raise ActionController::UrlGenerationError do
208 assert_raise ActionController::UrlGenerationError do
209 get type, :id => -10 # we won't have an id that's negative
213 assert_response :not_found
214 assert_template "browse/not_found"
215 assert_template :layout => "map"
217 xhr :get, type, :id => 0
218 assert_response :not_found
219 assert_template "browse/not_found"
220 assert_template :layout => "xhr"
223 assert_response :success
224 assert_template template
225 assert_template :layout => "map"
227 xhr :get, type, :id => id
228 assert_response :success
229 assert_template template
230 assert_template :layout => "xhr"