1 # frozen_string_literal: true
5 class OldWaysControllerTest < ActionDispatch::IntegrationTest
8 { :path => "/way/1/history", :method => :get },
9 { :controller => "old_ways", :action => "index", :id => "1" }
12 { :path => "/way/1/history/2", :method => :get },
13 { :controller => "old_ways", :action => "show", :id => "1", :version => "2" }
18 way = create(:way, :with_history)
19 sidebar_browse_check :way_history_path, way.id, "old_elements/index"
22 def test_index_show_redactions_to_unauthorized
23 way = create(:way, :with_history)
25 get way_history_path(:id => way, :params => { :show_redactions => true })
27 assert_response :redirect
30 def test_index_show_redactions_to_regular_user
31 way = create(:way, :with_history)
33 session_for(create(:user))
34 get way_history_path(:id => way, :params => { :show_redactions => true })
36 assert_response :redirect
40 way = create(:way, :with_history)
42 get old_way_path(way, 1)
44 assert_response :success
45 assert_template "old_ways/show"
46 assert_template :layout => "map"
49 def test_show_with_shared_nodes
50 node = create(:node, :with_history)
51 way = create(:way, :with_history)
52 create(:way_node, :way => way, :node => node)
53 create(:old_way_node, :old_way => way.old_ways.first, :node => node)
54 sharing_way = create(:way, :with_history)
55 create(:way_node, :way => sharing_way, :node => node)
56 create(:old_way_node, :old_way => sharing_way.old_ways.first, :node => node)
58 get old_way_path(way, 1)
60 assert_response :success
61 assert_template "old_ways/show"
62 assert_template :layout => "map"
65 def test_show_redacted_to_unauthorized_users
66 way = create(:way, :with_history, :version => 2)
67 way.old_ways.find_by(:version => 1).redact!(create(:redaction))
69 get old_way_path(way, 1, :params => { :show_redactions => true })
71 assert_response :redirect
74 def test_show_redacted_to_regular_users
75 way = create(:way, :with_history, :version => 2)
76 way.old_ways.find_by(:version => 1).redact!(create(:redaction))
78 session_for(create(:user))
79 get old_way_path(way, 1, :params => { :show_redactions => true })
81 assert_response :redirect
84 def test_show_not_found
85 get old_way_path(0, 0)
87 assert_response :not_found
88 assert_template "browse/not_found"
89 assert_template :layout => "map"
90 assert_select "#sidebar_content", /way #0 version 0 could not be found/
94 way = create(:way, :with_history)
96 with_settings(:web_timeout => -1) do
97 get old_way_path(way, 1)
100 assert_response :error
101 assert_template :layout => "map"
102 assert_dom "h2", "Timeout Error"
103 assert_dom "p", /#{Regexp.quote("the way with the id #{way.id}")}/