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", nodes(:visible_node).node_id, "browse/feature"
68 def test_read_node_history
69 browse_check "node_history", nodes(:visible_node).node_id, "browse/history"
72 def test_read_changeset
73 browse_check "changeset", changesets(:normal_user_first_change).id, "browse/changeset"
74 browse_check "changeset", changesets(:public_user_first_change).id, "browse/changeset"
77 def test_read_changeset_hidden_comments
78 browse_check "changeset", changesets(:normal_user_closed_change).id, "browse/changeset"
79 assert_select "div.changeset-comments ul li", :count => 3
81 session[:user] = users(:moderator_user).id
83 browse_check "changeset", changesets(:normal_user_closed_change).id, "browse/changeset"
84 assert_select "div.changeset-comments ul li", :count => 4
88 open_note = create(:note_with_comments)
90 browse_check "note", open_note.id, "browse/note"
93 def test_read_hidden_note
94 hidden_note_with_comment = create(:note_with_comments, :status => "hidden")
96 get :note, :id => hidden_note_with_comment.id
97 assert_response :not_found
98 assert_template "browse/not_found"
99 assert_template :layout => "map"
101 xhr :get, :note, :id => hidden_note_with_comment.id
102 assert_response :not_found
103 assert_template "browse/not_found"
104 assert_template :layout => "xhr"
106 session[:user] = users(:moderator_user).id
108 browse_check "note", hidden_note_with_comment.id, "browse/note"
111 def test_read_note_hidden_comments
112 note_with_hidden_comment = create(:note_with_comments, :comments_count => 2) do |note|
113 create(:note_comment, :note => note, :visible => false)
116 browse_check "note", note_with_hidden_comment.id, "browse/note"
117 assert_select "div.note-comments ul li", :count => 1
119 session[:user] = users(:moderator_user).id
121 browse_check "note", note_with_hidden_comment.id, "browse/note"
122 assert_select "div.note-comments ul li", :count => 2
126 # Methods to check redaction.
128 # note that these are presently highly reliant on the structure of the
129 # page for the selection tests, which doesn't work out particularly
130 # well if that structure changes. so... if you change the page layout
131 # then please make it more easily (and robustly) testable!
133 def test_redacted_node
134 get :node, :id => current_nodes(:redacted_node).id
135 assert_response :success
136 assert_template "feature"
138 # check that we don't show lat/lon for a redacted node.
139 assert_select ".browse-section", 1
140 assert_select ".browse-section.browse-node", 1
141 assert_select ".browse-section.browse-node .latitude", 0
142 assert_select ".browse-section.browse-node .longitude", 0
145 def test_redacted_node_history
146 get :node_history, :id => nodes(:redacted_node_redacted_version).node_id
147 assert_response :success
148 assert_template "browse/history"
150 # there are 2 revisions of the redacted node, but only one
151 # should be showing details here.
152 assert_select ".browse-section", 2
153 assert_select ".browse-section.browse-redacted", 1
154 assert_select ".browse-section.browse-node", 1
155 assert_select ".browse-section.browse-node .latitude", 0
156 assert_select ".browse-section.browse-node .longitude", 0
159 def test_redacted_way_history
160 get :way_history, :id => ways(:way_with_redacted_versions_v1).way_id
161 assert_response :success
162 assert_template "browse/history"
164 # there are 4 revisions of the redacted way, but only 2
165 # should be showing details here.
166 assert_select ".browse-section", 4
167 assert_select ".browse-section.browse-redacted", 2
168 assert_select ".browse-section.browse-way", 2
171 def test_redacted_relation_history
172 get :relation_history, :id => relations(:relation_with_redacted_versions_v1).relation_id
173 assert_response :success
174 assert_template "browse/history"
176 # there are 4 revisions of the redacted relation, but only 2
177 # should be showing details here.
178 assert_select ".browse-section", 4
179 assert_select ".browse-section.browse-redacted", 2
180 assert_select ".browse-section.browse-relation", 2
185 # This is a convenience method for most of the above checks
186 # First we check that when we don't have an id, it will correctly return a 404
187 # then we check that we get the correct 404 when a non-existant id is passed
188 # then we check that it will get a successful response, when we do pass an id
189 def browse_check(type, id, template)
190 assert_raise ActionController::UrlGenerationError do
194 assert_raise ActionController::UrlGenerationError do
195 get type, :id => -10 # we won't have an id that's negative
199 assert_response :not_found
200 assert_template "browse/not_found"
201 assert_template :layout => "map"
203 xhr :get, type, :id => 0
204 assert_response :not_found
205 assert_template "browse/not_found"
206 assert_template :layout => "xhr"
209 assert_response :success
210 assert_template template
211 assert_template :layout => "map"
213 xhr :get, type, :id => id
214 assert_response :success
215 assert_template template
216 assert_template :layout => "xhr"