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