Browse Source

Download value labels rather than values

pull/440/head
baarkerlounger 3 years ago
parent
commit
9684f195eb
  1. 13
      app/models/case_log.rb
  2. 15
      app/models/concerns/generate_csv.rb
  3. 6
      spec/requests/case_logs_controller_spec.rb

13
app/models/case_log.rb

@ -18,7 +18,6 @@ end
class CaseLog < ApplicationRecord class CaseLog < ApplicationRecord
include Validations::SoftValidations include Validations::SoftValidations
include GenerateCsv
has_paper_trail has_paper_trail
@ -294,6 +293,18 @@ class CaseLog < ApplicationRecord
LaRentRange.find_by(start_year: collection_start_year, la:, beds:, lettype:).soft_max LaRentRange.find_by(start_year: collection_start_year, la:, beds:, lettype:).soft_max
end end
def self.to_csv
CSV.generate(headers: true) do |csv|
csv << attribute_names
all.find_each do |record|
csv << record.attributes.map do |att, val|
record.form.get_question(att, record)&.label_from_value(val) || val
end
end
end
end
private private
PIO = Postcodes::IO.new PIO = Postcodes::IO.new

15
app/models/concerns/generate_csv.rb

@ -1,15 +0,0 @@
module GenerateCsv
extend ActiveSupport::Concern
class_methods do
def to_csv
CSV.generate(headers: true) do |csv|
csv << attribute_names
all.each do |record|
csv << record.attributes.values
end
end
end
end
end

6
spec/requests/case_logs_controller_spec.rb

@ -492,6 +492,7 @@ RSpec.describe CaseLogsController, type: :request do
:case_log, :case_log,
owning_organisation: organisation, owning_organisation: organisation,
managing_organisation: organisation, managing_organisation: organisation,
ecstat1: 1,
) )
end end
@ -511,6 +512,11 @@ RSpec.describe CaseLogsController, type: :request do
csv = CSV.parse(response.body) csv = CSV.parse(response.body)
expect(csv.count).to eq(2) expect(csv.count).to eq(2)
end end
it "downloads answer labels rather than values" do
csv = CSV.parse(response.body)
expect(csv.second[10]).to eq("Full-time - 30 hours or more")
end
end end
describe "PATCH" do describe "PATCH" do

Loading…
Cancel
Save