Skip to content

Commit

Permalink
Merge pull request #3958 from Crown-Commercial-Service/dependabot/bun…
Browse files Browse the repository at this point in the history
…dler/rubocop-rails-2.21.2

build(deps-dev): bump rubocop-rails from 2.20.2 to 2.21.2
  • Loading branch information
tim-s-ccs authored Oct 4, 2023
2 parents 5124c3f + 9f5abe3 commit 5761787
Show file tree
Hide file tree
Showing 32 changed files with 59 additions and 48 deletions.
1 change: 0 additions & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,5 @@ RSpec/IndexedLet:
FactoryBot/FactoryAssociationWithStrategy:
Enabled: false


Capybara/ClickLinkOrButtonStyle:
Enabled: false
4 changes: 2 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,7 @@ GEM
rubocop (~> 1.41)
rubocop-factory_bot (2.24.0)
rubocop (~> 1.33)
rubocop-rails (2.20.2)
rubocop-rails (2.21.2)
activesupport (>= 4.2.0)
rack (>= 1.1)
rubocop (>= 1.33.0, < 2.0)
Expand Down Expand Up @@ -605,7 +605,7 @@ GEM
unf (0.1.4)
unf_ext
unf_ext (0.0.8.2)
unicode-display_width (2.4.2)
unicode-display_width (2.5.0)
uniform_notifier (1.16.0)
version_gem (1.1.1)
virtus (2.0.0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module RM3830
module Admin
class SupplierFrameworkDataController < FacilitiesManagement::Admin::FrameworkController
def index
@fm_suppliers = SuppliersAdmin.all.order(:supplier_name).select(:supplier_id, :supplier_name, :lot_data).map do |supplier|
@fm_suppliers = SuppliersAdmin.order(:supplier_name).select(:supplier_id, :supplier_name, :lot_data).map do |supplier|
{ name: supplier.supplier_name, lot_numbers: supplier.lot_data.keys, supplier_id: supplier.supplier_id }
end

Expand Down
2 changes: 1 addition & 1 deletion app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ def contact_link(link_text)
def accordion_region_items(region_codes, with_overseas: false)
nuts1_regions = Nuts1Region.send(with_overseas ? :all_with_overseas : :all).to_h { |region| [region.code, { name: region.name, items: [] }] }

FacilitiesManagement::Region.all.each do |region|
FacilitiesManagement::Region.find_each do |region|
region_group_code = region.code[..2]

next unless nuts1_regions[region_group_code]
Expand Down
6 changes: 6 additions & 0 deletions app/models/concerns/static_record.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ def all
@all ||= []
end

delegate :first, :count, to: :all

def find_each(&)
all.each(&)
end

def find_by(arg)
all.find { |term| arg.all? { |k, v| term.public_send(k) == v } }
end
Expand Down
2 changes: 1 addition & 1 deletion app/models/facilities_management/rm3830/procurement.rb
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ def unanswered_contract_date_questions?

def copy_fm_rates_to_frozen
ActiveRecord::Base.transaction do
Rate.all.find_each do |rate|
Rate.find_each do |rate|
new_rate = FrozenRate.new
new_rate.facilities_management_rm3830_procurement_id = id
new_rate.code = rate.code
Expand Down
2 changes: 1 addition & 1 deletion app/models/facilities_management/rm3830/service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def self.direct_award_services(procurement_id)

return frozen_rate.where(direct_award: true).map(&:code) if frozen_rate.exists?

Rate.all.where(direct_award: true).map(&:code) unless frozen_rate.exists?
Rate.where(direct_award: true).map(&:code) unless frozen_rate.exists?
end
end

Expand Down
2 changes: 1 addition & 1 deletion app/models/facilities_management/rm3830/supplier_detail.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class SupplierDetail < ApplicationRecord
# rubocop:enable Rails/HasManyOrHasOneDependent

def self.selected_suppliers(for_lot, for_regions, for_services)
all.order(:supplier_name).select do |s|
order(:supplier_name).select do |s|
s.lot_data[for_lot] && (for_regions - s.lot_data[for_lot]['regions']).empty? && (for_services - s.lot_data[for_lot]['services']).empty?
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ def self.spreadsheet_import_status(procurement)
end

def self.supplier_names
@supplier_names ||= SupplierDetail.all.select(:supplier_id, :supplier_name).pluck(:supplier_id, :supplier_name).to_h
@supplier_names ||= SupplierDetail.select(:supplier_id, :supplier_name).pluck(:supplier_id, :supplier_name).to_h
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def suppliers
end

def da_service_codes
@da_service_codes ||= Rate.all.where(direct_award: true).pluck(:code)
@da_service_codes ||= Rate.where(direct_award: true).pluck(:code)
end

def work_packages
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ def save_spreadsheet_data
end

def delete_existing_procurement_buildings_and_services
@procurement.procurement_buildings.where.not(id: nil).each(&:destroy)
@procurement.procurement_buildings.where.not(id: nil).find_each(&:destroy)
end

def save_building(building_hash)
Expand Down
2 changes: 1 addition & 1 deletion app/services/static_data_loader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def self.load_static_data(static_data_class)
query = @queries[class_name.to_sym]
static_data_class.load_db(query)
rescue StandardError
call_rake static_data_class, class_name, query if static_data_class.all.count.zero?
call_rake static_data_class, class_name, query if static_data_class.count.zero?
end
end

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
class AddBuildingidToFacilitiesManagementBuildings < ActiveRecord::Migration[5.2]
# rubocop:disable Rails/DangerousColumnNames
def change
add_column :facilities_management_buildings, :id, :uuid
add_index :facilities_management_buildings, :id, unique: true
end
# rubocop:enable Rails/DangerousColumnNames
end
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
class ChangeProcurementBuildingServicePrimaryKey < ActiveRecord::Migration[5.2]
# rubocop:disable Rails/DangerousColumnNames
def up
add_column :facilities_management_procurement_building_services, :uuid, :uuid, default: 'gen_random_uuid()', null: false

Expand All @@ -9,4 +10,5 @@ def up

execute 'ALTER TABLE facilities_management_procurement_building_services ADD PRIMARY KEY (id);'
end
# rubocop:enable Rails/DangerousColumnNames
end
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class UpdateBuildingTypesInTheDb < ActiveRecord::Migration[5.2]
def up
FacilitiesManagement::Building.all.each do |building|
FacilitiesManagement::Building.find_each do |building|
updated_building_type = BUILDING_TYPE_KEY[building.building_type&.to_sym]
building.building_type = updated_building_type unless updated_building_type.nil?
building.building_json[:'building-type'] = updated_building_type unless updated_building_type.nil?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class FMSupplier < ApplicationRecord
end

def self.up
FMSupplier.all.each do |supplier|
FMSupplier.find_each do |supplier|
supplier.data['lots'].each do |lot|
lot['services'] = [] if lot['services'].nil?
end
Expand Down
4 changes: 2 additions & 2 deletions db/migrate/20200908110404_set_governing_law.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ class SetGoverningLaw < ActiveRecord::Migration[5.2]
DEFAULT_LAW = 'english'.freeze

def up
FacilitiesManagement::Procurement.direct_award.where(governing_law: nil).each do |procurement|
FacilitiesManagement::Procurement.direct_award.where(governing_law: nil).find_each do |procurement|
procurement.update(governing_law: DEFAULT_LAW)
end

FacilitiesManagement::Procurement.da_draft.where(governing_law: nil).each do |procurement|
FacilitiesManagement::Procurement.da_draft.where(governing_law: nil).find_each do |procurement|
procurement.update(governing_law: DEFAULT_LAW) if %w[review_and_generate review sending sent].include?(procurement.da_journey_state)
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class FMSupplier < ApplicationRecord

# rubocop:disable Metrics/AbcSize
def up
FMSupplier.all.each do |supplier|
FMSupplier.find_each do |supplier|
data = supplier.data
supplier.contact_name = data['contact_name']
supplier.contact_email = data['contact_email']
Expand All @@ -29,7 +29,7 @@ def down
add_index :fm_suppliers, ['data'], name: 'idxgin', using: :gin
add_index :fm_suppliers, ['data'], name: 'idxginp', opclass: :jsonb_path_ops, using: :gin

FMSupplier.all.each do |supplier|
FMSupplier.find_each do |supplier|
data = {}
data['supplier_id'] = supplier.supplier_id
data['contact_name'] = supplier.contact_name
Expand Down
2 changes: 1 addition & 1 deletion db/migrate/20201210141943_add_data_to_fm_suppliers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def up
SupplierDetail.reset_column_information
FMSupplier.reset_column_information

SupplierDetail.all.each do |supplier_detail|
SupplierDetail.find_each do |supplier_detail|
contact_email = supplier_detail.contact_email
fm_supplier = FMSupplier.find_by(contact_email:)
next if fm_supplier.blank?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class SupplierUser < ApplicationRecord
def up
SupplierDetail.reset_column_information

SupplierDetail.all.each do |supplier_detail|
SupplierDetail.find_each do |supplier_detail|
next if supplier_detail.user_id.present?

contact_email = supplier_detail.contact_email
Expand Down
4 changes: 2 additions & 2 deletions db/migrate/20210716112653_rename_unit_of_measure_table.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def up
OldUnitOfMeasurement.reset_column_information
NewUnitOfMeasurement.reset_column_information

OldUnitOfMeasurement.all.each do |row|
OldUnitOfMeasurement.find_each do |row|
NewUnitOfMeasurement.create(row.attributes)
end

Expand All @@ -47,7 +47,7 @@ def down
OldUnitOfMeasurement.reset_column_information
NewUnitOfMeasurement.reset_column_information

NewUnitOfMeasurement.all.each do |row|
NewUnitOfMeasurement.find_each do |row|
OldUnitOfMeasurement.create(row.attributes)
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@
end

Then('I deselect all checkboxes') do
# rubocop:disable Rails/FindEach
admin_page.all('input[type="checkbox"][checked="checked"]').each(&:uncheck)
# rubocop:enable Rails/FindEach
end

Then('I select {string} for the lot status') do |option|
Expand Down
2 changes: 1 addition & 1 deletion lib/tasks/facilities_management/rm3830/procurements.rake
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace :procurements do

FacilitiesManagement::RM3830::Procurement
.includes(:procurement_suppliers)
.where(aasm_state: %w[results da_draft direct_award further_competition closed]).each do |procurement|
.where(aasm_state: %w[results da_draft direct_award further_competition closed]).find_each do |procurement|
if procurement.procurement_suppliers.none?
puts "Deleting procurement with ID #{procurement.id}"
procurement.destroy
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -257,15 +257,15 @@
context 'when Save and continue is selected with no region codes' do
it 'redirects to facilities_management_rm3830_procurement_path for the new record' do
post :create, params: { facilities_management_rm3830_procurement: { contract_name: 'New procurement' } }
new_procurement = FacilitiesManagement::RM3830::Procurement.all.order(created_at: :asc).first
new_procurement = FacilitiesManagement::RM3830::Procurement.order(created_at: :asc).first
expect(response).to redirect_to facilities_management_rm3830_procurement_path(new_procurement.id)
end
end

context 'when Save and continue is selected with region codes' do
it 'redirects to facilities_management_rm3830_procurement_path for the new record' do
post :create, params: { facilities_management_rm3830_procurement: { contract_name: 'New procurement', region_codes: %w[UKC1 UKC2] } }
new_procurement = FacilitiesManagement::RM3830::Procurement.all.order(created_at: :asc).first
new_procurement = FacilitiesManagement::RM3830::Procurement.order(created_at: :asc).first
expect(response).to redirect_to facilities_management_rm3830_procurement_path(new_procurement.id, what_happens_next: true)
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/models/facilities_management/rm3830/rate_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
it 'contains data' do
benchmark_rates = {}
framework_rates = {}
described_class.all.each do |row|
described_class.find_each do |row|
code = row['code'].remove('.')
benchmark_rates[code] = row['benchmark'].to_f
framework_rates[code] = row['framework'].to_f
Expand Down
2 changes: 1 addition & 1 deletion spec/models/static_record_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
end

it 'freezes individual records' do
expect { klass.all.first.name = 'NEW' }
expect { klass.first.name = 'NEW' }
.to raise_exception(FrozenError)
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,10 @@
before do
create(:facilities_management_rm3830_procurement_building_av_normal_building, procurement:, service_codes:)
create(:facilities_management_rm3830_procurement_building_av_london_building, procurement:, service_codes:)
procurement.procurement_building_services.where(code: %w[C.2 C.5 G.1]).each { |pbs| pbs.update(service_standard: 'A') }
procurement.procurement_building_services.where(code: 'G.1').each { |pbs| pbs.update(no_of_building_occupants: volume) }
procurement.procurement_building_services.where(code: 'E.4').each { |pbs| pbs.update(no_of_appliances_for_testing: volume) }
procurement.procurement_building_services.where(code: 'C.5').each { |pbs| no_of_lifts.times { pbs.lifts.create(number_of_floors:) } }
procurement.procurement_building_services.where(code: %w[C.2 C.5 G.1]).find_each { |pbs| pbs.update(service_standard: 'A') }
procurement.procurement_building_services.where(code: 'G.1').find_each { |pbs| pbs.update(no_of_building_occupants: volume) }
procurement.procurement_building_services.where(code: 'E.4').find_each { |pbs| pbs.update(no_of_appliances_for_testing: volume) }
procurement.procurement_building_services.where(code: 'C.5').find_each { |pbs| no_of_lifts.times { pbs.lifts.create(number_of_floors:) } }
end

context 'and the lot is 1a' do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,11 +253,11 @@
before do
create(:facilities_management_rm3830_procurement_building_av_normal_building, procurement:, service_codes:)
create(:facilities_management_rm3830_procurement_building_av_london_building, procurement:, service_codes:)
procurement.procurement_building_services.where(code: 'C.1').each { |pbs| pbs.update(service_standard: 'A') }
procurement.procurement_building_services.where(code: 'G.1').each { |pbs| pbs.update(service_standard: 'A', no_of_building_occupants: 88000) }
procurement.procurement_building_services.where(code: 'I.1').each { |pbs| pbs.update(service_hours: 8736) }
procurement.procurement_building_services.where(code: 'K.2').each { |pbs| pbs.update(tones_to_be_collected_and_removed: 13000) }
procurement.procurement_building_services.where(code: 'H.4').each { |pbs| pbs.update(service_hours: 8736) }
procurement.procurement_building_services.where(code: 'C.1').find_each { |pbs| pbs.update(service_standard: 'A') }
procurement.procurement_building_services.where(code: 'G.1').find_each { |pbs| pbs.update(service_standard: 'A', no_of_building_occupants: 88000) }
procurement.procurement_building_services.where(code: 'I.1').find_each { |pbs| pbs.update(service_hours: 8736) }
procurement.procurement_building_services.where(code: 'K.2').find_each { |pbs| pbs.update(tones_to_be_collected_and_removed: 13000) }
procurement.procurement_building_services.where(code: 'H.4').find_each { |pbs| pbs.update(service_hours: 8736) }
end

context 'and the variance is just below -30%' do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,10 +156,10 @@
before do
create(:facilities_management_rm3830_procurement_building_av_normal_building, procurement:, service_codes:)
create(:facilities_management_rm3830_procurement_building_av_london_building, procurement:, service_codes:)
procurement.procurement_building_services.where(code: 'C.1').each { |pbs| pbs.update(service_standard: 'A') }
procurement.procurement_building_services.where(code: 'G.1').each { |pbs| pbs.update(service_standard: 'A', no_of_building_occupants: 3400) }
procurement.procurement_building_services.where(code: 'I.1').each { |pbs| pbs.update(service_hours: 6240) }
procurement.procurement_building_services.where(code: 'K.2').each { |pbs| pbs.update(tones_to_be_collected_and_removed: 13000) }
procurement.procurement_building_services.where(code: 'C.1').find_each { |pbs| pbs.update(service_standard: 'A') }
procurement.procurement_building_services.where(code: 'G.1').find_each { |pbs| pbs.update(service_standard: 'A', no_of_building_occupants: 3400) }
procurement.procurement_building_services.where(code: 'I.1').find_each { |pbs| pbs.update(service_hours: 6240) }
procurement.procurement_building_services.where(code: 'K.2').find_each { |pbs| pbs.update(tones_to_be_collected_and_removed: 13000) }
end

context 'and the variance is just below -30%' do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,10 @@
before do
create(:facilities_management_rm3830_procurement_building_av_normal_building, procurement:, service_codes:)
create(:facilities_management_rm3830_procurement_building_av_london_building, procurement:, service_codes:)
procurement.procurement_building_services.where(code: %w[C.1 C.2 C.3]).each { |pbs| pbs.update(service_standard: 'A') }
procurement.procurement_building_services.where(code: 'G.1').each { |pbs| pbs.update(service_standard: 'A', no_of_building_occupants: no_of_building_occupants) }
procurement.procurement_building_services.where(code: 'I.1').each { |pbs| pbs.update(service_hours: 6240) }
procurement.procurement_building_services.where(code: %w[K.2 K.3]).each { |pbs| pbs.update(tones_to_be_collected_and_removed:) }
procurement.procurement_building_services.where(code: %w[C.1 C.2 C.3]).find_each { |pbs| pbs.update(service_standard: 'A') }
procurement.procurement_building_services.where(code: 'G.1').find_each { |pbs| pbs.update(service_standard: 'A', no_of_building_occupants: no_of_building_occupants) }
procurement.procurement_building_services.where(code: 'I.1').find_each { |pbs| pbs.update(service_hours: 6240) }
procurement.procurement_building_services.where(code: %w[K.2 K.3]).find_each { |pbs| pbs.update(tones_to_be_collected_and_removed:) }
end

context 'and the variance is just below 30%' do
Expand Down
6 changes: 3 additions & 3 deletions spec/services/static_data_loader_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,21 @@
describe '.nuts1_codes_not_empty' do
it 'there is at least one Nuts1 Region' do
described_class.load_static_data(Nuts1Region)
expect(Nuts1Region.all.count.zero?).to be(false)
expect(Nuts1Region.count.zero?).to be(false)
end
end

describe '.nuts2_codes_not_empty' do
it 'there is at least 1 Nuts2 Regions' do
described_class.load_static_data(Nuts2Region)
expect(Nuts2Region.all.count.zero?).to be(false)
expect(Nuts2Region.count.zero?).to be(false)
end
end

describe '.nuts3_codes_not_empty' do
it 'there is at least 1 Nuts3 Region' do
described_class.load_static_data(Nuts3Region)
expect(Nuts3Region.all.count.zero?).to be(false)
expect(Nuts3Region.count.zero?).to be(false)
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ def add_other_sheet(sheet_name)
end

def da_service_codes
@da_service_codes ||= FacilitiesManagement::RM3830::Rate.all.where(direct_award: true).pluck(:code)
@da_service_codes ||= FacilitiesManagement::RM3830::Rate.where(direct_award: true).pluck(:code)
end

def work_packages
Expand Down

0 comments on commit 5761787

Please sign in to comment.