Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions app/controllers/followup_reports_controller.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

class FollowupReportsController < ApplicationController
after_action :verify_authorized

Expand Down
2 changes: 2 additions & 0 deletions app/controllers/mileage_reports_controller.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require "csv"

class MileageReportsController < ApplicationController
Expand Down
7 changes: 0 additions & 7 deletions spec/controllers/followup_reports_controller_spec.rb

This file was deleted.

7 changes: 0 additions & 7 deletions spec/controllers/mileage_reports_controller_spec.rb

This file was deleted.

50 changes: 50 additions & 0 deletions spec/requests/followup_reports_spec.rb
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")
Copy link

Copilot AI Apr 15, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The response Content-Type for CSV downloads usually includes a charset suffix, so eq("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.

Suggested change
expect(response.header["Content-Type"]).to eq("text/csv")
expect(response.header["Content-Type"]).to include("text/csv")

Copilot uses AI. Check for mistakes.
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
54 changes: 54 additions & 0 deletions spec/requests/mileage_reports_spec.rb
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")
Copy link

Copilot AI Apr 15, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Content-Type for send_data CSV responses typically includes a charset (e.g., text/csv; charset=utf-8). Expecting exact equality to "text/csv" is brittle and likely to fail; align with other request specs by using include("text/csv") or match(/text\/csv/) instead.

Suggested change
expect(response.header["Content-Type"]).to eq("text/csv")
expect(response.header["Content-Type"]).to include("text/csv")

Copilot uses AI. Check for mistakes.
expect(response.headers["Content-Disposition"]).to(
match("mileage-report-#{Time.current.strftime("%Y-%m-%d")}.csv")
)
end

it "adds the correct headers to the csv" do
sign_in admin

get mileage_reports_path(format: :csv)

csv_headers = [
"Contact Types",
"Occurred At",
"Miles Driven",
"Casa Case Number",
"Creator Name",
"Supervisor Name",
"Volunteer Address",
"Reimbursed"
]

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 mileage_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
Loading