]> git.openstreetmap.org Git - rails.git/blob - test/controllers/old_ways_controller_test.rb
Move way history ui tests to system tests
[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_show
21     way = create(:way, :with_history)
22
23     get old_way_path(way, 1)
24
25     assert_response :success
26     assert_template "old_ways/show"
27     assert_template :layout => "map"
28   end
29
30   def test_show_with_shared_nodes
31     node = create(:node, :with_history)
32     way = create(:way, :with_history)
33     create(:way_node, :way => way, :node => node)
34     create(:old_way_node, :old_way => way.old_ways.first, :node => node)
35     sharing_way = create(:way, :with_history)
36     create(:way_node, :way => sharing_way, :node => node)
37     create(:old_way_node, :old_way => sharing_way.old_ways.first, :node => node)
38
39     get old_way_path(way, 1)
40
41     assert_response :success
42     assert_template "old_ways/show"
43     assert_template :layout => "map"
44   end
45
46   def test_show_redacted_to_unauthorized_users
47     way = create(:way, :with_history, :version => 2)
48     way.old_ways.find_by(:version => 1).redact!(create(:redaction))
49
50     get old_way_path(way, 1, :params => { :show_redactions => true })
51
52     assert_response :redirect
53   end
54
55   def test_show_redacted_to_regular_users
56     way = create(:way, :with_history, :version => 2)
57     way.old_ways.find_by(:version => 1).redact!(create(:redaction))
58
59     session_for(create(:user))
60     get old_way_path(way, 1, :params => { :show_redactions => true })
61
62     assert_response :redirect
63   end
64
65   def test_show_not_found
66     get old_way_path(0, 0)
67
68     assert_response :not_found
69     assert_template "browse/not_found"
70     assert_template :layout => "map"
71     assert_select "#sidebar_content", /way #0 version 0 could not be found/
72   end
73
74   def test_show_timeout
75     way = create(:way, :with_history)
76
77     with_settings(:web_timeout => -1) do
78       get old_way_path(way, 1)
79     end
80
81     assert_response :error
82     assert_template :layout => "map"
83     assert_dom "h2", "Timeout Error"
84     assert_dom "p", /#{Regexp.quote("the way with the id #{way.id}")}/
85   end
86 end