]> git.openstreetmap.org Git - rails.git/blob - test/controllers/old_ways_controller_test.rb
Move old way 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_history
16     way = create(:way, :with_history)
17     sidebar_browse_check :way_history_path, way.id, "old_elements/index"
18     assert_select "h4", /^Version/ do
19       assert_select "a[href='#{old_way_path way, 1}']", :text => "1", :count => 1
20     end
21   end
22
23   def test_history_of_redacted
24     way = create(:way, :with_history, :version => 4)
25     way_v1 = way.old_ways.find_by(:version => 1)
26     way_v1.redact!(create(:redaction))
27     way_v3 = way.old_ways.find_by(:version => 3)
28     way_v3.redact!(create(:redaction))
29
30     get way_history_path(:id => way)
31     assert_response :success
32     assert_template "old_elements/index"
33
34     # there are 4 revisions of the redacted way, but only 2
35     # should be showing details here.
36     assert_select ".browse-section", 4
37     assert_select ".browse-section.browse-redacted", 2
38     assert_select ".browse-section.browse-way", 2
39   end
40
41   def test_unredacted_history_of_redacted
42     session_for(create(:moderator_user))
43     way = create(:way, :with_history, :version => 4)
44     way_v1 = way.old_ways.find_by(:version => 1)
45     way_v1.redact!(create(:redaction))
46     way_v3 = way.old_ways.find_by(:version => 3)
47     way_v3.redact!(create(:redaction))
48
49     get way_history_path(:id => way, :params => { :show_redactions => true })
50     assert_response :success
51     assert_template "old_elements/index"
52
53     assert_select ".browse-section", 4
54     assert_select ".browse-section.browse-redacted", 0
55     assert_select ".browse-section.browse-way", 4
56   end
57
58   def test_show
59     way = create(:way, :with_history)
60
61     get old_way_path(way, 1)
62
63     assert_response :success
64     assert_template "old_ways/show"
65     assert_template :layout => "map"
66   end
67
68   def test_show_with_shared_nodes
69     node = create(:node, :with_history)
70     way = create(:way, :with_history)
71     create(:way_node, :way => way, :node => node)
72     create(:old_way_node, :old_way => way.old_ways.first, :node => node)
73     sharing_way = create(:way, :with_history)
74     create(:way_node, :way => sharing_way, :node => node)
75     create(:old_way_node, :old_way => sharing_way.old_ways.first, :node => node)
76
77     get old_way_path(way, 1)
78
79     assert_response :success
80     assert_template "old_ways/show"
81     assert_template :layout => "map"
82   end
83
84   def test_show_redacted_to_unauthorized_users
85     way = create(:way, :with_history, :version => 2)
86     way.old_ways.find_by(:version => 1).redact!(create(:redaction))
87
88     get old_way_path(way, 1, :params => { :show_redactions => true })
89
90     assert_response :redirect
91   end
92
93   def test_show_redacted_to_regular_users
94     way = create(:way, :with_history, :version => 2)
95     way.old_ways.find_by(:version => 1).redact!(create(:redaction))
96
97     session_for(create(:user))
98     get old_way_path(way, 1, :params => { :show_redactions => true })
99
100     assert_response :redirect
101   end
102
103   def test_show_not_found
104     get old_way_path(0, 0)
105
106     assert_response :not_found
107     assert_template "browse/not_found"
108     assert_template :layout => "map"
109     assert_select "#sidebar_content", /way #0 version 0 could not be found/
110   end
111
112   def test_show_timeout
113     way = create(:way, :with_history)
114
115     with_settings(:web_timeout => -1) do
116       get old_way_path(way, 1)
117     end
118
119     assert_response :error
120     assert_template :layout => "map"
121     assert_dom "h2", "Timeout Error"
122     assert_dom "p", /#{Regexp.quote("the way with the id #{way.id}")}/
123   end
124 end