Skip to content
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

fix: Normalize CSV Comparison in Tests to Ignore Quotes #2264

Merged
merged 3 commits into from
Jul 9, 2024
Merged
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/graphql/types/data_exports/invoices/filters_input.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Types
module DataExports
module Invoices
2 changes: 2 additions & 0 deletions spec/graphql/types/data_exports/object_spec.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'rails_helper'

RSpec.describe Types::DataExports::Object do
12 changes: 11 additions & 1 deletion spec/models/deprecation_spec.rb
Original file line number Diff line number Diff line change
@@ -45,7 +45,7 @@
describe '.get_all_as_csv' do
it 'returns deprecation data for all organizations' do
csv = "org_id,org_name,org_email,last_event_sent_at,count\n"
csv += "#{organization.id},#{organization.name},#{organization.email},2024-05-22T14:58:20.280Z,101\n"
csv += "#{organization.id},#{csv_safe(organization.name)},#{organization.email},2024-05-22T14:58:20.280Z,101\n"
expect(described_class.get_all_as_csv(feature_name)).to eq(csv)
end
end
@@ -67,4 +67,14 @@
expect(Rails.cache.read("deprecation:#{feature_name}:#{organization.id}:count")).to be_nil
end
end

def csv_safe(value)
# Enclose the value in double quotes if it contains a comma or double quote
if value.include?(',') || value.include?('"')
value = value.gsub('"', '""') # Escape double quotes by doubling them
"\"#{value}\""
else
value
end
end
end