Skip to content
This repository was archived by the owner on Feb 19, 2025. It is now read-only.

Commit

Permalink
Merge pull request #63 from friendlycart/resilient-migrator
Browse files Browse the repository at this point in the history
Promo Migrator: Ignore missing rules and actions
  • Loading branch information
mamhoff authored Oct 31, 2023
2 parents a9ef2e2 + 18fbe92 commit 1a16596
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/solidus_friendly_promotions/promotion_migrator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ def call
generate_new_promotion_rules(old_promotion_rule)
end
new_promotion.actions = promotion.actions.flat_map do |old_promotion_action|
generate_new_promotion_actions(old_promotion_action).tap do |new_promotion_action|
generate_new_promotion_actions(old_promotion_action)&.tap do |new_promotion_action|
new_promotion_action.original_promotion_action = old_promotion_action
end
end
end.compact
new_promotion.save!
copy_promotion_code_batches(new_promotion)
copy_promotion_codes(new_promotion)
Expand Down Expand Up @@ -79,7 +79,7 @@ def generate_new_promotion_actions(old_promotion_action)
promo_action_config = promotion_map[:actions][old_promotion_action.class]
if promo_action_config.nil?
puts("#{old_promotion_action.class} is not supported")
return []
return nil
end
promo_action_config.call(old_promotion_action)
end
Expand Down
15 changes: 15 additions & 0 deletions spec/lib/solidus_friendly_promotions/promotion_migrator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,19 @@
expect(promotion_code_batch.base_code).to eq("DISNEY4LIFE")
end
end

context "if our rules and actions are missing from the promotion map" do
let(:promotion_map) do
{
rules: {},
actions: {}
}
end

it "still creates the promotion, but without rules or actions" do
subject
expect(Spree::Promotion.count).not_to be_zero
expect(SolidusFriendlyPromotions::Promotion.count).to eq(Spree::Promotion.count)
end
end
end

0 comments on commit 1a16596

Please sign in to comment.