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