-
-
Notifications
You must be signed in to change notification settings - Fork 523
Add coverage for Followups and Mileages reports #6856
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,5 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| require "csv" | ||
|
|
||
| class MileageReportsController < ApplicationController | ||
|
|
||
This file was deleted.
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| require "rails_helper" | ||
|
|
||
| RSpec.describe "FollowupReports", type: :request do | ||
| describe "GET /index" do | ||
| context "when the user has access" do | ||
| let(:admin) { build(:casa_admin) } | ||
|
|
||
| it "returns the CSV report" do | ||
| sign_in admin | ||
|
|
||
| get followup_reports_path(format: :csv) | ||
|
|
||
| expect(response).to have_http_status(:success) | ||
| expect(response.header["Content-Type"]).to eq("text/csv") | ||
| expect(response.headers["Content-Disposition"]).to( | ||
| match("followup-report-#{Time.current.strftime("%Y-%m-%d")}.csv") | ||
| ) | ||
| end | ||
|
|
||
| it "adds the correct headers to the csv" do | ||
| sign_in admin | ||
|
|
||
| get followup_reports_path(format: :csv) | ||
|
|
||
| csv_headers = [ | ||
| "Case Number", | ||
| "Volunteer Name(s)", | ||
| "Note Creator Name", | ||
| "Note" | ||
| ] | ||
|
|
||
| csv_headers.each { |header| expect(response.body).to include(header) } | ||
| end | ||
| end | ||
|
|
||
| context "when the user is not authorized to access" do | ||
| it "redirects to root and displays an unauthorized message" do | ||
| volunteer = build(:volunteer) | ||
| sign_in volunteer | ||
|
|
||
| get followup_reports_path(format: :csv) | ||
|
|
||
| expect(response).to redirect_to root_path | ||
| expect(response.request.flash[:notice]).to eq "Sorry, you are not authorized to perform this action." | ||
| end | ||
| end | ||
| end | ||
| end | ||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,54 @@ | ||||||
| # frozen_string_literal: true | ||||||
|
|
||||||
| require "rails_helper" | ||||||
|
|
||||||
| RSpec.describe "MileageReports", type: :request do | ||||||
| describe "GET /index" do | ||||||
| context "when the user has access" do | ||||||
| let(:admin) { build(:casa_admin) } | ||||||
|
|
||||||
| it "returns the CSV report" do | ||||||
| sign_in admin | ||||||
|
|
||||||
| get mileage_reports_path(format: :csv) | ||||||
|
|
||||||
| expect(response).to have_http_status(:success) | ||||||
| expect(response.header["Content-Type"]).to eq("text/csv") | ||||||
|
||||||
| expect(response.header["Content-Type"]).to eq("text/csv") | |
| expect(response.header["Content-Type"]).to include("text/csv") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The response
Content-Typefor CSV downloads usually includes a charset suffix, soeq("text/csv")is too strict. Use a partial match (e.g.,include("text/csv")/match(/text\/csv/)) to avoid brittle failures and match existing report request specs.