diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 2dbf889ef4..61b2cbfef9 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -14,10 +14,6 @@ Bundler/OrderedGems: Exclude: - 'Gemfile' -# Offense count: 48 -Lint/AmbiguousOperator: - Enabled: false - # Offense count: 8 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyleAlignWith, SupportedStylesAlignWith. diff --git a/app/models/model_set.rb b/app/models/model_set.rb index 0c0d156179..cb75f929ab 100644 --- a/app/models/model_set.rb +++ b/app/models/model_set.rb @@ -36,8 +36,8 @@ class ModelSet end def save - collection_to_delete.each &:destroy - collection_to_keep.all? &:save + collection_to_delete.each(&:destroy) + collection_to_keep.all?(&:save) end def collection_to_delete diff --git a/app/models/spree/option_type_decorator.rb b/app/models/spree/option_type_decorator.rb index aea706c847..e3ca3b30de 100644 --- a/app/models/spree/option_type_decorator.rb +++ b/app/models/spree/option_type_decorator.rb @@ -7,7 +7,7 @@ module Spree private def refresh_products_cache - products(:reload).each &:refresh_products_cache + products(:reload).each(&:refresh_products_cache) end end end diff --git a/app/models/spree/option_value_decorator.rb b/app/models/spree/option_value_decorator.rb index cfe9c23cca..5420af811c 100644 --- a/app/models/spree/option_value_decorator.rb +++ b/app/models/spree/option_value_decorator.rb @@ -7,13 +7,13 @@ module Spree private def refresh_products_cache - variants(:reload).each &:refresh_products_cache + variants(:reload).each(&:refresh_products_cache) end def refresh_products_cache_from_destroy vs = variants(:reload).to_a yield - vs.each &:refresh_products_cache + vs.each(&:refresh_products_cache) end end diff --git a/app/models/spree/order_decorator.rb b/app/models/spree/order_decorator.rb index 82bba48f2e..41a70383bc 100644 --- a/app/models/spree/order_decorator.rb +++ b/app/models/spree/order_decorator.rb @@ -161,7 +161,7 @@ Spree::Order.class_eval do end def cap_quantity_at_stock! - line_items.each &:cap_quantity_at_stock! + line_items.each(&:cap_quantity_at_stock!) end def set_distributor!(distributor) diff --git a/app/models/spree/product_decorator.rb b/app/models/spree/product_decorator.rb index 724101964b..3173304f41 100644 --- a/app/models/spree/product_decorator.rb +++ b/app/models/spree/product_decorator.rb @@ -216,7 +216,7 @@ Spree::Product.class_eval do if variant_unit_changed? option_types.delete self.class.all_variant_unit_option_types option_types << variant_unit_option_type if variant_unit.present? - variants_including_master.each &:update_units + variants_including_master.each(&:update_units) end end diff --git a/app/models/spree/product_option_type_decorator.rb b/app/models/spree/product_option_type_decorator.rb index e091b62efa..6410c014a4 100644 --- a/app/models/spree/product_option_type_decorator.rb +++ b/app/models/spree/product_option_type_decorator.rb @@ -4,7 +4,7 @@ Spree::ProductOptionType.class_eval do def remove_option_values self.product.variants_including_master.each do |variant| option_values = variant.option_values.where(option_type_id: self.option_type) - variant.option_values.destroy *option_values + variant.option_values.destroy(*option_values) end end end diff --git a/app/models/spree/property_decorator.rb b/app/models/spree/property_decorator.rb index 81577cef4e..7349436a2b 100644 --- a/app/models/spree/property_decorator.rb +++ b/app/models/spree/property_decorator.rb @@ -30,7 +30,7 @@ module Spree private def refresh_products_cache - product_properties(:reload).each &:refresh_products_cache + product_properties(:reload).each(&:refresh_products_cache) end end end diff --git a/app/models/spree/taxon_decorator.rb b/app/models/spree/taxon_decorator.rb index fcc71a92dc..71da03ccbf 100644 --- a/app/models/spree/taxon_decorator.rb +++ b/app/models/spree/taxon_decorator.rb @@ -57,6 +57,6 @@ Spree::Taxon.class_eval do private def refresh_products_cache - products(:reload).each &:refresh_products_cache + products(:reload).each(&:refresh_products_cache) end end diff --git a/lib/open_food_network/order_cycle_form_applicator.rb b/lib/open_food_network/order_cycle_form_applicator.rb index 1df429b4fb..2573d52aa6 100644 --- a/lib/open_food_network/order_cycle_form_applicator.rb +++ b/lib/open_food_network/order_cycle_form_applicator.rb @@ -172,7 +172,7 @@ module OpenFoodNetwork end def incoming_variant_ids - @order_cycle.supplied_variants.map &:id + @order_cycle.supplied_variants.map(&:id) end def variants_to_a(variants) diff --git a/lib/open_food_network/reports/bulk_coop_allocation_report.rb b/lib/open_food_network/reports/bulk_coop_allocation_report.rb index 11fb3070f8..2b5454ef75 100644 --- a/lib/open_food_network/reports/bulk_coop_allocation_report.rb +++ b/lib/open_food_network/reports/bulk_coop_allocation_report.rb @@ -6,7 +6,7 @@ module OpenFoodNetwork::Reports organise do group { |li| li.product } - sort &:name + sort(&:name) summary_row do column { |lis| "TOTAL" } diff --git a/lib/open_food_network/reports/bulk_coop_supplier_report.rb b/lib/open_food_network/reports/bulk_coop_supplier_report.rb index b37e8d00a5..ce789630a6 100644 --- a/lib/open_food_network/reports/bulk_coop_supplier_report.rb +++ b/lib/open_food_network/reports/bulk_coop_supplier_report.rb @@ -6,11 +6,11 @@ module OpenFoodNetwork::Reports organise do group { |li| li.product.supplier } - sort &:name + sort(&:name) organise do group { |li| li.product } - sort &:name + sort(&:name) summary_row do column { |lis| supplier_name(lis) } diff --git a/lib/open_food_network/reports/report.rb b/lib/open_food_network/reports/report.rb index 461c350e73..2bf0a48fbb 100644 --- a/lib/open_food_network/reports/report.rb +++ b/lib/open_food_network/reports/report.rb @@ -24,7 +24,7 @@ module OpenFoodNetwork::Reports rule = rule.next end - rules.map &:to_h + rules.map(&:to_h) end # -- DSL diff --git a/lib/open_food_network/sales_tax_report.rb b/lib/open_food_network/sales_tax_report.rb index 442286a61a..2d85411fa1 100644 --- a/lib/open_food_network/sales_tax_report.rb +++ b/lib/open_food_network/sales_tax_report.rb @@ -97,7 +97,7 @@ module OpenFoodNetwork end def tax_included_in(line_item) - line_item.adjustments.sum &:included_tax + line_item.adjustments.sum(&:included_tax) end def shipment_inc_vat diff --git a/lib/open_food_network/user_balance_calculator.rb b/lib/open_food_network/user_balance_calculator.rb index 32cd00c90c..ba9d089452 100644 --- a/lib/open_food_network/user_balance_calculator.rb +++ b/lib/open_food_network/user_balance_calculator.rb @@ -12,11 +12,11 @@ module OpenFoodNetwork private def completed_order_total - completed_orders.sum &:total + completed_orders.sum(&:total) end def payment_total - payments.sum &:amount + payments.sum(&:amount) end def completed_orders diff --git a/lib/open_food_network/variant_and_line_item_naming.rb b/lib/open_food_network/variant_and_line_item_naming.rb index 47b9f58936..42c78a80dc 100644 --- a/lib/open_food_network/variant_and_line_item_naming.rb +++ b/lib/open_food_network/variant_and_line_item_naming.rb @@ -11,7 +11,7 @@ module OpenFoodNetwork def options_text values = self.option_values.joins(:option_type).order("#{Spree::OptionType.table_name}.position asc") - values.map! &:presentation # This line changed + values.map!(&:presentation) # This line changed values.to_sentence({ :words_connector => ", ", :two_words_connector => ", " }) end diff --git a/lib/open_food_network/xero_invoices_report.rb b/lib/open_food_network/xero_invoices_report.rb index cab44aa55e..2614f61dfb 100644 --- a/lib/open_food_network/xero_invoices_report.rb +++ b/lib/open_food_network/xero_invoices_report.rb @@ -175,27 +175,27 @@ module OpenFoodNetwork end def total_untaxable_products(order) - order.line_items.without_tax.sum &:amount + order.line_items.without_tax.sum(&:amount) end def total_taxable_products(order) - order.line_items.with_tax.sum &:amount + order.line_items.with_tax.sum(&:amount) end def total_untaxable_fees(order) - order.adjustments.enterprise_fee.without_tax.sum &:amount + order.adjustments.enterprise_fee.without_tax.sum(&:amount) end def total_taxable_fees(order) - order.adjustments.enterprise_fee.with_tax.sum &:amount + order.adjustments.enterprise_fee.with_tax.sum(&:amount) end def total_shipping(order) - order.adjustments.shipping.sum &:amount + order.adjustments.shipping.sum(&:amount) end def total_transaction(order) - order.adjustments.payment_fee.sum &:amount + order.adjustments.payment_fee.sum(&:amount) end def tax_on_shipping_s(order) @@ -204,11 +204,11 @@ module OpenFoodNetwork end def total_untaxable_admin_adjustments(order) - order.adjustments.admin.without_tax.sum &:amount + order.adjustments.admin.without_tax.sum(&:amount) end def total_taxable_admin_adjustments(order) - order.adjustments.admin.with_tax.sum &:amount + order.adjustments.admin.with_tax.sum(&:amount) end def detail? diff --git a/spec/features/admin/order_cycles_spec.rb b/spec/features/admin/order_cycles_spec.rb index 2f826b51c4..d59b203ce6 100644 --- a/spec/features/admin/order_cycles_spec.rb +++ b/spec/features/admin/order_cycles_spec.rb @@ -181,7 +181,7 @@ feature %q{ scenario "updating an order cycle", js: true do # Given an order cycle with all the settings oc = create(:order_cycle) - initial_variants = oc.variants.sort_by &:id + initial_variants = oc.variants.sort_by(&:id) # And a coordinating, supplying and distributing enterprise with some products with variants coordinator = oc.coordinator diff --git a/spec/jobs/update_account_invoices_spec.rb b/spec/jobs/update_account_invoices_spec.rb index ad1a466d49..d9a2beca6b 100644 --- a/spec/jobs/update_account_invoices_spec.rb +++ b/spec/jobs/update_account_invoices_spec.rb @@ -106,7 +106,7 @@ describe UpdateAccountInvoices do end context "that starts in the future" do - travel_to -1.days + travel_to(-1.days) it "snags an error and does not update invoices" do updater.perform diff --git a/spec/lib/open_food_network/reports/report_spec.rb b/spec/lib/open_food_network/reports/report_spec.rb index 0421320119..2f06e3782e 100644 --- a/spec/lib/open_food_network/reports/report_spec.rb +++ b/spec/lib/open_food_network/reports/report_spec.rb @@ -10,23 +10,23 @@ module OpenFoodNetwork::Reports header 'One', 'Two', 'Three', 'Four' columns do - column &P1 - column &P2 - column &P3 - column &P4 + column(&P1) + column(&P2) + column(&P3) + column(&P4) end organise do - group &P1 - sort &P2 + group(&P1) + sort(&P2) organise do - group &P3 - sort &P4 + group(&P3) + sort(&P4) summary_row do - column &P1 - column &P4 + column(&P1) + column(&P4) end end end diff --git a/spec/lib/open_food_network/reports/row_spec.rb b/spec/lib/open_food_network/reports/row_spec.rb index deaa84e491..8643399a69 100644 --- a/spec/lib/open_food_network/reports/row_spec.rb +++ b/spec/lib/open_food_network/reports/row_spec.rb @@ -6,9 +6,9 @@ module OpenFoodNetwork::Reports let(:proc) { Proc.new {} } it "can define a number of columns and return them as an array" do - row.column &proc - row.column &proc - row.column &proc + row.column(&proc) + row.column(&proc) + row.column(&proc) row.to_a.should == [proc, proc, proc] end diff --git a/spec/lib/open_food_network/reports/rule_spec.rb b/spec/lib/open_food_network/reports/rule_spec.rb index 0e7a1d979b..99953f8391 100644 --- a/spec/lib/open_food_network/reports/rule_spec.rb +++ b/spec/lib/open_food_network/reports/rule_spec.rb @@ -6,17 +6,17 @@ module OpenFoodNetwork::Reports let(:proc) { Proc.new {} } it "can define a group proc and return it in a hash" do - rule.group &proc + rule.group(&proc) rule.to_h.should == {group_by: proc, sort_by: nil} end it "can define a sort proc and return it in a hash" do - rule.sort &proc + rule.sort(&proc) rule.to_h.should == {group_by: nil, sort_by: proc} end it "can define a nested rule" do - rule.organise &proc + rule.organise(&proc) rule.next.should be_a Rule end diff --git a/spec/models/tag_rule/discount_order_spec.rb b/spec/models/tag_rule/discount_order_spec.rb index 93723ad84a..07264cca8f 100644 --- a/spec/models/tag_rule/discount_order_spec.rb +++ b/spec/models/tag_rule/discount_order_spec.rb @@ -65,9 +65,9 @@ describe TagRule::DiscountOrder, type: :model do it "creates a new adjustment on the order" do tag_rule.send(:apply!) expect(adjustment).to be_a Spree::Adjustment - expect(adjustment.amount).to eq -10.00 + expect(adjustment.amount).to eq(-10.00) expect(adjustment.label).to eq "Discount" - expect(order.adjustment_total).to eq -10.00 + expect(order.adjustment_total).to eq(-10.00) expect(order.total).to eq 90.00 end end @@ -83,7 +83,7 @@ describe TagRule::DiscountOrder, type: :model do it "the adjustment is made on line item total, ie. ignores the shipping amount" do tag_rule.send(:apply!) expect(adjustment).to be_a Spree::Adjustment - expect(adjustment.amount).to eq -10.00 + expect(adjustment.amount).to eq(-10.00) expect(adjustment.label).to eq "Discount" expect(order.adjustment_total).to eq 15.00 expect(order.total).to eq 115.00