Skip to content

Commit

Permalink
Fix linting issues
Browse files Browse the repository at this point in the history
With the removal of our own .rubocop.yml, a few new linting problems
appeared.
  • Loading branch information
mamhoff committed Oct 25, 2024
1 parent 98c7d4f commit bf743d2
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ module SolidusPromotions
module Admin
module ConditionsHelper
def options_for_condition_types(benefit, condition)
options = benefit.available_conditions.map { |condition| [condition.model_name.human, condition.name] }
options = benefit.available_conditions.map do |available_condition|
[available_condition.model_name.human, available_condition.name]
end
options_for_select(options, condition&.type.to_s)
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,11 @@ def compute_amount(line_item)
order = line_item.order
line_items = applicable_line_items(order)

item_units = line_items.sort_by do |line_item|
[-line_item.quantity, line_item.id]
end.flat_map do |line_item|
Array.new(line_item.quantity) do
Item.new(line_item)
item_units = line_items.sort_by do |applicable_line_item|
[-applicable_line_item.quantity, applicable_line_item.id]
end.flat_map do |applicable_line_item|
Array.new(applicable_line_item.quantity) do
Item.new(applicable_line_item)
end
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ def initialize(order:, dry_run_promotion: nil)
def call
promos = connected_order_promotions | sale_promotions
promos << dry_run_promotion if dry_run_promotion
promos.flat_map(&:benefits).group_by(&:preload_relations).each do |preload_relations, benefits|
preload(records: benefits, associations: preload_relations)
benefits.flat_map(&:conditions).group_by(&:preload_relations).each do |preload_relations, conditions|
preload(records: conditions, associations: preload_relations)
promos.flat_map(&:benefits).group_by(&:preload_relations).each do |benefit_preload_relations, benefits|
preload(records: benefits, associations: benefit_preload_relations)
benefits.flat_map(&:conditions).group_by(&:preload_relations).each do |condition_preload_relations, conditions|
preload(records: conditions, associations: condition_preload_relations)
end
end
promos.reject { |promotion| promotion.usage_limit_exceeded?(excluded_orders: [order]) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def expect_order_connection(order:, promotion:, promotion_code: nil)
expect(order.solidus_order_promotions.flat_map(&:promotion_code)).to include(promotion_code)
end

def expect_adjustment_creation(adjustable:, promotion:, promotion_code: nil)
def expect_adjustment_creation(adjustable:, promotion:)
expect(adjustable.adjustments.map(&:source).map(&:promotion)).to include(promotion)
end

Expand Down Expand Up @@ -111,7 +111,7 @@ def expect_adjustment_creation(adjustable:, promotion:, promotion_code: nil)
expect(subject.success).to be_present
expect_order_connection(order: order, promotion: promotion, promotion_code: promotion_code)
order.line_items.each do |line_item|
expect_adjustment_creation(adjustable: line_item, promotion: promotion, promotion_code: promotion_code)
expect_adjustment_creation(adjustable: line_item, promotion: promotion)
end
# Ensure that applying the adjustment actually affects the order's total!
expect(order.reload.total).to eq(100)
Expand All @@ -134,7 +134,7 @@ def expect_adjustment_creation(adjustable:, promotion:, promotion_code: nil)
expect(subject.success).to be_present
expect_order_connection(order: order, promotion: promotion, promotion_code: promotion_code)
order.line_items.each do |line_item|
expect_adjustment_creation(adjustable: line_item, promotion: promotion, promotion_code: promotion_code)
expect_adjustment_creation(adjustable: line_item, promotion: promotion)
end
# Ensure that applying the adjustment actually affects the order's total!
expect(order.reload.total).to eq(100)
Expand All @@ -160,7 +160,7 @@ def expect_adjustment_creation(adjustable:, promotion:, promotion_code: nil)
expect(subject).to be_successful
expect_order_connection(order: order, promotion: promotion, promotion_code: promotion_code)
order.line_items.each do |line_item|
expect_adjustment_creation(adjustable: line_item, promotion: promotion, promotion_code: promotion_code)
expect_adjustment_creation(adjustable: line_item, promotion: promotion)
end
end
end
Expand All @@ -183,7 +183,7 @@ def expect_adjustment_creation(adjustable:, promotion:, promotion_code: nil)
expect(subject).to be_successful
order.line_items.each do |line_item|
expect(line_item.adjustments.count).to eq 2
expect_adjustment_creation(adjustable: line_item, promotion: promotion, promotion_code: promotion_code)
expect_adjustment_creation(adjustable: line_item, promotion: promotion)
end
end
end
Expand All @@ -209,7 +209,7 @@ def expect_adjustment_creation(adjustable:, promotion:, promotion_code: nil)

expect_order_connection(order: order, promotion: promotion, promotion_code: promotion_code)
order.shipments.each do |shipment|
expect_adjustment_creation(adjustable: shipment, promotion: promotion, promotion_code: promotion_code)
expect_adjustment_creation(adjustable: shipment, promotion: promotion)
end
end

Expand Down Expand Up @@ -243,7 +243,7 @@ def expect_adjustment_creation(adjustable:, promotion:, promotion_code: nil)
expect(order.all_adjustments.count).to eq(order.line_items.count)
expect_order_connection(order: order, promotion: promotion, promotion_code: promotion_code)
order.line_items.each do |line_item|
expect_adjustment_creation(adjustable: line_item, promotion: promotion, promotion_code: promotion_code)
expect_adjustment_creation(adjustable: line_item, promotion: promotion)
end
end

Expand Down

0 comments on commit bf743d2

Please sign in to comment.