Browse Source

Apply filters to csv downloads (#458)

pull/459/head
kosiakkatrina 3 years ago committed by GitHub
parent
commit
b4698e5ff7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      app/controllers/case_logs_controller.rb
  2. 12
      spec/requests/case_logs_controller_spec.rb

2
app/controllers/case_logs_controller.rb

@ -14,7 +14,7 @@ class CaseLogsController < ApplicationController
respond_to do |format|
format.html
format.csv do
send_data current_user.case_logs.to_csv, filename: "logs-#{Time.zone.now}.csv"
send_data filtered_case_logs.to_csv, filename: "logs-#{Time.zone.now}.csv"
end
end
end

12
spec/requests/case_logs_controller_spec.rb

@ -477,6 +477,10 @@ RSpec.describe CaseLogsController, type: :request do
before do
sign_in user
FactoryBot.create(:case_log)
FactoryBot.create(:case_log,
:completed,
owning_organisation: organisation,
managing_organisation: organisation)
get "/logs", headers: headers, params: {}
end
@ -488,13 +492,19 @@ RSpec.describe CaseLogsController, type: :request do
it "does not download other orgs logs" do
csv = CSV.parse(response.body)
expect(csv.count).to eq(2)
expect(csv.count).to eq(3)
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
it "dowloads filtered logs" do
get "/logs?status[]=completed", headers:, params: {}
csv = CSV.parse(response.body)
expect(csv.count).to eq(2)
end
end
context "when there are more than 20 logs" do

Loading…
Cancel
Save