From 592dc5fa9a6eea1dae09a7926d3fed324f96a896 Mon Sep 17 00:00:00 2001 From: Anton Khorev Date: Sun, 22 Jun 2025 18:20:01 +0300 Subject: [PATCH] Move old relation ui tests to system tests --- .../old_relations_controller_test.rb | 111 +++------------- test/system/element_old_version_test.rb | 120 ++++++++++++++++++ 2 files changed, 135 insertions(+), 96 deletions(-) diff --git a/test/controllers/old_relations_controller_test.rb b/test/controllers/old_relations_controller_test.rb index cd6737dca..2d86400a0 100644 --- a/test/controllers/old_relations_controller_test.rb +++ b/test/controllers/old_relations_controller_test.rb @@ -55,122 +55,49 @@ class OldRelationsControllerTest < ActionDispatch::IntegrationTest assert_select ".browse-section.browse-relation", 4 end - def test_visible_with_one_version + def test_show relation = create(:relation, :with_history) - get old_relation_path(relation, 1) - assert_response :success - assert_template "old_relations/show" - assert_template :layout => "map" - assert_select "h4", /^Version/ do - assert_select "a[href='#{old_relation_path relation, 1}']", :count => 0 - end - assert_select ".secondary-actions a[href='#{api_relation_version_path relation, 1}']", :count => 1 - assert_select ".secondary-actions a[href='#{relation_path relation}']", :count => 1 - assert_select ".secondary-actions a[href='#{old_relation_path relation, 1, :params => { :show_redactions => true }}']", :count => 0 - assert_select ".secondary-actions a[href='#{relation_history_path relation}']", :count => 1 - end - def test_visible_with_two_versions - relation = create(:relation, :with_history, :version => 2) get old_relation_path(relation, 1) - assert_response :success - assert_template "old_relations/show" - assert_template :layout => "map" - assert_select "h4", /^Version/ do - assert_select "a[href='#{old_relation_path relation, 1}']", :count => 0 - end - assert_select ".secondary-actions a[href='#{api_relation_version_path relation, 1}']", :count => 1 - assert_select ".secondary-actions a[href='#{relation_path relation}']", :count => 1 - assert_select ".secondary-actions a[href='#{relation_history_path relation}']", :count => 1 - assert_select ".secondary-actions a[href='#{old_relation_path relation, 2}']", :count => 1 - get old_relation_path(relation, 2) assert_response :success assert_template "old_relations/show" assert_template :layout => "map" - assert_select "h4", /^Version/ do - assert_select "a[href='#{old_relation_path relation, 2}']", :count => 0 - end - assert_select ".secondary-actions a[href='#{api_relation_version_path relation, 2}']", :count => 1 - assert_select ".secondary-actions a[href='#{relation_path relation}']", :count => 1 - assert_select ".secondary-actions a[href='#{relation_history_path relation}']", :count => 1 - assert_select ".secondary-actions a[href='#{old_relation_path relation, 1}']", :count => 1 end - def test_visible_with_members + def test_show_with_members relation = create(:relation, :with_history) create(:old_relation_member, :old_relation => relation.old_relations.first) - get old_relation_path(relation, 1) - assert_response :success - assert_template "old_relations/show" - assert_template :layout => "map" - end - test "show unrevealed redacted versions to anonymous users" do - relation = create_redacted_relation get old_relation_path(relation, 1) - assert_response :success - assert_template "old_relations/show" - assert_template :layout => "map" - assert_select "td", :text => "TOP SECRET", :count => 0 - assert_select ".secondary-actions a[href='#{relation_path relation}']", :count => 1 - assert_select ".secondary-actions a[href='#{old_relation_path relation, 1, :params => { :show_redactions => true }}']", :count => 0 - assert_select ".secondary-actions a[href='#{old_relation_path relation, 1}']", :count => 0 - assert_select ".secondary-actions a[href='#{api_relation_version_path relation, 1}']", :count => 0 - end - test "show unrevealed redacted versions to regular users" do - session_for(create(:user)) - relation = create_redacted_relation - get old_relation_path(relation, 1) assert_response :success assert_template "old_relations/show" assert_template :layout => "map" - assert_select "td", :text => "TOP SECRET", :count => 0 - assert_select ".secondary-actions a[href='#{relation_path relation}']", :count => 1 - assert_select ".secondary-actions a[href='#{old_relation_path relation, 1, :params => { :show_redactions => true }}']", :count => 0 - assert_select ".secondary-actions a[href='#{old_relation_path relation, 1}']", :count => 0 - assert_select ".secondary-actions a[href='#{api_relation_version_path relation, 1}']", :count => 0 end - test "show unrevealed redacted versions to moderators" do - session_for(create(:moderator_user)) - relation = create_redacted_relation - get old_relation_path(relation, 1) - assert_response :success - assert_template "old_relations/show" - assert_template :layout => "map" - assert_select "td", :text => "TOP SECRET", :count => 0 - assert_select ".secondary-actions a[href='#{relation_path relation}']", :count => 1 - assert_select ".secondary-actions a[href='#{old_relation_path relation, 1, :params => { :show_redactions => true }}']", :count => 1 - assert_select ".secondary-actions a[href='#{old_relation_path relation, 1}']", :count => 0 - assert_select ".secondary-actions a[href='#{api_relation_version_path relation, 1}']", :count => 0 - end + def test_show_redacted_to_unauthorized_users + relation = create(:relation, :with_history, :version => 2) + relation.old_relations.find_by(:version => 1).redact!(create(:redaction)) - test "don't reveal redacted versions to anonymous users" do - relation = create_redacted_relation get old_relation_path(relation, 1, :params => { :show_redactions => true }) + assert_response :redirect end - test "don't reveal redacted versions to regular users" do + def test_show_redacted_to_regular_users + relation = create(:relation, :with_history, :version => 2) + relation.old_relations.find_by(:version => 1).redact!(create(:redaction)) + session_for(create(:user)) - relation = create_redacted_relation get old_relation_path(relation, 1, :params => { :show_redactions => true }) - assert_response :redirect - end - test "reveal redacted versions to moderators" do - session_for(create(:moderator_user)) - relation = create_redacted_relation - get old_relation_path(relation, 1, :params => { :show_redactions => true }) - assert_response :success - assert_select "td", :text => "TOP SECRET", :count => 1 - assert_select ".secondary-actions a[href='#{old_relation_path relation, 1}']", :count => 1 + assert_response :redirect end - def test_not_found + def test_show_not_found get old_relation_path(0, 0) + assert_response :not_found assert_template "browse/not_found" assert_template :layout => "map" @@ -179,22 +106,14 @@ class OldRelationsControllerTest < ActionDispatch::IntegrationTest def test_show_timeout relation = create(:relation, :with_history) + with_settings(:web_timeout => -1) do get old_relation_path(relation, 1) end + assert_response :error assert_template :layout => "map" assert_dom "h2", "Timeout Error" assert_dom "p", /#{Regexp.quote("the relation with the id #{relation.id}")}/ end - - private - - def create_redacted_relation - create(:relation, :with_history, :version => 2) do |relation| - relation_v1 = relation.old_relations.find_by(:version => 1) - create(:old_relation_tag, :old_relation => relation_v1, :k => "name", :v => "TOP SECRET") - relation_v1.redact!(create(:redaction)) - end - end end diff --git a/test/system/element_old_version_test.rb b/test/system/element_old_version_test.rb index 8301a4d5e..c68418e8a 100644 --- a/test/system/element_old_version_test.rb +++ b/test/system/element_old_version_test.rb @@ -32,6 +32,21 @@ class ElementOldVersionTest < ApplicationSystemTestCase end end + test "shows a relation with one version" do + relation = create(:relation, :with_history) + + visit old_relation_path(relation, 1) + + within_sidebar do + assert_css "h2", :text => "Relation: #{relation.id}" + assert_css "h4", :text => "Version #1" + + assert_link "Download XML", :href => api_relation_version_path(relation, 1) + assert_link "View Details", :href => relation_path(relation) + assert_link "View History", :href => relation_history_path(relation) + end + end + test "shows a node with two versions" do node = create(:node, :with_history, :version => 2, :lat => 60, :lon => 30) node.old_nodes.find_by(:version => 1).update(:lat => 59, :lon => 29) @@ -83,6 +98,30 @@ class ElementOldVersionTest < ApplicationSystemTestCase end end + test "shows a relation with two versions" do + relation = create(:relation, :with_history, :version => 2) + + visit old_relation_path(relation, 1) + + within_sidebar do + assert_css "h2", :text => "Relation: #{relation.id}" + assert_css "h4", :text => "Version #1" + + assert_link "Download XML", :href => api_relation_version_path(relation, 1) + assert_link "View Details", :href => relation_path(relation) + assert_link "View History", :href => relation_history_path(relation) + + click_on "Version #2" + + assert_css "h2", :text => "Relation: #{relation.id}" + assert_css "h4", :text => "Version #2" + + assert_link "Download XML", :href => api_relation_version_path(relation, 2) + assert_link "View Details", :href => relation_path(relation) + assert_link "View History", :href => relation_history_path(relation) + end + end + test "show a redacted node version" do node = create_redacted_node @@ -119,6 +158,24 @@ class ElementOldVersionTest < ApplicationSystemTestCase end end + test "show a redacted relation version" do + relation = create_redacted_relation + + visit old_relation_path(relation, 1) + + within_sidebar do + assert_css "h2", :text => "Relation: #{relation.id}" + assert_text "Version 1 of this relation cannot be shown" + assert_no_text "Location" + assert_no_text "TOP SECRET" + + assert_no_link "Download XML" + assert_no_link "View Redacted Data" + assert_link "View Details", :href => relation_path(relation) + assert_link "View History", :href => relation_history_path(relation) + end + end + test "show a redacted node version to a regular user" do node = create_redacted_node @@ -157,6 +214,25 @@ class ElementOldVersionTest < ApplicationSystemTestCase end end + test "show a redacted relation version to a regular user" do + relation = create_redacted_relation + + sign_in_as(create(:user)) + visit old_relation_path(relation, 1) + + within_sidebar do + assert_css "h2", :text => "Relation: #{relation.id}" + assert_text "Version 1 of this relation cannot be shown" + assert_no_text "Location" + assert_no_text "TOP SECRET" + + assert_no_link "Download XML" + assert_no_link "View Redacted Data" + assert_link "View Details", :href => relation_path(relation) + assert_link "View History", :href => relation_history_path(relation) + end + end + test "show a redacted node version to a moderator" do node = create_redacted_node @@ -230,6 +306,42 @@ class ElementOldVersionTest < ApplicationSystemTestCase end end + test "show a redacted relation version to a moderator" do + relation = create_redacted_relation + + sign_in_as(create(:moderator_user)) + visit old_relation_path(relation, 1) + + within_sidebar do + assert_css "h2", :text => "Relation: #{relation.id}" + assert_text "Version 1 of this relation cannot be shown" + assert_no_text "Location" + assert_no_text "TOP SECRET" + + assert_no_link "Download XML" + assert_link "View Redacted Data" + assert_no_link "View Redaction Message" + assert_link "View Details", :href => relation_path(relation) + assert_link "View History", :href => relation_history_path(relation) + + click_on "View Redacted Data" + + assert_css "h2", :text => "Relation: #{relation.id}" + assert_css "h4", :text => "Redacted Version #1" + assert_text "TOP SECRET" + + assert_no_link "Download XML" + assert_no_link "View Redacted Data" + assert_link "View Redaction Message" + assert_link "View Details", :href => relation_path(relation) + assert_link "View History", :href => relation_history_path(relation) + + click_on "View Redaction Message" + + assert_text "Version 1 of this relation cannot be shown" + end + end + private def create_redacted_node @@ -248,4 +360,12 @@ class ElementOldVersionTest < ApplicationSystemTestCase way_v1.redact!(create(:redaction)) end end + + def create_redacted_relation + create(:relation, :with_history, :version => 2) do |relation| + relation_v1 = relation.old_relations.find_by(:version => 1) + create(:old_relation_tag, :old_relation => relation_v1, :k => "name", :v => "TOP SECRET") + relation_v1.redact!(create(:redaction)) + end + end end -- 2.39.5