Skip to content

Commit 60b88af

Browse files
authored
Merge pull request #6345 from blish/refactor-promotion-lanes
feat(Promotion): Make ordered lanes an array
2 parents b8c5268 + be0c164 commit 60b88af

File tree

3 files changed

+5
-5
lines changed

3 files changed

+5
-5
lines changed

promotions/app/models/solidus_promotions/order_adjuster/discount_order.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def initialize(order, promotions, dry_run: false)
1414
def call
1515
return order if order.shipped?
1616

17-
SolidusPromotions::Promotion.ordered_lanes.each_key do |lane|
17+
SolidusPromotions::Promotion.ordered_lanes.each do |lane|
1818
lane_promotions = promotions.select { |promotion| promotion.lane == lane }
1919
lane_benefits = eligible_benefits_for_promotable(lane_promotions.flat_map(&:benefits), order)
2020
perform_order_benefits(lane_benefits, lane) unless dry_run

promotions/app/models/solidus_promotions/promotion.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,13 @@ def self.human_enum_name(enum_name, enum_value)
5555
end
5656

5757
def self.lane_options
58-
ordered_lanes.map do |lane_name, _index|
59-
[human_enum_name(:lane, lane_name), lane_name]
58+
ordered_lanes.map do |lane|
59+
[human_enum_name(:lane, lane), lane]
6060
end
6161
end
6262

6363
def self.ordered_lanes
64-
lanes.sort_by(&:last).to_h
64+
lanes.keys.sort_by { |lane| lanes[lane] }
6565
end
6666

6767
def self.order_activatable?(order)

promotions/spec/models/solidus_promotions/promotion_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@
112112
describe ".ordered_lanes" do
113113
subject { described_class.ordered_lanes }
114114

115-
it { is_expected.to eq({ "pre" => 0, "default" => 1, "post" => 2 }) }
115+
it { is_expected.to eq(%w[pre default post]) }
116116
end
117117

118118
describe "validations" do

0 commit comments

Comments
 (0)