1 # frozen_string_literal: true
5 class OldNodesControllerTest < ActionDispatch::IntegrationTest
8 { :path => "/node/1/history", :method => :get },
9 { :controller => "old_nodes", :action => "index", :id => "1" }
12 { :path => "/node/1/history/2", :method => :get },
13 { :controller => "old_nodes", :action => "show", :id => "1", :version => "2" }
18 node = create(:node, :with_history)
19 sidebar_browse_check :node_history_path, node.id, "old_elements/index"
22 def test_index_show_redactions_to_unauthorized
23 node = create(:node, :with_history)
25 get node_history_path(:id => node, :params => { :show_redactions => true })
27 assert_response :redirect
30 def test_index_show_redactions_to_regular_user
31 node = create(:node, :with_history)
33 session_for(create(:user))
34 get node_history_path(:id => node, :params => { :show_redactions => true })
36 assert_response :redirect
40 node = create(:node, :with_history)
42 get old_node_path(node, 1)
44 assert_response :success
45 assert_template "old_nodes/show"
46 assert_template :layout => "map"
49 def test_show_redacted_to_unauthorized_users
50 node = create(:node, :with_history, :version => 2)
51 node.old_nodes.find_by(:version => 1).redact!(create(:redaction))
53 get old_node_path(node, 1, :params => { :show_redactions => true })
55 assert_response :redirect
58 def test_show_redacted_to_regular_users
59 node = create(:node, :with_history, :version => 2)
60 node.old_nodes.find_by(:version => 1).redact!(create(:redaction))
62 session_for(create(:user))
63 get old_node_path(node, 1, :params => { :show_redactions => true })
65 assert_response :redirect
68 def test_show_not_found
69 get old_node_path(0, 0)
71 assert_response :not_found
72 assert_template "browse/not_found"
73 assert_template :layout => "map"
74 assert_select "#sidebar_content", /node #0 version 0 could not be found/
78 node = create(:node, :with_history)
80 with_settings(:web_timeout => -1) do
81 get old_node_path(node, 1)
84 assert_response :error
85 assert_template :layout => "map"
86 assert_dom "h2", "Timeout Error"
87 assert_dom "p", /#{Regexp.quote("the node with the id #{node.id}")}/