Previously, users received multiple emails after successful payment: - One email per individual ticket (via orders_controller.rb) - One order-level email with all tickets (via order.rb mark_as_paid!) This resulted in N+1 emails for N tickets purchased. Changes: - Removed individual ticket email sending from orders_controller.rb - Kept single comprehensive order email in order.rb - Updated test to reflect that email failures don't prevent order completion - Users now receive exactly one email with all tickets as PDF attachments 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
38 lines
1.2 KiB
Ruby
38 lines
1.2 KiB
Ruby
require "test_helper"
|
|
|
|
class OrderEmailTest < ActiveSupport::TestCase
|
|
def setup
|
|
@order = orders(:draft_order)
|
|
end
|
|
|
|
test "sends purchase confirmation email when order is marked as paid" do
|
|
# Mock the mailer to capture the call
|
|
TicketMailer.expects(:purchase_confirmation_order).with(@order).returns(stub(deliver_now: true))
|
|
|
|
@order.mark_as_paid!
|
|
|
|
assert_equal "paid", @order.status
|
|
end
|
|
|
|
test "activates all tickets when order is marked as paid" do
|
|
@order.tickets.update_all(status: "reserved")
|
|
|
|
# Mock the mailer to avoid actual email sending
|
|
TicketMailer.stubs(:purchase_confirmation_order).returns(stub(deliver_now: true))
|
|
|
|
@order.mark_as_paid!
|
|
|
|
assert @order.tickets.all? { |ticket| ticket.status == "active" }
|
|
end
|
|
|
|
test "email sending failure does not prevent order completion" do
|
|
# Mock mailer to raise an error
|
|
TicketMailer.stubs(:purchase_confirmation_order).raises(StandardError.new("Email error"))
|
|
|
|
# Should not raise error - email failure is logged but doesn't fail the payment
|
|
@order.mark_as_paid!
|
|
|
|
# Order should still be marked as paid even if email fails
|
|
assert_equal "paid", @order.reload.status
|
|
end
|
|
end |