Skip to content

Commit

Permalink
Add the ability to restart PromotionCode Batch
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielePalombo committed Sep 14, 2023
1 parent ac42b91 commit 50ad9a0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
3 changes: 2 additions & 1 deletion core/app/models/spree/promotion_code/batch_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ def build_promotion_codes
private

def generate_random_codes
created_codes = 0
created_codes = promotion_code_batch.promotion_codes.count

batch_size = @options[:batch_size]

while created_codes < number_of_codes
Expand Down
10 changes: 10 additions & 0 deletions core/spec/models/spree/promotion_code/batch_builder_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,16 @@
expect(promotion.codes.size).to eq(number_of_codes)
end
end

context "when same promotion_codes are already present" do
before do
create_list(:promotion_code, 11, promotion: promotion, promotion_code_batch: promotion_code_batch)
end

it "creates only the missing promotion_codes" do
expect { subject.build_promotion_codes }.to change { promotion.codes.size }.by(39)
end
end
end
end

Expand Down

0 comments on commit 50ad9a0

Please sign in to comment.