From 6cb038c3629d69856a0177db0dbe0e94284438fc Mon Sep 17 00:00:00 2001 From: Pau Perez Date: Thu, 1 Feb 2018 09:52:53 +0100 Subject: [PATCH] Autocorrect rubocop Layout/BlockEndNewline cop --- .rubocop_todo.yml | 76 +++++++------------ app/models/order_cycle.rb | 3 +- .../spree/calculator/default_tax_decorator.rb | 3 +- app/models/spree/product_decorator.rb | 6 +- .../column_preferences_controller_spec.rb | 3 +- spec/controllers/shop_controller_spec.rb | 6 +- spec/features/admin/variant_overrides_spec.rb | 9 ++- spec/helpers/enterprises_helper_spec.rb | 12 ++- spec/jobs/update_billable_periods_spec.rb | 3 +- .../enterprise_fee_calculator_spec.rb | 18 +++-- .../lib/open_food_network/permissions_spec.rb | 6 +- .../user_balance_calculator_spec.rb | 30 +++++--- spec/models/order_cycle_spec.rb | 9 ++- spec/models/spree/product_spec.rb | 3 +- spec/models/spree/variant_spec.rb | 9 ++- .../serializers/enterprise_serializer_spec.rb | 3 +- 16 files changed, 109 insertions(+), 90 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 6598d0d940a..f3395c96f44 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,6 +1,6 @@ # This configuration was generated by # `rubocop --auto-gen-config --exclude-limit 1400` -# on 2018-01-20 12:46:57 +0100 using RuboCop version 0.49.1. +# on 2018-02-01 09:48:08 +0100 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 @@ -84,26 +84,6 @@ Layout/AlignParameters: - 'spec/lib/open_food_network/user_balance_calculator_spec.rb' - 'spec/support/request/authentication_workflow.rb' -# Offense count: 41 -# Cop supports --auto-correct. -Layout/BlockEndNewline: - Exclude: - - 'app/models/order_cycle.rb' - - 'app/models/spree/calculator/default_tax_decorator.rb' - - 'app/models/spree/product_decorator.rb' - - 'spec/controllers/admin/column_preferences_controller_spec.rb' - - 'spec/controllers/shop_controller_spec.rb' - - 'spec/features/admin/variant_overrides_spec.rb' - - 'spec/helpers/enterprises_helper_spec.rb' - - 'spec/jobs/update_billable_periods_spec.rb' - - 'spec/lib/open_food_network/enterprise_fee_calculator_spec.rb' - - 'spec/lib/open_food_network/permissions_spec.rb' - - 'spec/lib/open_food_network/user_balance_calculator_spec.rb' - - 'spec/models/order_cycle_spec.rb' - - 'spec/models/spree/product_spec.rb' - - 'spec/models/spree/variant_spec.rb' - - 'spec/serializers/enterprise_serializer_spec.rb' - # Offense count: 8 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyle, SupportedStyles, IndentOneStep, IndentationWidth. @@ -138,7 +118,7 @@ Layout/ElseAlignment: - 'app/serializers/api/admin/order_cycle_serializer.rb' - 'lib/open_food_network/sales_tax_report.rb' -# Offense count: 209 +# Offense count: 210 # Cop supports --auto-correct. Layout/EmptyLines: Exclude: @@ -228,6 +208,7 @@ Layout/EmptyLines: - 'spec/controllers/enterprises_controller_spec.rb' - 'spec/controllers/shop_controller_spec.rb' - 'spec/controllers/spree/admin/payments_controller_spec.rb' + - 'spec/controllers/spree/api/products_controller_spec.rb' - 'spec/controllers/spree/checkout_controller_spec.rb' - 'spec/controllers/spree/orders_controller_spec.rb' - 'spec/factories.rb' @@ -531,7 +512,7 @@ Layout/IndentationConsistency: - 'spec/models/spree/line_item_spec.rb' - 'spec/models/spree/product_spec.rb' -# Offense count: 19 +# Offense count: 18 # Cop supports --auto-correct. # Configuration parameters: Width, IgnoredPatterns. Layout/IndentationWidth: @@ -544,7 +525,6 @@ Layout/IndentationWidth: - 'app/serializers/api/admin/for_order_cycle/supplied_product_serializer.rb' - 'app/serializers/api/admin/order_cycle_serializer.rb' - 'lib/discourse/single_sign_on.rb' - - 'serializer.rb' - 'spec/features/consumer/shopping/variant_overrides_spec.rb' - 'spec/helpers/admin/business_model_configuration_helper_spec.rb' - 'spec/helpers/groups_helper_spec.rb' @@ -819,7 +799,7 @@ Layout/SpaceBeforeComma: - 'spec/features/admin/bulk_order_management_spec.rb' - 'spec/features/admin/bulk_product_update_spec.rb' -# Offense count: 5 +# Offense count: 6 # Cop supports --auto-correct. # Configuration parameters: AllowForAlignment. Layout/SpaceBeforeFirstArg: @@ -827,6 +807,7 @@ Layout/SpaceBeforeFirstArg: - 'spec/factories.rb' - 'spec/features/admin/bulk_product_update_spec.rb' - 'spec/features/admin/product_import_spec.rb' + - 'spec/features/consumer/multilingual_spec.rb' - 'spec/models/enterprise_fee_spec.rb' # Offense count: 1 @@ -923,7 +904,7 @@ Layout/SpaceInsideBrackets: - 'spec/lib/open_food_network/users_and_enterprises_report_spec.rb' - 'spec/performance/orders_controller_spec.rb' -# Offense count: 782 +# Offense count: 778 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyle, SupportedStyles, EnforcedStyleForEmptyBraces, SupportedStylesForEmptyBraces. # SupportedStyles: space, no_space, compact @@ -979,7 +960,6 @@ Layout/SpaceInsideHashLiteralBraces: - 'spec/controllers/admin/business_model_configuration_controller_spec.rb' - 'spec/controllers/admin/enterprises_controller_spec.rb' - 'spec/controllers/admin/order_cycles_controller_spec.rb' - - 'spec/controllers/api/enterprises_controller_spec.rb' - 'spec/controllers/api/statuses_controller_spec.rb' - 'spec/controllers/cart_controller_spec.rb' - 'spec/controllers/checkout_controller_spec.rb' @@ -989,7 +969,6 @@ Layout/SpaceInsideHashLiteralBraces: - 'spec/controllers/spree/admin/payments_controller_spec.rb' - 'spec/controllers/spree/admin/products_controller_spec.rb' - 'spec/controllers/spree/admin/reports_controller_spec.rb' - - 'spec/controllers/spree/api/line_items_controller_spec.rb' - 'spec/controllers/spree/api/products_controller_spec.rb' - 'spec/controllers/spree/api/variants_controller_spec.rb' - 'spec/controllers/spree/orders_controller_spec.rb' @@ -1061,12 +1040,14 @@ Layout/Tab: - 'spec/lib/spree/product_filters_spec.rb' - 'spec/models/spree/line_item_spec.rb' -# Offense count: 28 +# Offense count: 67 # Cop supports --auto-correct. Layout/TrailingWhitespace: Exclude: - 'app/models/distributor_shipping_method.rb' + - 'app/models/spree/calculator/default_tax_decorator.rb' - 'app/models/spree/money_decorator.rb' + - 'app/models/spree/product_decorator.rb' - 'app/serializers/api/image_serializer.rb' - 'app/serializers/api/shipping_method_serializer.rb' - 'app/views/json/_current_order.rabl' @@ -1074,10 +1055,21 @@ Layout/TrailingWhitespace: - 'app/views/json/_producer.rabl' - 'app/views/json/partials/_producer.rabl' - 'lib/tasks/dev.rake' + - 'spec/controllers/admin/column_preferences_controller_spec.rb' + - 'spec/controllers/shop_controller_spec.rb' - 'spec/features/admin/enterprise_user_spec.rb' + - 'spec/features/admin/variant_overrides_spec.rb' + - 'spec/helpers/enterprises_helper_spec.rb' + - 'spec/lib/open_food_network/enterprise_fee_calculator_spec.rb' - 'spec/lib/open_food_network/group_buy_report_spec.rb' - 'spec/lib/open_food_network/order_grouper_spec.rb' + - 'spec/lib/open_food_network/permissions_spec.rb' + - 'spec/lib/open_food_network/user_balance_calculator_spec.rb' + - 'spec/models/order_cycle_spec.rb' + - 'spec/models/spree/product_spec.rb' + - 'spec/models/spree/variant_spec.rb' - 'spec/serializers/admin/enterprise_serializer_spec.rb' + - 'spec/serializers/enterprise_serializer_spec.rb' - 'spec/support/request/menu_helper.rb' - 'spec/views/json/producers.json.rabl_spec.rb' @@ -1308,7 +1300,7 @@ Lint/Void: - 'spec/serializers/enterprise_serializer_spec.rb' - 'spec/support/request/web_helper.rb' -# Offense count: 793 +# Offense count: 794 # Configuration parameters: CountComments, ExcludedMethods. Metrics/BlockLength: Max: 672 @@ -1403,15 +1395,6 @@ Rails/FilePath: - 'spec/models/spree/variant_spec.rb' - 'spec/spec_helper.rb' -# Offense count: 2 -# Cop supports --auto-correct. -# Configuration parameters: Include. -# Include: app/models/**/*.rb -Rails/FindBy: - Exclude: - - 'app/models/product_importer.rb' - - 'app/models/variant_override.rb' - # Offense count: 2 # Cop supports --auto-correct. # Configuration parameters: Include. @@ -1569,7 +1552,7 @@ Style/BarePercentLiterals: - 'spec/features/admin/variants_spec.rb' - 'spec/support/request/web_helper.rb' -# Offense count: 208 +# Offense count: 207 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyle, SupportedStyles. # SupportedStyles: braces, no_braces, context_dependent @@ -1650,7 +1633,7 @@ Style/CaseEquality: - 'app/helpers/angular_form_helper.rb' - 'spec/models/spree/payment_spec.rb' -# Offense count: 88 +# Offense count: 87 # Configuration parameters: EnforcedStyle, SupportedStyles. # SupportedStyles: nested, compact Style/ClassAndModuleChildren: @@ -1731,7 +1714,6 @@ Style/ClassAndModuleChildren: - 'lib/open_food_network/reports/report.rb' - 'lib/open_food_network/reports/row.rb' - 'lib/open_food_network/reports/rule.rb' - - 'serializer.rb' - 'spec/controllers/spree/admin/base_controller_spec.rb' - 'spec/lib/open_food_network/reports/report_spec.rb' - 'spec/lib/open_food_network/reports/row_spec.rb' @@ -1881,7 +1863,7 @@ Style/GuardClause: - 'spec/support/request/distribution_helper.rb' - 'spec/support/request/shop_workflow.rb' -# Offense count: 1233 +# Offense count: 1219 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyle, SupportedStyles, UseHashRocketsWithSymbolValues, PreferHashRocketsForNonAlnumEndingSymbols. # SupportedStyles: ruby19, hash_rockets, no_mixed_keys, ruby19_no_mixed_keys @@ -1988,7 +1970,6 @@ Style/HashSyntax: - 'spec/archive/features/consumer/checkout_spec.rb' - 'spec/controllers/admin/bulk_line_items_controller_spec.rb' - 'spec/controllers/admin/stripe_connect_settings_controller_spec.rb' - - 'spec/controllers/api/enterprises_controller_spec.rb' - 'spec/controllers/api/order_cycles_controller_spec.rb' - 'spec/controllers/base_controller_spec.rb' - 'spec/controllers/cart_controller_spec.rb' @@ -1996,7 +1977,6 @@ Style/HashSyntax: - 'spec/controllers/spree/admin/orders_controller_spec.rb' - 'spec/controllers/spree/admin/payment_methods_controller_spec.rb' - 'spec/controllers/spree/admin/payments_controller_spec.rb' - - 'spec/controllers/spree/api/line_items_controller_spec.rb' - 'spec/controllers/spree/api/products_controller_spec.rb' - 'spec/controllers/spree/api/variants_controller_spec.rb' - 'spec/controllers/spree/credit_cards_controller_spec.rb' @@ -2139,14 +2119,13 @@ Style/NestedParenthesizedCalls: - 'spec/controllers/shop_controller_spec.rb' - 'spec/lib/open_food_network/users_and_enterprises_report_spec.rb' -# Offense count: 5 +# Offense count: 4 Style/NestedTernaryOperator: Exclude: - 'app/serializers/api/admin/product_serializer.rb' - 'app/serializers/api/admin/variant_serializer.rb' - 'app/views/spree/api/products/bulk_show.v1.rabl' - 'app/views/spree/api/variants/bulk_show.v1.rabl' - - 'serializer.rb' # Offense count: 3 # Cop supports --auto-correct. @@ -2440,14 +2419,13 @@ Style/SymbolProc: - 'spec/lib/open_food_network/group_buy_report_spec.rb' - 'spec/lib/open_food_network/order_grouper_spec.rb' -# Offense count: 6 +# Offense count: 5 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyle, SupportedStyles, AllowSafeAssignment. # SupportedStyles: require_parentheses, require_no_parentheses, require_parentheses_when_complex Style/TernaryParentheses: Exclude: - 'app/controllers/admin/enterprises_controller.rb' - - 'app/controllers/api/enterprises_controller.rb' - 'app/controllers/spree/admin/payment_methods_controller_decorator.rb' - 'app/controllers/spree/admin/shipping_methods_controller_decorator.rb' diff --git a/app/models/order_cycle.rb b/app/models/order_cycle.rb index 9c2dc9fcef6..b6b2e70e1b9 100644 --- a/app/models/order_cycle.rb +++ b/app/models/order_cycle.rb @@ -38,7 +38,8 @@ class OrderCycle < ActiveRecord::Base joins(:exchanges). merge(Exchange.outgoing). merge(Exchange.with_product(product)). - select('DISTINCT order_cycles.*') } + select('DISTINCT order_cycles.*') + } scope :with_distributor, lambda { |distributor| joins(:exchanges).merge(Exchange.outgoing).merge(Exchange.to_enterprise(distributor)) diff --git a/app/models/spree/calculator/default_tax_decorator.rb b/app/models/spree/calculator/default_tax_decorator.rb index 9a221b361c0..45149b6d4de 100644 --- a/app/models/spree/calculator/default_tax_decorator.rb +++ b/app/models/spree/calculator/default_tax_decorator.rb @@ -20,7 +20,8 @@ def compute_order(order) 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) } + (applicator.enterprise_fee.inherits_tax_category && line_item.product.tax_category == rate.tax_category) + } .sum { |applicator| applicator.enterprise_fee.compute_amount(line_item) } end diff --git a/app/models/spree/product_decorator.rb b/app/models/spree/product_decorator.rb index 0adb746aa41..34a0e687982 100644 --- a/app/models/spree/product_decorator.rb +++ b/app/models/spree/product_decorator.rb @@ -97,12 +97,14 @@ # 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) } + 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') } + where('order_cycles.id IS NOT NULL') + } scope :by_producer, joins(:supplier).order('enterprises.name') scope :by_name, order('name') diff --git a/spec/controllers/admin/column_preferences_controller_spec.rb b/spec/controllers/admin/column_preferences_controller_spec.rb index 19d867d9b86..0c1c33a9bdf 100644 --- a/spec/controllers/admin/column_preferences_controller_spec.rb +++ b/spec/controllers/admin/column_preferences_controller_spec.rb @@ -16,7 +16,8 @@ { id: column_preference.id, user_id: user1.id, action_name: "enterprises_index", column_name: 'name', visible: false }, { id: nil, user_id: user1.id, action_name: "enterprises_index", column_name: 'producer', visible: true }, { id: nil, user_id: user1.id, action_name: "enterprises_index", column_name: 'status', visible: true } - ] } + ] + } context "where I don't own the preferences submitted" do before do diff --git a/spec/controllers/shop_controller_spec.rb b/spec/controllers/shop_controller_spec.rb index a50895e5fee..52c0bd4174c 100644 --- a/spec/controllers/shop_controller_spec.rb +++ b/spec/controllers/shop_controller_spec.rb @@ -143,11 +143,13 @@ let!(:tag_rule) { create(:filter_products_tag_rule, enterprise: distributor, preferred_customer_tags: "member", - preferred_variant_tags: "members-only") } + preferred_variant_tags: "members-only") + } let!(:default_tag_rule) { create(:filter_products_tag_rule, enterprise: distributor, is_default: true, - preferred_variant_tags: "members-only") } + preferred_variant_tags: "members-only") + } let(:product1) { { "id" => 1, "name" => 'product 1', "variants" => [{ "id" => 4, "tag_list" => ["members-only"] }] } } let(:product2) { { "id" => 2, "name" => 'product 2', "variants" => [{ "id" => 5, "tag_list" => ["members-only"] }, {"id" => 9, "tag_list" => ["something"]}] } } let(:product3) { { "id" => 3, "name" => 'product 3', "variants" => [{ "id" => 6, "tag_list" => ["something-else"] }] } } diff --git a/spec/features/admin/variant_overrides_spec.rb b/spec/features/admin/variant_overrides_spec.rb index 9064913868f..853104711cc 100644 --- a/spec/features/admin/variant_overrides_spec.rb +++ b/spec/features/admin/variant_overrides_spec.rb @@ -16,9 +16,11 @@ let!(:producer_related) { create(:supplier_enterprise) } let!(:producer_unrelated) { create(:supplier_enterprise) } let!(:er1) { create(:enterprise_relationship, parent: producer, child: hub, - permissions_list: [:create_variant_overrides]) } + permissions_list: [:create_variant_overrides]) + } let!(:er2) { create(:enterprise_relationship, parent: producer_related, child: hub, - permissions_list: [:create_variant_overrides]) } + permissions_list: [:create_variant_overrides]) + } context "as an enterprise user" do let(:user) { create_enterprise_user enterprises: [hub, producer_managed] } @@ -26,7 +28,8 @@ describe "selecting a hub" do let!(:er1) { create(:enterprise_relationship, parent: hub2, child: producer_managed, - permissions_list: [:add_to_order_cycle]) } # This er should not confer ability to create VOs for hub2 + permissions_list: [:add_to_order_cycle]) + } # This er should not confer ability to create VOs for hub2 it "displays a list of hub choices (ie. only those managed by the user)" do visit spree.admin_path diff --git a/spec/helpers/enterprises_helper_spec.rb b/spec/helpers/enterprises_helper_spec.rb index b00dad88457..68a3ad09066 100644 --- a/spec/helpers/enterprises_helper_spec.rb +++ b/spec/helpers/enterprises_helper_spec.rb @@ -35,11 +35,13 @@ let!(:tag_rule) { create(:filter_shipping_methods_tag_rule, enterprise: distributor, preferred_customer_tags: "local", - preferred_shipping_method_tags: "local-delivery") } + preferred_shipping_method_tags: "local-delivery") + } let!(:default_tag_rule) { create(:filter_shipping_methods_tag_rule, enterprise: distributor, is_default: true, - preferred_shipping_method_tags: "local-delivery") } + preferred_shipping_method_tags: "local-delivery") + } let!(:tagged_sm) { sm1 } let!(:untagged_sm) { sm2 } @@ -142,11 +144,13 @@ let!(:tag_rule) { create(:filter_payment_methods_tag_rule, enterprise: distributor, preferred_customer_tags: "trusted", - preferred_payment_method_tags: "trusted") } + preferred_payment_method_tags: "trusted") + } let!(:default_tag_rule) { create(:filter_payment_methods_tag_rule, enterprise: distributor, is_default: true, - preferred_payment_method_tags: "trusted") } + preferred_payment_method_tags: "trusted") + } let(:tagged_pm) { pm1 } let(:untagged_pm) { pm2 } diff --git a/spec/jobs/update_billable_periods_spec.rb b/spec/jobs/update_billable_periods_spec.rb index 449e457cd6b..5024fd6dac1 100644 --- a/spec/jobs/update_billable_periods_spec.rb +++ b/spec/jobs/update_billable_periods_spec.rb @@ -413,7 +413,8 @@ def travel_to(time) double(:order, total: 10), double(:order, total: 20), double(:order, total: 30) - ]} + ] + } end context "when the account invoice is already_complete" do 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 5ece3ef7e9b..01b97346f79 100644 --- a/spec/lib/open_food_network/enterprise_fee_calculator_spec.rb +++ b/spec/lib/open_food_network/enterprise_fee_calculator_spec.rb @@ -19,9 +19,11 @@ module OpenFoodNetwork describe "supplier fees" do let!(:exchange1) { create(:exchange, order_cycle: order_cycle, sender: supplier1, receiver: coordinator, incoming: true, - enterprise_fees: [enterprise_fee1], variants: [product1.master]) } + enterprise_fees: [enterprise_fee1], variants: [product1.master]) + } let!(:exchange2) { create(:exchange, order_cycle: order_cycle, sender: supplier2, receiver: coordinator, incoming: true, - enterprise_fees: [enterprise_fee2], variants: [product2.master]) } + enterprise_fees: [enterprise_fee2], variants: [product2.master]) + } it "calculates via regular computation" do EnterpriseFeeCalculator.new(distributor, order_cycle).fees_for(product1.master).should == 20 @@ -36,7 +38,8 @@ module OpenFoodNetwork describe "coordinator fees" do let!(:exchange) { create(:exchange, order_cycle: order_cycle, sender: coordinator, receiver: distributor, incoming: false, - enterprise_fees: [], variants: [product1.master]) } + enterprise_fees: [], variants: [product1.master]) + } before do order_cycle.coordinator_fees = [enterprise_fee1, enterprise_fee2, enterprise_fee3] @@ -53,7 +56,8 @@ module OpenFoodNetwork describe "distributor fees" do let!(:exchange) { create(:exchange, order_cycle: order_cycle, sender: coordinator, receiver: distributor, incoming: false, - enterprise_fees: [enterprise_fee1, enterprise_fee2, enterprise_fee3], variants: [product1.master]) } + enterprise_fees: [enterprise_fee1, enterprise_fee2, enterprise_fee3], variants: [product1.master]) + } it "sums via regular computation" do EnterpriseFeeCalculator.new(distributor, order_cycle).fees_for(product1.master).should == 23 @@ -68,7 +72,8 @@ module OpenFoodNetwork describe "summing percentage fees for the variant" do let!(:enterprise_fee1) { create(:enterprise_fee, amount: 20, fee_type: "admin", calculator: ::Calculator::FlatPercentPerItem.new(preferred_flat_percent: 20)) } let!(:exchange) { create(:exchange, order_cycle: order_cycle, sender: coordinator, receiver: distributor, incoming: false, - enterprise_fees: [enterprise_fee1], variants: [product1.master]) } + enterprise_fees: [enterprise_fee1], variants: [product1.master]) + } it "sums via regular computation" do EnterpriseFeeCalculator.new(distributor, order_cycle).fees_for(product1.master).should == 2.00 @@ -89,7 +94,8 @@ module OpenFoodNetwork let!(:exchange) { create(:exchange, order_cycle: order_cycle, sender: coordinator, receiver: distributor, incoming: false, enterprise_fees: [ef_admin, ef_sales, ef_packing, ef_transport, ef_fundraising], - variants: [product1.master]) } + variants: [product1.master]) + } describe "regular computation" do it "returns a breakdown of fees" do diff --git a/spec/lib/open_food_network/permissions_spec.rb b/spec/lib/open_food_network/permissions_spec.rb index a26db2aa986..5e96a22080b 100644 --- a/spec/lib/open_food_network/permissions_spec.rb +++ b/spec/lib/open_food_network/permissions_spec.rb @@ -107,7 +107,8 @@ module OpenFoodNetwork let!(:hub) { create(:distributor_enterprise) } let!(:producer) { create(:supplier_enterprise) } let!(:er) { create(:enterprise_relationship, parent: producer, child: hub, - permissions_list: [:create_variant_overrides]) } + permissions_list: [:create_variant_overrides]) + } before do permissions.stub(:managed_enterprises) { Enterprise.where(id: hub.id) } @@ -139,7 +140,8 @@ module OpenFoodNetwork describe "hubs connected to the user by relationships only" do let!(:producer_managed) { create(:supplier_enterprise) } let!(:er_oc) { create(:enterprise_relationship, parent: hub, child: producer_managed, - permissions_list: [:add_to_order_cycle, :create_variant_overrides]) } + permissions_list: [:add_to_order_cycle, :create_variant_overrides]) + } before do permissions.stub(:managed_enterprises) { Enterprise.where(id: producer_managed.id) } diff --git a/spec/lib/open_food_network/user_balance_calculator_spec.rb b/spec/lib/open_food_network/user_balance_calculator_spec.rb index 7ff095d83a8..f4bb92a6687 100644 --- a/spec/lib/open_food_network/user_balance_calculator_spec.rb +++ b/spec/lib/open_food_network/user_balance_calculator_spec.rb @@ -11,14 +11,18 @@ module OpenFoodNetwork let!(:o1) { create(:order_with_totals_and_distribution, user: user1, distributor: hub1, - completed_at: 1.day.ago) } #total=10 + completed_at: 1.day.ago) + } #total=10 let!(:o2) { create(:order_with_totals_and_distribution, user: user1, distributor: hub1, - completed_at: 1.day.ago) } #total=10 + completed_at: 1.day.ago) + } #total=10 let!(:p1) { create(:payment, order: o1, amount: 15.00, - state: "completed") } + state: "completed") + } let!(:p2) { create(:payment, order: o2, amount: 2.00, - state: "completed") } + state: "completed") + } it "finds the correct balance for this email and enterprise" do UserBalanceCalculator.new(o1.email, hub1).balance.should == -3 @@ -28,9 +32,11 @@ module OpenFoodNetwork let!(:hub2) { create(:distributor_enterprise) } let!(:o3) { create(:order_with_totals_and_distribution, user: user1, distributor: hub2, - completed_at: 1.day.ago) } #total=10 + completed_at: 1.day.ago) + } #total=10 let!(:p3) { create(:payment, order: o3, amount: 15.00, - state: "completed") } + state: "completed") + } it "does not find the balance for other enterprises" do UserBalanceCalculator.new(o3.email, hub2).balance.should == 5 @@ -41,9 +47,11 @@ module OpenFoodNetwork let!(:user2) { create(:user) } let!(:o4) { create(:order_with_totals_and_distribution, user: user2, distributor: hub1, - completed_at: 1.day.ago) } #total=10 + completed_at: 1.day.ago) + } #total=10 let!(:p3) { create(:payment, order: o4, amount: 20.00, - state: "completed") } + state: "completed") + } it "does not find the balance for other users" do UserBalanceCalculator.new(o4.email, hub1).balance.should == 10 @@ -53,9 +61,11 @@ module OpenFoodNetwork context "with canceled orders" do let!(:o4) { create(:order_with_totals_and_distribution, user: user1, distributor: hub1, - completed_at: 1.day.ago, state: "canceled") } #total=10 + completed_at: 1.day.ago, state: "canceled") + } #total=10 let!(:p4) { create(:payment, order: o4, amount: 20.00, - state: "completed") } + state: "completed") + } it "does not include canceled orders in the balance" do UserBalanceCalculator.new(o4.email, hub1).balance.should == -3 diff --git a/spec/models/order_cycle_spec.rb b/spec/models/order_cycle_spec.rb index bdff9b45453..7a42f941643 100644 --- a/spec/models/order_cycle_spec.rb +++ b/spec/models/order_cycle_spec.rb @@ -196,11 +196,14 @@ let(:d1) { create(:enterprise) } let(:d2) { create(:enterprise) } let!(:e0) { create(:exchange, incoming: true, - order_cycle: oc, sender: create(:enterprise), receiver: oc.coordinator) } + order_cycle: oc, sender: create(:enterprise), receiver: oc.coordinator) + } let!(:e1) { create(:exchange, incoming: false, - order_cycle: oc, sender: oc.coordinator, receiver: d1) } + order_cycle: oc, sender: oc.coordinator, receiver: d1) + } let!(:e2) { create(:exchange, incoming: false, - order_cycle: oc, sender: oc.coordinator, receiver: d2) } + order_cycle: oc, sender: oc.coordinator, receiver: d2) + } let!(:p0) { create(:simple_product) } let!(:p1) { create(:simple_product) } let!(:p1_v_deleted) { create(:variant, product: p1, deleted_at: Time.zone.now) } diff --git a/spec/models/spree/product_spec.rb b/spec/models/spree/product_spec.rb index d9703b5f95b..fbb64ab3a70 100644 --- a/spec/models/spree/product_spec.rb +++ b/spec/models/spree/product_spec.rb @@ -512,7 +512,8 @@ module Spree let!(:p) { create(:simple_product, variant_unit: 'weight', variant_unit_scale: 1, - variant_unit_name: nil) } + variant_unit_name: nil) + } let!(:ot_volume) { create(:option_type, name: 'unit_volume', presentation: 'Volume') } diff --git a/spec/models/spree/variant_spec.rb b/spec/models/spree/variant_spec.rb index 046be2bfd22..eae3767573b 100644 --- a/spec/models/spree/variant_spec.rb +++ b/spec/models/spree/variant_spec.rb @@ -91,11 +91,14 @@ module Spree let(:v_external) { create(:variant, product: p_external) } let!(:ex_in) { create(:exchange, order_cycle: oc, sender: s, receiver: oc.coordinator, - incoming: true, variants: [v1, v2]) } + incoming: true, variants: [v1, v2]) + } let!(:ex_out1) { create(:exchange, order_cycle: oc, sender: oc.coordinator, receiver: d1, - incoming: false, variants: [v1]) } + incoming: false, variants: [v1]) + } let!(:ex_out2) { create(:exchange, order_cycle: oc, sender: oc.coordinator, receiver: d2, - incoming: false, variants: [v2]) } + incoming: false, variants: [v2]) + } it "returns variants in the order cycle and distributor" do p1.variants.for_distribution(oc, d1).should == [v1] diff --git a/spec/serializers/enterprise_serializer_spec.rb b/spec/serializers/enterprise_serializer_spec.rb index bea2672157e..10f41a16dd6 100644 --- a/spec/serializers/enterprise_serializer_spec.rb +++ b/spec/serializers/enterprise_serializer_spec.rb @@ -10,7 +10,8 @@ current_distributed_taxons: {enterprise.id => [123]}, supplied_taxons: {enterprise.id => [456]}, shipping_method_services: {}, - relatives: {enterprise.id => {producers: [123], distributors: [456]}}) } + relatives: {enterprise.id => {producers: [123], distributors: [456]}}) + } it "serializes an enterprise" do serializer.to_json.should match enterprise.name