From cee24dcca7da79160592cb1dff2e3c5bba92a4bb Mon Sep 17 00:00:00 2001 From: Pau Perez Date: Tue, 11 Jul 2017 10:10:07 +0200 Subject: [PATCH] Use indented style for multiline method calls This enables the Rubocop's Style/MultilineMethodCallIndentation cop with indentend enforced style. Which makes you split multiline method calls like: orders = Spree::Order .an_scope .another_scope .where(id: list_of_ids) It also autofixes the current violations and updates the rubocop_todo.yml --- .rubocop.yml | 5 + .rubocop_todo.yml | 115 ++++++++++-------- .../admin/order_cycles_controller.rb | 4 +- .../api/order_cycles_controller.rb | 4 +- app/controllers/base_controller.rb | 2 +- app/controllers/checkout_controller.rb | 2 +- .../admin/orders_controller_decorator.rb | 6 +- .../admin/reports_controller_decorator.rb | 2 +- .../admin/search_controller_decorator.rb | 2 +- .../spree/orders_controller_decorator.rb | 2 +- app/jobs/update_billable_periods.rb | 4 +- app/models/enterprise.rb | 22 ++-- app/models/enterprise_relationship.rb | 2 +- app/models/exchange.rb | 10 +- app/models/order_cycle.rb | 32 ++--- .../spree/calculator/default_tax_decorator.rb | 6 +- app/models/spree/line_item_decorator.rb | 16 +-- app/models/spree/order_decorator.rb | 8 +- app/models/spree/payment_method_decorator.rb | 10 +- app/models/spree/product_decorator.rb | 34 +++--- app/models/spree/shipping_method_decorator.rb | 18 +-- app/models/spree/taxon_decorator.rb | 6 +- app/models/spree/user_decorator.rb | 4 +- app/models/spree/variant_decorator.rb | 8 +- .../api/admin/exchange_serializer.rb | 4 +- lib/open_food_network/lettuce_share_report.rb | 2 +- .../order_cycle_form_applicator.rb | 2 +- .../order_cycle_permissions.rb | 4 +- lib/open_food_network/permissions.rb | 14 +-- lib/open_food_network/products_cache.rb | 4 +- lib/open_food_network/xero_invoices_report.rb | 10 +- spec/helpers/order_cycles_helper_spec.rb | 10 +- spec/jobs/update_account_invoices_spec.rb | 10 +- spec/jobs/update_billable_periods_spec.rb | 56 ++++----- .../enterprise_fee_calculator_spec.rb | 12 +- 35 files changed, 236 insertions(+), 216 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index d5c6c7800e..897bd34de4 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -11,6 +11,7 @@ AllCops: - 'db/**/*' - 'config/**/*' - 'script/**/*' + - 'vendor/**/*' - !ruby/regexp /old_and_unused\.rb$/ # OFN SETTINGS @@ -25,6 +26,10 @@ Style/Documentation: Style/StringLiterals: Enabled: false +Layout/MultilineMethodCallIndentation: + Enabled: true + EnforcedStyle: indented + # TEMPORARY/CONTESTED SETTINGS # These are still to be decided upon, but recommended for inclusion by # oeoeaio after scrutinising offenses the codebase diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index aaef41b82d..ee8e61e8a2 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,6 +1,6 @@ # This configuration was generated by # `rubocop --auto-gen-config --exclude-limit 100` -# on 2017-06-29 08:50:47 +1000 using RuboCop version 0.49.1. +# on 2017-07-12 10:36:44 +0200 using RuboCop version 0.49.1. # The point is for the user to remove these configuration records # one by one as the offenses are removed from the code base. # Note that changes in the inspected code, or installation of new @@ -526,54 +526,6 @@ Layout/MultilineMethodCallBraceLayout: - 'lib/open_food_network/products_renderer.rb' - 'spec/lib/open_food_network/products_and_inventory_report_spec.rb' -# Offense count: 191 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, SupportedStyles, IndentationWidth. -# SupportedStyles: aligned, indented, indented_relative_to_receiver -Layout/MultilineMethodCallIndentation: - Exclude: - - 'app/controllers/admin/order_cycles_controller.rb' - - 'app/controllers/admin/variant_overrides_controller.rb' - - 'app/controllers/api/order_cycles_controller.rb' - - 'app/controllers/base_controller.rb' - - 'app/controllers/checkout_controller.rb' - - 'app/controllers/spree/admin/orders_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' - - 'app/controllers/spree/api/products_controller_decorator.rb' - - 'app/controllers/spree/orders_controller_decorator.rb' - - 'app/jobs/update_billable_periods.rb' - - 'app/models/column_preference.rb' - - 'app/models/enterprise.rb' - - 'app/models/enterprise_relationship.rb' - - 'app/models/exchange.rb' - - 'app/models/order_cycle.rb' - - 'app/models/product_importer.rb' - - 'app/models/spree/ability_decorator.rb' - - 'app/models/spree/calculator/default_tax_decorator.rb' - - 'app/models/spree/line_item_decorator.rb' - - 'app/models/spree/order_decorator.rb' - - 'app/models/spree/payment_method_decorator.rb' - - 'app/models/spree/product_decorator.rb' - - 'app/models/spree/shipping_method_decorator.rb' - - 'app/models/spree/taxon_decorator.rb' - - 'app/models/spree/user_decorator.rb' - - 'app/models/spree/variant_decorator.rb' - - 'app/serializers/api/admin/exchange_serializer.rb' - - 'lib/open_food_network/lettuce_share_report.rb' - - 'lib/open_food_network/order_cycle_form_applicator.rb' - - 'lib/open_food_network/order_cycle_permissions.rb' - - 'lib/open_food_network/permissions.rb' - - 'lib/open_food_network/products_cache.rb' - - 'spec/controllers/spree/admin/reports_controller_spec.rb' - - 'spec/helpers/order_cycles_helper_spec.rb' - - 'spec/jobs/update_account_invoices_spec.rb' - - 'spec/jobs/update_billable_periods_spec.rb' - - 'spec/lib/open_food_network/enterprise_fee_calculator_spec.rb' - - 'spec/mailers/producer_mailer_spec.rb' - - 'spec/support/matchers/table_matchers.rb' - # Offense count: 34 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyle, SupportedStyles, IndentationWidth. @@ -1064,7 +1016,70 @@ Lint/UselessAccessModifier: Lint/Void: Exclude: - 'app/serializers/api/enterprise_serializer.rb' - - 'spec/**/*' + - 'spec/archive/features/consumer/checkout_spec.rb' + - 'spec/controllers/api/order_cycles_controller_spec.rb' + - 'spec/controllers/base_controller_spec.rb' + - 'spec/controllers/cart_controller_spec.rb' + - 'spec/controllers/checkout_controller_spec.rb' + - 'spec/controllers/enterprises_controller_spec.rb' + - 'spec/controllers/shop_controller_spec.rb' + - 'spec/controllers/spree/admin/adjustments_controller_spec.rb' + - 'spec/controllers/spree/admin/line_items_controller_spec.rb' + - 'spec/controllers/spree/admin/orders_controller_spec.rb' + - 'spec/controllers/spree/admin/variants_controller_spec.rb' + - 'spec/controllers/spree/api/products_controller_spec.rb' + - 'spec/controllers/spree/api/variants_controller_spec.rb' + - 'spec/controllers/spree/checkout_controller_spec.rb' + - 'spec/controllers/spree/orders_controller_spec.rb' + - 'spec/controllers/user_passwords_controller_spec.rb' + - 'spec/controllers/user_registrations_controller_spec.rb' + - 'spec/features/admin/enterprise_fees_spec.rb' + - 'spec/features/admin/enterprise_groups_spec.rb' + - 'spec/features/admin/enterprise_user_spec.rb' + - 'spec/features/admin/enterprises/index_spec.rb' + - 'spec/features/admin/enterprises_spec.rb' + - 'spec/features/admin/order_cycles_spec.rb' + - 'spec/features/admin/orders_spec.rb' + - 'spec/features/admin/payment_method_spec.rb' + - 'spec/features/admin/product_import_spec.rb' + - 'spec/features/admin/products_spec.rb' + - 'spec/features/admin/reports_spec.rb' + - 'spec/features/admin/shipping_methods_spec.rb' + - 'spec/features/admin/variant_overrides_spec.rb' + - 'spec/features/admin/variants_spec.rb' + - 'spec/features/consumer/shopping/checkout_spec.rb' + - 'spec/features/consumer/shopping/shopping_spec.rb' + - 'spec/features/consumer/shopping/variant_overrides_spec.rb' + - 'spec/helpers/html_helper_spec.rb' + - 'spec/helpers/products_helper_spec.rb' + - 'spec/lib/open_food_network/bulk_coop_report_spec.rb' + - 'spec/lib/open_food_network/enterprise_fee_applicator_spec.rb' + - 'spec/lib/open_food_network/enterprise_fee_calculator_spec.rb' + - 'spec/lib/open_food_network/enterprise_issue_validator_spec.rb' + - 'spec/lib/open_food_network/group_buy_report_spec.rb' + - 'spec/lib/open_food_network/orders_and_fulfillments_report_spec.rb' + - 'spec/lib/open_food_network/packing_report_spec.rb' + - 'spec/lib/open_food_network/reports/report_spec.rb' + - 'spec/lib/open_food_network/reports/rule_spec.rb' + - 'spec/mailers/enterprise_mailer_spec.rb' + - 'spec/mailers/order_mailer_spec.rb' + - 'spec/models/cart_spec.rb' + - 'spec/models/enterprise_relationship_spec.rb' + - 'spec/models/enterprise_spec.rb' + - 'spec/models/exchange_spec.rb' + - 'spec/models/order_cycle_spec.rb' + - 'spec/models/product_distribution_spec.rb' + - 'spec/models/spree/adjustment_spec.rb' + - 'spec/models/spree/line_item_spec.rb' + - 'spec/models/spree/order_populator_spec.rb' + - 'spec/models/spree/order_spec.rb' + - 'spec/models/spree/payment_method_spec.rb' + - 'spec/models/spree/payment_spec.rb' + - 'spec/models/spree/product_spec.rb' + - 'spec/models/spree/variant_spec.rb' + - 'spec/models/variant_override_spec.rb' + - 'spec/serializers/enterprise_serializer_spec.rb' + - 'spec/support/request/web_helper.rb' # Offense count: 706 # Configuration parameters: CountComments, ExcludedMethods. diff --git a/app/controllers/admin/order_cycles_controller.rb b/app/controllers/admin/order_cycles_controller.rb index 5646099cd5..5a70891376 100644 --- a/app/controllers/admin/order_cycles_controller.rb +++ b/app/controllers/admin/order_cycles_controller.rb @@ -100,10 +100,10 @@ module Admin def collection ocs = if params[:as] == "distributor" OrderCycle.ransack(params[:q]).result. - involving_managed_distributors_of(spree_current_user).order('updated_at DESC') + involving_managed_distributors_of(spree_current_user).order('updated_at DESC') elsif params[:as] == "producer" OrderCycle.ransack(params[:q]).result. - involving_managed_producers_of(spree_current_user).order('updated_at DESC') + involving_managed_producers_of(spree_current_user).order('updated_at DESC') else OrderCycle.ransack(params[:q]).result.accessible_by(spree_current_user) end diff --git a/app/controllers/api/order_cycles_controller.rb b/app/controllers/api/order_cycles_controller.rb index 23b333625e..dd62c7f4d0 100644 --- a/app/controllers/api/order_cycles_controller.rb +++ b/app/controllers/api/order_cycles_controller.rb @@ -11,10 +11,10 @@ module Api def accessible @order_cycles = if params[:as] == "distributor" OrderCycle.ransack(params[:q]).result. - involving_managed_distributors_of(current_api_user).order('updated_at DESC') + involving_managed_distributors_of(current_api_user).order('updated_at DESC') elsif params[:as] == "producer" OrderCycle.ransack(params[:q]).result. - involving_managed_producers_of(current_api_user).order('updated_at DESC') + involving_managed_producers_of(current_api_user).order('updated_at DESC') else OrderCycle.ransack(params[:q]).result.accessible_by(current_api_user) end diff --git a/app/controllers/base_controller.rb b/app/controllers/base_controller.rb index 7f9a0f2df6..0d385fd2a4 100644 --- a/app/controllers/base_controller.rb +++ b/app/controllers/base_controller.rb @@ -29,7 +29,7 @@ class BaseController < ApplicationController end @order_cycles = OrderCycle.with_distributor(@distributor).active - .order(@distributor.preferred_shopfront_order_cycle_order) + .order(@distributor.preferred_shopfront_order_cycle_order) applicator = OpenFoodNetwork::TagRuleApplicator.new(@distributor, "FilterOrderCycles", current_customer.andand.tag_list) applicator.filter!(@order_cycles) diff --git a/app/controllers/checkout_controller.rb b/app/controllers/checkout_controller.rb index 37c8bca206..58c0c62eac 100644 --- a/app/controllers/checkout_controller.rb +++ b/app/controllers/checkout_controller.rb @@ -88,7 +88,7 @@ class CheckoutController < Spree::CheckoutController def check_order_for_phantom_fees phantom_fees = @order.adjustments.joins('LEFT OUTER JOIN spree_line_items ON spree_line_items.id = spree_adjustments.source_id'). - where("originator_type = 'EnterpriseFee' AND source_type = 'Spree::LineItem' AND spree_line_items.id IS NULL") + where("originator_type = 'EnterpriseFee' AND source_type = 'Spree::LineItem' AND spree_line_items.id IS NULL") if phantom_fees.any? Bugsnag.notify(RuntimeError.new("Phantom Fees"), { diff --git a/app/controllers/spree/admin/orders_controller_decorator.rb b/app/controllers/spree/admin/orders_controller_decorator.rb index b9798c8ca1..443eda0538 100644 --- a/app/controllers/spree/admin/orders_controller_decorator.rb +++ b/app/controllers/spree/admin/orders_controller_decorator.rb @@ -112,9 +112,9 @@ Spree::Admin::OrdersController.class_eval do # Replaced this search to filter orders to only show those distributed by current user (or all for admin user) @search.result.includes([:user, :shipments, :payments]). - distributed_by_user(spree_current_user). - page(params[:page]). - per(params[:per_page] || Spree::Config[:orders_per_page]) + distributed_by_user(spree_current_user). + page(params[:page]). + per(params[:per_page] || Spree::Config[:orders_per_page]) end end diff --git a/app/controllers/spree/admin/reports_controller_decorator.rb b/app/controllers/spree/admin/reports_controller_decorator.rb index 88f28bb9ee..21cabcd936 100644 --- a/app/controllers/spree/admin/reports_controller_decorator.rb +++ b/app/controllers/spree/admin/reports_controller_decorator.rb @@ -224,7 +224,7 @@ Spree::Admin::ReportsController.class_eval do @suppliers = permissions.visible_enterprises_for_order_reports.is_primary_producer @order_cycles = OrderCycle.active_or_complete. - involving_managed_distributors_of(spree_current_user).order('orders_close_at DESC') + involving_managed_distributors_of(spree_current_user).order('orders_close_at DESC') @report_types = REPORT_TYPES[:orders_and_fulfillment] @report_type = params[:report_type] diff --git a/app/controllers/spree/admin/search_controller_decorator.rb b/app/controllers/spree/admin/search_controller_decorator.rb index 746a05c195..e61b83bed8 100644 --- a/app/controllers/spree/admin/search_controller_decorator.rb +++ b/app/controllers/spree/admin/search_controller_decorator.rb @@ -19,7 +19,7 @@ Spree::Admin::SearchController.class_eval do def customers if spree_current_user.enterprises.pluck(:id).include? params[:distributor_id].to_i @customers = Customer.ransack({m: 'or', email_start: params[:q], name_start: params[:q]}) - .result.where(enterprise_id: params[:distributor_id]) + .result.where(enterprise_id: params[:distributor_id]) else @customers = [] end diff --git a/app/controllers/spree/orders_controller_decorator.rb b/app/controllers/spree/orders_controller_decorator.rb index fb52bf88b9..3eb533e703 100644 --- a/app/controllers/spree/orders_controller_decorator.rb +++ b/app/controllers/spree/orders_controller_decorator.rb @@ -239,7 +239,7 @@ Spree::OrdersController.class_eval do return unless order_to_update.andand.complete? items = params[:order][:line_items_attributes] - .andand.select{ |k,attrs| attrs["quantity"].to_i > 0 } + .andand.select{ |k,attrs| attrs["quantity"].to_i > 0 } if items.empty? flash[:error] = I18n.t(:orders_cannot_remove_the_final_item) diff --git a/app/jobs/update_billable_periods.rb b/app/jobs/update_billable_periods.rb index 80f19d961a..46e64b81ca 100644 --- a/app/jobs/update_billable_periods.rb +++ b/app/jobs/update_billable_periods.rb @@ -106,8 +106,8 @@ class UpdateBillablePeriods end obsolete_billable_periods.includes({ account_invoice: :order}). - where('spree_orders.state <> \'complete\' OR account_invoices.order_id IS NULL'). - each(&:delete) + where('spree_orders.state <> \'complete\' OR account_invoices.order_id IS NULL'). + each(&:delete) end private diff --git a/app/models/enterprise.rb b/app/models/enterprise.rb index e9acbd51f6..39a4c5d5c3 100644 --- a/app/models/enterprise.rb +++ b/app/models/enterprise.rb @@ -103,9 +103,9 @@ class Enterprise < ActiveRecord::Base scope :activated, where("confirmed_at IS NOT NULL AND sells != 'unspecified'") scope :ready_for_checkout, lambda { joins(:shipping_methods). - joins(:payment_methods). - merge(Spree::PaymentMethod.available). - select('DISTINCT enterprises.*') + joins(:payment_methods). + merge(Spree::PaymentMethod.available). + select('DISTINCT enterprises.*') } scope :not_ready_for_checkout, lambda { # When ready_for_checkout is empty, ActiveRecord generates the SQL: @@ -152,25 +152,25 @@ class Enterprise < ActiveRecord::Base scope :active_distributors, lambda { with_distributed_products_outer.with_order_cycles_as_distributor_outer. - where('(product_distributions.product_id IS NOT NULL AND spree_products.deleted_at IS NULL AND spree_products.available_on <= ? AND spree_products.count_on_hand > 0) OR (order_cycles.id IS NOT NULL AND order_cycles.orders_open_at <= ? AND order_cycles.orders_close_at >= ?)', Time.zone.now, Time.zone.now, Time.zone.now). - select('DISTINCT enterprises.*') + where('(product_distributions.product_id IS NOT NULL AND spree_products.deleted_at IS NULL AND spree_products.available_on <= ? AND spree_products.count_on_hand > 0) OR (order_cycles.id IS NOT NULL AND order_cycles.orders_open_at <= ? AND order_cycles.orders_close_at >= ?)', Time.zone.now, Time.zone.now, Time.zone.now). + select('DISTINCT enterprises.*') } scope :distributors_with_active_order_cycles, lambda { with_order_cycles_as_distributor_outer. - merge(OrderCycle.active). - select('DISTINCT enterprises.*') + merge(OrderCycle.active). + select('DISTINCT enterprises.*') } scope :distributing_products, lambda { |products| # TODO: remove this when we pull out product distributions pds = joins("INNER JOIN product_distributions ON product_distributions.distributor_id = enterprises.id"). - where("product_distributions.product_id IN (?)", products).select('DISTINCT enterprises.id') + where("product_distributions.product_id IN (?)", products).select('DISTINCT enterprises.id') exs = joins("INNER JOIN exchanges ON (exchanges.receiver_id = enterprises.id AND exchanges.incoming = 'f')"). - joins('INNER JOIN exchange_variants ON (exchange_variants.exchange_id = exchanges.id)'). - joins('INNER JOIN spree_variants ON (spree_variants.id = exchange_variants.variant_id)'). - where('spree_variants.product_id IN (?)', products).select('DISTINCT enterprises.id') + joins('INNER JOIN exchange_variants ON (exchange_variants.exchange_id = exchanges.id)'). + joins('INNER JOIN spree_variants ON (spree_variants.id = exchange_variants.variant_id)'). + where('spree_variants.product_id IN (?)', products).select('DISTINCT enterprises.id') where(id: pds | exs) } diff --git a/app/models/enterprise_relationship.rb b/app/models/enterprise_relationship.rb index 7788c6aac6..1f87b8737b 100644 --- a/app/models/enterprise_relationship.rb +++ b/app/models/enterprise_relationship.rb @@ -21,7 +21,7 @@ class EnterpriseRelationship < ActiveRecord::Base scope :with_permission, ->(permission) { joins(:permissions). - where('enterprise_relationship_permissions.name = ?', permission) + where('enterprise_relationship_permissions.name = ?', permission) } scope :by_name, with_enterprises.order('child_enterprises.name, parent_enterprises.name') diff --git a/app/models/exchange.rb b/app/models/exchange.rb index f60c7289b6..3ce52b206a 100644 --- a/app/models/exchange.rb +++ b/app/models/exchange.rb @@ -33,14 +33,14 @@ class Exchange < ActiveRecord::Base scope :with_any_variant, lambda { |variants| joins(:exchange_variants).where('exchange_variants.variant_id IN (?)', variants).select('DISTINCT exchanges.*') } scope :with_product, lambda { |product| joins(:exchange_variants).where('exchange_variants.variant_id IN (?)', product.variants_including_master) } scope :by_enterprise_name, joins('INNER JOIN enterprises AS sender ON (sender.id = exchanges.sender_id)'). - joins('INNER JOIN enterprises AS receiver ON (receiver.id = exchanges.receiver_id)'). - order("CASE WHEN exchanges.incoming='t' THEN sender.name ELSE receiver.name END") + joins('INNER JOIN enterprises AS receiver ON (receiver.id = exchanges.receiver_id)'). + order("CASE WHEN exchanges.incoming='t' THEN sender.name ELSE receiver.name END") # Exchanges on order cycles that are dated and are upcoming or open are cached scope :cachable, outgoing. - joins(:order_cycle). - merge(OrderCycle.dated). - merge(OrderCycle.not_closed) + joins(:order_cycle). + merge(OrderCycle.dated). + merge(OrderCycle.not_closed) scope :managed_by, lambda { |user| if user.has_spree_role?('admin') diff --git a/app/models/order_cycle.rb b/app/models/order_cycle.rb index 7186c66c75..9c2dc9fcef 100644 --- a/app/models/order_cycle.rb +++ b/app/models/order_cycle.rb @@ -36,9 +36,9 @@ class OrderCycle < ActiveRecord::Base scope :distributing_product, lambda { |product| joins(:exchanges). - merge(Exchange.outgoing). - merge(Exchange.with_product(product)). - select('DISTINCT order_cycles.*') } + merge(Exchange.outgoing). + merge(Exchange.with_product(product)). + select('DISTINCT order_cycles.*') } scope :with_distributor, lambda { |distributor| joins(:exchanges).merge(Exchange.outgoing).merge(Exchange.to_enterprise(distributor)) @@ -59,14 +59,14 @@ class OrderCycle < ActiveRecord::Base scoped else with_exchanging_enterprises_outer. - where('order_cycles.coordinator_id IN (?) OR enterprises.id IN (?)', user.enterprises, user.enterprises). - select('DISTINCT order_cycles.*') + where('order_cycles.coordinator_id IN (?) OR enterprises.id IN (?)', user.enterprises, user.enterprises). + select('DISTINCT order_cycles.*') end } scope :with_exchanging_enterprises_outer, lambda { joins('LEFT OUTER JOIN exchanges ON (exchanges.order_cycle_id = order_cycles.id)'). - joins('LEFT OUTER JOIN enterprises ON (enterprises.id = exchanges.sender_id OR enterprises.id = exchanges.receiver_id)') + joins('LEFT OUTER JOIN enterprises ON (enterprises.id = exchanges.sender_id OR enterprises.id = exchanges.receiver_id)') } scope :involving_managed_distributors_of, lambda { |user| @@ -75,8 +75,8 @@ class OrderCycle < ActiveRecord::Base # Order cycles where I managed an enterprise at either end of an outgoing exchange # ie. coordinator or distibutor joins(:exchanges).merge(Exchange.outgoing). - where('exchanges.receiver_id IN (?) OR exchanges.sender_id IN (?)', enterprises, enterprises). - select('DISTINCT order_cycles.*') + where('exchanges.receiver_id IN (?) OR exchanges.sender_id IN (?)', enterprises, enterprises). + select('DISTINCT order_cycles.*') } scope :involving_managed_producers_of, lambda { |user| @@ -85,8 +85,8 @@ class OrderCycle < ActiveRecord::Base # Order cycles where I managed an enterprise at either end of an incoming exchange # ie. coordinator or producer joins(:exchanges).merge(Exchange.incoming). - where('exchanges.receiver_id IN (?) OR exchanges.sender_id IN (?)', enterprises, enterprises). - select('DISTINCT order_cycles.*') + where('exchanges.receiver_id IN (?) OR exchanges.sender_id IN (?)', enterprises, enterprises). + select('DISTINCT order_cycles.*') } def self.first_opening_for(distributor) @@ -106,12 +106,12 @@ class OrderCycle < ActiveRecord::Base def self.earliest_closing_times Hash[ Exchange. - outgoing. - joins(:order_cycle). - merge(OrderCycle.active). - group('exchanges.receiver_id'). - select('exchanges.receiver_id AS receiver_id, MIN(order_cycles.orders_close_at) AS earliest_close_at'). - map { |ex| [ex.receiver_id, ex.earliest_close_at.to_time] } + outgoing. + joins(:order_cycle). + merge(OrderCycle.active). + group('exchanges.receiver_id'). + select('exchanges.receiver_id AS receiver_id, MIN(order_cycles.orders_close_at) AS earliest_close_at'). + map { |ex| [ex.receiver_id, ex.earliest_close_at.to_time] } ] end diff --git a/app/models/spree/calculator/default_tax_decorator.rb b/app/models/spree/calculator/default_tax_decorator.rb index 623f2df26d..9a221b361c 100644 --- a/app/models/spree/calculator/default_tax_decorator.rb +++ b/app/models/spree/calculator/default_tax_decorator.rb @@ -19,9 +19,9 @@ Spree::Calculator::DefaultTax.class_eval do # Added this block, finds relevant fees for each line_item, calculates the tax on them, and returns the total tax per_item_fees_total = order.line_items.sum do |line_item| calculator.send(:per_item_enterprise_fee_applicators_for, line_item.variant) - .select { |applicator| (!applicator.enterprise_fee.inherits_tax_category && applicator.enterprise_fee.tax_category == rate.tax_category) || - (applicator.enterprise_fee.inherits_tax_category && line_item.product.tax_category == rate.tax_category) } - .sum { |applicator| applicator.enterprise_fee.compute_amount(line_item) } + .select { |applicator| (!applicator.enterprise_fee.inherits_tax_category && applicator.enterprise_fee.tax_category == rate.tax_category) || + (applicator.enterprise_fee.inherits_tax_category && line_item.product.tax_category == rate.tax_category) } + .sum { |applicator| applicator.enterprise_fee.compute_amount(line_item) } end # Added this block, finds relevant fees for whole order, calculates the tax on them, and returns the total tax diff --git a/app/models/spree/line_item_decorator.rb b/app/models/spree/line_item_decorator.rb index 935466d377..9c80df8bb4 100644 --- a/app/models/spree/line_item_decorator.rb +++ b/app/models/spree/line_item_decorator.rb @@ -19,28 +19,28 @@ Spree::LineItem.class_eval do else # Find line items that are from orders distributed by the user or supplied by the user joins(:variant => :product). - joins(:order). - where('spree_orders.distributor_id IN (?) OR spree_products.supplier_id IN (?)', user.enterprises, user.enterprises). - select('spree_line_items.*') + joins(:order). + where('spree_orders.distributor_id IN (?) OR spree_products.supplier_id IN (?)', user.enterprises, user.enterprises). + select('spree_line_items.*') end } scope :supplied_by, lambda { |enterprise| joins(:product). - where('spree_products.supplier_id = ?', enterprise) + where('spree_products.supplier_id = ?', enterprise) } scope :supplied_by_any, lambda { |enterprises| joins(:product). - where('spree_products.supplier_id IN (?)', enterprises) + where('spree_products.supplier_id IN (?)', enterprises) } scope :with_tax, joins(:adjustments). - where('spree_adjustments.originator_type = ?', 'Spree::TaxRate'). - select('DISTINCT spree_line_items.*') + where('spree_adjustments.originator_type = ?', 'Spree::TaxRate'). + select('DISTINCT spree_line_items.*') # Line items without a Spree::TaxRate-originated adjustment scope :without_tax, joins("LEFT OUTER JOIN spree_adjustments ON (spree_adjustments.adjustable_id=spree_line_items.id AND spree_adjustments.adjustable_type = 'Spree::LineItem' AND spree_adjustments.originator_type='Spree::TaxRate')"). - where('spree_adjustments.id IS NULL') + where('spree_adjustments.id IS NULL') def cap_quantity_at_stock! diff --git a/app/models/spree/order_decorator.rb b/app/models/spree/order_decorator.rb index 41a70383bc..04f86c2468 100644 --- a/app/models/spree/order_decorator.rb +++ b/app/models/spree/order_decorator.rb @@ -50,8 +50,8 @@ Spree::Order.class_eval do # Find orders that are distributed by the user or have products supplied by the user # WARNING: This only filters orders, you'll need to filter line items separately using LineItem.managed_by with_line_items_variants_and_products_outer. - where('spree_orders.distributor_id IN (?) OR spree_products.supplier_id IN (?)', user.enterprises, user.enterprises). - select('DISTINCT spree_orders.*') + where('spree_orders.distributor_id IN (?) OR spree_products.supplier_id IN (?)', user.enterprises, user.enterprises). + select('DISTINCT spree_orders.*') end } @@ -65,8 +65,8 @@ Spree::Order.class_eval do scope :with_line_items_variants_and_products_outer, lambda { joins('LEFT OUTER JOIN spree_line_items ON (spree_line_items.order_id = spree_orders.id)'). - joins('LEFT OUTER JOIN spree_variants ON (spree_variants.id = spree_line_items.variant_id)'). - joins('LEFT OUTER JOIN spree_products ON (spree_products.id = spree_variants.product_id)') + joins('LEFT OUTER JOIN spree_variants ON (spree_variants.id = spree_line_items.variant_id)'). + joins('LEFT OUTER JOIN spree_products ON (spree_products.id = spree_variants.product_id)') } scope :not_state, lambda { |state| diff --git a/app/models/spree/payment_method_decorator.rb b/app/models/spree/payment_method_decorator.rb index fb5faaef4c..ab19525d1a 100644 --- a/app/models/spree/payment_method_decorator.rb +++ b/app/models/spree/payment_method_decorator.rb @@ -19,14 +19,14 @@ Spree::PaymentMethod.class_eval do scoped else joins(:distributors). - where('distributors_payment_methods.distributor_id IN (?)', user.enterprises). - select('DISTINCT spree_payment_methods.*') + where('distributors_payment_methods.distributor_id IN (?)', user.enterprises). + select('DISTINCT spree_payment_methods.*') end } scope :for_distributor, lambda { |distributor| joins(:distributors). - where('enterprises.id = ?', distributor) + where('enterprises.id = ?', distributor) } scope :by_name, order('spree_payment_methods.name ASC') @@ -34,8 +34,8 @@ Spree::PaymentMethod.class_eval do # Rewrite Spree's ruby-land class method as a scope scope :available, lambda { |display_on='both'| where(active: true). - where('spree_payment_methods.display_on=? OR spree_payment_methods.display_on=? OR spree_payment_methods.display_on IS NULL', display_on, ''). - where('spree_payment_methods.environment=? OR spree_payment_methods.environment=? OR spree_payment_methods.environment IS NULL', Rails.env, '') + where('spree_payment_methods.display_on=? OR spree_payment_methods.display_on=? OR spree_payment_methods.display_on IS NULL', display_on, ''). + where('spree_payment_methods.environment=? OR spree_payment_methods.environment=? OR spree_payment_methods.environment IS NULL', Rails.env, '') } def init diff --git a/app/models/spree/product_decorator.rb b/app/models/spree/product_decorator.rb index 3173304f41..0adb746aa4 100644 --- a/app/models/spree/product_decorator.rb +++ b/app/models/spree/product_decorator.rb @@ -47,17 +47,17 @@ Spree::Product.class_eval do scope :with_product_distributions_outer, joins('LEFT OUTER JOIN product_distributions ON product_distributions.product_id = spree_products.id') scope :with_order_cycles_outer, joins('LEFT OUTER JOIN spree_variants AS o_spree_variants ON (o_spree_variants.product_id = spree_products.id)'). - joins('LEFT OUTER JOIN exchange_variants AS o_exchange_variants ON (o_exchange_variants.variant_id = o_spree_variants.id)'). - joins('LEFT OUTER JOIN exchanges AS o_exchanges ON (o_exchanges.id = o_exchange_variants.exchange_id)'). - joins('LEFT OUTER JOIN order_cycles AS o_order_cycles ON (o_order_cycles.id = o_exchanges.order_cycle_id)') + joins('LEFT OUTER JOIN exchange_variants AS o_exchange_variants ON (o_exchange_variants.variant_id = o_spree_variants.id)'). + joins('LEFT OUTER JOIN exchanges AS o_exchanges ON (o_exchanges.id = o_exchange_variants.exchange_id)'). + joins('LEFT OUTER JOIN order_cycles AS o_order_cycles ON (o_order_cycles.id = o_exchanges.order_cycle_id)') scope :with_order_cycles_inner, joins(:variants_including_master => {:exchanges => :order_cycle}) scope :visible_for, lambda { |enterprise| joins('LEFT OUTER JOIN spree_variants AS o_spree_variants ON (o_spree_variants.product_id = spree_products.id)'). - joins('LEFT OUTER JOIN inventory_items AS o_inventory_items ON (o_spree_variants.id = o_inventory_items.variant_id)'). - where('o_inventory_items.enterprise_id = (?) AND visible = (?)', enterprise, true). - select('DISTINCT spree_products.*') + joins('LEFT OUTER JOIN inventory_items AS o_inventory_items ON (o_spree_variants.id = o_inventory_items.variant_id)'). + where('o_inventory_items.enterprise_id = (?) AND visible = (?)', enterprise, true). + select('DISTINCT spree_products.*') } @@ -73,16 +73,16 @@ Spree::Product.class_eval do distributor = distributor.respond_to?(:id) ? distributor.id : distributor.to_i with_product_distributions_outer.with_order_cycles_outer. - where('product_distributions.distributor_id = ? OR (o_exchanges.incoming = ? AND o_exchanges.receiver_id = ?)', distributor, false, distributor). - select('distinct spree_products.*') + where('product_distributions.distributor_id = ? OR (o_exchanges.incoming = ? AND o_exchanges.receiver_id = ?)', distributor, false, distributor). + select('distinct spree_products.*') } scope :in_product_distribution_by, lambda { |distributor| distributor = distributor.respond_to?(:id) ? distributor.id : distributor.to_i with_product_distributions_outer. - where('product_distributions.distributor_id = ?', distributor). - select('distinct spree_products.*') + where('product_distributions.distributor_id = ?', distributor). + select('distinct spree_products.*') } # Find products that are supplied by a given enterprise or distributed via that enterprise EITHER through a product distribution OR through an order cycle @@ -90,19 +90,19 @@ Spree::Product.class_eval do enterprise = enterprise.respond_to?(:id) ? enterprise.id : enterprise.to_i with_product_distributions_outer.with_order_cycles_outer. - where('spree_products.supplier_id = ? OR product_distributions.distributor_id = ? OR (o_exchanges.incoming = ? AND o_exchanges.receiver_id = ?)', enterprise, enterprise, false, enterprise). - select('distinct spree_products.*') + where('spree_products.supplier_id = ? OR product_distributions.distributor_id = ? OR (o_exchanges.incoming = ? AND o_exchanges.receiver_id = ?)', enterprise, enterprise, false, enterprise). + select('distinct spree_products.*') } # Find products that are distributed by the given order cycle scope :in_order_cycle, lambda { |order_cycle| with_order_cycles_inner. - merge(Exchange.outgoing). - where('order_cycles.id = ?', order_cycle) } + merge(Exchange.outgoing). + where('order_cycles.id = ?', order_cycle) } scope :in_an_active_order_cycle, lambda { with_order_cycles_inner. - merge(OrderCycle.active). - merge(Exchange.outgoing). - where('order_cycles.id IS NOT NULL') } + merge(OrderCycle.active). + merge(Exchange.outgoing). + where('order_cycles.id IS NOT NULL') } scope :by_producer, joins(:supplier).order('enterprises.name') scope :by_name, order('name') diff --git a/app/models/spree/shipping_method_decorator.rb b/app/models/spree/shipping_method_decorator.rb index 9c276d82bf..d82dbdb380 100644 --- a/app/models/spree/shipping_method_decorator.rb +++ b/app/models/spree/shipping_method_decorator.rb @@ -15,14 +15,14 @@ Spree::ShippingMethod.class_eval do scoped else joins(:distributors). - where('distributors_shipping_methods.distributor_id IN (?)', user.enterprises). - select('DISTINCT spree_shipping_methods.*') + where('distributors_shipping_methods.distributor_id IN (?)', user.enterprises). + select('DISTINCT spree_shipping_methods.*') end } scope :for_distributor, lambda { |distributor| joins(:distributors). - where('enterprises.id = ?', distributor) + where('enterprises.id = ?', distributor) } scope :by_name, order('spree_shipping_methods.name ASC') @@ -33,12 +33,12 @@ Spree::ShippingMethod.class_eval do def self.services Hash[ Spree::ShippingMethod. - joins(:distributor_shipping_methods). - group('distributor_id'). - select("distributor_id"). - select("BOOL_OR(spree_shipping_methods.require_ship_address = 'f') AS pickup"). - select("BOOL_OR(spree_shipping_methods.require_ship_address = 't') AS delivery"). - map { |sm| [sm.distributor_id.to_i, {pickup: sm.pickup == 't', delivery: sm.delivery == 't'}] } + joins(:distributor_shipping_methods). + group('distributor_id'). + select("distributor_id"). + select("BOOL_OR(spree_shipping_methods.require_ship_address = 'f') AS pickup"). + select("BOOL_OR(spree_shipping_methods.require_ship_address = 't') AS delivery"). + map { |sm| [sm.distributor_id.to_i, {pickup: sm.pickup == 't', delivery: sm.delivery == 't'}] } ] end diff --git a/app/models/spree/taxon_decorator.rb b/app/models/spree/taxon_decorator.rb index 71da03ccbf..f3868563b3 100644 --- a/app/models/spree/taxon_decorator.rb +++ b/app/models/spree/taxon_decorator.rb @@ -38,13 +38,13 @@ Spree::Taxon.class_eval do # Format: {enterprise_id => [taxon_id, ...]} def self.distributed_taxons(which_taxons=:all) ents_and_vars = ExchangeVariant.joins(exchange: :order_cycle).merge(Exchange.outgoing) - .select("DISTINCT variant_id, receiver_id AS enterprise_id") + .select("DISTINCT variant_id, receiver_id AS enterprise_id") ents_and_vars = ents_and_vars.merge(OrderCycle.active) if which_taxons == :current taxons = Spree::Taxon - .select("DISTINCT spree_taxons.id, ents_and_vars.enterprise_id").joins(products: :variants_including_master) - .joins("INNER JOIN (#{ents_and_vars.to_sql}) AS ents_and_vars ON spree_variants.id = ents_and_vars.variant_id") + .select("DISTINCT spree_taxons.id, ents_and_vars.enterprise_id").joins(products: :variants_including_master) + .joins("INNER JOIN (#{ents_and_vars.to_sql}) AS ents_and_vars ON spree_variants.id = ents_and_vars.variant_id") taxons.inject({}) do |ts, t| ts[t.enterprise_id.to_i] ||= Set.new diff --git a/app/models/spree/user_decorator.rb b/app/models/spree/user_decorator.rb index b16e082f87..9c6db38d8a 100644 --- a/app/models/spree/user_decorator.rb +++ b/app/models/spree/user_decorator.rb @@ -27,8 +27,8 @@ Spree.user_class.class_eval do Spree::User.scoped else Spree::User - .includes(:enterprises) - .where("enterprises.id IN (SELECT enterprise_id FROM enterprise_roles WHERE user_id = ?)", id) + .includes(:enterprises) + .where("enterprises.id IN (SELECT enterprise_id FROM enterprise_roles WHERE user_id = ?)", id) end end diff --git a/app/models/spree/variant_decorator.rb b/app/models/spree/variant_decorator.rb index 1c276bef97..c23dbe385e 100644 --- a/app/models/spree/variant_decorator.rb +++ b/app/models/spree/variant_decorator.rb @@ -36,9 +36,9 @@ Spree::Variant.class_eval do scope :in_stock, where('spree_variants.count_on_hand > 0 OR spree_variants.on_demand=?', true) scope :in_order_cycle, lambda { |order_cycle| with_order_cycles_inner. - merge(Exchange.outgoing). - where('order_cycles.id = ?', order_cycle). - select('DISTINCT spree_variants.*') + merge(Exchange.outgoing). + where('order_cycles.id = ?', order_cycle). + select('DISTINCT spree_variants.*') } scope :for_distribution, lambda { |order_cycle, distributor| @@ -52,7 +52,7 @@ Spree::Variant.class_eval do scope :not_hidden_for, lambda { |enterprise| return where("1=0") unless enterprise.present? joins("LEFT OUTER JOIN (SELECT * from inventory_items WHERE enterprise_id = #{sanitize enterprise.andand.id}) AS o_inventory_items ON o_inventory_items.variant_id = spree_variants.id") - .where("o_inventory_items.id IS NULL OR o_inventory_items.visible = (?)", true) + .where("o_inventory_items.id IS NULL OR o_inventory_items.visible = (?)", true) } # Define sope as class method to allow chaining with other scopes filtering id. diff --git a/app/serializers/api/admin/exchange_serializer.rb b/app/serializers/api/admin/exchange_serializer.rb index e1c15c5210..355b4109e8 100644 --- a/app/serializers/api/admin/exchange_serializer.rb +++ b/app/serializers/api/admin/exchange_serializer.rb @@ -29,12 +29,12 @@ class Api::Admin::ExchangeSerializer < ActiveModel::Serializer def permitted_incoming_variants OpenFoodNetwork::OrderCyclePermissions.new(options[:current_user], object.order_cycle). - visible_variants_for_incoming_exchanges_from(object.sender) + visible_variants_for_incoming_exchanges_from(object.sender) end def permitted_outgoing_variants OpenFoodNetwork::OrderCyclePermissions.new(options[:current_user], object.order_cycle) - .visible_variants_for_outgoing_exchanges_to(object.receiver) + .visible_variants_for_outgoing_exchanges_to(object.receiver) end def tag_list diff --git a/lib/open_food_network/lettuce_share_report.rb b/lib/open_food_network/lettuce_share_report.rb index d1d16b2582..5c1d6c468a 100644 --- a/lib/open_food_network/lettuce_share_report.rb +++ b/lib/open_food_network/lettuce_share_report.rb @@ -19,7 +19,7 @@ module OpenFoodNetwork def table variants.select { |v| v.in_stock? } - .map do |variant| + .map do |variant| [ variant.product.name, variant.full_name, diff --git a/lib/open_food_network/order_cycle_form_applicator.rb b/lib/open_food_network/order_cycle_form_applicator.rb index 2573d52aa6..d1aca3c55f 100644 --- a/lib/open_food_network/order_cycle_form_applicator.rb +++ b/lib/open_food_network/order_cycle_form_applicator.rb @@ -129,7 +129,7 @@ module OpenFoodNetwork def editable_variant_ids_for_outgoing_exchange_between(sender, receiver) OpenFoodNetwork::OrderCyclePermissions.new(@spree_current_user, @order_cycle). - editable_variants_for_outgoing_exchanges_to(receiver).pluck(:id) + editable_variants_for_outgoing_exchanges_to(receiver).pluck(:id) end def find_exchange(sender_id, receiver_id, incoming) diff --git a/lib/open_food_network/order_cycle_permissions.rb b/lib/open_food_network/order_cycle_permissions.rb index f728348630..45fe5eb256 100644 --- a/lib/open_food_network/order_cycle_permissions.rb +++ b/lib/open_food_network/order_cycle_permissions.rb @@ -90,7 +90,7 @@ module OpenFoodNetwork else # All variants of the producer if it has granted P-OC to any of my managed hubs that are in this order cycle permitted = EnterpriseRelationship.permitting(managed_participating_hubs). - permitted_by(producer).with_permission(:add_to_order_cycle).present? + permitted_by(producer).with_permission(:add_to_order_cycle).present? if permitted Spree::Variant.joins(:product).where('spree_products.supplier_id = (?)', producer) else @@ -146,7 +146,7 @@ module OpenFoodNetwork # PLUS any of my incoming producers' variants that are already in an outgoing exchange of this hub, so things don't break # TODO: Remove this when all P-OC are sorted out active_variants = Spree::Variant.joins(:exchanges, :product). - where("exchanges.receiver_id = (?) AND spree_products.supplier_id IN (?) AND incoming = 'f'", hub, managed_enterprises.is_primary_producer) + where("exchanges.receiver_id = (?) AND spree_products.supplier_id IN (?) AND incoming = 'f'", hub, managed_enterprises.is_primary_producer) Spree::Variant.where(id: permitted_variants | active_variants) end diff --git a/lib/open_food_network/permissions.rb b/lib/open_food_network/permissions.rb index 795bd3cf68..0747df17ad 100644 --- a/lib/open_food_network/permissions.rb +++ b/lib/open_food_network/permissions.rb @@ -43,10 +43,10 @@ module OpenFoodNetwork # Permissions granted by create_variant_overrides relationship from producer to hub permissions = Hash[ EnterpriseRelationship. - permitting(hubs). - with_permission(:create_variant_overrides). - group_by { |er| er.child_id }. - map { |child_id, ers| [child_id, ers.map { |er| er.parent_id }] } + permitting(hubs). + with_permission(:create_variant_overrides). + group_by { |er| er.child_id }. + map { |child_id, ers| [child_id, ers.map { |er| er.parent_id }] } ] # Allow a producer hub to override it's own products without explicit permission @@ -68,11 +68,11 @@ module OpenFoodNetwork # P-OC to the distributor AND the order contains products of at least one of THE SAME producers granted_distributors = related_enterprises_granted(:add_to_order_cycle, by: managed_enterprises.is_primary_producer) produced = Spree::Order.with_line_items_variants_and_products_outer. - where( + where( "spree_orders.distributor_id IN (?) AND spree_products.supplier_id IN (?)", granted_distributors, related_enterprises_granting(:add_to_order_cycle, to: granted_distributors).merge(managed_enterprises.is_primary_producer) - ).pluck(:id) + ).pluck(:id) Spree::Order.where(id: editable | produced) end @@ -94,7 +94,7 @@ module OpenFoodNetwork # Any from visible orders, where the product is produced by one of my managed producers produced = Spree::LineItem.where(order_id: visible_orders.pluck(:id)).joins(:product). - where('spree_products.supplier_id IN (?)', managed_enterprises.is_primary_producer.pluck(:id)) + where('spree_products.supplier_id IN (?)', managed_enterprises.is_primary_producer.pluck(:id)) Spree::LineItem.where(id: editable | produced) end diff --git a/lib/open_food_network/products_cache.rb b/lib/open_food_network/products_cache.rb index 894861c633..99e15f070b 100644 --- a/lib/open_food_network/products_cache.rb +++ b/lib/open_food_network/products_cache.rb @@ -49,8 +49,8 @@ module OpenFoodNetwork def self.producer_property_changed(producer_property) products = producer_property.producer.supplied_products variants = Spree::Variant. - where(is_master: false, deleted_at: nil). - where(product_id: products) + where(is_master: false, deleted_at: nil). + where(product_id: products) exchanges_featuring_variants(variants).each do |exchange| refresh_cache exchange.receiver, exchange.order_cycle diff --git a/lib/open_food_network/xero_invoices_report.rb b/lib/open_food_network/xero_invoices_report.rb index 2614f61dfb..d37a056fc7 100644 --- a/lib/open_food_network/xero_invoices_report.rb +++ b/lib/open_food_network/xero_invoices_report.rb @@ -4,11 +4,11 @@ module OpenFoodNetwork @user = user @opts = opts. - reject { |k, v| v.blank? }. - reverse_merge({report_type: 'summary', - invoice_date: Time.zone.today, - due_date: Time.zone.today + 1.month, - account_code: 'food sales'}) + reject { |k, v| v.blank? }. + reverse_merge({report_type: 'summary', + invoice_date: Time.zone.today, + due_date: Time.zone.today + 1.month, + account_code: 'food sales'}) end def header diff --git a/spec/helpers/order_cycles_helper_spec.rb b/spec/helpers/order_cycles_helper_spec.rb index 6841889313..8390776ca1 100644 --- a/spec/helpers/order_cycles_helper_spec.rb +++ b/spec/helpers/order_cycles_helper_spec.rb @@ -42,20 +42,20 @@ describe OrderCyclesHelper do it "returns enterprises without shipping methods as disabled" do create(:payment_method, distributors: [e]) expect(helper.send(:validated_enterprise_options, [e], shipping_and_payment_methods: true)) - .to eq [['enterprise (no shipping methods)', e.id, {disabled: true}]] + .to eq [['enterprise (no shipping methods)', e.id, {disabled: true}]] end it "returns enterprises without payment methods as disabled" do create(:shipping_method, distributors: [e]) expect(helper.send(:validated_enterprise_options, [e], shipping_and_payment_methods: true)) - .to eq [['enterprise (no payment methods)', e.id, {disabled: true}]] + .to eq [['enterprise (no payment methods)', e.id, {disabled: true}]] end it "returns enterprises with unavailable payment methods as disabled" do create(:shipping_method, distributors: [e]) create(:payment_method, distributors: [e], active: false) expect(helper.send(:validated_enterprise_options, [e], shipping_and_payment_methods: true)) - .to eq [['enterprise (no payment methods)', e.id, {disabled: true}]] + .to eq [['enterprise (no payment methods)', e.id, {disabled: true}]] end it "returns unconfirmed enterprises as disabled" do @@ -63,12 +63,12 @@ describe OrderCyclesHelper do create(:payment_method, distributors: [e]) e.stub(:confirmed_at) { nil } expect(helper.send(:validated_enterprise_options, [e], confirmed: true)) - .to eq [['enterprise (unconfirmed)', e.id, {disabled: true}]] + .to eq [['enterprise (unconfirmed)', e.id, {disabled: true}]] end it "returns enterprises with neither shipping nor payment methods as disabled" do expect(helper.send(:validated_enterprise_options, [e], shipping_and_payment_methods: true)) - .to eq [['enterprise (no shipping or payment methods)', e.id, {disabled: true}]] + .to eq [['enterprise (no shipping or payment methods)', e.id, {disabled: true}]] end end diff --git a/spec/jobs/update_account_invoices_spec.rb b/spec/jobs/update_account_invoices_spec.rb index d9a2beca6b..0f0a78b505 100644 --- a/spec/jobs/update_account_invoices_spec.rb +++ b/spec/jobs/update_account_invoices_spec.rb @@ -62,9 +62,9 @@ describe UpdateAccountInvoices do it "updates invoices from the previous month" do updater.perform expect(updater).to have_received(:update).once - .with(june_account_invoice) + .with(june_account_invoice) expect(updater).to_not have_received(:update) - .with(july_account_invoice) + .with(july_account_invoice) end end @@ -74,7 +74,7 @@ describe UpdateAccountInvoices do it "updates invoices from the current month" do updater.perform expect(updater).to have_received(:update).once - .with(july_account_invoice) + .with(july_account_invoice) end end @@ -91,7 +91,7 @@ describe UpdateAccountInvoices do it "updates invoices from the previous month" do updater.perform expect(updater).to have_received(:update).once - .with(july_account_invoice) + .with(july_account_invoice) end end @@ -101,7 +101,7 @@ describe UpdateAccountInvoices do it "updates invoices from that current month" do updater.perform expect(updater).to have_received(:update).once - .with(july_account_invoice) + .with(july_account_invoice) end end diff --git a/spec/jobs/update_billable_periods_spec.rb b/spec/jobs/update_billable_periods_spec.rb index d868550e7e..449e457cd6 100644 --- a/spec/jobs/update_billable_periods_spec.rb +++ b/spec/jobs/update_billable_periods_spec.rb @@ -25,7 +25,7 @@ describe UpdateBillablePeriods do it "processes the previous month" do expect(updater).to receive(:split_for_trial) - .with(enterprise, start_of_july - 1.month, start_of_july, nil, nil) + .with(enterprise, start_of_july - 1.month, start_of_july, nil, nil) updater.perform end end @@ -35,7 +35,7 @@ describe UpdateBillablePeriods do it "processes the current month up until previous midnight" do expect(updater).to receive(:split_for_trial) - .with(enterprise, start_of_july, start_of_july + 1.day, nil, nil) + .with(enterprise, start_of_july, start_of_july + 1.day, nil, nil) updater.perform end end @@ -53,7 +53,7 @@ describe UpdateBillablePeriods do it "processes the month" do expect(updater).to receive(:split_for_trial) - .with(enterprise, start_of_july - 1.month, start_of_july, nil, nil) + .with(enterprise, start_of_july - 1.month, start_of_july, nil, nil) updater.perform end end @@ -63,7 +63,7 @@ describe UpdateBillablePeriods do it "processes the current month up to the previous midnight" do expect(updater).to receive(:split_for_trial) - .with(enterprise, start_of_july - 1.month, start_of_july-3.days, nil, nil) + .with(enterprise, start_of_july - 1.month, start_of_july-3.days, nil, nil) updater.perform end end @@ -89,7 +89,7 @@ describe UpdateBillablePeriods do it "begins at the start of the month" do expect(updater).to receive(:split_for_trial) - .with(enterprise, start_of_july, start_of_july + 28.days, nil, nil) + .with(enterprise, start_of_july, start_of_july + 28.days, nil, nil) updater.perform end end @@ -109,10 +109,10 @@ describe UpdateBillablePeriods do updater.perform expect(updater).to have_received(:split_for_trial) - .with(enterprise.versions.first.reify, start_of_july, start_of_july + 10.days, nil, nil) + .with(enterprise.versions.first.reify, start_of_july, start_of_july + 10.days, nil, nil) expect(updater).to have_received(:split_for_trial) - .with(enterprise, start_of_july + 10.days, start_of_july + 28.days, nil, nil) + .with(enterprise, start_of_july + 10.days, start_of_july + 28.days, nil, nil) end end @@ -133,10 +133,10 @@ describe UpdateBillablePeriods do updater.perform expect(updater).to have_received(:split_for_trial) - .with(enterprise.versions.first.reify, start_of_july, start_of_july + 10.days, nil, nil) + .with(enterprise.versions.first.reify, start_of_july, start_of_july + 10.days, nil, nil) expect(updater).to have_received(:split_for_trial) - .with(enterprise, start_of_july + 10.days, start_of_july + 28.days, nil, nil) + .with(enterprise, start_of_july + 10.days, start_of_july + 28.days, nil, nil) end end @@ -155,7 +155,7 @@ describe UpdateBillablePeriods do allow(updater).to receive(:split_for_trial).once updater.perform expect(updater).to have_received(:split_for_trial) - .with(enterprise, start_of_july, start_of_july + 28.days, nil, nil) + .with(enterprise, start_of_july, start_of_july + 28.days, nil, nil) end end @@ -179,7 +179,7 @@ describe UpdateBillablePeriods do allow(updater).to receive(:split_for_trial).once updater.perform expect(updater).to have_received(:split_for_trial) - .with(enterprise, start_of_july, start_of_july + 28.days, nil, nil) + .with(enterprise, start_of_july, start_of_july + 28.days, nil, nil) end end @@ -201,7 +201,7 @@ describe UpdateBillablePeriods do allow(updater).to receive(:split_for_trial).once updater.perform expect(updater).to have_received(:split_for_trial) - .with(enterprise, start_of_july, start_of_july + 15.days, nil, nil) + .with(enterprise, start_of_july, start_of_july + 15.days, nil, nil) end end end @@ -218,7 +218,7 @@ describe UpdateBillablePeriods do allow(updater).to receive(:split_for_trial).once updater.perform expect(updater).to have_received(:split_for_trial) - .with(enterprise, start_of_july + 10.days, start_of_july + 28.days, nil, nil) + .with(enterprise, start_of_july + 10.days, start_of_july + 28.days, nil, nil) end end @@ -249,7 +249,7 @@ describe UpdateBillablePeriods do allow(updater).to receive(:split_for_trial) updater.perform expect(updater).to have_received(:split_for_trial) - .with(enterprise, start_of_july, start_of_july + 20.days, nil, nil) + .with(enterprise, start_of_july, start_of_july + 20.days, nil, nil) end end end @@ -270,7 +270,7 @@ describe UpdateBillablePeriods do it "calls update_billable_period once for the entire period" do expect(updater).to have_received(:update_billable_period) - .with(enterprise, begins_at, ends_at, false) + .with(enterprise, begins_at, ends_at, false) end end @@ -285,7 +285,7 @@ describe UpdateBillablePeriods do it "calls update_billable_period once for the entire period" do expect(updater).to have_received(:update_billable_period) - .with(enterprise, begins_at, ends_at, false) + .with(enterprise, begins_at, ends_at, false) end end @@ -302,7 +302,7 @@ describe UpdateBillablePeriods do it "calls update_billable_period once for the entire period" do expect(updater).to have_received(:update_billable_period) - .with(enterprise, begins_at, ends_at, false) + .with(enterprise, begins_at, ends_at, false) end end @@ -316,12 +316,12 @@ describe UpdateBillablePeriods do it "calls update_billable_period once for the trial period" do expect(updater).to have_received(:update_billable_period) - .with(enterprise, begins_at, trial_expiry, true) + .with(enterprise, begins_at, trial_expiry, true) end it "calls update_billable_period once for the non-trial period" do expect(updater).to have_received(:update_billable_period) - .with(enterprise, trial_expiry, ends_at, false) + .with(enterprise, trial_expiry, ends_at, false) end end @@ -335,7 +335,7 @@ describe UpdateBillablePeriods do it "calls update_billable_period once for the entire (trial) period" do expect(updater).to have_received(:update_billable_period) - .with(enterprise, begins_at, ends_at, true) + .with(enterprise, begins_at, ends_at, true) end end end @@ -354,7 +354,7 @@ describe UpdateBillablePeriods do it "calls update_billable_period once for the entire period" do expect(updater).to have_received(:update_billable_period) - .with(enterprise, begins_at, ends_at, false) + .with(enterprise, begins_at, ends_at, false) end end @@ -368,17 +368,17 @@ describe UpdateBillablePeriods do it "calls update_billable_period once for the non-trial period before the trial" do expect(updater).to have_received(:update_billable_period) - .with(enterprise, begins_at, trial_start, false) + .with(enterprise, begins_at, trial_start, false) end it "calls update_billable_period once for the trial period" do expect(updater).to have_received(:update_billable_period) - .with(enterprise, trial_start, trial_expiry, true) + .with(enterprise, trial_start, trial_expiry, true) end it "calls update_billable_period once for the non-trial period after the trial" do expect(updater).to have_received(:update_billable_period) - .with(enterprise, trial_expiry, ends_at, false) + .with(enterprise, trial_expiry, ends_at, false) end end @@ -392,12 +392,12 @@ describe UpdateBillablePeriods do it "calls update_billable_period once for the non-trial period" do expect(updater).to have_received(:update_billable_period) - .with(enterprise, begins_at, trial_start, false) + .with(enterprise, begins_at, trial_start, false) end it "calls update_billable_period once for the trial period" do expect(updater).to have_received(:update_billable_period) - .with(enterprise, trial_start, ends_at, true) + .with(enterprise, trial_start, ends_at, true) end end end @@ -464,8 +464,8 @@ describe UpdateBillablePeriods do expect{ updater.update_billable_period(enterprise, start_of_july, start_of_july + 20.days, false) }.to change{ existing.reload.updated_at } - .from(start_of_july + 3.days) - .to(start_of_july + 10.days) + .from(start_of_july + 3.days) + .to(start_of_july + 10.days) } end end diff --git a/spec/lib/open_food_network/enterprise_fee_calculator_spec.rb b/spec/lib/open_food_network/enterprise_fee_calculator_spec.rb index 0fb42f3052..5ece3ef7e9 100644 --- a/spec/lib/open_food_network/enterprise_fee_calculator_spec.rb +++ b/spec/lib/open_food_network/enterprise_fee_calculator_spec.rb @@ -228,9 +228,9 @@ module OpenFoodNetwork it "makes fee applicators for a line item" do expect(efc.send(:per_item_enterprise_fee_applicators_for, line_item.variant)) - .to eq [OpenFoodNetwork::EnterpriseFeeApplicator.new(ef1, line_item.variant, 'supplier'), - OpenFoodNetwork::EnterpriseFeeApplicator.new(ef2, line_item.variant, 'distributor'), - OpenFoodNetwork::EnterpriseFeeApplicator.new(ef3, line_item.variant, 'coordinator')] + .to eq [OpenFoodNetwork::EnterpriseFeeApplicator.new(ef1, line_item.variant, 'supplier'), + OpenFoodNetwork::EnterpriseFeeApplicator.new(ef2, line_item.variant, 'distributor'), + OpenFoodNetwork::EnterpriseFeeApplicator.new(ef3, line_item.variant, 'coordinator')] end end @@ -264,9 +264,9 @@ module OpenFoodNetwork it "makes fee applicators for an order" do expect(efc.send(:per_order_enterprise_fee_applicators_for, order)) - .to eq [OpenFoodNetwork::EnterpriseFeeApplicator.new(ef1, nil, 'supplier'), - OpenFoodNetwork::EnterpriseFeeApplicator.new(ef2, nil, 'distributor'), - OpenFoodNetwork::EnterpriseFeeApplicator.new(ef3, nil, 'coordinator')] + .to eq [OpenFoodNetwork::EnterpriseFeeApplicator.new(ef1, nil, 'supplier'), + OpenFoodNetwork::EnterpriseFeeApplicator.new(ef2, nil, 'distributor'), + OpenFoodNetwork::EnterpriseFeeApplicator.new(ef3, nil, 'coordinator')] end end