Browse Source

extract move_csv_attributes method

pull/842/head
Kat 3 years ago
parent
commit
1153b1a902
  1. 22
      app/models/case_log.rb
  2. 2
      spec/requests/case_logs_controller_spec.rb

22
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

2
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

Loading…
Cancel
Save