]> git.openstreetmap.org Git - rails.git/blob - test/controllers/old_relations_controller_test.rb
Merge pull request #5932 from tomhughes/frozen-strings
[rails.git] / test / controllers / old_relations_controller_test.rb
1 # frozen_string_literal: true
2
3 require "test_helper"
4
5 class OldRelationsControllerTest < ActionDispatch::IntegrationTest
6   def test_routes
7     assert_routing(
8       { :path => "/relation/1/history", :method => :get },
9       { :controller => "old_relations", :action => "index", :id => "1" }
10     )
11     assert_routing(
12       { :path => "/relation/1/history/2", :method => :get },
13       { :controller => "old_relations", :action => "show", :id => "1", :version => "2" }
14     )
15   end
16
17   def test_index
18     relation = create(:relation, :with_history)
19     sidebar_browse_check :relation_history_path, relation.id, "old_elements/index"
20   end
21
22   def test_index_show_redactions_to_unauthorized
23     relation = create(:relation, :with_history)
24
25     get relation_history_path(:id => relation, :params => { :show_redactions => true })
26
27     assert_response :redirect
28   end
29
30   def test_index_show_redactions_to_regular_user
31     relation = create(:relation, :with_history)
32
33     session_for(create(:user))
34     get relation_history_path(:id => relation, :params => { :show_redactions => true })
35
36     assert_response :redirect
37   end
38
39   def test_show
40     relation = create(:relation, :with_history)
41
42     get old_relation_path(relation, 1)
43
44     assert_response :success
45     assert_template "old_relations/show"
46     assert_template :layout => "map"
47   end
48
49   def test_show_with_members
50     relation = create(:relation, :with_history)
51     create(:old_relation_member, :old_relation => relation.old_relations.first)
52
53     get old_relation_path(relation, 1)
54
55     assert_response :success
56     assert_template "old_relations/show"
57     assert_template :layout => "map"
58   end
59
60   def test_show_redacted_to_unauthorized_users
61     relation = create(:relation, :with_history, :version => 2)
62     relation.old_relations.find_by(:version => 1).redact!(create(:redaction))
63
64     get old_relation_path(relation, 1, :params => { :show_redactions => true })
65
66     assert_response :redirect
67   end
68
69   def test_show_redacted_to_regular_users
70     relation = create(:relation, :with_history, :version => 2)
71     relation.old_relations.find_by(:version => 1).redact!(create(:redaction))
72
73     session_for(create(:user))
74     get old_relation_path(relation, 1, :params => { :show_redactions => true })
75
76     assert_response :redirect
77   end
78
79   def test_show_not_found
80     get old_relation_path(0, 0)
81
82     assert_response :not_found
83     assert_template "browse/not_found"
84     assert_template :layout => "map"
85     assert_select "#sidebar_content", /relation #0 version 0 could not be found/
86   end
87
88   def test_show_timeout
89     relation = create(:relation, :with_history)
90
91     with_settings(:web_timeout => -1) do
92       get old_relation_path(relation, 1)
93     end
94
95     assert_response :error
96     assert_template :layout => "map"
97     assert_dom "h2", "Timeout Error"
98     assert_dom "p", /#{Regexp.quote("the relation with the id #{relation.id}")}/
99   end
100 end