From e8af4b85bf001ade543d03a503c769055d42e6a2 Mon Sep 17 00:00:00 2001 From: Tom Hughes Date: Tue, 26 Sep 2023 18:35:05 +0100 Subject: [PATCH] Fix new rubocop warnings --- test/controllers/api/changesets_controller_test.rb | 12 ++++++------ test/controllers/api/nodes_controller_test.rb | 3 +-- test/controllers/api/relations_controller_test.rb | 3 +-- test/controllers/api/users_controller_test.rb | 2 +- test/controllers/api/ways_controller_test.rb | 3 +-- test/controllers/changesets_controller_test.rb | 2 +- test/controllers/user_blocks_controller_test.rb | 2 +- test/lib/locale_test.rb | 2 +- test/lib/password_hash_test.rb | 2 +- test/lib/short_link_test.rb | 2 +- test/system/account_deletion_test.rb | 12 ++++++------ test/system/diary_entry_test.rb | 2 +- test/system/issues_test.rb | 12 ++++++------ test/system/preferences_test.rb | 4 ++-- test/system/report_diary_comment_test.rb | 4 ++-- test/system/report_diary_entry_test.rb | 8 ++++---- test/system/report_note_test.rb | 8 ++++---- test/system/report_user_test.rb | 12 ++++++------ test/system/user_logout_test.rb | 8 ++++---- test/system/user_signup_test.rb | 6 +++--- test/system/user_status_change_test.rb | 4 ++-- test/system/view_communities_test.rb | 2 +- test/test_helper.rb | 2 +- 23 files changed, 57 insertions(+), 60 deletions(-) diff --git a/test/controllers/api/changesets_controller_test.rb b/test/controllers/api/changesets_controller_test.rb index 433984414..b4bc4a5ab 100644 --- a/test/controllers/api/changesets_controller_test.rb +++ b/test/controllers/api/changesets_controller_test.rb @@ -199,7 +199,7 @@ module Api assert_equal Settings.api_version, js["version"] assert_equal Settings.generator, js["generator"] assert_equal changeset.id, js["changeset"]["id"] - assert js["changeset"]["open"] + assert_operator js["changeset"], :[], "open" assert_equal changeset.created_at.xmlschema, js["changeset"]["created_at"] assert_nil js["changeset"]["closed_at"] assert_nil js["changeset"]["tags"] @@ -215,7 +215,7 @@ module Api assert_equal Settings.api_version, js["version"] assert_equal Settings.generator, js["generator"] assert_equal changeset.id, js["changeset"]["id"] - assert js["changeset"]["open"] + assert_operator js["changeset"], :[], "open" assert_equal changeset.created_at.xmlschema, js["changeset"]["created_at"] assert_nil js["changeset"]["closed_at"] assert_nil js["changeset"]["tags"] @@ -697,10 +697,10 @@ module Api # check that the changeset bbox is within bounds cs = Changeset.find(changeset_id) - assert cs.min_lon >= -180 * GeoRecord::SCALE, "Minimum longitude (#{cs.min_lon / GeoRecord::SCALE}) should be >= -180 to be valid." - assert cs.max_lon <= 180 * GeoRecord::SCALE, "Maximum longitude (#{cs.max_lon / GeoRecord::SCALE}) should be <= 180 to be valid." - assert cs.min_lat >= -90 * GeoRecord::SCALE, "Minimum latitude (#{cs.min_lat / GeoRecord::SCALE}) should be >= -90 to be valid." - assert cs.max_lat <= 90 * GeoRecord::SCALE, "Maximum latitude (#{cs.max_lat / GeoRecord::SCALE}) should be <= 90 to be valid." + assert_operator cs.min_lon, :>=, -180 * GeoRecord::SCALE, "Minimum longitude (#{cs.min_lon / GeoRecord::SCALE}) should be >= -180 to be valid." + assert_operator cs.max_lon, :<=, 180 * GeoRecord::SCALE, "Maximum longitude (#{cs.max_lon / GeoRecord::SCALE}) should be <= 180 to be valid." + assert_operator cs.min_lat, :>=, -90 * GeoRecord::SCALE, "Minimum latitude (#{cs.min_lat / GeoRecord::SCALE}) should be >= -90 to be valid." + assert_operator cs.max_lat, :<=, 90 * GeoRecord::SCALE, "Maximum latitude (#{cs.max_lat / GeoRecord::SCALE}) should be <= 90 to be valid." end ## diff --git a/test/controllers/api/nodes_controller_test.rb b/test/controllers/api/nodes_controller_test.rb index 95658842b..9e680dd06 100644 --- a/test/controllers/api/nodes_controller_test.rb +++ b/test/controllers/api/nodes_controller_test.rb @@ -258,8 +258,7 @@ module Api # valid delete should return the new version number, which should # be greater than the old version number - assert @response.body.to_i > node.version, - "delete request should return a new version number for node" + assert_operator @response.body.to_i, :>, node.version, "delete request should return a new version number for node" # deleting the same node twice doesn't work xml = xml_for_node(node) diff --git a/test/controllers/api/relations_controller_test.rb b/test/controllers/api/relations_controller_test.rb index 7f2c19665..7d011c17f 100644 --- a/test/controllers/api/relations_controller_test.rb +++ b/test/controllers/api/relations_controller_test.rb @@ -612,8 +612,7 @@ module Api # valid delete should return the new version number, which should # be greater than the old version number - assert @response.body.to_i > multi_tag_relation.version, - "delete request should return a new version number for relation" + assert_operator @response.body.to_i, :>, multi_tag_relation.version, "delete request should return a new version number for relation" # this won't work since the relation is already deleted xml = update_changeset(xml_for_relation(deleted_relation), changeset.id) diff --git a/test/controllers/api/users_controller_test.rb b/test/controllers/api/users_controller_test.rb index aa4bf1e9d..8e7079b85 100644 --- a/test/controllers/api/users_controller_test.rb +++ b/test/controllers/api/users_controller_test.rb @@ -731,7 +731,7 @@ module Api def check_json_details(js, user, include_private, include_email) assert_equal user.id, js["user"]["id"] assert_equal user.description, js["user"]["description"] - assert js["user"]["contributor_terms"]["agreed"] + assert_operator js["user"]["contributor_terms"], :[], "agreed" if include_private assert_not js["user"]["contributor_terms"]["pd"] diff --git a/test/controllers/api/ways_controller_test.rb b/test/controllers/api/ways_controller_test.rb index 0cf30e4ff..2bed0e5d6 100644 --- a/test/controllers/api/ways_controller_test.rb +++ b/test/controllers/api/ways_controller_test.rb @@ -379,8 +379,7 @@ module Api # check the returned value - should be the new version number # valid delete should return the new version number, which should # be greater than the old version number - assert @response.body.to_i > way.version, - "delete request should return a new version number for way" + assert_operator @response.body.to_i, :>, way.version, "delete request should return a new version number for way" # this won't work since the way is already deleted xml = xml_for_way(deleted_way) diff --git a/test/controllers/changesets_controller_test.rb b/test/controllers/changesets_controller_test.rb index a71b5e8fe..79fd7a571 100644 --- a/test/controllers/changesets_controller_test.rb +++ b/test/controllers/changesets_controller_test.rb @@ -321,7 +321,7 @@ class ChangesetsControllerTest < ActionDispatch::IntegrationTest ## # check the result of a feed def check_feed_result(changesets) - assert changesets.size <= 20 + assert_operator changesets.size, :<=, 20 assert_select "feed", :count => [changesets.size, 1].min do assert_select "> title", :count => 1, :text => /^Changesets/ diff --git a/test/controllers/user_blocks_controller_test.rb b/test/controllers/user_blocks_controller_test.rb index 16a77624c..27022c973 100644 --- a/test/controllers/user_blocks_controller_test.rb +++ b/test/controllers/user_blocks_controller_test.rb @@ -356,7 +356,7 @@ class UserBlocksControllerTest < ActionDispatch::IntegrationTest assert_response :success assert_template "revoke" b = UserBlock.find(active_block.id) - assert b.ends_at - Time.now.utc > 100 + assert_operator b.ends_at - Time.now.utc, :>, 100 # Check that revoking a block works using POST post revoke_user_block_path(:id => active_block, :confirm => true) diff --git a/test/lib/locale_test.rb b/test/lib/locale_test.rb index d84239038..9aec035d1 100644 --- a/test/lib/locale_test.rb +++ b/test/lib/locale_test.rb @@ -80,7 +80,7 @@ class LocaleTest < ActiveSupport::TestCase end def test_available - assert Locale.available.count <= I18n.available_locales.count + assert_operator Locale.available.count, :<=, I18n.available_locales.count end def test_preferred diff --git a/test/lib/password_hash_test.rb b/test/lib/password_hash_test.rb index 2a42de123..9bfd73496 100644 --- a/test/lib/password_hash_test.rb +++ b/test/lib/password_hash_test.rb @@ -61,6 +61,6 @@ class PasswordHashTest < ActiveSupport::TestCase format = Argon2::HashFormat.new(hash) assert_equal "argon2id", format.variant - assert format.version <= 19 + assert_operator format.version, :<=, 19 end end diff --git a/test/lib/short_link_test.rb b/test/lib/short_link_test.rb index a0a1023bb..a32e1ac20 100644 --- a/test/lib/short_link_test.rb +++ b/test/lib/short_link_test.rb @@ -20,7 +20,7 @@ class ShortLinkTest < ActiveSupport::TestCase # smaller range. distance = Math.sqrt(((lat - lat2)**2) + ((lon - lon2)**2)) max_distance = 360.0 / (1 << (zoom + 8)) * 0.5 * Math.sqrt(5) - assert max_distance > distance, "Maximum expected error exceeded: #{max_distance} <= #{distance} for (#{lat}, #{lon}, #{zoom})." + assert_operator max_distance, :>, distance, "Maximum expected error exceeded: #{max_distance} <= #{distance} for (#{lat}, #{lon}, #{zoom})." end end diff --git a/test/system/account_deletion_test.rb b/test/system/account_deletion_test.rb index 5a55c5838..87e981c64 100644 --- a/test/system/account_deletion_test.rb +++ b/test/system/account_deletion_test.rb @@ -9,9 +9,9 @@ class AccountDeletionTest < ApplicationSystemTestCase test "the status is deleted and the personal data removed" do visit edit_account_path - click_on "Delete Account..." + click_link "Delete Account..." accept_confirm do - click_on "Delete Account" + click_link "Delete Account" end assert_current_path root_path @@ -23,9 +23,9 @@ class AccountDeletionTest < ApplicationSystemTestCase test "the user is signed out after deletion" do visit edit_account_path - click_on "Delete Account..." + click_link "Delete Account..." accept_confirm do - click_on "Delete Account" + click_link "Delete Account" end assert_content "Log In" @@ -34,9 +34,9 @@ class AccountDeletionTest < ApplicationSystemTestCase test "the user is shown a confirmation flash message" do visit edit_account_path - click_on "Delete Account..." + click_link "Delete Account..." accept_confirm do - click_on "Delete Account" + click_link "Delete Account" end assert_content "Account Deleted" diff --git a/test/system/diary_entry_test.rb b/test/system/diary_entry_test.rb index 31e6d7b07..554b89a6d 100644 --- a/test/system/diary_entry_test.rb +++ b/test/system/diary_entry_test.rb @@ -10,7 +10,7 @@ class DiaryEntrySystemTest < ApplicationSystemTestCase sign_in_as(create(:user)) visit diary_entries_path - click_on "Send a message to the author" + click_link "Send a message to the author" assert_content "Send a new message" assert_equal "Re: #{@diary_entry.title}", page.find_field("Subject").value diff --git a/test/system/issues_test.rb b/test/system/issues_test.rb index b9b989c07..a40306e3c 100644 --- a/test/system/issues_test.rb +++ b/test/system/issues_test.rb @@ -80,21 +80,21 @@ class IssuesTest < ApplicationSystemTestCase # No issues against the user visit issues_path fill_in "search_by_user", :with => good_user.display_name - click_on "Search" + click_button "Search" assert_no_content I18n.t("issues.index.user_not_found") assert_content I18n.t("issues.index.issues_not_found") # User doesn't exist visit issues_path fill_in "search_by_user", :with => "Nonexistent User" - click_on "Search" + click_button "Search" assert_content I18n.t("issues.index.user_not_found") assert_content I18n.t("issues.index.issues_not_found") # Find Issue against bad_user visit issues_path fill_in "search_by_user", :with => bad_user.display_name - click_on "Search" + click_button "Search" assert_no_content I18n.t("issues.index.user_not_found") assert_no_content I18n.t("issues.index.issues_not_found") end @@ -106,7 +106,7 @@ class IssuesTest < ApplicationSystemTestCase visit issue_path(issue) fill_in :issue_comment_body, :with => "test comment" - click_on "Add Comment" + click_button "Add Comment" assert_content I18n.t("issue_comments.create.comment_created") assert_content "test comment" @@ -123,7 +123,7 @@ class IssuesTest < ApplicationSystemTestCase fill_in :issue_comment_body, :with => "reassigning to moderators" check :reassign - click_on "Add Comment" + click_button "Add Comment" assert_content "and the issue was reassigned" assert_current_path issues_path(:status => "open") @@ -140,7 +140,7 @@ class IssuesTest < ApplicationSystemTestCase fill_in :issue_comment_body, :with => "reassigning to moderators" check :reassign - click_on "Add Comment" + click_button "Add Comment" assert_content "and the issue was reassigned" assert_current_path issue_path(issue) diff --git a/test/system/preferences_test.rb b/test/system/preferences_test.rb index 59a7209f5..b071b1f73 100644 --- a/test/system/preferences_test.rb +++ b/test/system/preferences_test.rb @@ -5,7 +5,7 @@ class PreferencesTest < ApplicationSystemTestCase sign_in_as(create(:user)) visit edit_preferences_path - click_on "Update Preferences" + click_button "Update Preferences" assert_content "Preferences updated" end @@ -15,7 +15,7 @@ class PreferencesTest < ApplicationSystemTestCase visit edit_preferences_path fill_in "Preferred Languages", :with => "fr" - click_on "Update Preferences" + click_button "Update Preferences" assert_content "Préférences mises à jour" end diff --git a/test/system/report_diary_comment_test.rb b/test/system/report_diary_comment_test.rb index 3504ab061..15ef1ad3c 100644 --- a/test/system/report_diary_comment_test.rb +++ b/test/system/report_diary_comment_test.rb @@ -19,14 +19,14 @@ class ReportDiaryCommentTest < ApplicationSystemTestCase visit diary_entry_path(@diary_entry.user.display_name, @diary_entry) assert_content @diary_entry.title - click_on I18n.t("diary_entries.diary_comment.report") + click_link I18n.t("diary_entries.diary_comment.report") assert_content "Report" assert_content I18n.t("reports.new.disclaimer.intro") choose I18n.t("reports.new.categories.diary_comment.spam_label") fill_in "report_details", :with => "This comment is spam" assert_difference "Issue.count", 1 do - click_on "Create Report" + click_button "Create Report" end assert_content "Your report has been registered successfully" diff --git a/test/system/report_diary_entry_test.rb b/test/system/report_diary_entry_test.rb index efb107065..d4e49b714 100644 --- a/test/system/report_diary_entry_test.rb +++ b/test/system/report_diary_entry_test.rb @@ -18,14 +18,14 @@ class ReportDiaryEntryTest < ApplicationSystemTestCase visit diary_entry_path(@diary_entry.user.display_name, @diary_entry) assert_content @diary_entry.title - click_on I18n.t("diary_entries.diary_entry.report") + click_link I18n.t("diary_entries.diary_entry.report") assert_content "Report" assert_content I18n.t("reports.new.disclaimer.intro") choose I18n.t("reports.new.categories.diary_entry.spam_label") fill_in "report_details", :with => "This is advertising" assert_difference "Issue.count", 1 do - click_on "Create Report" + click_button "Create Report" end assert_content "Your report has been registered successfully" @@ -42,14 +42,14 @@ class ReportDiaryEntryTest < ApplicationSystemTestCase visit diary_entry_path(@diary_entry.user.display_name, @diary_entry) assert_content @diary_entry.title - click_on I18n.t("diary_entries.diary_entry.report") + click_link I18n.t("diary_entries.diary_entry.report") assert_content "Report" assert_content I18n.t("reports.new.disclaimer.intro") choose I18n.t("reports.new.categories.diary_entry.spam_label") fill_in "report_details", :with => "This is advertising" assert_no_difference "Issue.count" do - click_on "Create Report" + click_button "Create Report" end issue.reload diff --git a/test/system/report_note_test.rb b/test/system/report_note_test.rb index 79894eb89..b7e1bfc9e 100644 --- a/test/system/report_note_test.rb +++ b/test/system/report_note_test.rb @@ -14,14 +14,14 @@ class ReportNoteTest < ApplicationSystemTestCase sign_in_as(create(:user)) visit note_path(note) - click_on I18n.t("notes.show.report") + click_link I18n.t("notes.show.report") assert_content "Report" assert_content I18n.t("reports.new.disclaimer.intro") choose I18n.t("reports.new.categories.note.spam_label") fill_in "report_details", :with => "This is spam" assert_difference "Issue.count", 1 do - click_on "Create Report" + click_button "Create Report" end assert_content "Your report has been registered successfully" @@ -35,14 +35,14 @@ class ReportNoteTest < ApplicationSystemTestCase sign_in_as(create(:user)) visit note_path(note) - click_on I18n.t("notes.show.report") + click_link I18n.t("notes.show.report") assert_content "Report" assert_content I18n.t("reports.new.disclaimer.intro") choose I18n.t("reports.new.categories.note.spam_label") fill_in "report_details", :with => "This is spam" assert_difference "Issue.count", 1 do - click_on "Create Report" + click_button "Create Report" end assert_content "Your report has been registered successfully" diff --git a/test/system/report_user_test.rb b/test/system/report_user_test.rb index 7a9e800c8..9a0abe9ea 100644 --- a/test/system/report_user_test.rb +++ b/test/system/report_user_test.rb @@ -14,14 +14,14 @@ class ReportUserTest < ApplicationSystemTestCase sign_in_as(create(:user)) visit user_path(user) - click_on I18n.t("users.show.report") + click_link I18n.t("users.show.report") assert_content "Report" assert_content I18n.t("reports.new.disclaimer.intro") choose I18n.t("reports.new.categories.user.vandal_label") fill_in "report_details", :with => "This user is a vandal" assert_difference "Issue.count", 1 do - click_on "Create Report" + click_button "Create Report" end assert_content "Your report has been registered successfully" @@ -35,14 +35,14 @@ class ReportUserTest < ApplicationSystemTestCase sign_in_as(create(:user)) visit user_path(user) - click_on I18n.t("users.show.report") + click_link I18n.t("users.show.report") assert_content "Report" assert_content I18n.t("reports.new.disclaimer.intro") choose I18n.t("reports.new.categories.user.vandal_label") fill_in "report_details", :with => "This user is a vandal" assert_difference "Issue.count", 1 do - click_on "Create Report" + click_button "Create Report" end assert_content "Your report has been registered successfully" @@ -52,14 +52,14 @@ class ReportUserTest < ApplicationSystemTestCase visit user_path(user) - click_on I18n.t("users.show.report") + click_link I18n.t("users.show.report") assert_content "Report" assert_content I18n.t("reports.new.disclaimer.intro") choose I18n.t("reports.new.categories.user.spam_label") fill_in "report_details", :with => "This user is a spammer" assert_no_difference "Issue.count" do - click_on "Create Report" + click_button "Create Report" end assert_content "Your report has been registered successfully" diff --git a/test/system/user_logout_test.rb b/test/system/user_logout_test.rb index a097b6374..fc27b7c18 100644 --- a/test/system/user_logout_test.rb +++ b/test/system/user_logout_test.rb @@ -6,8 +6,8 @@ class UserLogoutTest < ApplicationSystemTestCase sign_in_as(user) assert_no_content "Log In" - click_on user.display_name - click_on "Log Out" + click_button user.display_name + click_link "Log Out" assert_content "Log In" end @@ -17,8 +17,8 @@ class UserLogoutTest < ApplicationSystemTestCase visit traces_path assert_no_content "Log In" - click_on user.display_name - click_on "Log Out" + click_button user.display_name + click_link "Log Out" assert_content "Log In" assert_content "Public GPS Traces" end diff --git a/test/system/user_signup_test.rb b/test/system/user_signup_test.rb index 5bd88f5a4..88899d710 100644 --- a/test/system/user_signup_test.rb +++ b/test/system/user_signup_test.rb @@ -4,7 +4,7 @@ class UserSignupTest < ApplicationSystemTestCase test "Sign up from login page" do visit login_path - click_on "Register now" + click_link "Register now" assert_content "Confirm Password" end @@ -13,7 +13,7 @@ class UserSignupTest < ApplicationSystemTestCase user = build(:user) visit root_path - click_on "Sign Up" + click_link "Sign Up" fill_in "Email", :with => user.email fill_in "Email Confirmation", :with => user.email fill_in "Display Name", :with => user.display_name @@ -22,7 +22,7 @@ class UserSignupTest < ApplicationSystemTestCase click_button "Sign Up" assert_content "Contributor terms" - click_on "Cancel" + click_button "Cancel" assert_current_path "https://wiki.openstreetmap.org/wiki/Contributor_Terms_Declined" end diff --git a/test/system/user_status_change_test.rb b/test/system/user_status_change_test.rb index 30b923732..e4cca1eab 100644 --- a/test/system/user_status_change_test.rb +++ b/test/system/user_status_change_test.rb @@ -10,7 +10,7 @@ class UserStatusChangeTest < ApplicationSystemTestCase user = create(:user, :suspended) visit user_path(user) accept_confirm do - click_on "Unsuspend" + click_link "Unsuspend" end assert_no_content "Unsuspend" @@ -22,7 +22,7 @@ class UserStatusChangeTest < ApplicationSystemTestCase user = create(:user, :suspended) visit user_path(user) accept_confirm do - click_on "Confirm" + click_link "Confirm" end assert_no_content "Unsuspend" diff --git a/test/system/view_communities_test.rb b/test/system/view_communities_test.rb index 349d0a5bf..539daaa30 100644 --- a/test/system/view_communities_test.rb +++ b/test/system/view_communities_test.rb @@ -13,7 +13,7 @@ class ViewCommunitiesTest < ApplicationSystemTestCase visit edit_preferences_path fill_in "Preferred Languages", :with => "fr" - click_on "Update Preferences" + click_button "Update Preferences" visit "/communities" assert_link "OpenStreetMap États-Unis", :href => "https://www.openstreetmap.us/" diff --git a/test/test_helper.rb b/test/test_helper.rb index 7157abf5a..68749c0f7 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -245,7 +245,7 @@ module ActiveSupport visit login_path fill_in "username", :with => user.email fill_in "password", :with => "test" - click_on "Login", :match => :first + click_button "Login", :match => :first end def session_for(user) -- 2.39.5