If you introduced some combination of a user ID and promo code, then it won't prevent a race of one user firing many queries with different promo codes and stacking them up. It would, however, fix the original problem.
Class Discount
belongs_to :promo_code
belongs_to :customer
belongs_to :order
validates_presence_of :promo_code, :customer, :order
validates_associated :promo_code
validates_uniqueness_of :promo_code_id, :scope => [:customer_id, :order_id]
end
Limiting down to a single Promo-code per order: Class Discount
# ...
validates_uniqueness_of :order_id, :scope => :customer_id
endYou need to enforce the uniqueness in the DB.
add_index :discounts, [:promo_code_id, :customer_id, :order_id], :unique => true