Browse Source

Don't paginate CSV download

pull/455/head
baarkerlounger 3 years ago
parent
commit
206aab915d
  1. 4
      app/controllers/case_logs_controller.rb
  2. 64
      spec/requests/case_logs_controller_spec.rb

4
app/controllers/case_logs_controller.rb

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

64
spec/requests/case_logs_controller_spec.rb

@ -405,35 +405,51 @@ RSpec.describe CaseLogsController, type: :request do
let(:user) { FactoryBot.create(:user) } let(:user) { FactoryBot.create(:user) }
let(:organisation) { user.organisation } let(:organisation) { user.organisation }
let(:other_organisation) { FactoryBot.create(:organisation) } let(:other_organisation) { FactoryBot.create(:organisation) }
let!(:case_log) do
FactoryBot.create(
:case_log,
owning_organisation: organisation,
managing_organisation: organisation,
ecstat1: 1,
)
end
before do context "when a log exists" do
sign_in user let!(:case_log) do
FactoryBot.create(:case_log) FactoryBot.create(
get "/logs", headers: headers, params: {} :case_log,
end owning_organisation: organisation,
managing_organisation: organisation,
ecstat1: 1,
)
end
it "downloads a CSV file with headers" do before do
csv = CSV.parse(response.body) sign_in user
expect(csv.first.first).to eq("id") FactoryBot.create(:case_log)
expect(csv.second.first).to eq(case_log.id.to_s) get "/logs", headers: headers, params: {}
end end
it "downloads a CSV file with headers" do
csv = CSV.parse(response.body)
expect(csv.first.first).to eq("id")
expect(csv.second.first).to eq(case_log.id.to_s)
end
it "does not download other orgs logs" do
csv = CSV.parse(response.body)
expect(csv.count).to eq(2)
end
it "does not download other orgs logs" do it "downloads answer labels rather than values" do
csv = CSV.parse(response.body) csv = CSV.parse(response.body)
expect(csv.count).to eq(2) expect(csv.second[10]).to eq("Full-time – 30 hours or more")
end
end end
it "downloads answer labels rather than values" do context "when there are more than 20 logs" do
csv = CSV.parse(response.body) before do
expect(csv.second[10]).to eq("Full-time – 30 hours or more") sign_in user
FactoryBot.create_list(:case_log, 26, owning_organisation: organisation)
get "/logs", headers: headers, params: {}
end
it "does not paginate, it downloads all the user's logs" do
csv = CSV.parse(response.body)
expect(csv.count).to eq(27)
end
end end
end end

Loading…
Cancel
Save