]> git.openstreetmap.org Git - rails.git/blob - test/controllers/old_nodes_controller_test.rb
Link to previous/next versions from node version pages
[rails.git] / test / controllers / old_nodes_controller_test.rb
1 require "test_helper"
2
3 class OldNodesControllerTest < ActionDispatch::IntegrationTest
4   def test_routes
5     assert_routing(
6       { :path => "/node/1/history/2", :method => :get },
7       { :controller => "old_nodes", :action => "show", :id => "1", :version => "2" }
8     )
9   end
10
11   def test_visible_with_one_version
12     node = create(:node, :with_history)
13     get old_node_path(node, 1)
14     assert_response :success
15     assert_template "old_nodes/show"
16     assert_template :layout => "map"
17     assert_select "h4", /^Version/ do
18       assert_select "a[href='#{old_node_path node, 1}']", :count => 0
19     end
20     assert_select ".secondary-actions a[href='#{node_version_path node, 1}']", :count => 1
21     assert_select ".secondary-actions a[href='#{node_history_path node}']", :count => 1
22   end
23
24   def test_visible_with_two_versions
25     node = create(:node, :with_history, :version => 2)
26     get old_node_path(node, 1)
27     assert_response :success
28     assert_template "old_nodes/show"
29     assert_template :layout => "map"
30     assert_select "h4", /^Version/ do
31       assert_select "a[href='#{old_node_path node, 1}']", :count => 0
32     end
33     assert_select ".secondary-actions a[href='#{node_version_path node, 1}']", :count => 1
34     assert_select ".secondary-actions a[href='#{node_history_path node}']", :count => 1
35     assert_select ".secondary-actions a[href='#{old_node_path node, 2}']", :count => 1
36
37     get old_node_path(node, 2)
38     assert_response :success
39     assert_template "old_nodes/show"
40     assert_template :layout => "map"
41     assert_select "h4", /^Version/ do
42       assert_select "a[href='#{old_node_path node, 2}']", :count => 0
43     end
44     assert_select ".secondary-actions a[href='#{node_version_path node, 2}']", :count => 1
45     assert_select ".secondary-actions a[href='#{node_history_path node}']", :count => 1
46     assert_select ".secondary-actions a[href='#{old_node_path node, 1}']", :count => 1
47   end
48
49   def test_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     get old_node_path(node, 1)
54     assert_response :success
55     assert_template "old_nodes/show"
56     assert_template :layout => "map"
57     assert_select ".secondary-actions a[href='#{old_node_path node, 1}']", :count => 0
58     assert_select ".secondary-actions a[href='#{node_version_path node, 1}']", :count => 0
59   end
60
61   def test_not_found
62     get old_node_path(0, 0)
63     assert_response :not_found
64     assert_template "old_nodes/not_found"
65     assert_template :layout => "map"
66     assert_select "#sidebar_content", /node #0 version 0 could not be found/
67   end
68 end