From de9a86b3c672ab776d5dfbdebd2f04e43fc6f42f Mon Sep 17 00:00:00 2001 From: baarkerlounger <5101747+baarkerlounger@users.noreply.github.com> Date: Wed, 6 Jul 2022 16:44:02 +0100 Subject: [PATCH] Remove count query from CSV download path (#714) * Remove count query from CSV download path * Rubocop * Legit complete log * Spec --- app/controllers/case_logs_controller.rb | 11 +- spec/fixtures/complete_case_log.json | 316 ++++++++++++++---------- 2 files changed, 188 insertions(+), 139 deletions(-) diff --git a/app/controllers/case_logs_controller.rb b/app/controllers/case_logs_controller.rb index 876e337ff..740dd2003 100644 --- a/app/controllers/case_logs_controller.rb +++ b/app/controllers/case_logs_controller.rb @@ -14,12 +14,13 @@ class CaseLogsController < ApplicationController all_logs = current_user.case_logs unpaginated_filtered_logs = filtered_case_logs(filtered_collection(all_logs, search_term)) - @pagy, @case_logs = pagy(unpaginated_filtered_logs) - @searched = search_term.presence - @total_count = all_logs.size - respond_to do |format| - format.html + format.html do + @pagy, @case_logs = pagy(unpaginated_filtered_logs) + @searched = search_term.presence + @total_count = all_logs.size + end + format.csv do send_data unpaginated_filtered_logs.to_csv, filename: "logs-#{Time.zone.now}.csv" end diff --git a/spec/fixtures/complete_case_log.json b/spec/fixtures/complete_case_log.json index 9cb1fc62f..227da864b 100644 --- a/spec/fixtures/complete_case_log.json +++ b/spec/fixtures/complete_case_log.json @@ -1,138 +1,186 @@ { "case_log": { - "tenancycode": "T657", - "age1": 35, - "sex1": "F", - "ethnic": 0, - "national": 0, - "prevten": 6, - "armedforces": 1, - "armed_forces_partner": "", - "ecstat1": 1, - "hhmemb": 8, - "relat2": "P", - "age2": 32, - "sex2": "M", - "ecstat2": 6, - "relat3": "C", - "age3": 12, - "sex3": "M", - "ecstat3": 9, - "relat4": "C", - "age4": 12, - "sex4": "F", - "ecstat4": 9, - "relat5": "C", - "age5": 10, - "sex5": "X", - "ecstat5": 9, - "relat6": "C", - "age6": 5, - "sex6": "R", - "ecstat6": 9, - "age7": 5, - "sex7": "R", - "ecstat7": 9, - "relat8": "C", - "age8": 2, - "sex8": "R", - "ecstat8": 9, - "homeless": 2, - "reason": 1, - "underoccupation_benefitcap": 0, - "leftreg": 1, - "reservist": 0, - "illness": 1, - "preg_occ": 1, - "startdate": "12/12/2021", - "startertenancy": 0, - "tenancylength": 5, - "tenancy": 1, - "landlord": 1, - "previous_la_known": 1, - "la": "Barnet", - "postcode_full": "NW1 5TY", - "property_relet": 0, - "rsnvac": 14, - "property_reference": "P9876", - "unittype_gn": 7, - "property_building_type": "dummy", - "beds": 3, - "voiddate": "10/10/2020", - "majorrepairs": 1, - "mrcdate": "11/11/2020", - "offered": 2, - "wchair": 1, - "net_income_known": 1, - "earnings": 150, - "incfreq": 1, - "benefits": 1, - "hb": 1, - "period": 2, - "brent": 200, - "scharge": 50, - "pscharge": 40, - "supcharg": 35, - "tcharge": 325, - "outstanding_amount": 1, - "layear": 2, - "lawaitlist": 1, - "prevloc": "E07000105", - "ppostcode_full": "SE2 6RT", - "reasonpref": 1, - "cbl": 0, - "chr": 1, - "cap": 0, - "hbrentshortfall": 1, - "tshortfall": 12, - "reasonother": null, - "housingneeds_a": 1, - "housingneeds_b": 0, - "housingneeds_c": 0, - "housingneeds_f": 0, - "housingneeds_g": 0, - "housingneeds_h": 0, - "accessibility_requirements_prefer_not_to_say": 0, - "illness_type_1": 0, - "illness_type_2": 1, - "illness_type_3": 0, - "illness_type_4": 0, - "illness_type_8": 0, - "illness_type_5": 0, - "illness_type_6": 0, - "illness_type_7": 0, - "illness_type_9": 0, - "illness_type_10": 0, - "condition_effects_prefer_not_to_say": 1, - "rp_homeless": 0, - "rp_insan_unsat": 0, - "rp_medwel": 0, - "rp_hardship": 0, - "rp_dontknow": 0, - "discarded_at": "05/05/2020", - "net_income_value_check": 0, - "property_owner_organisation": "", - "property_manager_organisation": "", - "rent_type": 0, - "intermediate_rent_product_name": "", - "needstype": 1, - "sale_completion_date": "01/01/2020", - "purchaser_code": "", - "propcode": "123", - "postcode": "a1", - "postcod2": "w3", - "first_time_property_let_as_social_housing": 0, - "unitletas": 1, - "builtype": 0, - "property_wheelchair_accessible": 1, - "void_or_renewal_date": "05/05/2020", - "renewal": 0, - "new_build_handover_date": "01/01/2019", - "has_benefits": 1, - "household_charge": 0, - "is_carehome": 0, - "sheltered": 0, - "declaration": 1, - "referral": 1 + "tenancycode":"T1245", + "age1":34, + "sex1":"M", + "ethnic":1, + "national":1, + "prevten":3, + "ecstat1":1, + "hhmemb":3, + "age2":29, + "sex2":"F", + "ecstat2":2, + "age3":11, + "sex3":"R", + "ecstat3":9, + "age4":null, + "sex4":null, + "ecstat4":null, + "age5":null, + "sex5":null, + "ecstat5":null, + "age6":null, + "sex6":null, + "ecstat6":null, + "age7":null, + "sex7":null, + "ecstat7":null, + "age8":null, + "sex8":null, + "ecstat8":null, + "homeless":1, + "underoccupation_benefitcap":2, + "leftreg":null, + "reservist":null, + "illness":2, + "preg_occ":2, + "startertenancy":2, + "tenancylength":null, + "tenancy":2, + "ppostcode_full":"NW18TR", + "rsnvac":5, + "unittype_gn":7, + "beds":2, + "offered":0, + "wchair":1, + "earnings":190, + "incfreq":1, + "benefits":3, + "period":3, + "layear":7, + "waityear":2, + "postcode_full":"NW18EE", + "reasonpref":2, + "cbl":1, + "chr":0, + "cap":0, + "reasonother":"", + "housingneeds_a":0, + "housingneeds_b":0, + "housingneeds_c":1, + "housingneeds_f":0, + "housingneeds_g":0, + "housingneeds_h":0, + "illness_type_1":null, + "illness_type_2":null, + "illness_type_3":null, + "illness_type_4":null, + "illness_type_8":null, + "illness_type_5":null, + "illness_type_6":null, + "illness_type_7":null, + "illness_type_9":null, + "illness_type_10":null, + "rp_homeless":null, + "rp_insan_unsat":null, + "rp_medwel":null, + "rp_hardship":null, + "rp_dontknow":null, + "tenancyother":"", + "net_income_value_check":null, + "property_owner_organisation":null, + "property_manager_organisation":null, + "sale_or_letting":null, + "irproduct_other":"", + "purchaser_code":null, + "reason":42, + "propcode":"PT562", + "majorrepairs":1, + "la":"E09000007", + "prevloc":"E09000007", + "hb":9, + "hbrentshortfall":null, + "property_relet":null, + "mrcdate":"2021-05-07T00:00:00.000+01:00", + "incref":null, + "sale_completion_date":null, + "startdate":"2021-06-06T00:00:00.000+01:00", + "armedforces":2, + "first_time_property_let_as_social_housing":0, + "unitletas":1, + "builtype":1, + "voiddate":"2021-05-05T00:00:00.000+01:00", + "owning_organisation_id":1, + "managing_organisation_id":1, + "renttype":2, + "needstype":1, + "lettype":7, + "postcode_known":1, + "is_la_inferred":true, + "totchild":1, + "totelder":0, + "totadult":2, + "net_income_known":0, + "nocharge":0, + "is_carehome":null, + "household_charge":null, + "referral":2, + "brent":"350.0", + "scharge":"11.0", + "pscharge":"11.0", + "supcharg":"0.0", + "tcharge":"372.0", + "tshortfall":null, + "chcharge":null, + "declaration":1, + "ppcodenk":1, + "previous_la_known":null, + "is_previous_la_inferred":true, + "age1_known":0, + "age2_known":0, + "age3_known":0, + "age4_known":null, + "age5_known":null, + "age6_known":null, + "age7_known":null, + "age8_known":null, + "ethnic_group":0, + "ethnic_other":null, + "letting_allocation_unknown":0, + "details_known_2":0, + "details_known_3":0, + "details_known_4":null, + "details_known_5":null, + "details_known_6":null, + "details_known_7":null, + "details_known_8":null, + "rent_type":1, + "has_benefits":0, + "renewal":0, + "wrent":"87.5", + "wscharge":"2.75", + "wpschrge":"2.75", + "wsupchrg":"0.0", + "wtcharge":"93.0", + "wtshortfall":null, + "refused":1, + "housingneeds":2, + "wchchrg":null, + "newprop":2, + "relat2":"P", + "relat3":"C", + "relat4":null, + "relat5":null, + "relat6":null, + "relat7":null, + "relat8":null, + "rent_value_check":null, + "old_form_id":null, + "lar":null, + "irproduct":null, + "old_id":null, + "joint":null, + "created_by_id":2, + "illness_type_0":null, + "retirement_value_check":null, + "tshortfall_known":null, + "sheltered":null, + "pregnancy_value_check":null, + "hhtype":6, + "new_old":1, + "vacdays":30, + "scheme_id":null, + "location_id":null } }