From 1153b1a902ea626afbbecded8ec2affd3ef3739a Mon Sep 17 00:00:00 2001 From: Kat Date: Tue, 23 Aug 2022 11:19:56 +0100 Subject: [PATCH] extract move_csv_attributes method --- app/models/case_log.rb | 22 +++++++++++----------- spec/requests/case_logs_controller_spec.rb | 2 +- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/app/models/case_log.rb b/app/models/case_log.rb index fabb896d7..639cf46b3 100644 --- a/app/models/case_log.rb +++ b/app/models/case_log.rb @@ -500,13 +500,9 @@ class CaseLog < ApplicationRecord attributes end - def self.move_metadata_fields_to_front(initial_attributes) - attributes = initial_attributes.clone - %w[managing_organisation_name owning_organisation_name is_dpo created_by_name updated_at created_at status id].each do |attribute| - attributes.delete(attribute) - attributes.insert(0, attribute) - end - attributes + def self.move_metadata_fields_to_front(attributes) + metadata_fields = %w[managing_organisation_name owning_organisation_name is_dpo created_by_name updated_at created_at status id] + move_csv_attributes(attributes, metadata_fields, 0) end def self.move_is_inferred_fields(initial_attributes) @@ -518,11 +514,15 @@ class CaseLog < ApplicationRecord attributes end - def self.move_scheme_fields_to_back(initial_attributes) + def self.move_scheme_fields_to_back(attributes) + move_csv_attributes(attributes, %w[scheme_id location_id], -1) + end + + def self.move_csv_attributes(initial_attributes, fields_to_move, index) attributes = initial_attributes.clone - %w[scheme_id location_id].each do |attribute| - attributes.delete(attribute) - attributes.insert(-1, attribute) + fields_to_move.each do |field| + attributes.delete(field) + attributes.insert(index, field) end attributes end diff --git a/spec/requests/case_logs_controller_spec.rb b/spec/requests/case_logs_controller_spec.rb index 13d088e31..6ed0854ed 100644 --- a/spec/requests/case_logs_controller_spec.rb +++ b/spec/requests/case_logs_controller_spec.rb @@ -766,7 +766,7 @@ RSpec.describe CaseLogsController, type: :request do it "downloads answer labels rather than values" do csv = CSV.parse(response.body) - expect(csv.second[16]).to eq("Full-time – 30 hours or more") + expect(csv.second[15]).to eq("Full-time – 30 hours or more") end it "downloads filtered logs" do