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, "old_elements/index"
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 "old_elements/index"
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 "old_elements/index"
53 assert_select ".browse-section", 4
54 assert_select ".browse-section.browse-redacted", 0
55 assert_select ".browse-section.browse-relation", 4
59 relation = create(:relation, :with_history)
61 get old_relation_path(relation, 1)
63 assert_response :success
64 assert_template "old_relations/show"
65 assert_template :layout => "map"
68 def test_show_with_members
69 relation = create(:relation, :with_history)
70 create(:old_relation_member, :old_relation => relation.old_relations.first)
72 get old_relation_path(relation, 1)
74 assert_response :success
75 assert_template "old_relations/show"
76 assert_template :layout => "map"
79 def test_show_redacted_to_unauthorized_users
80 relation = create(:relation, :with_history, :version => 2)
81 relation.old_relations.find_by(:version => 1).redact!(create(:redaction))
83 get old_relation_path(relation, 1, :params => { :show_redactions => true })
85 assert_response :redirect
88 def test_show_redacted_to_regular_users
89 relation = create(:relation, :with_history, :version => 2)
90 relation.old_relations.find_by(:version => 1).redact!(create(:redaction))
92 session_for(create(:user))
93 get old_relation_path(relation, 1, :params => { :show_redactions => true })
95 assert_response :redirect
98 def test_show_not_found
99 get old_relation_path(0, 0)
101 assert_response :not_found
102 assert_template "browse/not_found"
103 assert_template :layout => "map"
104 assert_select "#sidebar_content", /relation #0 version 0 could not be found/
107 def test_show_timeout
108 relation = create(:relation, :with_history)
110 with_settings(:web_timeout => -1) do
111 get old_relation_path(relation, 1)
114 assert_response :error
115 assert_template :layout => "map"
116 assert_dom "h2", "Timeout Error"
117 assert_dom "p", /#{Regexp.quote("the relation with the id #{relation.id}")}/