3 class BrowseControllerTest < ActionDispatch::IntegrationTest
5 # test all routes which lead to this controller
8 { :path => "/node/1", :method => :get },
9 { :controller => "browse", :action => "node", :id => "1" }
12 { :path => "/way/1", :method => :get },
13 { :controller => "browse", :action => "way", :id => "1" }
16 { :path => "/relation/1", :method => :get },
17 { :controller => "browse", :action => "relation", :id => "1" }
20 { :path => "/query", :method => :get },
21 { :controller => "browse", :action => "query" }
25 def test_read_relation
26 relation = create(:relation)
27 sidebar_browse_check :relation_path, relation.id, "browse/feature"
28 assert_select "h4", /^Version/ do
29 assert_select "a[href='#{old_relation_path relation, 1}']", :text => "1", :count => 1
31 assert_select ".secondary-actions a[href='#{api_relation_path relation}']", :count => 1
32 assert_select ".secondary-actions a[href='#{relation_history_path relation}']", :count => 1
33 assert_select ".secondary-actions a[href='#{old_relation_path relation, 1}']", :count => 0
36 def test_multiple_version_relation_links
37 relation = create(:relation, :with_history, :version => 2)
38 sidebar_browse_check :relation_path, relation.id, "browse/feature"
39 assert_select ".secondary-actions a[href='#{relation_history_path relation}']", :count => 1
40 assert_select ".secondary-actions a[href='#{old_relation_path relation, 1}']", :count => 1
41 assert_select ".secondary-actions a[href='#{old_relation_path relation, 2}']", :count => 1
46 sidebar_browse_check :way_path, way.id, "browse/feature"
47 assert_select "h4", /^Version/ do
48 assert_select "a[href='#{old_way_path way, 1}']", :text => "1", :count => 1
50 assert_select ".secondary-actions a[href='#{api_way_path way}']", :count => 1
51 assert_select ".secondary-actions a[href='#{way_history_path way}']", :count => 1
52 assert_select ".secondary-actions a[href='#{old_way_path way, 1}']", :count => 0
55 def test_multiple_version_way_links
56 way = create(:way, :with_history, :version => 2)
57 sidebar_browse_check :way_path, way.id, "browse/feature"
58 assert_select ".secondary-actions a[href='#{way_history_path way}']", :count => 1
59 assert_select ".secondary-actions a[href='#{old_way_path way, 1}']", :count => 1
60 assert_select ".secondary-actions a[href='#{old_way_path way, 2}']", :count => 1
65 sidebar_browse_check :node_path, node.id, "browse/feature"
66 assert_select "h4", /^Version/ do
67 assert_select "a[href='#{old_node_path node, 1}']", :text => "1", :count => 1
69 assert_select ".secondary-actions a[href='#{api_node_path node}']", :count => 1
70 assert_select ".secondary-actions a[href='#{node_history_path node}']", :count => 1
71 assert_select ".secondary-actions a[href='#{old_node_path node, 1}']", :count => 0
74 def test_multiple_version_node_links
75 node = create(:node, :with_history, :version => 2)
76 sidebar_browse_check :node_path, node.id, "browse/feature"
77 assert_select ".secondary-actions a[href='#{node_history_path node}']", :count => 1
78 assert_select ".secondary-actions a[href='#{old_node_path node, 1}']", :count => 1
79 assert_select ".secondary-actions a[href='#{old_node_path node, 2}']", :count => 1
82 def test_read_deleted_node
83 node = create(:node, :visible => false)
84 sidebar_browse_check :node_path, node.id, "browse/feature"
85 assert_select "h4", /^Version/ do
86 assert_select "a[href='#{old_node_path node, 1}']", :text => "1", :count => 1
88 assert_select "a[href='#{api_node_path node}']", :count => 0
92 # Methods to check redaction.
94 # note that these are presently highly reliant on the structure of the
95 # page for the selection tests, which doesn't work out particularly
96 # well if that structure changes. so... if you change the page layout
97 # then please make it more easily (and robustly) testable!
99 def test_redacted_node
100 node = create(:node, :with_history, :deleted, :version => 2)
101 node_v1 = node.old_nodes.find_by(:version => 1)
102 node_v1.redact!(create(:redaction))
104 get node_path(:id => node)
105 assert_response :success
106 assert_template "feature"
108 # check that we don't show lat/lon for a redacted node.
109 assert_select ".browse-section", 1
110 assert_select ".browse-section.browse-node", 1
111 assert_select ".browse-section.browse-node .latitude", 0
112 assert_select ".browse-section.browse-node .longitude", 0
117 assert_response :success
118 assert_template "browse/query"
121 def test_anonymous_user_feature_page_secondary_actions
122 node = create(:node, :with_history)
123 get node_path(:id => node)
124 assert_response :success
125 assert_select ".secondary-actions a", :text => "View Details", :count => 0
126 assert_select ".secondary-actions a", :text => "View History", :count => 1
127 assert_select ".secondary-actions a", :text => "View Unredacted History", :count => 0
130 def test_regular_user_feature_page_secondary_actions
131 session_for(create(:user))
132 node = create(:node, :with_history)
133 get node_path(:id => node)
134 assert_response :success
135 assert_select ".secondary-actions a", :text => "View Details", :count => 0
136 assert_select ".secondary-actions a", :text => "View History", :count => 1
137 assert_select ".secondary-actions a", :text => "View Unredacted History", :count => 0
140 def test_moderator_user_feature_page_secondary_actions
141 session_for(create(:moderator_user))
142 node = create(:node, :with_history)
143 get node_path(:id => node)
144 assert_response :success
145 assert_select ".secondary-actions a", :text => "View Details", :count => 0
146 assert_select ".secondary-actions a", :text => "View History", :count => 1
147 assert_select ".secondary-actions a", :text => "View Unredacted History", :count => 1