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/node/1", :method => :get },
12 { :controller => "browse", :action => "node", :id => "1" }
15 { :path => "/browse/node/1/history", :method => :get },
16 { :controller => "browse", :action => "node_history", :id => "1" }
19 { :path => "/browse/way/1", :method => :get },
20 { :controller => "browse", :action => "way", :id => "1" }
23 { :path => "/browse/way/1/history", :method => :get },
24 { :controller => "browse", :action => "way_history", :id => "1" }
27 { :path => "/browse/relation/1", :method => :get },
28 { :controller => "browse", :action => "relation", :id => "1" }
31 { :path => "/browse/relation/1/history", :method => :get },
32 { :controller => "browse", :action => "relation_history", :id => "1" }
35 { :path => "/browse/changeset/1", :method => :get },
36 { :controller => "browse", :action => "changeset", :id => "1" }
39 { :path => "/browse/note/1", :method => :get },
40 { :controller => "browse", :action => "note", :id => "1" }
44 def test_read_relation
45 browse_check 'relation', relations(:visible_relation).relation_id, 'browse/feature'
48 def test_read_relation_history
49 browse_check 'relation_history', relations(:visible_relation).relation_id, 'browse/history'
53 browse_check 'way', ways(:visible_way).way_id, 'browse/feature'
56 def test_read_way_history
57 browse_check 'way_history', ways(:visible_way).way_id, 'browse/history'
61 browse_check 'node', nodes(:visible_node).node_id, 'browse/feature'
64 def test_read_node_history
65 browse_check 'node_history', nodes(:visible_node).node_id, 'browse/history'
68 def test_read_changeset
69 browse_check 'changeset', changesets(:normal_user_first_change).id, 'browse/changeset'
73 browse_check 'note', notes(:open_note).id, 'browse/note'
77 # Methods to check redaction.
79 # note that these are presently highly reliant on the structure of the
80 # page for the selection tests, which doesn't work out particularly
81 # well if that structure changes. so... if you change the page layout
82 # then please make it more easily (and robustly) testable!
84 def test_redacted_node_history
85 get :node_history, :id => nodes(:redacted_node_redacted_version).node_id
86 assert_response :success
87 assert_template 'browse/history'
89 # there are 2 revisions of the redacted node, but only one
90 # should be showing details here.
91 assert_select ".browse-section", 2
92 assert_select ".browse-section.browse-redacted", 1
93 assert_select ".browse-section.browse-node", 1
96 def test_redacted_way_history
97 get :way_history, :id => ways(:way_with_redacted_versions_v1).way_id
98 assert_response :success
99 assert_template 'browse/history'
101 # there are 4 revisions of the redacted way, but only 2
102 # should be showing details here.
103 assert_select ".browse-section", 4
104 assert_select ".browse-section.browse-redacted", 2
105 assert_select ".browse-section.browse-way", 2
108 def test_redacted_relation_history
109 get :relation_history, :id => relations(:relation_with_redacted_versions_v1).relation_id
110 assert_response :success
111 assert_template 'browse/history'
113 # there are 4 revisions of the redacted relation, but only 2
114 # should be showing details here.
115 assert_select ".browse-section", 4
116 assert_select ".browse-section.browse-redacted", 2
117 assert_select ".browse-section.browse-relation", 2
122 # This is a convenience method for most of the above checks
123 # First we check that when we don't have an id, it will correctly return a 404
124 # then we check that we get the correct 404 when a non-existant id is passed
125 # then we check that it will get a successful response, when we do pass an id
126 def browse_check(type, id, template)
127 assert_raise ActionController::UrlGenerationError do
130 assert_raise ActionController::UrlGenerationError do
131 get type, {:id => -10} # we won't have an id that's negative
133 get type, {:id => id}
134 assert_response :success
135 assert_template template