3 class OldNodesControllerTest < ActionDispatch::IntegrationTest
 
   6       { :path => "/node/1/history", :method => :get },
 
   7       { :controller => "old_nodes", :action => "index", :id => "1" }
 
  10       { :path => "/node/1/history/2", :method => :get },
 
  11       { :controller => "old_nodes", :action => "show", :id => "1", :version => "2" }
 
  16     node = create(:node, :with_history)
 
  17     sidebar_browse_check :node_history_path, node.id, "old_elements/index"
 
  18     assert_select "h4", /^Version/ do
 
  19       assert_select "a[href='#{old_node_path node, 1}']", :text => "1", :count => 1
 
  23   def test_history_of_redacted
 
  24     node = create(:node, :with_history, :deleted, :version => 2)
 
  25     node_v1 = node.old_nodes.find_by(:version => 1)
 
  26     node_v1.redact!(create(:redaction))
 
  28     get node_history_path(:id => node)
 
  29     assert_response :success
 
  30     assert_template "old_elements/index"
 
  32     # there are 2 revisions of the redacted node, but only one
 
  33     # should be showing details here.
 
  34     assert_select ".browse-section", 2
 
  35     assert_select ".browse-section.browse-redacted", 1
 
  36     assert_select ".browse-section.browse-node", 1
 
  37     assert_select ".browse-section.browse-node .latitude", 0
 
  38     assert_select ".browse-section.browse-node .longitude", 0
 
  41   def test_unredacted_history_of_redacted
 
  42     session_for(create(:moderator_user))
 
  43     node = create(:node, :with_history, :deleted, :version => 2)
 
  44     node_v1 = node.old_nodes.find_by(:version => 1)
 
  45     node_v1.redact!(create(:redaction))
 
  47     get node_history_path(:id => node, :params => { :show_redactions => true })
 
  48     assert_response :success
 
  49     assert_template "old_elements/index"
 
  51     assert_select ".browse-section", 2
 
  52     assert_select ".browse-section.browse-redacted", 0
 
  53     assert_select ".browse-section.browse-node", 2
 
  56   def test_anonymous_user_history_page_secondary_actions
 
  57     node = create(:node, :with_history)
 
  58     get node_history_path(:id => node)
 
  59     assert_response :success
 
  60     assert_select ".secondary-actions a", :text => "View Details", :count => 1
 
  61     assert_select ".secondary-actions a", :text => "View History", :count => 0
 
  62     assert_select ".secondary-actions a", :text => "View Unredacted History", :count => 0
 
  65   def test_regular_user_history_page_secondary_actions
 
  66     session_for(create(:user))
 
  67     node = create(:node, :with_history)
 
  68     get node_history_path(:id => node)
 
  69     assert_response :success
 
  70     assert_select ".secondary-actions a", :text => "View Details", :count => 1
 
  71     assert_select ".secondary-actions a", :text => "View History", :count => 0
 
  72     assert_select ".secondary-actions a", :text => "View Unredacted History", :count => 0
 
  75   def test_moderator_user_history_page_secondary_actions
 
  76     session_for(create(:moderator_user))
 
  77     node = create(:node, :with_history)
 
  78     get node_history_path(:id => node)
 
  79     assert_response :success
 
  80     assert_select ".secondary-actions a", :text => "View Details", :count => 1
 
  81     assert_select ".secondary-actions a", :text => "View History", :count => 0
 
  82     assert_select ".secondary-actions a", :text => "View Unredacted History", :count => 1
 
  85   def test_anonymous_user_unredacted_history_page_secondary_actions
 
  86     node = create(:node, :with_history)
 
  87     get node_history_path(:id => node, :params => { :show_redactions => true })
 
  88     assert_response :redirect
 
  91   def test_regular_user_unredacted_history_page_secondary_actions
 
  92     session_for(create(:user))
 
  93     node = create(:node, :with_history)
 
  94     get node_history_path(:id => node, :params => { :show_redactions => true })
 
  95     assert_response :redirect
 
  98   def test_moderator_user_unredacted_history_page_secondary_actions
 
  99     session_for(create(:moderator_user))
 
 100     node = create(:node, :with_history)
 
 101     get node_history_path(:id => node, :params => { :show_redactions => true })
 
 102     assert_response :success
 
 103     assert_select ".secondary-actions a", :text => "View Details", :count => 1
 
 104     assert_select ".secondary-actions a", :text => "View History", :count => 1
 
 105     assert_select ".secondary-actions a", :text => "View Unredacted History", :count => 0
 
 108   def test_visible_with_one_version
 
 109     node = create(:node, :with_history)
 
 110     get old_node_path(node, 1)
 
 111     assert_response :success
 
 112     assert_template "old_nodes/show"
 
 113     assert_template :layout => "map"
 
 114     assert_select "h4", /^Version/ do
 
 115       assert_select "a[href='#{old_node_path node, 1}']", :count => 0
 
 117     assert_select ".secondary-actions a[href='#{api_node_version_path node, 1}']", :count => 1
 
 118     assert_select ".secondary-actions a[href='#{node_path node}']", :count => 1
 
 119     assert_select ".secondary-actions a[href='#{old_node_path node, 1, :params => { :show_redactions => true }}']", :count => 0
 
 120     assert_select ".secondary-actions a[href='#{node_history_path node}']", :count => 1
 
 123   def test_visible_with_two_versions
 
 124     node = create(:node, :with_history, :version => 2)
 
 125     get old_node_path(node, 1)
 
 126     assert_response :success
 
 127     assert_template "old_nodes/show"
 
 128     assert_template :layout => "map"
 
 129     assert_select "h4", /^Version/ do
 
 130       assert_select "a[href='#{old_node_path node, 1}']", :count => 0
 
 132     assert_select ".secondary-actions a[href='#{api_node_version_path node, 1}']", :count => 1
 
 133     assert_select ".secondary-actions a[href='#{node_path node}']", :count => 1
 
 134     assert_select ".secondary-actions a[href='#{node_history_path node}']", :count => 1
 
 135     assert_select ".secondary-actions a[href='#{old_node_path node, 2}']", :count => 1
 
 137     get old_node_path(node, 2)
 
 138     assert_response :success
 
 139     assert_template "old_nodes/show"
 
 140     assert_template :layout => "map"
 
 141     assert_select "h4", /^Version/ do
 
 142       assert_select "a[href='#{old_node_path node, 2}']", :count => 0
 
 144     assert_select ".secondary-actions a[href='#{api_node_version_path node, 2}']", :count => 1
 
 145     assert_select ".secondary-actions a[href='#{node_path node}']", :count => 1
 
 146     assert_select ".secondary-actions a[href='#{node_history_path node}']", :count => 1
 
 147     assert_select ".secondary-actions a[href='#{old_node_path node, 1}']", :count => 1
 
 150   test "show unrevealed redacted versions to anonymous users" do
 
 151     node = create_redacted_node
 
 152     get old_node_path(node, 1)
 
 153     assert_response :success
 
 154     assert_template "old_nodes/show"
 
 155     assert_template :layout => "map"
 
 156     assert_select "td", :text => "TOP SECRET", :count => 0
 
 157     assert_select ".secondary-actions a[href='#{node_path node}']", :count => 1
 
 158     assert_select ".secondary-actions a[href='#{old_node_path node, 1, :params => { :show_redactions => true }}']", :count => 0
 
 159     assert_select ".secondary-actions a[href='#{old_node_path node, 1}']", :count => 0
 
 160     assert_select ".secondary-actions a[href='#{api_node_version_path node, 1}']", :count => 0
 
 163   test "show unrevealed redacted versions to regular users" do
 
 164     session_for(create(:user))
 
 165     node = create_redacted_node
 
 166     get old_node_path(node, 1)
 
 167     assert_response :success
 
 168     assert_template "old_nodes/show"
 
 169     assert_template :layout => "map"
 
 170     assert_select "td", :text => "TOP SECRET", :count => 0
 
 171     assert_select ".secondary-actions a[href='#{node_path node}']", :count => 1
 
 172     assert_select ".secondary-actions a[href='#{old_node_path node, 1, :params => { :show_redactions => true }}']", :count => 0
 
 173     assert_select ".secondary-actions a[href='#{old_node_path node, 1}']", :count => 0
 
 174     assert_select ".secondary-actions a[href='#{api_node_version_path node, 1}']", :count => 0
 
 177   test "show unrevealed redacted versions to moderators" do
 
 178     session_for(create(:moderator_user))
 
 179     node = create_redacted_node
 
 180     get old_node_path(node, 1)
 
 181     assert_response :success
 
 182     assert_template "old_nodes/show"
 
 183     assert_template :layout => "map"
 
 184     assert_select "td", :text => "TOP SECRET", :count => 0
 
 185     assert_select ".secondary-actions a[href='#{node_path node}']", :count => 1
 
 186     assert_select ".secondary-actions a[href='#{old_node_path node, 1, :params => { :show_redactions => true }}']", :count => 1
 
 187     assert_select ".secondary-actions a[href='#{old_node_path node, 1}']", :count => 0
 
 188     assert_select ".secondary-actions a[href='#{api_node_version_path node, 1}']", :count => 0
 
 191   test "don't reveal redacted versions to anonymous users" do
 
 192     node = create_redacted_node
 
 193     get old_node_path(node, 1, :params => { :show_redactions => true })
 
 194     assert_response :redirect
 
 197   test "don't reveal redacted versions to regular users" do
 
 198     session_for(create(:user))
 
 199     node = create_redacted_node
 
 200     get old_node_path(node, 1, :params => { :show_redactions => true })
 
 201     assert_response :redirect
 
 204   test "reveal redacted versions to moderators" do
 
 205     session_for(create(:moderator_user))
 
 206     node = create_redacted_node
 
 207     get old_node_path(node, 1, :params => { :show_redactions => true })
 
 208     assert_response :success
 
 209     assert_select "td", :text => "TOP SECRET", :count => 1
 
 210     assert_select ".secondary-actions a[href='#{old_node_path node, 1}']", :count => 1
 
 214     get old_node_path(0, 0)
 
 215     assert_response :not_found
 
 216     assert_template "browse/not_found"
 
 217     assert_template :layout => "map"
 
 218     assert_select "#sidebar_content", /node #0 version 0 could not be found/
 
 221   def test_show_timeout
 
 222     node = create(:node, :with_history)
 
 223     with_settings(:web_timeout => -1) do
 
 224       get old_node_path(node, 1)
 
 226     assert_response :error
 
 227     assert_template :layout => "map"
 
 228     assert_dom "h2", "Timeout Error"
 
 229     assert_dom "p", /#{Regexp.quote("the node with the id #{node.id}")}/
 
 234   def create_redacted_node
 
 235     create(:node, :with_history, :version => 2) do |node|
 
 236       node_v1 = node.old_nodes.find_by(:version => 1)
 
 237       create(:old_node_tag, :old_node => node_v1, :k => "name", :v => "TOP SECRET")
 
 238       node_v1.redact!(create(:redaction))