3 class OldNodesControllerTest < ActionDispatch::IntegrationTest
6 { :path => "/node/1/history", :method => :get },
7 { :controller => "old_nodes", :action => "index", :id => "1" }
10 { :path => "/node/1/history/2", :method => :get },
11 { :controller => "old_nodes", :action => "show", :id => "1", :version => "2" }
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
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))
28 get node_history_path(:id => node)
29 assert_response :success
30 assert_template "old_elements/index"
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
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))
47 get node_history_path(:id => node, :params => { :show_redactions => true })
48 assert_response :success
49 assert_template "old_elements/index"
51 assert_select ".browse-section", 2
52 assert_select ".browse-section.browse-redacted", 0
53 assert_select ".browse-section.browse-node", 2
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
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
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
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
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
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
109 node = create(:node, :with_history)
111 get old_node_path(node, 1)
113 assert_response :success
114 assert_template "old_nodes/show"
115 assert_template :layout => "map"
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))
122 get old_node_path(node, 1, :params => { :show_redactions => true })
124 assert_response :redirect
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))
131 session_for(create(:user))
132 get old_node_path(node, 1, :params => { :show_redactions => true })
134 assert_response :redirect
137 def test_show_not_found
138 get old_node_path(0, 0)
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/
146 def test_show_timeout
147 node = create(:node, :with_history)
149 with_settings(:web_timeout => -1) do
150 get old_node_path(node, 1)
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}")}/