]> git.openstreetmap.org Git - rails.git/blob - test/controllers/old_relations_controller_test.rb
Merge remote-tracking branch 'upstream/pull/6129'
[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_index
16     relation = create(:relation, :with_history)
17     sidebar_browse_check :relation_history_path, relation.id, "old_elements/index"
18   end
19
20   def test_index_show_redactions_to_unauthorized
21     relation = create(:relation, :with_history)
22
23     get relation_history_path(:id => relation, :params => { :show_redactions => true })
24
25     assert_response :redirect
26   end
27
28   def test_index_show_redactions_to_regular_user
29     relation = create(:relation, :with_history)
30
31     session_for(create(:user))
32     get relation_history_path(:id => relation, :params => { :show_redactions => true })
33
34     assert_response :redirect
35   end
36
37   def test_show
38     relation = create(:relation, :with_history)
39
40     get old_relation_path(relation, 1)
41
42     assert_response :success
43     assert_template "old_relations/show"
44     assert_template :layout => "map"
45   end
46
47   def test_show_with_members
48     relation = create(:relation, :with_history)
49     create(:old_relation_member, :old_relation => relation.old_relations.first)
50
51     get old_relation_path(relation, 1)
52
53     assert_response :success
54     assert_template "old_relations/show"
55     assert_template :layout => "map"
56   end
57
58   def test_show_redacted_to_unauthorized_users
59     relation = create(:relation, :with_history, :version => 2)
60     relation.old_relations.find_by(:version => 1).redact!(create(:redaction))
61
62     get old_relation_path(relation, 1, :params => { :show_redactions => true })
63
64     assert_response :redirect
65   end
66
67   def test_show_redacted_to_regular_users
68     relation = create(:relation, :with_history, :version => 2)
69     relation.old_relations.find_by(:version => 1).redact!(create(:redaction))
70
71     session_for(create(:user))
72     get old_relation_path(relation, 1, :params => { :show_redactions => true })
73
74     assert_response :redirect
75   end
76
77   def test_show_not_found
78     get old_relation_path(0, 0)
79
80     assert_response :not_found
81     assert_template "browse/not_found"
82     assert_template :layout => "map"
83     assert_select "#sidebar_content", /relation #0 version 0 could not be found/
84   end
85
86   def test_show_timeout
87     relation = create(:relation, :with_history)
88
89     with_settings(:web_timeout => -1) do
90       get old_relation_path(relation, 1)
91     end
92
93     assert_response :error
94     assert_template :layout => "map"
95     assert_dom "h2", "Timeout Error"
96     assert_dom "p", /#{Regexp.quote("the relation with the id #{relation.id}")}/
97   end
98 end