Skip to content

Commit

Permalink
Merge pull request #193 from fnf-org/kig/csv/ticket-request
Browse files Browse the repository at this point in the history
Fixing Ticket Request CSV as per request; upgrading gems
  • Loading branch information
beingmattlevy authored May 24, 2024
2 parents 6ba41b6 + 2efe9ad commit 5cff6ce
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 56 deletions.
12 changes: 6 additions & 6 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ GEM
mini_mime (1.1.5)
mini_racer (0.12.0)
libv8-node (~> 21.7.2.0)
minitest (5.23.0)
minitest (5.23.1)
msgpack (1.7.2)
multi_json (1.15.0)
mutex_m (0.2.0)
Expand Down Expand Up @@ -269,7 +269,7 @@ GEM
ast (~> 2.4.1)
racc
pg (1.5.6)
propshaft (0.8.0)
propshaft (0.9.0)
actionpack (>= 7.0.0)
activesupport (>= 7.0.0)
rack
Expand Down Expand Up @@ -325,11 +325,11 @@ GEM
zeitwerk (~> 2.6)
rainbow (3.1.1)
rake (13.2.1)
rdoc (6.6.3.1)
rdoc (6.7.0)
psych (>= 4.0.0)
redis (5.2.0)
redis-client (>= 0.22.0)
redis-client (0.22.1)
redis-client (0.22.2)
connection_pool
regexp_parser (2.9.2)
relaxed-rubocop (2.5)
Expand Down Expand Up @@ -367,7 +367,7 @@ GEM
rspec-mocks (~> 3.13)
rspec-support (~> 3.13)
rspec-support (3.13.1)
rubocop (1.63.5)
rubocop (1.64.0)
json (~> 2.3)
language_server-protocol (>= 3.17.0)
parallel (~> 1.10)
Expand Down Expand Up @@ -428,7 +428,7 @@ GEM
stimulus-rails (1.3.3)
railties (>= 6.0.0)
stringio (3.1.0)
stripe (11.4.0)
stripe (11.5.0)
strscan (3.1.0)
temple (0.10.3)
thor (1.3.1)
Expand Down
2 changes: 1 addition & 1 deletion app/classes/fnf/events/abstract_event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class << self
# @param [Object] subclass
def inherited(subclass)
# noinspection RubyMismatchedArgumentType
super(subclass)
super

subclass.include Ventable::Event

Expand Down
78 changes: 31 additions & 47 deletions app/models/ticket_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,76 +47,59 @@ class << self
# and then for each ticket request we return the primary user with the ticket request info,
# followed by one row per guest.
def for_csv(event)
table = []
[].tap do |table|
event.ticket_requests.active.each do |ticket_request|
# Main Ticket Request User Row
row = []

event.ticket_requests.active.each do |ticket_request|
# Main Ticket Request User Row
row = []
row << ticket_request.user.name
row << ticket_request.user.email

row << ticket_request.user.name
row << ticket_request.user.email
row << 'No'
row << ''
csv_columns.each do |column|
row << ticket_request.attributes[column]
end

csv_columns.each do |column|
row << ticket_request.attributes[column]
end

table << row

ticket_request.guests.each do |guest|
age_string = guest.include?(',') ? guest.gsub(/.*,/, '').strip : ''
first, last, = guest.split(/[\s,]+/)
email = guest.include?('<') ? guest.gsub(/.*</, '').gsub(/>.*/, '') : ''

next if "#{first} #{last}" == ticket_request.user.name || email == ticket_request.user.email

kids_age = age_string.empty? ? '' : kids_age(age_string)

table << ["#{first} #{last}", email, 'Yes', kids_age]
table << row
end
end

table
end

def csv_header
['Name', 'Email', 'Guest?', 'Kids Age', *csv_columns.map(&:titleize)]
['name', 'email', *csv_columns]
end

def csv_columns
%w[
address_line1
address_line2
city
state
zip_code
country_code
id
adults
kids
special_price
donation
cabins
needs_assistance
status
notes
status
created_at
updated_at
user_id
special_price
event_id
donation
role
role_explanation
previous_contribution
address_line1
address_line2
city
state
zip_code
country_code
admin_notes
car_camping
car_camping_explanation
admin_notes
early_arrival_passes
late_departure_passes
guests
]
end

private

def kids_age(string)
Integer(string)
rescue StandardError
''
end
end

# Deletions of TicketRequests are logical, not physical
Expand Down Expand Up @@ -205,8 +188,9 @@ def kids_age(string)
scope :declined, -> { where(status: STATUS_DECLINED) }
scope :not_declined, -> { where.not(status: STATUS_DECLINED) }

# Those TicketRequests that should be exported as a Guest List
scope :active, -> { where(status: [STATUS_COMPLETED, STATUS_AWAITING_PAYMENT]) }
# Those TicketRequests that should be exported as a Guest List and include user record to avoid N+1
# @see https://medium.com/doctolib/how-to-find-fix-and-prevent-n-1-queries-on-rails-6b30d9cfbbaf
scope :active, -> { where(status: [STATUS_COMPLETED, STATUS_AWAITING_PAYMENT]).includes(:user) }

def can_view?(user)
self.user == user || event.admin?(user)
Expand Down
4 changes: 2 additions & 2 deletions spec/models/ticket_request_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -466,13 +466,13 @@
it { is_expected.not_to eq [] }

# number of active requests with two guests each
its(:size) { is_expected.to eq(number_of_active_requests * 3) }
its(:size) { is_expected.to eq(number_of_active_requests) }
end

describe '.csv_columns' do
subject { described_class.csv_header }

it { is_expected.to start_with %w[Name Email Guest?] }
it { is_expected.to start_with %w[name email id adults kids] }
end
end
end

0 comments on commit 5cff6ce

Please sign in to comment.