Skip to content

Commit

Permalink
Rubocop -A
Browse files Browse the repository at this point in the history
  • Loading branch information
mamhoff committed Jan 27, 2024
1 parent 3aadd9e commit be37df1
Show file tree
Hide file tree
Showing 15 changed files with 20 additions and 23 deletions.
10 changes: 5 additions & 5 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ Rails/ApplicationController:
# This cop supports unsafe autocorrection (--autocorrect-all).
Rails/ApplicationJob:
Exclude:
- "core/app/jobs/spree/promotion_code_batch_job.rb"
- "legacy_promotions/app/jobs/spree/promotion_code_batch_job.rb"

# Offense count: 1
# This cop supports unsafe autocorrection (--autocorrect-all).
Expand All @@ -330,7 +330,7 @@ Rails/ApplicationRecord:
- "core/db/migrate/20170412103617_transform_tax_rate_category_relation.rb"
- "core/db/migrate/20180322142651_add_amount_remaining_to_store_credit_events.rb"
- "core/db/migrate/20180710170104_create_spree_store_credit_reasons_table.rb"
- "core/db/migrate/20190106184413_remove_code_from_spree_promotions.rb"
- "legacy_promotions/db/migrate/20190106184413_remove_code_from_spree_promotions.rb"
- "core/spec/lib/calculated_adjustments_spec.rb"
- "core/spec/models/spree/validations/db_maximum_length_validator_spec.rb"
- "core/spec/models/spree/wallet_payment_source_spec.rb"
Expand Down Expand Up @@ -476,8 +476,8 @@ Rails/ReflectionClassName:
Exclude:
- "core/app/models/spree/credit_card.rb"
- "core/app/models/spree/order.rb"
- "core/app/models/spree/promotion/rules/user.rb"
- "core/app/models/spree/promotion_rule_user.rb"
- "legacy_promotions/app/models/spree/promotion/rules/user.rb"
- "legacy_promotions/app/models/spree/promotion_rule_user.rb"
- "core/app/models/spree/role_user.rb"
- "core/app/models/spree/store_credit.rb"
- "core/app/models/spree/user_address.rb"
Expand Down Expand Up @@ -638,7 +638,7 @@ Style/OptionalBooleanParameter:
- "core/app/mailers/spree/reimbursement_mailer.rb"
- "core/app/models/concerns/spree/user_address_book.rb"
- "core/app/models/spree/order.rb"
- "core/app/models/spree/order_contents.rb"
- "core/app/models/spree/simple_order_contents.rb"
- "core/app/models/spree/stock/estimator.rb"

# Offense count: 4
Expand Down
2 changes: 1 addition & 1 deletion core/app/models/spree/simple_order_contents.rb
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def remove_from_line_item(variant, quantity, options = {})
def grab_line_item_by_variant(variant, raise_error = false, options = {})
line_item = order.find_line_item_by_variant(variant, options)

if !line_item.present? && raise_error
if line_item.blank? && raise_error
raise ActiveRecord::RecordNotFound, "Line item not found for variant #{variant.sku}"
end

Expand Down
2 changes: 1 addition & 1 deletion legacy_promotions/app/models/spree/promotion.rb
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ def remove_from(order)
actions.each do |action|
action.remove_from(order)
end
# note: this destroys the join table entry, not the promotion itself
# NOTE: this destroys the join table entry, not the promotion itself
order.promotions.destroy(self)
order.order_promotions.reset
order_promotions.reset
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

module Spree
class Promotion < Spree::Base

# This class encapsulates all the things the promotion system does to
# an order. It is called from the `Spree::OrderUpdater` before taxes are
# calculated, such that taxes always respect promotions.
Expand Down Expand Up @@ -43,6 +42,7 @@ def call
private

attr_reader :order

delegate :line_items, :shipments, to: :order

# Recalculate and persist the amount from this adjustment's source based on
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,8 @@ def eligible?(order, options = {})
@user = order.try(:user) || options[:user]
@email = order.email

if user || email
if !completed_orders.blank? && completed_orders.first != order
eligibility_errors.add(:base, eligibility_error_message(:not_first_order), error_code: :not_first_order)
end
if (user || email) && (completed_orders.present? && completed_orders.first != order)
eligibility_errors.add(:base, eligibility_error_message(:not_first_order), error_code: :not_first_order)
end

eligibility_errors.empty?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def applicable?(promotable)
end

def eligible?(order, _options = {})
unless order.user.present?
if order.user.blank?
eligibility_errors.add(:base, eligibility_error_message(:no_user_specified), error_code: :no_user_specified)
end
eligibility_errors.empty?
Expand Down
2 changes: 1 addition & 1 deletion legacy_promotions/app/models/spree/promotion_code.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def usage_count(excluded_orders: [])
complete.
where.not(spree_orders: { state: :canceled }).
joins(:order_promotions).
where(spree_orders_promotions: { promotion_code_id: self.id }).
where(spree_orders_promotions: { promotion_code_id: id }).
where.not(id: excluded_orders.map(&:id)).
count
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

class ::Spree::PromotionCode::BatchBuilder
attr_reader :promotion_code_batch, :options

delegate :promotion, :number_of_codes, :base_code, to: :promotion_code_batch

DEFAULT_OPTIONS = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,8 @@ def set_error_code(status_code, options = {})
end

def promotion
@promotion ||= begin
if promotion_code && promotion_code.promotion.active?
promotion_code.promotion
end
@promotion ||= if promotion_code && promotion_code.promotion.active?
promotion_code.promotion
end
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class Page

def initialize(order, path)
@order = order
@path = path.gsub(/\A\//, '')
@path = path.delete_prefix('/')
end

def activate
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,4 @@
%w[
Spree::Promotion::Actions::FreeShipping
].each { |klass| config.environment.promotions.shipping_actions << klass }

end
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# frozen_string_literal: true

require 'spree/core'

Check warning on line 3 in legacy_promotions/lib/solidus_legacy_promotions/migrations/promotions_with_code_handlers.rb

View check run for this annotation

Codecov / codecov/patch

legacy_promotions/lib/solidus_legacy_promotions/migrations/promotions_with_code_handlers.rb#L3

Added line #L3 was not covered by tests

module SolidusLegacyPromotions

Check warning on line 5 in legacy_promotions/lib/solidus_legacy_promotions/migrations/promotions_with_code_handlers.rb

View check run for this annotation

Codecov / codecov/patch

legacy_promotions/lib/solidus_legacy_promotions/migrations/promotions_with_code_handlers.rb#L5

Added line #L5 was not covered by tests
Expand Down
2 changes: 1 addition & 1 deletion legacy_promotions/solidus_legacy_promotions.gemspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

require_relative '../core/lib/spree/core/version.rb'
require_relative '../core/lib/spree/core/version'

Gem::Specification.new do |s|
s.platform = Gem::Platform::RUBY
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
context "when there are any applicable line items" do
before do
rule.preferred_eligible_values = Hash[line_item.product.id => [
line_item.variant.option_values.pluck(:id).first
line_item.variant.option_values.pick(:id)
]]
end
it { is_expected.to be true }
Expand Down
2 changes: 1 addition & 1 deletion legacy_promotions/spec/rails_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
config.use_transactional_fixtures = true

config.before :suite do
FileUtils.rm_rf(Rails.configuration.active_storage.service_configurations[:test][:root]) unless (ENV['DISABLE_ACTIVE_STORAGE'] == 'true')
FileUtils.rm_rf(Rails.configuration.active_storage.service_configurations[:test][:root]) unless ENV['DISABLE_ACTIVE_STORAGE'] == 'true'
DatabaseCleaner.clean_with :truncation
end

Expand Down

0 comments on commit be37df1

Please sign in to comment.