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