Skip to content

Instantly share code, notes, and snippets.

@KamaKAzii
Created August 29, 2017 13:48
Show Gist options
  • Save KamaKAzii/542ecb4458f8741011cf8237af9e67cd to your computer and use it in GitHub Desktop.
Save KamaKAzii/542ecb4458f8741011cf8237af9e67cd to your computer and use it in GitHub Desktop.
def self.purchase_as_guest_with_data(data)
s = create_student_from_data(data)
p = create_parent_from_data(data)
s_user = User.new
s_user.contact = s
s_user.email = s.email
s_user.password = data[:student][:password]
p_user = User.new
p_user.contact = p
p_user.email = p.email
p_user.password = data[:student][:password]
tickets = data[:ticket_allocation_ids].map do |id|
t = Ticket.new
t.ticket_allocation_id = id
t.contact = s
t.purchase_date = Date.today
t
end
ActiveRecord::Base.transaction do
s.save!
p.save!
s_user.save!
p_user.save!
tickets.each { |t| t.save! }
end
return [s, p, s_user, p_user] + tickets
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment