mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Fix a few problems introduced by rubocop auto correct
This commit is contained in:
@@ -26,6 +26,7 @@ Metrics/LineLength:
|
||||
- app/controllers/admin/bulk_line_items_controller.rb
|
||||
- app/controllers/admin/contents_controller.rb
|
||||
- app/controllers/admin/customers_controller.rb
|
||||
- app/controllers/admin/enterprises_controller.rb
|
||||
- app/controllers/admin/enterprise_fees_controller.rb
|
||||
- app/controllers/admin/enterprise_groups_controller.rb
|
||||
- app/controllers/admin/enterprise_relationships_controller.rb
|
||||
@@ -391,6 +392,7 @@ Metrics/AbcSize:
|
||||
Exclude:
|
||||
- app/controllers/admin/bulk_line_items_controller.rb
|
||||
- app/controllers/admin/customers_controller.rb
|
||||
- app/controllers/admin/enterprises_controller.rb
|
||||
- app/controllers/admin/enterprise_fees_controller.rb
|
||||
- app/controllers/admin/order_cycles_controller.rb
|
||||
- app/controllers/admin/product_import_controller.rb
|
||||
@@ -411,6 +413,7 @@ Metrics/AbcSize:
|
||||
- app/controllers/spree/admin/orders_controller_decorator.rb
|
||||
- app/controllers/spree/admin/overview_controller_decorator.rb
|
||||
- app/controllers/spree/admin/payments_controller_decorator.rb
|
||||
- app/controllers/spree/admin/payment_methods_controller_decorator.rb
|
||||
- app/controllers/spree/admin/products_controller_decorator.rb
|
||||
- app/controllers/spree/admin/reports_controller_decorator.rb
|
||||
- app/controllers/spree/admin/search_controller_decorator.rb
|
||||
@@ -494,6 +497,7 @@ Metrics/AbcSize:
|
||||
Metrics/CyclomaticComplexity:
|
||||
Max: 6
|
||||
Exclude:
|
||||
- app/controllers/admin/enterprises_controller.rb
|
||||
- app/controllers/admin/enterprise_fees_controller.rb
|
||||
- app/controllers/checkout_controller.rb
|
||||
- app/controllers/spree/admin/payments_controller_decorator.rb
|
||||
@@ -524,6 +528,7 @@ Metrics/CyclomaticComplexity:
|
||||
Metrics/PerceivedComplexity:
|
||||
Max: 7
|
||||
Exclude:
|
||||
- app/controllers/admin/enterprises_controller.rb
|
||||
- app/controllers/checkout_controller.rb
|
||||
- app/controllers/spree/admin/payments_controller_decorator.rb
|
||||
- app/controllers/spree/orders_controller_decorator.rb
|
||||
@@ -551,6 +556,7 @@ Metrics/MethodLength:
|
||||
Max: 10
|
||||
Exclude:
|
||||
- app/controllers/admin/customers_controller.rb
|
||||
- app/controllers/admin/enterprises_controller.rb
|
||||
- app/controllers/admin/enterprise_fees_controller.rb
|
||||
- app/controllers/admin/manager_invitations_controller.rb
|
||||
- app/controllers/admin/order_cycles_controller.rb
|
||||
@@ -562,6 +568,7 @@ Metrics/MethodLength:
|
||||
- app/controllers/shop_controller.rb
|
||||
- app/controllers/spree/admin/orders/customer_details_controller_decorator.rb
|
||||
- app/controllers/spree/admin/payments_controller_decorator.rb
|
||||
- app/controllers/spree/admin/payment_methods_controller_decorator.rb
|
||||
- app/controllers/spree/admin/products_controller_decorator.rb
|
||||
- app/controllers/spree/admin/reports_controller_decorator.rb
|
||||
- app/controllers/spree/admin/search_controller_decorator.rb
|
||||
@@ -636,6 +643,7 @@ Metrics/MethodLength:
|
||||
Metrics/ClassLength:
|
||||
Max: 100
|
||||
Exclude:
|
||||
- app/controllers/admin/enterprises_controller.rb
|
||||
- app/controllers/admin/order_cycles_controller.rb
|
||||
- app/controllers/admin/subscriptions_controller.rb
|
||||
- app/controllers/checkout_controller.rb
|
||||
|
||||
@@ -168,9 +168,20 @@ module Admin
|
||||
end
|
||||
|
||||
def load_methods_and_fees
|
||||
@payment_methods = Spree::PaymentMethod.managed_by(spree_current_user).sort_by!{ |pm| [@enterprise.payment_methods.include? pm ? 0 : 1, pm.name] }
|
||||
@shipping_methods = Spree::ShippingMethod.managed_by(spree_current_user).sort_by!{ |sm| [@enterprise.shipping_methods.include? sm ? 0 : 1, sm.name] }
|
||||
@enterprise_fees = EnterpriseFee.managed_by(spree_current_user).for_enterprise(@enterprise).order(:fee_type, :name).all
|
||||
# rubocop:disable Style/TernaryParentheses
|
||||
@payment_methods = Spree::PaymentMethod.managed_by(spree_current_user).sort_by! do |pm|
|
||||
[(@enterprise.payment_methods.include? pm) ? 0 : 1, pm.name]
|
||||
end
|
||||
@shipping_methods = Spree::ShippingMethod.managed_by(spree_current_user).sort_by! do |sm|
|
||||
[(@enterprise.shipping_methods.include? sm) ? 0 : 1, sm.name]
|
||||
end
|
||||
# rubocop:enable Style/TernaryParentheses
|
||||
|
||||
@enterprise_fees = EnterpriseFee
|
||||
.managed_by(spree_current_user)
|
||||
.for_enterprise(@enterprise)
|
||||
.order(:fee_type, :name)
|
||||
.all
|
||||
end
|
||||
|
||||
def load_groups
|
||||
@@ -274,7 +285,9 @@ module Admin
|
||||
# Overriding method on Spree's resource controller
|
||||
def location_after_save
|
||||
referer_path = OpenFoodNetwork::RefererParser.path(request.referer)
|
||||
# rubocop:disable Style/RegexpLiteral
|
||||
refered_from_producer_properties = referer_path =~ /\/producer_properties$/
|
||||
# rubocop:enable Style/RegexpLiteral
|
||||
|
||||
if refered_from_producer_properties
|
||||
main_app.admin_enterprise_producer_properties_path(@enterprise)
|
||||
|
||||
@@ -53,17 +53,21 @@ module Spree
|
||||
end
|
||||
|
||||
def load_data
|
||||
if spree_current_user.admin? || Rails.env.test?
|
||||
@providers = Gateway.providers.sort{ |p1, p2| p1.name <=> p2.name }
|
||||
else
|
||||
@providers = Gateway.providers.reject{ |p| p.name.include? "Bogus" }.sort{ |p1, p2| p1.name <=> p2.name }
|
||||
end
|
||||
@providers = if spree_current_user.admin? || Rails.env.test?
|
||||
Gateway.providers.sort_by(&:name)
|
||||
else
|
||||
Gateway.providers.reject{ |p| p.name.include? "Bogus" }.sort_by(&:name)
|
||||
end
|
||||
@providers.reject!{ |p| p.name.ends_with? "StripeConnect" } unless show_stripe?
|
||||
@calculators = PaymentMethod.calculators.sort_by(&:name)
|
||||
end
|
||||
|
||||
def load_hubs
|
||||
@hubs = Enterprise.managed_by(spree_current_user).is_distributor.sort_by!{ |d| [@payment_method.has_distributor? d ? 0 : 1, d.name] }
|
||||
# rubocop:disable Style/TernaryParentheses
|
||||
@hubs = Enterprise.managed_by(spree_current_user).is_distributor.sort_by! do |d|
|
||||
[(@payment_method.has_distributor? d) ? 0 : 1, d.name]
|
||||
end
|
||||
# rubocop:enable Style/TernaryParentheses
|
||||
end
|
||||
|
||||
# Show Stripe as an option if enabled, or if the
|
||||
|
||||
@@ -17,20 +17,25 @@ module Spree
|
||||
collection
|
||||
end
|
||||
|
||||
# Spree allows soft deletes of shipping_methods but our reports are not adapted to that.
|
||||
# So, this method prevents the deletion (even soft) of shipping_methods that are referenced in orders.
|
||||
# Spree allows soft deletes of shipping_methods but our reports are not adapted to that
|
||||
# Here we prevent the deletion (even soft) of shipping_methods that are referenced in orders
|
||||
def do_not_destroy_referenced_shipping_methods
|
||||
order = Order.joins(shipments: :shipping_rates).where( spree_shipping_rates: { shipping_method_id: @object } ).first
|
||||
if order
|
||||
flash[:error] = I18n.t(:shipping_method_destroy_error, number: order.number)
|
||||
redirect_to(collection_url) && (return)
|
||||
end
|
||||
order = Order.joins(shipments: :shipping_rates)
|
||||
.where( spree_shipping_rates: { shipping_method_id: @object } )
|
||||
.first
|
||||
return unless order
|
||||
flash[:error] = I18n.t(:shipping_method_destroy_error, number: order.number)
|
||||
redirect_to(collection_url) && return
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def load_hubs
|
||||
@hubs = Enterprise.managed_by(spree_current_user).is_distributor.sort_by!{ |d| [@shipping_method.has_distributor? d ? 0 : 1, d.name] }
|
||||
# rubocop:disable Style/TernaryParentheses
|
||||
@hubs = Enterprise.managed_by(spree_current_user).is_distributor.sort_by! do |d|
|
||||
[(@shipping_method.has_distributor? d) ? 0 : 1, d.name]
|
||||
end
|
||||
# rubocop:enable Style/TernaryParentheses
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -319,7 +319,6 @@ describe OrderManagement::Reports::EnterpriseFeeSummary::ReportService do
|
||||
amount: 25)
|
||||
end
|
||||
let!(:distributor_fee) do
|
||||
tax_category = create(:tax_category, name: "Distributor Tax A")
|
||||
create(:enterprise_fee, :flat_rate, name: "Distributor Fee A", enterprise: distributor,
|
||||
fee_type: "admin", inherits_tax_category: false,
|
||||
amount: 30)
|
||||
|
||||
@@ -12,7 +12,6 @@ class ProductFactory
|
||||
|
||||
private
|
||||
|
||||
# rubocop:disable Metrics/MethodLength, Metrics/AbcSize
|
||||
def product_data(enterprises)
|
||||
vegetables = Spree::Taxon.find_by_name('Vegetables')
|
||||
fruit = Spree::Taxon.find_by_name('Fruit')
|
||||
@@ -64,7 +63,6 @@ class ProductFactory
|
||||
}
|
||||
]
|
||||
end
|
||||
# rubocop:enable Metrics/MethodLength, Metrics/AbcSize
|
||||
|
||||
def create_product(hash)
|
||||
log "- #{hash[:name]}"
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
require 'spec_helper'
|
||||
require 'open_food_network/reports/row'
|
||||
|
||||
module OpenFoodNetwork::Reports
|
||||
describe Row do
|
||||
let(:row) { Row.new }
|
||||
let(:proc) { proc {} }
|
||||
# rubocop:disable Style/Proc
|
||||
let(:proc) { Proc.new {} }
|
||||
# rubocop:enable Style/Proc
|
||||
|
||||
it "can define a number of columns and return them as an array" do
|
||||
row.column(&proc)
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
require 'spec_helper'
|
||||
require 'open_food_network/reports/rule'
|
||||
|
||||
module OpenFoodNetwork::Reports
|
||||
describe Rule do
|
||||
let(:rule) { Rule.new }
|
||||
let(:proc) { proc {} }
|
||||
# rubocop:disable Style/Proc
|
||||
let(:proc) { Proc.new {} }
|
||||
# rubocop:enable Style/Proc
|
||||
|
||||
it "can define a group proc and return it in a hash" do
|
||||
rule.group(&proc)
|
||||
|
||||
Reference in New Issue
Block a user