]> git.openstreetmap.org Git - rails.git/blob - test/functional/browse_controller_test.rb
Add tests for diary_entry#comments
[rails.git] / test / functional / browse_controller_test.rb
1 require File.dirname(__FILE__) + '/../test_helper'
2 require 'browse_controller'
3
4 class BrowseControllerTest < ActionController::TestCase
5   api_fixtures
6
7   ##
8   # test all routes which lead to this controller
9   def test_routes
10     assert_routing(
11       { :path => "/browse/start", :method => :get },
12       { :controller => "browse", :action => "start" }
13     )
14     assert_routing(
15       { :path => "/browse/node/1", :method => :get },
16       { :controller => "browse", :action => "node", :id => "1" }
17     )
18     assert_routing(
19       { :path => "/browse/node/1/history", :method => :get },
20       { :controller => "browse", :action => "node_history", :id => "1" }
21     )
22     assert_routing(
23       { :path => "/browse/way/1", :method => :get },
24       { :controller => "browse", :action => "way", :id => "1" }
25     )
26     assert_routing(
27       { :path => "/browse/way/1/history", :method => :get },
28       { :controller => "browse", :action => "way_history", :id => "1" }
29     )
30     assert_routing(
31       { :path => "/browse/relation/1", :method => :get },
32       { :controller => "browse", :action => "relation", :id => "1" }
33     )
34     assert_routing(
35       { :path => "/browse/relation/1/history", :method => :get },
36       { :controller => "browse", :action => "relation_history", :id => "1" }
37     )
38     assert_routing(
39       { :path => "/browse/changeset/1", :method => :get },
40       { :controller => "browse", :action => "changeset", :id => "1" }
41     )
42     assert_routing(
43       { :path => "/browse/note/1", :method => :get },
44       { :controller => "browse", :action => "note", :id => "1" }
45     )
46   end
47
48   def test_start
49     xhr :get, :start
50     assert_response :success
51   end
52
53   def test_read_relation
54     browse_check 'relation', relations(:visible_relation).relation_id
55   end
56
57   def test_read_relation_history
58     browse_check 'relation_history', relations(:visible_relation).relation_id
59   end
60
61   def test_read_way
62     browse_check 'way', ways(:visible_way).way_id
63   end
64
65   def test_read_way_history
66     browse_check 'way_history', ways(:visible_way).way_id
67   end
68
69   def test_read_node
70     browse_check 'node', nodes(:visible_node).node_id
71   end
72
73   def test_read_node_history
74     browse_check 'node_history', nodes(:visible_node).node_id
75   end
76
77   def test_read_changeset
78     browse_check 'changeset', changesets(:normal_user_first_change).id
79   end
80
81   def test_read_note
82     browse_check 'note', notes(:open_note).id
83   end
84
85   ##
86   #  Methods to check redaction.
87   #
88   # note that these are presently highly reliant on the structure of the
89   # page for the selection tests, which doesn't work out particularly
90   # well if that structure changes. so... if you change the page layout
91   # then please make it more easily (and robustly) testable!
92   ##
93   def test_redacted_node_history
94     get :node_history, :id => nodes(:redacted_node_redacted_version).node_id
95     assert_response :success
96     assert_template 'node_history'
97
98     # there are 2 revisions of the redacted node, but only one
99     # should be showing details here.
100     assert_select "body div#content div.browse_details", 2
101     assert_select "body div#content div.browse_details[id=1] div.common", 0
102     assert_select "body div#content div.browse_details[id=2] div.common", 1
103   end
104
105   def test_redacted_way_history
106     get :way_history, :id => ways(:way_with_redacted_versions_v1).way_id
107     assert_response :success
108     assert_template 'way_history'
109
110     # there are 4 revisions of the redacted way, but only 2
111     # should be showing details here.
112     assert_select "body div#content div.browse_details", 4
113     assert_select "body div#content div.browse_details[id=1] div.common", 1
114     assert_select "body div#content div.browse_details[id=2] div.common", 0
115     assert_select "body div#content div.browse_details[id=3] div.common", 0
116     assert_select "body div#content div.browse_details[id=4] div.common", 1
117   end
118
119   def test_redacted_relation_history
120     get :relation_history, :id => relations(:relation_with_redacted_versions_v1).relation_id
121     assert_response :success
122     assert_template 'relation_history'
123
124     # there are 4 revisions of the redacted relation, but only 2
125     # should be showing details here.
126     assert_select "body div#content div.browse_details", 4
127     assert_select "body div#content div.browse_details[id=1] div.common", 1
128     assert_select "body div#content div.browse_details[id=2] div.common", 0
129     assert_select "body div#content div.browse_details[id=3] div.common", 0
130     assert_select "body div#content div.browse_details[id=4] div.common", 1
131   end
132
133 private
134
135   # This is a convenience method for most of the above checks
136   # First we check that when we don't have an id, it will correctly return a 404
137   # then we check that we get the correct 404 when a non-existant id is passed
138   # then we check that it will get a successful response, when we do pass an id
139   def browse_check(type, id)
140     assert_raise ActionController::UrlGenerationError do
141       get type
142     end
143     assert_raise ActionController::UrlGenerationError do
144       get type, {:id => -10} # we won't have an id that's negative
145     end
146     get type, {:id => id}
147     assert_response :success
148     assert_template type
149   end
150 end