]> git.openstreetmap.org Git - rails.git/blob - test/controllers/nodes_controller_test.rb
Remove checks for absence of links to current element versions
[rails.git] / test / controllers / nodes_controller_test.rb
1 require "test_helper"
2
3 class NodesControllerTest < ActionDispatch::IntegrationTest
4   ##
5   # test all routes which lead to this controller
6   def test_routes
7     assert_routing(
8       { :path => "/node/1", :method => :get },
9       { :controller => "nodes", :action => "show", :id => "1" }
10     )
11   end
12
13   def test_show
14     node = create(:node)
15     sidebar_browse_check :node_path, node.id, "elements/show"
16     assert_select "h4", /^Version/ do
17       assert_select "a[href='#{old_node_path node, 1}']", :text => "1", :count => 1
18     end
19     assert_select ".secondary-actions a[href='#{api_node_path node}']", :count => 1
20     assert_select ".secondary-actions a[href='#{node_history_path node}']", :count => 1
21   end
22
23   def test_show_multiple_versions
24     node = create(:node, :with_history, :version => 2)
25     sidebar_browse_check :node_path, node.id, "elements/show"
26     assert_select ".secondary-actions a[href='#{node_history_path node}']", :count => 1
27     assert_select ".secondary-actions a[href='#{old_node_path node, 1}']", :count => 1
28     assert_select ".secondary-actions a[href='#{old_node_path node, 2}']", :count => 1
29   end
30
31   def test_show_relation_member
32     member = create(:node)
33     relation = create(:relation)
34     create(:relation_member, :relation => relation, :member => member)
35     sidebar_browse_check :node_path, member.id, "elements/show"
36     assert_select "a[href='#{relation_path relation}']", :count => 1
37   end
38
39   def test_show_deleted
40     node = create(:node, :visible => false)
41     sidebar_browse_check :node_path, node.id, "elements/show"
42     assert_select "h4", /^Version/ do
43       assert_select "a[href='#{old_node_path node, 1}']", :text => "1", :count => 1
44     end
45     assert_select "a[href='#{api_node_path node}']", :count => 0
46   end
47
48   def test_show_redacted
49     node = create(:node, :with_history, :deleted, :version => 2)
50     node_v1 = node.old_nodes.find_by(:version => 1)
51     node_v1.redact!(create(:redaction))
52
53     get node_path(node)
54     assert_response :success
55     assert_template "elements/show"
56
57     # check that we don't show lat/lon for a redacted node.
58     assert_select ".browse-section", 1
59     assert_select ".browse-section.browse-node", 1
60     assert_select ".browse-section.browse-node .latitude", 0
61     assert_select ".browse-section.browse-node .longitude", 0
62   end
63
64   def test_show_secondary_actions_to_anonymous_user
65     node = create(:node, :with_history)
66     get node_path(node)
67     assert_response :success
68     assert_select ".secondary-actions a", :text => "View Details", :count => 0
69     assert_select ".secondary-actions a", :text => "View History", :count => 1
70     assert_select ".secondary-actions a", :text => "View Unredacted History", :count => 0
71   end
72
73   def test_show_secondary_actions_to_regular_user
74     session_for(create(:user))
75     node = create(:node, :with_history)
76     get node_path(node)
77     assert_response :success
78     assert_select ".secondary-actions a", :text => "View Details", :count => 0
79     assert_select ".secondary-actions a", :text => "View History", :count => 1
80     assert_select ".secondary-actions a", :text => "View Unredacted History", :count => 0
81   end
82
83   def test_show_secondary_actions_to_moderator
84     session_for(create(:moderator_user))
85     node = create(:node, :with_history)
86     get node_path(node)
87     assert_response :success
88     assert_select ".secondary-actions a", :text => "View Details", :count => 0
89     assert_select ".secondary-actions a", :text => "View History", :count => 1
90     assert_select ".secondary-actions a", :text => "View Unredacted History", :count => 1
91   end
92
93   def test_show_timeout
94     node = create(:node)
95     with_settings(:web_timeout => -1) do
96       get node_path(node)
97     end
98     assert_response :error
99     assert_template :layout => "map"
100     assert_dom "h2", "Timeout Error"
101     assert_dom "p", /#{Regexp.quote("the node with the id #{node.id}")}/
102   end
103 end