From 07854cf372ca192da86ae105eb48533d4908d900 Mon Sep 17 00:00:00 2001 From: luisramos0 Date: Thu, 23 May 2019 22:49:30 +0100 Subject: [PATCH] Fix a few problems introduced by rubocop auto correct --- .rubocop_manual_todo.yml | 8 +++++++ .../admin/enterprises_controller.rb | 19 ++++++++++++++--- .../payment_methods_controller_decorator.rb | 16 ++++++++------ .../shipping_methods_controller_decorator.rb | 21 ++++++++++++------- .../report_service_spec.rb | 1 - lib/tasks/sample_data/product_factory.rb | 2 -- .../lib/open_food_network/reports/row_spec.rb | 5 ++++- .../open_food_network/reports/rule_spec.rb | 5 ++++- 8 files changed, 55 insertions(+), 22 deletions(-) diff --git a/.rubocop_manual_todo.yml b/.rubocop_manual_todo.yml index 7e76c6d5dd..aece394456 100644 --- a/.rubocop_manual_todo.yml +++ b/.rubocop_manual_todo.yml @@ -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 diff --git a/app/controllers/admin/enterprises_controller.rb b/app/controllers/admin/enterprises_controller.rb index 05be3d6de2..a3f524d43b 100644 --- a/app/controllers/admin/enterprises_controller.rb +++ b/app/controllers/admin/enterprises_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) diff --git a/app/controllers/spree/admin/payment_methods_controller_decorator.rb b/app/controllers/spree/admin/payment_methods_controller_decorator.rb index fee939aa66..53a1404bc9 100644 --- a/app/controllers/spree/admin/payment_methods_controller_decorator.rb +++ b/app/controllers/spree/admin/payment_methods_controller_decorator.rb @@ -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 diff --git a/app/controllers/spree/admin/shipping_methods_controller_decorator.rb b/app/controllers/spree/admin/shipping_methods_controller_decorator.rb index c4e24fb169..866d1805ba 100644 --- a/app/controllers/spree/admin/shipping_methods_controller_decorator.rb +++ b/app/controllers/spree/admin/shipping_methods_controller_decorator.rb @@ -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 diff --git a/engines/order_management/spec/services/order_management/reports/enterprise_fee_summary/report_service_spec.rb b/engines/order_management/spec/services/order_management/reports/enterprise_fee_summary/report_service_spec.rb index 72e69f4b4a..cd75340b35 100644 --- a/engines/order_management/spec/services/order_management/reports/enterprise_fee_summary/report_service_spec.rb +++ b/engines/order_management/spec/services/order_management/reports/enterprise_fee_summary/report_service_spec.rb @@ -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) diff --git a/lib/tasks/sample_data/product_factory.rb b/lib/tasks/sample_data/product_factory.rb index 117f25b2e3..09cc60d3d3 100644 --- a/lib/tasks/sample_data/product_factory.rb +++ b/lib/tasks/sample_data/product_factory.rb @@ -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]}" diff --git a/spec/lib/open_food_network/reports/row_spec.rb b/spec/lib/open_food_network/reports/row_spec.rb index cd945a97d2..c541832edf 100644 --- a/spec/lib/open_food_network/reports/row_spec.rb +++ b/spec/lib/open_food_network/reports/row_spec.rb @@ -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) diff --git a/spec/lib/open_food_network/reports/rule_spec.rb b/spec/lib/open_food_network/reports/rule_spec.rb index 94223d1891..d800f6e818 100644 --- a/spec/lib/open_food_network/reports/rule_spec.rb +++ b/spec/lib/open_food_network/reports/rule_spec.rb @@ -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)