1 require File.dirname(__FILE__) + '/../test_helper'
2 require 'browse_controller'
4 class BrowseControllerTest < ActionController::TestCase
8 # test all routes which lead to this controller
11 { :path => "/browse/start", :method => :get },
12 { :controller => "browse", :action => "start" }
15 { :path => "/browse/node/1", :method => :get },
16 { :controller => "browse", :action => "node", :id => "1" }
19 { :path => "/browse/node/1/history", :method => :get },
20 { :controller => "browse", :action => "node_history", :id => "1" }
23 { :path => "/browse/way/1", :method => :get },
24 { :controller => "browse", :action => "way", :id => "1" }
27 { :path => "/browse/way/1/history", :method => :get },
28 { :controller => "browse", :action => "way_history", :id => "1" }
31 { :path => "/browse/relation/1", :method => :get },
32 { :controller => "browse", :action => "relation", :id => "1" }
35 { :path => "/browse/relation/1/history", :method => :get },
36 { :controller => "browse", :action => "relation_history", :id => "1" }
39 { :path => "/browse/changeset/1", :method => :get },
40 { :controller => "browse", :action => "changeset", :id => "1" }
43 { :path => "/browse/note/1", :method => :get },
44 { :controller => "browse", :action => "note", :id => "1" }
50 assert_response :success
53 def test_read_relation
54 browse_check 'relation', relations(:visible_relation).relation_id
57 def test_read_relation_history
58 browse_check 'relation_history', relations(:visible_relation).relation_id
62 browse_check 'way', ways(:visible_way).way_id
65 def test_read_way_history
66 browse_check 'way_history', ways(:visible_way).way_id
70 browse_check 'node', nodes(:visible_node).node_id
73 def test_read_node_history
74 browse_check 'node_history', nodes(:visible_node).node_id
77 def test_read_changeset
78 browse_check 'changeset', changesets(:normal_user_first_change).id
82 # Methods to check redaction.
84 # note that these are presently highly reliant on the structure of the
85 # page for the selection tests, which doesn't work out particularly
86 # well if that structure changes. so... if you change the page layout
87 # then please make it more easily (and robustly) testable!
89 def test_redacted_node_history
90 get :node_history, :id => nodes(:redacted_node_redacted_version).node_id
91 assert_response :success
92 assert_template 'node_history'
94 # there are 2 revisions of the redacted node, but only one
95 # should be showing details here.
96 assert_select "body div#content div.browse_details", 2
97 assert_select "body div#content div.browse_details[id=1] div.common", 0
98 assert_select "body div#content div.browse_details[id=2] div.common", 1
101 def test_redacted_way_history
102 get :way_history, :id => ways(:way_with_redacted_versions_v1).way_id
103 assert_response :success
104 assert_template 'way_history'
106 # there are 4 revisions of the redacted way, but only 2
107 # should be showing details here.
108 assert_select "body div#content div.browse_details", 4
109 assert_select "body div#content div.browse_details[id=1] div.common", 1
110 assert_select "body div#content div.browse_details[id=2] div.common", 0
111 assert_select "body div#content div.browse_details[id=3] div.common", 0
112 assert_select "body div#content div.browse_details[id=4] div.common", 1
115 def test_redacted_relation_history
116 get :relation_history, :id => relations(:relation_with_redacted_versions_v1).relation_id
117 assert_response :success
118 assert_template 'relation_history'
120 # there are 4 revisions of the redacted relation, but only 2
121 # should be showing details here.
122 assert_select "body div#content div.browse_details", 4
123 assert_select "body div#content div.browse_details[id=1] div.common", 1
124 assert_select "body div#content div.browse_details[id=2] div.common", 0
125 assert_select "body div#content div.browse_details[id=3] div.common", 0
126 assert_select "body div#content div.browse_details[id=4] div.common", 1
129 # This is a convenience method for most of the above checks
130 # First we check that when we don't have an id, it will correctly return a 404
131 # then we check that we get the correct 404 when a non-existant id is passed
132 # then we check that it will get a successful response, when we do pass an id
133 def browse_check(type, id)
134 assert_raise ActionController::RoutingError do
137 assert_raise ActionController::RoutingError do
138 get type, {:id => -10} # we won't have an id that's negative
140 get type, {:id => id}
141 assert_response :success