]> git.openstreetmap.org Git - rails.git/blob - test/controllers/nodes_controller_test.rb
Move current element actions to their own controllers
[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_deleted
33     node = create(:node, :visible => false)
34     sidebar_browse_check :node_path, node.id, "browse/feature"
35     assert_select "h4", /^Version/ do
36       assert_select "a[href='#{old_node_path node, 1}']", :text => "1", :count => 1
37     end
38     assert_select "a[href='#{api_node_path node}']", :count => 0
39   end
40
41   def test_show_redacted
42     node = create(:node, :with_history, :deleted, :version => 2)
43     node_v1 = node.old_nodes.find_by(:version => 1)
44     node_v1.redact!(create(:redaction))
45
46     get node_path(node)
47     assert_response :success
48     assert_template "feature"
49
50     # check that we don't show lat/lon for a redacted node.
51     assert_select ".browse-section", 1
52     assert_select ".browse-section.browse-node", 1
53     assert_select ".browse-section.browse-node .latitude", 0
54     assert_select ".browse-section.browse-node .longitude", 0
55   end
56
57   def test_show_secondary_actions_to_anonymous_user
58     node = create(:node, :with_history)
59     get node_path(node)
60     assert_response :success
61     assert_select ".secondary-actions a", :text => "View Details", :count => 0
62     assert_select ".secondary-actions a", :text => "View History", :count => 1
63     assert_select ".secondary-actions a", :text => "View Unredacted History", :count => 0
64   end
65
66   def test_show_secondary_actions_to_regular_user
67     session_for(create(:user))
68     node = create(:node, :with_history)
69     get node_path(node)
70     assert_response :success
71     assert_select ".secondary-actions a", :text => "View Details", :count => 0
72     assert_select ".secondary-actions a", :text => "View History", :count => 1
73     assert_select ".secondary-actions a", :text => "View Unredacted History", :count => 0
74   end
75
76   def test_show_secondary_actions_to_moderator
77     session_for(create(:moderator_user))
78     node = create(:node, :with_history)
79     get node_path(node)
80     assert_response :success
81     assert_select ".secondary-actions a", :text => "View Details", :count => 0
82     assert_select ".secondary-actions a", :text => "View History", :count => 1
83     assert_select ".secondary-actions a", :text => "View Unredacted History", :count => 1
84   end
85 end