3 class OldNodesControllerTest < ActionDispatch::IntegrationTest
6 { :path => "/node/1/history/2", :method => :get },
7 { :controller => "old_nodes", :action => "show", :id => "1", :version => "2" }
11 def test_visible_with_one_version
12 node = create(:node, :with_history)
13 get old_node_path(node, 1)
14 assert_response :success
15 assert_template "old_nodes/show"
16 assert_template :layout => "map"
17 assert_select "h4", /^Version/ do
18 assert_select "a[href='#{old_node_path node, 1}']", :count => 0
20 assert_select ".secondary-actions a[href='#{node_version_path node, 1}']", :count => 1
21 assert_select ".secondary-actions a[href='#{node_path node}']", :count => 1
22 assert_select ".secondary-actions a[href='#{old_node_path node, 1, :params => { :show_redactions => true }}']", :count => 0
23 assert_select ".secondary-actions a[href='#{node_history_path node}']", :count => 1
26 def test_visible_with_two_versions
27 node = create(:node, :with_history, :version => 2)
28 get old_node_path(node, 1)
29 assert_response :success
30 assert_template "old_nodes/show"
31 assert_template :layout => "map"
32 assert_select "h4", /^Version/ do
33 assert_select "a[href='#{old_node_path node, 1}']", :count => 0
35 assert_select ".secondary-actions a[href='#{node_version_path node, 1}']", :count => 1
36 assert_select ".secondary-actions a[href='#{node_path node}']", :count => 1
37 assert_select ".secondary-actions a[href='#{node_history_path node}']", :count => 1
38 assert_select ".secondary-actions a[href='#{old_node_path node, 2}']", :count => 1
40 get old_node_path(node, 2)
41 assert_response :success
42 assert_template "old_nodes/show"
43 assert_template :layout => "map"
44 assert_select "h4", /^Version/ do
45 assert_select "a[href='#{old_node_path node, 2}']", :count => 0
47 assert_select ".secondary-actions a[href='#{node_version_path node, 2}']", :count => 1
48 assert_select ".secondary-actions a[href='#{node_path node}']", :count => 1
49 assert_select ".secondary-actions a[href='#{node_history_path node}']", :count => 1
50 assert_select ".secondary-actions a[href='#{old_node_path node, 1}']", :count => 1
53 test "show unrevealed redacted versions to anonymous users" do
54 node = create_redacted_node
55 get old_node_path(node, 1)
56 assert_response :success
57 assert_template "old_nodes/show"
58 assert_template :layout => "map"
59 assert_select "td", :text => "TOP SECRET", :count => 0
60 assert_select ".secondary-actions a[href='#{node_path node}']", :count => 1
61 assert_select ".secondary-actions a[href='#{old_node_path node, 1, :params => { :show_redactions => true }}']", :count => 0
62 assert_select ".secondary-actions a[href='#{old_node_path node, 1}']", :count => 0
63 assert_select ".secondary-actions a[href='#{node_version_path node, 1}']", :count => 0
66 test "show unrevealed redacted versions to regular users" do
67 session_for(create(:user))
68 node = create_redacted_node
69 get old_node_path(node, 1)
70 assert_response :success
71 assert_template "old_nodes/show"
72 assert_template :layout => "map"
73 assert_select "td", :text => "TOP SECRET", :count => 0
74 assert_select ".secondary-actions a[href='#{node_path node}']", :count => 1
75 assert_select ".secondary-actions a[href='#{old_node_path node, 1, :params => { :show_redactions => true }}']", :count => 0
76 assert_select ".secondary-actions a[href='#{old_node_path node, 1}']", :count => 0
77 assert_select ".secondary-actions a[href='#{node_version_path node, 1}']", :count => 0
80 test "show unrevealed redacted versions to moderators" do
81 session_for(create(:moderator_user))
82 node = create_redacted_node
83 get old_node_path(node, 1)
84 assert_response :success
85 assert_template "old_nodes/show"
86 assert_template :layout => "map"
87 assert_select "td", :text => "TOP SECRET", :count => 0
88 assert_select ".secondary-actions a[href='#{node_path node}']", :count => 1
89 assert_select ".secondary-actions a[href='#{old_node_path node, 1, :params => { :show_redactions => true }}']", :count => 1
90 assert_select ".secondary-actions a[href='#{old_node_path node, 1}']", :count => 0
91 assert_select ".secondary-actions a[href='#{node_version_path node, 1}']", :count => 0
94 test "don't reveal redacted versions to anonymous users" do
95 node = create_redacted_node
96 get old_node_path(node, 1, :params => { :show_redactions => true })
97 assert_response :redirect
100 test "don't reveal redacted versions to regular users" do
101 session_for(create(:user))
102 node = create_redacted_node
103 get old_node_path(node, 1, :params => { :show_redactions => true })
104 assert_response :redirect
107 test "reveal redacted versions to moderators" do
108 session_for(create(:moderator_user))
109 node = create_redacted_node
110 get old_node_path(node, 1, :params => { :show_redactions => true })
111 assert_response :success
112 assert_select "td", :text => "TOP SECRET", :count => 1
113 assert_select ".secondary-actions a[href='#{old_node_path node, 1}']", :count => 1
117 get old_node_path(0, 0)
118 assert_response :not_found
119 assert_template "old_nodes/not_found"
120 assert_template :layout => "map"
121 assert_select "#sidebar_content", /node #0 version 0 could not be found/
126 def create_redacted_node
127 create(:node, :with_history, :version => 2) do |node|
128 node_v1 = node.old_nodes.find_by(:version => 1)
129 create(:old_node_tag, :old_node => node_v1, :k => "name", :v => "TOP SECRET")
130 node_v1.redact!(create(:redaction))