Skip to content

Commit

Permalink
Merge pull request openfoodfoundation#12589 from cyrillefr/FixRailsRe…
Browse files Browse the repository at this point in the history
…dundantActiveRecordAllMethodIssue

Fixes Rails/RedundantActiveRecordAllMethod issues
  • Loading branch information
dacook authored Jun 19, 2024
2 parents 66606ee + 654fda8 commit 0e0a7d9
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 15 deletions.
5 changes: 5 additions & 0 deletions .rubocop_styleguide.yml
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,11 @@ Rails/OutputSafety:
Exclude:
- spec/**/*

Rails/RedundantActiveRecordAllMethod:
AllowedReceivers:
- ActionMailer::Preview
- ActiveSupport::TimeZone

Rails/SkipsModelValidations:
AllowedMethods:
- touch
Expand Down
11 changes: 0 additions & 11 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -654,17 +654,6 @@ Rails/PluckInWhere:
Exclude:
- 'app/models/spree/variant.rb'

# Offense count: 4
# This cop supports unsafe autocorrection (--autocorrect-all).
# Configuration parameters: AllowedReceivers.
# AllowedReceivers: ActionMailer::Preview, ActiveSupport::TimeZone
Rails/RedundantActiveRecordAllMethod:
Exclude:
- 'app/models/spree/tax_rate.rb'
- 'app/models/spree/user.rb'
- 'app/models/spree/variant.rb'
- 'spec/system/admin/product_import_spec.rb'

# Offense count: 1
# This cop supports unsafe autocorrection (--autocorrect-all).
Rails/RelativeDateConstant:
Expand Down
2 changes: 1 addition & 1 deletion app/models/spree/tax_rate.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def self.match(order)
return [] if order.distributor && !order.distributor.charges_sales_tax
return [] unless order.tax_zone

all.includes(zone: { zone_members: :zoneable }).load.select do |rate|
includes(zone: { zone_members: :zoneable }).load.select do |rate|
rate.potentially_applicable?(order.tax_zone)
end
end
Expand Down
2 changes: 1 addition & 1 deletion app/models/spree/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def known_users
end

def build_enterprise_roles
Enterprise.all.find_each do |enterprise|
Enterprise.find_each do |enterprise|
unless enterprise_roles.find_by enterprise_id: enterprise.id
enterprise_roles.build(enterprise:)
end
Expand Down
2 changes: 1 addition & 1 deletion app/models/spree/variant.rb
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ def set_cost_currency
end

def create_stock_items
StockLocation.all.find_each do |stock_location|
StockLocation.find_each do |stock_location|
stock_location.propagate_variant(self)
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/system/admin/product_import_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
count_on_hand: 96)
}

let(:shipping_category_id_str) { Spree::ShippingCategory.all.first.id.to_s }
let(:shipping_category_id_str) { Spree::ShippingCategory.first.id.to_s }

describe "when importing products from uploaded file" do
before do
Expand Down

0 comments on commit 0e0a7d9

Please sign in to comment.