Skip to content

Commit aa11fbd

Browse files
authored
Merge pull request #6424 from mamhoff/validate-order-promotion-uniqueness
OrderPromotions: Validate promotion uniqueness per order
2 parents 3896980 + 25ab4c5 commit aa11fbd

File tree

2 files changed

+3
-0
lines changed

2 files changed

+3
-0
lines changed

promotions/app/models/solidus_promotions/order_promotion.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ class OrderPromotion < Spree::Base
1111
belongs_to :promotion_code, class_name: "SolidusPromotions::PromotionCode", optional: true
1212

1313
validates :promotion_code, presence: true, if: :require_promotion_code?
14+
validates :promotion_id, uniqueness: { scope: :order_id }
1415

1516
self.allowed_ransackable_associations = %w[promotion_code]
1617

promotions/spec/models/solidus_promotions/order_promotion_spec.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
let(:promotion) { build(:solidus_promotion) }
1111
let(:order_promotion) { build(:solidus_order_promotion, promotion: promotion) }
1212

13+
it { is_expected.to validate_uniqueness_of(:promotion_id).scoped_to(:order_id) }
14+
1315
describe "promotion code presence error" do
1416
subject do
1517
order_promotion.valid?

0 commit comments

Comments
 (0)