From ad2d128cc32a1941ef15fcd5d2d63285dbe0837a Mon Sep 17 00:00:00 2001 From: Arthur Campbell Date: Thu, 23 May 2024 17:28:57 +0100 Subject: [PATCH] escape . in regex for API call stubs to satisfy codeQL remove destroy_all call at the start of a test that was dealing with leftover modesl in the test db --- spec/features/form/page_routing_spec.rb | 2 +- spec/models/lettings_log_spec.rb | 6 +++--- spec/models/location_spec.rb | 2 +- spec/models/organisation_spec.rb | 1 - spec/models/sales_log_spec.rb | 4 ++-- spec/request_helper.rb | 2 +- spec/requests/lettings_logs_controller_spec.rb | 2 +- .../bulk_upload/lettings/year2023/row_parser_spec.rb | 2 +- spec/services/bulk_upload/sales/year2023/row_parser_spec.rb | 2 +- 9 files changed, 11 insertions(+), 12 deletions(-) diff --git a/spec/features/form/page_routing_spec.rb b/spec/features/form/page_routing_spec.rb index ee2894198..8ee63de03 100644 --- a/spec/features/form/page_routing_spec.rb +++ b/spec/features/form/page_routing_spec.rb @@ -72,7 +72,7 @@ RSpec.describe "Form Page Routing" do end it "does not show question if the answer could be inferred" do - stub_request(:get, /api.postcodes.io/) + stub_request(:get, /api\.postcodes\.io/) .to_return(status: 200, body: "{\"status\":200,\"result\":{\"admin_district\":\"Manchester\", \"codes\":{\"admin_district\": \"E08000003\"}}}", headers: {}) visit("/lettings-logs/#{id}/property-postcode") diff --git a/spec/models/lettings_log_spec.rb b/spec/models/lettings_log_spec.rb index 67bcc10e5..57580ab52 100644 --- a/spec/models/lettings_log_spec.rb +++ b/spec/models/lettings_log_spec.rb @@ -288,7 +288,7 @@ RSpec.describe LettingsLog do context "when saving addresses" do before do - stub_request(:get, /api.postcodes.io/) + stub_request(:get, /api\.postcodes\.io/) .to_return(status: 200, body: "{\"status\":200,\"result\":{\"admin_district\":\"Manchester\",\"codes\":{\"admin_district\": \"E08000003\"}}}", headers: {}) end @@ -396,7 +396,7 @@ RSpec.describe LettingsLog do context "when saving previous address" do before do - stub_request(:get, /api.postcodes.io/) + stub_request(:get, /api\.postcodes\.io/) .to_return(status: 200, body: "{\"status\":200,\"result\":{\"admin_district\":\"Manchester\", \"codes\":{\"admin_district\": \"E08000003\"}}}", headers: {}) end @@ -597,7 +597,7 @@ RSpec.describe LettingsLog do end before do - stub_request(:get, /api.postcodes.io/) + stub_request(:get, /api\.postcodes\.io/) .to_return(status: 200, body: "{\"status\":200,\"result\":{\"admin_district\":\"Manchester\",\"codes\":{\"admin_district\": \"E08000003\"}}}", headers: {}) end diff --git a/spec/models/location_spec.rb b/spec/models/location_spec.rb index 3bdc55b44..50dc4b4f4 100644 --- a/spec/models/location_spec.rb +++ b/spec/models/location_spec.rb @@ -9,7 +9,7 @@ RSpec.describe Location, type: :model do let(:location) { FactoryBot.build(:location) } before do - stub_request(:get, /api.postcodes.io/) + stub_request(:get, /api\.postcodes\.io/) .to_return(status: 200, body: "{\"status\":200,\"result\":{\"admin_district\":\"Manchester\",\"codes\":{\"admin_district\": \"E08000003\"}}}", headers: {}) stub_request(:get, /api.postcodes.io\/postcodes\/CA101AA/) diff --git a/spec/models/organisation_spec.rb b/spec/models/organisation_spec.rb index 11eb8eab1..2aa033ccf 100644 --- a/spec/models/organisation_spec.rb +++ b/spec/models/organisation_spec.rb @@ -243,7 +243,6 @@ RSpec.describe Organisation, type: :model do describe "scopes" do before do - described_class.destroy_all create(:organisation, name: "Joe Bloggs", active: false) create(:organisation, name: "Tom Smith", active: true) end diff --git a/spec/models/sales_log_spec.rb b/spec/models/sales_log_spec.rb index 242fbd9d6..e19aaf94a 100644 --- a/spec/models/sales_log_spec.rb +++ b/spec/models/sales_log_spec.rb @@ -535,7 +535,7 @@ RSpec.describe SalesLog, type: :model do context "when saving addresses" do before do - stub_request(:get, /api.postcodes.io/) + stub_request(:get, /api\.postcodes\.io/) .to_return(status: 200, body: "{\"status\":200,\"result\":{\"admin_district\":\"Manchester\",\"codes\":{\"admin_district\": \"E08000003\"}}}", headers: {}) end @@ -820,7 +820,7 @@ RSpec.describe SalesLog, type: :model do end before do - stub_request(:get, /api.postcodes.io/) + stub_request(:get, /api\.postcodes\.io/) .to_return(status: 200, body: "{\"status\":200,\"result\":{\"admin_district\":\"Manchester\", \"codes\":{\"admin_district\": \"E08000003\"}}}", headers: {}) end diff --git a/spec/request_helper.rb b/spec/request_helper.rb index 575a2aa09..d7de32b37 100644 --- a/spec/request_helper.rb +++ b/spec/request_helper.rb @@ -3,7 +3,7 @@ require "webmock/rspec" module RequestHelper def self.stub_http_requests WebMock.disable_net_connect!(allow_localhost: true) - WebMock.stub_request(:get, /api.postcodes.io/) + WebMock.stub_request(:get, /api\.postcodes\.io/) .to_return(status: 200, body: "{\"status\":404,\"error\":\"Postcode not found\"}", headers: {}) WebMock.stub_request(:get, "https://api.postcodes.io/postcodes/AA11AA") diff --git a/spec/requests/lettings_logs_controller_spec.rb b/spec/requests/lettings_logs_controller_spec.rb index 20aa085f3..725a8486d 100644 --- a/spec/requests/lettings_logs_controller_spec.rb +++ b/spec/requests/lettings_logs_controller_spec.rb @@ -1319,7 +1319,7 @@ RSpec.describe LettingsLogsController, type: :request do Singleton.__init__(FormHandler) completed_lettings_log.update!(startdate: Time.zone.local(2021, 4, 1), voiddate: Time.zone.local(2021, 4, 1), mrcdate: Time.zone.local(2021, 4, 1)) Timecop.unfreeze - stub_request(:get, /api.postcodes.io/) + stub_request(:get, /api\.postcodes\.io/) .to_return(status: 200, body: "{\"status\":200,\"result\":{\"admin_district\":\"Manchester\", \"codes\":{\"admin_district\": \"E08000003\"}}}", headers: {}) sign_in user end diff --git a/spec/services/bulk_upload/lettings/year2023/row_parser_spec.rb b/spec/services/bulk_upload/lettings/year2023/row_parser_spec.rb index 0c394b9c0..01de24879 100644 --- a/spec/services/bulk_upload/lettings/year2023/row_parser_spec.rb +++ b/spec/services/bulk_upload/lettings/year2023/row_parser_spec.rb @@ -84,7 +84,7 @@ RSpec.describe BulkUpload::Lettings::Year2023::RowParser do describe "validations" do before do - stub_request(:get, /api.postcodes.io/) + stub_request(:get, /api\.postcodes\.io/) .to_return(status: 200, body: "{\"status\":200,\"result\":{\"admin_district\":\"Manchester\", \"codes\":{\"admin_district\": \"E08000003\"}}}", headers: {}) parser.valid? diff --git a/spec/services/bulk_upload/sales/year2023/row_parser_spec.rb b/spec/services/bulk_upload/sales/year2023/row_parser_spec.rb index 02131381f..1a4f0375e 100644 --- a/spec/services/bulk_upload/sales/year2023/row_parser_spec.rb +++ b/spec/services/bulk_upload/sales/year2023/row_parser_spec.rb @@ -232,7 +232,7 @@ RSpec.describe BulkUpload::Sales::Year2023::RowParser do describe "validations" do before do - stub_request(:get, /api.postcodes.io/) + stub_request(:get, /api\.postcodes\.io/) .to_return(status: 200, body: "{\"status\":200,\"result\":{\"admin_district\":\"Manchester\", \"codes\":{\"admin_district\": \"E08000003\"}}}", headers: {}) parser.valid?