From d43711c26c5066699c6f0fef8ee4447e3e7ee426 Mon Sep 17 00:00:00 2001 From: Anton Khorev Date: Sun, 22 Jun 2025 18:04:27 +0300 Subject: [PATCH] Move old way ui tests to system tests --- test/controllers/old_ways_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_ways_controller_test.rb b/test/controllers/old_ways_controller_test.rb index 3ac6eaf2f..ca18bad87 100644 --- a/test/controllers/old_ways_controller_test.rb +++ b/test/controllers/old_ways_controller_test.rb @@ -55,49 +55,17 @@ class OldWaysControllerTest < ActionDispatch::IntegrationTest assert_select ".browse-section.browse-way", 4 end - def test_visible_with_one_version + def test_show way = create(:way, :with_history) - get old_way_path(way, 1) - assert_response :success - assert_template "old_ways/show" - assert_template :layout => "map" - assert_select "h4", /^Version/ do - assert_select "a[href='#{old_way_path way, 1}']", :count => 0 - end - assert_select ".secondary-actions a[href='#{api_way_version_path way, 1}']", :count => 1 - assert_select ".secondary-actions a[href='#{way_path way}']", :count => 1 - assert_select ".secondary-actions a[href='#{old_way_path way, 1, :params => { :show_redactions => true }}']", :count => 0 - assert_select ".secondary-actions a[href='#{way_history_path way}']", :count => 1 - end - def test_visible_with_two_versions - way = create(:way, :with_history, :version => 2) get old_way_path(way, 1) - assert_response :success - assert_template "old_ways/show" - assert_template :layout => "map" - assert_select "h4", /^Version/ do - assert_select "a[href='#{old_way_path way, 1}']", :count => 0 - end - assert_select ".secondary-actions a[href='#{api_way_version_path way, 1}']", :count => 1 - assert_select ".secondary-actions a[href='#{way_path way}']", :count => 1 - assert_select ".secondary-actions a[href='#{way_history_path way}']", :count => 1 - assert_select ".secondary-actions a[href='#{old_way_path way, 2}']", :count => 1 - get old_way_path(way, 2) assert_response :success assert_template "old_ways/show" assert_template :layout => "map" - assert_select "h4", /^Version/ do - assert_select "a[href='#{old_way_path way, 2}']", :count => 0 - end - assert_select ".secondary-actions a[href='#{api_way_version_path way, 2}']", :count => 1 - assert_select ".secondary-actions a[href='#{way_path way}']", :count => 1 - assert_select ".secondary-actions a[href='#{way_history_path way}']", :count => 1 - assert_select ".secondary-actions a[href='#{old_way_path way, 1}']", :count => 1 end - def test_visible_with_shared_nodes + def test_show_with_shared_nodes node = create(:node, :with_history) way = create(:way, :with_history) create(:way_node, :way => way, :node => node) @@ -105,77 +73,36 @@ class OldWaysControllerTest < ActionDispatch::IntegrationTest sharing_way = create(:way, :with_history) create(:way_node, :way => sharing_way, :node => node) create(:old_way_node, :old_way => sharing_way.old_ways.first, :node => node) - get old_way_path(way, 1) - assert_response :success - assert_template "old_ways/show" - assert_template :layout => "map" - end - test "show unrevealed redacted versions to anonymous users" do - way = create_redacted_way get old_way_path(way, 1) - assert_response :success - assert_template "old_ways/show" - assert_template :layout => "map" - assert_select "td", :text => "TOP SECRET", :count => 0 - assert_select ".secondary-actions a[href='#{way_path way}']", :count => 1 - assert_select ".secondary-actions a[href='#{old_way_path way, 1, :params => { :show_redactions => true }}']", :count => 0 - assert_select ".secondary-actions a[href='#{old_way_path way, 1}']", :count => 0 - assert_select ".secondary-actions a[href='#{api_way_version_path way, 1}']", :count => 0 - end - test "show unrevealed redacted versions to regular users" do - session_for(create(:user)) - way = create_redacted_way - get old_way_path(way, 1) assert_response :success assert_template "old_ways/show" assert_template :layout => "map" - assert_select "td", :text => "TOP SECRET", :count => 0 - assert_select ".secondary-actions a[href='#{way_path way}']", :count => 1 - assert_select ".secondary-actions a[href='#{old_way_path way, 1, :params => { :show_redactions => true }}']", :count => 0 - assert_select ".secondary-actions a[href='#{old_way_path way, 1}']", :count => 0 - assert_select ".secondary-actions a[href='#{api_way_version_path way, 1}']", :count => 0 end - test "show unrevealed redacted versions to moderators" do - session_for(create(:moderator_user)) - way = create_redacted_way - get old_way_path(way, 1) - assert_response :success - assert_template "old_ways/show" - assert_template :layout => "map" - assert_select "td", :text => "TOP SECRET", :count => 0 - assert_select ".secondary-actions a[href='#{way_path way}']", :count => 1 - assert_select ".secondary-actions a[href='#{old_way_path way, 1, :params => { :show_redactions => true }}']", :count => 1 - assert_select ".secondary-actions a[href='#{old_way_path way, 1}']", :count => 0 - assert_select ".secondary-actions a[href='#{api_way_version_path way, 1}']", :count => 0 - end + def test_show_redacted_to_unauthorized_users + way = create(:way, :with_history, :version => 2) + way.old_ways.find_by(:version => 1).redact!(create(:redaction)) - test "don't reveal redacted versions to anonymous users" do - way = create_redacted_way get old_way_path(way, 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 + way = create(:way, :with_history, :version => 2) + way.old_ways.find_by(:version => 1).redact!(create(:redaction)) + session_for(create(:user)) - way = create_redacted_way get old_way_path(way, 1, :params => { :show_redactions => true }) - assert_response :redirect - end - test "reveal redacted versions to moderators" do - session_for(create(:moderator_user)) - way = create_redacted_way - get old_way_path(way, 1, :params => { :show_redactions => true }) - assert_response :success - assert_select "td", :text => "TOP SECRET", :count => 1 - assert_select ".secondary-actions a[href='#{old_way_path way, 1}']", :count => 1 + assert_response :redirect end - def test_not_found + def test_show_not_found get old_way_path(0, 0) + assert_response :not_found assert_template "browse/not_found" assert_template :layout => "map" @@ -184,22 +111,14 @@ class OldWaysControllerTest < ActionDispatch::IntegrationTest def test_show_timeout way = create(:way, :with_history) + with_settings(:web_timeout => -1) do get old_way_path(way, 1) end + assert_response :error assert_template :layout => "map" assert_dom "h2", "Timeout Error" assert_dom "p", /#{Regexp.quote("the way with the id #{way.id}")}/ end - - private - - def create_redacted_way - create(:way, :with_history, :version => 2) do |way| - way_v1 = way.old_ways.find_by(:version => 1) - create(:old_way_tag, :old_way => way_v1, :k => "name", :v => "TOP SECRET") - way_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 e0306f030..8301a4d5e 100644 --- a/test/system/element_old_version_test.rb +++ b/test/system/element_old_version_test.rb @@ -17,6 +17,21 @@ class ElementOldVersionTest < ApplicationSystemTestCase end end + test "shows a way with one version" do + way = create(:way, :with_history) + + visit old_way_path(way, 1) + + within_sidebar do + assert_css "h2", :text => "Way: #{way.id}" + assert_css "h4", :text => "Version #1" + + assert_link "Download XML", :href => api_way_version_path(way, 1) + assert_link "View Details", :href => way_path(way) + assert_link "View History", :href => way_history_path(way) + 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) @@ -44,6 +59,30 @@ class ElementOldVersionTest < ApplicationSystemTestCase end end + test "shows a way with two versions" do + way = create(:way, :with_history, :version => 2) + + visit old_way_path(way, 1) + + within_sidebar do + assert_css "h2", :text => "Way: #{way.id}" + assert_css "h4", :text => "Version #1" + + assert_link "Download XML", :href => api_way_version_path(way, 1) + assert_link "View Details", :href => way_path(way) + assert_link "View History", :href => way_history_path(way) + + click_on "Version #2" + + assert_css "h2", :text => "Way: #{way.id}" + assert_css "h4", :text => "Version #2" + + assert_link "Download XML", :href => api_way_version_path(way, 2) + assert_link "View Details", :href => way_path(way) + assert_link "View History", :href => way_history_path(way) + end + end + test "show a redacted node version" do node = create_redacted_node @@ -62,6 +101,24 @@ class ElementOldVersionTest < ApplicationSystemTestCase end end + test "show a redacted way version" do + way = create_redacted_way + + visit old_way_path(way, 1) + + within_sidebar do + assert_css "h2", :text => "Way: #{way.id}" + assert_text "Version 1 of this way 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 => way_path(way) + assert_link "View History", :href => way_history_path(way) + end + end + test "show a redacted node version to a regular user" do node = create_redacted_node @@ -81,6 +138,25 @@ class ElementOldVersionTest < ApplicationSystemTestCase end end + test "show a redacted way version to a regular user" do + way = create_redacted_way + + sign_in_as(create(:user)) + visit old_way_path(way, 1) + + within_sidebar do + assert_css "h2", :text => "Way: #{way.id}" + assert_text "Version 1 of this way 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 => way_path(way) + assert_link "View History", :href => way_history_path(way) + end + end + test "show a redacted node version to a moderator" do node = create_redacted_node @@ -118,6 +194,42 @@ class ElementOldVersionTest < ApplicationSystemTestCase end end + test "show a redacted way version to a moderator" do + way = create_redacted_way + + sign_in_as(create(:moderator_user)) + visit old_way_path(way, 1) + + within_sidebar do + assert_css "h2", :text => "Way: #{way.id}" + assert_text "Version 1 of this way 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 => way_path(way) + assert_link "View History", :href => way_history_path(way) + + click_on "View Redacted Data" + + assert_css "h2", :text => "Way: #{way.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 => way_path(way) + assert_link "View History", :href => way_history_path(way) + + click_on "View Redaction Message" + + assert_text "Version 1 of this way cannot be shown" + end + end + private def create_redacted_node @@ -128,4 +240,12 @@ class ElementOldVersionTest < ApplicationSystemTestCase node_v1.redact!(create(:redaction)) end end + + def create_redacted_way + create(:way, :with_history, :version => 2) do |way| + way_v1 = way.old_ways.find_by(:version => 1) + create(:old_way_tag, :old_way => way_v1, :k => "name", :v => "TOP SECRET") + way_v1.redact!(create(:redaction)) + end + end end -- 2.39.5