1 # frozen_string_literal: true
 
   5 class OldRelationsControllerTest < ActionDispatch::IntegrationTest
 
   8       { :path => "/relation/1/history", :method => :get },
 
   9       { :controller => "old_relations", :action => "index", :id => "1" }
 
  12       { :path => "/relation/1/history/2", :method => :get },
 
  13       { :controller => "old_relations", :action => "show", :id => "1", :version => "2" }
 
  18     relation = create(:relation, :with_history)
 
  19     sidebar_browse_check :relation_history_path, relation.id, "old_elements/index"
 
  22   def test_index_show_redactions_to_unauthorized
 
  23     relation = create(:relation, :with_history)
 
  25     get relation_history_path(:id => relation, :params => { :show_redactions => true })
 
  27     assert_response :redirect
 
  30   def test_index_show_redactions_to_regular_user
 
  31     relation = create(:relation, :with_history)
 
  33     session_for(create(:user))
 
  34     get relation_history_path(:id => relation, :params => { :show_redactions => true })
 
  36     assert_response :redirect
 
  40     relation = create(:relation, :with_history)
 
  42     get old_relation_path(relation, 1)
 
  44     assert_response :success
 
  45     assert_template "old_relations/show"
 
  46     assert_template :layout => "map"
 
  49   def test_show_with_members
 
  50     relation = create(:relation, :with_history)
 
  51     create(:old_relation_member, :old_relation => relation.old_relations.first)
 
  53     get old_relation_path(relation, 1)
 
  55     assert_response :success
 
  56     assert_template "old_relations/show"
 
  57     assert_template :layout => "map"
 
  60   def test_show_redacted_to_unauthorized_users
 
  61     relation = create(:relation, :with_history, :version => 2)
 
  62     relation.old_relations.find_by(:version => 1).redact!(create(:redaction))
 
  64     get old_relation_path(relation, 1, :params => { :show_redactions => true })
 
  66     assert_response :redirect
 
  69   def test_show_redacted_to_regular_users
 
  70     relation = create(:relation, :with_history, :version => 2)
 
  71     relation.old_relations.find_by(:version => 1).redact!(create(:redaction))
 
  73     session_for(create(:user))
 
  74     get old_relation_path(relation, 1, :params => { :show_redactions => true })
 
  76     assert_response :redirect
 
  79   def test_show_not_found
 
  80     get old_relation_path(0, 0)
 
  82     assert_response :not_found
 
  83     assert_template "browse/not_found"
 
  84     assert_template :layout => "map"
 
  85     assert_select "#sidebar_content", /relation #0 version 0 could not be found/
 
  89     relation = create(:relation, :with_history)
 
  91     with_settings(:web_timeout => -1) do
 
  92       get old_relation_path(relation, 1)
 
  95     assert_response :error
 
  96     assert_template :layout => "map"
 
  97     assert_dom "h2", "Timeout Error"
 
  98     assert_dom "p", /#{Regexp.quote("the relation with the id #{relation.id}")}/