3 class BrowseControllerTest < ActionController::TestCase
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 => "/changeset/1", :method => :get },
33 { :controller => "browse", :action => "changeset", :id => "1" }
36 { :path => "/note/1", :method => :get },
37 { :controller => "browse", :action => "note", :id => "1" }
40 { :path => "/note/new", :method => :get },
41 { :controller => "browse", :action => "new_note" }
44 { :path => "/query", :method => :get },
45 { :controller => "browse", :action => "query" }
49 def test_read_relation
50 browse_check "relation", create(:relation).id, "browse/feature"
53 def test_read_relation_history
54 browse_check "relation_history", create(:relation, :with_history).id, "browse/history"
58 browse_check "way", create(:way).id, "browse/feature"
61 def test_read_way_history
62 browse_check "way_history", create(:way, :with_history).id, "browse/history"
66 browse_check "node", create(:node).id, "browse/feature"
69 def test_read_node_history
70 browse_check "node_history", create(:node, :with_history).id, "browse/history"
73 def test_read_changeset
75 private_changeset = create(:changeset, :user => create(:user, :data_public => false))
76 changeset = create(:changeset, :user => user)
77 create(:changeset, :user => user)
78 browse_check "changeset", private_changeset.id, "browse/changeset"
79 browse_check "changeset", changeset.id, "browse/changeset"
82 def test_read_changeset_hidden_comments
83 changeset = create(:changeset)
84 create_list(:changeset_comment, 3, :changeset => changeset)
85 create(:changeset_comment, :visible => false, :changeset => changeset)
87 browse_check "changeset", changeset.id, "browse/changeset"
88 assert_select "div.changeset-comments ul li", :count => 3
90 session[:user] = create(:moderator_user).id
92 browse_check "changeset", changeset.id, "browse/changeset"
93 assert_select "div.changeset-comments ul li", :count => 4
97 open_note = create(:note_with_comments)
99 browse_check "note", open_note.id, "browse/note"
102 def test_read_hidden_note
103 hidden_note_with_comment = create(:note_with_comments, :status => "hidden")
105 get :note, :params => { :id => hidden_note_with_comment.id }
106 assert_response :not_found
107 assert_template "browse/not_found"
108 assert_template :layout => "map"
110 get :note, :params => { :id => hidden_note_with_comment.id }, :xhr => true
111 assert_response :not_found
112 assert_template "browse/not_found"
113 assert_template :layout => "xhr"
115 session[:user] = create(:moderator_user).id
117 browse_check "note", hidden_note_with_comment.id, "browse/note"
120 def test_read_note_hidden_comments
121 note_with_hidden_comment = create(:note_with_comments, :comments_count => 2) do |note|
122 create(:note_comment, :note => note, :visible => false)
125 browse_check "note", note_with_hidden_comment.id, "browse/note"
126 assert_select "div.note-comments ul li", :count => 1
128 session[:user] = create(:moderator_user).id
130 browse_check "note", note_with_hidden_comment.id, "browse/note"
131 assert_select "div.note-comments ul li", :count => 2
134 def test_read_note_hidden_user_comment
135 hidden_user = create(:user, :status => "deleted")
136 note_with_hidden_user_comment = create(:note_with_comments, :comments_count => 2) do |note|
137 create(:note_comment, :note => note, :author => hidden_user)
140 browse_check "note", note_with_hidden_user_comment.id, "browse/note"
141 assert_select "div.note-comments ul li", :count => 1
143 session[:user] = create(:moderator_user).id
145 browse_check "note", note_with_hidden_user_comment.id, "browse/note"
146 assert_select "div.note-comments ul li", :count => 1
150 # Methods to check redaction.
152 # note that these are presently highly reliant on the structure of the
153 # page for the selection tests, which doesn't work out particularly
154 # well if that structure changes. so... if you change the page layout
155 # then please make it more easily (and robustly) testable!
157 def test_redacted_node
158 node = create(:node, :with_history, :deleted, :version => 2)
159 node_v1 = node.old_nodes.find_by(:version => 1)
160 node_v1.redact!(create(:redaction))
162 get :node, :params => { :id => node.id }
163 assert_response :success
164 assert_template "feature"
166 # check that we don't show lat/lon for a redacted node.
167 assert_select ".browse-section", 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_node_history
174 node = create(:node, :with_history, :deleted, :version => 2)
175 node_v1 = node.old_nodes.find_by(:version => 1)
176 node_v1.redact!(create(:redaction))
178 get :node_history, :params => { :id => node.id }
179 assert_response :success
180 assert_template "browse/history"
182 # there are 2 revisions of the redacted node, but only one
183 # should be showing details here.
184 assert_select ".browse-section", 2
185 assert_select ".browse-section.browse-redacted", 1
186 assert_select ".browse-section.browse-node", 1
187 assert_select ".browse-section.browse-node .latitude", 0
188 assert_select ".browse-section.browse-node .longitude", 0
191 def test_redacted_way_history
192 way = create(:way, :with_history, :version => 4)
193 way_v1 = way.old_ways.find_by(:version => 1)
194 way_v1.redact!(create(:redaction))
195 way_v3 = way.old_ways.find_by(:version => 3)
196 way_v3.redact!(create(:redaction))
198 get :way_history, :params => { :id => way.id }
199 assert_response :success
200 assert_template "browse/history"
202 # there are 4 revisions of the redacted way, but only 2
203 # should be showing details here.
204 assert_select ".browse-section", 4
205 assert_select ".browse-section.browse-redacted", 2
206 assert_select ".browse-section.browse-way", 2
209 def test_redacted_relation_history
210 relation = create(:relation, :with_history, :version => 4)
211 relation_v1 = relation.old_relations.find_by(:version => 1)
212 relation_v1.redact!(create(:redaction))
213 relation_v3 = relation.old_relations.find_by(:version => 3)
214 relation_v3.redact!(create(:redaction))
216 get :relation_history, :params => { :id => relation.id }
217 assert_response :success
218 assert_template "browse/history"
220 # there are 4 revisions of the redacted relation, but only 2
221 # should be showing details here.
222 assert_select ".browse-section", 4
223 assert_select ".browse-section.browse-redacted", 2
224 assert_select ".browse-section.browse-relation", 2
229 assert_response :success
230 assert_template "browse/new_note"
235 assert_response :success
236 assert_template "browse/query"
241 # This is a convenience method for most of the above checks
242 # First we check that when we don't have an id, it will correctly return a 404
243 # then we check that we get the correct 404 when a non-existant id is passed
244 # then we check that it will get a successful response, when we do pass an id
245 def browse_check(type, id, template)
246 assert_raise ActionController::UrlGenerationError do
250 assert_raise ActionController::UrlGenerationError do
251 get type, :params => { :id => -10 } # we won't have an id that's negative
254 get type, :params => { :id => 0 }
255 assert_response :not_found
256 assert_template "browse/not_found"
257 assert_template :layout => "map"
259 get type, :params => { :id => 0 }, :xhr => true
260 assert_response :not_found
261 assert_template "browse/not_found"
262 assert_template :layout => "xhr"
264 get type, :params => { :id => id }
265 assert_response :success
266 assert_template template
267 assert_template :layout => "map"
269 get type, :params => { :id => id }, :xhr => true
270 assert_response :success
271 assert_template template
272 assert_template :layout => "xhr"