diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml
index e383738009..3d5daf5f69 100644
--- a/.rubocop_todo.yml
+++ b/.rubocop_todo.yml
@@ -1,19 +1,11 @@
# This configuration was generated by
# `rubocop --auto-gen-config --exclude-limit 1400`
-# on 2021-03-25 06:59:27 UTC using RuboCop version 1.12.0.
+# on 2021-06-17 21:32:23 UTC using RuboCop version 1.17.0.
# 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
# versions of RuboCop, may require this file to be generated again.
-# Offense count: 2
-# Cop supports --auto-correct.
-# Configuration parameters: TreatCommentsAsGroupSeparators, ConsiderPunctuation, Include.
-# Include: **/*.gemfile, **/Gemfile, **/gems.rb
-Bundler/OrderedGems:
- Exclude:
- - 'Gemfile'
-
# Offense count: 4
# Configuration parameters: Include.
# Include: **/*.gemspec
@@ -24,170 +16,12 @@ Gemspec/RequiredRubyVersion:
- 'engines/order_management/order_management.gemspec'
- 'engines/web/web.gemspec'
-# Offense count: 2
+# Offense count: 25
# Cop supports --auto-correct.
-# Configuration parameters: EnforcedStyle, IndentationWidth.
-# SupportedStyles: with_first_argument, with_fixed_indentation
-Layout/ArgumentAlignment:
- Exclude:
- - 'spec/features/admin/order_cycles/simple_spec.rb'
-
-# Offense count: 5
-# Cop supports --auto-correct.
-# Configuration parameters: EnforcedStyleAlignWith, Severity.
-# SupportedStylesAlignWith: start_of_line, begin
-Layout/BeginEndAlignment:
- Exclude:
- - 'app/controllers/application_controller.rb'
- - 'app/controllers/spree/admin/reports_controller.rb'
- - 'app/jobs/job_logger.rb'
- - 'app/models/spree/address.rb'
- - 'app/models/spree/credit_card.rb'
-
-# Offense count: 2
-# Cop supports --auto-correct.
-# Configuration parameters: EnforcedStyleAlignWith.
-# SupportedStylesAlignWith: either, start_of_block, start_of_line
-Layout/BlockAlignment:
- Exclude:
- - 'spec/features/admin/order_cycles/complex_creating_specific_time_spec.rb'
- - 'spec/features/admin/order_cycles/simple_spec.rb'
-
-# Offense count: 2
-# Cop supports --auto-correct.
-Layout/CommentIndentation:
- Exclude:
- - 'spec/features/admin/order_cycles/simple_spec.rb'
-
-# Offense count: 1
-# Cop supports --auto-correct.
-Layout/EmptyLineAfterMagicComment:
- Exclude:
- - 'spec/features/admin/configuration/tax_rates_spec.rb'
-
-# Offense count: 2
-# Cop supports --auto-correct.
-# Configuration parameters: EmptyLineBetweenMethodDefs, EmptyLineBetweenClassDefs, EmptyLineBetweenModuleDefs, AllowAdjacentOneLineDefs, NumberOfEmptyLines.
-Layout/EmptyLineBetweenDefs:
- Exclude:
- - 'app/controllers/api/enterprise_attachment_controller.rb'
- - 'spec/controllers/spree/admin/base_controller_spec.rb'
-
-# Offense count: 1
-# Cop supports --auto-correct.
-Layout/EmptyLines:
- Exclude:
- - 'spec/controllers/spree/admin/reports_controller_spec.rb'
-
-# Offense count: 5
-# Cop supports --auto-correct.
-# Configuration parameters: AllowAliasSyntax, AllowedMethods.
-# AllowedMethods: alias_method, public, protected, private
-Layout/EmptyLinesAroundAttributeAccessor:
- Exclude:
- - 'app/models/spree/shipment.rb'
- - 'lib/open_food_network/customers_report.rb'
- - 'lib/open_food_network/packing_report.rb'
- - 'lib/open_food_network/payments_report.rb'
- - 'lib/open_food_network/users_and_enterprises_report.rb'
-
-# Offense count: 1
-# Cop supports --auto-correct.
-# Configuration parameters: EnforcedStyle.
-# SupportedStyles: empty_lines, no_empty_lines
-Layout/EmptyLinesAroundBlockBody:
- Exclude:
- - 'spec/features/admin/payment_method_spec.rb'
-
-# Offense count: 4
-# Cop supports --auto-correct.
-# Configuration parameters: EnforcedStyle, IndentationWidth.
-# SupportedStyles: special_inside_parentheses, consistent, align_brackets
-Layout/FirstArrayElementIndentation:
- Exclude:
- - 'spec/lib/open_food_network/order_cycle_management_report_spec.rb'
-
-# Offense count: 7
-# Cop supports --auto-correct.
-# Configuration parameters: AllowMultipleStyles, EnforcedHashRocketStyle, EnforcedColonStyle, EnforcedLastArgumentHashStyle.
-# SupportedHashRocketStyles: key, separator, table
-# SupportedColonStyles: key, separator, table
-# SupportedLastArgumentHashStyles: always_inspect, always_ignore, ignore_implicit, ignore_explicit
-Layout/HashAlignment:
- Exclude:
- - 'app/controllers/admin/order_cycles_controller.rb'
- - 'spec/features/admin/adjustments_spec.rb'
- - 'spec/models/spree/adjustment_spec.rb'
- - 'spec/models/spree/order_spec.rb'
-
-# Offense count: 1
-# Cop supports --auto-correct.
-# Configuration parameters: EnforcedStyle.
-# SupportedStyles: normal, indented_internal_methods
-Layout/IndentationConsistency:
- Exclude:
- - 'spec/features/admin/order_cycles/complex_creating_specific_time_spec.rb'
-
-# Offense count: 2
-# Cop supports --auto-correct.
-Layout/MultilineBlockLayout:
- Exclude:
- - 'spec/controllers/spree/orders_controller_spec.rb'
- - 'spec/services/process_payment_intent_spec.rb'
-
-# Offense count: 2
-# Cop supports --auto-correct.
-# Configuration parameters: EnforcedStyle.
-# SupportedStyles: symmetrical, new_line, same_line
-Layout/MultilineMethodCallBraceLayout:
- Exclude:
- - 'spec/controllers/spree/orders_controller_spec.rb'
- - 'spec/services/process_payment_intent_spec.rb'
-
-# Offense count: 4
-# Cop supports --auto-correct.
-Layout/RescueEnsureAlignment:
- Exclude:
- - 'app/controllers/application_controller.rb'
- - 'app/controllers/spree/admin/reports_controller.rb'
- - 'app/models/spree/address.rb'
- - 'app/models/spree/credit_card.rb'
-
-# Offense count: 2
-# Cop supports --auto-correct.
-Layout/SpaceAroundMethodCallOperator:
- Exclude:
- - 'spec/controllers/api/orders_controller_spec.rb'
- - 'spec/controllers/api/shipments_controller_spec.rb'
-
-# Offense count: 2
-# Cop supports --auto-correct.
-# Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBrackets.
-# SupportedStyles: space, no_space, compact
-# SupportedStylesForEmptyBrackets: space, no_space
-Layout/SpaceInsideArrayLiteralBrackets:
- Exclude:
- - 'spec/controllers/spree/admin/reports_controller_spec.rb'
-
-# Offense count: 4
-# Cop supports --auto-correct.
-# Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBraces.
-# SupportedStyles: space, no_space, compact
-# SupportedStylesForEmptyBraces: space, no_space
-Layout/SpaceInsideHashLiteralBraces:
- Exclude:
- - 'spec/services/embedded_page_service_spec.rb'
-
-# Offense count: 10
-# Cop supports --auto-correct.
-# Configuration parameters: AllowInHeredoc.
-Layout/TrailingWhitespace:
- Exclude:
- - 'spec/features/admin/order_cycles/simple_spec.rb'
- - 'spec/features/consumer/shopping/unit_price_spec.rb'
- - 'spec/support/features/datepicker_helper.rb'
- - 'spec/support/request/web_helper.rb'
- - 'spec/views/spree/orders/edit.html.haml_spec.rb'
+# Configuration parameters: AutoCorrect, AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
+# URISchemes: http, https
+Layout/LineLength:
+ Max: 148
# Offense count: 15
# Configuration parameters: AllowedMethods.
@@ -222,12 +56,16 @@ Lint/FloatComparison:
- 'app/models/product_import/entry_validator.rb'
- 'app/models/spree/gateway/pay_pal_express.rb'
-# Offense count: 5
+# Offense count: 1
Lint/IneffectiveAccessModifier:
Exclude:
- - 'app/models/column_preference.rb'
- 'app/models/spree/user.rb'
- - 'app/services/mail_configuration.rb'
+
+# Offense count: 2
+Lint/MissingSuper:
+ Exclude:
+ - 'app/components/distributor_title_component.rb'
+ - 'app/components/example_component.rb'
# Offense count: 1
# Cop supports --auto-correct.
@@ -238,18 +76,9 @@ Lint/RedundantSafeNavigation:
- 'app/models/spree/payment.rb'
# Offense count: 1
-# Cop supports --auto-correct.
-Lint/ScriptPermission:
+Lint/UselessAssignment:
Exclude:
- - '.simplecov'
-
-# Offense count: 2
-# Cop supports --auto-correct.
-# Configuration parameters: ContextCreatingMethods, MethodCreatingMethods.
-Lint/UselessAccessModifier:
- Exclude:
- - 'app/models/column_preference.rb'
- - 'app/services/mail_configuration.rb'
+ - 'app/models/spree/credit_card.rb'
# Offense count: 5
# Cop supports --auto-correct.
@@ -259,12 +88,48 @@ Lint/UselessMethodDefinition:
- 'app/controllers/spree/user_registrations_controller.rb'
- 'app/models/spree/gateway.rb'
+# Offense count: 13
+# Configuration parameters: IgnoredMethods, CountRepeatedAttributes.
+Metrics/AbcSize:
+ Max: 25
+
+# Offense count: 3
+# Configuration parameters: CountComments, CountAsOne, ExcludedMethods, IgnoredMethods.
+# IgnoredMethods: refine
+Metrics/BlockLength:
+ Max: 30
+
+# Offense count: 3
+# Configuration parameters: CountComments, CountAsOne.
+Metrics/ClassLength:
+ Max: 122
+
+# Offense count: 1
+# Configuration parameters: IgnoredMethods.
+Metrics/CyclomaticComplexity:
+ Max: 9
+
+# Offense count: 10
+# Configuration parameters: CountComments, CountAsOne, ExcludedMethods, IgnoredMethods.
+Metrics/MethodLength:
+ Max: 17
+
+# Offense count: 2
+# Configuration parameters: CountComments, CountAsOne.
+Metrics/ModuleLength:
+ Max: 369
+
# Offense count: 2
# Configuration parameters: Max, CountKeywordArgs.
Metrics/ParameterLists:
MaxOptionalParameters: 4
-# Offense count: 10
+# Offense count: 3
+# Configuration parameters: IgnoredMethods.
+Metrics/PerceivedComplexity:
+ Max: 10
+
+# Offense count: 9
Naming/AccessorMethodName:
Exclude:
- 'app/controllers/spree/admin/taxonomies_controller.rb'
@@ -282,42 +147,23 @@ Naming/HeredocDelimiterNaming:
Exclude:
- 'app/models/content_configuration.rb'
-# Offense count: 4
+# Offense count: 5
# Configuration parameters: EnforcedStyleForLeadingUnderscores.
# SupportedStylesForLeadingUnderscores: disallowed, required, optional
Naming/MemoizedInstanceVariableName:
Exclude:
- 'app/mailers/producer_mailer.rb'
+ - 'app/models/concerns/balance.rb'
- 'lib/open_food_network/address_finder.rb'
-# Offense count: 23
-# Configuration parameters: NamePrefix, ForbiddenPrefixes, AllowedMethods, MethodDefinitionMacros.
-# NamePrefix: is_, has_, have_
-# ForbiddenPrefixes: is_, has_, have_
-# AllowedMethods: is_a?
-# MethodDefinitionMacros: define_method, define_singleton_method
-Naming/PredicateName:
+# Offense count: 1
+# Configuration parameters: MinNameLength, AllowNamesEndingInNumbers, AllowedNames, ForbiddenNames.
+# AllowedNames: at, by, db, id, in, io, ip, of, on, os, pp, to
+Naming/MethodParameterName:
Exclude:
- - 'app/models/enterprise.rb'
- - 'app/models/enterprise_relationship.rb'
- - 'app/models/order_cycle.rb'
- - 'app/models/spree/ability.rb'
- - 'app/models/spree/adjustment.rb'
- - 'app/models/spree/credit_card.rb'
- - 'app/models/spree/line_item.rb'
- - 'app/models/spree/order.rb'
- - 'app/models/spree/payment_method.rb'
- - 'app/models/spree/preferences/file_configuration.rb'
- - 'app/models/spree/preferences/preferable.rb'
- - 'app/models/spree/shipping_method.rb'
- - 'app/models/spree/user.rb'
- - 'lib/open_food_network/customers_report.rb'
- - 'lib/open_food_network/order_cycle_management_report.rb'
- - 'lib/open_food_network/order_grouper.rb'
- - 'lib/open_food_network/packing_report.rb'
- - 'lib/tasks/data.rake'
+ - 'app/services/process_payment_intent.rb'
-# Offense count: 30
+# Offense count: 34
# Configuration parameters: EnforcedStyle, CheckMethodNames, CheckSymbols, AllowedIdentifiers.
# SupportedStyles: snake_case, normalcase, non_integer
# AllowedIdentifiers: capture3, iso8601, rfc1123_date, rfc822, rfc2822, rfc3339
@@ -332,18 +178,21 @@ Naming/VariableNumber:
- 'spec/factories/stock_location_factory.rb'
- 'spec/features/admin/reports_spec.rb'
- 'spec/models/spree/stock_item_spec.rb'
+ - 'spec/models/spree/tax_rate_spec.rb'
- 'spec/requests/api/orders_spec.rb'
-# Offense count: 9
+# Offense count: 2
# Cop supports --auto-correct.
Rails/ActiveRecordAliases:
Exclude:
- - 'app/models/spree/gateway/pay_pal_express.rb'
- - 'spec/controllers/line_items_controller_spec.rb'
- - 'spec/controllers/spree/orders_controller_spec.rb'
- - 'spec/features/admin/subscriptions_spec.rb'
- - 'spec/features/consumer/shopping/orders_spec.rb'
- - 'spec/requests/api/orders_spec.rb'
+ - 'app/models/spree/order_contents.rb'
+
+# Offense count: 1
+# Configuration parameters: Include.
+# Include: app/models/**/*.rb
+Rails/ActiveRecordOverride:
+ Exclude:
+ - 'app/models/spree/product.rb'
# Offense count: 1
# Cop supports --auto-correct.
@@ -351,12 +200,11 @@ Rails/ApplicationController:
Exclude:
- 'engines/dfc_provider/app/controllers/dfc_provider/api/base_controller.rb'
-# Offense count: 6
+# Offense count: 5
# Cop supports --auto-correct.
Rails/ApplicationJob:
Exclude:
- 'app/jobs/bulk_invoice_job.rb'
- - 'app/jobs/confirm_order_job.rb'
- 'app/jobs/heartbeat_job.rb'
- 'app/jobs/order_cycle_notification_job.rb'
- 'app/jobs/subscription_confirm_job.rb'
@@ -368,12 +216,21 @@ Rails/ApplicationMailer:
Exclude:
- 'app/mailers/spree/base_mailer.rb'
-# Offense count: 3
+# Offense count: 1
+# Cop supports --auto-correct.
+Rails/ApplicationRecord:
+ Exclude:
+ - 'lib/tasks/data/remove_transient_data.rb'
+
+# Offense count: 6
# Cop supports --auto-correct.
# Configuration parameters: NilOrEmpty, NotPresent, UnlessPresent.
Rails/Blank:
Exclude:
+ - 'app/jobs/subscription_placement_job.rb'
+ - 'app/models/spree/order_contents.rb'
- 'app/services/content_sanitizer.rb'
+ - 'engines/order_management/app/services/order_management/stock/package.rb'
- 'lib/stripe/authorize_response_patcher.rb'
# Offense count: 3
@@ -384,14 +241,6 @@ Rails/Date:
- 'app/models/order_cycle.rb'
- 'app/models/spree/credit_card.rb'
-# Offense count: 2
-# Cop supports --auto-correct.
-# Configuration parameters: EnforceForPrefixed.
-Rails/Delegate:
- Exclude:
- - 'app/models/spree/line_item.rb'
- - 'engines/order_management/app/services/order_management/reports/bulk_coop/renderers/html_renderer.rb'
-
# Offense count: 15
# Configuration parameters: EnforcedStyle.
# SupportedStyles: slashes, arguments
@@ -399,10 +248,10 @@ Rails/FilePath:
Exclude:
- 'app/models/product_import/product_importer.rb'
- 'lib/tasks/karma.rake'
- - 'spec/controllers/api/logos_controller_spec.rb'
- - 'spec/controllers/api/product_images_controller_spec.rb'
- - 'spec/controllers/api/promo_images_controller_spec.rb'
- - 'spec/controllers/api/terms_and_conditions_controller_spec.rb'
+ - 'spec/controllers/api/v0/logos_controller_spec.rb'
+ - 'spec/controllers/api/v0/product_images_controller_spec.rb'
+ - 'spec/controllers/api/v0/promo_images_controller_spec.rb'
+ - 'spec/controllers/api/v0/terms_and_conditions_controller_spec.rb'
- 'spec/factories/product_factory.rb'
- 'spec/features/admin/enterprises/images_spec.rb'
- 'spec/models/content_configuration_spec.rb'
@@ -437,7 +286,7 @@ Rails/HasAndBelongsToMany:
- 'app/models/spree/variant.rb'
- 'app/models/spree/zone.rb'
-# Offense count: 41
+# Offense count: 42
# Configuration parameters: Include.
# Include: app/models/**/*.rb
Rails/HasManyOrHasOneDependent:
@@ -456,6 +305,7 @@ Rails/HasManyOrHasOneDependent:
- 'app/models/spree/shipping_category.rb'
- 'app/models/spree/shipping_method.rb'
- 'app/models/spree/stock_item.rb'
+ - 'app/models/spree/tax_rate.rb'
- 'app/models/spree/taxonomy.rb'
- 'app/models/spree/user.rb'
- 'app/models/spree/variant.rb'
@@ -475,31 +325,31 @@ Rails/HelperInstanceVariable:
- 'app/helpers/spree/admin/orders_helper.rb'
- 'app/helpers/spree/orders_helper.rb'
-# Offense count: 38
+# Offense count: 35
# Configuration parameters: Include.
# Include: app/models/**/*.rb
Rails/InverseOf:
Exclude:
- - 'app/models/concerns/line_item_based_adjustment_handling.rb'
- - 'app/models/customer.rb'
- 'app/models/enterprise.rb'
- - 'app/models/enterprise_fee.rb'
- 'app/models/order_cycle.rb'
- 'app/models/spree/adjustment.rb'
- 'app/models/spree/country.rb'
- 'app/models/spree/credit_card.rb'
+ - 'app/models/spree/inventory_unit.rb'
- 'app/models/spree/line_item.rb'
- 'app/models/spree/option_type.rb'
- 'app/models/spree/order.rb'
- 'app/models/spree/payment.rb'
+ - 'app/models/spree/price.rb'
- 'app/models/spree/product.rb'
- 'app/models/spree/shipment.rb'
+ - 'app/models/spree/stock_item.rb'
+ - 'app/models/spree/tax_rate.rb'
- 'app/models/spree/taxonomy.rb'
- - 'app/models/spree/user.rb'
- 'app/models/spree/variant.rb'
- - 'app/models/subscription.rb'
+ - 'app/models/subscription_line_item.rb'
-# Offense count: 35
+# Offense count: 39
# Configuration parameters: Include.
# Include: app/controllers/**/*.rb
Rails/LexicallyScopedActionFilter:
@@ -516,6 +366,7 @@ Rails/LexicallyScopedActionFilter:
- 'app/controllers/spree/admin/payment_methods_controller.rb'
- 'app/controllers/spree/admin/payments_controller.rb'
- 'app/controllers/spree/admin/products_controller.rb'
+ - 'app/controllers/spree/admin/return_authorizations_controller.rb'
- 'app/controllers/spree/admin/search_controller.rb'
- 'app/controllers/spree/admin/shipping_methods_controller.rb'
- 'app/controllers/spree/admin/users_controller.rb'
@@ -537,41 +388,14 @@ Rails/OutputSafety:
- 'lib/spree/money.rb'
- 'spec/features/admin/order_print_ticket_spec.rb'
-# Offense count: 2
+# Offense count: 1
# Cop supports --auto-correct.
-Rails/PluralizationGrammar:
+# Configuration parameters: AutoCorrect.
+Rails/RelativeDateConstant:
Exclude:
- - 'spec/queries/complete_orders_with_balance_spec.rb'
+ - 'lib/tasks/data/remove_transient_data.rb'
-# Offense count: 3
-# Cop supports --auto-correct.
-# Configuration parameters: Include.
-# Include: **/Rakefile, **/*.rake
-Rails/RakeEnvironment:
- Exclude:
- - 'lib/tasks/specs.rake'
-
-# Offense count: 14
-# Cop supports --auto-correct.
-Rails/RedundantForeignKey:
- Exclude:
- - 'app/models/customer.rb'
- - 'app/models/enterprise.rb'
- - 'app/models/enterprise_fee.rb'
- - 'app/models/enterprise_group.rb'
- - 'app/models/spree/order.rb'
- - 'app/models/spree/shipping_method.rb'
- - 'app/models/spree/user.rb'
- - 'app/models/subscription.rb'
-
-# Offense count: 4
-Rails/ReflectionClassName:
- Exclude:
- - 'app/models/customer.rb'
- - 'app/models/enterprise_role.rb'
- - 'app/models/spree/order.rb'
-
-# Offense count: 284
+# Offense count: 301
# Configuration parameters: ForbiddenMethods, AllowedMethods.
# ForbiddenMethods: decrement!, decrement_counter, increment!, increment_counter, insert, insert!, insert_all, insert_all!, toggle!, touch, touch_all, update_all, update_attribute, update_column, update_columns, update_counters, upsert, upsert_all
Rails/SkipsModelValidations:
@@ -589,10 +413,13 @@ Rails/SkipsModelValidations:
- 'app/models/product_import/inventory_reset_strategy.rb'
- 'app/models/proxy_order.rb'
- 'app/models/spree/address.rb'
+ - 'app/models/spree/adjustment.rb'
- 'app/models/spree/credit_card.rb'
- 'app/models/spree/gateway/pay_pal_express.rb'
- 'app/models/spree/inventory_unit.rb'
+ - 'app/models/spree/item_adjustments.rb'
- 'app/models/spree/order.rb'
+ - 'app/models/spree/order/checkout.rb'
- 'app/models/spree/payment.rb'
- 'app/models/spree/product.rb'
- 'app/models/spree/shipment.rb'
@@ -604,28 +431,30 @@ Rails/SkipsModelValidations:
- 'app/models/subscription.rb'
- 'app/models/variant_override.rb'
- 'app/services/order_factory.rb'
- - 'app/services/process_payment_intent.rb'
- 'engines/order_management/app/services/order_management/order/updater.rb'
- 'engines/order_management/spec/services/order_management/reports/enterprise_fee_summary/report_service_spec.rb'
- 'engines/order_management/spec/services/order_management/subscriptions/stripe_payment_setup_spec.rb'
- - 'lib/spree/core/calculated_adjustments.rb'
+ - 'lib/spree/core/controller_helpers/order.rb'
- 'lib/tasks/data/anonymize_data.rake'
- 'lib/tasks/sample_data/product_factory.rb'
- 'lib/tasks/users.rake'
+ - 'spec/controllers/admin/bulk_line_items_controller_spec.rb'
- 'spec/controllers/admin/customers_controller_spec.rb'
- 'spec/controllers/admin/subscription_line_items_controller_spec.rb'
- 'spec/controllers/admin/variant_overrides_controller_spec.rb'
- - 'spec/controllers/api/order_cycles_controller_spec.rb'
- - 'spec/controllers/api/orders_controller_spec.rb'
- - 'spec/controllers/api/products_controller_spec.rb'
- - 'spec/controllers/api/shipments_controller_spec.rb'
- - 'spec/controllers/api/variants_controller_spec.rb'
+ - 'spec/controllers/api/v0/order_cycles_controller_spec.rb'
+ - 'spec/controllers/api/v0/orders_controller_spec.rb'
+ - 'spec/controllers/api/v0/products_controller_spec.rb'
+ - 'spec/controllers/api/v0/shipments_controller_spec.rb'
+ - 'spec/controllers/api/v0/variants_controller_spec.rb'
- 'spec/controllers/checkout_controller_spec.rb'
- 'spec/controllers/enterprises_controller_spec.rb'
- 'spec/controllers/spree/admin/orders/invoices_spec.rb'
+ - 'spec/controllers/spree/admin/orders/payments/payments_controller_spec.rb'
- 'spec/controllers/spree/admin/overview_controller_spec.rb'
- 'spec/controllers/spree/admin/payment_methods_controller_spec.rb'
- 'spec/controllers/spree/credit_cards_controller_spec.rb'
+ - 'spec/controllers/spree/orders_controller_spec.rb'
- 'spec/factories.rb'
- 'spec/factories/order_factory.rb'
- 'spec/factories/shipment_factory.rb'
@@ -635,6 +464,7 @@ Rails/SkipsModelValidations:
- 'spec/features/admin/order_cycles/complex_editing_spec.rb'
- 'spec/features/admin/order_cycles/simple_spec.rb'
- 'spec/features/admin/order_spec.rb'
+ - 'spec/features/admin/payments_spec.rb'
- 'spec/features/admin/reports_spec.rb'
- 'spec/features/consumer/caching/shops_caching_spec.rb'
- 'spec/features/consumer/shopping/checkout_spec.rb'
@@ -651,17 +481,19 @@ Rails/SkipsModelValidations:
- 'spec/lib/open_food_network/scope_variant_to_hub_spec.rb'
- 'spec/lib/stripe/credit_card_cloner_spec.rb'
- 'spec/lib/tasks/data/remove_transient_data_spec.rb'
+ - 'spec/migrations/migrate_enterprise_fee_tax_amounts_spec.rb'
- 'spec/models/concerns/variant_stock_spec.rb'
- 'spec/models/enterprise_relationship_spec.rb'
- 'spec/models/exchange_spec.rb'
- 'spec/models/spree/adjustment_spec.rb'
- 'spec/models/spree/asset_spec.rb'
- 'spec/models/spree/line_item_spec.rb'
+ - 'spec/models/spree/order/tax_spec.rb'
- 'spec/models/spree/order_inventory_spec.rb'
- 'spec/models/spree/order_spec.rb'
- 'spec/models/spree/tax_category_spec.rb'
+ - 'spec/models/spree/tax_rate_spec.rb'
- 'spec/models/spree/variant_spec.rb'
- - 'spec/models/tag_rule/discount_order_spec.rb'
- 'spec/queries/customers_with_balance_spec.rb'
- 'spec/queries/outstanding_balance_spec.rb'
- 'spec/serializers/api/admin/subscription_line_item_serializer_spec.rb'
@@ -677,7 +509,7 @@ Rails/SkipsModelValidations:
- 'spec/support/request/shop_workflow.rb'
- 'spec/views/spree/shared/_order_details.html.haml_spec.rb'
-# Offense count: 9
+# Offense count: 11
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle.
# SupportedStyles: strict, flexible
@@ -687,6 +519,7 @@ Rails/TimeZone:
- 'spec/controllers/spree/credit_cards_controller_spec.rb'
- 'spec/features/admin/order_cycles/complex_creating_specific_time_spec.rb'
- 'spec/features/admin/order_cycles/simple_spec.rb'
+ - 'spec/models/spree/tax_rate_spec.rb'
- 'spec/services/customer_order_cancellation_spec.rb'
# Offense count: 5
@@ -709,46 +542,29 @@ Rails/UnknownEnv:
- 'app/models/spree/app_configuration.rb'
- 'lib/spree/core/controller_helpers/ssl.rb'
-# Offense count: 15
-# Cop supports --auto-correct.
-# Configuration parameters: EnforcedStyle.
-# SupportedStyles: separated, grouped
-Style/AccessorGrouping:
- Exclude:
- - 'app/controllers/admin/resource_controller.rb'
- - 'app/models/customer.rb'
- - 'app/models/product_import/spreadsheet_entry.rb'
- - 'app/models/spree/line_item.rb'
- - 'app/services/action_callbacks.rb'
- - 'app/services/cart_service.rb'
- - 'lib/discourse/single_sign_on.rb'
-
-# Offense count: 2
+# Offense count: 1
# Cop supports --auto-correct.
# Configuration parameters: AllowOnConstant.
Style/CaseEquality:
Exclude:
- - 'app/helpers/angular_form_helper.rb'
- 'spec/models/spree/payment_spec.rb'
-# Offense count: 5
+# Offense count: 4
# Cop supports --auto-correct.
Style/CaseLikeIf:
Exclude:
- 'app/controllers/admin/order_cycles_controller.rb'
- - 'app/controllers/spree/orders_controller.rb'
- 'app/models/calculator/weight.rb'
- 'app/models/spree/payment/processing.rb'
- 'lib/active_merchant/billing/gateways/stripe_payment_intents.rb'
-# Offense count: 26
+# Offense count: 25
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle.
# SupportedStyles: nested, compact
Style/ClassAndModuleChildren:
Exclude:
- 'app/models/calculator/flat_percent_per_item.rb'
- - 'app/models/tag_rule/discount_order.rb'
- 'app/models/tag_rule/filter_order_cycles.rb'
- 'app/models/tag_rule/filter_payment_methods.rb'
- 'app/models/tag_rule/filter_shipping_methods.rb'
@@ -772,402 +588,17 @@ Style/ClassAndModuleChildren:
- 'spec/controllers/spree/admin/base_controller_spec.rb'
- 'spec/models/spree/payment_method_spec.rb'
-# Offense count: 5
-# Cop supports --auto-correct.
-# Configuration parameters: IgnoredMethods.
-# IgnoredMethods: ==, equal?, eql?
-Style/ClassEqualityComparison:
- Exclude:
- - 'app/controllers/spree/admin/payments_controller.rb'
- - 'app/models/tag_rule/discount_order.rb'
- - 'spec/lib/open_food_network/group_buy_report_spec.rb'
-
-# Offense count: 3
+# Offense count: 1
Style/ClassVars:
Exclude:
- - 'lib/open_food_network/rack_request_blocker.rb'
- 'lib/spree/core/delegate_belongs_to.rb'
-# Offense count: 1
-# Cop supports --auto-correct.
-Style/ExpandPathArguments:
- Exclude:
- - 'config.ru'
-
-# Offense count: 8
-# Cop supports --auto-correct.
-Style/ExplicitBlockArgument:
- Exclude:
- - 'app/helpers/groups_helper.rb'
- - 'app/services/cache_service.rb'
- - 'app/services/current_order_locker.rb'
- - 'spec/support/embedded_pages_helper.rb'
- - 'spec/support/performance_helper.rb'
- - 'spec/support/request/shop_workflow.rb'
-
# Offense count: 2
# Configuration parameters: MaxUnannotatedPlaceholdersAllowed, IgnoredMethods.
# SupportedStyles: annotated, template, unannotated
Style/FormatStringToken:
EnforcedStyle: unannotated
-# Offense count: 354
-# Cop supports --auto-correct.
-# Configuration parameters: EnforcedStyle.
-# SupportedStyles: always, always_true, never
-Style/FrozenStringLiteralComment:
- Exclude:
- - '.simplecov'
- - 'app/controllers/admin/bulk_line_items_controller.rb'
- - 'app/controllers/admin/column_preferences_controller.rb'
- - 'app/controllers/admin/contents_controller.rb'
- - 'app/controllers/admin/customers_controller.rb'
- - 'app/controllers/admin/enterprise_fees_controller.rb'
- - 'app/controllers/admin/enterprise_groups_controller.rb'
- - 'app/controllers/admin/enterprise_relationships_controller.rb'
- - 'app/controllers/admin/enterprise_roles_controller.rb'
- - 'app/controllers/admin/enterprises_controller.rb'
- - 'app/controllers/admin/inventory_items_controller.rb'
- - 'app/controllers/admin/invoice_settings_controller.rb'
- - 'app/controllers/admin/manager_invitations_controller.rb'
- - 'app/controllers/admin/matomo_settings_controller.rb'
- - 'app/controllers/admin/order_cycles_controller.rb'
- - 'app/controllers/admin/producer_properties_controller.rb'
- - 'app/controllers/admin/product_import_controller.rb'
- - 'app/controllers/admin/proxy_orders_controller.rb'
- - 'app/controllers/admin/resource_controller.rb'
- - 'app/controllers/admin/schedules_controller.rb'
- - 'app/controllers/admin/stripe_accounts_controller.rb'
- - 'app/controllers/admin/stripe_connect_settings_controller.rb'
- - 'app/controllers/admin/subscription_line_items_controller.rb'
- - 'app/controllers/admin/subscriptions_controller.rb'
- - 'app/controllers/admin/tag_rules_controller.rb'
- - 'app/controllers/admin/variant_overrides_controller.rb'
- - 'app/controllers/api/base_controller.rb'
- - 'app/controllers/api/customers_controller.rb'
- - 'app/controllers/api/enterprise_fees_controller.rb'
- - 'app/controllers/api/enterprises_controller.rb'
- - 'app/controllers/api/logos_controller.rb'
- - 'app/controllers/api/order_cycles_controller.rb'
- - 'app/controllers/api/orders_controller.rb'
- - 'app/controllers/api/product_images_controller.rb'
- - 'app/controllers/api/products_controller.rb'
- - 'app/controllers/api/promo_images_controller.rb'
- - 'app/controllers/api/shipments_controller.rb'
- - 'app/controllers/api/statuses_controller.rb'
- - 'app/controllers/api/taxonomies_controller.rb'
- - 'app/controllers/api/taxons_controller.rb'
- - 'app/controllers/api/variants_controller.rb'
- - 'app/controllers/cart_controller.rb'
- - 'app/controllers/discourse_sso_controller.rb'
- - 'app/controllers/enterprises_controller.rb'
- - 'app/controllers/groups_controller.rb'
- - 'app/controllers/home_controller.rb'
- - 'app/controllers/line_items_controller.rb'
- - 'app/controllers/map_controller.rb'
- - 'app/controllers/metal_decorator.rb'
- - 'app/controllers/producers_controller.rb'
- - 'app/controllers/registration_controller.rb'
- - 'app/controllers/shop_controller.rb'
- - 'app/controllers/shops_controller.rb'
- - 'app/controllers/sitemap_controller.rb'
- - 'app/controllers/spree/admin/adjustments_controller.rb'
- - 'app/controllers/spree/admin/base_controller.rb'
- - 'app/controllers/spree/admin/countries_controller.rb'
- - 'app/controllers/spree/admin/general_settings_controller.rb'
- - 'app/controllers/spree/admin/images_controller.rb'
- - 'app/controllers/spree/admin/invoices_controller.rb'
- - 'app/controllers/spree/admin/mail_methods_controller.rb'
- - 'app/controllers/spree/admin/orders/customer_details_controller.rb'
- - 'app/controllers/spree/admin/orders_controller.rb'
- - 'app/controllers/spree/admin/overview_controller.rb'
- - 'app/controllers/spree/admin/payment_methods_controller.rb'
- - 'app/controllers/spree/admin/product_properties_controller.rb'
- - 'app/controllers/spree/admin/products_controller.rb'
- - 'app/controllers/spree/admin/properties_controller.rb'
- - 'app/controllers/spree/admin/reports_controller.rb'
- - 'app/controllers/spree/admin/return_authorizations_controller.rb'
- - 'app/controllers/spree/admin/search_controller.rb'
- - 'app/controllers/spree/admin/shipping_categories_controller.rb'
- - 'app/controllers/spree/admin/shipping_methods_controller.rb'
- - 'app/controllers/spree/admin/states_controller.rb'
- - 'app/controllers/spree/admin/tax_categories_controller.rb'
- - 'app/controllers/spree/admin/tax_rates_controller.rb'
- - 'app/controllers/spree/admin/tax_settings_controller.rb'
- - 'app/controllers/spree/admin/taxonomies_controller.rb'
- - 'app/controllers/spree/admin/taxons_controller.rb'
- - 'app/controllers/spree/admin/users_controller.rb'
- - 'app/controllers/spree/admin/variants_controller.rb'
- - 'app/controllers/spree/admin/zones_controller.rb'
- - 'app/controllers/spree/orders_controller.rb'
- - 'app/controllers/spree/users_controller.rb'
- - 'app/controllers/stripe/callbacks_controller.rb'
- - 'app/controllers/stripe/webhooks_controller.rb'
- - 'app/controllers/user_confirmations_controller.rb'
- - 'app/controllers/user_passwords_controller.rb'
- - 'app/controllers/user_registrations_controller.rb'
- - 'app/helpers/admin/enterprises_helper.rb'
- - 'app/helpers/admin/injection_helper.rb'
- - 'app/helpers/admin/orders_helper.rb'
- - 'app/helpers/admin/subscriptions_helper.rb'
- - 'app/helpers/angular_form_builder.rb'
- - 'app/helpers/angular_form_helper.rb'
- - 'app/helpers/application_helper.rb'
- - 'app/helpers/checkout_helper.rb'
- - 'app/helpers/discourse_helper.rb'
- - 'app/helpers/enterprise_fees_helper.rb'
- - 'app/helpers/enterprises_helper.rb'
- - 'app/helpers/footer_links_helper.rb'
- - 'app/helpers/groups_helper.rb'
- - 'app/helpers/i18n_helper.rb'
- - 'app/helpers/injection_helper.rb'
- - 'app/helpers/map_helper.rb'
- - 'app/helpers/markdown_helper.rb'
- - 'app/helpers/serializer_helper.rb'
- - 'app/helpers/shared_helper.rb'
- - 'app/helpers/shop_helper.rb'
- - 'app/helpers/shop_mail_helper.rb'
- - 'app/helpers/spree/admin/base_helper.rb'
- - 'app/helpers/spree/admin/general_settings_helper.rb'
- - 'app/helpers/spree/admin/orders_helper.rb'
- - 'app/helpers/spree/admin/taxons_helper.rb'
- - 'app/helpers/spree/admin/zones_helper.rb'
- - 'app/helpers/spree/orders_helper.rb'
- - 'app/helpers/spree/reports_helper.rb'
- - 'app/helpers/spree_currency_helper.rb'
- - 'app/jobs/subscription_confirm_job.rb'
- - 'app/jobs/subscription_placement_job.rb'
- - 'app/mailers/enterprise_mailer.rb'
- - 'app/mailers/spree/user_mailer.rb'
- - 'app/mailers/subscription_mailer.rb'
- - 'app/models/adjustment_metadata.rb'
- - 'app/models/calculator/flat_percent_per_item.rb'
- - 'app/models/calculator/weight.rb'
- - 'app/models/column_preference.rb'
- - 'app/models/concerns/address_display.rb'
- - 'app/models/concerns/adjustment_scopes.rb'
- - 'app/models/concerns/line_item_based_adjustment_handling.rb'
- - 'app/models/concerns/order_shipment.rb'
- - 'app/models/concerns/product_stock.rb'
- - 'app/models/concerns/stock_settings_override_validation.rb'
- - 'app/models/concerns/variant_stock.rb'
- - 'app/models/content_configuration.rb'
- - 'app/models/coordinator_fee.rb'
- - 'app/models/customer.rb'
- - 'app/models/distributor_shipping_method.rb'
- - 'app/models/enterprise_fee.rb'
- - 'app/models/enterprise_relationship_permission.rb'
- - 'app/models/enterprise_role.rb'
- - 'app/models/exchange.rb'
- - 'app/models/exchange_fee.rb'
- - 'app/models/exchange_variant.rb'
- - 'app/models/inventory_item.rb'
- - 'app/models/order_cycle.rb'
- - 'app/models/preference_sections/footer_and_external_links_section.rb'
- - 'app/models/preference_sections/group_signup_page_section.rb'
- - 'app/models/preference_sections/header_section.rb'
- - 'app/models/preference_sections/home_page_section.rb'
- - 'app/models/preference_sections/hub_signup_page_section.rb'
- - 'app/models/preference_sections/main_links_section.rb'
- - 'app/models/preference_sections/producer_signup_page_section.rb'
- - 'app/models/preference_sections/user_guide_section.rb'
- - 'app/models/producer_property.rb'
- - 'app/models/product_import/entry_processor.rb'
- - 'app/models/product_import/entry_validator.rb'
- - 'app/models/product_import/inventory_reset_strategy.rb'
- - 'app/models/product_import/product_importer.rb'
- - 'app/models/product_import/reset_absent.rb'
- - 'app/models/product_import/settings.rb'
- - 'app/models/product_import/spreadsheet_data.rb'
- - 'app/models/product_import/spreadsheet_entry.rb'
- - 'app/models/product_import/unit_converter.rb'
- - 'app/models/proxy_order.rb'
- - 'app/models/schedule.rb'
- - 'app/models/spree/gateway/stripe_connect.rb'
- - 'app/models/spree/preferences/file_configuration.rb'
- - 'app/models/spree/property.rb'
- - 'app/models/spree/user.rb'
- - 'app/models/stripe_account.rb'
- - 'app/models/subscription.rb'
- - 'app/models/subscription_line_item.rb'
- - 'app/models/tag_rule.rb'
- - 'app/models/tag_rule/discount_order.rb'
- - 'app/models/tag_rule/filter_order_cycles.rb'
- - 'app/models/tag_rule/filter_payment_methods.rb'
- - 'app/models/tag_rule/filter_products.rb'
- - 'app/models/tag_rule/filter_shipping_methods.rb'
- - 'app/serializers/api/address_serializer.rb'
- - 'app/serializers/api/adjustment_serializer.rb'
- - 'app/serializers/api/cached_enterprise_serializer.rb'
- - 'app/serializers/api/country_serializer.rb'
- - 'app/serializers/api/credit_card_serializer.rb'
- - 'app/serializers/api/currency_config_serializer.rb'
- - 'app/serializers/api/current_order_serializer.rb'
- - 'app/serializers/api/customer_serializer.rb'
- - 'app/serializers/api/enterprise_serializer.rb'
- - 'app/serializers/api/enterprise_shopfront_list_serializer.rb'
- - 'app/serializers/api/enterprise_shopfront_serializer.rb'
- - 'app/serializers/api/enterprise_thin_serializer.rb'
- - 'app/serializers/api/group_list_serializer.rb'
- - 'app/serializers/api/id_name_serializer.rb'
- - 'app/serializers/api/id_serializer.rb'
- - 'app/serializers/api/image_serializer.rb'
- - 'app/serializers/api/line_item_serializer.rb'
- - 'app/serializers/api/order_cycle_serializer.rb'
- - 'app/serializers/api/order_detailed_serializer.rb'
- - 'app/serializers/api/order_serializer.rb'
- - 'app/serializers/api/payment_method_serializer.rb'
- - 'app/serializers/api/payment_serializer.rb'
- - 'app/serializers/api/product_serializer.rb'
- - 'app/serializers/api/property_serializer.rb'
- - 'app/serializers/api/rails_flash_serializer.rb'
- - 'app/serializers/api/shipment_serializer.rb'
- - 'app/serializers/api/shipping_method_serializer.rb'
- - 'app/serializers/api/shop_for_orders_serializer.rb'
- - 'app/serializers/api/state_serializer.rb'
- - 'app/serializers/api/taxon_jstree_attribute_serializer.rb'
- - 'app/serializers/api/taxon_jstree_serializer.rb'
- - 'app/serializers/api/taxon_serializer.rb'
- - 'app/serializers/api/uncached_enterprise_serializer.rb'
- - 'app/serializers/api/user_serializer.rb'
- - 'app/serializers/api/variant_serializer.rb'
- - 'app/services/bulk_invoice_service.rb'
- - 'app/services/cart_service.rb'
- - 'app/services/create_order_cycle.rb'
- - 'app/services/current_order_locker.rb'
- - 'app/services/default_shipping_category.rb'
- - 'app/services/default_stock_location.rb'
- - 'app/services/embedded_page_service.rb'
- - 'app/services/exchange_variant_bulk_updater.rb'
- - 'app/services/exchange_variant_deleter.rb'
- - 'app/services/invoice_renderer.rb'
- - 'app/services/line_item_syncer.rb'
- - 'app/services/mail_configuration.rb'
- - 'app/services/order_adjustments_fetcher.rb'
- - 'app/services/order_cycle_distributed_products.rb'
- - 'app/services/order_cycle_distributed_variants.rb'
- - 'app/services/order_cycle_form.rb'
- - 'app/services/order_factory.rb'
- - 'app/services/order_syncer.rb'
- - 'app/services/order_update_issues.rb'
- - 'app/services/order_workflow.rb'
- - 'app/services/permissions/order.rb'
- - 'app/services/product_tag_rules_filterer.rb'
- - 'app/services/products_renderer.rb'
- - 'app/services/search_orders.rb'
- - 'app/services/tax_rate_finder.rb'
- - 'app/services/upload_sanitizer.rb'
- - 'app/services/variant_deleter.rb'
- - 'app/services/variant_units/variant_and_line_item_naming.rb'
- - 'app/services/variants_stock_levels.rb'
- - 'app/validators/date_time_string_validator.rb'
- - 'app/validators/distributors_validator.rb'
- - 'app/validators/integer_array_validator.rb'
- - 'engines/order_management/app/controllers/order_management/application_controller.rb'
- - 'engines/order_management/app/services/order_management/reports/enterprise_fee_summary/authorizer.rb'
- - 'engines/order_management/app/services/order_management/reports/enterprise_fee_summary/data_representations/coordinator_fee.rb'
- - 'engines/order_management/app/services/order_management/reports/enterprise_fee_summary/data_representations/exchange_order_fee.rb'
- - 'engines/order_management/app/services/order_management/reports/enterprise_fee_summary/data_representations/incoming_exchange_line_item_fee.rb'
- - 'engines/order_management/app/services/order_management/reports/enterprise_fee_summary/data_representations/outgoing_exchange_line_item_fee.rb'
- - 'engines/order_management/app/services/order_management/reports/enterprise_fee_summary/data_representations/payment_method_fee.rb'
- - 'engines/order_management/app/services/order_management/reports/enterprise_fee_summary/data_representations/shipping_method_fee.rb'
- - 'engines/order_management/app/services/order_management/reports/enterprise_fee_summary/data_representations/using_enterprise_fee.rb'
- - 'engines/order_management/app/services/order_management/reports/enterprise_fee_summary/data_representations/with_i18n.rb'
- - 'engines/order_management/app/services/order_management/reports/enterprise_fee_summary/parameters.rb'
- - 'engines/order_management/app/services/order_management/reports/enterprise_fee_summary/permissions.rb'
- - 'engines/order_management/app/services/order_management/reports/enterprise_fee_summary/renderers/csv_renderer.rb'
- - 'engines/order_management/app/services/order_management/reports/enterprise_fee_summary/renderers/html_renderer.rb'
- - 'engines/order_management/app/services/order_management/reports/enterprise_fee_summary/report_data/enterprise_fee_type_total.rb'
- - 'engines/order_management/app/services/order_management/reports/enterprise_fee_summary/report_service.rb'
- - 'engines/order_management/app/services/order_management/reports/enterprise_fee_summary/scope.rb'
- - 'engines/order_management/app/services/order_management/reports/enterprise_fee_summary/summarizer.rb'
- - 'engines/order_management/app/services/reports.rb'
- - 'engines/order_management/app/services/reports/authorizer.rb'
- - 'engines/order_management/app/services/reports/parameters/base.rb'
- - 'engines/order_management/app/services/reports/permissions.rb'
- - 'engines/order_management/app/services/reports/renderers/base.rb'
- - 'engines/order_management/app/services/reports/report_data/base.rb'
- - 'engines/web/app/controllers/web/angular_templates_controller.rb'
- - 'engines/web/app/controllers/web/api/v0/cookies_consent_controller.rb'
- - 'engines/web/app/controllers/web/application_controller.rb'
- - 'engines/web/app/helpers/web/cookies_policy_helper.rb'
- - 'engines/web/lib/web/cookies_consent.rb'
- - 'lib/discourse/single_sign_on.rb'
- - 'lib/open_food_network/address_finder.rb'
- - 'lib/open_food_network/available_payment_method_filter.rb'
- - 'lib/open_food_network/column_preference_defaults.rb'
- - 'lib/open_food_network/customers_report.rb'
- - 'lib/open_food_network/enterprise_fee_applicator.rb'
- - 'lib/open_food_network/enterprise_fee_calculator.rb'
- - 'lib/open_food_network/enterprise_injection_data.rb'
- - 'lib/open_food_network/enterprise_issue_validator.rb'
- - 'lib/open_food_network/error_logger.rb'
- - 'lib/open_food_network/feature_toggle.rb'
- - 'lib/open_food_network/group_buy_report.rb'
- - 'lib/open_food_network/i18n_config.rb'
- - 'lib/open_food_network/lettuce_share_report.rb'
- - 'lib/open_food_network/order_and_distributor_report.rb'
- - 'lib/open_food_network/order_cycle_form_applicator.rb'
- - 'lib/open_food_network/order_cycle_management_report.rb'
- - 'lib/open_food_network/order_cycle_permissions.rb'
- - 'lib/open_food_network/order_grouper.rb'
- - 'lib/open_food_network/orders_and_fulfillments_report.rb'
- - 'lib/open_food_network/orders_and_fulfillments_report/customer_totals_report.rb'
- - 'lib/open_food_network/orders_and_fulfillments_report/default_report.rb'
- - 'lib/open_food_network/orders_and_fulfillments_report/distributor_totals_by_supplier_report.rb'
- - 'lib/open_food_network/orders_and_fulfillments_report/supplier_totals_by_distributor_report.rb'
- - 'lib/open_food_network/orders_and_fulfillments_report/supplier_totals_report.rb'
- - 'lib/open_food_network/packing_report.rb'
- - 'lib/open_food_network/paperclippable.rb'
- - 'lib/open_food_network/permissions.rb'
- - 'lib/open_food_network/products_and_inventory_report.rb'
- - 'lib/open_food_network/products_and_inventory_report_base.rb'
- - 'lib/open_food_network/property_merge.rb'
- - 'lib/open_food_network/rack_request_blocker.rb'
- - 'lib/open_food_network/referer_parser.rb'
- - 'lib/open_food_network/reports/line_items.rb'
- - 'lib/open_food_network/reports/list.rb'
- - 'lib/open_food_network/sales_tax_report.rb'
- - 'lib/open_food_network/scope_product_to_hub.rb'
- - 'lib/open_food_network/scope_variant_to_hub.rb'
- - 'lib/open_food_network/scope_variants_for_search.rb'
- - 'lib/open_food_network/spree_api_key_loader.rb'
- - 'lib/open_food_network/tag_rule_applicator.rb'
- - 'lib/open_food_network/users_and_enterprises_report.rb'
- - 'lib/open_food_network/xero_invoices_report.rb'
- - 'lib/spree/authentication_helpers.rb'
- - 'lib/stripe/account_connector.rb'
- - 'lib/stripe/profile_storer.rb'
- - 'lib/stripe/webhook_handler.rb'
- - 'lib/tasks/data.rake'
- - 'lib/tasks/data/anonymize_data.rake'
- - 'lib/tasks/enterprises.rake'
- - 'lib/tasks/karma.rake'
- - 'lib/tasks/missing_payments.rake'
- - 'lib/tasks/sample_data.rake'
- - 'lib/tasks/sample_data/addressing.rb'
- - 'lib/tasks/sample_data/customer_factory.rb'
- - 'lib/tasks/sample_data/enterprise_factory.rb'
- - 'lib/tasks/sample_data/fee_factory.rb'
- - 'lib/tasks/sample_data/group_factory.rb'
- - 'lib/tasks/sample_data/inventory_factory.rb'
- - 'lib/tasks/sample_data/logging.rb'
- - 'lib/tasks/sample_data/order_cycle_factory.rb'
- - 'lib/tasks/sample_data/payment_method_factory.rb'
- - 'lib/tasks/sample_data/permission_factory.rb'
- - 'lib/tasks/sample_data/product_factory.rb'
- - 'lib/tasks/sample_data/shipping_method_factory.rb'
- - 'lib/tasks/sample_data/taxon_factory.rb'
- - 'lib/tasks/sample_data/user_factory.rb'
- - 'lib/tasks/specs.rake'
- - 'lib/tasks/users.rake'
- - 'spec/features/consumer/shopping/unit_price_spec.rb'
- - 'spec/helpers/terms_and_conditions_helper_spec.rb'
- - 'spec/initializers/feature_toggles_spec.rb'
- - 'spec/lib/open_food_network/reports/line_items_spec.rb'
- - 'spec/models/concerns/balance_spec.rb'
- - 'spec/services/order_data_masker_spec.rb'
-
# Offense count: 6
# Cop supports --auto-correct.
Style/GlobalStdStream:
@@ -1185,56 +616,31 @@ Style/GuardClause:
- 'app/controllers/admin/enterprises_controller.rb'
- 'app/controllers/admin/order_cycles_controller.rb'
- 'app/controllers/admin/product_import_controller.rb'
- - 'app/controllers/api/shipments_controller.rb'
+ - 'app/controllers/api/v0/shipments_controller.rb'
- 'app/controllers/application_controller.rb'
- 'app/controllers/home_controller.rb'
- 'app/controllers/spree/orders_controller.rb'
- 'app/models/enterprise.rb'
- 'app/models/enterprise_group.rb'
- 'app/models/producer_property.rb'
+ - 'app/models/product_import/entry_processor.rb'
+ - 'app/models/spree/order.rb'
- 'app/models/spree/preferences/preferable_class_methods.rb'
- 'app/services/order_syncer.rb'
- 'app/services/variant_units/variant_and_line_item_naming.rb'
+ - 'engines/order_management/app/services/order_management/order/updater.rb'
- 'lib/discourse/single_sign_on.rb'
- 'lib/open_food_network/order_cycle_form_applicator.rb'
- - 'lib/open_food_network/rack_request_blocker.rb'
- 'lib/spree/core/controller_helpers/respond_with.rb'
- 'spec/support/request/distribution_helper.rb'
- 'spec/support/request/shop_workflow.rb'
-# Offense count: 10
-# Cop supports --auto-correct.
-# Configuration parameters: EnforcedStyle.
-# SupportedStyles: braces, no_braces
-Style/HashAsLastArrayItem:
- Exclude:
- - 'app/controllers/admin/enterprises_controller.rb'
- - 'app/controllers/admin/subscriptions_controller.rb'
- - 'app/services/exchange_products_renderer.rb'
- - 'app/services/permitted_attributes/checkout.rb'
- - 'app/services/permitted_attributes/order_cycle.rb'
- - 'app/services/permitted_attributes/product.rb'
- - 'lib/open_food_network/orders_and_fulfillments_report/distributor_totals_by_supplier_report.rb'
- - 'lib/open_food_network/xero_invoices_report.rb'
-
# Offense count: 1
# Configuration parameters: MinBranchesCount.
Style/HashLikeCase:
Exclude:
- 'app/models/enterprise.rb'
-# Offense count: 9
-# Cop supports --auto-correct.
-# Configuration parameters: EnforcedStyle, UseHashRocketsWithSymbolValues, PreferHashRocketsForNonAlnumEndingSymbols.
-# SupportedStyles: ruby19, hash_rockets, no_mixed_keys, ruby19_no_mixed_keys
-Style/HashSyntax:
- Exclude:
- - 'spec/features/admin/order_cycles/simple_spec.rb'
- - 'spec/features/consumer/account/cards_spec.rb'
- - 'spec/features/consumer/account/payments_spec.rb'
- - 'spec/features/consumer/account/settings_spec.rb'
- - 'spec/features/consumer/account_spec.rb'
-
# Offense count: 3
Style/MissingRespondToMissing:
Exclude:
@@ -1248,7 +654,22 @@ Style/MixinUsage:
- 'lib/open_food_network/orders_and_fulfillments_report.rb'
- 'spec/lib/open_food_network/packing_report_spec.rb'
-# Offense count: 41
+# Offense count: 22
+# Cop supports --auto-correct.
+Style/NestedModifier:
+ Exclude:
+ - 'spec/controllers/admin/subscriptions_controller_spec.rb'
+ - 'spec/controllers/line_items_controller_spec.rb'
+ - 'spec/controllers/spree/admin/orders_controller_spec.rb'
+ - 'spec/controllers/spree/orders_controller_spec.rb'
+ - 'spec/factories/order_factory.rb'
+ - 'spec/features/admin/payments_stripe_spec.rb'
+ - 'spec/features/admin/reports_spec.rb'
+ - 'spec/jobs/subscription_placement_job_spec.rb'
+ - 'spec/models/proxy_order_spec.rb'
+ - 'spec/models/spree/line_item_spec.rb'
+
+# Offense count: 34
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, IgnoredMethods.
# SupportedStyles: predicate, comparison
@@ -1265,16 +686,13 @@ Style/NumericPredicate:
- 'app/models/spree/order.rb'
- 'app/models/spree/order_contents.rb'
- 'app/models/spree/order_inventory.rb'
- - 'app/models/spree/preferences/preferable.rb'
- 'app/models/spree/user.rb'
- 'app/models/variant_override.rb'
- 'app/services/cart_service.rb'
- 'lib/open_food_network/customers_report.rb'
- 'lib/open_food_network/enterprise_fee_calculator.rb'
- 'lib/open_food_network/products_and_inventory_report_base.rb'
- - 'lib/open_food_network/rack_request_blocker.rb'
- 'lib/open_food_network/sales_tax_report.rb'
- - 'lib/open_food_network/xero_invoices_report.rb'
- 'lib/tasks/sample_data.rake'
# Offense count: 26
@@ -1287,9 +705,9 @@ Style/OptionalBooleanParameter:
- 'app/mailers/spree/shipment_mailer.rb'
- 'app/models/enterprise_relationship.rb'
- 'app/models/product_import/entry_processor.rb'
+ - 'app/models/spree/order_contents.rb'
- 'app/models/spree/preferences/file_configuration.rb'
- 'app/models/spree/shipment.rb'
- - 'app/services/cart_service.rb'
- 'engines/order_management/app/services/order_management/reports/bulk_coop/bulk_coop_report.rb'
- 'engines/order_management/app/services/order_management/stock/estimator.rb'
- 'lib/open_food_network/customers_report.rb'
@@ -1306,69 +724,15 @@ Style/OptionalBooleanParameter:
- 'lib/spree/core/delegate_belongs_to.rb'
- 'spec/support/request/web_helper.rb'
-# Offense count: 3
-# Cop supports --auto-correct.
-Style/RedundantAssignment:
- Exclude:
- - 'app/models/spree/payment.rb'
- - 'app/models/spree/taxon.rb'
- - 'lib/open_food_network/order_grouper.rb'
-
-# Offense count: 3
-# Cop supports --auto-correct.
-Style/RedundantBegin:
- Exclude:
- - 'lib/open_food_network/enterprise_injection_data.rb'
- - 'lib/open_food_network/order_cycle_permissions.rb'
-
-# Offense count: 2
-# Cop supports --auto-correct.
-Style/RedundantFileExtensionInRequire:
- Exclude:
- - 'engines/catalog/spec/spec_helper.rb'
- - 'engines/dfc_provider/spec/spec_helper.rb'
-
# Offense count: 1
# Cop supports --auto-correct.
-Style/RedundantInterpolation:
+# Configuration parameters: EnforcedStyle.
+# SupportedStyles: short, verbose
+Style/PreferredHashMethods:
Exclude:
- - 'spec/initializers/feature_toggles_spec.rb'
+ - 'app/controllers/api/v0/shipments_controller.rb'
-# Offense count: 2
-# Cop supports --auto-correct.
-Style/RedundantRegexpCharacterClass:
- Exclude:
- - 'app/models/spree/order.rb'
- - 'lib/stripe/authorize_response_patcher.rb'
-
-# Offense count: 11
-# Cop supports --auto-correct.
-Style/RedundantRegexpEscape:
- Exclude:
- - 'app/models/spree/order.rb'
- - 'engines/web/config/routes.rb'
- - 'lib/spree/localized_number.rb'
- - 'lib/stripe/authorize_response_patcher.rb'
-
-# Offense count: 1
-# Cop supports --auto-correct.
-# Configuration parameters: AllowMultipleReturnValues.
-Style/RedundantReturn:
- Exclude:
- - 'spec/support/features/datepicker_helper.rb'
-
-# Offense count: 6
-# Cop supports --auto-correct.
-# Configuration parameters: EnforcedStyle, AllowInnerSlashes.
-# SupportedStyles: slashes, percent_r, mixed
-Style/RegexpLiteral:
- Exclude:
- - 'spec/features/consumer/account/cards_spec.rb'
- - 'spec/features/consumer/account/payments_spec.rb'
- - 'spec/features/consumer/account/settings_spec.rb'
- - 'spec/features/consumer/account_spec.rb'
-
-# Offense count: 240
+# Offense count: 236
Style/Send:
Exclude:
- 'engines/order_management/spec/services/order_management/reports/bulk_coop/bulk_coop_report_spec.rb'
@@ -1399,7 +763,6 @@ Style/Send:
- 'spec/models/spree/payment_spec.rb'
- 'spec/models/spree/return_authorization_spec.rb'
- 'spec/models/spree/tax_rate_spec.rb'
- - 'spec/models/tag_rule/discount_order_spec.rb'
- 'spec/models/tag_rule/filter_order_cycles_spec.rb'
- 'spec/models/tag_rule/filter_payment_methods_spec.rb'
- 'spec/models/tag_rule/filter_products_spec.rb'
@@ -1417,22 +780,17 @@ Style/SingleArgumentDig:
- 'app/services/checkout/form_data_adapter.rb'
- 'lib/active_merchant/billing/gateways/stripe_payment_intents.rb'
-# Offense count: 10
+# Offense count: 5
# Cop supports --auto-correct.
-# Configuration parameters: AllowModifier.
-Style/SoleNestedConditional:
+Style/SlicingWithRange:
Exclude:
- - 'Rakefile'
- - 'app/controllers/checkout_controller.rb'
- - 'app/models/product_import/spreadsheet_entry.rb'
- - 'app/models/spree/address.rb'
- - 'app/models/spree/preferences/store.rb'
- - 'app/services/order_syncer.rb'
- - 'app/services/order_workflow.rb'
- - 'lib/spree/core/controller_helpers/order.rb'
- - 'spec/support/matchers/select2_matchers.rb'
+ - 'app/helpers/spree/admin/navigation_helper.rb'
+ - 'app/services/embedded_page_service.rb'
+ - 'engines/order_management/app/services/order_management/subscriptions/validator.rb'
+ - 'lib/discourse/single_sign_on.rb'
+ - 'spec/lib/open_food_network/order_grouper_spec.rb'
-# Offense count: 45
+# Offense count: 43
# Cop supports --auto-correct.
Style/StringConcatenation:
Exclude:
@@ -1443,9 +801,7 @@ Style/StringConcatenation:
- 'app/mailers/spree/user_mailer.rb'
- 'app/models/enterprise.rb'
- 'app/models/spree/credit_card.rb'
- - 'app/models/spree/line_item.rb'
- 'app/models/spree/payment_method.rb'
- - 'app/models/spree/tax_rate.rb'
- 'app/serializers/api/cached_enterprise_serializer.rb'
- 'app/serializers/api/enterprise_shopfront_list_serializer.rb'
- 'app/services/embedded_page_service.rb'
@@ -1468,31 +824,3 @@ Style/StringConcatenation:
- 'spec/services/embedded_page_service_spec.rb'
- 'spec/support/api_helper.rb'
- 'spec/support/features/datepicker_helper.rb'
-
-# Offense count: 1
-# Cop supports --auto-correct.
-Style/StructInheritance:
- Exclude:
- - 'lib/open_food_network/enterprise_fee_applicator.rb'
-
-# Offense count: 2
-# Cop supports --auto-correct.
-# Configuration parameters: AllowMethodsWithArguments, IgnoredMethods.
-# IgnoredMethods: respond_to, define_method
-Style/SymbolProc:
- Exclude:
- - 'app/models/spree/preferences/preferable.rb'
-
-# Offense count: 19
-# Cop supports --auto-correct.
-Style/WhileUntilModifier:
- Exclude:
- - 'spec/controllers/admin/subscriptions_controller_spec.rb'
- - 'spec/controllers/line_items_controller_spec.rb'
- - 'spec/controllers/spree/admin/orders_controller_spec.rb'
- - 'spec/controllers/spree/orders_controller_spec.rb'
- - 'spec/factories/order_factory.rb'
- - 'spec/features/admin/payments_stripe_spec.rb'
- - 'spec/jobs/subscription_placement_job_spec.rb'
- - 'spec/models/proxy_order_spec.rb'
- - 'spec/models/spree/line_item_spec.rb'
diff --git a/.simplecov b/.simplecov
old mode 100644
new mode 100755
diff --git a/Gemfile b/Gemfile
index aaf1e31191..97ffa4d94b 100644
--- a/Gemfile
+++ b/Gemfile
@@ -74,14 +74,14 @@ gem 'figaro'
gem 'geocoder'
gem 'gmaps4rails'
gem 'mimemagic', '> 0.3.5'
-gem 'paper_trail', '~> 10.3.1'
gem 'paperclip', '~> 3.4.1'
+gem 'paper_trail', '~> 10.3.1'
gem 'rack-rewrite'
gem 'rack-ssl', require: 'rack/ssl'
gem 'roadie-rails'
-gem 'redis', '>= 4.0', require: ['redis', 'redis/connection/hiredis']
gem 'hiredis'
+gem 'redis', '>= 4.0', require: ['redis', 'redis/connection/hiredis']
gem 'sidekiq'
gem 'sidekiq-scheduler'
@@ -152,17 +152,16 @@ end
group :test do
gem 'byebug'
gem 'codecov', require: false
+ gem 'pdf-reader'
+ gem 'rails-controller-testing'
gem 'simplecov', require: false
gem 'test-prof'
gem 'webmock'
- gem 'rails-controller-testing'
- gem 'pdf-reader'
# See spec/spec_helper.rb for instructions
# gem 'perftools.rb'
end
group :development do
- gem 'web-console'
gem 'debugger-linecache'
gem 'pry'
gem 'pry-byebug'
@@ -170,6 +169,7 @@ group :development do
gem 'rubocop-rails'
gem 'spring'
gem 'spring-commands-rspec'
+ gem 'web-console'
gem "view_component_storybook", require: "view_component/storybook/engine"
diff --git a/Rakefile b/Rakefile
index f7fce19311..e37edbf5b4 100755
--- a/Rakefile
+++ b/Rakefile
@@ -8,6 +8,6 @@ require_relative 'config/application'
Openfoodnetwork::Application.load_tasks
-unless ENV['DISABLE_KNAPSACK']
- Knapsack.load_tasks if defined?(Knapsack)
+if !ENV['DISABLE_KNAPSACK'] && defined?(Knapsack)
+ Knapsack.load_tasks
end
diff --git a/app/controllers/admin/bulk_line_items_controller.rb b/app/controllers/admin/bulk_line_items_controller.rb
index 91973448e9..4e3d46e565 100644
--- a/app/controllers/admin/bulk_line_items_controller.rb
+++ b/app/controllers/admin/bulk_line_items_controller.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
module Admin
class BulkLineItemsController < Spree::Admin::BaseController
include PaginationData
diff --git a/app/controllers/admin/column_preferences_controller.rb b/app/controllers/admin/column_preferences_controller.rb
index 4ff7734f22..fcf627f1b7 100644
--- a/app/controllers/admin/column_preferences_controller.rb
+++ b/app/controllers/admin/column_preferences_controller.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
module Admin
class ColumnPreferencesController < Admin::ResourceController
before_action :load_collection, only: [:bulk_update]
diff --git a/app/controllers/admin/contents_controller.rb b/app/controllers/admin/contents_controller.rb
index 1769732ec4..5841fa84eb 100644
--- a/app/controllers/admin/contents_controller.rb
+++ b/app/controllers/admin/contents_controller.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
module Admin
class ContentsController < Spree::Admin::BaseController
def edit
@@ -16,7 +18,8 @@ module Admin
# Save any uploaded images
ContentConfig.save
- flash[:success] = t(:successfully_updated, resource: I18n.t('admin.contents.edit.your_content'))
+ flash[:success] =
+ t(:successfully_updated, resource: I18n.t('admin.contents.edit.your_content'))
redirect_to main_app.edit_admin_contents_path
end
diff --git a/app/controllers/admin/customers_controller.rb b/app/controllers/admin/customers_controller.rb
index e655b0ae8e..71cc8fc2c8 100644
--- a/app/controllers/admin/customers_controller.rb
+++ b/app/controllers/admin/customers_controller.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
require 'open_food_network/address_finder'
module Admin
@@ -10,7 +12,10 @@ module Admin
tag_rule_mapping = TagRule.mapping_for(Enterprise.where(id: @customer.enterprise))
render_as_json @customer, tag_rule_mapping: tag_rule_mapping
},
- failure: lambda { render json: { errors: @customer.errors.full_messages }, status: :unprocessable_entity }
+ failure: lambda {
+ render json: { errors: @customer.errors.full_messages },
+ status: :unprocessable_entity
+ }
} }
def index
diff --git a/app/controllers/admin/enterprise_fees_controller.rb b/app/controllers/admin/enterprise_fees_controller.rb
index f506dfa093..54a320785f 100644
--- a/app/controllers/admin/enterprise_fees_controller.rb
+++ b/app/controllers/admin/enterprise_fees_controller.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
module Admin
class EnterpriseFeesController < Admin::ResourceController
before_action :load_enterprise_fee_set, only: :index
@@ -16,7 +18,9 @@ module Admin
respond_to do |format|
format.html
- format.json { render_as_json @collection, controller: self, include_calculators: @include_calculators }
+ format.json {
+ render_as_json @collection, controller: self, include_calculators: @include_calculators
+ }
# format.json { @presented_collection = @collection.each_with_index.map { |ef, i| EnterpriseFeePresenter.new(self, ef, i) } }
end
end
@@ -56,10 +60,12 @@ module Admin
order_cycle = OrderCycle.find_by(id: params[:order_cycle_id]) if params[:order_cycle_id]
coordinator = Enterprise.find_by(id: params[:coordinator_id]) if params[:coordinator_id]
order_cycle = OrderCycle.new(coordinator: coordinator) if order_cycle.nil? && coordinator.present?
- enterprises = OpenFoodNetwork::OrderCyclePermissions.new(spree_current_user, order_cycle).visible_enterprises
+ enterprises = OpenFoodNetwork::OrderCyclePermissions.new(spree_current_user,
+ order_cycle).visible_enterprises
EnterpriseFee.for_enterprises(enterprises).order('enterprise_id', 'fee_type', 'name')
else
- collection = EnterpriseFee.managed_by(spree_current_user).order('enterprise_id', 'fee_type', 'name')
+ collection = EnterpriseFee.managed_by(spree_current_user).order('enterprise_id',
+ 'fee_type', 'name')
collection = collection.for_enterprise(current_enterprise) if current_enterprise
collection
end
diff --git a/app/controllers/admin/enterprise_groups_controller.rb b/app/controllers/admin/enterprise_groups_controller.rb
index bfd5cca831..56b2468b5f 100644
--- a/app/controllers/admin/enterprise_groups_controller.rb
+++ b/app/controllers/admin/enterprise_groups_controller.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
module Admin
class EnterpriseGroupsController < Admin::ResourceController
before_action :load_data, except: :index
diff --git a/app/controllers/admin/enterprise_relationships_controller.rb b/app/controllers/admin/enterprise_relationships_controller.rb
index d1c77d3d53..3a6fd6d429 100644
--- a/app/controllers/admin/enterprise_relationships_controller.rb
+++ b/app/controllers/admin/enterprise_relationships_controller.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
module Admin
class EnterpriseRelationshipsController < Admin::ResourceController
def index
@@ -16,7 +18,8 @@ module Admin
if @enterprise_relationship.save
render plain: Api::Admin::EnterpriseRelationshipSerializer.new(@enterprise_relationship).to_json
else
- render status: :bad_request, json: { errors: @enterprise_relationship.errors.full_messages.join(', ') }
+ render status: :bad_request,
+ json: { errors: @enterprise_relationship.errors.full_messages.join(', ') }
end
end
diff --git a/app/controllers/admin/enterprise_roles_controller.rb b/app/controllers/admin/enterprise_roles_controller.rb
index be29df26fa..79a52d8b41 100644
--- a/app/controllers/admin/enterprise_roles_controller.rb
+++ b/app/controllers/admin/enterprise_roles_controller.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
module Admin
class EnterpriseRolesController < Admin::ResourceController
def index
@@ -13,7 +15,8 @@ module Admin
render plain: Api::Admin::EnterpriseRoleSerializer.new(@enterprise_role).to_json
else
- render status: :bad_request, json: { errors: @enterprise_role.errors.full_messages.join(', ') }
+ render status: :bad_request,
+ json: { errors: @enterprise_role.errors.full_messages.join(', ') }
end
end
diff --git a/app/controllers/admin/enterprises_controller.rb b/app/controllers/admin/enterprises_controller.rb
index a65dc15a93..c2a9460447 100644
--- a/app/controllers/admin/enterprises_controller.rb
+++ b/app/controllers/admin/enterprises_controller.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
require 'open_food_network/referer_parser'
require 'open_food_network/permissions'
require 'open_food_network/order_cycle_permissions'
@@ -32,7 +34,10 @@ module Admin
def index
respond_to do |format|
format.html
- format.json { render_as_json @collection, ams_prefix: params[:ams_prefix], spree_current_user: spree_current_user }
+ format.json {
+ render_as_json @collection, ams_prefix: params[:ams_prefix],
+ spree_current_user: spree_current_user
+ }
end
end
@@ -56,11 +61,15 @@ module Admin
respond_with(@object) do |format|
format.html { redirect_to location_after_save }
format.js { render layout: false }
- format.json { render_as_json @object, ams_prefix: 'index', spree_current_user: spree_current_user }
+ format.json {
+ render_as_json @object, ams_prefix: 'index', spree_current_user: spree_current_user
+ }
end
else
respond_with(@object) do |format|
- format.json { render json: { errors: @object.errors.messages }, status: :unprocessable_entity }
+ format.json {
+ render json: { errors: @object.errors.messages }, status: :unprocessable_entity
+ }
end
end
end
@@ -101,7 +110,8 @@ module Admin
def for_order_cycle
respond_to do |format|
format.json do
- render json: @collection, each_serializer: Api::Admin::ForOrderCycle::EnterpriseSerializer, order_cycle: @order_cycle, spree_current_user: spree_current_user
+ render json: @collection,
+ each_serializer: Api::Admin::ForOrderCycle::EnterpriseSerializer, order_cycle: @order_cycle, spree_current_user: spree_current_user
end
end
end
@@ -109,7 +119,8 @@ module Admin
def visible
respond_to do |format|
format.json do
- render_as_json @collection, ams_prefix: params[:ams_prefix] || 'basic', spree_current_user: spree_current_user
+ render_as_json @collection, ams_prefix: params[:ams_prefix] || 'basic',
+ spree_current_user: spree_current_user
end
end
end
@@ -152,7 +163,7 @@ module Admin
if enterprises.present?
enterprises.includes(
supplied_products:
- [:supplier, master: [:images], variants: { option_values: :option_type }]
+ [:supplier, { master: [:images], variants: { option_values: :option_type } }]
)
end
when :index
@@ -284,7 +295,8 @@ module Admin
end
def strip_new_properties
- unless spree_current_user.admin? || params.dig(:enterprise, :producer_properties_attributes).nil?
+ unless spree_current_user.admin? || params.dig(:enterprise,
+ :producer_properties_attributes).nil?
names = Spree::Property.pluck(:name)
enterprise_params[:producer_properties_attributes].each do |key, property|
enterprise_params[:producer_properties_attributes].delete key unless names.include? property[:property_name]
diff --git a/app/controllers/admin/inventory_items_controller.rb b/app/controllers/admin/inventory_items_controller.rb
index 779df14d79..4a2e40178c 100644
--- a/app/controllers/admin/inventory_items_controller.rb
+++ b/app/controllers/admin/inventory_items_controller.rb
@@ -1,15 +1,23 @@
+# frozen_string_literal: true
+
module Admin
class InventoryItemsController < Admin::ResourceController
respond_to :json
respond_override update: { json: {
success: lambda { render_as_json @inventory_item },
- failure: lambda { render json: { errors: @inventory_item.errors.full_messages }, status: :unprocessable_entity }
+ failure: lambda {
+ render json: { errors: @inventory_item.errors.full_messages },
+ status: :unprocessable_entity
+ }
} }
respond_override create: { json: {
success: lambda { render_as_json @inventory_item },
- failure: lambda { render json: { errors: @inventory_item.errors.full_messages }, status: :unprocessable_entity }
+ failure: lambda {
+ render json: { errors: @inventory_item.errors.full_messages },
+ status: :unprocessable_entity
+ }
} }
private
diff --git a/app/controllers/admin/invoice_settings_controller.rb b/app/controllers/admin/invoice_settings_controller.rb
index 0e52797b6b..36548e7df3 100644
--- a/app/controllers/admin/invoice_settings_controller.rb
+++ b/app/controllers/admin/invoice_settings_controller.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
module Admin
class InvoiceSettingsController < Spree::Admin::BaseController
def update
diff --git a/app/controllers/admin/manager_invitations_controller.rb b/app/controllers/admin/manager_invitations_controller.rb
index 3d9e93323d..39ea737021 100644
--- a/app/controllers/admin/manager_invitations_controller.rb
+++ b/app/controllers/admin/manager_invitations_controller.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
module Admin
class ManagerInvitationsController < Spree::Admin::BaseController
authorize_resource class: false
@@ -11,7 +13,8 @@ module Admin
existing_user = Spree::User.find_by(email: @email)
if existing_user
- render json: { errors: t('admin.enterprises.invite_manager.user_already_exists') }, status: :unprocessable_entity
+ render json: { errors: t('admin.enterprises.invite_manager.user_already_exists') },
+ status: :unprocessable_entity
return
end
@@ -20,7 +23,8 @@ module Admin
if new_user
render json: { user: new_user.id }, status: :ok
else
- render json: { errors: t('admin.enterprises.invite_manager.error') }, status: :internal_server_error
+ render json: { errors: t('admin.enterprises.invite_manager.error') },
+ status: :internal_server_error
end
end
diff --git a/app/controllers/admin/matomo_settings_controller.rb b/app/controllers/admin/matomo_settings_controller.rb
index 63196910f9..0775e4ab3f 100644
--- a/app/controllers/admin/matomo_settings_controller.rb
+++ b/app/controllers/admin/matomo_settings_controller.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
module Admin
class MatomoSettingsController < Spree::Admin::BaseController
def update
diff --git a/app/controllers/admin/order_cycles_controller.rb b/app/controllers/admin/order_cycles_controller.rb
index 56c317f0fb..05b6cb891d 100644
--- a/app/controllers/admin/order_cycles_controller.rb
+++ b/app/controllers/admin/order_cycles_controller.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
module Admin
class OrderCyclesController < Admin::ResourceController
include OrderCyclesHelper
@@ -156,8 +158,8 @@ module Admin
orders_close_at_gt = raw_params[:q].andand.delete(:orders_close_at_gt) || 31.days.ago
raw_params[:q] = {
g: [raw_params.delete(:q) || {}, { m: 'or',
- orders_close_at_gt: orders_close_at_gt,
- orders_close_at_null: true }]
+ orders_close_at_gt: orders_close_at_gt,
+ orders_close_at_null: true }]
}
@collection = collection
end
diff --git a/app/controllers/admin/producer_properties_controller.rb b/app/controllers/admin/producer_properties_controller.rb
index d2a4784a29..2ce3aca0db 100644
--- a/app/controllers/admin/producer_properties_controller.rb
+++ b/app/controllers/admin/producer_properties_controller.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
module Admin
class ProducerPropertiesController < Admin::ResourceController
before_action :load_enterprise
diff --git a/app/controllers/admin/product_import_controller.rb b/app/controllers/admin/product_import_controller.rb
index 8a5b5834b9..6c3dce8334 100644
--- a/app/controllers/admin/product_import_controller.rb
+++ b/app/controllers/admin/product_import_controller.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
require 'roo'
module Admin
@@ -12,7 +14,8 @@ module Admin
def import
@filepath = save_uploaded_file(params[:file])
- @importer = ProductImport::ProductImporter.new(File.new(@filepath), spree_current_user, params[:settings])
+ @importer = ProductImport::ProductImporter.new(File.new(@filepath), spree_current_user,
+ params[:settings])
@original_filename = params[:file].try(:original_filename)
@non_updatable_fields = ProductImport::EntryValidator.non_updatable_fields
@@ -34,7 +37,8 @@ module Admin
end
def reset_absent_products
- @importer = ProductImport::ProductImporter.new(File.new(params[:filepath]), spree_current_user, import_into: params[:import_into], enterprises_to_reset: params[:enterprises_to_reset], updated_ids: params[:updated_ids], settings: params[:settings])
+ @importer = ProductImport::ProductImporter.new(File.new(params[:filepath]),
+ spree_current_user, import_into: params[:import_into], enterprises_to_reset: params[:enterprises_to_reset], updated_ids: params[:updated_ids], settings: params[:settings])
if params.key?(:enterprises_to_reset) && params.key?(:updated_ids)
@importer.reset_absent(params[:updated_ids])
@@ -52,7 +56,8 @@ module Admin
end
def process_data(method)
- @importer = ProductImport::ProductImporter.new(File.new(params[:filepath]), spree_current_user, start: params[:start], end: params[:end], settings: params[:settings])
+ @importer = ProductImport::ProductImporter.new(File.new(params[:filepath]),
+ spree_current_user, start: params[:start], end: params[:end], settings: params[:settings])
begin
@importer.public_send("#{method}_entries")
@@ -75,7 +80,8 @@ module Admin
def check_spreadsheet_has_data(importer)
unless importer.item_count
- redirect_to '/admin/product_import', notice: I18n.t(:product_import_no_data_in_spreadsheet_notice)
+ redirect_to '/admin/product_import',
+ notice: I18n.t(:product_import_no_data_in_spreadsheet_notice)
true
end
end
diff --git a/app/controllers/admin/proxy_orders_controller.rb b/app/controllers/admin/proxy_orders_controller.rb
index c97bac2fc8..fbe51e5069 100644
--- a/app/controllers/admin/proxy_orders_controller.rb
+++ b/app/controllers/admin/proxy_orders_controller.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
module Admin
class ProxyOrdersController < Admin::ResourceController
respond_to :json
diff --git a/app/controllers/admin/resource_controller.rb b/app/controllers/admin/resource_controller.rb
index 3510093c0d..56fa7c5a5f 100644
--- a/app/controllers/admin/resource_controller.rb
+++ b/app/controllers/admin/resource_controller.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
module Admin
class ResourceController < Spree::Admin::BaseController
helper_method :new_object_url, :edit_object_url, :object_url, :collection_url
diff --git a/app/controllers/admin/schedules_controller.rb b/app/controllers/admin/schedules_controller.rb
index c88af92c32..e961f59b26 100644
--- a/app/controllers/admin/schedules_controller.rb
+++ b/app/controllers/admin/schedules_controller.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
require 'open_food_network/permissions'
require 'order_management/subscriptions/proxy_order_syncer'
@@ -15,18 +17,31 @@ module Admin
respond_to :json
respond_override create: { json: {
- success: lambda { render_as_json @schedule, editable_schedule_ids: permissions.editable_schedules.pluck(:id) },
- failure: lambda { render json: { errors: @schedule.errors.full_messages }, status: :unprocessable_entity }
+ success: lambda {
+ render_as_json @schedule,
+ editable_schedule_ids: permissions.editable_schedules.pluck(:id)
+ },
+ failure: lambda {
+ render json: { errors: @schedule.errors.full_messages },
+ status: :unprocessable_entity
+ }
} }
respond_override update: { json: {
- success: lambda { render_as_json @schedule, editable_schedule_ids: permissions.editable_schedules.pluck(:id) },
- failure: lambda { render json: { errors: @schedule.errors.full_messages }, status: :unprocessable_entity }
+ success: lambda {
+ render_as_json @schedule,
+ editable_schedule_ids: permissions.editable_schedules.pluck(:id)
+ },
+ failure: lambda {
+ render json: { errors: @schedule.errors.full_messages },
+ status: :unprocessable_entity
+ }
} }
def index
respond_to do |format|
format.json do
- render_as_json @collection, ams_prefix: params[:ams_prefix], editable_schedule_ids: permissions.editable_schedules.pluck(:id)
+ render_as_json @collection, ams_prefix: params[:ams_prefix],
+ editable_schedule_ids: permissions.editable_schedules.pluck(:id)
end
end
end
@@ -111,7 +126,8 @@ module Admin
def check_dependent_subscriptions
return if Subscription.where(schedule_id: @schedule).empty?
- render json: { errors: [t('admin.schedules.destroy.associated_subscriptions_error')] }, status: :conflict
+ render json: { errors: [t('admin.schedules.destroy.associated_subscriptions_error')] },
+ status: :conflict
end
def permissions
diff --git a/app/controllers/admin/stripe_accounts_controller.rb b/app/controllers/admin/stripe_accounts_controller.rb
index 91ae8a3403..b72175ac05 100644
--- a/app/controllers/admin/stripe_accounts_controller.rb
+++ b/app/controllers/admin/stripe_accounts_controller.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
require 'stripe/account_connector'
module Admin
diff --git a/app/controllers/admin/stripe_connect_settings_controller.rb b/app/controllers/admin/stripe_connect_settings_controller.rb
index 3b7ab969e2..81181b23c9 100644
--- a/app/controllers/admin/stripe_connect_settings_controller.rb
+++ b/app/controllers/admin/stripe_connect_settings_controller.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
# This controller is used by super admin users to update the settings the app is using
module Admin
diff --git a/app/controllers/admin/subscription_line_items_controller.rb b/app/controllers/admin/subscription_line_items_controller.rb
index 312e8846d7..b16d486225 100644
--- a/app/controllers/admin/subscription_line_items_controller.rb
+++ b/app/controllers/admin/subscription_line_items_controller.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
require 'open_food_network/permissions'
require 'open_food_network/order_cycle_permissions'
require 'open_food_network/scope_variant_to_hub'
diff --git a/app/controllers/admin/subscriptions_controller.rb b/app/controllers/admin/subscriptions_controller.rb
index aa1fd18db3..315a1a3c8b 100644
--- a/app/controllers/admin/subscriptions_controller.rb
+++ b/app/controllers/admin/subscriptions_controller.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
require 'open_food_network/permissions'
module Admin
@@ -85,7 +87,8 @@ module Admin
def collection
if request.format.json?
permissions.editable_subscriptions.ransack(params[:q]).result
- .preload([:shop, :customer, :schedule, :subscription_line_items, :ship_address, :bill_address, proxy_orders: { order: :order_cycle }])
+ .preload([:shop, :customer, :schedule, :subscription_line_items, :ship_address,
+ :bill_address, { proxy_orders: { order: :order_cycle } }])
else
Subscription.where("1=0")
end
@@ -116,11 +119,13 @@ module Admin
end
def wrap_bill_address_attrs
- subscription_params[:bill_address_attributes] = raw_params[:bill_address].slice(*Spree::Address.attribute_names)
+ subscription_params[:bill_address_attributes] =
+ raw_params[:bill_address].slice(*Spree::Address.attribute_names)
end
def wrap_ship_address_attrs
- subscription_params[:ship_address_attributes] = raw_params[:ship_address].slice(*Spree::Address.attribute_names)
+ subscription_params[:ship_address_attributes] =
+ raw_params[:ship_address].slice(*Spree::Address.attribute_names)
end
def check_for_open_orders
@@ -129,14 +134,16 @@ module Admin
@open_orders_to_keep = @subscription.proxy_orders.placed_and_open.pluck(:id)
return if @open_orders_to_keep.empty? || params[:open_orders] == 'keep'
- render json: { errors: { open_orders: t('admin.subscriptions.confirm_cancel_open_orders_msg') } }, status: :conflict
+ render json: { errors: { open_orders: t('admin.subscriptions.confirm_cancel_open_orders_msg') } },
+ status: :conflict
end
def check_for_canceled_orders
return if params[:canceled_orders] == 'notified'
return if @subscription.proxy_orders.active.canceled.empty?
- render json: { errors: { canceled_orders: t('admin.subscriptions.resume_canceled_orders_msg') } }, status: :conflict
+ render json: { errors: { canceled_orders: t('admin.subscriptions.resume_canceled_orders_msg') } },
+ status: :conflict
end
def strip_banned_attrs
diff --git a/app/controllers/admin/tag_rules_controller.rb b/app/controllers/admin/tag_rules_controller.rb
index 8ddbf82c83..fd00ea66be 100644
--- a/app/controllers/admin/tag_rules_controller.rb
+++ b/app/controllers/admin/tag_rules_controller.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
module Admin
class TagRulesController < Admin::ResourceController
respond_to :json
diff --git a/app/controllers/admin/variant_overrides_controller.rb b/app/controllers/admin/variant_overrides_controller.rb
index 6c20f59f44..33cc09fcf6 100644
--- a/app/controllers/admin/variant_overrides_controller.rb
+++ b/app/controllers/admin/variant_overrides_controller.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
require 'open_food_network/spree_api_key_loader'
module Admin
diff --git a/app/controllers/api/v0/taxons_controller.rb b/app/controllers/api/v0/taxons_controller.rb
index b3e74d0dac..f5529b7fcb 100644
--- a/app/controllers/api/v0/taxons_controller.rb
+++ b/app/controllers/api/v0/taxons_controller.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
module Api
module V0
class TaxonsController < Api::V0::BaseController
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb
index f7c6cfecb4..2fafbafcdd 100644
--- a/app/controllers/application_controller.rb
+++ b/app/controllers/application_controller.rb
@@ -52,10 +52,10 @@ class ApplicationController < ActionController::Base
def redirect_to(options = {}, response_status = {})
::Rails.logger.error("Redirected by #{begin
- caller(1).first
- rescue StandardError
- 'unknown'
- end}")
+ caller(1).first
+ rescue StandardError
+ 'unknown'
+ end}")
super(options, response_status)
end
diff --git a/app/controllers/cart_controller.rb b/app/controllers/cart_controller.rb
index 8ea8d31ab0..755b994a4c 100644
--- a/app/controllers/cart_controller.rb
+++ b/app/controllers/cart_controller.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
class CartController < BaseController
before_action :check_authorization
diff --git a/app/controllers/checkout_controller.rb b/app/controllers/checkout_controller.rb
index 5ec03bba20..f45e0e9c2f 100644
--- a/app/controllers/checkout_controller.rb
+++ b/app/controllers/checkout_controller.rb
@@ -152,8 +152,8 @@ class CheckoutController < ::BaseController
def checkout_workflow(shipping_method_id)
while @order.state != "complete"
- if @order.state == "payment"
- return if redirect_to_payment_gateway
+ if @order.state == "payment" && redirect_to_payment_gateway
+ return
end
next if OrderWorkflow.new(@order).next({ shipping_method_id: shipping_method_id })
diff --git a/app/controllers/discourse_sso_controller.rb b/app/controllers/discourse_sso_controller.rb
index e6753fb3db..8ac609e931 100644
--- a/app/controllers/discourse_sso_controller.rb
+++ b/app/controllers/discourse_sso_controller.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
require 'discourse/single_sign_on'
class DiscourseSsoController < ApplicationController
diff --git a/app/controllers/enterprises_controller.rb b/app/controllers/enterprises_controller.rb
index 841c9c76ff..93fb69053f 100644
--- a/app/controllers/enterprises_controller.rb
+++ b/app/controllers/enterprises_controller.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
require 'open_food_network/enterprise_injection_data'
class EnterprisesController < BaseController
diff --git a/app/controllers/groups_controller.rb b/app/controllers/groups_controller.rb
index d13876304e..c027a060e1 100644
--- a/app/controllers/groups_controller.rb
+++ b/app/controllers/groups_controller.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
class GroupsController < BaseController
layout 'darkswarm'
diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb
index c7612d3997..bcc04e8365 100644
--- a/app/controllers/home_controller.rb
+++ b/app/controllers/home_controller.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
class HomeController < BaseController
layout 'darkswarm'
diff --git a/app/controllers/line_items_controller.rb b/app/controllers/line_items_controller.rb
index b61d476d2e..50173af542 100644
--- a/app/controllers/line_items_controller.rb
+++ b/app/controllers/line_items_controller.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
class LineItemsController < BaseController
respond_to :json
diff --git a/app/controllers/map_controller.rb b/app/controllers/map_controller.rb
index 91c591e628..a64562762e 100644
--- a/app/controllers/map_controller.rb
+++ b/app/controllers/map_controller.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
class MapController < BaseController
layout 'darkswarm'
diff --git a/app/controllers/metal_decorator.rb b/app/controllers/metal_decorator.rb
index 0c8f81501f..9e9364fa81 100644
--- a/app/controllers/metal_decorator.rb
+++ b/app/controllers/metal_decorator.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
# For the API
ActionController::Metal.class_eval do
def spree_current_user
diff --git a/app/controllers/producers_controller.rb b/app/controllers/producers_controller.rb
index 108143e5e3..38e4e1c00f 100644
--- a/app/controllers/producers_controller.rb
+++ b/app/controllers/producers_controller.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
class ProducersController < BaseController
layout 'darkswarm'
diff --git a/app/controllers/registration_controller.rb b/app/controllers/registration_controller.rb
index 11f37fec13..29b523289e 100644
--- a/app/controllers/registration_controller.rb
+++ b/app/controllers/registration_controller.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
require 'open_food_network/spree_api_key_loader'
class RegistrationController < BaseController
diff --git a/app/controllers/shop_controller.rb b/app/controllers/shop_controller.rb
index c5f90a2856..b992d21a79 100644
--- a/app/controllers/shop_controller.rb
+++ b/app/controllers/shop_controller.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
class ShopController < BaseController
layout "darkswarm"
before_action :require_distributor_chosen, :set_order_cycles, except: :changeable_orders_alert
diff --git a/app/controllers/shops_controller.rb b/app/controllers/shops_controller.rb
index d644a5010f..6fc655c8bb 100644
--- a/app/controllers/shops_controller.rb
+++ b/app/controllers/shops_controller.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
class ShopsController < BaseController
layout 'darkswarm'
diff --git a/app/controllers/sitemap_controller.rb b/app/controllers/sitemap_controller.rb
index 103b6e93ee..c711fde412 100644
--- a/app/controllers/sitemap_controller.rb
+++ b/app/controllers/sitemap_controller.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
class SitemapController < ApplicationController
layout nil
diff --git a/app/controllers/spree/admin/adjustments_controller.rb b/app/controllers/spree/admin/adjustments_controller.rb
index 81e2194605..d86edaaac1 100644
--- a/app/controllers/spree/admin/adjustments_controller.rb
+++ b/app/controllers/spree/admin/adjustments_controller.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
module Spree
module Admin
class AdjustmentsController < ::Admin::ResourceController
diff --git a/app/controllers/spree/admin/base_controller.rb b/app/controllers/spree/admin/base_controller.rb
index 34e0202bdd..43115c5a46 100644
--- a/app/controllers/spree/admin/base_controller.rb
+++ b/app/controllers/spree/admin/base_controller.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
module Spree
module Admin
class BaseController < ApplicationController
diff --git a/app/controllers/spree/admin/countries_controller.rb b/app/controllers/spree/admin/countries_controller.rb
index 3cb6f78947..591014bd33 100644
--- a/app/controllers/spree/admin/countries_controller.rb
+++ b/app/controllers/spree/admin/countries_controller.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
module Spree
module Admin
class CountriesController < ::Admin::ResourceController
diff --git a/app/controllers/spree/admin/general_settings_controller.rb b/app/controllers/spree/admin/general_settings_controller.rb
index 6a7f116c89..3400686cf0 100644
--- a/app/controllers/spree/admin/general_settings_controller.rb
+++ b/app/controllers/spree/admin/general_settings_controller.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
module Spree
module Admin
class GeneralSettingsController < Spree::Admin::BaseController
diff --git a/app/controllers/spree/admin/images_controller.rb b/app/controllers/spree/admin/images_controller.rb
index 0757a78bf7..b258ef8e2c 100644
--- a/app/controllers/spree/admin/images_controller.rb
+++ b/app/controllers/spree/admin/images_controller.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
module Spree
module Admin
class ImagesController < ::Admin::ResourceController
diff --git a/app/controllers/spree/admin/invoices_controller.rb b/app/controllers/spree/admin/invoices_controller.rb
index 710fda1a3a..27d0009e53 100644
--- a/app/controllers/spree/admin/invoices_controller.rb
+++ b/app/controllers/spree/admin/invoices_controller.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
module Spree
module Admin
class InvoicesController < Spree::Admin::BaseController
diff --git a/app/controllers/spree/admin/mail_methods_controller.rb b/app/controllers/spree/admin/mail_methods_controller.rb
index 860f98bb49..df53f9275b 100644
--- a/app/controllers/spree/admin/mail_methods_controller.rb
+++ b/app/controllers/spree/admin/mail_methods_controller.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
module Spree
module Admin
class MailMethodsController < Spree::Admin::BaseController
diff --git a/app/controllers/spree/admin/orders/customer_details_controller.rb b/app/controllers/spree/admin/orders/customer_details_controller.rb
index 56502d54a0..a476c31fd2 100644
--- a/app/controllers/spree/admin/orders/customer_details_controller.rb
+++ b/app/controllers/spree/admin/orders/customer_details_controller.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
module Spree
module Admin
module Orders
diff --git a/app/controllers/spree/admin/orders_controller.rb b/app/controllers/spree/admin/orders_controller.rb
index 51f4bbe84d..505a182d39 100644
--- a/app/controllers/spree/admin/orders_controller.rb
+++ b/app/controllers/spree/admin/orders_controller.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
require 'open_food_network/spree_api_key_loader'
module Spree
diff --git a/app/controllers/spree/admin/overview_controller.rb b/app/controllers/spree/admin/overview_controller.rb
index d8bc38293a..229832514b 100644
--- a/app/controllers/spree/admin/overview_controller.rb
+++ b/app/controllers/spree/admin/overview_controller.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
# this clas was inspired (heavily) from the mephisto admin architecture
module Spree
module Admin
diff --git a/app/controllers/spree/admin/payment_methods_controller.rb b/app/controllers/spree/admin/payment_methods_controller.rb
index 0544f94faa..72ac7a7a35 100644
--- a/app/controllers/spree/admin/payment_methods_controller.rb
+++ b/app/controllers/spree/admin/payment_methods_controller.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
module Spree
module Admin
class PaymentMethodsController < ::Admin::ResourceController
diff --git a/app/controllers/spree/admin/payments_controller.rb b/app/controllers/spree/admin/payments_controller.rb
index 284830ecf0..8c831952ab 100644
--- a/app/controllers/spree/admin/payments_controller.rb
+++ b/app/controllers/spree/admin/payments_controller.rb
@@ -11,7 +11,7 @@ module Spree
before_action :can_transition_to_payment
# We ensure that items are in stock before all screens if the order is in the Payment state.
# This way, we don't allow someone to enter credit card details for an order only to be told
- # that it can't be processed.
+ # that it can't be processed.
before_action :ensure_sufficient_stock_lines
respond_to :html
@@ -150,7 +150,7 @@ module Spree
return if !@order.payment? || @order.insufficient_stock_lines.blank?
flash[:error] = I18n.t("spree.orders.line_item.insufficient_stock",
- on_hand: "0 #{out_of_stock_item_names}")
+ on_hand: "0 #{out_of_stock_item_names}")
redirect_to spree.edit_admin_order_url(@order)
end
@@ -171,7 +171,7 @@ module Spree
end
def authorize_stripe_sca_payment
- return unless @payment.payment_method.class == Spree::Gateway::StripeSCA
+ return unless @payment.payment_method.instance_of?(Spree::Gateway::StripeSCA)
@payment.authorize!(full_order_path(@payment.order))
diff --git a/app/controllers/spree/admin/product_properties_controller.rb b/app/controllers/spree/admin/product_properties_controller.rb
index 6c0b828641..c92f024d1f 100644
--- a/app/controllers/spree/admin/product_properties_controller.rb
+++ b/app/controllers/spree/admin/product_properties_controller.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
module Spree
module Admin
class ProductPropertiesController < ::Admin::ResourceController
diff --git a/app/controllers/spree/admin/products_controller.rb b/app/controllers/spree/admin/products_controller.rb
index 6dfd8d629a..0441b9a2f2 100644
--- a/app/controllers/spree/admin/products_controller.rb
+++ b/app/controllers/spree/admin/products_controller.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
require 'open_food_network/spree_api_key_loader'
require 'open_food_network/referer_parser'
require 'open_food_network/permissions'
@@ -161,7 +163,9 @@ module Spree
private
def product_set_from_params
- collection_hash = Hash[products_bulk_params[:products].each_with_index.map { |p, i| [i, p] }]
+ collection_hash = Hash[products_bulk_params[:products].each_with_index.map { |p, i|
+ [i, p]
+ } ]
Sets::ProductSet.new(collection_attributes: collection_hash)
end
diff --git a/app/controllers/spree/admin/properties_controller.rb b/app/controllers/spree/admin/properties_controller.rb
index 87cf620e5a..3b53b4b937 100644
--- a/app/controllers/spree/admin/properties_controller.rb
+++ b/app/controllers/spree/admin/properties_controller.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
module Spree
module Admin
class PropertiesController < ::Admin::ResourceController
diff --git a/app/controllers/spree/admin/reports_controller.rb b/app/controllers/spree/admin/reports_controller.rb
index 682d50250c..f0976ca4c1 100644
--- a/app/controllers/spree/admin/reports_controller.rb
+++ b/app/controllers/spree/admin/reports_controller.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
require 'csv'
require 'open_food_network/reports/list'
@@ -46,7 +48,8 @@ module Spree
def customers
@report_types = report_types[:customers]
@report_type = params[:report_type]
- @report = OpenFoodNetwork::CustomersReport.new spree_current_user, raw_params, render_content?
+ @report = OpenFoodNetwork::CustomersReport.new spree_current_user, raw_params,
+ render_content?
render_report(@report.header, @report.table, params[:csv], "customers_#{timestamp}.csv")
end
@@ -91,7 +94,8 @@ module Spree
def sales_tax
@distributors = my_distributors
@report_type = params[:report_type]
- @report = OpenFoodNetwork::SalesTaxReport.new spree_current_user, raw_params, render_content?
+ @report = OpenFoodNetwork::SalesTaxReport.new spree_current_user, raw_params,
+ render_content?
render_report(@report.header, @report.table, params[:csv], "sales_tax.csv")
end
@@ -101,7 +105,8 @@ module Spree
@report_type = params[:report_type]
# -- Build Report with Order Grouper
- @report = OpenFoodNetwork::PaymentsReport.new spree_current_user, raw_params, render_content?
+ @report = OpenFoodNetwork::PaymentsReport.new spree_current_user, raw_params,
+ render_content?
@table = order_grouper_table
csv_file_name = "payments_#{timestamp}.csv"
@@ -279,14 +284,14 @@ module Spree
def describe_report(report)
name = I18n.t(:name, scope: [:admin, :reports, report])
description = begin
- I18n.t!(:description, scope: [:admin, :reports, report])
- rescue I18n::MissingTranslationData
- render_to_string(
- partial: "#{report}_description",
- layout: false,
- locals: { report_types: report_types[report] }
- ).html_safe
- end
+ I18n.t!(:description, scope: [:admin, :reports, report])
+ rescue I18n::MissingTranslationData
+ render_to_string(
+ partial: "#{report}_description",
+ layout: false,
+ locals: { report_types: report_types[report] }
+ ).html_safe
+ end
{ name: name, url: url_for_report(report), description: description }
end
diff --git a/app/controllers/spree/admin/return_authorizations_controller.rb b/app/controllers/spree/admin/return_authorizations_controller.rb
index 313227f368..84b85ad345 100644
--- a/app/controllers/spree/admin/return_authorizations_controller.rb
+++ b/app/controllers/spree/admin/return_authorizations_controller.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
module Spree
module Admin
class ReturnAuthorizationsController < ::Admin::ResourceController
diff --git a/app/controllers/spree/admin/search_controller.rb b/app/controllers/spree/admin/search_controller.rb
index 802667a352..9869254b83 100644
--- a/app/controllers/spree/admin/search_controller.rb
+++ b/app/controllers/spree/admin/search_controller.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
module Spree
module Admin
class SearchController < Spree::Admin::BaseController
diff --git a/app/controllers/spree/admin/shipping_categories_controller.rb b/app/controllers/spree/admin/shipping_categories_controller.rb
index afb3c42f1b..fb689fe783 100644
--- a/app/controllers/spree/admin/shipping_categories_controller.rb
+++ b/app/controllers/spree/admin/shipping_categories_controller.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
module Spree
module Admin
class ShippingCategoriesController < ::Admin::ResourceController
diff --git a/app/controllers/spree/admin/shipping_methods_controller.rb b/app/controllers/spree/admin/shipping_methods_controller.rb
index 027603bff6..aa2e34b298 100644
--- a/app/controllers/spree/admin/shipping_methods_controller.rb
+++ b/app/controllers/spree/admin/shipping_methods_controller.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
module Spree
module Admin
class ShippingMethodsController < ::Admin::ResourceController
@@ -87,7 +89,7 @@ module Spree
params.require(:shipping_method).permit(
:name, :description, :display_on, :require_ship_address, :tag_list, :calculator_type,
:tax_category_id, distributor_ids: [],
- calculator_attributes: PermittedAttributes::Calculator.attributes
+ calculator_attributes: PermittedAttributes::Calculator.attributes
)
end
end
diff --git a/app/controllers/spree/admin/states_controller.rb b/app/controllers/spree/admin/states_controller.rb
index 0105cdddd9..ce031f384d 100644
--- a/app/controllers/spree/admin/states_controller.rb
+++ b/app/controllers/spree/admin/states_controller.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
module Spree
module Admin
class StatesController < ::Admin::ResourceController
diff --git a/app/controllers/spree/admin/tax_categories_controller.rb b/app/controllers/spree/admin/tax_categories_controller.rb
index f60c3d9174..e9d6547f48 100644
--- a/app/controllers/spree/admin/tax_categories_controller.rb
+++ b/app/controllers/spree/admin/tax_categories_controller.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
module Spree
module Admin
class TaxCategoriesController < ::Admin::ResourceController
diff --git a/app/controllers/spree/admin/tax_rates_controller.rb b/app/controllers/spree/admin/tax_rates_controller.rb
index 9e75426b93..8ae4c3db2c 100644
--- a/app/controllers/spree/admin/tax_rates_controller.rb
+++ b/app/controllers/spree/admin/tax_rates_controller.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
module Spree
module Admin
class TaxRatesController < ::Admin::ResourceController
diff --git a/app/controllers/spree/admin/tax_settings_controller.rb b/app/controllers/spree/admin/tax_settings_controller.rb
index 7ebeec543b..b43e3f615a 100644
--- a/app/controllers/spree/admin/tax_settings_controller.rb
+++ b/app/controllers/spree/admin/tax_settings_controller.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
module Spree
module Admin
class TaxSettingsController < Spree::Admin::BaseController
diff --git a/app/controllers/spree/admin/taxonomies_controller.rb b/app/controllers/spree/admin/taxonomies_controller.rb
index c2e668f1b6..68f65e000e 100644
--- a/app/controllers/spree/admin/taxonomies_controller.rb
+++ b/app/controllers/spree/admin/taxonomies_controller.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
module Spree
module Admin
class TaxonomiesController < ::Admin::ResourceController
diff --git a/app/controllers/spree/admin/taxons_controller.rb b/app/controllers/spree/admin/taxons_controller.rb
index 2d35da315b..ae625e9da6 100644
--- a/app/controllers/spree/admin/taxons_controller.rb
+++ b/app/controllers/spree/admin/taxons_controller.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
module Spree
module Admin
class TaxonsController < Spree::Admin::BaseController
diff --git a/app/controllers/spree/admin/users_controller.rb b/app/controllers/spree/admin/users_controller.rb
index 032e3aed56..bf5c054015 100644
--- a/app/controllers/spree/admin/users_controller.rb
+++ b/app/controllers/spree/admin/users_controller.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
module Spree
module Admin
class UsersController < ::Admin::ResourceController
diff --git a/app/controllers/spree/admin/variants_controller.rb b/app/controllers/spree/admin/variants_controller.rb
index c11c89b5af..fff1c5c139 100644
--- a/app/controllers/spree/admin/variants_controller.rb
+++ b/app/controllers/spree/admin/variants_controller.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
require 'open_food_network/scope_variants_for_search'
module Spree
diff --git a/app/controllers/spree/admin/zones_controller.rb b/app/controllers/spree/admin/zones_controller.rb
index d66512df44..f0acb77f22 100644
--- a/app/controllers/spree/admin/zones_controller.rb
+++ b/app/controllers/spree/admin/zones_controller.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
module Spree
module Admin
class ZonesController < ::Admin::ResourceController
diff --git a/app/controllers/spree/orders_controller.rb b/app/controllers/spree/orders_controller.rb
index 015ad64936..8f0162420d 100644
--- a/app/controllers/spree/orders_controller.rb
+++ b/app/controllers/spree/orders_controller.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
module Spree
class OrdersController < ::BaseController
include OrderCyclesHelper
@@ -131,7 +133,7 @@ module Spree
result = ProcessPaymentIntent.new(params["payment_intent"], @order).call!
unless result.ok?
- flash.now[:error] = "#{I18n.t("payment_could_not_process")}. #{result.error}"
+ flash.now[:error] = "#{I18n.t('payment_could_not_process')}. #{result.error}"
end
@order.reload
end
diff --git a/app/controllers/spree/paypal_controller.rb b/app/controllers/spree/paypal_controller.rb
index cae37e716b..82ccca19f3 100644
--- a/app/controllers/spree/paypal_controller.rb
+++ b/app/controllers/spree/paypal_controller.rb
@@ -26,7 +26,9 @@ module Spree
# sent back and the response is handled in the #confirm action in this controller.
redirect_to provider.express_checkout_url(pp_response, useraction: 'commit')
else
- flash[:error] = Spree.t('flash.generic_error', scope: 'paypal', reasons: pp_response.errors.map(&:long_message).join(" "))
+ flash[:error] =
+ Spree.t('flash.generic_error', scope: 'paypal',
+ reasons: pp_response.errors.map(&:long_message).join(" "))
redirect_to main_app.checkout_state_path(:payment)
end
rescue SocketError
diff --git a/app/controllers/spree/users_controller.rb b/app/controllers/spree/users_controller.rb
index 18effc349d..f97c4674ca 100644
--- a/app/controllers/spree/users_controller.rb
+++ b/app/controllers/spree/users_controller.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
module Spree
class UsersController < ::BaseController
layout 'darkswarm'
diff --git a/app/controllers/stripe/callbacks_controller.rb b/app/controllers/stripe/callbacks_controller.rb
index c699926a94..9eca54018f 100644
--- a/app/controllers/stripe/callbacks_controller.rb
+++ b/app/controllers/stripe/callbacks_controller.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
require 'stripe/account_connector'
module Stripe
@@ -13,7 +15,8 @@ module Stripe
else
flash[:error] = t('admin.controllers.enterprises.stripe_connect_fail')
end
- redirect_to main_app.edit_admin_enterprise_path(connector.enterprise, anchor: 'payment_methods')
+ redirect_to main_app.edit_admin_enterprise_path(connector.enterprise,
+ anchor: 'payment_methods')
rescue Stripe::StripeError => e
render plain: e.message, status: :internal_server_error
end
diff --git a/app/controllers/stripe/webhooks_controller.rb b/app/controllers/stripe/webhooks_controller.rb
index 41470d9e70..7497228326 100644
--- a/app/controllers/stripe/webhooks_controller.rb
+++ b/app/controllers/stripe/webhooks_controller.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
require 'stripe/webhook_handler'
module Stripe
diff --git a/app/controllers/user_confirmations_controller.rb b/app/controllers/user_confirmations_controller.rb
index 0915447bc5..b024504345 100644
--- a/app/controllers/user_confirmations_controller.rb
+++ b/app/controllers/user_confirmations_controller.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
class UserConfirmationsController < DeviseController
# Needed for access to current_ability, so we can authorize! actions
include Spree::Core::ControllerHelpers::Auth
diff --git a/app/controllers/user_passwords_controller.rb b/app/controllers/user_passwords_controller.rb
index 9314f5f41d..c33a1716f3 100644
--- a/app/controllers/user_passwords_controller.rb
+++ b/app/controllers/user_passwords_controller.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
class UserPasswordsController < Spree::UserPasswordsController
layout 'darkswarm'
diff --git a/app/controllers/user_registrations_controller.rb b/app/controllers/user_registrations_controller.rb
index f02309bf71..50638970f1 100644
--- a/app/controllers/user_registrations_controller.rb
+++ b/app/controllers/user_registrations_controller.rb
@@ -1,7 +1,9 @@
+# frozen_string_literal: true
+
require 'open_food_network/error_logger'
class UserRegistrationsController < Spree::UserRegistrationsController
- I18N_SCOPE = 'devise.user_registrations.spree_user'.freeze
+ I18N_SCOPE = 'devise.user_registrations.spree_user'
before_action :set_checkout_redirect, only: :create
diff --git a/app/helpers/admin/enterprises_helper.rb b/app/helpers/admin/enterprises_helper.rb
index 4f4bcde0f6..516caa9e1c 100644
--- a/app/helpers/admin/enterprises_helper.rb
+++ b/app/helpers/admin/enterprises_helper.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
module Admin
module EnterprisesHelper
def add_check_if_single(count)
diff --git a/app/helpers/admin/injection_helper.rb b/app/helpers/admin/injection_helper.rb
index c7cdd49c27..20482e0a4e 100644
--- a/app/helpers/admin/injection_helper.rb
+++ b/app/helpers/admin/injection_helper.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
module Admin
module InjectionHelper
def admin_inject_enterprise
diff --git a/app/helpers/admin/orders_helper.rb b/app/helpers/admin/orders_helper.rb
index 4be258821a..72a414bfd6 100644
--- a/app/helpers/admin/orders_helper.rb
+++ b/app/helpers/admin/orders_helper.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
module Admin
module OrdersHelper
# Adjustments to display under "Order adjustments".
diff --git a/app/helpers/admin/subscriptions_helper.rb b/app/helpers/admin/subscriptions_helper.rb
index 749584ea98..2f500ea55f 100644
--- a/app/helpers/admin/subscriptions_helper.rb
+++ b/app/helpers/admin/subscriptions_helper.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
module Admin
module SubscriptionsHelper
def subscriptions_setup_complete?(shops)
diff --git a/app/helpers/angular_form_builder.rb b/app/helpers/angular_form_builder.rb
index 41611f7f56..0fe5053f31 100644
--- a/app/helpers/angular_form_builder.rb
+++ b/app/helpers/angular_form_builder.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
class AngularFormBuilder < ActionView::Helpers::FormBuilder
def ng_fields_for(record_name, *_args)
raise "Nested ng_fields_for is not yet supported" if @fields_for_record_name.present?
@@ -23,13 +25,15 @@ class AngularFormBuilder < ActionView::Helpers::FormBuilder
def ng_select(method, choices, angular_field, options = {})
options.reverse_merge!('id' => angular_id(method), 'ng-model' => angular_model(method).to_s)
- @template.select_tag angular_name(method), @template.ng_options_for_select(choices, angular_field), options
+ @template.select_tag angular_name(method),
+ @template.ng_options_for_select(choices, angular_field), options
end
def ng_collection_select(method, collection, value_method, text_method, angular_field, options = {})
options.reverse_merge!('id' => angular_id(method), 'ng-model' => angular_model(method).to_s)
- @template.select_tag angular_name(method), @template.ng_options_from_collection_for_select(collection, value_method, text_method, angular_field), options
+ @template.select_tag angular_name(method),
+ @template.ng_options_from_collection_for_select(collection, value_method, text_method, angular_field), options
end
private
diff --git a/app/helpers/angular_form_helper.rb b/app/helpers/angular_form_helper.rb
index af21be3595..dd4afe9d86 100644
--- a/app/helpers/angular_form_helper.rb
+++ b/app/helpers/angular_form_helper.rb
@@ -1,6 +1,8 @@
+# frozen_string_literal: true
+
module AngularFormHelper
def ng_options_for_select(container, _angular_field = nil)
- return container if String === container
+ return container if container.is_a?(String)
container.map do |element|
html_attributes = option_html_attributes(element)
diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb
index d41d47bbb8..969a258446 100644
--- a/app/helpers/application_helper.rb
+++ b/app/helpers/application_helper.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
module ApplicationHelper
include RawParams
diff --git a/app/helpers/checkout_helper.rb b/app/helpers/checkout_helper.rb
index 5d764e15c4..8f05035bdd 100644
--- a/app/helpers/checkout_helper.rb
+++ b/app/helpers/checkout_helper.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
module CheckoutHelper
def guest_checkout_allowed?
current_order.distributor.allow_guest_orders?
@@ -10,12 +12,28 @@ module CheckoutHelper
# Remove empty tax adjustments and (optionally) shipping fees
adjustments.reject! { |a| a.originator_type == 'Spree::TaxRate' && a.amount == 0 }
- adjustments.reject! { |a| a.originator_type == 'Spree::ShippingMethod' } if exclude.include? :shipping
- adjustments.reject! { |a| a.originator_type == 'Spree::PaymentMethod' } if exclude.include? :payment
- adjustments.reject! { |a| a.adjustable_type == 'Spree::LineItem' } if exclude.include? :line_item
+ if exclude.include? :shipping
+ adjustments.reject! { |a|
+ a.originator_type == 'Spree::ShippingMethod'
+ }
+ end
+ if exclude.include? :payment
+ adjustments.reject! { |a|
+ a.originator_type == 'Spree::PaymentMethod'
+ }
+ end
+ if exclude.include? :line_item
+ adjustments.reject! { |a|
+ a.adjustable_type == 'Spree::LineItem'
+ }
+ end
- enterprise_fee_adjustments = adjustments.select { |a| a.originator_type == 'EnterpriseFee' && a.adjustable_type != 'Spree::LineItem' }
- adjustments.reject! { |a| a.originator_type == 'EnterpriseFee' && a.adjustable_type != 'Spree::LineItem' }
+ enterprise_fee_adjustments = adjustments.select { |a|
+ a.originator_type == 'EnterpriseFee' && a.adjustable_type != 'Spree::LineItem'
+ }
+ adjustments.reject! { |a|
+ a.originator_type == 'EnterpriseFee' && a.adjustable_type != 'Spree::LineItem'
+ }
unless exclude.include? :admin_and_handling
adjustments << Spree::Adjustment.new(
label: I18n.t(:orders_form_admin), amount: enterprise_fee_adjustments.sum(&:amount)
@@ -92,7 +110,8 @@ module CheckoutHelper
"ng-class" => "{error: !fieldValid('#{path}')}"
}.merge args
- render "shared/validated_select", name: name, path: path, options: options, attributes: attributes
+ render "shared/validated_select", name: name, path: path, options: options,
+ attributes: attributes
end
def payment_method_price(method, order)
diff --git a/app/helpers/discourse_helper.rb b/app/helpers/discourse_helper.rb
index 9e82c4d803..551636fe39 100644
--- a/app/helpers/discourse_helper.rb
+++ b/app/helpers/discourse_helper.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
module DiscourseHelper
def discourse_configured?
discourse_url.present?
diff --git a/app/helpers/enterprise_fees_helper.rb b/app/helpers/enterprise_fees_helper.rb
index 55647b6413..e6af949901 100644
--- a/app/helpers/enterprise_fees_helper.rb
+++ b/app/helpers/enterprise_fees_helper.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
module EnterpriseFeesHelper
def angular_name(method)
"sets_enterprise_fee_set[collection_attributes][{{ $index }}][#{method}]"
diff --git a/app/helpers/enterprises_helper.rb b/app/helpers/enterprises_helper.rb
index 52d9d134bf..397dff60f8 100644
--- a/app/helpers/enterprises_helper.rb
+++ b/app/helpers/enterprises_helper.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
require 'open_food_network/available_payment_method_filter'
module EnterprisesHelper
@@ -16,7 +18,8 @@ module EnterprisesHelper
shipping_methods = current_distributor.shipping_methods.display_on_checkout.to_a
- applicator = OpenFoodNetwork::TagRuleApplicator.new(current_distributor, "FilterShippingMethods", current_customer.andand.tag_list)
+ applicator = OpenFoodNetwork::TagRuleApplicator.new(current_distributor,
+ "FilterShippingMethods", current_customer.andand.tag_list)
applicator.filter!(shipping_methods)
shipping_methods.uniq
@@ -30,7 +33,8 @@ module EnterprisesHelper
filter = OpenFoodNetwork::AvailablePaymentMethodFilter.new
filter.filter!(payment_methods)
- applicator = OpenFoodNetwork::TagRuleApplicator.new(current_distributor, "FilterPaymentMethods", current_customer.andand.tag_list)
+ applicator = OpenFoodNetwork::TagRuleApplicator.new(current_distributor,
+ "FilterPaymentMethods", current_customer.andand.tag_list)
applicator.filter!(payment_methods)
payment_methods
@@ -47,7 +51,10 @@ module EnterprisesHelper
end
def enterprises_options(enterprises)
- enterprises.map { |enterprise| [enterprise.name + ": " + enterprise.address.address1 + ", " + enterprise.address.city, enterprise.id.to_i] }
+ enterprises.map { |enterprise|
+ [enterprise.name + ": " + enterprise.address.address1 + ", " + enterprise.address.city,
+ enterprise.id.to_i]
+ }
end
def enterprises_to_names(enterprises)
@@ -64,7 +71,8 @@ module EnterprisesHelper
def enterprise_confirm_delete_message(enterprise)
if enterprise.supplied_products.present?
- I18n.t(:enterprise_confirm_delete_message, product: pluralize(enterprise.supplied_products.count, 'product'))
+ I18n.t(:enterprise_confirm_delete_message,
+ product: pluralize(enterprise.supplied_products.count, 'product'))
else
t(:are_you_sure)
end
diff --git a/app/helpers/footer_links_helper.rb b/app/helpers/footer_links_helper.rb
index e084cca277..2cfb9f1c17 100644
--- a/app/helpers/footer_links_helper.rb
+++ b/app/helpers/footer_links_helper.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
require 'web/cookies_consent'
module FooterLinksHelper
diff --git a/app/helpers/groups_helper.rb b/app/helpers/groups_helper.rb
index 28b10f87f1..5f6b188abf 100644
--- a/app/helpers/groups_helper.rb
+++ b/app/helpers/groups_helper.rb
@@ -1,11 +1,11 @@
+# frozen_string_literal: true
+
module GroupsHelper
- def link_to_service(baseurl, name, html_options = {})
+ def link_to_service(baseurl, name, html_options = {}, &block)
return if name.blank?
html_options = html_options.merge target: '_blank'
- link_to ext_url(baseurl, name), html_options do
- yield
- end
+ link_to ext_url(baseurl, name), html_options, &block
end
def ext_url(prefix, url)
diff --git a/app/helpers/i18n_helper.rb b/app/helpers/i18n_helper.rb
index 8c827e1bba..6ca7d9d5b4 100644
--- a/app/helpers/i18n_helper.rb
+++ b/app/helpers/i18n_helper.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
module I18nHelper
def set_locale
UserLocaleSetter.new(spree_current_user, params[:locale], cookies).set_locale
diff --git a/app/helpers/injection_helper.rb b/app/helpers/injection_helper.rb
index 3af44f885f..cf2d268aa0 100644
--- a/app/helpers/injection_helper.rb
+++ b/app/helpers/injection_helper.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
require 'open_food_network/enterprise_injection_data'
module InjectionHelper
diff --git a/app/helpers/map_helper.rb b/app/helpers/map_helper.rb
index b2ef609c77..bc3b66c49c 100644
--- a/app/helpers/map_helper.rb
+++ b/app/helpers/map_helper.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
module MapHelper
def using_google_maps?
ENV["GOOGLE_MAPS_API_KEY"].present? || google_maps_configured_with_geocoder_api_key?
diff --git a/app/helpers/markdown_helper.rb b/app/helpers/markdown_helper.rb
index bd45e31124..6b9a98129b 100644
--- a/app/helpers/markdown_helper.rb
+++ b/app/helpers/markdown_helper.rb
@@ -1,6 +1,9 @@
+# frozen_string_literal: true
+
module MarkdownHelper
def render_markdown(markdown)
- md ||= Redcarpet::Markdown.new(Redcarpet::Render::HTML, no_intra_emphasis: true, tables: true, autolink: true, superscript: true)
+ md ||= Redcarpet::Markdown.new(Redcarpet::Render::HTML, no_intra_emphasis: true, tables: true,
+ autolink: true, superscript: true)
md.render markdown
end
end
diff --git a/app/helpers/order_cycles_helper.rb b/app/helpers/order_cycles_helper.rb
index d5184a0436..6341d230c6 100644
--- a/app/helpers/order_cycles_helper.rb
+++ b/app/helpers/order_cycles_helper.rb
@@ -32,7 +32,8 @@ module OrderCyclesHelper
end
def permitted_hub_enterprise_options_for(order_cycle)
- validated_enterprise_options permitted_hub_enterprises_for(order_cycle), shipping_and_payment_methods: true
+ validated_enterprise_options permitted_hub_enterprises_for(order_cycle),
+ shipping_and_payment_methods: true
end
def order_cycle_status_class(order_cycle)
diff --git a/app/helpers/serializer_helper.rb b/app/helpers/serializer_helper.rb
index f30d998f73..c3134e9c3f 100644
--- a/app/helpers/serializer_helper.rb
+++ b/app/helpers/serializer_helper.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
module SerializerHelper
def ids_to_objs(ids)
return [] if ids.blank?
diff --git a/app/helpers/shared_helper.rb b/app/helpers/shared_helper.rb
index 2c9bb17990..8d087e8aaa 100644
--- a/app/helpers/shared_helper.rb
+++ b/app/helpers/shared_helper.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
module SharedHelper
def distributor_link_class(distributor)
cart = current_order(true)
diff --git a/app/helpers/shop_helper.rb b/app/helpers/shop_helper.rb
index fbd48f719f..2f19c1d227 100644
--- a/app/helpers/shop_helper.rb
+++ b/app/helpers/shop_helper.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
module ShopHelper
def oc_select_options
@order_cycles.map { |oc| { time: pickup_time(oc), id: oc.id } }
diff --git a/app/helpers/shop_mail_helper.rb b/app/helpers/shop_mail_helper.rb
index ad97f878bb..924860d466 100644
--- a/app/helpers/shop_mail_helper.rb
+++ b/app/helpers/shop_mail_helper.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
module ShopMailHelper
# Long datetime format string used in emails to customers
#
diff --git a/app/helpers/spree/admin/base_helper.rb b/app/helpers/spree/admin/base_helper.rb
index 157762e823..3983cf3fda 100644
--- a/app/helpers/spree/admin/base_helper.rb
+++ b/app/helpers/spree/admin/base_helper.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
module Spree
module Admin
module BaseHelper
diff --git a/app/helpers/spree/admin/general_settings_helper.rb b/app/helpers/spree/admin/general_settings_helper.rb
index 29e491fe83..88d5a752dd 100644
--- a/app/helpers/spree/admin/general_settings_helper.rb
+++ b/app/helpers/spree/admin/general_settings_helper.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
module Spree
module Admin
module GeneralSettingsHelper
diff --git a/app/helpers/spree/admin/orders_helper.rb b/app/helpers/spree/admin/orders_helper.rb
index 112b264d7f..e631555560 100644
--- a/app/helpers/spree/admin/orders_helper.rb
+++ b/app/helpers/spree/admin/orders_helper.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
module Spree
module Admin
module OrdersHelper
diff --git a/app/helpers/spree/admin/taxons_helper.rb b/app/helpers/spree/admin/taxons_helper.rb
index 87ee61dbd5..e8e4d8d918 100644
--- a/app/helpers/spree/admin/taxons_helper.rb
+++ b/app/helpers/spree/admin/taxons_helper.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
module Spree
module Admin
module TaxonsHelper
diff --git a/app/helpers/spree/admin/zones_helper.rb b/app/helpers/spree/admin/zones_helper.rb
index fa8044e953..57a1a639c1 100644
--- a/app/helpers/spree/admin/zones_helper.rb
+++ b/app/helpers/spree/admin/zones_helper.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: false
+
module Spree
module Admin
module ZonesHelper
diff --git a/app/helpers/spree/orders_helper.rb b/app/helpers/spree/orders_helper.rb
index 2ade8790d2..a2f4837b8a 100644
--- a/app/helpers/spree/orders_helper.rb
+++ b/app/helpers/spree/orders_helper.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
module Spree
module OrdersHelper
def cart_is_empty
diff --git a/app/helpers/spree/payment_methods_helper.rb b/app/helpers/spree/payment_methods_helper.rb
index 361d6c6afd..50fe34d457 100644
--- a/app/helpers/spree/payment_methods_helper.rb
+++ b/app/helpers/spree/payment_methods_helper.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
module Spree
module PaymentMethodsHelper
def payment_method(payment)
diff --git a/app/helpers/spree/reports_helper.rb b/app/helpers/spree/reports_helper.rb
index eb1c60cd3c..38fcd2a35e 100644
--- a/app/helpers/spree/reports_helper.rb
+++ b/app/helpers/spree/reports_helper.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
require 'spree/money'
module Spree
diff --git a/app/helpers/spree_currency_helper.rb b/app/helpers/spree_currency_helper.rb
index 479ced2771..39e91c9918 100644
--- a/app/helpers/spree_currency_helper.rb
+++ b/app/helpers/spree_currency_helper.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
module SpreeCurrencyHelper
def spree_number_to_currency(amount)
Spree::Money.new(amount).to_s
diff --git a/app/helpers/terms_and_conditions_helper.rb b/app/helpers/terms_and_conditions_helper.rb
index 47580b098e..ce53ac3ed9 100644
--- a/app/helpers/terms_and_conditions_helper.rb
+++ b/app/helpers/terms_and_conditions_helper.rb
@@ -2,7 +2,8 @@
module TermsAndConditionsHelper
def link_to_platform_terms
- link_to(t("terms_of_service"), TermsOfServiceFile.current_url, target: "_blank")
+ link_to(t("terms_of_service"), TermsOfServiceFile.current_url, target: "_blank",
+ rel: "noopener")
end
def render_terms_and_conditions
diff --git a/app/jobs/job_logger.rb b/app/jobs/job_logger.rb
index 59de7d9c61..e72a35a69c 100644
--- a/app/jobs/job_logger.rb
+++ b/app/jobs/job_logger.rb
@@ -10,9 +10,9 @@ module JobLogger
def self.logger
@logger ||= begin
- logger = Rails.logger.clone
- logger.formatter = Formatter.new
- logger
- end
+ logger = Rails.logger.clone
+ logger.formatter = Formatter.new
+ logger
+ end
end
end
diff --git a/app/jobs/subscription_confirm_job.rb b/app/jobs/subscription_confirm_job.rb
index 80a4517a43..e492036220 100644
--- a/app/jobs/subscription_confirm_job.rb
+++ b/app/jobs/subscription_confirm_job.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
require 'order_management/subscriptions/summarizer'
# Confirms orders of unconfirmed proxy orders in recently closed Order Cycles
@@ -38,7 +40,9 @@ class SubscriptionConfirmJob < ActiveJob::Base
end
def recently_closed_order_cycles
- OrderCycle.closed.where('order_cycles.orders_close_at BETWEEN (?) AND (?) OR order_cycles.updated_at BETWEEN (?) AND (?)', 1.hour.ago, Time.zone.now, 1.hour.ago, Time.zone.now)
+ OrderCycle.closed.where(
+ 'order_cycles.orders_close_at BETWEEN (?) AND (?) OR order_cycles.updated_at BETWEEN (?) AND (?)', 1.hour.ago, Time.zone.now, 1.hour.ago, Time.zone.now
+ )
end
# It sets up payments, processes payments and sends confirmation emails
diff --git a/app/jobs/subscription_placement_job.rb b/app/jobs/subscription_placement_job.rb
index 2d5d726bb3..45a8de23cb 100644
--- a/app/jobs/subscription_placement_job.rb
+++ b/app/jobs/subscription_placement_job.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
require 'order_management/subscriptions/summarizer'
class SubscriptionPlacementJob < ActiveJob::Base
diff --git a/app/mailers/enterprise_mailer.rb b/app/mailers/enterprise_mailer.rb
index 3ac2677a67..dd094c8de4 100644
--- a/app/mailers/enterprise_mailer.rb
+++ b/app/mailers/enterprise_mailer.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
require 'devise/mailers/helpers'
class EnterpriseMailer < Spree::BaseMailer
include Devise::Mailers::Helpers
diff --git a/app/mailers/spree/user_mailer.rb b/app/mailers/spree/user_mailer.rb
index 449f4c5dfc..f85b8a11a0 100644
--- a/app/mailers/spree/user_mailer.rb
+++ b/app/mailers/spree/user_mailer.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
# This mailer is configured to be the Devise mailer
# Some methods here override Devise::Mailer methods
module Spree
diff --git a/app/mailers/subscription_mailer.rb b/app/mailers/subscription_mailer.rb
index 90efc9ee40..11900bde3b 100644
--- a/app/mailers/subscription_mailer.rb
+++ b/app/mailers/subscription_mailer.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
class SubscriptionMailer < Spree::BaseMailer
helper 'checkout'
helper MailerHelper
diff --git a/app/models/adjustment_metadata.rb b/app/models/adjustment_metadata.rb
index c282368aca..eb99ad1de7 100644
--- a/app/models/adjustment_metadata.rb
+++ b/app/models/adjustment_metadata.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
class AdjustmentMetadata < ApplicationRecord
belongs_to :adjustment, class_name: 'Spree::Adjustment'
belongs_to :enterprise
diff --git a/app/models/calculator/flat_percent_per_item.rb b/app/models/calculator/flat_percent_per_item.rb
index 84d4f73b8f..f9e197c594 100644
--- a/app/models/calculator/flat_percent_per_item.rb
+++ b/app/models/calculator/flat_percent_per_item.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
require 'spree/localized_number'
class Calculator::FlatPercentPerItem < Spree::Calculator
diff --git a/app/models/calculator/weight.rb b/app/models/calculator/weight.rb
index 8f060bb826..405598ebb7 100644
--- a/app/models/calculator/weight.rb
+++ b/app/models/calculator/weight.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
require 'spree/localized_number'
module Calculator
diff --git a/app/models/column_preference.rb b/app/models/column_preference.rb
index 0b60831541..a4e52b577c 100644
--- a/app/models/column_preference.rb
+++ b/app/models/column_preference.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
require 'open_food_network/column_preference_defaults'
class ColumnPreference < ApplicationRecord
@@ -10,7 +12,9 @@ class ColumnPreference < ApplicationRecord
belongs_to :user, class_name: "Spree::User"
validates :action_name, presence: true, inclusion: { in: proc { known_actions } }
- validates :column_name, presence: true, inclusion: { in: proc { |p| valid_columns_for(p.action_name) } }
+ validates :column_name, presence: true, inclusion: { in: proc { |p|
+ valid_columns_for(p.action_name)
+ } }
def self.for(user, action_name)
stored_preferences = where(user_id: user.id, action_name: action_name)
@@ -19,17 +23,18 @@ class ColumnPreference < ApplicationRecord
default_preferences.each_with_object([]) do |(column_name, default_attributes), preferences|
stored_preference = stored_preferences.find_by(column_name: column_name)
if stored_preference
- stored_preference.assign_attributes(default_attributes.select{ |k, _v| stored_preference[k].nil? })
+ stored_preference.assign_attributes(default_attributes.select{ |k, _v|
+ stored_preference[k].nil?
+ } )
preferences << stored_preference
else
- attributes = default_attributes.merge(user_id: user.id, action_name: action_name, column_name: column_name)
+ attributes = default_attributes.merge(user_id: user.id, action_name: action_name,
+ column_name: column_name)
preferences << ColumnPreference.new(attributes)
end
end
end
- private
-
def self.valid_columns_for(action_name)
__send__("#{action_name}_columns").keys.map(&:to_s)
end
diff --git a/app/models/concerns/address_display.rb b/app/models/concerns/address_display.rb
index c585087e18..602fbae7c6 100644
--- a/app/models/concerns/address_display.rb
+++ b/app/models/concerns/address_display.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
module AddressDisplay
def full_name_reverse
[lastname, firstname].reject(&:blank?).join(" ")
diff --git a/app/models/concerns/adjustment_scopes.rb b/app/models/concerns/adjustment_scopes.rb
index 927e9e8c1c..18e21fccec 100644
--- a/app/models/concerns/adjustment_scopes.rb
+++ b/app/models/concerns/adjustment_scopes.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
module AdjustmentScopes
extend ActiveSupport::Concern
diff --git a/app/models/concerns/order_shipment.rb b/app/models/concerns/order_shipment.rb
index 1f9c937bb5..267edf64f4 100644
--- a/app/models/concerns/order_shipment.rb
+++ b/app/models/concerns/order_shipment.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
require 'active_support/concern'
# This module is an adapter for OFN to work with Spree 2 code.
diff --git a/app/models/concerns/product_stock.rb b/app/models/concerns/product_stock.rb
index 60e98d7791..9ca52370fc 100644
--- a/app/models/concerns/product_stock.rb
+++ b/app/models/concerns/product_stock.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
require 'active_support/concern'
module ProductStock
diff --git a/app/models/concerns/stock_settings_override_validation.rb b/app/models/concerns/stock_settings_override_validation.rb
index b548a8b64b..7040cb50e0 100644
--- a/app/models/concerns/stock_settings_override_validation.rb
+++ b/app/models/concerns/stock_settings_override_validation.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
# Validates the combination of on_demand and count_on_hand values.
#
# `on_demand` can have three values: true, false or nil
diff --git a/app/models/concerns/variant_stock.rb b/app/models/concerns/variant_stock.rb
index 1fd816bc8c..81e9383727 100644
--- a/app/models/concerns/variant_stock.rb
+++ b/app/models/concerns/variant_stock.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
require 'active_support/concern'
# These methods were available in Spree 1, but were removed in Spree 2. We
diff --git a/app/models/content_configuration.rb b/app/models/content_configuration.rb
index efe91e05b6..0f34598cd7 100644
--- a/app/models/content_configuration.rb
+++ b/app/models/content_configuration.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
require 'open_food_network/paperclippable'
class ContentConfiguration < Spree::Preferences::FileConfiguration
@@ -27,18 +29,24 @@ class ContentConfiguration < Spree::Preferences::FileConfiguration
# Producer sign-up page
# All the following defaults using I18n don't work.
# https://github.com/openfoodfoundation/openfoodnetwork/issues/3816
- preference :producer_signup_pricing_table_html, :text, default: I18n.t(:content_configuration_pricing_table)
- preference :producer_signup_case_studies_html, :text, default: I18n.t(:content_configuration_case_studies)
+ preference :producer_signup_pricing_table_html, :text,
+ default: I18n.t(:content_configuration_pricing_table)
+ preference :producer_signup_case_studies_html, :text,
+ default: I18n.t(:content_configuration_case_studies)
preference :producer_signup_detail_html, :text, default: I18n.t(:content_configuration_detail)
# Hubs sign-up page
- preference :hub_signup_pricing_table_html, :text, default: I18n.t(:content_configuration_pricing_table)
- preference :hub_signup_case_studies_html, :text, default: I18n.t(:content_configuration_case_studies)
+ preference :hub_signup_pricing_table_html, :text,
+ default: I18n.t(:content_configuration_pricing_table)
+ preference :hub_signup_case_studies_html, :text,
+ default: I18n.t(:content_configuration_case_studies)
preference :hub_signup_detail_html, :text, default: I18n.t(:content_configuration_detail)
# Groups sign-up page
- preference :group_signup_pricing_table_html, :text, default: I18n.t(:content_configuration_pricing_table)
- preference :group_signup_case_studies_html, :text, default: I18n.t(:content_configuration_case_studies)
+ preference :group_signup_pricing_table_html, :text,
+ default: I18n.t(:content_configuration_pricing_table)
+ preference :group_signup_case_studies_html, :text,
+ default: I18n.t(:content_configuration_case_studies)
preference :group_signup_detail_html, :text, default: I18n.t(:content_configuration_detail)
# Main URLs
diff --git a/app/models/coordinator_fee.rb b/app/models/coordinator_fee.rb
index 92238cbebe..b308c611b1 100644
--- a/app/models/coordinator_fee.rb
+++ b/app/models/coordinator_fee.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
class CoordinatorFee < ApplicationRecord
belongs_to :order_cycle
belongs_to :enterprise_fee
diff --git a/app/models/customer.rb b/app/models/customer.rb
index e128bde491..a3baf79e6d 100644
--- a/app/models/customer.rb
+++ b/app/models/customer.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
class Customer < ApplicationRecord
acts_as_taggable
@@ -6,11 +8,11 @@ class Customer < ApplicationRecord
has_many :orders, class_name: "Spree::Order"
before_destroy :check_for_orders
- belongs_to :bill_address, foreign_key: :bill_address_id, class_name: "Spree::Address"
+ belongs_to :bill_address, class_name: "Spree::Address"
alias_attribute :billing_address, :bill_address
accepts_nested_attributes_for :bill_address
- belongs_to :ship_address, foreign_key: :ship_address_id, class_name: "Spree::Address"
+ belongs_to :ship_address, class_name: "Spree::Address"
alias_attribute :shipping_address, :ship_address
accepts_nested_attributes_for :ship_address
@@ -18,15 +20,15 @@ class Customer < ApplicationRecord
before_validation :empty_code
validates :code, uniqueness: { scope: :enterprise_id, allow_nil: true }
- validates :email, presence: true, uniqueness: { scope: :enterprise_id, message: I18n.t('validation_msg_is_associated_with_an_exising_customer') }
+ validates :email, presence: true,
+ uniqueness: { scope: :enterprise_id, message: I18n.t('validation_msg_is_associated_with_an_exising_customer') }
validates :enterprise, presence: true
scope :of, ->(enterprise) { where(enterprise_id: enterprise) }
before_create :associate_user
- attr_accessor :gateway_recurring_payment_client_secret
- attr_accessor :gateway_shop_id
+ attr_accessor :gateway_recurring_payment_client_secret, :gateway_shop_id
private
diff --git a/app/models/distributor_shipping_method.rb b/app/models/distributor_shipping_method.rb
index 87aba1b139..ebce5682bc 100644
--- a/app/models/distributor_shipping_method.rb
+++ b/app/models/distributor_shipping_method.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
class DistributorShippingMethod < ApplicationRecord
self.table_name = "distributors_shipping_methods"
belongs_to :shipping_method, class_name: "Spree::ShippingMethod", touch: true
diff --git a/app/models/enterprise.rb b/app/models/enterprise.rb
index 1b4697c57e..54bf40cb10 100644
--- a/app/models/enterprise.rb
+++ b/app/models/enterprise.rb
@@ -38,7 +38,6 @@ class Enterprise < ApplicationRecord
has_many :enterprise_roles, dependent: :destroy
has_many :users, through: :enterprise_roles
belongs_to :owner, class_name: 'Spree::User',
- foreign_key: :owner_id,
inverse_of: :owned_enterprises
has_and_belongs_to_many :payment_methods, join_table: 'distributors_payment_methods',
class_name: 'Spree::PaymentMethod',
diff --git a/app/models/enterprise_fee.rb b/app/models/enterprise_fee.rb
index ff17383598..91b262e279 100644
--- a/app/models/enterprise_fee.rb
+++ b/app/models/enterprise_fee.rb
@@ -1,10 +1,12 @@
+# frozen_string_literal: true
+
class EnterpriseFee < ApplicationRecord
include Spree::Core::CalculatedAdjustments
acts_as_paranoid
belongs_to :enterprise
- belongs_to :tax_category, class_name: 'Spree::TaxCategory', foreign_key: 'tax_category_id'
+ belongs_to :tax_category, class_name: 'Spree::TaxCategory'
has_many :coordinator_fees, dependent: :destroy
has_many :order_cycles, through: :coordinator_fees
diff --git a/app/models/enterprise_group.rb b/app/models/enterprise_group.rb
index cde5d60e7c..7d100ea2c6 100644
--- a/app/models/enterprise_group.rb
+++ b/app/models/enterprise_group.rb
@@ -9,7 +9,7 @@ class EnterpriseGroup < ApplicationRecord
acts_as_list
has_and_belongs_to_many :enterprises, join_table: 'enterprise_groups_enterprises'
- belongs_to :owner, class_name: 'Spree::User', foreign_key: :owner_id, inverse_of: :owned_groups
+ belongs_to :owner, class_name: 'Spree::User', inverse_of: :owned_groups
belongs_to :address, class_name: 'Spree::Address'
accepts_nested_attributes_for :address
validates :address, presence: true, associated: true
diff --git a/app/models/enterprise_relationship_permission.rb b/app/models/enterprise_relationship_permission.rb
index 55d70d57a8..33bf4a2fe2 100644
--- a/app/models/enterprise_relationship_permission.rb
+++ b/app/models/enterprise_relationship_permission.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
class EnterpriseRelationshipPermission < ApplicationRecord
default_scope { order('name') }
end
diff --git a/app/models/enterprise_role.rb b/app/models/enterprise_role.rb
index 72071eb69e..9b9290cf92 100644
--- a/app/models/enterprise_role.rb
+++ b/app/models/enterprise_role.rb
@@ -1,9 +1,12 @@
+# frozen_string_literal: true
+
class EnterpriseRole < ApplicationRecord
belongs_to :user, class_name: Spree.user_class.to_s
belongs_to :enterprise
validates :user, :enterprise, presence: true
- validates :enterprise_id, uniqueness: { scope: :user_id, message: I18n.t(:enterprise_role_uniqueness_error) }
+ validates :enterprise_id,
+ uniqueness: { scope: :user_id, message: I18n.t(:enterprise_role_uniqueness_error) }
scope :by_user_email, -> { joins(:user).order('spree_users.email ASC') }
end
diff --git a/app/models/exchange.rb b/app/models/exchange.rb
index 2cbb1e6928..a315ccd1c6 100644
--- a/app/models/exchange.rb
+++ b/app/models/exchange.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
# Representation of an enterprise being part of an order cycle.
#
# A producer can be part as supplier. The supplier's products can be selected to
diff --git a/app/models/exchange_fee.rb b/app/models/exchange_fee.rb
index 7d9fa49269..e2eda0d611 100644
--- a/app/models/exchange_fee.rb
+++ b/app/models/exchange_fee.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
class ExchangeFee < ApplicationRecord
belongs_to :exchange
belongs_to :enterprise_fee
diff --git a/app/models/exchange_variant.rb b/app/models/exchange_variant.rb
index 01b792734e..46ef647f89 100644
--- a/app/models/exchange_variant.rb
+++ b/app/models/exchange_variant.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
class ExchangeVariant < ApplicationRecord
belongs_to :exchange
belongs_to :variant, class_name: 'Spree::Variant'
diff --git a/app/models/inventory_item.rb b/app/models/inventory_item.rb
index 91ba0f6d10..601172999d 100644
--- a/app/models/inventory_item.rb
+++ b/app/models/inventory_item.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
class InventoryItem < ApplicationRecord
belongs_to :enterprise
belongs_to :variant, class_name: "Spree::Variant"
@@ -5,7 +7,8 @@ class InventoryItem < ApplicationRecord
validates :variant_id, uniqueness: { scope: :enterprise_id }
validates :enterprise, presence: true
validates :variant, presence: true
- validates :visible, inclusion: { in: [true, false], message: I18n.t(:inventory_item_visibility_error) }
+ validates :visible,
+ inclusion: { in: [true, false], message: I18n.t(:inventory_item_visibility_error) }
scope :visible, -> { where(visible: true) }
scope :hidden, -> { where(visible: false) }
diff --git a/app/models/order_cycle.rb b/app/models/order_cycle.rb
index 37073c3628..e4e2c26106 100644
--- a/app/models/order_cycle.rb
+++ b/app/models/order_cycle.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
require 'open_food_network/scope_variant_to_hub'
class OrderCycle < ApplicationRecord
diff --git a/app/models/preference_sections/footer_and_external_links_section.rb b/app/models/preference_sections/footer_and_external_links_section.rb
index cf9d926553..e2105bf3b8 100644
--- a/app/models/preference_sections/footer_and_external_links_section.rb
+++ b/app/models/preference_sections/footer_and_external_links_section.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
module PreferenceSections
class FooterAndExternalLinksSection
def name
diff --git a/app/models/preference_sections/group_signup_page_section.rb b/app/models/preference_sections/group_signup_page_section.rb
index b28570fcd6..6ef026111c 100644
--- a/app/models/preference_sections/group_signup_page_section.rb
+++ b/app/models/preference_sections/group_signup_page_section.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
module PreferenceSections
class GroupSignupPageSection
def name
diff --git a/app/models/preference_sections/header_section.rb b/app/models/preference_sections/header_section.rb
index 87e09d6e03..fda25ec075 100644
--- a/app/models/preference_sections/header_section.rb
+++ b/app/models/preference_sections/header_section.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
module PreferenceSections
class HeaderSection
def name
diff --git a/app/models/preference_sections/home_page_section.rb b/app/models/preference_sections/home_page_section.rb
index b050322689..0591e834c6 100644
--- a/app/models/preference_sections/home_page_section.rb
+++ b/app/models/preference_sections/home_page_section.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
module PreferenceSections
class HomePageSection
def name
diff --git a/app/models/preference_sections/hub_signup_page_section.rb b/app/models/preference_sections/hub_signup_page_section.rb
index 3c80e3ebff..d8ee08cb9f 100644
--- a/app/models/preference_sections/hub_signup_page_section.rb
+++ b/app/models/preference_sections/hub_signup_page_section.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
module PreferenceSections
class HubSignupPageSection
def name
diff --git a/app/models/preference_sections/main_links_section.rb b/app/models/preference_sections/main_links_section.rb
index b23833650f..9190483efc 100644
--- a/app/models/preference_sections/main_links_section.rb
+++ b/app/models/preference_sections/main_links_section.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
module PreferenceSections
class MainLinksSection
def name
diff --git a/app/models/preference_sections/producer_signup_page_section.rb b/app/models/preference_sections/producer_signup_page_section.rb
index bf96894c53..3633f1149e 100644
--- a/app/models/preference_sections/producer_signup_page_section.rb
+++ b/app/models/preference_sections/producer_signup_page_section.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
module PreferenceSections
class ProducerSignupPageSection
def name
diff --git a/app/models/preference_sections/user_guide_section.rb b/app/models/preference_sections/user_guide_section.rb
index 4c1323959f..05820bf226 100644
--- a/app/models/preference_sections/user_guide_section.rb
+++ b/app/models/preference_sections/user_guide_section.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
module PreferenceSections
class UserGuideSection
def name
diff --git a/app/models/producer_property.rb b/app/models/producer_property.rb
index 1d3ba6eb0e..171601cfa3 100644
--- a/app/models/producer_property.rb
+++ b/app/models/producer_property.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
class ProducerProperty < ApplicationRecord
belongs_to :producer, class_name: 'Enterprise', touch: true
belongs_to :property, class_name: 'Spree::Property'
diff --git a/app/models/product_import/entry_processor.rb b/app/models/product_import/entry_processor.rb
index 5d705bd4bb..71bbb1548f 100644
--- a/app/models/product_import/entry_processor.rb
+++ b/app/models/product_import/entry_processor.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
# This class handles the saving of new product, variant, and inventory records created during
# product import. It also collates data regarding this process for user feedback, as the import
# is processed in small stages sequentially over a number of requests.
@@ -36,7 +38,10 @@ module ProductImport
end
end
- @importer.errors.add(:importer, I18n.t(:product_importer_products_save_error)) if total_saved_count.zero?
+ if total_saved_count.zero?
+ @importer.errors.add(:importer,
+ I18n.t(:product_importer_products_save_error))
+ end
end
def count_existing_items
diff --git a/app/models/product_import/entry_validator.rb b/app/models/product_import/entry_validator.rb
index 34eed64fdf..debc68fb64 100644
--- a/app/models/product_import/entry_validator.rb
+++ b/app/models/product_import/entry_validator.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
# This class handles a number of custom validation processes that take place during product import,
# as a spreadsheet entry is checked to see if it is a valid product, variant, or inventory item.
# It also handles error messages and user feedback for the validation process.
diff --git a/app/models/product_import/inventory_reset_strategy.rb b/app/models/product_import/inventory_reset_strategy.rb
index 9be02965c9..826f0d032c 100644
--- a/app/models/product_import/inventory_reset_strategy.rb
+++ b/app/models/product_import/inventory_reset_strategy.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
module ProductImport
class InventoryResetStrategy
def initialize(excluded_items_ids)
diff --git a/app/models/product_import/product_importer.rb b/app/models/product_import/product_importer.rb
index 75e9d78846..f5464f7e6b 100644
--- a/app/models/product_import/product_importer.rb
+++ b/app/models/product_import/product_importer.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
# This is the main class for product import. It handles the initial processing of the CSV file,
# and begins the processing of the spreadsheet entries by the other product import classes.
# As spreadsheets can contain any number of entries (1000+), the import is split into smaller chunks
diff --git a/app/models/product_import/reset_absent.rb b/app/models/product_import/reset_absent.rb
index 5226b5a6d4..f53ab0b444 100644
--- a/app/models/product_import/reset_absent.rb
+++ b/app/models/product_import/reset_absent.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
module ProductImport
class ResetAbsent
def initialize(entry_processor, settings, reset_stock_strategy)
diff --git a/app/models/product_import/settings.rb b/app/models/product_import/settings.rb
index c0028138f8..ee22f218be 100644
--- a/app/models/product_import/settings.rb
+++ b/app/models/product_import/settings.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
module ProductImport
class Settings
def initialize(import_settings)
diff --git a/app/models/product_import/spreadsheet_data.rb b/app/models/product_import/spreadsheet_data.rb
index 79f1d0df92..99a46fbfd0 100644
--- a/app/models/product_import/spreadsheet_data.rb
+++ b/app/models/product_import/spreadsheet_data.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
# This class encapsulates a number of "indexes" used during product import. These contain hashes
# of information that need to be accessed at various stages of the import, and are built in order
# to minimise the number of queries that take place. So for instance, if a spreadsheet has 4000
diff --git a/app/models/product_import/spreadsheet_entry.rb b/app/models/product_import/spreadsheet_entry.rb
index f9ccac04a5..14759b6ea7 100644
--- a/app/models/product_import/spreadsheet_entry.rb
+++ b/app/models/product_import/spreadsheet_entry.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
# Objects of this class represent a line from a spreadsheet that will be processed and used
# to create either product, variant, or inventory records. These objects are referred to as
# "entry" or "entries" throughout product import.
@@ -8,17 +10,8 @@ module ProductImport
include ActiveModel::Conversion
include ActiveModel::Validations
- attr_accessor :line_number, :valid, :validates_as, :product_object,
- :product_validations, :on_hand_nil, :has_overrides, :units,
- :unscaled_units, :unit_type, :tax_category, :shipping_category
-
- attr_accessor :id, :product_id, :producer, :producer_id, :distributor,
- :distributor_id, :name, :display_name, :sku, :unit_value,
- :unit_description, :variant_unit, :variant_unit_scale,
- :variant_unit_name, :display_as, :category, :primary_taxon_id,
- :price, :on_hand, :on_demand,
- :tax_category_id, :shipping_category_id, :description,
- :import_date, :enterprise, :enterprise_id
+ attr_accessor :line_number, :valid, :validates_as, :product_object, :product_validations,
+ :on_hand_nil, :has_overrides, :units, :unscaled_units, :unit_type, :tax_category, :shipping_category, :id, :product_id, :producer, :producer_id, :distributor, :distributor_id, :name, :display_name, :sku, :unit_value, :unit_description, :variant_unit, :variant_unit_scale, :variant_unit_name, :display_as, :category, :primary_taxon_id, :price, :on_hand, :on_demand, :tax_category_id, :shipping_category_id, :description, :import_date, :enterprise, :enterprise_id
NON_DISPLAY_ATTRIBUTES = ['id', 'product_id', 'unscaled_units', 'variant_id', 'enterprise',
'enterprise_id', 'producer_id', 'distributor_id', 'primary_taxon',
@@ -92,8 +85,8 @@ module ProductImport
units = UnitConverter.new(attrs)
units.converted_attributes.each do |attr, value|
- if respond_to?("#{attr}=")
- public_send("#{attr}=", value) unless NON_PRODUCT_ATTRIBUTES.include?(attr)
+ if respond_to?("#{attr}=") && !NON_PRODUCT_ATTRIBUTES.include?(attr)
+ public_send("#{attr}=", value)
end
end
end
diff --git a/app/models/product_import/unit_converter.rb b/app/models/product_import/unit_converter.rb
index c5321a4990..a7434912b3 100644
--- a/app/models/product_import/unit_converter.rb
+++ b/app/models/product_import/unit_converter.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
# This class handles conversion of human-readable unit weights for products/variants into
# the non-human-readable format needed by the database. The table below shows how fields
# from a spreadsheet (left) become database fields (right):
diff --git a/app/models/proxy_order.rb b/app/models/proxy_order.rb
index c58d58528f..484c76faf8 100644
--- a/app/models/proxy_order.rb
+++ b/app/models/proxy_order.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
# Each Subscription has many ProxyOrders, one for each OrderCycle to which the Subscription applies
# Proxy pattern allows for deferral of initialization until absolutely required
# This reduces the need to keep Orders in sync with their parent Subscriptions
@@ -14,7 +16,9 @@ class ProxyOrder < ApplicationRecord
scope :not_closed, -> { joins(:order_cycle).merge(OrderCycle.not_closed) }
scope :canceled, -> { where('proxy_orders.canceled_at IS NOT NULL') }
scope :not_canceled, -> { where('proxy_orders.canceled_at IS NULL') }
- scope :placed_and_open, -> { joins(:order).not_closed.where(spree_orders: { state: ['complete', 'resumed'] }) }
+ scope :placed_and_open, -> {
+ joins(:order).not_closed.where(spree_orders: { state: ['complete', 'resumed'] })
+ }
def state
# NOTE: the order is important here
diff --git a/app/models/schedule.rb b/app/models/schedule.rb
index 1a11305ede..164e3ae4bc 100644
--- a/app/models/schedule.rb
+++ b/app/models/schedule.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
class Schedule < ApplicationRecord
has_paper_trail meta: { custom_data: proc { |schedule| schedule.order_cycle_ids.to_s } }
@@ -5,7 +7,9 @@ class Schedule < ApplicationRecord
has_many :order_cycles, through: :order_cycle_schedules
has_many :coordinators, -> { distinct }, through: :order_cycles
- scope :with_coordinator, lambda { |enterprise| joins(:order_cycles).where('coordinator_id = ?', enterprise.id).select('DISTINCT schedules.*') }
+ scope :with_coordinator, lambda { |enterprise|
+ joins(:order_cycles).where('coordinator_id = ?', enterprise.id).select('DISTINCT schedules.*')
+ }
def current_or_next_order_cycle
order_cycles.where('orders_close_at > (?)', Time.zone.now).order('orders_close_at ASC').first
diff --git a/app/models/spree/address.rb b/app/models/spree/address.rb
index 45834510d7..80630359a0 100644
--- a/app/models/spree/address.rb
+++ b/app/models/spree/address.rb
@@ -24,10 +24,10 @@ module Spree
def self.default
country = begin
- DefaultCountry.country
- rescue StandardError
- Spree::Country.first
- end
+ DefaultCountry.country
+ rescue StandardError
+ Spree::Country.first
+ end
new(country: country)
end
@@ -128,16 +128,14 @@ module Spree
# Ensure state_name belongs to country without states,
# or that it matches a predefined state name/abbr
- if state_name.present?
- if country.states.present?
- states = country.states.find_all_by_name_or_abbr(state_name)
+ if state_name.present? && country.states.present?
+ states = country.states.find_all_by_name_or_abbr(state_name)
- if states.size == 1
- self.state = states.first
- self.state_name = nil
- else
- errors.add(:state, :invalid)
- end
+ if states.size == 1
+ self.state = states.first
+ self.state_name = nil
+ else
+ errors.add(:state, :invalid)
end
end
diff --git a/app/models/spree/credit_card.rb b/app/models/spree/credit_card.rb
index 54872b0360..cc519d44c1 100644
--- a/app/models/spree/credit_card.rb
+++ b/app/models/spree/credit_card.rb
@@ -33,10 +33,10 @@ module Spree
def number=(num)
@number = begin
- num.gsub(/[^0-9]/, '')
- rescue StandardError
- nil
- end
+ num.gsub(/[^0-9]/, '')
+ rescue StandardError
+ nil
+ end
end
# cc_type is set by jquery.payment, which helpfully provides different
diff --git a/app/models/spree/gateway/stripe_connect.rb b/app/models/spree/gateway/stripe_connect.rb
index 493b9bd74e..fdd1d25a99 100644
--- a/app/models/spree/gateway/stripe_connect.rb
+++ b/app/models/spree/gateway/stripe_connect.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
require 'stripe/profile_storer'
module Spree
@@ -88,7 +90,8 @@ module Spree
end
def tokenize_instance_customer_card(customer, card)
- token = Stripe::Token.create({ card: card, customer: customer }, stripe_account: stripe_account_id)
+ token = Stripe::Token.create({ card: card, customer: customer },
+ stripe_account: stripe_account_id)
token.id
end
diff --git a/app/models/spree/image.rb b/app/models/spree/image.rb
index 0bbdc5a85d..7a3964a7a7 100644
--- a/app/models/spree/image.rb
+++ b/app/models/spree/image.rb
@@ -56,7 +56,8 @@ module Spree
def no_attachment_errors
return if attachment.errors.empty?
- errors.add :attachment, "Paperclip returned errors for file '#{attachment_file_name}' - check ImageMagick installation or image source file."
+ errors.add :attachment,
+ "Paperclip returned errors for file '#{attachment_file_name}' - check ImageMagick installation or image source file."
false
end
diff --git a/app/models/spree/line_item.rb b/app/models/spree/line_item.rb
index 38e92f0ccd..d760724fad 100644
--- a/app/models/spree/line_item.rb
+++ b/app/models/spree/line_item.rb
@@ -41,8 +41,7 @@ module Spree
delegate :product, :unit_description, :display_name, to: :variant
- attr_accessor :skip_stock_check # Allows manual skipping of Stock::AvailabilityValidator
- attr_accessor :target_shipment
+ attr_accessor :skip_stock_check, :target_shipment # Allows manual skipping of Stock::AvailabilityValidator
# -- Scopes
scope :managed_by, lambda { |user|
diff --git a/app/models/spree/order.rb b/app/models/spree/order.rb
index 28ce6a2d69..52af6395dc 100644
--- a/app/models/spree/order.rb
+++ b/app/models/spree/order.rb
@@ -28,14 +28,16 @@ module Spree
belongs_to :user, class_name: Spree.user_class.to_s
belongs_to :created_by, class_name: Spree.user_class.to_s
- belongs_to :bill_address, foreign_key: :bill_address_id, class_name: 'Spree::Address'
+ belongs_to :bill_address, class_name: 'Spree::Address'
alias_attribute :billing_address, :bill_address
- belongs_to :ship_address, foreign_key: :ship_address_id, class_name: 'Spree::Address'
+ belongs_to :ship_address, class_name: 'Spree::Address'
alias_attribute :shipping_address, :ship_address
has_many :state_changes, as: :stateful
- has_many :line_items, -> { order('created_at ASC') }, class_name: "Spree::LineItem", dependent: :destroy
+ has_many :line_items, -> {
+ order('created_at ASC')
+ }, class_name: "Spree::LineItem", dependent: :destroy
has_many :payments, dependent: :destroy
has_many :return_authorizations, dependent: :destroy, inverse_of: :order
has_many :adjustments, -> { order "#{Spree::Adjustment.table_name}.created_at ASC" },
@@ -88,7 +90,7 @@ module Spree
after_create :create_tax_charge!
validates :email, presence: true,
- format: /\A([\w\.%\+\-']+)@([\w\-]+\.)+([\w]{2,})\z/i,
+ format: /\A([\w.%+\-']+)@([\w\-]+\.)+(\w{2,})\z/i,
if: :require_email
make_permalink field: :number
@@ -474,7 +476,7 @@ module Spree
# an order is part-way through checkout and the user changes items in the cart; in that case
# we need to reset the checkout flow to ensure the order is processed correctly.
def ensure_updated_shipments
- if !self.completed? && shipments.any?
+ if !completed? && shipments.any?
shipments.destroy_all
restart_checkout_flow
end
@@ -674,6 +676,7 @@ module Spree
def require_customer?
return false if new_record? || state == 'cart'
+
true
end
diff --git a/app/models/spree/order_contents.rb b/app/models/spree/order_contents.rb
index 7914256e7a..d257d05877 100644
--- a/app/models/spree/order_contents.rb
+++ b/app/models/spree/order_contents.rb
@@ -70,7 +70,7 @@ module Spree
private
def discard_empty_line_items
- order.line_items = order.line_items.select {|li| li.quantity.positive? }
+ order.line_items = order.line_items.select { |li| li.quantity.positive? }
end
def update_shipment(target_shipment = nil)
diff --git a/app/models/spree/payment.rb b/app/models/spree/payment.rb
index d2d6bf9e97..ca22e8e938 100644
--- a/app/models/spree/payment.rb
+++ b/app/models/spree/payment.rb
@@ -108,12 +108,10 @@ module Spree
def actions
return [] unless payment_source&.respond_to?(:actions)
- actions = payment_source.actions.select do |action|
+ payment_source.actions.select do |action|
!payment_source.respond_to?("can_#{action}?") ||
payment_source.__send__("can_#{action}?", self)
end
-
- actions
end
def resend_authorization_email!
diff --git a/app/models/spree/preferences/file_configuration.rb b/app/models/spree/preferences/file_configuration.rb
index 278a76adf9..7015e60296 100644
--- a/app/models/spree/preferences/file_configuration.rb
+++ b/app/models/spree/preferences/file_configuration.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
module Spree
module Preferences
class FileConfiguration < Configuration
diff --git a/app/models/spree/preferences/preferable.rb b/app/models/spree/preferences/preferable.rb
index 6b970f87c4..dd8fc41120 100644
--- a/app/models/spree/preferences/preferable.rb
+++ b/app/models/spree/preferences/preferable.rb
@@ -20,6 +20,8 @@ module Spree
base.class_eval do
extend Spree::Preferences::PreferableClassMethods
+ # Disabling rubocop rule because the fix to this rubocop warning breaks specs
+ # rubocop:disable Style/SymbolProc
if respond_to?(:after_create)
after_create do |obj|
obj.save_pending_preferences
@@ -31,6 +33,7 @@ module Spree
obj.clear_preferences
end
end
+ # rubocop:enable Style/SymbolProc
end
end
@@ -120,6 +123,7 @@ module Spree
when :integer
value.to_i
when :boolean
+ # rubocop:disable Style/NumericPredicate
if value.is_a?(FalseClass) ||
value.nil? ||
value == 0 ||
@@ -129,6 +133,7 @@ module Spree
else
true
end
+ # rubocop:enable Style/NumericPredicate
else
value
end
diff --git a/app/models/spree/preferences/store.rb b/app/models/spree/preferences/store.rb
index 5940fdf4a3..270ffc8de1 100644
--- a/app/models/spree/preferences/store.rb
+++ b/app/models/spree/preferences/store.rb
@@ -36,18 +36,15 @@ module Spree
return val
end
- if should_persist?
- # If it's not in the cache, maybe it's in the database, but
- # has been cleared from the cache
+ # If it's not in the cache, maybe it's in the database, but
+ # has been cleared from the cache
+ # does it exist in the database?
+ if should_persist? && (Spree::Preference.table_exists? && preference = Spree::Preference.find_by(key: key))
+ # it does exist, so let's put it back into the cache
+ @cache.write(preference.key, preference.value)
- # does it exist in the database?
- if Spree::Preference.table_exists? && preference = Spree::Preference.find_by(key: key)
- # it does exist, so let's put it back into the cache
- @cache.write(preference.key, preference.value)
-
- # and return the value
- return preference.value
- end
+ # and return the value
+ return preference.value
end
unless fallback.nil?
diff --git a/app/models/spree/property.rb b/app/models/spree/property.rb
index 900519aa6c..3762c3b393 100644
--- a/app/models/spree/property.rb
+++ b/app/models/spree/property.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
module Spree
class Property < ApplicationRecord
has_many :product_properties, dependent: :destroy
diff --git a/app/models/spree/shipment.rb b/app/models/spree/shipment.rb
index 447363cc7f..804e09de3f 100644
--- a/app/models/spree/shipment.rb
+++ b/app/models/spree/shipment.rb
@@ -18,6 +18,7 @@ module Spree
after_save :ensure_correct_adjustment, :update_adjustments
attr_accessor :special_instructions
+
alias_attribute :amount, :cost
accepts_nested_attributes_for :address
diff --git a/app/models/spree/shipping_method.rb b/app/models/spree/shipping_method.rb
index efff8c56bc..82dbee7e45 100644
--- a/app/models/spree/shipping_method.rb
+++ b/app/models/spree/shipping_method.rb
@@ -20,8 +20,7 @@ module Spree
foreign_key: 'distributor_id'
has_and_belongs_to_many :zones, join_table: 'spree_shipping_methods_zones',
- class_name: 'Spree::Zone',
- foreign_key: 'shipping_method_id'
+ class_name: 'Spree::Zone'
belongs_to :tax_category, class_name: 'Spree::TaxCategory'
diff --git a/app/models/spree/tax_rate.rb b/app/models/spree/tax_rate.rb
index 369aabb3bf..03b40c8f90 100644
--- a/app/models/spree/tax_rate.rb
+++ b/app/models/spree/tax_rate.rb
@@ -77,10 +77,10 @@ module Spree
def potentially_applicable?(order_tax_zone)
# If the rate's zone matches the order's tax zone, then it's applicable.
zone == order_tax_zone ||
- # If the rate's zone *contains* the order's tax zone, then it's applicable.
- zone.contains?(order_tax_zone) ||
- # The rate's zone is the default zone, then it's always applicable.
- (included_in_price? && zone.default_tax)
+ # If the rate's zone *contains* the order's tax zone, then it's applicable.
+ zone.contains?(order_tax_zone) ||
+ # The rate's zone is the default zone, then it's always applicable.
+ (included_in_price? && zone.default_tax)
end
# Creates necessary tax adjustments for the item.
@@ -90,7 +90,7 @@ module Spree
included = included_in_price && default_zone_or_zone_match?(order)
- self.adjustments.create!(
+ adjustments.create!(
adjustable: item,
amount: amount,
order: order,
@@ -141,7 +141,7 @@ module Spree
def create_label(adjustment_amount)
label = ""
label << "#{Spree.t(:refund)} " if adjustment_amount.negative?
- label << "#{(name.presence || tax_category.name)} "
+ label << "#{name.presence || tax_category.name} "
label << (show_rate_in_label? ? "#{amount * 100}%" : "")
label << " (#{I18n.t('models.tax_rate.included_in_price')})" if included_in_price?
label
diff --git a/app/models/spree/taxon.rb b/app/models/spree/taxon.rb
index 2c9b3177da..f17bb48f97 100644
--- a/app/models/spree/taxon.rb
+++ b/app/models/spree/taxon.rb
@@ -51,8 +51,7 @@ module Spree
end
def active_products
- scope = products.active
- scope
+ products.active
end
def pretty_name
diff --git a/app/models/spree/user.rb b/app/models/spree/user.rb
index 372a29bf29..f7efda3b35 100644
--- a/app/models/spree/user.rb
+++ b/app/models/spree/user.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
module Spree
class User < ApplicationRecord
devise :database_authenticatable, :token_authenticatable, :registerable, :recoverable,
@@ -5,15 +7,14 @@ module Spree
:encryptable, :confirmable, encryptor: 'authlogic_sha512', reconfirmable: true
has_many :orders
- belongs_to :ship_address, foreign_key: 'ship_address_id', class_name: 'Spree::Address'
- belongs_to :bill_address, foreign_key: 'bill_address_id', class_name: 'Spree::Address'
+ belongs_to :ship_address, class_name: 'Spree::Address'
+ belongs_to :bill_address, class_name: 'Spree::Address'
has_and_belongs_to_many :spree_roles,
join_table: 'spree_roles_users',
- foreign_key: "user_id",
class_name: "Spree::Role"
- has_many :spree_orders, foreign_key: "user_id", class_name: "Spree::Order"
+ has_many :spree_orders, class_name: "Spree::Order"
before_validation :set_login
before_destroy :check_completed_orders
diff --git a/app/models/stripe_account.rb b/app/models/stripe_account.rb
index 2065bc14ec..5eaeb4f3f4 100644
--- a/app/models/stripe_account.rb
+++ b/app/models/stripe_account.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
class StripeAccount < ApplicationRecord
belongs_to :enterprise
validates :stripe_user_id, :stripe_publishable_key, presence: true
diff --git a/app/models/subscription.rb b/app/models/subscription.rb
index c8f6901816..d6278cd837 100644
--- a/app/models/subscription.rb
+++ b/app/models/subscription.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
class Subscription < ApplicationRecord
ALLOWED_PAYMENT_METHOD_TYPES = ["Spree::PaymentMethod::Check",
"Spree::Gateway::StripeConnect",
@@ -8,8 +10,8 @@ class Subscription < ApplicationRecord
belongs_to :schedule
belongs_to :shipping_method, class_name: 'Spree::ShippingMethod'
belongs_to :payment_method, class_name: 'Spree::PaymentMethod'
- belongs_to :bill_address, foreign_key: :bill_address_id, class_name: "Spree::Address"
- belongs_to :ship_address, foreign_key: :ship_address_id, class_name: "Spree::Address"
+ belongs_to :bill_address, class_name: "Spree::Address"
+ belongs_to :ship_address, class_name: "Spree::Address"
has_many :subscription_line_items, inverse_of: :subscription
has_many :order_cycles, through: :schedule
has_many :proxy_orders
@@ -21,10 +23,14 @@ class Subscription < ApplicationRecord
accepts_nested_attributes_for :subscription_line_items, allow_destroy: true
accepts_nested_attributes_for :bill_address, :ship_address
- scope :not_ended, -> { where('subscriptions.ends_at > (?) OR subscriptions.ends_at IS NULL', Time.zone.now) }
+ scope :not_ended, -> {
+ where('subscriptions.ends_at > (?) OR subscriptions.ends_at IS NULL', Time.zone.now)
+ }
scope :not_canceled, -> { where('subscriptions.canceled_at IS NULL') }
scope :not_paused, -> { where('subscriptions.paused_at IS NULL') }
- scope :active, -> { not_canceled.not_ended.not_paused.where('subscriptions.begins_at <= (?)', Time.zone.now) }
+ scope :active, -> {
+ not_canceled.not_ended.not_paused.where('subscriptions.begins_at <= (?)', Time.zone.now)
+ }
def closed_proxy_orders
proxy_orders.closed
diff --git a/app/models/subscription_line_item.rb b/app/models/subscription_line_item.rb
index 795d5996ce..31a9450ea3 100644
--- a/app/models/subscription_line_item.rb
+++ b/app/models/subscription_line_item.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
class SubscriptionLineItem < ApplicationRecord
belongs_to :subscription, inverse_of: :subscription_line_items
belongs_to :variant, -> { with_deleted }, class_name: 'Spree::Variant'
diff --git a/app/models/tag_rule.rb b/app/models/tag_rule.rb
index 6f61d4a31a..b1d5b83ef9 100644
--- a/app/models/tag_rule.rb
+++ b/app/models/tag_rule.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
class TagRule < ApplicationRecord
belongs_to :enterprise
diff --git a/app/models/tag_rule/filter_order_cycles.rb b/app/models/tag_rule/filter_order_cycles.rb
index fd467a1658..c9048593f6 100644
--- a/app/models/tag_rule/filter_order_cycles.rb
+++ b/app/models/tag_rule/filter_order_cycles.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
class TagRule::FilterOrderCycles < TagRule
preference :matched_order_cycles_visibility, :string, default: "visible"
preference :exchange_tags, :string, default: ""
diff --git a/app/models/tag_rule/filter_payment_methods.rb b/app/models/tag_rule/filter_payment_methods.rb
index 11d5b5e737..6bcf2709ef 100644
--- a/app/models/tag_rule/filter_payment_methods.rb
+++ b/app/models/tag_rule/filter_payment_methods.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
class TagRule::FilterPaymentMethods < TagRule
preference :matched_payment_methods_visibility, :string, default: "visible"
preference :payment_method_tags, :string, default: ""
diff --git a/app/models/tag_rule/filter_products.rb b/app/models/tag_rule/filter_products.rb
index 40035a21d5..20ff29bfc9 100644
--- a/app/models/tag_rule/filter_products.rb
+++ b/app/models/tag_rule/filter_products.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
class TagRule
class FilterProducts < TagRule
preference :matched_variants_visibility, :string, default: "visible"
diff --git a/app/models/tag_rule/filter_shipping_methods.rb b/app/models/tag_rule/filter_shipping_methods.rb
index a5de92da8b..43b58a2052 100644
--- a/app/models/tag_rule/filter_shipping_methods.rb
+++ b/app/models/tag_rule/filter_shipping_methods.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
class TagRule::FilterShippingMethods < TagRule
preference :matched_shipping_methods_visibility, :string, default: "visible"
preference :shipping_method_tags, :string, default: ""
diff --git a/app/serializers/api/address_serializer.rb b/app/serializers/api/address_serializer.rb
index 4ef6d7d790..acc986d5f7 100644
--- a/app/serializers/api/address_serializer.rb
+++ b/app/serializers/api/address_serializer.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
class Api::AddressSerializer < ActiveModel::Serializer
# cached
# delegate :cache_key, to: :object
diff --git a/app/serializers/api/adjustment_serializer.rb b/app/serializers/api/adjustment_serializer.rb
index 44fa26f227..741e3699a4 100644
--- a/app/serializers/api/adjustment_serializer.rb
+++ b/app/serializers/api/adjustment_serializer.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
module Api
class AdjustmentSerializer < ActiveModel::Serializer
attributes :id, :amount, :label, :eligible,
diff --git a/app/serializers/api/cached_enterprise_serializer.rb b/app/serializers/api/cached_enterprise_serializer.rb
index 7c091b51c9..cec5388204 100644
--- a/app/serializers/api/cached_enterprise_serializer.rb
+++ b/app/serializers/api/cached_enterprise_serializer.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
require 'open_food_network/property_merge'
module Api
diff --git a/app/serializers/api/country_serializer.rb b/app/serializers/api/country_serializer.rb
index 8a7bca33de..8516328d5a 100644
--- a/app/serializers/api/country_serializer.rb
+++ b/app/serializers/api/country_serializer.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
class Api::CountrySerializer < ActiveModel::Serializer
attributes :id, :name, :states
diff --git a/app/serializers/api/credit_card_serializer.rb b/app/serializers/api/credit_card_serializer.rb
index bab0f5bc8d..d7ac10d001 100644
--- a/app/serializers/api/credit_card_serializer.rb
+++ b/app/serializers/api/credit_card_serializer.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
module Api
class CreditCardSerializer < ActiveModel::Serializer
attributes :id, :brand, :number, :expiry, :formatted, :delete_link, :is_default
diff --git a/app/serializers/api/currency_config_serializer.rb b/app/serializers/api/currency_config_serializer.rb
index ac87f6d9a1..a9b1bbd7f1 100644
--- a/app/serializers/api/currency_config_serializer.rb
+++ b/app/serializers/api/currency_config_serializer.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
class Api::CurrencyConfigSerializer < ActiveModel::Serializer
attributes :currency, :display_currency, :symbol, :symbol_position, :hide_cents
diff --git a/app/serializers/api/current_order_serializer.rb b/app/serializers/api/current_order_serializer.rb
index 2ec8d4e541..9860f64821 100644
--- a/app/serializers/api/current_order_serializer.rb
+++ b/app/serializers/api/current_order_serializer.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
class Api::CurrentOrderSerializer < ActiveModel::Serializer
attributes :id, :item_total, :email, :shipping_method_id,
:display_total, :payment_method_id
diff --git a/app/serializers/api/customer_serializer.rb b/app/serializers/api/customer_serializer.rb
index 1c437a987e..053313cb30 100644
--- a/app/serializers/api/customer_serializer.rb
+++ b/app/serializers/api/customer_serializer.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
module Api
class CustomerSerializer < ActiveModel::Serializer
attributes :id, :enterprise_id, :name, :code, :email, :allow_charges
diff --git a/app/serializers/api/enterprise_serializer.rb b/app/serializers/api/enterprise_serializer.rb
index 94dbda5ada..ef1c73762b 100644
--- a/app/serializers/api/enterprise_serializer.rb
+++ b/app/serializers/api/enterprise_serializer.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
require 'open_food_network/property_merge'
class Api::EnterpriseSerializer < ActiveModel::Serializer
diff --git a/app/serializers/api/enterprise_shopfront_list_serializer.rb b/app/serializers/api/enterprise_shopfront_list_serializer.rb
index f636c239cb..8cd95c1547 100644
--- a/app/serializers/api/enterprise_shopfront_list_serializer.rb
+++ b/app/serializers/api/enterprise_shopfront_list_serializer.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
# Represents the minimum details of an Enterprise when all shopfronts are being listed
module Api
class EnterpriseShopfrontListSerializer < ActiveModel::Serializer
diff --git a/app/serializers/api/enterprise_shopfront_serializer.rb b/app/serializers/api/enterprise_shopfront_serializer.rb
index 035f8fde51..9707356799 100644
--- a/app/serializers/api/enterprise_shopfront_serializer.rb
+++ b/app/serializers/api/enterprise_shopfront_serializer.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
# Represents the properties of an Enterprise when viewing the details of listed shopfronts
module Api
class EnterpriseShopfrontSerializer < ActiveModel::Serializer
diff --git a/app/serializers/api/enterprise_thin_serializer.rb b/app/serializers/api/enterprise_thin_serializer.rb
index cdc4d6b9eb..956ec20d05 100644
--- a/app/serializers/api/enterprise_thin_serializer.rb
+++ b/app/serializers/api/enterprise_thin_serializer.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
module Api
class EnterpriseThinSerializer < ActiveModel::Serializer
attributes :name, :id, :active, :path
diff --git a/app/serializers/api/group_list_serializer.rb b/app/serializers/api/group_list_serializer.rb
index 46e851ab4f..420255b287 100644
--- a/app/serializers/api/group_list_serializer.rb
+++ b/app/serializers/api/group_list_serializer.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
module Api
class GroupListSerializer < ActiveModel::Serializer
attributes :id, :name, :permalink, :email, :website, :facebook, :instagram,
diff --git a/app/serializers/api/id_name_serializer.rb b/app/serializers/api/id_name_serializer.rb
index 1db5f2439e..e49c8705e6 100644
--- a/app/serializers/api/id_name_serializer.rb
+++ b/app/serializers/api/id_name_serializer.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
class Api::IdNameSerializer < ActiveModel::Serializer
attributes :id, :name
end
diff --git a/app/serializers/api/id_serializer.rb b/app/serializers/api/id_serializer.rb
index 0093338e6e..617d58d197 100644
--- a/app/serializers/api/id_serializer.rb
+++ b/app/serializers/api/id_serializer.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
class Api::IdSerializer < ActiveModel::Serializer
attributes :id
end
diff --git a/app/serializers/api/image_serializer.rb b/app/serializers/api/image_serializer.rb
index 70c62b397a..ead54697d6 100644
--- a/app/serializers/api/image_serializer.rb
+++ b/app/serializers/api/image_serializer.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
class Api::ImageSerializer < ActiveModel::Serializer
attributes :id, :alt, :thumb_url, :small_url, :image_url, :large_url
diff --git a/app/serializers/api/line_item_serializer.rb b/app/serializers/api/line_item_serializer.rb
index f8022caef3..0f2196e083 100644
--- a/app/serializers/api/line_item_serializer.rb
+++ b/app/serializers/api/line_item_serializer.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
class Api::LineItemSerializer < ActiveModel::Serializer
attributes :id, :quantity, :max_quantity, :price, :order_id
diff --git a/app/serializers/api/order_cycle_serializer.rb b/app/serializers/api/order_cycle_serializer.rb
index f01d79a931..25ef75d29f 100644
--- a/app/serializers/api/order_cycle_serializer.rb
+++ b/app/serializers/api/order_cycle_serializer.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
module Api
class OrderCycleSerializer < ActiveModel::Serializer
attributes :order_cycle_id, :orders_close_at
diff --git a/app/serializers/api/order_detailed_serializer.rb b/app/serializers/api/order_detailed_serializer.rb
index fd625b6936..1343a57edd 100644
--- a/app/serializers/api/order_detailed_serializer.rb
+++ b/app/serializers/api/order_detailed_serializer.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
module Api
class OrderDetailedSerializer < Api::Admin::OrderSerializer
has_one :shipping_method, serializer: Api::ShippingMethodSerializer
diff --git a/app/serializers/api/order_serializer.rb b/app/serializers/api/order_serializer.rb
index 3123b973a9..b4a9460ce3 100644
--- a/app/serializers/api/order_serializer.rb
+++ b/app/serializers/api/order_serializer.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
module Api
class OrderSerializer < ActiveModel::Serializer
attributes :number, :completed_at, :total, :state, :shipment_state, :payment_state,
diff --git a/app/serializers/api/payment_method_serializer.rb b/app/serializers/api/payment_method_serializer.rb
index a135f5d792..8ee984de10 100644
--- a/app/serializers/api/payment_method_serializer.rb
+++ b/app/serializers/api/payment_method_serializer.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
class Api::PaymentMethodSerializer < ActiveModel::Serializer
attributes :name, :description, :id, :method_type,
:price
diff --git a/app/serializers/api/payment_serializer.rb b/app/serializers/api/payment_serializer.rb
index 033803faf9..8d8e365882 100644
--- a/app/serializers/api/payment_serializer.rb
+++ b/app/serializers/api/payment_serializer.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
module Api
class PaymentSerializer < ActiveModel::Serializer
attributes :amount, :updated_at, :payment_method, :state, :cvv_response_message
diff --git a/app/serializers/api/product_serializer.rb b/app/serializers/api/product_serializer.rb
index 994df3bd52..b37bc78366 100644
--- a/app/serializers/api/product_serializer.rb
+++ b/app/serializers/api/product_serializer.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
require "open_food_network/scope_variant_to_hub"
class Api::ProductSerializer < ActiveModel::Serializer
diff --git a/app/serializers/api/property_serializer.rb b/app/serializers/api/property_serializer.rb
index cdb3f2bae3..6255ba2602 100644
--- a/app/serializers/api/property_serializer.rb
+++ b/app/serializers/api/property_serializer.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
class Api::PropertySerializer < ActiveModel::Serializer
attributes :id, :name, :presentation
diff --git a/app/serializers/api/rails_flash_serializer.rb b/app/serializers/api/rails_flash_serializer.rb
index ea7912b1e7..212aeebde7 100644
--- a/app/serializers/api/rails_flash_serializer.rb
+++ b/app/serializers/api/rails_flash_serializer.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
module Api
class RailsFlashSerializer < ActiveModel::Serializer
attributes :info, :success, :error, :notice
diff --git a/app/serializers/api/shipment_serializer.rb b/app/serializers/api/shipment_serializer.rb
index 71fc27450b..1c03d9eb5e 100644
--- a/app/serializers/api/shipment_serializer.rb
+++ b/app/serializers/api/shipment_serializer.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
module Api
class ShipmentSerializer < ActiveModel::Serializer
attributes :id, :tracking, :number, :order_id, :cost, :shipped_at, :stock_location_name, :state
diff --git a/app/serializers/api/shipping_method_serializer.rb b/app/serializers/api/shipping_method_serializer.rb
index 26e6b71201..66f48a151a 100644
--- a/app/serializers/api/shipping_method_serializer.rb
+++ b/app/serializers/api/shipping_method_serializer.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
class Api::ShippingMethodSerializer < ActiveModel::Serializer
attributes :id, :require_ship_address, :name, :description,
:price
diff --git a/app/serializers/api/shop_for_orders_serializer.rb b/app/serializers/api/shop_for_orders_serializer.rb
index 1b8fa51b85..a8dc799012 100644
--- a/app/serializers/api/shop_for_orders_serializer.rb
+++ b/app/serializers/api/shop_for_orders_serializer.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
module Api
class ShopForOrdersSerializer < ActiveModel::Serializer
attributes :id, :name, :hash, :logo
diff --git a/app/serializers/api/state_serializer.rb b/app/serializers/api/state_serializer.rb
index 2862c24468..7d839e0bcc 100644
--- a/app/serializers/api/state_serializer.rb
+++ b/app/serializers/api/state_serializer.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
class Api::StateSerializer < ActiveModel::Serializer
attributes :id, :name, :abbr, :country_id
end
diff --git a/app/serializers/api/taxon_jstree_attribute_serializer.rb b/app/serializers/api/taxon_jstree_attribute_serializer.rb
index abf10d406d..3fff38e11e 100644
--- a/app/serializers/api/taxon_jstree_attribute_serializer.rb
+++ b/app/serializers/api/taxon_jstree_attribute_serializer.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
module Api
class TaxonJstreeAttributeSerializer < ActiveModel::Serializer
attributes :id, :name
diff --git a/app/serializers/api/taxon_jstree_serializer.rb b/app/serializers/api/taxon_jstree_serializer.rb
index cd457c644b..6f862dc404 100644
--- a/app/serializers/api/taxon_jstree_serializer.rb
+++ b/app/serializers/api/taxon_jstree_serializer.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
module Api
class TaxonJstreeSerializer < ActiveModel::Serializer
attributes :data, :state
diff --git a/app/serializers/api/taxon_serializer.rb b/app/serializers/api/taxon_serializer.rb
index 43d3ddefd9..38eb2bf3dd 100644
--- a/app/serializers/api/taxon_serializer.rb
+++ b/app/serializers/api/taxon_serializer.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
class Api::TaxonSerializer < ActiveModel::Serializer
cached
delegate :cache_key, to: :object
diff --git a/app/serializers/api/uncached_enterprise_serializer.rb b/app/serializers/api/uncached_enterprise_serializer.rb
index 1bbae872ba..fb6b478a28 100644
--- a/app/serializers/api/uncached_enterprise_serializer.rb
+++ b/app/serializers/api/uncached_enterprise_serializer.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
module Api
class UncachedEnterpriseSerializer < ActiveModel::Serializer
include SerializerHelper
diff --git a/app/serializers/api/user_serializer.rb b/app/serializers/api/user_serializer.rb
index 3d9e64e956..e0bd297972 100644
--- a/app/serializers/api/user_serializer.rb
+++ b/app/serializers/api/user_serializer.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
module Api
class UserSerializer < ActiveModel::Serializer
attributes :id, :email
diff --git a/app/serializers/api/variant_serializer.rb b/app/serializers/api/variant_serializer.rb
index 06d841c392..3c2ede89ae 100644
--- a/app/serializers/api/variant_serializer.rb
+++ b/app/serializers/api/variant_serializer.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
class Api::VariantSerializer < ActiveModel::Serializer
attributes :id, :is_master, :product_name, :sku,
:options_text, :unit_value, :unit_description, :unit_to_display,
@@ -44,9 +46,7 @@ class Api::VariantSerializer < ActiveModel::Serializer
price_with_fees / (unit_price.denominator || 1)
end
- def unit_price_unit
- unit_price.unit
- end
+ delegate :unit, to: :unit_price, prefix: true
private
diff --git a/app/services/bulk_invoice_service.rb b/app/services/bulk_invoice_service.rb
index 6776ad448a..dc1b31f17d 100644
--- a/app/services/bulk_invoice_service.rb
+++ b/app/services/bulk_invoice_service.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
class BulkInvoiceService
attr_reader :id
diff --git a/app/services/cache_service.rb b/app/services/cache_service.rb
index dc3a7fac0e..24ac38cdf6 100644
--- a/app/services/cache_service.rb
+++ b/app/services/cache_service.rb
@@ -5,18 +5,15 @@ class CacheService
FILTERS_EXPIRY = 30.seconds.freeze
SHOPS_EXPIRY = 15.seconds.freeze
- def self.cache(cache_key, options = {})
- Rails.cache.fetch cache_key.to_s, options do
- yield
- end
+ def self.cache(cache_key, options = {}, &block)
+ Rails.cache.fetch cache_key.to_s, options, &block
end
# Yields a cached query, expired by the most recently updated record for a given class.
# E.g: if *any* Spree::Taxon record is updated, all keys based on Spree::Taxon will auto-expire.
- def self.cached_data_by_class(cache_key, cached_class)
- Rails.cache.fetch "#{cache_key}-#{cached_class}-#{latest_timestamp_by_class(cached_class)}" do
- yield
- end
+ def self.cached_data_by_class(cache_key, cached_class, &block)
+ Rails.cache.fetch "#{cache_key}-#{cached_class}-#{latest_timestamp_by_class(cached_class)}",
+ &block
end
# Gets the :updated_at value of the most recently updated record for a given class, and returns
@@ -25,12 +22,10 @@ class CacheService
cached_class.maximum(:updated_at).to_i
end
- def self.home_stats(statistic)
+ def self.home_stats(statistic, &block)
Rails.cache.fetch("home_stats_count_#{statistic}",
expires_in: HOME_STATS_EXPIRY,
- race_condition_ttl: 10) do
- yield
- end
+ race_condition_ttl: 10, &block)
end
module FragmentCaching
diff --git a/app/services/cart_service.rb b/app/services/cart_service.rb
index 5587438996..a405b41d44 100644
--- a/app/services/cart_service.rb
+++ b/app/services/cart_service.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
require 'open_food_network/scope_variant_to_hub'
# Previously Spree::OrderPopulator. Modified to work with max_quantity and variant overrides.
@@ -74,11 +76,9 @@ class CartService
end
def cart_remove(variant)
- begin
- order.contents.remove(variant)
- rescue ActiveRecord::RecordNotFound
- # Nothing to remove; no line items for this variant were found.
- end
+ order.contents.remove(variant)
+ rescue ActiveRecord::RecordNotFound
+ # Nothing to remove; no line items for this variant were found.
end
def final_quantities(variant, quantity, max_quantity)
@@ -107,15 +107,15 @@ class CartService
(data[:variants] || []).each do |variant_id, quantity|
if quantity.is_a?(ActionController::Parameters)
variants_array.push({
- variant_id: variant_id.to_i,
- quantity: quantity[:quantity].to_i,
- max_quantity: quantity[:max_quantity].to_i
- })
+ variant_id: variant_id.to_i,
+ quantity: quantity[:quantity].to_i,
+ max_quantity: quantity[:max_quantity].to_i
+ })
else
variants_array.push({
- variant_id: variant_id.to_i,
- quantity: quantity.to_i
- })
+ variant_id: variant_id.to_i,
+ quantity: quantity.to_i
+ })
end
end
variants_array
@@ -153,7 +153,8 @@ class CartService
end
def check_variant_available_under_distribution(variant)
- return true if OrderCycleDistributedVariants.new(@order_cycle, @distributor).available_variants.include? variant
+ return true if OrderCycleDistributedVariants.new(@order_cycle,
+ @distributor).available_variants.include? variant
errors.add(:base, I18n.t(:spree_order_populator_availability_error))
false
diff --git a/app/services/create_order_cycle.rb b/app/services/create_order_cycle.rb
index a7c631991e..c8f9ce1b18 100644
--- a/app/services/create_order_cycle.rb
+++ b/app/services/create_order_cycle.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
# Creates an order cycle for the provided enterprise and selecting all the
# variants specified for both incoming and outgoing exchanges
class CreateOrderCycle
diff --git a/app/services/current_order_locker.rb b/app/services/current_order_locker.rb
index c420e4ec0d..fe47eebddb 100644
--- a/app/services/current_order_locker.rb
+++ b/app/services/current_order_locker.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
# Locks a controller's current order including its variants.
#
# It should be used when making major changes like checking out the order.
@@ -7,8 +9,8 @@ class CurrentOrderLocker
#
# https://guides.rubyonrails.org/action_controller_overview.html#filters
#
- def self.around(controller)
- lock_order_and_variants(controller.current_order) { yield }
+ def self.around(controller, &block)
+ lock_order_and_variants(controller.current_order, &block)
end
# Locking will not prevent all access to these rows. Other processes are
diff --git a/app/services/default_country.rb b/app/services/default_country.rb
index c805e261b0..11b85e90a4 100644
--- a/app/services/default_country.rb
+++ b/app/services/default_country.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
class DefaultCountry
def self.id
country.id
diff --git a/app/services/default_shipping_category.rb b/app/services/default_shipping_category.rb
index 8e0a7b90ae..38a2df77a6 100644
--- a/app/services/default_shipping_category.rb
+++ b/app/services/default_shipping_category.rb
@@ -1,7 +1,9 @@
+# frozen_string_literal: true
+
# Encapsulates the concept of default stock location in creation of a product or a shipping method.
class DefaultShippingCategory
- NAME = 'Default'.freeze
+ NAME = 'Default'
def self.create!
Spree::ShippingCategory.create!(name: NAME)
diff --git a/app/services/default_stock_location.rb b/app/services/default_stock_location.rb
index 7ec0476321..0b79f446ec 100644
--- a/app/services/default_stock_location.rb
+++ b/app/services/default_stock_location.rb
@@ -1,12 +1,15 @@
+# frozen_string_literal: true
+
# Encapsulates the concept of default stock location that OFN has, as explained
# in https://github.com/openfoodfoundation/openfoodnetwork/wiki/Spree-Upgrade%3A-Stock-locations
class DefaultStockLocation
- NAME = 'default'.freeze
+ NAME = 'default'
def self.create!
country = Spree::Country.find_by(iso: ENV['DEFAULT_COUNTRY_CODE'])
state = country.states.first
- Spree::StockLocation.create!(name: NAME, country_id: country.id, state_id: state.id, backorderable_default: false)
+ Spree::StockLocation.create!(name: NAME, country_id: country.id, state_id: state.id,
+ backorderable_default: false)
end
def self.destroy_all
diff --git a/app/services/embedded_page_service.rb b/app/services/embedded_page_service.rb
index f2d6021e20..8468992167 100644
--- a/app/services/embedded_page_service.rb
+++ b/app/services/embedded_page_service.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
# Processes requests for pages embedded in iframes
class EmbeddedPageService
diff --git a/app/services/exchange_products_renderer.rb b/app/services/exchange_products_renderer.rb
index 19b3133641..a622ad94a1 100644
--- a/app/services/exchange_products_renderer.rb
+++ b/app/services/exchange_products_renderer.rb
@@ -96,7 +96,7 @@ class ExchangeProductsRenderer
return enterprises if enterprises.empty?
enterprises.includes(
- supplied_products: [:supplier, :variants, master: [:images]]
+ supplied_products: [:supplier, :variants, { master: [:images] }]
)
end
end
diff --git a/app/services/exchange_variant_bulk_updater.rb b/app/services/exchange_variant_bulk_updater.rb
index a617649c81..3e5345fff2 100644
--- a/app/services/exchange_variant_bulk_updater.rb
+++ b/app/services/exchange_variant_bulk_updater.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
class ExchangeVariantBulkUpdater
def initialize(exchange)
@exchange = exchange
diff --git a/app/services/exchange_variant_deleter.rb b/app/services/exchange_variant_deleter.rb
index 190b318711..0db1abd884 100644
--- a/app/services/exchange_variant_deleter.rb
+++ b/app/services/exchange_variant_deleter.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
class ExchangeVariantDeleter
def delete(product)
ExchangeVariant.
diff --git a/app/services/invoice_renderer.rb b/app/services/invoice_renderer.rb
index 956550d51b..78dbe3938b 100644
--- a/app/services/invoice_renderer.rb
+++ b/app/services/invoice_renderer.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
class InvoiceRenderer
def initialize(renderer = ApplicationController.new)
@renderer = renderer
diff --git a/app/services/line_item_syncer.rb b/app/services/line_item_syncer.rb
index 68b86d6a97..010312fef4 100644
--- a/app/services/line_item_syncer.rb
+++ b/app/services/line_item_syncer.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: false
+
# Responsible for keeping line items on initialised orders for a subscription in sync with
# the subscription line items on that subscription.
diff --git a/app/services/mail_configuration.rb b/app/services/mail_configuration.rb
index c90b3b1321..5a06fda324 100644
--- a/app/services/mail_configuration.rb
+++ b/app/services/mail_configuration.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
# Configures Rails to use the specified mail configuration
# by setting entries on the Spree Config
# and initializing Spree:MailSettings that uses the Spree::Config.
@@ -9,8 +11,6 @@ class MailConfiguration
apply_mail_settings
end
- private
-
def self.configuration
{
mail_host: ENV.fetch('MAIL_HOST'),
diff --git a/app/services/order_adjustments_fetcher.rb b/app/services/order_adjustments_fetcher.rb
index 09618b60f4..6f236074b9 100644
--- a/app/services/order_adjustments_fetcher.rb
+++ b/app/services/order_adjustments_fetcher.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
# This class allows orders with eager-loaded adjustment objects to calculate various adjustment
# types without triggering additional queries.
#
diff --git a/app/services/order_cycle_distributed_products.rb b/app/services/order_cycle_distributed_products.rb
index 5b6b0d9412..afe47b6cf7 100644
--- a/app/services/order_cycle_distributed_products.rb
+++ b/app/services/order_cycle_distributed_products.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
# Returns a (paginatable) AR object for the products or variants in stock for a given shop and OC.
# The stock-checking includes on_demand and stock level overrides from variant_overrides.
class OrderCycleDistributedProducts
diff --git a/app/services/order_cycle_distributed_variants.rb b/app/services/order_cycle_distributed_variants.rb
index 6a53b7a092..1b5c64c83e 100644
--- a/app/services/order_cycle_distributed_variants.rb
+++ b/app/services/order_cycle_distributed_variants.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
class OrderCycleDistributedVariants
def initialize(order_cycle, distributor)
@order_cycle = order_cycle
diff --git a/app/services/order_cycle_form.rb b/app/services/order_cycle_form.rb
index 87292a8a0c..6e96b9af68 100644
--- a/app/services/order_cycle_form.rb
+++ b/app/services/order_cycle_form.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
require 'open_food_network/permissions'
require 'open_food_network/order_cycle_form_applicator'
require 'order_management/subscriptions/proxy_order_syncer'
diff --git a/app/services/order_factory.rb b/app/services/order_factory.rb
index 3d8510a0df..077dbac288 100644
--- a/app/services/order_factory.rb
+++ b/app/services/order_factory.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
require 'open_food_network/scope_variant_to_hub'
# Builds orders based on a set of attributes
@@ -79,7 +81,8 @@ class OrderFactory
def create_payment
@order.recreate_all_fees!
- @order.payments.create(payment_method_id: attrs[:payment_method_id], amount: @order.reload.total)
+ @order.payments.create(payment_method_id: attrs[:payment_method_id],
+ amount: @order.reload.total)
end
def stock_limited_quantity(variant_on_demand, variant_on_hand, requested)
diff --git a/app/services/order_syncer.rb b/app/services/order_syncer.rb
index 343e73c665..f7b38a3e7b 100644
--- a/app/services/order_syncer.rb
+++ b/app/services/order_syncer.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
# Responsible for ensuring that any updates to a Subscription are propagated to any
# orders belonging to that Subscription which have been instantiated
class OrderSyncer
@@ -81,8 +83,8 @@ class OrderSyncer
# switching from pick-up to delivery affects whether simultaneous changes to shipping address
# are ignored or not.
pickup_to_delivery = force_ship_address_required?(order)
- if !pickup_to_delivery || order.shipment.present?
- save_ship_address_in_order(order) if (ship_address.changes.keys & relevant_address_attrs).any?
+ if (!pickup_to_delivery || order.shipment.present?) && (ship_address.changes.keys & relevant_address_attrs).any?
+ save_ship_address_in_order(order)
end
if !pickup_to_delivery || order.shipment.blank?
order.updater.shipping_address_from_distributor
diff --git a/app/services/order_update_issues.rb b/app/services/order_update_issues.rb
index e0389dbc5b..bcdf3c644e 100644
--- a/app/services/order_update_issues.rb
+++ b/app/services/order_update_issues.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
# Wrapper for a hash of issues encountered by instances of OrderSyncer and LineItemSyncer
# Used to report issues to the user when they attempt to update a subscription
diff --git a/app/services/order_workflow.rb b/app/services/order_workflow.rb
index b55ed43ce1..a21ccc67f2 100644
--- a/app/services/order_workflow.rb
+++ b/app/services/order_workflow.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
class OrderWorkflow
attr_reader :order
@@ -52,8 +54,8 @@ class OrderWorkflow
end
def after_transition_hook(options)
- if order.state == "delivery"
- order.select_shipping_method(options[:shipping_method_id]) if options[:shipping_method_id]
+ if order.state == "delivery" && (options[:shipping_method_id])
+ order.select_shipping_method(options[:shipping_method_id])
end
persist_all_payments if order.state == "payment"
diff --git a/app/services/permissions/order.rb b/app/services/permissions/order.rb
index a0c084cf8e..3ee221aa88 100644
--- a/app/services/permissions/order.rb
+++ b/app/services/permissions/order.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
require 'open_food_network/permissions'
module Permissions
diff --git a/app/services/permitted_attributes/checkout.rb b/app/services/permitted_attributes/checkout.rb
index 5eb9325f87..7020160df4 100644
--- a/app/services/permitted_attributes/checkout.rb
+++ b/app/services/permitted_attributes/checkout.rb
@@ -11,12 +11,12 @@ module PermittedAttributes
order: [
:email, :special_instructions,
:existing_card_id, :shipping_method_id,
- payments_attributes: [
+ { payments_attributes: [
:payment_method_id,
- source_attributes: PermittedAttributes::PaymentSource.attributes
+ { source_attributes: PermittedAttributes::PaymentSource.attributes }
],
- ship_address_attributes: PermittedAttributes::Address.attributes,
- bill_address_attributes: PermittedAttributes::Address.attributes
+ ship_address_attributes: PermittedAttributes::Address.attributes,
+ bill_address_attributes: PermittedAttributes::Address.attributes }
],
payment_source: PermittedAttributes::PaymentSource.attributes
)
diff --git a/app/services/permitted_attributes/order_cycle.rb b/app/services/permitted_attributes/order_cycle.rb
index 987bd3adf2..1a7c9047b3 100644
--- a/app/services/permitted_attributes/order_cycle.rb
+++ b/app/services/permitted_attributes/order_cycle.rb
@@ -16,7 +16,7 @@ module PermittedAttributes
[
:name, :orders_open_at, :orders_close_at, :coordinator_id,
:preferred_product_selection_from_coordinator_inventory_only,
- schedule_ids: [], coordinator_fee_ids: []
+ { schedule_ids: [], coordinator_fee_ids: [] }
]
end
@@ -33,9 +33,9 @@ module PermittedAttributes
:select_all_variants, :receival_instructions,
:pickup_time, :pickup_instructions,
:tag_list,
- tags: [:text],
- enterprise_fee_ids: [],
- variants: {}
+ { tags: [:text],
+ enterprise_fee_ids: [],
+ variants: {} }
]
end
end
diff --git a/app/services/permitted_attributes/product.rb b/app/services/permitted_attributes/product.rb
index 461876190e..0f5ba4ea5b 100644
--- a/app/services/permitted_attributes/product.rb
+++ b/app/services/permitted_attributes/product.rb
@@ -9,9 +9,9 @@ module PermittedAttributes
:display_as, :sku, :available_on, :group_buy, :group_buy_unit_size,
:taxon_ids, :primary_taxon_id, :tax_category_id, :shipping_category_id,
:meta_keywords, :meta_description, :notes, :inherits_properties,
- product_properties_attributes: [:id, :property_name, :value],
- variants_attributes: [PermittedAttributes::Variant.attributes],
- images_attributes: [:attachment]
+ { product_properties_attributes: [:id, :property_name, :value],
+ variants_attributes: [PermittedAttributes::Variant.attributes],
+ images_attributes: [:attachment] }
]
end
end
diff --git a/app/services/process_payment_intent.rb b/app/services/process_payment_intent.rb
index cd085c3391..395debc31e 100644
--- a/app/services/process_payment_intent.rb
+++ b/app/services/process_payment_intent.rb
@@ -42,7 +42,6 @@ class ProcessPaymentIntent
else
Result.new(ok: false, error: I18n.t("payment_could_not_complete"))
end
-
rescue Stripe::StripeError => e
Result.new(ok: false, error: e.message)
end
diff --git a/app/services/product_tag_rules_filterer.rb b/app/services/product_tag_rules_filterer.rb
index fcb678a672..50b6168dc6 100644
--- a/app/services/product_tag_rules_filterer.rb
+++ b/app/services/product_tag_rules_filterer.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
# Takes a Spree::Variant AR object and filters results based on applicable tag rules.
# Tag rules exists in the context of enterprise, customer, and variant_overrides,
# and are applied to variant_overrides only. Returns a Spree::Variant AR object.
diff --git a/app/services/products_renderer.rb b/app/services/products_renderer.rb
index 963330dba8..b53c868d97 100644
--- a/app/services/products_renderer.rb
+++ b/app/services/products_renderer.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
require 'open_food_network/scope_product_to_hub'
class ProductsRenderer
diff --git a/app/services/search_orders.rb b/app/services/search_orders.rb
index 8e96cfbfa0..3e17a8bed3 100644
--- a/app/services/search_orders.rb
+++ b/app/services/search_orders.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
class SearchOrders
attr_reader :orders
diff --git a/app/services/tax_rate_finder.rb b/app/services/tax_rate_finder.rb
index de16839044..59d24dd052 100644
--- a/app/services/tax_rate_finder.rb
+++ b/app/services/tax_rate_finder.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
# Finds tax rates on which an adjustment is based on.
# For example a packaging fee may contain VAT. This service finds the VAT rate
# for the tax included in the packaging fee.
diff --git a/app/services/terms_of_service.rb b/app/services/terms_of_service.rb
index 440be232cf..dc84b14988 100644
--- a/app/services/terms_of_service.rb
+++ b/app/services/terms_of_service.rb
@@ -1,11 +1,13 @@
+# frozen_string_literal: true
+
class TermsOfService
def self.tos_accepted?(customer, distributor = nil)
return false unless accepted_at = customer&.terms_and_conditions_accepted_at
- if distributor
- accepted_at > distributor.terms_and_conditions_updated_at
- else
- accepted_at > TermsOfServiceFile.updated_at
- end
+ accepted_at > if distributor
+ distributor.terms_and_conditions_updated_at
+ else
+ TermsOfServiceFile.updated_at
+ end
end
end
diff --git a/app/services/upload_sanitizer.rb b/app/services/upload_sanitizer.rb
index 4f5fc2bb3a..dfd8ae07e4 100644
--- a/app/services/upload_sanitizer.rb
+++ b/app/services/upload_sanitizer.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: false
+
# Formats uploaded files to UTF-8 encoding and strips unexpected BOM characters.
# Takes an open File object as input
class UploadSanitizer
diff --git a/app/services/variant_deleter.rb b/app/services/variant_deleter.rb
index f499f0c24d..fb9637f780 100644
--- a/app/services/variant_deleter.rb
+++ b/app/services/variant_deleter.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
# Checks the validity of a soft-delete call.
class VariantDeleter
def delete(variant)
diff --git a/app/services/variant_units/variant_and_line_item_naming.rb b/app/services/variant_units/variant_and_line_item_naming.rb
index 6e325c1fe5..9980abe083 100644
--- a/app/services/variant_units/variant_and_line_item_naming.rb
+++ b/app/services/variant_units/variant_and_line_item_naming.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
# This module is included in both the Spree::Variant and Spree::LineItem model decorators
# It contains all of our logic for creating and naming option values (which are associated
# with both models) and methods for printing human readable "names" for instances of these models.
@@ -78,7 +80,8 @@ module VariantUnits
option_type = product.variant_unit_option_type
if option_type
name = option_value_name
- ov = Spree::OptionValue.where(option_type_id: option_type, name: name, presentation: name).first ||
+ ov = Spree::OptionValue.where(option_type_id: option_type, name: name,
+ presentation: name).first ||
Spree::OptionValue.create!(option_type: option_type, name: name, presentation: name)
option_values << ov
end
diff --git a/app/services/variants_stock_levels.rb b/app/services/variants_stock_levels.rb
index a72abc8ffb..e76c1fef99 100644
--- a/app/services/variants_stock_levels.rb
+++ b/app/services/variants_stock_levels.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
# Report the stock levels of:
# - all variants in the order
# - all requested variant ids
diff --git a/app/validators/date_time_string_validator.rb b/app/validators/date_time_string_validator.rb
index f1a4eccbfb..a70bf9a0c7 100644
--- a/app/validators/date_time_string_validator.rb
+++ b/app/validators/date_time_string_validator.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
# Validates a datetime string with relaxed rules
#
# This uses ActiveSupport::TimeZone.parse behind the scenes.
diff --git a/app/validators/distributors_validator.rb b/app/validators/distributors_validator.rb
index 845983429d..a4002210aa 100644
--- a/app/validators/distributors_validator.rb
+++ b/app/validators/distributors_validator.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
# This is workaround only for https://github.com/openfoodfoundation/openfoodnetwork/issues/1560#issuecomment-300832051
class DistributorsValidator < ActiveModel::Validator
def validate(record)
diff --git a/app/validators/integer_array_validator.rb b/app/validators/integer_array_validator.rb
index 27042c972b..64f718a4d3 100644
--- a/app/validators/integer_array_validator.rb
+++ b/app/validators/integer_array_validator.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
# Validates an integer array
#
# This uses Integer() behind the scenes.
diff --git a/config.ru b/config.ru
index 0a9098c6cc..0e1070856d 100644
--- a/config.ru
+++ b/config.ru
@@ -15,5 +15,5 @@ if ENV.fetch('KILL_UNICORNS', false) && ['production', 'staging'].include?(ENV['
( ENV.fetch('UWK_MEM_MAX', 850).to_i * (1024**2) )
end
-require ::File.expand_path('../config/environment', __FILE__)
+require ::File.expand_path('config/environment', __dir__)
run Openfoodnetwork::Application
diff --git a/engines/catalog/spec/spec_helper.rb b/engines/catalog/spec/spec_helper.rb
index 3492f4f944..f6b5d7710e 100644
--- a/engines/catalog/spec/spec_helper.rb
+++ b/engines/catalog/spec/spec_helper.rb
@@ -1,5 +1,5 @@
# frozen_string_literal: true
-require "../../spec/spec_helper.rb"
+require '../../spec/spec_helper'
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].sort.each { |f| require f }
diff --git a/engines/dfc_provider/spec/spec_helper.rb b/engines/dfc_provider/spec/spec_helper.rb
index 3492f4f944..f6b5d7710e 100644
--- a/engines/dfc_provider/spec/spec_helper.rb
+++ b/engines/dfc_provider/spec/spec_helper.rb
@@ -1,5 +1,5 @@
# frozen_string_literal: true
-require "../../spec/spec_helper.rb"
+require '../../spec/spec_helper'
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].sort.each { |f| require f }
diff --git a/engines/order_management/app/controllers/order_management/application_controller.rb b/engines/order_management/app/controllers/order_management/application_controller.rb
index ba61b2290b..7834901f27 100644
--- a/engines/order_management/app/controllers/order_management/application_controller.rb
+++ b/engines/order_management/app/controllers/order_management/application_controller.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
module OrderManagement
class ApplicationController < ActionController::Base
protect_from_forgery with: :exception
diff --git a/engines/order_management/app/services/order_management/reports/bulk_coop/bulk_coop_report.rb b/engines/order_management/app/services/order_management/reports/bulk_coop/bulk_coop_report.rb
index 9b34c4a0fc..5a5bbc7b33 100644
--- a/engines/order_management/app/services/order_management/reports/bulk_coop/bulk_coop_report.rb
+++ b/engines/order_management/app/services/order_management/reports/bulk_coop/bulk_coop_report.rb
@@ -92,10 +92,39 @@ module OrderManagement
proc { |lis| lis.first.product.group_buy_unit_size || 0.0 },
proc { |_lis| "" },
proc { |_lis| "" },
- proc { |lis| lis.sum { |li| li.quantity * (li.weight_from_unit_value || 0) } },
- proc { |lis| lis.sum { |li| (li.max_quantity || 0) * (li.weight_from_unit_value || 0) } },
- proc { |lis| ( (lis.first.product.group_buy_unit_size || 0).zero? ? 0 : ( lis.sum { |li| [li.max_quantity || 0, li.quantity || 0].max * (li.weight_from_unit_value || 0) } / lis.first.product.group_buy_unit_size ) ).floor },
- proc { |lis| lis.sum { |li| [li.max_quantity || 0, li.quantity || 0].max * (li.weight_from_unit_value || 0) } - ( ( (lis.first.product.group_buy_unit_size || 0).zero? ? 0 : ( lis.sum { |li| [li.max_quantity || 0, li.quantity || 0].max * (li.weight_from_unit_value || 0) } / lis.first.product.group_buy_unit_size ) ).floor * (lis.first.product.group_buy_unit_size || 0) ) }] },
+ proc { |lis|
+ lis.sum { |li|
+ li.quantity * (li.weight_from_unit_value || 0)
+ }
+ },
+ proc { |lis|
+ lis.sum { |li|
+ (li.max_quantity || 0) * (li.weight_from_unit_value || 0)
+ }
+ },
+ proc { |lis|
+ ( if (lis.first.product.group_buy_unit_size || 0).zero?
+ 0
+ else
+ ( lis.sum { |li|
+ [li.max_quantity || 0,
+ li.quantity || 0].max * (li.weight_from_unit_value || 0)
+ } / lis.first.product.group_buy_unit_size )
+ end ).floor
+ },
+ proc { |lis|
+ lis.sum { |li|
+ [li.max_quantity || 0,
+ li.quantity || 0].max * (li.weight_from_unit_value || 0)
+ } - ( ( if (lis.first.product.group_buy_unit_size || 0).zero?
+ 0
+ else
+ ( lis.sum { |li|
+ [li.max_quantity || 0,
+ li.quantity || 0].max * (li.weight_from_unit_value || 0)
+ } / lis.first.product.group_buy_unit_size )
+ end ).floor * (lis.first.product.group_buy_unit_size || 0) )
+ }] },
{ group_by: proc { |li| li.full_name },
sort_by: proc { |full_name| full_name } }]
end
diff --git a/engines/order_management/app/services/order_management/reports/bulk_coop/renderers/html_renderer.rb b/engines/order_management/app/services/order_management/reports/bulk_coop/renderers/html_renderer.rb
index 03f7934e06..92594feaae 100644
--- a/engines/order_management/app/services/order_management/reports/bulk_coop/renderers/html_renderer.rb
+++ b/engines/order_management/app/services/order_management/reports/bulk_coop/renderers/html_renderer.rb
@@ -10,9 +10,7 @@ module OrderManagement
context.render(action: :create, renderer: self)
end
- def header
- report_data.header
- end
+ delegate :header, to: :report_data
def data_rows
report_data.list
diff --git a/engines/order_management/app/services/order_management/reports/enterprise_fee_summary/authorizer.rb b/engines/order_management/app/services/order_management/reports/enterprise_fee_summary/authorizer.rb
index 51b1393630..b85fdcbb6f 100644
--- a/engines/order_management/app/services/order_management/reports/enterprise_fee_summary/authorizer.rb
+++ b/engines/order_management/app/services/order_management/reports/enterprise_fee_summary/authorizer.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
module OrderManagement
module Reports
module EnterpriseFeeSummary
diff --git a/engines/order_management/app/services/order_management/reports/enterprise_fee_summary/data_representations/coordinator_fee.rb b/engines/order_management/app/services/order_management/reports/enterprise_fee_summary/data_representations/coordinator_fee.rb
index 0fda10c2f4..9d11b94d26 100644
--- a/engines/order_management/app/services/order_management/reports/enterprise_fee_summary/data_representations/coordinator_fee.rb
+++ b/engines/order_management/app/services/order_management/reports/enterprise_fee_summary/data_representations/coordinator_fee.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
# This module provides EnterpriseFeeSummary::Scope DB result to report mappings for coordinator fees
# in an order cycle.
diff --git a/engines/order_management/app/services/order_management/reports/enterprise_fee_summary/data_representations/exchange_order_fee.rb b/engines/order_management/app/services/order_management/reports/enterprise_fee_summary/data_representations/exchange_order_fee.rb
index c92d81c361..efef74fd11 100644
--- a/engines/order_management/app/services/order_management/reports/enterprise_fee_summary/data_representations/exchange_order_fee.rb
+++ b/engines/order_management/app/services/order_management/reports/enterprise_fee_summary/data_representations/exchange_order_fee.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
# This module provides EnterpriseFeeSummary::Scope DB result to report mappings for exchange fees
# that use order-based calculators.
diff --git a/engines/order_management/app/services/order_management/reports/enterprise_fee_summary/data_representations/incoming_exchange_line_item_fee.rb b/engines/order_management/app/services/order_management/reports/enterprise_fee_summary/data_representations/incoming_exchange_line_item_fee.rb
index 1bff07b5b0..2ab859a193 100644
--- a/engines/order_management/app/services/order_management/reports/enterprise_fee_summary/data_representations/incoming_exchange_line_item_fee.rb
+++ b/engines/order_management/app/services/order_management/reports/enterprise_fee_summary/data_representations/incoming_exchange_line_item_fee.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
# This module provides EnterpriseFeeSummary::Scope DB result to report mappings for incoming
# exchange fees that use line item -based calculators.
diff --git a/engines/order_management/app/services/order_management/reports/enterprise_fee_summary/data_representations/outgoing_exchange_line_item_fee.rb b/engines/order_management/app/services/order_management/reports/enterprise_fee_summary/data_representations/outgoing_exchange_line_item_fee.rb
index c4b997c774..3a547d659b 100644
--- a/engines/order_management/app/services/order_management/reports/enterprise_fee_summary/data_representations/outgoing_exchange_line_item_fee.rb
+++ b/engines/order_management/app/services/order_management/reports/enterprise_fee_summary/data_representations/outgoing_exchange_line_item_fee.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
# This module provides EnterpriseFeeSummary::Scope DB result to report mappings for outgoing
# exchange fees that use line item -based calculators.
diff --git a/engines/order_management/app/services/order_management/reports/enterprise_fee_summary/data_representations/payment_method_fee.rb b/engines/order_management/app/services/order_management/reports/enterprise_fee_summary/data_representations/payment_method_fee.rb
index ed0d30af1f..4fab78ad56 100644
--- a/engines/order_management/app/services/order_management/reports/enterprise_fee_summary/data_representations/payment_method_fee.rb
+++ b/engines/order_management/app/services/order_management/reports/enterprise_fee_summary/data_representations/payment_method_fee.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
# This module provides EnterpriseFeeSummary::Scope DB result to report mappings for payment method
# fees.
diff --git a/engines/order_management/app/services/order_management/reports/enterprise_fee_summary/data_representations/shipping_method_fee.rb b/engines/order_management/app/services/order_management/reports/enterprise_fee_summary/data_representations/shipping_method_fee.rb
index b96fd99e34..3863ff6d29 100644
--- a/engines/order_management/app/services/order_management/reports/enterprise_fee_summary/data_representations/shipping_method_fee.rb
+++ b/engines/order_management/app/services/order_management/reports/enterprise_fee_summary/data_representations/shipping_method_fee.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
# This module provides EnterpriseFeeSummary::Scope DB result to report mappings for shipping method
# fees.
diff --git a/engines/order_management/app/services/order_management/reports/enterprise_fee_summary/data_representations/using_enterprise_fee.rb b/engines/order_management/app/services/order_management/reports/enterprise_fee_summary/data_representations/using_enterprise_fee.rb
index c9c04477df..85e466c7ce 100644
--- a/engines/order_management/app/services/order_management/reports/enterprise_fee_summary/data_representations/using_enterprise_fee.rb
+++ b/engines/order_management/app/services/order_management/reports/enterprise_fee_summary/data_representations/using_enterprise_fee.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
# Different EnterpriseFeeSummary::Scope DB result attributes are checked when dealing with
# enterprise fees that are attached to an order cycle in different ways.
#
diff --git a/engines/order_management/app/services/order_management/reports/enterprise_fee_summary/data_representations/with_i18n.rb b/engines/order_management/app/services/order_management/reports/enterprise_fee_summary/data_representations/with_i18n.rb
index 8440886020..92ce8859f5 100644
--- a/engines/order_management/app/services/order_management/reports/enterprise_fee_summary/data_representations/with_i18n.rb
+++ b/engines/order_management/app/services/order_management/reports/enterprise_fee_summary/data_representations/with_i18n.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
module OrderManagement
module Reports
module EnterpriseFeeSummary
diff --git a/engines/order_management/app/services/order_management/reports/enterprise_fee_summary/parameters.rb b/engines/order_management/app/services/order_management/reports/enterprise_fee_summary/parameters.rb
index 938feeea75..d32f2492e0 100644
--- a/engines/order_management/app/services/order_management/reports/enterprise_fee_summary/parameters.rb
+++ b/engines/order_management/app/services/order_management/reports/enterprise_fee_summary/parameters.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
module OrderManagement
module Reports
module EnterpriseFeeSummary
diff --git a/engines/order_management/app/services/order_management/reports/enterprise_fee_summary/permissions.rb b/engines/order_management/app/services/order_management/reports/enterprise_fee_summary/permissions.rb
index 95ce055f24..e518d0b89b 100644
--- a/engines/order_management/app/services/order_management/reports/enterprise_fee_summary/permissions.rb
+++ b/engines/order_management/app/services/order_management/reports/enterprise_fee_summary/permissions.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
module OrderManagement
module Reports
module EnterpriseFeeSummary
diff --git a/engines/order_management/app/services/order_management/reports/enterprise_fee_summary/renderers/csv_renderer.rb b/engines/order_management/app/services/order_management/reports/enterprise_fee_summary/renderers/csv_renderer.rb
index c4c8450485..253f904430 100644
--- a/engines/order_management/app/services/order_management/reports/enterprise_fee_summary/renderers/csv_renderer.rb
+++ b/engines/order_management/app/services/order_management/reports/enterprise_fee_summary/renderers/csv_renderer.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
module OrderManagement
module Reports
module EnterpriseFeeSummary
diff --git a/engines/order_management/app/services/order_management/reports/enterprise_fee_summary/renderers/html_renderer.rb b/engines/order_management/app/services/order_management/reports/enterprise_fee_summary/renderers/html_renderer.rb
index 23ed8f26ba..fa372fe893 100644
--- a/engines/order_management/app/services/order_management/reports/enterprise_fee_summary/renderers/html_renderer.rb
+++ b/engines/order_management/app/services/order_management/reports/enterprise_fee_summary/renderers/html_renderer.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
module OrderManagement
module Reports
module EnterpriseFeeSummary
diff --git a/engines/order_management/app/services/order_management/reports/enterprise_fee_summary/report_data/enterprise_fee_type_total.rb b/engines/order_management/app/services/order_management/reports/enterprise_fee_summary/report_data/enterprise_fee_type_total.rb
index ca781af4e4..dddcd2ca46 100644
--- a/engines/order_management/app/services/order_management/reports/enterprise_fee_summary/report_data/enterprise_fee_type_total.rb
+++ b/engines/order_management/app/services/order_management/reports/enterprise_fee_summary/report_data/enterprise_fee_type_total.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
module OrderManagement
module Reports
module EnterpriseFeeSummary
diff --git a/engines/order_management/app/services/order_management/reports/enterprise_fee_summary/report_service.rb b/engines/order_management/app/services/order_management/reports/enterprise_fee_summary/report_service.rb
index d0fd952161..43525fee87 100644
--- a/engines/order_management/app/services/order_management/reports/enterprise_fee_summary/report_service.rb
+++ b/engines/order_management/app/services/order_management/reports/enterprise_fee_summary/report_service.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
module OrderManagement
module Reports
module EnterpriseFeeSummary
diff --git a/engines/order_management/app/services/order_management/reports/enterprise_fee_summary/scope.rb b/engines/order_management/app/services/order_management/reports/enterprise_fee_summary/scope.rb
index 78da81e503..59a5cd0470 100644
--- a/engines/order_management/app/services/order_management/reports/enterprise_fee_summary/scope.rb
+++ b/engines/order_management/app/services/order_management/reports/enterprise_fee_summary/scope.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
module OrderManagement
module Reports
module EnterpriseFeeSummary
@@ -53,7 +55,8 @@ module OrderManagement
def for_orders
chain_to_scope do
where(
- adjustable_type: ["Spree::Order", "Spree::Shipment", "Spree::LineItem", "Spree::Payment"]
+ adjustable_type: ["Spree::Order", "Spree::Shipment", "Spree::LineItem",
+ "Spree::Payment"]
)
end
end
diff --git a/engines/order_management/app/services/order_management/reports/enterprise_fee_summary/summarizer.rb b/engines/order_management/app/services/order_management/reports/enterprise_fee_summary/summarizer.rb
index 554c11999e..3f9b0098b5 100644
--- a/engines/order_management/app/services/order_management/reports/enterprise_fee_summary/summarizer.rb
+++ b/engines/order_management/app/services/order_management/reports/enterprise_fee_summary/summarizer.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
module OrderManagement
module Reports
module EnterpriseFeeSummary
diff --git a/engines/order_management/app/services/reports.rb b/engines/order_management/app/services/reports.rb
index ec85236122..5a25947ad7 100644
--- a/engines/order_management/app/services/reports.rb
+++ b/engines/order_management/app/services/reports.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
module Reports
class UnsupportedReportFormatException < StandardError; end
end
diff --git a/engines/order_management/app/services/reports/authorizer.rb b/engines/order_management/app/services/reports/authorizer.rb
index 1f232b0160..2e58266579 100644
--- a/engines/order_management/app/services/reports/authorizer.rb
+++ b/engines/order_management/app/services/reports/authorizer.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
module Reports
class Authorizer
class ParameterNotAllowedError < StandardError; end
diff --git a/engines/order_management/app/services/reports/parameters/base.rb b/engines/order_management/app/services/reports/parameters/base.rb
index 31148fd47c..0a3490f914 100644
--- a/engines/order_management/app/services/reports/parameters/base.rb
+++ b/engines/order_management/app/services/reports/parameters/base.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
module Reports
module Parameters
class Base
diff --git a/engines/order_management/app/services/reports/permissions.rb b/engines/order_management/app/services/reports/permissions.rb
index df8588670f..ebdfeacf24 100644
--- a/engines/order_management/app/services/reports/permissions.rb
+++ b/engines/order_management/app/services/reports/permissions.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
module Reports
class Permissions
attr_accessor :user
diff --git a/engines/order_management/app/services/reports/renderers/base.rb b/engines/order_management/app/services/reports/renderers/base.rb
index 73fda10231..3fb3a55f12 100644
--- a/engines/order_management/app/services/reports/renderers/base.rb
+++ b/engines/order_management/app/services/reports/renderers/base.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
module Reports
module Renderers
class Base
diff --git a/engines/order_management/app/services/reports/report_data/base.rb b/engines/order_management/app/services/reports/report_data/base.rb
index a7d0595078..94fd55ac3f 100644
--- a/engines/order_management/app/services/reports/report_data/base.rb
+++ b/engines/order_management/app/services/reports/report_data/base.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
module Reports
module ReportData
class Base
diff --git a/engines/order_management/spec/services/order_management/order/updater_spec.rb b/engines/order_management/spec/services/order_management/order/updater_spec.rb
index 7531ff7ec5..b17355a50a 100644
--- a/engines/order_management/spec/services/order_management/order/updater_spec.rb
+++ b/engines/order_management/spec/services/order_management/order/updater_spec.rb
@@ -28,9 +28,12 @@ module OrderManagement
end
it "updates adjustment totals" do
- allow(order).to receive_message_chain(:all_adjustments, :additional, :eligible, :sum).and_return(-5)
- allow(order).to receive_message_chain(:all_adjustments, :tax, :additional, :sum).and_return(20)
- allow(order).to receive_message_chain(:all_adjustments, :tax, :inclusive, :sum).and_return(15)
+ allow(order).to receive_message_chain(:all_adjustments, :additional, :eligible,
+ :sum).and_return(-5)
+ allow(order).to receive_message_chain(:all_adjustments, :tax, :additional,
+ :sum).and_return(20)
+ allow(order).to receive_message_chain(:all_adjustments, :tax, :inclusive,
+ :sum).and_return(15)
allow(order).to receive_message_chain(:adjustments, :admin, :sum).and_return(2)
updater.update_adjustment_total
diff --git a/engines/order_management/spec/services/order_management/reports/bulk_coop/bulk_coop_report_spec.rb b/engines/order_management/spec/services/order_management/reports/bulk_coop/bulk_coop_report_spec.rb
index 8fdfc4e2d8..5084671813 100644
--- a/engines/order_management/spec/services/order_management/reports/bulk_coop/bulk_coop_report_spec.rb
+++ b/engines/order_management/spec/services/order_management/reports/bulk_coop/bulk_coop_report_spec.rb
@@ -27,7 +27,8 @@ describe OrderManagement::Reports::BulkCoop::BulkCoopReport do
end
it 'shows canceled orders' do
- o2 = create(:order, state: 'canceled', completed_at: 1.day.ago, order_cycle: oc1, distributor: d1)
+ o2 = create(:order, state: 'canceled', completed_at: 1.day.ago, order_cycle: oc1,
+ distributor: d1)
line_item = build(:line_item_with_shipment)
o2.line_items << line_item
expect(subject.table_items).to include(line_item)
@@ -44,7 +45,8 @@ describe OrderManagement::Reports::BulkCoop::BulkCoopReport do
end
it 'shows canceled orders' do
- o2 = create(:order, state: 'canceled', completed_at: 1.day.ago, order_cycle: oc1, distributor: d1)
+ o2 = create(:order, state: 'canceled', completed_at: 1.day.ago, order_cycle: oc1,
+ distributor: d1)
line_item = build(:line_item_with_shipment)
o2.line_items << line_item
expect(subject.table_items).to include(line_item)
diff --git a/engines/web/app/controllers/web/angular_templates_controller.rb b/engines/web/app/controllers/web/angular_templates_controller.rb
index d8670a4664..75566fd108 100644
--- a/engines/web/app/controllers/web/angular_templates_controller.rb
+++ b/engines/web/app/controllers/web/angular_templates_controller.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
module Web
class AngularTemplatesController < ApplicationController
helper Web::Engine.helpers
diff --git a/engines/web/app/controllers/web/application_controller.rb b/engines/web/app/controllers/web/application_controller.rb
index 410b0ae531..32351f898d 100644
--- a/engines/web/app/controllers/web/application_controller.rb
+++ b/engines/web/app/controllers/web/application_controller.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
module Web
class ApplicationController < ActionController::Base
protect_from_forgery with: :exception
diff --git a/engines/web/app/helpers/web/cookies_policy_helper.rb b/engines/web/app/helpers/web/cookies_policy_helper.rb
index 0274b2d6c7..9ed4c47b73 100644
--- a/engines/web/app/helpers/web/cookies_policy_helper.rb
+++ b/engines/web/app/helpers/web/cookies_policy_helper.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
module Web
module CookiesPolicyHelper
def render_cookie_entry(cookie_name, cookie_desc, cookie_domain = nil)
diff --git a/engines/web/config/routes.rb b/engines/web/config/routes.rb
index b2a060617a..0b6e6f3fbf 100644
--- a/engines/web/config/routes.rb
+++ b/engines/web/config/routes.rb
@@ -5,5 +5,6 @@ Openfoodnetwork::Application.routes.append do
resource :consent, only: [:show, :create, :destroy], controller: "web/api/v0/cookies_consent"
end
- get "/angular-templates/:id", to: "web/angular_templates#show", constraints: { name: %r{[\/\w\.]+} }
+ get "/angular-templates/:id", to: "web/angular_templates#show",
+ constraints: { name: %r{[/\w.]+} }
end
diff --git a/engines/web/lib/web/cookies_consent.rb b/engines/web/lib/web/cookies_consent.rb
index 64f6c0c825..a2f085d520 100644
--- a/engines/web/lib/web/cookies_consent.rb
+++ b/engines/web/lib/web/cookies_consent.rb
@@ -1,6 +1,8 @@
+# frozen_string_literal: true
+
module Web
class CookiesConsent
- COOKIE_NAME = 'cookies_consent'.freeze
+ COOKIE_NAME = 'cookies_consent'
def initialize(cookies, domain)
@cookies = cookies
diff --git a/lib/discourse/single_sign_on.rb b/lib/discourse/single_sign_on.rb
index 7f44b352a2..81264ce7f9 100644
--- a/lib/discourse/single_sign_on.rb
+++ b/lib/discourse/single_sign_on.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
# This class is the reference implementation of a SSO provider from Discourse.
module Discourse
@@ -5,11 +7,11 @@ module Discourse
ACCESSORS = [:nonce, :name, :username, :email, :avatar_url, :avatar_force_update, :require_activation,
:about_me, :external_id, :return_sso_url, :admin, :moderator, :suppress_welcome_message].freeze
FIXNUMS = [].freeze
- BOOLS = [:avatar_force_update, :admin, :moderator, :require_activation, :suppress_welcome_message].freeze
+ BOOLS = [:avatar_force_update, :admin, :moderator, :require_activation,
+ :suppress_welcome_message].freeze
NONCE_EXPIRY_TIME = 10.minutes
- attr_accessor(*ACCESSORS)
- attr_accessor :sso_secret, :sso_url
+ attr_accessor(*ACCESSORS, :sso_secret, :sso_url)
def self.sso_secret
raise "sso_secret not implemented on class, be sure to set it on instance"
diff --git a/lib/open_food_network/address_finder.rb b/lib/open_food_network/address_finder.rb
index c2313b9693..53b5290ff9 100644
--- a/lib/open_food_network/address_finder.rb
+++ b/lib/open_food_network/address_finder.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
# Finds an address based on the data provided
# Can take any combination of an email String, Customer or Spree::User as args
# The #bill_address and #ship_address methods automatically return matched addresses
diff --git a/lib/open_food_network/available_payment_method_filter.rb b/lib/open_food_network/available_payment_method_filter.rb
index d42d4ae51b..f15714d1fb 100644
--- a/lib/open_food_network/available_payment_method_filter.rb
+++ b/lib/open_food_network/available_payment_method_filter.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
module OpenFoodNetwork
class AvailablePaymentMethodFilter
def filter!(payment_methods)
diff --git a/lib/open_food_network/column_preference_defaults.rb b/lib/open_food_network/column_preference_defaults.rb
index a79cfdd4c7..3f135f6b61 100644
--- a/lib/open_food_network/column_preference_defaults.rb
+++ b/lib/open_food_network/column_preference_defaults.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
module OpenFoodNetwork
module ColumnPreferenceDefaults
private
diff --git a/lib/open_food_network/customers_report.rb b/lib/open_food_network/customers_report.rb
index 457dc66d59..0b3dd440c5 100644
--- a/lib/open_food_network/customers_report.rb
+++ b/lib/open_food_network/customers_report.rb
@@ -1,6 +1,9 @@
+# frozen_string_literal: true
+
module OpenFoodNetwork
class CustomersReport
attr_reader :params
+
def initialize(user, params = {}, compile_table = false)
@params = params
@user = user
diff --git a/lib/open_food_network/enterprise_fee_applicator.rb b/lib/open_food_network/enterprise_fee_applicator.rb
index 8b12e17e76..e856ca3f8d 100644
--- a/lib/open_food_network/enterprise_fee_applicator.rb
+++ b/lib/open_food_network/enterprise_fee_applicator.rb
@@ -1,5 +1,7 @@
+# frozen_string_literal: true
+
module OpenFoodNetwork
- class EnterpriseFeeApplicator < Struct.new(:enterprise_fee, :variant, :role)
+ EnterpriseFeeApplicator = Struct.new(:enterprise_fee, :variant, :role) do
def create_line_item_adjustment(line_item)
create_adjustment(line_item_adjustment_label, line_item)
end
@@ -15,7 +17,8 @@ module OpenFoodNetwork
label, adjustable, true, "closed", tax_category(adjustable)
)
- AdjustmentMetadata.create! adjustment: adjustment, enterprise: enterprise_fee.enterprise, fee_name: enterprise_fee.name, fee_type: enterprise_fee.fee_type, enterprise_role: role
+ AdjustmentMetadata.create! adjustment: adjustment, enterprise: enterprise_fee.enterprise,
+ fee_name: enterprise_fee.name, fee_type: enterprise_fee.fee_type, enterprise_role: role
end
def line_item_adjustment_label
@@ -27,7 +30,8 @@ module OpenFoodNetwork
end
def base_adjustment_label
- I18n.t(:enterprise_fee_by, type: enterprise_fee.fee_type, role: role, enterprise_name: enterprise_fee.enterprise.name)
+ I18n.t(:enterprise_fee_by, type: enterprise_fee.fee_type, role: role,
+ enterprise_name: enterprise_fee.enterprise.name)
end
def tax_category(target)
diff --git a/lib/open_food_network/enterprise_fee_calculator.rb b/lib/open_food_network/enterprise_fee_calculator.rb
index 47db702182..cfc66be18f 100644
--- a/lib/open_food_network/enterprise_fee_calculator.rb
+++ b/lib/open_food_network/enterprise_fee_calculator.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
require 'open_food_network/enterprise_fee_applicator'
module OpenFoodNetwork
@@ -33,7 +35,8 @@ module OpenFoodNetwork
def fees_by_type_for(variant)
per_item_enterprise_fee_applicators_for(variant).each_with_object({}) do |applicator, fees|
fees[applicator.enterprise_fee.fee_type.to_sym] ||= 0
- fees[applicator.enterprise_fee.fee_type.to_sym] += calculate_fee_for variant, applicator.enterprise_fee
+ fees[applicator.enterprise_fee.fee_type.to_sym] += calculate_fee_for variant,
+ applicator.enterprise_fee
end.select { |_fee_type, amount| amount > 0 }
end
@@ -58,7 +61,8 @@ module OpenFoodNetwork
@order_cycle.exchanges_carrying(variant, @distributor).each do |exchange|
exchange.enterprise_fees.per_item.each do |enterprise_fee|
- fees << OpenFoodNetwork::EnterpriseFeeApplicator.new(enterprise_fee, variant, exchange.role)
+ fees << OpenFoodNetwork::EnterpriseFeeApplicator.new(enterprise_fee, variant,
+ exchange.role)
end
end
@@ -129,7 +133,8 @@ module OpenFoodNetwork
def calculate_fee_for(variant, enterprise_fee)
# Spree's Calculator interface accepts Orders or LineItems,
# so we meet that interface with a struct.
- line_item = OpenStruct.new variant: variant, quantity: 1, price: variant.price, amount: variant.price
+ line_item = OpenStruct.new variant: variant, quantity: 1, price: variant.price,
+ amount: variant.price
enterprise_fee.compute_amount(line_item)
end
end
diff --git a/lib/open_food_network/enterprise_injection_data.rb b/lib/open_food_network/enterprise_injection_data.rb
index dd6db131af..31801c63f9 100644
--- a/lib/open_food_network/enterprise_injection_data.rb
+++ b/lib/open_food_network/enterprise_injection_data.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
module OpenFoodNetwork
class EnterpriseInjectionData
def active_distributor_ids
@@ -10,24 +12,21 @@ module OpenFoodNetwork
end
def shipping_method_services
- @shipping_method_services ||= begin
- CacheService.cached_data_by_class("shipping_method_services", Spree::ShippingMethod) do
- # This result relies on a simple join with DistributorShippingMethod.
- # Updated DistributorShippingMethod records touch their associated Spree::ShippingMethod.
- Spree::ShippingMethod.services
- end
+ @shipping_method_services ||= CacheService.cached_data_by_class("shipping_method_services",
+ Spree::ShippingMethod) do
+ # This result relies on a simple join with DistributorShippingMethod.
+ # Updated DistributorShippingMethod records touch their associated Spree::ShippingMethod.
+ Spree::ShippingMethod.services
end
end
def supplied_taxons
- @supplied_taxons ||= begin
- CacheService.cached_data_by_class("supplied_taxons", Spree::Taxon) do
- # This result relies on a join with associated supplied products, through the
- # class Classification which maps the relationship. Classification records touch
- # their associated Spree::Taxon when updated. A Spree::Product's primary_taxon
- # is also touched when changed.
- Spree::Taxon.supplied_taxons
- end
+ @supplied_taxons ||= CacheService.cached_data_by_class("supplied_taxons", Spree::Taxon) do
+ # This result relies on a join with associated supplied products, through the
+ # class Classification which maps the relationship. Classification records touch
+ # their associated Spree::Taxon when updated. A Spree::Product's primary_taxon
+ # is also touched when changed.
+ Spree::Taxon.supplied_taxons
end
end
diff --git a/lib/open_food_network/enterprise_issue_validator.rb b/lib/open_food_network/enterprise_issue_validator.rb
index b845046f2a..b69a7e6f36 100644
--- a/lib/open_food_network/enterprise_issue_validator.rb
+++ b/lib/open_food_network/enterprise_issue_validator.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
module OpenFoodNetwork
class EnterpriseIssueValidator
include Rails.application.routes.url_helpers
@@ -11,14 +13,16 @@ module OpenFoodNetwork
unless shipping_methods_ok?
issues << {
- description: I18n.t('admin.enterprise_issues.has_no_shipping_methods', enterprise: @enterprise.name),
+ description: I18n.t('admin.enterprise_issues.has_no_shipping_methods',
+ enterprise: @enterprise.name),
link: "#{I18n.t('admin.enterprise_issues.create_new')}"
}
end
unless payment_methods_ok?
issues << {
- description: I18n.t('admin.enterprise_issues.has_no_payment_methods', enterprise: @enterprise.name),
+ description: I18n.t('admin.enterprise_issues.has_no_payment_methods',
+ enterprise: @enterprise.name),
link: "#{I18n.t('admin.enterprise_issues.create_new')}"
}
end
diff --git a/lib/open_food_network/error_logger.rb b/lib/open_food_network/error_logger.rb
index a1199c9e68..51ea1e715e 100644
--- a/lib/open_food_network/error_logger.rb
+++ b/lib/open_food_network/error_logger.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
# Our error logging API currently wraps Bugsnag.
# It makes us more flexible if we wanted to replace Bugsnag or change logging
# behaviour.
diff --git a/lib/open_food_network/feature_toggle.rb b/lib/open_food_network/feature_toggle.rb
index 2863ef4cee..4886c92f97 100644
--- a/lib/open_food_network/feature_toggle.rb
+++ b/lib/open_food_network/feature_toggle.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
module OpenFoodNetwork
# This feature toggles implementation provides two mechanisms to conditionally enable features.
#
diff --git a/lib/open_food_network/group_buy_report.rb b/lib/open_food_network/group_buy_report.rb
index 245f6ca945..c6ab52a6df 100644
--- a/lib/open_food_network/group_buy_report.rb
+++ b/lib/open_food_network/group_buy_report.rb
@@ -1,13 +1,17 @@
+# frozen_string_literal: true
+
module OpenFoodNetwork
GroupBuyVariantRow = Struct.new(:variant, :sum_quantities, :sum_max_quantities) do
def to_row
- [variant.product.supplier.name, variant.product.name, I18n.t('admin.reports.unitsize'), variant.options_text, variant.weight, sum_quantities, sum_max_quantities]
+ [variant.product.supplier.name, variant.product.name, I18n.t('admin.reports.unitsize'),
+ variant.options_text, variant.weight, sum_quantities, sum_max_quantities]
end
end
GroupBuyProductRow = Struct.new(:product, :sum_quantities, :sum_max_quantities) do
def to_row
- [product.supplier.name, product.name, I18n.t('admin.reports.unitsize'), I18n.t('admin.reports.total'), "", sum_quantities, sum_max_quantities]
+ [product.supplier.name, product.name, I18n.t('admin.reports.unitsize'),
+ I18n.t('admin.reports.total'), "", sum_quantities, sum_max_quantities]
end
end
@@ -40,13 +44,17 @@ module OpenFoodNetwork
variant_groups.each do |variant, line_items_by_variant|
sum_quantities = line_items_by_variant.to_a.sum(&:quantity)
sum_max_quantities = line_items_by_variant.sum { |li| li.max_quantity || 0 }
- variants_and_quantities << GroupBuyVariantRow.new(variant, sum_quantities, sum_max_quantities)
+ variants_and_quantities << GroupBuyVariantRow.new(variant, sum_quantities,
+ sum_max_quantities)
end
# Sum quantities for each product (Total line)
sum_quantities = line_items_by_product.sum { |li| (li.variant.weight || 0) * li.quantity }
- sum_max_quantities = line_items_by_product.sum { |li| (li.variant.weight || 0) * (li.max_quantity || 0) }
- variants_and_quantities << GroupBuyProductRow.new(product, sum_quantities, sum_max_quantities)
+ sum_max_quantities = line_items_by_product.sum { |li|
+ (li.variant.weight || 0) * (li.max_quantity || 0)
+ }
+ variants_and_quantities << GroupBuyProductRow.new(product, sum_quantities,
+ sum_max_quantities)
end
end
variants_and_quantities
diff --git a/lib/open_food_network/i18n_config.rb b/lib/open_food_network/i18n_config.rb
index 3807aeae5d..8830f93378 100644
--- a/lib/open_food_network/i18n_config.rb
+++ b/lib/open_food_network/i18n_config.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
module OpenFoodNetwork
# Provides access to the language settings.
# Currently, language settings are read from the environment.
diff --git a/lib/open_food_network/lettuce_share_report.rb b/lib/open_food_network/lettuce_share_report.rb
index 49fffbadac..25868c9006 100644
--- a/lib/open_food_network/lettuce_share_report.rb
+++ b/lib/open_food_network/lettuce_share_report.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
require 'open_food_network/products_and_inventory_report_base'
require 'variant_units/option_value_namer'
diff --git a/lib/open_food_network/order_and_distributor_report.rb b/lib/open_food_network/order_and_distributor_report.rb
index a82f300873..310e8c537d 100644
--- a/lib/open_food_network/order_and_distributor_report.rb
+++ b/lib/open_food_network/order_and_distributor_report.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
module OpenFoodNetwork
class OrderAndDistributorReport
def initialize(user, params = {}, render_table = false)
diff --git a/lib/open_food_network/order_cycle_form_applicator.rb b/lib/open_food_network/order_cycle_form_applicator.rb
index 960508f06d..67952eb632 100644
--- a/lib/open_food_network/order_cycle_form_applicator.rb
+++ b/lib/open_food_network/order_cycle_form_applicator.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
require 'open_food_network/order_cycle_permissions'
module OpenFoodNetwork
@@ -61,11 +63,13 @@ module OpenFoodNetwork
attr_accessor :touched_exchanges
def exchange_exists?(sender_id, receiver_id, incoming)
- @order_cycle.exchanges.where(sender_id: sender_id, receiver_id: receiver_id, incoming: incoming).present?
+ @order_cycle.exchanges.where(sender_id: sender_id, receiver_id: receiver_id,
+ incoming: incoming).present?
end
def add_exchange(sender_id, receiver_id, incoming, attrs = {})
- attrs = attrs.reverse_merge(sender_id: sender_id, receiver_id: receiver_id, incoming: incoming)
+ attrs = attrs.reverse_merge(sender_id: sender_id, receiver_id: receiver_id,
+ incoming: incoming)
variant_ids = attrs.delete :variant_ids
exchange = @order_cycle.exchanges.build attrs
@@ -78,7 +82,8 @@ module OpenFoodNetwork
end
def update_exchange(sender_id, receiver_id, incoming, attrs = {})
- exchange = @order_cycle.exchanges.where(sender_id: sender_id, receiver_id: receiver_id, incoming: incoming).first
+ exchange = @order_cycle.exchanges.where(sender_id: sender_id, receiver_id: receiver_id,
+ incoming: incoming).first
return unless permission_for(exchange)
remove_unauthorized_exchange_attributes(exchange, attrs)
diff --git a/lib/open_food_network/order_cycle_management_report.rb b/lib/open_food_network/order_cycle_management_report.rb
index 6344a5d538..d845e6eedf 100644
--- a/lib/open_food_network/order_cycle_management_report.rb
+++ b/lib/open_food_network/order_cycle_management_report.rb
@@ -141,7 +141,9 @@ module OpenFoodNetwork
end
def has_temperature_controlled_items?(order)
- order.line_items.any? { |line_item| line_item.product.shipping_category.andand.temperature_controlled }
+ order.line_items.any? { |line_item|
+ line_item.product.shipping_category.andand.temperature_controlled
+ }
end
def is_payment_methods?
diff --git a/lib/open_food_network/order_cycle_permissions.rb b/lib/open_food_network/order_cycle_permissions.rb
index 2fea3258b0..a3423c8c65 100644
--- a/lib/open_food_network/order_cycle_permissions.rb
+++ b/lib/open_food_network/order_cycle_permissions.rb
@@ -242,9 +242,7 @@ module OpenFoodNetwork
end
def active_outgoing_variants(hub)
- @active_outgoing_variants ||= begin
- @order_cycle.exchanges.outgoing.where(receiver_id: hub).first.andand.variants || []
- end
+ @active_outgoing_variants ||= @order_cycle.exchanges.outgoing.where(receiver_id: hub).first.andand.variants || []
end
def user_manages_coordinator_or(enterprise)
diff --git a/lib/open_food_network/order_grouper.rb b/lib/open_food_network/order_grouper.rb
index 8d810254d5..cc4720bab9 100644
--- a/lib/open_food_network/order_grouper.rb
+++ b/lib/open_food_network/order_grouper.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
module OpenFoodNetwork
class OrderGrouper
def initialize(rules, column_constructors, report = nil)
@@ -54,8 +56,7 @@ module OpenFoodNetwork
def table(items)
tree = build_tree(items, @rules)
- table = build_table(tree)
- table
+ build_table(tree)
end
private
diff --git a/lib/open_food_network/orders_and_fulfillments_report.rb b/lib/open_food_network/orders_and_fulfillments_report.rb
index ed7850d644..d6bd7487d6 100644
--- a/lib/open_food_network/orders_and_fulfillments_report.rb
+++ b/lib/open_food_network/orders_and_fulfillments_report.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
require "open_food_network/reports/line_items"
require "open_food_network/orders_and_fulfillments_report/supplier_totals_report"
require "open_food_network/orders_and_fulfillments_report/supplier_totals_by_distributor_report"
diff --git a/lib/open_food_network/orders_and_fulfillments_report/customer_totals_report.rb b/lib/open_food_network/orders_and_fulfillments_report/customer_totals_report.rb
index 94bd22882c..ee5c4f4007 100644
--- a/lib/open_food_network/orders_and_fulfillments_report/customer_totals_report.rb
+++ b/lib/open_food_network/orders_and_fulfillments_report/customer_totals_report.rb
@@ -1,8 +1,10 @@
+# frozen_string_literal: true
+
# rubocop:disable Metrics/ClassLength
module OpenFoodNetwork
class OrdersAndFulfillmentsReport
class CustomerTotalsReport
- REPORT_TYPE = "order_cycle_customer_totals".freeze
+ REPORT_TYPE = "order_cycle_customer_totals"
attr_reader :context
diff --git a/lib/open_food_network/orders_and_fulfillments_report/default_report.rb b/lib/open_food_network/orders_and_fulfillments_report/default_report.rb
index b739e4c238..9fd0efa6a0 100644
--- a/lib/open_food_network/orders_and_fulfillments_report/default_report.rb
+++ b/lib/open_food_network/orders_and_fulfillments_report/default_report.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
module OpenFoodNetwork
class OrdersAndFulfillmentsReport
class DefaultReport
diff --git a/lib/open_food_network/orders_and_fulfillments_report/distributor_totals_by_supplier_report.rb b/lib/open_food_network/orders_and_fulfillments_report/distributor_totals_by_supplier_report.rb
index d9828e6aef..5ce88bdab6 100644
--- a/lib/open_food_network/orders_and_fulfillments_report/distributor_totals_by_supplier_report.rb
+++ b/lib/open_food_network/orders_and_fulfillments_report/distributor_totals_by_supplier_report.rb
@@ -1,7 +1,9 @@
+# frozen_string_literal: true
+
module OpenFoodNetwork
class OrdersAndFulfillmentsReport
class DistributorTotalsBySupplierReport
- REPORT_TYPE = "order_cycle_distributor_totals_by_supplier".freeze
+ REPORT_TYPE = "order_cycle_distributor_totals_by_supplier"
attr_reader :context
@@ -68,7 +70,7 @@ module OpenFoodNetwork
# rubocop:enable Metrics/AbcSize
def line_item_includes
- [{ order: [:distributor, :adjustments, shipments: { shipping_rates: :shipping_method }],
+ [{ order: [:distributor, :adjustments, { shipments: { shipping_rates: :shipping_method } }],
variant: [{ option_values: :option_type }, { product: :supplier }] }]
end
end
diff --git a/lib/open_food_network/orders_and_fulfillments_report/supplier_totals_by_distributor_report.rb b/lib/open_food_network/orders_and_fulfillments_report/supplier_totals_by_distributor_report.rb
index 98aa381a79..d294a514c6 100644
--- a/lib/open_food_network/orders_and_fulfillments_report/supplier_totals_by_distributor_report.rb
+++ b/lib/open_food_network/orders_and_fulfillments_report/supplier_totals_by_distributor_report.rb
@@ -1,7 +1,9 @@
+# frozen_string_literal: true
+
module OpenFoodNetwork
class OrdersAndFulfillmentsReport
class SupplierTotalsByDistributorReport
- REPORT_TYPE = "order_cycle_supplier_totals_by_distributor".freeze
+ REPORT_TYPE = "order_cycle_supplier_totals_by_distributor"
attr_reader :context
diff --git a/lib/open_food_network/orders_and_fulfillments_report/supplier_totals_report.rb b/lib/open_food_network/orders_and_fulfillments_report/supplier_totals_report.rb
index a7a341664c..60c11d93e0 100644
--- a/lib/open_food_network/orders_and_fulfillments_report/supplier_totals_report.rb
+++ b/lib/open_food_network/orders_and_fulfillments_report/supplier_totals_report.rb
@@ -1,7 +1,9 @@
+# frozen_string_literal: true
+
module OpenFoodNetwork
class OrdersAndFulfillmentsReport
class SupplierTotalsReport
- REPORT_TYPE = "order_cycle_supplier_totals".freeze
+ REPORT_TYPE = "order_cycle_supplier_totals"
attr_reader :context
diff --git a/lib/open_food_network/packing_report.rb b/lib/open_food_network/packing_report.rb
index 8fcc1eb904..ab60c449a5 100644
--- a/lib/open_food_network/packing_report.rb
+++ b/lib/open_food_network/packing_report.rb
@@ -1,8 +1,11 @@
+# frozen_string_literal: true
+
require "open_food_network/reports/line_items"
module OpenFoodNetwork
class PackingReport
attr_reader :params
+
def initialize(user, params = {}, render_table = false)
@params = params
@user = user
diff --git a/lib/open_food_network/paperclippable.rb b/lib/open_food_network/paperclippable.rb
index 4bb6396695..e510c6af82 100644
--- a/lib/open_food_network/paperclippable.rb
+++ b/lib/open_food_network/paperclippable.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
# Allow use of Paperclip's has_attached_file on non-ActiveRecord classes
# https://gist.github.com/basgys/5712426
diff --git a/lib/open_food_network/payments_report.rb b/lib/open_food_network/payments_report.rb
index 2d0d2d8be5..efbecec205 100644
--- a/lib/open_food_network/payments_report.rb
+++ b/lib/open_food_network/payments_report.rb
@@ -3,6 +3,7 @@
module OpenFoodNetwork
class PaymentsReport
attr_reader :params
+
def initialize(user, params = {}, render_table = false)
@params = params
@user = user
diff --git a/lib/open_food_network/permissions.rb b/lib/open_food_network/permissions.rb
index 8f55de56fe..a3ddb7f36e 100644
--- a/lib/open_food_network/permissions.rb
+++ b/lib/open_food_network/permissions.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
module OpenFoodNetwork
class Permissions
def initialize(user)
diff --git a/lib/open_food_network/products_and_inventory_report.rb b/lib/open_food_network/products_and_inventory_report.rb
index 0e89434abd..df40f3aa4c 100644
--- a/lib/open_food_network/products_and_inventory_report.rb
+++ b/lib/open_food_network/products_and_inventory_report.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
require 'open_food_network/products_and_inventory_report_base'
module OpenFoodNetwork
diff --git a/lib/open_food_network/products_and_inventory_report_base.rb b/lib/open_food_network/products_and_inventory_report_base.rb
index c669dc4d6a..22cd561f36 100644
--- a/lib/open_food_network/products_and_inventory_report_base.rb
+++ b/lib/open_food_network/products_and_inventory_report_base.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
require 'open_food_network/scope_variant_to_hub'
module OpenFoodNetwork
diff --git a/lib/open_food_network/property_merge.rb b/lib/open_food_network/property_merge.rb
index 82bf92eaee..84a5ed066a 100644
--- a/lib/open_food_network/property_merge.rb
+++ b/lib/open_food_network/property_merge.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
module OpenFoodNetwork
class PropertyMerge
def self.merge(primary, secondary)
diff --git a/lib/open_food_network/referer_parser.rb b/lib/open_food_network/referer_parser.rb
index 20be289f44..5fa3ea5670 100644
--- a/lib/open_food_network/referer_parser.rb
+++ b/lib/open_food_network/referer_parser.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
module OpenFoodNetwork
class RefererParser
def self.path(referer)
diff --git a/lib/open_food_network/reports/line_items.rb b/lib/open_food_network/reports/line_items.rb
index 3fcc904246..c8622860df 100644
--- a/lib/open_food_network/reports/line_items.rb
+++ b/lib/open_food_network/reports/line_items.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
module OpenFoodNetwork
module Reports
# shared code to search and list line items
diff --git a/lib/open_food_network/reports/list.rb b/lib/open_food_network/reports/list.rb
index e4425ba936..bfbc625488 100644
--- a/lib/open_food_network/reports/list.rb
+++ b/lib/open_food_network/reports/list.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
module OpenFoodNetwork
module Reports
class List
diff --git a/lib/open_food_network/sales_tax_report.rb b/lib/open_food_network/sales_tax_report.rb
index 5d1099e824..e117b0924c 100644
--- a/lib/open_food_network/sales_tax_report.rb
+++ b/lib/open_food_network/sales_tax_report.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
module OpenFoodNetwork
class SalesTaxReport
include Spree::ReportsHelper
diff --git a/lib/open_food_network/scope_product_to_hub.rb b/lib/open_food_network/scope_product_to_hub.rb
index a8707b7032..e50790a8da 100644
--- a/lib/open_food_network/scope_product_to_hub.rb
+++ b/lib/open_food_network/scope_product_to_hub.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
require 'open_food_network/scope_variant_to_hub'
module OpenFoodNetwork
diff --git a/lib/open_food_network/scope_variant_to_hub.rb b/lib/open_food_network/scope_variant_to_hub.rb
index 0e4f36e7e9..568121a342 100644
--- a/lib/open_food_network/scope_variant_to_hub.rb
+++ b/lib/open_food_network/scope_variant_to_hub.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
module OpenFoodNetwork
class ScopeVariantToHub
def initialize(hub, variant_overrides = nil)
diff --git a/lib/open_food_network/scope_variants_for_search.rb b/lib/open_food_network/scope_variants_for_search.rb
index 5d16eafefe..1ceb52499d 100644
--- a/lib/open_food_network/scope_variants_for_search.rb
+++ b/lib/open_food_network/scope_variants_for_search.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
require 'open_food_network/scope_variant_to_hub'
# Used to return a set of variants which match the criteria provided
diff --git a/lib/open_food_network/spree_api_key_loader.rb b/lib/open_food_network/spree_api_key_loader.rb
index 5eb7236221..c3a532acbf 100644
--- a/lib/open_food_network/spree_api_key_loader.rb
+++ b/lib/open_food_network/spree_api_key_loader.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
module OpenFoodNetwork
module SpreeApiKeyLoader
def load_spree_api_key
diff --git a/lib/open_food_network/tag_rule_applicator.rb b/lib/open_food_network/tag_rule_applicator.rb
index 0c01f5dd18..09060a8ecf 100644
--- a/lib/open_food_network/tag_rule_applicator.rb
+++ b/lib/open_food_network/tag_rule_applicator.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
module OpenFoodNetwork
class TagRuleApplicator
attr_reader :enterprise, :rule_class, :customer_tags
diff --git a/lib/open_food_network/users_and_enterprises_report.rb b/lib/open_food_network/users_and_enterprises_report.rb
index 4a88e2f5f9..fc13095534 100644
--- a/lib/open_food_network/users_and_enterprises_report.rb
+++ b/lib/open_food_network/users_and_enterprises_report.rb
@@ -1,6 +1,9 @@
+# frozen_string_literal: true
+
module OpenFoodNetwork
class UsersAndEnterprisesReport
attr_reader :params
+
def initialize(params = {}, compile_table = false)
@params = params
@compile_table = compile_table
diff --git a/lib/open_food_network/xero_invoices_report.rb b/lib/open_food_network/xero_invoices_report.rb
index a92c133607..b36cc95ca1 100644
--- a/lib/open_food_network/xero_invoices_report.rb
+++ b/lib/open_food_network/xero_invoices_report.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
module OpenFoodNetwork
class XeroInvoicesReport
def initialize(user, opts = {}, compile_table = false)
@@ -15,7 +17,8 @@ module OpenFoodNetwork
def header
# NOTE: These are NOT to be translated, they need to be in this exact format to work with Xero
- %w(*ContactName EmailAddress POAddressLine1 POAddressLine2 POAddressLine3 POAddressLine4 POCity PORegion POPostalCode POCountry *InvoiceNumber Reference *InvoiceDate *DueDate InventoryItemCode *Description *Quantity *UnitAmount Discount *AccountCode *TaxType TrackingName1 TrackingOption1 TrackingName2 TrackingOption2 Currency BrandingTheme Paid?)
+ %w(*ContactName EmailAddress POAddressLine1 POAddressLine2 POAddressLine3 POAddressLine4
+ POCity PORegion POPostalCode POCountry *InvoiceNumber Reference *InvoiceDate *DueDate InventoryItemCode *Description *Quantity *UnitAmount Discount *AccountCode *TaxType TrackingName1 TrackingOption1 TrackingName2 TrackingOption2 Currency BrandingTheme Paid?)
end
def search
@@ -49,7 +52,7 @@ module OpenFoodNetwork
def line_item_includes
[:bill_address, :adjustments,
- line_items: { variant: [{ option_values: :option_type }, { product: :supplier }] }]
+ { line_items: { variant: [{ option_values: :option_type }, { product: :supplier }] } }]
end
def detail_rows_for_order(order, invoice_number, opts)
@@ -109,25 +112,30 @@ module OpenFoodNetwork
def produce_summary_rows(order, invoice_number, opts)
[summary_row(order, I18n.t(:report_header_total_untaxable_produce), total_untaxable_products(order), invoice_number, I18n.t(:report_header_gst_free_income), opts),
- summary_row(order, I18n.t(:report_header_total_taxable_produce), total_taxable_products(order), invoice_number, I18n.t(:report_header_gst_on_income), opts)]
+ summary_row(order, I18n.t(:report_header_total_taxable_produce),
+ total_taxable_products(order), invoice_number, I18n.t(:report_header_gst_on_income), opts)]
end
def fee_summary_rows(order, invoice_number, opts)
[summary_row(order, I18n.t(:report_header_total_untaxable_fees), total_untaxable_fees(order), invoice_number, I18n.t(:report_header_gst_free_income), opts),
- summary_row(order, I18n.t(:report_header_total_taxable_fees), total_taxable_fees(order), invoice_number, I18n.t(:report_header_gst_on_income), opts)]
+ summary_row(order, I18n.t(:report_header_total_taxable_fees), total_taxable_fees(order),
+ invoice_number, I18n.t(:report_header_gst_on_income), opts)]
end
def shipping_summary_rows(order, invoice_number, opts)
- [summary_row(order, I18n.t(:report_header_delivery_shipping_cost), total_shipping(order), invoice_number, tax_on_shipping_s(order), opts)]
+ [summary_row(order, I18n.t(:report_header_delivery_shipping_cost), total_shipping(order),
+ invoice_number, tax_on_shipping_s(order), opts)]
end
def payment_summary_rows(order, invoice_number, opts)
- [summary_row(order, I18n.t(:report_header_transaction_fee), total_transaction(order), invoice_number, I18n.t(:report_header_gst_free_income), opts)]
+ [summary_row(order, I18n.t(:report_header_transaction_fee), total_transaction(order),
+ invoice_number, I18n.t(:report_header_gst_free_income), opts)]
end
def admin_adjustment_summary_rows(order, invoice_number, opts)
[summary_row(order, I18n.t(:report_header_total_untaxable_admin), total_untaxable_admin_adjustments(order), invoice_number, I18n.t(:report_header_gst_free_income), opts),
- summary_row(order, I18n.t(:report_header_total_taxable_admin), total_taxable_admin_adjustments(order), invoice_number, I18n.t(:report_header_gst_on_income), opts)]
+ summary_row(order, I18n.t(:report_header_total_taxable_admin),
+ total_taxable_admin_adjustments(order), invoice_number, I18n.t(:report_header_gst_on_income), opts)]
end
def summary_row(order, description, amount, invoice_number, tax_type, opts = {})
@@ -135,7 +143,9 @@ module OpenFoodNetwork
end
def row(order, sku, description, quantity, amount, invoice_number, tax_type, opts = {})
+ # rubocop:disable Style/NumericPredicate
return nil if amount == 0
+ # rubocop:enable Style/NumericPredicate
[order.bill_address.andand.full_name,
order.email,
diff --git a/lib/spree/authentication_helpers.rb b/lib/spree/authentication_helpers.rb
index 64e015fb5c..f463ebbdb4 100644
--- a/lib/spree/authentication_helpers.rb
+++ b/lib/spree/authentication_helpers.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
module Spree
module AuthenticationHelpers
def self.included(receiver)
diff --git a/lib/spree/core/controller_helpers/order.rb b/lib/spree/core/controller_helpers/order.rb
index e0f7423613..1f9fe80827 100644
--- a/lib/spree/core/controller_helpers/order.rb
+++ b/lib/spree/core/controller_helpers/order.rb
@@ -59,10 +59,8 @@ module Spree
def associate_user
@order ||= current_order
- if spree_current_user && @order
- if @order.user.blank? || @order.email.blank?
- @order.associate_user!(spree_current_user)
- end
+ if spree_current_user && @order && (@order.user.blank? || @order.email.blank?)
+ @order.associate_user!(spree_current_user)
end
session[:guest_token] = nil
diff --git a/lib/spree/localized_number.rb b/lib/spree/localized_number.rb
index c248fd98a1..c0a2226671 100644
--- a/lib/spree/localized_number.rb
+++ b/lib/spree/localized_number.rb
@@ -44,7 +44,7 @@ module Spree
def self.valid_localizable_number?(number)
return true unless number.is_a?(String) || number.respond_to?(:to_d)
- return false if number =~ /[\.,]\d{2}[\.,]/
+ return false if number =~ /[.,]\d{2}[.,]/
true
end
@@ -57,16 +57,16 @@ module Spree
add_trailing_zeros(number)
- number = number.gsub(/[\.,]/, '') # Replace all (.) and (,) so the string result becomes in "cents"
- number.to_d / 100 # Let to_decimal do the rest
+ number = number.gsub(/[.,]/, '') # Replace all (.) and (,) so the string result becomes in "cents"
+ number.to_d / 100 # Let to_decimal do the rest
end
def self.add_trailing_zeros(number)
# If string ends in a single digit (e.g. ,2), make it ,20 in order for the result to be in "cents"
- number << "0" if number =~ /^.*[\.,]\d{1}$/
+ number << "0" if number =~ /^.*[.,]\d{1}$/
# If does not end in ,00 / .00 then add trailing 00 to turn it into cents
- number << "00" unless number =~ /^.*[\.,]\d{2}$/
+ number << "00" unless number =~ /^.*[.,]\d{2}$/
end
private
diff --git a/lib/stripe/account_connector.rb b/lib/stripe/account_connector.rb
index cb96c0e1d8..f92d452aa0 100644
--- a/lib/stripe/account_connector.rb
+++ b/lib/stripe/account_connector.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
# Encapsulation of logic used to handle the response from Stripe following an
# attempt to connect an account to the instance using the OAuth Connection Flow
# https://stripe.com/docs/connect/standard-accounts#oauth-flow
diff --git a/lib/stripe/authorize_response_patcher.rb b/lib/stripe/authorize_response_patcher.rb
index 3d8195f14a..3dfdddbd2f 100644
--- a/lib/stripe/authorize_response_patcher.rb
+++ b/lib/stripe/authorize_response_patcher.rb
@@ -28,7 +28,7 @@ module Stripe
return unless %w(authorize_with_url redirect_to_url).include?(next_action_type)
url = next_action[next_action_type]["url"]
- return url if url.match(%r{https?:\/\/[\S]+}) && url.include?("stripe.com")
+ return url if url.match(%r{https?://\S+}) && url.include?("stripe.com")
end
# This field is used because the Spree code recognizes and stores it
diff --git a/lib/stripe/credit_card_clone_finder.rb b/lib/stripe/credit_card_clone_finder.rb
index 78321b734b..d8e1b73557 100644
--- a/lib/stripe/credit_card_clone_finder.rb
+++ b/lib/stripe/credit_card_clone_finder.rb
@@ -11,7 +11,8 @@ module Stripe
return nil unless fingerprint = fingerprint_for_card(@card)
return nil unless email = @card.user&.email
- customers = Stripe::Customer.list({ email: email, limit: 100 }, stripe_account: @stripe_account)
+ customers = Stripe::Customer.list({ email: email, limit: 100 },
+ stripe_account: @stripe_account)
customers.auto_paging_each do |customer|
options = { customer: customer.id, type: 'card', limit: 100 }
diff --git a/lib/stripe/profile_storer.rb b/lib/stripe/profile_storer.rb
index f3176fcf9a..688bb4f9e8 100644
--- a/lib/stripe/profile_storer.rb
+++ b/lib/stripe/profile_storer.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
# Encapsulation of logic used to convert a token generated by Stripe Elements
# into a Stripe Customer + Card which can then be charged at a later point in time
# Stores the generated customer & card ids against the local instance of Spree::CreditCard
diff --git a/lib/stripe/webhook_handler.rb b/lib/stripe/webhook_handler.rb
index d7f49b186f..5fdf8da66b 100644
--- a/lib/stripe/webhook_handler.rb
+++ b/lib/stripe/webhook_handler.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
module Stripe
class WebhookHandler
def initialize(event)
diff --git a/lib/tasks/data.rake b/lib/tasks/data.rake
index a8255b96bc..88ba3904cf 100644
--- a/lib/tasks/data.rake
+++ b/lib/tasks/data.rake
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
namespace :ofn do
namespace :data do
desc "Adding relationships based on recent order cycles"
@@ -11,10 +13,12 @@ namespace :ofn do
next if exchange.sender == exchange.receiver
# Ensure that an enterprise relationship from the producer to the coordinator exists
- relationship = EnterpriseRelationship.where(parent_id: exchange.sender_id, child_id: exchange.receiver_id).first
+ relationship = EnterpriseRelationship.where(parent_id: exchange.sender_id,
+ child_id: exchange.receiver_id).first
if relationship.blank?
puts "CREATING: #{exchange.sender.name} TO #{exchange.receiver.name}"
- relationship = EnterpriseRelationship.create!(parent_id: exchange.sender_id, child_id: exchange.receiver_id)
+ relationship = EnterpriseRelationship.create!(parent_id: exchange.sender_id,
+ child_id: exchange.receiver_id)
end
# And that P-OC is granted
unless relationship.has_permission?(:add_to_order_cycle)
@@ -27,10 +31,12 @@ namespace :ofn do
order_cycle.exchanges.outgoing.each do |exchange|
unless exchange.sender == exchange.receiver
# Enure that an enterprise relationship from the hub to the coordinator exists
- relationship = EnterpriseRelationship.where(parent_id: exchange.receiver_id, child_id: exchange.sender_id).first
+ relationship = EnterpriseRelationship.where(parent_id: exchange.receiver_id,
+ child_id: exchange.sender_id).first
if relationship.blank?
puts "CREATING: #{exchange.receiver.name} TO #{exchange.sender.name}"
- relationship = EnterpriseRelationship.create!(parent_id: exchange.receiver_id, child_id: exchange.sender_id)
+ relationship = EnterpriseRelationship.create!(parent_id: exchange.receiver_id,
+ child_id: exchange.sender_id)
end
# And that P-OC is granted
unless relationship.has_permission?(:add_to_order_cycle)
@@ -40,16 +46,21 @@ namespace :ofn do
end
# For each variant in the exchange
- products = Spree::Product.joins(:variants_including_master).where('spree_variants.id IN (?)', exchange.variants).pluck(:id).uniq
- producers = Enterprise.joins(:supplied_products).where("spree_products.id IN (?)", products).distinct
+ products = Spree::Product.joins(:variants_including_master).where(
+ 'spree_variants.id IN (?)', exchange.variants
+ ).pluck(:id).uniq
+ producers = Enterprise.joins(:supplied_products).where("spree_products.id IN (?)",
+ products).distinct
producers.each do |producer|
next if producer == exchange.receiver
# Ensure that an enterprise relationship from the producer to the hub exists
- relationship = EnterpriseRelationship.where(parent_id: producer.id, child_id: exchange.receiver_id).first
+ relationship = EnterpriseRelationship.where(parent_id: producer.id,
+ child_id: exchange.receiver_id).first
if relationship.blank?
puts "CREATING: #{producer.name} TO #{exchange.receiver.name}"
- relationship = EnterpriseRelationship.create!(parent_id: producer.id, child_id: exchange.receiver_id)
+ relationship = EnterpriseRelationship.create!(parent_id: producer.id,
+ child_id: exchange.receiver_id)
end
# And that P-OC is granted
unless relationship.has_permission?(:add_to_order_cycle)
diff --git a/lib/tasks/data/anonymize_data.rake b/lib/tasks/data/anonymize_data.rake
index bdc6e37c1f..21ecc090ce 100644
--- a/lib/tasks/data/anonymize_data.rake
+++ b/lib/tasks/data/anonymize_data.rake
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
require 'highline'
namespace :ofn do
diff --git a/lib/tasks/enterprises.rake b/lib/tasks/enterprises.rake
index 0c1c0f4aa6..c062f0d46d 100644
--- a/lib/tasks/enterprises.rake
+++ b/lib/tasks/enterprises.rake
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
require 'csv'
namespace :ofn do
@@ -28,11 +30,13 @@ namespace :ofn do
end
def enterprise_header
- ['name', 'description', 'long_description', 'is_primary_producer', 'is_distributor', 'contact_name', 'phone', 'email', 'website', 'twitter', 'abn', 'acn', 'pickup_times', 'next_collection_at', 'distributor_info', 'visible', 'facebook', 'instagram', 'linkedin', 'address1', 'address2', 'city', 'zipcode', 'state', 'country']
+ ['name', 'description', 'long_description', 'is_primary_producer', 'is_distributor',
+ 'contact_name', 'phone', 'email', 'website', 'twitter', 'abn', 'acn', 'pickup_times', 'next_collection_at', 'distributor_info', 'visible', 'facebook', 'instagram', 'linkedin', 'address1', 'address2', 'city', 'zipcode', 'state', 'country']
end
def enterprise_row(enterprise)
- [enterprise.name, enterprise.description, enterprise.long_description, enterprise.is_primary_producer, enterprise.is_distributor, enterprise.contact_name, enterprise.phone, enterprise.email, enterprise.website, enterprise.twitter, enterprise.abn, enterprise.acn, enterprise.pickup_times, enterprise.next_collection_at, enterprise.distributor_info, enterprise.visible, enterprise.facebook, enterprise.instagram, enterprise.linkedin, enterprise.address.address1, enterprise.address.address2, enterprise.address.city, enterprise.address.zipcode, enterprise.address.state_name, enterprise.address.country.andand.name]
+ [enterprise.name, enterprise.description, enterprise.long_description,
+ enterprise.is_primary_producer, enterprise.is_distributor, enterprise.contact_name, enterprise.phone, enterprise.email, enterprise.website, enterprise.twitter, enterprise.abn, enterprise.acn, enterprise.pickup_times, enterprise.next_collection_at, enterprise.distributor_info, enterprise.visible, enterprise.facebook, enterprise.instagram, enterprise.linkedin, enterprise.address.address1, enterprise.address.address2, enterprise.address.city, enterprise.address.zipcode, enterprise.address.state_name, enterprise.address.country.andand.name]
end
end
end
diff --git a/lib/tasks/karma.rake b/lib/tasks/karma.rake
index 2755a3f6a8..fe90a8d04f 100644
--- a/lib/tasks/karma.rake
+++ b/lib/tasks/karma.rake
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
ENV["RAILS_ENV"] ||= 'test'
namespace :karma do
diff --git a/lib/tasks/missing_payments.rake b/lib/tasks/missing_payments.rake
index da986d0f08..67a13e12cc 100644
--- a/lib/tasks/missing_payments.rake
+++ b/lib/tasks/missing_payments.rake
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
# Find gaps in the sequence of payment ids.
# If there are gaps then see if there is a log entry with a payment result for
# the now lost payment. If there are some then you probably want to follow up
diff --git a/lib/tasks/sample_data.rake b/lib/tasks/sample_data.rake
index 40cc210f6d..c349831211 100644
--- a/lib/tasks/sample_data.rake
+++ b/lib/tasks/sample_data.rake
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
require "tasks/sample_data/customer_factory"
require "tasks/sample_data/enterprise_factory"
require "tasks/sample_data/fee_factory"
diff --git a/lib/tasks/sample_data/addressing.rb b/lib/tasks/sample_data/addressing.rb
index c7f651837f..96319f98a3 100644
--- a/lib/tasks/sample_data/addressing.rb
+++ b/lib/tasks/sample_data/addressing.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
module Addressing
private
diff --git a/lib/tasks/sample_data/customer_factory.rb b/lib/tasks/sample_data/customer_factory.rb
index 866f98f487..169f4d9fc4 100644
--- a/lib/tasks/sample_data/customer_factory.rb
+++ b/lib/tasks/sample_data/customer_factory.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
require "tasks/sample_data/logging"
module SampleData
diff --git a/lib/tasks/sample_data/enterprise_factory.rb b/lib/tasks/sample_data/enterprise_factory.rb
index 5c884dfc9e..7a2055eed5 100644
--- a/lib/tasks/sample_data/enterprise_factory.rb
+++ b/lib/tasks/sample_data/enterprise_factory.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
require "tasks/sample_data/addressing"
require "tasks/sample_data/logging"
diff --git a/lib/tasks/sample_data/fee_factory.rb b/lib/tasks/sample_data/fee_factory.rb
index c972be971d..5142b84431 100644
--- a/lib/tasks/sample_data/fee_factory.rb
+++ b/lib/tasks/sample_data/fee_factory.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
require "tasks/sample_data/logging"
module SampleData
diff --git a/lib/tasks/sample_data/group_factory.rb b/lib/tasks/sample_data/group_factory.rb
index 8c51a362e9..d3e1047bcf 100644
--- a/lib/tasks/sample_data/group_factory.rb
+++ b/lib/tasks/sample_data/group_factory.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
require "tasks/sample_data/addressing"
require "tasks/sample_data/logging"
diff --git a/lib/tasks/sample_data/inventory_factory.rb b/lib/tasks/sample_data/inventory_factory.rb
index 22d836c1ed..bcd719779a 100644
--- a/lib/tasks/sample_data/inventory_factory.rb
+++ b/lib/tasks/sample_data/inventory_factory.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
require "tasks/sample_data/logging"
module SampleData
diff --git a/lib/tasks/sample_data/logging.rb b/lib/tasks/sample_data/logging.rb
index 4c8ca493b6..ad85624092 100644
--- a/lib/tasks/sample_data/logging.rb
+++ b/lib/tasks/sample_data/logging.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
module Logging
private
diff --git a/lib/tasks/sample_data/order_cycle_factory.rb b/lib/tasks/sample_data/order_cycle_factory.rb
index 8fe9e11def..0f9dc258e8 100644
--- a/lib/tasks/sample_data/order_cycle_factory.rb
+++ b/lib/tasks/sample_data/order_cycle_factory.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
require "tasks/sample_data/logging"
module SampleData
diff --git a/lib/tasks/sample_data/payment_method_factory.rb b/lib/tasks/sample_data/payment_method_factory.rb
index 71d6870720..4febf09fa4 100644
--- a/lib/tasks/sample_data/payment_method_factory.rb
+++ b/lib/tasks/sample_data/payment_method_factory.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
require "tasks/sample_data/addressing"
require "tasks/sample_data/logging"
diff --git a/lib/tasks/sample_data/permission_factory.rb b/lib/tasks/sample_data/permission_factory.rb
index c5129c89c1..c2e1c9fc6a 100644
--- a/lib/tasks/sample_data/permission_factory.rb
+++ b/lib/tasks/sample_data/permission_factory.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
require "tasks/sample_data/logging"
module SampleData
diff --git a/lib/tasks/sample_data/product_factory.rb b/lib/tasks/sample_data/product_factory.rb
index 56869186da..0591617f8b 100644
--- a/lib/tasks/sample_data/product_factory.rb
+++ b/lib/tasks/sample_data/product_factory.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
require "tasks/sample_data/logging"
module SampleData
diff --git a/lib/tasks/sample_data/shipping_method_factory.rb b/lib/tasks/sample_data/shipping_method_factory.rb
index e2688e744f..09bb0a7653 100644
--- a/lib/tasks/sample_data/shipping_method_factory.rb
+++ b/lib/tasks/sample_data/shipping_method_factory.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
require "tasks/sample_data/addressing"
require "tasks/sample_data/logging"
diff --git a/lib/tasks/sample_data/taxon_factory.rb b/lib/tasks/sample_data/taxon_factory.rb
index 5278003022..d9545c24d1 100644
--- a/lib/tasks/sample_data/taxon_factory.rb
+++ b/lib/tasks/sample_data/taxon_factory.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
require "tasks/sample_data/logging"
module SampleData
diff --git a/lib/tasks/sample_data/user_factory.rb b/lib/tasks/sample_data/user_factory.rb
index 4d7d132b48..d7b0648871 100644
--- a/lib/tasks/sample_data/user_factory.rb
+++ b/lib/tasks/sample_data/user_factory.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
require "tasks/sample_data/logging"
module SampleData
diff --git a/lib/tasks/specs.rake b/lib/tasks/specs.rake
index feb9052681..64ef61f0ed 100644
--- a/lib/tasks/specs.rake
+++ b/lib/tasks/specs.rake
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
namespace :ofn do
namespace :specs do
namespace :run do
@@ -21,7 +23,7 @@ namespace :ofn do
end
desc "Run Rspec tests excluding folders"
- task :excluding_folders, [:folders] do |_task, args|
+ task :excluding_folders, [:folders] => :environment do |_task, args|
success = execute_rspec_for_spec_folders(
spec_folders - (args[:folders].split(",") + args.extras)
)
@@ -49,7 +51,7 @@ namespace :ofn do
namespace engine_name do
desc "Run RSpec tests for engine \"#{engine_name}\""
- task :rspec do
+ task rspec: :environment do
success = execute_rspec_for_engine(engine_path)
abort "Failure when running tests for engine \"#{engine_name}\"" unless success
end
@@ -58,7 +60,7 @@ namespace :ofn do
namespace :all do
desc "Run RSpec tests for all engines"
- task :rspec do
+ task rspec: :environment do
success = true
engine_paths.each do |engine_path|
diff --git a/lib/tasks/users.rake b/lib/tasks/users.rake
index 30f76f9449..d1249cb9a0 100644
--- a/lib/tasks/users.rake
+++ b/lib/tasks/users.rake
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
require 'csv'
namespace :ofn do
diff --git a/spec/components/distributor_title_component_spec.rb b/spec/components/distributor_title_component_spec.rb
index 3b206c4b2d..b678027f49 100644
--- a/spec/components/distributor_title_component_spec.rb
+++ b/spec/components/distributor_title_component_spec.rb
@@ -1,8 +1,10 @@
+# frozen_string_literal: true
+
require "spec_helper"
describe "DistributorTitle tests", type: :component do
it "displays distributor title with its name" do
- render_inline(DistributorTitleComponent.new(name: "Freddy's Farm Shop")) { }
+ render_inline(DistributorTitleComponent.new(name: "Freddy's Farm Shop")) {}
expect(page).to have_selector "h3", text: "Freddy's Farm Shop"
- end
+ end
end
diff --git a/spec/components/example_component_spec.rb b/spec/components/example_component_spec.rb
index 0cac3d8ff5..f40eeb5ee8 100644
--- a/spec/components/example_component_spec.rb
+++ b/spec/components/example_component_spec.rb
@@ -1,8 +1,10 @@
+# frozen_string_literal: true
+
require "spec_helper"
describe "ExampleComponent tests", type: :component do
it "displays the h1 with the given parameter" do
- render_inline(ExampleComponent.new(title: "Hello")) { }
+ render_inline(ExampleComponent.new(title: "Hello")) {}
expect(page).to have_selector "h1", text: "Hello"
- end
+ end
end
diff --git a/spec/components/stories/distributor_title_component_stories.rb b/spec/components/stories/distributor_title_component_stories.rb
index 9a292449b5..410288cb56 100644
--- a/spec/components/stories/distributor_title_component_stories.rb
+++ b/spec/components/stories/distributor_title_component_stories.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
class DistributorTitleComponentStories < ViewComponent::Storybook::Stories
story(:default) do
controls do
diff --git a/spec/components/stories/example_component_stories.rb b/spec/components/stories/example_component_stories.rb
index 874b3cf576..46230c86d3 100644
--- a/spec/components/stories/example_component_stories.rb
+++ b/spec/components/stories/example_component_stories.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
class ExampleComponentStories < ViewComponent::Storybook::Stories
story(:with_short_text) do
controls do
diff --git a/spec/controllers/admin/bulk_line_items_controller_spec.rb b/spec/controllers/admin/bulk_line_items_controller_spec.rb
index 6d5fda5ce7..4e31f4f12d 100644
--- a/spec/controllers/admin/bulk_line_items_controller_spec.rb
+++ b/spec/controllers/admin/bulk_line_items_controller_spec.rb
@@ -6,11 +6,23 @@ describe Admin::BulkLineItemsController, type: :controller do
describe '#index' do
render_views
- let(:line_item_attributes) { %i[id quantity max_quantity price supplier final_weight_volume units_product units_variant order] }
+ let(:line_item_attributes) {
+ %i[id quantity max_quantity price supplier final_weight_volume units_product units_variant
+ order]
+ }
let!(:dist1) { FactoryBot.create(:distributor_enterprise) }
- let!(:order1) { FactoryBot.create(:order, state: 'complete', completed_at: 1.day.ago, distributor: dist1, billing_address: FactoryBot.create(:address) ) }
- let!(:order2) { FactoryBot.create(:order, state: 'complete', completed_at: Time.zone.now, distributor: dist1, billing_address: FactoryBot.create(:address) ) }
- let!(:order3) { FactoryBot.create(:order, state: 'complete', completed_at: Time.zone.now, distributor: dist1, billing_address: FactoryBot.create(:address) ) }
+ let!(:order1) {
+ FactoryBot.create(:order, state: 'complete', completed_at: 1.day.ago, distributor: dist1,
+ billing_address: FactoryBot.create(:address) )
+ }
+ let!(:order2) {
+ FactoryBot.create(:order, state: 'complete', completed_at: Time.zone.now, distributor: dist1,
+ billing_address: FactoryBot.create(:address) )
+ }
+ let!(:order3) {
+ FactoryBot.create(:order, state: 'complete', completed_at: Time.zone.now, distributor: dist1,
+ billing_address: FactoryBot.create(:address) )
+ }
let!(:line_item1) { FactoryBot.create(:line_item_with_shipment, order: order1) }
let!(:line_item2) { FactoryBot.create(:line_item_with_shipment, order: order2) }
let!(:line_item3) { FactoryBot.create(:line_item_with_shipment, order: order2) }
@@ -46,11 +58,15 @@ describe Admin::BulkLineItemsController, type: :controller do
end
it "formats final_weight_volume as a float" do
- expect(json_response['line_items'].map{ |line_item| line_item['final_weight_volume'] }.all?{ |fwv| fwv.is_a?(Float) }).to eq(true)
+ expect(json_response['line_items'].map{ |line_item|
+ line_item['final_weight_volume']
+ }.all?{ |fwv| fwv.is_a?(Float) }).to eq(true)
end
it "returns distributor object with id key" do
- expect(json_response['line_items'].map{ |line_item| line_item['supplier'] }.all?{ |d| d.key?('id') }).to eq(true)
+ expect(json_response['line_items'].map{ |line_item|
+ line_item['supplier']
+ }.all?{ |d| d.key?('id') }).to eq(true)
end
end
@@ -81,11 +97,26 @@ describe Admin::BulkLineItemsController, type: :controller do
let(:distributor2) { create(:distributor_enterprise) }
let(:coordinator) { create(:distributor_enterprise) }
let(:order_cycle) { create(:simple_order_cycle, coordinator: coordinator) }
- let!(:order1) { FactoryBot.create(:order, order_cycle: order_cycle, state: 'complete', completed_at: Time.zone.now, distributor: distributor1, billing_address: FactoryBot.create(:address) ) }
- let!(:line_item1) { FactoryBot.create(:line_item_with_shipment, order: order1, product: FactoryBot.create(:product, supplier: supplier)) }
- let!(:line_item2) { FactoryBot.create(:line_item_with_shipment, order: order1, product: FactoryBot.create(:product, supplier: supplier)) }
- let!(:order2) { FactoryBot.create(:order, order_cycle: order_cycle, state: 'complete', completed_at: Time.zone.now, distributor: distributor2, billing_address: FactoryBot.create(:address) ) }
- let!(:line_item3) { FactoryBot.create(:line_item_with_shipment, order: order2, product: FactoryBot.create(:product, supplier: supplier)) }
+ let!(:order1) {
+ FactoryBot.create(:order, order_cycle: order_cycle, state: 'complete',
+ completed_at: Time.zone.now, distributor: distributor1, billing_address: FactoryBot.create(:address) )
+ }
+ let!(:line_item1) {
+ FactoryBot.create(:line_item_with_shipment, order: order1,
+ product: FactoryBot.create(:product, supplier: supplier))
+ }
+ let!(:line_item2) {
+ FactoryBot.create(:line_item_with_shipment, order: order1,
+ product: FactoryBot.create(:product, supplier: supplier))
+ }
+ let!(:order2) {
+ FactoryBot.create(:order, order_cycle: order_cycle, state: 'complete',
+ completed_at: Time.zone.now, distributor: distributor2, billing_address: FactoryBot.create(:address) )
+ }
+ let!(:line_item3) {
+ FactoryBot.create(:line_item_with_shipment, order: order2,
+ product: FactoryBot.create(:product, supplier: supplier))
+ }
context "producer enterprise" do
before do
@@ -155,9 +186,13 @@ describe Admin::BulkLineItemsController, type: :controller do
let(:distributor1) { create(:distributor_enterprise) }
let(:coordinator) { create(:distributor_enterprise) }
let(:order_cycle) { create(:simple_order_cycle, coordinator: coordinator) }
- let!(:order1) { FactoryBot.create(:order, order_cycle: order_cycle, state: 'complete', completed_at: Time.zone.now, distributor: distributor1, billing_address: FactoryBot.create(:address) ) }
+ let!(:order1) {
+ FactoryBot.create(:order, order_cycle: order_cycle, state: 'complete',
+ completed_at: Time.zone.now, distributor: distributor1, billing_address: FactoryBot.create(:address) )
+ }
let!(:line_item1) {
- line_item1 = FactoryBot.create(:line_item_with_shipment, order: order1, product: FactoryBot.create(:product, supplier: supplier))
+ line_item1 = FactoryBot.create(:line_item_with_shipment, order: order1,
+ product: FactoryBot.create(:product, supplier: supplier))
# make sure shipment is available through db reloads of this line_item
line_item1.tap(&:save!)
}
@@ -257,8 +292,14 @@ describe Admin::BulkLineItemsController, type: :controller do
let(:distributor1) { create(:distributor_enterprise) }
let(:coordinator) { create(:distributor_enterprise) }
let(:order_cycle) { create(:simple_order_cycle, coordinator: coordinator) }
- let!(:order1) { FactoryBot.create(:order, order_cycle: order_cycle, state: 'complete', completed_at: Time.zone.now, distributor: distributor1, billing_address: FactoryBot.create(:address) ) }
- let!(:line_item1) { FactoryBot.create(:line_item_with_shipment, order: order1, product: FactoryBot.create(:product, supplier: supplier)) }
+ let!(:order1) {
+ FactoryBot.create(:order, order_cycle: order_cycle, state: 'complete',
+ completed_at: Time.zone.now, distributor: distributor1, billing_address: FactoryBot.create(:address) )
+ }
+ let!(:line_item1) {
+ FactoryBot.create(:line_item_with_shipment, order: order1,
+ product: FactoryBot.create(:product, supplier: supplier))
+ }
let(:params) { { id: line_item1.id, order_id: order1.number } }
before do
@@ -296,7 +337,8 @@ describe Admin::BulkLineItemsController, type: :controller do
let(:outgoing_exchange) { order_cycle.exchanges.outgoing.first }
let!(:order) {
- create(:order_with_line_items, line_items_count: 2, distributor: distributor, order_cycle: order_cycle)
+ create(:order_with_line_items, line_items_count: 2, distributor: distributor,
+ order_cycle: order_cycle)
}
let(:line_item1) { order.line_items.first }
let(:line_item2) { order.line_items.last }
@@ -304,20 +346,25 @@ describe Admin::BulkLineItemsController, type: :controller do
let!(:zone) { create(:zone_with_member) }
let(:tax_included) { true }
let(:tax_rate5) { create(:tax_rate, amount: 0.05, zone: zone, included_in_price: tax_included) }
- let(:tax_rate10) { create(:tax_rate, amount: 0.10, zone: zone, included_in_price: tax_included) }
- let(:tax_rate15) { create(:tax_rate, amount: 0.15, zone: zone, included_in_price: tax_included) }
+ let(:tax_rate10) {
+ create(:tax_rate, amount: 0.10, zone: zone, included_in_price: tax_included)
+ }
+ let(:tax_rate15) {
+ create(:tax_rate, amount: 0.15, zone: zone, included_in_price: tax_included)
+ }
let(:tax_cat5) { create(:tax_category, tax_rates: [tax_rate5]) }
let(:tax_cat10) { create(:tax_category, tax_rates: [tax_rate10]) }
let(:tax_cat15) { create(:tax_category, tax_rates: [tax_rate15]) }
let!(:shipping_method) {
create(:shipping_method_with, :shipping_fee, tax_category: tax_cat5, name: "Shiperoo",
- distributors: [distributor])
+ distributors: [distributor])
}
let!(:payment_method) { create(:payment_method, :per_item, distributors: [distributor]) }
let(:line_item_fee1) {
- create(:enterprise_fee, :per_item, amount: 1, inherits_tax_category: false, tax_category: tax_cat15)
+ create(:enterprise_fee, :per_item, amount: 1, inherits_tax_category: false,
+ tax_category: tax_cat15)
}
let(:line_item_fee2) {
create(:enterprise_fee, :per_item, amount: 2, inherits_tax_category: true)
@@ -336,7 +383,8 @@ describe Admin::BulkLineItemsController, type: :controller do
order.recreate_all_fees!
order.create_tax_charge!
order.update_order!
- order.payments << create(:payment, payment_method: payment_method, amount: order.total, state: "completed")
+ order.payments << create(:payment, payment_method: payment_method, amount: order.total,
+ state: "completed")
allow(controller).to receive(:spree_current_user) { distributor.owner }
allow(Spree::LineItem).to receive(:find) { line_item1 }
diff --git a/spec/controllers/admin/column_preferences_controller_spec.rb b/spec/controllers/admin/column_preferences_controller_spec.rb
index 74ee067825..ff1250898a 100644
--- a/spec/controllers/admin/column_preferences_controller_spec.rb
+++ b/spec/controllers/admin/column_preferences_controller_spec.rb
@@ -11,13 +11,19 @@ describe Admin::ColumnPreferencesController, type: :controller do
let!(:enterprise) { create(:enterprise, owner: user1, users: [user1, user2]) }
context "json" do
- let!(:column_preference) { ColumnPreference.create(user_id: user1.id, action_name: 'enterprises_index', column_name: "name", visible: true) }
+ let!(:column_preference) {
+ ColumnPreference.create(user_id: user1.id, action_name: 'enterprises_index', column_name: "name",
+ visible: true)
+ }
let(:column_preference_params) {
[
- { 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 }
+ { 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 }
]
}
@@ -27,7 +33,8 @@ describe Admin::ColumnPreferencesController, type: :controller do
end
it "prevents me from updating the column preferences" do
- spree_put :bulk_update, format: :json, action_name: "enterprises_index", column_preferences: column_preference_params
+ spree_put :bulk_update, format: :json, action_name: "enterprises_index",
+ column_preferences: column_preference_params
expect(ColumnPreference.count).to be 1
end
end
@@ -38,8 +45,10 @@ describe Admin::ColumnPreferencesController, type: :controller do
end
it "allows me to update the column preferences" do
- spree_put :bulk_update, format: :json, action_name: "enterprises_index", column_preferences: column_preference_params
- expect(ColumnPreference.where(user_id: user1.id, action_name: 'enterprises_index').count).to be 3
+ spree_put :bulk_update, format: :json, action_name: "enterprises_index",
+ column_preferences: column_preference_params
+ expect(ColumnPreference.where(user_id: user1.id,
+ action_name: 'enterprises_index').count).to be 3
end
end
end
diff --git a/spec/controllers/admin/customers_controller_spec.rb b/spec/controllers/admin/customers_controller_spec.rb
index b8271ff27c..9630772d86 100644
--- a/spec/controllers/admin/customers_controller_spec.rb
+++ b/spec/controllers/admin/customers_controller_spec.rb
@@ -43,7 +43,7 @@ module Admin
end
it 'calls CustomersWithBalance' do
- customers_with_balance = instance_double(CustomersWithBalance)
+ customers_with_balance = instance_double(CustomersWithBalance)
allow(CustomersWithBalance)
.to receive(:new).with(enterprise) { customers_with_balance }
@@ -162,7 +162,8 @@ module Admin
end
it "allows me to update the customer" do
- spree_put :update, format: :json, id: customer.id, customer: { email: 'new.email@gmail.com' }
+ spree_put :update, format: :json, id: customer.id,
+ customer: { email: 'new.email@gmail.com' }
expect(JSON.parse(response.body)["id"]).to eq customer.id
expect(assigns(:customer)).to eq customer
expect(customer.reload.email).to eq 'new.email@gmail.com'
@@ -175,7 +176,8 @@ module Admin
end
it "prevents me from updating the customer" do
- spree_put :update, format: :json, id: customer.id, customer: { email: 'new.email@gmail.com' }
+ spree_put :update, format: :json, id: customer.id,
+ customer: { email: 'new.email@gmail.com' }
expect(response).to redirect_to unauthorized_path
expect(assigns(:customer)).to eq nil
expect(customer.email).to_not eq 'new.email@gmail.com'
@@ -189,7 +191,8 @@ module Admin
let(:another_enterprise) { create(:distributor_enterprise) }
def create_customer(enterprise)
- spree_put :create, format: :json, customer: { email: 'new@example.com', enterprise_id: enterprise.id }
+ spree_put :create, format: :json,
+ customer: { email: 'new@example.com', enterprise_id: enterprise.id }
end
context "json" do
diff --git a/spec/controllers/admin/enterprises_controller_spec.rb b/spec/controllers/admin/enterprises_controller_spec.rb
index 381080cf6c..d8b2e4f781 100644
--- a/spec/controllers/admin/enterprises_controller_spec.rb
+++ b/spec/controllers/admin/enterprises_controller_spec.rb
@@ -15,12 +15,17 @@ describe Admin::EnterprisesController, type: :controller do
let(:supplier) { create(:supplier_enterprise, owner: supplier_owner) }
let(:country) { Spree::Country.find_by name: 'Australia' }
let(:state) { Spree::State.find_by name: 'Victoria' }
- let(:address_params) { { address1: 'a', city: 'a', zipcode: 'a', country_id: country.id, state_id: state.id } }
+ let(:address_params) {
+ { address1: 'a', city: 'a', zipcode: 'a', country_id: country.id, state_id: state.id }
+ }
before { @request.env['HTTP_REFERER'] = 'http://test.com/' }
describe "creating an enterprise" do
- let(:enterprise_params) { { enterprise: { name: 'zzz', permalink: 'zzz', is_primary_producer: '0', address_attributes: address_params } } }
+ let(:enterprise_params) {
+ { enterprise: { name: 'zzz', permalink: 'zzz', is_primary_producer: '0',
+ address_attributes: address_params } }
+ }
it "grants management permission if the current user is an enterprise user" do
allow(controller).to receive_messages spree_current_user: distributor_manager
@@ -148,7 +153,9 @@ describe Admin::EnterprisesController, type: :controller do
it "does not allow managers to be changed" do
allow(controller).to receive_messages spree_current_user: distributor_manager
- update_params = { id: distributor, enterprise: { user_ids: [distributor_owner.id, distributor_manager.id, user.id] } }
+ update_params = { id: distributor,
+ enterprise: { user_ids: [distributor_owner.id, distributor_manager.id,
+ user.id] } }
spree_post :update, update_params
distributor.reload
@@ -157,7 +164,8 @@ describe Admin::EnterprisesController, type: :controller do
it "updates enterprise preferences" do
allow(controller).to receive_messages spree_current_user: distributor_manager
- update_params = { id: distributor, enterprise: { preferred_show_customer_names_to_suppliers: "1" } }
+ update_params = { id: distributor,
+ enterprise: { preferred_show_customer_names_to_suppliers: "1" } }
spree_post :update, update_params
distributor.reload
@@ -271,7 +279,9 @@ describe Admin::EnterprisesController, type: :controller do
it "allows managers to be changed" do
allow(controller).to receive_messages spree_current_user: distributor_owner
- update_params = { id: distributor, enterprise: { user_ids: [distributor_owner.id, distributor_manager.id, user.id] } }
+ update_params = { id: distributor,
+ enterprise: { user_ids: [distributor_owner.id, distributor_manager.id,
+ user.id] } }
spree_post :update, update_params
distributor.reload
@@ -300,7 +310,9 @@ describe Admin::EnterprisesController, type: :controller do
it "allows managers to be changed" do
allow(controller).to receive_messages spree_current_user: admin_user
- update_params = { id: distributor, enterprise: { user_ids: [distributor_owner.id, distributor_manager.id, user.id] } }
+ update_params = { id: distributor,
+ enterprise: { user_ids: [distributor_owner.id, distributor_manager.id,
+ user.id] } }
spree_post :update, update_params
distributor.reload
@@ -421,7 +433,10 @@ describe Admin::EnterprisesController, type: :controller do
profile_enterprise1.enterprise_roles.build(user: new_owner).save
profile_enterprise2.enterprise_roles.build(user: new_owner).save
allow(controller).to receive_messages spree_current_user: new_owner
- bulk_enterprise_params = { sets_enterprise_set: { collection_attributes: { '0' => { id: profile_enterprise1.id, sells: 'any', owner_id: new_owner.id }, '1' => { id: profile_enterprise2.id, sells: 'any', owner_id: new_owner.id } } } }
+ bulk_enterprise_params = { sets_enterprise_set: { collection_attributes: {
+ '0' => { id: profile_enterprise1.id, sells: 'any',
+ owner_id: new_owner.id }, '1' => { id: profile_enterprise2.id, sells: 'any', owner_id: new_owner.id }
+ } } }
spree_put :bulk_update, bulk_enterprise_params
profile_enterprise1.reload
@@ -436,7 +451,9 @@ describe Admin::EnterprisesController, type: :controller do
allow_any_instance_of(Sets::EnterpriseSet).to receive(:save) { false }
profile_enterprise1.enterprise_roles.build(user: new_owner).save
allow(controller).to receive_messages spree_current_user: new_owner
- bulk_enterprise_params = { sets_enterprise_set: { collection_attributes: { '0' => { id: profile_enterprise1.id, visible: 'false' } } } }
+ bulk_enterprise_params = { sets_enterprise_set: { collection_attributes: { '0' => {
+ id: profile_enterprise1.id, visible: 'false'
+ } } } }
spree_put :bulk_update, bulk_enterprise_params
expect(assigns(:enterprise_set).collection).to eq [profile_enterprise1]
end
@@ -445,7 +462,10 @@ describe Admin::EnterprisesController, type: :controller do
context "as the owner of an enterprise" do
it "allows 'sells' and 'owner' to be changed" do
allow(controller).to receive_messages spree_current_user: original_owner
- bulk_enterprise_params = { sets_enterprise_set: { collection_attributes: { '0' => { id: profile_enterprise1.id, sells: 'any', owner_id: new_owner.id }, '1' => { id: profile_enterprise2.id, sells: 'any', owner_id: new_owner.id } } } }
+ bulk_enterprise_params = { sets_enterprise_set: { collection_attributes: {
+ '0' => { id: profile_enterprise1.id, sells: 'any',
+ owner_id: new_owner.id }, '1' => { id: profile_enterprise2.id, sells: 'any', owner_id: new_owner.id }
+ } } }
spree_put :bulk_update, bulk_enterprise_params
profile_enterprise1.reload
@@ -462,7 +482,10 @@ describe Admin::EnterprisesController, type: :controller do
profile_enterprise1.enterprise_roles.build(user: new_owner).save
profile_enterprise2.enterprise_roles.build(user: new_owner).save
allow(controller).to receive_messages spree_current_user: admin_user
- bulk_enterprise_params = { sets_enterprise_set: { collection_attributes: { '0' => { id: profile_enterprise1.id, sells: 'any', owner_id: new_owner.id }, '1' => { id: profile_enterprise2.id, sells: 'any', owner_id: new_owner.id } } } }
+ bulk_enterprise_params = { sets_enterprise_set: { collection_attributes: {
+ '0' => { id: profile_enterprise1.id, sells: 'any',
+ owner_id: new_owner.id }, '1' => { id: profile_enterprise2.id, sells: 'any', owner_id: new_owner.id }
+ } } }
spree_put :bulk_update, bulk_enterprise_params
profile_enterprise1.reload
@@ -502,21 +525,24 @@ describe Admin::EnterprisesController, type: :controller do
context "when an order_cycle_id is provided in params" do
before { get :for_order_cycle, as: :json, params: { order_cycle_id: 1 } }
it "initializes permissions with the existing OrderCycle" do
- expect(OpenFoodNetwork::OrderCyclePermissions).to have_received(:new).with(user, "existing OrderCycle")
+ expect(OpenFoodNetwork::OrderCyclePermissions).to have_received(:new).with(user,
+ "existing OrderCycle")
end
end
context "when a coordinator is provided in params" do
before { get :for_order_cycle, as: :json, params: { coordinator_id: 1 } }
it "initializes permissions with a new OrderCycle" do
- expect(OpenFoodNetwork::OrderCyclePermissions).to have_received(:new).with(user, "new OrderCycle")
+ expect(OpenFoodNetwork::OrderCyclePermissions).to have_received(:new).with(user,
+ "new OrderCycle")
end
end
context "when both an order cycle and a coordinator are provided in params" do
before { get :for_order_cycle, as: :json, params: { order_cycle_id: 1, coordinator_id: 1 } }
it "initializes permissions with the existing OrderCycle" do
- expect(OpenFoodNetwork::OrderCyclePermissions).to have_received(:new).with(user, "existing OrderCycle")
+ expect(OpenFoodNetwork::OrderCyclePermissions).to have_received(:new).with(user,
+ "existing OrderCycle")
end
end
end
@@ -531,11 +557,13 @@ describe Admin::EnterprisesController, type: :controller do
allow(controller).to receive_messages spree_current_user: user
# :create_variant_overrides does not affect visiblity (at time of writing)
- create(:enterprise_relationship, parent: not_visible_enterprise, child: visible_enterprise, permissions_list: [:create_variant_overrides])
+ create(:enterprise_relationship, parent: not_visible_enterprise, child: visible_enterprise,
+ permissions_list: [:create_variant_overrides])
end
it "uses permissions to determine which enterprises are visible and should be rendered" do
- expect(controller).to receive(:render_as_json).with([visible_enterprise], ams_prefix: 'basic', spree_current_user: user).and_call_original
+ expect(controller).to receive(:render_as_json).with([visible_enterprise],
+ ams_prefix: 'basic', spree_current_user: user).and_call_original
get :visible, format: :json
end
end
diff --git a/spec/controllers/admin/inventory_items_controller_spec.rb b/spec/controllers/admin/inventory_items_controller_spec.rb
index 6f4f873102..57aeee0b0a 100644
--- a/spec/controllers/admin/inventory_items_controller_spec.rb
+++ b/spec/controllers/admin/inventory_items_controller_spec.rb
@@ -9,8 +9,13 @@ describe Admin::InventoryItemsController, type: :controller do
let(:enterprise) { create(:distributor_enterprise) }
let(:variant) { create(:variant) }
- let(:inventory_item) { create(:inventory_item, enterprise: enterprise, variant: variant, visible: true) }
- let(:params) { { format: format, inventory_item: { enterprise_id: enterprise.id, variant_id: variant.id, visible: false } } }
+ let(:inventory_item) {
+ create(:inventory_item, enterprise: enterprise, variant: variant, visible: true)
+ }
+ let(:params) {
+ { format: format,
+ inventory_item: { enterprise_id: enterprise.id, variant_id: variant.id, visible: false } }
+ }
context "where I don't manage the inventory item enterprise" do
before do
@@ -39,7 +44,8 @@ describe Admin::InventoryItemsController, type: :controller do
context "and the producer has granted VO permission" do
before do
- create(:enterprise_relationship, parent: variant.product.supplier, child: enterprise, permissions_list: [:create_variant_overrides])
+ create(:enterprise_relationship, parent: variant.product.supplier, child: enterprise,
+ permissions_list: [:create_variant_overrides])
end
context "with acceptable data" do
@@ -54,7 +60,11 @@ describe Admin::InventoryItemsController, type: :controller do
context "with unacceptable data" do
render_views
- let!(:bad_params) { { format: format, inventory_item: { enterprise_id: enterprise.id, variant_id: variant.id, visible: nil } } }
+ let!(:bad_params) {
+ { format: format,
+ inventory_item: { enterprise_id: enterprise.id, variant_id: variant.id,
+ visible: nil } }
+ }
it "returns an error message" do
expect{ spree_post :create, bad_params }.to change{ InventoryItem.count }.by(0)
@@ -72,7 +82,9 @@ describe Admin::InventoryItemsController, type: :controller do
let(:enterprise) { create(:distributor_enterprise) }
let(:variant) { create(:variant) }
- let(:inventory_item) { create(:inventory_item, enterprise: enterprise, variant: variant, visible: true) }
+ let(:inventory_item) {
+ create(:inventory_item, enterprise: enterprise, variant: variant, visible: true)
+ }
let(:params) { { format: format, id: inventory_item.id, inventory_item: { visible: false } } }
context "where I don't manage the inventory item enterprise" do
@@ -102,7 +114,8 @@ describe Admin::InventoryItemsController, type: :controller do
context "and the producer has granted VO permission" do
before do
- create(:enterprise_relationship, parent: variant.product.supplier, child: enterprise, permissions_list: [:create_variant_overrides])
+ create(:enterprise_relationship, parent: variant.product.supplier, child: enterprise,
+ permissions_list: [:create_variant_overrides])
end
context "with acceptable data" do
@@ -115,7 +128,9 @@ describe Admin::InventoryItemsController, type: :controller do
context "with unacceptable data" do
render_views
- let!(:bad_params) { { format: format, id: inventory_item.id, inventory_item: { visible: nil } } }
+ let!(:bad_params) {
+ { format: format, id: inventory_item.id, inventory_item: { visible: nil } }
+ }
it "returns an error message" do
expect{ spree_put :update, bad_params }.to change{ InventoryItem.count }.by(0)
diff --git a/spec/controllers/admin/order_cycles_controller_spec.rb b/spec/controllers/admin/order_cycles_controller_spec.rb
index ab6450e42e..0f01ab7fce 100644
--- a/spec/controllers/admin/order_cycles_controller_spec.rb
+++ b/spec/controllers/admin/order_cycles_controller_spec.rb
@@ -13,10 +13,18 @@ module Admin
describe "#index" do
describe "when the user manages a coordinator" do
let!(:coordinator) { create(:distributor_enterprise, owner: distributor_owner) }
- let!(:oc1) { create(:simple_order_cycle, orders_open_at: 70.days.ago, orders_close_at: 60.days.ago ) }
- let!(:oc2) { create(:simple_order_cycle, orders_open_at: 70.days.ago, orders_close_at: 40.days.ago ) }
- let!(:oc3) { create(:simple_order_cycle, orders_open_at: 70.days.ago, orders_close_at: 20.days.ago ) }
- let!(:oc4) { create(:simple_order_cycle, orders_open_at: 70.days.ago, orders_close_at: nil ) }
+ let!(:oc1) {
+ create(:simple_order_cycle, orders_open_at: 70.days.ago, orders_close_at: 60.days.ago )
+ }
+ let!(:oc2) {
+ create(:simple_order_cycle, orders_open_at: 70.days.ago, orders_close_at: 40.days.ago )
+ }
+ let!(:oc3) {
+ create(:simple_order_cycle, orders_open_at: 70.days.ago, orders_close_at: 20.days.ago )
+ }
+ let!(:oc4) {
+ create(:simple_order_cycle, orders_open_at: 70.days.ago, orders_close_at: nil )
+ }
context "html" do
it "doesn't load any data" do
@@ -203,11 +211,19 @@ module Admin
let(:coordinator) { order_cycle.coordinator }
let(:hub) { create(:distributor_enterprise) }
let(:v) { create(:variant) }
- let!(:incoming_exchange) { create(:exchange, order_cycle: order_cycle, sender: producer, receiver: coordinator, incoming: true, variants: [v]) }
- let!(:outgoing_exchange) { create(:exchange, order_cycle: order_cycle, sender: coordinator, receiver: hub, incoming: false, variants: [v]) }
+ let!(:incoming_exchange) {
+ create(:exchange, order_cycle: order_cycle, sender: producer, receiver: coordinator,
+ incoming: true, variants: [v])
+ }
+ let!(:outgoing_exchange) {
+ create(:exchange, order_cycle: order_cycle, sender: coordinator, receiver: hub, incoming: false,
+ variants: [v])
+ }
let(:allowed) { { incoming_exchanges: [], outgoing_exchanges: [] } }
- let(:restricted) { { name: 'some name', orders_open_at: 1.day.from_now.to_s, orders_close_at: 1.day.ago.to_s } }
+ let(:restricted) {
+ { name: 'some name', orders_open_at: 1.day.from_now.to_s, orders_close_at: 1.day.ago.to_s }
+ }
let(:params) { { format: :json, id: order_cycle.id, order_cycle: allowed.merge(restricted) } }
let(:form_mock) { instance_double(OrderCycleForm, save: true) }
diff --git a/spec/controllers/admin/proxy_orders_controller_spec.rb b/spec/controllers/admin/proxy_orders_controller_spec.rb
index bd4145015e..1511789ce2 100644
--- a/spec/controllers/admin/proxy_orders_controller_spec.rb
+++ b/spec/controllers/admin/proxy_orders_controller_spec.rb
@@ -10,7 +10,9 @@ describe Admin::ProxyOrdersController, type: :controller do
let!(:shop) { create(:distributor_enterprise) }
let!(:order_cycle) { create(:simple_order_cycle, orders_close_at: 1.day.from_now) }
let!(:subscription) { create(:subscription, shop: shop, with_items: true) }
- let!(:proxy_order) { create(:proxy_order, subscription: subscription, order_cycle: order_cycle) }
+ let!(:proxy_order) {
+ create(:proxy_order, subscription: subscription, order_cycle: order_cycle)
+ }
before do
allow(controller).to receive(:spree_current_user) { user }
@@ -73,7 +75,9 @@ describe Admin::ProxyOrdersController, type: :controller do
let!(:subscription) do
create(:subscription, shipping_method: shipping_method, shop: shop, with_items: true)
end
- let!(:proxy_order) { create(:proxy_order, subscription: subscription, order_cycle: order_cycle) }
+ let!(:proxy_order) {
+ create(:proxy_order, subscription: subscription, order_cycle: order_cycle)
+ }
let(:order) { proxy_order.initialise_order! }
before do
diff --git a/spec/controllers/admin/schedules_controller_spec.rb b/spec/controllers/admin/schedules_controller_spec.rb
index 544d31050d..e6536cf0ea 100644
--- a/spec/controllers/admin/schedules_controller_spec.rb
+++ b/spec/controllers/admin/schedules_controller_spec.rb
@@ -31,9 +31,15 @@ describe Admin::SchedulesController, type: :controller do
end
context "and there is a schedule of an OC coordinated by _another_ enterprise I manage and the first enterprise is given" do
- let!(:other_managed_coordinator) { create(:distributor_enterprise, owner: managed_coordinator.owner) }
- let!(:other_coordinated_order_cycle) { create(:simple_order_cycle, coordinator: other_managed_coordinator) }
- let!(:other_coordinated_schedule) { create(:schedule, order_cycles: [other_coordinated_order_cycle] ) }
+ let!(:other_managed_coordinator) {
+ create(:distributor_enterprise, owner: managed_coordinator.owner)
+ }
+ let!(:other_coordinated_order_cycle) {
+ create(:simple_order_cycle, coordinator: other_managed_coordinator)
+ }
+ let!(:other_coordinated_schedule) {
+ create(:schedule, order_cycles: [other_coordinated_order_cycle] )
+ }
let(:params) { { format: :json, enterprise_id: managed_coordinator.id } }
it "scopes @collection to schedules containing order_cycles coordinated by the first enterprise" do
@@ -56,12 +62,26 @@ describe Admin::SchedulesController, type: :controller do
let(:user) { create(:user, enterprise_limit: 10) }
let!(:managed_coordinator) { create(:enterprise, owner: user) }
let!(:managed_enterprise) { create(:enterprise, owner: user) }
- let!(:coordinated_order_cycle) { create(:simple_order_cycle, coordinator: managed_coordinator ) }
- let!(:coordinated_order_cycle2) { create(:simple_order_cycle, coordinator: managed_enterprise ) }
- let!(:uncoordinated_order_cycle) { create(:simple_order_cycle, coordinator: create(:enterprise) ) }
- let!(:uncoordinated_order_cycle2) { create(:simple_order_cycle, coordinator: create(:enterprise)) }
- let!(:uncoordinated_order_cycle3) { create(:simple_order_cycle, coordinator: create(:enterprise)) }
- let!(:coordinated_schedule) { create(:schedule, order_cycles: [coordinated_order_cycle, uncoordinated_order_cycle, uncoordinated_order_cycle3] ) }
+ let!(:coordinated_order_cycle) {
+ create(:simple_order_cycle, coordinator: managed_coordinator )
+ }
+ let!(:coordinated_order_cycle2) {
+ create(:simple_order_cycle, coordinator: managed_enterprise )
+ }
+ let!(:uncoordinated_order_cycle) {
+ create(:simple_order_cycle, coordinator: create(:enterprise) )
+ }
+ let!(:uncoordinated_order_cycle2) {
+ create(:simple_order_cycle, coordinator: create(:enterprise))
+ }
+ let!(:uncoordinated_order_cycle3) {
+ create(:simple_order_cycle, coordinator: create(:enterprise))
+ }
+ let!(:coordinated_schedule) {
+ create(:schedule,
+ order_cycles: [coordinated_order_cycle, uncoordinated_order_cycle,
+ uncoordinated_order_cycle3] )
+ }
let!(:uncoordinated_schedule) { create(:schedule, order_cycles: [uncoordinated_order_cycle] ) }
context "json" do
@@ -73,7 +93,8 @@ describe Admin::SchedulesController, type: :controller do
end
it "allows me to update basic information" do
- spree_put :update, format: :json, id: coordinated_schedule.id, schedule: { name: "my awesome schedule" }
+ spree_put :update, format: :json, id: coordinated_schedule.id,
+ schedule: { name: "my awesome schedule" }
expect(JSON.parse(response.body)["id"]).to eq coordinated_schedule.id
expect(JSON.parse(response.body)["name"]).to eq "my awesome schedule"
expect(assigns(:schedule)).to eq coordinated_schedule
@@ -81,13 +102,17 @@ describe Admin::SchedulesController, type: :controller do
end
it "allows me to add/remove only order cycles I coordinate to/from the schedule" do
- order_cycle_ids = [coordinated_order_cycle2.id, uncoordinated_order_cycle2.id, uncoordinated_order_cycle3.id]
- spree_put :update, format: :json, id: coordinated_schedule.id, order_cycle_ids: order_cycle_ids
+ order_cycle_ids = [coordinated_order_cycle2.id, uncoordinated_order_cycle2.id,
+ uncoordinated_order_cycle3.id]
+ spree_put :update, format: :json, id: coordinated_schedule.id,
+ order_cycle_ids: order_cycle_ids
expect(assigns(:schedule)).to eq coordinated_schedule
# coordinated_order_cycle2 is added, uncoordinated_order_cycle is NOT removed
- expect(coordinated_schedule.reload.order_cycles).to include coordinated_order_cycle2, uncoordinated_order_cycle, uncoordinated_order_cycle3
+ expect(coordinated_schedule.reload.order_cycles).to include coordinated_order_cycle2,
+ uncoordinated_order_cycle, uncoordinated_order_cycle3
# coordinated_order_cycle is removed, uncoordinated_order_cycle2 is NOT added
- expect(coordinated_schedule.reload.order_cycles).to_not include coordinated_order_cycle, uncoordinated_order_cycle2
+ expect(coordinated_schedule.reload.order_cycles).to_not include coordinated_order_cycle,
+ uncoordinated_order_cycle2
end
it "syncs proxy orders when order_cycle_ids change" do
@@ -95,11 +120,14 @@ describe Admin::SchedulesController, type: :controller do
allow(OrderManagement::Subscriptions::ProxyOrderSyncer).to receive(:new) { syncer_mock }
expect(syncer_mock).to receive(:sync!).exactly(2).times
- spree_put :update, format: :json, id: coordinated_schedule.id, order_cycle_ids: [coordinated_order_cycle.id, coordinated_order_cycle2.id]
+ spree_put :update, format: :json, id: coordinated_schedule.id,
+ order_cycle_ids: [coordinated_order_cycle.id, coordinated_order_cycle2.id]
reset_controller_environment
- spree_put :update, format: :json, id: coordinated_schedule.id, order_cycle_ids: [coordinated_order_cycle.id]
+ spree_put :update, format: :json, id: coordinated_schedule.id,
+ order_cycle_ids: [coordinated_order_cycle.id]
reset_controller_environment
- spree_put :update, format: :json, id: coordinated_schedule.id, order_cycle_ids: [coordinated_order_cycle.id]
+ spree_put :update, format: :json, id: coordinated_schedule.id,
+ order_cycle_ids: [coordinated_order_cycle.id]
end
end
@@ -109,7 +137,8 @@ describe Admin::SchedulesController, type: :controller do
end
it "prevents me from updating the schedule" do
- spree_put :update, format: :json, id: coordinated_schedule.id, schedule: { name: "my awesome schedule" }
+ spree_put :update, format: :json, id: coordinated_schedule.id,
+ schedule: { name: "my awesome schedule" }
expect(response).to redirect_to unauthorized_path
expect(assigns(:schedule)).to eq nil
expect(coordinated_schedule.name).to_not eq "my awesome schedule"
@@ -121,8 +150,12 @@ describe Admin::SchedulesController, type: :controller do
describe "create" do
let(:user) { create(:user) }
let!(:managed_coordinator) { create(:enterprise, owner: user) }
- let!(:coordinated_order_cycle) { create(:simple_order_cycle, coordinator: managed_coordinator ) }
- let!(:uncoordinated_order_cycle) { create(:simple_order_cycle, coordinator: create(:enterprise)) }
+ let!(:coordinated_order_cycle) {
+ create(:simple_order_cycle, coordinator: managed_coordinator )
+ }
+ let!(:uncoordinated_order_cycle) {
+ create(:simple_order_cycle, coordinator: create(:enterprise))
+ }
def create_schedule(params)
spree_put :create, params
@@ -142,7 +175,8 @@ describe Admin::SchedulesController, type: :controller do
context "where I manage at least one of the order cycles to be added to the schedules" do
before do
- params.merge!( order_cycle_ids: [coordinated_order_cycle.id, uncoordinated_order_cycle.id] )
+ params.merge!( order_cycle_ids: [coordinated_order_cycle.id,
+ uncoordinated_order_cycle.id] )
end
it "allows me to create the schedule, adding only order cycles that I manage" do
@@ -175,13 +209,15 @@ describe Admin::SchedulesController, type: :controller do
context 'as an admin user' do
before do
allow(controller).to receive(:spree_current_user) { create(:admin_user) }
- params.merge!( order_cycle_ids: [coordinated_order_cycle.id, uncoordinated_order_cycle.id] )
+ params.merge!( order_cycle_ids: [coordinated_order_cycle.id,
+ uncoordinated_order_cycle.id] )
end
it "allows me to create a schedule" do
expect { create_schedule params }.to change(Schedule, :count).by(1)
schedule = Schedule.last
- expect(schedule.order_cycles).to include coordinated_order_cycle, uncoordinated_order_cycle
+ expect(schedule.order_cycles).to include coordinated_order_cycle,
+ uncoordinated_order_cycle
end
end
end
@@ -191,8 +227,12 @@ describe Admin::SchedulesController, type: :controller do
let(:user) { create(:user, enterprise_limit: 10) }
let(:managed_coordinator) { create(:enterprise, owner: user) }
let(:coordinated_order_cycle) { create(:simple_order_cycle, coordinator: managed_coordinator ) }
- let(:uncoordinated_order_cycle) { create(:simple_order_cycle, coordinator: create(:enterprise) ) }
- let(:coordinated_schedule) { create(:schedule, order_cycles: [coordinated_order_cycle, uncoordinated_order_cycle] ) }
+ let(:uncoordinated_order_cycle) {
+ create(:simple_order_cycle, coordinator: create(:enterprise) )
+ }
+ let(:coordinated_schedule) {
+ create(:schedule, order_cycles: [coordinated_order_cycle, uncoordinated_order_cycle] )
+ }
let(:uncoordinated_schedule) { create(:schedule, order_cycles: [uncoordinated_order_cycle] ) }
let(:params) { { format: :json } }
diff --git a/spec/controllers/admin/stripe_accounts_controller_spec.rb b/spec/controllers/admin/stripe_accounts_controller_spec.rb
index 11478c9b34..04a126b91b 100644
--- a/spec/controllers/admin/stripe_accounts_controller_spec.rb
+++ b/spec/controllers/admin/stripe_accounts_controller_spec.rb
@@ -128,11 +128,14 @@ describe Admin::StripeAccountsController, type: :controller do
end
context "when a stripe account is associated with the specified enterprise" do
- let!(:account) { create(:stripe_account, stripe_user_id: "acc_123", enterprise: enterprise) }
+ let!(:account) {
+ create(:stripe_account, stripe_user_id: "acc_123", enterprise: enterprise)
+ }
context "but access has been revoked or does not exist on stripe's servers" do
before do
- stub_request(:get, "https://api.stripe.com/v1/accounts/acc_123").to_return(status: 404)
+ stub_request(:get,
+ "https://api.stripe.com/v1/accounts/acc_123").to_return(status: 404)
end
it "returns with a status of 'access_revoked'" do
@@ -153,7 +156,8 @@ describe Admin::StripeAccountsController, type: :controller do
end
before do
- stub_request(:get, "https://api.stripe.com/v1/accounts/acc_123").to_return(body: JSON.generate(stripe_account_mock))
+ stub_request(:get,
+ "https://api.stripe.com/v1/accounts/acc_123").to_return(body: JSON.generate(stripe_account_mock))
end
it "returns with a status of 'connected'" do
diff --git a/spec/controllers/admin/subscription_line_items_controller_spec.rb b/spec/controllers/admin/subscription_line_items_controller_spec.rb
index 29719cdc1c..639cce1538 100644
--- a/spec/controllers/admin/subscription_line_items_controller_spec.rb
+++ b/spec/controllers/admin/subscription_line_items_controller_spec.rb
@@ -10,15 +10,27 @@ describe Admin::SubscriptionLineItemsController, type: :controller do
let!(:shop) { create(:enterprise, owner: user) }
let(:unmanaged_shop) { create(:enterprise) }
let!(:product) { create(:product) }
- let!(:variant) { create(:variant, product: product, unit_value: '100', price: 15.00, option_values: []) }
- let!(:outgoing_exchange) { order_cycle.exchanges.create(sender: shop, receiver: shop, variants: [variant], enterprise_fees: [enterprise_fee]) }
+ let!(:variant) {
+ create(:variant, product: product, unit_value: '100', price: 15.00, option_values: [])
+ }
+ let!(:outgoing_exchange) {
+ order_cycle.exchanges.create(sender: shop, receiver: shop, variants: [variant],
+ enterprise_fees: [enterprise_fee])
+ }
let!(:enterprise_fee) { create(:enterprise_fee, amount: 3.50) }
- let!(:order_cycle) { create(:simple_order_cycle, coordinator: shop, orders_open_at: 2.days.from_now, orders_close_at: 7.days.from_now) }
+ let!(:order_cycle) {
+ create(:simple_order_cycle, coordinator: shop, orders_open_at: 2.days.from_now,
+ orders_close_at: 7.days.from_now)
+ }
let!(:schedule) { create(:schedule, order_cycles: [order_cycle]) }
- let(:unmanaged_schedule) { create(:schedule, order_cycles: [create(:simple_order_cycle, coordinator: unmanaged_shop)]) }
+ let(:unmanaged_schedule) {
+ create(:schedule, order_cycles: [create(:simple_order_cycle, coordinator: unmanaged_shop)])
+ }
context "json" do
- let(:params) { { format: :json, subscription_line_item: { quantity: 2, variant_id: variant.id } } }
+ let(:params) {
+ { format: :json, subscription_line_item: { quantity: 2, variant_id: variant.id } }
+ }
context 'as an enterprise user' do
before { allow(controller).to receive(:spree_current_user) { user } }
@@ -96,7 +108,9 @@ describe Admin::SubscriptionLineItemsController, type: :controller do
end
context "where a relevant variant override exists" do
- let!(:override) { create(:variant_override, hub_id: shop.id, variant_id: variant.id, price: 12.00) }
+ let!(:override) {
+ create(:variant_override, hub_id: shop.id, variant_id: variant.id, price: 12.00)
+ }
it "returns a serialized subscription line item with a price estimate, based on the override" do
spree_post :build, params
diff --git a/spec/controllers/admin/subscriptions_controller_spec.rb b/spec/controllers/admin/subscriptions_controller_spec.rb
index 322a5e488e..125271c483 100644
--- a/spec/controllers/admin/subscriptions_controller_spec.rb
+++ b/spec/controllers/admin/subscriptions_controller_spec.rb
@@ -117,7 +117,9 @@ describe Admin::SubscriptionsController, type: :controller do
context 'as an non-manager of the specified shop' do
before do
- allow(controller).to receive(:spree_current_user) { create(:user, enterprises: [create(:enterprise)]) }
+ allow(controller).to receive(:spree_current_user) {
+ create(:user, enterprises: [create(:enterprise)])
+ }
end
it 'redirects to unauthorized' do
@@ -135,17 +137,25 @@ describe Admin::SubscriptionsController, type: :controller do
it 'returns errors' do
expect{ spree_post :create, params }.to_not change{ Subscription.count }
json_response = JSON.parse(response.body)
- expect(json_response['errors'].keys).to include 'schedule', 'customer', 'payment_method', 'shipping_method', 'begins_at'
+ expect(json_response['errors'].keys).to include 'schedule', 'customer', 'payment_method',
+ 'shipping_method', 'begins_at'
end
end
context 'when I submit params containing ids of inaccessible objects' do
# As 'user' I shouldnt be able to associate a subscription with any of these.
let(:unmanaged_enterprise) { create(:enterprise) }
- let(:unmanaged_schedule) { create(:schedule, order_cycles: [create(:simple_order_cycle, coordinator: unmanaged_enterprise)]) }
+ let(:unmanaged_schedule) {
+ create(:schedule,
+ order_cycles: [create(:simple_order_cycle, coordinator: unmanaged_enterprise)])
+ }
let(:unmanaged_customer) { create(:customer, enterprise: unmanaged_enterprise) }
- let(:unmanaged_payment_method) { create(:payment_method, distributors: [unmanaged_enterprise]) }
- let(:unmanaged_shipping_method) { create(:shipping_method, distributors: [unmanaged_enterprise]) }
+ let(:unmanaged_payment_method) {
+ create(:payment_method, distributors: [unmanaged_enterprise])
+ }
+ let(:unmanaged_shipping_method) {
+ create(:shipping_method, distributors: [unmanaged_enterprise])
+ }
before do
params[:subscription].merge!(
@@ -161,7 +171,8 @@ describe Admin::SubscriptionsController, type: :controller do
it 'returns errors' do
expect{ spree_post :create, params }.to_not change{ Subscription.count }
json_response = JSON.parse(response.body)
- expect(json_response['errors'].keys).to include 'schedule', 'customer', 'payment_method', 'shipping_method', 'ends_at'
+ expect(json_response['errors'].keys).to include 'schedule', 'customer', 'payment_method',
+ 'shipping_method', 'ends_at'
end
end
@@ -194,7 +205,10 @@ describe Admin::SubscriptionsController, type: :controller do
end
context 'where the specified variants are available from the shop' do
- let!(:exchange) { create(:exchange, order_cycle: order_cycle, incoming: false, receiver: shop, variants: [variant]) }
+ let!(:exchange) {
+ create(:exchange, order_cycle: order_cycle, incoming: false, receiver: shop,
+ variants: [variant])
+ }
it 'creates subscription line items for the subscription' do
expect{ spree_post :create, params }.to change{ Subscription.count }.by(1)
@@ -248,10 +262,18 @@ describe Admin::SubscriptionsController, type: :controller do
let!(:shop) { create(:distributor_enterprise, owner: user) }
let!(:customer) { create(:customer, enterprise: shop) }
let!(:product1) { create(:product, supplier: shop) }
- let!(:variant1) { create(:variant, product: product1, unit_value: '100', price: 12.00, option_values: []) }
+ let!(:variant1) {
+ create(:variant, product: product1, unit_value: '100', price: 12.00, option_values: [])
+ }
let!(:enterprise_fee) { create(:enterprise_fee, amount: 1.75) }
- let!(:order_cycle) { create(:simple_order_cycle, coordinator: shop, orders_open_at: 2.days.from_now, orders_close_at: 7.days.from_now) }
- let!(:outgoing_exchange) { order_cycle.exchanges.create(sender: shop, receiver: shop, variants: [variant1], enterprise_fees: [enterprise_fee]) }
+ let!(:order_cycle) {
+ create(:simple_order_cycle, coordinator: shop, orders_open_at: 2.days.from_now,
+ orders_close_at: 7.days.from_now)
+ }
+ let!(:outgoing_exchange) {
+ order_cycle.exchanges.create(sender: shop, receiver: shop, variants: [variant1],
+ enterprise_fees: [enterprise_fee])
+ }
let!(:schedule) { create(:schedule, order_cycles: [order_cycle]) }
let!(:payment_method) { create(:payment_method, distributors: [shop]) }
let!(:shipping_method) { create(:shipping_method, distributors: [shop]) }
@@ -262,14 +284,17 @@ describe Admin::SubscriptionsController, type: :controller do
schedule: schedule,
payment_method: payment_method,
shipping_method: shipping_method,
- subscription_line_items: [create(:subscription_line_item, variant: variant1, quantity: 2)])
+ subscription_line_items: [create(:subscription_line_item, variant: variant1,
+ quantity: 2)])
}
let(:subscription_line_item1) { subscription.subscription_line_items.first }
let(:params) { { format: :json, id: subscription.id, subscription: {} } }
context 'as an non-manager of the subscription shop' do
before do
- allow(controller).to receive(:spree_current_user) { create(:user, enterprises: [create(:enterprise)]) }
+ allow(controller).to receive(:spree_current_user) {
+ create(:user, enterprises: [create(:enterprise)])
+ }
end
it 'redirects to unauthorized' do
@@ -302,8 +327,12 @@ describe Admin::SubscriptionsController, type: :controller do
context 'when I submit params containing ids of inaccessible objects' do
# As 'user' I shouldnt be able to associate a subscription with any of these.
let(:unmanaged_enterprise) { create(:enterprise) }
- let(:unmanaged_payment_method) { create(:payment_method, distributors: [unmanaged_enterprise]) }
- let(:unmanaged_shipping_method) { create(:shipping_method, distributors: [unmanaged_enterprise]) }
+ let(:unmanaged_payment_method) {
+ create(:payment_method, distributors: [unmanaged_enterprise])
+ }
+ let(:unmanaged_shipping_method) {
+ create(:shipping_method, distributors: [unmanaged_enterprise])
+ }
before do
params[:subscription].merge!(
@@ -344,15 +373,21 @@ describe Admin::SubscriptionsController, type: :controller do
context 'with subscription_line_items params' do
let!(:product2) { create(:product) }
- let!(:variant2) { create(:variant, product: product2, unit_value: '1000', price: 6.00, option_values: []) }
+ let!(:variant2) {
+ create(:variant, product: product2, unit_value: '1000', price: 6.00, option_values: [])
+ }
before do
- params[:subscription_line_items] = [{ id: subscription_line_item1.id, quantity: 1, variant_id: variant1.id }, { quantity: 2, variant_id: variant2.id }]
+ params[:subscription_line_items] =
+ [{ id: subscription_line_item1.id, quantity: 1, variant_id: variant1.id },
+ { quantity: 2, variant_id: variant2.id }]
end
context 'where the specified variants are not available from the shop' do
it 'returns an error' do
- expect{ spree_post :update, params }.to_not change{ subscription.subscription_line_items.count }
+ expect{ spree_post :update, params }.to_not change{
+ subscription.subscription_line_items.count
+ }
json_response = JSON.parse(response.body)
expect(json_response['errors']['subscription_line_items']).to eq ["#{product2.name} - #{variant2.full_name} is not available from the selected schedule"]
end
@@ -362,7 +397,9 @@ describe Admin::SubscriptionsController, type: :controller do
before { outgoing_exchange.update(variants: [variant1, variant2]) }
it 'creates subscription line items for the subscription' do
- expect{ spree_post :update, params }.to change{ subscription.subscription_line_items.count }.by(1)
+ expect{ spree_post :update, params }.to change{
+ subscription.subscription_line_items.count
+ }.by(1)
subscription.reload
expect(subscription.subscription_line_items.count).to be 2
subscription_line_item = subscription.subscription_line_items.last
@@ -380,7 +417,9 @@ describe Admin::SubscriptionsController, type: :controller do
let!(:shop) { create(:distributor_enterprise) }
let!(:order_cycle) { create(:simple_order_cycle, orders_close_at: 1.day.from_now) }
let!(:subscription) { create(:subscription, shop: shop, with_items: true) }
- let!(:proxy_order) { create(:proxy_order, subscription: subscription, order_cycle: order_cycle) }
+ let!(:proxy_order) {
+ create(:proxy_order, subscription: subscription, order_cycle: order_cycle)
+ }
before do
allow(controller).to receive(:spree_current_user) { user }
@@ -412,10 +451,12 @@ describe Admin::SubscriptionsController, type: :controller do
context "when at least one associated order is still 'open'" do
let(:order_cycle) { subscription.order_cycles.first }
- let(:proxy_order) { create(:proxy_order, subscription: subscription, order_cycle: order_cycle) }
+ let(:proxy_order) {
+ create(:proxy_order, subscription: subscription, order_cycle: order_cycle)
+ }
let!(:order) { proxy_order.initialise_order! }
- before { while !order.completed? do break unless order.next! end }
+ before { break unless order.next! while !order.completed? }
context "when no 'open_orders' directive has been provided" do
it "renders an error, asking what to do" do
@@ -511,10 +552,12 @@ describe Admin::SubscriptionsController, type: :controller do
context "when at least one associated order is still 'open'" do
let(:order_cycle) { subscription.order_cycles.first }
- let(:proxy_order) { create(:proxy_order, subscription: subscription, order_cycle: order_cycle) }
+ let(:proxy_order) {
+ create(:proxy_order, subscription: subscription, order_cycle: order_cycle)
+ }
let!(:order) { proxy_order.initialise_order! }
- before { while !order.completed? do break unless order.next! end }
+ before { break unless order.next! while !order.completed? }
context "when no 'open_orders' directive has been provided" do
it "renders an error, asking what to do" do
@@ -578,7 +621,9 @@ describe Admin::SubscriptionsController, type: :controller do
describe 'unpause' do
let!(:user) { create(:user, enterprise_limit: 10) }
let!(:shop) { create(:distributor_enterprise) }
- let!(:subscription) { create(:subscription, shop: shop, paused_at: Time.zone.now, with_items: true) }
+ let!(:subscription) {
+ create(:subscription, shop: shop, paused_at: Time.zone.now, with_items: true)
+ }
before do
allow(controller).to receive(:spree_current_user) { user }
@@ -610,10 +655,12 @@ describe Admin::SubscriptionsController, type: :controller do
context "when at least one order in an open order cycle is 'complete'" do
let(:order_cycle) { subscription.order_cycles.first }
- let(:proxy_order) { create(:proxy_order, subscription: subscription, order_cycle: order_cycle) }
+ let(:proxy_order) {
+ create(:proxy_order, subscription: subscription, order_cycle: order_cycle)
+ }
let!(:order) { proxy_order.initialise_order! }
- before { while !order.completed? do break unless order.next! end }
+ before { break unless order.next! while !order.completed? }
context "when no associated orders are 'canceled'" do
it 'renders the unpaused subscription as json, leaves the order untouched' do
@@ -707,7 +754,9 @@ describe Admin::SubscriptionsController, type: :controller do
context "when other payment methods exist" do
let!(:stripe) { create(:stripe_connect_payment_method, distributors: [shop]) }
- let!(:paypal) { Spree::Gateway::PayPalExpress.create!(name: "PayPalExpress", distributor_ids: [shop.id]) }
+ let!(:paypal) {
+ Spree::Gateway::PayPalExpress.create!(name: "PayPalExpress", distributor_ids: [shop.id])
+ }
let!(:bogus) { create(:bogus_payment_method, distributors: [shop]) }
it "only loads Stripe and Cash payment methods" do
diff --git a/spec/controllers/admin/variant_overrides_controller_spec.rb b/spec/controllers/admin/variant_overrides_controller_spec.rb
index 44165bde23..6a3aa8c0e5 100644
--- a/spec/controllers/admin/variant_overrides_controller_spec.rb
+++ b/spec/controllers/admin/variant_overrides_controller_spec.rb
@@ -9,9 +9,14 @@ describe Admin::VariantOverridesController, type: :controller do
let(:hub) { create(:distributor_enterprise) }
let(:variant) { create(:variant) }
- let!(:inventory_item) { create(:inventory_item, enterprise: hub, variant: variant, visible: true) }
+ let!(:inventory_item) {
+ create(:inventory_item, enterprise: hub, variant: variant, visible: true)
+ }
let!(:variant_override) { create(:variant_override, hub: hub, variant: variant) }
- let(:variant_override_params) { [{ id: variant_override.id, price: 123.45, count_on_hand: 321, sku: "MySKU", on_demand: false }] }
+ let(:variant_override_params) {
+ [{ id: variant_override.id, price: 123.45, count_on_hand: 321, sku: "MySKU",
+ on_demand: false }]
+ }
context "where I don't manage the variant override hub" do
before do
@@ -47,7 +52,8 @@ describe Admin::VariantOverridesController, type: :controller do
context "and the producer has granted VO permission" do
before do
- create(:enterprise_relationship, parent: variant.product.supplier, child: hub, permissions_list: [:create_variant_overrides])
+ create(:enterprise_relationship, parent: variant.product.supplier, child: hub,
+ permissions_list: [:create_variant_overrides])
end
it "loads data" do
@@ -69,7 +75,10 @@ describe Admin::VariantOverridesController, type: :controller do
end
context "where params for a variant override are blank" do
- let(:variant_override_params) { [{ id: variant_override.id, price: "", count_on_hand: "", default_stock: nil, resettable: nil, sku: nil, on_demand: nil }] }
+ let(:variant_override_params) {
+ [{ id: variant_override.id, price: "", count_on_hand: "", default_stock: nil, resettable: nil,
+ sku: nil, on_demand: nil }]
+ }
it "destroys the variant override" do
put :bulk_update, as: format, params: { variant_overrides: variant_override_params }
@@ -79,7 +88,9 @@ describe Admin::VariantOverridesController, type: :controller do
context "and there is a variant override for a deleted variant" do
let(:deleted_variant) { create(:variant) }
- let!(:variant_override_of_deleted_variant) { create(:variant_override, hub: hub, variant: deleted_variant) }
+ let!(:variant_override_of_deleted_variant) {
+ create(:variant_override, hub: hub, variant: deleted_variant)
+ }
before { deleted_variant.update_attribute :deleted_at, Time.zone.now }
@@ -105,8 +116,14 @@ describe Admin::VariantOverridesController, type: :controller do
let(:product) { create(:product, supplier: producer) }
let(:variant1) { create(:variant, product: product) }
let(:variant2) { create(:variant, product: product) }
- let!(:variant_override1) { create(:variant_override, hub: hub, variant: variant1, count_on_hand: 5, default_stock: 7, resettable: true) }
- let!(:variant_override2) { create(:variant_override, hub: hub, variant: variant2, count_on_hand: 2, default_stock: 1, resettable: false) }
+ let!(:variant_override1) {
+ create(:variant_override, hub: hub, variant: variant1, count_on_hand: 5, default_stock: 7,
+ resettable: true)
+ }
+ let!(:variant_override2) {
+ create(:variant_override, hub: hub, variant: variant2, count_on_hand: 2, default_stock: 1,
+ resettable: false)
+ }
let(:params) { { format: format, hub_id: hub.id } }
@@ -136,7 +153,10 @@ describe Admin::VariantOverridesController, type: :controller do
end
context "where the producer has granted create_variant_overrides permission to the hub" do
- let!(:er1) { create(:enterprise_relationship, parent: producer, child: hub, permissions_list: [:create_variant_overrides]) }
+ let!(:er1) {
+ create(:enterprise_relationship, parent: producer, child: hub,
+ permissions_list: [:create_variant_overrides])
+ }
it "loads data" do
put :bulk_reset, params: params
@@ -159,8 +179,14 @@ describe Admin::VariantOverridesController, type: :controller do
let(:hub2) { create(:distributor_enterprise, owner: hub.owner) }
let(:product) { create(:product, supplier: producer) }
let(:variant3) { create(:variant, product: product) }
- let!(:variant_override3) { create(:variant_override, hub: hub2, variant: variant3, count_on_hand: 1, default_stock: 13, resettable: true) }
- let!(:er2) { create(:enterprise_relationship, parent: producer, child: hub2, permissions_list: [:create_variant_overrides]) }
+ let!(:variant_override3) {
+ create(:variant_override, hub: hub2, variant: variant3, count_on_hand: 1, default_stock: 13,
+ resettable: true)
+ }
+ let!(:er2) {
+ create(:enterprise_relationship, parent: producer, child: hub2,
+ permissions_list: [:create_variant_overrides])
+ }
it "does not reset count_on_hand for variant_overrides not in params" do
expect {
diff --git a/spec/controllers/api/v0/exchange_products_controller_spec.rb b/spec/controllers/api/v0/exchange_products_controller_spec.rb
index 01394ec215..a0a895edea 100644
--- a/spec/controllers/api/v0/exchange_products_controller_spec.rb
+++ b/spec/controllers/api/v0/exchange_products_controller_spec.rb
@@ -36,14 +36,16 @@ module Api
describe "when an exchange id param is provided" do
it "uses exchange order_cycle, incoming and enterprise to fetch products" do
- api_get :index, exchange_id: exchange.id, order_cycle_id: 666, enterprise_id: 666, incoming: false
+ api_get :index, exchange_id: exchange.id, order_cycle_id: 666, enterprise_id: 666,
+ incoming: false
expect(json_response["products"].first["supplier_name"]).to eq exchange.variants.first.product.supplier.name
end
end
describe "when an exchange id param is not provided" do
it "uses params order_cycle, incoming and enterprise to fetch products" do
- api_get :index, order_cycle_id: order_cycle.id, enterprise_id: exchange.sender_id, incoming: true
+ api_get :index, order_cycle_id: order_cycle.id, enterprise_id: exchange.sender_id,
+ incoming: true
expect(json_response["products"].first["supplier_name"]).to eq exchange.variants.first.product.supplier.name
end
end
@@ -51,7 +53,9 @@ module Api
describe "pagination" do
let(:exchange) { order_cycle.exchanges.outgoing.first }
- let(:products_relation) { Spree::Product.includes(:variants).where("spree_variants.id": exchange.variants.map(&:id)) }
+ let(:products_relation) {
+ Spree::Product.includes(:variants).where("spree_variants.id": exchange.variants.map(&:id))
+ }
before do
stub_const("#{Api::V0::ExchangeProductsController}::DEFAULT_PER_PAGE", 1)
diff --git a/spec/controllers/api/v0/logos_controller_spec.rb b/spec/controllers/api/v0/logos_controller_spec.rb
index 98571ae9d2..d87f919fe7 100644
--- a/spec/controllers/api/v0/logos_controller_spec.rb
+++ b/spec/controllers/api/v0/logos_controller_spec.rb
@@ -12,7 +12,9 @@ module Api
let(:enterprise_manager) { create(:user, enterprise_limit: 10, enterprises: [enterprise]) }
let(:other_enterprise_owner) { create(:user) }
let(:other_enterprise) { create(:enterprise, owner: other_enterprise_owner ) }
- let(:other_enterprise_manager) { create(:user, enterprise_limit: 10, enterprises: [other_enterprise]) }
+ let(:other_enterprise_manager) {
+ create(:user, enterprise_limit: 10, enterprises: [other_enterprise])
+ }
describe "removing logo" do
image_path = File.open(Rails.root.join("app", "assets", "images", "logo-black.png"))
diff --git a/spec/controllers/api/v0/order_cycles_controller_spec.rb b/spec/controllers/api/v0/order_cycles_controller_spec.rb
index 274b9152fd..27e04ee456 100644
--- a/spec/controllers/api/v0/order_cycles_controller_spec.rb
+++ b/spec/controllers/api/v0/order_cycles_controller_spec.rb
@@ -139,7 +139,8 @@ module Api
it "returns hidden variants made visible for this specific customer" do
vo1.update_attribute(:tag_list, default_hide_rule.preferred_variant_tags)
- vo3.update_attribute(:tag_list, "#{show_rule.preferred_variant_tags},#{default_hide_rule.preferred_variant_tags}")
+ vo3.update_attribute(:tag_list,
+ "#{show_rule.preferred_variant_tags},#{default_hide_rule.preferred_variant_tags}")
customer.update_attribute(:tag_list, show_rule.preferred_customer_tags)
api_get :products, id: order_cycle.id, distributor: distributor.id
@@ -206,10 +207,18 @@ module Api
context "with custom taxon ordering applied and duplicate product names in the order cycle" do
let!(:supplier) { create(:supplier_enterprise) }
- let!(:product5) { create(:product, name: "Duplicate name", primary_taxon: taxon3, supplier: supplier) }
- let!(:product6) { create(:product, name: "Duplicate name", primary_taxon: taxon3, supplier: supplier) }
- let!(:product7) { create(:product, name: "Duplicate name", primary_taxon: taxon2, supplier: supplier) }
- let!(:product8) { create(:product, name: "Duplicate name", primary_taxon: taxon2, supplier: supplier) }
+ let!(:product5) {
+ create(:product, name: "Duplicate name", primary_taxon: taxon3, supplier: supplier)
+ }
+ let!(:product6) {
+ create(:product, name: "Duplicate name", primary_taxon: taxon3, supplier: supplier)
+ }
+ let!(:product7) {
+ create(:product, name: "Duplicate name", primary_taxon: taxon2, supplier: supplier)
+ }
+ let!(:product8) {
+ create(:product, name: "Duplicate name", primary_taxon: taxon2, supplier: supplier)
+ }
before do
distributor.preferred_shopfront_taxon_order = "#{taxon2.id},#{taxon3.id},#{taxon1.id}"
@@ -221,7 +230,8 @@ module Api
it "displays products in new order" do
api_get :products, id: order_cycle.id, distributor: distributor.id
- expect(product_ids).to eq [product7.id, product8.id, product2.id, product3.id, product5.id, product6.id, product1.id]
+ expect(product_ids).to eq [product7.id, product8.id, product2.id, product3.id, product5.id,
+ product6.id, product1.id]
end
it "displays products in correct order across multiple pages" do
diff --git a/spec/controllers/api/v0/orders_controller_spec.rb b/spec/controllers/api/v0/orders_controller_spec.rb
index 29e2af8090..9ef8e942f1 100644
--- a/spec/controllers/api/v0/orders_controller_spec.rb
+++ b/spec/controllers/api/v0/orders_controller_spec.rb
@@ -116,7 +116,8 @@ module Api
end
it 'can show only completed orders' do
- get :index, params: { q: { completed_at_not_null: true, s: 'created_at desc' } }, as: :json
+ get :index, params: { q: { completed_at_not_null: true, s: 'created_at desc' } },
+ as: :json
expect(json_response['orders']).to eq serialized_orders([order4, order3, order2, order1])
end
@@ -143,7 +144,9 @@ module Api
end
describe "#show" do
- let!(:order) { create(:completed_order_with_totals, order_cycle: order_cycle, distributor: distributor ) }
+ let!(:order) {
+ create(:completed_order_with_totals, order_cycle: order_cycle, distributor: distributor )
+ }
context "Resource not found" do
before { allow(controller).to receive(:spree_current_user) { admin_user } }
@@ -179,7 +182,9 @@ module Api
end
it "returns unauthorized, as the order product's supplier owner" do
- allow(controller).to receive(:spree_current_user) { order.line_items.first.variant.product.supplier.owner }
+ allow(controller).to receive(:spree_current_user) {
+ order.line_items.first.variant.product.supplier.owner
+ }
get :show, params: { id: order.number }
assert_unauthorized!
end
@@ -192,7 +197,9 @@ module Api
end
context "as distributor owner" do
- let!(:order) { create(:completed_order_with_fees, order_cycle: order_cycle, distributor: distributor ) }
+ let!(:order) {
+ create(:completed_order_with_fees, order_cycle: order_cycle, distributor: distributor )
+ }
before { allow(controller).to receive(:spree_current_user) { order.distributor.owner } }
@@ -203,7 +210,8 @@ module Api
end
it "can view an order with weight calculator (this validates case where options[current_order] is nil on the shipping method serializer)" do
- order.shipping_method.update_attribute(:calculator, create(:weight_calculator, calculable: order))
+ order.shipping_method.update_attribute(:calculator,
+ create(:weight_calculator, calculable: order))
allow(controller).to receive(:current_order).and_return order
get :show, params: { id: order.number }
expect_order
@@ -236,7 +244,7 @@ module Api
expect(json_response[:payments].first[:amount]).to eq order.payments.first.amount.to_s
expect(json_response[:line_items].size).to eq order.line_items.size
- expect(json_response[:line_items].first[:variant][:product_name]). to eq order.line_items.first.variant.product.name
+ expect(json_response[:line_items].first[:variant][:product_name]).to eq order.line_items.first.variant.product.name
end
end
end
diff --git a/spec/controllers/api/v0/product_images_controller_spec.rb b/spec/controllers/api/v0/product_images_controller_spec.rb
index 311654b745..65cc9597dd 100644
--- a/spec/controllers/api/v0/product_images_controller_spec.rb
+++ b/spec/controllers/api/v0/product_images_controller_spec.rb
@@ -19,14 +19,16 @@ module Api
let(:current_api_user) { create(:admin_user) }
it "saves a new image when none is present" do
- post :update_product_image, xhr: true, params: { product_id: product_without_image.id, file: image, use_route: :product_images }
+ post :update_product_image, xhr: true,
+ params: { product_id: product_without_image.id, file: image, use_route: :product_images }
expect(response.status).to eq 201
expect(product_without_image.images.first.id).to eq json_response['id']
end
it "updates an existing product image" do
- post :update_product_image, xhr: true, params: { product_id: product_with_image.id, file: image, use_route: :product_images }
+ post :update_product_image, xhr: true,
+ params: { product_id: product_with_image.id, file: image, use_route: :product_images }
expect(response.status).to eq 200
expect(product_with_image.images.first.id).to eq json_response['id']
diff --git a/spec/controllers/api/v0/products_controller_spec.rb b/spec/controllers/api/v0/products_controller_spec.rb
index e55152cd19..1d9938117d 100644
--- a/spec/controllers/api/v0/products_controller_spec.rb
+++ b/spec/controllers/api/v0/products_controller_spec.rb
@@ -9,12 +9,19 @@ describe Api::V0::ProductsController, type: :controller do
let(:supplier) { create(:supplier_enterprise) }
let(:supplier2) { create(:supplier_enterprise) }
let!(:product) { create(:product, supplier: supplier) }
- let!(:inactive_product) { create(:product, available_on: Time.zone.now.tomorrow, name: "inactive") }
+ let!(:inactive_product) {
+ create(:product, available_on: Time.zone.now.tomorrow, name: "inactive")
+ }
let(:product_other_supplier) { create(:product, supplier: supplier2) }
let(:product_with_image) { create(:product_with_image, supplier: supplier) }
- let(:attributes) { ["id", "name", "supplier", "price", "on_hand", "available_on", "permalink_live"] }
+ let(:attributes) {
+ ["id", "name", "supplier", "price", "on_hand", "available_on", "permalink_live"]
+ }
let(:all_attributes) { ["id", "name", "price", "available_on", "variants"] }
- let(:variants_attributes) { ["id", "options_text", "unit_value", "unit_description", "unit_to_display", "on_demand", "display_as", "display_name", "name_to_display", "sku", "on_hand", "price"] }
+ let(:variants_attributes) {
+ ["id", "options_text", "unit_value", "unit_description", "unit_to_display", "on_demand",
+ "display_as", "display_name", "name_to_display", "sku", "on_hand", "price"]
+ }
let(:current_api_user) { build(:user) }
@@ -36,11 +43,15 @@ describe Api::V0::ProductsController, type: :controller do
api_get :show, id: product.to_param
expect(all_attributes.all?{ |attr| json_response.keys.include? attr }).to eq(true)
- expect(variants_attributes.all?{ |attr| json_response['variants'].first.keys.include? attr }).to eq(true)
+ expect(variants_attributes.all?{ |attr|
+ json_response['variants'].first.keys.include? attr
+ } ).to eq(true)
end
context "finds a product by permalink first then by id" do
- let!(:other_product) { create(:product, permalink: "these-are-not-the-droids-you-are-looking-for") }
+ let!(:other_product) {
+ create(:product, permalink: "these-are-not-the-droids-you-are-looking-for")
+ }
before do
product.update_attribute(:permalink, "#{other_product.id}-and-1-ways")
@@ -122,7 +133,8 @@ describe Api::V0::ProductsController, type: :controller do
expect(response.status).to eq(422)
expect(json_response["error"]).to eq("Invalid resource. Please fix errors and try again.")
errors = json_response["errors"]
- expect(errors.keys).to match_array(["name", "price", "primary_taxon", "shipping_category", "supplier", "variant_unit"])
+ expect(errors.keys).to match_array(["name", "price", "primary_taxon", "shipping_category",
+ "supplier", "variant_unit"])
end
it "can update a product" do
@@ -186,7 +198,7 @@ describe Api::V0::ProductsController, type: :controller do
end
# test cases related to bug #660: product duplication clones master variant
-
+
# stock info - clone is set to zero
it '(does not) clone the stock info of the product' do
spree_post :clone, product_id: product.id, format: :json
@@ -199,7 +211,7 @@ describe Api::V0::ProductsController, type: :controller do
expect(Spree::Product.second.variants.count).not_to eq Spree::Product.first.variants.count
end
- #price info: it does not consider price changes; it considers the price set upon product creation
+ # price info: it does not consider price changes; it considers the price set upon product creation
it '(does not) clone price which was updated' do
product.update_attribute(:price, 2.22)
spree_post :clone, product_id: product.id, format: :json
@@ -246,17 +258,20 @@ describe Api::V0::ProductsController, type: :controller do
it "returns a list of products" do
api_get :bulk_products, { page: 1, per_page: 15 }, format: :json
- expect(returned_product_ids).to eq [product4.id, product3.id, product2.id, inactive_product.id, product.id]
+ expect(returned_product_ids).to eq [product4.id, product3.id, product2.id,
+ inactive_product.id, product.id]
end
it "returns pagination data" do
api_get :bulk_products, { page: 1, per_page: 15 }, format: :json
- expect(json_response['pagination']).to eq "results" => 5, "pages" => 1, "page" => 1, "per_page" => 15
+ expect(json_response['pagination']).to eq "results" => 5, "pages" => 1, "page" => 1,
+ "per_page" => 15
end
it "uses defaults when page and per_page are not supplied" do
api_get :bulk_products, format: :json
- expect(json_response['pagination']).to eq "results" => 5, "pages" => 1, "page" => 1, "per_page" => 15
+ expect(json_response['pagination']).to eq "results" => 5, "pages" => 1, "page" => 1,
+ "per_page" => 15
end
it "returns paginated products by page" do
@@ -268,12 +283,14 @@ describe Api::V0::ProductsController, type: :controller do
end
it "filters results by supplier" do
- api_get :bulk_products, { page: 1, per_page: 15, q: { supplier_id_eq: supplier.id } }, format: :json
+ api_get :bulk_products, { page: 1, per_page: 15, q: { supplier_id_eq: supplier.id } },
+ format: :json
expect(returned_product_ids).to eq [product2.id, inactive_product.id, product.id]
end
it "filters results by product category" do
- api_get :bulk_products, { page: 1, per_page: 15, q: { primary_taxon_id_eq: taxon.id } }, format: :json
+ api_get :bulk_products, { page: 1, per_page: 15, q: { primary_taxon_id_eq: taxon.id } },
+ format: :json
expect(returned_product_ids).to eq [product3.id, product2.id]
end
@@ -282,7 +299,8 @@ describe Api::V0::ProductsController, type: :controller do
product2.variants.first.update_attribute :import_date, 2.days.ago
product3.variants.first.update_attribute :import_date, 1.day.ago
- api_get :bulk_products, { page: 1, per_page: 15, import_date: 1.day.ago.to_date.to_s }, format: :json
+ api_get :bulk_products, { page: 1, per_page: 15, import_date: 1.day.ago.to_date.to_s },
+ format: :json
expect(returned_product_ids).to eq [product3.id, product.id]
end
end
diff --git a/spec/controllers/api/v0/promo_images_controller_spec.rb b/spec/controllers/api/v0/promo_images_controller_spec.rb
index 6754397637..928ac352fe 100644
--- a/spec/controllers/api/v0/promo_images_controller_spec.rb
+++ b/spec/controllers/api/v0/promo_images_controller_spec.rb
@@ -12,7 +12,9 @@ module Api
let(:enterprise_manager) { create(:user, enterprise_limit: 10, enterprises: [enterprise]) }
let(:other_enterprise_owner) { create(:user) }
let(:other_enterprise) { create(:enterprise, owner: other_enterprise_owner ) }
- let(:other_enterprise_manager) { create(:user, enterprise_limit: 10, enterprises: [other_enterprise]) }
+ let(:other_enterprise_manager) {
+ create(:user, enterprise_limit: 10, enterprises: [other_enterprise])
+ }
describe "removing promo image" do
image_path = File.open(Rails.root.join("app", "assets", "images", "logo-black.png"))
diff --git a/spec/controllers/api/v0/shipments_controller_spec.rb b/spec/controllers/api/v0/shipments_controller_spec.rb
index 35aebc1b88..77b6775cd4 100644
--- a/spec/controllers/api/v0/shipments_controller_spec.rb
+++ b/spec/controllers/api/v0/shipments_controller_spec.rb
@@ -266,7 +266,7 @@ describe Api::V0::ShipmentsController, type: :controller do
expect(order.payment_state).to eq "balance_due" # total changed, payment is due
end
- context "using the 'unlock' parameter with closed adjustments" do
+ context "using the 'unlock' parameter with closed adjustments" do
before do
order.shipment_adjustments.each(&:close)
end
@@ -356,10 +356,10 @@ describe Api::V0::ShipmentsController, type: :controller do
before do
allow(Spree::Order).to receive(:find_by!) { fee_order }
- allow(controller).to receive(:find_and_update_shipment) { }
- allow(controller).to receive(:refuse_changing_cancelled_orders) { }
+ allow(controller).to receive(:find_and_update_shipment) {}
+ allow(controller).to receive(:refuse_changing_cancelled_orders) {}
allow(fee_order).to receive(:contents) { contents }
- allow(contents).to receive(:add) { }
+ allow(contents).to receive(:add) {}
allow(fee_order).to receive(:recreate_all_fees!)
end
diff --git a/spec/controllers/api/v0/states_controller_spec.rb b/spec/controllers/api/v0/states_controller_spec.rb
index e9d9d11ad9..fdcbd19e13 100644
--- a/spec/controllers/api/v0/states_controller_spec.rb
+++ b/spec/controllers/api/v0/states_controller_spec.rb
@@ -23,7 +23,8 @@ module Api
context "pagination" do
before do
expect(Spree::State).to receive(:all).and_return(@scope = double)
- allow(@scope).to receive_message_chain(:ransack, :result, :includes, :order).and_return(@scope)
+ allow(@scope).to receive_message_chain(:ransack, :result, :includes,
+ :order).and_return(@scope)
end
it "does not paginate states results when asked not to do so" do
diff --git a/spec/controllers/api/v0/terms_and_conditions_controller_spec.rb b/spec/controllers/api/v0/terms_and_conditions_controller_spec.rb
index 8269683cba..7497e61d7a 100644
--- a/spec/controllers/api/v0/terms_and_conditions_controller_spec.rb
+++ b/spec/controllers/api/v0/terms_and_conditions_controller_spec.rb
@@ -12,7 +12,9 @@ module Api
describe "removing terms and conditions file" do
fake_terms_file_path = File.open(Rails.root.join("app", "assets", "images", "logo-black.png"))
- let(:terms_and_conditions_file) { Rack::Test::UploadedFile.new(fake_terms_file_path, "application/pdf") }
+ let(:terms_and_conditions_file) {
+ Rack::Test::UploadedFile.new(fake_terms_file_path, "application/pdf")
+ }
let(:enterprise) { create(:enterprise, owner: enterprise_owner) }
before do
diff --git a/spec/controllers/api/v0/variants_controller_spec.rb b/spec/controllers/api/v0/variants_controller_spec.rb
index 439a03e22d..fb50f7679c 100644
--- a/spec/controllers/api/v0/variants_controller_spec.rb
+++ b/spec/controllers/api/v0/variants_controller_spec.rb
@@ -9,7 +9,10 @@ describe Api::V0::VariantsController, type: :controller do
let!(:variant1) { FactoryBot.create(:variant) }
let!(:variant2) { FactoryBot.create(:variant) }
let!(:variant3) { FactoryBot.create(:variant) }
- let(:attributes) { [:id, :options_text, :price, :on_hand, :unit_value, :unit_description, :on_demand, :display_as, :display_name] }
+ let(:attributes) {
+ [:id, :options_text, :price, :on_hand, :unit_value, :unit_description, :on_demand, :display_as,
+ :display_name]
+ }
before do
allow(controller).to receive(:spree_current_user) { current_api_user }
@@ -130,7 +133,8 @@ describe Api::V0::VariantsController, type: :controller do
it "can create a new variant" do
original_number_of_variants = variant.product.variants.count
- api_post :create, variant: { sku: "12345", unit_value: "1", unit_description: "L" }, product_id: variant.product.to_param
+ api_post :create, variant: { sku: "12345", unit_value: "1", unit_description: "L" },
+ product_id: variant.product.to_param
expect(attributes.all?{ |attr| json_response.include? attr.to_s }).to eq(true)
expect(response.status).to eq(201)
diff --git a/spec/controllers/cart_controller_spec.rb b/spec/controllers/cart_controller_spec.rb
index 86c78eacd5..1c69a2bbe5 100644
--- a/spec/controllers/cart_controller_spec.rb
+++ b/spec/controllers/cart_controller_spec.rb
@@ -49,17 +49,28 @@ describe CartController, type: :controller do
let!(:variant_not_in_the_order) { create(:variant) }
let(:hub) { create(:distributor_enterprise, with_payment_and_shipping: true) }
- let!(:variant_override_in_the_order) { create(:variant_override, hub: hub, variant: variant_in_the_order, price: 55.55, count_on_hand: 20, default_stock: nil, resettable: false) }
- let!(:variant_override_not_in_the_order) { create(:variant_override, hub: hub, variant: variant_not_in_the_order, count_on_hand: 7, default_stock: nil, resettable: false) }
+ let!(:variant_override_in_the_order) {
+ create(:variant_override, hub: hub, variant: variant_in_the_order, price: 55.55,
+ count_on_hand: 20, default_stock: nil, resettable: false)
+ }
+ let!(:variant_override_not_in_the_order) {
+ create(:variant_override, hub: hub, variant: variant_not_in_the_order, count_on_hand: 7,
+ default_stock: nil, resettable: false)
+ }
- let(:order_cycle) { create(:simple_order_cycle, suppliers: [producer], coordinator: hub, distributors: [hub]) }
+ let(:order_cycle) {
+ create(:simple_order_cycle, suppliers: [producer], coordinator: hub, distributors: [hub])
+ }
let!(:order) { subject.current_order(true) }
- let!(:line_item) { create(:line_item, order: order, variant: variant_in_the_order, quantity: 2, max_quantity: 3) }
+ let!(:line_item) {
+ create(:line_item, order: order, variant: variant_in_the_order, quantity: 2, max_quantity: 3)
+ }
before do
variant_in_the_order.on_hand = 4
variant_not_in_the_order.on_hand = 2
- order_cycle.exchanges.outgoing.first.variants = [variant_in_the_order, variant_not_in_the_order]
+ order_cycle.exchanges.outgoing.first.variants = [variant_in_the_order,
+ variant_not_in_the_order]
order.order_cycle = order_cycle
order.distributor = hub
order.save
@@ -97,7 +108,8 @@ describe CartController, type: :controller do
allow(controller).to receive(:current_order).and_return(order)
expect do
- spree_post :populate, variants: { variant.id => 1 }, variant_attributes: { variant.id => { max_quantity: "3" } }
+ spree_post :populate, variants: { variant.id => 1 },
+ variant_attributes: { variant.id => { max_quantity: "3" } }
end.to change(Spree::LineItem, :count).by(1)
end
end
diff --git a/spec/controllers/checkout_controller_spec.rb b/spec/controllers/checkout_controller_spec.rb
index 3f12646288..2a2158537d 100644
--- a/spec/controllers/checkout_controller_spec.rb
+++ b/spec/controllers/checkout_controller_spec.rb
@@ -49,7 +49,8 @@ describe CheckoutController, type: :controller do
let(:shipping_method) { distributor.shipping_methods.first }
before do
- order.line_items << create(:line_item, variant: order_cycle.variants_distributed_by(distributor).first)
+ order.line_items << create(:line_item,
+ variant: order_cycle.variants_distributed_by(distributor).first)
allow(controller).to receive(:current_distributor).and_return(distributor)
allow(controller).to receive(:current_order_cycle).and_return(order_cycle)
@@ -68,7 +69,7 @@ describe CheckoutController, type: :controller do
"default_bill_address" => false,
"default_ship_address" => false,
"email" => user.email,
- "payments_attributes" => [{"payment_method_id" => payment_method.id}],
+ "payments_attributes" => [{ "payment_method_id" => payment_method.id }],
"ship_address_attributes" => order.bill_address.attributes,
"shipping_method_id" => shipping_method.id
}
@@ -294,14 +295,16 @@ describe CheckoutController, type: :controller do
it "returns errors and flash if order.update fails" do
spree_post :update, format: :json, order: {}
expect(response.status).to eq(400)
- expect(response.body).to eq({ errors: assigns[:order].errors, flash: { error: order.errors.full_messages.to_sentence } }.to_json)
+ expect(response.body).to eq({ errors: assigns[:order].errors,
+ flash: { error: order.errors.full_messages.to_sentence } }.to_json)
end
it "returns errors and flash if order.next fails" do
allow(order).to receive(:update).and_return true
allow(order).to receive(:next).and_return false
spree_post :update, format: :json, order: {}
- expect(response.body).to eq({ errors: assigns[:order].errors, flash: { error: "Payment could not be processed, please check the details you entered" } }.to_json)
+ expect(response.body).to eq({ errors: assigns[:order].errors,
+ flash: { error: "Payment could not be processed, please check the details you entered" } }.to_json)
end
it "returns order confirmation url on success" do
@@ -321,7 +324,8 @@ describe CheckoutController, type: :controller do
spree_post :update, format: :json, order: {}
expect(response.status).to eq(400)
- expect(response.body).to eq({ errors: {}, flash: { error: I18n.t("checkout.failed") } }.to_json)
+ expect(response.body).to eq({ errors: {},
+ flash: { error: I18n.t("checkout.failed") } }.to_json)
end
it "returns a specific error on Spree::Core::GatewayError" do
@@ -355,7 +359,9 @@ describe CheckoutController, type: :controller do
it "tries a maximum of 3 times before giving up and returning an error" do
allow(order).to receive(:update).and_return true
- allow(order).to receive(:next) { raise ActiveRecord::StaleObjectError.new(Spree::Variant.new, 'update') }
+ allow(order).to receive(:next) {
+ raise ActiveRecord::StaleObjectError.new(Spree::Variant.new, 'update')
+ }
spree_post :update, format: :json, order: {}
expect(response.status).to eq(400)
@@ -380,7 +386,8 @@ describe CheckoutController, type: :controller do
expect(Checkout::PaypalRedirect).to receive(:new).and_return(paypal_redirect)
expect(paypal_redirect).to receive(:path).and_return("test_path")
- spree_post :update, order: { payments_attributes: [{ payment_method_id: payment_method.id }] }
+ spree_post :update,
+ order: { payments_attributes: [{ payment_method_id: payment_method.id }] }
expect(response.body).to eq({ path: "test_path" }.to_json)
end
@@ -394,7 +401,8 @@ describe CheckoutController, type: :controller do
expect(Checkout::StripeRedirect).to receive(:new).and_return(stripe_redirect)
expect(stripe_redirect).to receive(:path).and_return("test_path")
- spree_post :update, order: { payments_attributes: [{ payment_method_id: payment_method.id }] }
+ spree_post :update,
+ order: { payments_attributes: [{ payment_method_id: payment_method.id }] }
expect(response.body).to eq({ path: "test_path" }.to_json)
end
diff --git a/spec/controllers/enterprises_controller_spec.rb b/spec/controllers/enterprises_controller_spec.rb
index 1328c04d73..c9ee7b4437 100644
--- a/spec/controllers/enterprises_controller_spec.rb
+++ b/spec/controllers/enterprises_controller_spec.rb
@@ -9,8 +9,14 @@ describe EnterprisesController, type: :controller do
let(:line_item) { create(:line_item) }
let!(:current_distributor) { create(:distributor_enterprise, with_payment_and_shipping: true) }
let!(:distributor) { create(:distributor_enterprise, with_payment_and_shipping: true) }
- let!(:order_cycle1) { create(:simple_order_cycle, distributors: [distributor], orders_open_at: 2.days.ago, orders_close_at: 3.days.from_now, variants: [line_item.variant] ) }
- let!(:order_cycle2) { create(:simple_order_cycle, distributors: [distributor], orders_open_at: 3.days.ago, orders_close_at: 4.days.from_now ) }
+ let!(:order_cycle1) {
+ create(:simple_order_cycle, distributors: [distributor], orders_open_at: 2.days.ago,
+ orders_close_at: 3.days.from_now, variants: [line_item.variant] )
+ }
+ let!(:order_cycle2) {
+ create(:simple_order_cycle, distributors: [distributor], orders_open_at: 3.days.ago,
+ orders_close_at: 4.days.from_now )
+ }
before do
order.set_distributor! current_distributor
@@ -48,7 +54,10 @@ describe EnterprisesController, type: :controller do
end
context "using FilterOrderCycles tag rules" do
- let!(:order_cycle3) { create(:simple_order_cycle, distributors: [distributor], orders_open_at: 3.days.ago, orders_close_at: 4.days.from_now) }
+ let!(:order_cycle3) {
+ create(:simple_order_cycle, distributors: [distributor], orders_open_at: 3.days.ago,
+ orders_close_at: 4.days.from_now)
+ }
let!(:oc3_exchange) { order_cycle3.exchanges.outgoing.to_enterprise(distributor).first }
let(:customer) { create(:customer, user: user, enterprise: distributor) }
@@ -106,7 +115,9 @@ describe EnterprisesController, type: :controller do
describe "when an out of stock item is in the cart" do
let(:variant) { create(:variant, on_demand: false, on_hand: 10) }
let(:line_item) { create(:line_item, variant: variant) }
- let(:order_cycle) { create(:simple_order_cycle, distributors: [current_distributor], variants: [variant]) }
+ let(:order_cycle) {
+ create(:simple_order_cycle, distributors: [current_distributor], variants: [variant])
+ }
before do
order.set_distribution! current_distributor, order_cycle
diff --git a/spec/controllers/line_items_controller_spec.rb b/spec/controllers/line_items_controller_spec.rb
index 7e215d337e..9d1f230f57 100644
--- a/spec/controllers/line_items_controller_spec.rb
+++ b/spec/controllers/line_items_controller_spec.rb
@@ -9,8 +9,9 @@ describe LineItemsController, type: :controller do
context "listing bought items" do
let!(:completed_order) do
- order = create(:completed_order_with_totals, user: user, distributor: distributor, order_cycle: order_cycle, line_items_count: 1)
- while !order.completed? do break unless order.next! end
+ order = create(:completed_order_with_totals, user: user, distributor: distributor,
+ order_cycle: order_cycle, line_items_count: 1)
+ break unless order.next! while !order.completed?
order
end
@@ -34,12 +35,15 @@ describe LineItemsController, type: :controller do
let(:item) do
order = create(:completed_order_with_totals)
item = create(:line_item, order: order)
- while !order.completed? do break unless order.next! end
+ break unless order.next! while !order.completed?
item
end
let(:order) { item.order }
- let(:order_cycle) { create(:simple_order_cycle, distributors: [distributor], variants: [order.line_item_variants]) }
+ let(:order_cycle) {
+ create(:simple_order_cycle, distributors: [distributor],
+ variants: [order.line_item_variants])
+ }
before { allow(controller).to receive_messages spree_current_user: item.order.user }
@@ -86,7 +90,9 @@ describe LineItemsController, type: :controller do
end
context "after a payment is captured" do
- let(:payment) { create(:check_payment, amount: order.total, order: order, state: 'completed') }
+ let(:payment) {
+ create(:check_payment, amount: order.total, order: order, state: 'completed')
+ }
before { payment.capture! }
it 'updates the payment state' do
@@ -156,14 +162,21 @@ describe LineItemsController, type: :controller do
let(:variant2) { create(:variant) }
let(:distributor) { create(:distributor_enterprise, allow_order_changes: true) }
let(:order_cycle) { create(:simple_order_cycle, distributors: [distributor]) }
- let(:calculator) { Calculator::PriceSack.new(preferred_minimal_amount: 15, preferred_normal_amount: 22, preferred_discount_amount: 11) }
+ let(:calculator) {
+ Calculator::PriceSack.new(preferred_minimal_amount: 15, preferred_normal_amount: 22,
+ preferred_discount_amount: 11)
+ }
let(:enterprise_fee) { create(:enterprise_fee, calculator: calculator) }
- let!(:exchange) { create(:exchange, incoming: true, sender: variant1.product.supplier, receiver: order_cycle.coordinator, variants: [variant1, variant2], enterprise_fees: [enterprise_fee]) }
+ let!(:exchange) {
+ create(:exchange, incoming: true, sender: variant1.product.supplier,
+ receiver: order_cycle.coordinator, variants: [variant1, variant2], enterprise_fees: [enterprise_fee])
+ }
let!(:order) do
- order = create(:completed_order_with_totals, user: user, distributor: distributor, order_cycle: order_cycle, line_items_count: 2)
+ order = create(:completed_order_with_totals, user: user, distributor: distributor,
+ order_cycle: order_cycle, line_items_count: 2)
order.reload.line_items.first.update(variant_id: variant1.id)
order.line_items.last.update(variant_id: variant2.id)
- while !order.completed? do break unless order.next! end
+ break unless order.next! while !order.completed?
order.recreate_all_fees!
order
end
diff --git a/spec/controllers/shop_controller_spec.rb b/spec/controllers/shop_controller_spec.rb
index c1245a736b..b072152e72 100644
--- a/spec/controllers/shop_controller_spec.rb
+++ b/spec/controllers/shop_controller_spec.rb
@@ -5,7 +5,9 @@ require 'spec_helper'
describe ShopController, type: :controller do
let!(:pm) { create(:payment_method) }
let!(:sm) { create(:shipping_method) }
- let(:distributor) { create(:distributor_enterprise, payment_methods: [pm], shipping_methods: [sm]) }
+ let(:distributor) {
+ create(:distributor_enterprise, payment_methods: [pm], shipping_methods: [sm])
+ }
it "redirects to the home page if no distributor is selected" do
get :show
diff --git a/spec/controllers/spree/admin/adjustments_controller_spec.rb b/spec/controllers/spree/admin/adjustments_controller_spec.rb
index d36842e7ad..b8e1a2bb13 100644
--- a/spec/controllers/spree/admin/adjustments_controller_spec.rb
+++ b/spec/controllers/spree/admin/adjustments_controller_spec.rb
@@ -49,7 +49,8 @@ module Spree
describe "creating an adjustment" do
it "sets included tax to zero when no tax rate is specified" do
- spree_post :create, order_id: order.number, adjustment: { label: 'Testing included tax', amount: '110' }, tax_rate_id: ''
+ spree_post :create, order_id: order.number,
+ adjustment: { label: 'Testing included tax', amount: '110' }, tax_rate_id: ''
expect(response).to redirect_to spree.admin_order_adjustments_path(order)
a = Adjustment.last
@@ -62,7 +63,8 @@ module Spree
end
it "calculates included tax when a tax rate is provided" do
- spree_post :create, order_id: order.number, adjustment: { label: 'Testing included tax', amount: '110' }, tax_rate_id: tax_rate.id.to_s
+ spree_post :create, order_id: order.number,
+ adjustment: { label: 'Testing included tax', amount: '110' }, tax_rate_id: tax_rate.id.to_s
expect(response).to redirect_to spree.admin_order_adjustments_path(order)
a = Adjustment.last
@@ -81,7 +83,8 @@ module Spree
}
it "sets included tax to zero when no tax rate is specified" do
- spree_put :update, order_id: order.number, id: adjustment.id, adjustment: { label: 'Testing included tax', amount: '110' }, tax_rate_id: ''
+ spree_put :update, order_id: order.number, id: adjustment.id,
+ adjustment: { label: 'Testing included tax', amount: '110' }, tax_rate_id: ''
expect(response).to redirect_to spree.admin_order_adjustments_path(order)
a = Adjustment.last
@@ -94,7 +97,8 @@ module Spree
end
it "calculates included tax when a tax rate is provided" do
- spree_put :update, order_id: order.number, id: adjustment.id, adjustment: { label: 'Testing included tax', amount: '110' }, tax_rate_id: tax_rate.id.to_s
+ spree_put :update, order_id: order.number, id: adjustment.id,
+ adjustment: { label: 'Testing included tax', amount: '110' }, tax_rate_id: tax_rate.id.to_s
expect(response).to redirect_to spree.admin_order_adjustments_path(order)
a = Adjustment.last
@@ -110,7 +114,9 @@ module Spree
describe "#delete" do
let!(:order) { create(:completed_order_with_totals) }
- let(:payment_fee) { create(:adjustment, amount: 0.50, order: order, adjustable: order.payments.first) }
+ let(:payment_fee) {
+ create(:adjustment, amount: 0.50, order: order, adjustable: order.payments.first)
+ }
context "as an enterprise user with edit permissions on the order" do
before do
@@ -154,7 +160,8 @@ module Spree
it "doesn't create adjustments" do
expect {
- spree_post :create, order_id: order.number, adjustment: { label: "Testing", amount: "110" }, tax_rate_id: ""
+ spree_post :create, order_id: order.number,
+ adjustment: { label: "Testing", amount: "110" }, tax_rate_id: ""
}.to_not change { [Adjustment.count, order.reload.total] }
expect(response).to redirect_to spree.admin_order_adjustments_path(order)
@@ -162,7 +169,8 @@ module Spree
it "doesn't change adjustments" do
expect {
- spree_put :update, order_id: order.number, id: adjustment.id, adjustment: { label: "Testing", amount: "110" }, tax_rate_id: ""
+ spree_put :update, order_id: order.number, id: adjustment.id,
+ adjustment: { label: "Testing", amount: "110" }, tax_rate_id: ""
}.to_not change { [adjustment.reload.amount, order.reload.total] }
expect(response).to redirect_to spree.admin_order_adjustments_path(order)
diff --git a/spec/controllers/spree/admin/base_controller_spec.rb b/spec/controllers/spree/admin/base_controller_spec.rb
index 4bcc4b64db..887118b665 100644
--- a/spec/controllers/spree/admin/base_controller_spec.rb
+++ b/spec/controllers/spree/admin/base_controller_spec.rb
@@ -48,7 +48,8 @@ describe Spree::Admin::BaseController, type: :controller do
it "passes a prefix to the serializer method and renders with each_serializer" do
expect(controller).to receive(:serializer).with(prefix) { "SerializerClass" }
- expect(controller).to receive(:render).with(json: data, each_serializer: "SerializerClass")
+ expect(controller).to receive(:render).with(json: data,
+ each_serializer: "SerializerClass")
controller.send(:render_as_json, data, ams_prefix: prefix)
end
end
@@ -58,7 +59,8 @@ describe Spree::Admin::BaseController, type: :controller do
it "does not pass a prefix to the serializer method and renders with each_serializer" do
expect(controller).to receive(:serializer).with(prefix) { "SerializerClass" }
- expect(controller).to receive(:render).with(json: data, each_serializer: "SerializerClass")
+ expect(controller).to receive(:render).with(json: data,
+ each_serializer: "SerializerClass")
controller.send(:render_as_json, data, ams_prefix: prefix)
end
end
@@ -68,6 +70,7 @@ describe Spree::Admin::BaseController, type: :controller do
describe "determining the name of the serializer to be used" do
before do
class Api::Admin::AllowedPrefixBaseSerializer; end;
+
class Api::Admin::BaseSerializer; end;
allow(controller).to receive(:ams_prefix_whitelist) { [:allowed_prefix] }
end
@@ -75,7 +78,8 @@ describe Spree::Admin::BaseController, type: :controller do
context "when a prefix is passed in" do
context "and the prefix appears in the whitelist" do
it "returns the requested serializer" do
- expect(controller.send(:serializer, 'allowed_prefix')).to eq Api::Admin::AllowedPrefixBaseSerializer
+ expect(controller.send(:serializer,
+ 'allowed_prefix')).to eq Api::Admin::AllowedPrefixBaseSerializer
end
end
diff --git a/spec/controllers/spree/admin/orders/customer_details_controller_spec.rb b/spec/controllers/spree/admin/orders/customer_details_controller_spec.rb
index 4744bedb25..89a1466248 100644
--- a/spec/controllers/spree/admin/orders/customer_details_controller_spec.rb
+++ b/spec/controllers/spree/admin/orders/customer_details_controller_spec.rb
@@ -52,7 +52,8 @@ describe Spree::Admin::Orders::CustomerDetailsController, type: :controller do
context "when adding details of a registered user" do
it "redirects to shipments on success" do
- spree_post :update, order: { email: user.email, bill_address_attributes: address_params, ship_address_attributes: address_params }, order_id: order.number
+ spree_post :update,
+ order: { email: user.email, bill_address_attributes: address_params, ship_address_attributes: address_params }, order_id: order.number
order.reload
@@ -62,7 +63,8 @@ describe Spree::Admin::Orders::CustomerDetailsController, type: :controller do
context "when adding details of an unregistered user" do
it "redirects to shipments on success" do
- spree_post :update, order: { email: 'unregistered@email.com', bill_address_attributes: address_params, ship_address_attributes: address_params }, order_id: order.number
+ spree_post :update,
+ order: { email: 'unregistered@email.com', bill_address_attributes: address_params, ship_address_attributes: address_params }, order_id: order.number
order.reload
diff --git a/spec/controllers/spree/admin/orders/invoices_spec.rb b/spec/controllers/spree/admin/orders/invoices_spec.rb
index f2e18d5d70..036950b996 100644
--- a/spec/controllers/spree/admin/orders/invoices_spec.rb
+++ b/spec/controllers/spree/admin/orders/invoices_spec.rb
@@ -8,7 +8,10 @@ describe Spree::Admin::OrdersController, type: :controller do
describe "#invoice" do
let!(:user) { create(:user) }
let!(:enterprise_user) { create(:user) }
- let!(:order) { create(:order_with_distributor, bill_address: create(:address), ship_address: create(:address)) }
+ let!(:order) {
+ create(:order_with_distributor, bill_address: create(:address),
+ ship_address: create(:address))
+ }
let!(:distributor) { order.distributor }
let(:params) { { id: order.number } }
@@ -69,7 +72,10 @@ describe Spree::Admin::OrdersController, type: :controller do
describe "#print" do
let!(:user) { create(:user) }
let!(:enterprise_user) { create(:user) }
- let!(:order) { create(:order_with_distributor, bill_address: create(:address), ship_address: create(:address)) }
+ let!(:order) {
+ create(:order_with_distributor, bill_address: create(:address),
+ ship_address: create(:address))
+ }
let!(:distributor) { order.distributor }
let(:params) { { id: order.number } }
diff --git a/spec/controllers/spree/admin/orders_controller_spec.rb b/spec/controllers/spree/admin/orders_controller_spec.rb
index b4fdd52b9a..a6251602c5 100644
--- a/spec/controllers/spree/admin/orders_controller_spec.rb
+++ b/spec/controllers/spree/admin/orders_controller_spec.rb
@@ -82,12 +82,16 @@ describe Spree::Admin::OrdersController, type: :controller do
}
let(:order_cycle) { create(:simple_order_cycle, distributors: [distributor]) }
let(:enterprise_fee) { create(:enterprise_fee, calculator: build(:calculator_per_item) ) }
- let!(:exchange) { create(:exchange, incoming: true, sender: variant1.product.supplier, receiver: order_cycle.coordinator, variants: [variant1, variant2], enterprise_fees: [enterprise_fee]) }
+ let!(:exchange) {
+ create(:exchange, incoming: true, sender: variant1.product.supplier,
+ receiver: order_cycle.coordinator, variants: [variant1, variant2], enterprise_fees: [enterprise_fee])
+ }
let!(:order) do
- order = create(:completed_order_with_totals, line_items_count: 2, distributor: distributor, order_cycle: order_cycle)
+ order = create(:completed_order_with_totals, line_items_count: 2,
+ distributor: distributor, order_cycle: order_cycle)
order.reload.line_items.first.update(variant_id: variant1.id)
order.line_items.last.update(variant_id: variant2.id)
- while !order.completed? do break unless order.next! end
+ break unless order.next! while !order.completed?
order.recreate_all_fees!
order
end
@@ -187,7 +191,7 @@ describe Spree::Admin::OrdersController, type: :controller do
context "when the order has legacy taxes" do
let(:legacy_tax_adjustment) {
create(:adjustment, amount: 0.5, included: false, originator: tax_rate,
- order: order, adjustable: order, state: "closed")
+ order: order, adjustable: order, state: "closed")
}
before do
@@ -230,7 +234,8 @@ describe Spree::Admin::OrdersController, type: :controller do
before do
order.line_items << line_item
order.save
- params[:order][:line_items_attributes] = [{ id: line_item.id, quantity: line_item.quantity }]
+ params[:order][:line_items_attributes] =
+ [{ id: line_item.id, quantity: line_item.quantity }]
end
context "and no errors" do
diff --git a/spec/controllers/spree/admin/payment_methods_controller_spec.rb b/spec/controllers/spree/admin/payment_methods_controller_spec.rb
index 497d430de6..418a7a2a56 100644
--- a/spec/controllers/spree/admin/payment_methods_controller_spec.rb
+++ b/spec/controllers/spree/admin/payment_methods_controller_spec.rb
@@ -10,14 +10,18 @@ module Spree
describe Admin::PaymentMethodsController, type: :controller do
describe "#create and #update" do
let!(:enterprise) { create(:distributor_enterprise, owner: user) }
- let(:payment_method) { GatewayWithPassword.create!(name: "Bogus", preferred_password: "haxme", distributor_ids: [enterprise.id]) }
+ let(:payment_method) {
+ GatewayWithPassword.create!(name: "Bogus", preferred_password: "haxme",
+ distributor_ids: [enterprise.id])
+ }
let!(:user) { create(:user) }
before { allow(controller).to receive(:spree_current_user) { user } }
it "does not clear password on update" do
expect(payment_method.preferred_password).to eq "haxme"
- spree_put :update, id: payment_method.id, payment_method: { type: payment_method.class.to_s, preferred_password: "" }
+ spree_put :update, id: payment_method.id,
+ payment_method: { type: payment_method.class.to_s, preferred_password: "" }
expect(response).to redirect_to spree.edit_admin_payment_method_path(payment_method)
payment_method.reload
@@ -34,7 +38,9 @@ module Spree
it "can create a payment method of a valid type" do
expect {
- spree_post :create, payment_method: { name: "Test Method", type: "Spree::Gateway::Bogus", distributor_ids: [enterprise.id] }
+ spree_post :create,
+ payment_method: { name: "Test Method", type: "Spree::Gateway::Bogus",
+ distributor_ids: [enterprise.id] }
}.to change(Spree::PaymentMethod, :count).by(1)
expect(response).to be_redirect
@@ -43,7 +49,9 @@ module Spree
it "can not create a payment method of an invalid type" do
expect {
- spree_post :create, payment_method: { name: "Invalid Payment Method", type: "Spree::InvalidType", distributor_ids: [enterprise.id] }
+ spree_post :create,
+ payment_method: { name: "Invalid Payment Method", type: "Spree::InvalidType",
+ distributor_ids: [enterprise.id] }
}.to change(Spree::PaymentMethod, :count).by(0)
expect(response).to be_redirect
@@ -104,7 +112,10 @@ module Spree
let!(:user) { create(:user, enterprise_limit: 2) }
let!(:enterprise1) { create(:distributor_enterprise, owner: user) }
let!(:enterprise2) { create(:distributor_enterprise, owner: create(:user)) }
- let!(:payment_method) { create(:stripe_connect_payment_method, distributor_ids: [enterprise1.id, enterprise2.id], preferred_enterprise_id: enterprise2.id) }
+ let!(:payment_method) {
+ create(:stripe_connect_payment_method, distributor_ids: [enterprise1.id, enterprise2.id],
+ preferred_enterprise_id: enterprise2.id)
+ }
before { allow(controller).to receive(:spree_current_user) { user } }
@@ -165,7 +176,8 @@ module Spree
context "Requesting provider preference fields" do
let(:enterprise) { create(:distributor_enterprise) }
let(:user) do
- new_user = create(:user, email: 'enterprise@hub.com', password: 'blahblah', password_confirmation: 'blahblah', )
+ new_user = create(:user, email: 'enterprise@hub.com', password: 'blahblah',
+ password_confirmation: 'blahblah', )
new_user.spree_roles = [] # for some reason unbeknown to me, this new user gets admin permissions by default.
new_user.enterprise_roles.build(enterprise: enterprise).save
new_user.save
diff --git a/spec/controllers/spree/admin/products_controller_spec.rb b/spec/controllers/spree/admin/products_controller_spec.rb
index 7ee42b9aa2..7f2177494d 100644
--- a/spec/controllers/spree/admin/products_controller_spec.rb
+++ b/spec/controllers/spree/admin/products_controller_spec.rb
@@ -181,7 +181,10 @@ describe Spree::Admin::ProductsController, type: :controller do
describe "change product supplier" do
let(:distributor) { create(:distributor_enterprise) }
- let!(:order_cycle) { create(:simple_order_cycle, variants: [product.variants.first], coordinator: distributor, distributors: [distributor]) }
+ let!(:order_cycle) {
+ create(:simple_order_cycle, variants: [product.variants.first], coordinator: distributor,
+ distributors: [distributor])
+ }
it "should remove product from existing Order Cycles" do
new_producer = create(:enterprise)
diff --git a/spec/controllers/spree/admin/reports_controller_spec.rb b/spec/controllers/spree/admin/reports_controller_spec.rb
index 4ae4e0cf13..2f9edf9de7 100644
--- a/spec/controllers/spree/admin/reports_controller_spec.rb
+++ b/spec/controllers/spree/admin/reports_controller_spec.rb
@@ -20,12 +20,19 @@ describe Spree::Admin::ReportsController, type: :controller do
let(:product3) { create(:product, price: 34.56, supplier: supplier3) }
# Given two order cycles with both distributors
- let(:ocA) { create(:simple_order_cycle, coordinator: coordinator1, distributors: [distributor1, distributor2], suppliers: [supplier1, supplier2, supplier3], variants: [product1.master, product3.master]) }
- let(:ocB) { create(:simple_order_cycle, coordinator: coordinator2, distributors: [distributor1, distributor2], suppliers: [supplier1, supplier2, supplier3], variants: [product2.master]) }
+ let(:ocA) {
+ create(:simple_order_cycle, coordinator: coordinator1, distributors: [distributor1, distributor2],
+ suppliers: [supplier1, supplier2, supplier3], variants: [product1.master, product3.master])
+ }
+ let(:ocB) {
+ create(:simple_order_cycle, coordinator: coordinator2, distributors: [distributor1, distributor2],
+ suppliers: [supplier1, supplier2, supplier3], variants: [product2.master])
+ }
# orderA1 can only be accessed by supplier1, supplier3 and distributor1
let(:orderA1) do
- order = create(:order, distributor: distributor1, bill_address: bill_address, ship_address: ship_address, special_instructions: instructions, order_cycle: ocA)
+ order = create(:order, distributor: distributor1, bill_address: bill_address,
+ ship_address: ship_address, special_instructions: instructions, order_cycle: ocA)
order.line_items << create(:line_item, variant: product1.master)
order.line_items << create(:line_item, variant: product3.master)
order.finalize!
@@ -34,7 +41,8 @@ describe Spree::Admin::ReportsController, type: :controller do
end
# orderA2 can only be accessed by supplier2 and distributor2
let(:orderA2) do
- order = create(:order, distributor: distributor2, bill_address: bill_address, ship_address: ship_address, special_instructions: instructions, order_cycle: ocA)
+ order = create(:order, distributor: distributor2, bill_address: bill_address,
+ ship_address: ship_address, special_instructions: instructions, order_cycle: ocA)
order.line_items << create(:line_item, variant: product2.master)
order.finalize!
order.save
@@ -42,7 +50,8 @@ describe Spree::Admin::ReportsController, type: :controller do
end
# orderB1 can only be accessed by supplier1, supplier3 and distributor1
let(:orderB1) do
- order = create(:order, distributor: distributor1, bill_address: bill_address, ship_address: ship_address, special_instructions: instructions, order_cycle: ocB)
+ order = create(:order, distributor: distributor1, bill_address: bill_address,
+ ship_address: ship_address, special_instructions: instructions, order_cycle: ocB)
order.line_items << create(:line_item, variant: product1.master)
order.line_items << create(:line_item, variant: product3.master)
order.finalize!
@@ -51,7 +60,8 @@ describe Spree::Admin::ReportsController, type: :controller do
end
# orderB2 can only be accessed by supplier2 and distributor2
let(:orderB2) do
- order = create(:order, distributor: distributor2, bill_address: bill_address, ship_address: ship_address, special_instructions: instructions, order_cycle: ocB)
+ order = create(:order, distributor: distributor2, bill_address: bill_address,
+ ship_address: ship_address, special_instructions: instructions, order_cycle: ocB)
order.line_items << create(:line_item, variant: product2.master)
order.finalize!
order.save
@@ -151,7 +161,8 @@ describe Spree::Admin::ReportsController, type: :controller do
context "where I have granted P-OC to the distributor" do
before do
- create(:enterprise_relationship, parent: supplier1, child: distributor1, permissions_list: [:add_to_order_cycle])
+ create(:enterprise_relationship, parent: supplier1, child: distributor1,
+ permissions_list: [:add_to_order_cycle])
end
it "only shows product line items that I am supplying" do
@@ -291,7 +302,6 @@ describe Spree::Admin::ReportsController, type: :controller do
end
end
-
context 'Order Cycle Management' do
let!(:present_objects) { [orderA1, orderA2, orderB1, orderB2] }
@@ -302,7 +312,7 @@ describe Spree::Admin::ReportsController, type: :controller do
it 'renders the delivery report' do
spree_post :order_cycle_management, {
q: { completed_at_lt: 1.day.ago },
- shipping_method_in: [ "123" ], # We just need to search for shipping methods
+ shipping_method_in: ["123"], # We just need to search for shipping methods
report_type: "delivery",
}
diff --git a/spec/controllers/spree/admin/tax_rates_controller_spec.rb b/spec/controllers/spree/admin/tax_rates_controller_spec.rb
index 1a5668b727..27d0c10464 100644
--- a/spec/controllers/spree/admin/tax_rates_controller_spec.rb
+++ b/spec/controllers/spree/admin/tax_rates_controller_spec.rb
@@ -38,7 +38,8 @@ module Spree
context "when the amount is changed" do
it "duplicates the record and soft-deletes the duplicate" do
expect {
- spree_put :update, id: tax_rate.id, tax_rate: { name: "Changed Rate", amount: "0.5" }
+ spree_put :update, id: tax_rate.id,
+ tax_rate: { name: "Changed Rate", amount: "0.5" }
}.to change{ Spree::TaxRate.with_deleted.count }.by(1)
expect(response).to redirect_to spree.admin_tax_rates_url
@@ -58,7 +59,8 @@ module Spree
context "when included_in_price is changed" do
it "duplicates the record and soft-deletes the duplicate" do
expect {
- spree_put :update, id: tax_rate.id, tax_rate: { name: "Changed Rate", included_in_price: "1" }
+ spree_put :update, id: tax_rate.id,
+ tax_rate: { name: "Changed Rate", included_in_price: "1" }
}.to change{ Spree::TaxRate.with_deleted.count }.by(1)
expect(response).to redirect_to spree.admin_tax_rates_url
diff --git a/spec/controllers/spree/admin/variants_controller_spec.rb b/spec/controllers/spree/admin/variants_controller_spec.rb
index 7d13264599..09f34d14c8 100644
--- a/spec/controllers/spree/admin/variants_controller_spec.rb
+++ b/spec/controllers/spree/admin/variants_controller_spec.rb
@@ -69,17 +69,20 @@ module Spree
end
it 'deletes the variant' do
- spree_delete :destroy, id: variant.id, product_id: variant.product.permalink, format: 'html'
+ spree_delete :destroy, id: variant.id, product_id: variant.product.permalink,
+ format: 'html'
expect(variant).to have_received(:destroy)
end
it 'shows a success flash message' do
- spree_delete :destroy, id: variant.id, product_id: variant.product.permalink, format: 'html'
+ spree_delete :destroy, id: variant.id, product_id: variant.product.permalink,
+ format: 'html'
expect(flash[:success]).to be
end
it 'redirects to admin_product_variants_url' do
- spree_delete :destroy, id: variant.id, product_id: variant.product.permalink, format: 'html'
+ spree_delete :destroy, id: variant.id, product_id: variant.product.permalink,
+ format: 'html'
expect(response).to redirect_to spree.admin_product_variants_url(variant.product.permalink)
end
@@ -87,7 +90,8 @@ module Spree
exchange = create(:exchange)
variant.exchanges << exchange
- spree_delete :destroy, id: variant.id, product_id: variant.product.permalink, format: 'html'
+ spree_delete :destroy, id: variant.id, product_id: variant.product.permalink,
+ format: 'html'
expect(variant.exchanges.reload).to be_empty
end
end
diff --git a/spec/controllers/spree/credit_cards_controller_spec.rb b/spec/controllers/spree/credit_cards_controller_spec.rb
index d256c95479..15a69cbd30 100644
--- a/spec/controllers/spree/credit_cards_controller_spec.rb
+++ b/spec/controllers/spree/credit_cards_controller_spec.rb
@@ -30,7 +30,9 @@ describe Spree::CreditCardsController, type: :controller do
end
context "when the request to store the customer/card with Stripe is successful" do
- let(:response_mock) { { status: 200, body: JSON.generate(id: "cus_AZNMJ", default_source: "card_1AEEb") } }
+ let(:response_mock) {
+ { status: 200, body: JSON.generate(id: "cus_AZNMJ", default_source: "card_1AEEb") }
+ }
it "saves the card locally" do
spree_post :new_from_token, params
@@ -53,7 +55,8 @@ describe Spree::CreditCardsController, type: :controller do
expect{ spree_post :new_from_token, params }.to_not change(Spree::CreditCard, :count)
json_response = JSON.parse(response.body)
- flash_message = I18n.t(:spree_gateway_error_flash_for_checkout, error: I18n.t(:card_could_not_be_saved))
+ flash_message = I18n.t(:spree_gateway_error_flash_for_checkout,
+ error: I18n.t(:card_could_not_be_saved))
expect(json_response["flash"]["error"]).to eq flash_message
end
end
@@ -187,7 +190,8 @@ describe Spree::CreditCardsController, type: :controller do
it "deletes the card and redirects to account_path" do
expect{ spree_delete :destroy, params }.to change(Spree::CreditCard, :count).by(-1)
- expect(flash[:success]).to eq I18n.t(:card_has_been_removed, number: "x-#{card.last_digits}")
+ expect(flash[:success]).to eq I18n.t(:card_has_been_removed,
+ number: "x-#{card.last_digits}")
expect(response).to redirect_to spree.account_path(anchor: 'cards')
end
diff --git a/spec/controllers/spree/orders_controller_spec.rb b/spec/controllers/spree/orders_controller_spec.rb
index 7934617294..9b20dd9de8 100644
--- a/spec/controllers/spree/orders_controller_spec.rb
+++ b/spec/controllers/spree/orders_controller_spec.rb
@@ -13,7 +13,9 @@ describe Spree::OrdersController, type: :controller do
describe "viewing an order" do
let(:customer) { create(:customer) }
- let(:order) { create(:order_with_credit_payment, customer: customer, distributor: customer.enterprise) }
+ let(:order) {
+ create(:order_with_credit_payment, customer: customer, distributor: customer.enterprise)
+ }
before do
allow(controller).to receive(:spree_current_user) { current_user }
@@ -88,13 +90,15 @@ describe Spree::OrdersController, type: :controller do
state: "payment")
}
let(:payment_method) { create(:stripe_sca_payment_method) }
- let!(:payment) { create(
- :payment,
- payment_method: payment_method,
- cvv_response_message: "https://stripe.com/redirect",
- response_code: "pi_123",
- order: order,
- state: "pending")
+ let!(:payment) {
+ create(
+ :payment,
+ payment_method: payment_method,
+ cvv_response_message: "https://stripe.com/redirect",
+ response_code: "pi_123",
+ order: order,
+ state: "pending"
+ )
}
before do
@@ -165,7 +169,7 @@ describe Spree::OrdersController, type: :controller do
get :show, params: { id: order.number, payment_intent: payment_intent }
expect(response.status).to eq 200
- expect(flash[:error]).to eq("#{I18n.t("payment_could_not_process")}. error message")
+ expect(flash[:error]).to eq("#{I18n.t('payment_could_not_process')}. error message")
payment.reload
expect(payment.cvv_response_message).to eq("https://stripe.com/redirect")
expect(payment.state).to eq("pending")
@@ -190,7 +194,7 @@ describe Spree::OrdersController, type: :controller do
get :show, params: { id: order.number, payment_intent: payment_intent }
expect(response.status).to eq 200
- expect(flash[:error]).to eq("#{I18n.t("payment_could_not_process")}. ")
+ expect(flash[:error]).to eq("#{I18n.t('payment_could_not_process')}. ")
payment.reload
expect(payment.cvv_response_message).to eq("https://stripe.com/redirect")
expect(payment.state).to eq("pending")
@@ -244,7 +248,10 @@ describe Spree::OrdersController, type: :controller do
describe "when an item is in the cart" do
let(:order) { subject.current_order(true) }
let(:oc) { create(:simple_order_cycle, distributors: [d], variants: [variant]) }
- let(:d) { create(:distributor_enterprise, shipping_methods: [create(:shipping_method)], payment_methods: [create(:payment_method)]) }
+ let(:d) {
+ create(:distributor_enterprise, shipping_methods: [create(:shipping_method)],
+ payment_methods: [create(:payment_method)])
+ }
let(:variant) { create(:variant, on_demand: false, on_hand: 5) }
let(:line_item) { order.line_items.last }
@@ -335,8 +342,12 @@ describe Spree::OrdersController, type: :controller do
describe "removing items from a completed order" do
context "with shipping and transaction fees" do
- let(:distributor) { create(:distributor_enterprise, charges_sales_tax: true, allow_order_changes: true) }
- let(:shipping_tax_rate) { create(:tax_rate, amount: 0.25, included_in_price: true, zone: create(:zone_with_member)) }
+ let(:distributor) {
+ create(:distributor_enterprise, charges_sales_tax: true, allow_order_changes: true)
+ }
+ let(:shipping_tax_rate) {
+ create(:tax_rate, amount: 0.25, included_in_price: true, zone: create(:zone_with_member))
+ }
let(:shipping_tax_category) { create(:tax_category, tax_rates: [shipping_tax_rate]) }
let(:order) {
create(:completed_order_with_fees, distributor: distributor, shipping_fee: shipping_fee,
@@ -386,12 +397,16 @@ describe Spree::OrdersController, type: :controller do
let(:distributor) { create(:distributor_enterprise, allow_order_changes: true) }
let(:order_cycle) { create(:simple_order_cycle, distributors: [distributor]) }
let(:enterprise_fee) { create(:enterprise_fee, calculator: build(:calculator_per_item) ) }
- let!(:exchange) { create(:exchange, incoming: true, sender: variant1.product.supplier, receiver: order_cycle.coordinator, variants: [variant1, variant2], enterprise_fees: [enterprise_fee]) }
+ let!(:exchange) {
+ create(:exchange, incoming: true, sender: variant1.product.supplier,
+ receiver: order_cycle.coordinator, variants: [variant1, variant2], enterprise_fees: [enterprise_fee])
+ }
let!(:order) do
- order = create(:completed_order_with_totals, line_items_count: 2, user: user, distributor: distributor, order_cycle: order_cycle)
+ order = create(:completed_order_with_totals, line_items_count: 2, user: user,
+ distributor: distributor, order_cycle: order_cycle)
order.reload.line_items.first.update(variant_id: variant1.id)
order.reload.line_items.last.update(variant_id: variant2.id)
- while !order.completed? do break unless order.next! end
+ break unless order.next! while !order.completed?
order.recreate_all_fees!
order
end
@@ -568,7 +583,10 @@ describe Spree::OrdersController, type: :controller do
end
context "when the order is complete" do
- let(:order) { create(:completed_order_with_totals, user: user, distributor: create(:distributor_enterprise)) }
+ let(:order) {
+ create(:completed_order_with_totals, user: user,
+ distributor: create(:distributor_enterprise))
+ }
before do
setup_email
diff --git a/spec/controllers/spree/paypal_controller_spec.rb b/spec/controllers/spree/paypal_controller_spec.rb
index b239667772..babe102935 100644
--- a/spec/controllers/spree/paypal_controller_spec.rb
+++ b/spec/controllers/spree/paypal_controller_spec.rb
@@ -62,9 +62,11 @@ module Spree
let(:response) { true }
let(:provider_success_url) { "https://test.com/success" }
let(:response_mock) { double(:response, success?: response, errors: [] ) }
- let(:provider_mock) { double(:provider, build_set_express_checkout: true,
- set_express_checkout: response_mock,
- express_checkout_url: provider_success_url) }
+ let(:provider_mock) {
+ double(:provider, build_set_express_checkout: true,
+ set_express_checkout: response_mock,
+ express_checkout_url: provider_success_url)
+ }
before do
allow(controller).to receive(:current_order) { order }
@@ -74,7 +76,7 @@ module Spree
context "when processing is successful" do
it "redirects to a success URL generated by the payment provider" do
- expect(spree_post :express).to redirect_to provider_success_url
+ expect(spree_post(:express)).to redirect_to provider_success_url
end
end
@@ -82,7 +84,7 @@ module Spree
let(:response) { false }
it "redirects to checkout_state_path with a flash error" do
- expect(spree_post :express).to redirect_to checkout_state_path(:payment)
+ expect(spree_post(:express)).to redirect_to checkout_state_path(:payment)
expect(flash[:error]).to eq "PayPal failed. "
end
end
@@ -93,7 +95,7 @@ module Spree
end
it "redirects to checkout_state_path with a flash error" do
- expect(spree_post :express).to redirect_to checkout_state_path(:payment)
+ expect(spree_post(:express)).to redirect_to checkout_state_path(:payment)
expect(flash[:error]).to eq "Could not connect to PayPal."
end
end
diff --git a/spec/controllers/spree/user_sessions_controller_spec.rb b/spec/controllers/spree/user_sessions_controller_spec.rb
index 2b440e7af9..fcbca67cf3 100644
--- a/spec/controllers/spree/user_sessions_controller_spec.rb
+++ b/spec/controllers/spree/user_sessions_controller_spec.rb
@@ -13,7 +13,8 @@ describe Spree::UserSessionsController, type: :controller do
context "succeed" do
context "when referer is not '/checkout'" do
it "redirects to root" do
- spree_post :create, spree_user: { email: user.email, password: user.password }, use_route: :spree
+ spree_post :create, spree_user: { email: user.email, password: user.password },
+ use_route: :spree
expect(response).to redirect_to root_path
end
end
@@ -22,7 +23,8 @@ describe Spree::UserSessionsController, type: :controller do
before { @request.env['HTTP_REFERER'] = 'http://test.com/checkout' }
it "redirects to checkout" do
- spree_post :create, spree_user: { email: user.email, password: user.password }, use_route: :spree
+ spree_post :create, spree_user: { email: user.email, password: user.password },
+ use_route: :spree
expect(response).to redirect_to checkout_path
end
end
diff --git a/spec/controllers/spree/users_controller_spec.rb b/spec/controllers/spree/users_controller_spec.rb
index 4115860b33..a1855cea11 100644
--- a/spec/controllers/spree/users_controller_spec.rb
+++ b/spec/controllers/spree/users_controller_spec.rb
@@ -14,7 +14,9 @@ describe Spree::UsersController, type: :controller do
let!(:distributor2) { create(:distributor_enterprise) }
let!(:d1o1) { create(:completed_order_with_totals, distributor: distributor1, user_id: u1.id) }
let!(:d1o2) { create(:completed_order_with_totals, distributor: distributor1, user_id: u1.id) }
- let!(:d1_order_for_u2) { create(:completed_order_with_totals, distributor: distributor1, user_id: u2.id) }
+ let!(:d1_order_for_u2) {
+ create(:completed_order_with_totals, distributor: distributor1, user_id: u2.id)
+ }
let!(:d1o3) { create(:order, state: 'cart', distributor: distributor1, user_id: u1.id) }
let!(:d2o1) { create(:completed_order_with_totals, distributor: distributor2, user_id: u2.id) }
@@ -79,7 +81,9 @@ describe Spree::UsersController, type: :controller do
context '#create' do
it 'should create a new user' do
- post :create, params: { user: { email: 'foobar@example.com', password: 'foobar123', password_confirmation: 'foobar123' } }
+ post :create,
+ params: { user: { email: 'foobar@example.com', password: 'foobar123',
+ password_confirmation: 'foobar123' } }
expect(assigns[:user].new_record?).to be_falsey
end
end
diff --git a/spec/controllers/stripe/callbacks_controller_spec.rb b/spec/controllers/stripe/callbacks_controller_spec.rb
index b1c4abcf2c..a744ec0d09 100644
--- a/spec/controllers/stripe/callbacks_controller_spec.rb
+++ b/spec/controllers/stripe/callbacks_controller_spec.rb
@@ -46,7 +46,8 @@ describe Stripe::CallbacksController, type: :controller do
allow(connector).to receive(:enterprise) { enterprise }
spree_get :index, params
expect(flash[:notice]).to eq I18n.t('admin.controllers.enterprises.stripe_connect_cancelled')
- expect(response).to redirect_to edit_admin_enterprise_path(enterprise, anchor: 'payment_methods')
+ expect(response).to redirect_to edit_admin_enterprise_path(enterprise,
+ anchor: 'payment_methods')
end
end
@@ -57,7 +58,8 @@ describe Stripe::CallbacksController, type: :controller do
allow(connector).to receive(:enterprise) { enterprise }
spree_get :index, params
expect(flash[:error]).to eq I18n.t('admin.controllers.enterprises.stripe_connect_fail')
- expect(response).to redirect_to edit_admin_enterprise_path(enterprise, anchor: 'payment_methods')
+ expect(response).to redirect_to edit_admin_enterprise_path(enterprise,
+ anchor: 'payment_methods')
end
end
end
@@ -69,7 +71,8 @@ describe Stripe::CallbacksController, type: :controller do
allow(connector).to receive(:enterprise) { enterprise }
spree_get :index, params
expect(flash[:success]).to eq I18n.t('admin.controllers.enterprises.stripe_connect_success')
- expect(response).to redirect_to edit_admin_enterprise_path(enterprise, anchor: 'payment_methods')
+ expect(response).to redirect_to edit_admin_enterprise_path(enterprise,
+ anchor: 'payment_methods')
end
end
end
diff --git a/spec/controllers/stripe/webhooks_controller_spec.rb b/spec/controllers/stripe/webhooks_controller_spec.rb
index c8390ca6e1..c993f91d35 100644
--- a/spec/controllers/stripe/webhooks_controller_spec.rb
+++ b/spec/controllers/stripe/webhooks_controller_spec.rb
@@ -17,7 +17,8 @@ describe Stripe::WebhooksController, type: :controller do
context "when invalid json is provided" do
before do
- allow(Stripe::Webhook).to receive(:construct_event).and_raise JSON::ParserError, "parsing failed"
+ allow(Stripe::Webhook).to receive(:construct_event).and_raise JSON::ParserError,
+ "parsing failed"
end
it "responds with a 400" do
@@ -28,7 +29,9 @@ describe Stripe::WebhooksController, type: :controller do
context "when event signature verification fails" do
before do
- allow(Stripe::Webhook).to receive(:construct_event).and_raise Stripe::SignatureVerificationError.new("verfication failed", "header")
+ allow(Stripe::Webhook).to receive(:construct_event).and_raise Stripe::SignatureVerificationError.new(
+ "verfication failed", "header"
+ )
end
it "responds with a 401" do
diff --git a/spec/controllers/user_passwords_controller_spec.rb b/spec/controllers/user_passwords_controller_spec.rb
index db4700b4f2..c90a2a3917 100644
--- a/spec/controllers/user_passwords_controller_spec.rb
+++ b/spec/controllers/user_passwords_controller_spec.rb
@@ -53,7 +53,8 @@ describe UserPasswordsController, type: :controller do
end
it "returns error when user is unconfirmed" do
- post :create, xhr: true, params: { spree_user: { email: unconfirmed_user.email }, use_route: :spree }
+ post :create, xhr: true,
+ params: { spree_user: { email: unconfirmed_user.email }, use_route: :spree }
expect(response.status).to eq 401
expect(json_response).to eq 'error' => I18n.t('email_unconfirmed')
end
diff --git a/spec/factories/line_item_factory.rb b/spec/factories/line_item_factory.rb
index d67dcdf24b..6f8fb04972 100644
--- a/spec/factories/line_item_factory.rb
+++ b/spec/factories/line_item_factory.rb
@@ -19,7 +19,8 @@ FactoryBot.define do
if shipment.nil?
shipping_method = evaluator.shipping_method
unless shipping_method
- shipping_method = create(:shipping_method_with, :shipping_fee, shipping_fee: evaluator.shipping_fee)
+ shipping_method = create(:shipping_method_with, :shipping_fee,
+ shipping_fee: evaluator.shipping_fee)
shipping_method.distributors << line_item.order.distributor if line_item.order.distributor
end
shipment = create(:shipment_with, :shipping_method, shipping_method: shipping_method,
diff --git a/spec/factories/order_cycle_factory.rb b/spec/factories/order_cycle_factory.rb
index fadce85de2..62425f518f 100644
--- a/spec/factories/order_cycle_factory.rb
+++ b/spec/factories/order_cycle_factory.rb
@@ -13,7 +13,7 @@ FactoryBot.define do
}
end
- after(:create) do |oc, proxy|
+ after(:create) do |_oc, proxy|
proxy.exchanges.incoming.each do |exchange|
ExchangeFee.create!(
exchange: exchange,
diff --git a/spec/factories/order_factory.rb b/spec/factories/order_factory.rb
index 1fc3156897..bde16360c1 100644
--- a/spec/factories/order_factory.rb
+++ b/spec/factories/order_factory.rb
@@ -93,10 +93,10 @@ FactoryBot.define do
payment_method: evaluator.payment_method)
order.recreate_all_fees!
order.ship_address = evaluator.ship_address
- while !order.delivery? do break unless a = order.next! end
+ break unless a = order.next! while !order.delivery?
order.select_shipping_method(evaluator.shipping_method.id)
- while !order.completed? do break unless a = order.next! end
+ break unless a = order.next! while !order.completed?
end
end
end
@@ -129,7 +129,7 @@ FactoryBot.define do
create(:payment, state: "checkout", order: order, amount: order.total,
payment_method: evaluator.payment_method)
order.ship_address = evaluator.ship_address
- while !order.completed? do break unless order.next! end
+ break unless order.next! while !order.completed?
order.update_columns(
completed_at: evaluator.completed_at,
@@ -174,7 +174,8 @@ FactoryBot.define do
end
after(:create) do |order, evaluator|
- create(:payment, amount: order.total + evaluator.credit_amount, order: order, state: "completed")
+ create(:payment, amount: order.total + evaluator.credit_amount, order: order,
+ state: "completed")
order.reload
end
end
@@ -188,7 +189,8 @@ FactoryBot.define do
end
after(:create) do |order, evaluator|
- create(:payment, amount: order.total - evaluator.unpaid_amount, order: order, state: "completed")
+ create(:payment, amount: order.total - evaluator.unpaid_amount, order: order,
+ state: "completed")
order.reload
end
end
@@ -220,7 +222,7 @@ FactoryBot.define do
tax_category: evaluator.shipping_tax_category)
order.reload
- while !order.completed? do break unless order.next! end
+ break unless order.next! while !order.completed?
order.reload
end
end
diff --git a/spec/factories/shipment_factory.rb b/spec/factories/shipment_factory.rb
index c17c6b3fe4..9eb6bee44d 100644
--- a/spec/factories/shipment_factory.rb
+++ b/spec/factories/shipment_factory.rb
@@ -17,7 +17,9 @@ FactoryBot.define do
shipment.add_shipping_method(create(:shipping_method), true)
shipment.order.line_items.each do |line_item|
- line_item.quantity.times { shipment.inventory_units.create(variant_id: line_item.variant_id) }
+ line_item.quantity.times {
+ shipment.inventory_units.create(variant_id: line_item.variant_id)
+ }
end
end
end
diff --git a/spec/factories/stock_location_factory.rb b/spec/factories/stock_location_factory.rb
index ac32b2e514..89f4d87084 100644
--- a/spec/factories/stock_location_factory.rb
+++ b/spec/factories/stock_location_factory.rb
@@ -16,7 +16,8 @@ FactoryBot.define do
country { |stock_location| Spree::Country.first || stock_location.association(:country) }
state do |stock_location|
- stock_location.country.states.first || stock_location.association(:state, country: stock_location.country)
+ stock_location.country.states.first || stock_location.association(:state,
+ country: stock_location.country)
end
factory :stock_location_with_items do
diff --git a/spec/factories/user_factory.rb b/spec/factories/user_factory.rb
index 7404e56c67..ff5c1d8844 100644
--- a/spec/factories/user_factory.rb
+++ b/spec/factories/user_factory.rb
@@ -14,7 +14,11 @@ FactoryBot.define do
login { email }
password { 'secret' }
password_confirmation { password }
- authentication_token { generate(:user_authentication_token) } if Spree.user_class.attribute_method? :authentication_token
+ if Spree.user_class.attribute_method? :authentication_token
+ authentication_token {
+ generate(:user_authentication_token)
+ }
+ end
confirmation_sent_at { '1970-01-01 00:00:00' }
confirmed_at { '1970-01-01 00:00:01' }
diff --git a/spec/features/admin/adjustments_spec.rb b/spec/features/admin/adjustments_spec.rb
index 9e6b192bc3..887a4bd59e 100644
--- a/spec/features/admin/adjustments_spec.rb
+++ b/spec/features/admin/adjustments_spec.rb
@@ -13,8 +13,14 @@ feature '
let!(:distributor) { create(:distributor_enterprise, charges_sales_tax: true) }
let!(:order_cycle) { create(:simple_order_cycle, distributors: [distributor]) }
- let!(:order) { create(:order_with_totals_and_distribution, user: user, distributor: distributor, order_cycle: order_cycle, state: 'complete', payment_state: 'balance_due') }
- let!(:tax_rate) { create(:tax_rate, name: 'GST', calculator: build(:calculator, preferred_amount: 10), zone: create(:zone_with_member)) }
+ let!(:order) {
+ create(:order_with_totals_and_distribution, user: user, distributor: distributor,
+ order_cycle: order_cycle, state: 'complete', payment_state: 'balance_due')
+ }
+ let!(:tax_rate) {
+ create(:tax_rate, name: 'GST', calculator: build(:calculator, preferred_amount: 10),
+ zone: create(:zone_with_member))
+ }
before do
order.finalize!
@@ -43,7 +49,7 @@ feature '
scenario "modifying taxed adjustments on an order" do
# Given a taxed adjustment
adjustment = create(:adjustment, label: "Extra Adjustment", adjustable: order,
- amount: 110, included_tax: 10, order: order)
+ amount: 110, included_tax: 10, order: order)
# When I go to the adjustments page for the order
login_as_admin_and_visit spree.admin_orders_path
@@ -67,7 +73,7 @@ feature '
scenario "modifying an untaxed adjustment on an order" do
# Given an untaxed adjustment
adjustment = create(:adjustment, label: "Extra Adjustment", adjustable: order,
- amount: 110, included_tax: 0, order: order)
+ amount: 110, included_tax: 0, order: order)
# When I go to the adjustments page for the order
login_as_admin_and_visit spree.admin_orders_path
@@ -91,7 +97,7 @@ feature '
scenario "viewing adjustments on a canceled order" do
# Given a taxed adjustment
adjustment = create(:adjustment, label: "Extra Adjustment", adjustable: order,
- amount: 110, included_tax: 10, order: order)
+ amount: 110, included_tax: 10, order: order)
order.cancel!
login_as_admin_and_visit spree.edit_admin_order_path(order)
diff --git a/spec/features/admin/bulk_order_management_spec.rb b/spec/features/admin/bulk_order_management_spec.rb
index 943171eef5..abc53c2f69 100644
--- a/spec/features/admin/bulk_order_management_spec.rb
+++ b/spec/features/admin/bulk_order_management_spec.rb
@@ -40,10 +40,18 @@ feature '
end
context "displaying individual columns" do
- let!(:o1) { create(:order_with_distributor, state: 'complete', completed_at: Time.zone.now, bill_address: create(:address) ) }
- let!(:o2) { create(:order_with_distributor, state: 'complete', completed_at: Time.zone.now, bill_address: nil ) }
+ let!(:o1) {
+ create(:order_with_distributor, state: 'complete', completed_at: Time.zone.now,
+ bill_address: create(:address) )
+ }
+ let!(:o2) {
+ create(:order_with_distributor, state: 'complete', completed_at: Time.zone.now,
+ bill_address: nil )
+ }
let!(:li1) { create(:line_item_with_shipment, order: o1) }
- let!(:li2) { create(:line_item_with_shipment, order: o2, product: create(:product_with_option_types) ) }
+ let!(:li2) {
+ create(:line_item_with_shipment, order: o2, product: create(:product_with_option_types) )
+ }
before :each do
visit_bulk_order_management
@@ -56,9 +64,12 @@ feature '
end
it "displays a column for order date" do
- expect(page).to have_selector "th.date", text: I18n.t("admin.orders.bulk_management.order_date").upcase, visible: true
- expect(page).to have_selector "td.date", text: o1.completed_at.strftime('%B %d, %Y'), visible: true
- expect(page).to have_selector "td.date", text: o2.completed_at.strftime('%B %d, %Y'), visible: true
+ expect(page).to have_selector "th.date",
+ text: I18n.t("admin.orders.bulk_management.order_date").upcase, visible: true
+ expect(page).to have_selector "td.date", text: o1.completed_at.strftime('%B %d, %Y'),
+ visible: true
+ expect(page).to have_selector "td.date", text: o2.completed_at.strftime('%B %d, %Y'),
+ visible: true
end
it "displays a column for producer" do
@@ -70,7 +81,8 @@ feature '
it "displays a column for variant description, which shows only product name when options text is blank" do
expect(page).to have_selector "th.variant", text: "PRODUCT: UNIT", visible: true
expect(page).to have_selector "td.variant", text: li1.product.name, visible: true
- expect(page).to have_selector "td.variant", text: (li2.product.name + ": " + li2.variant.options_text), visible: true
+ expect(page).to have_selector "td.variant",
+ text: (li2.product.name + ": " + li2.variant.options_text), visible: true
end
it "displays a field for quantity" do
@@ -103,8 +115,10 @@ feature '
click_on "Name"
end
- expect(page).to have_selector("#listing_orders .line_item:nth-child(1) .full_name", text: customer_names[0])
- expect(page).to have_selector("#listing_orders .line_item:nth-child(2) .full_name", text: customer_names[1])
+ expect(page).to have_selector("#listing_orders .line_item:nth-child(1) .full_name",
+ text: customer_names[0])
+ expect(page).to have_selector("#listing_orders .line_item:nth-child(2) .full_name",
+ text: customer_names[1])
end
it "sorts by customer name in reverse when the customer name header is clicked twice" do
@@ -115,8 +129,10 @@ feature '
click_on "Name"
end
- expect(page).to have_selector("#listing_orders .line_item:nth-child(1) .full_name", text: customer_names[1])
- expect(page).to have_selector("#listing_orders .line_item:nth-child(2) .full_name", text: customer_names[0])
+ expect(page).to have_selector("#listing_orders .line_item:nth-child(1) .full_name",
+ text: customer_names[1])
+ expect(page).to have_selector("#listing_orders .line_item:nth-child(2) .full_name",
+ text: customer_names[0])
end
end
end
@@ -182,10 +198,16 @@ feature '
login_as_admin
end
- let!(:p1) { create(:product_with_option_types, group_buy: true, group_buy_unit_size: 5000, variant_unit: "weight", variants: [create(:variant, unit_value: 1000)] ) }
+ let!(:p1) {
+ create(:product_with_option_types, group_buy: true, group_buy_unit_size: 5000,
+ variant_unit: "weight", variants: [create(:variant, unit_value: 1000)] )
+ }
let!(:v1) { p1.variants.first }
let!(:o1) { create(:order_with_distributor, state: 'complete', completed_at: Time.zone.now ) }
- let!(:li1) { create(:line_item_with_shipment, order: o1, variant: v1, quantity: 5, final_weight_volume: 1000, price: 10.00 ) }
+ let!(:li1) {
+ create(:line_item_with_shipment, order: o1, variant: v1, quantity: 5, final_weight_volume: 1000,
+ price: 10.00 )
+ }
before { v1.update_attribute(:on_hand, 100) }
@@ -225,7 +247,8 @@ feature '
within "tr#li_#{li1.id}" do
expect(page).to have_field "final_weight_volume", with: li1.final_weight_volume.round.to_s
fill_in "quantity", with: 6
- expect(page).to have_field "final_weight_volume", with: ((li1.final_weight_volume * 6) / 5).round.to_s
+ expect(page).to have_field "final_weight_volume",
+ with: ((li1.final_weight_volume * 6) / 5).round.to_s
end
end
end
@@ -235,7 +258,8 @@ feature '
visit_bulk_order_management
expect(page).to have_selector "th", text: "NAME"
- expect(page).to have_selector "th", text: I18n.t("admin.orders.bulk_management.order_date").upcase
+ expect(page).to have_selector "th",
+ text: I18n.t("admin.orders.bulk_management.order_date").upcase
expect(page).to have_selector "th", text: "PRODUCER"
expect(page).to have_selector "th", text: "PRODUCT: UNIT"
expect(page).to have_selector "th", text: "QUANTITY"
@@ -245,7 +269,8 @@ feature '
expect(page).to have_no_selector "th", text: "PRODUCER"
expect(page).to have_selector "th", text: "NAME"
- expect(page).to have_selector "th", text: I18n.t("admin.orders.bulk_management.order_date").upcase
+ expect(page).to have_selector "th",
+ text: I18n.t("admin.orders.bulk_management.order_date").upcase
expect(page).to have_selector "th", text: "PRODUCT: UNIT"
expect(page).to have_selector "th", text: "QUANTITY"
expect(page).to have_selector "th", text: "MAX"
@@ -256,9 +281,16 @@ feature '
context "supplier filter" do
let!(:s1) { create(:supplier_enterprise) }
let!(:s2) { create(:supplier_enterprise) }
- let!(:o1) { create(:order_with_distributor, state: 'complete', completed_at: Time.zone.now, order_cycle: create(:simple_order_cycle) ) }
- let!(:li1) { create(:line_item_with_shipment, order: o1, product: create(:product, supplier: s1) ) }
- let!(:li2) { create(:line_item_with_shipment, order: o1, product: create(:product, supplier: s2) ) }
+ let!(:o1) {
+ create(:order_with_distributor, state: 'complete', completed_at: Time.zone.now,
+ order_cycle: create(:simple_order_cycle) )
+ }
+ let!(:li1) {
+ create(:line_item_with_shipment, order: o1, product: create(:product, supplier: s1) )
+ }
+ let!(:li2) {
+ create(:line_item_with_shipment, order: o1, product: create(:product, supplier: s2) )
+ }
before :each do
visit_bulk_order_management
@@ -293,8 +325,14 @@ feature '
context "distributor filter" do
let!(:d1) { create(:distributor_enterprise) }
let!(:d2) { create(:distributor_enterprise) }
- let!(:o1) { create(:order_with_distributor, state: 'complete', completed_at: Time.zone.now, distributor: d1, order_cycle: create(:simple_order_cycle) ) }
- let!(:o2) { create(:order_with_distributor, state: 'complete', completed_at: Time.zone.now, distributor: d2, order_cycle: create(:simple_order_cycle) ) }
+ let!(:o1) {
+ create(:order_with_distributor, state: 'complete', completed_at: Time.zone.now, distributor: d1,
+ order_cycle: create(:simple_order_cycle) )
+ }
+ let!(:o2) {
+ create(:order_with_distributor, state: 'complete', completed_at: Time.zone.now, distributor: d2,
+ order_cycle: create(:simple_order_cycle) )
+ }
let!(:li1) { create(:line_item_with_shipment, order: o1 ) }
let!(:li2) { create(:line_item_with_shipment, order: o2 ) }
@@ -330,8 +368,14 @@ feature '
let!(:distributor) { create(:distributor_enterprise) }
let!(:oc1) { create(:simple_order_cycle, distributors: [distributor]) }
let!(:oc2) { create(:simple_order_cycle, distributors: [distributor]) }
- let!(:o1) { create(:order_with_distributor, state: 'complete', completed_at: Time.zone.now, order_cycle: oc1 ) }
- let!(:o2) { create(:order_with_distributor, state: 'complete', completed_at: Time.zone.now, order_cycle: oc2 ) }
+ let!(:o1) {
+ create(:order_with_distributor, state: 'complete', completed_at: Time.zone.now,
+ order_cycle: oc1 )
+ }
+ let!(:o2) {
+ create(:order_with_distributor, state: 'complete', completed_at: Time.zone.now,
+ order_cycle: oc2 )
+ }
let!(:li1) { create(:line_item_with_shipment, order: o1 ) }
let!(:li2) { create(:line_item_with_shipment, order: o2 ) }
@@ -342,7 +386,8 @@ feature '
it "displays a select box for order cycles, which filters line items by the selected order cycle" do
expect(page).to have_selector "tr#li_#{li1.id}"
expect(page).to have_selector "tr#li_#{li2.id}"
- expect(page).to have_select2 'order_cycle_filter', with_options: OrderCycle.pluck(:name).unshift("All")
+ expect(page).to have_select2 'order_cycle_filter',
+ with_options: OrderCycle.pluck(:name).unshift("All")
select2_select oc1.name, from: "order_cycle_filter"
expect(page).to have_no_selector "#loading img.spinner"
expect(page).to have_selector "tr#li_#{li1.id}"
@@ -370,8 +415,14 @@ feature '
let!(:oc2) { create(:simple_order_cycle, suppliers: [s2], distributors: [d2] ) }
let!(:p1) { create(:product, supplier: s1) }
let!(:p2) { create(:product, supplier: s2) }
- let!(:o1) { create(:order_with_distributor, state: 'complete', completed_at: Time.zone.now, distributor: d1, order_cycle: oc1 ) }
- let!(:o2) { create(:order_with_distributor, state: 'complete', completed_at: Time.zone.now, distributor: d2, order_cycle: oc2 ) }
+ let!(:o1) {
+ create(:order_with_distributor, state: 'complete', completed_at: Time.zone.now, distributor: d1,
+ order_cycle: oc1 )
+ }
+ let!(:o2) {
+ create(:order_with_distributor, state: 'complete', completed_at: Time.zone.now, distributor: d2,
+ order_cycle: oc2 )
+ }
let!(:li1) { create(:line_item_with_shipment, order: o1, product: p1 ) }
let!(:li2) { create(:line_item_with_shipment, order: o2, product: p2 ) }
@@ -441,10 +492,20 @@ feature '
end
context "using date restriction controls" do
- let!(:o1) { create(:order_with_distributor, state: 'complete', completed_at: Time.zone.today - 7.days - 1.second) }
- let!(:o2) { create(:order_with_distributor, state: 'complete', completed_at: Time.zone.today - 7.days) }
- let!(:o3) { create(:order_with_distributor, state: 'complete', completed_at: Time.zone.now.end_of_day) }
- let!(:o4) { create(:order_with_distributor, state: 'complete', completed_at: Time.zone.now.end_of_day + 1.second) }
+ let!(:o1) {
+ create(:order_with_distributor, state: 'complete',
+ completed_at: Time.zone.today - 7.days - 1.second)
+ }
+ let!(:o2) {
+ create(:order_with_distributor, state: 'complete', completed_at: Time.zone.today - 7.days)
+ }
+ let!(:o3) {
+ create(:order_with_distributor, state: 'complete', completed_at: Time.zone.now.end_of_day)
+ }
+ let!(:o4) {
+ create(:order_with_distributor, state: 'complete',
+ completed_at: Time.zone.now.end_of_day + 1.second)
+ }
let!(:li1) { create(:line_item_with_shipment, order: o1, quantity: 1 ) }
let!(:li2) { create(:line_item_with_shipment, order: o2, quantity: 2 ) }
let!(:li3) { create(:line_item_with_shipment, order: o3, quantity: 3 ) }
@@ -495,7 +556,8 @@ feature '
end
it "shows a dialog and ignores changes when confirm dialog is accepted" do
- page.driver.accept_modal :confirm, text: "Unsaved changes exist and will be lost if you continue." do
+ page.driver.accept_modal :confirm,
+ text: "Unsaved changes exist and will be lost if you continue." do
find('#start_date_filter').click
select_date_from_datepicker Time.zone.today - 9.days
end
@@ -506,7 +568,8 @@ feature '
end
it "shows a dialog and keeps changes when confirm dialog is rejected" do
- page.driver.dismiss_modal :confirm, text: "Unsaved changes exist and will be lost if you continue." do
+ page.driver.dismiss_modal :confirm,
+ text: "Unsaved changes exist and will be lost if you continue." do
find('#start_date_filter').click
select_date_from_datepicker Time.zone.today - 9.days
end
@@ -535,16 +598,22 @@ feature '
it "displays a checkbox to which toggles the 'checked' state of all checkboxes" do
check "toggle_bulk"
- page.all("input[type='checkbox'][name='bulk']").each{ |checkbox| expect(checkbox.checked?).to be true }
+ page.all("input[type='checkbox'][name='bulk']").each{ |checkbox|
+ expect(checkbox.checked?).to be true
+ }
uncheck "toggle_bulk"
- page.all("input[type='checkbox'][name='bulk']").each{ |checkbox| expect(checkbox.checked?).to be false }
+ page.all("input[type='checkbox'][name='bulk']").each{ |checkbox|
+ expect(checkbox.checked?).to be false
+ }
end
it "displays a bulk action select box with a list of actions" do
list_of_actions = ['Delete Selected']
find("div#bulk-actions-dropdown").click
within("div#bulk-actions-dropdown") do
- list_of_actions.each { |action_name| expect(page).to have_selector "div.menu_item", text: action_name }
+ list_of_actions.each { |action_name|
+ expect(page).to have_selector "div.menu_item", text: action_name
+ }
end
end
@@ -593,8 +662,14 @@ feature '
context "using action buttons" do
context "using edit buttons" do
let(:address) { create(:address) }
- let!(:o1) { create(:order_with_distributor, ship_address: address, state: 'complete', completed_at: Time.zone.now ) }
- let!(:o2) { create(:order_with_distributor, ship_address: address, state: 'complete', completed_at: Time.zone.now ) }
+ let!(:o1) {
+ create(:order_with_distributor, ship_address: address, state: 'complete',
+ completed_at: Time.zone.now )
+ }
+ let!(:o2) {
+ create(:order_with_distributor, ship_address: address, state: 'complete',
+ completed_at: Time.zone.now )
+ }
let!(:li1) { create(:line_item_with_shipment, order: o1 ) }
let!(:li2) { create(:line_item_with_shipment, order: o2 ) }
@@ -606,7 +681,8 @@ feature '
expect(page).to have_selector "a.edit-order", count: 2
# Shows a confirm dialog when unsaved changes exist
- page.driver.dismiss_modal :confirm, text: "Unsaved changes exist and will be lost if you continue." do
+ page.driver.dismiss_modal :confirm,
+ text: "Unsaved changes exist and will be lost if you continue." do
within "tr#li_#{li1.id}" do
fill_in "quantity", with: (li1.quantity + 1)
find("a.edit-order").click
@@ -628,8 +704,12 @@ feature '
end
context "using delete buttons" do
- let!(:o1) { create(:order_with_distributor, state: 'complete', completed_at: Time.zone.now ) }
- let!(:o2) { create(:order_with_distributor, state: 'complete', completed_at: Time.zone.now ) }
+ let!(:o1) {
+ create(:order_with_distributor, state: 'complete', completed_at: Time.zone.now )
+ }
+ let!(:o2) {
+ create(:order_with_distributor, state: 'complete', completed_at: Time.zone.now )
+ }
let!(:li1) { create(:line_item_with_shipment, order: o1 ) }
let!(:li2) { create(:line_item_with_shipment, order: o2 ) }
@@ -655,11 +735,18 @@ feature '
let!(:o2) { create(:order_with_distributor, state: 'complete', completed_at: Time.zone.now ) }
let!(:li1) { create(:line_item_with_shipment, order: o1 ) }
let!(:li2) { create(:line_item_with_shipment, order: o2 ) }
- let!(:p3) { create(:product_with_option_types, group_buy: true, group_buy_unit_size: 5000, variant_unit: "weight", variants: [create(:variant, unit_value: 1000)] ) }
+ let!(:p3) {
+ create(:product_with_option_types, group_buy: true, group_buy_unit_size: 5000,
+ variant_unit: "weight", variants: [create(:variant, unit_value: 1000)] )
+ }
let!(:v3) { p3.variants.first }
let!(:o3) { create(:order_with_distributor, state: 'complete', completed_at: Time.zone.now ) }
- let!(:li3) { create(:line_item_with_shipment, order: o3, variant: v3, quantity: 3, max_quantity: 6 ) }
- let!(:li4) { create(:line_item_with_shipment, order: o2, variant: v3, quantity: 1, max_quantity: 3 ) }
+ let!(:li3) {
+ create(:line_item_with_shipment, order: o3, variant: v3, quantity: 3, max_quantity: 6 )
+ }
+ let!(:li4) {
+ create(:line_item_with_shipment, order: o2, variant: v3, quantity: 1, max_quantity: 3 )
+ }
before :each do
visit_bulk_order_management
@@ -717,10 +804,20 @@ feature '
let(:s1) { create(:supplier_enterprise, name: 'First Supplier') }
let(:d1) { create(:distributor_enterprise, name: 'First Distributor') }
let(:d2) { create(:distributor_enterprise, name: 'Another Distributor') }
- let!(:o1) { create(:order_with_distributor, state: 'complete', completed_at: Time.zone.now, distributor: d1 ) }
- let!(:o2) { create(:order_with_distributor, state: 'complete', completed_at: Time.zone.now, distributor: d2 ) }
- let!(:line_item_distributed) { create(:line_item_with_shipment, order: o1, product: create(:product, supplier: s1) ) }
- let!(:line_item_not_distributed) { create(:line_item_with_shipment, order: o2, product: create(:product, supplier: s1) ) }
+ let!(:o1) {
+ create(:order_with_distributor, state: 'complete', completed_at: Time.zone.now,
+ distributor: d1 )
+ }
+ let!(:o2) {
+ create(:order_with_distributor, state: 'complete', completed_at: Time.zone.now,
+ distributor: d2 )
+ }
+ let!(:line_item_distributed) {
+ create(:line_item_with_shipment, order: o1, product: create(:product, supplier: s1) )
+ }
+ let!(:line_item_not_distributed) {
+ create(:line_item_with_shipment, order: o2, product: create(:product, supplier: s1) )
+ }
before(:each) do
@enterprise_user = create(:user)
diff --git a/spec/features/admin/bulk_product_update_spec.rb b/spec/features/admin/bulk_product_update_spec.rb
index 607199b860..018a77eae6 100644
--- a/spec/features/admin/bulk_product_update_spec.rb
+++ b/spec/features/admin/bulk_product_update_spec.rb
@@ -40,8 +40,10 @@ feature '
visit spree.admin_products_path
- expect(page).to have_select "producer_id", with_options: [s1.name, s2.name, s3.name], selected: s2.name
- expect(page).to have_select "producer_id", with_options: [s1.name, s2.name, s3.name], selected: s3.name
+ expect(page).to have_select "producer_id", with_options: [s1.name, s2.name, s3.name],
+ selected: s2.name
+ expect(page).to have_select "producer_id", with_options: [s1.name, s2.name, s3.name],
+ selected: s3.name
end
it "displays a date input for available_on for each product, formatted to yyyy-mm-dd hh:mm:ss" do
@@ -84,7 +86,8 @@ feature '
end
it "displays a select box for the unit of measure for the product's variants" do
- p = FactoryBot.create(:product, variant_unit: 'weight', variant_unit_scale: 1, variant_unit_name: '')
+ p = FactoryBot.create(:product, variant_unit: 'weight', variant_unit_scale: 1,
+ variant_unit_name: '')
visit spree.admin_products_path
@@ -92,7 +95,8 @@ feature '
end
it "displays a text field for the item name when unit is set to 'Items'" do
- p = FactoryBot.create(:product, variant_unit: 'items', variant_unit_scale: nil, variant_unit_name: 'packet')
+ p = FactoryBot.create(:product, variant_unit: 'items', variant_unit_scale: nil,
+ variant_unit_name: 'packet')
visit spree.admin_products_path
@@ -135,7 +139,8 @@ feature '
expect(page).to have_selector "a.view-variants", count: 1
all("a.view-variants").each(&:click)
- expect(page).to have_selector "span[name='on_hand']", text: p1.variants.to_a.sum(&:on_hand).to_s
+ expect(page).to have_selector "span[name='on_hand']",
+ text: p1.variants.to_a.sum(&:on_hand).to_s
expect(page).to have_field "variant_on_hand", with: "15"
expect(page).to have_field "variant_on_hand", with: "6"
end
@@ -155,9 +160,12 @@ feature '
end
it "displays a unit value field (for each variant) for each product" do
- p1 = FactoryBot.create(:product, price: 2.0, variant_unit: "weight", variant_unit_scale: "1000")
- v1 = FactoryBot.create(:variant, product: p1, is_master: false, price: 12.75, unit_value: 1200, unit_description: "(small bag)", display_as: "bag")
- v2 = FactoryBot.create(:variant, product: p1, is_master: false, price: 2.50, unit_value: 4800, unit_description: "(large bag)", display_as: "bin")
+ p1 = FactoryBot.create(:product, price: 2.0, variant_unit: "weight",
+ variant_unit_scale: "1000")
+ v1 = FactoryBot.create(:variant, product: p1, is_master: false, price: 12.75,
+ unit_value: 1200, unit_description: "(small bag)", display_as: "bag")
+ v2 = FactoryBot.create(:variant, product: p1, is_master: false, price: 2.50,
+ unit_value: 4800, unit_description: "(large bag)", display_as: "bin")
visit spree.admin_products_path
expect(page).to have_selector "a.view-variants", count: 1
@@ -271,7 +279,8 @@ feature '
s2 = FactoryBot.create(:supplier_enterprise)
t1 = FactoryBot.create(:taxon)
t2 = FactoryBot.create(:taxon)
- p = FactoryBot.create(:product, supplier: s1, available_on: Date.current, variant_unit: 'volume', variant_unit_scale: 1, primary_taxon: t2, sku: "OLD SKU")
+ p = FactoryBot.create(:product, supplier: s1, available_on: Date.current,
+ variant_unit: 'volume', variant_unit_scale: 1, primary_taxon: t2, sku: "OLD SKU")
login_as_admin
visit spree.admin_products_path
@@ -560,7 +569,9 @@ feature '
end
uri = URI.parse(current_url)
- expect("#{uri.path}?#{uri.query}").to eq spree.edit_admin_product_path(v1.product.permalink, producerFilter: p1.supplier.id)
+ expect("#{uri.path}?#{uri.query}").to eq spree.edit_admin_product_path(
+ v1.product.permalink, producerFilter: p1.supplier.id
+ )
end
it "shows an edit button for variants, which takes the user to the standard edit page for that variant" do
@@ -574,7 +585,9 @@ feature '
end
uri = URI.parse(current_url)
- expect(URI.parse(current_url).path).to eq spree.edit_admin_product_variant_path(v1.product.permalink, v1.id)
+ expect(URI.parse(current_url).path).to eq spree.edit_admin_product_variant_path(
+ v1.product.permalink, v1.id
+ )
end
it "shows an edit button for variants, which takes the user to the standard edit page for that variant, url includes selected filter" do
@@ -592,7 +605,9 @@ feature '
end
uri = URI.parse(current_url)
- expect("#{uri.path}?#{uri.query}").to eq spree.edit_admin_product_variant_path(v1.product.permalink, v1.id, producerFilter: p1.supplier.id)
+ expect("#{uri.path}?#{uri.query}").to eq spree.edit_admin_product_variant_path(
+ v1.product.permalink, v1.id, producerFilter: p1.supplier.id
+ )
end
end
@@ -691,8 +706,12 @@ feature '
let(:distributor_unmanaged) { create(:distributor_enterprise, name: 'Distributor Unmanaged') }
let!(:product_supplied) { create(:product, supplier: supplier_managed1, price: 10.0) }
let!(:product_not_supplied) { create(:product, supplier: supplier_unmanaged) }
- let!(:product_supplied_permitted) { create(:product, name: 'Product Permitted', supplier: supplier_permitted, price: 10.0) }
- let(:product_supplied_inactive) { create(:product, supplier: supplier_managed1, price: 10.0, available_on: 1.week.from_now) }
+ let!(:product_supplied_permitted) {
+ create(:product, name: 'Product Permitted', supplier: supplier_permitted, price: 10.0)
+ }
+ let(:product_supplied_inactive) {
+ create(:product, supplier: supplier_managed1, price: 10.0, available_on: 1.week.from_now)
+ }
let!(:supplier_permitted_relationship) do
create(:enterprise_relationship, parent: supplier_permitted, child: supplier_managed1,
@@ -719,7 +738,8 @@ feature '
it "shows only suppliers that I manage or have permission to" do
visit spree.admin_products_path
- expect(page).to have_select 'producer_id', with_options: [supplier_managed1.name, supplier_managed2.name, supplier_permitted.name], selected: supplier_managed1.name
+ expect(page).to have_select 'producer_id',
+ with_options: [supplier_managed1.name, supplier_managed2.name, supplier_permitted.name], selected: supplier_managed1.name
expect(page).to have_no_select 'producer_id', with_options: [supplier_unmanaged.name]
end
@@ -739,7 +759,9 @@ feature '
find("a", text: "NEW PRODUCT").click
expect(page).to have_content 'NEW PRODUCT'
- expect(page).to have_select 'product_supplier_id', with_options: [supplier_managed1.name, supplier_managed2.name, supplier_permitted.name]
+ expect(page).to have_select 'product_supplier_id',
+ with_options: [supplier_managed1.name, supplier_managed2.name,
+ supplier_permitted.name]
within 'fieldset#new_product' do
fill_in 'product_name', with: 'Big Bag Of Apples'
@@ -772,7 +794,8 @@ feature '
fill_in "product_name", with: "Big Bag Of Potatoes"
select supplier_managed2.name, from: 'producer_id'
- fill_in "available_on", with: 3.days.ago.beginning_of_day.strftime("%F %T"), fill_options: { clear: :backspace }
+ fill_in "available_on", with: 3.days.ago.beginning_of_day.strftime("%F %T"),
+ fill_options: { clear: :backspace }
select "Weight (kg)", from: "variant_unit_with_scale"
find("a.view-variants").click
diff --git a/spec/features/admin/configuration/general_settings_spec.rb b/spec/features/admin/configuration/general_settings_spec.rb
index ecb6d61c91..099b251391 100644
--- a/spec/features/admin/configuration/general_settings_spec.rb
+++ b/spec/features/admin/configuration/general_settings_spec.rb
@@ -25,7 +25,8 @@ describe "General Settings" do
click_button "Update"
within("[class='flash success']") do
- expect(page).to have_content(Spree.t(:successfully_updated, resource: Spree.t(:general_settings)))
+ expect(page).to have_content(Spree.t(:successfully_updated,
+ resource: Spree.t(:general_settings)))
end
expect(find("#site_name").value).to eq("OFN Demo Site99")
end
@@ -41,7 +42,8 @@ describe "General Settings" do
click_button 'Update'
- expect(page).to have_content(Spree.t(:successfully_updated, resource: Spree.t(:general_settings)))
+ expect(page).to have_content(Spree.t(:successfully_updated,
+ resource: Spree.t(:general_settings)))
expect(page).to have_checked_field('10.00 $')
end
end
diff --git a/spec/features/admin/configuration/tax_rates_spec.rb b/spec/features/admin/configuration/tax_rates_spec.rb
index c0108c18c3..b1c63413ff 100644
--- a/spec/features/admin/configuration/tax_rates_spec.rb
+++ b/spec/features/admin/configuration/tax_rates_spec.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
require 'spec_helper'
describe "Tax Rates" do
diff --git a/spec/features/admin/customers_spec.rb b/spec/features/admin/customers_spec.rb
index f6ff3689f0..b42032be77 100644
--- a/spec/features/admin/customers_spec.rb
+++ b/spec/features/admin/customers_spec.rb
@@ -26,7 +26,8 @@ feature 'Customers' do
it "passes the smoke test" do
# Prompts for a hub for a list of my managed enterprises
- expect(page).to have_select2 "shop_id", with_options: [managed_distributor1.name, managed_distributor2.name], without_options: [unmanaged_distributor.name]
+ expect(page).to have_select2 "shop_id",
+ with_options: [managed_distributor1.name, managed_distributor2.name], without_options: [unmanaged_distributor.name]
select2_select managed_distributor2.name, from: "shop_id"
@@ -56,15 +57,19 @@ feature 'Customers' do
within "#customers thead" do
click_on "Email"
end
- expect(page).to have_selector("#customers .customer:nth-child(1) .email", text: customer_emails[0])
- expect(page).to have_selector("#customers .customer:nth-child(2) .email", text: customer_emails[1])
+ expect(page).to have_selector("#customers .customer:nth-child(1) .email",
+ text: customer_emails[0])
+ expect(page).to have_selector("#customers .customer:nth-child(2) .email",
+ text: customer_emails[1])
# Then sorting in reverse when the header is clicked again
within "#customers thead" do
click_on "Email"
end
- expect(page).to have_selector("#customers .customer:nth-child(1) .email", text: customer_emails[1])
- expect(page).to have_selector("#customers .customer:nth-child(2) .email", text: customer_emails[0])
+ expect(page).to have_selector("#customers .customer:nth-child(1) .email",
+ text: customer_emails[1])
+ expect(page).to have_selector("#customers .customer:nth-child(2) .email",
+ text: customer_emails[0])
# Toggling columns
expect(page).to have_selector "th.email"
@@ -81,7 +86,8 @@ feature 'Customers' do
find("a.delete-customer").click
end
end
- expect(page).to have_selector "#info-dialog .text", text: I18n.t('admin.customers.destroy.has_associated_orders')
+ expect(page).to have_selector "#info-dialog .text",
+ text: I18n.t('admin.customers.destroy.has_associated_orders')
click_button "OK"
}.to_not change{ Customer.count }
@@ -96,12 +102,26 @@ feature 'Customers' do
end
describe "for a shop with multiple customers" do
- let!(:order1) { create(:order, total: 0, payment_total: 88, distributor: managed_distributor1, user: nil, state: 'complete', customer: customer1) }
- let!(:order2) { create(:order, total: 99, payment_total: 0, distributor: managed_distributor1, user: nil, state: 'complete', customer: customer2) }
- let!(:order3) { create(:order, total: 0, payment_total: 0, distributor: managed_distributor1, user: nil, state: 'complete', customer: customer4) }
+ let!(:order1) {
+ create(:order, total: 0, payment_total: 88, distributor: managed_distributor1, user: nil,
+ state: 'complete', customer: customer1)
+ }
+ let!(:order2) {
+ create(:order, total: 99, payment_total: 0, distributor: managed_distributor1, user: nil,
+ state: 'complete', customer: customer2)
+ }
+ let!(:order3) {
+ create(:order, total: 0, payment_total: 0, distributor: managed_distributor1, user: nil,
+ state: 'complete', customer: customer4)
+ }
- let!(:payment_method) { create(:stripe_sca_payment_method, distributors: [managed_distributor1]) }
- let!(:payment1) { create(:payment, order: order1, state: 'completed', payment_method: payment_method, response_code: 'pi_123', amount: 88.00) }
+ let!(:payment_method) {
+ create(:stripe_sca_payment_method, distributors: [managed_distributor1])
+ }
+ let!(:payment1) {
+ create(:payment, order: order1, state: 'completed', payment_method: payment_method,
+ response_code: 'pi_123', amount: 88.00)
+ }
before do
customer4.update enterprise: managed_distributor1
@@ -128,7 +148,10 @@ feature 'Customers' do
end
context "with an additional negative payment (or refund)" do
- let!(:payment2) { create(:payment, order: order1, state: 'completed', payment_method: payment_method, response_code: 'pi_123', amount: -25.00) }
+ let!(:payment2) {
+ create(:payment, order: order1, state: 'completed', payment_method: payment_method,
+ response_code: 'pi_123', amount: -25.00)
+ }
before do
order1.user = user
@@ -325,14 +348,16 @@ feature 'Customers' do
click_link('New Customer')
fill_in 'email', with: "not_an_email"
click_button 'Add Customer'
- expect(page).to have_selector "#new-customer-dialog .error", text: "Please enter a valid email address"
+ expect(page).to have_selector "#new-customer-dialog .error",
+ text: "Please enter a valid email address"
}.to_not change{ Customer.of(managed_distributor1).count }
# When an existing email is used
expect{
fill_in 'email', with: customer1.email
click_button 'Add Customer'
- expect(page).to have_selector "#new-customer-dialog .error", text: "Email is associated with an existing customer"
+ expect(page).to have_selector "#new-customer-dialog .error",
+ text: "Email is associated with an existing customer"
}.to_not change{ Customer.of(managed_distributor1).count }
# When a new valid email is used
diff --git a/spec/features/admin/enterprise_fees_spec.rb b/spec/features/admin/enterprise_fees_spec.rb
index 057840525b..455d653018 100644
--- a/spec/features/admin/enterprise_fees_spec.rb
+++ b/spec/features/admin/enterprise_fees_spec.rb
@@ -12,17 +12,21 @@ feature '
let!(:tax_category_gst) { create(:tax_category, name: 'GST') }
scenario "listing enterprise fees" do
- fee = create(:enterprise_fee, name: '$0.50 / kg', fee_type: 'packing', tax_category: tax_category_gst)
+ fee = create(:enterprise_fee, name: '$0.50 / kg', fee_type: 'packing',
+ tax_category: tax_category_gst)
amount = fee.calculator.preferred_amount
login_as_admin_and_visit spree.edit_admin_general_settings_path
click_link 'Enterprise Fees'
expect(page).to have_select "sets_enterprise_fee_set_collection_attributes_0_enterprise_id"
- expect(page).to have_select "sets_enterprise_fee_set_collection_attributes_0_fee_type", selected: 'Packing fee'
+ expect(page).to have_select "sets_enterprise_fee_set_collection_attributes_0_fee_type",
+ selected: 'Packing fee'
expect(page).to have_selector "input[value='$0.50 / kg']"
- expect(page).to have_select "sets_enterprise_fee_set_collection_attributes_0_tax_category_id", selected: 'GST'
- expect(page).to have_select "sets_enterprise_fee_set_collection_attributes_0_calculator_type", selected: 'Flat Rate (per item)'
+ expect(page).to have_select "sets_enterprise_fee_set_collection_attributes_0_tax_category_id",
+ selected: 'GST'
+ expect(page).to have_select "sets_enterprise_fee_set_collection_attributes_0_calculator_type",
+ selected: 'Flat Rate (per item)'
expect(page).to have_selector "input[value='#{amount}']"
end
@@ -46,7 +50,8 @@ feature '
expect(page).to have_selector "input[value='Hello!']"
# When I fill in the calculator fields and click update
- fill_in 'sets_enterprise_fee_set_collection_attributes_0_calculator_attributes_preferred_flat_percent', with: '12.34'
+ fill_in 'sets_enterprise_fee_set_collection_attributes_0_calculator_attributes_preferred_flat_percent',
+ with: '12.34'
click_button 'Update'
# Then I should see the correct values in my calculator fields
@@ -65,15 +70,19 @@ feature '
select 'Foo', from: 'sets_enterprise_fee_set_collection_attributes_0_enterprise_id'
select 'Admin', from: 'sets_enterprise_fee_set_collection_attributes_0_fee_type'
fill_in 'sets_enterprise_fee_set_collection_attributes_0_name', with: 'Greetings!'
- select 'Inherit From Product', from: 'sets_enterprise_fee_set_collection_attributes_0_tax_category_id'
+ select 'Inherit From Product',
+ from: 'sets_enterprise_fee_set_collection_attributes_0_tax_category_id'
select 'Flat Percent', from: 'sets_enterprise_fee_set_collection_attributes_0_calculator_type'
click_button 'Update'
# Then I should see the updated fields for my fee
- expect(page).to have_select "sets_enterprise_fee_set_collection_attributes_0_enterprise_id", selected: 'Foo'
- expect(page).to have_select "sets_enterprise_fee_set_collection_attributes_0_fee_type", selected: 'Admin fee'
+ expect(page).to have_select "sets_enterprise_fee_set_collection_attributes_0_enterprise_id",
+ selected: 'Foo'
+ expect(page).to have_select "sets_enterprise_fee_set_collection_attributes_0_fee_type",
+ selected: 'Admin fee'
expect(page).to have_selector "input[value='Greetings!']"
- expect(page).to have_select 'sets_enterprise_fee_set_collection_attributes_0_tax_category_id', selected: 'Inherit From Product'
+ expect(page).to have_select 'sets_enterprise_fee_set_collection_attributes_0_tax_category_id',
+ selected: 'Inherit From Product'
expect(page).to have_selector "option[selected]", text: 'Flat Percent (per item)'
fee.reload
@@ -123,7 +132,8 @@ feature '
within(".side_menu") { click_link 'Enterprise Fees' }
click_link "Create One Now"
- select distributor1.name, from: 'sets_enterprise_fee_set_collection_attributes_0_enterprise_id'
+ select distributor1.name,
+ from: 'sets_enterprise_fee_set_collection_attributes_0_enterprise_id'
select 'Packing', from: 'sets_enterprise_fee_set_collection_attributes_0_fee_type'
fill_in 'sets_enterprise_fee_set_collection_attributes_0_name', with: 'foo'
select 'GST', from: 'sets_enterprise_fee_set_collection_attributes_0_tax_category_id'
@@ -133,7 +143,8 @@ feature '
expect(flash_message).to eq('Your enterprise fees have been updated.')
# After saving, we should be redirected to the fees for our chosen enterprise
- expect(page).not_to have_select 'sets_enterprise_fee_set_collection_attributes_1_enterprise_id', selected: 'Second Distributor'
+ expect(page).not_to have_select 'sets_enterprise_fee_set_collection_attributes_1_enterprise_id',
+ selected: 'Second Distributor'
enterprise_fee = EnterpriseFee.find_by name: 'foo'
expect(enterprise_fee.enterprise).to eq(distributor1)
@@ -146,14 +157,18 @@ feature '
visit edit_admin_enterprise_path(distributor1)
within(".side_menu") { click_link 'Enterprise Fees' }
click_link "Manage Enterprise Fees"
- expect(page).to have_field 'sets_enterprise_fee_set_collection_attributes_0_name', with: 'One'
- expect(page).not_to have_field 'sets_enterprise_fee_set_collection_attributes_1_name', with: 'Two'
+ expect(page).to have_field 'sets_enterprise_fee_set_collection_attributes_0_name',
+ with: 'One'
+ expect(page).not_to have_field 'sets_enterprise_fee_set_collection_attributes_1_name',
+ with: 'Two'
visit edit_admin_enterprise_path(distributor2)
within(".side_menu") { click_link 'Enterprise Fees' }
click_link "Manage Enterprise Fees"
- expect(page).not_to have_field 'sets_enterprise_fee_set_collection_attributes_0_name', with: 'One'
- expect(page).to have_field 'sets_enterprise_fee_set_collection_attributes_0_name', with: 'Two'
+ expect(page).not_to have_field 'sets_enterprise_fee_set_collection_attributes_0_name',
+ with: 'One'
+ expect(page).to have_field 'sets_enterprise_fee_set_collection_attributes_0_name',
+ with: 'Two'
end
it "only allows me to select enterprises I have access to" do
diff --git a/spec/features/admin/enterprise_relationships_spec.rb b/spec/features/admin/enterprise_relationships_spec.rb
index 3dd2c24f99..2ac5659002 100644
--- a/spec/features/admin/enterprise_relationships_spec.rb
+++ b/spec/features/admin/enterprise_relationships_spec.rb
@@ -14,10 +14,13 @@ feature '
scenario "listing relationships" do
# Given some enterprises with relationships
- e1, e2, e3, e4 = create(:enterprise), create(:enterprise), create(:enterprise), create(:enterprise)
- create(:enterprise_relationship, parent: e1, child: e2, permissions_list: [:add_to_order_cycle])
+ e1, e2, e3, e4 = create(:enterprise), create(:enterprise), create(:enterprise),
+create(:enterprise)
+ create(:enterprise_relationship, parent: e1, child: e2,
+ permissions_list: [:add_to_order_cycle])
create(:enterprise_relationship, parent: e2, child: e3, permissions_list: [:manage_products])
- create(:enterprise_relationship, parent: e3, child: e4, permissions_list: [:add_to_order_cycle, :manage_products])
+ create(:enterprise_relationship, parent: e3, child: e4,
+ permissions_list: [:add_to_order_cycle, :manage_products])
# When I go to the relationships page
visit spree.admin_dashboard_path
@@ -49,10 +52,12 @@ feature '
# Wait for row to appear since have_relationship doesn't wait
expect(page).to have_selector 'tr', count: 2
- expect_relationship_with_permissions e1, e2, ['to add to order cycle', 'to add products to inventory', 'to edit profile']
+ expect_relationship_with_permissions e1, e2,
+ ['to add to order cycle', 'to add products to inventory', 'to edit profile']
er = EnterpriseRelationship.where(parent_id: e1, child_id: e2).first
expect(er).to be_present
- expect(er.permissions.map(&:name)).to match_array ['add_to_order_cycle', 'edit_profile', 'create_variant_overrides']
+ expect(er.permissions.map(&:name)).to match_array ['add_to_order_cycle', 'edit_profile',
+ 'create_variant_overrides']
end
scenario "attempting to create a relationship with invalid data" do
@@ -75,7 +80,8 @@ feature '
scenario "deleting a relationship" do
e1 = create(:enterprise, name: 'One')
e2 = create(:enterprise, name: 'Two')
- er = create(:enterprise_relationship, parent: e1, child: e2, permissions_list: [:add_to_order_cycle])
+ er = create(:enterprise_relationship, parent: e1, child: e2,
+ permissions_list: [:add_to_order_cycle])
visit admin_enterprise_relationships_path
expect(page).to have_relationship e1, e2, 'to add to order cycle'
@@ -112,7 +118,8 @@ feature '
scenario "enterprise user can only add their own enterprises as parent" do
visit admin_enterprise_relationships_path
expect(page).to have_select2 'enterprise_relationship_parent_id', options: ['', d1.name]
- expect(page).to have_select2 'enterprise_relationship_child_id', with_options: ['', d1.name, d2.name, d3.name]
+ expect(page).to have_select2 'enterprise_relationship_child_id',
+ with_options: ['', d1.name, d2.name, d3.name]
end
end
diff --git a/spec/features/admin/enterprise_roles_spec.rb b/spec/features/admin/enterprise_roles_spec.rb
index 4720e36334..d7bb6db59b 100644
--- a/spec/features/admin/enterprise_roles_spec.rb
+++ b/spec/features/admin/enterprise_roles_spec.rb
@@ -16,7 +16,8 @@ feature '
scenario "listing relationships" do
# Given some users and enterprises with relationships
u1, u2 = create(:user), create(:user)
- e1, e2, e3, e4 = create(:enterprise), create(:enterprise), create(:enterprise), create(:enterprise)
+ e1, e2, e3, e4 = create(:enterprise), create(:enterprise), create(:enterprise),
+create(:enterprise)
create(:enterprise_role, user: u1, enterprise: e1)
create(:enterprise_role, user: u1, enterprise: e2)
create(:enterprise_role, user: u2, enterprise: e3)
@@ -94,7 +95,9 @@ feature '
let(:new_email) { 'new@manager.com' }
let!(:enterprise) { create(:enterprise, name: 'Test Enterprise', owner: user1) }
- let!(:enterprise_role) { create(:enterprise_role, user_id: user2.id, enterprise_id: enterprise.id) }
+ let!(:enterprise_role) {
+ create(:enterprise_role, user_id: user2.id, enterprise_id: enterprise.id)
+ }
before do
click_link 'Enterprises'
diff --git a/spec/features/admin/enterprise_user_spec.rb b/spec/features/admin/enterprise_user_spec.rb
index 4f3ca747e5..0434ca451c 100644
--- a/spec/features/admin/enterprise_user_spec.rb
+++ b/spec/features/admin/enterprise_user_spec.rb
@@ -15,7 +15,9 @@ feature '
let(:supplier_profile) { create(:supplier_enterprise, name: 'Supplier profile', sells: 'none') }
let!(:distributor1) { create(:distributor_enterprise, name: 'Distributor 3') }
let!(:distributor2) { create(:distributor_enterprise, name: 'Distributor 4') }
- let(:distributor_profile) { create(:distributor_enterprise, name: 'Distributor profile', sells: 'none') }
+ let(:distributor_profile) {
+ create(:distributor_enterprise, name: 'Distributor profile', sells: 'none')
+ }
describe "creating an enterprise user" do
context "with a limitted number of owned enterprises" do
diff --git a/spec/features/admin/enterprises/images_spec.rb b/spec/features/admin/enterprises/images_spec.rb
index 4716ba2ded..87c0673b19 100644
--- a/spec/features/admin/enterprises/images_spec.rb
+++ b/spec/features/admin/enterprises/images_spec.rb
@@ -66,7 +66,8 @@ feature "Managing enterprise images" do
scenario "editing promo image" do
# Adding image
- attach_file "enterprise[promo_image]", Rails.root.join("app", "assets", "images", "logo-white.png")
+ attach_file "enterprise[promo_image]",
+ Rails.root.join("app", "assets", "images", "logo-white.png")
click_button "Update"
expect(page).to have_content("Enterprise \"#{distributor.name}\" has been successfully updated!")
@@ -77,7 +78,8 @@ feature "Managing enterprise images" do
end
# Replacing image
- attach_file "enterprise[promo_image]", Rails.root.join("app", "assets", "images", "logo-black.png")
+ attach_file "enterprise[promo_image]",
+ Rails.root.join("app", "assets", "images", "logo-black.png")
click_button "Update"
expect(page).to have_content("Enterprise \"#{distributor.name}\" has been successfully updated!")
diff --git a/spec/features/admin/enterprises/index_spec.rb b/spec/features/admin/enterprises/index_spec.rb
index 2709dd2201..0f07a79864 100644
--- a/spec/features/admin/enterprises/index_spec.rb
+++ b/spec/features/admin/enterprises/index_spec.rb
@@ -83,12 +83,14 @@ feature 'Enterprises Index' do
it "does not update the enterprises and displays errors" do
d_row_index = enterprise_row_index(d.name)
within("tr.enterprise-#{d.id}") do
- select d_manager.email, from: "sets_enterprise_set_collection_attributes_#{d_row_index}_owner_id"
+ select d_manager.email,
+ from: "sets_enterprise_set_collection_attributes_#{d_row_index}_owner_id"
end
second_distributor_row_index = enterprise_row_index(second_distributor.name)
within("tr.enterprise-#{second_distributor.id}") do
- select d_manager.email, from: "sets_enterprise_set_collection_attributes_#{second_distributor_row_index}_owner_id"
+ select d_manager.email,
+ from: "sets_enterprise_set_collection_attributes_#{second_distributor_row_index}_owner_id"
end
click_button "Update"
expect(flash_message).to eq('Update failed')
@@ -107,7 +109,10 @@ feature 'Enterprises Index' do
let(:distributor2) { create(:distributor_enterprise, name: 'Another Distributor') }
let(:distributor3) { create(:distributor_enterprise, name: 'Yet Another Distributor') }
let(:enterprise_manager) { create(:user) }
- let!(:er) { create(:enterprise_relationship, parent: distributor3, child: distributor1, permissions_list: [:edit_profile]) }
+ let!(:er) {
+ create(:enterprise_relationship, parent: distributor3, child: distributor1,
+ permissions_list: [:edit_profile])
+ }
before(:each) do
enterprise_manager.enterprise_roles.build(enterprise: supplier1).save
@@ -165,7 +170,9 @@ feature 'Enterprises Index' do
describe "as the owner of an enterprise" do
let!(:user) { create(:user) }
- let!(:owned_distributor) { create(:distributor_enterprise, name: 'Owned Distributor', owner: user) }
+ let!(:owned_distributor) {
+ create(:distributor_enterprise, name: 'Owned Distributor', owner: user)
+ }
before do
login_as user
diff --git a/spec/features/admin/enterprises_spec.rb b/spec/features/admin/enterprises_spec.rb
index 32652eee59..0a9e0e2445 100644
--- a/spec/features/admin/enterprises_spec.rb
+++ b/spec/features/admin/enterprises_spec.rb
@@ -273,13 +273,15 @@ feature '
login_as_admin_and_visit main_app.admin_enterprise_producer_properties_path(s)
# And I remove the property
- expect(page).to have_field 'enterprise_producer_properties_attributes_0_property_name', with: 'Certified Organic'
+ expect(page).to have_field 'enterprise_producer_properties_attributes_0_property_name',
+ with: 'Certified Organic'
within("#spree_producer_property_#{pp.id}") { page.find('a.remove_fields').click }
click_button 'Update'
# Then the property should have been removed
expect(current_path).to eq main_app.admin_enterprise_producer_properties_path(s)
- expect(page).not_to have_field 'enterprise_producer_properties_attributes_0_property_name', with: 'Certified Organic'
+ expect(page).not_to have_field 'enterprise_producer_properties_attributes_0_property_name',
+ with: 'Certified Organic'
expect(s.producer_properties.reload).to be_empty
end
end
@@ -291,7 +293,10 @@ feature '
let(:distributor2) { create(:distributor_enterprise, name: 'Another Distributor') }
let(:distributor3) { create(:distributor_enterprise, name: 'Yet Another Distributor') }
let(:enterprise_user) { create(:user, enterprise_limit: 1) }
- let!(:er) { create(:enterprise_relationship, parent: distributor3, child: distributor1, permissions_list: [:edit_profile]) }
+ let!(:er) {
+ create(:enterprise_relationship, parent: distributor3, child: distributor1,
+ permissions_list: [:edit_profile])
+ }
before(:each) do
enterprise_user.enterprise_roles.build(enterprise: supplier1).save
@@ -315,7 +320,8 @@ feature '
click_link 'New Enterprise'
end
- expect(page).to have_content I18n.t('js.admin.enterprise_limit_reached', contact_email: ContentConfig.footer_email)
+ expect(page).to have_content I18n.t('js.admin.enterprise_limit_reached',
+ contact_email: ContentConfig.footer_email)
end
end
@@ -413,7 +419,8 @@ feature '
end
# -- Update only
- select2_select "Certified Organic", from: 'enterprise_producer_properties_attributes_0_property_name'
+ select2_select "Certified Organic",
+ from: 'enterprise_producer_properties_attributes_0_property_name'
fill_in 'enterprise_producer_properties_attributes_0_value', with: "NASAA 12345"
diff --git a/spec/features/admin/order_cycles/complex_creating_specific_time_spec.rb b/spec/features/admin/order_cycles/complex_creating_specific_time_spec.rb
index 9607270012..0b90c2d9cf 100644
--- a/spec/features/admin/order_cycles/complex_creating_specific_time_spec.rb
+++ b/spec/features/admin/order_cycles/complex_creating_specific_time_spec.rb
@@ -20,12 +20,16 @@ feature '
product = create(:product, supplier: supplier)
v1 = create(:variant, product: product)
v2 = create(:variant, product: product)
- distributor = create(:distributor_enterprise, name: 'My distributor', with_payment_and_shipping: true)
+ distributor = create(:distributor_enterprise, name: 'My distributor',
+ with_payment_and_shipping: true)
# Relationships required for interface to work
- create(:enterprise_relationship, parent: supplier, child: coordinator, permissions_list: [:add_to_order_cycle])
- create(:enterprise_relationship, parent: distributor, child: coordinator, permissions_list: [:add_to_order_cycle])
- create(:enterprise_relationship, parent: supplier, child: distributor, permissions_list: [:add_to_order_cycle])
+ create(:enterprise_relationship, parent: supplier, child: coordinator,
+ permissions_list: [:add_to_order_cycle])
+ create(:enterprise_relationship, parent: distributor, child: coordinator,
+ permissions_list: [:add_to_order_cycle])
+ create(:enterprise_relationship, parent: supplier, child: distributor,
+ permissions_list: [:add_to_order_cycle])
# And some enterprise fees
supplier_fee = create(:enterprise_fee, enterprise: supplier, name: 'Supplier fee')
@@ -62,8 +66,8 @@ feature '
find('#order_cycle_orders_close_at').click
# select date
select_date_from_datepicker Time.at(order_cycle_closing_time)
- # select time
- within(".flatpickr-calendar.open .flatpickr-time") do
+ # select time
+ within(".flatpickr-calendar.open .flatpickr-time") do
find('.flatpickr-hour').set('%02d' % order_cycle_closing_time.hour)
find('.flatpickr-minute').set('%02d' % order_cycle_closing_time.min)
end
@@ -96,8 +100,9 @@ feature '
# And I add a supplier fee
within("tr.supplier-#{supplier.id}") { click_button 'Add fee' }
- select 'My supplier', from: 'order_cycle_incoming_exchange_0_enterprise_fees_0_enterprise_id'
- select 'Supplier fee', from: 'order_cycle_incoming_exchange_0_enterprise_fees_0_enterprise_fee_id'
+ select 'My supplier', from: 'order_cycle_incoming_exchange_0_enterprise_fees_0_enterprise_id'
+ select 'Supplier fee',
+ from: 'order_cycle_incoming_exchange_0_enterprise_fees_0_enterprise_fee_id'
click_button 'Save and Next'
@@ -119,8 +124,10 @@ feature '
# And I add a distributor fee
within("tr.distributor-#{distributor.id}") { click_button 'Add fee' }
- select 'My distributor', from: 'order_cycle_outgoing_exchange_0_enterprise_fees_0_enterprise_id'
- select 'Distributor fee', from: 'order_cycle_outgoing_exchange_0_enterprise_fees_0_enterprise_fee_id'
+ select 'My distributor',
+ from: 'order_cycle_outgoing_exchange_0_enterprise_fees_0_enterprise_id'
+ select 'Distributor fee',
+ from: 'order_cycle_outgoing_exchange_0_enterprise_fees_0_enterprise_fee_id'
click_button 'Save and Back to List'
@@ -128,8 +135,10 @@ feature '
toggle_columns "Producers", "Shops"
expect(page).to have_input "oc#{oc.id}[name]", value: "Plums & Avos"
- expect(page).to have_input "oc#{oc.id}[orders_open_at]", value: Time.at(order_cycle_opening_time), visible: false
- expect(page).to have_input "oc#{oc.id}[orders_close_at]", value: Time.at(order_cycle_closing_time), visible: false
+ expect(page).to have_input "oc#{oc.id}[orders_open_at]",
+ value: Time.at(order_cycle_opening_time), visible: false
+ expect(page).to have_input "oc#{oc.id}[orders_close_at]",
+ value: Time.at(order_cycle_closing_time), visible: false
expect(page).to have_content "My coordinator"
expect(page).to have_selector 'td.producers', text: 'My supplier'
diff --git a/spec/features/admin/order_cycles/complex_editing_multiple_product_pages_spec.rb b/spec/features/admin/order_cycles/complex_editing_multiple_product_pages_spec.rb
index 892438c003..f365099e5f 100644
--- a/spec/features/admin/order_cycles/complex_editing_multiple_product_pages_spec.rb
+++ b/spec/features/admin/order_cycles/complex_editing_multiple_product_pages_spec.rb
@@ -42,7 +42,8 @@ feature '
expect_all_products_loaded
- expect(page).to have_checked_field "order_cycle_incoming_exchange_0_variants_#{new_product.variants.first.id}", disabled: false
+ expect(page).to have_checked_field "order_cycle_incoming_exchange_0_variants_#{new_product.variants.first.id}",
+ disabled: false
end
def expect_all_products_loaded
diff --git a/spec/features/admin/order_cycles/complex_editing_spec.rb b/spec/features/admin/order_cycles/complex_editing_spec.rb
index ef290949cc..b052e4bd67 100644
--- a/spec/features/admin/order_cycles/complex_editing_spec.rb
+++ b/spec/features/admin/order_cycles/complex_editing_spec.rb
@@ -35,8 +35,10 @@ feature '
expect(page).to have_selector 'td.supplier_name', text: oc.suppliers.first.name
expect(page).to have_selector 'td.supplier_name', text: oc.suppliers.last.name
- expect(page).to have_field 'order_cycle_incoming_exchange_0_receival_instructions', with: 'instructions 0'
- expect(page).to have_field 'order_cycle_incoming_exchange_1_receival_instructions', with: 'instructions 1'
+ expect(page).to have_field 'order_cycle_incoming_exchange_0_receival_instructions',
+ with: 'instructions 0'
+ expect(page).to have_field 'order_cycle_incoming_exchange_1_receival_instructions',
+ with: 'instructions 1'
# And the suppliers should have products
page.all('table.exchanges tbody tr.supplier').each_with_index do |row, i|
@@ -50,12 +52,16 @@ feature '
# And the suppliers should have fees
supplier = oc.suppliers.min_by(&:name)
- expect(page).to have_select 'order_cycle_incoming_exchange_0_enterprise_fees_0_enterprise_id', selected: supplier.name
- expect(page).to have_select 'order_cycle_incoming_exchange_0_enterprise_fees_0_enterprise_fee_id', selected: supplier.enterprise_fees.first.name
+ expect(page).to have_select 'order_cycle_incoming_exchange_0_enterprise_fees_0_enterprise_id',
+ selected: supplier.name
+ expect(page).to have_select 'order_cycle_incoming_exchange_0_enterprise_fees_0_enterprise_fee_id',
+ selected: supplier.enterprise_fees.first.name
supplier = oc.suppliers.max_by(&:name)
- expect(page).to have_select 'order_cycle_incoming_exchange_1_enterprise_fees_0_enterprise_id', selected: supplier.name
- expect(page).to have_select 'order_cycle_incoming_exchange_1_enterprise_fees_0_enterprise_fee_id', selected: supplier.enterprise_fees.first.name
+ expect(page).to have_select 'order_cycle_incoming_exchange_1_enterprise_fees_0_enterprise_id',
+ selected: supplier.name
+ expect(page).to have_select 'order_cycle_incoming_exchange_1_enterprise_fees_0_enterprise_fee_id',
+ selected: supplier.enterprise_fees.first.name
click_button 'Next'
@@ -64,9 +70,11 @@ feature '
expect(page).to have_selector 'td.distributor_name', text: oc.distributors.last.name
expect(page).to have_field 'order_cycle_outgoing_exchange_0_pickup_time', with: 'time 0'
- expect(page).to have_field 'order_cycle_outgoing_exchange_0_pickup_instructions', with: 'instructions 0'
+ expect(page).to have_field 'order_cycle_outgoing_exchange_0_pickup_instructions',
+ with: 'instructions 0'
expect(page).to have_field 'order_cycle_outgoing_exchange_1_pickup_time', with: 'time 1'
- expect(page).to have_field 'order_cycle_outgoing_exchange_1_pickup_instructions', with: 'instructions 1'
+ expect(page).to have_field 'order_cycle_outgoing_exchange_1_pickup_instructions',
+ with: 'instructions 1'
# And the distributors should have products
page.all('table.exchanges tbody tr.distributor').each_with_index do |row, i|
@@ -80,12 +88,16 @@ feature '
# And the distributors should have fees
distributor = oc.distributors.min_by(&:id)
- expect(page).to have_select 'order_cycle_outgoing_exchange_0_enterprise_fees_0_enterprise_id', selected: distributor.name
- expect(page).to have_select 'order_cycle_outgoing_exchange_0_enterprise_fees_0_enterprise_fee_id', selected: distributor.enterprise_fees.first.name
+ expect(page).to have_select 'order_cycle_outgoing_exchange_0_enterprise_fees_0_enterprise_id',
+ selected: distributor.name
+ expect(page).to have_select 'order_cycle_outgoing_exchange_0_enterprise_fees_0_enterprise_fee_id',
+ selected: distributor.enterprise_fees.first.name
distributor = oc.distributors.max_by(&:id)
- expect(page).to have_select 'order_cycle_outgoing_exchange_1_enterprise_fees_0_enterprise_id', selected: distributor.name
- expect(page).to have_select 'order_cycle_outgoing_exchange_1_enterprise_fees_0_enterprise_fee_id', selected: distributor.enterprise_fees.first.name
+ expect(page).to have_select 'order_cycle_outgoing_exchange_1_enterprise_fees_0_enterprise_id',
+ selected: distributor.name
+ expect(page).to have_select 'order_cycle_outgoing_exchange_1_enterprise_fees_0_enterprise_fee_id',
+ selected: distributor.enterprise_fees.first.name
end
private
diff --git a/spec/features/admin/order_cycles/complex_updating_specific_time_spec.rb b/spec/features/admin/order_cycles/complex_updating_specific_time_spec.rb
index e791e792a3..4e1f6d5e7b 100644
--- a/spec/features/admin/order_cycles/complex_updating_specific_time_spec.rb
+++ b/spec/features/admin/order_cycles/complex_updating_specific_time_spec.rb
@@ -10,8 +10,12 @@ xfeature '
include AuthenticationHelper
include WebHelper
- let(:order_cycle_opening_time) { Time.zone.local(2040, 11, 0o6, 0o6, 0o0, 0o0).strftime("%F %T %z") }
- let(:order_cycle_closing_time) { Time.zone.local(2040, 11, 13, 17, 0o0, 0o0).strftime("%F %T %z") }
+ let(:order_cycle_opening_time) {
+ Time.zone.local(2040, 11, 0o6, 0o6, 0o0, 0o0).strftime("%F %T %z")
+ }
+ let(:order_cycle_closing_time) {
+ Time.zone.local(2040, 11, 13, 17, 0o0, 0o0).strftime("%F %T %z")
+ }
scenario "updating an order cycle", js: true do
# Given an order cycle with all the settings
@@ -21,15 +25,19 @@ xfeature '
# And a coordinating, supplying and distributing enterprise with some products with variants
coordinator = oc.coordinator
supplier = create(:supplier_enterprise, name: 'My supplier')
- distributor = create(:distributor_enterprise, name: 'My distributor', with_payment_and_shipping: true)
+ distributor = create(:distributor_enterprise, name: 'My distributor',
+ with_payment_and_shipping: true)
product = create(:product, supplier: supplier)
v1 = create(:variant, product: product)
v2 = create(:variant, product: product)
# Relationships required for interface to work
- create(:enterprise_relationship, parent: supplier, child: coordinator, permissions_list: [:add_to_order_cycle])
- create(:enterprise_relationship, parent: distributor, child: coordinator, permissions_list: [:add_to_order_cycle])
- create(:enterprise_relationship, parent: supplier, child: distributor, permissions_list: [:add_to_order_cycle])
+ create(:enterprise_relationship, parent: supplier, child: coordinator,
+ permissions_list: [:add_to_order_cycle])
+ create(:enterprise_relationship, parent: distributor, child: coordinator,
+ permissions_list: [:add_to_order_cycle])
+ create(:enterprise_relationship, parent: supplier, child: distributor,
+ permissions_list: [:add_to_order_cycle])
# And some enterprise fees
supplier_fee1 = create(:enterprise_fee, enterprise: supplier, name: 'Supplier fee 1')
@@ -71,7 +79,8 @@ xfeature '
open_all_exchange_product_tabs
- expect(page).to have_selector "#order_cycle_incoming_exchange_1_variants_#{initial_variants.last.id}", visible: true
+ expect(page).to have_selector "#order_cycle_incoming_exchange_1_variants_#{initial_variants.last.id}",
+ visible: true
page.find("#order_cycle_incoming_exchange_1_variants_#{initial_variants.last.id}", visible: true).click # uncheck (with visible:true filter)
check "order_cycle_incoming_exchange_2_variants_#{v1.id}"
check "order_cycle_incoming_exchange_2_variants_#{v2.id}"
@@ -79,12 +88,14 @@ xfeature '
# And I configure some supplier fees
within("tr.supplier-#{supplier.id}") { click_button 'Add fee' }
select 'My supplier', from: 'order_cycle_incoming_exchange_2_enterprise_fees_0_enterprise_id'
- select 'Supplier fee 1', from: 'order_cycle_incoming_exchange_2_enterprise_fees_0_enterprise_fee_id'
+ select 'Supplier fee 1',
+ from: 'order_cycle_incoming_exchange_2_enterprise_fees_0_enterprise_fee_id'
within("tr.supplier-#{supplier.id}") { click_button 'Add fee' }
within("tr.supplier-#{supplier.id}") { click_button 'Add fee' }
click_link 'order_cycle_incoming_exchange_2_enterprise_fees_0_remove'
select 'My supplier', from: 'order_cycle_incoming_exchange_2_enterprise_fees_0_enterprise_id'
- select 'Supplier fee 2', from: 'order_cycle_incoming_exchange_2_enterprise_fees_0_enterprise_fee_id'
+ select 'Supplier fee 2',
+ from: 'order_cycle_incoming_exchange_2_enterprise_fees_0_enterprise_fee_id'
click_button 'Save and Next'
expect(page).to have_content 'Your order cycle has been updated.'
@@ -114,12 +125,14 @@ xfeature '
# And I configure some distributor fees
within("tr.distributor-#{distributor.id}") { click_button 'Add fee' }
select 'My distributor', from: 'order_cycle_outgoing_exchange_2_enterprise_fees_0_enterprise_id'
- select 'Distributor fee 1', from: 'order_cycle_outgoing_exchange_2_enterprise_fees_0_enterprise_fee_id'
+ select 'Distributor fee 1',
+ from: 'order_cycle_outgoing_exchange_2_enterprise_fees_0_enterprise_fee_id'
within("tr.distributor-#{distributor.id}") { click_button 'Add fee' }
within("tr.distributor-#{distributor.id}") { click_button 'Add fee' }
click_link 'order_cycle_outgoing_exchange_2_enterprise_fees_0_remove'
select 'My distributor', from: 'order_cycle_outgoing_exchange_2_enterprise_fees_0_enterprise_id'
- select 'Distributor fee 2', from: 'order_cycle_outgoing_exchange_2_enterprise_fees_0_enterprise_fee_id'
+ select 'Distributor fee 2',
+ from: 'order_cycle_outgoing_exchange_2_enterprise_fees_0_enterprise_fee_id'
expect(page).to have_selector "#save-bar"
click_button 'Save and Back to List'
@@ -149,11 +162,14 @@ xfeature '
# And it should have some variants selected
selected_initial_variants = initial_variants.take initial_variants.size - 1
- expect(oc.variants.map(&:id)).to match_array((selected_initial_variants.map(&:id) + [v1.id, v2.id]))
+ expect(oc.variants.map(&:id)).to match_array((selected_initial_variants.map(&:id) + [v1.id,
+ v2.id]))
# And the collection details should have been updated
- expect(oc.exchanges.where(pickup_time: 'New time 0', pickup_instructions: 'New instructions 0')).to be_present
- expect(oc.exchanges.where(pickup_time: 'New time 1', pickup_instructions: 'New instructions 1')).to be_present
+ expect(oc.exchanges.where(pickup_time: 'New time 0',
+ pickup_instructions: 'New instructions 0')).to be_present
+ expect(oc.exchanges.where(pickup_time: 'New time 1',
+ pickup_instructions: 'New instructions 1')).to be_present
end
private
diff --git a/spec/features/admin/order_cycles/list_spec.rb b/spec/features/admin/order_cycles/list_spec.rb
index 4f2af626ef..3cbabd5fae 100644
--- a/spec/features/admin/order_cycles/list_spec.rb
+++ b/spec/features/admin/order_cycles/list_spec.rb
@@ -53,8 +53,10 @@ feature '
within('table#listing_order_cycles tbody tr:nth-child(2)') do
# Then I should see the basic fields
expect(page).to have_input "oc#{oc1.id}[name]", value: oc1.name
- expect(page).to have_input "oc#{oc1.id}[orders_open_at]", value: oc1.orders_open_at, visible: false
- expect(page).to have_input "oc#{oc1.id}[orders_close_at]", value: oc1.orders_close_at, visible: false
+ expect(page).to have_input "oc#{oc1.id}[orders_open_at]", value: oc1.orders_open_at,
+ visible: false
+ expect(page).to have_input "oc#{oc1.id}[orders_close_at]", value: oc1.orders_close_at,
+ visible: false
expect(page).to have_content oc1.coordinator.name
# And I should see the suppliers and distributors
@@ -114,7 +116,8 @@ feature '
# Attempting to edit dates of an open order cycle with active subscriptions
find("#oc#{oc1.id}_orders_open_at").click
- expect(page).to have_selector "#confirm-dialog .message", text: I18n.t('admin.order_cycles.date_warning.msg', n: 1)
+ expect(page).to have_selector "#confirm-dialog .message",
+ text: I18n.t('admin.order_cycles.date_warning.msg', n: 1)
end
describe 'listing order cycles with other locales' do
diff --git a/spec/features/admin/order_cycles/simple_spec.rb b/spec/features/admin/order_cycles/simple_spec.rb
index ee63ede2bb..0da4e7222f 100644
--- a/spec/features/admin/order_cycles/simple_spec.rb
+++ b/spec/features/admin/order_cycles/simple_spec.rb
@@ -13,11 +13,11 @@ feature '
scenario "updating many order cycle opening/closing times at once", js: true do
# Given three order cycles
oc1 = create(:simple_order_cycle,
- orders_open_at: Time.zone.local(2000, 12, 12, 12, 12, 0),
- orders_close_at: Time.zone.local(2041, 12, 12, 12, 12, 1))
+ orders_open_at: Time.zone.local(2000, 12, 12, 12, 12, 0),
+ orders_close_at: Time.zone.local(2041, 12, 12, 12, 12, 1))
oc2 = create(:simple_order_cycle,
- orders_open_at: Time.zone.local(2000, 12, 12, 12, 12, 2),
- orders_close_at: Time.zone.local(2041, 12, 12, 12, 12, 3))
+ orders_open_at: Time.zone.local(2000, 12, 12, 12, 12, 2),
+ orders_close_at: Time.zone.local(2041, 12, 12, 12, 12, 3))
oc3 = create(:simple_order_cycle,
orders_open_at: Time.zone.local(2040, 12, 12, 12, 12, 4),
orders_close_at: Time.zone.local(2041, 12, 12, 12, 12, 5))
@@ -27,18 +27,18 @@ feature '
## -- OC1
find("input#oc#{oc1.id}_name").set ""
- fill_in("oc#{oc1.id}_name", :with => "Updated Order Cycle 1")
-
+ fill_in("oc#{oc1.id}_name", with: "Updated Order Cycle 1")
+
## -- OC2
- fill_in("oc#{oc2.id}_name", :with => "Updated Order Cycle 2")
+ fill_in("oc#{oc2.id}_name", with: "Updated Order Cycle 2")
within("tr.order-cycle-#{oc2.id} .orders_open_at") do
find('input.datetimepicker', match: :first).click
end
within(".flatpickr-calendar.open") do
- # Then select first of month
- find('.dayContainer .flatpickr-day', text: "1").click
- end
+ # Then select first of month
+ find('.dayContainer .flatpickr-day', text: "1").click
+ end
within("tr.order-cycle-#{oc2.id}") do
# Then that date/time should appear on the form
@@ -46,13 +46,13 @@ feature '
end
# -- OC3
- fill_in("oc#{oc3.id}_name", :with => "Updated Order Cycle 3")
+ fill_in("oc#{oc3.id}_name", with: "Updated Order Cycle 3")
within("tr.order-cycle-#{oc3.id} .orders_close_at") do
find('input.datetimepicker', match: :first).click
end
within(".flatpickr-calendar.open") do
- # Then select first of month
+ # Then select first of month
find('.dayContainer .flatpickr-day', text: "1").click
end
@@ -65,7 +65,8 @@ feature '
# Then my details should have been saved
expect(page).to have_selector "#save-bar", text: "Order cycles have been updated."
order_cycles = OrderCycle.order("id ASC")
- expect(order_cycles.map(&:name)).to eq ["Updated Order Cycle 1", "Updated Order Cycle 2", "Updated Order Cycle 3"]
+ expect(order_cycles.map(&:name)).to eq ["Updated Order Cycle 1", "Updated Order Cycle 2",
+ "Updated Order Cycle 3"]
expect(order_cycles.map { |oc| oc.orders_open_at.sec }).to eq [0, 0, 4]
expect(order_cycles.map { |oc| oc.orders_close_at.sec }).to eq [1, 3, 0]
end
@@ -118,31 +119,52 @@ feature '
let!(:supplier_unmanaged) { create(:supplier_enterprise, name: 'Unmanaged supplier') }
let!(:supplier_permitted) { create(:supplier_enterprise, name: 'Permitted supplier') }
let!(:distributor_managed) { create(:distributor_enterprise, name: 'Managed distributor') }
- let!(:other_distributor_managed) { create(:distributor_enterprise, name: 'Other Managed distributor') }
+ let!(:other_distributor_managed) {
+ create(:distributor_enterprise, name: 'Other Managed distributor')
+ }
let!(:distributor_unmanaged) { create(:distributor_enterprise, name: 'Unmanaged Distributor') }
let!(:distributor_permitted) { create(:distributor_enterprise, name: 'Permitted distributor') }
- let!(:distributor_managed_fee) { create(:enterprise_fee, enterprise: distributor_managed, name: 'Managed distributor fee') }
- let!(:shipping_method) { create(:shipping_method, distributors: [distributor_managed, distributor_unmanaged, distributor_permitted]) }
- let!(:payment_method) { create(:payment_method, distributors: [distributor_managed, distributor_unmanaged, distributor_permitted]) }
+ let!(:distributor_managed_fee) {
+ create(:enterprise_fee, enterprise: distributor_managed, name: 'Managed distributor fee')
+ }
+ let!(:shipping_method) {
+ create(:shipping_method,
+ distributors: [distributor_managed, distributor_unmanaged, distributor_permitted])
+ }
+ let!(:payment_method) {
+ create(:payment_method,
+ distributors: [distributor_managed, distributor_unmanaged, distributor_permitted])
+ }
let!(:product_managed) { create(:product, supplier: supplier_managed) }
let!(:variant_managed) { product_managed.variants.first }
let!(:product_permitted) { create(:product, supplier: supplier_permitted) }
let!(:variant_permitted) { product_permitted.variants.first }
- let!(:schedule) { create(:schedule, name: 'Schedule1', order_cycles: [create(:simple_order_cycle, coordinator: distributor_managed)]) }
- let!(:schedule_of_other_managed_distributor) { create(:schedule, name: 'Other Schedule', order_cycles: [create(:simple_order_cycle, coordinator: other_distributor_managed)]) }
+ let!(:schedule) {
+ create(:schedule, name: 'Schedule1',
+ order_cycles: [create(:simple_order_cycle, coordinator: distributor_managed)])
+ }
+ let!(:schedule_of_other_managed_distributor) {
+ create(:schedule, name: 'Other Schedule',
+ order_cycles: [create(:simple_order_cycle, coordinator: other_distributor_managed)])
+ }
before do
# Relationships required for interface to work
# Both suppliers allow both managed distributor to distribute their products (and add them to the order cycle)
- create(:enterprise_relationship, parent: supplier_managed, child: distributor_managed, permissions_list: [:add_to_order_cycle])
- create(:enterprise_relationship, parent: supplier_permitted, child: distributor_managed, permissions_list: [:add_to_order_cycle])
+ create(:enterprise_relationship, parent: supplier_managed, child: distributor_managed,
+ permissions_list: [:add_to_order_cycle])
+ create(:enterprise_relationship, parent: supplier_permitted, child: distributor_managed,
+ permissions_list: [:add_to_order_cycle])
# Both suppliers allow permitted distributor to distribute their products
- create(:enterprise_relationship, parent: supplier_managed, child: distributor_permitted, permissions_list: [:add_to_order_cycle])
- create(:enterprise_relationship, parent: supplier_permitted, child: distributor_permitted, permissions_list: [:add_to_order_cycle])
+ create(:enterprise_relationship, parent: supplier_managed, child: distributor_permitted,
+ permissions_list: [:add_to_order_cycle])
+ create(:enterprise_relationship, parent: supplier_permitted, child: distributor_permitted,
+ permissions_list: [:add_to_order_cycle])
# Permitted distributor can be added to the order cycle
- create(:enterprise_relationship, parent: distributor_permitted, child: distributor_managed, permissions_list: [:add_to_order_cycle])
+ create(:enterprise_relationship, parent: distributor_permitted, child: distributor_managed,
+ permissions_list: [:add_to_order_cycle])
end
context "that is a manager of the coordinator" do
@@ -156,8 +178,10 @@ feature '
end
scenario "viewing a list of order cycles I am coordinating" do
- oc_user_coordinating = create(:simple_order_cycle, suppliers: [supplier_managed, supplier_unmanaged], coordinator: distributor_managed, distributors: [distributor_managed, distributor_unmanaged], name: 'Order Cycle 1' )
- oc_for_other_user = create(:simple_order_cycle, coordinator: supplier_unmanaged, name: 'Order Cycle 2' )
+ oc_user_coordinating = create(:simple_order_cycle,
+ suppliers: [supplier_managed, supplier_unmanaged], coordinator: distributor_managed, distributors: [distributor_managed, distributor_unmanaged], name: 'Order Cycle 1' )
+ oc_for_other_user = create(:simple_order_cycle, coordinator: supplier_unmanaged,
+ name: 'Order Cycle 2' )
visit spree.admin_dashboard_path
click_link "Order Cycles"
@@ -180,7 +204,8 @@ feature '
visit admin_order_cycles_path
click_link 'New Order Cycle'
- [distributor_unmanaged.name, supplier_managed.name, supplier_unmanaged.name].each do |enterprise_name|
+ [distributor_unmanaged.name, supplier_managed.name,
+ supplier_unmanaged.name].each do |enterprise_name|
expect(page).not_to have_select 'coordinator_id', with_options: [enterprise_name]
end
select2_select 'Managed distributor', from: 'coordinator_id'
@@ -189,7 +214,8 @@ feature '
fill_in 'order_cycle_name', with: 'My order cycle'
fill_in 'order_cycle_orders_open_at', with: '2040-11-06 06:00:00'
fill_in 'order_cycle_orders_close_at', with: '2040-11-13 17:00:00'
- expect(page).not_to have_select2 'schedule_ids', with_options: [schedule_of_other_managed_distributor.name]
+ expect(page).not_to have_select2 'schedule_ids',
+ with_options: [schedule_of_other_managed_distributor.name]
select2_select schedule.name, from: 'schedule_ids'
click_button 'Add coordinator fee'
@@ -213,7 +239,8 @@ feature '
expect(page).to_not have_content "Loading..."
expect(page).to have_select 'new_distributor_id'
- expect(page).not_to have_select 'new_distributor_id', with_options: [distributor_unmanaged.name]
+ expect(page).not_to have_select 'new_distributor_id',
+ with_options: [distributor_unmanaged.name]
select 'Managed distributor', from: 'new_distributor_id'
click_button 'Add distributor'
select 'Permitted distributor', from: 'new_distributor_id'
@@ -246,14 +273,16 @@ feature '
end
scenario "editing an order cycle" do
- oc = create(:simple_order_cycle, suppliers: [supplier_managed, supplier_permitted, supplier_unmanaged], coordinator: distributor_managed, distributors: [distributor_managed, distributor_permitted, distributor_unmanaged], name: 'Order Cycle 1' )
+ oc = create(:simple_order_cycle,
+ suppliers: [supplier_managed, supplier_permitted, supplier_unmanaged], coordinator: distributor_managed, distributors: [distributor_managed, distributor_permitted, distributor_unmanaged], name: 'Order Cycle 1' )
distributor_managed.update_attribute(:enable_subscriptions, true)
visit edit_admin_order_cycle_path(oc)
expect(page).to have_field 'order_cycle_name', with: oc.name
select2_select schedule.name, from: 'schedule_ids'
- expect(page).not_to have_select2 'schedule_ids', with_options: [schedule_of_other_managed_distributor.name]
+ expect(page).not_to have_select2 'schedule_ids',
+ with_options: [schedule_of_other_managed_distributor.name]
click_button 'Save and Next'
@@ -299,16 +328,19 @@ feature '
end
scenario "editing an order cycle" do
- oc = create(:simple_order_cycle, suppliers: [supplier_managed, supplier_permitted, supplier_unmanaged], coordinator: distributor_managed, distributors: [distributor_managed, distributor_permitted, distributor_unmanaged], name: 'Order Cycle 1' )
+ oc = create(:simple_order_cycle,
+ suppliers: [supplier_managed, supplier_permitted, supplier_unmanaged], coordinator: distributor_managed, distributors: [distributor_managed, distributor_permitted, distributor_unmanaged], name: 'Order Cycle 1' )
v1 = create(:variant, product: create(:product, supplier: supplier_managed) )
v2 = create(:variant, product: create(:product, supplier: supplier_managed) )
# Incoming exchange
- ex_in = oc.exchanges.where(sender_id: supplier_managed, receiver_id: distributor_managed, incoming: true).first
+ ex_in = oc.exchanges.where(sender_id: supplier_managed, receiver_id: distributor_managed,
+ incoming: true).first
ex_in.update(variant_ids: [v1.id, v2.id])
# Outgoing exchange
- ex_out = oc.exchanges.where(sender_id: distributor_managed, receiver_id: distributor_managed, incoming: false).first
+ ex_out = oc.exchanges.where(sender_id: distributor_managed,
+ receiver_id: distributor_managed, incoming: false).first
ex_out.update(variant_ids: [v1.id, v2.id])
# Stub editable_variants_for_outgoing_exchanges method so we can test permissions
@@ -336,11 +368,13 @@ feature '
end
# I should be able to see and toggle v1
- expect(page).to have_checked_field "order_cycle_outgoing_exchange_0_variants_#{v1.id}", disabled: false
+ expect(page).to have_checked_field "order_cycle_outgoing_exchange_0_variants_#{v1.id}",
+ disabled: false
uncheck "order_cycle_outgoing_exchange_0_variants_#{v1.id}"
# I should be able to see but not toggle v2, because I don't have permission
- expect(page).to have_checked_field "order_cycle_outgoing_exchange_0_variants_#{v2.id}", disabled: true
+ expect(page).to have_checked_field "order_cycle_outgoing_exchange_0_variants_#{v2.id}",
+ disabled: true
expect(page).not_to have_selector "table.exchanges tr.distributor-#{distributor_managed.id} td.tags"
@@ -349,9 +383,11 @@ feature '
expect(page).to have_content "Your order cycle has been updated."
oc.reload
- expect(oc.suppliers).to match_array [supplier_managed, supplier_permitted, supplier_unmanaged]
+ expect(oc.suppliers).to match_array [supplier_managed, supplier_permitted,
+ supplier_unmanaged]
expect(oc.coordinator).to eq(distributor_managed)
- expect(oc.distributors).to match_array [distributor_managed, distributor_permitted, distributor_unmanaged]
+ expect(oc.distributors).to match_array [distributor_managed, distributor_permitted,
+ distributor_unmanaged]
end
end
@@ -360,23 +396,27 @@ feature '
let(:new_user) { create(:user) }
before do
- create(:enterprise_relationship, parent: supplier_managed, child: my_distributor, permissions_list: [:add_to_order_cycle])
+ create(:enterprise_relationship, parent: supplier_managed, child: my_distributor,
+ permissions_list: [:add_to_order_cycle])
new_user.enterprise_roles.build(enterprise: my_distributor).save
login_to_admin_as new_user
end
scenario "editing an order cycle" do
- oc = create(:simple_order_cycle, suppliers: [supplier_managed, supplier_permitted, supplier_unmanaged], coordinator: distributor_managed, distributors: [my_distributor, distributor_managed, distributor_permitted, distributor_unmanaged], name: 'Order Cycle 1' )
+ oc = create(:simple_order_cycle,
+ suppliers: [supplier_managed, supplier_permitted, supplier_unmanaged], coordinator: distributor_managed, distributors: [my_distributor, distributor_managed, distributor_permitted, distributor_unmanaged], name: 'Order Cycle 1' )
v1 = create(:variant, product: create(:product, supplier: supplier_managed) )
v2 = create(:variant, product: create(:product, supplier: supplier_managed) )
# Incoming exchange
- ex_in = oc.exchanges.where(sender_id: supplier_managed, receiver_id: distributor_managed, incoming: true).first
+ ex_in = oc.exchanges.where(sender_id: supplier_managed, receiver_id: distributor_managed,
+ incoming: true).first
ex_in.update(variant_ids: [v1.id, v2.id])
# Outgoing exchange
- ex_out = oc.exchanges.where(sender_id: distributor_managed, receiver_id: my_distributor, incoming: false).first
+ ex_out = oc.exchanges.where(sender_id: distributor_managed, receiver_id: my_distributor,
+ incoming: false).first
ex_out.update(variant_ids: [v1.id, v2.id])
# Stub editable_variants_for_incoming_exchanges method so we can test permissions
@@ -404,11 +444,13 @@ feature '
# I should be able to see and toggle v1
expect(page).to have_selector ".exchange-product-variant"
- expect(page).to have_checked_field "order_cycle_incoming_exchange_0_variants_#{v1.id}", disabled: false
+ expect(page).to have_checked_field "order_cycle_incoming_exchange_0_variants_#{v1.id}",
+ disabled: false
uncheck "order_cycle_incoming_exchange_0_variants_#{v1.id}"
# I should be able to see but not toggle v2, because I don't have permission
- expect(page).to have_checked_field "order_cycle_incoming_exchange_0_variants_#{v2.id}", disabled: true
+ expect(page).to have_checked_field "order_cycle_incoming_exchange_0_variants_#{v2.id}",
+ disabled: true
# When I save, any exchange that I can't manage remains
click_button 'Save and Next'
@@ -417,9 +459,11 @@ feature '
expect(page).to have_selector "table.exchanges tr.distributor-#{my_distributor.id} td.tags"
oc.reload
- expect(oc.suppliers).to match_array [supplier_managed, supplier_permitted, supplier_unmanaged]
+ expect(oc.suppliers).to match_array [supplier_managed, supplier_permitted,
+ supplier_unmanaged]
expect(oc.coordinator).to eq(distributor_managed)
- expect(oc.distributors).to match_array [my_distributor, distributor_managed, distributor_permitted, distributor_unmanaged]
+ expect(oc.distributors).to match_array [my_distributor, distributor_managed,
+ distributor_permitted, distributor_unmanaged]
end
end
end
@@ -496,8 +540,10 @@ feature '
oc = OrderCycle.last
expect(page).to have_input "oc#{oc.id}[name]", value: "Plums & Avos"
- expect(page).to have_input "oc#{oc.id}[orders_open_at]", value: Time.zone.local(2040, 10, 17, 0o6, 0o0, 0o0).strftime("%F %T %z"), visible: false
- expect(page).to have_input "oc#{oc.id}[orders_close_at]", value: Time.zone.local(2040, 10, 24, 17, 0o0, 0o0).strftime("%F %T %z"), visible: false
+ expect(page).to have_input "oc#{oc.id}[orders_open_at]",
+ value: Time.zone.local(2040, 10, 17, 0o6, 0o0, 0o0).strftime("%F %T %z"), visible: false
+ expect(page).to have_input "oc#{oc.id}[orders_close_at]",
+ value: Time.zone.local(2040, 10, 24, 17, 0o0, 0o0).strftime("%F %T %z"), visible: false
# And it should have some variants selected
expect(oc.exchanges.incoming.first.variants.count).to eq(2)
@@ -515,7 +561,8 @@ feature '
scenario "editing an order cycle" do
# Given an order cycle with pickup time and instructions
fee = create(:enterprise_fee, name: 'my fee', enterprise: enterprise)
- oc = create(:simple_order_cycle, suppliers: [enterprise], coordinator: enterprise, distributors: [enterprise], variants: [v1], coordinator_fees: [fee])
+ oc = create(:simple_order_cycle, suppliers: [enterprise], coordinator: enterprise,
+ distributors: [enterprise], variants: [v1], coordinator_fees: [fee])
ex = oc.exchanges.outgoing.first
ex.update! pickup_time: 'pickup time', pickup_instructions: 'pickup instructions'
@@ -529,10 +576,13 @@ feature '
# Then I should see the basic settings
expect(page).to have_field 'order_cycle_name', with: oc.name
- expect(page).to have_field 'order_cycle_orders_open_at', with: oc.orders_open_at.strftime("%Y-%m-%d %H:%M")
- expect(page).to have_field 'order_cycle_orders_close_at', with: oc.orders_close_at.strftime("%Y-%m-%d %H:%M")
+ expect(page).to have_field 'order_cycle_orders_open_at',
+ with: oc.orders_open_at.strftime("%Y-%m-%d %H:%M")
+ expect(page).to have_field 'order_cycle_orders_close_at',
+ with: oc.orders_close_at.strftime("%Y-%m-%d %H:%M")
expect(page).to have_field 'order_cycle_outgoing_exchange_0_pickup_time', with: 'pickup time'
- expect(page).to have_field 'order_cycle_outgoing_exchange_0_pickup_instructions', with: 'pickup instructions'
+ expect(page).to have_field 'order_cycle_outgoing_exchange_0_pickup_instructions',
+ with: 'pickup instructions'
# And I should see the products
expect(page).to have_checked_field "order_cycle_incoming_exchange_0_variants_#{v1.id}"
@@ -547,7 +597,8 @@ feature '
# Given an order cycle with pickup time and instructions
fee1 = create(:enterprise_fee, name: 'my fee', enterprise: enterprise)
fee2 = create(:enterprise_fee, name: 'that fee', enterprise: enterprise)
- oc = create(:simple_order_cycle, suppliers: [enterprise], coordinator: enterprise, distributors: [enterprise], variants: [v1], coordinator_fees: [fee1])
+ oc = create(:simple_order_cycle, suppliers: [enterprise], coordinator: enterprise,
+ distributors: [enterprise], variants: [v1], coordinator_fees: [fee1])
ex = oc.exchanges.outgoing.first
ex.update! pickup_time: 'pickup time', pickup_instructions: 'pickup instructions'
@@ -587,8 +638,10 @@ feature '
oc = OrderCycle.last
expect(page).to have_input "oc#{oc.id}[name]", value: "Plums & Avos"
- expect(page).to have_input "oc#{oc.id}[orders_open_at]", value: Time.zone.local(2040, 10, 17, 0o6, 0o0, 0o0).strftime("%F %T %z"), visible: false
- expect(page).to have_input "oc#{oc.id}[orders_close_at]", value: Time.zone.local(2040, 10, 24, 17, 0o0, 0o0).strftime("%F %T %z"), visible: false
+ expect(page).to have_input "oc#{oc.id}[orders_open_at]",
+ value: Time.zone.local(2040, 10, 17, 0o6, 0o0, 0o0).strftime("%F %T %z"), visible: false
+ expect(page).to have_input "oc#{oc.id}[orders_close_at]",
+ value: Time.zone.local(2040, 10, 24, 17, 0o0, 0o0).strftime("%F %T %z"), visible: false
# And it should have a variant selected
expect(oc.exchanges.incoming.first.variants).to eq([v2])
diff --git a/spec/features/admin/order_spec.rb b/spec/features/admin/order_spec.rb
index 9ed8df28d0..8a9404f870 100644
--- a/spec/features/admin/order_spec.rb
+++ b/spec/features/admin/order_spec.rb
@@ -176,8 +176,10 @@ feature '
# Regression test for #7337
context "creating a new order with a variant override" do
- let!(:override) { create(:variant_override, hub: distributor, variant: product.variants.first,
- count_on_hand: 100) }
+ let!(:override) {
+ create(:variant_override, hub: distributor, variant: product.variants.first,
+ count_on_hand: 100)
+ }
before do
product.variants.first.update(on_demand: false, on_hand: 0)
@@ -358,7 +360,8 @@ feature '
href: spree.resend_admin_order_path(order)
expect(page).to have_link "Send Invoice", href: spree.invoice_admin_order_path(order)
expect(page).to have_link "Print Invoice", href: spree.print_admin_order_path(order)
- expect(page).to have_link "Cancel Order", href: spree.fire_admin_order_path(order, e: 'cancel')
+ expect(page).to have_link "Cancel Order",
+ href: spree.fire_admin_order_path(order, e: 'cancel')
end
end
diff --git a/spec/features/admin/overview_spec.rb b/spec/features/admin/overview_spec.rb
index 5c72bb5e5f..fb1c772b4b 100644
--- a/spec/features/admin/overview_spec.rb
+++ b/spec/features/admin/overview_spec.rb
@@ -26,7 +26,8 @@ feature '
it "displays a link to the map page" do
visit '/admin'
expect(page).to have_selector ".dashboard_item h3", text: "Your profile live"
- expect(page).to have_selector ".dashboard_item .button.bottom", text: "SEE #{d1.name.upcase} LIVE"
+ expect(page).to have_selector ".dashboard_item .button.bottom",
+ text: "SEE #{d1.name.upcase} LIVE"
end
context "when visibilty is set to false" do
@@ -37,7 +38,8 @@ feature '
it "displays a message telling how to set visibility" do
visit '/admin'
- expect(page).to have_selector ".alert-box", text: "To allow people to find you, turn on your visibility under Manage #{d1.name}."
+ expect(page).to have_selector ".alert-box",
+ text: "To allow people to find you, turn on your visibility under Manage #{d1.name}."
end
end
@@ -73,19 +75,25 @@ feature '
expect(page).to have_selector ".dashboard_item#products"
expect(page).to have_selector ".dashboard_item#order_cycles"
expect(page).to have_selector ".dashboard_item#enterprises .list-item", text: d1.name
- expect(page).to have_selector ".dashboard_item#enterprises .list-item", text: non_distributor_enterprise.name
- expect(page).to have_selector ".dashboard_item#enterprises .button.bottom", text: "MANAGE MY ENTERPRISES"
+ expect(page).to have_selector ".dashboard_item#enterprises .list-item",
+ text: non_distributor_enterprise.name
+ expect(page).to have_selector ".dashboard_item#enterprises .button.bottom",
+ text: "MANAGE MY ENTERPRISES"
end
context "but no products or order cycles" do
it "prompts the user to create a new product and to manage order cycles" do
visit '/admin'
expect(page).to have_selector ".dashboard_item#products h3", text: "Products"
- expect(page).to have_selector ".dashboard_item#products .list-item", text: "You don't have any active products."
- expect(page).to have_selector ".dashboard_item#products .button.bottom", text: "CREATE A NEW PRODUCT"
+ expect(page).to have_selector ".dashboard_item#products .list-item",
+ text: "You don't have any active products."
+ expect(page).to have_selector ".dashboard_item#products .button.bottom",
+ text: "CREATE A NEW PRODUCT"
expect(page).to have_selector ".dashboard_item#order_cycles h3", text: "Order Cycles"
- expect(page).to have_selector ".dashboard_item#order_cycles .list-item", text: "You don't have any active order cycles."
- expect(page).to have_selector ".dashboard_item#order_cycles .button.bottom", text: "MANAGE ORDER CYCLES"
+ expect(page).to have_selector ".dashboard_item#order_cycles .list-item",
+ text: "You don't have any active order cycles."
+ expect(page).to have_selector ".dashboard_item#order_cycles .button.bottom",
+ text: "MANAGE ORDER CYCLES"
end
end
@@ -96,11 +104,15 @@ feature '
it "displays information about products and order cycles" do
visit '/admin'
expect(page).to have_selector ".dashboard_item#products h3", text: "Products"
- expect(page).to have_selector ".dashboard_item#products .list-item", text: "You don't have any active products."
- expect(page).to have_selector ".dashboard_item#products .button.bottom", text: "CREATE A NEW PRODUCT"
+ expect(page).to have_selector ".dashboard_item#products .list-item",
+ text: "You don't have any active products."
+ expect(page).to have_selector ".dashboard_item#products .button.bottom",
+ text: "CREATE A NEW PRODUCT"
expect(page).to have_selector ".dashboard_item#order_cycles h3", text: "Order Cycles"
- expect(page).to have_selector ".dashboard_item#order_cycles .list-item", text: "You don't have any active order cycles."
- expect(page).to have_selector ".dashboard_item#order_cycles .button.bottom", text: "MANAGE ORDER CYCLES"
+ expect(page).to have_selector ".dashboard_item#order_cycles .list-item",
+ text: "You don't have any active order cycles."
+ expect(page).to have_selector ".dashboard_item#order_cycles .button.bottom",
+ text: "MANAGE ORDER CYCLES"
end
end
end
diff --git a/spec/features/admin/payment_method_spec.rb b/spec/features/admin/payment_method_spec.rb
index 38ffa8b960..7663e5736f 100644
--- a/spec/features/admin/payment_method_spec.rb
+++ b/spec/features/admin/payment_method_spec.rb
@@ -32,12 +32,26 @@ feature '
context "using stripe connect" do
let(:user) { create(:user, enterprise_limit: 5) }
- let!(:connected_enterprise) { create(:distributor_enterprise, name: "Connected", owner: user) }
- let!(:revoked_account_enterprise) { create(:distributor_enterprise, name: "Revoked", owner: user) }
- let!(:missing_account_enterprise) { create(:distributor_enterprise, name: "Missing", owner: user) }
- let!(:valid_stripe_account) { create(:stripe_account, enterprise: connected_enterprise, stripe_user_id: "acc_connected123") }
- let!(:disconnected_stripe_account) { create(:stripe_account, enterprise: revoked_account_enterprise, stripe_user_id: "acc_revoked123") }
- let!(:stripe_account_mock) { { id: "acc_connected123", business_name: "My Org", charges_enabled: true } }
+ let!(:connected_enterprise) {
+ create(:distributor_enterprise, name: "Connected", owner: user)
+ }
+ let!(:revoked_account_enterprise) {
+ create(:distributor_enterprise, name: "Revoked", owner: user)
+ }
+ let!(:missing_account_enterprise) {
+ create(:distributor_enterprise, name: "Missing", owner: user)
+ }
+ let!(:valid_stripe_account) {
+ create(:stripe_account, enterprise: connected_enterprise,
+ stripe_user_id: "acc_connected123")
+ }
+ let!(:disconnected_stripe_account) {
+ create(:stripe_account, enterprise: revoked_account_enterprise,
+ stripe_user_id: "acc_revoked123")
+ }
+ let!(:stripe_account_mock) {
+ { id: "acc_connected123", business_name: "My Org", charges_enabled: true }
+ }
around do |example|
original_stripe_connect_enabled = Spree::Config[:stripe_connect_enabled]
@@ -48,8 +62,10 @@ feature '
before do
Spree::Config.set(stripe_connect_enabled: true)
Stripe.api_key = "sk_test_12345"
- stub_request(:get, "https://api.stripe.com/v1/accounts/acc_connected123").to_return(body: JSON.generate(stripe_account_mock))
- stub_request(:get, "https://api.stripe.com/v1/accounts/acc_revoked123").to_return(status: 404)
+ stub_request(:get,
+ "https://api.stripe.com/v1/accounts/acc_connected123").to_return(body: JSON.generate(stripe_account_mock))
+ stub_request(:get,
+ "https://api.stripe.com/v1/accounts/acc_revoked123").to_return(status: 404)
end
it "communicates the status of the stripe connection to the user" do
@@ -59,32 +75,43 @@ feature '
select2_select "Stripe", from: "payment_method_type"
select2_select "Missing", from: "payment_method_preferred_enterprise_id"
- expect(page).to have_selector "#stripe-account-status .alert-box.error", text: I18n.t("spree.admin.payment_methods.stripe_connect.account_missing_msg")
+ expect(page).to have_selector "#stripe-account-status .alert-box.error",
+ text: I18n.t("spree.admin.payment_methods.stripe_connect.account_missing_msg")
connect_one = I18n.t("spree.admin.payment_methods.stripe_connect.connect_one")
- expect(page).to have_link connect_one, href: edit_admin_enterprise_path(missing_account_enterprise, anchor: "/payment_methods")
+ expect(page).to have_link connect_one,
+ href: edit_admin_enterprise_path(missing_account_enterprise,
+ anchor: "/payment_methods")
select2_select "Revoked", from: "payment_method_preferred_enterprise_id"
- expect(page).to have_selector "#stripe-account-status .alert-box.error", text: I18n.t("spree.admin.payment_methods.stripe_connect.access_revoked_msg")
+ expect(page).to have_selector "#stripe-account-status .alert-box.error",
+ text: I18n.t("spree.admin.payment_methods.stripe_connect.access_revoked_msg")
select2_select "Connected", from: "payment_method_preferred_enterprise_id"
expect(page).to have_selector "#stripe-account-status .status", text: "Status: Connected"
- expect(page).to have_selector "#stripe-account-status .account_id", text: "Account ID: acc_connected123"
- expect(page).to have_selector "#stripe-account-status .business_name", text: "Business Name: My Org"
- expect(page).to have_selector "#stripe-account-status .charges_enabled", text: "Charges Enabled: Yes"
+ expect(page).to have_selector "#stripe-account-status .account_id",
+ text: "Account ID: acc_connected123"
+ expect(page).to have_selector "#stripe-account-status .business_name",
+ text: "Business Name: My Org"
+ expect(page).to have_selector "#stripe-account-status .charges_enabled",
+ text: "Charges Enabled: Yes"
end
end
scenario "checking a single distributor is checked by default" do
2.times.each { Enterprise.last.destroy }
login_as_admin_and_visit spree.new_admin_payment_method_path
- expect(page).to have_field "payment_method_distributor_ids_#{@distributors[0].id}", checked: true
+ expect(page).to have_field "payment_method_distributor_ids_#{@distributors[0].id}",
+ checked: true
end
scenario "checking more than a distributor displays no default choice" do
login_as_admin_and_visit spree.new_admin_payment_method_path
- expect(page).to have_field "payment_method_distributor_ids_#{@distributors[0].id}", checked: false
- expect(page).to have_field "payment_method_distributor_ids_#{@distributors[1].id}", checked: false
- expect(page).to have_field "payment_method_distributor_ids_#{@distributors[2].id}", checked: false
+ expect(page).to have_field "payment_method_distributor_ids_#{@distributors[0].id}",
+ checked: false
+ expect(page).to have_field "payment_method_distributor_ids_#{@distributors[1].id}",
+ checked: false
+ expect(page).to have_field "payment_method_distributor_ids_#{@distributors[2].id}",
+ checked: false
end
end
@@ -139,7 +166,9 @@ feature '
let(:distributor2) { create(:distributor_enterprise, name: 'Second Distributor') }
let(:distributor3) { create(:distributor_enterprise, name: 'Third Distributor') }
let(:payment_method1) { create(:payment_method, name: 'One', distributors: [distributor1]) }
- let(:payment_method2) { create(:payment_method, name: 'Two', distributors: [distributor1, distributor2]) }
+ let(:payment_method2) {
+ create(:payment_method, name: 'Two', distributors: [distributor1, distributor2])
+ }
let(:payment_method3) { create(:payment_method, name: 'Three', distributors: [distributor3]) }
before(:each) do
@@ -299,5 +328,4 @@ feature '
end
end
end
-
end
diff --git a/spec/features/admin/payments_stripe_spec.rb b/spec/features/admin/payments_stripe_spec.rb
index a4467a4f5a..60cbf7f289 100644
--- a/spec/features/admin/payments_stripe_spec.rb
+++ b/spec/features/admin/payments_stripe_spec.rb
@@ -94,7 +94,7 @@ feature '
stub_payment_intents_post_request order: order, stripe_account_header: true
stub_successful_capture_request order: order
- while !order.payment? do break unless order.next! end
+ break unless order.next! while !order.payment?
end
it "adds a payment with state complete" do
diff --git a/spec/features/admin/product_import_spec.rb b/spec/features/admin/product_import_spec.rb
index 7efc715bb0..2ec27b0a7c 100644
--- a/spec/features/admin/product_import_spec.rb
+++ b/spec/features/admin/product_import_spec.rb
@@ -13,7 +13,10 @@ feature "Product Import", js: true do
let!(:user2) { create(:user) }
let!(:enterprise) { create(:supplier_enterprise, owner: user, name: "User Enterprise") }
let!(:enterprise2) { create(:distributor_enterprise, owner: user2, name: "Another Enterprise") }
- let!(:relationship) { create(:enterprise_relationship, parent: enterprise, child: enterprise2, permissions_list: [:create_variant_overrides]) }
+ let!(:relationship) {
+ create(:enterprise_relationship, parent: enterprise, child: enterprise2,
+ permissions_list: [:create_variant_overrides])
+ }
let!(:category) { create(:taxon, name: 'Vegetables') }
let!(:category2) { create(:taxon, name: 'Cake') }
@@ -22,13 +25,31 @@ feature "Product Import", js: true do
let!(:shipping_category) { create(:shipping_category) }
let!(:product) { create(:simple_product, supplier: enterprise2, name: 'Hypothetical Cake') }
- let!(:variant) { create(:variant, product_id: product.id, price: '8.50', on_hand: 100, unit_value: '500', display_name: 'Preexisting Banana') }
- let!(:product2) { create(:simple_product, supplier: enterprise, on_hand: 100, name: 'Beans', unit_value: '500', description: '', primary_taxon_id: category.id) }
- let!(:product3) { create(:simple_product, supplier: enterprise, on_hand: 100, name: 'Sprouts', unit_value: '500') }
- let!(:product4) { create(:simple_product, supplier: enterprise, on_hand: 100, name: 'Cabbage', unit_value: '500') }
- let!(:product5) { create(:simple_product, supplier: enterprise2, on_hand: 100, name: 'Lettuce', unit_value: '500') }
- let!(:variant_override) { create(:variant_override, variant_id: product4.variants.first.id, hub: enterprise2, count_on_hand: 42) }
- let!(:variant_override2) { create(:variant_override, variant_id: product5.variants.first.id, hub: enterprise, count_on_hand: 96) }
+ let!(:variant) {
+ create(:variant, product_id: product.id, price: '8.50', on_hand: 100, unit_value: '500',
+ display_name: 'Preexisting Banana')
+ }
+ let!(:product2) {
+ create(:simple_product, supplier: enterprise, on_hand: 100, name: 'Beans', unit_value: '500',
+ description: '', primary_taxon_id: category.id)
+ }
+ let!(:product3) {
+ create(:simple_product, supplier: enterprise, on_hand: 100, name: 'Sprouts', unit_value: '500')
+ }
+ let!(:product4) {
+ create(:simple_product, supplier: enterprise, on_hand: 100, name: 'Cabbage', unit_value: '500')
+ }
+ let!(:product5) {
+ create(:simple_product, supplier: enterprise2, on_hand: 100, name: 'Lettuce', unit_value: '500')
+ }
+ let!(:variant_override) {
+ create(:variant_override, variant_id: product4.variants.first.id, hub: enterprise2,
+ count_on_hand: 42)
+ }
+ let!(:variant_override2) {
+ create(:variant_override, variant_id: product5.variants.first.id, hub: enterprise,
+ count_on_hand: 96)
+ }
let(:shipping_category_id_str) { Spree::ShippingCategory.all.first.id.to_s }
@@ -41,9 +62,12 @@ feature "Product Import", js: true do
it "validates entries and saves them if they are all valid and allows viewing new items in Bulk Products" do
csv_data = CSV.generate do |csv|
- csv << ["name", "producer", "category", "on_hand", "price", "units", "unit_type", "shipping_category_id"]
- csv << ["Carrots", "User Enterprise", "Vegetables", "5", "3.20", "500", "g", shipping_category_id_str]
- csv << ["Potatoes", "User Enterprise", "Vegetables", "6", "6.50", "1", "kg", shipping_category_id_str]
+ csv << ["name", "producer", "category", "on_hand", "price", "units", "unit_type",
+ "shipping_category_id"]
+ csv << ["Carrots", "User Enterprise", "Vegetables", "5", "3.20", "500", "g",
+ shipping_category_id_str]
+ csv << ["Potatoes", "User Enterprise", "Vegetables", "6", "6.50", "1", "kg",
+ shipping_category_id_str]
end
File.write('/tmp/test.csv', csv_data)
@@ -84,10 +108,14 @@ feature "Product Import", js: true do
it "displays info about invalid entries but no save button if all items are invalid" do
csv_data = CSV.generate do |csv|
- csv << ["name", "producer", "category", "on_hand", "price", "units", "unit_type", "shipping_category_id"]
- csv << ["Carrots", "User Enterprise", "Vegetables", "5", "3.20", "500", "g", shipping_category_id_str]
- csv << ["Carrots", "User Enterprise", "Vegetables", "5", "5.50", "1", "kg", shipping_category_id_str]
- csv << ["Bad Carrots", "Unkown Enterprise", "Mouldy vegetables", "666", "3.20", "", "g", shipping_category_id_str]
+ csv << ["name", "producer", "category", "on_hand", "price", "units", "unit_type",
+ "shipping_category_id"]
+ csv << ["Carrots", "User Enterprise", "Vegetables", "5", "3.20", "500", "g",
+ shipping_category_id_str]
+ csv << ["Carrots", "User Enterprise", "Vegetables", "5", "5.50", "1", "kg",
+ shipping_category_id_str]
+ csv << ["Bad Carrots", "Unkown Enterprise", "Mouldy vegetables", "666", "3.20", "", "g",
+ shipping_category_id_str]
csv << ["Bad Potatoes", "", "Vegetables", "6", "6", "6", ""]
end
File.write('/tmp/test.csv', csv_data)
@@ -110,8 +138,10 @@ feature "Product Import", js: true do
it "handles saving of named tax and shipping categories" do
csv_data = CSV.generate do |csv|
- csv << ["name", "producer", "category", "on_hand", "price", "units", "unit_type", "tax_category", "shipping_category"]
- csv << ["Carrots", "User Enterprise", "Vegetables", "5", "3.20", "500", "g", tax_category.name, shipping_category.name]
+ csv << ["name", "producer", "category", "on_hand", "price", "units", "unit_type",
+ "tax_category", "shipping_category"]
+ csv << ["Carrots", "User Enterprise", "Vegetables", "5", "3.20", "500", "g",
+ tax_category.name, shipping_category.name]
end
File.write('/tmp/test.csv', csv_data)
@@ -139,9 +169,12 @@ feature "Product Import", js: true do
it "records a timestamp on import that can be viewed and filtered under Bulk Edit Products" do
csv_data = CSV.generate do |csv|
- csv << ["name", "producer", "category", "on_hand", "price", "units", "unit_type", "shipping_category_id"]
- csv << ["Carrots", "User Enterprise", "Vegetables", "5", "3.20", "500", "g", shipping_category_id_str]
- csv << ["Potatoes", "User Enterprise", "Vegetables", "6", "6.50", "1", "kg", shipping_category_id_str]
+ csv << ["name", "producer", "category", "on_hand", "price", "units", "unit_type",
+ "shipping_category_id"]
+ csv << ["Carrots", "User Enterprise", "Vegetables", "5", "3.20", "500", "g",
+ shipping_category_id_str]
+ csv << ["Potatoes", "User Enterprise", "Vegetables", "6", "6.50", "1", "kg",
+ shipping_category_id_str]
end
File.write('/tmp/test.csv', csv_data)
@@ -185,8 +218,10 @@ feature "Product Import", js: true do
it "can reset product stock to zero for products not present in the CSV" do
csv_data = CSV.generate do |csv|
- csv << ["name", "producer", "category", "on_hand", "price", "units", "unit_type", "shipping_category_id"]
- csv << ["Carrots", "User Enterprise", "Vegetables", "500", "3.20", "500", "g", shipping_category_id_str]
+ csv << ["name", "producer", "category", "on_hand", "price", "units", "unit_type",
+ "shipping_category_id"]
+ csv << ["Carrots", "User Enterprise", "Vegetables", "500", "3.20", "500", "g",
+ shipping_category_id_str]
end
File.write('/tmp/test.csv', csv_data)
@@ -212,10 +247,14 @@ feature "Product Import", js: true do
it "can save a new product and variant of that product at the same time, add variant to existing product" do
csv_data = CSV.generate do |csv|
- csv << ["name", "producer", "category", "on_hand", "price", "units", "unit_type", "display_name", "shipping_category_id"]
- csv << ["Potatoes", "User Enterprise", "Vegetables", "5", "3.50", "500", "g", "Small Bag", shipping_category_id_str]
- csv << ["Potatoes", "User Enterprise", "Vegetables", "6", "5.50", "2000", "g", "Big Bag", shipping_category_id_str]
- csv << ["Beans", "User Enterprise", "Vegetables", "7", "2.50", "250", "g", nil, shipping_category_id_str]
+ csv << ["name", "producer", "category", "on_hand", "price", "units", "unit_type",
+ "display_name", "shipping_category_id"]
+ csv << ["Potatoes", "User Enterprise", "Vegetables", "5", "3.50", "500", "g", "Small Bag",
+ shipping_category_id_str]
+ csv << ["Potatoes", "User Enterprise", "Vegetables", "6", "5.50", "2000", "g", "Big Bag",
+ shipping_category_id_str]
+ csv << ["Beans", "User Enterprise", "Vegetables", "7", "2.50", "250", "g", nil,
+ shipping_category_id_str]
end
File.write('/tmp/test.csv', csv_data)
@@ -251,8 +290,10 @@ feature "Product Import", js: true do
csv_data = CSV.generate do |csv|
csv << ["name", "distributor", "producer", "category", "on_hand", "price", "units"]
csv << ["Beans", "Another Enterprise", "User Enterprise", "Vegetables", "5", "3.20", "500"]
- csv << ["Sprouts", "Another Enterprise", "User Enterprise", "Vegetables", "6", "6.50", "500"]
- csv << ["Cabbage", "Another Enterprise", "User Enterprise", "Vegetables", "2001", "1.50", "500"]
+ csv << ["Sprouts", "Another Enterprise", "User Enterprise", "Vegetables", "6", "6.50",
+ "500"]
+ csv << ["Cabbage", "Another Enterprise", "User Enterprise", "Vegetables", "2001", "1.50",
+ "500"]
end
File.write('/tmp/test.csv', csv_data)
@@ -277,9 +318,12 @@ feature "Product Import", js: true do
expect(page).to have_selector '.inv-created-count', text: '2'
expect(page).to have_selector '.inv-updated-count', text: '1'
- beans_override = VariantOverride.where(variant_id: product2.variants.first.id, hub_id: enterprise2.id).first
- sprouts_override = VariantOverride.where(variant_id: product3.variants.first.id, hub_id: enterprise2.id).first
- cabbage_override = VariantOverride.where(variant_id: product4.variants.first.id, hub_id: enterprise2.id).first
+ beans_override = VariantOverride.where(variant_id: product2.variants.first.id,
+ hub_id: enterprise2.id).first
+ sprouts_override = VariantOverride.where(variant_id: product3.variants.first.id,
+ hub_id: enterprise2.id).first
+ cabbage_override = VariantOverride.where(variant_id: product4.variants.first.id,
+ hub_id: enterprise2.id).first
expect(Float(beans_override.price)).to eq 3.20
expect(beans_override.count_on_hand).to eq 5
@@ -303,10 +347,13 @@ feature "Product Import", js: true do
end
it "handles a unit of kg for inventory import" do
- product = create(:simple_product, supplier: enterprise, on_hand: 100, name: 'Beets', unit_value: '1000', variant_unit_scale: 1000)
+ product = create(:simple_product, supplier: enterprise, on_hand: 100, name: 'Beets',
+ unit_value: '1000', variant_unit_scale: 1000)
csv_data = CSV.generate do |csv|
- csv << ["name", "distributor", "producer", "category", "on_hand", "price", "unit_type", "units", "on_demand"]
- csv << ["Beets", "Another Enterprise", "User Enterprise", "Vegetables", nil, "3.20", "kg", "1", "true"]
+ csv << ["name", "distributor", "producer", "category", "on_hand", "price", "unit_type",
+ "units", "on_demand"]
+ csv << ["Beets", "Another Enterprise", "User Enterprise", "Vegetables", nil, "3.20", "kg",
+ "1", "true"]
end
File.write('/tmp/test.csv', csv_data)
@@ -329,16 +376,20 @@ feature "Product Import", js: true do
visit main_app.admin_inventory_path
expect(page).to have_content "Beets"
- expect(page).to have_select "variant-overrides-#{Spree::Product.find_by(name: 'Beets').variants.first.id}-on_demand", selected: "Yes"
- expect(page).to have_input "variant-overrides-#{Spree::Product.find_by(name: 'Beets').variants.first.id}-price", with: "3.2"
+ expect(page).to have_select "variant-overrides-#{Spree::Product.find_by(name: 'Beets').variants.first.id}-on_demand",
+ selected: "Yes"
+ expect(page).to have_input "variant-overrides-#{Spree::Product.find_by(name: 'Beets').variants.first.id}-price",
+ with: "3.2"
end
it "handles the Items unit for inventory import" do
-
- product = create(:simple_product, supplier: enterprise, on_hand: nil, name: 'Aubergine', unit_value: '1', variant_unit_scale: nil, variant_unit: "items", variant_unit_name: "Bag")
+ product = create(:simple_product, supplier: enterprise, on_hand: nil, name: 'Aubergine',
+ unit_value: '1', variant_unit_scale: nil, variant_unit: "items", variant_unit_name: "Bag")
csv_data = CSV.generate do |csv|
- csv << ["name", "distributor", "producer", "category", "on_hand", "price", "unit_type", "units", "on_demand", "variant_unit_name"]
- csv << ["Aubergine", "Another Enterprise", "User Enterprise", "Vegetables", "", "3.3", "kg", "1", "true", "Bag"]
+ csv << ["name", "distributor", "producer", "category", "on_hand", "price", "unit_type",
+ "units", "on_demand", "variant_unit_name"]
+ csv << ["Aubergine", "Another Enterprise", "User Enterprise", "Vegetables", "", "3.3",
+ "kg", "1", "true", "Bag"]
end
File.write('/tmp/test.csv', csv_data)
@@ -357,16 +408,22 @@ feature "Product Import", js: true do
visit main_app.admin_inventory_path
expect(page).to have_content "Aubergine"
- expect(page).to have_select "variant-overrides-#{Spree::Product.find_by(name: 'Aubergine').variants.first.id}-on_demand", selected: "Yes"
- expect(page).to have_input "variant-overrides-#{Spree::Product.find_by(name: 'Aubergine').variants.first.id}-price", with: "3.3"
+ expect(page).to have_select "variant-overrides-#{Spree::Product.find_by(name: 'Aubergine').variants.first.id}-on_demand",
+ selected: "Yes"
+ expect(page).to have_input "variant-overrides-#{Spree::Product.find_by(name: 'Aubergine').variants.first.id}-price",
+ with: "3.3"
end
it "handles on_demand and on_hand validations with inventory" do
csv_data = CSV.generate do |csv|
- csv << ["name", "distributor", "producer", "category", "on_hand", "price", "units", "on_demand"]
- csv << ["Beans", "Another Enterprise", "User Enterprise", "Vegetables", nil, "3.20", "500", "true"]
- csv << ["Sprouts", "Another Enterprise", "User Enterprise", "Vegetables", "6", "6.50", "500", "false"]
- csv << ["Cabbage", "Another Enterprise", "User Enterprise", "Vegetables", nil, "1.50", "500", nil]
+ csv << ["name", "distributor", "producer", "category", "on_hand", "price", "units",
+ "on_demand"]
+ csv << ["Beans", "Another Enterprise", "User Enterprise", "Vegetables", nil, "3.20", "500",
+ "true"]
+ csv << ["Sprouts", "Another Enterprise", "User Enterprise", "Vegetables", "6", "6.50",
+ "500", "false"]
+ csv << ["Cabbage", "Another Enterprise", "User Enterprise", "Vegetables", nil, "1.50",
+ "500", nil]
end
File.write('/tmp/test.csv', csv_data)
@@ -387,9 +444,12 @@ feature "Product Import", js: true do
expect(page).to have_selector '.inv-created-count', text: '2'
expect(page).to have_selector '.inv-updated-count', text: '1'
- beans_override = VariantOverride.where(variant_id: product2.variants.first.id, hub_id: enterprise2.id).first
- sprouts_override = VariantOverride.where(variant_id: product3.variants.first.id, hub_id: enterprise2.id).first
- cabbage_override = VariantOverride.where(variant_id: product4.variants.first.id, hub_id: enterprise2.id).first
+ beans_override = VariantOverride.where(variant_id: product2.variants.first.id,
+ hub_id: enterprise2.id).first
+ sprouts_override = VariantOverride.where(variant_id: product3.variants.first.id,
+ hub_id: enterprise2.id).first
+ cabbage_override = VariantOverride.where(variant_id: product4.variants.first.id,
+ hub_id: enterprise2.id).first
expect(Float(beans_override.price)).to eq 3.20
expect(beans_override.count_on_hand).to be_nil
@@ -406,9 +466,12 @@ feature "Product Import", js: true do
it "imports lines with all allowed units" do
csv_data = CSV.generate do |csv|
- csv << ["name", "producer", "category", "on_hand", "price", "units", "unit_type", "shipping_category_id"]
- csv << ["Carrots", "User Enterprise", "Vegetables", "5", "3.20", "1", "lb", shipping_category_id_str]
- csv << ["Potatoes", "User Enterprise", "Vegetables", "6", "6.50", "8", "oz", shipping_category_id_str]
+ csv << ["name", "producer", "category", "on_hand", "price", "units", "unit_type",
+ "shipping_category_id"]
+ csv << ["Carrots", "User Enterprise", "Vegetables", "5", "3.20", "1", "lb",
+ shipping_category_id_str]
+ csv << ["Potatoes", "User Enterprise", "Vegetables", "6", "6.50", "8", "oz",
+ shipping_category_id_str]
end
File.write('/tmp/test.csv', csv_data)
@@ -435,14 +498,16 @@ feature "Product Import", js: true do
within "#p_#{Spree::Product.find_by(name: 'Carrots').id}" do
expect(page).to have_input "product_name", with: "Carrots"
expect(page).to have_select "variant_unit_with_scale", selected: "Weight (lb)"
- expect(page).to have_content "5" #on_hand
+ expect(page).to have_content "5" # on_hand
end
end
it "imports lines with item products" do
csv_data = CSV.generate do |csv|
- csv << ["name", "producer", "category", "on_hand", "price", "units", "unit_type", "variant_unit_name", "shipping_category_id"]
- csv << ["Cupcake", "User Enterprise", "Cake", "5", "2.2", "1", "", "Bunch", shipping_category_id_str]
+ csv << ["name", "producer", "category", "on_hand", "price", "units", "unit_type",
+ "variant_unit_name", "shipping_category_id"]
+ csv << ["Cupcake", "User Enterprise", "Cake", "5", "2.2", "1", "", "Bunch",
+ shipping_category_id_str]
end
File.write('/tmp/test.csv', csv_data)
@@ -472,14 +537,16 @@ feature "Product Import", js: true do
expect(page).to have_input "product_name", with: "Cupcake"
expect(page).to have_select "variant_unit_with_scale", selected: "Items"
expect(page).to have_input "variant_unit_name", with: "Bunch"
- expect(page).to have_content "5" #on_hand
+ expect(page).to have_content "5" # on_hand
end
end
it "does not allow import for lines with unknown units" do
csv_data = CSV.generate do |csv|
- csv << ["name", "producer", "category", "on_hand", "price", "units", "unit_type", "shipping_category_id"]
- csv << ["Heavy Carrots", "Unkown Enterprise", "Mouldy vegetables", "666", "3.20", "1", "stones", shipping_category_id_str]
+ csv << ["name", "producer", "category", "on_hand", "price", "units", "unit_type",
+ "shipping_category_id"]
+ csv << ["Heavy Carrots", "Unkown Enterprise", "Mouldy vegetables", "666", "3.20", "1",
+ "stones", shipping_category_id_str]
end
File.write('/tmp/test.csv', csv_data)
@@ -550,7 +617,8 @@ feature "Product Import", js: true do
expect(page).to have_no_selector '.create-count'
expect(page).to have_no_selector '.update-count'
expect(page).to have_no_selector 'input[type=submit][value="Save"]'
- expect(flash_message).to match(I18n.t('admin.product_import.model.malformed_csv', error_message: ""))
+ expect(flash_message).to match(I18n.t('admin.product_import.model.malformed_csv',
+ error_message: ""))
File.delete('/tmp/test.csv')
end
@@ -561,9 +629,12 @@ feature "Product Import", js: true do
it "only allows product import into enterprises the user is permitted to manage" do
csv_data = CSV.generate do |csv|
- csv << ["name", "producer", "category", "on_hand", "price", "units", "unit_type", "shipping_category_id"]
- csv << ["My Carrots", "User Enterprise", "Vegetables", "5", "3.20", "500", "g", shipping_category_id_str]
- csv << ["Your Potatoes", "Another Enterprise", "Vegetables", "6", "6.50", "1", "kg", shipping_category_id_str]
+ csv << ["name", "producer", "category", "on_hand", "price", "units", "unit_type",
+ "shipping_category_id"]
+ csv << ["My Carrots", "User Enterprise", "Vegetables", "5", "3.20", "500", "g",
+ shipping_category_id_str]
+ csv << ["Your Potatoes", "Another Enterprise", "Vegetables", "6", "6.50", "1", "kg",
+ shipping_category_id_str]
end
File.write('/tmp/test.csv', csv_data)
@@ -586,10 +657,10 @@ feature "Product Import", js: true do
end
describe "handling a large file (120 data rows)" do
- let!(:producer) {enterprise}
+ let!(:producer) { enterprise }
let!(:tax_category) { create(:tax_category, name: "Tax Category Name") }
let!(:shipping_category) { create(:shipping_category, name: "Shipping Category Name") }
-
+
let!(:csv_file) { file_fixture('sample_file_120_products.csv') }
before do
diff --git a/spec/features/admin/products_spec.rb b/spec/features/admin/products_spec.rb
index 080fd74702..5f8640b30b 100644
--- a/spec/features/admin/products_spec.rb
+++ b/spec/features/admin/products_spec.rb
@@ -114,7 +114,7 @@ feature '
expect(page).to have_content "Unit value can't be blank"
end
end
-
+
describe "deleting", js: true do
let!(:product1) { create(:simple_product, name: 'a product to keep', supplier: @supplier) }
@@ -162,7 +162,9 @@ feature '
end
describe 'cloning' do
- let!(:product1) { create(:simple_product, name: 'a weight product', supplier: @supplier, variant_unit: "weight") }
+ let!(:product1) {
+ create(:simple_product, name: 'a weight product', supplier: @supplier, variant_unit: "weight")
+ }
context 'products', js: true do
before { login_as_admin_and_visit spree.admin_products_path }
@@ -212,7 +214,8 @@ feature '
select 'None', from: "product_tax_category_id"
# Should only have suppliers listed which the user can manage
- expect(page).to have_select 'product_supplier_id', with_options: [@supplier2.name, @supplier_permitted.name]
+ expect(page).to have_select 'product_supplier_id',
+ with_options: [@supplier2.name, @supplier_permitted.name]
expect(page).not_to have_select 'product_supplier_id', with_options: [@supplier.name]
click_button 'Create'
@@ -253,25 +256,43 @@ feature '
# Link back to the bulk product update page should include the filters
expected_admin_product_url = Regexp.new(Regexp.escape("#{spree.admin_products_path}#?#{filter.to_query}"))
- expect(page).to have_link(I18n.t('admin.products.back_to_products_list'), href: expected_admin_product_url)
+ expect(page).to have_link(I18n.t('admin.products.back_to_products_list'),
+ href: expected_admin_product_url)
expect(page).to have_link(I18n.t(:cancel), href: expected_admin_product_url)
- expected_product_url = Regexp.new(Regexp.escape(spree.edit_admin_product_path(product.permalink, filter)))
- expect(page).to have_link(I18n.t('admin.products.tabs.product_details'), href: expected_product_url)
+ expected_product_url = Regexp.new(Regexp.escape(spree.edit_admin_product_path(
+ product.permalink, filter
+ )))
+ expect(page).to have_link(I18n.t('admin.products.tabs.product_details'),
+ href: expected_product_url)
- expected_product_image_url = Regexp.new(Regexp.escape(spree.admin_product_images_path(product.permalink, filter)))
- expect(page).to have_link(I18n.t('admin.products.tabs.images'), href: expected_product_image_url)
+ expected_product_image_url = Regexp.new(Regexp.escape(spree.admin_product_images_path(
+ product.permalink, filter
+ )))
+ expect(page).to have_link(I18n.t('admin.products.tabs.images'),
+ href: expected_product_image_url)
- expected_product_variant_url = Regexp.new(Regexp.escape(spree.admin_product_variants_path(product.permalink, filter)))
- expect(page).to have_link(I18n.t('admin.products.tabs.variants'), href: expected_product_variant_url)
+ expected_product_variant_url = Regexp.new(Regexp.escape(spree.admin_product_variants_path(
+ product.permalink, filter
+ )))
+ expect(page).to have_link(I18n.t('admin.products.tabs.variants'),
+ href: expected_product_variant_url)
- expected_product_properties_url = Regexp.new(Regexp.escape(spree.admin_product_product_properties_path(product.permalink, filter)))
- expect(page).to have_link(I18n.t('admin.products.tabs.product_properties'), href: expected_product_properties_url)
+ expected_product_properties_url = Regexp.new(Regexp.escape(spree.admin_product_product_properties_path(
+ product.permalink, filter
+ )))
+ expect(page).to have_link(I18n.t('admin.products.tabs.product_properties'),
+ href: expected_product_properties_url)
- expected_product_group_buy_option_url = Regexp.new(Regexp.escape(spree.group_buy_options_admin_product_path(product.permalink, filter)))
- expect(page).to have_link(I18n.t('admin.products.tabs.group_buy_options'), href: expected_product_group_buy_option_url)
+ expected_product_group_buy_option_url = Regexp.new(Regexp.escape(spree.group_buy_options_admin_product_path(
+ product.permalink, filter
+ )))
+ expect(page).to have_link(I18n.t('admin.products.tabs.group_buy_options'),
+ href: expected_product_group_buy_option_url)
- expected_product_seo_url = Regexp.new(Regexp.escape(spree.seo_admin_product_path(product.permalink, filter)))
+ expected_product_seo_url = Regexp.new(Regexp.escape(spree.seo_admin_product_path(
+ product.permalink, filter
+ )))
expect(page).to have_link(I18n.t(:search), href: expected_product_seo_url)
end
@@ -296,7 +317,8 @@ feature '
visit spree.group_buy_options_admin_product_path(product, filter)
- expected_cancel_link = Regexp.new(Regexp.escape(spree.edit_admin_product_path(product, filter)))
+ expected_cancel_link = Regexp.new(Regexp.escape(spree.edit_admin_product_path(product,
+ filter)))
expect(page).to have_link(I18n.t(:cancel), href: expected_cancel_link)
end
@@ -331,7 +353,8 @@ feature '
visit spree.seo_admin_product_path(product, filter)
- expected_cancel_link = Regexp.new(Regexp.escape(spree.edit_admin_product_path(product, filter)))
+ expected_cancel_link = Regexp.new(Regexp.escape(spree.edit_admin_product_path(product,
+ filter)))
expect(page).to have_link(I18n.t(:cancel), href: expected_cancel_link)
end
@@ -355,9 +378,12 @@ feature '
uri = URI.parse(current_url)
# we stay on the same url as the new image content is loaded via an ajax call
- expect("#{uri.path}?#{uri.query}").to eq spree.admin_product_product_properties_path(product, filter)
+ expect("#{uri.path}?#{uri.query}").to eq spree.admin_product_product_properties_path(product,
+ filter)
- expected_cancel_link = Regexp.new(Regexp.escape(spree.admin_product_product_properties_path(product, filter)))
+ expected_cancel_link = Regexp.new(Regexp.escape(spree.admin_product_product_properties_path(
+ product, filter
+ )))
expect(page).to have_link(I18n.t(:cancel), href: expected_cancel_link)
end
@@ -368,7 +394,8 @@ feature '
# When I navigate to the product properties page
visit spree.admin_product_product_properties_path(product)
- expect(page).to have_select2 'product_product_properties_attributes_0_property_name', selected: 'fooprop'
+ expect(page).to have_select2 'product_product_properties_attributes_0_property_name',
+ selected: 'fooprop'
expect(page).to have_field 'product_product_properties_attributes_0_value', with: 'fooval'
# And I delete the property
@@ -378,7 +405,8 @@ feature '
click_button 'Update'
# Then the property should have been deleted
- expect(page).not_to have_field 'product_product_properties_attributes_0_property_name', with: 'fooprop'
+ expect(page).not_to have_field 'product_product_properties_attributes_0_property_name',
+ with: 'fooprop'
expect(page).not_to have_field 'product_product_properties_attributes_0_value', with: 'fooval'
expect(product.reload.property('fooprop')).to be_nil
end
@@ -397,7 +425,8 @@ feature '
end
uri = URI.parse(current_url)
- expect("#{uri.path}?#{uri.query}").to eq spree.admin_product_product_properties_path(product, filter)
+ expect("#{uri.path}?#{uri.query}").to eq spree.admin_product_product_properties_path(product,
+ filter)
end
scenario "adding product properties including url filters", js: true do
@@ -439,7 +468,8 @@ feature '
# we stay on the same url as the new image content is loaded via an ajax call
expect("#{uri.path}?#{uri.query}").to eq spree.admin_product_images_path(product, filter)
- expected_cancel_link = Regexp.new(Regexp.escape(spree.admin_product_images_path(product, filter)))
+ expected_cancel_link = Regexp.new(Regexp.escape(spree.admin_product_images_path(product,
+ filter)))
expect(page).to have_link(I18n.t(:cancel), href: expected_cancel_link)
end
@@ -463,23 +493,28 @@ feature '
visit spree.admin_product_images_path(product, filter)
- expected_new_image_link = Regexp.new(Regexp.escape(spree.new_admin_product_image_path(product, filter)))
+ expected_new_image_link = Regexp.new(Regexp.escape(spree.new_admin_product_image_path(
+ product, filter
+ )))
expect(page).to have_link(I18n.t('spree.new_image'), href: expected_new_image_link)
end
scenario "loading edit product image page including url filter", js: true do
product = create(:simple_product, supplier: @supplier2)
image = File.open(File.expand_path('../../../app/assets/images/logo-white.png', __dir__))
- image_object = Spree::Image.create(viewable_id: product.master.id, viewable_type: 'Spree::Variant', alt: "position 1", attachment: image, position: 1)
+ image_object = Spree::Image.create(viewable_id: product.master.id,
+ viewable_type: 'Spree::Variant', alt: "position 1", attachment: image, position: 1)
visit spree.admin_product_images_path(product, filter)
page.find("a.icon-edit").click
uri = URI.parse(current_url)
- expect("#{uri.path}?#{uri.query}").to eq spree.edit_admin_product_image_path(product, image_object, filter)
+ expect("#{uri.path}?#{uri.query}").to eq spree.edit_admin_product_image_path(product,
+ image_object, filter)
- expected_cancel_link = Regexp.new(Regexp.escape(spree.admin_product_images_path(product, filter)))
+ expected_cancel_link = Regexp.new(Regexp.escape(spree.admin_product_images_path(product,
+ filter)))
expect(page).to have_link(I18n.t(:cancel), href: expected_cancel_link)
expect(page).to have_link("Back To Images List", href: expected_cancel_link)
end
@@ -487,7 +522,8 @@ feature '
scenario "updating a product image including url filter", js: true do
product = create(:simple_product, supplier: @supplier2)
image = File.open(File.expand_path('../../../app/assets/images/logo-white.png', __dir__))
- image_object = Spree::Image.create(viewable_id: product.master.id, viewable_type: 'Spree::Variant', alt: "position 1", attachment: image, position: 1)
+ image_object = Spree::Image.create(viewable_id: product.master.id,
+ viewable_type: 'Spree::Variant', alt: "position 1", attachment: image, position: 1)
file_path = Rails.root + "spec/support/fixtures/thinking-cat.jpg"
@@ -505,7 +541,8 @@ feature '
scenario "deleting product images", js: true do
product = create(:simple_product, supplier: @supplier2)
image = File.open(File.expand_path('../../../app/assets/images/logo-white.png', __dir__))
- Spree::Image.create(viewable_id: product.master.id, viewable_type: 'Spree::Variant', alt: "position 1", attachment: image, position: 1)
+ Spree::Image.create(viewable_id: product.master.id, viewable_type: 'Spree::Variant',
+ alt: "position 1", attachment: image, position: 1)
visit spree.admin_product_images_path(product)
expect(page).to have_selector "table.index td img"
@@ -522,7 +559,8 @@ feature '
scenario "deleting product image including url filter", js: true do
product = create(:simple_product, supplier: @supplier2)
image = File.open(File.expand_path('../../../app/assets/images/logo-white.png', __dir__))
- Spree::Image.create(viewable_id: product.master.id, viewable_type: 'Spree::Variant', alt: "position 1", attachment: image, position: 1)
+ Spree::Image.create(viewable_id: product.master.id, viewable_type: 'Spree::Variant',
+ alt: "position 1", attachment: image, position: 1)
visit spree.admin_product_images_path(product, filter)
@@ -558,14 +596,22 @@ feature '
end
describe 'a shared example' do
- it_behaves_like 'selecting a unit from dropdown', 'Weight (g)', var_unit: 'weight', var_unit_scale: 1
- it_behaves_like 'selecting a unit from dropdown', 'Weight (kg)', var_unit: 'weight', var_unit_scale: 1000
- it_behaves_like 'selecting a unit from dropdown', 'Weight (T)', var_unit: 'weight', var_unit_scale: 1_000_000
- it_behaves_like 'selecting a unit from dropdown', 'Weight (oz)', var_unit: 'weight', var_unit_scale: 28.35
- it_behaves_like 'selecting a unit from dropdown', 'Weight (lb)', var_unit: 'weight', var_unit_scale: 453.6
- it_behaves_like 'selecting a unit from dropdown', 'Volume (mL)', var_unit: 'volume', var_unit_scale: 0.001
- it_behaves_like 'selecting a unit from dropdown', 'Volume (L)', var_unit: 'volume', var_unit_scale: 1
- it_behaves_like 'selecting a unit from dropdown', 'Volume (kL)', var_unit: 'volume', var_unit_scale: 1000
+ it_behaves_like 'selecting a unit from dropdown', 'Weight (g)', var_unit: 'weight',
+ var_unit_scale: 1
+ it_behaves_like 'selecting a unit from dropdown', 'Weight (kg)', var_unit: 'weight',
+ var_unit_scale: 1000
+ it_behaves_like 'selecting a unit from dropdown', 'Weight (T)', var_unit: 'weight',
+ var_unit_scale: 1_000_000
+ it_behaves_like 'selecting a unit from dropdown', 'Weight (oz)', var_unit: 'weight',
+ var_unit_scale: 28.35
+ it_behaves_like 'selecting a unit from dropdown', 'Weight (lb)', var_unit: 'weight',
+ var_unit_scale: 453.6
+ it_behaves_like 'selecting a unit from dropdown', 'Volume (mL)', var_unit: 'volume',
+ var_unit_scale: 0.001
+ it_behaves_like 'selecting a unit from dropdown', 'Volume (L)', var_unit: 'volume',
+ var_unit_scale: 1
+ it_behaves_like 'selecting a unit from dropdown', 'Volume (kL)', var_unit: 'volume',
+ var_unit_scale: 1000
end
end
end
diff --git a/spec/features/admin/reports/payments_report_spec.rb b/spec/features/admin/reports/payments_report_spec.rb
index 8ed50fcf70..8b0df8520d 100644
--- a/spec/features/admin/reports/payments_report_spec.rb
+++ b/spec/features/admin/reports/payments_report_spec.rb
@@ -62,10 +62,14 @@ describe "Payments Reports" do
context 'when choosing payment totals report type' do
let(:paypal) { create(:payment_method, name: "PayPal") }
- let!(:paypal_payment) { create(:payment, order: order, payment_method: paypal, state: "completed", amount: 5) }
+ let!(:paypal_payment) {
+ create(:payment, order: order, payment_method: paypal, state: "completed", amount: 5)
+ }
let(:eft) { create(:payment_method, name: "EFT") }
- let!(:eft_payment) { create(:payment, order: other_order, payment_method: eft, state: "completed", amount: 6) }
+ let!(:eft_payment) {
+ create(:payment, order: other_order, payment_method: eft, state: "completed", amount: 6)
+ }
it 'shows orders with payment state, their balance and and payment totals' do
visit spree.payments_admin_reports_path
diff --git a/spec/features/admin/reports_spec.rb b/spec/features/admin/reports_spec.rb
index 460562e98f..a11c88e451 100644
--- a/spec/features/admin/reports_spec.rb
+++ b/spec/features/admin/reports_spec.rb
@@ -57,7 +57,8 @@ feature '
rows = find("table#listing_customers").all("thead tr")
table = rows.map { |r| r.all("th").map { |c| c.text.strip } }
expect(table.sort).to eq([
- ["First Name", "Last Name", "Billing Address", "Email", "Phone", "Hub", "Hub Address", "Shipping Method"]
+ ["First Name", "Last Name", "Billing Address", "Email", "Phone", "Hub", "Hub Address",
+ "Shipping Method"]
].sort)
end
end
@@ -73,7 +74,8 @@ feature '
rows = find("table#listing_ocm_orders").all("thead tr")
table = rows.map { |r| r.all("th").map { |c| c.text.strip } }
expect(table.sort).to eq([
- ["First Name", "Last Name", "Hub", "Hub Code", "Email", "Phone", "Shipping Method", "Payment Method", "Amount", "Balance"]
+ ["First Name", "Last Name", "Hub", "Hub Code", "Email", "Phone", "Shipping Method",
+ "Payment Method", "Amount", "Balance"]
].sort)
end
@@ -83,7 +85,8 @@ feature '
rows = find("table#listing_ocm_orders").all("thead tr")
table = rows.map { |r| r.all("th").map { |c| c.text.strip } }
expect(table.sort).to eq([
- ["First Name", "Last Name", "Hub", "Hub Code", "Delivery Address", "Delivery Postcode", "Phone", "Shipping Method", "Payment Method", "Amount", "Balance", "Temp Controlled Items?", "Special Instructions"]
+ ["First Name", "Last Name", "Hub", "Hub Code", "Delivery Address", "Delivery Postcode",
+ "Phone", "Shipping Method", "Payment Method", "Amount", "Balance", "Temp Controlled Items?", "Special Instructions"]
].sort)
end
end
@@ -95,7 +98,9 @@ feature '
let(:bill_address1) { create(:address, lastname: "MULLER") }
let(:bill_address2) { create(:address, lastname: "Mistery") }
- let(:distributor_address) { create(:address, address1: "distributor address", city: 'The Shire', zipcode: "1234") }
+ let(:distributor_address) {
+ create(:address, address1: "distributor address", city: 'The Shire', zipcode: "1234")
+ }
let(:distributor) { create(:distributor_enterprise, address: distributor_address) }
let(:order1) { create(:order, distributor: distributor, bill_address: bill_address1) }
let(:order2) { create(:order, distributor: distributor, bill_address: bill_address2) }
@@ -124,7 +129,8 @@ feature '
rows = find("table#listing_orders").all("thead tr")
table = rows.map { |r| r.all("th").map { |c| c.text.strip } }
expect(table.sort).to eq([
- ["Hub", "Code", "First Name", "Last Name", "Supplier", "Product", "Variant", "Quantity", "TempControlled?"]
+ ["Hub", "Code", "First Name", "Last Name", "Supplier", "Product", "Variant", "Quantity",
+ "TempControlled?"]
].sort)
expect(page).to have_selector 'table#listing_orders tbody tr', count: 5 # Totals row per order
end
@@ -132,17 +138,17 @@ feature '
scenario "Alphabetically Sorted Pack by Customer" do
click_link "Pack By Customer"
click_button 'Search'
-
+
rows = find("table#listing_orders").all("tr")
table = rows.map { |r| r.all("th,td").map { |c| c.text.strip }[3] }
expect(table).to eq([
- "Last Name",
- order2.bill_address.lastname,
- "",
- order1.bill_address.lastname,
- order1.bill_address.lastname,
- ""
- ])
+ "Last Name",
+ order2.bill_address.lastname,
+ "",
+ order1.bill_address.lastname,
+ order1.bill_address.lastname,
+ ""
+ ])
end
scenario "Pack By Supplier" do
@@ -155,7 +161,8 @@ feature '
rows = find("table#listing_orders").all("thead tr")
table = rows.map { |r| r.all("th").map { |c| c.text.strip } }
expect(table.sort).to eq([
- ["Hub", "Supplier", "Code", "First Name", "Last Name", "Product", "Variant", "Quantity", "TempControlled?"]
+ ["Hub", "Supplier", "Code", "First Name", "Last Name", "Product", "Variant", "Quantity",
+ "TempControlled?"]
].sort)
expect(all('table#listing_orders tbody tr').count).to eq(4) # Totals row per supplier
end
@@ -178,24 +185,45 @@ feature '
end
describe "sales tax report" do
- let(:distributor1) { create(:distributor_enterprise, with_payment_and_shipping: true, charges_sales_tax: true) }
- let(:distributor2) { create(:distributor_enterprise, with_payment_and_shipping: true, charges_sales_tax: true) }
+ let(:distributor1) {
+ create(:distributor_enterprise, with_payment_and_shipping: true, charges_sales_tax: true)
+ }
+ let(:distributor2) {
+ create(:distributor_enterprise, with_payment_and_shipping: true, charges_sales_tax: true)
+ }
let(:user1) { create(:user, enterprises: [distributor1]) }
let(:user2) { create(:user, enterprises: [distributor2]) }
let(:shipping_tax_rate) { create(:tax_rate, amount: 0.20, included_in_price: true, zone: zone) }
let(:shipping_tax_category) { create(:tax_category, tax_rates: [shipping_tax_rate]) }
- let!(:shipping_method) { create(:shipping_method_with, :expensive_name, distributors: [distributor1], tax_category: shipping_tax_category) }
- let(:enterprise_fee) { create(:enterprise_fee, enterprise: user1.enterprises.first, tax_category: product2.tax_category, calculator: Calculator::FlatRate.new(preferred_amount: 120.0)) }
- let(:order_cycle) { create(:simple_order_cycle, coordinator: distributor1, coordinator_fees: [enterprise_fee], distributors: [distributor1], variants: [product1.variants.first, product2.variants.first]) }
+ let!(:shipping_method) {
+ create(:shipping_method_with, :expensive_name, distributors: [distributor1],
+ tax_category: shipping_tax_category)
+ }
+ let(:enterprise_fee) {
+ create(:enterprise_fee, enterprise: user1.enterprises.first, tax_category: product2.tax_category,
+ calculator: Calculator::FlatRate.new(preferred_amount: 120.0))
+ }
+ let(:order_cycle) {
+ create(:simple_order_cycle, coordinator: distributor1, coordinator_fees: [enterprise_fee],
+ distributors: [distributor1], variants: [product1.variants.first, product2.variants.first])
+ }
let!(:zone) { create(:zone_with_member) }
let(:address) { create(:address) }
- let(:order1) { create(:order, order_cycle: order_cycle, distributor: user1.enterprises.first, ship_address: address, bill_address: address) }
+ let(:order1) {
+ create(:order, order_cycle: order_cycle, distributor: user1.enterprises.first,
+ ship_address: address, bill_address: address)
+ }
let(:product1) { create(:taxed_product, zone: zone, price: 12.54, tax_rate_amount: 0) }
let(:product2) { create(:taxed_product, zone: zone, price: 500.15, tax_rate_amount: 0.2) }
- let!(:line_item1) { create(:line_item, variant: product1.variants.first, price: 12.54, quantity: 1, order: order1) }
- let!(:line_item2) { create(:line_item, variant: product2.variants.first, price: 500.15, quantity: 3, order: order1) }
+ let!(:line_item1) {
+ create(:line_item, variant: product1.variants.first, price: 12.54, quantity: 1, order: order1)
+ }
+ let!(:line_item2) {
+ create(:line_item, variant: product2.variants.first, price: 500.15, quantity: 3,
+ order: order1)
+ }
before do
order1.reload
@@ -214,8 +242,10 @@ feature '
it "reports" do
# Then it should give me access only to managed enterprises
- expect(page).to have_select 'q_distributor_id_eq', with_options: [user1.enterprises.first.name]
- expect(page).not_to have_select 'q_distributor_id_eq', with_options: [user2.enterprises.first.name]
+ expect(page).to have_select 'q_distributor_id_eq',
+ with_options: [user1.enterprises.first.name]
+ expect(page).not_to have_select 'q_distributor_id_eq',
+ with_options: [user2.enterprises.first.name]
# When I filter to just one distributor
select user1.enterprises.first.name, from: 'q_distributor_id_eq'
@@ -249,12 +279,20 @@ feature '
context "with two orders on the same day at different times" do
let(:bill_address) { create(:address) }
- let(:distributor_address) { create(:address, address1: "distributor address", city: 'The Shire', zipcode: "1234") }
+ let(:distributor_address) {
+ create(:address, address1: "distributor address", city: 'The Shire', zipcode: "1234")
+ }
let(:distributor) { create(:distributor_enterprise, address: distributor_address) }
let(:product) { create(:product) }
let(:shipping_instructions) { "pick up on thursday please!" }
- let(:order1) { create(:order, distributor: distributor, bill_address: bill_address, special_instructions: shipping_instructions) }
- let(:order2) { create(:order, distributor: distributor, bill_address: bill_address, special_instructions: shipping_instructions) }
+ let(:order1) {
+ create(:order, distributor: distributor, bill_address: bill_address,
+ special_instructions: shipping_instructions)
+ }
+ let(:order2) {
+ create(:order, distributor: distributor, bill_address: bill_address,
+ special_instructions: shipping_instructions)
+ }
before do
Timecop.travel(Time.zone.local(2013, 4, 25, 14, 0, 0)) { order1.finalize! }
@@ -280,7 +318,8 @@ feature '
it "handles order cycles with nil opening or closing times" do
distributor = create(:distributor_enterprise)
- oc = create(:simple_order_cycle, name: "My Order Cycle", distributors: [distributor], orders_open_at: Time.zone.now, orders_close_at: nil)
+ oc = create(:simple_order_cycle, name: "My Order Cycle", distributors: [distributor],
+ orders_open_at: Time.zone.now, orders_close_at: nil)
o = create(:order, order_cycle: oc, distributor: distributor)
login_as_admin_and_visit spree.orders_and_fulfillment_admin_reports_path
@@ -292,8 +331,14 @@ feature '
describe "products and inventory report", js: true do
let(:supplier) { create(:supplier_enterprise, name: 'Supplier Name') }
let(:taxon) { create(:taxon, name: 'Taxon Name') }
- let(:product1) { create(:simple_product, name: "Product Name", price: 100, supplier: supplier, primary_taxon: taxon) }
- let(:product2) { create(:simple_product, name: "Product 2", price: 99.0, variant_unit: 'weight', variant_unit_scale: 1, unit_value: '100', supplier: supplier, primary_taxon: taxon, sku: "product_sku") }
+ let(:product1) {
+ create(:simple_product, name: "Product Name", price: 100, supplier: supplier,
+ primary_taxon: taxon)
+ }
+ let(:product2) {
+ create(:simple_product, name: "Product 2", price: 99.0, variant_unit: 'weight',
+ variant_unit_scale: 1, unit_value: '100', supplier: supplier, primary_taxon: taxon, sku: "product_sku")
+ }
let(:variant1) { product1.variants.first }
let(:variant2) { create(:variant, product: product1, price: 80.0) }
let(:variant3) { product2.variants.first }
@@ -321,10 +366,14 @@ feature '
click_link 'Products & Inventory'
click_button "Go"
expect(page).to have_content "Supplier"
- expect(page).to have_table_row ["Supplier", "Producer Suburb", "Product", "Product Properties", "Taxons", "Variant Value", "Price", "Group Buy Unit Quantity", "Amount", "SKU"].map(&:upcase)
- expect(page).to have_table_row [product1.supplier.name, product1.supplier.address.city, "Product Name", product1.properties.map(&:presentation).join(", "), product1.primary_taxon.name, "Test", "100.0", product1.group_buy_unit_size.to_s, "", "sku1"]
- expect(page).to have_table_row [product1.supplier.name, product1.supplier.address.city, "Product Name", product1.properties.map(&:presentation).join(", "), product1.primary_taxon.name, "Something", "80.0", product1.group_buy_unit_size.to_s, "", "sku2"]
- expect(page).to have_table_row [product2.supplier.name, product1.supplier.address.city, "Product 2", product1.properties.map(&:presentation).join(", "), product2.primary_taxon.name, "100g", "99.0", product1.group_buy_unit_size.to_s, "", "product_sku"]
+ expect(page).to have_table_row ["Supplier", "Producer Suburb", "Product",
+ "Product Properties", "Taxons", "Variant Value", "Price", "Group Buy Unit Quantity", "Amount", "SKU"].map(&:upcase)
+ expect(page).to have_table_row [product1.supplier.name, product1.supplier.address.city,
+ "Product Name", product1.properties.map(&:presentation).join(", "), product1.primary_taxon.name, "Test", "100.0", product1.group_buy_unit_size.to_s, "", "sku1"]
+ expect(page).to have_table_row [product1.supplier.name, product1.supplier.address.city,
+ "Product Name", product1.properties.map(&:presentation).join(", "), product1.primary_taxon.name, "Something", "80.0", product1.group_buy_unit_size.to_s, "", "sku2"]
+ expect(page).to have_table_row [product2.supplier.name, product1.supplier.address.city,
+ "Product 2", product1.properties.map(&:presentation).join(", "), product2.primary_taxon.name, "100g", "99.0", product1.group_buy_unit_size.to_s, "", "product_sku"]
end
it "shows the LettuceShare report" do
@@ -332,8 +381,10 @@ feature '
click_link 'LettuceShare'
click_button "Go"
- expect(page).to have_table_row ['PRODUCT', 'Description', 'Qty', 'Pack Size', 'Unit', 'Unit Price', 'Total', 'GST incl.', 'Grower and growing method', 'Taxon'].map(&:upcase)
- expect(page).to have_table_row ['Product 2', '100g', '', '100', 'g', '99.0', '', '0', 'Supplier Name (Organic - NASAA 12345)', 'Taxon Name']
+ expect(page).to have_table_row ['PRODUCT', 'Description', 'Qty', 'Pack Size', 'Unit',
+ 'Unit Price', 'Total', 'GST incl.', 'Grower and growing method', 'Taxon'].map(&:upcase)
+ expect(page).to have_table_row ['Product 2', '100g', '', '100', 'g', '99.0', '', '0',
+ 'Supplier Name (Organic - NASAA 12345)', 'Taxon Name']
end
end
@@ -385,38 +436,82 @@ feature '
end
describe "Xero invoices report" do
- let(:distributor1) { create(:distributor_enterprise, with_payment_and_shipping: true, charges_sales_tax: true) }
- let(:distributor2) { create(:distributor_enterprise, with_payment_and_shipping: true, charges_sales_tax: true) }
+ let(:distributor1) {
+ create(:distributor_enterprise, with_payment_and_shipping: true, charges_sales_tax: true)
+ }
+ let(:distributor2) {
+ create(:distributor_enterprise, with_payment_and_shipping: true, charges_sales_tax: true)
+ }
let(:user1) { create(:user, enterprises: [distributor1]) }
let(:user2) { create(:user, enterprises: [distributor2]) }
let(:shipping_method) { create(:shipping_method_with, :expensive_name) }
let(:shipment) { create(:shipment_with, :shipping_method, shipping_method: shipping_method) }
- let(:enterprise_fee1) { create(:enterprise_fee, enterprise: user1.enterprises.first, tax_category: product2.tax_category, calculator: Calculator::FlatRate.new(preferred_amount: 10)) }
- let(:enterprise_fee2) { create(:enterprise_fee, enterprise: user1.enterprises.first, tax_category: product2.tax_category, calculator: Calculator::FlatRate.new(preferred_amount: 20)) }
- let(:order_cycle) { create(:simple_order_cycle, coordinator: distributor1, coordinator_fees: [enterprise_fee1, enterprise_fee2], distributors: [distributor1], variants: [product1.master]) }
+ let(:enterprise_fee1) {
+ create(:enterprise_fee, enterprise: user1.enterprises.first, tax_category: product2.tax_category,
+ calculator: Calculator::FlatRate.new(preferred_amount: 10))
+ }
+ let(:enterprise_fee2) {
+ create(:enterprise_fee, enterprise: user1.enterprises.first, tax_category: product2.tax_category,
+ calculator: Calculator::FlatRate.new(preferred_amount: 20))
+ }
+ let(:order_cycle) {
+ create(:simple_order_cycle, coordinator: distributor1,
+ coordinator_fees: [enterprise_fee1, enterprise_fee2], distributors: [distributor1], variants: [product1.master])
+ }
let!(:zone) { create(:zone_with_member) }
let(:bill_address) {
create(:address, firstname: 'Customer', lastname: 'Name', address1: 'customer l1',
address2: '', city: 'customer city', zipcode: 1234)
}
- let(:order1) { create(:order, order_cycle: order_cycle, distributor: user1.enterprises.first, shipments: [shipment], bill_address: bill_address) }
- let(:product1) { create(:taxed_product, zone: zone, price: 12.54, tax_rate_amount: 0, sku: 'sku1') }
- let(:product2) { create(:taxed_product, zone: zone, price: 500.15, tax_rate_amount: 0.2, sku: 'sku2') }
+ let(:order1) {
+ create(:order, order_cycle: order_cycle, distributor: user1.enterprises.first,
+ shipments: [shipment], bill_address: bill_address)
+ }
+ let(:product1) {
+ create(:taxed_product, zone: zone, price: 12.54, tax_rate_amount: 0, sku: 'sku1')
+ }
+ let(:product2) {
+ create(:taxed_product, zone: zone, price: 500.15, tax_rate_amount: 0.2, sku: 'sku2')
+ }
describe "with adjustments" do
- let!(:line_item1) { create(:line_item, variant: product1.variants.first, price: 12.54, quantity: 1, order: order1) }
- let!(:line_item2) { create(:line_item, variant: product2.variants.first, price: 500.15, quantity: 3, order: order1) }
+ let!(:line_item1) {
+ create(:line_item, variant: product1.variants.first, price: 12.54, quantity: 1,
+ order: order1)
+ }
+ let!(:line_item2) {
+ create(:line_item, variant: product2.variants.first, price: 500.15, quantity: 3,
+ order: order1)
+ }
let!(:tax_category) { create(:tax_category) }
let!(:tax_rate) { create(:tax_rate, tax_category: tax_category) }
- let!(:adj_shipping) { create(:adjustment, order: order1, adjustable: order1, label: "Shipping", originator: shipping_method, amount: 100.55) }
- let!(:adj_fee1) { create(:adjustment, order: order1, adjustable: order1, originator: enterprise_fee1, label: "Enterprise fee untaxed", amount: 10) }
- let!(:adj_fee2) { create(:adjustment, order: order1, adjustable: order1, originator: enterprise_fee2, label: "Enterprise fee taxed", amount: 20, tax_category: tax_category) }
- let!(:adj_fee2_tax) { create(:adjustment, order: order1, adjustable: adj_fee2, originator: tax_rate, amount: 3, state: "closed") }
- let!(:adj_manual1) { create(:adjustment, order: order1, adjustable: order1, originator: nil, label: "Manual adjustment", amount: 30) }
- let!(:adj_manual2) { create(:adjustment, order: order1, adjustable: order1, originator: nil, label: "Manual adjustment", amount: 40, included_tax: 3) }
+ let!(:adj_shipping) {
+ create(:adjustment, order: order1, adjustable: order1, label: "Shipping",
+ originator: shipping_method, amount: 100.55)
+ }
+ let!(:adj_fee1) {
+ create(:adjustment, order: order1, adjustable: order1, originator: enterprise_fee1,
+ label: "Enterprise fee untaxed", amount: 10)
+ }
+ let!(:adj_fee2) {
+ create(:adjustment, order: order1, adjustable: order1, originator: enterprise_fee2,
+ label: "Enterprise fee taxed", amount: 20, tax_category: tax_category)
+ }
+ let!(:adj_fee2_tax) {
+ create(:adjustment, order: order1, adjustable: adj_fee2, originator: tax_rate, amount: 3,
+ state: "closed")
+ }
+ let!(:adj_manual1) {
+ create(:adjustment, order: order1, adjustable: order1, originator: nil,
+ label: "Manual adjustment", amount: 30)
+ }
+ let!(:adj_manual2) {
+ create(:adjustment, order: order1, adjustable: order1, originator: nil,
+ label: "Manual adjustment", amount: 40, included_tax: 3)
+ }
before do
order1.update_order!
@@ -440,13 +535,19 @@ feature '
click_button "Search"
expect(xero_invoice_table).to match_table [
xero_invoice_header,
- xero_invoice_summary_row('Total untaxable produce (no tax)', 12.54, 'GST Free Income'),
- xero_invoice_summary_row('Total taxable produce (tax inclusive)', 1500.45, 'GST on Income'),
- xero_invoice_summary_row('Total untaxable fees (no tax)', 10.0, 'GST Free Income'),
+ xero_invoice_summary_row('Total untaxable produce (no tax)', 12.54,
+ 'GST Free Income'),
+ xero_invoice_summary_row('Total taxable produce (tax inclusive)', 1500.45,
+ 'GST on Income'),
+ xero_invoice_summary_row('Total untaxable fees (no tax)', 10.0,
+ 'GST Free Income'),
xero_invoice_summary_row('Total taxable fees (tax inclusive)', 20.0, 'GST on Income'),
- xero_invoice_summary_row('Delivery Shipping Cost (tax inclusive)', 100.55, 'GST on Income'),
- xero_invoice_summary_row('Total untaxable admin adjustments (no tax)', 30.0, 'GST Free Income'),
- xero_invoice_summary_row('Total taxable admin adjustments (tax inclusive)', 40.0, 'GST on Income')
+ xero_invoice_summary_row('Delivery Shipping Cost (tax inclusive)', 100.55,
+ 'GST on Income'),
+ xero_invoice_summary_row('Total untaxable admin adjustments (no tax)', 30.0,
+ 'GST Free Income'),
+ xero_invoice_summary_row('Total taxable admin adjustments (tax inclusive)', 40.0,
+ 'GST on Income')
]
end
@@ -457,17 +558,25 @@ feature '
fill_in 'account_code', with: 'abc123'
click_button 'Search'
- opts = { invoice_number: '5', invoice_date: '2015-02-12', due_date: '2015-03-12', account_code: 'abc123' }
+ opts = { invoice_number: '5', invoice_date: '2015-02-12', due_date: '2015-03-12',
+ account_code: 'abc123' }
expect(xero_invoice_table).to match_table [
xero_invoice_header,
- xero_invoice_summary_row('Total untaxable produce (no tax)', 12.54, 'GST Free Income', opts),
- xero_invoice_summary_row('Total taxable produce (tax inclusive)', 1500.45, 'GST on Income', opts),
- xero_invoice_summary_row('Total untaxable fees (no tax)', 10.0, 'GST Free Income', opts),
- xero_invoice_summary_row('Total taxable fees (tax inclusive)', 20.0, 'GST on Income', opts),
- xero_invoice_summary_row('Delivery Shipping Cost (tax inclusive)', 100.55, 'GST on Income', opts),
- xero_invoice_summary_row('Total untaxable admin adjustments (no tax)', 30.0, 'GST Free Income', opts),
- xero_invoice_summary_row('Total taxable admin adjustments (tax inclusive)', 40.0, 'GST on Income', opts)
+ xero_invoice_summary_row('Total untaxable produce (no tax)', 12.54,
+ 'GST Free Income', opts),
+ xero_invoice_summary_row('Total taxable produce (tax inclusive)', 1500.45,
+ 'GST on Income', opts),
+ xero_invoice_summary_row('Total untaxable fees (no tax)', 10.0,
+ 'GST Free Income', opts),
+ xero_invoice_summary_row('Total taxable fees (tax inclusive)', 20.0,
+ 'GST on Income', opts),
+ xero_invoice_summary_row('Delivery Shipping Cost (tax inclusive)', 100.55,
+ 'GST on Income', opts),
+ xero_invoice_summary_row('Total untaxable admin adjustments (no tax)', 30.0,
+ 'GST Free Income', opts),
+ xero_invoice_summary_row('Total taxable admin adjustments (tax inclusive)', 40.0,
+ 'GST on Income', opts)
]
end
@@ -483,9 +592,12 @@ feature '
xero_invoice_li_row(line_item2),
xero_invoice_adjustment_row(adj_manual1),
xero_invoice_adjustment_row(adj_manual2),
- xero_invoice_summary_row('Total untaxable fees (no tax)', 10.0, 'GST Free Income', opts),
- xero_invoice_summary_row('Total taxable fees (tax inclusive)', 20.0, 'GST on Income', opts),
- xero_invoice_summary_row('Delivery Shipping Cost (tax inclusive)', 100.55, 'GST on Income', opts)
+ xero_invoice_summary_row('Total untaxable fees (no tax)', 10.0,
+ 'GST Free Income', opts),
+ xero_invoice_summary_row('Total taxable fees (tax inclusive)', 20.0,
+ 'GST on Income', opts),
+ xero_invoice_summary_row('Delivery Shipping Cost (tax inclusive)', 100.55,
+ 'GST on Income', opts)
]
end
end
@@ -497,7 +609,8 @@ feature '
end
def xero_invoice_header
- %w(*ContactName EmailAddress POAddressLine1 POAddressLine2 POAddressLine3 POAddressLine4 POCity PORegion POPostalCode POCountry *InvoiceNumber Reference *InvoiceDate *DueDate InventoryItemCode *Description *Quantity *UnitAmount Discount *AccountCode *TaxType TrackingName1 TrackingOption1 TrackingName2 TrackingOption2 Currency BrandingTheme Paid?)
+ %w(*ContactName EmailAddress POAddressLine1 POAddressLine2 POAddressLine3 POAddressLine4
+ POCity PORegion POPostalCode POCountry *InvoiceNumber Reference *InvoiceDate *DueDate InventoryItemCode *Description *Quantity *UnitAmount Discount *AccountCode *TaxType TrackingName1 TrackingOption1 TrackingName2 TrackingOption2 Currency BrandingTheme Paid?)
end
def xero_invoice_summary_row(description, amount, tax_type, opts = {})
@@ -506,7 +619,8 @@ feature '
def xero_invoice_li_row(line_item, opts = {})
tax_type = line_item.has_tax? ? 'GST on Income' : 'GST Free Income'
- xero_invoice_row line_item.product.sku, line_item.product_and_full_name, line_item.price.to_s, line_item.quantity.to_s, tax_type, opts
+ xero_invoice_row line_item.product.sku, line_item.product_and_full_name,
+ line_item.price.to_s, line_item.quantity.to_s, tax_type, opts
end
def xero_invoice_adjustment_row(adjustment, opts = {})
@@ -515,7 +629,8 @@ feature '
end
def xero_invoice_row(sku, description, amount, quantity, tax_type, opts = {})
- opts.reverse_merge!(customer_name: 'Customer Name', address1: 'customer l1', city: 'customer city', state: 'Victoria', zipcode: '1234', country: 'Australia', invoice_number: order1.number, order_number: order1.number, invoice_date: '2015-04-26', due_date: '2015-05-26', account_code: 'food sales')
+ opts.reverse_merge!(customer_name: 'Customer Name', address1: 'customer l1',
+ city: 'customer city', state: 'Victoria', zipcode: '1234', country: 'Australia', invoice_number: order1.number, order_number: order1.number, invoice_date: '2015-04-26', due_date: '2015-05-26', account_code: 'food sales')
[opts[:customer_name], 'customer@email.com', opts[:address1], '', '', '', opts[:city], opts[:state], opts[:zipcode], opts[:country], opts[:invoice_number], opts[:order_number], opts[:invoice_date], opts[:due_date],
diff --git a/spec/features/admin/schedules_spec.rb b/spec/features/admin/schedules_spec.rb
index 52745000bb..cb14ef1b5c 100644
--- a/spec/features/admin/schedules_spec.rb
+++ b/spec/features/admin/schedules_spec.rb
@@ -8,13 +8,20 @@ feature 'Schedules', js: true do
context "as an enterprise user" do
let(:user) { create(:user, enterprise_limit: 10) }
- let(:managed_enterprise) { create(:distributor_enterprise, owner: user, enable_subscriptions: true) }
+ let(:managed_enterprise) {
+ create(:distributor_enterprise, owner: user, enable_subscriptions: true)
+ }
let(:unmanaged_enterprise) { create(:distributor_enterprise, enable_subscriptions: true) }
- let(:managed_enterprise2) { create(:distributor_enterprise, owner: user, enable_subscriptions: true) }
+ let(:managed_enterprise2) {
+ create(:distributor_enterprise, owner: user, enable_subscriptions: true)
+ }
let!(:oc1) { create(:simple_order_cycle, coordinator: managed_enterprise, name: 'oc1') }
let!(:oc2) { create(:simple_order_cycle, coordinator: managed_enterprise, name: 'oc2') }
let!(:oc3) { create(:simple_order_cycle, coordinator: managed_enterprise, name: 'oc3') }
- let!(:oc4) { create(:simple_order_cycle, coordinator: unmanaged_enterprise, distributors: [managed_enterprise], name: 'oc4') }
+ let!(:oc4) {
+ create(:simple_order_cycle, coordinator: unmanaged_enterprise, distributors: [managed_enterprise],
+ name: 'oc4')
+ }
let!(:oc5) { create(:simple_order_cycle, coordinator: managed_enterprise2, name: 'oc5') }
let!(:weekly_schedule) { create(:schedule, name: 'Weekly', order_cycles: [oc1, oc2, oc3, oc4]) }
@@ -65,7 +72,9 @@ feature 'Schedules', js: true do
end
describe "updating existing schedules" do
- let!(:fortnightly_schedule) { create(:schedule, name: 'Fortnightly', order_cycles: [oc1, oc3]) }
+ let!(:fortnightly_schedule) {
+ create(:schedule, name: 'Fortnightly', order_cycles: [oc1, oc3])
+ }
it "immediately shows updated schedule lists for order cycles" do
visit admin_order_cycles_path
diff --git a/spec/features/admin/shipping_methods_spec.rb b/spec/features/admin/shipping_methods_spec.rb
index 6e4a1c5e44..691483305c 100644
--- a/spec/features/admin/shipping_methods_spec.rb
+++ b/spec/features/admin/shipping_methods_spec.rb
@@ -70,15 +70,18 @@ feature 'shipping methods' do
scenario "checking a single distributor is checked by default" do
first_distributor = Enterprise.first
visit spree.new_admin_shipping_method_path
- expect(page).to have_field "shipping_method_distributor_ids_#{first_distributor.id}", checked: true
+ expect(page).to have_field "shipping_method_distributor_ids_#{first_distributor.id}",
+ checked: true
end
scenario "checking more than a distributor displays no default choice" do
distributor1 = create(:distributor_enterprise, name: 'Alice Farm Shop')
distributor2 = create(:distributor_enterprise, name: 'Bob Farm Hub')
visit spree.new_admin_shipping_method_path
- expect(page).to have_field "shipping_method_distributor_ids_#{distributor1.id}", checked: false
- expect(page).to have_field "shipping_method_distributor_ids_#{distributor2.id}", checked: false
+ expect(page).to have_field "shipping_method_distributor_ids_#{distributor1.id}",
+ checked: false
+ expect(page).to have_field "shipping_method_distributor_ids_#{distributor2.id}",
+ checked: false
end
end
@@ -88,7 +91,9 @@ feature 'shipping methods' do
let(:distributor2) { create(:distributor_enterprise, name: 'Second Distributor') }
let(:distributor3) { create(:distributor_enterprise, name: 'Third Distributor') }
let(:shipping_method1) { create(:shipping_method, name: 'One', distributors: [distributor1]) }
- let(:shipping_method2) { create(:shipping_method, name: 'Two', distributors: [distributor1, distributor2]) }
+ let(:shipping_method2) {
+ create(:shipping_method, name: 'Two', distributors: [distributor1, distributor2])
+ }
let(:sm3) { create(:shipping_method, name: 'Three', distributors: [distributor3]) }
let(:shipping_category) { create(:shipping_category) }
diff --git a/spec/features/admin/subscriptions_spec.rb b/spec/features/admin/subscriptions_spec.rb
index efbc500fb4..b62f3b31a8 100644
--- a/spec/features/admin/subscriptions_spec.rb
+++ b/spec/features/admin/subscriptions_spec.rb
@@ -16,11 +16,20 @@ feature 'Subscriptions' do
before { login_as user }
context 'listing subscriptions' do
- let!(:subscription) { create(:subscription, shop: shop, with_items: true, with_proxy_orders: true) }
+ let!(:subscription) {
+ create(:subscription, shop: shop, with_items: true, with_proxy_orders: true)
+ }
let!(:customer) { create(:customer, name: "Customer A") }
- let!(:other_subscription) { create(:subscription, shop: shop, customer: customer, with_items: true, with_proxy_orders: true) }
- let!(:subscription2) { create(:subscription, shop: shop2, with_items: true, with_proxy_orders: true) }
- let!(:subscription_unmanaged) { create(:subscription, shop: shop_unmanaged, with_items: true, with_proxy_orders: true) }
+ let!(:other_subscription) {
+ create(:subscription, shop: shop, customer: customer, with_items: true,
+ with_proxy_orders: true)
+ }
+ let!(:subscription2) {
+ create(:subscription, shop: shop2, with_items: true, with_proxy_orders: true)
+ }
+ let!(:subscription_unmanaged) {
+ create(:subscription, shop: shop_unmanaged, with_items: true, with_proxy_orders: true)
+ }
before do
subscription.update(shipping_fee_estimate: 3.5)
@@ -34,7 +43,8 @@ feature 'Subscriptions' do
click_link 'Orders'
click_link 'Subscriptions'
- expect(page).to have_select2 "shop_id", with_options: [shop.name, shop2.name], without_options: [shop_unmanaged.name]
+ expect(page).to have_select2 "shop_id", with_options: [shop.name, shop2.name],
+ without_options: [shop_unmanaged.name]
select2_select shop2.name, from: "shop_id"
@@ -183,17 +193,35 @@ feature 'Subscriptions' do
context 'creating a new subscription' do
let(:address) { create(:address) }
let!(:customer_user) { create(:user) }
- let!(:credit_card1) { create(:stored_credit_card, user: customer_user, cc_type: 'visa', last_digits: 1111, month: 10, year: 2030) }
- let!(:customer) { create(:customer, enterprise: shop, bill_address: address, user: customer_user, allow_charges: true) }
+ let!(:credit_card1) {
+ create(:stored_credit_card, user: customer_user, cc_type: 'visa', last_digits: 1111, month: 10,
+ year: 2030)
+ }
+ let!(:customer) {
+ create(:customer, enterprise: shop, bill_address: address, user: customer_user,
+ allow_charges: true)
+ }
let!(:test_product) { create(:product, supplier: shop) }
- let!(:test_variant) { create(:variant, product: test_product, unit_value: "100", price: 12.00, option_values: []) }
+ let!(:test_variant) {
+ create(:variant, product: test_product, unit_value: "100", price: 12.00, option_values: [])
+ }
let!(:shop_product) { create(:product, supplier: shop) }
- let!(:shop_variant) { create(:variant, product: shop_product, unit_value: "1000", price: 6.00, option_values: []) }
+ let!(:shop_variant) {
+ create(:variant, product: shop_product, unit_value: "1000", price: 6.00, option_values: [])
+ }
let!(:enterprise_fee) { create(:enterprise_fee, amount: 1.75) }
- let!(:order_cycle) { create(:simple_order_cycle, coordinator: shop, orders_open_at: 2.days.from_now, orders_close_at: 7.days.from_now) }
- let!(:outgoing_exchange) { order_cycle.exchanges.create(sender: shop, receiver: shop, variants: [test_variant, shop_variant], enterprise_fees: [enterprise_fee]) }
+ let!(:order_cycle) {
+ create(:simple_order_cycle, coordinator: shop, orders_open_at: 2.days.from_now,
+ orders_close_at: 7.days.from_now)
+ }
+ let!(:outgoing_exchange) {
+ order_cycle.exchanges.create(sender: shop, receiver: shop, variants: [test_variant, shop_variant],
+ enterprise_fees: [enterprise_fee])
+ }
let!(:schedule) { create(:schedule, order_cycles: [order_cycle]) }
- let!(:payment_method) { create(:stripe_connect_payment_method, name: 'Credit Card', distributors: [shop]) }
+ let!(:payment_method) {
+ create(:stripe_connect_payment_method, name: 'Credit Card', distributors: [shop])
+ }
let!(:shipping_method) { create(:shipping_method, distributors: [shop]) }
before do
@@ -257,7 +285,8 @@ feature 'Subscriptions' do
# Adding a product and getting a price estimate
add_variant_to_subscription test_variant, 2
within 'table#subscription-line-items tr.item', match: :first do
- expect(page).to have_selector '.description', text: "#{test_product.name} - #{test_variant.full_name}"
+ expect(page).to have_selector '.description',
+ text: "#{test_product.name} - #{test_variant.full_name}"
expect(page).to have_selector 'td.price', text: "$13.75"
expect(page).to have_input 'quantity', with: "2"
expect(page).to have_selector 'td.total', text: "$27.50"
@@ -281,7 +310,8 @@ feature 'Subscriptions' do
# Adding a new product
add_variant_to_subscription shop_variant, 3
within 'table#subscription-line-items tr.item', match: :first do
- expect(page).to have_selector '.description', text: "#{shop_product.name} - #{shop_variant.full_name}"
+ expect(page).to have_selector '.description',
+ text: "#{shop_product.name} - #{shop_variant.full_name}"
expect(page).to have_selector 'td.price', text: "$7.75"
expect(page).to have_input 'quantity', with: "3"
expect(page).to have_selector 'td.total', text: "$23.25"
@@ -300,7 +330,8 @@ feature 'Subscriptions' do
# Prices are shown in the index
within 'table#subscription-line-items tr.item', match: :first do
- expect(page).to have_selector '.description', text: "#{shop_product.name} - #{shop_variant.full_name}"
+ expect(page).to have_selector '.description',
+ text: "#{shop_product.name} - #{shop_variant.full_name}"
expect(page).to have_selector 'td.price', text: "$7.75"
expect(page).to have_input 'quantity', with: "3"
expect(page).to have_selector 'td.total', text: "$23.25"
@@ -328,17 +359,36 @@ feature 'Subscriptions' do
let!(:product1) { create(:product, supplier: shop) }
let!(:product2) { create(:product, supplier: shop) }
let!(:product3) { create(:product, supplier: shop) }
- let!(:variant1) { create(:variant, product: product1, unit_value: '100', price: 12.00, option_values: []) }
- let!(:variant2) { create(:variant, product: product2, unit_value: '1000', price: 6.00, option_values: []) }
- let!(:variant3) { create(:variant, product: product3, unit_value: '10000', price: 22.00, option_values: []) }
+ let!(:variant1) {
+ create(:variant, product: product1, unit_value: '100', price: 12.00, option_values: [])
+ }
+ let!(:variant2) {
+ create(:variant, product: product2, unit_value: '1000', price: 6.00, option_values: [])
+ }
+ let!(:variant3) {
+ create(:variant, product: product3, unit_value: '10000', price: 22.00, option_values: [])
+ }
let!(:enterprise_fee) { create(:enterprise_fee, amount: 1.75) }
- let!(:order_cycle) { create(:simple_order_cycle, coordinator: shop, orders_open_at: 2.days.from_now, orders_close_at: 7.days.from_now) }
- let!(:outgoing_exchange) { order_cycle.exchanges.create(sender: shop, receiver: shop, variants: [variant1, variant2], enterprise_fees: [enterprise_fee]) }
+ let!(:order_cycle) {
+ create(:simple_order_cycle, coordinator: shop, orders_open_at: 2.days.from_now,
+ orders_close_at: 7.days.from_now)
+ }
+ let!(:outgoing_exchange) {
+ order_cycle.exchanges.create(sender: shop, receiver: shop, variants: [variant1, variant2],
+ enterprise_fees: [enterprise_fee])
+ }
let!(:schedule) { create(:schedule, order_cycles: [order_cycle]) }
- let!(:variant3_oc) { create(:simple_order_cycle, coordinator: shop, orders_open_at: 2.days.from_now, orders_close_at: 7.days.from_now) }
- let!(:variant3_ex) { variant3_oc.exchanges.create(sender: shop, receiver: shop, variants: [variant3]) }
+ let!(:variant3_oc) {
+ create(:simple_order_cycle, coordinator: shop, orders_open_at: 2.days.from_now,
+ orders_close_at: 7.days.from_now)
+ }
+ let!(:variant3_ex) {
+ variant3_oc.exchanges.create(sender: shop, receiver: shop, variants: [variant3])
+ }
let!(:payment_method) { create(:payment_method, distributors: [shop]) }
- let!(:stripe_payment_method) { create(:stripe_connect_payment_method, name: 'Credit Card', distributors: [shop]) }
+ let!(:stripe_payment_method) {
+ create(:stripe_connect_payment_method, name: 'Credit Card', distributors: [shop])
+ }
let!(:shipping_method) { create(:shipping_method, distributors: [shop]) }
let!(:subscription) {
create(:subscription,
@@ -347,7 +397,8 @@ feature 'Subscriptions' do
schedule: schedule,
payment_method: payment_method,
shipping_method: shipping_method,
- subscription_line_items: [create(:subscription_line_item, variant: variant1, quantity: 2, price_estimate: 13.75)],
+ subscription_line_items: [create(:subscription_line_item, variant: variant1,
+ quantity: 2, price_estimate: 13.75)],
with_proxy_orders: true)
}
@@ -370,7 +421,8 @@ feature 'Subscriptions' do
# Existing products should be visible
click_button 'edit-products'
within "#sli_0" do
- expect(page).to have_selector '.description', text: "#{product1.name} - #{variant1.full_name}"
+ expect(page).to have_selector '.description',
+ text: "#{product1.name} - #{variant1.full_name}"
expect(page).to have_selector 'td.price', text: "$13.75"
expect(page).to have_input 'quantity', with: "2"
expect(page).to have_selector 'td.total', text: "$27.50"
@@ -386,7 +438,8 @@ feature 'Subscriptions' do
# Add variant2 to the subscription
add_variant_to_subscription(variant2, 1)
within "#sli_0" do
- expect(page).to have_selector '.description', text: "#{product2.name} - #{variant2.full_name}"
+ expect(page).to have_selector '.description',
+ text: "#{product2.name} - #{variant2.full_name}"
expect(page).to have_selector 'td.price', text: "$7.75"
expect(page).to have_input 'quantity', with: "1"
expect(page).to have_selector 'td.total', text: "$7.75"
@@ -398,7 +451,8 @@ feature 'Subscriptions' do
# Add variant3 to the subscription (even though it is not available)
add_variant_to_subscription(variant3, 1)
within "#sli_1" do
- expect(page).to have_selector '.description', text: "#{product3.name} - #{variant3.full_name}"
+ expect(page).to have_selector '.description',
+ text: "#{product3.name} - #{variant3.full_name}"
expect(page).to have_selector 'td.price', text: "$22.00"
expect(page).to have_input 'quantity', with: "1"
expect(page).to have_selector 'td.total', text: "$22.00"
@@ -444,7 +498,8 @@ feature 'Subscriptions' do
click_button 'Save Changes'
expect(page).to have_content 'Saved'
- expect(page).to have_selector "#order_update_issues_dialog .message", text: I18n.t("admin.subscriptions.order_update_issues_msg")
+ expect(page).to have_selector "#order_update_issues_dialog .message",
+ text: I18n.t("admin.subscriptions.order_update_issues_msg")
end
end
end
@@ -456,21 +511,26 @@ feature 'Subscriptions' do
let!(:shop_variant) { create(:variant, product: shop_product, unit_value: "2000") }
let!(:permitted_supplier) do
create(:supplier_enterprise).tap do |supplier|
- create(:enterprise_relationship, child: shop, parent: supplier, permissions_list: [:add_to_order_cycle])
+ create(:enterprise_relationship, child: shop, parent: supplier,
+ permissions_list: [:add_to_order_cycle])
end
end
let!(:permitted_supplier_product) { create(:product, supplier: permitted_supplier) }
- let!(:permitted_supplier_variant) { create(:variant, product: permitted_supplier_product, unit_value: "2000") }
+ let!(:permitted_supplier_variant) {
+ create(:variant, product: permitted_supplier_product, unit_value: "2000")
+ }
let!(:incoming_exchange_product) { create(:product) }
let!(:incoming_exchange_variant) do
create(:variant, product: incoming_exchange_product, unit_value: "2000").tap do |variant|
- create(:exchange, order_cycle: order_cycle, incoming: true, receiver: shop, variants: [variant])
+ create(:exchange, order_cycle: order_cycle, incoming: true, receiver: shop,
+ variants: [variant])
end
end
let!(:outgoing_exchange_product) { create(:product) }
let!(:outgoing_exchange_variant) do
create(:variant, product: outgoing_exchange_product, unit_value: "2000").tap do |variant|
- create(:exchange, order_cycle: order_cycle, incoming: false, receiver: shop, variants: [variant])
+ create(:exchange, order_cycle: order_cycle, incoming: false, receiver: shop,
+ variants: [variant])
end
end
let!(:enterprise_fee) { create(:enterprise_fee, amount: 1.75) }
diff --git a/spec/features/admin/tag_rules_spec.rb b/spec/features/admin/tag_rules_spec.rb
index 610b0fe8b7..05814bf736 100644
--- a/spec/features/admin/tag_rules_spec.rb
+++ b/spec/features/admin/tag_rules_spec.rb
@@ -27,7 +27,8 @@ feature 'Tag Rules', js: true do
click_button "Add Rule"
within(".customer_tag #tr_0") do
fill_in_tag "volunteers-only"
- select2_select "NOT VISIBLE", from: "enterprise_tag_rules_attributes_0_preferred_matched_shipping_methods_visibility"
+ select2_select "NOT VISIBLE",
+ from: "enterprise_tag_rules_attributes_0_preferred_matched_shipping_methods_visibility"
end
# New FilterProducts Rule
@@ -36,7 +37,8 @@ feature 'Tag Rules', js: true do
click_button "Add Rule"
within(".customer_tag #tr_1") do
fill_in_tag "volunteers-only1"
- select2_select "VISIBLE", from: "enterprise_tag_rules_attributes_1_preferred_matched_variants_visibility"
+ select2_select "VISIBLE",
+ from: "enterprise_tag_rules_attributes_1_preferred_matched_variants_visibility"
end
# New FilterPaymentMethods Rule
@@ -45,7 +47,8 @@ feature 'Tag Rules', js: true do
click_button "Add Rule"
within(".customer_tag #tr_2") do
fill_in_tag "volunteers-only2"
- select2_select "VISIBLE", from: "enterprise_tag_rules_attributes_2_preferred_matched_payment_methods_visibility"
+ select2_select "VISIBLE",
+ from: "enterprise_tag_rules_attributes_2_preferred_matched_payment_methods_visibility"
end
# New FilterOrderCycles Rule
@@ -54,7 +57,8 @@ feature 'Tag Rules', js: true do
click_button "Add Rule"
within(".customer_tag #tr_3") do
fill_in_tag "volunteers-only3"
- select2_select "NOT VISIBLE", from: "enterprise_tag_rules_attributes_3_preferred_matched_order_cycles_visibility"
+ select2_select "NOT VISIBLE",
+ from: "enterprise_tag_rules_attributes_3_preferred_matched_order_cycles_visibility"
end
# New DEFAULT FilterOrderCycles Rule
@@ -96,11 +100,26 @@ feature 'Tag Rules', js: true do
end
context "updating" do
- let!(:default_fsm_tag_rule) { create(:filter_shipping_methods_tag_rule, enterprise: enterprise, preferred_matched_shipping_methods_visibility: "visible", is_default: true, preferred_shipping_method_tags: "local" ) }
- let!(:fp_tag_rule) { create(:filter_products_tag_rule, enterprise: enterprise, preferred_matched_variants_visibility: "visible", preferred_customer_tags: "member", preferred_variant_tags: "member" ) }
- let!(:fpm_tag_rule) { create(:filter_payment_methods_tag_rule, enterprise: enterprise, preferred_matched_payment_methods_visibility: "hidden", preferred_customer_tags: "trusted", preferred_payment_method_tags: "trusted" ) }
- let!(:foc_tag_rule) { create(:filter_order_cycles_tag_rule, enterprise: enterprise, preferred_matched_order_cycles_visibility: "visible", preferred_customer_tags: "wholesale", preferred_exchange_tags: "wholesale" ) }
- let!(:fsm_tag_rule) { create(:filter_shipping_methods_tag_rule, enterprise: enterprise, preferred_matched_shipping_methods_visibility: "hidden", preferred_customer_tags: "local", preferred_shipping_method_tags: "local" ) }
+ let!(:default_fsm_tag_rule) {
+ create(:filter_shipping_methods_tag_rule, enterprise: enterprise,
+ preferred_matched_shipping_methods_visibility: "visible", is_default: true, preferred_shipping_method_tags: "local" )
+ }
+ let!(:fp_tag_rule) {
+ create(:filter_products_tag_rule, enterprise: enterprise,
+ preferred_matched_variants_visibility: "visible", preferred_customer_tags: "member", preferred_variant_tags: "member" )
+ }
+ let!(:fpm_tag_rule) {
+ create(:filter_payment_methods_tag_rule, enterprise: enterprise,
+ preferred_matched_payment_methods_visibility: "hidden", preferred_customer_tags: "trusted", preferred_payment_method_tags: "trusted" )
+ }
+ let!(:foc_tag_rule) {
+ create(:filter_order_cycles_tag_rule, enterprise: enterprise,
+ preferred_matched_order_cycles_visibility: "visible", preferred_customer_tags: "wholesale", preferred_exchange_tags: "wholesale" )
+ }
+ let!(:fsm_tag_rule) {
+ create(:filter_shipping_methods_tag_rule, enterprise: enterprise,
+ preferred_matched_shipping_methods_visibility: "hidden", preferred_customer_tags: "local", preferred_shipping_method_tags: "local" )
+ }
before do
visit_tag_rules
@@ -109,10 +128,14 @@ feature 'Tag Rules', js: true do
it "saves changes to rules of each type" do
# Tag groups exist
expect(page).to have_selector '.customer_tag .header', text: "For customers tagged:", count: 4
- expect(page).to have_selector '.customer_tag .header tags-input .tag-list ti-tag-item', text: "member", count: 1
- expect(page).to have_selector '.customer_tag .header tags-input .tag-list ti-tag-item', text: "local", count: 1
- expect(page).to have_selector '.customer_tag .header tags-input .tag-list ti-tag-item', text: "wholesale", count: 1
- expect(page).to have_selector '.customer_tag .header tags-input .tag-list ti-tag-item', text: "trusted", count: 1
+ expect(page).to have_selector '.customer_tag .header tags-input .tag-list ti-tag-item',
+ text: "member", count: 1
+ expect(page).to have_selector '.customer_tag .header tags-input .tag-list ti-tag-item',
+ text: "local", count: 1
+ expect(page).to have_selector '.customer_tag .header tags-input .tag-list ti-tag-item',
+ text: "wholesale", count: 1
+ expect(page).to have_selector '.customer_tag .header tags-input .tag-list ti-tag-item',
+ text: "trusted", count: 1
all(:css, ".customer_tag .header tags-input").each do |node|
node.find("li.tag-item a.remove-button").click
within(:xpath, node.path) { fill_in_tag "volunteer", ".tags input" }
@@ -129,32 +152,40 @@ feature 'Tag Rules', js: true do
within ".customer_tag #tr_1" do
within "li.tag-item", text: "member ✖" do find("a.remove-button").click end
fill_in_tag "volunteers-only1"
- expect(page).to have_select2 "enterprise_tag_rules_attributes_1_preferred_matched_variants_visibility", selected: 'VISIBLE'
- select2_select 'NOT VISIBLE', from: "enterprise_tag_rules_attributes_1_preferred_matched_variants_visibility"
+ expect(page).to have_select2 "enterprise_tag_rules_attributes_1_preferred_matched_variants_visibility",
+ selected: 'VISIBLE'
+ select2_select 'NOT VISIBLE',
+ from: "enterprise_tag_rules_attributes_1_preferred_matched_variants_visibility"
end
# FilterPaymentMethods rule
within ".customer_tag #tr_2" do
within "li.tag-item", text: "trusted ✖" do find("a.remove-button").click end
fill_in_tag "volunteers-only2"
- expect(page).to have_select2 "enterprise_tag_rules_attributes_2_preferred_matched_payment_methods_visibility", selected: 'NOT VISIBLE'
- select2_select 'VISIBLE', from: "enterprise_tag_rules_attributes_2_preferred_matched_payment_methods_visibility"
+ expect(page).to have_select2 "enterprise_tag_rules_attributes_2_preferred_matched_payment_methods_visibility",
+ selected: 'NOT VISIBLE'
+ select2_select 'VISIBLE',
+ from: "enterprise_tag_rules_attributes_2_preferred_matched_payment_methods_visibility"
end
# FilterOrderCycles rule
within ".customer_tag #tr_3" do
within "li.tag-item", text: "wholesale ✖" do find("a.remove-button").click end
fill_in_tag "volunteers-only3"
- expect(page).to have_select2 "enterprise_tag_rules_attributes_3_preferred_matched_order_cycles_visibility", selected: 'VISIBLE'
- select2_select 'NOT VISIBLE', from: "enterprise_tag_rules_attributes_3_preferred_matched_order_cycles_visibility"
+ expect(page).to have_select2 "enterprise_tag_rules_attributes_3_preferred_matched_order_cycles_visibility",
+ selected: 'VISIBLE'
+ select2_select 'NOT VISIBLE',
+ from: "enterprise_tag_rules_attributes_3_preferred_matched_order_cycles_visibility"
end
# FilterShippingMethods rule
within ".customer_tag #tr_4" do
within "li.tag-item", text: "local ✖" do find("a.remove-button").click end
fill_in_tag "volunteers-only4"
- expect(page).to have_select2 "enterprise_tag_rules_attributes_4_preferred_matched_shipping_methods_visibility", selected: 'NOT VISIBLE'
- select2_select 'VISIBLE', from: "enterprise_tag_rules_attributes_4_preferred_matched_shipping_methods_visibility"
+ expect(page).to have_select2 "enterprise_tag_rules_attributes_4_preferred_matched_shipping_methods_visibility",
+ selected: 'NOT VISIBLE'
+ select2_select 'VISIBLE',
+ from: "enterprise_tag_rules_attributes_4_preferred_matched_shipping_methods_visibility"
end
# Moving the Shipping Methods to top priority
@@ -194,8 +225,12 @@ feature 'Tag Rules', js: true do
end
context "deleting" do
- let!(:tag_rule) { create(:filter_products_tag_rule, enterprise: enterprise, preferred_customer_tags: "member" ) }
- let!(:default_rule) { create(:filter_products_tag_rule, is_default: true, enterprise: enterprise ) }
+ let!(:tag_rule) {
+ create(:filter_products_tag_rule, enterprise: enterprise, preferred_customer_tags: "member" )
+ }
+ let!(:default_rule) {
+ create(:filter_products_tag_rule, is_default: true, enterprise: enterprise )
+ }
before do
visit_tag_rules
diff --git a/spec/features/admin/variant_overrides_spec.rb b/spec/features/admin/variant_overrides_spec.rb
index 6322af44b3..4ef8e3f116 100644
--- a/spec/features/admin/variant_overrides_spec.rb
+++ b/spec/features/admin/variant_overrides_spec.rb
@@ -46,17 +46,30 @@ feature "
end
context "when inventory_items exist for variants" do
- let!(:product) { create(:simple_product, supplier: producer, variant_unit: 'weight', variant_unit_scale: 1) }
+ let!(:product) {
+ create(:simple_product, supplier: producer, variant_unit: 'weight', variant_unit_scale: 1)
+ }
let!(:variant) { create(:variant, product: product, unit_value: 1, price: 1.23, on_hand: 12) }
let!(:inventory_item) { create(:inventory_item, enterprise: hub, variant: variant ) }
- let!(:product_managed) { create(:simple_product, supplier: producer_managed, variant_unit: 'weight', variant_unit_scale: 1) }
- let!(:variant_managed) { create(:variant, product: product_managed, unit_value: 3, price: 3.65, on_hand: 2) }
- let!(:inventory_item_managed) { create(:inventory_item, enterprise: hub, variant: variant_managed ) }
+ let!(:product_managed) {
+ create(:simple_product, supplier: producer_managed, variant_unit: 'weight',
+ variant_unit_scale: 1)
+ }
+ let!(:variant_managed) {
+ create(:variant, product: product_managed, unit_value: 3, price: 3.65, on_hand: 2)
+ }
+ let!(:inventory_item_managed) {
+ create(:inventory_item, enterprise: hub, variant: variant_managed )
+ }
let!(:product_related) { create(:simple_product, supplier: producer_related) }
- let!(:variant_related) { create(:variant, product: product_related, unit_value: 2, price: 2.34, on_hand: 23) }
- let!(:inventory_item_related) { create(:inventory_item, enterprise: hub, variant: variant_related ) }
+ let!(:variant_related) {
+ create(:variant, product: product_related, unit_value: 2, price: 2.34, on_hand: 23)
+ }
+ let!(:inventory_item_related) {
+ create(:inventory_item, enterprise: hub, variant: variant_related )
+ }
let!(:product_unrelated) { create(:simple_product, supplier: producer_unrelated) }
@@ -76,11 +89,14 @@ feature "
expect(page).to have_table_row ['PRODUCER', 'PRODUCT', 'PRICE', 'ON HAND', 'ON DEMAND?']
expect(page).to have_table_row [producer.name, product.name, '', '', '']
expect(page).to have_input "variant-overrides-#{variant.id}-price", placeholder: '1.23'
- expect(page).to have_input "variant-overrides-#{variant.id}-count_on_hand", placeholder: '12'
+ expect(page).to have_input "variant-overrides-#{variant.id}-count_on_hand",
+ placeholder: '12'
expect(page).to have_table_row [producer_related.name, product_related.name, '', '', '']
- expect(page).to have_input "variant-overrides-#{variant_related.id}-price", placeholder: '2.34'
- expect(page).to have_input "variant-overrides-#{variant_related.id}-count_on_hand", placeholder: '23'
+ expect(page).to have_input "variant-overrides-#{variant_related.id}-price",
+ placeholder: '2.34'
+ expect(page).to have_input "variant-overrides-#{variant_related.id}-count_on_hand",
+ placeholder: '23'
# filters the products to those the hub can override
expect(page).not_to have_content producer_managed.name
@@ -224,14 +240,32 @@ feature "
end
context "with overrides" do
- let!(:vo) { create(:variant_override, :on_demand, variant: variant, hub: hub, price: 77.77, default_stock: 1000, resettable: true, tag_list: ["tag1", "tag2", "tag3"]) }
- let!(:vo_no_auth) { create(:variant_override, variant: variant, hub: hub2, price: 1, count_on_hand: 2) }
- let!(:product2) { create(:simple_product, supplier: producer, variant_unit: 'weight', variant_unit_scale: 1) }
- let!(:variant2) { create(:variant, product: product2, unit_value: 8, price: 1.00, on_hand: 12) }
+ let!(:vo) {
+ create(:variant_override, :on_demand, variant: variant, hub: hub, price: 77.77,
+ default_stock: 1000, resettable: true, tag_list: ["tag1", "tag2", "tag3"])
+ }
+ let!(:vo_no_auth) {
+ create(:variant_override, variant: variant, hub: hub2, price: 1, count_on_hand: 2)
+ }
+ let!(:product2) {
+ create(:simple_product, supplier: producer, variant_unit: 'weight',
+ variant_unit_scale: 1)
+ }
+ let!(:variant2) {
+ create(:variant, product: product2, unit_value: 8, price: 1.00, on_hand: 12)
+ }
let!(:inventory_item2) { create(:inventory_item, enterprise: hub, variant: variant2) }
- let!(:vo_no_reset) { create(:variant_override, variant: variant2, hub: hub, price: 3.99, count_on_hand: 40, default_stock: 100, resettable: false) }
- let!(:variant3) { create(:variant, product: product, unit_value: 2, price: 5.00, on_hand: 6) }
- let!(:vo3) { create(:variant_override, variant: variant3, hub: hub, price: 6, count_on_hand: 7, sku: "SOMESKU", default_stock: 100, resettable: false) }
+ let!(:vo_no_reset) {
+ create(:variant_override, variant: variant2, hub: hub, price: 3.99, count_on_hand: 40,
+ default_stock: 100, resettable: false)
+ }
+ let!(:variant3) {
+ create(:variant, product: product, unit_value: 2, price: 5.00, on_hand: 6)
+ }
+ let!(:vo3) {
+ create(:variant_override, variant: variant3, hub: hub, price: 6, count_on_hand: 7, sku: "SOMESKU",
+ default_stock: 100, resettable: false)
+ }
let!(:inventory_item3) { create(:inventory_item, enterprise: hub, variant: variant3) }
before do
@@ -240,11 +274,15 @@ feature "
end
it "product values are affected by overrides" do
- expect(page).to have_input "variant-overrides-#{variant.id}-price", with: '77.77', placeholder: '1.23'
- expect(page).to have_input "variant-overrides-#{variant.id}-count_on_hand", with: "", placeholder: I18n.t("js.variants.on_demand.yes")
- expect(page).to have_select "variant-overrides-#{variant.id}-on_demand", selected: I18n.t("js.variant_overrides.on_demand.yes")
+ expect(page).to have_input "variant-overrides-#{variant.id}-price", with: '77.77',
+ placeholder: '1.23'
+ expect(page).to have_input "variant-overrides-#{variant.id}-count_on_hand", with: "",
+ placeholder: I18n.t("js.variants.on_demand.yes")
+ expect(page).to have_select "variant-overrides-#{variant.id}-on_demand",
+ selected: I18n.t("js.variant_overrides.on_demand.yes")
- expect(page).to have_input "variant-overrides-#{variant2.id}-count_on_hand", with: "40", placeholder: ""
+ expect(page).to have_input "variant-overrides-#{variant2.id}-count_on_hand",
+ with: "40", placeholder: ""
end
it "updates existing overrides" do
@@ -327,25 +365,30 @@ feature "
it "resets stock to defaults" do
first("div#bulk-actions-dropdown").click
- first("div#bulk-actions-dropdown div.menu div.menu_item", text: "Reset Stock Levels To Defaults").click
+ first("div#bulk-actions-dropdown div.menu div.menu_item",
+ text: "Reset Stock Levels To Defaults").click
expect(page).to have_content 'Stocks reset to defaults.'
vo.reload
- expect(page).to have_input "variant-overrides-#{variant.id}-count_on_hand", with: "1000", placeholder: ""
+ expect(page).to have_input "variant-overrides-#{variant.id}-count_on_hand",
+ with: "1000", placeholder: ""
expect(vo.count_on_hand).to eq(1000)
end
it "doesn't reset stock levels if the behaviour is disabled" do
first("div#bulk-actions-dropdown").click
- first("div#bulk-actions-dropdown div.menu div.menu_item", text: "Reset Stock Levels To Defaults").click
+ first("div#bulk-actions-dropdown div.menu div.menu_item",
+ text: "Reset Stock Levels To Defaults").click
vo_no_reset.reload
- expect(page).to have_input "variant-overrides-#{variant2.id}-count_on_hand", with: "40", placeholder: ""
+ expect(page).to have_input "variant-overrides-#{variant2.id}-count_on_hand",
+ with: "40", placeholder: ""
expect(vo_no_reset.count_on_hand).to eq(40)
end
it "prompts to save changes before reset if any are pending" do
fill_in "variant-overrides-#{variant.id}-price", with: '200'
first("div#bulk-actions-dropdown").click
- first("div#bulk-actions-dropdown div.menu div.menu_item", text: "Reset Stock Levels To Defaults").click
+ first("div#bulk-actions-dropdown div.menu div.menu_item",
+ text: "Reset Stock Levels To Defaults").click
expect(page).to have_content "Save changes first"
end
@@ -418,8 +461,12 @@ feature "
end
describe "when inventory_items do not exist for variants" do
- let!(:product) { create(:simple_product, supplier: producer, variant_unit: 'weight', variant_unit_scale: 1) }
- let!(:variant1) { create(:variant, product: product, unit_value: 1, price: 1.23, on_hand: 12) }
+ let!(:product) {
+ create(:simple_product, supplier: producer, variant_unit: 'weight', variant_unit_scale: 1)
+ }
+ let!(:variant1) {
+ create(:variant, product: product, unit_value: 1, price: 1.23, on_hand: 12)
+ }
let!(:variant2) { create(:variant, product: product, unit_value: 2, price: 4.56, on_hand: 3) }
context "when a hub is selected" do
@@ -432,7 +479,8 @@ feature "
expect(page).to have_no_selector "table#variant-overrides tr#v_#{variant1.id}"
expect(page).to have_no_selector "table#variant-overrides tr#v_#{variant2.id}"
- expect(page).to have_selector '.alert-row span.message', text: "There are 1 new products available to add to your inventory."
+ expect(page).to have_selector '.alert-row span.message',
+ text: "There are 1 new products available to add to your inventory."
click_button "Review Now"
expect(page).to have_table_row ['PRODUCER', 'PRODUCT', 'VARIANT', 'ADD', 'HIDE']
diff --git a/spec/features/consumer/account/cards_spec.rb b/spec/features/consumer/account/cards_spec.rb
index 606fc08e9f..a33beed8ed 100644
--- a/spec/features/consumer/account/cards_spec.rb
+++ b/spec/features/consumer/account/cards_spec.rb
@@ -10,8 +10,13 @@ feature "Credit Cards", js: true do
describe "as a logged in user" do
let(:user) { create(:user) }
let!(:customer) { create(:customer, user: user) }
- let!(:default_card) { create(:stored_credit_card, user_id: user.id, gateway_customer_profile_id: 'cus_AZNMJ', is_default: true) }
- let!(:non_default_card) { create(:stored_credit_card, user_id: user.id, gateway_customer_profile_id: 'cus_FDTG') }
+ let!(:default_card) {
+ create(:stored_credit_card, user_id: user.id, gateway_customer_profile_id: 'cus_AZNMJ',
+ is_default: true)
+ }
+ let!(:non_default_card) {
+ create(:stored_credit_card, user_id: user.id, gateway_customer_profile_id: 'cus_FDTG')
+ }
around do |example|
original_stripe_connect_enabled = Spree::Config[:stripe_connect_enabled]
@@ -39,7 +44,7 @@ feature "Credit Cards", js: true do
it "passes the smoke test" do
visit "/account"
- find("a", :text => %r{#{I18n.t('spree.users.show.tabs.cards')}}i).click
+ find("a", text: /#{I18n.t('spree.users.show.tabs.cards')}/i).click
expect(page).to have_content I18n.t(:saved_cards)
@@ -81,7 +86,8 @@ feature "Credit Cards", js: true do
click_link I18n.t(:delete)
end
- expect(page).to have_content I18n.t(:card_has_been_removed, number: "x-#{default_card.last_digits}")
+ expect(page).to have_content I18n.t(:card_has_been_removed,
+ number: "x-#{default_card.last_digits}")
expect(page).to have_no_selector ".card#card#{default_card.id}"
# Allows authorisation of card use by shops
diff --git a/spec/features/consumer/account/payments_spec.rb b/spec/features/consumer/account/payments_spec.rb
index 9f6ddf33c9..bdcfb66d05 100644
--- a/spec/features/consumer/account/payments_spec.rb
+++ b/spec/features/consumer/account/payments_spec.rb
@@ -21,7 +21,7 @@ feature "Payments requiring action", js: true do
it "shows a table of payments requiring authorization" do
visit "/account"
- find("a", :text => %r{#{I18n.t('spree.users.show.tabs.transactions')}}i).click
+ find("a", text: /#{I18n.t('spree.users.show.tabs.transactions')}/i).click
expect(page).to have_content I18n.t("spree.users.transactions.authorisation_required")
end
end
@@ -34,7 +34,7 @@ feature "Payments requiring action", js: true do
it "does not show the table of payments requiring authorization" do
visit "/account"
- find("a", :text => %r{#{I18n.t('spree.users.show.tabs.transactions')}}i).click
+ find("a", text: /#{I18n.t('spree.users.show.tabs.transactions')}/i).click
expect(page).to_not have_content I18n.t("spree.users.transactions.authorisation_required")
end
end
diff --git a/spec/features/consumer/account/settings_spec.rb b/spec/features/consumer/account/settings_spec.rb
index 964a8d0fbe..3a83ba952d 100644
--- a/spec/features/consumer/account/settings_spec.rb
+++ b/spec/features/consumer/account/settings_spec.rb
@@ -18,7 +18,7 @@ feature "Account Settings", js: true do
setup_email
login_as user
visit "/account"
- find("a", :text => %r{#{I18n.t('spree.users.show.tabs.settings')}}i).click
+ find("a", text: /#{I18n.t('spree.users.show.tabs.settings')}/i).click
expect(page).to have_content I18n.t('spree.users.form.account_settings')
end
@@ -37,7 +37,7 @@ feature "Account Settings", js: true do
user.reload
expect(user.email).to eq 'old@email.com'
expect(user.unconfirmed_email).to eq 'new@email.com'
- find("a", :text => %r{#{I18n.t('spree.users.show.tabs.settings')}}i).click
+ find("a", text: /#{I18n.t('spree.users.show.tabs.settings')}/i).click
expect(page).to have_content I18n.t('spree.users.show.unconfirmed_email',
unconfirmed_email: 'new@email.com')
end
diff --git a/spec/features/consumer/account_spec.rb b/spec/features/consumer/account_spec.rb
index ce85e5e9d3..00c004ed7e 100644
--- a/spec/features/consumer/account_spec.rb
+++ b/spec/features/consumer/account_spec.rb
@@ -23,10 +23,18 @@ feature '
context "with completed orders" do
let(:order_cycle) { create(:simple_order_cycle) }
- let!(:d1o1) { create(:completed_order_with_totals, distributor: distributor1, user: user, total: 10_000, order_cycle: order_cycle) }
- let!(:d1o2) { create(:order_without_full_payment, distributor: distributor1, user: user, total: 5000, order_cycle: order_cycle) }
+ let!(:d1o1) {
+ create(:completed_order_with_totals, distributor: distributor1, user: user, total: 10_000,
+ order_cycle: order_cycle)
+ }
+ let!(:d1o2) {
+ create(:order_without_full_payment, distributor: distributor1, user: user, total: 5000,
+ order_cycle: order_cycle)
+ }
let!(:d2o1) { create(:completed_order_with_totals, distributor: distributor2, user: user) }
- let!(:credit_order) { create(:order_with_credit_payment, distributor: distributor_credit, user: user) }
+ let!(:credit_order) {
+ create(:order_with_credit_payment, distributor: distributor_credit, user: user)
+ }
before do
credit_order.update_order!
@@ -54,7 +62,7 @@ feature '
href: "#{distributor_credit.permalink}/shop", count: 1)
# Viewing transaction history
- find("a", :text => %r{#{I18n.t('spree.users.show.tabs.transactions')}}i).click
+ find("a", text: /#{I18n.t('spree.users.show.tabs.transactions')}/i).click
# It shows all hubs that have been ordered from with balance or credit
expect(page).to have_content distributor1.name
@@ -89,8 +97,10 @@ feature '
expect(page).to have_link d1o2.number, href: order_path(d1o2)
expect(page).to have_link(distributor1.name,
href: "#{distributor1.permalink}/shop", count: 2)
- expect(page).to have_link I18n.t('spree.users.open_orders.cancel'), href: cancel_order_path(d1o1)
- expect(page).to have_link I18n.t('spree.users.open_orders.cancel'), href: cancel_order_path(d1o2)
+ expect(page).to have_link I18n.t('spree.users.open_orders.cancel'),
+ href: cancel_order_path(d1o1)
+ expect(page).to have_link I18n.t('spree.users.open_orders.cancel'),
+ href: cancel_order_path(d1o2)
end
end
end
diff --git a/spec/features/consumer/authentication_spec.rb b/spec/features/consumer/authentication_spec.rb
index 3b06f3a97a..1ef63e3217 100644
--- a/spec/features/consumer/authentication_spec.rb
+++ b/spec/features/consumer/authentication_spec.rb
@@ -113,7 +113,9 @@ feature "Authentication", js: true do
context "user with unconfirmed email" do
let(:email) { "test@example.org" }
- let!(:user) { Spree::User.create(email: email, unconfirmed_email: email, password: "secret") }
+ let!(:user) {
+ Spree::User.create(email: email, unconfirmed_email: email, password: "secret")
+ }
scenario "cannot reset password before confirming email" do
fill_in "Your email", with: email
diff --git a/spec/features/consumer/caching/darkswarm_caching_spec.rb b/spec/features/consumer/caching/darkswarm_caching_spec.rb
index 14ccbd2ab9..cb0baf979d 100644
--- a/spec/features/consumer/caching/darkswarm_caching_spec.rb
+++ b/spec/features/consumer/caching/darkswarm_caching_spec.rb
@@ -7,9 +7,16 @@ feature "Darkswarm data caching", js: true, caching: true do
let!(:property) { create(:property, presentation: "Cached Property") }
let!(:producer) { create(:supplier_enterprise) }
- let!(:distributor) { create(:distributor_enterprise, with_payment_and_shipping: true, is_primary_producer: true) }
- let!(:product) { create(:simple_product, supplier: producer, primary_taxon: taxon, taxons: [taxon], properties: [property]) }
- let!(:order_cycle) { create(:simple_order_cycle, distributors: [distributor], coordinator: distributor) }
+ let!(:distributor) {
+ create(:distributor_enterprise, with_payment_and_shipping: true, is_primary_producer: true)
+ }
+ let!(:product) {
+ create(:simple_product, supplier: producer, primary_taxon: taxon, taxons: [taxon],
+ properties: [property])
+ }
+ let!(:order_cycle) {
+ create(:simple_order_cycle, distributors: [distributor], coordinator: distributor)
+ }
let(:exchange) { order_cycle.exchanges.outgoing.where(receiver_id: distributor.id).first }
before do
diff --git a/spec/features/consumer/caching/shops_caching_spec.rb b/spec/features/consumer/caching/shops_caching_spec.rb
index 25ac1a1918..71d57a4bec 100644
--- a/spec/features/consumer/caching/shops_caching_spec.rb
+++ b/spec/features/consumer/caching/shops_caching_spec.rb
@@ -6,8 +6,12 @@ feature "Shops caching", js: true, caching: true do
include WebHelper
include UIComponentHelper
- let!(:distributor) { create(:distributor_enterprise, with_payment_and_shipping: true, is_primary_producer: true) }
- let!(:order_cycle) { create(:open_order_cycle, distributors: [distributor], coordinator: distributor) }
+ let!(:distributor) {
+ create(:distributor_enterprise, with_payment_and_shipping: true, is_primary_producer: true)
+ }
+ let!(:order_cycle) {
+ create(:open_order_cycle, distributors: [distributor], coordinator: distributor)
+ }
describe "caching enterprises AMS data" do
it "caches data for all enterprises, with the provided options" do
@@ -43,12 +47,20 @@ feature "Shops caching", js: true, caching: true do
let!(:taxon2) { create(:taxon, name: "New Taxon") }
let!(:property) { create(:property, presentation: "Cached Property") }
let!(:property2) { create(:property, presentation: "New Property") }
- let!(:product) { create(:product, taxons: [taxon], primary_taxon: taxon, properties: [property]) }
+ let!(:product) {
+ create(:product, taxons: [taxon], primary_taxon: taxon, properties: [property])
+ }
let(:exchange) { order_cycle.exchanges.to_enterprises(distributor).outgoing.first }
- let(:test_domain) { "#{Capybara.current_session.server.host}:#{Capybara.current_session.server.port}" }
- let(:taxons_key) { "views/#{test_domain}/api/v0/order_cycles/#{order_cycle.id}/taxons.json?distributor=#{distributor.id}" }
- let(:properties_key) { "views/#{test_domain}/api/v0/order_cycles/#{order_cycle.id}/properties.json?distributor=#{distributor.id}" }
+ let(:test_domain) {
+ "#{Capybara.current_session.server.host}:#{Capybara.current_session.server.port}"
+ }
+ let(:taxons_key) {
+ "views/#{test_domain}/api/v0/order_cycles/#{order_cycle.id}/taxons.json?distributor=#{distributor.id}"
+ }
+ let(:properties_key) {
+ "views/#{test_domain}/api/v0/order_cycles/#{order_cycle.id}/properties.json?distributor=#{distributor.id}"
+ }
let(:options) { { expires_in: CacheService::FILTERS_EXPIRY } }
before do
diff --git a/spec/features/consumer/groups_spec.rb b/spec/features/consumer/groups_spec.rb
index 287804726b..583cfa8556 100644
--- a/spec/features/consumer/groups_spec.rb
+++ b/spec/features/consumer/groups_spec.rb
@@ -60,7 +60,10 @@ feature 'Groups', js: true do
describe "shops" do
describe "filtering by product property" do
let!(:group) { create(:enterprise_group, enterprises: [d1, d2], on_front_page: true) }
- let!(:order_cycle) { create(:simple_order_cycle, distributors: [d1, d2], coordinator: create(:distributor_enterprise)) }
+ let!(:order_cycle) {
+ create(:simple_order_cycle, distributors: [d1, d2],
+ coordinator: create(:distributor_enterprise))
+ }
let(:producer) { create(:supplier_enterprise) }
let(:d1) { create(:distributor_enterprise, with_payment_and_shipping: true) }
let(:d2) { create(:distributor_enterprise, with_payment_and_shipping: true) }
diff --git a/spec/features/consumer/multilingual_spec.rb b/spec/features/consumer/multilingual_spec.rb
index 34932152e2..a8e16df100 100644
--- a/spec/features/consumer/multilingual_spec.rb
+++ b/spec/features/consumer/multilingual_spec.rb
@@ -43,7 +43,9 @@ feature 'Multilingual', js: true do
context 'with a product in the cart' do
let(:distributor) { create(:distributor_enterprise, with_payment_and_shipping: true) }
- let!(:order_cycle) { create(:simple_order_cycle, distributors: [distributor], variants: [product.variants.first]) }
+ let!(:order_cycle) {
+ create(:simple_order_cycle, distributors: [distributor], variants: [product.variants.first])
+ }
let(:product) { create(:simple_product) }
let(:order) { create(:order, order_cycle: order_cycle, distributor: distributor) }
@@ -126,7 +128,8 @@ feature 'Multilingual', js: true do
find('.language-switcher').click
within '.language-switcher .dropdown' do
expect(page).to have_link I18n.t('language_name', locale: :en), href: '?locale=en'
- expect(page).to have_link I18n.t('language_name', locale: :es, default: 'Language Name'), href: '?locale=es'
+ expect(page).to have_link I18n.t('language_name', locale: :es, default: 'Language Name'),
+ href: '?locale=es'
find('li a[href="?locale=es"]').click
end
diff --git a/spec/features/consumer/producers_spec.rb b/spec/features/consumer/producers_spec.rb
index cdddd16cce..b88457eed4 100644
--- a/spec/features/consumer/producers_spec.rb
+++ b/spec/features/consumer/producers_spec.rb
@@ -18,8 +18,12 @@ feature '
let(:taxon_fruit) { create(:taxon, name: 'Fruit') }
let(:taxon_veg) { create(:taxon, name: 'Vegetables') }
- let!(:product1) { create(:simple_product, supplier: producer1, primary_taxon: taxon_fruit, taxons: [taxon_fruit]) }
- let!(:product2) { create(:simple_product, supplier: producer2, primary_taxon: taxon_veg, taxons: [taxon_veg]) }
+ let!(:product1) {
+ create(:simple_product, supplier: producer1, primary_taxon: taxon_fruit, taxons: [taxon_fruit])
+ }
+ let!(:product2) {
+ create(:simple_product, supplier: producer2, primary_taxon: taxon_veg, taxons: [taxon_veg])
+ }
let(:shop) { create(:distributor_enterprise) }
let!(:er) { create(:enterprise_relationship, parent: shop, child: producer1) }
diff --git a/spec/features/consumer/registration_spec.rb b/spec/features/consumer/registration_spec.rb
index 4975206323..9e382dae25 100644
--- a/spec/features/consumer/registration_spec.rb
+++ b/spec/features/consumer/registration_spec.rb
@@ -12,9 +12,11 @@ feature "Registration", js: true do
before do
Spree::Config.enterprises_require_tos = false
- albania = Spree::Country.create!({ name: "Albania", iso3: "ALB", iso: "AL", iso_name: "ALBANIA", numcode: "8" })
+ albania = Spree::Country.create!({ name: "Albania", iso3: "ALB", iso: "AL",
+ iso_name: "ALBANIA", numcode: "8" })
Spree::State.create!({ name: "Berat", abbr: "BRA", country: albania })
- Spree::Country.create!({ name: "Chad", iso3: "TCD", iso: "TD", iso_name: "CHAD", numcode: "148" })
+ Spree::Country.create!({ name: "Chad", iso3: "TCD", iso: "TD", iso_name: "CHAD",
+ numcode: "148" })
AddressGeocoder.any_instance.stub(:geocode)
end
@@ -54,7 +56,8 @@ feature "Registration", js: true do
fill_in 'enterprise_address', with: '123 Abc Street'
fill_in 'enterprise_city', with: 'Northcote'
fill_in 'enterprise_zipcode', with: '3070'
- expect(page).to have_select('enterprise_country', options: ["Albania", "Australia"], selected: 'Australia')
+ expect(page).to have_select('enterprise_country', options: ["Albania", "Australia"],
+ selected: 'Australia')
select 'Vic', from: 'enterprise_state'
click_button "Continue"
expect(page).to have_content 'Who is responsible for managing My Awesome Enterprise?'
diff --git a/spec/features/consumer/shopping/cart_spec.rb b/spec/features/consumer/shopping/cart_spec.rb
index b34c45ac7f..0a7ffdb8a1 100644
--- a/spec/features/consumer/shopping/cart_spec.rb
+++ b/spec/features/consumer/shopping/cart_spec.rb
@@ -10,12 +10,23 @@ feature "full-page cart", js: true do
describe "viewing the cart" do
let!(:zone) { create(:zone_with_member) }
- let(:distributor) { create(:distributor_enterprise, with_payment_and_shipping: true, charges_sales_tax: true) }
+ let(:distributor) {
+ create(:distributor_enterprise, with_payment_and_shipping: true, charges_sales_tax: true)
+ }
let(:supplier) { create(:supplier_enterprise) }
- let!(:order_cycle) { create(:simple_order_cycle, suppliers: [supplier], distributors: [distributor], coordinator: create(:distributor_enterprise), variants: [product_with_tax.variants.first, product_with_fee.variants.first]) }
- let(:enterprise_fee) { create(:enterprise_fee, amount: 11.00, tax_category: product_with_tax.tax_category) }
- let(:product_with_tax) { create(:taxed_product, supplier: supplier, zone: zone, price: 110.00, tax_rate_amount: 0.1) }
- let(:product_with_fee) { create(:simple_product, supplier: supplier, price: 0.86, on_hand: 100) }
+ let!(:order_cycle) {
+ create(:simple_order_cycle, suppliers: [supplier], distributors: [distributor],
+ coordinator: create(:distributor_enterprise), variants: [product_with_tax.variants.first, product_with_fee.variants.first])
+ }
+ let(:enterprise_fee) {
+ create(:enterprise_fee, amount: 11.00, tax_category: product_with_tax.tax_category)
+ }
+ let(:product_with_tax) {
+ create(:taxed_product, supplier: supplier, zone: zone, price: 110.00, tax_rate_amount: 0.1)
+ }
+ let(:product_with_fee) {
+ create(:simple_product, supplier: supplier, price: 0.86, on_hand: 100)
+ }
let(:order) { create(:order, order_cycle: order_cycle, distributor: distributor) }
before do
@@ -61,7 +72,10 @@ feature "full-page cart", js: true do
end
describe "percentage fees" do
- let(:percentage_fee) { create(:enterprise_fee, calculator: Calculator::FlatPercentPerItem.new(preferred_flat_percent: 20)) }
+ let(:percentage_fee) {
+ create(:enterprise_fee,
+ calculator: Calculator::FlatPercentPerItem.new(preferred_flat_percent: 20))
+ }
before do
add_enterprise_fee percentage_fee
@@ -95,10 +109,13 @@ feature "full-page cart", js: true do
it "shows admin and handlings row" do
expect(page).to have_selector('#cart-detail')
expect(page).to have_content('Admin & Handling')
- expect(page).to have_selector '.cart-item-price', text: with_currency(0.86)
- expect(page).to have_selector '.order-total.item-total', text: with_currency(2.58)
- expect(page).to have_selector '.order-total.distribution-total', text: with_currency(1.00)
- expect(page).to have_selector '.order-total.grand-total', text: with_currency(3.58) # price * 3 + 1
+ expect(page).to have_selector '.cart-item-price',
+ text: with_currency(0.86)
+ expect(page).to have_selector '.order-total.item-total',
+ text: with_currency(2.58)
+ expect(page).to have_selector '.order-total.distribution-total',
+ text: with_currency(1.00)
+ expect(page).to have_selector '.order-total.grand-total', text: with_currency(3.58) # price * 3 + 1
end
end
@@ -131,7 +148,8 @@ feature "full-page cart", js: true do
add_enterprise_fee admin_fee
cart_service = CartService.new(order)
- cart_service.populate(variants: { product_with_fee.variants.first.id => 3, product_with_tax.variants.first.id => 3 })
+ cart_service.populate(variants: { product_with_fee.variants.first.id => 3,
+ product_with_tax.variants.first.id => 3 })
order.recreate_all_fees!
visit main_app.cart_path
@@ -226,7 +244,8 @@ feature "full-page cart", js: true do
visit main_app.cart_path
# shows a relevant Flash message
- expect(page).to have_selector ".alert-box", text: I18n.t('spree.orders.error_flash_for_unavailable_items')
+ expect(page).to have_selector ".alert-box",
+ text: I18n.t('spree.orders.error_flash_for_unavailable_items')
# "Continue Shopping" and "Checkout" buttons are disabled
expect(page).to have_selector "a.continue-shopping[disabled=disabled]"
@@ -255,8 +274,14 @@ feature "full-page cart", js: true do
context "when ordered in the same order cycle" do
let(:address) { create(:address) }
let(:user) { create(:user, bill_address: address, ship_address: address) }
- let!(:prev_order1) { create(:completed_order_with_totals, order_cycle: order_cycle, distributor: distributor, user: user) }
- let!(:prev_order2) { create(:completed_order_with_totals, order_cycle: order_cycle, distributor: distributor, user: user) }
+ let!(:prev_order1) {
+ create(:completed_order_with_totals, order_cycle: order_cycle, distributor: distributor,
+ user: user)
+ }
+ let!(:prev_order2) {
+ create(:completed_order_with_totals, order_cycle: order_cycle, distributor: distributor,
+ user: user)
+ }
before do
order.user = user
diff --git a/spec/features/consumer/shopping/checkout_auth_spec.rb b/spec/features/consumer/shopping/checkout_auth_spec.rb
index 2a9d178fc0..187ff61861 100644
--- a/spec/features/consumer/shopping/checkout_auth_spec.rb
+++ b/spec/features/consumer/shopping/checkout_auth_spec.rb
@@ -12,7 +12,10 @@ feature "As a consumer I want to check out my cart", js: true do
describe "using the checkout" do
let(:distributor) { create(:distributor_enterprise, with_payment_and_shipping: true) }
let(:supplier) { create(:supplier_enterprise) }
- let!(:order_cycle) { create(:simple_order_cycle, distributors: [distributor], coordinator: create(:distributor_enterprise), variants: [product.variants.first]) }
+ let!(:order_cycle) {
+ create(:simple_order_cycle, distributors: [distributor],
+ coordinator: create(:distributor_enterprise), variants: [product.variants.first])
+ }
let(:product) { create(:simple_product, supplier: supplier) }
let(:order) { create(:order, order_cycle: order_cycle, distributor: distributor) }
let(:address) { create(:address, firstname: "Foo", lastname: "Bar") }
diff --git a/spec/features/consumer/shopping/checkout_spec.rb b/spec/features/consumer/shopping/checkout_spec.rb
index 581f006abf..895ab58424 100644
--- a/spec/features/consumer/shopping/checkout_spec.rb
+++ b/spec/features/consumer/shopping/checkout_spec.rb
@@ -12,27 +12,47 @@ feature "As a consumer I want to check out my cart", js: true do
let!(:zone) { create(:zone_with_member) }
let(:distributor) { create(:distributor_enterprise, charges_sales_tax: true) }
let(:supplier) { create(:supplier_enterprise) }
- let!(:order_cycle) { create(:simple_order_cycle, suppliers: [supplier], distributors: [distributor], coordinator: create(:distributor_enterprise), variants: [variant]) }
+ let!(:order_cycle) {
+ create(:simple_order_cycle, suppliers: [supplier], distributors: [distributor],
+ coordinator: create(:distributor_enterprise), variants: [variant])
+ }
let(:enterprise_fee) { create(:enterprise_fee, amount: 1.23, tax_category: fee_tax_category) }
let(:fee_tax_rate) { create(:tax_rate, amount: 0.10, zone: zone, included_in_price: true) }
let(:fee_tax_category) { create(:tax_category, tax_rates: [fee_tax_rate]) }
- let(:product) { create(:taxed_product, supplier: supplier, price: 10, zone: zone, tax_rate_amount: 0.1) }
+ let(:product) {
+ create(:taxed_product, supplier: supplier, price: 10, zone: zone, tax_rate_amount: 0.1)
+ }
let(:variant) { product.variants.first }
- let(:order) { create(:order, order_cycle: order_cycle, distributor: distributor, bill_address_id: nil, ship_address_id: nil) }
+ let(:order) {
+ create(:order, order_cycle: order_cycle, distributor: distributor, bill_address_id: nil,
+ ship_address_id: nil)
+ }
let(:shipping_tax_rate) { create(:tax_rate, amount: 0.25, zone: zone, included_in_price: true) }
let(:shipping_tax_category) { create(:tax_category, tax_rates: [shipping_tax_rate]) }
- let(:free_shipping) { create(:shipping_method, require_ship_address: true, name: "Frogs", description: "yellow", calculator: Calculator::FlatRate.new(preferred_amount: 0.00)) }
+ let(:free_shipping) {
+ create(:shipping_method, require_ship_address: true, name: "Frogs", description: "yellow",
+ calculator: Calculator::FlatRate.new(preferred_amount: 0.00))
+ }
let(:shipping_with_fee) {
create(:shipping_method, require_ship_address: false, tax_category: shipping_tax_category,
name: "Donkeys", description: "blue",
calculator: Calculator::FlatRate.new(preferred_amount: 4.56))
}
- let(:tagged_shipping) { create(:shipping_method, require_ship_address: false, name: "Local", tag_list: "local") }
- let!(:check_without_fee) { create(:payment_method, distributors: [distributor], name: "Roger rabbit", type: "Spree::PaymentMethod::Check") }
- let!(:check_with_fee) { create(:payment_method, distributors: [distributor], calculator: Calculator::FlatRate.new(preferred_amount: 5.67)) }
+ let(:tagged_shipping) {
+ create(:shipping_method, require_ship_address: false, name: "Local", tag_list: "local")
+ }
+ let!(:check_without_fee) {
+ create(:payment_method, distributors: [distributor], name: "Roger rabbit",
+ type: "Spree::PaymentMethod::Check")
+ }
+ let!(:check_with_fee) {
+ create(:payment_method, distributors: [distributor],
+ calculator: Calculator::FlatRate.new(preferred_amount: 5.67))
+ }
let!(:paypal) do
- Spree::Gateway::PayPalExpress.create!(name: "Paypal", environment: 'test', distributor_ids: [distributor.id]).tap do |pm|
+ Spree::Gateway::PayPalExpress.create!(name: "Paypal", environment: 'test',
+ distributor_ids: [distributor.id]).tap do |pm|
pm.preferred_login = 'devnull-facilitator_api1.rohanmitchell.com'
pm.preferred_password = '1406163716'
pm.preferred_signature = 'AFcWxV21C7fd0v3bYYYRCpSSRl31AaTntNJ-AjvUJkWf4dgJIvcLsf1V'
@@ -138,7 +158,9 @@ feature "As a consumer I want to check out my cart", js: true do
context "when distributor has T&Cs" do
let(:fake_terms_and_conditions_path) { Rails.root.join("app/assets/images/logo-white.png") }
- let(:terms_and_conditions_file) { Rack::Test::UploadedFile.new(fake_terms_and_conditions_path, "application/pdf") }
+ let(:terms_and_conditions_file) {
+ Rack::Test::UploadedFile.new(fake_terms_and_conditions_path, "application/pdf")
+ }
before do
order.distributor.terms_and_conditions = terms_and_conditions_file
@@ -148,7 +170,8 @@ feature "As a consumer I want to check out my cart", js: true do
describe "when customer has not accepted T&Cs before" do
it "shows a link to the T&Cs and disables checkout button until terms are accepted" do
visit checkout_path
- expect(page).to have_link("Terms and Conditions", href: order.distributor.terms_and_conditions.url)
+ expect(page).to have_link("Terms and Conditions",
+ href: order.distributor.terms_and_conditions.url)
expect(page).to have_button("Place order now", disabled: true)
@@ -232,7 +255,9 @@ feature "As a consumer I want to check out my cart", js: true do
context "when the seller's terms and the platform's terms have to be accepted" do
let(:fake_terms_and_conditions_path) { Rails.root.join("app/assets/images/logo-white.png") }
- let(:terms_and_conditions_file) { Rack::Test::UploadedFile.new(fake_terms_and_conditions_path, "application/pdf") }
+ let(:terms_and_conditions_file) {
+ Rack::Test::UploadedFile.new(fake_terms_and_conditions_path, "application/pdf")
+ }
let(:tos_url) { "https://example.org/tos" }
before do
@@ -247,7 +272,8 @@ feature "As a consumer I want to check out my cart", js: true do
visit checkout_path
within "#checkout_form" do
- expect(page).to have_link("Terms and Conditions", href: order.distributor.terms_and_conditions.url)
+ expect(page).to have_link("Terms and Conditions",
+ href: order.distributor.terms_and_conditions.url)
expect(page).to have_link("Terms of service", href: tos_url)
expect(page).to have_button("Place order now", disabled: true)
end
@@ -262,7 +288,10 @@ feature "As a consumer I want to check out my cart", js: true do
end
context "with previous orders" do
- let!(:prev_order) { create(:completed_order_with_totals, order_cycle: order_cycle, distributor: distributor, user: order.user) }
+ let!(:prev_order) {
+ create(:completed_order_with_totals, order_cycle: order_cycle, distributor: distributor,
+ user: order.user)
+ }
before do
order.distributor.allow_order_changes = true
@@ -471,7 +500,8 @@ feature "As a consumer I want to check out my cart", js: true do
expect(order.shipment_state).to eq "pending"
end
- it "takes us to the cart page with an error when a product becomes out of stock just before we purchase", js: true do
+ it "takes us to the cart page with an error when a product becomes out of stock just before we purchase",
+ js: true do
variant.on_demand = false
variant.on_hand = 0
variant.save!
@@ -525,7 +555,10 @@ feature "As a consumer I want to check out my cart", js: true do
describe "credit card payments" do
["Spree::Gateway::Bogus", "Spree::Gateway::BogusSimple"].each do |gateway_type|
context "with a credit card payment method using #{gateway_type}" do
- let!(:check_without_fee) { create(:payment_method, distributors: [distributor], name: "Roger rabbit", type: gateway_type) }
+ let!(:check_without_fee) {
+ create(:payment_method, distributors: [distributor], name: "Roger rabbit",
+ type: gateway_type)
+ }
it "takes us to the order confirmation page when submitted with a valid credit card" do
fill_in 'Card Number', with: "4111111111111111"
diff --git a/spec/features/consumer/shopping/checkout_stripe_spec.rb b/spec/features/consumer/shopping/checkout_stripe_spec.rb
index 0ff0cfe412..c81c44d577 100644
--- a/spec/features/consumer/shopping/checkout_stripe_spec.rb
+++ b/spec/features/consumer/shopping/checkout_stripe_spec.rb
@@ -10,14 +10,25 @@ feature "Check out with Stripe", js: true do
include StripeStubs
let(:distributor) { create(:distributor_enterprise) }
- let!(:order_cycle) { create(:simple_order_cycle, distributors: [distributor], variants: [variant]) }
+ let!(:order_cycle) {
+ create(:simple_order_cycle, distributors: [distributor], variants: [variant])
+ }
let(:product) { create(:product, price: 10) }
let(:variant) { product.variants.first }
- let(:order) { create(:order, order_cycle: order_cycle, distributor: distributor, bill_address_id: nil, ship_address_id: nil) }
+ let(:order) {
+ create(:order, order_cycle: order_cycle, distributor: distributor, bill_address_id: nil,
+ ship_address_id: nil)
+ }
- let(:shipping_with_fee) { create(:shipping_method, require_ship_address: false, name: "Donkeys", calculator: Calculator::FlatRate.new(preferred_amount: 4.56)) }
+ let(:shipping_with_fee) {
+ create(:shipping_method, require_ship_address: false, name: "Donkeys",
+ calculator: Calculator::FlatRate.new(preferred_amount: 4.56))
+ }
let(:free_shipping) { create(:shipping_method) }
- let!(:check_with_fee) { create(:payment_method, distributors: [distributor], calculator: Calculator::FlatRate.new(preferred_amount: 5.67)) }
+ let!(:check_with_fee) {
+ create(:payment_method, distributors: [distributor],
+ calculator: Calculator::FlatRate.new(preferred_amount: 5.67))
+ }
before do
setup_stripe
@@ -49,7 +60,9 @@ feature "Check out with Stripe", js: true do
gateway_customer_profile_id: "i_am_saved")
end
- let!(:stripe_account) { create(:stripe_account, enterprise_id: distributor.id, stripe_user_id: 'some_id') }
+ let!(:stripe_account) {
+ create(:stripe_account, enterprise_id: distributor.id, stripe_user_id: 'some_id')
+ }
let(:response_mock) { { id: "ch_1234", object: "charge", amount: 2000 } }
@@ -215,7 +228,8 @@ feature "Check out with Stripe", js: true do
stub_list_customers_request(email: order.user.email, response: {})
stub_get_customer_payment_methods_request(customer: "cus_A456", response: {})
stub_get_customer_payment_methods_request(customer: "cus_A123", response: {})
- stub_payment_methods_post_request request: { payment_method: "pm_123", customer: "cus_A123" }, response: { pm_id: "pm_123" }
+ stub_payment_methods_post_request request: { payment_method: "pm_123", customer: "cus_A123" },
+ response: { pm_id: "pm_123" }
stub_add_metadata_request(payment_method: "pm_123", response: {})
stub_payment_intents_post_request order: order
stub_successful_capture_request order: order
@@ -237,7 +251,8 @@ feature "Check out with Stripe", js: true do
expect(user_credit_card.gateway_customer_profile_id).to eq "cus_A123"
# Prepare a second order
- new_order = create(:order, user: user, order_cycle: order_cycle, distributor: distributor, bill_address_id: nil, ship_address_id: nil)
+ new_order = create(:order, user: user, order_cycle: order_cycle,
+ distributor: distributor, bill_address_id: nil, ship_address_id: nil)
set_order(new_order)
add_product_to_cart(new_order, product, quantity: 10)
stub_payment_intents_post_request order: new_order
diff --git a/spec/features/consumer/shopping/embedded_shopfronts_spec.rb b/spec/features/consumer/shopping/embedded_shopfronts_spec.rb
index cd6ba81484..759c325134 100644
--- a/spec/features/consumer/shopping/embedded_shopfronts_spec.rb
+++ b/spec/features/consumer/shopping/embedded_shopfronts_spec.rb
@@ -11,9 +11,15 @@ feature "Using embedded shopfront functionality", js: true do
include UIComponentHelper
describe "using iframes" do
- let(:distributor) { create(:distributor_enterprise, name: 'My Embedded Hub', permalink: 'test_enterprise', with_payment_and_shipping: true) }
+ let(:distributor) {
+ create(:distributor_enterprise, name: 'My Embedded Hub', permalink: 'test_enterprise',
+ with_payment_and_shipping: true)
+ }
let(:supplier) { create(:supplier_enterprise) }
- let(:oc1) { create(:simple_order_cycle, distributors: [distributor], coordinator: create(:distributor_enterprise), orders_close_at: 2.days.from_now) }
+ let(:oc1) {
+ create(:simple_order_cycle, distributors: [distributor],
+ coordinator: create(:distributor_enterprise), orders_close_at: 2.days.from_now)
+ }
let(:product) { create(:simple_product, name: 'Framed Apples', supplier: supplier) }
let(:variant) { create(:variant, product: product, price: 19.99) }
let(:exchange) { Exchange.find(oc1.exchanges.to_enterprises(distributor).outgoing.first.id) }
diff --git a/spec/features/consumer/shopping/orders_spec.rb b/spec/features/consumer/shopping/orders_spec.rb
index 0050e66fcf..9fc945410d 100644
--- a/spec/features/consumer/shopping/orders_spec.rb
+++ b/spec/features/consumer/shopping/orders_spec.rb
@@ -89,7 +89,9 @@ feature "Order Management", js: true do
describe "editing a completed order" do
let(:address) { create(:address) }
let(:user) { create(:user, bill_address: address, ship_address: address) }
- let(:distributor) { create(:distributor_enterprise, with_payment_and_shipping: true, charges_sales_tax: true) }
+ let(:distributor) {
+ create(:distributor_enterprise, with_payment_and_shipping: true, charges_sales_tax: true)
+ }
let(:order_cycle) { create(:order_cycle) }
let(:shipping_method) { distributor.shipping_methods.first }
let(:order) do
diff --git a/spec/features/consumer/shopping/products_spec.rb b/spec/features/consumer/shopping/products_spec.rb
index 0d7eb3f9b1..1affe14668 100644
--- a/spec/features/consumer/shopping/products_spec.rb
+++ b/spec/features/consumer/shopping/products_spec.rb
@@ -11,7 +11,10 @@ feature "As a consumer I want to view products", js: true do
describe "Viewing a product" do
let(:distributor) { create(:distributor_enterprise, with_payment_and_shipping: true) }
let(:supplier) { create(:supplier_enterprise) }
- let(:oc1) { create(:simple_order_cycle, distributors: [distributor], coordinator: create(:distributor_enterprise), orders_close_at: 2.days.from_now) }
+ let(:oc1) {
+ create(:simple_order_cycle, distributors: [distributor],
+ coordinator: create(:distributor_enterprise), orders_close_at: 2.days.from_now)
+ }
let(:product) { create(:simple_product, supplier: supplier) }
let(:variant) { product.variants.first }
let(:order) { create(:order, distributor: distributor) }
diff --git a/spec/features/consumer/shopping/shopping_spec.rb b/spec/features/consumer/shopping/shopping_spec.rb
index 590afc8202..98467b6ab3 100644
--- a/spec/features/consumer/shopping/shopping_spec.rb
+++ b/spec/features/consumer/shopping/shopping_spec.rb
@@ -11,8 +11,14 @@ feature "As a consumer I want to shop with a distributor", js: true do
describe "Viewing a distributor" do
let(:distributor) { create(:distributor_enterprise, with_payment_and_shipping: true) }
let(:supplier) { create(:supplier_enterprise) }
- let(:oc1) { create(:simple_order_cycle, distributors: [distributor], coordinator: create(:distributor_enterprise), orders_close_at: 2.days.from_now) }
- let(:oc2) { create(:simple_order_cycle, distributors: [distributor], coordinator: create(:distributor_enterprise), orders_close_at: 3.days.from_now) }
+ let(:oc1) {
+ create(:simple_order_cycle, distributors: [distributor],
+ coordinator: create(:distributor_enterprise), orders_close_at: 2.days.from_now)
+ }
+ let(:oc2) {
+ create(:simple_order_cycle, distributors: [distributor],
+ coordinator: create(:distributor_enterprise), orders_close_at: 3.days.from_now)
+ }
let(:product) { create(:simple_product, supplier: supplier, meta_keywords: "Domestic") }
let(:variant) { product.variants.first }
let(:order) { create(:order, distributor: distributor) }
@@ -196,7 +202,9 @@ feature "As a consumer I want to shop with a distributor", js: true do
describe "after selecting an order cycle with products visible" do
let(:variant1) { create(:variant, product: product, price: 20) }
let(:variant2) { create(:variant, product: product, price: 30, display_name: "Badgers") }
- let(:product2) { create(:simple_product, supplier: supplier, name: "Meercats", meta_keywords: "Wild") }
+ let(:product2) {
+ create(:simple_product, supplier: supplier, name: "Meercats", meta_keywords: "Wild")
+ }
let(:variant3) { create(:variant, product: product2, price: 40, display_name: "Ferrets") }
let(:exchange) { Exchange.find(oc1.exchanges.to_enterprises(distributor).outgoing.first.id) }
@@ -509,13 +517,15 @@ feature "As a consumer I want to shop with a distributor", js: true do
end
it "shows the last order cycle" do
- oc1 = create(:simple_order_cycle, distributors: [distributor], orders_open_at: 17.days.ago, orders_close_at: 10.days.ago)
+ oc1 = create(:simple_order_cycle, distributors: [distributor], orders_open_at: 17.days.ago,
+ orders_close_at: 10.days.ago)
visit shop_path
expect(page).to have_content "The last cycle closed 10 days ago"
end
it "shows the next order cycle" do
- oc1 = create(:simple_order_cycle, distributors: [distributor], orders_open_at: 10.days.from_now, orders_close_at: 17.days.from_now)
+ oc1 = create(:simple_order_cycle, distributors: [distributor],
+ orders_open_at: 10.days.from_now, orders_close_at: 17.days.from_now)
visit shop_path
expect(page).to have_content "The next cycle opens in 10 days"
end
diff --git a/spec/features/consumer/shopping/unit_price_spec.rb b/spec/features/consumer/shopping/unit_price_spec.rb
index 05b94a7af9..0bf9c18343 100644
--- a/spec/features/consumer/shopping/unit_price_spec.rb
+++ b/spec/features/consumer/shopping/unit_price_spec.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
require 'spec_helper'
feature "As a consumer, I want to check unit price information for a product", js: true do
@@ -8,7 +10,10 @@ feature "As a consumer, I want to check unit price information for a product", j
let(:distributor) { create(:distributor_enterprise, with_payment_and_shipping: true) }
let(:supplier) { create(:supplier_enterprise) }
- let(:oc1) { create(:simple_order_cycle, distributors: [distributor], coordinator: create(:distributor_enterprise), orders_close_at: 2.days.from_now) }
+ let(:oc1) {
+ create(:simple_order_cycle, distributors: [distributor],
+ coordinator: create(:distributor_enterprise), orders_close_at: 2.days.from_now)
+ }
let(:product) { create(:simple_product, supplier: supplier) }
let(:variant) { product.variants.first }
let(:order) { create(:order, distributor: distributor) }
@@ -28,12 +33,12 @@ feature "As a consumer, I want to check unit price information for a product", j
it "one click on the question mark icon should open the tooltip, another click should close it" do
expect(page).to have_selector '.variant-unit-price'
- within '.variant-unit-price' do
+ within '.variant-unit-price' do
expect(page).to have_selector '.question-mark-icon'
end
find('.question-mark-icon').click
expect(page).to have_selector '.joyride-tip-guide.question-mark-tooltip'
- within '.joyride-tip-guide.question-mark-tooltip' do
+ within '.joyride-tip-guide.question-mark-tooltip' do
expect(page).to have_content I18n.t('js.shopfront.unit_price_tooltip')
end
@@ -49,12 +54,12 @@ feature "As a consumer, I want to check unit price information for a product", j
click_button "Add"
toggle_cart
end
-
+
it "shows/hide the unit price information with the question mark icon in the sidebar" do
expect(page).to have_selector ".cart-content .question-mark-icon"
find(".cart-content .question-mark-icon").click
expect(page).to have_selector '.joyride-tip-guide.question-mark-tooltip'
- within '.joyride-tip-guide.question-mark-tooltip' do
+ within '.joyride-tip-guide.question-mark-tooltip' do
expect(page).to have_content I18n.t('js.shopfront.unit_price_tooltip')
end
page.find("body").click
diff --git a/spec/features/consumer/shopping/variant_overrides_spec.rb b/spec/features/consumer/shopping/variant_overrides_spec.rb
index ce093f1c64..1feea3de5c 100644
--- a/spec/features/consumer/shopping/variant_overrides_spec.rb
+++ b/spec/features/consumer/shopping/variant_overrides_spec.rb
@@ -11,7 +11,9 @@ feature "shopping with variant overrides defined", js: true do
let(:hub) { create(:distributor_enterprise, with_payment_and_shipping: true) }
let(:producer) { create(:supplier_enterprise) }
- let(:oc) { create(:simple_order_cycle, suppliers: [producer], coordinator: hub, distributors: [hub]) }
+ let(:oc) {
+ create(:simple_order_cycle, suppliers: [producer], coordinator: hub, distributors: [hub])
+ }
let(:outgoing_exchange) { oc.exchanges.outgoing.first }
let(:sm) { hub.shipping_methods.first }
let(:pm) { hub.payment_methods.first }
@@ -23,20 +25,49 @@ feature "shopping with variant overrides defined", js: true do
let(:product1_variant2) { create(:variant, product: product1, price: 22.22, unit_value: 2) }
let(:product2_variant1) { create(:variant, product: product2, price: 33.33, unit_value: 3) }
let(:product1_variant3) { create(:variant, product: product1, price: 44.44, unit_value: 4) }
- let(:product3_variant1) { create(:variant, product: product3, price: 55.55, unit_value: 5, on_demand: true) }
- let(:product3_variant2) { create(:variant, product: product3, price: 66.66, unit_value: 6, on_demand: true) }
+ let(:product3_variant1) {
+ create(:variant, product: product3, price: 55.55, unit_value: 5, on_demand: true)
+ }
+ let(:product3_variant2) {
+ create(:variant, product: product3, price: 66.66, unit_value: 6, on_demand: true)
+ }
let(:product4_variant1) { create(:variant, product: product4, price: 77.77, unit_value: 7) }
- let!(:product1_variant1_override) { create(:variant_override, :use_producer_stock_settings, hub: hub, variant: product1_variant1, price: 55.55, count_on_hand: nil, default_stock: nil, resettable: false) }
- let!(:product1_variant2_override) { create(:variant_override, hub: hub, variant: product1_variant2, count_on_hand: 0, default_stock: nil, resettable: false) }
- let!(:product2_variant1_override) { create(:variant_override, hub: hub, variant: product2_variant1, count_on_hand: 0, default_stock: nil, resettable: false) }
- let!(:product1_variant3_override) { create(:variant_override, hub: hub, variant: product1_variant3, count_on_hand: 3, default_stock: nil, resettable: false) }
- let!(:product3_variant1_override) { create(:variant_override, hub: hub, variant: product3_variant1, count_on_hand: 0, default_stock: nil, resettable: false) }
- let!(:product3_variant2_override) { create(:variant_override, hub: hub, variant: product3_variant2, count_on_hand: 6, default_stock: nil, resettable: false) }
- let(:enterprise_fee) { create(:enterprise_fee, enterprise: hub, fee_type: 'packing', calculator: Calculator::FlatPercentPerItem.new(preferred_flat_percent: 10)) }
- let!(:product4_variant1_override) { create(:variant_override, hub: hub, variant: product4_variant1, count_on_hand: nil, on_demand: true, default_stock: nil, resettable: false) }
+ let!(:product1_variant1_override) {
+ create(:variant_override, :use_producer_stock_settings, hub: hub, variant: product1_variant1,
+ price: 55.55, count_on_hand: nil, default_stock: nil, resettable: false)
+ }
+ let!(:product1_variant2_override) {
+ create(:variant_override, hub: hub, variant: product1_variant2, count_on_hand: 0,
+ default_stock: nil, resettable: false)
+ }
+ let!(:product2_variant1_override) {
+ create(:variant_override, hub: hub, variant: product2_variant1, count_on_hand: 0,
+ default_stock: nil, resettable: false)
+ }
+ let!(:product1_variant3_override) {
+ create(:variant_override, hub: hub, variant: product1_variant3, count_on_hand: 3,
+ default_stock: nil, resettable: false)
+ }
+ let!(:product3_variant1_override) {
+ create(:variant_override, hub: hub, variant: product3_variant1, count_on_hand: 0,
+ default_stock: nil, resettable: false)
+ }
+ let!(:product3_variant2_override) {
+ create(:variant_override, hub: hub, variant: product3_variant2, count_on_hand: 6,
+ default_stock: nil, resettable: false)
+ }
+ let(:enterprise_fee) {
+ create(:enterprise_fee, enterprise: hub, fee_type: 'packing',
+ calculator: Calculator::FlatPercentPerItem.new(preferred_flat_percent: 10))
+ }
+ let!(:product4_variant1_override) {
+ create(:variant_override, hub: hub, variant: product4_variant1, count_on_hand: nil,
+ on_demand: true, default_stock: nil, resettable: false)
+ }
before do
- outgoing_exchange.variants = [product1_variant1, product1_variant2, product2_variant1, product1_variant3, product3_variant1, product3_variant2, product4_variant1]
+ outgoing_exchange.variants = [product1_variant1, product1_variant2, product2_variant1,
+ product1_variant3, product3_variant1, product3_variant2, product4_variant1]
outgoing_exchange.enterprise_fees << enterprise_fee
sm.calculator.preferred_amount = 0
visit enterprise_shop_path(hub)
@@ -78,16 +109,19 @@ feature "shopping with variant overrides defined", js: true do
click_add_to_cart product1_variant1, 2
toggle_cart
expect(page).to have_selector "#cart-variant-#{product1_variant1.id} .quantity", text: '2'
- expect(page).to have_selector "#cart-variant-#{product1_variant1.id} .total-price", text: with_currency(122.22)
+ expect(page).to have_selector "#cart-variant-#{product1_variant1.id} .total-price",
+ text: with_currency(122.22)
end
it "shows the correct prices in the shopping cart" do
click_add_to_cart product1_variant1, 2
edit_cart
- expect(page).to have_selector "tr.line-item.variant-#{product1_variant1.id} .cart-item-price", text: with_currency(61.11)
+ expect(page).to have_selector "tr.line-item.variant-#{product1_variant1.id} .cart-item-price",
+ text: with_currency(61.11)
expect(page).to have_field "order[line_items_attributes][0][quantity]", with: '2'
- expect(page).to have_selector "tr.line-item.variant-#{product1_variant1.id} .cart-item-total", text: with_currency(122.22)
+ expect(page).to have_selector "tr.line-item.variant-#{product1_variant1.id} .cart-item-total",
+ text: with_currency(122.22)
expect(page).to have_selector "#edit-cart .item-total", text: with_currency(122.22)
expect(page).to have_selector "#edit-cart .grand-total", text: with_currency(122.22)
diff --git a/spec/features/consumer/shops_spec.rb b/spec/features/consumer/shops_spec.rb
index fbe27069f1..ca1f9faf03 100644
--- a/spec/features/consumer/shops_spec.rb
+++ b/spec/features/consumer/shops_spec.rb
@@ -12,7 +12,10 @@ feature 'Shops', js: true do
let!(:profile) { create(:distributor_enterprise, sells: 'none') }
let!(:d1) { create(:distributor_enterprise, with_payment_and_shipping: true) }
let!(:d2) { create(:distributor_enterprise, with_payment_and_shipping: true) }
- let!(:order_cycle) { create(:simple_order_cycle, distributors: [distributor], coordinator: create(:distributor_enterprise)) }
+ let!(:order_cycle) {
+ create(:simple_order_cycle, distributors: [distributor],
+ coordinator: create(:distributor_enterprise))
+ }
let!(:producer) { create(:supplier_enterprise) }
let!(:er) { create(:enterprise_relationship, parent: distributor, child: producer) }
@@ -75,7 +78,10 @@ feature 'Shops', js: true do
end
describe "filtering by product property" do
- let!(:order_cycle) { create(:simple_order_cycle, distributors: [d1, d2], coordinator: create(:distributor_enterprise)) }
+ let!(:order_cycle) {
+ create(:simple_order_cycle, distributors: [d1, d2],
+ coordinator: create(:distributor_enterprise))
+ }
let!(:p1) { create(:simple_product, supplier: producer) }
let!(:p2) { create(:simple_product, supplier: create(:supplier_enterprise)) }
let(:ex_d1) { order_cycle.exchanges.outgoing.where(receiver_id: d1).first }
@@ -107,13 +113,17 @@ feature 'Shops', js: true do
end
describe "taxon badges" do
- let!(:closed_oc) { create(:closed_order_cycle, distributors: [shop], variants: [p_closed.variants.first]) }
+ let!(:closed_oc) {
+ create(:closed_order_cycle, distributors: [shop], variants: [p_closed.variants.first])
+ }
let!(:p_closed) { create(:simple_product, primary_taxon: taxon_closed, taxons: [taxon_closed]) }
let(:shop) { create(:distributor_enterprise, with_payment_and_shipping: true) }
let(:taxon_closed) { create(:taxon, name: 'Closed') }
describe "open shops" do
- let!(:open_oc) { create(:open_order_cycle, distributors: [shop], variants: [p_open.variants.first]) }
+ let!(:open_oc) {
+ create(:open_order_cycle, distributors: [shop], variants: [p_open.variants.first])
+ }
let!(:p_open) { create(:simple_product, primary_taxon: taxon_open, taxons: [taxon_open]) }
let(:taxon_open) { create(:taxon, name: 'Open') }
@@ -136,7 +146,10 @@ feature 'Shops', js: true do
end
describe "property badges" do
- let!(:order_cycle) { create(:simple_order_cycle, distributors: [distributor], coordinator: create(:distributor_enterprise), variants: [product.variants.first]) }
+ let!(:order_cycle) {
+ create(:simple_order_cycle, distributors: [distributor],
+ coordinator: create(:distributor_enterprise), variants: [product.variants.first])
+ }
let(:product) { create(:simple_product, supplier: producer) }
before do
@@ -162,7 +175,10 @@ feature 'Shops', js: true do
describe "hub producer modal" do
let!(:product) { create(:simple_product, supplier: producer, taxons: [taxon]) }
let!(:taxon) { create(:taxon, name: 'Fruit') }
- let!(:order_cycle) { create(:simple_order_cycle, distributors: [distributor], coordinator: create(:distributor_enterprise), variants: [product.variants.first]) }
+ let!(:order_cycle) {
+ create(:simple_order_cycle, distributors: [distributor],
+ coordinator: create(:distributor_enterprise), variants: [product.variants.first])
+ }
it "shows hub producer modals" do
visit shops_path
diff --git a/spec/helpers/admin/subscriptions_helper_spec.rb b/spec/helpers/admin/subscriptions_helper_spec.rb
index 00b4c973e9..dec9c2d6af 100644
--- a/spec/helpers/admin/subscriptions_helper_spec.rb
+++ b/spec/helpers/admin/subscriptions_helper_spec.rb
@@ -8,7 +8,9 @@ describe Admin::SubscriptionsHelper, type: :helper do
let(:customer) { create(:customer, enterprise: shop) }
let(:shipping_method) { create(:shipping_method, distributors: [shop]) }
let(:payment_method) { create(:payment_method, distributors: [shop]) }
- let(:schedule) { create(:schedule, order_cycles: [create(:simple_order_cycle, coordinator: shop)] ) }
+ let(:schedule) {
+ create(:schedule, order_cycles: [create(:simple_order_cycle, coordinator: shop)] )
+ }
context "when a shop has no shipping methods present" do
before { customer; payment_method; schedule }
@@ -16,7 +18,9 @@ describe Admin::SubscriptionsHelper, type: :helper do
end
context "when a shop has no Cash or Stripe payment methods present" do
- let!(:paypal) { Spree::Gateway::PayPalExpress.create!(name: "PayPalExpress", distributor_ids: [shop.id]) }
+ let!(:paypal) {
+ Spree::Gateway::PayPalExpress.create!(name: "PayPalExpress", distributor_ids: [shop.id])
+ }
before { customer; shipping_method; schedule }
it { expect(helper.subscriptions_setup_complete?([shop])).to be false }
end
diff --git a/spec/helpers/checkout_helper_spec.rb b/spec/helpers/checkout_helper_spec.rb
index 2ebd0f7c48..7239b72911 100644
--- a/spec/helpers/checkout_helper_spec.rb
+++ b/spec/helpers/checkout_helper_spec.rb
@@ -8,7 +8,8 @@ describe CheckoutHelper, type: :helper do
"shared/validated_input",
name: "test",
path: "foo",
- attributes: { :required => true, :type => :email, :name => "foo", :id => "foo", "ng-model" => "foo", "ng-class" => "{error: !fieldValid('foo')}" }
+ attributes: { :required => true, :type => :email, :name => "foo", :id => "foo",
+ "ng-model" => "foo", "ng-class" => "{error: !fieldValid('foo')}" }
)
helper.validated_input("test", "foo", type: :email)
@@ -18,7 +19,8 @@ describe CheckoutHelper, type: :helper do
let(:order) { double(:order, total_tax: 123.45, currency: 'AUD') }
it "retrieves the total tax on the order" do
- expect(helper.display_checkout_tax_total(order)).to eq(Spree::Money.new(123.45, currency: 'AUD'))
+ expect(helper.display_checkout_tax_total(order)).to eq(Spree::Money.new(123.45,
+ currency: 'AUD'))
end
end
diff --git a/spec/helpers/enterprises_helper_spec.rb b/spec/helpers/enterprises_helper_spec.rb
index b8e6fb19b6..5959392667 100644
--- a/spec/helpers/enterprises_helper_spec.rb
+++ b/spec/helpers/enterprises_helper_spec.rb
@@ -10,8 +10,12 @@ describe EnterprisesHelper, type: :helper do
before { allow(helper).to receive(:spree_current_user) { user } }
describe "loading available shipping methods" do
- let!(:distributor_shipping_method) { create(:shipping_method, require_ship_address: false, distributors: [distributor]) }
- let!(:other_distributor_shipping_method) { create(:shipping_method, require_ship_address: false, distributors: [some_other_distributor]) }
+ let!(:distributor_shipping_method) {
+ create(:shipping_method, require_ship_address: false, distributors: [distributor])
+ }
+ let!(:other_distributor_shipping_method) {
+ create(:shipping_method, require_ship_address: false, distributors: [some_other_distributor])
+ }
context "when the order has no current_distributor" do
before do
@@ -32,7 +36,8 @@ describe EnterprisesHelper, type: :helper do
end
it "does not return 'back office only' shipping method" do
- backoffice_only_shipping_method = create(:shipping_method, require_ship_address: false, distributors: [distributor], display_on: 'back_end')
+ backoffice_only_shipping_method = create(:shipping_method, require_ship_address: false,
+ distributors: [distributor], display_on: 'back_end')
expect(helper.available_shipping_methods).to_not include backoffice_only_shipping_method
expect(helper.available_shipping_methods).to_not include other_distributor_shipping_method
@@ -64,8 +69,13 @@ describe EnterprisesHelper, type: :helper do
end
context "with a preferred visiblity of 'visible', default visibility of 'hidden'" do
- before { tag_rule.update_attribute(:preferred_matched_shipping_methods_visibility, 'visible') }
- before { default_tag_rule.update_attribute(:preferred_matched_shipping_methods_visibility, 'hidden') }
+ before {
+ tag_rule.update_attribute(:preferred_matched_shipping_methods_visibility, 'visible')
+ }
+ before {
+ default_tag_rule.update_attribute(:preferred_matched_shipping_methods_visibility,
+ 'hidden')
+ }
context "when the customer is nil" do
it "applies default action (hide)" do
@@ -96,8 +106,13 @@ describe EnterprisesHelper, type: :helper do
end
context "with a preferred visiblity of 'hidden', default visibility of 'visible'" do
- before { tag_rule.update_attribute(:preferred_matched_shipping_methods_visibility, 'hidden') }
- before { default_tag_rule.update_attribute(:preferred_matched_shipping_methods_visibility, 'visible') }
+ before {
+ tag_rule.update_attribute(:preferred_matched_shipping_methods_visibility, 'hidden')
+ }
+ before {
+ default_tag_rule.update_attribute(:preferred_matched_shipping_methods_visibility,
+ 'visible')
+ }
context "when the customer is nil" do
it "applies default action (show)" do
@@ -175,8 +190,12 @@ describe EnterprisesHelper, type: :helper do
end
context "with a preferred visiblity of 'visible', default visibility of 'hidden'" do
- before { tag_rule.update_attribute(:preferred_matched_payment_methods_visibility, 'visible') }
- before { default_tag_rule.update_attribute(:preferred_matched_payment_methods_visibility, 'hidden') }
+ before {
+ tag_rule.update_attribute(:preferred_matched_payment_methods_visibility, 'visible')
+ }
+ before {
+ default_tag_rule.update_attribute(:preferred_matched_payment_methods_visibility, 'hidden')
+ }
context "when the customer is nil" do
it "applies default action (hide)" do
@@ -207,8 +226,13 @@ describe EnterprisesHelper, type: :helper do
end
context "with a preferred visiblity of 'hidden', default visibility of 'visible'" do
- before { tag_rule.update_attribute(:preferred_matched_payment_methods_visibility, 'hidden') }
- before { default_tag_rule.update_attribute(:preferred_matched_payment_methods_visibility, 'visible') }
+ before {
+ tag_rule.update_attribute(:preferred_matched_payment_methods_visibility, 'hidden')
+ }
+ before {
+ default_tag_rule.update_attribute(:preferred_matched_payment_methods_visibility,
+ 'visible')
+ }
context "when the customer is nil" do
it "applies default action (show)" do
@@ -239,8 +263,14 @@ describe EnterprisesHelper, type: :helper do
end
context "when StripeConnect payment methods are present" do
- let!(:pm3) { create(:stripe_connect_payment_method, distributors: [distributor], preferred_enterprise_id: distributor.id) }
- let!(:pm4) { create(:stripe_connect_payment_method, distributors: [distributor], preferred_enterprise_id: some_other_distributor.id) }
+ let!(:pm3) {
+ create(:stripe_connect_payment_method, distributors: [distributor],
+ preferred_enterprise_id: distributor.id)
+ }
+ let!(:pm4) {
+ create(:stripe_connect_payment_method, distributors: [distributor],
+ preferred_enterprise_id: some_other_distributor.id)
+ }
let(:available_payment_methods) { helper.available_payment_methods }
around do |example|
diff --git a/spec/helpers/injection_helper_spec.rb b/spec/helpers/injection_helper_spec.rb
index ecc7b100eb..c4abbdbf17 100644
--- a/spec/helpers/injection_helper_spec.rb
+++ b/spec/helpers/injection_helper_spec.rb
@@ -8,12 +8,17 @@ describe InjectionHelper, type: :helper do
let!(:distributor1) { create(:distributor_enterprise) }
let!(:distributor2) { create(:distributor_enterprise) }
let!(:user) { create(:user) }
- let!(:d1o1) { create(:completed_order_with_totals, distributor: distributor1, user_id: user.id, total: 10_000) }
- let!(:d1o2) { create(:completed_order_with_totals, distributor: distributor1, user_id: user.id, total: 5000) }
+ let!(:d1o1) {
+ create(:completed_order_with_totals, distributor: distributor1, user_id: user.id, total: 10_000)
+ }
+ let!(:d1o2) {
+ create(:completed_order_with_totals, distributor: distributor1, user_id: user.id, total: 5000)
+ }
let!(:d2o1) { create(:completed_order_with_totals, distributor: distributor2, user_id: user.id) }
it "will inject via AMS" do
- expect(helper.inject_json_array("test", [enterprise], Api::IdSerializer)).to match /#{enterprise.id}/
+ expect(helper.inject_json_array("test", [enterprise],
+ Api::IdSerializer)).to match /#{enterprise.id}/
end
it "injects enterprises" do
@@ -70,8 +75,10 @@ describe InjectionHelper, type: :helper do
it "only injects credit cards with a payment profile" do
allow(helper).to receive(:spree_current_user) { user }
- card1 = create(:credit_card, last_digits: "1234", user_id: user.id, gateway_customer_profile_id: 'cust_123')
- card2 = create(:credit_card, last_digits: "4321", user_id: user.id, gateway_customer_profile_id: nil)
+ card1 = create(:credit_card, last_digits: "1234", user_id: user.id,
+ gateway_customer_profile_id: 'cust_123')
+ card2 = create(:credit_card, last_digits: "4321", user_id: user.id,
+ gateway_customer_profile_id: nil)
injected_cards = helper.inject_saved_credit_cards
expect(injected_cards).to match "1234"
expect(injected_cards).to_not match "4321"
diff --git a/spec/helpers/order_cycles_helper_spec.rb b/spec/helpers/order_cycles_helper_spec.rb
index c9687452c7..a5fa043c12 100644
--- a/spec/helpers/order_cycles_helper_spec.rb
+++ b/spec/helpers/order_cycles_helper_spec.rb
@@ -33,7 +33,8 @@ describe OrderCyclesHelper, type: :helper do
end
it "asks for a validation option list" do
- expect(helper).to receive(:validated_enterprise_options).with("enterprise list", shipping_and_payment_methods: true)
+ expect(helper).to receive(:validated_enterprise_options).with("enterprise list",
+ shipping_and_payment_methods: true)
helper.permitted_hub_enterprise_options_for(oc)
end
end
diff --git a/spec/helpers/spree/admin/base_helper_spec.rb b/spec/helpers/spree/admin/base_helper_spec.rb
index 867871bca1..4a862dd831 100644
--- a/spec/helpers/spree/admin/base_helper_spec.rb
+++ b/spec/helpers/spree/admin/base_helper_spec.rb
@@ -7,7 +7,9 @@ describe Spree::Admin::BaseHelper, type: :helper do
describe "#link_to_remove_fields" do
let(:name) { 'Hola' }
- let(:form) { double('form_for', hidden_field: '') }
+ let(:form) {
+ double('form_for', hidden_field: '')
+ }
let(:options) { {} }
subject { helper.link_to_remove_fields(name, form, options) }
diff --git a/spec/helpers/terms_and_conditions_helper_spec.rb b/spec/helpers/terms_and_conditions_helper_spec.rb
index 3878891b28..4121725d2a 100644
--- a/spec/helpers/terms_and_conditions_helper_spec.rb
+++ b/spec/helpers/terms_and_conditions_helper_spec.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
require 'spec_helper'
describe TermsAndConditionsHelper, type: :helper do
diff --git a/spec/jobs/subscription_confirm_job_spec.rb b/spec/jobs/subscription_confirm_job_spec.rb
index d25a7560cc..8c2ac1a2cb 100644
--- a/spec/jobs/subscription_confirm_job_spec.rb
+++ b/spec/jobs/subscription_confirm_job_spec.rb
@@ -9,8 +9,14 @@ describe SubscriptionConfirmJob do
describe "finding proxy_orders that are ready to be confirmed" do
let(:shop) { create(:distributor_enterprise) }
- let(:order_cycle1) { create(:simple_order_cycle, coordinator: shop, orders_close_at: 59.minutes.ago, updated_at: 1.day.ago) }
- let(:order_cycle2) { create(:simple_order_cycle, coordinator: shop, orders_close_at: 61.minutes.ago, updated_at: 1.day.ago) }
+ let(:order_cycle1) {
+ create(:simple_order_cycle, coordinator: shop, orders_close_at: 59.minutes.ago,
+ updated_at: 1.day.ago)
+ }
+ let(:order_cycle2) {
+ create(:simple_order_cycle, coordinator: shop, orders_close_at: 61.minutes.ago,
+ updated_at: 1.day.ago)
+ }
let(:schedule) { create(:schedule, order_cycles: [order_cycle1, order_cycle2]) }
let(:subscription) { create(:subscription, with_items: true, shop: shop, schedule: schedule) }
let!(:proxy_order) do
@@ -105,10 +111,18 @@ describe SubscriptionConfirmJob do
end
describe "finding recently closed order cycles" do
- let!(:order_cycle1) { create(:simple_order_cycle, orders_close_at: 61.minutes.ago, updated_at: 61.minutes.ago) }
- let!(:order_cycle2) { create(:simple_order_cycle, orders_close_at: nil, updated_at: 59.minutes.ago) }
- let!(:order_cycle3) { create(:simple_order_cycle, orders_close_at: 61.minutes.ago, updated_at: 59.minutes.ago) }
- let!(:order_cycle4) { create(:simple_order_cycle, orders_close_at: 59.minutes.ago, updated_at: 61.minutes.ago) }
+ let!(:order_cycle1) {
+ create(:simple_order_cycle, orders_close_at: 61.minutes.ago, updated_at: 61.minutes.ago)
+ }
+ let!(:order_cycle2) {
+ create(:simple_order_cycle, orders_close_at: nil, updated_at: 59.minutes.ago)
+ }
+ let!(:order_cycle3) {
+ create(:simple_order_cycle, orders_close_at: 61.minutes.ago, updated_at: 59.minutes.ago)
+ }
+ let!(:order_cycle4) {
+ create(:simple_order_cycle, orders_close_at: 59.minutes.ago, updated_at: 61.minutes.ago)
+ }
let!(:order_cycle5) { create(:simple_order_cycle, orders_close_at: 1.minute.from_now) }
it "returns closed order cycles whose orders_close_at or updated_at date is within the last hour" do
@@ -150,11 +164,15 @@ describe SubscriptionConfirmJob do
context "Stripe SCA" do
let(:stripe_sca_payment_method) { create(:stripe_sca_payment_method) }
- let(:stripe_sca_payment) { create(:payment, amount: 10, payment_method: stripe_sca_payment_method) }
+ let(:stripe_sca_payment) {
+ create(:payment, amount: 10, payment_method: stripe_sca_payment_method)
+ }
let(:provider) { double }
before do
- allow_any_instance_of(Stripe::CreditCardCloner).to receive(:find_or_clone) { ["cus_123", "pm_1234"] }
+ allow_any_instance_of(Stripe::CreditCardCloner).to receive(:find_or_clone) {
+ ["cus_123", "pm_1234"]
+ }
allow(order).to receive(:pending_payments) { [stripe_sca_payment] }
allow(stripe_sca_payment_method).to receive(:provider) { provider }
allow(stripe_sca_payment_method.provider).to receive(:purchase) { true }
@@ -175,7 +193,9 @@ describe SubscriptionConfirmJob do
context "Stripe Connect" do
let(:stripe_connect_payment_method) { create(:stripe_connect_payment_method) }
- let(:stripe_connect_payment) { create(:payment, amount: 10, payment_method: stripe_connect_payment_method) }
+ let(:stripe_connect_payment) {
+ create(:payment, amount: 10, payment_method: stripe_connect_payment_method)
+ }
before do
allow(order).to receive(:pending_payments) { [stripe_connect_payment] }
@@ -200,7 +220,9 @@ describe SubscriptionConfirmJob do
context "and an error is added to the order when updating payments" do
before do
- expect(job).to receive(:setup_payment!) { |order| order.errors.add(:base, "a payment error") }
+ expect(job).to receive(:setup_payment!) { |order|
+ order.errors.add(:base, "a payment error")
+ }
end
it "sends a failed payment email" do
@@ -215,7 +237,8 @@ describe SubscriptionConfirmJob do
context "when an error occurs while processing the payment" do
before do
- expect(payment).to receive(:process_offline!).and_raise Spree::Core::GatewayError, "payment failure error"
+ expect(payment).to receive(:process_offline!).and_raise Spree::Core::GatewayError,
+ "payment failure error"
end
it "sends a failed payment email" do
diff --git a/spec/jobs/subscription_placement_job_spec.rb b/spec/jobs/subscription_placement_job_spec.rb
index 2e8273894f..06b092a400 100644
--- a/spec/jobs/subscription_placement_job_spec.rb
+++ b/spec/jobs/subscription_placement_job_spec.rb
@@ -7,11 +7,19 @@ describe SubscriptionPlacementJob do
describe "finding proxy_orders that are ready to be placed" do
let(:shop) { create(:distributor_enterprise) }
- let(:order_cycle1) { create(:simple_order_cycle, coordinator: shop, orders_open_at: 1.minute.ago, orders_close_at: 10.minutes.from_now) }
- let(:order_cycle2) { create(:simple_order_cycle, coordinator: shop, orders_open_at: 10.minutes.ago, orders_close_at: 1.minute.ago) }
+ let(:order_cycle1) {
+ create(:simple_order_cycle, coordinator: shop, orders_open_at: 1.minute.ago,
+ orders_close_at: 10.minutes.from_now)
+ }
+ let(:order_cycle2) {
+ create(:simple_order_cycle, coordinator: shop, orders_open_at: 10.minutes.ago,
+ orders_close_at: 1.minute.ago)
+ }
let(:schedule) { create(:schedule, order_cycles: [order_cycle1, order_cycle2]) }
let(:subscription) { create(:subscription, shop: shop, schedule: schedule) }
- let!(:proxy_order) { create(:proxy_order, subscription: subscription, order_cycle: order_cycle1) } # OK
+ let!(:proxy_order) {
+ create(:proxy_order, subscription: subscription, order_cycle: order_cycle1)
+ } # OK
it "ignores proxy orders where the OC has closed" do
expect(job.send(:proxy_orders)).to include proxy_order
@@ -66,7 +74,9 @@ describe SubscriptionPlacementJob do
let(:order_cycle) { create(:simple_order_cycle) }
let(:shop) { order_cycle.coordinator }
let(:order) { create(:order, order_cycle: order_cycle, distributor: shop) }
- let(:ex) { create(:exchange, order_cycle: order_cycle, sender: shop, receiver: shop, incoming: false) }
+ let(:ex) {
+ create(:exchange, order_cycle: order_cycle, sender: shop, receiver: shop, incoming: false)
+ }
let(:variant1) { create(:variant, on_hand: 5) }
let(:variant2) { create(:variant, on_hand: 5) }
let(:variant3) { create(:variant, on_hand: 5) }
@@ -152,7 +162,7 @@ describe SubscriptionPlacementJob do
end
context "when the order is already complete" do
- before { while !order.completed? do break unless order.next! end }
+ before { break unless order.next! while !order.completed? }
it "records an issue and ignores it" do
ActionMailer::Base.deliveries.clear
@@ -183,7 +193,9 @@ describe SubscriptionPlacementJob do
end
it "does not place the order, clears all adjustments, and sends an empty_order email" do
- expect{ job.send(:place_order, order) }.to_not change{ order.reload.completed_at }.from(nil)
+ expect{ job.send(:place_order, order) }.to_not change{
+ order.reload.completed_at
+ }.from(nil)
expect(order.all_adjustments).to be_empty
expect(order.total).to eq 0
expect(order.adjustment_total).to eq 0
@@ -203,7 +215,7 @@ describe SubscriptionPlacementJob do
it "does not enqueue confirmation emails" do
expect{ job.send(:place_order, order) }
- .to_not have_enqueued_mail(Spree::OrderMailer, :confirm_email_for_customer)
+ .to_not have_enqueued_mail(Spree::OrderMailer, :confirm_email_for_customer)
expect(job).to have_received(:send_placement_email).with(order, anything).once
end
diff --git a/spec/lib/open_food_network/address_finder_spec.rb b/spec/lib/open_food_network/address_finder_spec.rb
index 51e4b1a11e..b3adb80dc5 100644
--- a/spec/lib/open_food_network/address_finder_spec.rb
+++ b/spec/lib/open_food_network/address_finder_spec.rb
@@ -88,7 +88,10 @@ module OpenFoodNetwork
describe "last_used_bill_address" do
let(:distributor) { create(:distributor_enterprise) }
let(:address) { create(:address) }
- let(:order) { create(:completed_order_with_totals, user: nil, email: email, distributor: distributor, bill_address: nil) }
+ let(:order) {
+ create(:completed_order_with_totals, user: nil, email: email, distributor: distributor,
+ bill_address: nil)
+ }
let(:finder) { AddressFinder.new(email) }
context "when searching by email is not allowed" do
@@ -147,7 +150,10 @@ module OpenFoodNetwork
end
context "and an order with a required ship address exists" do
- let(:order) { create(:shipped_order, user: nil, email: email, distributor: distributor, shipments: [], ship_address: address) }
+ let(:order) {
+ create(:shipped_order, user: nil, email: email, distributor: distributor, shipments: [],
+ ship_address: address)
+ }
before do
order.shipping_method.update_attribute(:require_ship_address, true)
@@ -165,7 +171,10 @@ module OpenFoodNetwork
end
context "and an order with a ship address exists" do
- let(:order) { create(:shipped_order, user: nil, email: email, distributor: distributor, shipments: [], ship_address: address) }
+ let(:order) {
+ create(:shipped_order, user: nil, email: email, distributor: distributor, shipments: [],
+ ship_address: address)
+ }
context "and the shipping method requires an address" do
before { order.shipping_method.update_attribute(:require_ship_address, true) }
@@ -185,7 +194,10 @@ module OpenFoodNetwork
end
context "and an order without a ship address exists" do
- let!(:order) { create(:shipped_order, user: nil, email: email, distributor: distributor, shipments: [], ship_address: nil) }
+ let!(:order) {
+ create(:shipped_order, user: nil, email: email, distributor: distributor, shipments: [],
+ ship_address: nil)
+ }
it "return nil" do
expect(finder.send(:last_used_ship_address)).to eq nil
diff --git a/spec/lib/open_food_network/customers_report_spec.rb b/spec/lib/open_food_network/customers_report_spec.rb
index cd02dacd34..f1df21332f 100644
--- a/spec/lib/open_food_network/customers_report_spec.rb
+++ b/spec/lib/open_food_network/customers_report_spec.rb
@@ -41,7 +41,8 @@ module OpenFoodNetwork
end
it "returns headers for addresses" do
- expect(subject.header).to eq(["First Name", "Last Name", "Billing Address", "Email", "Phone", "Hub", "Hub Address", "Shipping Method"])
+ expect(subject.header).to eq(["First Name", "Last Name", "Billing Address", "Email",
+ "Phone", "Hub", "Hub Address", "Shipping Method"])
end
it "builds a table from a list of variants" do
diff --git a/spec/lib/open_food_network/enterprise_fee_applicator_spec.rb b/spec/lib/open_food_network/enterprise_fee_applicator_spec.rb
index be95930f95..af7f4ddd7a 100644
--- a/spec/lib/open_food_network/enterprise_fee_applicator_spec.rb
+++ b/spec/lib/open_food_network/enterprise_fee_applicator_spec.rb
@@ -65,7 +65,7 @@ module OpenFoodNetwork
let(:variant) { double(:variant, product: double(:product, name: 'Bananas')) }
let(:enterprise_fee) {
double(:enterprise_fee, fee_type: 'packing',
- enterprise: double(:enterprise, name: 'Ballantyne'))
+ enterprise: double(:enterprise, name: 'Ballantyne'))
}
let(:applicator) { EnterpriseFeeApplicator.new enterprise_fee, variant, 'distributor' }
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 97068516f9..24b4ea07b6 100644
--- a/spec/lib/open_food_network/enterprise_fee_calculator_spec.rb
+++ b/spec/lib/open_food_network/enterprise_fee_calculator_spec.rb
@@ -18,7 +18,9 @@ module OpenFoodNetwork
describe "summing all the per-item fees for the variant in the specified hub + order cycle" do
let(:enterprise_fee1) { create(:enterprise_fee, amount: 20) }
let(:enterprise_fee2) { create(:enterprise_fee, amount: 3) }
- let(:enterprise_fee3) { create(:enterprise_fee, calculator: Calculator::FlatRate.new(preferred_amount: 2)) }
+ let(:enterprise_fee3) {
+ create(:enterprise_fee, calculator: Calculator::FlatRate.new(preferred_amount: 2))
+ }
describe "supplier fees" do
let!(:exchange1) {
@@ -31,13 +33,17 @@ module OpenFoodNetwork
}
it "calculates via regular computation" do
- expect(EnterpriseFeeCalculator.new(distributor, order_cycle).fees_for(product1.master)).to eq(20)
- expect(EnterpriseFeeCalculator.new(distributor, order_cycle).fees_for(product2.master)).to eq(3)
+ expect(EnterpriseFeeCalculator.new(distributor,
+ order_cycle).fees_for(product1.master)).to eq(20)
+ expect(EnterpriseFeeCalculator.new(distributor,
+ order_cycle).fees_for(product2.master)).to eq(3)
end
it "calculates via indexed computation" do
- expect(EnterpriseFeeCalculator.new(distributor, order_cycle).indexed_fees_for(product1.master)).to eq(20)
- expect(EnterpriseFeeCalculator.new(distributor, order_cycle).indexed_fees_for(product2.master)).to eq(3)
+ expect(EnterpriseFeeCalculator.new(distributor,
+ order_cycle).indexed_fees_for(product1.master)).to eq(20)
+ expect(EnterpriseFeeCalculator.new(distributor,
+ order_cycle).indexed_fees_for(product2.master)).to eq(3)
end
end
@@ -52,11 +58,13 @@ module OpenFoodNetwork
end
it "sums via regular computation" do
- expect(EnterpriseFeeCalculator.new(distributor, order_cycle).fees_for(product1.master)).to eq(23)
+ expect(EnterpriseFeeCalculator.new(distributor,
+ order_cycle).fees_for(product1.master)).to eq(23)
end
it "sums via indexed computation" do
- expect(EnterpriseFeeCalculator.new(distributor, order_cycle).indexed_fees_for(product1.master)).to eq(23)
+ expect(EnterpriseFeeCalculator.new(distributor,
+ order_cycle).indexed_fees_for(product1.master)).to eq(23)
end
end
@@ -67,28 +75,35 @@ module OpenFoodNetwork
}
it "sums via regular computation" do
- expect(EnterpriseFeeCalculator.new(distributor, order_cycle).fees_for(product1.master)).to eq(23)
+ expect(EnterpriseFeeCalculator.new(distributor,
+ order_cycle).fees_for(product1.master)).to eq(23)
end
it "sums via indexed computation" do
- expect(EnterpriseFeeCalculator.new(distributor, order_cycle).indexed_fees_for(product1.master)).to eq(23)
+ expect(EnterpriseFeeCalculator.new(distributor,
+ order_cycle).indexed_fees_for(product1.master)).to eq(23)
end
end
end
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!(: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])
}
it "sums via regular computation" do
- expect(EnterpriseFeeCalculator.new(distributor, order_cycle).fees_for(product1.master)).to eq(2.00)
+ expect(EnterpriseFeeCalculator.new(distributor,
+ order_cycle).fees_for(product1.master)).to eq(2.00)
end
it "sums via indexed computation" do
- expect(EnterpriseFeeCalculator.new(distributor, order_cycle).indexed_fees_for(product1.master)).to eq(2.00)
+ expect(EnterpriseFeeCalculator.new(distributor,
+ order_cycle).indexed_fees_for(product1.master)).to eq(2.00)
end
end
end
@@ -108,23 +123,31 @@ module OpenFoodNetwork
describe "regular computation" do
it "returns a breakdown of fees" do
- expect(EnterpriseFeeCalculator.new(distributor, order_cycle).fees_by_type_for(product1.master)).to eq(admin: 1.23, sales: 4.56, packing: 7.89, transport: 0.12, fundraising: 3.45)
+ expect(EnterpriseFeeCalculator.new(distributor,
+ order_cycle).fees_by_type_for(product1.master)).to eq(admin: 1.23, sales: 4.56, packing: 7.89,
+ transport: 0.12, fundraising: 3.45)
end
it "filters out zero fees" do
ef_admin.calculator.update_attribute :preferred_amount, 0
- expect(EnterpriseFeeCalculator.new(distributor, order_cycle).fees_by_type_for(product1.master)).to eq(sales: 4.56, packing: 7.89, transport: 0.12, fundraising: 3.45)
+ expect(EnterpriseFeeCalculator.new(distributor,
+ order_cycle).fees_by_type_for(product1.master)).to eq(sales: 4.56, packing: 7.89, transport: 0.12,
+ fundraising: 3.45)
end
end
describe "indexed computation" do
it "returns a breakdown of fees" do
- expect(EnterpriseFeeCalculator.new(distributor, order_cycle).indexed_fees_by_type_for(product1.master)).to eq(admin: 1.23, sales: 4.56, packing: 7.89, transport: 0.12, fundraising: 3.45)
+ expect(EnterpriseFeeCalculator.new(distributor,
+ order_cycle).indexed_fees_by_type_for(product1.master)).to eq(admin: 1.23, sales: 4.56,
+ packing: 7.89, transport: 0.12, fundraising: 3.45)
end
it "filters out zero fees" do
ef_admin.calculator.update_attribute :preferred_amount, 0
- expect(EnterpriseFeeCalculator.new(distributor, order_cycle).indexed_fees_by_type_for(product1.master)).to eq(sales: 4.56, packing: 7.89, transport: 0.12, fundraising: 3.45)
+ expect(EnterpriseFeeCalculator.new(distributor,
+ order_cycle).indexed_fees_by_type_for(product1.master)).to eq(sales: 4.56, packing: 7.89,
+ transport: 0.12, fundraising: 3.45)
end
end
end
@@ -133,15 +156,21 @@ module OpenFoodNetwork
let(:order) { create(:order, distributor: distributor, order_cycle: order_cycle) }
let!(:line_item) { create(:line_item, order: order, variant: product1.master) }
let(:enterprise_fee_line_item) { create(:enterprise_fee) }
- let(:enterprise_fee_order) { create(:enterprise_fee, calculator: Calculator::FlatRate.new(preferred_amount: 2)) }
- let!(:exchange) { create(:exchange, order_cycle: order_cycle, sender: coordinator, receiver: distributor, incoming: false, variants: [product1.master]) }
+ let(:enterprise_fee_order) {
+ create(:enterprise_fee, calculator: Calculator::FlatRate.new(preferred_amount: 2))
+ }
+ let!(:exchange) {
+ create(:exchange, order_cycle: order_cycle, sender: coordinator, receiver: distributor,
+ incoming: false, variants: [product1.master])
+ }
before { order.reload }
it "creates adjustments for a line item" do
exchange.enterprise_fees << enterprise_fee_line_item
- EnterpriseFeeCalculator.new(distributor, order_cycle).create_line_item_adjustments_for line_item
+ EnterpriseFeeCalculator.new(distributor,
+ order_cycle).create_line_item_adjustments_for line_item
a = Spree::Adjustment.last
expect(a.metadata.fee_name).to eq(enterprise_fee_line_item.name)
@@ -167,7 +196,10 @@ module OpenFoodNetwork
let!(:ef_exchange) { create(:enterprise_fee) }
let!(:ef_coordinator) { create(:enterprise_fee) }
let!(:ef_other_distributor) { create(:enterprise_fee) }
- let!(:exchange) { create(:exchange, sender: order_cycle.coordinator, receiver: distributor, order_cycle: order_cycle, enterprise_fees: [ef_exchange], variants: [v]) }
+ let!(:exchange) {
+ create(:exchange, sender: order_cycle.coordinator, receiver: distributor,
+ order_cycle: order_cycle, enterprise_fees: [ef_exchange], variants: [v])
+ }
let(:v) { create(:variant) }
let(:indexed_variants) { { v.id => v } }
let(:indexed_enterprise_fees) { subject.instance_variable_get(:@indexed_enterprise_fees) }
@@ -186,7 +218,8 @@ module OpenFoodNetwork
end
it "does not include outgoing exchanges to other distributors" do
- create(:exchange, order_cycle: order_cycle, sender: order_cycle.coordinator, receiver: distributor_other, enterprise_fees: [ef_other_distributor], variants: [v])
+ create(:exchange, order_cycle: order_cycle, sender: order_cycle.coordinator,
+ receiver: distributor_other, enterprise_fees: [ef_other_distributor], variants: [v])
expect(subject.send(:per_item_enterprise_fees_with_exchange_details)).to eq([ef_exchange])
end
@@ -224,8 +257,12 @@ module OpenFoodNetwork
let(:line_item) { double(:line_item, variant: variant, order: order) }
before do
- allow(incoming_exchange).to receive(:enterprise_fees) { double(:enterprise_fees, per_item: [ef1]) }
- allow(outgoing_exchange).to receive(:enterprise_fees) { double(:enterprise_fees, per_item: [ef2]) }
+ allow(incoming_exchange).to receive(:enterprise_fees) {
+ double(:enterprise_fees, per_item: [ef1])
+ }
+ allow(outgoing_exchange).to receive(:enterprise_fees) {
+ double(:enterprise_fees, per_item: [ef2])
+ }
allow(oc).to receive(:exchanges_carrying) { [incoming_exchange, outgoing_exchange] }
allow(oc).to receive(:coordinator_fees) { double(:coodinator_fees, per_item: [ef3]) }
end
@@ -235,7 +272,9 @@ module OpenFoodNetwork
let(:order) { double(:order, distributor: distributor, order_cycle: oc) }
it "creates an adjustment for each fee" do
- expect(efc).to receive(:per_item_enterprise_fee_applicators_for).with(variant) { [applicator] }
+ expect(efc).to receive(:per_item_enterprise_fee_applicators_for).with(variant) {
+ [applicator]
+ }
expect(applicator).to receive(:create_line_item_adjustment).with(line_item)
efc.create_line_item_adjustments_for line_item
end
@@ -243,8 +282,10 @@ 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')]
+ OpenFoodNetwork::EnterpriseFeeApplicator.new(ef2, line_item.variant,
+ 'distributor'),
+ OpenFoodNetwork::EnterpriseFeeApplicator.new(ef3, line_item.variant,
+ 'coordinator')]
end
end
@@ -260,8 +301,12 @@ module OpenFoodNetwork
describe "for an order" do
before do
- allow(incoming_exchange).to receive(:enterprise_fees) { double(:enterprise_fees, per_order: [ef1]) }
- allow(outgoing_exchange).to receive(:enterprise_fees) { double(:enterprise_fees, per_order: [ef2]) }
+ allow(incoming_exchange).to receive(:enterprise_fees) {
+ double(:enterprise_fees, per_order: [ef1])
+ }
+ allow(outgoing_exchange).to receive(:enterprise_fees) {
+ double(:enterprise_fees, per_order: [ef2])
+ }
allow(oc).to receive(:exchanges_supplying) { [incoming_exchange, outgoing_exchange] }
allow(oc).to receive(:coordinator_fees) { double(:coodinator_fees, per_order: [ef3]) }
end
@@ -271,7 +316,9 @@ module OpenFoodNetwork
let(:order) { double(:order, distributor: distributor, order_cycle: oc) }
it "creates an adjustment for each fee" do
- expect(efc).to receive(:per_order_enterprise_fee_applicators_for).with(order) { [applicator] }
+ expect(efc).to receive(:per_order_enterprise_fee_applicators_for).with(order) {
+ [applicator]
+ }
expect(applicator).to receive(:create_order_adjustment).with(order)
efc.create_order_adjustments_for order
end
diff --git a/spec/lib/open_food_network/group_buy_report_spec.rb b/spec/lib/open_food_network/group_buy_report_spec.rb
index bdf9404f05..cbb633f6aa 100644
--- a/spec/lib/open_food_network/group_buy_report_spec.rb
+++ b/spec/lib/open_food_network/group_buy_report_spec.rb
@@ -8,7 +8,8 @@ module OpenFoodNetwork
before(:each) do
@orders = []
bill_address = create(:address)
- distributor_address = create(:address, address1: "distributor address", city: 'The Shire', zipcode: "1234")
+ distributor_address = create(:address, address1: "distributor address", city: 'The Shire',
+ zipcode: "1234")
distributor = create(:distributor_enterprise, address: distributor_address)
@supplier1 = create(:supplier_enterprise)
@@ -19,11 +20,13 @@ module OpenFoodNetwork
shipping_instructions = "pick up on thursday please!"
- order1 = create(:order, distributor: distributor, bill_address: bill_address, special_instructions: shipping_instructions)
+ order1 = create(:order, distributor: distributor, bill_address: bill_address,
+ special_instructions: shipping_instructions)
line_item11 = create(:line_item, variant: @variant1, order: order1)
@orders << order1.reload
- order2 = create(:order, distributor: distributor, bill_address: bill_address, special_instructions: shipping_instructions)
+ order2 = create(:order, distributor: distributor, bill_address: bill_address,
+ special_instructions: shipping_instructions)
line_item21 = create(:line_item, variant: @variant1, order: order2)
@variant2 = create(:variant)
@@ -38,7 +41,8 @@ module OpenFoodNetwork
@variant3.product.supplier = @supplier2
@variant3.product.save!
- order3 = create(:order, distributor: distributor, bill_address: bill_address, special_instructions: shipping_instructions)
+ order3 = create(:order, distributor: distributor, bill_address: bill_address,
+ special_instructions: shipping_instructions)
line_item31 = create(:line_item, variant: @variant3, order: order3)
@orders << order3.reload
end
@@ -46,7 +50,8 @@ module OpenFoodNetwork
it "should return a header row describing the report" do
subject = GroupBuyReport.new [@order1]
header = subject.header
- expect(header).to eq(["Supplier", "Product", "Unit Size", "Variant", "Weight", "Total Ordered", "Total Max"])
+ expect(header).to eq(["Supplier", "Product", "Unit Size", "Variant", "Weight",
+ "Total Ordered", "Total Max"])
end
it "should provide the required variant and quantity information in a table" do
@@ -54,12 +59,15 @@ module OpenFoodNetwork
table = subject.table
- line_items = @orders.map(&:line_items).flatten.select{ |li| li.product.supplier == @supplier1 && li.variant == @variant1 }
+ line_items = @orders.map(&:line_items).flatten.select{ |li|
+ li.product.supplier == @supplier1 && li.variant == @variant1
+ }
sum_quantities = line_items.map(&:quantity).sum
sum_max_quantities = line_items.map { |li| li.max_quantity || 0 }.sum
- expect(table[0]).to eq([@variant1.product.supplier.name, @variant1.product.name, "UNITSIZE", @variant1.options_text, @variant1.weight, sum_quantities, sum_max_quantities])
+ expect(table[0]).to eq([@variant1.product.supplier.name, @variant1.product.name, "UNITSIZE",
+ @variant1.options_text, @variant1.weight, sum_quantities, sum_max_quantities])
end
it "should return a table wherein each rows contains the same number of columns as the heading" do
@@ -78,8 +86,12 @@ module OpenFoodNetwork
table_row_objects = subject.variants_and_quantities
- variant_rows = table_row_objects.select { |r| r.class == OpenFoodNetwork::GroupBuyVariantRow }
- product_rows = table_row_objects.select { |r| r.class == OpenFoodNetwork::GroupBuyProductRow }
+ variant_rows = table_row_objects.select { |r|
+ r.instance_of?(OpenFoodNetwork::GroupBuyVariantRow)
+ }
+ product_rows = table_row_objects.select { |r|
+ r.instance_of?(OpenFoodNetwork::GroupBuyProductRow)
+ }
supplier_groups = variant_rows.group_by { |r| r.variant.product.supplier }
variant_groups = variant_rows.group_by(&:variant)
diff --git a/spec/lib/open_food_network/lettuce_share_report_spec.rb b/spec/lib/open_food_network/lettuce_share_report_spec.rb
index 44605d186a..7f32110299 100644
--- a/spec/lib/open_food_network/lettuce_share_report_spec.rb
+++ b/spec/lib/open_food_network/lettuce_share_report_spec.rb
@@ -41,28 +41,39 @@ module OpenFoodNetwork
let(:variant2) { create(:variant) }
let(:variant3) { create(:variant) }
let(:variant4) { create(:variant, on_hand: 0, on_demand: true) }
- let(:hub_address) { create(:address, address1: "distributor address", city: 'The Shire', zipcode: "1234") }
+ let(:hub_address) {
+ create(:address, address1: "distributor address", city: 'The Shire', zipcode: "1234")
+ }
let(:hub) { create(:distributor_enterprise, address: hub_address) }
let(:variant2_override) { create(:variant_override, hub: hub, variant: variant2) }
- let(:variant3_override) { create(:variant_override, hub: hub, variant: variant3, count_on_hand: 0) }
+ let(:variant3_override) {
+ create(:variant_override, hub: hub, variant: variant3, count_on_hand: 0)
+ }
it "all items" do
- allow(report).to receive(:child_variants) { Spree::Variant.where(id: [variant, variant2, variant3]) }
+ allow(report).to receive(:child_variants) {
+ Spree::Variant.where(id: [variant, variant2, variant3])
+ }
expect(report.table.count).to eq 3
end
it "only available items" do
variant.on_hand = 0
- allow(report).to receive(:child_variants) { Spree::Variant.where(id: [variant, variant2, variant3, variant4]) }
+ allow(report).to receive(:child_variants) {
+ Spree::Variant.where(id: [variant, variant2, variant3, variant4])
+ }
expect(report.table.count).to eq 3
end
it "only available items considering overrides" do
- create(:exchange, incoming: false, receiver_id: hub.id, variants: [variant, variant2, variant3])
+ create(:exchange, incoming: false, receiver_id: hub.id,
+ variants: [variant, variant2, variant3])
# create the overrides
variant2_override
variant3_override
- allow(report).to receive(:child_variants) { Spree::Variant.where(id: [variant, variant2, variant3]) }
+ allow(report).to receive(:child_variants) {
+ Spree::Variant.where(id: [variant, variant2, variant3])
+ }
allow(report).to receive(:params) { { distributor_id: hub.id } }
rows = report.table
expect(rows.count).to eq 2
diff --git a/spec/lib/open_food_network/order_cycle_form_applicator_spec.rb b/spec/lib/open_food_network/order_cycle_form_applicator_spec.rb
index befa035486..677152ce9f 100644
--- a/spec/lib/open_food_network/order_cycle_form_applicator_spec.rb
+++ b/spec/lib/open_food_network/order_cycle_form_applicator_spec.rb
@@ -13,15 +13,21 @@ module OpenFoodNetwork
coordinator_id = 123
supplier_id = 456
- incoming_exchange = { enterprise_id: supplier_id, incoming: true, variants: { '1' => true, '2' => false, '3' => true }, enterprise_fee_ids: [1, 2], receival_instructions: 'receival instructions' }
+ incoming_exchange = { enterprise_id: supplier_id, incoming: true,
+ variants: { '1' => true, '2' => false, '3' => true }, enterprise_fee_ids: [1, 2], receival_instructions: 'receival instructions' }
- oc = double(:order_cycle, coordinator_id: coordinator_id, exchanges: [], incoming_exchanges: [incoming_exchange], outgoing_exchanges: [])
+ oc = double(:order_cycle, coordinator_id: coordinator_id, exchanges: [],
+ incoming_exchanges: [incoming_exchange], outgoing_exchanges: [])
applicator = OrderCycleFormApplicator.new(oc, user)
- expect(applicator).to receive(:incoming_exchange_variant_ids).with(incoming_exchange).and_return([1, 3])
- expect(applicator).to receive(:exchange_exists?).with(supplier_id, coordinator_id, true).and_return(false)
- expect(applicator).to receive(:add_exchange).with(supplier_id, coordinator_id, true, variant_ids: [1, 3], enterprise_fee_ids: [1, 2], receival_instructions: 'receival instructions')
+ expect(applicator).to receive(:incoming_exchange_variant_ids).with(incoming_exchange).and_return([
+ 1, 3
+ ])
+ expect(applicator).to receive(:exchange_exists?).with(supplier_id, coordinator_id,
+ true).and_return(false)
+ expect(applicator).to receive(:add_exchange).with(supplier_id, coordinator_id, true,
+ variant_ids: [1, 3], enterprise_fee_ids: [1, 2], receival_instructions: 'receival instructions')
expect(applicator).to receive(:destroy_untouched_exchanges)
applicator.go!
@@ -31,15 +37,21 @@ module OpenFoodNetwork
coordinator_id = 123
distributor_id = 456
- outgoing_exchange = { enterprise_id: distributor_id, incoming: false, variants: { '1' => true, '2' => false, '3' => true }, enterprise_fee_ids: [1, 2], pickup_time: 'pickup time', pickup_instructions: 'pickup instructions', tag_list: 'wholesale' }
+ outgoing_exchange = { enterprise_id: distributor_id, incoming: false,
+ variants: { '1' => true, '2' => false, '3' => true }, enterprise_fee_ids: [1, 2], pickup_time: 'pickup time', pickup_instructions: 'pickup instructions', tag_list: 'wholesale' }
- oc = double(:order_cycle, coordinator_id: coordinator_id, exchanges: [], incoming_exchanges: [], outgoing_exchanges: [outgoing_exchange])
+ oc = double(:order_cycle, coordinator_id: coordinator_id, exchanges: [],
+ incoming_exchanges: [], outgoing_exchanges: [outgoing_exchange])
applicator = OrderCycleFormApplicator.new(oc, user)
- expect(applicator).to receive(:outgoing_exchange_variant_ids).with(outgoing_exchange).and_return([1, 3])
- expect(applicator).to receive(:exchange_exists?).with(coordinator_id, distributor_id, false).and_return(false)
- expect(applicator).to receive(:add_exchange).with(coordinator_id, distributor_id, false, variant_ids: [1, 3], enterprise_fee_ids: [1, 2], pickup_time: 'pickup time', pickup_instructions: 'pickup instructions', tag_list: 'wholesale')
+ expect(applicator).to receive(:outgoing_exchange_variant_ids).with(outgoing_exchange).and_return([
+ 1, 3
+ ])
+ expect(applicator).to receive(:exchange_exists?).with(coordinator_id, distributor_id,
+ false).and_return(false)
+ expect(applicator).to receive(:add_exchange).with(coordinator_id, distributor_id, false,
+ variant_ids: [1, 3], enterprise_fee_ids: [1, 2], pickup_time: 'pickup time', pickup_instructions: 'pickup instructions', tag_list: 'wholesale')
expect(applicator).to receive(:destroy_untouched_exchanges)
applicator.go!
@@ -49,19 +61,25 @@ module OpenFoodNetwork
coordinator_id = 123
supplier_id = 456
- incoming_exchange = { enterprise_id: supplier_id, incoming: true, variants: { '1' => true, '2' => false, '3' => true }, enterprise_fee_ids: [1, 2], receival_instructions: 'receival instructions' }
+ incoming_exchange = { enterprise_id: supplier_id, incoming: true,
+ variants: { '1' => true, '2' => false, '3' => true }, enterprise_fee_ids: [1, 2], receival_instructions: 'receival instructions' }
oc = double(:order_cycle,
coordinator_id: coordinator_id,
- exchanges: [double(:exchange, sender_id: supplier_id, receiver_id: coordinator_id, incoming: true)],
+ exchanges: [double(:exchange, sender_id: supplier_id,
+ receiver_id: coordinator_id, incoming: true)],
incoming_exchanges: [incoming_exchange],
outgoing_exchanges: [])
applicator = OrderCycleFormApplicator.new(oc, user)
- expect(applicator).to receive(:incoming_exchange_variant_ids).with(incoming_exchange).and_return([1, 3])
- expect(applicator).to receive(:exchange_exists?).with(supplier_id, coordinator_id, true).and_return(true)
- expect(applicator).to receive(:update_exchange).with(supplier_id, coordinator_id, true, variant_ids: [1, 3], enterprise_fee_ids: [1, 2], receival_instructions: 'receival instructions')
+ expect(applicator).to receive(:incoming_exchange_variant_ids).with(incoming_exchange).and_return([
+ 1, 3
+ ])
+ expect(applicator).to receive(:exchange_exists?).with(supplier_id, coordinator_id,
+ true).and_return(true)
+ expect(applicator).to receive(:update_exchange).with(supplier_id, coordinator_id, true,
+ variant_ids: [1, 3], enterprise_fee_ids: [1, 2], receival_instructions: 'receival instructions')
expect(applicator).to receive(:destroy_untouched_exchanges)
applicator.go!
@@ -71,19 +89,25 @@ module OpenFoodNetwork
coordinator_id = 123
distributor_id = 456
- outgoing_exchange = { enterprise_id: distributor_id, incoming: false, variants: { '1' => true, '2' => false, '3' => true }, enterprise_fee_ids: [1, 2], pickup_time: 'pickup time', pickup_instructions: 'pickup instructions', tag_list: 'wholesale' }
+ outgoing_exchange = { enterprise_id: distributor_id, incoming: false,
+ variants: { '1' => true, '2' => false, '3' => true }, enterprise_fee_ids: [1, 2], pickup_time: 'pickup time', pickup_instructions: 'pickup instructions', tag_list: 'wholesale' }
oc = double(:order_cycle,
coordinator_id: coordinator_id,
- exchanges: [double(:exchange, sender_id: coordinator_id, receiver_id: distributor_id, incoming: false)],
+ exchanges: [double(:exchange, sender_id: coordinator_id,
+ receiver_id: distributor_id, incoming: false)],
incoming_exchanges: [],
outgoing_exchanges: [outgoing_exchange])
applicator = OrderCycleFormApplicator.new(oc, user)
- expect(applicator).to receive(:outgoing_exchange_variant_ids).with(outgoing_exchange).and_return([1, 3])
- expect(applicator).to receive(:exchange_exists?).with(coordinator_id, distributor_id, false).and_return(true)
- expect(applicator).to receive(:update_exchange).with(coordinator_id, distributor_id, false, variant_ids: [1, 3], enterprise_fee_ids: [1, 2], pickup_time: 'pickup time', pickup_instructions: 'pickup instructions', tag_list: 'wholesale')
+ expect(applicator).to receive(:outgoing_exchange_variant_ids).with(outgoing_exchange).and_return([
+ 1, 3
+ ])
+ expect(applicator).to receive(:exchange_exists?).with(coordinator_id, distributor_id,
+ false).and_return(true)
+ expect(applicator).to receive(:update_exchange).with(coordinator_id, distributor_id, false,
+ variant_ids: [1, 3], enterprise_fee_ids: [1, 2], pickup_time: 'pickup time', pickup_instructions: 'pickup instructions', tag_list: 'wholesale')
expect(applicator).to receive(:destroy_untouched_exchanges)
applicator.go!
@@ -93,7 +117,8 @@ module OpenFoodNetwork
it "destroys untouched exchanges" do
coordinator_id = 123
supplier_id = 456
- exchange = double(:exchange, id: 1, sender_id: supplier_id, receiver_id: coordinator_id, incoming: true)
+ exchange = double(:exchange, id: 1, sender_id: supplier_id, receiver_id: coordinator_id,
+ incoming: true)
oc = double(:order_cycle,
coordinator_id: coordinator_id,
@@ -156,7 +181,10 @@ module OpenFoodNetwork
let!(:v7) { create(:variant) } # Existing + Request Add + Not Editable + Not Incoming
let!(:v8) { create(:variant) } # Existing + Request Add + Editable + Not Incoming
let!(:v9) { create(:variant) } # Not Existing + Request Add + Editable + Not Incoming
- let!(:exchange) { create(:exchange, incoming: false, variant_ids: [v3.id, v4.id, v5.id, v6.id, v7.id, v8.id]) }
+ let!(:exchange) {
+ create(:exchange, incoming: false,
+ variant_ids: [v3.id, v4.id, v5.id, v6.id, v7.id, v8.id])
+ }
let!(:oc) { exchange.order_cycle }
let!(:enterprise) { exchange.receiver }
let!(:coordinator) { oc.coordinator }
@@ -177,8 +205,12 @@ module OpenFoodNetwork
end
before do
- allow(applicator).to receive(:incoming_variant_ids) { [v1.id, v2.id, v3.id, v4.id, v5.id, v6.id] }
- allow(applicator).to receive(:editable_variant_ids_for_outgoing_exchange_between) { [v1.id, v3.id, v4.id, v5.id, v8.id, v9.id] }
+ allow(applicator).to receive(:incoming_variant_ids) {
+ [v1.id, v2.id, v3.id, v4.id, v5.id, v6.id]
+ }
+ allow(applicator).to receive(:editable_variant_ids_for_outgoing_exchange_between) {
+ [v1.id, v3.id, v4.id, v5.id, v8.id, v9.id]
+ }
end
it "updates the list of variants for the exchange" do
@@ -216,7 +248,9 @@ module OpenFoodNetwork
let!(:v5) { create(:variant) } # Existing + Request Remove + Editable
let!(:v6) { create(:variant) } # Existing + Request Remove + Not Editable
let!(:v7) { create(:variant) } # Existing + Not mentioned + Editable
- let!(:exchange) { create(:exchange, incoming: true, variant_ids: [v3.id, v4.id, v5.id, v6.id, v7.id]) }
+ let!(:exchange) {
+ create(:exchange, incoming: true, variant_ids: [v3.id, v4.id, v5.id, v6.id, v7.id])
+ }
let!(:oc) { exchange.order_cycle }
let!(:enterprise) { exchange.sender }
let!(:coordinator) { oc.coordinator }
@@ -235,7 +269,9 @@ module OpenFoodNetwork
end
before do
- allow(applicator).to receive(:editable_variant_ids_for_incoming_exchange_between) { [v1.id, v3.id, v5.id, v7.id] }
+ allow(applicator).to receive(:editable_variant_ids_for_incoming_exchange_between) {
+ [v1.id, v3.id, v5.id, v7.id]
+ }
end
it "updates the list of variants for the exchange" do
@@ -297,11 +333,16 @@ module OpenFoodNetwork
exchange = FactoryBot.create(:exchange, order_cycle: oc)
applicator = OrderCycleFormApplicator.new(oc, user)
- expect(applicator.send(:exchange_exists?, exchange.sender_id, exchange.receiver_id, exchange.incoming)).to be true
- expect(applicator.send(:exchange_exists?, exchange.sender_id, exchange.receiver_id, !exchange.incoming)).to be false
- expect(applicator.send(:exchange_exists?, exchange.receiver_id, exchange.sender_id, exchange.incoming)).to be false
- expect(applicator.send(:exchange_exists?, exchange.sender_id, 999_999, exchange.incoming)).to be false
- expect(applicator.send(:exchange_exists?, 999_999, exchange.receiver_id, exchange.incoming)).to be false
+ expect(applicator.send(:exchange_exists?, exchange.sender_id, exchange.receiver_id,
+ exchange.incoming)).to be true
+ expect(applicator.send(:exchange_exists?, exchange.sender_id, exchange.receiver_id,
+ !exchange.incoming)).to be false
+ expect(applicator.send(:exchange_exists?, exchange.receiver_id, exchange.sender_id,
+ exchange.incoming)).to be false
+ expect(applicator.send(:exchange_exists?, exchange.sender_id, 999_999,
+ exchange.incoming)).to be false
+ expect(applicator.send(:exchange_exists?, 999_999, exchange.receiver_id,
+ exchange.incoming)).to be false
expect(applicator.send(:exchange_exists?, 999_999, 888_888, exchange.incoming)).to be false
end
@@ -320,7 +361,8 @@ module OpenFoodNetwork
before do
allow(applicator).to receive(:manages_coordinator?) { true }
applicator.send(:touched_exchanges=, [])
- applicator.send(:add_exchange, sender.id, receiver.id, incoming, variant_ids: [variant1.id, variant2.id], enterprise_fee_ids: [enterprise_fee1.id, enterprise_fee2.id])
+ applicator.send(:add_exchange, sender.id, receiver.id, incoming,
+ variant_ids: [variant1.id, variant2.id], enterprise_fee_ids: [enterprise_fee1.id, enterprise_fee2.id])
end
it "adds new exchanges" do
@@ -338,7 +380,8 @@ module OpenFoodNetwork
context "as a user which does not manage the coorindator" do
before do
allow(applicator).to receive(:manages_coordinator?) { false }
- applicator.send(:add_exchange, sender.id, receiver.id, incoming, variant_ids: [variant1.id, variant2.id], enterprise_fee_ids: [enterprise_fee1.id, enterprise_fee2.id])
+ applicator.send(:add_exchange, sender.id, receiver.id, incoming,
+ variant_ids: [variant1.id, variant2.id], enterprise_fee_ids: [enterprise_fee1.id, enterprise_fee2.id])
end
it "does not add new exchanges" do
@@ -360,7 +403,10 @@ module OpenFoodNetwork
let!(:enterprise_fee2) { create(:enterprise_fee) }
let!(:enterprise_fee3) { create(:enterprise_fee) }
- let!(:exchange) { create(:exchange, order_cycle: oc, sender: sender, receiver: receiver, incoming: incoming, variant_ids: [variant1.id, variant2.id], enterprise_fee_ids: [enterprise_fee1.id, enterprise_fee2.id]) }
+ let!(:exchange) {
+ create(:exchange, order_cycle: oc, sender: sender, receiver: receiver, incoming: incoming,
+ variant_ids: [variant1.id, variant2.id], enterprise_fee_ids: [enterprise_fee1.id, enterprise_fee2.id])
+ }
context "as a manager of the coorindator" do
before do
@@ -368,7 +414,8 @@ module OpenFoodNetwork
allow(applicator).to receive(:manager_for) { false }
allow(applicator).to receive(:permission_for) { true }
applicator.send(:touched_exchanges=, [])
- applicator.send(:update_exchange, sender.id, receiver.id, incoming, variant_ids: [variant1.id, variant3.id], enterprise_fee_ids: [enterprise_fee2.id, enterprise_fee3.id], pickup_time: 'New Pickup Time', pickup_instructions: 'New Pickup Instructions', tag_list: 'wholesale')
+ applicator.send(:update_exchange, sender.id, receiver.id, incoming,
+ variant_ids: [variant1.id, variant3.id], enterprise_fee_ids: [enterprise_fee2.id, enterprise_fee3.id], pickup_time: 'New Pickup Time', pickup_instructions: 'New Pickup Instructions', tag_list: 'wholesale')
end
it "updates the variants, enterprise fees tags, and pickup information of the exchange" do
@@ -388,7 +435,8 @@ module OpenFoodNetwork
allow(applicator).to receive(:manager_for) { true }
allow(applicator).to receive(:permission_for) { true }
applicator.send(:touched_exchanges=, [])
- applicator.send(:update_exchange, sender.id, receiver.id, incoming, variant_ids: [variant1.id, variant3.id], enterprise_fee_ids: [enterprise_fee2.id, enterprise_fee3.id], pickup_time: 'New Pickup Time', pickup_instructions: 'New Pickup Instructions', tag_list: 'wholesale')
+ applicator.send(:update_exchange, sender.id, receiver.id, incoming,
+ variant_ids: [variant1.id, variant3.id], enterprise_fee_ids: [enterprise_fee2.id, enterprise_fee3.id], pickup_time: 'New Pickup Time', pickup_instructions: 'New Pickup Instructions', tag_list: 'wholesale')
end
it "updates the variants, enterprise fees, tags and pickup information of the exchange" do
@@ -408,7 +456,8 @@ module OpenFoodNetwork
allow(applicator).to receive(:manager_for) { false }
allow(applicator).to receive(:permission_for) { true }
applicator.send(:touched_exchanges=, [])
- applicator.send(:update_exchange, sender.id, receiver.id, incoming, variant_ids: [variant1.id, variant3.id], enterprise_fee_ids: [enterprise_fee2.id, enterprise_fee3.id], pickup_time: 'New Pickup Time', pickup_instructions: 'New Pickup Instructions', tag_list: 'wholesale')
+ applicator.send(:update_exchange, sender.id, receiver.id, incoming,
+ variant_ids: [variant1.id, variant3.id], enterprise_fee_ids: [enterprise_fee2.id, enterprise_fee3.id], pickup_time: 'New Pickup Time', pickup_instructions: 'New Pickup Instructions', tag_list: 'wholesale')
end
it "updates the variants in the exchange, but not the fees, tags or pickup information" do
@@ -442,11 +491,13 @@ module OpenFoodNetwork
oc = FactoryBot.create(:simple_order_cycle)
applicator = OrderCycleFormApplicator.new(oc, user)
incoming = true
- exchange = FactoryBot.create(:exchange, order_cycle: oc, sender: sender, receiver: receiver, incoming: incoming)
+ exchange = FactoryBot.create(:exchange, order_cycle: oc, sender: sender,
+ receiver: receiver, incoming: incoming)
variant1 = FactoryBot.create(:variant)
applicator.send(:touched_exchanges=, [])
- applicator.send(:update_exchange, sender.id, receiver.id, incoming, variant_ids: [variant1.id])
+ applicator.send(:update_exchange, sender.id, receiver.id, incoming,
+ variant_ids: [variant1.id])
expect(exchange.variants).not_to eq([variant1])
end
diff --git a/spec/lib/open_food_network/order_cycle_management_report_spec.rb b/spec/lib/open_food_network/order_cycle_management_report_spec.rb
index 3beb2bd985..25f848dbf9 100644
--- a/spec/lib/open_food_network/order_cycle_management_report_spec.rb
+++ b/spec/lib/open_food_network/order_cycle_management_report_spec.rb
@@ -165,17 +165,17 @@ module OpenFoodNetwork
it 'returns rows with payment information' do
expect(subject.table_items).to eq([[
- order.billing_address.firstname,
- order.billing_address.lastname,
- order.distributor.name,
- '',
- order.email,
- order.billing_address.phone,
- order.shipment.shipping_method.name,
- nil,
- nil,
- -order.total
- ]])
+ order.billing_address.firstname,
+ order.billing_address.lastname,
+ order.distributor.name,
+ '',
+ order.email,
+ order.billing_address.phone,
+ order.shipment.shipping_method.name,
+ nil,
+ nil,
+ -order.total
+ ]])
end
end
@@ -191,20 +191,20 @@ module OpenFoodNetwork
it 'returns rows with delivery information' do
expect(subject.table_items).to eq([[
- order.ship_address.firstname,
- order.ship_address.lastname,
- order.distributor.name,
- "",
- "#{order.ship_address.address1} #{order.ship_address.address2} #{order.ship_address.city}",
- order.ship_address.zipcode,
- order.ship_address.phone,
- order.shipment.shipping_method.name,
- nil,
- nil,
- -order.total,
- false,
- order.special_instructions
- ]])
+ order.ship_address.firstname,
+ order.ship_address.lastname,
+ order.distributor.name,
+ "",
+ "#{order.ship_address.address1} #{order.ship_address.address2} #{order.ship_address.city}",
+ order.ship_address.zipcode,
+ order.ship_address.phone,
+ order.shipment.shipping_method.name,
+ nil,
+ nil,
+ -order.total,
+ false,
+ order.special_instructions
+ ]])
end
end
end
diff --git a/spec/lib/open_food_network/order_cycle_permissions_spec.rb b/spec/lib/open_food_network/order_cycle_permissions_spec.rb
index 715fcef5c0..4cabc5d3ac 100644
--- a/spec/lib/open_food_network/order_cycle_permissions_spec.rb
+++ b/spec/lib/open_food_network/order_cycle_permissions_spec.rb
@@ -17,7 +17,9 @@ module OpenFoodNetwork
let(:permissions) { OrderCyclePermissions.new(user, nil) }
before do
- allow(permissions).to receive(:managed_enterprises) { Enterprise.where(id: [coordinator]) }
+ allow(permissions).to receive(:managed_enterprises) {
+ Enterprise.where(id: [coordinator])
+ }
end
it "returns an empty scope" do
@@ -27,7 +29,9 @@ module OpenFoodNetwork
context "as a manager of the coordinator" do
before do
- allow(permissions).to receive(:managed_enterprises) { Enterprise.where(id: [coordinator]) }
+ allow(permissions).to receive(:managed_enterprises) {
+ Enterprise.where(id: [coordinator])
+ }
end
it "returns the coordinator itself" do
@@ -36,7 +40,8 @@ module OpenFoodNetwork
context "where P-OC has been granted to the coordinator by other enterprises" do
before do
- create(:enterprise_relationship, parent: hub, child: coordinator, permissions_list: [:add_to_order_cycle])
+ create(:enterprise_relationship, parent: hub, child: coordinator,
+ permissions_list: [:add_to_order_cycle])
end
context "where the coordinator sells any" do
@@ -58,8 +63,14 @@ module OpenFoodNetwork
context "where P-OC has not been granted to the coordinator by other enterprises" do
context "where the other enterprise are already in the order cycle" do
- let!(:ex_incoming) { create(:exchange, order_cycle: oc, sender: producer, receiver: coordinator, incoming: true) }
- let!(:ex_outgoing) { create(:exchange, order_cycle: oc, sender: coordinator, receiver: hub, incoming: false) }
+ let!(:ex_incoming) {
+ create(:exchange, order_cycle: oc, sender: producer, receiver: coordinator,
+ incoming: true)
+ }
+ let!(:ex_outgoing) {
+ create(:exchange, order_cycle: oc, sender: coordinator, receiver: hub,
+ incoming: false)
+ }
context "where the coordinator sells any" do
it "returns enterprises which have granted P-OC to the coordinator" do
@@ -93,11 +104,15 @@ module OpenFoodNetwork
context "that has granted P-OC to the coordinator" do
before do
- create(:enterprise_relationship, parent: hub, child: coordinator, permissions_list: [:add_to_order_cycle])
+ create(:enterprise_relationship, parent: hub, child: coordinator,
+ permissions_list: [:add_to_order_cycle])
end
context "where my hub is in the order cycle" do
- let!(:ex_outgoing) { create(:exchange, order_cycle: oc, sender: coordinator, receiver: hub, incoming: false) }
+ let!(:ex_outgoing) {
+ create(:exchange, order_cycle: oc, sender: coordinator, receiver: hub,
+ incoming: false)
+ }
it "returns my hub" do
enterprises = permissions.visible_enterprises
@@ -107,11 +122,15 @@ module OpenFoodNetwork
context "and has been granted P-OC by a producer" do
before do
- create(:enterprise_relationship, parent: producer, child: hub, permissions_list: [:add_to_order_cycle])
+ create(:enterprise_relationship, parent: producer, child: hub,
+ permissions_list: [:add_to_order_cycle])
end
context "where the producer is in the order cycle" do
- let!(:ex_incoming) { create(:exchange, order_cycle: oc, sender: producer, receiver: coordinator, incoming: true) }
+ let!(:ex_incoming) {
+ create(:exchange, order_cycle: oc, sender: producer, receiver: coordinator,
+ incoming: true)
+ }
it "returns the producer" do
enterprises = permissions.visible_enterprises
@@ -131,11 +150,15 @@ module OpenFoodNetwork
context "and has granted P-OC to a producer" do
before do
- create(:enterprise_relationship, parent: hub, child: producer, permissions_list: [:add_to_order_cycle])
+ create(:enterprise_relationship, parent: hub, child: producer,
+ permissions_list: [:add_to_order_cycle])
end
context "where the producer is in the order cycle" do
- let!(:ex_incoming) { create(:exchange, order_cycle: oc, sender: producer, receiver: coordinator, incoming: true) }
+ let!(:ex_incoming) {
+ create(:exchange, order_cycle: oc, sender: producer, receiver: coordinator,
+ incoming: true)
+ }
it "returns the producer" do
enterprises = permissions.visible_enterprises
@@ -171,7 +194,10 @@ module OpenFoodNetwork
end
context "but is already in the order cycle" do
- let!(:ex) { create(:exchange, order_cycle: oc, sender: coordinator, receiver: hub, incoming: false) }
+ let!(:ex) {
+ create(:exchange, order_cycle: oc, sender: coordinator, receiver: hub,
+ incoming: false)
+ }
it "returns my hub" do
enterprises = permissions.visible_enterprises
@@ -180,7 +206,9 @@ module OpenFoodNetwork
end
context "and distributes variants distributed by an unmanaged and unpermitted producer" do
- before { ex.variants << create(:variant, product: create(:product, supplier: producer)) }
+ before {
+ ex.variants << create(:variant, product: create(:product, supplier: producer))
+ }
# TODO: update this when we are confident about P-OCs
it "returns that producer as well" do
@@ -200,11 +228,15 @@ module OpenFoodNetwork
context "which has granted P-OC to the coordinator" do
before do
- create(:enterprise_relationship, parent: producer, child: coordinator, permissions_list: [:add_to_order_cycle])
+ create(:enterprise_relationship, parent: producer, child: coordinator,
+ permissions_list: [:add_to_order_cycle])
end
context "where my producer is in the order cycle" do
- let!(:ex_incoming) { create(:exchange, order_cycle: oc, sender: producer, receiver: coordinator, incoming: true) }
+ let!(:ex_incoming) {
+ create(:exchange, order_cycle: oc, sender: producer, receiver: coordinator,
+ incoming: true)
+ }
it "returns my producer" do
enterprises = permissions.visible_enterprises
@@ -214,11 +246,15 @@ module OpenFoodNetwork
context "and has been granted P-OC by a hub" do
before do
- create(:enterprise_relationship, parent: hub, child: producer, permissions_list: [:add_to_order_cycle])
+ create(:enterprise_relationship, parent: hub, child: producer,
+ permissions_list: [:add_to_order_cycle])
end
context "where the hub is also in the order cycle" do
- let!(:ex_outgoing) { create(:exchange, order_cycle: oc, sender: coordinator, receiver: hub, incoming: false) }
+ let!(:ex_outgoing) {
+ create(:exchange, order_cycle: oc, sender: coordinator, receiver: hub,
+ incoming: false)
+ }
it "returns the hub as well" do
enterprises = permissions.visible_enterprises
@@ -239,11 +275,15 @@ module OpenFoodNetwork
context "and has granted P-OC to a hub" do
before do
- create(:enterprise_relationship, parent: producer, child: hub, permissions_list: [:add_to_order_cycle])
+ create(:enterprise_relationship, parent: producer, child: hub,
+ permissions_list: [:add_to_order_cycle])
end
context "where the hub is also in the order cycle" do
- let!(:ex_outgoing) { create(:exchange, order_cycle: oc, sender: coordinator, receiver: hub, incoming: false) }
+ let!(:ex_outgoing) {
+ create(:exchange, order_cycle: oc, sender: coordinator, receiver: hub,
+ incoming: false)
+ }
it "returns the hub as well" do
enterprises = permissions.visible_enterprises
@@ -280,7 +320,10 @@ module OpenFoodNetwork
end
context "but is already in the order cycle" do
- let!(:ex_incoming) { create(:exchange, order_cycle: oc, sender: producer, receiver: coordinator, incoming: true) }
+ let!(:ex_incoming) {
+ create(:exchange, order_cycle: oc, sender: producer, receiver: coordinator,
+ incoming: true)
+ }
# TODO: update this when we are confident about P-OCs
it "returns my producer" do
@@ -290,8 +333,14 @@ module OpenFoodNetwork
end
context "and has variants distributed by an outgoing hub" do
- let!(:ex_outgoing) { create(:exchange, order_cycle: oc, sender: coordinator, receiver: hub, incoming: false) }
- before { ex_outgoing.variants << create(:variant, product: create(:product, supplier: producer)) }
+ let!(:ex_outgoing) {
+ create(:exchange, order_cycle: oc, sender: coordinator, receiver: hub,
+ incoming: false)
+ }
+ before {
+ ex_outgoing.variants << create(:variant,
+ product: create(:product, supplier: producer))
+ }
# TODO: update this when we are confident about P-OCs
it "returns that hub as well" do
@@ -307,11 +356,18 @@ module OpenFoodNetwork
describe "finding exchanges of an order cycle that an admin can manage" do
describe "as the manager of the coordinator" do
- let!(:ex_in) { create(:exchange, order_cycle: oc, sender: producer, receiver: coordinator, incoming: true) }
- let!(:ex_out) { create(:exchange, order_cycle: oc, sender: coordinator, receiver: hub, incoming: false) }
+ let!(:ex_in) {
+ create(:exchange, order_cycle: oc, sender: producer, receiver: coordinator,
+ incoming: true)
+ }
+ let!(:ex_out) {
+ create(:exchange, order_cycle: oc, sender: coordinator, receiver: hub, incoming: false)
+ }
before do
- allow(permissions).to receive(:managed_enterprises) { Enterprise.where(id: [coordinator]) }
+ allow(permissions).to receive(:managed_enterprises) {
+ Enterprise.where(id: [coordinator])
+ }
end
it "returns all exchanges in the order cycle, regardless of hubE permissions" do
@@ -320,14 +376,19 @@ module OpenFoodNetwork
end
describe "as the manager of a hub" do
- let!(:ex_in) { create(:exchange, order_cycle: oc, sender: producer, receiver: coordinator, incoming: true) }
+ let!(:ex_in) {
+ create(:exchange, order_cycle: oc, sender: producer, receiver: coordinator,
+ incoming: true)
+ }
before do
allow(permissions).to receive(:managed_enterprises) { Enterprise.where(id: [hub]) }
end
context "where my hub is in the order cycle" do
- let!(:ex_out) { create(:exchange, order_cycle: oc, sender: coordinator, receiver: hub, incoming: false) }
+ let!(:ex_out) {
+ create(:exchange, order_cycle: oc, sender: coordinator, receiver: hub, incoming: false)
+ }
it "returns my hub's outgoing exchange" do
expect(permissions.visible_exchanges).to eq([ex_out])
@@ -335,7 +396,8 @@ module OpenFoodNetwork
context "where my hub has been granted P-OC by an incoming producer" do
before do
- create(:enterprise_relationship, parent: producer, child: hub, permissions_list: [:add_to_order_cycle])
+ create(:enterprise_relationship, parent: producer, child: hub,
+ permissions_list: [:add_to_order_cycle])
end
it "returns the producer's incoming exchange" do
@@ -361,7 +423,9 @@ module OpenFoodNetwork
context "where my hub's outgoing exchange contains variants of a producer I don't manage and has not given my hub P-OC" do
let!(:product) { create(:product, supplier: producer) }
let!(:variant) { create(:variant, product: product) }
- let!(:ex_out) { create(:exchange, order_cycle: oc, sender: coordinator, receiver: hub, incoming: true) }
+ let!(:ex_out) {
+ create(:exchange, order_cycle: oc, sender: coordinator, receiver: hub, incoming: true)
+ }
before { ex_out.variants << variant }
it "returns incoming exchanges supplying the variants in my outgoing exchange" do
@@ -372,14 +436,19 @@ module OpenFoodNetwork
end
describe "as the manager of a producer" do
- let!(:ex_out) { create(:exchange, order_cycle: oc, sender: coordinator, receiver: hub, incoming: false) }
+ let!(:ex_out) {
+ create(:exchange, order_cycle: oc, sender: coordinator, receiver: hub, incoming: false)
+ }
before do
allow(permissions).to receive(:managed_enterprises) { Enterprise.where(id: [producer]) }
end
context "where my producer supplies to the order cycle" do
- let!(:ex_in) { create(:exchange, order_cycle: oc, sender: producer, receiver: coordinator, incoming: true) }
+ let!(:ex_in) {
+ create(:exchange, order_cycle: oc, sender: producer, receiver: coordinator,
+ incoming: true)
+ }
it "returns my producer's incoming exchange" do
expect(permissions.visible_exchanges).to eq([ex_in])
@@ -387,7 +456,8 @@ module OpenFoodNetwork
context "my producer has granted P-OC to an outgoing hub" do
before do
- create(:enterprise_relationship, parent: producer, child: hub, permissions_list: [:add_to_order_cycle])
+ create(:enterprise_relationship, parent: producer, child: hub,
+ permissions_list: [:add_to_order_cycle])
end
it "returns the hub's outgoing exchange" do
@@ -416,7 +486,10 @@ module OpenFoodNetwork
before { ex_out.variants << variant }
context "where my producer supplies to the order cycle" do
- let!(:ex_in) { create(:exchange, order_cycle: oc, sender: producer, receiver: coordinator, incoming: true) }
+ let!(:ex_in) {
+ create(:exchange, order_cycle: oc, sender: producer, receiver: coordinator,
+ incoming: true)
+ }
it "returns the outgoing exchange" do
expect(permissions.visible_exchanges).to include ex_out
@@ -442,7 +515,9 @@ module OpenFoodNetwork
describe "incoming exchanges" do
context "as a manager of the coordinator" do
before do
- allow(permissions).to receive(:managed_enterprises) { Enterprise.where(id: [coordinator]) }
+ allow(permissions).to receive(:managed_enterprises) {
+ Enterprise.where(id: [coordinator])
+ }
end
it "returns all variants belonging to the sending producer" do
@@ -454,7 +529,9 @@ module OpenFoodNetwork
context "as a manager of the producer" do
before do
- allow(permissions).to receive(:managed_enterprises) { Enterprise.where(id: [producer1]) }
+ allow(permissions).to receive(:managed_enterprises) {
+ Enterprise.where(id: [producer1])
+ }
end
it "returns all variants belonging to the sending producer" do
@@ -467,11 +544,15 @@ module OpenFoodNetwork
context "as a manager of a hub which has been granted P-OC by the producer" do
before do
allow(permissions).to receive(:managed_enterprises) { Enterprise.where(id: [hub]) }
- create(:enterprise_relationship, parent: producer1, child: hub, permissions_list: [:add_to_order_cycle])
+ create(:enterprise_relationship, parent: producer1, child: hub,
+ permissions_list: [:add_to_order_cycle])
end
context "where the hub is in the order cycle" do
- let!(:ex) { create(:exchange, order_cycle: oc, sender: coordinator, receiver: hub, incoming: false) }
+ let!(:ex) {
+ create(:exchange, order_cycle: oc, sender: coordinator, receiver: hub,
+ incoming: false)
+ }
it "returns variants produced by that producer only" do
visible = permissions.visible_variants_for_incoming_exchanges_from(producer1)
@@ -494,8 +575,11 @@ module OpenFoodNetwork
describe "outgoing exchanges" do
context "as a manager of the coordinator" do
before do
- allow(permissions).to receive(:managed_enterprises) { Enterprise.where(id: [coordinator]) }
- create(:enterprise_relationship, parent: producer1, child: hub, permissions_list: [:add_to_order_cycle])
+ allow(permissions).to receive(:managed_enterprises) {
+ Enterprise.where(id: [coordinator])
+ }
+ create(:enterprise_relationship, parent: producer1, child: hub,
+ permissions_list: [:add_to_order_cycle])
end
it "returns all variants of any producer which has granted the outgoing hub P-OC" do
@@ -522,7 +606,10 @@ module OpenFoodNetwork
# TODO: for backwards compatability, remove later
context "when an exchange exists between the coordinator and the hub within this order cycle" do
- let!(:ex) { create(:exchange, order_cycle: oc, sender: coordinator, receiver: hub, incoming: false) }
+ let!(:ex) {
+ create(:exchange, order_cycle: oc, sender: coordinator, receiver: hub,
+ incoming: false)
+ }
# producer2 produces v2 and has not granted P-OC to hub (or coordinator for that matter)
before { ex.variants << v2 }
@@ -537,7 +624,8 @@ module OpenFoodNetwork
context "as manager of an outgoing hub" do
before do
allow(permissions).to receive(:managed_enterprises) { Enterprise.where(id: [hub]) }
- create(:enterprise_relationship, parent: producer1, child: hub, permissions_list: [:add_to_order_cycle])
+ create(:enterprise_relationship, parent: producer1, child: hub,
+ permissions_list: [:add_to_order_cycle])
end
it "returns all variants of any producer which has granted the outgoing hub P-OC" do
@@ -558,7 +646,10 @@ module OpenFoodNetwork
# TODO: for backwards compatability, remove later
context "when an exchange exists between the coordinator and the hub within this order cycle" do
- let!(:ex) { create(:exchange, order_cycle: oc, sender: coordinator, receiver: hub, incoming: false) }
+ let!(:ex) {
+ create(:exchange, order_cycle: oc, sender: coordinator, receiver: hub,
+ incoming: false)
+ }
# producer2 produces v2 and has not granted P-OC to hub
before { ex.variants << v2 }
@@ -572,12 +663,18 @@ module OpenFoodNetwork
context "as the manager of a producer which has granted P-OC to an outgoing hub" do
before do
- allow(permissions).to receive(:managed_enterprises) { Enterprise.where(id: [producer1]) }
- create(:enterprise_relationship, parent: producer1, child: hub, permissions_list: [:add_to_order_cycle])
+ allow(permissions).to receive(:managed_enterprises) {
+ Enterprise.where(id: [producer1])
+ }
+ create(:enterprise_relationship, parent: producer1, child: hub,
+ permissions_list: [:add_to_order_cycle])
end
context "where my producer is in the order cycle" do
- let!(:ex) { create(:exchange, order_cycle: oc, sender: producer1, receiver: coordinator, incoming: true) }
+ let!(:ex) {
+ create(:exchange, order_cycle: oc, sender: producer1, receiver: coordinator,
+ incoming: true)
+ }
it "returns all of my produced variants" do
visible = permissions.visible_variants_for_outgoing_exchanges_to(hub)
@@ -598,8 +695,11 @@ module OpenFoodNetwork
context "as the manager of a producer which has not granted P-OC to an outgoing hub" do
before do
- allow(permissions).to receive(:managed_enterprises) { Enterprise.where(id: [producer2]) }
- create(:enterprise_relationship, parent: producer1, child: hub, permissions_list: [:add_to_order_cycle])
+ allow(permissions).to receive(:managed_enterprises) {
+ Enterprise.where(id: [producer2])
+ }
+ create(:enterprise_relationship, parent: producer1, child: hub,
+ permissions_list: [:add_to_order_cycle])
end
it "returns an empty array" do
@@ -608,7 +708,10 @@ module OpenFoodNetwork
# TODO: for backwards compatability, remove later
context "but which has variants already in the exchange" do
- let!(:ex) { create(:exchange, order_cycle: oc, sender: coordinator, receiver: hub, incoming: false) }
+ let!(:ex) {
+ create(:exchange, order_cycle: oc, sender: coordinator, receiver: hub,
+ incoming: false)
+ }
# This one won't be in the exchange, and so shouldn't be visible
let!(:v3) { create(:variant, product: create(:simple_product, supplier: producer2)) }
@@ -633,7 +736,9 @@ module OpenFoodNetwork
describe "incoming exchanges" do
context "as a manager of the coordinator" do
before do
- allow(permissions).to receive(:managed_enterprises) { Enterprise.where(id: [coordinator]) }
+ allow(permissions).to receive(:managed_enterprises) {
+ Enterprise.where(id: [coordinator])
+ }
end
it "returns all variants belonging to the sending producer" do
@@ -645,7 +750,9 @@ module OpenFoodNetwork
context "as a manager of the producer" do
before do
- allow(permissions).to receive(:managed_enterprises) { Enterprise.where(id: [producer1]) }
+ allow(permissions).to receive(:managed_enterprises) {
+ Enterprise.where(id: [producer1])
+ }
end
it "returns all variants belonging to the sending producer" do
@@ -658,7 +765,8 @@ module OpenFoodNetwork
context "as a manager of a hub which has been granted P-OC by the producer" do
before do
allow(permissions).to receive(:managed_enterprises) { Enterprise.where(id: [hub]) }
- create(:enterprise_relationship, parent: producer1, child: hub, permissions_list: [:add_to_order_cycle])
+ create(:enterprise_relationship, parent: producer1, child: hub,
+ permissions_list: [:add_to_order_cycle])
end
it "does not return variants produced by that producer" do
@@ -671,8 +779,11 @@ module OpenFoodNetwork
describe "outgoing exchanges" do
context "as a manager of the coordinator" do
before do
- allow(permissions).to receive(:managed_enterprises) { Enterprise.where(id: [coordinator]) }
- create(:enterprise_relationship, parent: producer1, child: hub, permissions_list: [:add_to_order_cycle])
+ allow(permissions).to receive(:managed_enterprises) {
+ Enterprise.where(id: [coordinator])
+ }
+ create(:enterprise_relationship, parent: producer1, child: hub,
+ permissions_list: [:add_to_order_cycle])
end
it "returns all variants of any producer which has granted the outgoing hub P-OC" do
@@ -699,7 +810,10 @@ module OpenFoodNetwork
# TODO: for backwards compatability, remove later
context "when an exchange exists between the coordinator and the hub within this order cycle" do
- let!(:ex) { create(:exchange, order_cycle: oc, sender: coordinator, receiver: hub, incoming: false) }
+ let!(:ex) {
+ create(:exchange, order_cycle: oc, sender: coordinator, receiver: hub,
+ incoming: false)
+ }
# producer2 produces v2 and has not granted P-OC to hub (or coordinator for that matter)
before { ex.variants << v2 }
@@ -714,7 +828,8 @@ module OpenFoodNetwork
context "as manager of an outgoing hub" do
before do
allow(permissions).to receive(:managed_enterprises) { Enterprise.where(id: [hub]) }
- create(:enterprise_relationship, parent: producer1, child: hub, permissions_list: [:add_to_order_cycle])
+ create(:enterprise_relationship, parent: producer1, child: hub,
+ permissions_list: [:add_to_order_cycle])
end
it "returns all variants of any producer which has granted the outgoing hub P-OC" do
@@ -735,7 +850,10 @@ module OpenFoodNetwork
# TODO: for backwards compatability, remove later
context "when an exchange exists between the coordinator and the hub within this order cycle" do
- let!(:ex) { create(:exchange, order_cycle: oc, sender: coordinator, receiver: hub, incoming: false) }
+ let!(:ex) {
+ create(:exchange, order_cycle: oc, sender: coordinator, receiver: hub,
+ incoming: false)
+ }
# producer2 produces v2 and has not granted P-OC to hub
before { ex.variants << v2 }
@@ -749,16 +867,23 @@ module OpenFoodNetwork
context "as the manager of a producer which has granted P-OC to an outgoing hub" do
before do
- allow(permissions).to receive(:managed_enterprises) { Enterprise.where(id: [producer1]) }
- create(:enterprise_relationship, parent: producer1, child: hub, permissions_list: [:add_to_order_cycle])
+ allow(permissions).to receive(:managed_enterprises) {
+ Enterprise.where(id: [producer1])
+ }
+ create(:enterprise_relationship, parent: producer1, child: hub,
+ permissions_list: [:add_to_order_cycle])
end
context "where my producer is in the order cycle" do
- let!(:ex) { create(:exchange, order_cycle: oc, sender: producer1, receiver: coordinator, incoming: true) }
+ let!(:ex) {
+ create(:exchange, order_cycle: oc, sender: producer1, receiver: coordinator,
+ incoming: true)
+ }
context "where the outgoing hub has granted P-OC to my producer" do
before do
- create(:enterprise_relationship, parent: hub, child: producer1, permissions_list: [:add_to_order_cycle])
+ create(:enterprise_relationship, parent: hub, child: producer1,
+ permissions_list: [:add_to_order_cycle])
end
it "returns all of my produced variants" do
@@ -790,8 +915,11 @@ module OpenFoodNetwork
context "as the manager of a producer which has not granted P-OC to an outgoing hub" do
before do
- allow(permissions).to receive(:managed_enterprises) { Enterprise.where(id: [producer2]) }
- create(:enterprise_relationship, parent: producer1, child: hub, permissions_list: [:add_to_order_cycle])
+ allow(permissions).to receive(:managed_enterprises) {
+ Enterprise.where(id: [producer2])
+ }
+ create(:enterprise_relationship, parent: producer1, child: hub,
+ permissions_list: [:add_to_order_cycle])
end
it "returns an empty array" do
@@ -800,7 +928,10 @@ module OpenFoodNetwork
# TODO: for backwards compatability, remove later
context "but which has variants already in the exchange" do
- let!(:ex) { create(:exchange, order_cycle: oc, sender: coordinator, receiver: hub, incoming: false) }
+ let!(:ex) {
+ create(:exchange, order_cycle: oc, sender: coordinator, receiver: hub,
+ incoming: false)
+ }
# This one won't be in the exchange, and so shouldn't be visible
let!(:v3) { create(:variant, product: create(:simple_product, supplier: producer2)) }
diff --git a/spec/lib/open_food_network/order_grouper_spec.rb b/spec/lib/open_food_network/order_grouper_spec.rb
index 734d906c0d..db6538efec 100644
--- a/spec/lib/open_food_network/order_grouper_spec.rb
+++ b/spec/lib/open_food_network/order_grouper_spec.rb
@@ -11,9 +11,29 @@ module OpenFoodNetwork
context "constructing the table" do
it "should build a tree then build a table" do
- rules = [{ group_by: proc { |sentence| sentence.paragraph.chapter }, sort_by: proc { |chapter| chapter.name }, summary_columns: [proc { |is| is.first.paragraph.chapter.name }, proc { |_is| "TOTAL" }, proc { |_is| "" }, proc { |is| is.sum(&:property1) }] },
- { group_by: proc { |sentence| sentence.paragraph }, sort_by: proc { |paragraph| paragraph.name } }]
- columns = [proc { |is| is.first.paragraph.chapter.name }, proc { |is| is.first.paragraph.name }, proc { |is| is.first.name }, proc { |is| is.sum(&:property1) }]
+ rules = [{ group_by: proc { |sentence|
+ sentence.paragraph.chapter
+ }, sort_by: proc { |chapter|
+ chapter.name
+ }, summary_columns: [proc { |is|
+ is.first.paragraph.chapter.name
+ }, proc { |_is|
+ "TOTAL"
+ }, proc { |_is|
+ ""
+ }, proc { |is|
+ is.sum(&:property1)
+ }] },
+ { group_by: proc { |sentence| sentence.paragraph }, sort_by: proc { |paragraph|
+ paragraph.name
+ } }]
+ columns = [proc { |is| is.first.paragraph.chapter.name }, proc { |is|
+ is.first.paragraph.name
+ }, proc { |is|
+ is.first.name
+ }, proc { |is|
+ is.sum(&:property1)
+ }]
subject = OrderGrouper.new rules, columns
@@ -64,7 +84,8 @@ module OpenFoodNetwork
subject = OrderGrouper.new @rules, @columns
grouped_tree = double(:grouped_tree)
- expect(subject).to receive(:group_and_sort).with(@rule1, @rules[1..-1], @items).and_return(grouped_tree)
+ expect(subject).to receive(:group_and_sort).with(@rule1, @rules[1..-1],
+ @items).and_return(grouped_tree)
expect(subject.build_tree(@items, @rules)).to eq(grouped_tree)
end
@@ -79,7 +100,9 @@ module OpenFoodNetwork
groups = double(:groups)
expect(@items).to receive(:group_by).and_return(groups)
sorted_groups = {}
- 1.upto(number_of_categories) { |i| sorted_groups[i] = double(:group, name: "Group " + i.to_s ) }
+ 1.upto(number_of_categories) { |i|
+ sorted_groups[i] = double(:group, name: "Group " + i.to_s )
+ }
expect(groups).to receive(:sort_by).and_return(sorted_groups)
group = { group1: 1, group2: 2, group3: 3 }
expect(subject).to receive(:build_tree).exactly(number_of_categories).times.and_return(group)
@@ -133,7 +156,8 @@ module OpenFoodNetwork
end
it "should return an extra row when a :summary_row key appears in a given Hash" do
- groups = { items1: @items1, items2: @items2, items3: @items3, summary_row: { items: { items2: @items2, items3: @items3 }, columns: @sumcols } }
+ groups = { items1: @items1, items2: @items2, items3: @items3,
+ summary_row: { items: { items2: @items2, items3: @items3 }, columns: @sumcols } }
subject = OrderGrouper.new @rules, @columns
diff --git a/spec/lib/open_food_network/orders_and_fulfillments_report_spec.rb b/spec/lib/open_food_network/orders_and_fulfillments_report_spec.rb
index 88abc87c69..b87d872a0e 100644
--- a/spec/lib/open_food_network/orders_and_fulfillments_report_spec.rb
+++ b/spec/lib/open_food_network/orders_and_fulfillments_report_spec.rb
@@ -61,7 +61,9 @@ describe OpenFoodNetwork::OrdersAndFulfillmentsReport do
ship_address: create(:address)
)
}
- let(:li2) { build(:line_item_with_shipment, product: create(:simple_product, supplier: s1)) }
+ let(:li2) {
+ build(:line_item_with_shipment, product: create(:simple_product, supplier: s1))
+ }
before do
o2.line_items << li2
@@ -101,7 +103,9 @@ describe OpenFoodNetwork::OrdersAndFulfillmentsReport do
ship_address: create(:address)
)
}
- let(:li2) { build(:line_item_with_shipment, product: create(:simple_product, supplier: s1)) }
+ let(:li2) {
+ build(:line_item_with_shipment, product: create(:simple_product, supplier: s1))
+ }
before do
o2.line_items << li2
@@ -215,7 +219,8 @@ describe OpenFoodNetwork::OrdersAndFulfillmentsReport do
# Add a second line item for Fuji variant to the order, to test grouping in this edge case.
order.line_items << build(:line_item_with_shipment, variant: fuji, price: nil, quantity: 4)
- second_order.line_items << build(:line_item_with_shipment, variant: fuji, price: nil, quantity: 8)
+ second_order.line_items << build(:line_item_with_shipment, variant: fuji, price: nil,
+ quantity: 8)
end
it "groups line items by variant and order" do
diff --git a/spec/lib/open_food_network/permissions_spec.rb b/spec/lib/open_food_network/permissions_spec.rb
index 867437b7f1..aab09eceb8 100644
--- a/spec/lib/open_food_network/permissions_spec.rb
+++ b/spec/lib/open_food_network/permissions_spec.rb
@@ -16,7 +16,8 @@ module OpenFoodNetwork
before { allow(user).to receive(:admin?) { true } }
it "returns all enterprises" do
- expect(permissions.send(:managed_and_related_enterprises_granting, :some_permission)).to match_array [e1, e2]
+ expect(permissions.send(:managed_and_related_enterprises_granting,
+ :some_permission)).to match_array [e1, e2]
end
end
@@ -26,8 +27,11 @@ module OpenFoodNetwork
it "returns only my managed enterprises any that have granting them P-OC" do
expect(permissions).to receive(:managed_enterprises) { Enterprise.where(id: e1) }
- expect(permissions).to receive(:related_enterprises_granting).with(:some_permission) { Enterprise.where(id: e3).select(:id) }
- expect(permissions.send(:managed_and_related_enterprises_granting, :some_permission)).to match_array [e1, e3]
+ expect(permissions).to receive(:related_enterprises_granting).with(:some_permission) {
+ Enterprise.where(id: e3).select(:id)
+ }
+ expect(permissions.send(:managed_and_related_enterprises_granting,
+ :some_permission)).to match_array [e1, e3]
end
end
end
@@ -37,7 +41,8 @@ module OpenFoodNetwork
before { allow(user).to receive(:admin?) { true } }
it "returns all enterprises" do
- expect(permissions.send(:managed_and_related_enterprises_granting, :some_permission)).to match_array [e1, e2]
+ expect(permissions.send(:managed_and_related_enterprises_granting,
+ :some_permission)).to match_array [e1, e2]
end
end
@@ -48,9 +53,14 @@ module OpenFoodNetwork
it "returns only my managed enterprises any that have granting them P-OC" do
expect(permissions).to receive(:managed_enterprises) { Enterprise.where(id: e1) }
- expect(permissions).to receive(:related_enterprises_granting).with(:some_permission) { Enterprise.where(id: e3).select(:id) }
- expect(permissions).to receive(:related_enterprises_granted).with(:some_permission) { Enterprise.where(id: e4).select(:id) }
- expect(permissions.send(:managed_and_related_enterprises_with, :some_permission)).to match_array [e1, e3, e4]
+ expect(permissions).to receive(:related_enterprises_granting).with(:some_permission) {
+ Enterprise.where(id: e3).select(:id)
+ }
+ expect(permissions).to receive(:related_enterprises_granted).with(:some_permission) {
+ Enterprise.where(id: e4).select(:id)
+ }
+ expect(permissions.send(:managed_and_related_enterprises_with,
+ :some_permission)).to match_array [e1, e3, e4]
end
end
end
@@ -151,7 +161,9 @@ module OpenFoodNetwork
}
before do
- allow(permissions).to receive(:managed_enterprises) { Enterprise.where(id: producer_managed.id) }
+ allow(permissions).to receive(:managed_enterprises) {
+ Enterprise.where(id: producer_managed.id)
+ }
end
it "does not allow the user to create variant overrides for the hub" do
@@ -161,7 +173,9 @@ module OpenFoodNetwork
it "does not return managed producers (ie. only uses explicitly granted VO permissions)" do
producer2 = create(:supplier_enterprise)
- allow(permissions).to receive(:managed_enterprises) { Enterprise.where(id: [hub, producer2]) }
+ allow(permissions).to receive(:managed_enterprises) {
+ Enterprise.where(id: [hub, producer2])
+ }
expect(permissions.variant_override_enterprises_per_hub[hub.id]).to_not include producer2.id
end
@@ -179,7 +193,9 @@ module OpenFoodNetwork
before do
allow(permissions).to receive(:managed_enterprise_products) { Spree::Product.where('1=0') }
- allow(permissions).to receive(:related_enterprises_granting).with(:manage_products) { Enterprise.where("1=0").select(:id) }
+ allow(permissions).to receive(:related_enterprises_granting).with(:manage_products) {
+ Enterprise.where("1=0").select(:id)
+ }
end
it "returns products produced by managed enterprises" do
@@ -201,8 +217,12 @@ module OpenFoodNetwork
before do
allow(permissions).to receive(:managed_enterprise_products) { Spree::Product.where("1=0") }
- allow(permissions).to receive(:related_enterprises_granting).with(:manage_products) { Enterprise.where("1=0").select(:id) }
- allow(permissions).to receive(:related_enterprises_granting).with(:add_to_order_cycle) { Enterprise.where("1=0").select(:id) }
+ allow(permissions).to receive(:related_enterprises_granting).with(:manage_products) {
+ Enterprise.where("1=0").select(:id)
+ }
+ allow(permissions).to receive(:related_enterprises_granting).with(:add_to_order_cycle) {
+ Enterprise.where("1=0").select(:id)
+ }
end
it "returns products produced by managed enterprises" do
@@ -239,7 +259,9 @@ module OpenFoodNetwork
########################################
describe "finding related enterprises with a particular permission" do
- let!(:er) { create(:enterprise_relationship, parent: e1, child: e2, permissions_list: [permission]) }
+ let!(:er) {
+ create(:enterprise_relationship, parent: e1, child: e2, permissions_list: [permission])
+ }
it "returns the enterprises" do
allow(permissions).to receive(:managed_enterprises) { Enterprise.where(id: e2) }
@@ -255,7 +277,9 @@ module OpenFoodNetwork
describe "finding enterprises that are managed or with a particular permission" do
before do
allow(permissions).to receive(:managed_enterprises) { Enterprise.where('1=0') }
- allow(permissions).to receive(:related_enterprises_granting) { Enterprise.where('1=0').select(:id) }
+ allow(permissions).to receive(:related_enterprises_granting) {
+ Enterprise.where('1=0').select(:id)
+ }
allow(permissions).to receive(:admin?) { false }
end
diff --git a/spec/lib/open_food_network/products_and_inventory_report_spec.rb b/spec/lib/open_food_network/products_and_inventory_report_spec.rb
index a9a3cd7715..48a1ba27e1 100644
--- a/spec/lib/open_food_network/products_and_inventory_report_spec.rb
+++ b/spec/lib/open_food_network/products_and_inventory_report_spec.rb
@@ -36,10 +36,15 @@ module OpenFoodNetwork
count_on_hand: 10,
price: 100)
allow(variant).to receive_message_chain(:product, :supplier, :name).and_return("Supplier")
- allow(variant).to receive_message_chain(:product, :supplier, :address, :city).and_return("A city")
+ allow(variant).to receive_message_chain(:product, :supplier, :address,
+ :city).and_return("A city")
allow(variant).to receive_message_chain(:product, :name).and_return("Product Name")
- allow(variant).to receive_message_chain(:product, :properties).and_return [double(name: "property1"), double(name: "property2")]
- allow(variant).to receive_message_chain(:product, :taxons).and_return [double(name: "taxon1"), double(name: "taxon2")]
+ allow(variant).to receive_message_chain(:product,
+ :properties).and_return [double(name: "property1"),
+ double(name: "property2")]
+ allow(variant).to receive_message_chain(:product,
+ :taxons).and_return [double(name: "taxon1"),
+ double(name: "taxon2")]
allow(variant).to receive_message_chain(:product, :group_buy_unit_size).and_return(21)
allow(subject).to receive(:variants).and_return [variant]
@@ -121,7 +126,8 @@ module OpenFoodNetwork
distributor = create(:distributor_enterprise)
product1 = create(:simple_product, supplier: supplier)
product2 = create(:simple_product, supplier: supplier)
- order_cycle = create(:simple_order_cycle, suppliers: [supplier], distributors: [distributor], variants: [product2.variants.first])
+ order_cycle = create(:simple_order_cycle, suppliers: [supplier],
+ distributors: [distributor], variants: [product2.variants.first])
allow(subject).to receive(:params).and_return(distributor_id: distributor.id)
expect(subject.filter(variants)).to eq([product2.variants.first])
@@ -131,7 +137,8 @@ module OpenFoodNetwork
distributor = create(:distributor_enterprise)
product = create(:simple_product, supplier: supplier, price: 5)
variant = product.variants.first
- order_cycle = create(:simple_order_cycle, suppliers: [supplier], distributors: [distributor], variants: [product.variants.first])
+ order_cycle = create(:simple_order_cycle, suppliers: [supplier],
+ distributors: [distributor], variants: [product.variants.first])
create(:variant_override, hub: distributor, variant: variant, price: 2)
result = subject.filter(variants)
@@ -143,7 +150,8 @@ module OpenFoodNetwork
distributor = create(:distributor_enterprise)
product = create(:simple_product, supplier: supplier, price: 5)
variant = product.variants.first
- order_cycle = create(:simple_order_cycle, suppliers: [supplier], distributors: [distributor], variants: [product.variants.first])
+ order_cycle = create(:simple_order_cycle, suppliers: [supplier],
+ distributors: [distributor], variants: [product.variants.first])
create(:variant_override, hub: distributor, variant: variant, price: 2)
allow(subject).to receive(:params).and_return(distributor_id: distributor.id)
@@ -156,7 +164,8 @@ module OpenFoodNetwork
distributor = create(:distributor_enterprise)
product1 = create(:simple_product, supplier: supplier)
product2 = create(:simple_product, supplier: supplier)
- order_cycle = create(:simple_order_cycle, suppliers: [supplier], distributors: [distributor], variants: [product1.variants.first])
+ order_cycle = create(:simple_order_cycle, suppliers: [supplier],
+ distributors: [distributor], variants: [product1.variants.first])
allow(subject).to receive(:params).and_return(order_cycle_id: order_cycle.id)
expect(subject.filter(variants)).to eq([product1.variants.first])
@@ -169,10 +178,14 @@ module OpenFoodNetwork
other_distributor = create(:distributor_enterprise)
other_supplier = create(:supplier_enterprise)
not_filtered_variant = create(:simple_product, supplier: supplier).variants.first
- variant_filtered_by_order_cycle = create(:simple_product, supplier: supplier).variants.first
- variant_filtered_by_distributor = create(:simple_product, supplier: supplier).variants.first
- variant_filtered_by_supplier = create(:simple_product, supplier: other_supplier).variants.first
- variant_filtered_by_stock = create(:simple_product, supplier: supplier, on_hand: 0).variants.first
+ variant_filtered_by_order_cycle = create(:simple_product,
+ supplier: supplier).variants.first
+ variant_filtered_by_distributor = create(:simple_product,
+ supplier: supplier).variants.first
+ variant_filtered_by_supplier = create(:simple_product,
+ supplier: other_supplier).variants.first
+ variant_filtered_by_stock = create(:simple_product, supplier: supplier,
+ on_hand: 0).variants.first
# This OC contains all products except the one that should be filtered
# by order cycle. We create a separate OC further down to proof that
diff --git a/spec/lib/open_food_network/reports/line_items_spec.rb b/spec/lib/open_food_network/reports/line_items_spec.rb
index 63d9696f4b..34f8f359bf 100644
--- a/spec/lib/open_food_network/reports/line_items_spec.rb
+++ b/spec/lib/open_food_network/reports/line_items_spec.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
require 'spec_helper'
require 'open_food_network/reports/line_items'
diff --git a/spec/lib/open_food_network/scope_variant_to_hub_spec.rb b/spec/lib/open_food_network/scope_variant_to_hub_spec.rb
index 9f25e6788c..930c078f29 100644
--- a/spec/lib/open_food_network/scope_variant_to_hub_spec.rb
+++ b/spec/lib/open_food_network/scope_variant_to_hub_spec.rb
@@ -9,10 +9,18 @@ module OpenFoodNetwork
let(:v) { create(:variant, price: 11.11, on_hand: 1, on_demand: true, sku: "VARIANTSKU") }
let(:v2) { create(:variant, price: 22.22, on_hand: 5) }
let(:v3) { create(:variant, price: 33.33, on_hand: 6) }
- let(:vo) { create(:variant_override, hub: hub, variant: v, price: 22.22, count_on_hand: 2, on_demand: false, sku: "VOSKU") }
- let(:vo2) { create(:variant_override, hub: hub, variant: v2, price: 33.33, count_on_hand: nil, on_demand: true) }
- let(:vo3) { create(:variant_override, hub: hub, variant: v3, price: 44.44, count_on_hand: 16) }
- let(:vo_price_only) { create(:variant_override, :use_producer_stock_settings, hub: hub, variant: v, price: 22.22) }
+ let(:vo) {
+ create(:variant_override, hub: hub, variant: v, price: 22.22, count_on_hand: 2, on_demand: false,
+ sku: "VOSKU")
+ }
+ let(:vo2) {
+ create(:variant_override, hub: hub, variant: v2, price: 33.33, count_on_hand: nil,
+ on_demand: true)
+ }
+ let(:vo3) { create(:variant_override, hub: hub, variant: v3, price: 44.44, count_on_hand: 16) }
+ let(:vo_price_only) {
+ create(:variant_override, :use_producer_stock_settings, hub: hub, variant: v, price: 22.22)
+ }
let(:scoper) { ScopeVariantToHub.new(hub) }
describe "overriding price" do
diff --git a/spec/lib/open_food_network/tag_rule_applicator_spec.rb b/spec/lib/open_food_network/tag_rule_applicator_spec.rb
index 7bc180a52c..82d7fac903 100644
--- a/spec/lib/open_food_network/tag_rule_applicator_spec.rb
+++ b/spec/lib/open_food_network/tag_rule_applicator_spec.rb
@@ -6,12 +6,30 @@ require 'spec_helper'
module OpenFoodNetwork
describe TagRuleApplicator do
let!(:enterprise) { create(:distributor_enterprise) }
- let!(:oc_tag_rule) { create(:filter_order_cycles_tag_rule, enterprise: enterprise, priority: 6, preferred_customer_tags: "tag1", preferred_exchange_tags: "tag1", preferred_matched_order_cycles_visibility: "visible" ) }
- let!(:product_tag_rule1) { create(:filter_products_tag_rule, enterprise: enterprise, priority: 5, preferred_customer_tags: "tag1", preferred_variant_tags: "tag1", preferred_matched_variants_visibility: "visible" ) }
- let!(:product_tag_rule2) { create(:filter_products_tag_rule, enterprise: enterprise, priority: 4, preferred_customer_tags: "tag1", preferred_variant_tags: "tag3", preferred_matched_variants_visibility: "hidden" ) }
- let!(:product_tag_rule3) { create(:filter_products_tag_rule, enterprise: enterprise, priority: 3, preferred_customer_tags: "tag2", preferred_variant_tags: "tag1", preferred_matched_variants_visibility: "visible" ) }
- let!(:default_product_tag_rule) { create(:filter_products_tag_rule, enterprise: enterprise, priority: 2, is_default: true, preferred_variant_tags: "tag1", preferred_matched_variants_visibility: "hidden" ) }
- let!(:sm_tag_rule) { create(:filter_shipping_methods_tag_rule, enterprise: enterprise, priority: 1, preferred_customer_tags: "tag1", preferred_shipping_method_tags: "tag1", preferred_matched_shipping_methods_visibility: "visible" ) }
+ let!(:oc_tag_rule) {
+ create(:filter_order_cycles_tag_rule, enterprise: enterprise, priority: 6,
+ preferred_customer_tags: "tag1", preferred_exchange_tags: "tag1", preferred_matched_order_cycles_visibility: "visible" )
+ }
+ let!(:product_tag_rule1) {
+ create(:filter_products_tag_rule, enterprise: enterprise, priority: 5,
+ preferred_customer_tags: "tag1", preferred_variant_tags: "tag1", preferred_matched_variants_visibility: "visible" )
+ }
+ let!(:product_tag_rule2) {
+ create(:filter_products_tag_rule, enterprise: enterprise, priority: 4,
+ preferred_customer_tags: "tag1", preferred_variant_tags: "tag3", preferred_matched_variants_visibility: "hidden" )
+ }
+ let!(:product_tag_rule3) {
+ create(:filter_products_tag_rule, enterprise: enterprise, priority: 3,
+ preferred_customer_tags: "tag2", preferred_variant_tags: "tag1", preferred_matched_variants_visibility: "visible" )
+ }
+ let!(:default_product_tag_rule) {
+ create(:filter_products_tag_rule, enterprise: enterprise, priority: 2, is_default: true,
+ preferred_variant_tags: "tag1", preferred_matched_variants_visibility: "hidden" )
+ }
+ let!(:sm_tag_rule) {
+ create(:filter_shipping_methods_tag_rule, enterprise: enterprise, priority: 1,
+ preferred_customer_tags: "tag1", preferred_shipping_method_tags: "tag1", preferred_matched_shipping_methods_visibility: "visible" )
+ }
describe "initialisation" do
context "when enterprise is nil" do
@@ -25,12 +43,16 @@ module OpenFoodNetwork
end
context "when rule_type does not match an existing rule type" do
- let(:applicator) { OpenFoodNetwork::TagRuleApplicator.new(enterprise, "FilterSomething", ["tag1"]) }
+ let(:applicator) {
+ OpenFoodNetwork::TagRuleApplicator.new(enterprise, "FilterSomething", ["tag1"])
+ }
it { expect{ applicator }.to raise_error NameError }
end
context "when enterprise and rule_type are present" do
- let(:applicator) { OpenFoodNetwork::TagRuleApplicator.new(enterprise, "FilterProducts", customer_tags) }
+ let(:applicator) {
+ OpenFoodNetwork::TagRuleApplicator.new(enterprise, "FilterProducts", customer_tags)
+ }
context "when the customer tags are nil" do
let!(:customer_tags) { nil }
@@ -72,7 +94,8 @@ module OpenFoodNetwork
end
it "selects only rules of the specified type, in order of priority" do
- expect(rules).to eq [default_product_tag_rule, product_tag_rule3, product_tag_rule2, product_tag_rule1]
+ expect(rules).to eq [default_product_tag_rule, product_tag_rule3, product_tag_rule2,
+ product_tag_rule1]
end
it "splits rules into those which match customer tags and those which don't, in order of priority" do
@@ -183,9 +206,15 @@ module OpenFoodNetwork
end
describe "reject?" do
- let(:applicator) { OpenFoodNetwork::TagRuleApplicator.new(enterprise, "FilterProducts", ["tag1"]) }
- let(:customer_rule) { double(:customer_rule, reject_matched?: "customer_rule.reject_matched?" ) }
- let(:default_rule) { double(:customer_rule, reject_matched?: "default_rule.reject_matched?" ) }
+ let(:applicator) {
+ OpenFoodNetwork::TagRuleApplicator.new(enterprise, "FilterProducts", ["tag1"])
+ }
+ let(:customer_rule) {
+ double(:customer_rule, reject_matched?: "customer_rule.reject_matched?" )
+ }
+ let(:default_rule) {
+ double(:customer_rule, reject_matched?: "default_rule.reject_matched?" )
+ }
let(:dummy) { double(:dummy) }
before{ allow(applicator).to receive(:customer_rules) { [customer_rule] } }
@@ -221,22 +250,36 @@ module OpenFoodNetwork
end
describe "smoke test for products" do
- let(:product1) { { :id => 1, :name => 'product 1', "variants" => [{ :id => 4, "tag_list" => ["tag1"] }] } }
- let(:product2) { { :id => 2, :name => 'product 2', "variants" => [{ :id => 5, "tag_list" => ["tag1"] }, { :id => 9, "tag_list" => ["tag2"] }] } }
- let(:product3) { { :id => 3, :name => 'product 3', "variants" => [{ :id => 6, "tag_list" => ["tag3"] }] } }
+ let(:product1) {
+ { :id => 1, :name => 'product 1', "variants" => [{ :id => 4, "tag_list" => ["tag1"] }] }
+ }
+ let(:product2) {
+ { :id => 2, :name => 'product 2',
+ "variants" => [{ :id => 5, "tag_list" => ["tag1"] }, { :id => 9, "tag_list" => ["tag2"] }] }
+ }
+ let(:product3) {
+ { :id => 3, :name => 'product 3', "variants" => [{ :id => 6, "tag_list" => ["tag3"] }] }
+ }
let!(:products_array) { [product1, product2, product3] }
context "when customer tags don't match any rules" do
- let(:applicator) { OpenFoodNetwork::TagRuleApplicator.new(enterprise, "FilterProducts", ["lalalala"]) }
+ let(:applicator) {
+ OpenFoodNetwork::TagRuleApplicator.new(enterprise, "FilterProducts", ["lalalala"])
+ }
it "applies the default rule" do
applicator.filter!(products_array)
- expect(products_array).to eq [{ :id => 2, :name => 'product 2', "variants" => [{ :id => 9, "tag_list" => ["tag2"] }] }, product3]
+ expect(products_array).to eq [
+ { :id => 2, :name => 'product 2',
+ "variants" => [{ :id => 9, "tag_list" => ["tag2"] }] }, product3
+ ]
end
end
context "when customer tags match one or more rules" do
- let(:applicator) { OpenFoodNetwork::TagRuleApplicator.new(enterprise, "FilterProducts", ["tag1"]) }
+ let(:applicator) {
+ OpenFoodNetwork::TagRuleApplicator.new(enterprise, "FilterProducts", ["tag1"])
+ }
it "applies those rules" do
# product_tag_rule1 and product_tag_rule2 are being applied
diff --git a/spec/lib/open_food_network/xero_invoices_report_spec.rb b/spec/lib/open_food_network/xero_invoices_report_spec.rb
index 0e746cbc74..bcc77347c2 100644
--- a/spec/lib/open_food_network/xero_invoices_report_spec.rb
+++ b/spec/lib/open_food_network/xero_invoices_report_spec.rb
@@ -10,7 +10,10 @@ module OpenFoodNetwork
let(:user) { create(:user) }
describe "option defaults" do
- let(:report) { XeroInvoicesReport.new user, initial_invoice_number: '', invoice_date: '', due_date: '', account_code: '' }
+ let(:report) {
+ XeroInvoicesReport.new user, initial_invoice_number: '', invoice_date: '', due_date: '',
+ account_code: ''
+ }
around { |example| Timecop.travel(Time.zone.local(2015, 5, 5, 14, 0, 0)) { example.run } }
@@ -23,7 +26,10 @@ module OpenFoodNetwork
end
describe "summary rows" do
- let(:report) { XeroInvoicesReport.new user, initial_invoice_number: '', invoice_date: '', due_date: '', account_code: '' }
+ let(:report) {
+ XeroInvoicesReport.new user, initial_invoice_number: '', invoice_date: '', due_date: '',
+ account_code: ''
+ }
let(:order) { double(:order) }
let(:summary_rows) { report.send(:summary_rows_for_order, order, 1, {}) }
diff --git a/spec/lib/stripe/account_connector_spec.rb b/spec/lib/stripe/account_connector_spec.rb
index 54c5091150..2fc37b345d 100644
--- a/spec/lib/stripe/account_connector_spec.rb
+++ b/spec/lib/stripe/account_connector_spec.rb
@@ -53,7 +53,9 @@ module Stripe
context "and the decoded state param contains an 'enterprise_id' key" do
let(:payload) { { enterprise_id: enterprise.permalink } }
- let(:token_response) { { "stripe_user_id" => "some_user_id", "stripe_publishable_key" => "some_key" } }
+ let(:token_response) {
+ { "stripe_user_id" => "some_user_id", "stripe_publishable_key" => "some_key" }
+ }
before do
stub_request(:post, "https://connect.stripe.com/oauth/token").
diff --git a/spec/lib/stripe/webhook_handler_spec.rb b/spec/lib/stripe/webhook_handler_spec.rb
index 381d09f536..d893979507 100644
--- a/spec/lib/stripe/webhook_handler_spec.rb
+++ b/spec/lib/stripe/webhook_handler_spec.rb
@@ -69,7 +69,9 @@ module Stripe
context "when some stripe accounts are destroyed" do
before do
- allow(handler).to receive(:destroy_stripe_accounts_linked_to).with('some.account') { [double(:destroyed_stripe_account)] }
+ allow(handler).to receive(:destroy_stripe_accounts_linked_to).with('some.account') {
+ [double(:destroyed_stripe_account)]
+ }
end
it { expect(handler.send(:deauthorize)).to be :success }
@@ -77,7 +79,9 @@ module Stripe
context "when no stripe accounts are destroyed" do
before do
- allow(handler).to receive(:destroy_stripe_accounts_linked_to).with('some.account') { [] }
+ allow(handler).to receive(:destroy_stripe_accounts_linked_to).with('some.account') {
+ []
+ }
end
it { expect(handler.send(:deauthorize)).to be :ignored }
diff --git a/spec/mailers/order_mailer_spec.rb b/spec/mailers/order_mailer_spec.rb
index e05b71ccb7..a0bcd70912 100644
--- a/spec/mailers/order_mailer_spec.rb
+++ b/spec/mailers/order_mailer_spec.rb
@@ -142,10 +142,14 @@ describe Spree::OrderMailer do
describe "order confimation" do
let(:bill_address) { create(:address) }
- let(:distributor_address) { create(:address, address1: "distributor address", city: 'The Shire', zipcode: "1234") }
+ let(:distributor_address) {
+ create(:address, address1: "distributor address", city: 'The Shire', zipcode: "1234")
+ }
let(:distributor) { create(:distributor_enterprise, address: distributor_address) }
let(:shipping_instructions) { "pick up on thursday please!" }
- let(:ship_address) { create(:address, address1: "distributor address", city: 'The Shire', zipcode: "1234") }
+ let(:ship_address) {
+ create(:address, address1: "distributor address", city: 'The Shire', zipcode: "1234")
+ }
let(:order) {
create(:order_with_line_items, distributor: distributor, bill_address: bill_address, ship_address: ship_address,
special_instructions: shipping_instructions)
diff --git a/spec/mailers/producer_mailer_spec.rb b/spec/mailers/producer_mailer_spec.rb
index b05b59b819..a83a683ac0 100644
--- a/spec/mailers/producer_mailer_spec.rb
+++ b/spec/mailers/producer_mailer_spec.rb
@@ -9,21 +9,32 @@ describe ProducerMailer, type: :mailer do
before { setup_email }
let!(:zone) { create(:zone_with_member) }
- let!(:tax_rate) { create(:tax_rate, included_in_price: true, calculator: Calculator::DefaultTax.new, zone: zone, amount: 0.1) }
+ let!(:tax_rate) {
+ create(:tax_rate, included_in_price: true, calculator: Calculator::DefaultTax.new, zone: zone,
+ amount: 0.1)
+ }
let!(:tax_category) { create(:tax_category, tax_rates: [tax_rate]) }
let(:s1) { create(:supplier_enterprise) }
let(:s2) { create(:supplier_enterprise) }
let(:s3) { create(:supplier_enterprise) }
let(:d1) { create(:distributor_enterprise, charges_sales_tax: true) }
let(:d2) { create(:distributor_enterprise) }
- let(:p1) { create(:product, name: "Zebra", price: 12.34, supplier: s1, tax_category: tax_category) }
+ let(:p1) {
+ create(:product, name: "Zebra", price: 12.34, supplier: s1, tax_category: tax_category)
+ }
let(:p2) { create(:product, name: "Aardvark", price: 23.45, supplier: s2) }
let(:p3) { create(:product, name: "Banana", price: 34.56, supplier: s1) }
let(:p4) { create(:product, name: "coffee", price: 45.67, supplier: s1) }
let(:p5) { create(:product, name: "Daffodil", price: 56.78, supplier: s1) }
let(:order_cycle) { create(:simple_order_cycle) }
- let!(:incoming_exchange) { order_cycle.exchanges.create! sender: s1, receiver: d1, incoming: true, receival_instructions: 'Outside shed.' }
- let!(:outgoing_exchange) { order_cycle.exchanges.create! sender: d1, receiver: d1, incoming: false, pickup_time: 'Tue, 23rd Dec' }
+ let!(:incoming_exchange) {
+ order_cycle.exchanges.create! sender: s1, receiver: d1, incoming: true,
+ receival_instructions: 'Outside shed.'
+ }
+ let!(:outgoing_exchange) {
+ order_cycle.exchanges.create! sender: d1, receiver: d1, incoming: false,
+ pickup_time: 'Tue, 23rd Dec'
+ }
let!(:order) do
order = create(:order, distributor: d1, order_cycle: order_cycle, state: 'complete')
diff --git a/spec/mailers/subscription_mailer_spec.rb b/spec/mailers/subscription_mailer_spec.rb
index 7950663e25..bcfb0d87ec 100644
--- a/spec/mailers/subscription_mailer_spec.rb
+++ b/spec/mailers/subscription_mailer_spec.rb
@@ -192,7 +192,8 @@ describe SubscriptionMailer, type: :mailer do
it "sends the email" do
body = strip_tags(SubscriptionMailer.deliveries.last.body.encoded)
expect(body).to include I18n.t("email_so_failed_payment_intro_html")
- explainer = I18n.t("email_so_failed_payment_explainer_html", distributor: subscription.shop.name)
+ explainer = I18n.t("email_so_failed_payment_explainer_html",
+ distributor: subscription.shop.name)
expect(body).to include strip_tags(explainer)
details = I18n.t("email_so_failed_payment_details_html", distributor: subscription.shop.name)
expect(body).to include strip_tags(details)
@@ -258,7 +259,9 @@ describe SubscriptionMailer, type: :mailer do
allow(summary).to receive(:order_count) { 37 }
allow(summary).to receive(:success_count) { 35 }
allow(summary).to receive(:issue_count) { 2 }
- allow(summary).to receive(:issues) { { processing: { 1 => "Some Error Message", 2 => nil } } }
+ allow(summary).to receive(:issues) {
+ { processing: { 1 => "Some Error Message", 2 => nil } }
+ }
allow(summary).to receive(:orders_affected_by) { [order1, order2] }
end
@@ -371,14 +374,17 @@ describe SubscriptionMailer, type: :mailer do
allow(summary).to receive(:order_count) { 37 }
allow(summary).to receive(:success_count) { 35 }
allow(summary).to receive(:issue_count) { 2 }
- allow(summary).to receive(:issues) { { failed_payment: { 1 => "Some Error Message", 2 => nil } } }
+ allow(summary).to receive(:issues) {
+ { failed_payment: { 1 => "Some Error Message", 2 => nil } }
+ }
allow(summary).to receive(:orders_affected_by) { [order1, order2] }
end
context "when no unrecorded issues are present" do
it "sends the email, which notifies the enterprise that some issues were encountered" do
SubscriptionMailer.confirmation_summary_email(summary).deliver_now
- expect(body).to include I18n.t("#{scope}.confirmation_summary_email.intro", shop: shop.name)
+ expect(body).to include I18n.t("#{scope}.confirmation_summary_email.intro",
+ shop: shop.name)
expect(body).to include I18n.t("#{scope}.summary_overview.total", count: 37)
expect(body).to include I18n.t("#{scope}.summary_overview.success_some", count: 35)
expect(body).to include I18n.t("#{scope}.summary_overview.issues")
diff --git a/spec/migrations/migrate_enterprise_fee_tax_amounts_spec.rb b/spec/migrations/migrate_enterprise_fee_tax_amounts_spec.rb
index 62a6ddf16e..1b9518453d 100644
--- a/spec/migrations/migrate_enterprise_fee_tax_amounts_spec.rb
+++ b/spec/migrations/migrate_enterprise_fee_tax_amounts_spec.rb
@@ -10,13 +10,17 @@ describe MigrateEnterpriseFeeTaxAmounts do
let(:tax_rate_regular) { create(:tax_rate, tax_category: tax_category_regular) }
let(:tax_category_inherited) { create(:tax_category) }
let(:tax_rate_inherited) { create(:tax_rate, tax_category: tax_category_inherited) }
- let(:enterprise_fee_regular) { create(:enterprise_fee, inherits_tax_category: false,
- tax_category: tax_category_regular) }
+ let(:enterprise_fee_regular) {
+ create(:enterprise_fee, inherits_tax_category: false,
+ tax_category: tax_category_regular)
+ }
let(:enterprise_fee_inheriting) { create(:enterprise_fee, inherits_tax_category: true) }
let(:fee_without_tax) { create(:adjustment, originator: enterprise_fee_regular, included_tax: 0) }
let(:fee_regular) { create(:adjustment, originator: enterprise_fee_regular, included_tax: 1.23) }
- let(:fee_inheriting) { create(:adjustment, originator: enterprise_fee_inheriting,
- adjustable: line_item, included_tax: 4.56) }
+ let(:fee_inheriting) {
+ create(:adjustment, originator: enterprise_fee_inheriting,
+ adjustable: line_item, included_tax: 4.56)
+ }
let(:product) { create(:product, tax_category: tax_category_inherited) }
let!(:line_item) { create(:line_item, variant: product.variants.first) }
diff --git a/spec/models/calculator/flexi_rate_spec.rb b/spec/models/calculator/flexi_rate_spec.rb
index 3f351fb94d..81bbc95ee6 100644
--- a/spec/models/calculator/flexi_rate_spec.rb
+++ b/spec/models/calculator/flexi_rate_spec.rb
@@ -29,10 +29,12 @@ describe Calculator::FlexiRate do
end
it "allows creation of new object with all the attributes" do
- Calculator::FlexiRate.new(preferred_first_item: 1, preferred_additional_item: 1, preferred_max_items: 1)
+ Calculator::FlexiRate.new(preferred_first_item: 1, preferred_additional_item: 1,
+ preferred_max_items: 1)
end
context "extends LocalizedNumber" do
- it_behaves_like "a model using the LocalizedNumber module", [:preferred_first_item, :preferred_additional_item]
+ it_behaves_like "a model using the LocalizedNumber module",
+ [:preferred_first_item, :preferred_additional_item]
end
end
diff --git a/spec/models/calculator/price_sack_spec.rb b/spec/models/calculator/price_sack_spec.rb
index f37d614f3a..0034b20963 100644
--- a/spec/models/calculator/price_sack_spec.rb
+++ b/spec/models/calculator/price_sack_spec.rb
@@ -77,6 +77,8 @@ describe Calculator::PriceSack do
end
context "extends LocalizedNumber" do
- it_behaves_like "a model using the LocalizedNumber module", [:preferred_minimal_amount, :preferred_normal_amount, :preferred_discount_amount]
+ it_behaves_like "a model using the LocalizedNumber module",
+ [:preferred_minimal_amount, :preferred_normal_amount,
+ :preferred_discount_amount]
end
end
diff --git a/spec/models/calculator/weight_spec.rb b/spec/models/calculator/weight_spec.rb
index 4ca6d15ab5..620714577b 100644
--- a/spec/models/calculator/weight_spec.rb
+++ b/spec/models/calculator/weight_spec.rb
@@ -174,7 +174,10 @@ describe Calculator::Weight do
end
context "when the product uses item unit" do
- let!(:product_attributes) { { variant_unit: "items", variant_unit_scale: nil, variant_unit_name: "pc", display_as: "pc" } }
+ let!(:product_attributes) {
+ { variant_unit: "items", variant_unit_scale: nil, variant_unit_name: "pc",
+ display_as: "pc" }
+ }
let!(:variant_attributes) { { unit_value: 3.0, weight: 2.5, display_as: "pc" } }
it "is correct" do
@@ -187,7 +190,8 @@ describe Calculator::Weight do
context "when variant_unit is 'items'" do
let(:product) {
- build_stubbed(:product, variant_unit: 'items', variant_unit_scale: nil, variant_unit_name: "bunch")
+ build_stubbed(:product, variant_unit: 'items', variant_unit_scale: nil,
+ variant_unit_name: "bunch")
}
let(:line_item) { build_stubbed(:line_item, variant: variant, quantity: 1) }
@@ -214,7 +218,8 @@ describe Calculator::Weight do
context "when unit_value is nil and variant.weight is present" do
let(:variant) {
- build_stubbed(:variant, product: product, unit_description: "bunches", unit_value: nil, weight: 10.0)
+ build_stubbed(:variant, product: product, unit_description: "bunches", unit_value: nil,
+ weight: 10.0)
}
it "uses the variant weight" do
@@ -226,7 +231,8 @@ describe Calculator::Weight do
context "when unit_value is nil and variant.weight is nil" do
let(:variant) {
- build_stubbed(:variant, product: product, unit_description: "bunches", unit_value: nil, weight: nil)
+ build_stubbed(:variant, product: product, unit_description: "bunches", unit_value: nil,
+ weight: nil)
}
it "uses zero weight" do
diff --git a/spec/models/column_preference_spec.rb b/spec/models/column_preference_spec.rb
index 1e9a1d8fce..108c76b4ac 100644
--- a/spec/models/column_preference_spec.rb
+++ b/spec/models/column_preference_spec.rb
@@ -10,8 +10,14 @@ describe ColumnPreference, type: :model do
end
let(:user) { create(:user) }
- let!(:col1_pref) { ColumnPreference.create(user_id: user.id, action_name: 'some_action', column_name: 'col1', visible: true) }
- let!(:col2_pref) { ColumnPreference.create(user_id: user.id, action_name: 'some_action', column_name: 'col2', visible: false) }
+ let!(:col1_pref) {
+ ColumnPreference.create(user_id: user.id, action_name: 'some_action', column_name: 'col1',
+ visible: true)
+ }
+ let!(:col2_pref) {
+ ColumnPreference.create(user_id: user.id, action_name: 'some_action', column_name: 'col2',
+ visible: false)
+ }
let(:defaults) {
{
col1: { name: "col1", visible: false },
diff --git a/spec/models/concerns/balance_spec.rb b/spec/models/concerns/balance_spec.rb
index b723284456..9531f04816 100644
--- a/spec/models/concerns/balance_spec.rb
+++ b/spec/models/concerns/balance_spec.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
require 'spec_helper'
describe Balance do
diff --git a/spec/models/concerns/order_shipment_spec.rb b/spec/models/concerns/order_shipment_spec.rb
index 9d45f33d1b..2b1aa320d5 100644
--- a/spec/models/concerns/order_shipment_spec.rb
+++ b/spec/models/concerns/order_shipment_spec.rb
@@ -52,7 +52,9 @@ describe OrderShipment do
context "when shipping_method_id is not valid for the order" do
it "returns nil" do
invalid_shipping_method_id = order.shipment.shipping_method.id + 1000
- expect(shipment.shipping_rates).to receive(:find_by).with(shipping_method_id: invalid_shipping_method_id) { nil }
+ expect(shipment.shipping_rates).to receive(:find_by).with(shipping_method_id: invalid_shipping_method_id) {
+ nil
+ }
expect(order.select_shipping_method(invalid_shipping_method_id)).to be_nil
end
diff --git a/spec/models/customer_spec.rb b/spec/models/customer_spec.rb
index 3a8fa36f14..78d9715f50 100644
--- a/spec/models/customer_spec.rb
+++ b/spec/models/customer_spec.rb
@@ -48,7 +48,8 @@ describe Customer, type: :model do
let!(:enterprise) { create(:distributor_enterprise) }
it "associates no user using non-existing email" do
- c = Customer.create(enterprise: enterprise, email: 'some-email-not-associated-with-a-user@email.com')
+ c = Customer.create(enterprise: enterprise,
+ email: 'some-email-not-associated-with-a-user@email.com')
expect(c.user).to be_nil
end
diff --git a/spec/models/enterprise_caching_spec.rb b/spec/models/enterprise_caching_spec.rb
index e5506c46ab..28d1d951c8 100644
--- a/spec/models/enterprise_caching_spec.rb
+++ b/spec/models/enterprise_caching_spec.rb
@@ -51,7 +51,10 @@ describe Enterprise do
describe "with a distributed product" do
let(:product) { create(:simple_product) }
- let(:oc) { create(:simple_order_cycle, distributors: [enterprise], variants: [product.variants.first]) }
+ let(:oc) {
+ create(:simple_order_cycle, distributors: [enterprise],
+ variants: [product.variants.first])
+ }
let(:supplier) { product.supplier }
let!(:classification) { create(:classification, taxon: taxon, product: product) }
let(:property) { product.product_properties.last }
diff --git a/spec/models/enterprise_fee_spec.rb b/spec/models/enterprise_fee_spec.rb
index 1533b29674..2eeb2ae027 100644
--- a/spec/models/enterprise_fee_spec.rb
+++ b/spec/models/enterprise_fee_spec.rb
@@ -31,7 +31,9 @@ describe EnterpriseFee do
describe "for tax_category" do
let(:tax_category) { create(:tax_category) }
- let(:enterprise_fee) { create(:enterprise_fee, tax_category_id: nil, inherits_tax_category: true) }
+ let(:enterprise_fee) {
+ create(:enterprise_fee, tax_category_id: nil, inherits_tax_category: true)
+ }
it "maintains valid tax_category settings" do
# Changing just tax_category, when inheriting
@@ -117,7 +119,8 @@ describe EnterpriseFee do
it "clears adjustments from per-order fees" do
order = create(:order)
enterprise_fee = create(:enterprise_fee)
- enterprise_fee_aplicator = OpenFoodNetwork::EnterpriseFeeApplicator.new(enterprise_fee, nil, 'coordinator')
+ enterprise_fee_aplicator = OpenFoodNetwork::EnterpriseFeeApplicator.new(enterprise_fee, nil,
+ 'coordinator')
enterprise_fee_aplicator.create_order_adjustment(order)
expect do
diff --git a/spec/models/enterprise_relationship_spec.rb b/spec/models/enterprise_relationship_spec.rb
index 619bf4834a..ad2ea9627c 100644
--- a/spec/models/enterprise_relationship_spec.rb
+++ b/spec/models/enterprise_relationship_spec.rb
@@ -35,7 +35,8 @@ describe EnterpriseRelationship do
describe "creating with a permission list" do
context "creating a new list of permissions" do
it "creates a new permission for each item in the list" do
- er = EnterpriseRelationship.create! parent: e1, child: e2, permissions_list: ['one', 'two']
+ er = EnterpriseRelationship.create! parent: e1, child: e2,
+ permissions_list: ['one', 'two']
er.reload
expect(er.permissions.map(&:name)).to match_array ['one', 'two']
end
@@ -48,7 +49,10 @@ describe EnterpriseRelationship do
end
context "updating an existing list of permissions" do
- let(:er) { create(:enterprise_relationship, parent: e1, child: e2, permissions_list: ["one", "two", "three"]) }
+ let(:er) {
+ create(:enterprise_relationship, parent: e1, child: e2,
+ permissions_list: ["one", "two", "three"])
+ }
it "creates a new permission for each item in the list that has no existing permission" do
er.permissions_list = ['four']
er.save!
@@ -149,11 +153,26 @@ describe EnterpriseRelationship do
let(:some_other_producer) { create(:supplier_enterprise) }
context "when variant_override permission is present" do
- let!(:er) { create(:enterprise_relationship, child: hub, parent: producer, permissions_list: [:add_to_order_cycles, :create_variant_overrides] ) }
- let!(:some_other_er) { create(:enterprise_relationship, child: hub, parent: some_other_producer, permissions_list: [:add_to_order_cycles, :create_variant_overrides] ) }
- let!(:vo1) { create(:variant_override, hub: hub, variant: create(:variant, product: create(:product, supplier: producer))) }
- let!(:vo2) { create(:variant_override, hub: hub, variant: create(:variant, product: create(:product, supplier: producer))) }
- let!(:vo3) { create(:variant_override, hub: hub, variant: create(:variant, product: create(:product, supplier: some_other_producer))) }
+ let!(:er) {
+ create(:enterprise_relationship, child: hub, parent: producer,
+ permissions_list: [:add_to_order_cycles, :create_variant_overrides] )
+ }
+ let!(:some_other_er) {
+ create(:enterprise_relationship, child: hub, parent: some_other_producer,
+ permissions_list: [:add_to_order_cycles, :create_variant_overrides] )
+ }
+ let!(:vo1) {
+ create(:variant_override, hub: hub,
+ variant: create(:variant, product: create(:product, supplier: producer)))
+ }
+ let!(:vo2) {
+ create(:variant_override, hub: hub,
+ variant: create(:variant, product: create(:product, supplier: producer)))
+ }
+ let!(:vo3) {
+ create(:variant_override, hub: hub,
+ variant: create(:variant, product: create(:product, supplier: some_other_producer)))
+ }
context "revoking variant override permissions" do
context "when the enterprise relationship is destroyed" do
@@ -190,14 +209,31 @@ describe EnterpriseRelationship do
end
context "when variant_override permission is not present" do
- let!(:er) { create(:enterprise_relationship, child: hub, parent: producer, permissions_list: [:add_to_order_cycles] ) }
- let!(:some_other_er) { create(:enterprise_relationship, child: hub, parent: some_other_producer, permissions_list: [:add_to_order_cycles] ) }
- let!(:vo1) { create(:variant_override, hub: hub, variant: create(:variant, product: create(:product, supplier: producer)), permission_revoked_at: Time.now.in_time_zone) }
- let!(:vo2) { create(:variant_override, hub: hub, variant: create(:variant, product: create(:product, supplier: producer)), permission_revoked_at: Time.now.in_time_zone) }
- let!(:vo3) { create(:variant_override, hub: hub, variant: create(:variant, product: create(:product, supplier: some_other_producer)), permission_revoked_at: Time.now.in_time_zone) }
+ let!(:er) {
+ create(:enterprise_relationship, child: hub, parent: producer,
+ permissions_list: [:add_to_order_cycles] )
+ }
+ let!(:some_other_er) {
+ create(:enterprise_relationship, child: hub, parent: some_other_producer,
+ permissions_list: [:add_to_order_cycles] )
+ }
+ let!(:vo1) {
+ create(:variant_override, hub: hub,
+ variant: create(:variant, product: create(:product, supplier: producer)), permission_revoked_at: Time.now.in_time_zone)
+ }
+ let!(:vo2) {
+ create(:variant_override, hub: hub,
+ variant: create(:variant, product: create(:product, supplier: producer)), permission_revoked_at: Time.now.in_time_zone)
+ }
+ let!(:vo3) {
+ create(:variant_override, hub: hub,
+ variant: create(:variant, product: create(:product, supplier: some_other_producer)), permission_revoked_at: Time.now.in_time_zone)
+ }
context "and is then added" do
- before { er.permissions_list = [:add_to_order_cycles, :create_variant_overrides]; er.save! }
+ before {
+ er.permissions_list = [:add_to_order_cycles, :create_variant_overrides]; er.save!
+ }
it "should set permission_revoked_at to nil for all relevant variant overrides" do
expect(vo1.reload.permission_revoked_at).to be_nil
expect(vo2.reload.permission_revoked_at).to be_nil
diff --git a/spec/models/enterprise_spec.rb b/spec/models/enterprise_spec.rb
index b4bfc76c0e..0ed09a5140 100644
--- a/spec/models/enterprise_spec.rb
+++ b/spec/models/enterprise_spec.rb
@@ -109,7 +109,8 @@ describe Enterprise do
expect {
e2.owner = u1
e2.save!
- }.to raise_error ActiveRecord::RecordInvalid, "Validation failed: #{u1.email} is not permitted to own any more enterprises (limit is 5)."
+ }.to raise_error ActiveRecord::RecordInvalid,
+ "Validation failed: #{u1.email} is not permitted to own any more enterprises (limit is 5)."
end
end
end
@@ -311,7 +312,8 @@ describe Enterprise do
s = create(:supplier_enterprise)
d = create(:distributor_enterprise)
p = create(:product)
- create(:simple_order_cycle, orders_open_at: 10.days.from_now, orders_close_at: 17.days.from_now, suppliers: [s], distributors: [d], variants: [p.master])
+ create(:simple_order_cycle, orders_open_at: 10.days.from_now,
+ orders_close_at: 17.days.from_now, suppliers: [s], distributors: [d], variants: [p.master])
expect(Enterprise.distributors_with_active_order_cycles).not_to include d
end
end
@@ -355,14 +357,17 @@ describe Enterprise do
let(:product) { create(:product) }
it "returns enterprises distributing via an order cycle" do
- order_cycle = create(:simple_order_cycle, distributors: [distributor], variants: [product.master])
+ order_cycle = create(:simple_order_cycle, distributors: [distributor],
+ variants: [product.master])
expect(Enterprise.distributing_products(product.id)).to eq([distributor])
end
it "does not return duplicate enterprises" do
another_product = create(:product)
- order_cycle = create(:simple_order_cycle, distributors: [distributor], variants: [product.master, another_product.master])
- expect(Enterprise.distributing_products([product.id, another_product.id])).to eq([distributor])
+ order_cycle = create(:simple_order_cycle, distributors: [distributor],
+ variants: [product.master, another_product.master])
+ expect(Enterprise.distributing_products([product.id,
+ another_product.id])).to eq([distributor])
end
end
@@ -410,8 +415,10 @@ describe Enterprise do
it "creates links from the new producer to all hubs owned by the same user, granting add_to_order_cycle and create_variant_overrides permissions" do
producer1
- should_have_enterprise_relationship from: producer1, to: hub1, with: [:add_to_order_cycle, :create_variant_overrides]
- should_have_enterprise_relationship from: producer1, to: hub2, with: [:add_to_order_cycle, :create_variant_overrides]
+ should_have_enterprise_relationship from: producer1, to: hub1,
+ with: [:add_to_order_cycle, :create_variant_overrides]
+ should_have_enterprise_relationship from: producer1, to: hub2,
+ with: [:add_to_order_cycle, :create_variant_overrides]
end
it "does not create any other links" do
@@ -427,8 +434,10 @@ describe Enterprise do
producer2
hub1
- should_have_enterprise_relationship from: producer1, to: hub1, with: [:add_to_order_cycle, :create_variant_overrides]
- should_have_enterprise_relationship from: producer2, to: hub1, with: [:add_to_order_cycle, :create_variant_overrides]
+ should_have_enterprise_relationship from: producer1, to: hub1,
+ with: [:add_to_order_cycle, :create_variant_overrides]
+ should_have_enterprise_relationship from: producer2, to: hub1,
+ with: [:add_to_order_cycle, :create_variant_overrides]
end
it "creates links from the new hub to all hubs owned by the same user, granting add_to_order_cycle permission" do
@@ -445,8 +454,12 @@ describe Enterprise do
producer1
producer2
expect { hub1 }.to change(EnterpriseRelationship, :count).by(2) # 2 producer links
- expect { hub2 }.to change(EnterpriseRelationship, :count).by(3) # 2 producer links + 1 hub link
- expect { hub3 }.to change(EnterpriseRelationship, :count).by(4) # 2 producer links + 2 hub links
+ expect {
+ hub2
+ }.to change(EnterpriseRelationship, :count).by(3) # 2 producer links + 1 hub link
+ expect {
+ hub3
+ }.to change(EnterpriseRelationship, :count).by(4) # 2 producer links + 2 hub links
end
end
@@ -454,7 +467,8 @@ describe Enterprise do
er = EnterpriseRelationship.where(parent_id: opts[:from], child_id: opts[:to]).last
expect(er).not_to be_nil
if opts[:with] == :all_permissions
- expect(er.permissions.map(&:name)).to match_array ['add_to_order_cycle', 'manage_products', 'edit_profile', 'create_variant_overrides']
+ expect(er.permissions.map(&:name)).to match_array ['add_to_order_cycle',
+ 'manage_products', 'edit_profile', 'create_variant_overrides']
elsif opts.key? :with
expect(er.permissions.map(&:name)).to match_array opts[:with].map(&:to_s)
end
@@ -483,7 +497,9 @@ describe Enterprise do
let(:product2) { create(:simple_product, primary_taxon: taxon1, taxons: [taxon1, taxon2]) }
let(:product3) { create(:simple_product, primary_taxon: taxon3) }
let(:oc) { create(:order_cycle) }
- let(:ex) { create(:exchange, order_cycle: oc, incoming: false, sender: supplier, receiver: distributor) }
+ let(:ex) {
+ create(:exchange, order_cycle: oc, incoming: false, sender: supplier, receiver: distributor)
+ }
it "gets all taxons of all distributed products" do
allow(Spree::Product).to receive(:in_distributor).and_return [product1, product2]
@@ -534,10 +550,18 @@ describe Enterprise do
describe "provide enterprise category" do
let(:producer_sell_all) { build_stubbed(:enterprise, is_primary_producer: true, sells: "any") }
let(:producer_sell_own) { build_stubbed(:enterprise, is_primary_producer: true, sells: "own") }
- let(:producer_sell_none) { build_stubbed(:enterprise, is_primary_producer: true, sells: "none") }
- let(:non_producer_sell_all) { build_stubbed(:enterprise, is_primary_producer: false, sells: "any") }
- let(:non_producer_sell_own) { build_stubbed(:enterprise, is_primary_producer: false, sells: "own") }
- let(:non_producer_sell_none) { build_stubbed(:enterprise, is_primary_producer: false, sells: "none") }
+ let(:producer_sell_none) {
+ build_stubbed(:enterprise, is_primary_producer: true, sells: "none")
+ }
+ let(:non_producer_sell_all) {
+ build_stubbed(:enterprise, is_primary_producer: false, sells: "any")
+ }
+ let(:non_producer_sell_own) {
+ build_stubbed(:enterprise, is_primary_producer: false, sells: "own")
+ }
+ let(:non_producer_sell_none) {
+ build_stubbed(:enterprise, is_primary_producer: false, sells: "none")
+ }
it "should output enterprise categories" do
expect(producer_sell_all.is_primary_producer).to eq(true)
diff --git a/spec/models/exchange_spec.rb b/spec/models/exchange_spec.rb
index 4e98bec02e..0e8ccdba1a 100644
--- a/spec/models/exchange_spec.rb
+++ b/spec/models/exchange_spec.rb
@@ -55,8 +55,12 @@ describe Exchange do
let(:coordinator) { create(:distributor_enterprise) }
let(:distributor) { create(:distributor_enterprise) }
let(:oc) { create(:simple_order_cycle, coordinator: coordinator) }
- let(:incoming_exchange) { oc.exchanges.create! sender: supplier, receiver: coordinator, incoming: true }
- let(:outgoing_exchange) { oc.exchanges.create! sender: coordinator, receiver: distributor, incoming: false }
+ let(:incoming_exchange) {
+ oc.exchanges.create! sender: supplier, receiver: coordinator, incoming: true
+ }
+ let(:outgoing_exchange) {
+ oc.exchanges.create! sender: coordinator, receiver: distributor, incoming: false
+ }
describe "reporting whether it is an incoming exchange" do
it "returns true for incoming exchanges" do
@@ -142,8 +146,12 @@ describe Exchange do
end
describe "finding exchanges by direction" do
- let!(:incoming_exchange) { oc.exchanges.create! sender: supplier, receiver: coordinator, incoming: true }
- let!(:outgoing_exchange) { oc.exchanges.create! sender: coordinator, receiver: distributor, incoming: false }
+ let!(:incoming_exchange) {
+ oc.exchanges.create! sender: supplier, receiver: coordinator, incoming: true
+ }
+ let!(:outgoing_exchange) {
+ oc.exchanges.create! sender: coordinator, receiver: distributor, incoming: false
+ }
it "finds incoming exchanges" do
expect(Exchange.incoming).to eq([incoming_exchange])
@@ -172,17 +180,22 @@ describe Exchange do
it "finds exchanges coming from any of a number of enterprises" do
expect(Exchange.from_enterprises([coordinator])).to eq([outgoing_exchange])
- expect(Exchange.from_enterprises([supplier, coordinator])).to match_array [incoming_exchange, outgoing_exchange]
+ expect(Exchange.from_enterprises([supplier,
+ coordinator])).to match_array [incoming_exchange,
+ outgoing_exchange]
end
it "finds exchanges going to any of a number of enterprises" do
expect(Exchange.to_enterprises([coordinator])).to eq([incoming_exchange])
- expect(Exchange.to_enterprises([coordinator, distributor])).to match_array [incoming_exchange, outgoing_exchange]
+ expect(Exchange.to_enterprises([coordinator,
+ distributor])).to match_array [incoming_exchange,
+ outgoing_exchange]
end
it "finds exchanges involving any of a number of enterprises" do
expect(Exchange.involving([supplier])).to eq([incoming_exchange])
- expect(Exchange.involving([coordinator])).to match_array [incoming_exchange, outgoing_exchange]
+ expect(Exchange.involving([coordinator])).to match_array [incoming_exchange,
+ outgoing_exchange]
expect(Exchange.involving([distributor])).to eq([outgoing_exchange])
end
end
diff --git a/spec/models/order_balance_spec.rb b/spec/models/order_balance_spec.rb
index bad8998733..69411c5a63 100644
--- a/spec/models/order_balance_spec.rb
+++ b/spec/models/order_balance_spec.rb
@@ -82,9 +82,9 @@ describe OrderBalance do
end
describe '#amount' do
- before do
- allow(order).to receive(:new_outstanding_balance) { 123 }
- end
+ before do
+ allow(order).to receive(:new_outstanding_balance) { 123 }
+ end
it 'calls #new_outstanding_balance' do
expect(order).to receive(:new_outstanding_balance)
diff --git a/spec/models/order_cycle_spec.rb b/spec/models/order_cycle_spec.rb
index a9a4622331..1031a53c6b 100644
--- a/spec/models/order_cycle_spec.rb
+++ b/spec/models/order_cycle_spec.rb
@@ -40,19 +40,24 @@ describe OrderCycle do
end
it "finds order cycles in various stages of their lifecycle" do
- oc_active = create(:simple_order_cycle, orders_open_at: 1.week.ago, orders_close_at: 1.week.from_now)
- oc_not_yet_open = create(:simple_order_cycle, orders_open_at: 1.week.from_now, orders_close_at: 2.weeks.from_now)
- oc_already_closed = create(:simple_order_cycle, orders_open_at: 2.weeks.ago, orders_close_at: 1.week.ago)
+ oc_active = create(:simple_order_cycle, orders_open_at: 1.week.ago,
+ orders_close_at: 1.week.from_now)
+ oc_not_yet_open = create(:simple_order_cycle, orders_open_at: 1.week.from_now,
+ orders_close_at: 2.weeks.from_now)
+ oc_already_closed = create(:simple_order_cycle, orders_open_at: 2.weeks.ago,
+ orders_close_at: 1.week.ago)
oc_undated = create(:simple_order_cycle, orders_open_at: nil, orders_close_at: nil)
oc_undated_open = create(:simple_order_cycle, orders_open_at: 1.week.ago, orders_close_at: nil)
- oc_undated_close = create(:simple_order_cycle, orders_open_at: nil, orders_close_at: 1.week.from_now)
+ oc_undated_close = create(:simple_order_cycle, orders_open_at: nil,
+ orders_close_at: 1.week.from_now)
expect(OrderCycle.active).to eq([oc_active])
expect(OrderCycle.inactive).to match_array [oc_not_yet_open, oc_already_closed]
expect(OrderCycle.upcoming).to eq([oc_not_yet_open])
expect(OrderCycle.closed).to eq([oc_already_closed])
expect(OrderCycle.undated).to eq([oc_undated, oc_undated_open, oc_undated_close])
- expect(OrderCycle.not_closed).to eq([oc_active, oc_not_yet_open, oc_undated, oc_undated_open, oc_undated_close])
+ expect(OrderCycle.not_closed).to eq([oc_active, oc_not_yet_open, oc_undated, oc_undated_open,
+ oc_undated_close])
expect(OrderCycle.dated).to eq([oc_active, oc_not_yet_open, oc_already_closed])
end
@@ -175,8 +180,14 @@ describe OrderCycle do
let!(:p0) { create(:simple_product) }
let!(:p1) { create(:simple_product) }
let!(:p1_v_deleted) { create(:variant, product: p1) }
- let!(:p1_v_visible) { create(:variant, product: p1, inventory_items: [create(:inventory_item, enterprise: d2, visible: true)]) }
- let!(:p1_v_hidden) { create(:variant, product: p1, inventory_items: [create(:inventory_item, enterprise: d2, visible: false)]) }
+ let!(:p1_v_visible) {
+ create(:variant, product: p1,
+ inventory_items: [create(:inventory_item, enterprise: d2, visible: true)])
+ }
+ let!(:p1_v_hidden) {
+ create(:variant, product: p1,
+ inventory_items: [create(:inventory_item, enterprise: d2, visible: false)])
+ }
let!(:p2) { create(:simple_product) }
let!(:p2_v) { create(:variant, product: p2) }
@@ -195,7 +206,8 @@ describe OrderCycle do
end
it "reports on the variants exchanged" do
- expect(oc.variants).to match_array [p0.master, p1.master, p2.master, p2_v, p1_v_visible, p1_v_hidden]
+ expect(oc.variants).to match_array [p0.master, p1.master, p2.master, p2_v, p1_v_visible,
+ p1_v_hidden]
end
it "returns the correct count of variants" do
@@ -207,7 +219,8 @@ describe OrderCycle do
end
it "reports on the variants distributed" do
- expect(oc.distributed_variants).to match_array [p1.master, p2.master, p2_v, p1_v_visible, p1_v_hidden]
+ expect(oc.distributed_variants).to match_array [p1.master, p2.master, p2_v, p1_v_visible,
+ p1_v_hidden]
end
it "reports on the products distributed by a particular distributor" do
@@ -262,9 +275,12 @@ describe OrderCycle do
@d1 = create(:enterprise)
@d2 = create(:enterprise, next_collection_at: '2-8pm Friday')
- @e0 = create(:exchange, order_cycle: @oc, sender: create(:enterprise), receiver: @oc.coordinator, incoming: true)
- @e1 = create(:exchange, order_cycle: @oc, sender: @oc.coordinator, receiver: @d1, incoming: false, pickup_time: '5pm Tuesday', pickup_instructions: "Come get it!")
- @e2 = create(:exchange, order_cycle: @oc, sender: @oc.coordinator, receiver: @d2, incoming: false, pickup_time: nil)
+ @e0 = create(:exchange, order_cycle: @oc, sender: create(:enterprise),
+ receiver: @oc.coordinator, incoming: true)
+ @e1 = create(:exchange, order_cycle: @oc, sender: @oc.coordinator, receiver: @d1,
+ incoming: false, pickup_time: '5pm Tuesday', pickup_instructions: "Come get it!")
+ @e2 = create(:exchange, order_cycle: @oc, sender: @oc.coordinator, receiver: @d2,
+ incoming: false, pickup_time: nil)
end
it "finds the exchange for a distributor" do
@@ -354,7 +370,8 @@ describe OrderCycle do
it "clones itself" do
coordinator = create(:enterprise);
- oc = create(:simple_order_cycle, coordinator_fees: [create(:enterprise_fee, enterprise: coordinator)], preferred_product_selection_from_coordinator_inventory_only: true)
+ oc = create(:simple_order_cycle,
+ coordinator_fees: [create(:enterprise_fee, enterprise: coordinator)], preferred_product_selection_from_coordinator_inventory_only: true)
ex1 = create(:exchange, order_cycle: oc)
ex2 = create(:exchange, order_cycle: oc)
oc.clone!
@@ -381,7 +398,8 @@ describe OrderCycle do
describe "finding recently closed order cycles" do
it "should give the most recently closed order cycle for a distributor" do
distributor = create(:distributor_enterprise)
- oc = create(:simple_order_cycle, name: 'oc 1', distributors: [distributor], orders_open_at: 10.days.ago, orders_close_at: 9.days.ago)
+ oc = create(:simple_order_cycle, name: 'oc 1', distributors: [distributor],
+ orders_open_at: 10.days.ago, orders_close_at: 9.days.ago)
expect(OrderCycle.most_recently_closed_for(distributor)).to eq(oc)
end
@@ -394,7 +412,8 @@ describe OrderCycle do
describe "finding order cycles opening in the future" do
it "should give the soonest opening order cycle for a distributor" do
distributor = create(:distributor_enterprise)
- oc = create(:simple_order_cycle, name: 'oc 1', distributors: [distributor], orders_open_at: 10.days.from_now, orders_close_at: 11.days.from_now)
+ oc = create(:simple_order_cycle, name: 'oc 1', distributors: [distributor],
+ orders_open_at: 10.days.from_now, orders_close_at: 11.days.from_now)
expect(OrderCycle.first_opening_for(distributor)).to eq(oc)
end
@@ -407,8 +426,10 @@ describe OrderCycle do
describe "finding open order cycles" do
it "should give the soonest closing order cycle for a distributor" do
distributor = create(:distributor_enterprise)
- oc = create(:simple_order_cycle, name: 'oc 1', distributors: [distributor], orders_open_at: 1.day.ago, orders_close_at: 11.days.from_now)
- oc2 = create(:simple_order_cycle, name: 'oc 2', distributors: [distributor], orders_open_at: 2.days.ago, orders_close_at: 12.days.from_now)
+ oc = create(:simple_order_cycle, name: 'oc 1', distributors: [distributor],
+ orders_open_at: 1.day.ago, orders_close_at: 11.days.from_now)
+ oc2 = create(:simple_order_cycle, name: 'oc 2', distributors: [distributor],
+ orders_open_at: 2.days.ago, orders_close_at: 12.days.from_now)
expect(OrderCycle.first_closing_for(distributor)).to eq(oc)
end
end
@@ -436,11 +457,23 @@ describe OrderCycle do
let(:shop) { create(:enterprise) }
let(:user) { create(:user) }
let(:oc) { create(:order_cycle) }
- let!(:order) { create(:completed_order_with_totals, distributor: shop, user: user, order_cycle: oc) }
- let!(:order_from_other_hub) { create(:completed_order_with_totals, distributor: create(:enterprise), user: user, order_cycle: oc) }
- let!(:order_from_other_user) { create(:completed_order_with_totals, distributor: shop, user: create(:user), order_cycle: oc) }
- let!(:order_from_other_oc) { create(:completed_order_with_totals, distributor: shop, user: user, order_cycle: create(:order_cycle)) }
- let!(:order_cancelled) { create(:completed_order_with_totals, distributor: shop, user: user, order_cycle: oc) }
+ let!(:order) {
+ create(:completed_order_with_totals, distributor: shop, user: user, order_cycle: oc)
+ }
+ let!(:order_from_other_hub) {
+ create(:completed_order_with_totals, distributor: create(:enterprise), user: user,
+ order_cycle: oc)
+ }
+ let!(:order_from_other_user) {
+ create(:completed_order_with_totals, distributor: shop, user: create(:user), order_cycle: oc)
+ }
+ let!(:order_from_other_oc) {
+ create(:completed_order_with_totals, distributor: shop, user: user,
+ order_cycle: create(:order_cycle))
+ }
+ let!(:order_cancelled) {
+ create(:completed_order_with_totals, distributor: shop, user: user, order_cycle: oc)
+ }
before do
setup_email
diff --git a/spec/models/product_import/reset_absent_spec.rb b/spec/models/product_import/reset_absent_spec.rb
index 22e574ec28..c853d3e79c 100644
--- a/spec/models/product_import/reset_absent_spec.rb
+++ b/spec/models/product_import/reset_absent_spec.rb
@@ -39,7 +39,9 @@ module ProductImport
)
end
- let(:reset_stock_strategy) { instance_double(Catalog::ProductImport::ProductsResetStrategy) }
+ let(:reset_stock_strategy) {
+ instance_double(Catalog::ProductImport::ProductsResetStrategy)
+ }
before do
allow(entry_processor)
diff --git a/spec/models/product_importer_spec.rb b/spec/models/product_importer_spec.rb
index 57354144e8..3c6915297e 100644
--- a/spec/models/product_importer_spec.rb
+++ b/spec/models/product_importer_spec.rb
@@ -8,11 +8,24 @@ describe ProductImport::ProductImporter do
let!(:user) { create(:user) }
let!(:user2) { create(:user) }
let!(:user3) { create(:user) }
- let!(:enterprise) { create(:enterprise, is_primary_producer: true, owner: user, name: "User Enterprise") }
- let!(:enterprise2) { create(:distributor_enterprise, is_primary_producer: true, owner: user2, name: "Another Enterprise") }
- let!(:enterprise3) { create(:distributor_enterprise, is_primary_producer: true, owner: user3, name: "And Another Enterprise") }
- let!(:enterprise4) { create(:enterprise, is_primary_producer: false, owner: user, name: "Non-Producer") }
- let!(:relationship) { create(:enterprise_relationship, parent: enterprise, child: enterprise2, permissions_list: [:create_variant_overrides]) }
+ let!(:enterprise) {
+ create(:enterprise, is_primary_producer: true, owner: user, name: "User Enterprise")
+ }
+ let!(:enterprise2) {
+ create(:distributor_enterprise, is_primary_producer: true, owner: user2,
+ name: "Another Enterprise")
+ }
+ let!(:enterprise3) {
+ create(:distributor_enterprise, is_primary_producer: true, owner: user3,
+ name: "And Another Enterprise")
+ }
+ let!(:enterprise4) {
+ create(:enterprise, is_primary_producer: false, owner: user, name: "Non-Producer")
+ }
+ let!(:relationship) {
+ create(:enterprise_relationship, parent: enterprise, child: enterprise2,
+ permissions_list: [:create_variant_overrides])
+ }
let!(:category) { create(:taxon, name: 'Vegetables') }
let!(:category2) { create(:taxon, name: 'Cake') }
@@ -22,23 +35,68 @@ describe ProductImport::ProductImporter do
let!(:tax_category2) { create(:tax_category) }
let!(:shipping_category) { create(:shipping_category) }
- let!(:product) { create(:simple_product, supplier: enterprise2, name: 'Hypothetical Cake', description: nil, primary_taxon_id: category2.id) }
- let!(:variant) { create(:variant, product_id: product.id, price: '8.50', on_hand: '100', unit_value: '500', display_name: 'Preexisting Banana') }
- let!(:product2) { create(:simple_product, supplier: enterprise, on_hand: '100', name: 'Beans', unit_value: '500', primary_taxon_id: category.id, description: nil) }
- let!(:product3) { create(:simple_product, supplier: enterprise, on_hand: '100', name: 'Sprouts', unit_value: '500', primary_taxon_id: category.id) }
- let!(:product4) { create(:simple_product, supplier: enterprise, on_hand: '100', name: 'Cabbage', unit_value: '1', variant_unit_scale: nil, variant_unit: "items", variant_unit_name: "Whole", primary_taxon_id: category.id) }
- let!(:product5) { create(:simple_product, supplier: enterprise2, on_hand: '100', name: 'Lettuce', unit_value: '500', primary_taxon_id: category.id) }
- let!(:product6) { create(:simple_product, supplier: enterprise3, on_hand: '100', name: 'Beetroot', unit_value: '500', on_demand: true, variant_unit_scale: 1, variant_unit: 'weight', primary_taxon_id: category.id, description: nil) }
- let!(:product7) { create(:simple_product, supplier: enterprise3, on_hand: '100', name: 'Tomato', unit_value: '500', variant_unit_scale: 1, variant_unit: 'weight', primary_taxon_id: category.id, description: nil) }
+ let!(:product) {
+ create(:simple_product, supplier: enterprise2, name: 'Hypothetical Cake', description: nil,
+ primary_taxon_id: category2.id)
+ }
+ let!(:variant) {
+ create(:variant, product_id: product.id, price: '8.50', on_hand: '100', unit_value: '500',
+ display_name: 'Preexisting Banana')
+ }
+ let!(:product2) {
+ create(:simple_product, supplier: enterprise, on_hand: '100', name: 'Beans', unit_value: '500',
+ primary_taxon_id: category.id, description: nil)
+ }
+ let!(:product3) {
+ create(:simple_product, supplier: enterprise, on_hand: '100', name: 'Sprouts', unit_value: '500',
+ primary_taxon_id: category.id)
+ }
+ let!(:product4) {
+ create(:simple_product, supplier: enterprise, on_hand: '100', name: 'Cabbage', unit_value: '1',
+ variant_unit_scale: nil, variant_unit: "items", variant_unit_name: "Whole", primary_taxon_id: category.id)
+ }
+ let!(:product5) {
+ create(:simple_product, supplier: enterprise2, on_hand: '100', name: 'Lettuce', unit_value: '500',
+ primary_taxon_id: category.id)
+ }
+ let!(:product6) {
+ create(:simple_product, supplier: enterprise3, on_hand: '100', name: 'Beetroot',
+ unit_value: '500', on_demand: true, variant_unit_scale: 1, variant_unit: 'weight', primary_taxon_id: category.id, description: nil)
+ }
+ let!(:product7) {
+ create(:simple_product, supplier: enterprise3, on_hand: '100', name: 'Tomato', unit_value: '500',
+ variant_unit_scale: 1, variant_unit: 'weight', primary_taxon_id: category.id, description: nil)
+ }
- let!(:product8) { create(:simple_product, supplier: enterprise, on_hand: '100', name: 'Oats', description: "", unit_value: '500', variant_unit_scale: 1, variant_unit: 'weight', primary_taxon_id: category4.id) }
- let!(:product9) { create(:simple_product, supplier: enterprise, on_hand: '100', name: 'Oats', description: "", unit_value: '500', variant_unit_scale: 1, variant_unit: 'weight', primary_taxon_id: category4.id) }
- let!(:variant2) { create(:variant, product_id: product8.id, price: '4.50', on_hand: '100', unit_value: '500', display_name: 'Porridge Oats') }
- let!(:variant3) { create(:variant, product_id: product8.id, price: '5.50', on_hand: '100', unit_value: '500', display_name: 'Rolled Oats') }
- let!(:variant4) { create(:variant, product_id: product9.id, price: '6.50', on_hand: '100', unit_value: '500', display_name: 'Flaked Oats') }
+ let!(:product8) {
+ create(:simple_product, supplier: enterprise, on_hand: '100', name: 'Oats', description: "",
+ unit_value: '500', variant_unit_scale: 1, variant_unit: 'weight', primary_taxon_id: category4.id)
+ }
+ let!(:product9) {
+ create(:simple_product, supplier: enterprise, on_hand: '100', name: 'Oats', description: "",
+ unit_value: '500', variant_unit_scale: 1, variant_unit: 'weight', primary_taxon_id: category4.id)
+ }
+ let!(:variant2) {
+ create(:variant, product_id: product8.id, price: '4.50', on_hand: '100', unit_value: '500',
+ display_name: 'Porridge Oats')
+ }
+ let!(:variant3) {
+ create(:variant, product_id: product8.id, price: '5.50', on_hand: '100', unit_value: '500',
+ display_name: 'Rolled Oats')
+ }
+ let!(:variant4) {
+ create(:variant, product_id: product9.id, price: '6.50', on_hand: '100', unit_value: '500',
+ display_name: 'Flaked Oats')
+ }
- let!(:variant_override) { create(:variant_override, variant_id: product4.variants.first.id, hub: enterprise2, count_on_hand: 42) }
- let!(:variant_override2) { create(:variant_override, variant_id: product5.variants.first.id, hub: enterprise, count_on_hand: 96) }
+ let!(:variant_override) {
+ create(:variant_override, variant_id: product4.variants.first.id, hub: enterprise2,
+ count_on_hand: 42)
+ }
+ let!(:variant_override2) {
+ create(:variant_override, variant_id: product5.variants.first.id, hub: enterprise,
+ count_on_hand: 96)
+ }
let(:permissions) { OpenFoodNetwork::Permissions.new(user) }
@@ -49,12 +107,18 @@ describe ProductImport::ProductImporter do
describe "importing products from a spreadsheet" do
let(:csv_data) {
CSV.generate do |csv|
- csv << ["name", "producer", "category", "on_hand", "price", "units", "unit_type", "variant_unit_name", "on_demand", "shipping_category"]
- csv << ["Carrots", enterprise.name, "Vegetables", "5", "3.20", "500", "g", "", "", shipping_category.name]
- csv << ["Potatoes", enterprise.name, "Vegetables", "6", "6.50", "2", "kg", "", "", shipping_category.name]
- csv << ["Pea Soup", enterprise.name, "Vegetables", "8", "5.50", "750", "ml", "", "0", shipping_category.name]
- csv << ["Salad", enterprise.name, "Vegetables", "7", "4.50", "1", "", "bags", "", shipping_category.name]
- csv << ["Hot Cross Buns", enterprise.name, "Cake", "7", "3.50", "1", "", "buns", "1", shipping_category.name]
+ csv << ["name", "producer", "category", "on_hand", "price", "units", "unit_type",
+ "variant_unit_name", "on_demand", "shipping_category"]
+ csv << ["Carrots", enterprise.name, "Vegetables", "5", "3.20", "500", "g", "", "",
+ shipping_category.name]
+ csv << ["Potatoes", enterprise.name, "Vegetables", "6", "6.50", "2", "kg", "", "",
+ shipping_category.name]
+ csv << ["Pea Soup", enterprise.name, "Vegetables", "8", "5.50", "750", "ml", "", "0",
+ shipping_category.name]
+ csv << ["Salad", enterprise.name, "Vegetables", "7", "4.50", "1", "", "bags", "",
+ shipping_category.name]
+ csv << ["Hot Cross Buns", enterprise.name, "Cake", "7", "3.50", "1", "", "buns", "1",
+ shipping_category.name]
end
}
let(:importer) { import_data csv_data }
@@ -135,8 +199,10 @@ describe ProductImport::ProductImporter do
describe "when uploading a spreadsheet with some invalid entries" do
let(:csv_data) {
CSV.generate do |csv|
- csv << ["name", "producer", "category", "on_hand", "price", "units", "unit_type", "shipping_category"]
- csv << ["Good Carrots", enterprise.name, "Vegetables", "5", "3.20", "500", "g", shipping_category.name]
+ csv << ["name", "producer", "category", "on_hand", "price", "units", "unit_type",
+ "shipping_category"]
+ csv << ["Good Carrots", enterprise.name, "Vegetables", "5", "3.20", "500", "g",
+ shipping_category.name]
csv << ["Bad Potatoes", "", "Vegetables", "6", "6.50", "1", "", shipping_category.name]
end
}
@@ -181,7 +247,8 @@ describe ProductImport::ProductImporter do
# an unquoted \n will create a non valid line which will fail entry validation hence why we are only testing with \r
it "should raise an unquoted field error if data include unquoted field with \r character" do
expect(importer.errors.messages.values).to include(
- [I18n.t('admin.product_import.model.malformed_csv', error_message: "Unquoted fields do not allow new line <\"\\r\"> in line 3.")]
+ [I18n.t('admin.product_import.model.malformed_csv',
+ error_message: "Unquoted fields do not allow new line <\"\\r\"> in line 3.")]
)
end
end
@@ -189,8 +256,10 @@ describe ProductImport::ProductImporter do
describe "when shipping category is missing" do
let(:csv_data) {
CSV.generate do |csv|
- csv << ["name", "producer", "category", "on_hand", "price", "units", "unit_type", "variant_unit_name", "on_demand", "shipping_category"]
- csv << ["Shipping Test", enterprise.name, "Vegetables", "5", "3.20", "500", "g", "", nil, nil]
+ csv << ["name", "producer", "category", "on_hand", "price", "units", "unit_type",
+ "variant_unit_name", "on_demand", "shipping_category"]
+ csv << ["Shipping Test", enterprise.name, "Vegetables", "5", "3.20", "500", "g", "", nil,
+ nil]
end
}
let(:importer) { import_data csv_data }
@@ -225,9 +294,12 @@ describe ProductImport::ProductImporter do
describe "adding new variants to existing products and updating exiting products" do
let(:csv_data) {
CSV.generate do |csv|
- csv << ["name", "producer", "category", "on_hand", "price", "units", "unit_type", "display_name", "shipping_category"]
- csv << ["Hypothetical Cake", enterprise2.name, "Cake", "5", "5.50", "500", "g", "Preexisting Banana", shipping_category.name]
- csv << ["Hypothetical Cake", enterprise2.name, "Cake", "6", "3.50", "500", "g", "Emergent Coffee", shipping_category.name]
+ csv << ["name", "producer", "category", "on_hand", "price", "units", "unit_type",
+ "display_name", "shipping_category"]
+ csv << ["Hypothetical Cake", enterprise2.name, "Cake", "5", "5.50", "500", "g",
+ "Preexisting Banana", shipping_category.name]
+ csv << ["Hypothetical Cake", enterprise2.name, "Cake", "6", "3.50", "500", "g",
+ "Emergent Coffee", shipping_category.name]
end
}
let(:importer) { import_data csv_data }
@@ -267,8 +339,10 @@ describe ProductImport::ProductImporter do
describe "updating an exiting variant" do
let(:csv_data) {
CSV.generate do |csv|
- csv << ["name", "producer", "description", "category", "on_hand", "price", "units", "unit_type", "display_name", "shipping_category"]
- csv << ["Hypothetical Cake", enterprise2.name, "New Description", "Cake", "5", "5.50", "500", "g", "Preexisting Banana", shipping_category.name]
+ csv << ["name", "producer", "description", "category", "on_hand", "price", "units",
+ "unit_type", "display_name", "shipping_category"]
+ csv << ["Hypothetical Cake", enterprise2.name, "New Description", "Cake", "5", "5.50",
+ "500", "g", "Preexisting Banana", shipping_category.name]
end
}
let(:importer) { import_data csv_data }
@@ -286,12 +360,18 @@ describe ProductImport::ProductImporter do
describe "adding new product and sub-variant at the same time" do
let(:csv_data) {
CSV.generate do |csv|
- csv << ["name", "producer", "category", "on_hand", "price", "units", "unit_type", "display_name", "shipping_category"]
- csv << ["Potatoes", enterprise.name, "Vegetables", "5", "3.50", "500", "g", "Small Bag", shipping_category.name]
- csv << ["Chives", enterprise.name, "Vegetables", "6", "4.50", "500", "g", "Bunch", shipping_category.name]
- csv << ["Potatoes", enterprise.name, "Vegetables", "6", "5.50", "2", "kg", "Big Bag", shipping_category.name]
- csv << ["Potatoes", enterprise.name, "Vegetables", "6", "22.00", "10000", "g", "Small Sack", shipping_category.name]
- csv << ["Potatoes", enterprise.name, "Vegetables", "6", "60.00", "30000", "", "Big Sack", shipping_category.name]
+ csv << ["name", "producer", "category", "on_hand", "price", "units", "unit_type",
+ "display_name", "shipping_category"]
+ csv << ["Potatoes", enterprise.name, "Vegetables", "5", "3.50", "500", "g", "Small Bag",
+ shipping_category.name]
+ csv << ["Chives", enterprise.name, "Vegetables", "6", "4.50", "500", "g", "Bunch",
+ shipping_category.name]
+ csv << ["Potatoes", enterprise.name, "Vegetables", "6", "5.50", "2", "kg", "Big Bag",
+ shipping_category.name]
+ csv << ["Potatoes", enterprise.name, "Vegetables", "6", "22.00", "10000", "g",
+ "Small Sack", shipping_category.name]
+ csv << ["Potatoes", enterprise.name, "Vegetables", "6", "60.00", "30000", "", "Big Sack",
+ shipping_category.name]
end
}
let(:importer) { import_data csv_data }
@@ -334,9 +414,12 @@ describe ProductImport::ProductImporter do
describe "updating various fields" do
let(:csv_data) {
CSV.generate do |csv|
- csv << ["name", "producer", "category", "on_hand", "price", "units", "unit_type", "on_demand", "sku", "shipping_category"]
- csv << ["Beetroot", enterprise3.name, "Vegetables", "5", "3.50", "500", "g", "0", nil, shipping_category.name]
- csv << ["Tomato", enterprise3.name, "Vegetables", "6", "5.50", "500", "g", "1", "TOMS", shipping_category.name]
+ csv << ["name", "producer", "category", "on_hand", "price", "units", "unit_type",
+ "on_demand", "sku", "shipping_category"]
+ csv << ["Beetroot", enterprise3.name, "Vegetables", "5", "3.50", "500", "g", "0", nil,
+ shipping_category.name]
+ csv << ["Tomato", enterprise3.name, "Vegetables", "6", "5.50", "500", "g", "1", "TOMS",
+ shipping_category.name]
end
}
let(:importer) { import_data csv_data }
@@ -395,7 +478,8 @@ describe ProductImport::ProductImporter do
describe "when more than one product of the same name already exists with multiple variants each" do
let(:csv_data) {
CSV.generate do |csv|
- csv << ["name", "producer", "category", "description", "on_hand", "price", "units", "unit_type", "display_name", "shipping_category"]
+ csv << ["name", "producer", "category", "description", "on_hand", "price", "units",
+ "unit_type", "display_name", "shipping_category"]
csv << ["Oats", enterprise.name, "Cereal", "", "50", "3.50", "500", "g", "Rolled Oats", shipping_category.name] # Update
csv << ["Oats", enterprise.name, "Cereal", "", "80", "3.75", "500", "g", "Flaked Oats", shipping_category.name] # Update
csv << ["Oats", enterprise.name, "Cereal", "", "60", "5.50", "500", "g", "Magic Oats", shipping_category.name] # Add
@@ -431,7 +515,8 @@ describe ProductImport::ProductImporter do
describe "when importer processes create and update across multiple stages" do
let(:csv_data) {
CSV.generate do |csv|
- csv << ["name", "producer", "category", "on_hand", "price", "units", "unit_type", "display_name", "shipping_category"]
+ csv << ["name", "producer", "category", "on_hand", "price", "units", "unit_type",
+ "display_name", "shipping_category"]
csv << ["Bag of Oats", enterprise.name, "Cereal", "60", "5.50", "500", "g", "Magic Oats", shipping_category.name] # Add
csv << ["Bag of Oats", enterprise.name, "Cereal", "70", "8.50", "500", "g", "French Oats", shipping_category.name] # Add
csv << ["Bag of Oats", enterprise.name, "Cereal", "80", "9.50", "500", "g", "Organic Oats", shipping_category.name] # Add
@@ -497,7 +582,8 @@ describe ProductImport::ProductImporter do
describe "creating and updating inventory" do
let(:csv_data) {
CSV.generate do |csv|
- csv << ["name", "distributor", "producer", "on_hand", "price", "units", "unit_type", "variant_unit_name"]
+ csv << ["name", "distributor", "producer", "on_hand", "price", "units", "unit_type",
+ "variant_unit_name"]
csv << ["Beans", enterprise2.name, enterprise.name, "5", "3.20", "500", "g", ""]
csv << ["Sprouts", enterprise2.name, enterprise.name, "6", "6.50", "500", "g", ""]
csv << ["Cabbage", enterprise2.name, enterprise.name, "2001", "1.50", "1", "", "Whole"]
@@ -523,9 +609,12 @@ describe ProductImport::ProductImporter do
expect(importer.updated_ids).to be_a(Array)
expect(importer.updated_ids.count).to eq 3
- beans_override = VariantOverride.where(variant_id: product2.variants.first.id, hub_id: enterprise2.id).first
- sprouts_override = VariantOverride.where(variant_id: product3.variants.first.id, hub_id: enterprise2.id).first
- cabbage_override = VariantOverride.where(variant_id: product4.variants.first.id, hub_id: enterprise2.id).first
+ beans_override = VariantOverride.where(variant_id: product2.variants.first.id,
+ hub_id: enterprise2.id).first
+ sprouts_override = VariantOverride.where(variant_id: product3.variants.first.id,
+ hub_id: enterprise2.id).first
+ cabbage_override = VariantOverride.where(variant_id: product4.variants.first.id,
+ hub_id: enterprise2.id).first
expect(Float(beans_override.price)).to eq 3.20
expect(beans_override.count_on_hand).to eq 5
@@ -553,7 +642,8 @@ describe ProductImport::ProductImporter do
expect(importer.inventory_created_count).to eq 1
override = VariantOverride.where(variant_id: variant2.id, hub_id: enterprise2.id).first
- visible = InventoryItem.where(variant_id: variant2.id, enterprise_id: enterprise2.id).first.visible
+ visible = InventoryItem.where(variant_id: variant2.id,
+ enterprise_id: enterprise2.id).first.visible
expect(override.count_on_hand).to eq 900
expect(visible).to be_truthy
@@ -561,10 +651,14 @@ describe ProductImport::ProductImporter do
end
describe "updating existing item that was set to hidden in inventory" do
- let!(:inventory) { InventoryItem.create(variant_id: product4.variants.first.id, enterprise_id: enterprise2.id, visible: false) }
+ let!(:inventory) {
+ InventoryItem.create(variant_id: product4.variants.first.id, enterprise_id: enterprise2.id,
+ visible: false)
+ }
let(:csv_data) {
CSV.generate do |csv|
- csv << ["name", "distributor", "producer", "on_hand", "price", "units", "variant_unit_name"]
+ csv << ["name", "distributor", "producer", "on_hand", "price", "units",
+ "variant_unit_name"]
csv << ["Cabbage", enterprise2.name, enterprise.name, "900", "", "1", "Whole"]
end
}
@@ -575,8 +669,10 @@ describe ProductImport::ProductImporter do
expect(importer.inventory_updated_count).to eq 1
- override = VariantOverride.where(variant_id: product4.variants.first.id, hub_id: enterprise2.id).first
- visible = InventoryItem.where(variant_id: product4.variants.first.id, enterprise_id: enterprise2.id).first.visible
+ override = VariantOverride.where(variant_id: product4.variants.first.id,
+ hub_id: enterprise2.id).first
+ visible = InventoryItem.where(variant_id: product4.variants.first.id,
+ enterprise_id: enterprise2.id).first.visible
expect(override.count_on_hand).to eq 900
expect(visible).to be_truthy
@@ -587,9 +683,12 @@ describe ProductImport::ProductImporter do
describe "handling enterprise permissions" do
it "only allows product import into enterprises the user is permitted to manage" do
csv_data = CSV.generate do |csv|
- csv << ["name", "producer", "category", "on_hand", "price", "units", "unit_type", "shipping_category"]
- csv << ["My Carrots", enterprise.name, "Vegetables", "5", "3.20", "500", "g", shipping_category.name]
- csv << ["Your Potatoes", enterprise2.name, "Vegetables", "6", "6.50", "1", "kg", shipping_category.name]
+ csv << ["name", "producer", "category", "on_hand", "price", "units", "unit_type",
+ "shipping_category"]
+ csv << ["My Carrots", enterprise.name, "Vegetables", "5", "3.20", "500", "g",
+ shipping_category.name]
+ csv << ["Your Potatoes", enterprise2.name, "Vegetables", "6", "6.50", "1", "kg",
+ shipping_category.name]
end
importer = import_data csv_data, import_user: user
@@ -630,7 +729,8 @@ describe ProductImport::ProductImporter do
expect(importer.updated_ids).to be_a(Array)
expect(importer.updated_ids.count).to eq 1
- beans = VariantOverride.where(variant_id: product2.variants.first.id, hub_id: enterprise2.id).first
+ beans = VariantOverride.where(variant_id: product2.variants.first.id,
+ hub_id: enterprise2.id).first
expect(beans.count_on_hand).to eq 777
end
@@ -660,9 +760,12 @@ describe ProductImport::ProductImporter do
describe "applying settings and defaults on import" do
it "can reset all products for an enterprise that are not present in the uploaded file to zero stock" do
csv_data = CSV.generate do |csv|
- csv << ["name", "producer", "category", "on_hand", "price", "units", "unit_type", "shipping_category"]
- csv << ["Carrots", enterprise.name, "Vegetables", "5", "3.20", "500", "g", shipping_category.name]
- csv << ["Beans", enterprise.name, "Vegetables", "6", "6.50", "500", "g", shipping_category.name]
+ csv << ["name", "producer", "category", "on_hand", "price", "units", "unit_type",
+ "shipping_category"]
+ csv << ["Carrots", enterprise.name, "Vegetables", "5", "3.20", "500", "g",
+ shipping_category.name]
+ csv << ["Beans", enterprise.name, "Vegetables", "6", "6.50", "500", "g",
+ shipping_category.name]
end
importer = import_data csv_data, reset_all_absent: true
@@ -683,7 +786,8 @@ describe ProductImport::ProductImporter do
updated_ids = importer.updated_ids
- importer = import_data csv_data, reset_all_absent: true, updated_ids: updated_ids, enterprises_to_reset: [enterprise.id]
+ importer = import_data csv_data, reset_all_absent: true, updated_ids: updated_ids,
+ enterprises_to_reset: [enterprise.id]
importer.reset_absent(updated_ids)
expect(importer.products_reset_count).to eq 7
@@ -718,13 +822,18 @@ describe ProductImport::ProductImporter do
updated_ids = importer.updated_ids
- importer = import_data csv_data, import_into: 'inventories', reset_all_absent: true, updated_ids: updated_ids, enterprises_to_reset: [enterprise2.id]
+ importer = import_data csv_data, import_into: 'inventories', reset_all_absent: true,
+ updated_ids: updated_ids, enterprises_to_reset: [enterprise2.id]
importer.reset_absent(updated_ids)
- beans = VariantOverride.where(variant_id: product2.variants.first.id, hub_id: enterprise2.id).first
- sprouts = VariantOverride.where(variant_id: product3.variants.first.id, hub_id: enterprise2.id).first
- cabbage = VariantOverride.where(variant_id: product4.variants.first.id, hub_id: enterprise2.id).first
- lettuce = VariantOverride.where(variant_id: product5.variants.first.id, hub_id: enterprise.id).first
+ beans = VariantOverride.where(variant_id: product2.variants.first.id,
+ hub_id: enterprise2.id).first
+ sprouts = VariantOverride.where(variant_id: product3.variants.first.id,
+ hub_id: enterprise2.id).first
+ cabbage = VariantOverride.where(variant_id: product4.variants.first.id,
+ hub_id: enterprise2.id).first
+ lettuce = VariantOverride.where(variant_id: product5.variants.first.id,
+ hub_id: enterprise.id).first
expect(beans.count_on_hand).to eq 6 # Present in file, created
expect(sprouts.count_on_hand).to eq 7 # Present in file, created
@@ -744,7 +853,8 @@ def import_data(csv_data, args = {})
reset_all_absent = args[:reset_all_absent] || false
updated_ids = args[:updated_ids] || nil
enterprises_to_reset = args[:enterprises_to_reset] || nil
- settings = args[:settings] || { 'import_into' => import_into, 'reset_all_absent' => reset_all_absent }
+ settings = args[:settings] || { 'import_into' => import_into,
+ 'reset_all_absent' => reset_all_absent }
File.write('/tmp/test-m.csv', csv_data)
@file ||= File.new('/tmp/test-m.csv')
@@ -764,7 +874,8 @@ def filter(type, entries)
valid_count += 1 if type == 'valid' && (validates_as != '')
valid_count += 1 if type == 'invalid' && (validates_as == '')
- valid_count += 1 if type == 'create_product' && ['new_product', 'new_variant'].include?(validates_as)
+ valid_count += 1 if type == 'create_product' && ['new_product',
+ 'new_variant'].include?(validates_as)
valid_count += 1 if type == 'update_product' && validates_as == 'existing_variant'
valid_count += 1 if type == 'create_inventory' && validates_as == 'new_inventory_item'
valid_count += 1 if type == 'update_inventory' && validates_as == 'existing_inventory_item'
diff --git a/spec/models/proxy_order_spec.rb b/spec/models/proxy_order_spec.rb
index fc6ccf9810..8f6c9973aa 100644
--- a/spec/models/proxy_order_spec.rb
+++ b/spec/models/proxy_order_spec.rb
@@ -13,7 +13,9 @@ describe ProxyOrder, type: :model do
end
context "when the order cycle is not yet closed" do
- let(:proxy_order) { create(:proxy_order, subscription: subscription, order: order, order_cycle: order_cycle) }
+ let(:proxy_order) {
+ create(:proxy_order, subscription: subscription, order: order, order_cycle: order_cycle)
+ }
before { order_cycle.update(orders_open_at: 1.day.ago, orders_close_at: 3.days.from_now) }
context "and an order has not been initialised" do
@@ -30,7 +32,9 @@ describe ProxyOrder, type: :model do
let(:order) { create(:completed_order_with_totals) }
it "returns true and sets canceled_at to the current time, and cancels the order" do
- expect(Spree::OrderMailer).to receive(:cancel_email) { double(:email, deliver_later: true) }
+ expect(Spree::OrderMailer).to receive(:cancel_email) {
+ double(:email, deliver_later: true)
+ }
expect(proxy_order.cancel).to be true
expect_cancelled_now proxy_order
expect(order.reload.state).to eq 'canceled'
@@ -51,7 +55,9 @@ describe ProxyOrder, type: :model do
end
context "when the order cycle is already closed" do
- let(:proxy_order) { create(:proxy_order, subscription: subscription, order: order, order_cycle: order_cycle) }
+ let(:proxy_order) {
+ create(:proxy_order, subscription: subscription, order: order, order_cycle: order_cycle)
+ }
before { order_cycle.update(orders_open_at: 3.days.ago, orders_close_at: 1.minute.ago) }
context "and an order has not been initialised" do
@@ -107,8 +113,10 @@ describe ProxyOrder, type: :model do
context "and the order has already been cancelled" do
before do
- allow(Spree::OrderMailer).to receive(:cancel_email) { double(:email, deliver_later: true) }
- while !order.completed? do break unless order.next! end
+ allow(Spree::OrderMailer).to receive(:cancel_email) {
+ double(:email, deliver_later: true)
+ }
+ break unless order.next! while !order.completed?
order.cancel
end
@@ -121,7 +129,7 @@ describe ProxyOrder, type: :model do
end
context "and the order has not been cancelled" do
- before { while !order.completed? do break unless order.next! end }
+ before { break unless order.next! while !order.completed? }
it "returns true and clears canceled_at" do
expect(proxy_order.resume).to be true
@@ -147,8 +155,10 @@ describe ProxyOrder, type: :model do
context "and the order has been cancelled" do
before do
- allow(Spree::OrderMailer).to receive(:cancel_email) { double(:email, deliver_later: true) }
- while !order.completed? do break unless order.next! end
+ allow(Spree::OrderMailer).to receive(:cancel_email) {
+ double(:email, deliver_later: true)
+ }
+ break unless order.next! while !order.completed?
order.cancel
end
@@ -161,7 +171,7 @@ describe ProxyOrder, type: :model do
end
context "and the order has not been cancelled" do
- before { while !order.completed? do break unless order.next! end }
+ before { break unless order.next! while !order.completed? }
it "returns false and does nothing" do
expect(proxy_order.resume).to eq false
diff --git a/spec/models/spree/ability_spec.rb b/spec/models/spree/ability_spec.rb
index 6fcc30e722..fe19c51f6a 100644
--- a/spec/models/spree/ability_spec.rb
+++ b/spec/models/spree/ability_spec.rb
@@ -328,7 +328,10 @@ describe Spree::Ability do
let(:er1) { create(:enterprise_relationship, parent: s1, child: d1) }
let(:er2) { create(:enterprise_relationship, parent: d1, child: s1) }
- let(:er_ps) { create(:enterprise_relationship, parent: s_related, child: s1, permissions_list: [:manage_products]) }
+ let(:er_ps) {
+ create(:enterprise_relationship, parent: s_related, child: s1,
+ permissions_list: [:manage_products])
+ }
subject { user }
let(:user) { nil }
@@ -345,19 +348,27 @@ describe Spree::Ability do
let(:order) { create(:order) }
it "should be able to read/write their enterprises' products and variants" do
- is_expected.to have_ability([:admin, :read, :update, :bulk_update, :clone, :destroy], for: p1)
- is_expected.to have_ability([:admin, :index, :read, :edit, :update, :search, :destroy, :delete], for: p1.master)
+ is_expected.to have_ability([:admin, :read, :update, :bulk_update, :clone, :destroy],
+ for: p1)
+ is_expected.to have_ability(
+ [:admin, :index, :read, :edit, :update, :search, :destroy, :delete], for: p1.master
+ )
end
it "should be able to read/write related enterprises' products and variants with manage_products permission" do
er_ps
- is_expected.to have_ability([:admin, :read, :update, :bulk_update, :clone, :destroy], for: p_related)
- is_expected.to have_ability([:admin, :index, :read, :edit, :update, :search, :destroy, :delete], for: p_related.master)
+ is_expected.to have_ability([:admin, :read, :update, :bulk_update, :clone, :destroy],
+ for: p_related)
+ is_expected.to have_ability(
+ [:admin, :index, :read, :edit, :update, :search, :destroy, :delete], for: p_related.master
+ )
end
it "should not be able to read/write other enterprises' products and variants" do
- is_expected.not_to have_ability([:admin, :read, :update, :bulk_update, :clone, :destroy], for: p2)
- is_expected.not_to have_ability([:admin, :index, :read, :edit, :update, :search, :destroy], for: p2.master)
+ is_expected.not_to have_ability([:admin, :read, :update, :bulk_update, :clone, :destroy],
+ for: p2)
+ is_expected.not_to have_ability([:admin, :index, :read, :edit, :update, :search, :destroy],
+ for: p2.master)
end
it "should not be able to access admin actions on orders" do
@@ -370,19 +381,28 @@ describe Spree::Ability do
it "should be able to read/write their enterprises' product variants" do
is_expected.to have_ability([:create], for: Spree::Variant)
- is_expected.to have_ability([:admin, :index, :read, :create, :edit, :search, :update, :destroy, :delete], for: p1.master)
+ is_expected.to have_ability(
+ [:admin, :index, :read, :create, :edit, :search, :update, :destroy,
+ :delete], for: p1.master
+ )
end
it "should not be able to read/write other enterprises' product variants" do
- is_expected.not_to have_ability([:admin, :index, :read, :create, :edit, :search, :update, :destroy], for: p2.master)
+ is_expected.not_to have_ability(
+ [:admin, :index, :read, :create, :edit, :search, :update, :destroy], for: p2.master
+ )
end
it "should be able to read/write their enterprises' product properties" do
- is_expected.to have_ability([:admin, :index, :read, :create, :edit, :update_positions, :destroy], for: Spree::ProductProperty)
+ is_expected.to have_ability(
+ [:admin, :index, :read, :create, :edit, :update_positions,
+ :destroy], for: Spree::ProductProperty
+ )
end
it "should be able to read/write their enterprises' product images" do
- is_expected.to have_ability([:admin, :index, :read, :create, :edit, :update, :destroy], for: Spree::Image)
+ is_expected.to have_ability([:admin, :index, :read, :create, :edit, :update, :destroy],
+ for: Spree::Image)
end
it "should be able to read Taxons (in order to create classifications)" do
@@ -390,11 +410,15 @@ describe Spree::Ability do
end
it "should be able to read/write Classifications on a product" do
- is_expected.to have_ability([:admin, :index, :read, :create, :edit], for: Spree::Classification)
+ is_expected.to have_ability([:admin, :index, :read, :create, :edit],
+ for: Spree::Classification)
end
it "should be able to read/write their enterprises' producer properties" do
- is_expected.to have_ability([:admin, :index, :read, :create, :edit, :update_positions, :destroy], for: ProducerProperty)
+ is_expected.to have_ability(
+ [:admin, :index, :read, :create, :edit, :update_positions,
+ :destroy], for: ProducerProperty
+ )
end
it "should be able to read and create enterprise relationships" do
@@ -410,13 +434,19 @@ describe Spree::Ability do
end
it "should be able to read some reports" do
- is_expected.to have_ability([:admin, :index, :customers, :bulk_coop, :orders_and_fulfillment, :products_and_inventory, :order_cycle_management], for: Spree::Admin::ReportsController)
+ is_expected.to have_ability(
+ [:admin, :index, :customers, :bulk_coop, :orders_and_fulfillment, :products_and_inventory,
+ :order_cycle_management], for: Spree::Admin::ReportsController
+ )
end
include_examples "allows access to Enterprise Fee Summary"
it "should not be able to read other reports" do
- is_expected.not_to have_ability([:group_buys, :payments, :orders_and_distributors, :users_and_enterprises, :xero_invoices], for: Spree::Admin::ReportsController)
+ is_expected.not_to have_ability(
+ [:group_buys, :payments, :orders_and_distributors, :users_and_enterprises,
+ :xero_invoices], for: Spree::Admin::ReportsController
+ )
end
it "should not be able to access customer actions" do
@@ -428,7 +458,8 @@ describe Spree::Ability do
let!(:order_cycle) { create(:simple_order_cycle) }
it "should not be able to access read/update order_cycle actions" do
- is_expected.not_to have_ability([:admin, :index, :read, :edit, :update], for: order_cycle)
+ is_expected.not_to have_ability([:admin, :index, :read, :edit, :update],
+ for: order_cycle)
end
it "should not be able to access bulk_update, clone order cycle actions" do
@@ -446,7 +477,10 @@ describe Spree::Ability do
context "where the enterprise is in an order_cycle" do
let!(:order_cycle) { create(:simple_order_cycle) }
- let!(:exchange){ create(:exchange, incoming: true, order_cycle: order_cycle, receiver: order_cycle.coordinator, sender: s1) }
+ let!(:exchange){
+ create(:exchange, incoming: true, order_cycle: order_cycle, receiver: order_cycle.coordinator,
+ sender: s1)
+ }
it "should be able to access read/update order cycle actions" do
is_expected.to have_ability([:admin, :index, :read, :edit, :update], for: order_cycle)
@@ -493,22 +527,36 @@ describe Spree::Ability do
describe "editing enterprises" do
let!(:d_related) { create(:distributor_enterprise) }
- let!(:er_pd) { create(:enterprise_relationship, parent: d_related, child: d1, permissions_list: [:edit_profile]) }
+ let!(:er_pd) {
+ create(:enterprise_relationship, parent: d_related, child: d1,
+ permissions_list: [:edit_profile])
+ }
it "should be able to edit enterprises it manages" do
- is_expected.to have_ability([:read, :edit, :update, :remove_logo, :remove_promo_image, :remove_terms_and_conditions, :bulk_update, :resend_confirmation], for: d1)
+ is_expected.to have_ability(
+ [:read, :edit, :update, :remove_logo, :remove_promo_image, :remove_terms_and_conditions,
+ :bulk_update, :resend_confirmation], for: d1
+ )
end
it "should be able to edit enterprises it has permission to" do
- is_expected.to have_ability([:read, :edit, :update, :remove_logo, :remove_promo_image, :remove_terms_and_conditions, :bulk_update, :resend_confirmation], for: d_related)
+ is_expected.to have_ability(
+ [:read, :edit, :update, :remove_logo, :remove_promo_image, :remove_terms_and_conditions,
+ :bulk_update, :resend_confirmation], for: d_related
+ )
end
it "should be able to manage shipping methods, payment methods and enterprise fees for enterprises it manages" do
- is_expected.to have_ability([:manage_shipping_methods, :manage_payment_methods, :manage_enterprise_fees], for: d1)
+ is_expected.to have_ability(
+ [:manage_shipping_methods, :manage_payment_methods, :manage_enterprise_fees], for: d1
+ )
end
it "should not be able to manage shipping methods, payment methods and enterprise fees for enterprises it has edit profile permission to" do
- is_expected.not_to have_ability([:manage_shipping_methods, :manage_payment_methods, :manage_enterprise_fees], for: d_related)
+ is_expected.not_to have_ability(
+ [:manage_shipping_methods, :manage_payment_methods,
+ :manage_enterprise_fees], for: d_related
+ )
end
end
@@ -518,10 +566,14 @@ describe Spree::Ability do
let(:vo3) { create(:variant_override, hub: d2, variant: p1.master) }
let(:vo4) { create(:variant_override, hub: d2, variant: p2.master) }
- let!(:er1) { create(:enterprise_relationship, parent: s1, child: d1, permissions_list: [:create_variant_overrides]) }
+ let!(:er1) {
+ create(:enterprise_relationship, parent: s1, child: d1,
+ permissions_list: [:create_variant_overrides])
+ }
it "should be able to access variant overrides page" do
- is_expected.to have_ability([:admin, :index, :bulk_update, :bulk_reset], for: VariantOverride)
+ is_expected.to have_ability([:admin, :index, :bulk_update, :bulk_reset],
+ for: VariantOverride)
end
it "should be able to read/write their own variant overrides" do
@@ -566,27 +618,33 @@ describe Spree::Ability do
end
it "should be able to read/write Payments on a product" do
- is_expected.to have_ability([:admin, :index, :read, :create, :edit, :update, :fire], for: Spree::Payment)
+ is_expected.to have_ability([:admin, :index, :read, :create, :edit, :update, :fire],
+ for: Spree::Payment)
end
it "should be able to read/write Shipments on a product" do
- is_expected.to have_ability([:admin, :index, :read, :create, :edit, :update, :fire], for: Spree::Shipment)
+ is_expected.to have_ability([:admin, :index, :read, :create, :edit, :update, :fire],
+ for: Spree::Shipment)
end
it "should be able to read/write Adjustments on a product" do
- is_expected.to have_ability([:admin, :index, :read, :create, :edit, :update, :fire], for: Spree::Adjustment)
+ is_expected.to have_ability([:admin, :index, :read, :create, :edit, :update, :fire],
+ for: Spree::Adjustment)
end
it "should be able to read/write ReturnAuthorizations on a product" do
- is_expected.to have_ability([:admin, :index, :read, :create, :edit, :update, :fire], for: Spree::ReturnAuthorization)
+ is_expected.to have_ability([:admin, :index, :read, :create, :edit, :update, :fire],
+ for: Spree::ReturnAuthorization)
end
it "should be able to read/write PaymentMethods" do
- is_expected.to have_ability([:admin, :index, :create, :update, :destroy], for: Spree::PaymentMethod)
+ is_expected.to have_ability([:admin, :index, :create, :update, :destroy],
+ for: Spree::PaymentMethod)
end
it "should be able to read/write ShippingMethods" do
- is_expected.to have_ability([:admin, :index, :create, :update, :destroy], for: Spree::ShippingMethod)
+ is_expected.to have_ability([:admin, :index, :create, :update, :destroy],
+ for: Spree::ShippingMethod)
end
it "should be able to read and create enterprise relationships" do
@@ -602,13 +660,17 @@ describe Spree::Ability do
end
it "should be able to read some reports" do
- is_expected.to have_ability([:admin, :index, :customers, :sales_tax, :group_buys, :bulk_coop, :payments, :orders_and_distributors, :orders_and_fulfillment, :products_and_inventory, :order_cycle_management, :xero_invoices], for: Spree::Admin::ReportsController)
+ is_expected.to have_ability(
+ [:admin, :index, :customers, :sales_tax, :group_buys, :bulk_coop, :payments,
+ :orders_and_distributors, :orders_and_fulfillment, :products_and_inventory, :order_cycle_management, :xero_invoices], for: Spree::Admin::ReportsController
+ )
end
include_examples "allows access to Enterprise Fee Summary"
it "should not be able to read other reports" do
- is_expected.not_to have_ability([:users_and_enterprises], for: Spree::Admin::ReportsController)
+ is_expected.not_to have_ability([:users_and_enterprises],
+ for: Spree::Admin::ReportsController)
end
it "should be able to access customer actions" do
@@ -617,7 +679,10 @@ describe Spree::Ability do
context "for a given order_cycle" do
let!(:order_cycle) { create(:simple_order_cycle, coordinator: d2) }
- let!(:exchange){ create(:exchange, incoming: false, order_cycle: order_cycle, receiver: d1, sender: order_cycle.coordinator) }
+ let!(:exchange){
+ create(:exchange, incoming: false, order_cycle: order_cycle, receiver: d1,
+ sender: order_cycle.coordinator)
+ }
it "should be able to access read and update order cycle actions" do
is_expected.to have_ability([:admin, :index, :read, :edit, :update], for: order_cycle)
@@ -649,11 +714,15 @@ describe Spree::Ability do
let(:oc2) { create(:simple_order_cycle, coordinator: d2) }
it "should be able to read/write OrderCycles they are the co-ordinator of" do
- is_expected.to have_ability([:admin, :index, :read, :edit, :update, :bulk_update, :clone, :destroy], for: oc1)
+ is_expected.to have_ability(
+ [:admin, :index, :read, :edit, :update, :bulk_update, :clone, :destroy], for: oc1
+ )
end
it "should not be able to read/write OrderCycles they are not the co-ordinator of" do
- should_not have_ability([:admin, :index, :read, :create, :edit, :update, :bulk_update, :clone, :destroy], for: oc2)
+ should_not have_ability(
+ [:admin, :index, :read, :create, :edit, :update, :bulk_update, :clone, :destroy], for: oc2
+ )
end
it "should be able to create OrderCycles" do
@@ -661,7 +730,10 @@ describe Spree::Ability do
end
it "should be able to read/write EnterpriseFees" do
- is_expected.to have_ability([:admin, :index, :read, :create, :edit, :bulk_update, :destroy, :for_order_cycle], for: EnterpriseFee)
+ is_expected.to have_ability(
+ [:admin, :index, :read, :create, :edit, :bulk_update, :destroy,
+ :for_order_cycle], for: EnterpriseFee
+ )
end
it "should be able to add enterprises to order cycles" do
@@ -753,7 +825,9 @@ describe Spree::Ability do
describe "when user of the distributor which is also the producer" do
let(:user) { distributor.owner }
- let!(:distributor) { create(:distributor_enterprise, is_primary_producer: true, sells: "any") }
+ let!(:distributor) {
+ create(:distributor_enterprise, is_primary_producer: true, sells: "any")
+ }
let!(:producer) { distributor }
it "should have permission" do
@@ -764,7 +838,8 @@ describe Spree::Ability do
describe "when owner of the distributor with add_to_order_cycle permission to the producer" do
let!(:unauthorized_enterprise) do
create(:enterprise, sells: "any").tap do |record|
- create(:enterprise_relationship, parent: producer, child: record, permissions_list: [:add_to_order_cycle])
+ create(:enterprise_relationship, parent: producer, child: record,
+ permissions_list: [:add_to_order_cycle])
end
end
let(:user) { unauthorized_enterprise.owner }
@@ -777,7 +852,8 @@ describe Spree::Ability do
describe "when owner of the enterprise with create_variant_overrides permission to the producer" do
let!(:authorized_enterprise) do
create(:enterprise, sells: "any").tap do |record|
- create(:enterprise_relationship, parent: producer, child: record, permissions_list: [:create_variant_overrides])
+ create(:enterprise_relationship, parent: producer, child: record,
+ permissions_list: [:create_variant_overrides])
end
end
let(:user) { authorized_enterprise.owner }
@@ -789,7 +865,8 @@ describe Spree::Ability do
describe "when the enterprise is not a distributor" do
let!(:authorized_enterprise) do
create(:enterprise, sells: "none").tap do |record|
- create(:enterprise_relationship, parent: producer, child: record, permissions_list: [:create_variant_overrides])
+ create(:enterprise_relationship, parent: producer, child: record,
+ permissions_list: [:create_variant_overrides])
end
end
diff --git a/spec/models/spree/adjustment_spec.rb b/spec/models/spree/adjustment_spec.rb
index 76c63879dc..4ee57d8b77 100644
--- a/spec/models/spree/adjustment_spec.rb
+++ b/spec/models/spree/adjustment_spec.rb
@@ -9,7 +9,9 @@ module Spree
describe "scopes" do
let!(:arbitrary_adjustment) { create(:adjustment, label: "Arbitrary") }
- let!(:return_authorization_adjustment) { create(:adjustment, originator: create(:return_authorization)) }
+ let!(:return_authorization_adjustment) {
+ create(:adjustment, originator: create(:return_authorization))
+ }
it "returns return_authorization adjustments" do
expect(Spree::Adjustment.return_authorization.to_a).to eq [return_authorization_adjustment]
@@ -21,7 +23,8 @@ module Spree
let(:originator) { instance_double(EnterpriseFee, compute_amount: 10.0) }
before do
- allow(adjustment).to receive_messages originator: originator, label: 'adjustment', amount: 0
+ allow(adjustment).to receive_messages originator: originator, label: 'adjustment',
+ amount: 0
end
it "should do nothing when closed" do
@@ -223,8 +226,12 @@ module Spree
let(:order) { create(:order, distributor: hub) }
let(:line_item) { create(:line_item, order: order) }
- let(:shipping_method) { create(:shipping_method_with, :flat_rate, tax_category: tax_category) }
- let(:shipment) { create(:shipment_with, :shipping_method, shipping_method: shipping_method, order: order) }
+ let(:shipping_method) {
+ create(:shipping_method_with, :flat_rate, tax_category: tax_category)
+ }
+ let(:shipment) {
+ create(:shipment_with, :shipping_method, shipping_method: shipping_method, order: order)
+ }
describe "the shipping charge" do
it "is the adjustment amount" do
@@ -325,14 +332,23 @@ module Spree
describe "EnterpriseFee adjustments" do
let(:zone) { create(:zone_with_member) }
- let(:fee_tax_rate) { create(:tax_rate, included_in_price: true, calculator: ::Calculator::DefaultTax.new, zone: zone, amount: 0.1) }
+ let(:fee_tax_rate) {
+ create(:tax_rate, included_in_price: true, calculator: ::Calculator::DefaultTax.new, zone: zone,
+ amount: 0.1)
+ }
let(:fee_tax_category) { create(:tax_category, tax_rates: [fee_tax_rate]) }
let(:coordinator) { create(:distributor_enterprise, charges_sales_tax: true) }
let(:variant) { create(:variant, product: create(:product, tax_category: nil)) }
- let(:order_cycle) { create(:simple_order_cycle, coordinator: coordinator, coordinator_fees: [enterprise_fee], distributors: [coordinator], variants: [variant]) }
+ let(:order_cycle) {
+ create(:simple_order_cycle, coordinator: coordinator, coordinator_fees: [enterprise_fee],
+ distributors: [coordinator], variants: [variant])
+ }
let(:line_item) { create(:line_item, variant: variant) }
- let(:order) { create(:order, line_items: [line_item], order_cycle: order_cycle, distributor: coordinator) }
+ let(:order) {
+ create(:order, line_items: [line_item], order_cycle: order_cycle,
+ distributor: coordinator)
+ }
let(:fee) { order.all_adjustments.reload.enterprise_fee.first }
let(:fee_tax) { fee.adjustments.tax.first }
@@ -342,7 +358,10 @@ module Spree
end
context "when enterprise fees are taxed per-order" do
- let(:enterprise_fee) { create(:enterprise_fee, enterprise: coordinator, tax_category: fee_tax_category, calculator: ::Calculator::FlatRate.new(preferred_amount: 50.0)) }
+ let(:enterprise_fee) {
+ create(:enterprise_fee, enterprise: coordinator, tax_category: fee_tax_category,
+ calculator: ::Calculator::FlatRate.new(preferred_amount: 50.0))
+ }
describe "when the tax rate includes the tax in the price" do
it "records the correct amount in a tax adjustment" do
@@ -378,7 +397,10 @@ module Spree
end
context "when enterprise fees are taxed per-item" do
- let(:enterprise_fee) { create(:enterprise_fee, enterprise: coordinator, tax_category: fee_tax_category, calculator: ::Calculator::PerItem.new(preferred_amount: 50.0)) }
+ let(:enterprise_fee) {
+ create(:enterprise_fee, enterprise: coordinator, tax_category: fee_tax_category,
+ calculator: ::Calculator::PerItem.new(preferred_amount: 50.0))
+ }
describe "when the tax rate includes the tax in the price" do
it "records the correct amount in a tax adjustment" do
@@ -401,7 +423,8 @@ module Spree
context "when enterprise fees inherit their tax_category from the product they are applied to" do
let(:product_tax_rate) {
- create(:tax_rate, included_in_price: true, calculator: ::Calculator::DefaultTax.new, zone: zone, amount: 0.2)
+ create(:tax_rate, included_in_price: true, calculator: ::Calculator::DefaultTax.new,
+ zone: zone, amount: 0.2)
}
let(:product_tax_category) { create(:tax_category, tax_rates: [product_tax_rate]) }
@@ -411,7 +434,10 @@ module Spree
end
context "when enterprise fees are taxed per-order" do
- let(:enterprise_fee) { create(:enterprise_fee, enterprise: coordinator, inherits_tax_category: true, calculator: ::Calculator::FlatRate.new(preferred_amount: 50.0)) }
+ let(:enterprise_fee) {
+ create(:enterprise_fee, enterprise: coordinator, inherits_tax_category: true,
+ calculator: ::Calculator::FlatRate.new(preferred_amount: 50.0))
+ }
describe "when the tax rate includes the tax in the price" do
it "records no tax on the enterprise fee adjustments" do
@@ -439,7 +465,10 @@ module Spree
end
context "when enterprise fees are taxed per-item" do
- let(:enterprise_fee) { create(:enterprise_fee, enterprise: coordinator, inherits_tax_category: true, calculator: ::Calculator::PerItem.new(preferred_amount: 50.0)) }
+ let(:enterprise_fee) {
+ create(:enterprise_fee, enterprise: coordinator, inherits_tax_category: true,
+ calculator: ::Calculator::PerItem.new(preferred_amount: 50.0))
+ }
describe "when the tax rate includes the tax in the price" do
it "records the correct amount in a tax adjustment" do
diff --git a/spec/models/spree/gateway/stripe_connect_spec.rb b/spec/models/spree/gateway/stripe_connect_spec.rb
index 4f5793f551..4b25c81439 100644
--- a/spec/models/spree/gateway/stripe_connect_spec.rb
+++ b/spec/models/spree/gateway/stripe_connect_spec.rb
@@ -70,7 +70,8 @@ describe Spree::Gateway::StripeConnect, type: :model do
end
it "requests a new token for the customer and card from Stripe, and returns the id of the response" do
- expect(subject.send(:tokenize_instance_customer_card, customer_id, card_id)).to eq token_mock[:id]
+ expect(subject.send(:tokenize_instance_customer_card, customer_id,
+ card_id)).to eq token_mock[:id]
end
end
@@ -88,7 +89,8 @@ describe Spree::Gateway::StripeConnect, type: :model do
end
it "adds the stripe_account to the gateway options hash" do
- expect(provider).to have_received(:refund).with(money, response_code, hash_including(stripe_account: stripe_account_id))
+ expect(provider).to have_received(:refund).with(money, response_code,
+ hash_including(stripe_account: stripe_account_id))
end
end
diff --git a/spec/models/spree/gateway/stripe_sca_spec.rb b/spec/models/spree/gateway/stripe_sca_spec.rb
index ef4216240d..bf8b29d9b8 100644
--- a/spec/models/spree/gateway/stripe_sca_spec.rb
+++ b/spec/models/spree/gateway/stripe_sca_spec.rb
@@ -33,7 +33,7 @@ describe Spree::Gateway::StripeSCA, type: :model do
stub_request(:get, "https://api.stripe.com/v1/payment_intents/12345").
to_return(status: 200, body: payment_authorised)
stub_request(:post, "https://api.stripe.com/v1/payment_intents/12345/capture").
- with(body: {"amount_to_capture" => order.total}).
+ with(body: { "amount_to_capture" => order.total }).
to_return(status: 200, body: capture_successful)
response = subject.purchase(order.total, credit_card, gateway_options)
@@ -58,7 +58,7 @@ describe Spree::Gateway::StripeSCA, type: :model do
it "succeeds if payment intent state is requires_capture" do
stub_request(:post, "https://api.stripe.com/v1/payment_intents/12345/capture").
- with(body: {"amount_to_capture" => order.total}).
+ with(body: { "amount_to_capture" => order.total }).
to_return(status: 200, body: capture_successful)
allow(Stripe::PaymentIntentValidator).to receive_message_chain(:new, :call).
diff --git a/spec/models/spree/line_item_spec.rb b/spec/models/spree/line_item_spec.rb
index c740d4b018..848b5a8271 100644
--- a/spec/models/spree/line_item_spec.rb
+++ b/spec/models/spree/line_item_spec.rb
@@ -172,7 +172,9 @@ module Spree
describe "finding line items with and without tax" do
let(:tax_rate) { create(:tax_rate, calculator: ::Calculator::DefaultTax.new) }
- let!(:adjustment1) { create(:adjustment, originator: tax_rate, label: "TR", amount: 123, included_tax: 10.00) }
+ let!(:adjustment1) {
+ create(:adjustment, originator: tax_rate, label: "TR", amount: 123, included_tax: 10.00)
+ }
before do
li1
@@ -289,13 +291,15 @@ module Spree
ship_address: bill_address)
}
let!(:shipping_method) { create(:shipping_method, distributors: [hub]) }
- let!(:line_item) { create(:line_item, variant: variant_on_demand, quantity: 10, order: order) }
+ let!(:line_item) {
+ create(:line_item, variant: variant_on_demand, quantity: 10, order: order)
+ }
before do
order.reload
order.update_totals
order.payments << create(:payment, amount: order.total)
- until order.completed? do break unless order.next! end
+ break unless order.next! until order.completed?
order.payment_state = 'paid'
order.select_shipping_method(shipping_method.id)
order.shipment.update!(order)
@@ -344,14 +348,18 @@ module Spree
it "draws stock from the variant override" do
expect(vo.reload.count_on_hand).to eq 3
- expect{ line_item.increment!(:quantity) }.to_not change{ Spree::Variant.find(variant.id).on_hand }
+ expect{ line_item.increment!(:quantity) }.to_not change{
+ Spree::Variant.find(variant.id).on_hand
+ }
expect(vo.reload.count_on_hand).to eq 2
end
end
context "when a variant override does not apply" do
it "draws stock from the variant" do
- expect{ line_item.increment!(:quantity) }.to change{ Spree::Variant.find(variant.id).on_hand }.by(-1)
+ expect{ line_item.increment!(:quantity) }.to change{
+ Spree::Variant.find(variant.id).on_hand
+ }.by(-1)
end
end
end
@@ -388,7 +396,9 @@ module Spree
let!(:v) { create(:variant, on_demand: false, on_hand: 10) }
let!(:v_on_demand) { create(:variant, on_demand: true, on_hand: 1) }
let(:li) { build_stubbed(:line_item, variant: v, order: o, quantity: 5, max_quantity: 5) }
- let(:li_on_demand) { build_stubbed(:line_item, variant: v_on_demand, order: o, quantity: 99, max_quantity: 99) }
+ let(:li_on_demand) {
+ build_stubbed(:line_item, variant: v_on_demand, order: o, quantity: 99, max_quantity: 99)
+ }
context "when the variant is on_demand" do
it { expect(li_on_demand.sufficient_stock?).to be true }
@@ -475,7 +485,10 @@ module Spree
describe "unit value/description" do
describe "inheriting units" do
- let!(:p) { create(:product, variant_unit: "weight", variant_unit_scale: 1, master: create(:variant, unit_value: 1000 )) }
+ let!(:p) {
+ create(:product, variant_unit: "weight", variant_unit_scale: 1,
+ master: create(:variant, unit_value: 1000 ))
+ }
let!(:v) { p.variants.first }
let!(:o) { create(:order) }
@@ -491,7 +504,9 @@ module Spree
end
context "when a final_weight_volume has been set" do
- let(:li) { build(:line_item, order: o, variant: v, quantity: 3, final_weight_volume: 2000) }
+ let(:li) {
+ build(:line_item, order: o, variant: v, quantity: 3, final_weight_volume: 2000)
+ }
it "uses the changed value" do
expect(li.final_weight_volume).to eq 2000
diff --git a/spec/models/spree/order/state_machine_spec.rb b/spec/models/spree/order/state_machine_spec.rb
index e61b84a9f4..74c9f8cf25 100644
--- a/spec/models/spree/order/state_machine_spec.rb
+++ b/spec/models/spree/order/state_machine_spec.rb
@@ -94,7 +94,8 @@ describe Spree::Order do
end
before do
- allow(order).to receive_messages line_items: [build(:line_item, variant: variant, quantity: 2)]
+ allow(order).to receive_messages line_items: [build(:line_item, variant: variant,
+ quantity: 2)]
allow(order.line_items).to receive_messages find_by_variant_id: order.line_items.first
allow(order).to receive_messages completed?: true
diff --git a/spec/models/spree/order_contents_spec.rb b/spec/models/spree/order_contents_spec.rb
index 88f6ff48fd..6e03cd35e2 100644
--- a/spec/models/spree/order_contents_spec.rb
+++ b/spec/models/spree/order_contents_spec.rb
@@ -55,7 +55,7 @@ describe Spree::OrderContents do
expect{
subject.remove(variant)
- }.to change(Spree::LineItem, :count).by -1
+ }.to change(Spree::LineItem, :count).by(-1)
end
end
diff --git a/spec/models/spree/order_inventory_spec.rb b/spec/models/spree/order_inventory_spec.rb
index e4f84565bf..09de81a866 100644
--- a/spec/models/spree/order_inventory_spec.rb
+++ b/spec/models/spree/order_inventory_spec.rb
@@ -103,8 +103,10 @@ describe Spree::OrderInventory do
it 'should destroy backordered units first' do
allow(shipment).to receive_messages(inventory_units_for: [build(:inventory_unit, variant_id: variant.id, state: 'backordered'),
- build(:inventory_unit, variant_id: variant.id, state: 'on_hand'),
- build(:inventory_unit, variant_id: variant.id, state: 'backordered')])
+ build(:inventory_unit,
+ variant_id: variant.id, state: 'on_hand'),
+ build(:inventory_unit,
+ variant_id: variant.id, state: 'backordered')])
expect(shipment.inventory_units_for[0]).to receive(:destroy)
expect(shipment.inventory_units_for[1]).not_to receive(:destroy)
@@ -115,7 +117,8 @@ describe Spree::OrderInventory do
it 'should destroy unshipped units first' do
allow(shipment).to receive_messages(inventory_units_for: [build(:inventory_unit, variant_id: variant.id, state: 'shipped'),
- build(:inventory_unit, variant_id: variant.id, state: 'on_hand')] )
+ build(:inventory_unit,
+ variant_id: variant.id, state: 'on_hand')] )
expect(shipment.inventory_units_for[0]).not_to receive(:destroy)
expect(shipment.inventory_units_for[1]).to receive(:destroy)
@@ -125,7 +128,8 @@ describe Spree::OrderInventory do
it 'only attempts to destroy as many units as are eligible, and return amount destroyed' do
allow(shipment).to receive_messages(inventory_units_for: [build(:inventory_unit, variant_id: variant.id, state: 'shipped'),
- build(:inventory_unit, variant_id: variant.id, state: 'on_hand')] )
+ build(:inventory_unit,
+ variant_id: variant.id, state: 'on_hand')] )
expect(shipment.inventory_units_for[0]).not_to receive(:destroy)
expect(shipment.inventory_units_for[1]).to receive(:destroy)
diff --git a/spec/models/spree/order_spec.rb b/spec/models/spree/order_spec.rb
index bc8fcb9510..e6b7086e98 100644
--- a/spec/models/spree/order_spec.rb
+++ b/spec/models/spree/order_spec.rb
@@ -605,12 +605,18 @@ describe Spree::Order do
describe "getting the shipping tax" do
let(:order) { create(:order) }
- let(:shipping_tax_rate) { create(:tax_rate, amount: 0.25, included_in_price: true, zone: create(:zone_with_member)) }
+ let(:shipping_tax_rate) {
+ create(:tax_rate, amount: 0.25, included_in_price: true, zone: create(:zone_with_member))
+ }
let(:shipping_tax_category) { create(:tax_category, tax_rates: [shipping_tax_rate]) }
- let!(:shipping_method) { create(:shipping_method_with, :flat_rate, tax_category: shipping_tax_category) }
+ let!(:shipping_method) {
+ create(:shipping_method_with, :flat_rate, tax_category: shipping_tax_category)
+ }
context "with a taxed shipment" do
- let!(:shipment) { create(:shipment_with, :shipping_method, shipping_method: shipping_method, order: order) }
+ let!(:shipment) {
+ create(:shipment_with, :shipping_method, shipping_method: shipping_method, order: order)
+ }
before do
allow(order).to receive(:tax_zone) { shipping_tax_rate.zone }
@@ -647,7 +653,7 @@ describe Spree::Order do
}
let!(:admin_adjustment) {
create(:adjustment, adjustable: order, originator: nil,
- amount: 6.7, order: order, state: "closed")
+ amount: 6.7, order: order, state: "closed")
}
it "returns a sum of all taxes on enterprise fees" do
@@ -799,7 +805,8 @@ describe Spree::Order do
let(:distributor) { create(:enterprise) }
before do
- subject.order_cycle = create(:simple_order_cycle, distributors: [distributor], variants: [variant1, variant2])
+ subject.order_cycle = create(:simple_order_cycle, distributors: [distributor],
+ variants: [variant1, variant2])
subject.distributor = distributor
line_item1 = create(:line_item, order: subject, variant: variant1)
@@ -810,7 +817,8 @@ describe Spree::Order do
it "allows the change when all variants in the order are provided by the new distributor in the new order cycle" do
new_distributor = create(:enterprise)
- new_order_cycle = create(:simple_order_cycle, distributors: [new_distributor], variants: [variant1, variant2])
+ new_order_cycle = create(:simple_order_cycle, distributors: [new_distributor],
+ variants: [variant1, variant2])
subject.distributor = new_distributor
expect(subject).not_to be_valid
@@ -835,7 +843,8 @@ describe Spree::Order do
end
it "finds only orders not in specified state" do
- o = FactoryBot.create(:completed_order_with_totals, distributor: create(:distributor_enterprise))
+ o = FactoryBot.create(:completed_order_with_totals,
+ distributor: create(:distributor_enterprise))
o.cancel!
expect(Spree::Order.not_state(:canceled)).not_to include o
end
@@ -948,7 +957,9 @@ describe Spree::Order do
end
context "and a customer for order.distributor and order.user.email does not alread exist" do
- let!(:customer) { create(:customer, enterprise: distributor, email: 'some-other-email@email.com') }
+ let!(:customer) {
+ create(:customer, enterprise: distributor, email: 'some-other-email@email.com')
+ }
it "does not set the customer and returns nil" do
result = order.send(:associate_customer)
@@ -986,7 +997,9 @@ describe Spree::Order do
context "when a customer not been linked to the order" do
context "but one matching order#email_for_customer already exists" do
- let!(:customer) { create(:customer, enterprise: distributor, email: 'some-other-email@email.com') }
+ let!(:customer) {
+ create(:customer, enterprise: distributor, email: 'some-other-email@email.com')
+ }
before { allow(order).to receive(:email_for_customer) { 'some-other-email@email.com' } }
it "links the customer customer to the order" do
@@ -1109,10 +1122,13 @@ describe Spree::Order do
end
context "changing the shipping method to one without fees" do
- let(:shipping_method) { create(:shipping_method, calculator: Calculator::FlatRate.new(preferred_amount: 0)) }
+ let(:shipping_method) {
+ create(:shipping_method, calculator: Calculator::FlatRate.new(preferred_amount: 0))
+ }
it "updates shipping fees" do
- order.shipments = [create(:shipment_with, :shipping_method, shipping_method: shipping_method)]
+ order.shipments = [create(:shipment_with, :shipping_method,
+ shipping_method: shipping_method)]
order.save
expect(order.adjustment_total).to eq expected_fees - (item_num * shipping_fee)
@@ -1122,7 +1138,9 @@ describe Spree::Order do
end
context "changing the payment method to one without fees" do
- let(:payment_method) { create(:payment_method, calculator: Calculator::FlatRate.new(preferred_amount: 0)) }
+ let(:payment_method) {
+ create(:payment_method, calculator: Calculator::FlatRate.new(preferred_amount: 0))
+ }
it "removes transaction fees" do
# Change the payment method
@@ -1158,12 +1176,19 @@ describe Spree::Order do
end
context "when an order has been finalised in this order cycle" do
- let!(:prev_order) { create(:completed_order_with_totals, distributor: distributor, order_cycle: order_cycle, user: order.user) }
- let!(:prev_order2) { create(:completed_order_with_totals, distributor: distributor, order_cycle: order_cycle, user: order.user) }
+ let!(:prev_order) {
+ create(:completed_order_with_totals, distributor: distributor, order_cycle: order_cycle,
+ user: order.user)
+ }
+ let!(:prev_order2) {
+ create(:completed_order_with_totals, distributor: distributor, order_cycle: order_cycle,
+ user: order.user)
+ }
let(:product) { create(:product) }
before do
- prev_order.contents.update_or_create(product.variants.first, { quantity: 1, max_quantity: 3 })
+ prev_order.contents.update_or_create(product.variants.first,
+ { quantity: 1, max_quantity: 3 })
prev_order2.reload # to get the right response from line_items
end
@@ -1177,7 +1202,9 @@ describe Spree::Order do
describe "determining checkout steps for an order" do
let!(:enterprise) { create(:enterprise) }
let!(:order) { create(:order, distributor: enterprise) }
- let!(:payment_method) { create(:stripe_connect_payment_method, distributor_ids: [enterprise.id]) }
+ let!(:payment_method) {
+ create(:stripe_connect_payment_method, distributor_ids: [enterprise.id])
+ }
let!(:payment) { create(:payment, order: order, payment_method: payment_method) }
it "does not include the :confirm step" do
diff --git a/spec/models/spree/payment_method_spec.rb b/spec/models/spree/payment_method_spec.rb
index 812b74b513..324b1aebd5 100644
--- a/spec/models/spree/payment_method_spec.rb
+++ b/spec/models/spree/payment_method_spec.rb
@@ -72,10 +72,12 @@ module Spree
free_payment_method = create(:payment_method) # flat rate calculator with preferred_amount of 0
expect(free_payment_method.compute_amount(order)).to eq 0
- flat_rate_payment_method = create(:payment_method, calculator: ::Calculator::FlatRate.new(preferred_amount: 10))
+ flat_rate_payment_method = create(:payment_method,
+ calculator: ::Calculator::FlatRate.new(preferred_amount: 10))
expect(flat_rate_payment_method.compute_amount(order)).to eq 10
- flat_percent_payment_method = create(:payment_method, calculator: ::Calculator::FlatPercentItemTotal.new(preferred_flat_percent: 10))
+ flat_percent_payment_method = create(:payment_method,
+ calculator: ::Calculator::FlatPercentItemTotal.new(preferred_flat_percent: 10))
expect(flat_percent_payment_method.compute_amount(order)).to eq 0
product = create(:product)
@@ -89,7 +91,9 @@ module Spree
let!(:distributor_b) { create(:distributor_enterprise) }
let!(:distributor_c) { create(:distributor_enterprise) }
- let!(:payment_method_a) { create(:payment_method, distributors: [distributor_a, distributor_b]) }
+ let!(:payment_method_a) {
+ create(:payment_method, distributors: [distributor_a, distributor_b])
+ }
let!(:payment_method_b) { create(:payment_method, distributors: [distributor_b]) }
let!(:payment_method_c) { create(:payment_method, distributors: [distributor_c]) }
diff --git a/spec/models/spree/payment_spec.rb b/spec/models/spree/payment_spec.rb
index e45cad131c..ad3ebfadf4 100644
--- a/spec/models/spree/payment_spec.rb
+++ b/spec/models/spree/payment_spec.rb
@@ -185,7 +185,8 @@ describe Spree::Payment do
context "purchase" do
it "should call purchase on the gateway with the payment amount" do
- expect(gateway).to receive(:purchase).with(amount_in_cents, card, anything).and_return(success_response)
+ expect(gateway).to receive(:purchase).with(amount_in_cents, card,
+ anything).and_return(success_response)
payment.purchase!
end
@@ -288,7 +289,8 @@ describe Spree::Payment do
context "when profiles are supported" do
it "should call payment_gateway.void with the payment's response_code" do
gateway.stub payment_profiles_supported?: true
- expect(gateway).to receive(:void).with('123', card, anything).and_return(success_response)
+ expect(gateway).to receive(:void).with('123', card,
+ anything).and_return(success_response)
payment.void_transaction!
end
end
@@ -354,7 +356,8 @@ describe Spree::Payment do
end
it "should call credit on the gateway with the credit amount and response_code" do
- expect(gateway).to receive(:credit).with(1000, card, '123', anything).and_return(success_response)
+ expect(gateway).to receive(:credit).with(1000, card, '123',
+ anything).and_return(success_response)
payment.credit!
end
end
@@ -460,7 +463,9 @@ describe Spree::Payment do
context "raises an error if no source is specified" do
specify do
payment = build_stubbed(:payment, source: nil, payment_method: gateway)
- expect { payment.process! }.to raise_error(Spree::Core::GatewayError, Spree.t(:payment_processing_failed))
+ expect {
+ payment.process!
+ }.to raise_error(Spree::Core::GatewayError, Spree.t(:payment_processing_failed))
end
end
end
@@ -572,7 +577,7 @@ describe Spree::Payment do
create(:payment, amount: 100, order: order)
end
end
-
+
context "when profiles are supported" do
before do
gateway.stub payment_profiles_supported?: true
@@ -883,8 +888,13 @@ describe Spree::Payment do
context "to Stripe payments" do
let(:shop) { create(:enterprise) }
- let(:payment_method) { create(:stripe_connect_payment_method, distributor_ids: [create(:distributor_enterprise).id], preferred_enterprise_id: shop.id) }
- let(:payment) { create(:payment, order: order, payment_method: payment_method, amount: order.total) }
+ let(:payment_method) {
+ create(:stripe_connect_payment_method, distributor_ids: [create(:distributor_enterprise).id],
+ preferred_enterprise_id: shop.id)
+ }
+ let(:payment) {
+ create(:payment, order: order, payment_method: payment_method, amount: order.total)
+ }
let(:calculator) { ::Calculator::FlatPercentItemTotal.new(preferred_flat_percent: 10) }
before do
@@ -895,7 +905,9 @@ describe Spree::Payment do
end
context "when the payment fails" do
- let(:failed_response) { ActiveMerchant::Billing::Response.new(false, "This is an error message") }
+ let(:failed_response) {
+ ActiveMerchant::Billing::Response.new(false, "This is an error message")
+ }
before do
allow(payment_method).to receive(:purchase) { failed_response }
diff --git a/spec/models/spree/product_spec.rb b/spec/models/spree/product_spec.rb
index 37fd516ada..91cb6cec6b 100644
--- a/spec/models/spree/product_spec.rb
+++ b/spec/models/spree/product_spec.rb
@@ -410,7 +410,10 @@ module Spree
let(:product) { create(:simple_product) }
let(:supplier) { product.supplier }
let(:distributor) { create(:distributor_enterprise) }
- let!(:oc) { create(:simple_order_cycle, distributors: [distributor], variants: [product.variants.first]) }
+ let!(:oc) {
+ create(:simple_order_cycle, distributors: [distributor],
+ variants: [product.variants.first])
+ }
it "touches the supplier" do
expect { product.destroy }.to change { supplier.reload.updated_at }
@@ -558,8 +561,10 @@ module Spree
d2 = create(:distributor_enterprise)
p1 = create(:product)
p2 = create(:product)
- oc1 = create(:simple_order_cycle, suppliers: [s], distributors: [d1], variants: [p1.master])
- oc2 = create(:simple_order_cycle, suppliers: [s], distributors: [d2], variants: [p2.master])
+ oc1 = create(:simple_order_cycle, suppliers: [s], distributors: [d1],
+ variants: [p1.master])
+ oc2 = create(:simple_order_cycle, suppliers: [s], distributors: [d2],
+ variants: [p2.master])
expect(Product.in_order_cycle(oc1)).to eq([p1])
end
end
@@ -572,8 +577,10 @@ module Spree
p1 = create(:product)
p2 = create(:product)
p3 = create(:product)
- oc2 = create(:simple_order_cycle, suppliers: [s], distributors: [d2], variants: [p2.master], orders_open_at: 8.days.ago, orders_close_at: 1.day.ago)
- oc2 = create(:simple_order_cycle, suppliers: [s], distributors: [d3], variants: [p3.master], orders_close_at: Date.tomorrow)
+ oc2 = create(:simple_order_cycle, suppliers: [s], distributors: [d2],
+ variants: [p2.master], orders_open_at: 8.days.ago, orders_close_at: 1.day.ago)
+ oc2 = create(:simple_order_cycle, suppliers: [s], distributors: [d3],
+ variants: [p3.master], orders_close_at: Date.tomorrow)
expect(Product.in_an_active_order_cycle).to eq([p3])
end
end
@@ -611,8 +618,12 @@ module Spree
let!(:new_variant) { create(:variant) }
let!(:hidden_variant) { create(:variant) }
let!(:visible_variant) { create(:variant) }
- let!(:hidden_inventory_item) { create(:inventory_item, enterprise: enterprise, variant: hidden_variant, visible: false ) }
- let!(:visible_inventory_item) { create(:inventory_item, enterprise: enterprise, variant: visible_variant, visible: true ) }
+ let!(:hidden_inventory_item) {
+ create(:inventory_item, enterprise: enterprise, variant: hidden_variant, visible: false )
+ }
+ let!(:visible_inventory_item) {
+ create(:inventory_item, enterprise: enterprise, variant: visible_variant, visible: true )
+ }
let!(:products) { Spree::Product.visible_for(enterprise) }
@@ -631,8 +642,10 @@ module Spree
let!(:p3) { create(:simple_product, supplier: other_producer ) }
before do
- create(:enterprise_relationship, parent: add_to_oc_producer, child: shop, permissions_list: [:add_to_order_cycle])
- create(:enterprise_relationship, parent: other_producer, child: shop, permissions_list: [:manage_products])
+ create(:enterprise_relationship, parent: add_to_oc_producer, child: shop,
+ permissions_list: [:add_to_order_cycle])
+ create(:enterprise_relationship, parent: other_producer, child: shop,
+ permissions_list: [:manage_products])
end
it 'shows products produced by the enterprise and any producers granting P-OC' do
@@ -660,7 +673,8 @@ module Spree
product.set_property 'Organic Certified', 'NASAA 12345'
property = product.properties.last
- expect(product.properties_including_inherited).to eq([{ id: property.id, name: "Organic Certified", value: 'NASAA 12345' }])
+ expect(product.properties_including_inherited).to eq([{ id: property.id,
+ name: "Organic Certified", value: 'NASAA 12345' }])
end
it "returns producer properties as a hash" do
@@ -670,7 +684,8 @@ module Spree
supplier.set_producer_property 'Organic Certified', 'NASAA 54321'
property = supplier.properties.last
- expect(product.properties_including_inherited).to eq([{ id: property.id, name: "Organic Certified", value: 'NASAA 54321' }])
+ expect(product.properties_including_inherited).to eq([{ id: property.id,
+ name: "Organic Certified", value: 'NASAA 54321' }])
end
it "overrides producer properties with product properties" do
@@ -681,7 +696,8 @@ module Spree
supplier.set_producer_property 'Organic Certified', 'NASAA 54321'
property = product.properties.last
- expect(product.properties_including_inherited).to eq([{ id: property.id, name: "Organic Certified", value: 'NASAA 12345' }])
+ expect(product.properties_including_inherited).to eq([{ id: property.id,
+ name: "Organic Certified", value: 'NASAA 12345' }])
end
context "when product has an inherit_properties value set to true" do
@@ -692,7 +708,8 @@ module Spree
supplier.set_producer_property 'Organic Certified', 'NASAA 54321'
property = supplier.properties.last
- expect(product.properties_including_inherited).to eq([{ id: property.id, name: "Organic Certified", value: 'NASAA 54321' }])
+ expect(product.properties_including_inherited).to eq([{ id: property.id,
+ name: "Organic Certified", value: 'NASAA 54321' }])
end
end
@@ -859,7 +876,9 @@ module Spree
let(:v) { create(:variant, product: p) }
let(:oc) { create(:simple_order_cycle) }
let(:s) { create(:supplier_enterprise) }
- let(:e) { create(:exchange, order_cycle: oc, incoming: true, sender: s, receiver: oc.coordinator) }
+ let(:e) {
+ create(:exchange, order_cycle: oc, incoming: true, sender: s, receiver: oc.coordinator)
+ }
it "removes the master variant from all order cycles" do
e.variants << p.master
@@ -896,8 +915,12 @@ module Spree
context "when some variants have import date and some do not" do
let!(:variant_a) { create(:variant, product: product, import_date: nil) }
- let!(:variant_b) { create(:variant, product: product, import_date: reference_time - 1.hour) }
- let!(:variant_c) { create(:variant, product: product, import_date: reference_time - 2.hours) }
+ let!(:variant_b) {
+ create(:variant, product: product, import_date: reference_time - 1.hour)
+ }
+ let!(:variant_c) {
+ create(:variant, product: product, import_date: reference_time - 2.hours)
+ }
it "returns the most recent import date" do
expect(product.import_date).to eq(variant_b.import_date)
@@ -905,9 +928,15 @@ module Spree
end
context "when all variants have import date" do
- let!(:variant_a) { create(:variant, product: product, import_date: reference_time - 2.hours) }
- let!(:variant_b) { create(:variant, product: product, import_date: reference_time - 1.hour) }
- let!(:variant_c) { create(:variant, product: product, import_date: reference_time - 3.hours) }
+ let!(:variant_a) {
+ create(:variant, product: product, import_date: reference_time - 2.hours)
+ }
+ let!(:variant_b) {
+ create(:variant, product: product, import_date: reference_time - 1.hour)
+ }
+ let!(:variant_c) {
+ create(:variant, product: product, import_date: reference_time - 3.hours)
+ }
it "returns the most recent import date" do
expect(product.import_date).to eq(variant_b.import_date)
diff --git a/spec/models/spree/return_authorization_spec.rb b/spec/models/spree/return_authorization_spec.rb
index 9abd0f3d89..760c496663 100644
--- a/spec/models/spree/return_authorization_spec.rb
+++ b/spec/models/spree/return_authorization_spec.rb
@@ -70,7 +70,8 @@ describe Spree::ReturnAuthorization do
let(:inventory_unit) { order.shipments.first.inventory_units.first }
before do
- allow(return_authorization).to receive_messages(inventory_units: [inventory_unit], amount: -20)
+ allow(return_authorization).to receive_messages(inventory_units: [inventory_unit],
+ amount: -20)
allow(Spree::Adjustment).to receive(:create)
allow(order).to receive(:update_order!)
end
diff --git a/spec/models/spree/shipping_method_spec.rb b/spec/models/spree/shipping_method_spec.rb
index c3c65d0215..b505a3a808 100644
--- a/spec/models/spree/shipping_method_spec.rb
+++ b/spec/models/spree/shipping_method_spec.rb
@@ -31,7 +31,9 @@ module Spree
let!(:distributor_b) { create(:distributor_enterprise) }
let!(:distributor_c) { create(:distributor_enterprise) }
- let!(:shipping_method_a) { create(:shipping_method, distributors: [distributor_a, distributor_b]) }
+ let!(:shipping_method_a) {
+ create(:shipping_method, distributors: [distributor_a, distributor_b])
+ }
let!(:shipping_method_b) { create(:shipping_method, distributors: [distributor_b]) }
let!(:shipping_method_c) { create(:shipping_method, distributors: [distributor_c]) }
@@ -67,9 +69,13 @@ module Spree
let!(:d3) { create(:distributor_enterprise) }
let!(:d4) { create(:distributor_enterprise) }
let!(:d1_pickup) { create(:shipping_method, require_ship_address: false, distributors: [d1]) }
- let!(:d1_delivery) { create(:shipping_method, require_ship_address: true, distributors: [d1]) }
+ let!(:d1_delivery) {
+ create(:shipping_method, require_ship_address: true, distributors: [d1])
+ }
let!(:d2_pickup) { create(:shipping_method, require_ship_address: false, distributors: [d2]) }
- let!(:d3_delivery) { create(:shipping_method, require_ship_address: true, distributors: [d3]) }
+ let!(:d3_delivery) {
+ create(:shipping_method, require_ship_address: true, distributors: [d3])
+ }
it "reports when the services are available" do
expect(ShippingMethod.services[d1.id]).to eq(pickup: true, delivery: true)
diff --git a/spec/models/spree/stock_item_spec.rb b/spec/models/spree/stock_item_spec.rb
index 05060c182b..d3b1b26bab 100644
--- a/spec/models/spree/stock_item_spec.rb
+++ b/spec/models/spree/stock_item_spec.rb
@@ -91,7 +91,10 @@ RSpec.describe Spree::StockItem do
end
context "adds new items" do
- before { allow(subject).to receive_messages(backordered_inventory_units: [inventory_unit, inventory_unit_2]) }
+ before {
+ allow(subject).to receive_messages(backordered_inventory_units: [inventory_unit,
+ inventory_unit_2])
+ }
it "fills existing backorders" do
expect(inventory_unit).to receive(:fill_backorder)
diff --git a/spec/models/spree/tax_rate_spec.rb b/spec/models/spree/tax_rate_spec.rb
index e057373256..bf50676f29 100644
--- a/spec/models/spree/tax_rate_spec.rb
+++ b/spec/models/spree/tax_rate_spec.rb
@@ -7,7 +7,10 @@ module Spree
describe "#match" do
let!(:zone) { create(:zone_with_member) }
let!(:order) { create(:order, distributor: hub, bill_address: create(:address)) }
- let!(:tax_rate) { create(:tax_rate, included_in_price: true, calculator: ::Calculator::FlatRate.new(preferred_amount: 0.1), zone: zone) }
+ let!(:tax_rate) {
+ create(:tax_rate, included_in_price: true,
+ calculator: ::Calculator::FlatRate.new(preferred_amount: 0.1), zone: zone)
+ }
describe "when the order's hub charges sales tax" do
let(:hub) { create(:distributor_enterprise, charges_sales_tax: true) }
@@ -35,7 +38,9 @@ module Spree
end
describe "ensuring that tax rate is marked as tax included_in_price" do
- let(:tax_rate) { create(:tax_rate, included_in_price: false, calculator: ::Calculator::DefaultTax.new) }
+ let(:tax_rate) {
+ create(:tax_rate, included_in_price: false, calculator: ::Calculator::DefaultTax.new)
+ }
it "sets included_in_price to true" do
tax_rate.send(:with_tax_included_in_price) do
@@ -326,7 +331,7 @@ module Spree
tax_category: @category,
zone: @zone
)
- @rate2 = Spree::TaxRate.create(
+ @rate2 = Spree::TaxRate.create(
amount: 0.05,
calculator: ::Calculator::DefaultTax.new,
tax_category: @category,
diff --git a/spec/models/spree/taxon_spec.rb b/spec/models/spree/taxon_spec.rb
index 6d09e79623..b264fa68db 100644
--- a/spec/models/spree/taxon_spec.rb
+++ b/spec/models/spree/taxon_spec.rb
@@ -19,8 +19,12 @@ module Spree
end
describe "finding distributed taxons" do
- let!(:oc_open) { create(:open_order_cycle, distributors: [e], variants: [p_open.variants.first]) }
- let!(:oc_closed) { create(:closed_order_cycle, distributors: [e], variants: [p_closed.variants.first]) }
+ let!(:oc_open) {
+ create(:open_order_cycle, distributors: [e], variants: [p_open.variants.first])
+ }
+ let!(:oc_closed) {
+ create(:closed_order_cycle, distributors: [e], variants: [p_closed.variants.first])
+ }
let!(:p_open) { create(:simple_product, primary_taxon: t1) }
let!(:p_closed) { create(:simple_product, primary_taxon: t2) }
@@ -93,7 +97,9 @@ module Spree
let(:taxonomy) { create(:taxonomy) }
it "does not error out" do
- expect { taxonomy.root.children.where(name: "Some name").first_or_create }.not_to raise_error
+ expect {
+ taxonomy.root.children.where(name: "Some name").first_or_create
+ }.not_to raise_error
end
end
end
diff --git a/spec/models/spree/user_spec.rb b/spec/models/spree/user_spec.rb
index 406f41fdca..599a2fcb76 100644
--- a/spec/models/spree/user_spec.rb
+++ b/spec/models/spree/user_spec.rb
@@ -16,7 +16,9 @@ describe Spree::User do
old_bill_address = user.bill_address
new_bill_address = create(:address, firstname: 'abc')
- user.update(bill_address_attributes: new_bill_address.dup.attributes.merge('id' => old_bill_address.id).except!('created_at', 'updated_at'))
+ user.update(bill_address_attributes: new_bill_address.dup.attributes.merge('id' => old_bill_address.id).except!(
+ 'created_at', 'updated_at'
+ ))
expect(user.bill_address.id).to eq old_bill_address.id
expect(user.bill_address.firstname).to eq new_bill_address.firstname
@@ -25,7 +27,9 @@ describe Spree::User do
it 'creates new shipping address' do
new_ship_address = create(:address, firstname: 'abc')
- user.update(ship_address_attributes: new_ship_address.dup.attributes.except!('created_at', 'updated_at'))
+ user.update(ship_address_attributes: new_ship_address.dup.attributes.except!(
+ 'created_at', 'updated_at'
+ ))
expect(user.ship_address.id).not_to eq new_ship_address.id
expect(user.ship_address.firstname).to eq new_ship_address.firstname
@@ -50,7 +54,8 @@ describe Spree::User do
expect do
u2.owned_enterprises << e2
u2.save!
- end.to raise_error ActiveRecord::RecordInvalid, "Validation failed: #{u2.email} is not permitted to own any more enterprises (limit is 1)."
+ end.to raise_error ActiveRecord::RecordInvalid,
+ "Validation failed: #{u2.email} is not permitted to own any more enterprises (limit is 1)."
end
end
diff --git a/spec/models/spree/variant_spec.rb b/spec/models/spree/variant_spec.rb
index 3589df55aa..548f82e1d8 100644
--- a/spec/models/spree/variant_spec.rb
+++ b/spec/models/spree/variant_spec.rb
@@ -28,7 +28,9 @@ module Spree
context "price parsing" do
before(:each) do
I18n.locale = I18n.default_locale
- I18n.backend.store_translations(:de, { number: { currency: { format: { delimiter: '.', separator: ',' } } } })
+ I18n.backend.store_translations(:de,
+ { number: { currency: { format: { delimiter: '.',
+ separator: ',' } } } })
end
after do
@@ -308,8 +310,12 @@ module Spree
let!(:hidden_variant) { create(:variant) }
let!(:visible_variant) { create(:variant) }
- let!(:hidden_inventory_item) { create(:inventory_item, enterprise: enterprise, variant: hidden_variant, visible: false ) }
- let!(:visible_inventory_item) { create(:inventory_item, enterprise: enterprise, variant: visible_variant, visible: true ) }
+ let!(:hidden_inventory_item) {
+ create(:inventory_item, enterprise: enterprise, variant: hidden_variant, visible: false )
+ }
+ let!(:visible_inventory_item) {
+ create(:inventory_item, enterprise: enterprise, variant: visible_variant, visible: true )
+ }
context "finding variants that are not hidden from an enterprise's inventory" do
context "when the enterprise given is nil" do
@@ -331,9 +337,18 @@ module Spree
context "when inventory items exist for other enterprises" do
let(:other_enterprise) { create(:distributor_enterprise) }
- let!(:new_inventory_item) { create(:inventory_item, enterprise: other_enterprise, variant: new_variant, visible: true ) }
- let!(:hidden_inventory_item2) { create(:inventory_item, enterprise: other_enterprise, variant: visible_variant, visible: false ) }
- let!(:visible_inventory_item2) { create(:inventory_item, enterprise: other_enterprise, variant: hidden_variant, visible: true ) }
+ let!(:new_inventory_item) {
+ create(:inventory_item, enterprise: other_enterprise, variant: new_variant,
+ visible: true )
+ }
+ let!(:hidden_inventory_item2) {
+ create(:inventory_item, enterprise: other_enterprise, variant: visible_variant,
+ visible: false )
+ }
+ let!(:visible_inventory_item2) {
+ create(:inventory_item, enterprise: other_enterprise, variant: hidden_variant,
+ visible: true )
+ }
it "lists any variants that are not listed as visible=false only for the relevant enterprise" do
expect(variants).to include new_variant, visible_variant
@@ -358,12 +373,16 @@ module Spree
let(:add_to_oc_producer) { create(:supplier_enterprise) }
let(:other_producer) { create(:supplier_enterprise) }
let!(:v1) { create(:variant, product: create(:simple_product, supplier: shop ) ) }
- let!(:v2) { create(:variant, product: create(:simple_product, supplier: add_to_oc_producer ) ) }
+ let!(:v2) {
+ create(:variant, product: create(:simple_product, supplier: add_to_oc_producer ) )
+ }
let!(:v3) { create(:variant, product: create(:simple_product, supplier: other_producer ) ) }
before do
- create(:enterprise_relationship, parent: add_to_oc_producer, child: shop, permissions_list: [:add_to_order_cycle])
- create(:enterprise_relationship, parent: other_producer, child: shop, permissions_list: [:manage_products])
+ create(:enterprise_relationship, parent: add_to_oc_producer, child: shop,
+ permissions_list: [:add_to_order_cycle])
+ create(:enterprise_relationship, parent: other_producer, child: shop,
+ permissions_list: [:manage_products])
end
it 'shows variants produced by the enterprise and any producers granting P-OC' do
@@ -425,7 +444,9 @@ module Spree
order_cycle = double(:order_cycle)
variant = Variant.new
- expect_any_instance_of(OpenFoodNetwork::EnterpriseFeeCalculator).to receive(:fees_for).with(variant) { 23 }
+ expect_any_instance_of(OpenFoodNetwork::EnterpriseFeeCalculator).to receive(:fees_for).with(variant) {
+ 23
+ }
expect(variant.fees_for(distributor, order_cycle)).to eq(23)
end
@@ -438,7 +459,9 @@ module Spree
variant = Variant.new
fees = double(:fees)
- expect_any_instance_of(OpenFoodNetwork::EnterpriseFeeCalculator).to receive(:fees_by_type_for).with(variant) { fees }
+ expect_any_instance_of(OpenFoodNetwork::EnterpriseFeeCalculator).to receive(:fees_by_type_for).with(variant) {
+ fees
+ }
expect(variant.fees_by_type_for(distributor, order_cycle)).to eq(fees)
end
@@ -645,7 +668,9 @@ module Spree
context "when the variant does not have a display_as value set" do
let!(:p) { create(:simple_product, variant_unit: 'weight', variant_unit_scale: 1) }
- let!(:v) { create(:variant, product: p, unit_value: 5, unit_description: 'bar', display_as: '') }
+ let!(:v) {
+ create(:variant, product: p, unit_value: 5, unit_description: 'bar', display_as: '')
+ }
it "requests the name of the new option_value from OptionValueName" do
expect_any_instance_of(VariantUnits::OptionValueNamer).to receive(:name).exactly(1).times.and_call_original
@@ -657,7 +682,9 @@ module Spree
context "when the variant has a display_as value set" do
let!(:p) { create(:simple_product, variant_unit: 'weight', variant_unit_scale: 1) }
- let!(:v) { create(:variant, product: p, unit_value: 5, unit_description: 'bar', display_as: 'FOOS!') }
+ let!(:v) {
+ create(:variant, product: p, unit_value: 5, unit_description: 'bar', display_as: 'FOOS!')
+ }
it "does not request the name of the new option_value from OptionValueName" do
expect_any_instance_of(VariantUnits::OptionValueNamer).not_to receive(:name)
@@ -748,7 +775,6 @@ module Spree
end
end
-
describe "#default_price" do
let(:variant) { create(:variant) }
let(:default_price) { variant.default_price }
diff --git a/spec/models/stripe_account_spec.rb b/spec/models/stripe_account_spec.rb
index 75595d3142..0a95a2ddcd 100644
--- a/spec/models/stripe_account_spec.rb
+++ b/spec/models/stripe_account_spec.rb
@@ -9,7 +9,9 @@ describe StripeAccount do
let!(:enterprise2) { create(:enterprise) }
let(:client_id) { 'ca_abc123' }
let(:stripe_user_id) { 'acct_abc123' }
- let!(:stripe_account) { create(:stripe_account, enterprise: enterprise, stripe_user_id: stripe_user_id) }
+ let!(:stripe_account) {
+ create(:stripe_account, enterprise: enterprise, stripe_user_id: stripe_user_id)
+ }
before do
Stripe.api_key = "sk_test_12345"
@@ -20,7 +22,8 @@ describe StripeAccount do
before do
stub_request(:post, "https://connect.stripe.com/oauth/deauthorize").
with(body: { "client_id" => client_id, "stripe_user_id" => stripe_user_id }).
- to_return(status: 400, body: JSON.generate(error: 'invalid_grant', error_description: "Some Message"))
+ to_return(status: 400, body: JSON.generate(error: 'invalid_grant',
+ error_description: "Some Message"))
end
it "destroys the record and notifies Bugsnag" do
@@ -44,7 +47,9 @@ describe StripeAccount do
end
context "if the account is also associated with another Enterprise" do
- let!(:another_stripe_account) { create(:stripe_account, enterprise: enterprise2, stripe_user_id: stripe_user_id) }
+ let!(:another_stripe_account) {
+ create(:stripe_account, enterprise: enterprise2, stripe_user_id: stripe_user_id)
+ }
it "Doesn't make a Stripe API disconnection request " do
expect(Stripe::OAuth).to_not receive(:deauthorize)
diff --git a/spec/models/tag_rule/filter_order_cycles_spec.rb b/spec/models/tag_rule/filter_order_cycles_spec.rb
index fffa14469b..311cbc61d3 100644
--- a/spec/models/tag_rule/filter_order_cycles_spec.rb
+++ b/spec/models/tag_rule/filter_order_cycles_spec.rb
@@ -29,12 +29,20 @@ describe TagRule::FilterOrderCycles, type: :model do
end
context "when the rule has preferred exchange tags specified that match ANY of the exchange tags" do
- before { allow(tag_rule).to receive(:preferred_exchange_tags) { "wholesale,some_tag,member" } }
+ before {
+ allow(tag_rule).to receive(:preferred_exchange_tags) {
+ "wholesale,some_tag,member"
+ }
+ }
it { expect(tag_rule.send(:tags_match?, exchange_object)).to be true }
end
context "when the rule has preferred exchange tags specified that match NONE of the exchange tags" do
- before { allow(tag_rule).to receive(:preferred_exchange_tags) { "wholesale,some_tag,some_other_tag" } }
+ before {
+ allow(tag_rule).to receive(:preferred_exchange_tags) {
+ "wholesale,some_tag,some_other_tag"
+ }
+ }
it { expect(tag_rule.send(:tags_match?, exchange_object)).to be false }
end
end
diff --git a/spec/models/tag_rule/filter_payment_methods_spec.rb b/spec/models/tag_rule/filter_payment_methods_spec.rb
index 403e82a7b5..adaeeae9eb 100644
--- a/spec/models/tag_rule/filter_payment_methods_spec.rb
+++ b/spec/models/tag_rule/filter_payment_methods_spec.rb
@@ -21,12 +21,20 @@ describe TagRule::FilterPaymentMethods, type: :model do
end
context "when the rule has preferred customer tags specified that match ANY of the customer tags" do
- before { allow(tag_rule).to receive(:preferred_payment_method_tags) { "wholesale,some_tag,member" } }
+ before {
+ allow(tag_rule).to receive(:preferred_payment_method_tags) {
+ "wholesale,some_tag,member"
+ }
+ }
it { expect(tag_rule.send(:tags_match?, payment_method)).to be true }
end
context "when the rule has preferred customer tags specified that match NONE of the customer tags" do
- before { allow(tag_rule).to receive(:preferred_payment_method_tags) { "wholesale,some_tag,some_other_tag" } }
+ before {
+ allow(tag_rule).to receive(:preferred_payment_method_tags) {
+ "wholesale,some_tag,some_other_tag"
+ }
+ }
it { expect(tag_rule.send(:tags_match?, payment_method)).to be false }
end
end
diff --git a/spec/models/tag_rule/filter_products_spec.rb b/spec/models/tag_rule/filter_products_spec.rb
index becf7a3cb7..4a72cb2170 100644
--- a/spec/models/tag_rule/filter_products_spec.rb
+++ b/spec/models/tag_rule/filter_products_spec.rb
@@ -21,12 +21,20 @@ describe TagRule::FilterProducts, type: :model do
end
context "when the rule has preferred variant tags specified that match ANY of the variant tags" do
- before { allow(tag_rule).to receive(:preferred_variant_tags) { "wholesale,some_tag,member" } }
+ before {
+ allow(tag_rule).to receive(:preferred_variant_tags) {
+ "wholesale,some_tag,member"
+ }
+ }
it { expect(tag_rule.send(:tags_match?, variant_object)).to be true }
end
context "when the rule has preferred variant tags specified that match NONE of the variant tags" do
- before { allow(tag_rule).to receive(:preferred_variant_tags) { "wholesale,some_tag,some_other_tag" } }
+ before {
+ allow(tag_rule).to receive(:preferred_variant_tags) {
+ "wholesale,some_tag,some_other_tag"
+ }
+ }
it { expect(tag_rule.send(:tags_match?, variant_object)).to be false }
end
end
diff --git a/spec/models/tag_rule/filter_shipping_methods_spec.rb b/spec/models/tag_rule/filter_shipping_methods_spec.rb
index b1ac8c23ed..a326fe5a04 100644
--- a/spec/models/tag_rule/filter_shipping_methods_spec.rb
+++ b/spec/models/tag_rule/filter_shipping_methods_spec.rb
@@ -13,7 +13,9 @@ describe TagRule::FilterShippingMethods, type: :model do
end
context "when the shipping method is not nil" do
- let(:shipping_method) { build_stubbed(:shipping_method, tag_list: ["member", "local", "volunteer"]) }
+ let(:shipping_method) {
+ build_stubbed(:shipping_method, tag_list: ["member", "local", "volunteer"])
+ }
context "when the rule has no preferred shipping method tags specified" do
before { allow(tag_rule).to receive(:preferred_shipping_method_tags) { "" } }
@@ -21,12 +23,20 @@ describe TagRule::FilterShippingMethods, type: :model do
end
context "when the rule has preferred customer tags specified that match ANY of the customer tags" do
- before { allow(tag_rule).to receive(:preferred_shipping_method_tags) { "wholesale,some_tag,member" } }
+ before {
+ allow(tag_rule).to receive(:preferred_shipping_method_tags) {
+ "wholesale,some_tag,member"
+ }
+ }
it { expect(tag_rule.send(:tags_match?, shipping_method)).to be true }
end
context "when the rule has preferred customer tags specified that match NONE of the customer tags" do
- before { allow(tag_rule).to receive(:preferred_shipping_method_tags) { "wholesale,some_tag,some_other_tag" } }
+ before {
+ allow(tag_rule).to receive(:preferred_shipping_method_tags) {
+ "wholesale,some_tag,some_other_tag"
+ }
+ }
it { expect(tag_rule.send(:tags_match?, shipping_method)).to be false }
end
end
diff --git a/spec/models/terms_of_service_file_spec.rb b/spec/models/terms_of_service_file_spec.rb
index 16acf2a16a..37db0e1f13 100644
--- a/spec/models/terms_of_service_file_spec.rb
+++ b/spec/models/terms_of_service_file_spec.rb
@@ -30,7 +30,7 @@ describe TermsOfServiceFile do
it "points to the last uploaded file with timestamp parameter" do
file = TermsOfServiceFile.create!(attachment: pdf)
- expect(subject).to match /^\/system\/terms_of_service_files\/attachments.*Terms-of-service\.pdf\?\d+$/
+ expect(subject).to match %r{^/system/terms_of_service_files/attachments.*Terms-of-service\.pdf\?\d+$}
end
end
diff --git a/spec/models/variant_override_spec.rb b/spec/models/variant_override_spec.rb
index 037116b889..734dc0b304 100644
--- a/spec/models/variant_override_spec.rb
+++ b/spec/models/variant_override_spec.rb
@@ -9,9 +9,15 @@ describe VariantOverride do
describe "scopes" do
let(:hub1) { create(:distributor_enterprise) }
let(:hub2) { create(:distributor_enterprise) }
- let!(:vo1) { create(:variant_override, hub: hub1, variant: variant, import_date: Time.zone.now.yesterday) }
- let!(:vo2) { create(:variant_override, hub: hub2, variant: variant, import_date: Time.zone.now) }
- let!(:vo3) { create(:variant_override, hub: hub1, variant: variant, permission_revoked_at: Time.zone.now) }
+ let!(:vo1) {
+ create(:variant_override, hub: hub1, variant: variant, import_date: Time.zone.now.yesterday)
+ }
+ let!(:vo2) {
+ create(:variant_override, hub: hub2, variant: variant, import_date: Time.zone.now)
+ }
+ let!(:vo3) {
+ create(:variant_override, hub: hub1, variant: variant, permission_revoked_at: Time.zone.now)
+ }
it "ignores variant_overrides with revoked_permissions by default" do
expect(VariantOverride.all).to_not include vo3
@@ -259,7 +265,8 @@ describe VariantOverride do
describe "resetting stock levels" do
describe "forcing the on hand level to the value in the default_stock field" do
it "succeeds for variant override that forces limited stock" do
- vo = create(:variant_override, variant: variant, hub: hub, count_on_hand: 12, default_stock: 20, resettable: true)
+ vo = create(:variant_override, variant: variant, hub: hub, count_on_hand: 12,
+ default_stock: 20, resettable: true)
vo.reset_stock!
vo.reload
@@ -268,7 +275,8 @@ describe VariantOverride do
end
it "succeeds for variant override that forces unlimited stock" do
- vo = create(:variant_override, :on_demand, variant: variant, hub: hub, default_stock: 20, resettable: true)
+ vo = create(:variant_override, :on_demand, variant: variant, hub: hub, default_stock: 20,
+ resettable: true)
vo.reset_stock!
vo.reload
@@ -277,7 +285,8 @@ describe VariantOverride do
end
it "succeeds for variant override that uses producer stock settings" do
- vo = create(:variant_override, :use_producer_stock_settings, variant: variant, hub: hub, default_stock: 20, resettable: true)
+ vo = create(:variant_override, :use_producer_stock_settings, variant: variant, hub: hub,
+ default_stock: 20, resettable: true)
vo.reset_stock!
vo.reload
@@ -287,14 +296,16 @@ describe VariantOverride do
end
it "silently logs an error if the variant override doesn't have a default stock level" do
- vo = create(:variant_override, variant: variant, hub: hub, count_on_hand: 12, default_stock: nil, resettable: true)
+ vo = create(:variant_override, variant: variant, hub: hub, count_on_hand: 12,
+ default_stock: nil, resettable: true)
expect(Bugsnag).to receive(:notify)
vo.reset_stock!
expect(vo.reload.count_on_hand).to eq(12)
end
it "doesn't reset the level if the behaviour is disabled" do
- vo = create(:variant_override, variant: variant, hub: hub, count_on_hand: 12, default_stock: 10, resettable: false)
+ vo = create(:variant_override, variant: variant, hub: hub, count_on_hand: 12,
+ default_stock: 10, resettable: false)
vo.reset_stock!
expect(vo.reload.count_on_hand).to eq(12)
end
diff --git a/spec/performance/orders_controller_spec.rb b/spec/performance/orders_controller_spec.rb
index 49f7ec2be2..ac38074708 100644
--- a/spec/performance/orders_controller_spec.rb
+++ b/spec/performance/orders_controller_spec.rb
@@ -4,7 +4,11 @@ require 'spec_helper'
describe Spree::OrdersController, type: :controller, performance: true do
let(:distributor) { create(:distributor_enterprise) }
- let(:order_cycle) { create(:simple_order_cycle, distributors: [distributor], variants: products.map { |p| p.variants.first }) }
+ let(:order_cycle) {
+ create(:simple_order_cycle, distributors: [distributor], variants: products.map { |p|
+ p.variants.first
+ } )
+ }
let(:products) { (0...num_products).map { create(:product) } }
let(:order) { subject.current_order(true) }
let(:num_products) { 20 }
diff --git a/spec/performance/shop_controller_spec.rb b/spec/performance/shop_controller_spec.rb
index 8af430358e..a37a264db4 100644
--- a/spec/performance/shop_controller_spec.rb
+++ b/spec/performance/shop_controller_spec.rb
@@ -5,7 +5,9 @@ require 'spec_helper'
describe ShopController, type: :controller, performance: true do
let(:d) { create(:distributor_enterprise) }
let(:enterprise_fee) { create(:enterprise_fee) }
- let(:order_cycle) { create(:simple_order_cycle, distributors: [d], coordinator_fees: [enterprise_fee]) }
+ let(:order_cycle) {
+ create(:simple_order_cycle, distributors: [d], coordinator_fees: [enterprise_fee])
+ }
before do
allow(controller).to receive(:current_distributor) { d }
@@ -29,7 +31,8 @@ describe ShopController, type: :controller, performance: true do
p.set_property 'Organic Certified', 'NASAA 12345'
v1 = create(:variant, product: p)
v2 = create(:variant, product: p)
- Spree::Image.create! viewable_id: p.master.id, viewable_type: 'Spree::Variant', attachment: image
+ Spree::Image.create! viewable_id: p.master.id, viewable_type: 'Spree::Variant',
+ attachment: image
exchange.variants << [v1, v2]
end
diff --git a/spec/queries/complete_orders_with_balance_spec.rb b/spec/queries/complete_orders_with_balance_spec.rb
index 9d46feb7da..fae8ea5881 100644
--- a/spec/queries/complete_orders_with_balance_spec.rb
+++ b/spec/queries/complete_orders_with_balance_spec.rb
@@ -11,7 +11,7 @@ describe CompleteOrdersWithBalance do
context 'when the user has complete orders' do
let(:order) do
- create(:order, state: 'complete', total: 2.0, payment_total: 1.0, completed_at: 2.day.ago)
+ create(:order, state: 'complete', total: 2.0, payment_total: 1.0, completed_at: 2.days.ago)
end
let!(:other_order) do
create(
@@ -20,7 +20,7 @@ describe CompleteOrdersWithBalance do
state: 'complete',
total: 2.0,
payment_total: 1.0,
- completed_at: 1.days.ago
+ completed_at: 1.day.ago
)
end
diff --git a/spec/requests/api/orders_spec.rb b/spec/requests/api/orders_spec.rb
index 41a050ee8f..ef25152bbc 100644
--- a/spec/requests/api/orders_spec.rb
+++ b/spec/requests/api/orders_spec.rb
@@ -9,13 +9,20 @@ describe 'api/v0/orders', type: :request do
# type should be replaced with swagger 3.01 valid schema: {type: string} when rswag #317 is resolved:
# https://github.com/rswag/rswag/pull/319
parameter name: 'X-Spree-Token', in: :header, type: :string
- parameter name: 'q[distributor_id_eq]', in: :query, type: :string, required: false, description: "Query orders for a specific distributor id."
- parameter name: 'q[completed_at_gt]', in: :query, type: :string, required: false, description: "Query orders completed after a date."
- parameter name: 'q[completed_at_lt]', in: :query, type: :string, required: false, description: "Query orders completed before a date."
- parameter name: 'q[state_eq]', in: :query, type: :string, required: false, description: "Query orders by order state, eg 'cart', 'complete'."
- parameter name: 'q[payment_state_eq]', in: :query, type: :string, required: false, description: "Query orders by order payment_state, eg 'balance_due', 'paid', 'failed'."
- parameter name: 'q[email_cont]', in: :query, type: :string, required: false, description: "Query orders where the order email contains a string."
- parameter name: 'q[order_cycle_id_eq]', in: :query, type: :string, required: false, description: "Query orders for a specific order_cycle id."
+ parameter name: 'q[distributor_id_eq]', in: :query, type: :string, required: false,
+ description: "Query orders for a specific distributor id."
+ parameter name: 'q[completed_at_gt]', in: :query, type: :string, required: false,
+ description: "Query orders completed after a date."
+ parameter name: 'q[completed_at_lt]', in: :query, type: :string, required: false,
+ description: "Query orders completed before a date."
+ parameter name: 'q[state_eq]', in: :query, type: :string, required: false,
+ description: "Query orders by order state, eg 'cart', 'complete'."
+ parameter name: 'q[payment_state_eq]', in: :query, type: :string, required: false,
+ description: "Query orders by order payment_state, eg 'balance_due', 'paid', 'failed'."
+ parameter name: 'q[email_cont]', in: :query, type: :string, required: false,
+ description: "Query orders where the order email contains a string."
+ parameter name: 'q[order_cycle_id_eq]', in: :query, type: :string, required: false,
+ description: "Query orders for a specific order_cycle id."
response(200, 'get orders') do
# Adds model metadata for Swagger UI. Ideally we'd be able to just add:
@@ -28,10 +35,18 @@ describe 'api/v0/orders', type: :request do
}
}
context "when there are four orders with different properties set" do
- let!(:order_dist_1) { create(:order_with_distributor, email: "specific_name@example.com") }
+ let!(:order_dist_1) {
+ create(:order_with_distributor, email: "specific_name@example.com")
+ }
let!(:order_dist_2) { create(:order_with_totals_and_distribution) }
- let!(:order_dist_1_complete) { create(:order, distributor: order_dist_1.distributor, state: 'complete', completed_at: Time.zone.today - 7.days) }
- let!(:order_dist_1_credit_owed) { create(:order, distributor: order_dist_1.distributor, payment_state: 'credit_owed', completed_at: Time.zone.today) }
+ let!(:order_dist_1_complete) {
+ create(:order, distributor: order_dist_1.distributor, state: 'complete',
+ completed_at: Time.zone.today - 7.days)
+ }
+ let!(:order_dist_1_credit_owed) {
+ create(:order, distributor: order_dist_1.distributor, payment_state: 'credit_owed',
+ completed_at: Time.zone.today)
+ }
let(:user) { order_dist_1.distributor.owner }
let(:'X-Spree-Token') do
diff --git a/spec/requests/checkout/failed_checkout_spec.rb b/spec/requests/checkout/failed_checkout_spec.rb
index 9dade977c1..dff05e4dfc 100644
--- a/spec/requests/checkout/failed_checkout_spec.rb
+++ b/spec/requests/checkout/failed_checkout_spec.rb
@@ -7,20 +7,31 @@ describe "checking out an order that initially fails", type: :request do
let!(:shop) { create(:enterprise) }
let!(:order_cycle) { create(:simple_order_cycle) }
- let!(:exchange) { create(:exchange, order_cycle: order_cycle, sender: order_cycle.coordinator, receiver: shop, incoming: false, pickup_time: "Monday") }
+ let!(:exchange) {
+ create(:exchange, order_cycle: order_cycle, sender: order_cycle.coordinator, receiver: shop,
+ incoming: false, pickup_time: "Monday")
+ }
let!(:address) { create(:address) }
let!(:line_item) { create(:line_item, order: order, quantity: 3, price: 5.00) }
- let!(:payment_method) { create(:bogus_payment_method, distributor_ids: [shop.id], environment: Rails.env) }
- let!(:check_payment_method) { create(:payment_method, distributor_ids: [shop.id], environment: Rails.env) }
+ let!(:payment_method) {
+ create(:bogus_payment_method, distributor_ids: [shop.id], environment: Rails.env)
+ }
+ let!(:check_payment_method) {
+ create(:payment_method, distributor_ids: [shop.id], environment: Rails.env)
+ }
let!(:shipping_method) { create(:shipping_method, distributor_ids: [shop.id]) }
let!(:shipment) { create(:shipment_with, :shipping_method, shipping_method: shipping_method) }
- let!(:order) { create(:order, shipments: [shipment], distributor: shop, order_cycle: order_cycle) }
+ let!(:order) {
+ create(:order, shipments: [shipment], distributor: shop, order_cycle: order_cycle)
+ }
let(:params) do
{ order: {
shipping_method_id: shipping_method.id,
payments_attributes: [{ payment_method_id: payment_method.id }],
- bill_address_attributes: address.attributes.slice("firstname", "lastname", "address1", "address2", "phone", "city", "zipcode", "state_id", "country_id"),
- ship_address_attributes: address.attributes.slice("firstname", "lastname", "address1", "address2", "phone", "city", "zipcode", "state_id", "country_id")
+ bill_address_attributes: address.attributes.slice("firstname", "lastname", "address1",
+ "address2", "phone", "city", "zipcode", "state_id", "country_id"),
+ ship_address_attributes: address.attributes.slice("firstname", "lastname", "address1",
+ "address2", "phone", "city", "zipcode", "state_id", "country_id")
} }
end
diff --git a/spec/serializers/api/admin/exchange_serializer_spec.rb b/spec/serializers/api/admin/exchange_serializer_spec.rb
index 07218c249a..aeaba4f396 100644
--- a/spec/serializers/api/admin/exchange_serializer_spec.rb
+++ b/spec/serializers/api/admin/exchange_serializer_spec.rb
@@ -13,17 +13,24 @@ describe Api::Admin::ExchangeSerializer do
context "serializing incoming exchanges" do
let(:exchange) { create(:exchange, incoming: true, variants: [v1, v2, v3]) }
- let!(:inventory_item) { create(:inventory_item, enterprise: exchange.order_cycle.coordinator, variant: v1, visible: true) }
+ let!(:inventory_item) {
+ create(:inventory_item, enterprise: exchange.order_cycle.coordinator, variant: v1,
+ visible: true)
+ }
before do
allow(OpenFoodNetwork::OrderCyclePermissions).to receive(:new) { permissions_mock }
- allow(permissions_mock).to receive(:visible_variants_for_incoming_exchanges_from) { permitted_variants }
+ allow(permissions_mock).to receive(:visible_variants_for_incoming_exchanges_from) {
+ permitted_variants
+ }
allow(permitted_variants).to receive(:visible_for).and_call_original
end
context "when order cycle shows only variants in the coordinator's inventory" do
before do
- allow(exchange.order_cycle).to receive(:prefers_product_selection_from_coordinator_inventory_only?) { true }
+ allow(exchange.order_cycle).to receive(:prefers_product_selection_from_coordinator_inventory_only?) {
+ true
+ }
end
it "filters variants within the exchange based on permissions, and visibility in inventory" do
@@ -38,7 +45,9 @@ describe Api::Admin::ExchangeSerializer do
context "when order cycle shows all available products" do
before do
- allow(exchange.order_cycle).to receive(:prefers_product_selection_from_coordinator_inventory_only?) { false }
+ allow(exchange.order_cycle).to receive(:prefers_product_selection_from_coordinator_inventory_only?) {
+ false
+ }
end
it "filters variants within the exchange based on permissions only" do
@@ -54,18 +63,24 @@ describe Api::Admin::ExchangeSerializer do
context "serializing outgoing exchanges" do
let(:exchange) { create(:exchange, incoming: false, variants: [v1, v2, v3]) }
- let!(:inventory_item) { create(:inventory_item, enterprise: exchange.receiver, variant: v1, visible: true) }
+ let!(:inventory_item) {
+ create(:inventory_item, enterprise: exchange.receiver, variant: v1, visible: true)
+ }
before do
allow(OpenFoodNetwork::OrderCyclePermissions).to receive(:new) { permissions_mock }
- allow(permissions_mock).to receive(:visible_variants_for_outgoing_exchanges_to) { permitted_variants }
+ allow(permissions_mock).to receive(:visible_variants_for_outgoing_exchanges_to) {
+ permitted_variants
+ }
allow(permitted_variants).to receive(:visible_for).and_call_original
allow(permitted_variants).to receive(:not_hidden_for).and_call_original
end
context "when the receiver prefers to see all variants (not just those in their inventory)" do
before do
- allow(exchange.receiver).to receive(:prefers_product_selection_from_inventory_only?) { false }
+ allow(exchange.receiver).to receive(:prefers_product_selection_from_inventory_only?) {
+ false
+ }
end
it "filters variants within the exchange based on permissions only" do
@@ -81,7 +96,9 @@ describe Api::Admin::ExchangeSerializer do
context "when the receiver prefers to restrict visible variants to only those in their inventory" do
before do
- allow(exchange.receiver).to receive(:prefers_product_selection_from_inventory_only?) { true }
+ allow(exchange.receiver).to receive(:prefers_product_selection_from_inventory_only?) {
+ true
+ }
end
it "filters variants within the exchange based on permissions, and inventory visibility" do
diff --git a/spec/serializers/api/admin/for_order_cycle/supplied_product_serializer_spec.rb b/spec/serializers/api/admin/for_order_cycle/supplied_product_serializer_spec.rb
index 33fe74578e..6b8002067c 100644
--- a/spec/serializers/api/admin/for_order_cycle/supplied_product_serializer_spec.rb
+++ b/spec/serializers/api/admin/for_order_cycle/supplied_product_serializer_spec.rb
@@ -8,12 +8,19 @@ describe Api::Admin::ForOrderCycle::SuppliedProductSerializer do
let!(:product) { create(:simple_product) }
let!(:non_inventory_variant) { product.variants.first }
let!(:inventory_variant) { create(:variant, product: product.reload) }
- let(:serialized_product) { Api::Admin::ForOrderCycle::SuppliedProductSerializer.new(product, order_cycle: order_cycle ).to_json }
- let!(:inventory_item) { create(:inventory_item, enterprise: coordinator, variant: inventory_variant, visible: true) }
+ let(:serialized_product) {
+ Api::Admin::ForOrderCycle::SuppliedProductSerializer.new(product,
+ order_cycle: order_cycle ).to_json
+ }
+ let!(:inventory_item) {
+ create(:inventory_item, enterprise: coordinator, variant: inventory_variant, visible: true)
+ }
context "when order cycle shows only variants in the coordinator's inventory" do
before do
- allow(order_cycle).to receive(:prefers_product_selection_from_coordinator_inventory_only?) { true }
+ allow(order_cycle).to receive(:prefers_product_selection_from_coordinator_inventory_only?) {
+ true
+ }
end
describe "variants" do
@@ -26,7 +33,9 @@ describe Api::Admin::ForOrderCycle::SuppliedProductSerializer do
context "when order cycle shows all available products" do
before do
- allow(order_cycle).to receive(:prefers_product_selection_from_coordinator_inventory_only?) { false }
+ allow(order_cycle).to receive(:prefers_product_selection_from_coordinator_inventory_only?) {
+ false
+ }
end
describe "supplied products" do
diff --git a/spec/serializers/api/admin/order_cycle_serializer_spec.rb b/spec/serializers/api/admin/order_cycle_serializer_spec.rb
index 869fac68cc..2418decbe8 100644
--- a/spec/serializers/api/admin/order_cycle_serializer_spec.rb
+++ b/spec/serializers/api/admin/order_cycle_serializer_spec.rb
@@ -6,7 +6,10 @@ module Api
module Admin
describe OrderCycleSerializer do
let(:order_cycle) { create(:order_cycle) }
- let(:serializer) { Api::Admin::OrderCycleSerializer.new order_cycle, current_user: order_cycle.coordinator.owner }
+ let(:serializer) {
+ Api::Admin::OrderCycleSerializer.new order_cycle,
+ current_user: order_cycle.coordinator.owner
+ }
it "serializes an order cycle" do
expect(serializer.to_json).to include order_cycle.name
diff --git a/spec/serializers/api/admin/subscription_customer_serializer_spec.rb b/spec/serializers/api/admin/subscription_customer_serializer_spec.rb
index b0cc0bcae2..52a556c946 100644
--- a/spec/serializers/api/admin/subscription_customer_serializer_spec.rb
+++ b/spec/serializers/api/admin/subscription_customer_serializer_spec.rb
@@ -6,7 +6,9 @@ describe Api::Admin::SubscriptionCustomerSerializer do
let(:address) { build(:address) }
let(:customer) { build(:customer) }
let(:serializer) { Api::Admin::SubscriptionCustomerSerializer.new(customer) }
- let(:finder_mock) { instance_double(OpenFoodNetwork::AddressFinder, bill_address: address, ship_address: address) }
+ let(:finder_mock) {
+ instance_double(OpenFoodNetwork::AddressFinder, bill_address: address, ship_address: address)
+ }
before do
allow(serializer).to receive(:finder) { finder_mock }
diff --git a/spec/serializers/api/admin/variant_override_serializer_spec.rb b/spec/serializers/api/admin/variant_override_serializer_spec.rb
index ded6abdc63..aac75e138b 100644
--- a/spec/serializers/api/admin/variant_override_serializer_spec.rb
+++ b/spec/serializers/api/admin/variant_override_serializer_spec.rb
@@ -5,7 +5,10 @@ describe Api::Admin::VariantOverrideSerializer do
let(:hub) { create(:distributor_enterprise) }
let(:price) { 77.77 }
let(:count_on_hand) { 11_111 }
- let(:variant_override) { create(:variant_override, variant: variant, hub: hub, price: price, count_on_hand: count_on_hand) }
+ let(:variant_override) {
+ create(:variant_override, variant: variant, hub: hub, price: price,
+ count_on_hand: count_on_hand)
+ }
it "serializes a variant override" do
serializer = Api::Admin::VariantOverrideSerializer.new variant_override
diff --git a/spec/serializers/api/enterprise_shopfront_serializer_spec.rb b/spec/serializers/api/enterprise_shopfront_serializer_spec.rb
index 4079b51a6b..ca7d8ea013 100644
--- a/spec/serializers/api/enterprise_shopfront_serializer_spec.rb
+++ b/spec/serializers/api/enterprise_shopfront_serializer_spec.rb
@@ -9,7 +9,9 @@ describe Api::EnterpriseShopfrontSerializer do
let!(:taxon1) { create(:taxon, name: 'Meat') }
let!(:taxon2) { create(:taxon, name: 'Veg') }
- let!(:product) { create(:product, supplier: producer, primary_taxon: taxon1, taxons: [taxon1, taxon2] ) }
+ let!(:product) {
+ create(:product, supplier: producer, primary_taxon: taxon1, taxons: [taxon1, taxon2] )
+ }
let(:close_time) { 2.days.from_now }
let!(:oc) { create(:simple_order_cycle, orders_close_at: close_time, distributors: [hub]) }
diff --git a/spec/serializers/api/product_serializer_spec.rb b/spec/serializers/api/product_serializer_spec.rb
index 417b35fa27..11ee826b12 100644
--- a/spec/serializers/api/product_serializer_spec.rb
+++ b/spec/serializers/api/product_serializer_spec.rb
@@ -30,7 +30,6 @@ describe Api::ProductSerializer do
:id, :name, :permalink, :meta_keywords, :group_buy, :notes, :description, :description_html,
:properties_with_values, :variants, :primary_taxon, :taxons, :images, :supplier
]
-
end
it "serializes product properties" do
diff --git a/spec/services/address_geocoder_spec.rb b/spec/services/address_geocoder_spec.rb
index 2d9754846e..0df81ae6d3 100644
--- a/spec/services/address_geocoder_spec.rb
+++ b/spec/services/address_geocoder_spec.rb
@@ -7,14 +7,14 @@ describe AddressGeocoder do
let(:victoria) { Spree::State.find_or_create_by(name: "Victoria", country: australia) }
let(:address) do
create(:address,
- address1: "12 Galvin Street",
- address2: "Unit 1",
- city: "Altona",
- country: australia,
- state: victoria,
- zipcode: 3018,
- latitude: nil,
- longitude: nil)
+ address1: "12 Galvin Street",
+ address2: "Unit 1",
+ city: "Altona",
+ country: australia,
+ state: victoria,
+ zipcode: 3018,
+ latitude: nil,
+ longitude: nil)
end
it "formats the address into a single comma separated string when passing it to the geocoder" do
diff --git a/spec/services/bulk_invoice_service_spec.rb b/spec/services/bulk_invoice_service_spec.rb
index b145dc8501..62aaa977cb 100644
--- a/spec/services/bulk_invoice_service_spec.rb
+++ b/spec/services/bulk_invoice_service_spec.rb
@@ -62,9 +62,12 @@ describe BulkInvoiceService do
end
it "orders with completed desc" do
- order_old = create(:order_with_distributor, :with_line_item, :completed, completed_at: 2.minutes.ago)
- order_oldest = create(:order_with_distributor, :with_line_item, :completed, completed_at: 4.minutes.ago)
- order_older = create(:order_with_distributor, :with_line_item, :completed, completed_at: 3.minutes.ago)
+ order_old = create(:order_with_distributor, :with_line_item, :completed,
+ completed_at: 2.minutes.ago)
+ order_oldest = create(:order_with_distributor, :with_line_item, :completed,
+ completed_at: 4.minutes.ago)
+ order_older = create(:order_with_distributor, :with_line_item, :completed,
+ completed_at: 3.minutes.ago)
expect(renderer).to receive(:render_to_string).with(order_old).ordered.and_return("")
expect(renderer).to receive(:render_to_string).with(order_older).ordered.and_return("")
diff --git a/spec/services/cart_service_spec.rb b/spec/services/cart_service_spec.rb
index b92e03355a..fc0117377b 100644
--- a/spec/services/cart_service_spec.rb
+++ b/spec/services/cart_service_spec.rb
@@ -284,7 +284,8 @@ describe CartService do
let(:order_cycle_distributed_variants) { double(:order_cycle_distributed_variants) }
before do
- expect(OrderCycleDistributedVariants).to receive(:new).with(234, 123).and_return(order_cycle_distributed_variants)
+ expect(OrderCycleDistributedVariants).to receive(:new).with(234,
+ 123).and_return(order_cycle_distributed_variants)
cart_service.instance_eval { @distributor = 123; @order_cycle = 234 }
end
diff --git a/spec/services/embedded_page_service_spec.rb b/spec/services/embedded_page_service_spec.rb
index 20cb156969..bcf92447f4 100644
--- a/spec/services/embedded_page_service_spec.rb
+++ b/spec/services/embedded_page_service_spec.rb
@@ -4,10 +4,20 @@ require 'spec_helper'
describe EmbeddedPageService do
let(:enterprise_slug) { 'test-enterprise' }
- let(:params) { { controller: 'enterprises', action: 'shop', id: enterprise_slug, embedded_shopfront: true } }
+ let(:params) {
+ { controller: 'enterprises', action: 'shop', id: enterprise_slug, embedded_shopfront: true }
+ }
let(:session) { {} }
- let(:request) { ActionController::TestRequest.new({'HTTP_HOST' => 'ofn-instance.com', 'HTTP_REFERER' => 'https://embedding-enterprise.com'}, nil, nil) }
- let(:response) { ActionDispatch::TestResponse.new(200, 'X-Frame-Options' => 'DENY', 'Content-Security-Policy' => "frame-ancestors 'none'") }
+ let(:request) {
+ ActionController::TestRequest.new(
+ { 'HTTP_HOST' => 'ofn-instance.com',
+ 'HTTP_REFERER' => 'https://embedding-enterprise.com' }, nil, nil
+ )
+ }
+ let(:response) {
+ ActionDispatch::TestResponse.new(200, 'X-Frame-Options' => 'DENY',
+ 'Content-Security-Policy' => "frame-ancestors 'none'")
+ }
let(:service) { EmbeddedPageService.new(params, session, request, response) }
before do
@@ -63,7 +73,11 @@ describe EmbeddedPageService do
end
context "when the request's referer is malformed" do
- let(:request) { ActionController::TestRequest.new({'HTTP_HOST' => 'ofn-instance.com', 'HTTP_REFERER' => 'hello'}, nil, nil) }
+ let(:request) {
+ ActionController::TestRequest.new(
+ { 'HTTP_HOST' => 'ofn-instance.com', 'HTTP_REFERER' => 'hello' }, nil, nil
+ )
+ }
before do
service.embed!
end
diff --git a/spec/services/exchange_products_renderer_spec.rb b/spec/services/exchange_products_renderer_spec.rb
index ba9dc76d8b..f2c5fd7bc6 100644
--- a/spec/services/exchange_products_renderer_spec.rb
+++ b/spec/services/exchange_products_renderer_spec.rb
@@ -31,7 +31,8 @@ describe ExchangeProductsRenderer do
it "loads products" do
products = renderer.exchange_products(false, exchange.receiver)
- suppliers = [exchange.variants[0].product.supplier.name, exchange.variants[1].product.supplier.name]
+ suppliers = [exchange.variants[0].product.supplier.name,
+ exchange.variants[1].product.supplier.name]
expect(suppliers).to include products.first.supplier.name
expect(suppliers).to include products.second.supplier.name
end
@@ -44,7 +45,9 @@ describe ExchangeProductsRenderer do
end
context "showing products from coordinator inventory only" do
- before { order_cycle.update prefers_product_selection_from_coordinator_inventory_only: true }
+ before {
+ order_cycle.update prefers_product_selection_from_coordinator_inventory_only: true
+ }
it "loads no products if there are no products from the coordinator inventory" do
products = renderer.exchange_products(false, exchange.receiver)
@@ -54,7 +57,8 @@ describe ExchangeProductsRenderer do
it "loads products from the coordinator inventory" do
# Add variant already in the exchange to the coordinator's inventory
- exchange.variants.first.inventory_items = [create(:inventory_item, enterprise: order_cycle.coordinator)]
+ exchange.variants.first.inventory_items = [create(:inventory_item,
+ enterprise: order_cycle.coordinator)]
products = renderer.exchange_products(false, exchange.receiver)
@@ -76,8 +80,14 @@ describe ExchangeProductsRenderer do
describe "when OC is showing only the coordinators inventory" do
let(:exchange_with_visible_variant) { order_cycle.exchanges.incoming.last }
let(:exchange_with_hidden_variant) { order_cycle.exchanges.incoming.first }
- let!(:visible_inventory_item) { create(:inventory_item, enterprise: order_cycle.coordinator, variant: exchange_with_visible_variant.variants.first, visible: true) }
- let!(:hidden_inventory_item) { create(:inventory_item, enterprise: order_cycle.coordinator, variant: exchange_with_hidden_variant.variants.first, visible: false) }
+ let!(:visible_inventory_item) {
+ create(:inventory_item, enterprise: order_cycle.coordinator,
+ variant: exchange_with_visible_variant.variants.first, visible: true)
+ }
+ let!(:hidden_inventory_item) {
+ create(:inventory_item, enterprise: order_cycle.coordinator,
+ variant: exchange_with_hidden_variant.variants.first, visible: false)
+ }
before do
order_cycle.prefers_product_selection_from_coordinator_inventory_only = true
diff --git a/spec/services/order_cycle_distributed_products_spec.rb b/spec/services/order_cycle_distributed_products_spec.rb
index 3f10a03831..178fe37e9b 100644
--- a/spec/services/order_cycle_distributed_products_spec.rb
+++ b/spec/services/order_cycle_distributed_products_spec.rb
@@ -14,7 +14,8 @@ describe OrderCycleDistributedProducts do
describe "product distributed by distributor in the OC" do
it "returns products" do
- expect(described_class.new(distributor, order_cycle, customer).products_relation).to eq([product])
+ expect(described_class.new(distributor, order_cycle,
+ customer).products_relation).to eq([product])
end
end
@@ -28,7 +29,8 @@ describe OrderCycleDistributedProducts do
end
it "does not return product" do
- expect(described_class.new(distributor, order_cycle, customer).products_relation).to_not include product
+ expect(described_class.new(distributor, order_cycle,
+ customer).products_relation).to_not include product
end
end
@@ -39,33 +41,40 @@ describe OrderCycleDistributedProducts do
end
it "does not return product" do
- expect(described_class.new(distributor, order_cycle, customer).products_relation).to_not include product
+ expect(described_class.new(distributor, order_cycle,
+ customer).products_relation).to_not include product
end
end
describe "filtering products that are out of stock" do
context "with regular variants" do
it "returns product when variant is in stock" do
- expect(described_class.new(distributor, order_cycle, customer).products_relation).to include product
+ expect(described_class.new(distributor, order_cycle,
+ customer).products_relation).to include product
end
it "does not return product when variant is out of stock" do
variant.update_attribute(:on_hand, 0)
- expect(described_class.new(distributor, order_cycle, customer).products_relation).to_not include product
+ expect(described_class.new(distributor, order_cycle,
+ customer).products_relation).to_not include product
end
end
context "with variant overrides" do
- let!(:override) { create(:variant_override, hub: distributor, variant: variant, count_on_hand: 0) }
+ let!(:override) {
+ create(:variant_override, hub: distributor, variant: variant, count_on_hand: 0)
+ }
it "does not return product when an override is out of stock" do
- expect(described_class.new(distributor, order_cycle, customer).products_relation).to_not include product
+ expect(described_class.new(distributor, order_cycle,
+ customer).products_relation).to_not include product
end
it "returns product when an override is in stock" do
variant.update_attribute(:on_hand, 0)
override.update_attribute(:count_on_hand, 10)
- expect(described_class.new(distributor, order_cycle, customer).products_relation).to include product
+ expect(described_class.new(distributor, order_cycle,
+ customer).products_relation).to include product
end
end
end
diff --git a/spec/services/order_cycle_form_spec.rb b/spec/services/order_cycle_form_spec.rb
index baaaffecd8..4d5bce792c 100644
--- a/spec/services/order_cycle_form_spec.rb
+++ b/spec/services/order_cycle_form_spec.rb
@@ -62,16 +62,24 @@ describe OrderCycleForm do
let(:user) { create(:user, enterprise_limit: 10) }
let!(:managed_coordinator) { create(:enterprise, owner: user) }
let!(:managed_enterprise) { create(:enterprise, owner: user) }
- let!(:coordinated_order_cycle) { create(:simple_order_cycle, coordinator: managed_coordinator ) }
- let!(:coordinated_order_cycle2) { create(:simple_order_cycle, coordinator: managed_enterprise ) }
- let!(:uncoordinated_order_cycle) { create(:simple_order_cycle, coordinator: create(:enterprise) ) }
+ let!(:coordinated_order_cycle) {
+ create(:simple_order_cycle, coordinator: managed_coordinator )
+ }
+ let!(:coordinated_order_cycle2) {
+ create(:simple_order_cycle, coordinator: managed_enterprise )
+ }
+ let!(:uncoordinated_order_cycle) {
+ create(:simple_order_cycle, coordinator: create(:enterprise) )
+ }
let!(:coordinated_schedule) { create(:schedule, order_cycles: [coordinated_order_cycle] ) }
let!(:coordinated_schedule2) { create(:schedule, order_cycles: [coordinated_order_cycle2] ) }
let!(:uncoordinated_schedule) { create(:schedule, order_cycles: [uncoordinated_order_cycle] ) }
context "where I manage the order_cycle's coordinator" do
let(:form) { OrderCycleForm.new(coordinated_order_cycle, params, user) }
- let(:syncer_mock) { instance_double(OrderManagement::Subscriptions::ProxyOrderSyncer, sync!: true) }
+ let(:syncer_mock) {
+ instance_double(OrderManagement::Subscriptions::ProxyOrderSyncer, sync!: true)
+ }
before do
allow(OrderManagement::Subscriptions::ProxyOrderSyncer).to receive(:new) { syncer_mock }
diff --git a/spec/services/order_data_masker_spec.rb b/spec/services/order_data_masker_spec.rb
index 70aeab7bd9..9c98f967e2 100644
--- a/spec/services/order_data_masker_spec.rb
+++ b/spec/services/order_data_masker_spec.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
require 'spec_helper'
describe OrderDataMasker do
diff --git a/spec/services/order_factory_spec.rb b/spec/services/order_factory_spec.rb
index 9b6e096a8c..5c5fdba2db 100644
--- a/spec/services/order_factory_spec.rb
+++ b/spec/services/order_factory_spec.rb
@@ -22,7 +22,8 @@ describe OrderFactory do
describe "create" do
let(:attrs) do
attrs = {}
- attrs[:line_items] = [{ variant_id: variant1.id, quantity: 2 }, { variant_id: variant2.id, quantity: 4 }]
+ attrs[:line_items] =
+ [{ variant_id: variant1.id, quantity: 2 }, { variant_id: variant2.id, quantity: 4 }]
attrs[:customer_id] = customer.id
attrs[:distributor_id] = shop.id
attrs[:order_cycle_id] = order_cycle.id
@@ -104,7 +105,9 @@ describe OrderFactory do
end
context "when an override is present" do
- let!(:override) { create(:variant_override, hub_id: shop.id, variant_id: variant1.id, count_on_hand: 3) }
+ let!(:override) {
+ create(:variant_override, hub_id: shop.id, variant_id: variant1.id, count_on_hand: 3)
+ }
before { attrs[:line_items].first[:quantity] = 6 }
context "when skip_stock_check is not requested" do
@@ -135,7 +138,9 @@ describe OrderFactory do
end
context "when an override is present" do
- let!(:override) { create(:variant_override, hub_id: shop.id, variant_id: variant1.id, price: 3.0) }
+ let!(:override) {
+ create(:variant_override, hub_id: shop.id, variant_id: variant1.id, price: 3.0)
+ }
it "uses the price from the override" do
expect_new_order
diff --git a/spec/services/order_syncer_spec.rb b/spec/services/order_syncer_spec.rb
index f2158aaff0..9c7ba71425 100644
--- a/spec/services/order_syncer_spec.rb
+++ b/spec/services/order_syncer_spec.rb
@@ -150,7 +150,10 @@ describe OrderSyncer do
let!(:bill_address_attrs) { subscription.bill_address.attributes }
let!(:ship_address_attrs) { subscription.ship_address.attributes }
- let(:params) { { bill_address_attributes: { id: bill_address_attrs["id"], firstname: "Bill", address1: "123 abc st", phone: "1123581321" } } }
+ let(:params) {
+ { bill_address_attributes: { id: bill_address_attrs["id"], firstname: "Bill",
+ address1: "123 abc st", phone: "1123581321" } }
+ }
let(:syncer) { OrderSyncer.new(subscription) }
context "when a ship address is not required" do
@@ -255,7 +258,10 @@ describe OrderSyncer do
let!(:bill_address_attrs) { subscription.bill_address.attributes }
let!(:ship_address_attrs) { subscription.ship_address.attributes }
- let(:params) { { ship_address_attributes: { id: ship_address_attrs["id"], firstname: "Ship", address1: "123 abc st", phone: "1123581321" } } }
+ let(:params) {
+ { ship_address_attributes: { id: ship_address_attrs["id"], firstname: "Ship",
+ address1: "123 abc st", phone: "1123581321" } }
+ }
let(:syncer) { OrderSyncer.new(subscription) }
context "when a ship address is not required" do
@@ -275,7 +281,9 @@ describe OrderSyncer do
end
context "but the shipping method is being changed to one that requires a ship_address" do
- let(:new_shipping_method) { create(:shipping_method, distributors: [distributor], require_ship_address: true) }
+ let(:new_shipping_method) {
+ create(:shipping_method, distributors: [distributor], require_ship_address: true)
+ }
before { params.merge!(shipping_method_id: new_shipping_method.id) }
@@ -384,7 +392,8 @@ describe OrderSyncer do
expect(order.reload.total.to_f).to eq 59.97
subscription.assign_attributes(params)
expect(syncer.sync!).to be true
- line_items = Spree::LineItem.where(order_id: subscription.orders, variant_id: sli.variant_id)
+ line_items = Spree::LineItem.where(order_id: subscription.orders,
+ variant_id: sli.variant_id)
expect(line_items.map(&:quantity)).to eq [2]
expect(order.reload.total.to_f).to eq 79.96
end
@@ -403,7 +412,8 @@ describe OrderSyncer do
it "updates the line_item quantities and totals on all orders" do
expect(syncer.sync!).to be true
- line_items = Spree::LineItem.where(order_id: subscription.orders, variant_id: sli.variant_id)
+ line_items = Spree::LineItem.where(order_id: subscription.orders,
+ variant_id: sli.variant_id)
expect(line_items.map(&:quantity)).to eq [3]
expect(order.reload.total.to_f).to eq 99.95
end
@@ -415,7 +425,8 @@ describe OrderSyncer do
expect(syncer.sync!).to be true
- line_items = Spree::LineItem.where(order_id: subscription.orders, variant_id: sli.variant_id)
+ line_items = Spree::LineItem.where(order_id: subscription.orders,
+ variant_id: sli.variant_id)
expect(line_items.map(&:quantity)).to eq [1]
expect(order.reload.total.to_f).to eq 59.97
line_item = order.line_items.find_by(variant_id: sli.variant_id)
@@ -490,7 +501,9 @@ describe OrderSyncer do
end
context "when quantity is within available stock" do
- let(:params) { { subscription_line_items_attributes: [{ id: nil, variant_id: variant.id, quantity: 1 }] } }
+ let(:params) {
+ { subscription_line_items_attributes: [{ id: nil, variant_id: variant.id, quantity: 1 }] }
+ }
it "adds the line item and updates the total on all orders" do
expect(syncer.sync!).to be true
@@ -502,7 +515,9 @@ describe OrderSyncer do
end
context "when quantity is greater than available stock" do
- let(:params) { { subscription_line_items_attributes: [{ id: nil, variant_id: variant.id, quantity: 7 }] } }
+ let(:params) {
+ { subscription_line_items_attributes: [{ id: nil, variant_id: variant.id, quantity: 7 }] }
+ }
context "when order is not complete" do
it "adds the line_item and updates totals on all orders" do
@@ -530,15 +545,19 @@ describe OrderSyncer do
it "does nothing to the order and adds the order to order_update_issues" do
expect(syncer.sync!).to be true
- line_items = Spree::LineItem.where(order_id: subscription.orders, variant_id: variant.id)
+ line_items = Spree::LineItem.where(order_id: subscription.orders,
+ variant_id: variant.id)
expect(line_items.map(&:quantity)).to eq []
subscription.save # this is necessary to get an id on the subscription_line_items
- params = { subscription_line_items_attributes: [{ id: subscription.subscription_line_items.last.id, quantity: 2 }] }
+ params = { subscription_line_items_attributes: [{
+ id: subscription.subscription_line_items.last.id, quantity: 2
+ }] }
subscription.assign_attributes(params)
expect(syncer.sync!).to be true
- line_items = Spree::LineItem.where(order_id: subscription.orders, variant_id: variant.id)
+ line_items = Spree::LineItem.where(order_id: subscription.orders,
+ variant_id: variant.id)
expect(line_items.map(&:quantity)).to eq []
expect(syncer.order_update_issues[order.id]).to include "#{variant.product.name} - #{variant.full_name}"
end
diff --git a/spec/services/permissions/order_spec.rb b/spec/services/permissions/order_spec.rb
index 9373b8d2a0..ceebf77ff3 100644
--- a/spec/services/permissions/order_spec.rb
+++ b/spec/services/permissions/order_spec.rb
@@ -9,10 +9,18 @@ module Permissions
let!(:basic_permissions) { OpenFoodNetwork::Permissions.new(user) }
let(:distributor) { create(:distributor_enterprise) }
let(:coordinator) { create(:distributor_enterprise) }
- let(:order_cycle) { create(:simple_order_cycle, coordinator: coordinator, distributors: [distributor]) }
- let(:order_completed) { create(:completed_order_with_totals, order_cycle: order_cycle, distributor: distributor ) }
- let(:order_cancelled) { create(:order, order_cycle: order_cycle, distributor: distributor, state: 'canceled' ) }
- let(:order_cart) { create(:order, order_cycle: order_cycle, distributor: distributor, state: 'cart' ) }
+ let(:order_cycle) {
+ create(:simple_order_cycle, coordinator: coordinator, distributors: [distributor])
+ }
+ let(:order_completed) {
+ create(:completed_order_with_totals, order_cycle: order_cycle, distributor: distributor )
+ }
+ let(:order_cancelled) {
+ create(:order, order_cycle: order_cycle, distributor: distributor, state: 'canceled' )
+ }
+ let(:order_cart) {
+ create(:order, order_cycle: order_cycle, distributor: distributor, state: 'cart' )
+ }
let(:order_from_last_year) {
create(:completed_order_with_totals, order_cycle: order_cycle, distributor: distributor,
completed_at: Time.zone.now - 1.year)
@@ -32,7 +40,9 @@ module Permissions
context "as the hub through which the order was placed" do
before do
- allow(basic_permissions).to receive(:managed_enterprises) { Enterprise.where(id: distributor) }
+ allow(basic_permissions).to receive(:managed_enterprises) {
+ Enterprise.where(id: distributor)
+ }
end
it "should let me see the order" do
@@ -42,8 +52,12 @@ module Permissions
context "as the coordinator of the order cycle through which the order was placed" do
before do
- allow(basic_permissions).to receive(:managed_enterprises) { Enterprise.where(id: coordinator) }
- allow(basic_permissions).to receive(:coordinated_order_cycles) { OrderCycle.where(id: order_cycle) }
+ allow(basic_permissions).to receive(:managed_enterprises) {
+ Enterprise.where(id: coordinator)
+ }
+ allow(basic_permissions).to receive(:coordinated_order_cycles) {
+ OrderCycle.where(id: order_cycle)
+ }
end
it "should let me see the order" do
@@ -65,8 +79,11 @@ module Permissions
context "as a producer which has granted P-OC to the distributor of an order" do
before do
- allow(basic_permissions).to receive(:managed_enterprises) { Enterprise.where(id: producer) }
- create(:enterprise_relationship, parent: producer, child: distributor, permissions_list: [:add_to_order_cycle])
+ allow(basic_permissions).to receive(:managed_enterprises) {
+ Enterprise.where(id: producer)
+ }
+ create(:enterprise_relationship, parent: producer, child: distributor,
+ permissions_list: [:add_to_order_cycle])
end
context "which contains my products" do
@@ -89,7 +106,9 @@ module Permissions
context "as an enterprise that is a distributor in the order cycle, but not the distributor of the order" do
before do
- allow(basic_permissions).to receive(:managed_enterprises) { Enterprise.where(id: random_enterprise) }
+ allow(basic_permissions).to receive(:managed_enterprises) {
+ Enterprise.where(id: random_enterprise)
+ }
end
it "should not let me see the order" do
@@ -111,7 +130,9 @@ module Permissions
context "as the hub through which the parent order was placed" do
before do
- allow(basic_permissions).to receive(:managed_enterprises) { Enterprise.where(id: distributor) }
+ allow(basic_permissions).to receive(:managed_enterprises) {
+ Enterprise.where(id: distributor)
+ }
end
it "should let me see the line_items" do
@@ -121,8 +142,12 @@ module Permissions
context "as the coordinator of the order cycle through which the parent order was placed" do
before do
- allow(basic_permissions).to receive(:managed_enterprises) { Enterprise.where(id: coordinator) }
- allow(basic_permissions).to receive(:coordinated_order_cycles) { OrderCycle.where(id: order_cycle) }
+ allow(basic_permissions).to receive(:managed_enterprises) {
+ Enterprise.where(id: coordinator)
+ }
+ allow(basic_permissions).to receive(:coordinated_order_cycles) {
+ OrderCycle.where(id: order_cycle)
+ }
end
it "should let me see the line_items" do
@@ -132,8 +157,11 @@ module Permissions
context "as the manager producer which has granted P-OC to the distributor of the parent order" do
before do
- allow(basic_permissions).to receive(:managed_enterprises) { Enterprise.where(id: producer) }
- create(:enterprise_relationship, parent: producer, child: distributor, permissions_list: [:add_to_order_cycle])
+ allow(basic_permissions).to receive(:managed_enterprises) {
+ Enterprise.where(id: producer)
+ }
+ create(:enterprise_relationship, parent: producer, child: distributor,
+ permissions_list: [:add_to_order_cycle])
line_item1.product.supplier = producer
line_item1.product.save
@@ -148,7 +176,9 @@ module Permissions
context "as an enterprise that is a distributor in the order cycle, but not the distributor of the parent order" do
before do
- allow(basic_permissions).to receive(:managed_enterprises) { Enterprise.where(id: random_enterprise) }
+ allow(basic_permissions).to receive(:managed_enterprises) {
+ Enterprise.where(id: random_enterprise)
+ }
end
it "should not let me see the line_items" do
diff --git a/spec/services/permitted_attributes/order_cycle_spec.rb b/spec/services/permitted_attributes/order_cycle_spec.rb
index 5940e9bb62..072ddb51cf 100644
--- a/spec/services/permitted_attributes/order_cycle_spec.rb
+++ b/spec/services/permitted_attributes/order_cycle_spec.rb
@@ -7,7 +7,9 @@ module PermittedAttributes
let(:oc_permitted_attributes) { PermittedAttributes::OrderCycle.new(params) }
describe "with basic attributes" do
- let(:params) { ActionController::Parameters.new(order_cycle: { id: "2", name: "First Order Cycle" } ) }
+ let(:params) {
+ ActionController::Parameters.new(order_cycle: { id: "2", name: "First Order Cycle" } )
+ }
it "keeps permitted and removes not permitted" do
permitted_attributes = oc_permitted_attributes.call
@@ -18,7 +20,10 @@ module PermittedAttributes
end
describe "nested incoming_exchanges attributes" do
- let(:params) { ActionController::Parameters.new(order_cycle: { incoming_exchanges: [{ sender_id: "2", name: "Exchange Name", variants: [] }] } ) }
+ let(:params) {
+ ActionController::Parameters.new(order_cycle: { incoming_exchanges: [{ sender_id: "2",
+ name: "Exchange Name", variants: [] }] } )
+ }
it "keeps permitted and removes not permitted" do
permitted_attributes = oc_permitted_attributes.call
@@ -30,7 +35,10 @@ module PermittedAttributes
end
describe "variants inside incoming_exchanges attributes" do
- let(:params) { ActionController::Parameters.new(order_cycle: { incoming_exchanges: [{ variants: { "7" => true, "12" => true } }] } ) }
+ let(:params) {
+ ActionController::Parameters.new(order_cycle: { incoming_exchanges: [{ variants: { "7" => true,
+ "12" => true } }] } )
+ }
it "keeps all variant_ids provided" do
permitted_attributes = oc_permitted_attributes.call
diff --git a/spec/services/process_payment_intent_spec.rb b/spec/services/process_payment_intent_spec.rb
index 13b788395e..a7bd257dc5 100644
--- a/spec/services/process_payment_intent_spec.rb
+++ b/spec/services/process_payment_intent_spec.rb
@@ -8,16 +8,19 @@ describe ProcessPaymentIntent do
describe "processing a payment intent" do
let(:customer) { create(:customer) }
let(:order) {
- create(:order_with_totals, customer: customer, distributor: customer.enterprise, state: "payment")
+ create(:order_with_totals, customer: customer, distributor: customer.enterprise,
+ state: "payment")
}
let(:payment_method) { create(:stripe_sca_payment_method) }
- let!(:payment) { create(
- :payment,
- payment_method: payment_method,
- cvv_response_message: "https://stripe.com/redirect",
- response_code: "pi_123",
- order: order,
- state: "pending")
+ let!(:payment) {
+ create(
+ :payment,
+ payment_method: payment_method,
+ cvv_response_message: "https://stripe.com/redirect",
+ response_code: "pi_123",
+ order: order,
+ state: "pending"
+ )
}
let(:validator) { instance_double(Stripe::PaymentIntentValidator) }
@@ -48,7 +51,8 @@ describe ProcessPaymentIntent do
context "where the stripe payment intent validation responds with errors" do
before do
allow(validator)
- .to receive(:call).with(intent, anything).and_raise(Stripe::StripeError, "error message")
+ .to receive(:call).with(intent, anything).and_raise(Stripe::StripeError,
+ "error message")
end
it "returns returns the error message" do
diff --git a/spec/services/product_tag_rules_filterer_spec.rb b/spec/services/product_tag_rules_filterer_spec.rb
index 550b06a345..1624f9b09b 100644
--- a/spec/services/product_tag_rules_filterer_spec.rb
+++ b/spec/services/product_tag_rules_filterer_spec.rb
@@ -13,7 +13,9 @@ describe ProductTagRulesFilterer do
let(:variant_hidden_by_default) { create(:variant_override, variant: v1, hub: distributor) }
let(:variant_hidden_by_rule) { create(:variant_override, variant: v2, hub: distributor) }
let(:variant_shown_by_rule) { create(:variant_override, variant: v3, hub: distributor) }
- let(:variant_hidden_for_another_customer) { create(:variant_override, variant: v4, hub: distributor) }
+ let(:variant_hidden_for_another_customer) {
+ create(:variant_override, variant: v4, hub: distributor)
+ }
let(:customer) { create(:customer, enterprise: distributor) }
let(:variants_relation) {
Spree::Variant.joins(:product).where("spree_products.supplier_id = ?", distributor.id)
@@ -66,7 +68,8 @@ describe ProductTagRulesFilterer do
describe "#overrides_to_hide" do
context "with default rules" do
it "lists overrides tagged as hidden for this customer" do
- variant_hidden_by_default.update_attribute(:tag_list, default_hide_rule.preferred_variant_tags)
+ variant_hidden_by_default.update_attribute(:tag_list,
+ default_hide_rule.preferred_variant_tags)
overrides_to_hide = filterer.__send__(:overrides_to_hide)
expect(overrides_to_hide).to eq [variant_hidden_by_default.id]
@@ -76,12 +79,15 @@ describe ProductTagRulesFilterer do
context "with default and specific rules" do
it "lists overrides tagged as hidden for this customer" do
customer.update_attribute(:tag_list, hide_rule.preferred_customer_tags)
- variant_hidden_by_default.update_attribute(:tag_list, default_hide_rule.preferred_variant_tags)
+ variant_hidden_by_default.update_attribute(:tag_list,
+ default_hide_rule.preferred_variant_tags)
variant_hidden_by_rule.update_attribute(:tag_list, hide_rule.preferred_variant_tags)
- variant_hidden_for_another_customer.update_attribute(:tag_list, non_applicable_rule.preferred_variant_tags)
+ variant_hidden_for_another_customer.update_attribute(:tag_list,
+ non_applicable_rule.preferred_variant_tags)
overrides_to_hide = filterer.__send__(:overrides_to_hide)
- expect(overrides_to_hide).to include variant_hidden_by_default.id, variant_hidden_by_rule.id
+ expect(overrides_to_hide).to include variant_hidden_by_default.id,
+ variant_hidden_by_rule.id
end
end
end
diff --git a/spec/services/products_renderer_spec.rb b/spec/services/products_renderer_spec.rb
index 3794da31c7..146942b695 100644
--- a/spec/services/products_renderer_spec.rb
+++ b/spec/services/products_renderer_spec.rb
@@ -86,10 +86,18 @@ describe ProductsRenderer do
let(:hub) { create(:distributor_enterprise) }
let(:oc) { create(:simple_order_cycle, distributors: [hub], variants: [v1, v3, v4]) }
let(:p) { create(:simple_product) }
- let!(:v1) { create(:variant, product: p, unit_value: 3) } # In exchange, not in inventory (ie. not_hidden)
+ let!(:v1) {
+ create(:variant, product: p, unit_value: 3)
+ } # In exchange, not in inventory (ie. not_hidden)
let!(:v2) { create(:variant, product: p, unit_value: 5) } # Not in exchange
- let!(:v3) { create(:variant, product: p, unit_value: 7, inventory_items: [create(:inventory_item, enterprise: hub, visible: true)]) }
- let!(:v4) { create(:variant, product: p, unit_value: 9, inventory_items: [create(:inventory_item, enterprise: hub, visible: false)]) }
+ let!(:v3) {
+ create(:variant, product: p, unit_value: 7,
+ inventory_items: [create(:inventory_item, enterprise: hub, visible: true)])
+ }
+ let!(:v4) {
+ create(:variant, product: p, unit_value: 9,
+ inventory_items: [create(:inventory_item, enterprise: hub, visible: false)])
+ }
let(:products_renderer) { ProductsRenderer.new(hub, oc, customer) }
let(:variants) { products_renderer.send(:variants_for_shop_by_id) }
diff --git a/spec/services/unit_prices_spec.rb b/spec/services/unit_prices_spec.rb
index 0e836f2c29..eaec852e44 100644
--- a/spec/services/unit_prices_spec.rb
+++ b/spec/services/unit_prices_spec.rb
@@ -81,7 +81,7 @@ describe UnitPrice do
it "returns 2 for a 2 pound variant" do
allow(product).to receive(:variant_unit_scale) { 453.6 }
allow(product).to receive(:variant_unit) { "weight" }
- variant.unit_value = 2*453.6
+ variant.unit_value = 2 * 453.6
expect(subject.denominator).to eq(2)
end
end
diff --git a/spec/services/variant_units/option_value_namer_spec.rb b/spec/services/variant_units/option_value_namer_spec.rb
index f99e63878e..da3124c19c 100644
--- a/spec/services/variant_units/option_value_namer_spec.rb
+++ b/spec/services/variant_units/option_value_namer_spec.rb
@@ -95,7 +95,8 @@ module VariantUnits
end
it "generates values for all weight scales" do
- [[1.0, 'g'], [28.35, 'oz'], [453.6, 'lb'], [1000.0, 'kg'], [1_000_000.0, 'T']].each do |scale, unit|
+ [[1.0, 'g'], [28.35, 'oz'], [453.6, 'lb'], [1000.0, 'kg'],
+ [1_000_000.0, 'T']].each do |scale, unit|
p = double(:product, variant_unit: 'weight', variant_unit_scale: scale)
allow(v).to receive(:product) { p }
allow(v).to receive(:unit_value) { 10.0 * scale }
@@ -121,7 +122,8 @@ module VariantUnits
it "generates values for item units" do
%w(packet box).each do |unit|
- p = double(:product, variant_unit: 'items', variant_unit_scale: nil, variant_unit_name: unit)
+ p = double(:product, variant_unit: 'items', variant_unit_scale: nil,
+ variant_unit_name: unit)
allow(v).to receive(:product) { p }
allow(v).to receive(:unit_value) { 100 }
expect(subject.send(:option_value_value_unit)).to eq [100, unit.pluralize]
@@ -129,14 +131,16 @@ module VariantUnits
end
it "generates singular values for item units when value is 1" do
- p = double(:product, variant_unit: 'items', variant_unit_scale: nil, variant_unit_name: 'packet')
+ p = double(:product, variant_unit: 'items', variant_unit_scale: nil,
+ variant_unit_name: 'packet')
allow(v).to receive(:product) { p }
allow(v).to receive(:unit_value) { 1 }
expect(subject.send(:option_value_value_unit)).to eq [1, 'packet']
end
it "returns [nil, nil] when unit value is not set" do
- p = double(:product, variant_unit: 'items', variant_unit_scale: nil, variant_unit_name: 'foo')
+ p = double(:product, variant_unit: 'items', variant_unit_scale: nil,
+ variant_unit_name: 'foo')
allow(v).to receive(:product) { p }
allow(v).to receive(:unit_value) { nil }
expect(subject.send(:option_value_value_unit)).to eq [nil, nil]
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
index 2676a2c1f0..547031ccb1 100644
--- a/spec/spec_helper.rb
+++ b/spec/spec_helper.rb
@@ -112,10 +112,16 @@ RSpec.configure do |config|
end
# DatabaseCleaner
- config.before(:suite) { DatabaseCleaner.clean_with :deletion, except: ['spree_countries', 'spree_states'] }
+ config.before(:suite) {
+ DatabaseCleaner.clean_with :deletion, except: ['spree_countries', 'spree_states']
+ }
config.before(:each) { DatabaseCleaner.strategy = :transaction }
- config.before(:each, js: true) { DatabaseCleaner.strategy = :deletion, { except: ['spree_countries', 'spree_states'] } }
- config.before(:each, concurrency: true) { DatabaseCleaner.strategy = :deletion, { except: ['spree_countries', 'spree_states'] } }
+ config.before(:each, js: true) {
+ DatabaseCleaner.strategy = :deletion, { except: ['spree_countries', 'spree_states'] }
+ }
+ config.before(:each, concurrency: true) {
+ DatabaseCleaner.strategy = :deletion, { except: ['spree_countries', 'spree_states'] }
+ }
config.before(:each) { DatabaseCleaner.start }
config.after(:each) { DatabaseCleaner.clean }
config.after(:each, js: true) do
@@ -164,7 +170,9 @@ RSpec.configure do |config|
end
# Geocoding
- config.before(:each) { allow_any_instance_of(Spree::Address).to receive(:geocode).and_return([1, 1]) }
+ config.before(:each) {
+ allow_any_instance_of(Spree::Address).to receive(:geocode).and_return([1, 1])
+ }
default_country_id = DefaultCountry.id
checkout_zone = Spree::Config[:checkout_zone]
diff --git a/spec/support/cancan_helper.rb b/spec/support/cancan_helper.rb
index 33615f0694..1acba887c3 100644
--- a/spec/support/cancan_helper.rb
+++ b/spec/support/cancan_helper.rb
@@ -11,7 +11,11 @@ module Spree
target = options[:for]
@ability_result = {}
ability_hash = { ability_hash => true } if ability_hash.is_a? Symbol # e.g.: :create => {:create => true}
- ability_hash = ability_hash.inject({}){ |member, i| member.merge(i => true) } if ability_hash.is_a? Array # e.g.: [:create, :read] => {:create=>true, :read=>true}
+ if ability_hash.is_a? Array
+ ability_hash = ability_hash.inject({}){ |member, i|
+ member.merge(i => true)
+ }
+ end
ability_hash.each do |action, _true_or_false|
@ability_result[action] = ability.can?(action, target)
end
@@ -22,7 +26,11 @@ module Spree
failure_message do |user|
ability_hash, options = expected
ability_hash = { ability_hash => true } if ability_hash.is_a? Symbol # e.g.: :create
- ability_hash = ability_hash.inject({}){ |member, i| member.merge(i => true) } if ability_hash.is_a? Array # e.g.: [:create, :read] => {:create=>true, :read=>true}
+ if ability_hash.is_a? Array
+ ability_hash = ability_hash.inject({}){ |member, i|
+ member.merge(i => true)
+ }
+ end
target = options[:for]
message = "expected User:#{user} to have ability: #{ability_hash} for #{target}, but actual result is #{@ability_result}"
end
diff --git a/spec/support/embedded_pages_helper.rb b/spec/support/embedded_pages_helper.rb
index 064bd89a71..30a0a04749 100644
--- a/spec/support/embedded_pages_helper.rb
+++ b/spec/support/embedded_pages_helper.rb
@@ -2,10 +2,8 @@
module OpenFoodNetwork
module EmbeddedPagesHelper
- def on_embedded_page
- within_frame :frame do
- yield
- end
+ def on_embedded_page(&block)
+ within_frame :frame, &block
end
end
end
diff --git a/spec/support/features/datepicker_helper.rb b/spec/support/features/datepicker_helper.rb
index f07cc74f7a..dbe9e7d1f6 100644
--- a/spec/support/features/datepicker_helper.rb
+++ b/spec/support/features/datepicker_helper.rb
@@ -10,7 +10,8 @@ module Features
def select_date_from_datepicker(date)
navigate_datepicker_to_month date
- find('.flatpickr-calendar.open .flatpickr-days .flatpickr-day:not(.prevMonthDay)', text: date.strftime("%e").to_s.strip, exact_text: true, match: :first).click
+ find('.flatpickr-calendar.open .flatpickr-days .flatpickr-day:not(.prevMonthDay)',
+ text: date.strftime("%e").to_s.strip, exact_text: true, match: :first).click
end
def select_datetime_from_datepicker(datetime)
@@ -23,7 +24,7 @@ module Features
def navigate_datepicker_to_month(date, reference_date = Time.zone.today)
month_and_year = date.strftime("%-m %Y")
-
+
until datepicker_month_and_year == month_and_year.upcase
if date < reference_date
navigate_datepicker_to_previous_month
@@ -44,7 +45,7 @@ module Features
def datepicker_month_and_year
month = find(".flatpickr-calendar.open .flatpickr-current-month select.flatpickr-monthDropdown-months").value.to_i + 1
year = find(".flatpickr-calendar.open .flatpickr-current-month .numInputWrapper .cur-year").value
- return month.to_s + " " + year.to_s
+ month.to_s + " " + year.to_s
end
end
end
diff --git a/spec/support/i18n_translations_checker.rb b/spec/support/i18n_translations_checker.rb
index a722f13302..a464cfc660 100644
--- a/spec/support/i18n_translations_checker.rb
+++ b/spec/support/i18n_translations_checker.rb
@@ -34,14 +34,12 @@ module Spree
root = translations
processed_keys = []
translation_keys.each do |key|
- begin
- root = root.fetch(key.to_sym)
- processed_keys << key.to_sym
- rescue KeyError
- error = "#{(processed_keys << key).join('.')} (#{I18n.locale})"
- unless Spree.missing_translation_messages.include?(error)
- Spree.missing_translation_messages << error
- end
+ root = root.fetch(key.to_sym)
+ processed_keys << key.to_sym
+ rescue KeyError
+ error = "#{(processed_keys << key).join('.')} (#{I18n.locale})"
+ unless Spree.missing_translation_messages.include?(error)
+ Spree.missing_translation_messages << error
end
end
end
diff --git a/spec/support/matchers/select2_matchers.rb b/spec/support/matchers/select2_matchers.rb
index 4f451a87c4..117b67aacc 100644
--- a/spec/support/matchers/select2_matchers.rb
+++ b/spec/support/matchers/select2_matchers.rb
@@ -14,14 +14,17 @@ RSpec::Matchers.define :have_select2 do |id, options = {}|
results << node.has_selector?(from)
- if results.all?
- results << selected_option_is(from, options[:selected]) if options.key? :selected
+ if results.all? && (options.key? :selected)
+ results << selected_option_is(from, options[:selected])
end
if results.all?
results << all_options_present(from, options[:with_options]) if options.key? :with_options
results << exact_options_present(from, options[:options]) if options.key? :options
- results << all_options_absent(from, options[:without_options]) if options.key? :without_options
+ if options.key? :without_options
+ results << all_options_absent(from,
+ options[:without_options])
+ end
end
results.all?
@@ -46,8 +49,8 @@ RSpec::Matchers.define :have_select2 do |id, options = {}|
# results << selected_option_is(from, options[:selected]) if options.key? :selected
# end
- if results.none?
- results << all_options_absent(from, options[:with_options]) if options.key? :with_options
+ if results.none? && (options.key? :with_options)
+ results << all_options_absent(from, options[:with_options])
# results << exact_options_present(from, options[:options]) if options.key? :options
# results << no_options_present(from, options[:without_options]) if options.key? :without_options
end
diff --git a/spec/support/performance_helper.rb b/spec/support/performance_helper.rb
index 9b5adcb32b..f0236997fb 100644
--- a/spec/support/performance_helper.rb
+++ b/spec/support/performance_helper.rb
@@ -2,12 +2,12 @@
module OpenFoodNetwork
module PerformanceHelper
- def multi_benchmark(num_samples, cache_key_patterns: [])
+ def multi_benchmark(num_samples, cache_key_patterns: [], &block)
results = (0..num_samples).map do |_i|
ActiveRecord::Base.connection.query_cache.clear
delete_cache_keys(cache_key_patterns)
- result = Benchmark.measure { yield }
+ result = Benchmark.measure(&block)
puts result
diff --git a/spec/support/request/shop_workflow.rb b/spec/support/request/shop_workflow.rb
index d6859c2f9f..7eedb9898b 100644
--- a/spec/support/request/shop_workflow.rb
+++ b/spec/support/request/shop_workflow.rb
@@ -34,7 +34,9 @@ module ShopWorkflow
end
def set_order(order)
- allow_any_instance_of(ApplicationController).to receive(:session).and_return(order_id: order.id, access_token: order.token)
+ allow_any_instance_of(ApplicationController).to receive(:session).and_return(
+ order_id: order.id, access_token: order.token
+ )
end
def add_product_to_cart(order, product, quantity: 1)
@@ -82,12 +84,10 @@ module ShopWorkflow
wait_for_cart
end
- def within_variant(variant = nil)
+ def within_variant(variant = nil, &block)
selector = variant ? "#variant-#{variant.id}" : ".variants"
expect(page).to have_selector selector
- within(selector) do
- yield
- end
+ within(selector, &block)
end
def open_bulk_quantity_modal(variant)
diff --git a/spec/support/request/web_helper.rb b/spec/support/request/web_helper.rb
index 86ba297357..7daced0791 100644
--- a/spec/support/request/web_helper.rb
+++ b/spec/support/request/web_helper.rb
@@ -23,7 +23,7 @@ module WebHelper
selector += "[placeholder='#{opts[:placeholder]}']" if opts.key? :placeholder
visible = opts.key?(:visible) ? opts[:visible] : true
-
+
element = page.all(selector, visible: visible).first
expect(element.value).to eq(opts[:with]) if element && opts.key?(:with)
@@ -32,11 +32,9 @@ module WebHelper
def fill_in_fields(field_values)
field_values.each do |key, value|
- begin
- fill_in key, with: value
- rescue Capybara::ElementNotFound
- find_field(key).select(value)
- end
+ fill_in key, with: value
+ rescue Capybara::ElementNotFound
+ find_field(key).select(value)
end
end
@@ -120,7 +118,8 @@ module WebHelper
end
def open_select2(selector)
- page.find(selector).scroll_to(page.find(selector)).find(:css, '.select2-choice, .select2-search-field').click
+ page.find(selector).scroll_to(page.find(selector)).find(:css,
+ '.select2-choice, .select2-search-field').click
end
def close_select2
diff --git a/spec/support/seeds.rb b/spec/support/seeds.rb
index a8546c7af3..7b098401a2 100644
--- a/spec/support/seeds.rb
+++ b/spec/support/seeds.rb
@@ -8,7 +8,8 @@
# You can add more entries here if you need them for your tests.
if Spree::Country.where(nil).empty?
- Spree::Country.create!({ "name" => "Australia", "iso3" => "AUS", "iso" => "AU", "iso_name" => "AUSTRALIA", "numcode" => "36" })
+ Spree::Country.create!({ "name" => "Australia", "iso3" => "AUS", "iso" => "AU",
+ "iso_name" => "AUSTRALIA", "numcode" => "36" })
country = Spree::Country.find_by(name: 'Australia')
Spree::State.create!({ "name" => "Victoria", "abbr" => "Vic", :country => country })
Spree::State.create!({ "name" => "New South Wales", "abbr" => "NSW", :country => country })
diff --git a/spec/views/spree/admin/payment_methods/index.html.haml_spec.rb b/spec/views/spree/admin/payment_methods/index.html.haml_spec.rb
index 2a8d4bd991..6e2c9eb48b 100644
--- a/spec/views/spree/admin/payment_methods/index.html.haml_spec.rb
+++ b/spec/views/spree/admin/payment_methods/index.html.haml_spec.rb
@@ -31,7 +31,8 @@ describe "spree/admin/payment_methods/index.html.haml" do
it "shows only the providers of the existing payment methods" do
render
- expect(rendered).to have_content "Cash/EFT/etc. (payments for which automatic validation is not required)", count: 2
+ expect(rendered).to have_content "Cash/EFT/etc. (payments for which automatic validation is not required)",
+ count: 2
end
it "does not show Enviroment column" do
@@ -55,7 +56,8 @@ describe "spree/admin/payment_methods/index.html.haml" do
it "shows only the providers of the existing payment methods" do
render
- expect(rendered).to have_content "Cash/EFT/etc. (payments for which automatic validation is not required)", count: 2
+ expect(rendered).to have_content "Cash/EFT/etc. (payments for which automatic validation is not required)",
+ count: 2
end
it "shows the Enviroment column" do