]> git.openstreetmap.org Git - rails.git/blob - test/controllers/nodes_controller_test.rb
Merge remote-tracking branch 'upstream/pull/4786'
[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, "browse/feature"
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     assert_select ".secondary-actions a[href='#{old_node_path node, 1}']", :count => 0
22   end
23
24   def test_show_multiple_versions
25     node = create(:node, :with_history, :version => 2)
26     sidebar_browse_check :node_path, node.id, "browse/feature"
27     assert_select ".secondary-actions a[href='#{node_history_path node}']", :count => 1
28     assert_select ".secondary-actions a[href='#{old_node_path node, 1}']", :count => 1
29     assert_select ".secondary-actions a[href='#{old_node_path node, 2}']", :count => 1
30   end
31
32   def test_show_relation_member
33     member = create(:node)
34     relation = create(:relation)
35     create(:relation_member, :relation => relation, :member => member)
36     sidebar_browse_check :node_path, member.id, "browse/feature"
37     assert_select "a[href='#{relation_path relation}']", :count => 1
38   end
39
40   def test_show_deleted
41     node = create(:node, :visible => false)
42     sidebar_browse_check :node_path, node.id, "browse/feature"
43     assert_select "h4", /^Version/ do
44       assert_select "a[href='#{old_node_path node, 1}']", :text => "1", :count => 1
45     end
46     assert_select "a[href='#{api_node_path node}']", :count => 0
47   end
48
49   def test_show_redacted
50     node = create(:node, :with_history, :deleted, :version => 2)
51     node_v1 = node.old_nodes.find_by(:version => 1)
52     node_v1.redact!(create(:redaction))
53
54     get node_path(node)
55     assert_response :success
56     assert_template "feature"
57
58     # check that we don't show lat/lon for a redacted node.
59     assert_select ".browse-section", 1
60     assert_select ".browse-section.browse-node", 1
61     assert_select ".browse-section.browse-node .latitude", 0
62     assert_select ".browse-section.browse-node .longitude", 0
63   end
64
65   def test_show_secondary_actions_to_anonymous_user
66     node = create(:node, :with_history)
67     get node_path(node)
68     assert_response :success
69     assert_select ".secondary-actions a", :text => "View Details", :count => 0
70     assert_select ".secondary-actions a", :text => "View History", :count => 1
71     assert_select ".secondary-actions a", :text => "View Unredacted History", :count => 0
72   end
73
74   def test_show_secondary_actions_to_regular_user
75     session_for(create(:user))
76     node = create(:node, :with_history)
77     get node_path(node)
78     assert_response :success
79     assert_select ".secondary-actions a", :text => "View Details", :count => 0
80     assert_select ".secondary-actions a", :text => "View History", :count => 1
81     assert_select ".secondary-actions a", :text => "View Unredacted History", :count => 0
82   end
83
84   def test_show_secondary_actions_to_moderator
85     session_for(create(:moderator_user))
86     node = create(:node, :with_history)
87     get node_path(node)
88     assert_response :success
89     assert_select ".secondary-actions a", :text => "View Details", :count => 0
90     assert_select ".secondary-actions a", :text => "View History", :count => 1
91     assert_select ".secondary-actions a", :text => "View Unredacted History", :count => 1
92   end
93 end