3 class OldRelationsControllerTest < ActionDispatch::IntegrationTest
6 { :path => "/relation/1/history/2", :method => :get },
7 { :controller => "old_relations", :action => "show", :id => "1", :version => "2" }
11 def test_visible_with_one_version
12 relation = create(:relation, :with_history)
13 get old_relation_path(relation, 1)
14 assert_response :success
15 assert_template "old_relations/show"
16 assert_template :layout => "map"
17 assert_select "h4", /^Version/ do
18 assert_select "a[href='#{old_relation_path relation, 1}']", :count => 0
20 assert_select ".secondary-actions a[href='#{relation_version_path relation, 1}']", :count => 1
21 assert_select ".secondary-actions a[href='#{relation_path relation}']", :count => 1
22 assert_select ".secondary-actions a[href='#{relation_history_path relation}']", :count => 1
25 def test_visible_with_two_versions
26 relation = create(:relation, :with_history, :version => 2)
27 get old_relation_path(relation, 1)
28 assert_response :success
29 assert_template "old_relations/show"
30 assert_template :layout => "map"
31 assert_select "h4", /^Version/ do
32 assert_select "a[href='#{old_relation_path relation, 1}']", :count => 0
34 assert_select ".secondary-actions a[href='#{relation_version_path relation, 1}']", :count => 1
35 assert_select ".secondary-actions a[href='#{relation_path relation}']", :count => 1
36 assert_select ".secondary-actions a[href='#{relation_history_path relation}']", :count => 1
37 assert_select ".secondary-actions a[href='#{old_relation_path relation, 2}']", :count => 1
39 get old_relation_path(relation, 2)
40 assert_response :success
41 assert_template "old_relations/show"
42 assert_template :layout => "map"
43 assert_select "h4", /^Version/ do
44 assert_select "a[href='#{old_relation_path relation, 2}']", :count => 0
46 assert_select ".secondary-actions a[href='#{relation_version_path relation, 2}']", :count => 1
47 assert_select ".secondary-actions a[href='#{relation_path relation}']", :count => 1
48 assert_select ".secondary-actions a[href='#{relation_history_path relation}']", :count => 1
49 assert_select ".secondary-actions a[href='#{old_relation_path relation, 1}']", :count => 1
52 def test_visible_with_members
53 relation = create(:relation, :with_history)
54 create(:old_relation_member, :old_relation => relation.old_relations.first)
55 get old_relation_path(relation, 1)
56 assert_response :success
57 assert_template "old_relations/show"
58 assert_template :layout => "map"
62 relation = create_redacted_relation
63 get old_relation_path(relation, 1)
64 assert_response :success
65 assert_template "old_relations/show"
66 assert_template :layout => "map"
67 assert_select ".secondary-actions a[href='#{relation_path relation}']", :count => 1
68 assert_select ".secondary-actions a[href='#{old_relation_path relation, 1}']", :count => 0
69 assert_select ".secondary-actions a[href='#{relation_version_path relation, 1}']", :count => 0
72 test "don't show redacted versions to anonymous users" do
73 relation = create_redacted_relation
74 get old_relation_path(relation, 1, :params => { :show_redactions => true })
75 assert_response :redirect
78 test "don't show redacted versions to regular users" do
79 session_for(create(:user))
80 relation = create_redacted_relation
81 get old_relation_path(relation, 1, :params => { :show_redactions => true })
82 assert_response :redirect
85 test "show redacted versions to moderators" do
86 session_for(create(:moderator_user))
87 relation = create_redacted_relation
88 get old_relation_path(relation, 1, :params => { :show_redactions => true })
89 assert_response :success
93 get old_relation_path(0, 0)
94 assert_response :not_found
95 assert_template "old_relations/not_found"
96 assert_template :layout => "map"
97 assert_select "#sidebar_content", /relation #0 version 0 could not be found/
102 def create_redacted_relation
103 create(:relation, :with_history, :deleted, :version => 2) do |relation|
104 relation_v1 = relation.old_relations.find_by(:version => 1)
105 relation_v1.redact!(create(:redaction))