]> git.openstreetmap.org Git - rails.git/blob - test/controllers/old_relations_controller_test.rb
Move old relation ui tests to system tests
[rails.git] / test / controllers / old_relations_controller_test.rb
1 require "test_helper"
2
3 class OldRelationsControllerTest < ActionDispatch::IntegrationTest
4   def test_routes
5     assert_routing(
6       { :path => "/relation/1/history", :method => :get },
7       { :controller => "old_relations", :action => "index", :id => "1" }
8     )
9     assert_routing(
10       { :path => "/relation/1/history/2", :method => :get },
11       { :controller => "old_relations", :action => "show", :id => "1", :version => "2" }
12     )
13   end
14
15   def test_history
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
20     end
21   end
22
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))
29
30     get relation_history_path(:id => relation)
31     assert_response :success
32     assert_template "old_elements/index"
33
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
39   end
40
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))
48
49     get relation_history_path(:id => relation, :params => { :show_redactions => true })
50     assert_response :success
51     assert_template "old_elements/index"
52
53     assert_select ".browse-section", 4
54     assert_select ".browse-section.browse-redacted", 0
55     assert_select ".browse-section.browse-relation", 4
56   end
57
58   def test_show
59     relation = create(:relation, :with_history)
60
61     get old_relation_path(relation, 1)
62
63     assert_response :success
64     assert_template "old_relations/show"
65     assert_template :layout => "map"
66   end
67
68   def test_show_with_members
69     relation = create(:relation, :with_history)
70     create(:old_relation_member, :old_relation => relation.old_relations.first)
71
72     get old_relation_path(relation, 1)
73
74     assert_response :success
75     assert_template "old_relations/show"
76     assert_template :layout => "map"
77   end
78
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))
82
83     get old_relation_path(relation, 1, :params => { :show_redactions => true })
84
85     assert_response :redirect
86   end
87
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))
91
92     session_for(create(:user))
93     get old_relation_path(relation, 1, :params => { :show_redactions => true })
94
95     assert_response :redirect
96   end
97
98   def test_show_not_found
99     get old_relation_path(0, 0)
100
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/
105   end
106
107   def test_show_timeout
108     relation = create(:relation, :with_history)
109
110     with_settings(:web_timeout => -1) do
111       get old_relation_path(relation, 1)
112     end
113
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}")}/
118   end
119 end