3 class OldRelationsControllerTest < ActionDispatch::IntegrationTest
6 { :path => "/relation/1/history", :method => :get },
7 { :controller => "old_relations", :action => "index", :id => "1" }
10 { :path => "/relation/1/history/2", :method => :get },
11 { :controller => "old_relations", :action => "show", :id => "1", :version => "2" }
16 relation = create(:relation, :with_history)
17 sidebar_browse_check :relation_history_path, relation.id, "browse/history"
18 assert_select "h4", /^Version/ do
19 assert_select "a[href='#{old_relation_path relation, 1}']", :text => "1", :count => 1
23 def test_history_of_redacted
24 relation = create(:relation, :with_history, :version => 4)
25 relation_v1 = relation.old_relations.find_by(:version => 1)
26 relation_v1.redact!(create(:redaction))
27 relation_v3 = relation.old_relations.find_by(:version => 3)
28 relation_v3.redact!(create(:redaction))
30 get relation_history_path(:id => relation)
31 assert_response :success
32 assert_template "browse/history"
34 # there are 4 revisions of the redacted relation, but only 2
35 # should be showing details here.
36 assert_select ".browse-section", 4
37 assert_select ".browse-section.browse-redacted", 2
38 assert_select ".browse-section.browse-relation", 2
41 def test_unredacted_history_of_redacted
42 session_for(create(:moderator_user))
43 relation = create(:relation, :with_history, :version => 4)
44 relation_v1 = relation.old_relations.find_by(:version => 1)
45 relation_v1.redact!(create(:redaction))
46 relation_v3 = relation.old_relations.find_by(:version => 3)
47 relation_v3.redact!(create(:redaction))
49 get relation_history_path(:id => relation, :params => { :show_redactions => true })
50 assert_response :success
51 assert_template "browse/history"
53 assert_select ".browse-section", 4
54 assert_select ".browse-section.browse-redacted", 0
55 assert_select ".browse-section.browse-relation", 4
58 def test_visible_with_one_version
59 relation = create(:relation, :with_history)
60 get old_relation_path(relation, 1)
61 assert_response :success
62 assert_template "old_relations/show"
63 assert_template :layout => "map"
64 assert_select "h4", /^Version/ do
65 assert_select "a[href='#{old_relation_path relation, 1}']", :count => 0
67 assert_select ".secondary-actions a[href='#{api_old_relation_path relation, 1}']", :count => 1
68 assert_select ".secondary-actions a[href='#{relation_path relation}']", :count => 1
69 assert_select ".secondary-actions a[href='#{old_relation_path relation, 1, :params => { :show_redactions => true }}']", :count => 0
70 assert_select ".secondary-actions a[href='#{relation_history_path relation}']", :count => 1
73 def test_visible_with_two_versions
74 relation = create(:relation, :with_history, :version => 2)
75 get old_relation_path(relation, 1)
76 assert_response :success
77 assert_template "old_relations/show"
78 assert_template :layout => "map"
79 assert_select "h4", /^Version/ do
80 assert_select "a[href='#{old_relation_path relation, 1}']", :count => 0
82 assert_select ".secondary-actions a[href='#{api_old_relation_path relation, 1}']", :count => 1
83 assert_select ".secondary-actions a[href='#{relation_path relation}']", :count => 1
84 assert_select ".secondary-actions a[href='#{relation_history_path relation}']", :count => 1
85 assert_select ".secondary-actions a[href='#{old_relation_path relation, 2}']", :count => 1
87 get old_relation_path(relation, 2)
88 assert_response :success
89 assert_template "old_relations/show"
90 assert_template :layout => "map"
91 assert_select "h4", /^Version/ do
92 assert_select "a[href='#{old_relation_path relation, 2}']", :count => 0
94 assert_select ".secondary-actions a[href='#{api_old_relation_path relation, 2}']", :count => 1
95 assert_select ".secondary-actions a[href='#{relation_path relation}']", :count => 1
96 assert_select ".secondary-actions a[href='#{relation_history_path relation}']", :count => 1
97 assert_select ".secondary-actions a[href='#{old_relation_path relation, 1}']", :count => 1
100 def test_visible_with_members
101 relation = create(:relation, :with_history)
102 create(:old_relation_member, :old_relation => relation.old_relations.first)
103 get old_relation_path(relation, 1)
104 assert_response :success
105 assert_template "old_relations/show"
106 assert_template :layout => "map"
109 test "show unrevealed redacted versions to anonymous users" do
110 relation = create_redacted_relation
111 get old_relation_path(relation, 1)
112 assert_response :success
113 assert_template "old_relations/show"
114 assert_template :layout => "map"
115 assert_select "td", :text => "TOP SECRET", :count => 0
116 assert_select ".secondary-actions a[href='#{relation_path relation}']", :count => 1
117 assert_select ".secondary-actions a[href='#{old_relation_path relation, 1, :params => { :show_redactions => true }}']", :count => 0
118 assert_select ".secondary-actions a[href='#{old_relation_path relation, 1}']", :count => 0
119 assert_select ".secondary-actions a[href='#{api_old_relation_path relation, 1}']", :count => 0
122 test "show unrevealed redacted versions to regular users" do
123 session_for(create(:user))
124 relation = create_redacted_relation
125 get old_relation_path(relation, 1)
126 assert_response :success
127 assert_template "old_relations/show"
128 assert_template :layout => "map"
129 assert_select "td", :text => "TOP SECRET", :count => 0
130 assert_select ".secondary-actions a[href='#{relation_path relation}']", :count => 1
131 assert_select ".secondary-actions a[href='#{old_relation_path relation, 1, :params => { :show_redactions => true }}']", :count => 0
132 assert_select ".secondary-actions a[href='#{old_relation_path relation, 1}']", :count => 0
133 assert_select ".secondary-actions a[href='#{api_old_relation_path relation, 1}']", :count => 0
136 test "show unrevealed redacted versions to moderators" do
137 session_for(create(:moderator_user))
138 relation = create_redacted_relation
139 get old_relation_path(relation, 1)
140 assert_response :success
141 assert_template "old_relations/show"
142 assert_template :layout => "map"
143 assert_select "td", :text => "TOP SECRET", :count => 0
144 assert_select ".secondary-actions a[href='#{relation_path relation}']", :count => 1
145 assert_select ".secondary-actions a[href='#{old_relation_path relation, 1, :params => { :show_redactions => true }}']", :count => 1
146 assert_select ".secondary-actions a[href='#{old_relation_path relation, 1}']", :count => 0
147 assert_select ".secondary-actions a[href='#{api_old_relation_path relation, 1}']", :count => 0
150 test "don't reveal redacted versions to anonymous users" do
151 relation = create_redacted_relation
152 get old_relation_path(relation, 1, :params => { :show_redactions => true })
153 assert_response :redirect
156 test "don't reveal redacted versions to regular users" do
157 session_for(create(:user))
158 relation = create_redacted_relation
159 get old_relation_path(relation, 1, :params => { :show_redactions => true })
160 assert_response :redirect
163 test "reveal redacted versions to moderators" do
164 session_for(create(:moderator_user))
165 relation = create_redacted_relation
166 get old_relation_path(relation, 1, :params => { :show_redactions => true })
167 assert_response :success
168 assert_select "td", :text => "TOP SECRET", :count => 1
169 assert_select ".secondary-actions a[href='#{old_relation_path relation, 1}']", :count => 1
173 get old_relation_path(0, 0)
174 assert_response :not_found
175 assert_template "old_relations/not_found"
176 assert_template :layout => "map"
177 assert_select "#sidebar_content", /relation #0 version 0 could not be found/
180 def test_show_timeout
181 relation = create(:relation, :with_history)
182 with_settings(:web_timeout => -1) do
183 get old_relation_path(relation, 1)
185 assert_response :error
186 assert_template :layout => "map"
187 assert_dom "h2", "Timeout Error"
188 assert_dom "p", /#{Regexp.quote("the relation with the id #{relation.id}")}/
193 def create_redacted_relation
194 create(:relation, :with_history, :version => 2) do |relation|
195 relation_v1 = relation.old_relations.find_by(:version => 1)
196 create(:old_relation_tag, :old_relation => relation_v1, :k => "name", :v => "TOP SECRET")
197 relation_v1.redact!(create(:redaction))