Browse Source

Cldc 1433 csv output symbols correctly (#837)

* Add BOMs before CSV info

* add BOM to tests

* DRYing

* remove added blank line
pull/839/head
natdeanlewissoftwire 2 years ago committed by GitHub
parent
commit
3d9fb63707
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      app/controllers/application_controller.rb
  2. 2
      app/controllers/case_logs_controller.rb
  3. 4
      app/controllers/organisations_controller.rb
  4. 2
      app/controllers/users_controller.rb
  5. 2
      spec/requests/case_logs_controller_spec.rb

4
app/controllers/application_controller.rb

@ -14,4 +14,8 @@ protected
def user_for_paper_trail
current_user
end
def byte_order_mark
"\uFEFF"
end
end

2
app/controllers/case_logs_controller.rb

@ -22,7 +22,7 @@ class CaseLogsController < ApplicationController
end
format.csv do
send_data unpaginated_filtered_logs.to_csv(current_user), filename: "logs-#{Time.zone.now}.csv"
send_data byte_order_mark + unpaginated_filtered_logs.to_csv(current_user), filename: "logs-#{Time.zone.now}.csv"
end
end
end

4
app/controllers/organisations_controller.rb

@ -45,7 +45,7 @@ class OrganisationsController < ApplicationController
end
end
format.csv do
send_data unpaginated_filtered_users.to_csv, filename: "users-#{@organisation.name}-#{Time.zone.now}.csv"
send_data byte_order_mark + unpaginated_filtered_users.to_csv, filename: "users-#{@organisation.name}-#{Time.zone.now}.csv"
end
end
end
@ -103,7 +103,7 @@ class OrganisationsController < ApplicationController
end
format.csv do
send_data unpaginated_filtered_logs.to_csv, filename: "logs-#{@organisation.name}-#{Time.zone.now}.csv"
send_data byte_order_mark + unpaginated_filtered_logs.to_csv, filename: "logs-#{@organisation.name}-#{Time.zone.now}.csv"
end
end
else

2
app/controllers/users_controller.rb

@ -20,7 +20,7 @@ class UsersController < ApplicationController
format.html
format.csv do
if current_user.support?
send_data filtered_users.to_csv, filename: "users-#{Time.zone.now}.csv"
send_data byte_order_mark + filtered_users.to_csv, filename: "users-#{Time.zone.now}.csv"
else
head :unauthorized
end

2
spec/requests/case_logs_controller_spec.rb

@ -755,7 +755,7 @@ RSpec.describe CaseLogsController, type: :request do
it "downloads a CSV file with headers" do
csv = CSV.parse(response.body)
expect(csv.first.first).to eq("id")
expect(csv.first.first).to eq("\uFEFFid")
expect(csv.second.first).to eq(case_log.id.to_s)
end

Loading…
Cancel
Save