]> git.openstreetmap.org Git - rails.git/blob - test/controllers/old_nodes_controller_test.rb
Move old node ui tests to system tests
[rails.git] / test / controllers / old_nodes_controller_test.rb
1 require "test_helper"
2
3 class OldNodesControllerTest < ActionDispatch::IntegrationTest
4   def test_routes
5     assert_routing(
6       { :path => "/node/1/history", :method => :get },
7       { :controller => "old_nodes", :action => "index", :id => "1" }
8     )
9     assert_routing(
10       { :path => "/node/1/history/2", :method => :get },
11       { :controller => "old_nodes", :action => "show", :id => "1", :version => "2" }
12     )
13   end
14
15   def test_history
16     node = create(:node, :with_history)
17     sidebar_browse_check :node_history_path, node.id, "old_elements/index"
18     assert_select "h4", /^Version/ do
19       assert_select "a[href='#{old_node_path node, 1}']", :text => "1", :count => 1
20     end
21   end
22
23   def test_history_of_redacted
24     node = create(:node, :with_history, :deleted, :version => 2)
25     node_v1 = node.old_nodes.find_by(:version => 1)
26     node_v1.redact!(create(:redaction))
27
28     get node_history_path(:id => node)
29     assert_response :success
30     assert_template "old_elements/index"
31
32     # there are 2 revisions of the redacted node, but only one
33     # should be showing details here.
34     assert_select ".browse-section", 2
35     assert_select ".browse-section.browse-redacted", 1
36     assert_select ".browse-section.browse-node", 1
37     assert_select ".browse-section.browse-node .latitude", 0
38     assert_select ".browse-section.browse-node .longitude", 0
39   end
40
41   def test_unredacted_history_of_redacted
42     session_for(create(:moderator_user))
43     node = create(:node, :with_history, :deleted, :version => 2)
44     node_v1 = node.old_nodes.find_by(:version => 1)
45     node_v1.redact!(create(:redaction))
46
47     get node_history_path(:id => node, :params => { :show_redactions => true })
48     assert_response :success
49     assert_template "old_elements/index"
50
51     assert_select ".browse-section", 2
52     assert_select ".browse-section.browse-redacted", 0
53     assert_select ".browse-section.browse-node", 2
54   end
55
56   def test_anonymous_user_history_page_secondary_actions
57     node = create(:node, :with_history)
58     get node_history_path(:id => node)
59     assert_response :success
60     assert_select ".secondary-actions a", :text => "View Details", :count => 1
61     assert_select ".secondary-actions a", :text => "View History", :count => 0
62     assert_select ".secondary-actions a", :text => "View Unredacted History", :count => 0
63   end
64
65   def test_regular_user_history_page_secondary_actions
66     session_for(create(:user))
67     node = create(:node, :with_history)
68     get node_history_path(:id => node)
69     assert_response :success
70     assert_select ".secondary-actions a", :text => "View Details", :count => 1
71     assert_select ".secondary-actions a", :text => "View History", :count => 0
72     assert_select ".secondary-actions a", :text => "View Unredacted History", :count => 0
73   end
74
75   def test_moderator_user_history_page_secondary_actions
76     session_for(create(:moderator_user))
77     node = create(:node, :with_history)
78     get node_history_path(:id => node)
79     assert_response :success
80     assert_select ".secondary-actions a", :text => "View Details", :count => 1
81     assert_select ".secondary-actions a", :text => "View History", :count => 0
82     assert_select ".secondary-actions a", :text => "View Unredacted History", :count => 1
83   end
84
85   def test_anonymous_user_unredacted_history_page_secondary_actions
86     node = create(:node, :with_history)
87     get node_history_path(:id => node, :params => { :show_redactions => true })
88     assert_response :redirect
89   end
90
91   def test_regular_user_unredacted_history_page_secondary_actions
92     session_for(create(:user))
93     node = create(:node, :with_history)
94     get node_history_path(:id => node, :params => { :show_redactions => true })
95     assert_response :redirect
96   end
97
98   def test_moderator_user_unredacted_history_page_secondary_actions
99     session_for(create(:moderator_user))
100     node = create(:node, :with_history)
101     get node_history_path(:id => node, :params => { :show_redactions => true })
102     assert_response :success
103     assert_select ".secondary-actions a", :text => "View Details", :count => 1
104     assert_select ".secondary-actions a", :text => "View History", :count => 1
105     assert_select ".secondary-actions a", :text => "View Unredacted History", :count => 0
106   end
107
108   def test_show
109     node = create(:node, :with_history)
110
111     get old_node_path(node, 1)
112
113     assert_response :success
114     assert_template "old_nodes/show"
115     assert_template :layout => "map"
116   end
117
118   def test_show_redacted_to_unauthorized_users
119     node = create(:node, :with_history, :version => 2)
120     node.old_nodes.find_by(:version => 1).redact!(create(:redaction))
121
122     get old_node_path(node, 1, :params => { :show_redactions => true })
123
124     assert_response :redirect
125   end
126
127   def test_show_redacted_to_regular_users
128     node = create(:node, :with_history, :version => 2)
129     node.old_nodes.find_by(:version => 1).redact!(create(:redaction))
130
131     session_for(create(:user))
132     get old_node_path(node, 1, :params => { :show_redactions => true })
133
134     assert_response :redirect
135   end
136
137   def test_show_not_found
138     get old_node_path(0, 0)
139
140     assert_response :not_found
141     assert_template "browse/not_found"
142     assert_template :layout => "map"
143     assert_select "#sidebar_content", /node #0 version 0 could not be found/
144   end
145
146   def test_show_timeout
147     node = create(:node, :with_history)
148
149     with_settings(:web_timeout => -1) do
150       get old_node_path(node, 1)
151     end
152
153     assert_response :error
154     assert_template :layout => "map"
155     assert_dom "h2", "Timeout Error"
156     assert_dom "p", /#{Regexp.quote("the node with the id #{node.id}")}/
157   end
158 end