diff --git a/.rubocop_manual_todo.yml b/.rubocop_manual_todo.yml
index f8de8f86e7..7e76c6d5dd 100644
--- a/.rubocop_manual_todo.yml
+++ b/.rubocop_manual_todo.yml
@@ -22,44 +22,41 @@
Metrics/LineLength:
Max: 100
Exclude:
+ - Gemfile
- app/controllers/admin/bulk_line_items_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/enterprises_controller.rb
+ - app/controllers/admin/enterprise_roles_controller.rb
- app/controllers/admin/inventory_items_controller.rb
- app/controllers/admin/manager_invitations_controller.rb
- app/controllers/admin/order_cycles_controller.rb
- app/controllers/admin/product_import_controller.rb
- app/controllers/admin/proxy_orders_controller.rb
- app/controllers/admin/schedules_controller.rb
- - app/controllers/admin/subscription_line_items_controller.rb
- app/controllers/admin/subscriptions_controller.rb
- app/controllers/admin/variant_overrides_controller.rb
- app/controllers/api/enterprise_attachment_controller.rb
+ - app/controllers/api/order_cycles_controller.rb
- app/controllers/api/product_images_controller.rb
- app/controllers/application_controller.rb
- app/controllers/checkout_controller.rb
- app/controllers/spree/admin/adjustments_controller_decorator.rb
- app/controllers/spree/admin/base_controller_decorator.rb
- - app/controllers/spree/admin/line_items_controller_decorator.rb
- app/controllers/spree/admin/orders_controller_decorator.rb
- - app/controllers/spree/admin/payment_methods_controller_decorator.rb
+ - app/controllers/spree/admin/payments_controller_decorator.rb
- app/controllers/spree/admin/products_controller_decorator.rb
- app/controllers/spree/admin/reports_controller_decorator.rb
- - app/controllers/spree/admin/shipping_methods_controller_decorator.rb
- app/controllers/spree/api/products_controller_decorator.rb
- app/controllers/spree/credit_cards_controller.rb
- app/controllers/spree/orders_controller_decorator.rb
- app/controllers/spree/paypal_controller_decorator.rb
- app/controllers/stripe/callbacks_controller.rb
- - app/helpers/admin/account_helper.rb
- app/helpers/admin/injection_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/enterprises_helper.rb
- app/helpers/footer_links_helper.rb
@@ -71,17 +68,17 @@ Metrics/LineLength:
- app/helpers/spree/admin/navigation_helper_decorator.rb
- app/helpers/spree/admin/orders_helper_decorator.rb
- app/helpers/spree/orders_helper.rb
- - app/jobs/products_cache_integrity_checker_job.rb
- app/jobs/subscription_confirm_job.rb
- - app/jobs/subscription_placement_job.rb
- - app/mailers/producer_mailer.rb
- - app/mailers/spree/order_mailer_decorator.rb
- app/mailers/subscription_mailer.rb
- app/models/column_preference.rb
+ - app/models/concerns/order_shipment.rb
+ - app/models/concerns/product_stock.rb
+ - app/models/concerns/variant_stock.rb
- app/models/content_configuration.rb
- app/models/customer.rb
- - app/models/enterprise_fee.rb
- app/models/enterprise.rb
+ - app/models/enterprise_fee.rb
+ - app/models/enterprise_group.rb
- app/models/enterprise_relationship.rb
- app/models/enterprise_role.rb
- app/models/exchange.rb
@@ -97,9 +94,10 @@ Metrics/LineLength:
- app/models/schedule.rb
- app/models/spree/ability_decorator.rb
- app/models/spree/adjustment_decorator.rb
+ - app/models/spree/app_configuration_decorator.rb
- app/models/spree/calculator/default_tax_decorator.rb
- - app/models/spree/calculator/flexi_rate_decorator.rb
- app/models/spree/classification_decorator.rb
+ - app/models/spree/concerns/payment_method_distributors.rb
- app/models/spree/gateway/stripe_connect.rb
- app/models/spree/line_item_decorator.rb
- app/models/spree/order_decorator.rb
@@ -108,16 +106,14 @@ Metrics/LineLength:
- app/models/spree/product_decorator.rb
- app/models/spree/shipment_decorator.rb
- app/models/spree/shipping_method_decorator.rb
+ - app/models/spree/tax_rate_decorator.rb
- app/models/spree/taxon_decorator.rb
- app/models/spree/user_decorator.rb
- app/models/spree/variant_decorator.rb
- app/models/subscription.rb
- app/models/variant_override.rb
- app/models/variant_override_set.rb
- - app/overrides/add_distributor_details_js_to_product.rb
- app/overrides/add_enterprise_fees_to_admin_configurations_menu.rb
- - app/overrides/replace_checkout_payment_button.rb
- - app/overrides/replace_payment_name_with_description.rb
- app/serializers/api/admin/basic_enterprise_serializer.rb
- app/serializers/api/admin/enterprise_fee_serializer.rb
- app/serializers/api/admin/enterprise_serializer.rb
@@ -127,36 +123,34 @@ Metrics/LineLength:
- app/serializers/api/admin/index_order_cycle_serializer.rb
- app/serializers/api/admin/line_item_serializer.rb
- app/serializers/api/admin/order_cycle_serializer.rb
- - app/serializers/api/admin/product_serializer.rb
- app/serializers/api/admin/subscription_serializer.rb
- app/serializers/api/admin/tag_rule_serializer.rb
- app/serializers/api/admin/variant_override_serializer.rb
- app/serializers/api/admin/variant_serializer.rb
- app/services/cart_service.rb
+ - app/services/default_stock_location.rb
- app/services/embedded_page_service.rb
- app/services/line_item_syncer.rb
- app/services/order_cycle_form.rb
- app/services/order_factory.rb
- app/services/order_syncer.rb
- app/services/subscriptions_count.rb
+ - app/services/variants_stock_levels.rb
- app/views/json/_groups.rabl
- - app/views/json/partials/_enterprise.rabl
- app/views/json/_producer.rabl
+ - app/views/json/partials/_enterprise.rabl
- app/views/spree/api/products/bulk_show.v1.rabl
- app/views/spree/api/variants/bulk_show.v1.rabl
- engines/web/app/helpers/web/cookies_policy_helper.rb
- - Gemfile
- lib/discourse/single_sign_on.rb
- lib/open_food_network/available_payment_method_filter.rb
- lib/open_food_network/bulk_coop_report.rb
- lib/open_food_network/customers_report.rb
- - app/services/order_cycle_distributed_variants.rb
- lib/open_food_network/enterprise_fee_applicator.rb
- lib/open_food_network/enterprise_fee_calculator.rb
- lib/open_food_network/enterprise_issue_validator.rb
- lib/open_food_network/group_buy_report.rb
- lib/open_food_network/lettuce_share_report.rb
- - lib/open_food_network/locking.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
@@ -166,8 +160,8 @@ Metrics/LineLength:
- lib/open_food_network/payments_report.rb
- lib/open_food_network/permalink_generator.rb
- lib/open_food_network/permissions.rb
- - lib/open_food_network/products_and_inventory_report_base.rb
- lib/open_food_network/products_cache.rb
+ - lib/open_food_network/products_renderer.rb
- lib/open_food_network/proxy_order_syncer.rb
- lib/open_food_network/reports/bulk_coop_allocation_report.rb
- lib/open_food_network/reports/line_items.rb
@@ -175,16 +169,13 @@ Metrics/LineLength:
- lib/open_food_network/users_and_enterprises_report.rb
- lib/open_food_network/variant_and_line_item_naming.rb
- lib/open_food_network/xero_invoices_report.rb
- - lib/spree/core/calculated_adjustments_decorator.rb
- lib/spree/core/controller_helpers/respond_with_decorator.rb
- lib/spree/localized_number.rb
- lib/spree/product_filters.rb
- lib/stripe/profile_storer.rb
- lib/tasks/cache.rake
- lib/tasks/data.rake
- - lib/tasks/dev.rake
- lib/tasks/enterprises.rake
- - spec/archive/features/consumer/checkout_spec.rb
- spec/controllers/admin/bulk_line_items_controller_spec.rb
- spec/controllers/admin/column_preferences_controller_spec.rb
- spec/controllers/admin/customers_controller_spec.rb
@@ -212,18 +203,20 @@ Metrics/LineLength:
- spec/controllers/shops_controller_spec.rb
- spec/controllers/spree/admin/adjustments_controller_spec.rb
- spec/controllers/spree/admin/base_controller_spec.rb
- - spec/controllers/spree/admin/line_items_controller_spec.rb
- - spec/controllers/spree/admin/orders_controller_spec.rb
- spec/controllers/spree/admin/orders/customer_details_controller_spec.rb
+ - spec/controllers/spree/admin/orders_controller_spec.rb
- spec/controllers/spree/admin/payment_methods_controller_spec.rb
- spec/controllers/spree/admin/payments_controller_spec.rb
- spec/controllers/spree/admin/reports_controller_spec.rb
+ - spec/controllers/spree/admin/variants_controller_spec.rb
+ - spec/controllers/spree/api/line_items_controller_spec.rb
- spec/controllers/spree/api/products_controller_spec.rb
+ - spec/controllers/spree/api/shipments_controller_spec.rb
- spec/controllers/spree/api/variants_controller_spec.rb
- spec/controllers/spree/credit_cards_controller_spec.rb
- spec/controllers/spree/orders_controller_spec.rb
- - spec/controllers/spree/users_controller_spec.rb
- spec/controllers/spree/user_sessions_controller_spec.rb
+ - spec/controllers/spree/users_controller_spec.rb
- spec/controllers/stripe/callbacks_controller_spec.rb
- spec/controllers/stripe/webhooks_controller_spec.rb
- spec/controllers/user_confirmations_controller_spec.rb
@@ -235,10 +228,10 @@ Metrics/LineLength:
- spec/features/admin/enterprise_fees_spec.rb
- spec/features/admin/enterprise_relationships_spec.rb
- spec/features/admin/enterprise_roles_spec.rb
+ - spec/features/admin/enterprise_user_spec.rb
- spec/features/admin/enterprises/images_spec.rb
- spec/features/admin/enterprises/index_spec.rb
- spec/features/admin/enterprises_spec.rb
- - spec/features/admin/enterprise_user_spec.rb
- spec/features/admin/image_settings_spec.rb
- spec/features/admin/multilingual_spec.rb
- spec/features/admin/order_cycles_spec.rb
@@ -279,6 +272,7 @@ Metrics/LineLength:
- spec/helpers/order_cycles_helper_spec.rb
- spec/helpers/spree/admin/base_helper_spec.rb
- spec/jobs/confirm_order_job_spec.rb
+ - spec/jobs/products_cache_integrity_checker_job_spec.rb
- spec/jobs/refresh_products_cache_job_spec.rb
- spec/jobs/subscription_confirm_job_spec.rb
- spec/jobs/subscription_placement_job_spec.rb
@@ -286,7 +280,6 @@ Metrics/LineLength:
- spec/lib/open_food_network/bulk_coop_report_spec.rb
- spec/lib/open_food_network/cached_products_renderer_spec.rb
- spec/lib/open_food_network/customers_report_spec.rb
- - spec/services/order_cycle_distributed_variants.rb
- spec/lib/open_food_network/enterprise_fee_applicator_spec.rb
- spec/lib/open_food_network/enterprise_fee_calculator_spec.rb
- spec/lib/open_food_network/enterprise_injection_data_spec.rb
@@ -297,6 +290,7 @@ Metrics/LineLength:
- spec/lib/open_food_network/order_cycle_form_applicator_spec.rb
- spec/lib/open_food_network/order_cycle_permissions_spec.rb
- spec/lib/open_food_network/order_grouper_spec.rb
+ - spec/lib/open_food_network/orders_and_fulfillments_report_spec.rb
- spec/lib/open_food_network/packing_report_spec.rb
- spec/lib/open_food_network/permissions_spec.rb
- spec/lib/open_food_network/products_and_inventory_report_spec.rb
@@ -315,6 +309,8 @@ Metrics/LineLength:
- spec/mailers/producer_mailer_spec.rb
- spec/mailers/subscription_mailer_spec.rb
- spec/models/column_preference_spec.rb
+ - spec/models/concerns/order_shipment_spec.rb
+ - spec/models/concerns/product_stock_spec.rb
- spec/models/customer_spec.rb
- spec/models/enterprise_caching_spec.rb
- spec/models/enterprise_fee_spec.rb
@@ -341,8 +337,8 @@ Metrics/LineLength:
- spec/models/spree/product_spec.rb
- spec/models/spree/property_spec.rb
- spec/models/spree/shipping_method_spec.rb
- - spec/models/spree/taxon_spec.rb
- spec/models/spree/tax_rate_spec.rb
+ - spec/models/spree/taxon_spec.rb
- spec/models/spree/user_spec.rb
- spec/models/spree/variant_spec.rb
- spec/models/stripe_account_spec.rb
@@ -366,17 +362,19 @@ Metrics/LineLength:
- spec/serializers/admin/for_order_cycle/supplied_product_serializer_spec.rb
- spec/serializers/admin/subscription_customer_serializer_spec.rb
- spec/serializers/admin/variant_override_serializer_spec.rb
- - spec/serializers/current_order_serializer.rb
- - spec/serializers/enterprise_serializer_spec.rb
+ - spec/serializers/api/enterprise_shopfront_serializer_spec.rb
+ - spec/serializers/current_order_serializer_spec.rb
- spec/serializers/order_serializer_spec.rb
- spec/services/cart_service_spec.rb
- spec/services/embedded_page_service_spec.rb
+ - spec/services/order_cycle_distributed_variants_spec.rb
- spec/services/order_cycle_form_spec.rb
- spec/services/order_factory_spec.rb
- spec/services/order_syncer_spec.rb
- spec/services/subscription_estimator_spec.rb
- spec/services/subscription_form_spec.rb
- spec/services/subscription_validator_spec.rb
+ - spec/services/subscription_variants_service_spec.rb
- spec/spec_helper.rb
- spec/support/cancan_helper.rb
- spec/support/delayed_job_helper.rb
@@ -394,7 +392,6 @@ Metrics/AbcSize:
- app/controllers/admin/bulk_line_items_controller.rb
- app/controllers/admin/customers_controller.rb
- app/controllers/admin/enterprise_fees_controller.rb
- - app/controllers/admin/enterprises_controller.rb
- app/controllers/admin/order_cycles_controller.rb
- app/controllers/admin/product_import_controller.rb
- app/controllers/admin/schedules_controller.rb
@@ -408,17 +405,18 @@ Metrics/AbcSize:
- app/controllers/cart_controller.rb
- app/controllers/checkout_controller.rb
- app/controllers/discourse_sso_controller.rb
+ - app/controllers/enterprises_controller.rb
- app/controllers/spree/admin/adjustments_controller_decorator.rb
- - app/controllers/spree/admin/line_items_controller_decorator.rb
+ - app/controllers/spree/admin/orders/customer_details_controller_decorator.rb
- app/controllers/spree/admin/orders_controller_decorator.rb
- app/controllers/spree/admin/overview_controller_decorator.rb
- - app/controllers/spree/admin/payment_methods_controller_decorator.rb
- app/controllers/spree/admin/payments_controller_decorator.rb
- app/controllers/spree/admin/products_controller_decorator.rb
- app/controllers/spree/admin/reports_controller_decorator.rb
- app/controllers/spree/admin/search_controller_decorator.rb
- - app/controllers/spree/admin/shipping_methods_controller_decorator.rb
+ - app/controllers/spree/admin/variants_controller_decorator.rb
- app/controllers/spree/api/products_controller_decorator.rb
+ - app/controllers/spree/api/shipments_controller_decorator.rb
- app/controllers/spree/credit_cards_controller.rb
- app/controllers/spree/orders_controller_decorator.rb
- app/controllers/spree/user_sessions_controller_decorator.rb
@@ -435,15 +433,14 @@ Metrics/AbcSize:
- app/mailers/producer_mailer.rb
- app/models/calculator/flat_percent_per_item.rb
- app/models/column_preference.rb
- - app/models/enterprise_group.rb
- app/models/enterprise.rb
+ - app/models/enterprise_group.rb
- app/models/enterprise_relationship.rb
- app/models/model_set.rb
- app/models/product_import/entry_processor.rb
- app/models/product_import/entry_validator.rb
- app/models/proxy_order.rb
- app/models/spree/ability_decorator.rb
- - app/models/spree/adjustment_decorator.rb
- app/models/spree/calculator/default_tax_decorator.rb
- app/models/spree/calculator/flexi_rate_decorator.rb
- app/models/spree/line_item_decorator.rb
@@ -453,7 +450,6 @@ Metrics/AbcSize:
- app/models/spree/product_set.rb
- app/models/spree/taxon_decorator.rb
- app/serializers/api/admin/enterprise_serializer.rb
- - app/serializers/api/enterprise_serializer.rb
- app/serializers/api/product_serializer.rb
- app/serializers/api/variant_serializer.rb
- app/services/cart_service.rb
@@ -474,7 +470,6 @@ Metrics/AbcSize:
- lib/open_food_network/orders_and_fulfillments_report.rb
- lib/open_food_network/packing_report.rb
- lib/open_food_network/payments_report.rb
- - lib/open_food_network/permissions.rb
- lib/open_food_network/products_and_inventory_report.rb
- lib/open_food_network/reports/line_items.rb
- lib/open_food_network/sales_tax_report.rb
@@ -485,9 +480,11 @@ Metrics/AbcSize:
- lib/spree/localized_number.rb
- lib/stripe/account_connector.rb
- lib/tasks/enterprises.rake
- - spec/archive/features/consumer/checkout_spec.rb
- - spec/controllers/spree/admin/orders_controller_spec.rb
+ - lib/tasks/sample_data/product_factory.rb
+ - spec/controllers/spree/api/shipments_controller_spec.rb
+ - spec/features/admin/product_import_spec.rb
- spec/features/admin/reports_spec.rb
+ - spec/features/admin/subscriptions_spec.rb
- spec/features/consumer/shopping/checkout_spec.rb
- spec/features/consumer/shopping/variant_overrides_spec.rb
- spec/models/enterprise_spec.rb
@@ -498,9 +495,8 @@ Metrics/CyclomaticComplexity:
Max: 6
Exclude:
- app/controllers/admin/enterprise_fees_controller.rb
- - app/controllers/admin/enterprises_controller.rb
- app/controllers/checkout_controller.rb
- - app/controllers/spree/admin/orders_controller_decorator.rb
+ - app/controllers/spree/admin/payments_controller_decorator.rb
- app/controllers/spree/orders_controller_decorator.rb
- app/helpers/checkout_helper.rb
- app/helpers/i18n_helper.rb
@@ -511,7 +507,6 @@ Metrics/CyclomaticComplexity:
- app/models/product_import/entry_processor.rb
- app/models/product_import/entry_validator.rb
- app/models/spree/ability_decorator.rb
- - app/models/spree/adjustment_decorator.rb
- app/models/spree/payment_decorator.rb
- app/models/spree/product_decorator.rb
- app/models/spree/product_set.rb
@@ -529,9 +524,8 @@ Metrics/CyclomaticComplexity:
Metrics/PerceivedComplexity:
Max: 7
Exclude:
- - app/controllers/admin/enterprises_controller.rb
- app/controllers/checkout_controller.rb
- - app/controllers/spree/admin/orders_controller_decorator.rb
+ - app/controllers/spree/admin/payments_controller_decorator.rb
- app/controllers/spree/orders_controller_decorator.rb
- app/helpers/checkout_helper.rb
- app/helpers/i18n_helper.rb
@@ -541,7 +535,6 @@ Metrics/PerceivedComplexity:
- app/models/product_import/entry_processor.rb
- app/models/product_import/entry_validator.rb
- app/models/spree/ability_decorator.rb
- - app/models/spree/line_item_decorator.rb
- app/models/spree/order_decorator.rb
- app/models/spree/product_decorator.rb
- app/models/spree/product_set.rb
@@ -559,7 +552,6 @@ Metrics/MethodLength:
Exclude:
- app/controllers/admin/customers_controller.rb
- app/controllers/admin/enterprise_fees_controller.rb
- - app/controllers/admin/enterprises_controller.rb
- app/controllers/admin/manager_invitations_controller.rb
- app/controllers/admin/order_cycles_controller.rb
- app/controllers/admin/stripe_accounts_controller.rb
@@ -568,14 +560,11 @@ Metrics/MethodLength:
- app/controllers/cart_controller.rb
- app/controllers/checkout_controller.rb
- app/controllers/shop_controller.rb
- - app/controllers/spree/admin/line_items_controller_decorator.rb
- - app/controllers/spree/admin/orders_controller_decorator.rb
- - app/controllers/spree/admin/payment_methods_controller_decorator.rb
+ - app/controllers/spree/admin/orders/customer_details_controller_decorator.rb
- app/controllers/spree/admin/payments_controller_decorator.rb
- app/controllers/spree/admin/products_controller_decorator.rb
- app/controllers/spree/admin/reports_controller_decorator.rb
- app/controllers/spree/admin/search_controller_decorator.rb
- - app/controllers/spree/admin/shipping_methods_controller_decorator.rb
- app/controllers/spree/credit_cards_controller.rb
- app/controllers/spree/orders_controller_decorator.rb
- app/controllers/spree/user_sessions_controller_decorator.rb
@@ -597,24 +586,23 @@ Metrics/MethodLength:
- app/models/product_import/entry_validator.rb
- app/models/product_import/product_importer.rb
- app/models/spree/ability_decorator.rb
- - app/models/spree/adjustment_decorator.rb
- app/models/spree/calculator/default_tax_decorator.rb
- app/models/spree/calculator/flexi_rate_decorator.rb
- - app/models/spree/line_item_decorator.rb
- app/models/spree/order_decorator.rb
- app/models/spree/payment_decorator.rb
- app/models/spree/payment_method_decorator.rb
+ - app/models/spree/product_decorator.rb
- app/models/spree/product_set.rb
- - app/models/spree/taxon_decorator.rb
- app/serializers/api/admin/order_cycle_serializer.rb
- - app/services/cart_service.rb
+ - app/serializers/api/cached_enterprise_serializer.rb
- app/services/order_cycle_form.rb
+ - engines/order_management/app/services/order_management/reports/enterprise_fee_summary/scope.rb
- lib/discourse/single_sign_on.rb
- lib/open_food_network/bulk_coop_report.rb
- - lib/open_food_network/cached_products_renderer.rb
- lib/open_food_network/column_preference_defaults.rb
- lib/open_food_network/customers_report.rb
- lib/open_food_network/enterprise_fee_calculator.rb
+ - lib/open_food_network/enterprise_issue_validator.rb
- lib/open_food_network/group_buy_report.rb
- lib/open_food_network/lettuce_share_report.rb
- lib/open_food_network/option_value_namer.rb
@@ -639,7 +627,7 @@ Metrics/MethodLength:
- lib/spree/core/controller_helpers/respond_with_decorator.rb
- lib/spree/localized_number.rb
- lib/stripe/profile_storer.rb
- - spec/archive/features/consumer/checkout_spec.rb
+ - lib/tasks/sample_data/product_factory.rb
- spec/features/consumer/shopping/checkout_spec.rb
- spec/features/consumer/shopping/variant_overrides_spec.rb
- spec/models/product_importer_spec.rb
@@ -648,7 +636,6 @@ Metrics/MethodLength:
Metrics/ClassLength:
Max: 100
Exclude:
- - app/controllers/admin/enterprises_controller.rb
- app/controllers/admin/order_cycles_controller.rb
- app/controllers/admin/subscriptions_controller.rb
- app/controllers/checkout_controller.rb
@@ -658,8 +645,10 @@ Metrics/ClassLength:
- app/models/product_import/entry_validator.rb
- app/models/product_import/product_importer.rb
- app/models/spree/ability_decorator.rb
- - app/serializers/api/enterprise_serializer.rb
+ - app/serializers/api/cached_enterprise_serializer.rb
+ - app/serializers/api/enterprise_shopfront_serializer.rb
- app/services/cart_service.rb
+ - engines/order_management/app/services/order_management/reports/enterprise_fee_summary/scope.rb
- lib/open_food_network/bulk_coop_report.rb
- lib/open_food_network/enterprise_fee_calculator.rb
- lib/open_food_network/order_cycle_form_applicator.rb
@@ -682,6 +671,7 @@ Metrics/ModuleLength:
- spec/controllers/api/orders_controller_spec.rb
- spec/controllers/spree/api/products_controller_spec.rb
- spec/lib/open_food_network/address_finder_spec.rb
+ - spec/lib/open_food_network/cached_products_renderer_spec.rb
- spec/lib/open_food_network/customers_report_spec.rb
- spec/lib/open_food_network/enterprise_fee_calculator_spec.rb
- spec/lib/open_food_network/option_value_namer_spec.rb
@@ -712,8 +702,3 @@ Metrics/ParameterLists:
- app/models/product_import/entry_validator.rb
- lib/open_food_network/xero_invoices_report.rb
- spec/features/admin/reports_spec.rb
-
-Metrics/BlockNesting:
- Max: 3
- Exclude:
- - app/controllers/checkout_controller.rb
diff --git a/.rubocop_styleguide.yml b/.rubocop_styleguide.yml
index accf9e6314..13214b0aed 100644
--- a/.rubocop_styleguide.yml
+++ b/.rubocop_styleguide.yml
@@ -194,8 +194,6 @@ Metrics/BlockNesting:
Metrics/ClassLength:
Max: 100
- Exclude:
- - engines/order_management/app/services/order_management/reports/enterprise_fee_summary/scope.rb
Metrics/ModuleLength:
Max: 100
@@ -205,8 +203,6 @@ Metrics/CyclomaticComplexity:
Metrics/MethodLength:
Max: 10
- Exclude:
- - engines/order_management/app/services/order_management/reports/enterprise_fee_summary/scope.rb
Metrics/ParameterLists:
Max: 5
diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml
index 0d335fa70b..df97c2b8fe 100644
--- a/.rubocop_todo.yml
+++ b/.rubocop_todo.yml
@@ -1,323 +1,20 @@
# This configuration was generated by
# `rubocop --auto-gen-config --exclude-limit 1400`
-# on 2019-01-02 13:44:41 +0100 using RuboCop version 0.57.2.
+# on 2019-05-23 21:20:00 +0100 using RuboCop version 0.57.2.
# 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: 32
-# Cop supports --auto-correct.
-# Configuration parameters: Include, TreatCommentsAsGroupSeparators.
-# Include: **/*.gemfile, **/Gemfile, **/gems.rb
-Bundler/OrderedGems:
- Exclude:
- - 'Gemfile'
-
-# Offense count: 115
-# Cop supports --auto-correct.
-Layout/AlignArray:
- Exclude:
- - 'lib/open_food_network/bulk_coop_report.rb'
- - 'lib/open_food_network/customers_report.rb'
- - 'lib/open_food_network/orders_and_fulfillments_report.rb'
- - 'lib/open_food_network/packing_report.rb'
- - 'spec/lib/open_food_network/order_grouper_spec.rb'
-
-# Offense count: 122
-# Cop supports --auto-correct.
-# Configuration parameters: EnforcedHashRocketStyle, EnforcedColonStyle, EnforcedLastArgumentHashStyle.
-# SupportedHashRocketStyles: key, separator, table
-# SupportedColonStyles: key, separator, table
-# SupportedLastArgumentHashStyles: always_inspect, always_ignore, ignore_implicit, ignore_explicit
-Layout/AlignHash:
- Exclude:
- - 'app/overrides/replace_shipping_address_form_with_distributor_details.rb'
- - 'lib/open_food_network/bulk_coop_report.rb'
- - 'lib/open_food_network/orders_and_fulfillments_report.rb'
- - 'lib/open_food_network/packing_report.rb'
- - 'lib/open_food_network/payments_report.rb'
- - 'spec/archive/features/consumer/checkout_spec.rb'
- - 'spec/features/admin/bulk_product_update_spec.rb'
- - 'spec/features/admin/order_cycles_spec.rb'
- - 'spec/features/admin/products_spec.rb'
- - 'spec/features/admin/variant_overrides_spec.rb'
- - 'spec/features/consumer/shopping/cart_spec.rb'
- - 'spec/lib/open_food_network/customers_report_spec.rb'
- - 'spec/lib/open_food_network/enterprise_fee_calculator_spec.rb'
- - 'spec/lib/open_food_network/permissions_spec.rb'
- - 'spec/lib/open_food_network/products_and_inventory_report_spec.rb'
- - 'spec/lib/open_food_network/user_balance_calculator_spec.rb'
- - 'spec/models/enterprise_relationship_spec.rb'
- - 'spec/models/exchange_spec.rb'
- - 'spec/models/order_cycle_spec.rb'
- - 'spec/models/spree/shipping_method_spec.rb'
- - 'spec/models/spree/variant_spec.rb'
- - 'spec/models/variant_override_spec.rb'
-
-# Offense count: 49
-# Cop supports --auto-correct.
-# Configuration parameters: EnforcedStyle, IndentationWidth.
-# SupportedStyles: with_first_parameter, with_fixed_indentation
-Layout/AlignParameters:
- Exclude:
- - 'app/helpers/injection_helper.rb'
- - 'app/models/enterprise.rb'
- - 'app/models/enterprise_group.rb'
- - 'app/models/enterprise_relationship.rb'
- - 'app/serializers/api/address_serializer.rb'
- - 'app/serializers/api/shipping_method_serializer.rb'
- - 'lib/spree/product_filters.rb'
- - 'spec/controllers/enterprises_controller_spec.rb'
- - 'spec/controllers/shop_controller_spec.rb'
- - 'spec/features/admin/enterprise_fees_spec.rb'
- - 'spec/features/admin/enterprise_relationships_spec.rb'
- - 'spec/features/admin/order_cycles_spec.rb'
- - 'spec/features/consumer/shopping/checkout_spec.rb'
- - 'spec/features/consumer/shopping/orders_spec.rb'
- - 'spec/helpers/enterprises_helper_spec.rb'
- - 'spec/lib/open_food_network/user_balance_calculator_spec.rb'
- - 'spec/serializers/variant_serializer_spec.rb'
- - 'spec/support/request/authentication_workflow.rb'
-
-# Offense count: 5
-# Cop supports --auto-correct.
-# Configuration parameters: EnforcedStyleAlignWith.
-# SupportedStylesAlignWith: either, start_of_block, start_of_line
-Layout/BlockAlignment:
- Exclude:
- - 'spec/lib/open_food_network/enterprise_fee_calculator_spec.rb'
- - 'spec/models/enterprise_spec.rb'
- - 'spec/models/spree/line_item_spec.rb'
- - 'spec/models/spree/product_spec.rb'
-
-# Offense count: 2
-# Cop supports --auto-correct.
-Layout/BlockEndNewline:
- Exclude:
- - 'spec/features/consumer/shopping/cart_spec.rb'
- - 'spec/models/variant_override_spec.rb'
-
# Offense count: 1
# Cop supports --auto-correct.
-Layout/ClosingHeredocIndentation:
+# Configuration parameters: EnforcedStyleAlignWith, AutoCorrect, Severity.
+# SupportedStylesAlignWith: start_of_line, def
+Layout/DefEndAlignment:
Exclude:
- - 'app/models/content_configuration.rb'
+ - 'app/models/order_updater.rb'
-# Offense count: 2
-# Cop supports --auto-correct.
-Layout/ClosingParenthesisIndentation:
- Exclude:
- - 'spec/controllers/spree/admin/orders/customer_details_controller_spec.rb'
- - 'spec/serializers/variant_serializer_spec.rb'
-
-# Offense count: 8
-# Cop supports --auto-correct.
-Layout/ElseAlignment:
- Exclude:
- - 'app/controllers/admin/order_cycles_controller.rb'
- - 'app/controllers/api/order_cycles_controller.rb'
- - 'app/serializers/api/admin/for_order_cycle/enterprise_serializer.rb'
- - 'app/serializers/api/admin/for_order_cycle/supplied_product_serializer.rb'
- - 'app/serializers/api/admin/order_cycle_serializer.rb'
- - 'lib/open_food_network/sales_tax_report.rb'
-
-# Offense count: 187
-# Cop supports --auto-correct.
-Layout/EmptyLines:
- Exclude:
- - 'app/controllers/admin/enterprise_fees_controller.rb'
- - 'app/controllers/admin/order_cycles_controller.rb'
- - 'app/controllers/admin/producer_properties_controller.rb'
- - 'app/controllers/admin/tag_rules_controller.rb'
- - 'app/controllers/admin/variant_overrides_controller.rb'
- - 'app/controllers/api/statuses_controller.rb'
- - 'app/controllers/spree/admin/adjustments_controller_decorator.rb'
- - 'app/controllers/spree/admin/base_controller_decorator.rb'
- - 'app/controllers/spree/admin/general_settings_controller_decorator.rb'
- - 'app/controllers/spree/admin/payments_controller_decorator.rb'
- - 'app/controllers/spree/admin/products_controller_decorator.rb'
- - 'app/controllers/spree/admin/variants_controller_decorator.rb'
- - 'app/controllers/spree/orders_controller_decorator.rb'
- - 'app/helpers/angular_form_helper.rb'
- - 'app/helpers/injection_helper.rb'
- - 'app/helpers/spree/admin/base_helper_decorator.rb'
- - 'app/jobs/products_cache_integrity_checker_job.rb'
- - 'app/jobs/refresh_products_cache_job.rb'
- - 'app/models/coordinator_fee.rb'
- - 'app/models/enterprise_fee.rb'
- - 'app/models/exchange.rb'
- - 'app/models/exchange_fee.rb'
- - 'app/models/inventory_item.rb'
- - 'app/models/producer_property.rb'
- - 'app/models/spree/classification_decorator.rb'
- - 'app/models/spree/gateway/migs.rb'
- - 'app/models/spree/gateway/pin.rb'
- - 'app/models/spree/image_decorator.rb'
- - 'app/models/spree/line_item_decorator.rb'
- - 'app/models/spree/option_type_decorator.rb'
- - 'app/models/spree/option_value_decorator.rb'
- - 'app/models/spree/payment_decorator.rb'
- - 'app/models/spree/preference_decorator.rb'
- - 'app/models/spree/preferences/file_configuration.rb'
- - 'app/models/spree/price_decorator.rb'
- - 'app/models/spree/product_decorator.rb'
- - 'app/models/spree/product_property_decorator.rb'
- - 'app/models/spree/property_decorator.rb'
- - 'app/models/spree/shipping_method_decorator.rb'
- - 'app/models/spree/tax_rate_decorator.rb'
- - 'app/models/spree/taxon_decorator.rb'
- - 'lib/open_food_network/cached_products_renderer.rb'
- - 'lib/open_food_network/enterprise_fee_applicator.rb'
- - 'lib/open_food_network/enterprise_issue_validator.rb'
- - 'lib/open_food_network/integrity_checker.rb'
- - 'lib/open_food_network/lettuce_share_report.rb'
- - 'lib/open_food_network/option_value_namer.rb'
- - 'lib/open_food_network/order_cycle_form_applicator.rb'
- - 'lib/open_food_network/order_cycle_permissions.rb'
- - 'lib/open_food_network/products_cache.rb'
- - 'lib/open_food_network/products_cache_integrity_checker.rb'
- - 'lib/open_food_network/products_renderer.rb'
- - 'lib/open_food_network/reports/bulk_coop_report.rb'
- - 'lib/open_food_network/sales_tax_report.rb'
- - 'lib/open_food_network/scope_product_to_hub.rb'
- - 'lib/open_food_network/xero_invoices_report.rb'
- - 'lib/spree/core/controller_helpers/order_decorator.rb'
- - 'lib/tasks/cache.rake'
- - 'lib/tasks/enterprises.rake'
- - 'spec/archive/features/consumer/checkout_spec.rb'
- - 'spec/controllers/admin/column_preferences_controller_spec.rb'
- - 'spec/controllers/admin/enterprises_controller_spec.rb'
- - 'spec/controllers/admin/order_cycles_controller_spec.rb'
- - 'spec/controllers/admin/subscription_line_items_controller_spec.rb'
- - 'spec/controllers/enterprises_controller_spec.rb'
- - 'spec/controllers/shop_controller_spec.rb'
- - 'spec/controllers/spree/admin/payments_controller_spec.rb'
- - 'spec/controllers/spree/api/products_controller_spec.rb'
- - 'spec/controllers/spree/checkout_controller_spec.rb'
- - 'spec/controllers/spree/orders_controller_spec.rb'
- - 'spec/features/admin/bulk_product_update_spec.rb'
- - 'spec/features/admin/enterprise_relationships_spec.rb'
- - 'spec/features/admin/enterprise_roles_spec.rb'
- - 'spec/features/admin/enterprises/index_spec.rb'
- - 'spec/features/admin/enterprises_spec.rb'
- - 'spec/features/admin/order_cycles_spec.rb'
- - 'spec/features/admin/orders_spec.rb'
- - 'spec/features/admin/product_import_spec.rb'
- - 'spec/features/admin/products_spec.rb'
- - 'spec/features/admin/reports_spec.rb'
- - 'spec/features/admin/shipping_methods_spec.rb'
- - 'spec/features/admin/variant_overrides_spec.rb'
- - 'spec/features/admin/variants_spec.rb'
- - 'spec/features/consumer/producers_spec.rb'
- - 'spec/features/consumer/registration_spec.rb'
- - 'spec/features/consumer/shopping/variant_overrides_spec.rb'
- - 'spec/features/consumer/shops_spec.rb'
- - 'spec/helpers/checkout_helper_spec.rb'
- - 'spec/jobs/heartbeat_job_spec.rb'
- - 'spec/lib/open_food_network/enterprise_fee_calculator_spec.rb'
- - 'spec/lib/open_food_network/option_value_namer_spec.rb'
- - 'spec/lib/open_food_network/order_cycle_form_applicator_spec.rb'
- - 'spec/lib/open_food_network/order_cycle_management_report_spec.rb'
- - 'spec/lib/open_food_network/order_cycle_permissions_spec.rb'
- - 'spec/lib/open_food_network/products_cache_spec.rb'
- - 'spec/lib/open_food_network/reports/report_spec.rb'
- - 'spec/lib/open_food_network/tag_rule_applicator_spec.rb'
- - 'spec/mailers/producer_mailer_spec.rb'
- - 'spec/models/enterprise_fee_spec.rb'
- - 'spec/models/enterprise_spec.rb'
- - 'spec/models/model_set_spec.rb'
- - 'spec/models/spree/adjustment_spec.rb'
- - 'spec/models/spree/line_item_spec.rb'
- - 'spec/models/spree/order_spec.rb'
- - 'spec/models/spree/product_spec.rb'
- - 'spec/models/spree/shipping_method_spec.rb'
- - 'spec/models/spree/variant_spec.rb'
- - 'spec/serializers/admin/exchange_serializer_spec.rb'
- - 'spec/serializers/admin/for_order_cycle/enterprise_serializer_spec.rb'
- - 'spec/serializers/admin/for_order_cycle/supplied_product_serializer_spec.rb'
- - 'spec/serializers/credit_card_serializer_spec.rb'
- - 'spec/support/delayed_job_helper.rb'
- - 'spec/support/matchers/table_matchers.rb'
-
-# Offense count: 1
-# Cop supports --auto-correct.
-Layout/EmptyLinesAroundArguments:
- Exclude:
- - 'spec/archive/features/consumer/checkout_spec.rb'
-
-# Offense count: 51
-# Cop supports --auto-correct.
-# Configuration parameters: EnforcedStyle.
-# SupportedStyles: empty_lines, no_empty_lines
-Layout/EmptyLinesAroundBlockBody:
- Exclude:
- - 'app/controllers/spree/api/orders_controller_decorator.rb'
- - 'app/controllers/spree/checkout_controller_decorator.rb'
- - 'app/models/spree/calculator/default_tax_decorator.rb'
- - 'app/models/spree/money_decorator.rb'
- - 'app/models/spree/option_value_decorator.rb'
- - 'lib/open_food_network/group_buy_report.rb'
- - 'lib/spree/money_decorator.rb'
- - 'spec/controllers/admin/order_cycles_controller_spec.rb'
- - 'spec/controllers/admin/tag_rules_controller_spec.rb'
- - 'spec/controllers/spree/admin/reports_controller_spec.rb'
- - 'spec/controllers/spree/api/orders_controller_spec.rb'
- - 'spec/controllers/spree/orders_controller_spec.rb'
- - 'spec/controllers/user_confirmations_controller_spec.rb'
- - 'spec/features/admin/caching_spec.rb'
- - 'spec/features/admin/orders_spec.rb'
- - 'spec/features/admin/reports_spec.rb'
- - 'spec/features/consumer/cookies_spec.rb'
- - 'spec/features/consumer/shopping/embedded_groups_spec.rb'
- - 'spec/features/consumer/shopping/embedded_shopfronts_spec.rb'
- - 'spec/features/consumer/shopping/shopping_spec.rb'
- - 'spec/helpers/shared_helper_spec.rb'
- - 'spec/helpers/shop_helper_spec.rb'
- - 'spec/helpers/spree/orders_helper_spec.rb'
- - 'spec/lib/open_food_network/group_buy_report_spec.rb'
- - 'spec/lib/open_food_network/lettuce_share_report_spec.rb'
- - 'spec/lib/open_food_network/order_grouper_spec.rb'
- - 'spec/lib/open_food_network/referer_parser_spec.rb'
- - 'spec/lib/open_food_network/user_balance_calculator_spec.rb'
- - 'spec/models/spree/ability_spec.rb'
- - 'spec/models/spree/product_spec.rb'
- - 'spec/models/tag_rule/filter_payment_methods_spec.rb'
- - 'spec/models/tag_rule/filter_products_spec.rb'
- - 'spec/models/tag_rule/filter_shipping_methods_spec.rb'
- - 'spec/serializers/admin/for_order_cycle/enterprise_serializer_spec.rb'
- - 'spec/serializers/admin/for_order_cycle/supplied_product_serializer_spec.rb'
- - 'spec/support/matchers/delegate_matchers.rb'
- - 'spec/support/matchers/select2_matchers.rb'
- - 'spec/support/matchers/table_matchers.rb'
-
-# Offense count: 23
-# Cop supports --auto-correct.
-# Configuration parameters: EnforcedStyle.
-# SupportedStyles: empty_lines, empty_lines_except_namespace, empty_lines_special, no_empty_lines, beginning_only, ending_only
-Layout/EmptyLinesAroundClassBody:
- Exclude:
- - 'app/controllers/admin/enterprise_fees_controller.rb'
- - 'app/controllers/admin/inventory_items_controller.rb'
- - 'app/controllers/admin/tag_rules_controller.rb'
- - 'app/controllers/api/enterprises_controller.rb'
- - 'app/controllers/application_controller.rb'
- - 'app/controllers/home_controller.rb'
- - 'app/models/coordinator_fee.rb'
- - 'app/models/producer_property.rb'
- - 'app/models/spree/preferences/file_configuration.rb'
- - 'app/serializers/api/admin/enterprise_fee_serializer.rb'
- - 'app/serializers/api/admin/index_enterprise_serializer.rb'
- - 'app/serializers/api/currency_config_serializer.rb'
- - 'app/serializers/api/product_serializer.rb'
- - 'lib/discourse/single_sign_on.rb'
- - 'app/services/order_cycle_distributed_variants.rb'
- - 'lib/open_food_network/lettuce_share_report.rb'
- - 'lib/open_food_network/order_and_distributor_report.rb'
- - 'lib/open_food_network/rack_request_blocker.rb'
- - 'lib/open_food_network/reports/bulk_coop_report.rb'
-
-# Offense count: 5
+# Offense count: 4
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyleAlignWith, AutoCorrect, Severity.
# SupportedStylesAlignWith: keyword, variable, start_of_line
@@ -325,557 +22,14 @@ Layout/EndAlignment:
Exclude:
- 'app/controllers/admin/order_cycles_controller.rb'
- 'app/controllers/api/order_cycles_controller.rb'
- - 'app/serializers/api/admin/for_order_cycle/enterprise_serializer.rb'
- 'app/serializers/api/admin/for_order_cycle/supplied_product_serializer.rb'
- 'app/serializers/api/admin/order_cycle_serializer.rb'
-# Offense count: 45
-# Cop supports --auto-correct.
-# Configuration parameters: AllowForAlignment, ForceEqualSignAlignment.
-Layout/ExtraSpacing:
- Exclude:
- - 'app/controllers/admin/enterprises_controller.rb'
- - 'app/controllers/checkout_controller.rb'
- - 'app/helpers/admin/injection_helper.rb'
- - 'app/models/enterprise.rb'
- - 'app/models/spree/classification_decorator.rb'
- - 'config.ru'
- - 'lib/open_food_network/bulk_coop_report.rb'
- - 'lib/open_food_network/option_value_namer.rb'
- - 'lib/open_food_network/paperclippable.rb'
- - 'lib/open_food_network/variant_and_line_item_naming.rb'
- - 'lib/spree/product_filters.rb'
- - 'lib/tasks/karma.rake'
- - 'spec/features/admin/bulk_order_management_spec.rb'
- - 'spec/features/admin/bulk_product_update_spec.rb'
- - 'spec/features/admin/orders_spec.rb'
- - 'spec/features/admin/reports_spec.rb'
- - 'spec/features/consumer/groups_spec.rb'
- - 'spec/features/consumer/shopping/shopping_spec.rb'
- - 'spec/lib/open_food_network/enterprise_fee_calculator_spec.rb'
- - 'spec/lib/open_food_network/reports/rule_spec.rb'
- - 'spec/models/enterprise_fee_spec.rb'
- - 'spec/models/enterprise_spec.rb'
- - 'spec/models/order_cycle_spec.rb'
- - 'spec/models/spree/adjustment_spec.rb'
- - 'spec/models/spree/gateway/stripe_connect_spec.rb'
- - 'spec/models/spree/order_spec.rb'
- - 'spec/serializers/admin/for_order_cycle/enterprise_serializer_spec.rb'
- - 'spec/serializers/admin/for_order_cycle/supplied_product_serializer_spec.rb'
- - 'spec/spec_helper.rb'
- - 'spec/support/request/web_helper.rb'
-
-# Offense count: 1
-# Cop supports --auto-correct.
-# Configuration parameters: EnforcedStyle, IndentationWidth.
-# SupportedStyles: consistent, consistent_relative_to_receiver, special_for_inner_method_call, special_for_inner_method_call_in_parentheses
-Layout/FirstParameterIndentation:
- Exclude:
- - 'spec/controllers/spree/admin/orders/customer_details_controller_spec.rb'
-
-# Offense count: 6
-# Cop supports --auto-correct.
-# Configuration parameters: IndentationWidth.
-# SupportedStyles: special_inside_parentheses, consistent, align_brackets
-Layout/IndentArray:
- EnforcedStyle: consistent
-
-# Offense count: 53
-# Cop supports --auto-correct.
-# Configuration parameters: IndentationWidth.
-# SupportedStyles: special_inside_parentheses, consistent, align_braces
-Layout/IndentHash:
- EnforcedStyle: consistent
-
-# Offense count: 19
-# Cop supports --auto-correct.
-# Configuration parameters: EnforcedStyle.
-# SupportedStyles: normal, rails
-Layout/IndentationConsistency:
- Exclude:
- - 'lib/open_food_network/permissions.rb'
- - 'spec/controllers/admin/tag_rules_controller_spec.rb'
- - 'spec/features/consumer/shopping/checkout_spec.rb'
- - 'spec/models/spree/line_item_spec.rb'
- - 'spec/models/spree/product_spec.rb'
-
-# Offense count: 19
-# Cop supports --auto-correct.
-# Configuration parameters: Width, IgnoredPatterns.
-Layout/IndentationWidth:
- Exclude:
- - 'app/controllers/admin/order_cycles_controller.rb'
- - 'app/controllers/api/order_cycles_controller.rb'
- - 'app/models/spree/line_item_decorator.rb'
- - 'app/serializers/api/admin/for_order_cycle/enterprise_serializer.rb'
- - 'app/serializers/api/admin/for_order_cycle/supplied_product_serializer.rb'
- - 'app/serializers/api/admin/order_cycle_serializer.rb'
- - 'spec/features/consumer/shopping/variant_overrides_spec.rb'
- - 'spec/helpers/groups_helper_spec.rb'
- - 'spec/lib/open_food_network/enterprise_fee_calculator_spec.rb'
- - 'spec/lib/open_food_network/order_grouper_spec.rb'
- - 'spec/lib/spree/product_filters_spec.rb'
- - 'spec/mailers/enterprise_mailer_spec.rb'
- - 'spec/models/enterprise_spec.rb'
- - 'spec/models/spree/calculator/flexi_rate_spec.rb'
-
-# Offense count: 43
-# Cop supports --auto-correct.
-Layout/LeadingCommentSpace:
- Exclude:
- - 'Gemfile'
- - 'app/models/content_configuration.rb'
- - 'app/models/spree/inventory_unit_decorator.rb'
- - 'app/models/spree/taxon_decorator.rb'
- - 'app/serializers/api/address_serializer.rb'
- - 'app/serializers/api/product_serializer.rb'
- - 'spec/archive/features/consumer/checkout_spec.rb'
- - 'spec/controllers/spree/api/line_items_controller_spec.rb'
- - 'spec/features/admin/products_spec.rb'
- - 'spec/features/admin/reports_spec.rb'
- - 'spec/lib/open_food_network/order_grouper_spec.rb'
- - 'spec/lib/open_food_network/user_balance_calculator_spec.rb'
- - 'spec/models/enterprise_spec.rb'
- - 'spec/models/spree/order_spec.rb'
- - 'spec/spec_helper.rb'
- - 'spec/support/cancan_helper.rb'
- - 'spec/support/matchers/select2_matchers.rb'
- - 'spec/support/request/authentication_workflow.rb'
-
-# Offense count: 45
-# Cop supports --auto-correct.
-Layout/MultilineBlockLayout:
- Exclude:
- - 'app/models/spree/calculator/default_tax_decorator.rb'
- - 'app/models/spree/product_decorator.rb'
- - 'spec/controllers/admin/column_preferences_controller_spec.rb'
- - 'spec/controllers/shop_controller_spec.rb'
- - 'spec/controllers/spree/orders_controller_spec.rb'
- - 'spec/features/admin/variant_overrides_spec.rb'
- - 'spec/features/consumer/shopping/cart_spec.rb'
- - 'spec/helpers/enterprises_helper_spec.rb'
- - 'spec/lib/open_food_network/enterprise_fee_calculator_spec.rb'
- - 'spec/lib/open_food_network/permissions_spec.rb'
- - 'spec/lib/open_food_network/user_balance_calculator_spec.rb'
- - 'spec/models/column_preference_spec.rb'
- - 'spec/models/order_cycle_spec.rb'
- - 'spec/models/spree/product_spec.rb'
- - 'spec/models/spree/variant_spec.rb'
- - 'spec/models/variant_override_spec.rb'
- - 'spec/serializers/enterprise_serializer_spec.rb'
-
# Offense count: 4
-# Cop supports --auto-correct.
-# Configuration parameters: EnforcedStyle.
-# SupportedStyles: symmetrical, new_line, same_line
-Layout/MultilineHashBraceLayout:
- Exclude:
- - 'app/controllers/spree/admin/products_controller_decorator.rb'
- - 'lib/spree/product_filters.rb'
- - 'spec/support/request/authentication_workflow.rb'
-
-# Offense count: 6
-# Cop supports --auto-correct.
-# Configuration parameters: EnforcedStyle.
-# SupportedStyles: symmetrical, new_line, same_line
-Layout/MultilineMethodCallBraceLayout:
- Exclude:
- - 'app/helpers/spree/orders_helper.rb'
- - 'app/models/spree/variant_decorator.rb'
- - 'lib/open_food_network/products_renderer.rb'
- - 'spec/features/admin/order_cycles_spec.rb'
- - 'spec/features/consumer/shopping/orders_spec.rb'
- - 'spec/lib/open_food_network/products_and_inventory_report_spec.rb'
-
-# Offense count: 4
-# Cop supports --auto-correct.
-# Configuration parameters: EnforcedStyle, IndentationWidth.
-# SupportedStyles: aligned, indented, indented_relative_to_receiver
-Layout/MultilineMethodCallIndentation:
- Exclude:
- - 'spec/lib/open_food_network/cached_products_renderer_spec.rb'
- - 'spec/serializers/variant_serializer_spec.rb'
-
-# Offense count: 26
-# Cop supports --auto-correct.
-# Configuration parameters: EnforcedStyle, IndentationWidth.
-# SupportedStyles: aligned, indented
-Layout/MultilineOperationIndentation:
- Exclude:
- - 'app/controllers/application_controller.rb'
- - 'app/controllers/spree/admin/payment_methods_controller_decorator.rb'
- - 'app/controllers/spree/admin/shipping_methods_controller_decorator.rb'
- - 'app/helpers/enterprises_helper.rb'
- - 'app/models/producer_property.rb'
- - 'app/models/spree/ability_decorator.rb'
- - 'app/models/variant_override_set.rb'
- - 'lib/open_food_network/order_cycle_permissions.rb'
- - 'lib/open_food_network/sales_tax_report.rb'
- - 'lib/open_food_network/users_and_enterprises_report.rb'
-
-# Offense count: 7
-# Cop supports --auto-correct.
-Layout/SpaceAfterColon:
- Exclude:
- - 'spec/features/admin/variants_spec.rb'
- - 'spec/features/consumer/account_spec.rb'
- - 'spec/models/spree/ability_spec.rb'
- - 'spec/spec_helper.rb'
-
-# Offense count: 83
-# Cop supports --auto-correct.
-Layout/SpaceAfterComma:
- Exclude:
- - 'app/controllers/admin/order_cycles_controller.rb'
- - 'app/controllers/spree/admin/products_controller_decorator.rb'
- - 'app/controllers/spree/orders_controller_decorator.rb'
- - 'app/models/column_preference.rb'
- - 'lib/discourse/single_sign_on.rb'
- - 'lib/open_food_network/order_cycle_form_applicator.rb'
- - 'lib/open_food_network/users_and_enterprises_report.rb'
- - 'spec/controllers/admin/enterprises_controller_spec.rb'
- - 'spec/controllers/admin/variant_overrides_controller_spec.rb'
- - 'spec/features/admin/bulk_order_management_spec.rb'
- - 'spec/features/admin/bulk_product_update_spec.rb'
- - 'spec/features/admin/customers_spec.rb'
- - 'spec/features/admin/variant_overrides_spec.rb'
- - 'spec/lib/open_food_network/group_buy_report_spec.rb'
- - 'spec/lib/open_food_network/subscription_summary_spec.rb'
- - 'spec/models/content_configuration_spec.rb'
- - 'spec/models/spree/line_item_spec.rb'
- - 'spec/models/spree/order_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'
- - 'spec/models/tag_rule/filter_shipping_methods_spec.rb'
- - 'spec/spec_helper.rb'
- - 'spec/support/cancan_helper.rb'
-
-# Offense count: 2
-# Cop supports --auto-correct.
-Layout/SpaceAfterSemicolon:
- Exclude:
- - 'spec/controllers/spree/admin/base_controller_spec.rb'
-
-# Offense count: 59
-# Cop supports --auto-correct.
-# Configuration parameters: EnforcedStyle.
-# SupportedStyles: space, no_space
-Layout/SpaceAroundEqualsInParameterDefault:
- Exclude:
- - 'app/controllers/spree/admin/base_controller_decorator.rb'
- - 'app/helpers/admin/injection_helper.rb'
- - 'app/helpers/angular_form_helper.rb'
- - 'app/helpers/checkout_helper.rb'
- - 'app/helpers/order_cycles_helper.rb'
- - 'app/helpers/spree/base_helper_decorator.rb'
- - 'app/models/column_preference_set.rb'
- - 'app/models/enterprise_fee_set.rb'
- - 'app/models/enterprise_relationship.rb'
- - 'app/models/enterprise_set.rb'
- - 'app/models/exchange.rb'
- - 'app/models/model_set.rb'
- - 'app/models/order_cycle_set.rb'
- - 'app/models/spree/calculator/per_item_decorator.rb'
- - 'app/models/spree/payment_decorator.rb'
- - 'app/models/spree/payment_method_decorator.rb'
- - 'app/models/spree/preferences/file_configuration.rb'
- - 'app/models/spree/product_set.rb'
- - 'app/models/spree/taxon_decorator.rb'
- - 'app/models/variant_override_set.rb'
- - 'lib/discourse/single_sign_on.rb'
- - 'lib/open_food_network/enterprise_fee_calculator.rb'
- - 'lib/open_food_network/enterprise_issue_validator.rb'
- - 'lib/open_food_network/order_cycle_form_applicator.rb'
- - 'lib/open_food_network/permissions.rb'
- - 'lib/open_food_network/tag_rule_applicator.rb'
- - 'lib/open_food_network/xero_invoices_report.rb'
- - 'lib/spree/money_decorator.rb'
- - 'spec/features/admin/enterprise_relationships_spec.rb'
- - 'spec/features/admin/reports_spec.rb'
- - 'spec/models/enterprise_spec.rb'
- - 'spec/support/matchers/select2_matchers.rb'
- - 'spec/support/request/distribution_helper.rb'
- - 'spec/support/request/web_helper.rb'
-
-# Offense count: 50
-# Cop supports --auto-correct.
-# Configuration parameters: AllowForAlignment.
-Layout/SpaceAroundOperators:
- Exclude:
- - 'app/controllers/checkout_controller.rb'
- - 'app/overrides/remove_search_bar.rb'
- - 'app/overrides/remove_side_bar.rb'
- - 'app/overrides/replace_shipping_address_form_with_distributor_details.rb'
- - 'lib/open_food_network/xero_invoices_report.rb'
- - 'lib/spree/product_filters.rb'
- - 'spec/controllers/admin/enterprises_controller_spec.rb'
- - 'spec/features/admin/bulk_order_management_spec.rb'
- - 'spec/features/admin/bulk_product_update_spec.rb'
- - 'spec/features/consumer/shopping/checkout_spec.rb'
- - 'spec/helpers/checkout_helper_spec.rb'
- - 'spec/helpers/order_cycles_helper_spec.rb'
- - 'spec/lib/open_food_network/order_grouper_spec.rb'
- - 'spec/lib/stripe/account_connector_spec.rb'
- - 'spec/spec_helper.rb'
- - 'spec/support/cancan_helper.rb'
- - 'spec/support/seeds.rb'
-
-# Offense count: 5
-# Cop supports --auto-correct.
-Layout/SpaceBeforeComma:
- Exclude:
- - 'app/helpers/checkout_helper.rb'
- - 'lib/open_food_network/orders_and_fulfillments_report.rb'
- - 'spec/features/admin/bulk_order_management_spec.rb'
- - 'spec/features/admin/bulk_product_update_spec.rb'
-
-# Offense count: 4
-# Cop supports --auto-correct.
-# Configuration parameters: AllowForAlignment.
-Layout/SpaceBeforeFirstArg:
- Exclude:
- - 'spec/features/admin/bulk_product_update_spec.rb'
- - 'spec/features/consumer/multilingual_spec.rb'
- - 'spec/models/enterprise_fee_spec.rb'
-
-# Offense count: 5
-# Cop supports --auto-correct.
-# Configuration parameters: EnforcedStyle.
-# SupportedStyles: require_no_space, require_space
-Layout/SpaceInLambdaLiteral:
- Exclude:
- - 'app/models/spree/product_decorator.rb'
- - 'app/models/spree/variant_decorator.rb'
-
-# Offense count: 128
-# Cop supports --auto-correct.
-# Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBrackets.
-# SupportedStyles: space, no_space, compact
-# SupportedStylesForEmptyBrackets: space, no_space
-Layout/SpaceInsideArrayLiteralBrackets:
- Exclude:
- - 'app/controllers/admin/order_cycles_controller.rb'
- - 'app/helpers/spree/reports_helper.rb'
- - 'lib/open_food_network/bulk_coop_report.rb'
- - 'lib/open_food_network/orders_and_fulfillments_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'
- - 'spec/controllers/admin/variant_overrides_controller_spec.rb'
- - 'spec/features/admin/reports_spec.rb'
- - 'spec/lib/open_food_network/order_grouper_spec.rb'
- - 'spec/lib/open_food_network/users_and_enterprises_report_spec.rb'
- - 'spec/models/spree/order_spec.rb'
-
-# Offense count: 192
-# Cop supports --auto-correct.
-# Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBraces, SpaceBeforeBlockParameters.
-# SupportedStyles: space, no_space
-# SupportedStylesForEmptyBraces: space, no_space
-Layout/SpaceInsideBlockBraces:
- Exclude:
- - 'app/controllers/spree/admin/payment_methods_controller_decorator.rb'
- - 'app/controllers/spree/admin/payments_controller_decorator.rb'
- - 'app/controllers/spree/admin/variants_controller_decorator.rb'
- - 'app/controllers/spree/orders_controller_decorator.rb'
- - 'app/models/column_preference.rb'
- - 'app/models/spree/order_decorator.rb'
- - 'lib/spree/product_filters.rb'
- - 'lib/tasks/karma.rake'
- - 'spec/archive/features/consumer/checkout_spec.rb'
- - 'spec/controllers/admin/inventory_items_controller_spec.rb'
- - 'spec/controllers/admin/tag_rules_controller_spec.rb'
- - 'spec/controllers/admin/variant_overrides_controller_spec.rb'
- - 'spec/controllers/spree/admin/base_controller_spec.rb'
- - 'spec/controllers/spree/admin/orders_controller_spec.rb'
- - 'spec/controllers/spree/admin/search_controller_spec.rb'
- - 'spec/features/admin/bulk_order_management_spec.rb'
- - 'spec/features/admin/customers_spec.rb'
- - 'spec/features/admin/tag_rules_spec.rb'
- - 'spec/features/consumer/account_spec.rb'
- - 'spec/features/consumer/shopping/products_spec.rb'
- - 'spec/features/consumer/shops_spec.rb'
- - 'spec/helpers/enterprises_helper_spec.rb'
- - 'spec/helpers/injection_helper_spec.rb'
- - 'spec/helpers/spree/orders_helper_spec.rb'
- - 'spec/lib/open_food_network/order_cycle_form_applicator_spec.rb'
- - 'spec/lib/open_food_network/order_grouper_spec.rb'
- - 'spec/lib/open_food_network/products_renderer_spec.rb'
- - 'spec/lib/open_food_network/tag_rule_applicator_spec.rb'
- - 'spec/models/column_preference_spec.rb'
- - 'spec/models/enterprise_relationship_spec.rb'
- - 'spec/models/spree/line_item_spec.rb'
- - 'spec/models/spree/order_spec.rb'
- - 'spec/models/spree/payment_spec.rb'
- - 'spec/models/spree/product_spec.rb'
- - 'spec/models/tag_rule/discount_order_spec.rb'
- - 'spec/serializers/admin/for_order_cycle/enterprise_serializer_spec.rb'
- - 'spec/serializers/admin/for_order_cycle/supplied_product_serializer_spec.rb'
- - 'spec/spec_helper.rb'
- - 'spec/support/cancan_helper.rb'
-
-# Offense count: 702
-# Cop supports --auto-correct.
-# Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBraces.
-# SupportedStyles: space, no_space, compact
-# SupportedStylesForEmptyBraces: space, no_space
-Layout/SpaceInsideHashLiteralBraces:
- Exclude:
- - 'app/controllers/admin/enterprise_relationships_controller.rb'
- - 'app/controllers/admin/enterprise_roles_controller.rb'
- - 'app/controllers/api/statuses_controller.rb'
- - 'app/controllers/checkout_controller.rb'
- - 'app/controllers/spree/admin/line_items_controller_decorator.rb'
- - 'app/controllers/spree/admin/products_controller_decorator.rb'
- - 'app/controllers/spree/admin/search_controller_decorator.rb'
- - 'app/helpers/admin/injection_helper.rb'
- - 'app/helpers/angular_form_builder.rb'
- - 'app/helpers/injection_helper.rb'
- - 'app/helpers/order_cycles_helper.rb'
- - 'app/helpers/serializer_helper.rb'
- - 'app/helpers/spree/admin/base_helper_decorator.rb'
- - 'app/helpers/spree/admin/navigation_helper_decorator.rb'
- - 'app/mailers/spree/base_mailer_decorator.rb'
- - 'app/models/enterprise.rb'
- - 'app/models/enterprise_group.rb'
- - 'app/models/enterprise_relationship.rb'
- - 'app/models/producer_property.rb'
- - 'app/models/spree/gateway/stripe_connect.rb'
- - 'app/models/spree/product_decorator.rb'
- - 'app/models/spree/property_decorator.rb'
- - 'app/models/spree/shipping_method_decorator.rb'
- - 'app/serializers/api/admin/enterprise_fee_serializer.rb'
- - 'app/serializers/api/admin/order_cycle_serializer.rb'
- - 'lib/open_food_network/feature_toggle.rb'
- - 'lib/open_food_network/option_value_namer.rb'
- - 'lib/open_food_network/order_cycle_form_applicator.rb'
- - 'lib/open_food_network/order_cycle_management_report.rb'
- - 'lib/open_food_network/reports/rule.rb'
- - 'lib/open_food_network/sales_tax_report.rb'
- - 'lib/open_food_network/variant_and_line_item_naming.rb'
- - 'lib/open_food_network/xero_invoices_report.rb'
- - 'spec/controllers/admin/enterprises_controller_spec.rb'
- - 'spec/controllers/admin/manager_invitations_controller_spec.rb'
- - 'spec/controllers/admin/order_cycles_controller_spec.rb'
- - 'spec/controllers/admin/subscriptions_controller_spec.rb'
- - 'spec/controllers/api/statuses_controller_spec.rb'
- - 'spec/controllers/checkout_controller_spec.rb'
- - 'spec/controllers/enterprises_controller_spec.rb'
- - 'spec/controllers/shop_controller_spec.rb'
- - 'spec/controllers/spree/admin/adjustments_controller_spec.rb'
- - 'spec/controllers/spree/admin/payments_controller_spec.rb'
- - 'spec/controllers/spree/admin/products_controller_spec.rb'
- - 'spec/controllers/spree/admin/reports_controller_spec.rb'
- - 'spec/controllers/spree/api/products_controller_spec.rb'
- - 'spec/controllers/spree/api/variants_controller_spec.rb'
- - 'spec/controllers/spree/orders_controller_spec.rb'
- - 'spec/controllers/spree/user_sessions_controller_spec.rb'
- - 'spec/controllers/user_passwords_controller_spec.rb'
- - 'spec/controllers/user_registrations_controller_spec.rb'
- - 'spec/features/admin/image_settings_spec.rb'
- - 'spec/features/admin/products_spec.rb'
- - 'spec/features/admin/reports_spec.rb'
- - 'spec/features/consumer/shopping/checkout_spec.rb'
- - 'spec/helpers/checkout_helper_spec.rb'
- - 'spec/helpers/order_cycles_helper_spec.rb'
- - 'spec/lib/open_food_network/enterprise_fee_calculator_spec.rb'
- - 'spec/lib/open_food_network/feature_toggle_spec.rb'
- - 'spec/lib/open_food_network/lettuce_share_report_spec.rb'
- - 'spec/lib/open_food_network/order_cycle_form_applicator_spec.rb'
- - 'spec/lib/open_food_network/permissions_spec.rb'
- - 'spec/lib/open_food_network/reports/report_spec.rb'
- - 'spec/lib/open_food_network/reports/rule_spec.rb'
- - 'spec/lib/open_food_network/tag_rule_applicator_spec.rb'
- - 'spec/lib/stripe/account_connector_spec.rb'
- - 'spec/models/customer_spec.rb'
- - 'spec/models/enterprise_fee_spec.rb'
- - 'spec/models/enterprise_relationship_spec.rb'
- - 'spec/models/exchange_spec.rb'
- - 'spec/models/model_set_spec.rb'
- - 'spec/models/product_importer_spec.rb'
- - 'spec/models/spree/ability_spec.rb'
- - 'spec/models/spree/gateway/stripe_connect_spec.rb'
- - 'spec/models/spree/image_spec.rb'
- - 'spec/models/spree/order_spec.rb'
- - 'spec/models/spree/product_spec.rb'
- - 'spec/models/spree/shipping_method_spec.rb'
- - 'spec/models/spree/taxon_spec.rb'
- - 'spec/models/spree/variant_spec.rb'
- - 'spec/models/tag_rule/discount_order_spec.rb'
- - 'spec/performance/orders_controller_spec.rb'
- - 'spec/requests/checkout/failed_checkout_spec.rb'
- - 'spec/requests/checkout/stripe_connect_spec.rb'
- - 'spec/serializers/enterprise_serializer_spec.rb'
- - 'spec/services/order_syncer_spec.rb'
- - 'spec/services/subscription_form_spec.rb'
- - 'spec/spec_helper.rb'
- - 'spec/support/cancan_helper.rb'
- - 'spec/support/request/authentication_workflow.rb'
- - 'spec/support/request/shop_workflow.rb'
- - 'spec/support/seeds.rb'
-
-# Offense count: 4
-# Cop supports --auto-correct.
-# Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBrackets.
-# SupportedStyles: space, no_space
-# SupportedStylesForEmptyBrackets: space, no_space
-Layout/SpaceInsideReferenceBrackets:
- Exclude:
- - 'app/serializers/api/admin/exchange_serializer.rb'
- - 'spec/performance/orders_controller_spec.rb'
-
-# Offense count: 10
-# Cop supports --auto-correct.
-# Configuration parameters: EnforcedStyle.
-# SupportedStyles: space, no_space
-Layout/SpaceInsideStringInterpolation:
- Exclude:
- - 'app/controllers/enterprises_controller.rb'
- - 'lib/open_food_network/users_and_enterprises_report.rb'
- - 'spec/support/request/web_helper.rb'
-
-# Offense count: 4
-# Cop supports --auto-correct.
-# Configuration parameters: IndentationWidth.
-Layout/Tab:
- Exclude:
- - 'app/models/spree/line_item_decorator.rb'
- - 'spec/lib/spree/product_filters_spec.rb'
- - 'spec/models/spree/line_item_spec.rb'
-
-# Offense count: 57
-# Cop supports --auto-correct.
-# Configuration parameters: AllowInHeredoc.
-Layout/TrailingWhitespace:
- Exclude:
- - 'app/models/distributor_shipping_method.rb'
- - 'app/models/spree/money_decorator.rb'
- - 'app/models/spree/product_decorator.rb'
- - 'app/serializers/api/image_serializer.rb'
- - 'app/serializers/api/shipping_method_serializer.rb'
- - 'app/views/json/_current_order.rabl'
- - 'app/views/json/_enterprises.rabl'
- - 'app/views/json/_producer.rabl'
- - 'app/views/json/partials/_producer.rabl'
- - 'spec/controllers/admin/column_preferences_controller_spec.rb'
- - 'spec/features/admin/customers_spec.rb'
- - 'spec/features/consumer/cookies_spec.rb'
- - 'spec/helpers/enterprises_helper_spec.rb'
- - 'spec/lib/open_food_network/enterprise_fee_calculator_spec.rb'
- - 'spec/lib/open_food_network/group_buy_report_spec.rb'
- - 'spec/lib/open_food_network/order_grouper_spec.rb'
- - 'spec/lib/open_food_network/permissions_spec.rb'
- - 'spec/lib/open_food_network/user_balance_calculator_spec.rb'
- - 'spec/models/spree/variant_spec.rb'
- - 'spec/serializers/admin/enterprise_serializer_spec.rb'
- - 'spec/serializers/enterprise_serializer_spec.rb'
- - 'spec/support/request/menu_helper.rb'
-
-# Offense count: 2
Lint/AmbiguousOperator:
Exclude:
+ - 'app/controllers/spree/admin/orders/customer_details_controller_decorator.rb'
+ - 'app/controllers/spree/admin/orders_controller_decorator.rb'
- 'spec/controllers/api/enterprise_fees_controller_spec.rb'
- 'spec/controllers/spree/admin/payments_controller_spec.rb'
@@ -889,128 +43,49 @@ Lint/DuplicateMethods:
Lint/IneffectiveAccessModifier:
Exclude:
- 'app/models/column_preference.rb'
+ - 'app/services/mail_configuration.rb'
- 'lib/open_food_network/feature_toggle.rb'
- 'lib/open_food_network/products_cache.rb'
- 'spec/lib/open_food_network/reports/report_spec.rb'
-# Offense count: 2
-# Cop supports --auto-correct.
-# Configuration parameters: EnforcedStyle.
-# SupportedStyles: runtime_error, standard_error
-Lint/InheritException:
- Exclude:
- - 'lib/open_food_network/cached_products_renderer.rb'
- - 'lib/open_food_network/products_renderer.rb'
-
# Offense count: 1
Lint/InterpolationCheck:
Exclude:
- 'spec/features/consumer/shopping/embedded_groups_spec.rb'
-# Offense count: 1
-Lint/LiteralAsCondition:
- Exclude:
- - 'lib/open_food_network/rack_request_blocker.rb'
-
-# Offense count: 1
-# Cop supports --auto-correct.
-Lint/ScriptPermission:
- Exclude:
- - 'Rakefile'
-
# Offense count: 3
Lint/ShadowingOuterLocalVariable:
Exclude:
- 'app/models/model_set.rb'
- 'spec/models/model_set_spec.rb'
-# Offense count: 6
-# Cop supports --auto-correct.
-Lint/StringConversionInInterpolation:
- Exclude:
- - 'app/controllers/enterprises_controller.rb'
- - 'app/helpers/admin/injection_helper.rb'
- - 'app/helpers/injection_helper.rb'
- - 'app/helpers/spree/products_helper_decorator.rb'
- - 'app/serializers/api/admin/tag_rule_serializer.rb'
-
# Offense count: 2
Lint/UnderscorePrefixedVariableName:
Exclude:
- 'spec/support/cancan_helper.rb'
-# Offense count: 121
-# Cop supports --auto-correct.
-# Configuration parameters: IgnoreEmptyBlocks, AllowUnusedKeywordArguments.
-Lint/UnusedBlockArgument:
- Exclude:
- - 'app/controllers/admin/column_preferences_controller.rb'
- - 'app/controllers/admin/enterprises_controller.rb'
- - 'app/controllers/admin/order_cycles_controller.rb'
- - 'app/controllers/spree/orders_controller_decorator.rb'
- - 'app/models/column_preference.rb'
- - 'app/models/model_set.rb'
- - 'app/models/spree/order_decorator.rb'
- - 'lib/open_food_network/bulk_coop_report.rb'
- - 'lib/open_food_network/enterprise_fee_calculator.rb'
- - 'lib/open_food_network/group_buy_report.rb'
- - 'lib/open_food_network/option_value_namer.rb'
- - 'lib/open_food_network/order_cycle_form_applicator.rb'
- - 'lib/open_food_network/order_grouper.rb'
- - 'lib/open_food_network/orders_and_fulfillments_report.rb'
- - 'lib/open_food_network/packing_report.rb'
- - 'lib/open_food_network/reports/bulk_coop_allocation_report.rb'
- - 'lib/open_food_network/reports/bulk_coop_supplier_report.rb'
- - 'lib/open_food_network/sales_tax_report.rb'
- - 'lib/open_food_network/xero_invoices_report.rb'
- - 'spec/lib/open_food_network/order_grouper_spec.rb'
- - 'spec/support/cancan_helper.rb'
- - 'spec/support/delayed_job_helper.rb'
- - 'spec/support/matchers/delegate_matchers.rb'
- - 'spec/support/matchers/select2_matchers.rb'
- - 'spec/support/matchers/table_matchers.rb'
- - 'spec/support/performance_helper.rb'
-
-# Offense count: 15
-# Cop supports --auto-correct.
-# Configuration parameters: AllowUnusedKeywordArguments, IgnoreEmptyMethods.
-Lint/UnusedMethodArgument:
- Exclude:
- - 'app/helpers/angular_form_builder.rb'
- - 'app/helpers/angular_form_helper.rb'
- - 'app/helpers/order_cycles_helper.rb'
- - 'app/helpers/spree/base_helper_decorator.rb'
- - 'app/models/spree/ability_decorator.rb'
- - 'app/models/spree/product_decorator.rb'
- - 'lib/open_food_network/enterprise_fee_applicator.rb'
- - 'lib/open_food_network/order_cycle_form_applicator.rb'
- - 'lib/open_food_network/paperclippable.rb'
- - 'lib/open_food_network/rack_request_blocker.rb'
-
-# Offense count: 5
+# Offense count: 6
# Configuration parameters: ContextCreatingMethods, MethodCreatingMethods.
Lint/UselessAccessModifier:
Exclude:
- 'app/models/column_preference.rb'
+ - 'app/services/mail_configuration.rb'
- 'lib/open_food_network/feature_toggle.rb'
- 'lib/open_food_network/products_cache.rb'
- 'lib/open_food_network/reports/bulk_coop_report.rb'
- 'spec/lib/open_food_network/reports/report_spec.rb'
-# Offense count: 240
+# Offense count: 1
+Lint/UselessAssignment:
+ Exclude:
+ - 'spec/**/*'
+ - 'engines/order_management/spec/services/order_management/reports/enterprise_fee_summary/report_service_spec.rb'
+
+# Offense count: 91
# Configuration parameters: CheckForMethodsWithNoSideEffects.
Lint/Void:
Exclude:
- 'app/serializers/api/enterprise_serializer.rb'
- - 'spec/archive/features/consumer/checkout_spec.rb'
- - 'spec/controllers/api/order_cycles_controller_spec.rb'
- - 'spec/controllers/checkout_controller_spec.rb'
- - 'spec/controllers/enterprises_controller_spec.rb'
- - 'spec/controllers/shop_controller_spec.rb'
- - 'spec/controllers/spree/admin/adjustments_controller_spec.rb'
- - 'spec/controllers/spree/admin/variants_controller_spec.rb'
- - 'spec/controllers/spree/api/products_controller_spec.rb'
- - 'spec/controllers/spree/api/variants_controller_spec.rb'
- 'spec/features/admin/bulk_product_update_spec.rb'
- 'spec/features/admin/enterprise_groups_spec.rb'
- 'spec/features/admin/enterprises/index_spec.rb'
@@ -1018,57 +93,54 @@ Lint/Void:
- 'spec/features/admin/order_cycles_spec.rb'
- 'spec/features/admin/payment_method_spec.rb'
- 'spec/features/admin/products_spec.rb'
- - 'spec/features/admin/shipping_methods_spec.rb'
- 'spec/features/admin/variant_overrides_spec.rb'
- 'spec/features/admin/variants_spec.rb'
- 'spec/features/consumer/shopping/checkout_spec.rb'
- 'spec/features/consumer/shopping/shopping_spec.rb'
- 'spec/features/consumer/shopping/variant_overrides_spec.rb'
- - 'spec/helpers/html_helper_spec.rb'
- - 'spec/helpers/products_helper_spec.rb'
- - 'spec/lib/open_food_network/bulk_coop_report_spec.rb'
- - 'spec/lib/open_food_network/enterprise_fee_applicator_spec.rb'
- - 'spec/lib/open_food_network/enterprise_fee_calculator_spec.rb'
- - 'spec/lib/open_food_network/enterprise_issue_validator_spec.rb'
- - 'spec/lib/open_food_network/group_buy_report_spec.rb'
- - 'spec/lib/open_food_network/packing_report_spec.rb'
- - 'spec/lib/open_food_network/reports/report_spec.rb'
- - 'spec/lib/open_food_network/reports/rule_spec.rb'
- - 'spec/mailers/order_mailer_spec.rb'
- - 'spec/models/enterprise_relationship_spec.rb'
- - 'spec/models/enterprise_spec.rb'
- - 'spec/models/exchange_spec.rb'
- - 'spec/models/order_cycle_spec.rb'
- - 'spec/models/spree/adjustment_spec.rb'
- - 'spec/models/spree/line_item_spec.rb'
- - 'spec/models/spree/order_spec.rb'
- - 'spec/models/spree/payment_method_spec.rb'
- - 'spec/models/spree/payment_spec.rb'
- - 'spec/models/spree/product_spec.rb'
- - 'spec/models/spree/variant_spec.rb'
- - 'spec/serializers/enterprise_serializer_spec.rb'
- - 'spec/support/request/web_helper.rb'
-# Offense count: 110
+# Offense count: 162
+Metrics/AbcSize:
+ Max: 283
+
+# Offense count: 108
# Configuration parameters: CountComments, ExcludedMethods.
Metrics/BlockLength:
- Max: 787
+ Max: 774
-# Offense count: 1
+# Offense count: 23
# Configuration parameters: CountComments.
Metrics/ClassLength:
- Max: 117
+ Max: 324
-# Offense count: 1
+# Offense count: 31
+Metrics/CyclomaticComplexity:
+ Max: 23
+
+# Offense count: 2382
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
# URISchemes: http, https
Metrics/LineLength:
- Max: 141
+ Max: 619
-# Offense count: 1
+# Offense count: 146
# Configuration parameters: CountComments.
Metrics/MethodLength:
- Max: 14
+ Max: 99
+
+# Offense count: 29
+# Configuration parameters: CountComments.
+Metrics/ModuleLength:
+ Max: 633
+
+# Offense count: 6
+# Configuration parameters: CountKeywordArgs.
+Metrics/ParameterLists:
+ Max: 8
+
+# Offense count: 25
+Metrics/PerceivedComplexity:
+ Max: 21
# Offense count: 7
Naming/AccessorMethodName:
@@ -1145,12 +217,11 @@ Naming/VariableName:
Exclude:
- 'app/helpers/admin/injection_helper.rb'
-# Offense count: 10
+# Offense count: 4
# Configuration parameters: EnforcedStyle.
# SupportedStyles: snake_case, normalcase, non_integer
Naming/VariableNumber:
Exclude:
- - 'spec/archive/features/consumer/checkout_spec.rb'
- 'spec/lib/open_food_network/products_and_inventory_report_spec.rb'
# Offense count: 1
@@ -1158,97 +229,12 @@ Performance/Caller:
Exclude:
- 'app/controllers/application_controller.rb'
-# Offense count: 2
-# Cop supports --auto-correct.
-Performance/CompareWithBlock:
- Exclude:
- - 'app/controllers/spree/admin/payment_methods_controller_decorator.rb'
-
# Offense count: 1
-# Cop supports --auto-correct.
-# Configuration parameters: IncludeActiveSupportAliases.
-Performance/DoubleStartEndWith:
- Exclude:
- - 'app/helpers/application_helper.rb'
-
-# Offense count: 5
-# Cop supports --auto-correct.
-Performance/InefficientHashSearch:
- Exclude:
- - 'app/models/product_import/product_importer.rb'
- - 'app/models/spree/payment_method_decorator.rb'
- - 'app/models/spree/preferences/file_configuration.rb'
- - 'lib/stripe/account_connector.rb'
- - 'lib/stripe/webhook_handler.rb'
-
-# Offense count: 3
-# Cop supports --auto-correct.
-Performance/RedundantBlockCall:
- Exclude:
- - 'app/controllers/application_controller.rb'
- - 'app/helpers/angular_form_builder.rb'
- - 'spec/features/admin/overview_spec.rb'
-
-# Offense count: 7
-# Cop supports --auto-correct.
-# Configuration parameters: MaxKeyValuePairs.
-Performance/RedundantMerge:
- Exclude:
- - 'lib/open_food_network/reports/rule.rb'
- - 'lib/spree/core/controller_helpers/respond_with_decorator.rb'
- - 'spec/models/spree/line_item_spec.rb'
-
-# Offense count: 5
-# Cop supports --auto-correct.
-Performance/Size:
- Exclude:
- - 'spec/models/producer_property_spec.rb'
- - 'spec/models/spree/property_spec.rb'
-
-# Offense count: 2
-# Cop supports --auto-correct.
-Performance/StringReplacement:
- Exclude:
- - 'app/helpers/spree/admin/navigation_helper_decorator.rb'
- - 'app/models/spree/preferences/file_configuration.rb'
-
-# Offense count: 4
-# Cop supports --auto-correct.
-Performance/UnneededSort:
- Exclude:
- - 'spec/features/admin/order_cycles_spec.rb'
-
-# Offense count: 11
-# Cop supports --auto-correct.
-# Configuration parameters: NilOrEmpty, NotPresent, UnlessPresent.
-Rails/Blank:
- Exclude:
- - 'app/controllers/spree/admin/orders_controller_decorator.rb'
- - 'app/helpers/enterprises_helper.rb'
- - 'app/models/enterprise_group.rb'
- - 'app/models/order_cycle.rb'
- - 'app/models/spree/variant_decorator.rb'
- - 'lib/open_food_network/order_cycle_permissions.rb'
- - 'lib/tasks/data.rake'
-
-# Offense count: 3
# Configuration parameters: EnforcedStyle.
# SupportedStyles: strict, flexible
Rails/Date:
Exclude:
- 'app/models/order_cycle.rb'
- - 'spec/controllers/admin/enterprises_controller_spec.rb'
-
-# Offense count: 6
-# Cop supports --auto-correct.
-# Configuration parameters: EnforceForPrefixed.
-Rails/Delegate:
- Exclude:
- - 'app/models/spree/line_item_decorator.rb'
- - 'app/models/spree/product_property_decorator.rb'
- - 'app/serializers/api/admin/calculator_serializer.rb'
- - 'app/serializers/api/admin/tag_rule_serializer.rb'
- - 'app/serializers/api/variant_serializer.rb'
# Offense count: 8
# Configuration parameters: EnforcedStyle.
@@ -1263,15 +249,6 @@ Rails/FilePath:
- 'spec/models/spree/variant_spec.rb'
- 'spec/spec_helper.rb'
-# Offense count: 2
-# Cop supports --auto-correct.
-# Configuration parameters: Include.
-# Include: app/models/**/*.rb
-Rails/FindEach:
- Exclude:
- - 'app/models/enterprise.rb'
- - 'app/models/spree/user_decorator.rb'
-
# Offense count: 7
# Configuration parameters: Include.
# Include: app/models/**/*.rb
@@ -1281,10 +258,10 @@ Rails/HasAndBelongsToMany:
- 'app/models/enterprise_group.rb'
- 'app/models/order_cycle.rb'
- 'app/models/schedule.rb'
+ - 'app/models/spree/concerns/payment_method_distributors.rb'
- 'app/models/spree/line_item_decorator.rb'
- - 'app/models/spree/payment_method_decorator.rb'
-# Offense count: 28
+# Offense count: 25
# Configuration parameters: Include.
# Include: app/models/**/*.rb
Rails/HasManyOrHasOneDependent:
@@ -1301,34 +278,6 @@ Rails/HasManyOrHasOneDependent:
- 'app/models/spree/variant_decorator.rb'
- 'app/models/subscription.rb'
-# Offense count: 46
-# Cop supports --auto-correct.
-# Configuration parameters: EnforcedStyle.
-# SupportedStyles: numeric, symbolic
-Rails/HttpStatus:
- Exclude:
- - 'app/controllers/admin/bulk_line_items_controller.rb'
- - 'app/controllers/admin/column_preferences_controller.rb'
- - 'app/controllers/admin/customers_controller.rb'
- - 'app/controllers/admin/enterprise_relationships_controller.rb'
- - 'app/controllers/admin/enterprise_roles_controller.rb'
- - 'app/controllers/admin/manager_invitations_controller.rb'
- - 'app/controllers/admin/tag_rules_controller.rb'
- - 'app/controllers/admin/variant_overrides_controller.rb'
- - 'app/controllers/api/customers_controller.rb'
- - 'app/controllers/api/enterprise_fees_controller.rb'
- - 'app/controllers/api/enterprises_controller.rb'
- - 'app/controllers/application_controller.rb'
- - 'app/controllers/checkout_controller.rb'
- - 'app/controllers/enterprises_controller.rb'
- - 'app/controllers/line_items_controller.rb'
- - 'app/controllers/shop_controller.rb'
- - 'app/controllers/spree/admin/line_items_controller_decorator.rb'
- - 'app/controllers/spree/admin/products_controller_decorator.rb'
- - 'app/controllers/spree/store_controller_decorator.rb'
- - 'app/controllers/stripe/callbacks_controller.rb'
- - 'app/controllers/stripe/webhooks_controller.rb'
-
# Offense count: 6
Rails/OutputSafety:
Exclude:
@@ -1339,37 +288,7 @@ Rails/OutputSafety:
- 'lib/spree/money_decorator.rb'
- 'spec/features/admin/orders_spec.rb'
-# Offense count: 10
-# Cop supports --auto-correct.
-Rails/PluralizationGrammar:
- Exclude:
- - 'spec/features/admin/order_cycles_spec.rb'
- - 'spec/models/order_cycle_spec.rb'
- - 'spec/models/spree/product_spec.rb'
-
-# Offense count: 1
-# Cop supports --auto-correct.
-Rails/Presence:
- Exclude:
- - 'app/serializers/api/admin/customer_serializer.rb'
-
-# Offense count: 2
-# Cop supports --auto-correct.
-# Configuration parameters: NotNilAndNotEmpty, NotBlank, UnlessBlank.
-Rails/Present:
- Exclude:
- - 'app/models/producer_property.rb'
- - 'lib/open_food_network/products_and_inventory_report.rb'
-
-# Offense count: 3
-# Cop supports --auto-correct.
-# Configuration parameters: Include.
-# Include: app/models/**/*.rb
-Rails/ReadWriteAttribute:
- Exclude:
- - 'app/models/enterprise.rb'
-
-# Offense count: 46
+# Offense count: 42
# Configuration parameters: Include.
# Include: app/models/**/*.rb
Rails/ScopeArgs:
@@ -1388,7 +307,7 @@ Rails/ScopeArgs:
- 'app/models/spree/shipping_method_decorator.rb'
- 'app/models/spree/variant_decorator.rb'
-# Offense count: 17
+# Offense count: 16
# Configuration parameters: EnforcedStyle.
# SupportedStyles: strict, flexible
Rails/TimeZone:
@@ -1409,105 +328,7 @@ Rails/TimeZone:
# Environments: development, test, production
Rails/UnknownEnv:
Exclude:
- - 'lib/open_food_network/cached_products_renderer.rb'
-
-# Offense count: 19
-# Cop supports --auto-correct.
-# Configuration parameters: Include.
-# Include: app/models/**/*.rb
-Rails/Validation:
- Exclude:
- - 'app/models/enterprise.rb'
- - 'app/models/enterprise_fee.rb'
- - 'app/models/enterprise_relationship.rb'
- - 'app/models/enterprise_role.rb'
- - 'app/models/exchange.rb'
- - 'app/models/order_cycle.rb'
- - 'app/models/spree/product_decorator.rb'
-
-# Offense count: 18
-# Cop supports --auto-correct.
-# Configuration parameters: EnforcedStyle.
-# SupportedStyles: always, conditionals
-Style/AndOr:
- Exclude:
- - 'app/controllers/checkout_controller.rb'
- - 'app/controllers/enterprises_controller.rb'
- - 'app/controllers/line_items_controller.rb'
- - 'app/controllers/spree/admin/shipping_methods_controller_decorator.rb'
- - 'app/controllers/spree/orders_controller_decorator.rb'
- - 'app/helpers/discourse_helper.rb'
- - 'app/helpers/spree/admin/navigation_helper_decorator.rb'
- - 'app/models/spree/adjustment_decorator.rb'
- - 'app/models/spree/order_decorator.rb'
- - 'app/views/json/partials/_enterprise.rabl'
- - 'lib/spree/core/controller_helpers/respond_with_decorator.rb'
-
-# Offense count: 1
-# Cop supports --auto-correct.
-# Configuration parameters: EnforcedStyle.
-# SupportedStyles: percent_q, bare_percent
-Style/BarePercentLiterals:
- Exclude:
- - 'spec/features/admin/variants_spec.rb'
-
-# Offense count: 212
-# Cop supports --auto-correct.
-# Configuration parameters: EnforcedStyle.
-# SupportedStyles: braces, no_braces, context_dependent
-Style/BracesAroundHashParameters:
- Exclude:
- - 'app/controllers/admin/enterprises_controller.rb'
- - 'app/controllers/api/enterprises_controller.rb'
- - 'app/controllers/checkout_controller.rb'
- - 'app/controllers/spree/admin/products_controller_decorator.rb'
- - 'app/controllers/spree/admin/search_controller_decorator.rb'
- - 'app/helpers/angular_form_builder.rb'
- - 'app/helpers/checkout_helper.rb'
- - 'app/helpers/spree/admin/orders_helper_decorator.rb'
- - 'app/models/exchange.rb'
- - 'app/models/spree/adjustment_decorator.rb'
- - 'app/models/spree/line_item_decorator.rb'
- - 'app/models/spree/order_decorator.rb'
- - 'app/serializers/api/admin/order_cycle_serializer.rb'
- - 'lib/open_food_network/order_cycle_form_applicator.rb'
- - 'lib/open_food_network/reports/rule.rb'
- - 'lib/open_food_network/variant_and_line_item_naming.rb'
- - 'lib/open_food_network/xero_invoices_report.rb'
- - 'spec/controllers/admin/enterprises_controller_spec.rb'
- - 'spec/controllers/admin/manager_invitations_controller_spec.rb'
- - 'spec/controllers/admin/order_cycles_controller_spec.rb'
- - 'spec/controllers/api/order_cycles_controller_spec.rb'
- - 'spec/controllers/enterprises_controller_spec.rb'
- - 'spec/controllers/line_items_controller_spec.rb'
- - 'spec/controllers/spree/admin/adjustments_controller_spec.rb'
- - 'spec/controllers/spree/admin/base_controller_spec.rb'
- - 'spec/controllers/spree/admin/orders_controller_spec.rb'
- - 'spec/controllers/spree/admin/payment_methods_controller_spec.rb'
- - 'spec/controllers/spree/admin/products_controller_spec.rb'
- - 'spec/controllers/spree/admin/reports_controller_spec.rb'
- - 'spec/controllers/spree/api/products_controller_spec.rb'
- - 'spec/controllers/spree/api/variants_controller_spec.rb'
- - 'spec/controllers/spree/orders_controller_spec.rb'
- - 'spec/controllers/user_confirmations_controller_spec.rb'
- - 'spec/controllers/user_registrations_controller_spec.rb'
- - 'spec/features/admin/order_cycles_spec.rb'
- - 'spec/features/admin/products_spec.rb'
- - 'spec/features/admin/reports_spec.rb'
- - 'spec/features/admin/tax_settings_spec.rb'
- - 'spec/helpers/order_cycles_helper_spec.rb'
- - 'spec/lib/open_food_network/feature_toggle_spec.rb'
- - 'spec/lib/open_food_network/order_cycle_form_applicator_spec.rb'
- - 'spec/lib/open_food_network/subscription_summarizer_spec.rb'
- - 'spec/models/spree/ability_spec.rb'
- - 'spec/models/spree/order_spec.rb'
- - 'spec/models/spree/product_spec.rb'
- - 'spec/models/spree/taxon_spec.rb'
- - 'spec/serializers/admin/customer_serializer_spec.rb'
- - 'spec/spec_helper.rb'
- - 'spec/support/cancan_helper.rb'
- - 'spec/support/request/authentication_workflow.rb'
- - 'spec/support/request/shop_workflow.rb'
+ - 'app/models/spree/app_configuration_decorator.rb'
# Offense count: 2
Style/CaseEquality:
@@ -1515,7 +336,7 @@ Style/CaseEquality:
- 'app/helpers/angular_form_helper.rb'
- 'spec/models/spree/payment_spec.rb'
-# Offense count: 82
+# Offense count: 79
# Cop supports --auto-correct.
# Configuration parameters: AutoCorrect, EnforcedStyle.
# SupportedStyles: nested, compact
@@ -1524,6 +345,7 @@ Style/ClassAndModuleChildren:
- 'app/controllers/spree/store_controller_decorator.rb'
- 'app/helpers/angular_form_helper.rb'
- 'app/models/calculator/flat_percent_per_item.rb'
+ - 'app/models/spree/concerns/payment_method_distributors.rb'
- 'app/models/spree/gateway/migs.rb'
- 'app/models/spree/gateway/pin.rb'
- 'app/models/spree/preferences/file_configuration.rb'
@@ -1595,85 +417,21 @@ Style/ClassAndModuleChildren:
- 'spec/lib/open_food_network/reports/row_spec.rb'
- 'spec/lib/open_food_network/reports/rule_spec.rb'
-# Offense count: 3
-# Cop supports --auto-correct.
-# Configuration parameters: EnforcedStyle.
-# SupportedStyles: is_a?, kind_of?
-Style/ClassCheck:
- Exclude:
- - 'app/controllers/checkout_controller.rb'
- - 'lib/open_food_network/users_and_enterprises_report.rb'
-
# Offense count: 2
Style/ClassVars:
Exclude:
- 'lib/open_food_network/rack_request_blocker.rb'
-# Offense count: 3
-# Cop supports --auto-correct.
-Style/ColonMethodCall:
- Exclude:
- - 'app/controllers/admin/enterprises_controller.rb'
- - 'app/controllers/application_controller.rb'
- - 'lib/discourse/single_sign_on.rb'
-
# Offense count: 1
Style/CommentedKeyword:
Exclude:
- 'app/controllers/application_controller.rb'
-# Offense count: 6
-# Cop supports --auto-correct.
-# Configuration parameters: EnforcedStyle, SingleLineConditionsOnly, IncludeTernaryExpressions.
-# SupportedStyles: assign_to_condition, assign_inside_condition
-Style/ConditionalAssignment:
- Exclude:
- - 'app/controllers/checkout_controller.rb'
- - 'app/controllers/spree/admin/search_controller_decorator.rb'
- - 'app/models/spree/calculator/per_item_decorator.rb'
- - 'app/models/spree/line_item_decorator.rb'
- - 'spec/lib/open_food_network/order_grouper_spec.rb'
-
# Offense count: 2
Style/DateTime:
Exclude:
- 'lib/open_food_network/users_and_enterprises_report.rb'
-# Offense count: 5
-# Cop supports --auto-correct.
-Style/EachWithObject:
- Exclude:
- - 'app/models/spree/taxon_decorator.rb'
- - 'app/models/tag_rule.rb'
- - 'lib/open_food_network/enterprise_fee_calculator.rb'
- - 'lib/open_food_network/products_renderer.rb'
-
-# Offense count: 2
-# Cop supports --auto-correct.
-Style/EmptyLiteral:
- Exclude:
- - 'app/helpers/checkout_helper.rb'
- - 'app/models/spree/order_decorator.rb'
-
-# Offense count: 5
-# Cop supports --auto-correct.
-# Configuration parameters: EnforcedStyle.
-# SupportedStyles: compact, expanded
-Style/EmptyMethod:
- Exclude:
- - 'app/controllers/admin/variant_overrides_controller.rb'
- - 'app/controllers/home_controller.rb'
- - 'app/controllers/map_controller.rb'
- - 'app/controllers/producers_controller.rb'
- - 'app/controllers/spree/admin/products_controller_decorator.rb'
-
-# Offense count: 2
-# Cop supports --auto-correct.
-Style/ExpandPathArguments:
- Exclude:
- - 'spec/features/admin/products_spec.rb'
- - 'spec/performance/shop_controller_spec.rb'
-
# Offense count: 5
# Configuration parameters: EnforcedStyle.
# SupportedStyles: annotated, template, unannotated
@@ -1683,11 +441,10 @@ Style/FormatStringToken:
- 'lib/open_food_network/sales_tax_report.rb'
- 'spec/models/enterprise_spec.rb'
-# Offense count: 76
+# Offense count: 61
# Configuration parameters: MinBodyLength.
Style/GuardClause:
Exclude:
- - 'app/controllers/admin/enterprises_controller.rb'
- 'app/controllers/admin/order_cycles_controller.rb'
- 'app/controllers/admin/product_import_controller.rb'
- 'app/controllers/application_controller.rb'
@@ -1699,7 +456,7 @@ Style/GuardClause:
- 'app/controllers/spree/admin/orders_controller_decorator.rb'
- 'app/controllers/spree/admin/products_controller_decorator.rb'
- 'app/controllers/spree/admin/resource_controller_decorator.rb'
- - 'app/controllers/spree/admin/shipping_methods_controller_decorator.rb'
+ - 'app/controllers/spree/admin/variants_controller_decorator.rb'
- 'app/controllers/spree/orders_controller_decorator.rb'
- 'app/controllers/spree/paypal_controller_decorator.rb'
- 'app/jobs/products_cache_integrity_checker_job.rb'
@@ -1711,6 +468,8 @@ Style/GuardClause:
- 'app/models/spree/preference_decorator.rb'
- 'app/models/spree/product_decorator.rb'
- 'app/models/spree/user_decorator.rb'
+ - 'app/services/advance_order_service.rb'
+ - 'app/services/order_syncer.rb'
- 'lib/discourse/single_sign_on.rb'
- 'lib/open_food_network/order_cycle_form_applicator.rb'
- 'lib/open_food_network/products_cache.rb'
@@ -1719,141 +478,10 @@ Style/GuardClause:
- 'lib/open_food_network/variant_and_line_item_naming.rb'
- 'lib/spree/core/controller_helpers/order_decorator.rb'
- 'lib/spree/core/controller_helpers/respond_with_decorator.rb'
- - 'spec/features/admin/orders_spec.rb'
- 'spec/support/delayed_job_helper.rb'
- 'spec/support/request/distribution_helper.rb'
- 'spec/support/request/shop_workflow.rb'
-# Offense count: 872
-# Cop supports --auto-correct.
-# Configuration parameters: EnforcedStyle, UseHashRocketsWithSymbolValues, PreferHashRocketsForNonAlnumEndingSymbols.
-# SupportedStyles: ruby19, hash_rockets, no_mixed_keys, ruby19_no_mixed_keys
-Style/HashSyntax:
- Exclude:
- - 'app/controllers/admin/contents_controller.rb'
- - 'app/controllers/admin/enterprise_fees_controller.rb'
- - 'app/controllers/admin/enterprises_controller.rb'
- - 'app/controllers/admin/order_cycles_controller.rb'
- - 'app/controllers/admin/stripe_connect_settings_controller.rb'
- - 'app/controllers/admin/tag_rules_controller.rb'
- - 'app/controllers/api/enterprises_controller.rb'
- - 'app/controllers/checkout_controller.rb'
- - 'app/controllers/spree/admin/line_items_controller_decorator.rb'
- - 'app/controllers/spree/admin/orders_controller_decorator.rb'
- - 'app/controllers/spree/admin/products_controller_decorator.rb'
- - 'app/controllers/spree/admin/search_controller_decorator.rb'
- - 'app/controllers/spree/admin/shipping_methods_controller_decorator.rb'
- - 'app/controllers/spree/api/products_controller_decorator.rb'
- - 'app/controllers/spree/paypal_controller_decorator.rb'
- - 'app/controllers/spree/store_controller_decorator.rb'
- - 'app/controllers/user_passwords_controller.rb'
- - 'app/helpers/angular_form_builder.rb'
- - 'app/helpers/application_helper.rb'
- - 'app/helpers/checkout_helper.rb'
- - 'app/helpers/enterprises_helper.rb'
- - 'app/helpers/spree/admin/navigation_helper_decorator.rb'
- - 'app/helpers/spree/admin/orders_helper_decorator.rb'
- - 'app/mailers/enterprise_mailer.rb'
- - 'app/mailers/spree/user_mailer_decorator.rb'
- - 'app/models/calculator/flat_percent_per_item.rb'
- - 'app/models/enterprise.rb'
- - 'app/models/enterprise_fee.rb'
- - 'app/models/enterprise_group.rb'
- - 'app/models/enterprise_role.rb'
- - 'app/models/exchange_variant.rb'
- - 'app/models/order_cycle.rb'
- - 'app/models/spree/adjustment_decorator.rb'
- - 'app/models/spree/classification_decorator.rb'
- - 'app/models/spree/gateway/migs.rb'
- - 'app/models/spree/gateway/pin.rb'
- - 'app/models/spree/gateway/stripe_connect.rb'
- - 'app/models/spree/gateway_decorator.rb'
- - 'app/models/spree/line_item_decorator.rb'
- - 'app/models/spree/order_decorator.rb'
- - 'app/models/spree/payment_decorator.rb'
- - 'app/models/spree/payment_method_decorator.rb'
- - 'app/models/spree/product_decorator.rb'
- - 'app/models/spree/taxon_decorator.rb'
- - 'app/models/spree/user_decorator.rb'
- - 'app/overrides/add_enterprise_fees_to_admin_configurations_menu.rb'
- - 'app/overrides/remove_search_bar.rb'
- - 'app/overrides/remove_side_bar.rb'
- - 'app/overrides/set_auth_token_in_backend.rb'
- - 'app/overrides/set_auth_token_in_frontend.rb'
- - 'app/presenters/variant_presenter.rb'
- - 'app/serializers/api/admin/enterprise_fee_serializer.rb'
- - 'app/views/api/order_cycles/bulk_show.v1.rabl'
- - 'app/views/json/_order_cycle.rabl'
- - 'app/views/json/partials/_hub.rabl'
- - 'app/views/spree/admin/variants/search.rabl'
- - 'app/views/spree/api/products/bulk_show.v1.rabl'
- - 'lib/open_food_network/enterprise_fee_calculator.rb'
- - 'lib/open_food_network/order_cycle_form_applicator.rb'
- - 'lib/open_food_network/products_cache.rb'
- - 'lib/open_food_network/variant_and_line_item_naming.rb'
- - 'lib/spree/api/testing_support/helpers_decorator.rb'
- - 'lib/spree/api/testing_support/setup.rb'
- - 'lib/spree/core/controller_helpers/respond_with_decorator.rb'
- - 'lib/spree/money_decorator.rb'
- - 'lib/spree/product_filters.rb'
- - 'lib/tasks/cache.rake'
- - 'lib/tasks/data.rake'
- - 'lib/tasks/enterprises.rake'
- - 'lib/tasks/karma.rake'
- - 'spec/archive/features/consumer/checkout_spec.rb'
- - 'spec/controllers/admin/bulk_line_items_controller_spec.rb'
- - 'spec/controllers/admin/stripe_connect_settings_controller_spec.rb'
- - 'spec/controllers/api/order_cycles_controller_spec.rb'
- - 'spec/controllers/base_controller_spec.rb'
- - 'spec/controllers/spree/admin/payment_methods_controller_spec.rb'
- - 'spec/controllers/spree/admin/payments_controller_spec.rb'
- - 'spec/controllers/spree/api/products_controller_spec.rb'
- - 'spec/controllers/spree/api/variants_controller_spec.rb'
- - 'spec/controllers/spree/user_sessions_controller_spec.rb'
- - 'spec/controllers/user_registrations_controller_spec.rb'
- - 'spec/features/admin/bulk_order_management_spec.rb'
- - 'spec/features/admin/bulk_product_update_spec.rb'
- - 'spec/features/admin/customers_spec.rb'
- - 'spec/features/admin/enterprise_groups_spec.rb'
- - 'spec/features/admin/enterprises_spec.rb'
- - 'spec/features/admin/order_cycles_spec.rb'
- - 'spec/features/admin/orders_spec.rb'
- - 'spec/features/admin/overview_spec.rb'
- - 'spec/features/admin/payment_method_spec.rb'
- - 'spec/features/admin/products_spec.rb'
- - 'spec/features/admin/reports_spec.rb'
- - 'spec/features/admin/shipping_methods_spec.rb'
- - 'spec/features/admin/subscriptions_spec.rb'
- - 'spec/features/admin/variant_overrides_spec.rb'
- - 'spec/features/consumer/account/cards_spec.rb'
- - 'spec/features/consumer/cookies_spec.rb'
- - 'spec/features/consumer/footer_links_spec.rb'
- - 'spec/features/consumer/shopping/products_spec.rb'
- - 'spec/features/consumer/shopping/shopping_spec.rb'
- - 'spec/jobs/subscription_placement_job_spec.rb'
- - 'spec/lib/open_food_network/group_buy_report_spec.rb'
- - 'spec/lib/open_food_network/lettuce_share_report_spec.rb'
- - 'spec/lib/open_food_network/order_cycle_form_applicator_spec.rb'
- - 'spec/lib/open_food_network/order_grouper_spec.rb'
- - 'spec/lib/open_food_network/tag_rule_applicator_spec.rb'
- - 'spec/mailers/order_mailer_spec.rb'
- - 'spec/models/enterprise_fee_spec.rb'
- - 'spec/models/enterprise_spec.rb'
- - 'spec/models/exchange_spec.rb'
- - 'spec/models/order_cycle_spec.rb'
- - 'spec/models/spree/calculator/flat_rate_spec.rb'
- - 'spec/models/spree/image_spec.rb'
- - 'spec/models/spree/order_spec.rb'
- - 'spec/models/spree/payment_spec.rb'
- - 'spec/models/spree/product_spec.rb'
- - 'spec/models/tag_rule/discount_order_spec.rb'
- - 'spec/requests/checkout/paypal_spec.rb'
- - 'spec/requests/checkout/stripe_connect_spec.rb'
- - 'spec/spec_helper.rb'
- - 'spec/support/request/authentication_workflow.rb'
- - 'spec/support/request/web_helper.rb'
- - 'spec/support/seeds.rb'
-
# Offense count: 3
Style/IfInsideElse:
Exclude:
@@ -1861,59 +489,12 @@ Style/IfInsideElse:
- 'app/controllers/admin/variant_overrides_controller.rb'
- 'app/controllers/spree/admin/products_controller_decorator.rb'
-# Offense count: 1
-# Cop supports --auto-correct.
-Style/InfiniteLoop:
- Exclude:
- - 'lib/open_food_network/rack_request_blocker.rb'
-
-# Offense count: 2
-# Cop supports --auto-correct.
-# Configuration parameters: InverseMethods, InverseBlocks.
-Style/InverseMethods:
- Exclude:
- - 'app/controllers/admin/column_preferences_controller.rb'
- - 'spec/support/cancan_helper.rb'
-
-# Offense count: 5
-# Cop supports --auto-correct.
-Style/LineEndConcatenation:
- Exclude:
- - 'lib/spree/core/controller_helpers/respond_with_decorator.rb'
- - 'spec/controllers/spree/admin/base_controller_spec.rb'
-
-# Offense count: 9
-# Cop supports --auto-correct.
-# Configuration parameters: IgnoredMethods.
-Style/MethodCallWithoutArgsParentheses:
- Exclude:
- - 'app/controllers/spree/admin/payment_methods_controller_decorator.rb'
- - 'app/views/json/_groups.rabl'
- - 'spec/features/consumer/registration_spec.rb'
- - 'spec/models/spree/payment_method_spec.rb'
- - 'spec/support/request/ui_component_helper.rb'
-
-# Offense count: 10
-# Cop supports --auto-correct.
-# Configuration parameters: EnforcedStyle.
-# SupportedStyles: require_parentheses, require_no_parentheses, require_no_parentheses_except_multiline
-Style/MethodDefParentheses:
- Exclude:
- - 'app/helpers/enterprises_helper.rb'
- - 'app/models/spree/product_decorator.rb'
- - 'app/services/order_cycle_distributed_variants.rb'
- - 'lib/open_food_network/feature_toggle.rb'
- - 'lib/open_food_network/group_buy_report.rb'
- - 'spec/support/request/authentication_workflow.rb'
- - 'spec/support/request/ui_component_helper.rb'
- - 'spec/support/request/web_helper.rb'
-
# Offense count: 1
Style/MissingRespondToMissing:
Exclude:
- 'app/helpers/application_helper.rb'
-# Offense count: 6
+# Offense count: 5
Style/MixinUsage:
Exclude:
- 'lib/open_food_network/orders_and_fulfillments_report.rb'
@@ -1922,79 +503,13 @@ Style/MixinUsage:
- 'spec/lib/open_food_network/order_cycle_management_report_spec.rb'
- 'spec/lib/open_food_network/packing_report_spec.rb'
-# Offense count: 4
-# Cop supports --auto-correct.
-Style/MultilineIfModifier:
- Exclude:
- - 'lib/open_food_network/enterprise_issue_validator.rb'
- - 'lib/spree/core/controller_helpers/respond_with_decorator.rb'
-
-# Offense count: 6
-# Cop supports --auto-correct.
-Style/MutableConstant:
- Exclude:
- - 'app/models/enterprise.rb'
- - 'app/models/enterprise_fee.rb'
- - 'lib/discourse/single_sign_on.rb'
-
-# Offense count: 7
-# Cop supports --auto-correct.
-# Configuration parameters: Whitelist.
-# Whitelist: be, be_a, be_an, be_between, be_falsey, be_kind_of, be_instance_of, be_truthy, be_within, eq, eql, end_with, include, match, raise_error, respond_to, start_with
-Style/NestedParenthesizedCalls:
- Exclude:
- - 'app/controllers/admin/enterprises_controller.rb'
- - 'lib/open_food_network/users_and_enterprises_report.rb'
- - 'spec/controllers/shop_controller_spec.rb'
- - 'spec/lib/open_food_network/users_and_enterprises_report_spec.rb'
-
-# Offense count: 4
+# Offense count: 2
Style/NestedTernaryOperator:
Exclude:
- - 'app/serializers/api/admin/product_serializer.rb'
- - 'app/serializers/api/admin/variant_serializer.rb'
- 'app/views/spree/api/products/bulk_show.v1.rabl'
- 'app/views/spree/api/variants/bulk_show.v1.rabl'
-# Offense count: 2
-# Cop supports --auto-correct.
-# Configuration parameters: EnforcedStyle, MinBodyLength.
-# SupportedStyles: skip_modifier_ifs, always
-Style/Next:
- Exclude:
- - 'lib/tasks/data.rake'
-
-# Offense count: 6
-# Cop supports --auto-correct.
-Style/NilComparison:
- Exclude:
- - 'lib/discourse/single_sign_on.rb'
- - 'lib/open_food_network/order_grouper.rb'
- - 'spec/features/consumer/shopping/shopping_spec.rb'
- - 'spec/models/order_cycle_spec.rb'
- - 'spec/models/spree/order_spec.rb'
-
-# Offense count: 1
-# Cop supports --auto-correct.
-Style/Not:
- Exclude:
- - 'app/models/spree/order_decorator.rb'
-
-# Offense count: 16
-# Cop supports --auto-correct.
-# Configuration parameters: EnforcedOctalStyle.
-# SupportedOctalStyles: zero_with_o, zero_only
-Style/NumericLiteralPrefix:
- Exclude:
- - 'spec/features/admin/order_cycles_spec.rb'
-
-# Offense count: 12
-# Cop supports --auto-correct.
-# Configuration parameters: Strict.
-Style/NumericLiterals:
- MinDigits: 11
-
-# Offense count: 14
+# Offense count: 10
# Cop supports --auto-correct.
# Configuration parameters: AutoCorrect, EnforcedStyle.
# SupportedStyles: predicate, comparison
@@ -2010,118 +525,12 @@ Style/NumericPredicate:
- 'lib/open_food_network/xero_invoices_report.rb'
- 'lib/spree/money_decorator.rb'
-# Offense count: 2
-# Cop supports --auto-correct.
-Style/OneLineConditional:
- Exclude:
- - 'app/controllers/spree/admin/orders_controller_decorator.rb'
-
-# Offense count: 1
-# Cop supports --auto-correct.
-# Configuration parameters: AllowSafeAssignment, AllowInMultilineConditions.
-Style/ParenthesesAroundCondition:
- Exclude:
- - 'app/controllers/checkout_controller.rb'
-
-# Offense count: 1
-# Cop supports --auto-correct.
-# Configuration parameters: EnforcedStyle.
-# SupportedStyles: short, verbose
-Style/PreferredHashMethods:
- Exclude:
- - 'app/controllers/spree/orders_controller_decorator.rb'
-
-# Offense count: 18
-# Cop supports --auto-correct.
-Style/Proc:
- Exclude:
- - 'spec/lib/open_food_network/order_grouper_spec.rb'
- - 'spec/lib/open_food_network/reports/report_spec.rb'
- - 'spec/lib/open_food_network/reports/row_spec.rb'
- - 'spec/lib/open_food_network/reports/rule_spec.rb'
-
-# Offense count: 5
-# Cop supports --auto-correct.
-# Configuration parameters: EnforcedStyle.
-# SupportedStyles: compact, exploded
-Style/RaiseArgs:
- Exclude:
- - 'app/controllers/discourse_sso_controller.rb'
- - 'lib/open_food_network/cached_products_renderer.rb'
- - 'lib/open_food_network/products_renderer.rb'
- - 'spec/models/spree/tax_rate_spec.rb'
-
-# Offense count: 2
-# Cop supports --auto-correct.
-Style/RedundantBegin:
- Exclude:
- - 'app/controllers/shop_controller.rb'
- - 'app/models/spree/product_decorator.rb'
-
-# Offense count: 4
-# Cop supports --auto-correct.
-Style/RedundantException:
- Exclude:
- - 'lib/discourse/single_sign_on.rb'
-
-# Offense count: 9
-# Cop supports --auto-correct.
-Style/RedundantParentheses:
- Exclude:
- - 'lib/open_food_network/bulk_coop_report.rb'
- - 'lib/spree/core/controller_helpers/respond_with_decorator.rb'
- - 'lib/spree/product_filters.rb'
- - 'spec/controllers/admin/enterprises_controller_spec.rb'
- - 'spec/features/admin/bulk_product_update_spec.rb'
-
-# Offense count: 8
-# Cop supports --auto-correct.
-# Configuration parameters: AllowMultipleReturnValues.
-Style/RedundantReturn:
- Exclude:
- - 'app/controllers/admin/enterprise_fees_controller.rb'
- - 'app/controllers/admin/enterprises_controller.rb'
- - 'app/models/enterprise_fee.rb'
- - 'app/models/spree/adjustment_decorator.rb'
- - 'app/models/spree/classification_decorator.rb'
- - 'app/serializers/api/admin/enterprise_serializer.rb'
-
-# Offense count: 95
-# Cop supports --auto-correct.
-Style/RedundantSelf:
- Exclude:
- - 'app/models/calculator/flat_percent_per_item.rb'
- - 'app/models/enterprise.rb'
- - 'app/models/exchange.rb'
- - 'app/models/order_cycle.rb'
- - 'app/models/producer_property.rb'
- - 'app/models/spree/calculator/flat_percent_item_total_decorator.rb'
- - 'app/models/spree/calculator/flexi_rate_decorator.rb'
- - 'app/models/spree/calculator/per_item_decorator.rb'
- - 'app/models/spree/gateway/migs.rb'
- - 'app/models/spree/gateway/pin.rb'
- - 'app/models/spree/line_item_decorator.rb'
- - 'app/models/spree/order_decorator.rb'
- - 'app/models/spree/payment_method_decorator.rb'
- - 'app/models/spree/product_decorator.rb'
- - 'app/models/spree/product_option_type_decorator.rb'
- - 'app/models/spree/shipping_method_decorator.rb'
- - 'app/models/spree/tax_rate_decorator.rb'
- - 'app/models/spree/taxon_decorator.rb'
- - 'app/models/spree/user_decorator.rb'
- - 'app/models/spree/variant_decorator.rb'
- - 'lib/open_food_network/locking.rb'
- - 'lib/open_food_network/rack_request_blocker.rb'
- - 'lib/open_food_network/reports/report.rb'
- - 'lib/open_food_network/variant_and_line_item_naming.rb'
-
-# Offense count: 16
+# Offense count: 15
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, AllowInnerSlashes.
# SupportedStyles: slashes, percent_r, mixed
Style/RegexpLiteral:
Exclude:
- - 'app/controllers/admin/enterprises_controller.rb'
- 'app/helpers/groups_helper.rb'
- 'app/helpers/html_helper.rb'
- 'app/models/enterprise.rb'
@@ -2131,23 +540,16 @@ Style/RegexpLiteral:
- 'spec/mailers/subscription_mailer_spec.rb'
- 'spec/models/content_configuration_spec.rb'
-# Offense count: 2
-# Cop supports --auto-correct.
-Style/RescueModifier:
- Exclude:
- - 'app/controllers/application_controller.rb'
- - 'lib/tasks/data.rake'
-
-# Offense count: 266
+# Offense count: 244
Style/Send:
Exclude:
+ - 'app/models/spree/shipping_method_decorator.rb'
- 'spec/controllers/admin/subscriptions_controller_spec.rb'
- 'spec/controllers/checkout_controller_spec.rb'
- 'spec/controllers/shop_controller_spec.rb'
- 'spec/controllers/spree/admin/base_controller_spec.rb'
- 'spec/controllers/spree/orders_controller_spec.rb'
- 'spec/helpers/order_cycles_helper_spec.rb'
- - 'spec/jobs/refresh_products_cache_job_spec.rb'
- 'spec/jobs/subscription_confirm_job_spec.rb'
- 'spec/jobs/subscription_placement_job_spec.rb'
- 'spec/lib/open_food_network/address_finder_spec.rb'
@@ -2168,9 +570,7 @@ Style/Send:
- 'spec/lib/stripe/webhook_handler_spec.rb'
- 'spec/models/enterprise_spec.rb'
- 'spec/models/exchange_spec.rb'
- - 'spec/models/order_cycle_spec.rb'
- 'spec/models/spree/gateway/stripe_connect_spec.rb'
- - 'spec/models/spree/line_item_spec.rb'
- 'spec/models/spree/order_spec.rb'
- 'spec/models/spree/payment_spec.rb'
- 'spec/models/spree/preference_spec.rb'
@@ -2184,135 +584,8 @@ Style/Send:
- 'spec/spec_helper.rb'
- 'spec/support/localized_number_helper.rb'
- 'spec/support/matchers/delegate_matchers.rb'
- - 'spec/support/request/web_helper.rb'
-
-# Offense count: 3
-# Cop supports --auto-correct.
-# Configuration parameters: EnforcedStyle.
-# SupportedStyles: require_parentheses, require_no_parentheses
-Style/StabbyLambdaParentheses:
- Exclude:
- - 'app/models/spree/product_decorator.rb'
- - 'app/models/spree/variant_decorator.rb'
-
-# Offense count: 14
-# Cop supports --auto-correct.
-# Configuration parameters: EnforcedStyle.
-# SupportedStyles: single_quotes, double_quotes
-Style/StringLiteralsInInterpolation:
- Exclude:
- - 'app/controllers/application_controller.rb'
- - 'lib/discourse/single_sign_on.rb'
- - 'lib/open_food_network/users_and_enterprises_report.rb'
- - 'spec/features/admin/bulk_order_management_spec.rb'
- - 'spec/support/cancan_helper.rb'
# Offense count: 1
Style/StructInheritance:
Exclude:
- 'lib/open_food_network/enterprise_fee_applicator.rb'
-
-# Offense count: 90
-# Cop supports --auto-correct.
-# Configuration parameters: IgnoredMethods.
-# IgnoredMethods: respond_to, define_method
-Style/SymbolProc:
- Exclude:
- - 'app/helpers/angular_form_helper.rb'
- - 'app/helpers/spree/admin/navigation_helper_decorator.rb'
- - 'app/models/spree/product_decorator.rb'
- - 'app/views/json/_producer.rabl'
- - 'app/views/json/partials/_enterprise.rabl'
- - 'app/views/spree/admin/variants/search.rabl'
- - 'app/views/spree/api/products/bulk_show.v1.rabl'
- - 'lib/open_food_network/bulk_coop_report.rb'
- - 'lib/open_food_network/group_buy_report.rb'
- - 'lib/open_food_network/lettuce_share_report.rb'
- - 'lib/open_food_network/orders_and_fulfillments_report.rb'
- - 'lib/open_food_network/packing_report.rb'
- - 'lib/open_food_network/payments_report.rb'
- - 'lib/open_food_network/permissions.rb'
- - 'lib/open_food_network/reports/bulk_coop_allocation_report.rb'
- - 'lib/open_food_network/reports/bulk_coop_supplier_report.rb'
- - 'lib/spree/product_filters.rb'
- - 'spec/controllers/api/order_cycles_controller_spec.rb'
- - 'spec/controllers/spree/api/products_controller_spec.rb'
- - 'spec/controllers/spree/api/variants_controller_spec.rb'
- - 'spec/features/admin/bulk_product_update_spec.rb'
- - 'spec/features/admin/order_cycles_spec.rb'
- - 'spec/lib/open_food_network/group_buy_report_spec.rb'
- - 'spec/lib/open_food_network/order_grouper_spec.rb'
-
-# Offense count: 5
-# Cop supports --auto-correct.
-# Configuration parameters: EnforcedStyle, AllowSafeAssignment.
-# SupportedStyles: require_parentheses, require_no_parentheses, require_parentheses_when_complex
-Style/TernaryParentheses:
- Exclude:
- - 'app/controllers/admin/enterprises_controller.rb'
- - 'app/controllers/spree/admin/payment_methods_controller_decorator.rb'
- - 'app/controllers/spree/admin/shipping_methods_controller_decorator.rb'
-
-# Offense count: 1
-# Cop supports --auto-correct.
-# Configuration parameters: AllowNamedUnderscoreVariables.
-Style/TrailingUnderscoreVariable:
- Exclude:
- - 'lib/open_food_network/option_value_namer.rb'
-
-# Offense count: 3
-# Cop supports --auto-correct.
-Style/UnlessElse:
- Exclude:
- - 'app/models/enterprise.rb'
- - 'lib/open_food_network/order_grouper.rb'
-
-# Offense count: 5
-# Cop supports --auto-correct.
-Style/UnneededCondition:
- Exclude:
- - 'app/controllers/admin/resource_controller.rb'
- - 'app/controllers/application_controller.rb'
- - 'app/serializers/api/order_serializer.rb'
-
-# Offense count: 33
-# Cop supports --auto-correct.
-Style/UnneededInterpolation:
- Exclude:
- - 'app/controllers/admin/resource_controller.rb'
- - 'app/helpers/angular_form_builder.rb'
- - 'app/helpers/injection_helper.rb'
- - 'lib/discourse/single_sign_on.rb'
- - 'spec/features/admin/bulk_order_management_spec.rb'
- - 'spec/features/admin/bulk_product_update_spec.rb'
- - 'spec/features/admin/order_cycles_spec.rb'
- - 'spec/features/admin/reports_spec.rb'
- - 'spec/lib/open_food_network/order_cycle_form_applicator_spec.rb'
- - 'spec/support/request/ui_component_helper.rb'
-
-# Offense count: 22
-# Cop supports --auto-correct.
-Style/UnneededPercentQ:
- Exclude:
- - 'spec/archive/features/consumer/checkout_spec.rb'
- - 'spec/features/admin/adjustments_spec.rb'
- - 'spec/features/admin/bulk_order_management_spec.rb'
- - 'spec/features/admin/bulk_product_update_spec.rb'
- - 'spec/features/admin/content_spec.rb'
- - 'spec/features/admin/enterprise_fees_spec.rb'
- - 'spec/features/admin/enterprise_groups_spec.rb'
- - 'spec/features/admin/enterprise_relationships_spec.rb'
- - 'spec/features/admin/enterprise_roles_spec.rb'
- - 'spec/features/admin/enterprise_user_spec.rb'
- - 'spec/features/admin/enterprises_spec.rb'
- - 'spec/features/admin/image_settings_spec.rb'
- - 'spec/features/admin/order_cycles_spec.rb'
- - 'spec/features/admin/orders_spec.rb'
- - 'spec/features/admin/overview_spec.rb'
- - 'spec/features/admin/payment_method_spec.rb'
- - 'spec/features/admin/products_spec.rb'
- - 'spec/features/admin/reports_spec.rb'
- - 'spec/features/admin/variant_overrides_spec.rb'
- - 'spec/features/admin/variants_spec.rb'
- - 'spec/features/consumer/account_spec.rb'
- - 'spec/features/consumer/producers_spec.rb'
diff --git a/Gemfile b/Gemfile
index 591c43b87c..004f96da71 100644
--- a/Gemfile
+++ b/Gemfile
@@ -2,11 +2,11 @@ source 'https://rubygems.org'
ruby "2.1.5"
git_source(:github) { |repo_name| "https://github.com/#{repo_name}.git" }
+gem 'i18n', '~> 0.6.11'
+gem 'i18n-js', '~> 3.2.2'
gem 'rails', '~> 3.2.22'
gem 'rails-i18n', '~> 3.0.0'
gem 'rails_safe_tasks', '~> 1.0'
-gem 'i18n', '~> 0.6.11'
-gem 'i18n-js', '~> 3.2.2'
# Patched version. See http://rubysec.com/advisories/CVE-2015-5312/.
gem 'nokogiri', '>= 1.6.7.1'
@@ -21,8 +21,8 @@ gem 'pg'
# for details.
gem 'spree', github: 'openfoodfoundation/spree', branch: '2-0-4-stable'
-gem 'spree_i18n', github: 'spree/spree_i18n', branch: '1-3-stable'
gem 'spree_auth_devise', github: 'spree/spree_auth_devise', branch: '2-0-stable'
+gem 'spree_i18n', github: 'spree/spree_i18n', branch: '1-3-stable'
# Our branch contains two changes
# - Pass customer email and phone number to PayPal (merged to upstream master)
@@ -34,51 +34,51 @@ gem 'stripe'
# which is needed for Pin Payments (and possibly others).
gem 'activemerchant', '~> 1.78'
-gem 'oauth2', '~> 1.4.1' # Used for Stripe Connect
gem 'jwt', '~> 2.1'
+gem 'oauth2', '~> 1.4.1' # Used for Stripe Connect
-gem 'delayed_job_active_record'
gem 'daemons'
+gem 'delayed_job_active_record'
gem 'delayed_job_web'
# Fix bug in simple_form preventing collection_check_boxes usage within form_for block
# When merged, revert to upstream gem
gem 'simple_form', github: 'RohanM/simple_form'
-gem 'unicorn'
+gem 'andand'
gem 'angularjs-rails', '1.5.5'
+gem 'aws-sdk'
gem 'bugsnag'
+gem 'db2fog'
gem 'haml'
+gem 'rabl'
+gem 'redcarpet'
gem 'sass', "~> 3.3"
gem 'sass-rails', '~> 3.2.3', groups: [:default, :assets]
-gem 'redcarpet'
-gem 'aws-sdk'
-gem 'db2fog'
-gem 'andand'
gem 'truncate_html'
-gem 'rabl'
+gem 'unicorn'
# AMS is pinned to 0.8.4 because 0.9.x is a complete re-write, as is 0.10.x
# Once Rails is updated to 5.x we should bump directly to 0.10.x
gem "active_model_serializers", "0.8.4"
-gem 'oj'
-gem 'deface', '1.0.2'
-gem 'paperclip', '~> 3.4.1'
+gem 'acts-as-taggable-on', '~> 3.4'
+gem 'angularjs-file-upload-rails', '~> 2.4.1'
+gem 'blockenspiel'
+gem 'custom_error_message', github: 'jeremydurham/custom-err-msg'
gem 'dalli'
+gem 'deface', '1.0.2'
+gem 'diffy'
+gem 'figaro'
gem 'geocoder'
gem 'gmaps4rails'
-gem 'spinjs-rails'
-gem 'rack-ssl', require: 'rack/ssl'
-gem 'rack-rewrite'
-gem 'custom_error_message', github: 'jeremydurham/custom-err-msg'
-gem 'angularjs-file-upload-rails', '~> 2.4.1'
-gem 'roadie-rails', '~> 1.1.1'
-gem 'figaro'
-gem 'blockenspiel'
-gem 'acts-as-taggable-on', '~> 3.4'
+gem 'oj'
gem 'paper_trail', '~> 5.2.3'
-gem 'diffy'
+gem 'paperclip', '~> 3.4.1'
+gem 'rack-rewrite'
+gem 'rack-ssl', require: 'rack/ssl'
+gem 'roadie-rails', '~> 1.1.1'
gem 'skylight', '< 2.0'
+gem 'spinjs-rails'
gem 'combine_pdf'
gem 'wicked_pdf'
@@ -94,64 +94,64 @@ gem 'whenever', require: false
# Gems used only for assets and not required
# in production environments by default.
group :assets do
- gem 'compass-rails'
gem 'coffee-rails', '~> 3.2.1'
+ gem 'compass-rails'
gem 'therubyracer', '=0.12.0'
gem 'uglifier', '>= 1.0.3'
- gem 'turbo-sprockets-rails3'
+ gem 'angular-rails-templates', '~> 0.3.0'
gem 'foundation-icons-sass-rails'
gem 'momentjs-rails'
- gem 'angular-rails-templates', '~> 0.3.0'
+ gem 'turbo-sprockets-rails3'
end
gem "foundation-rails"
gem 'foundation_rails_helper', github: 'willrjmarshall/foundation_rails_helper', branch: "rails3"
-gem 'jquery-rails', '3.0.4'
gem 'jquery-migrate-rails'
+gem 'jquery-rails', '3.0.4'
gem 'ofn-qz', github: 'openfoodfoundation/ofn-qz', ref: '60da2ae4c44cbb4c8d602f59fb5fff8d0f21db3c'
group :test, :development do
# Pretty printed test output
- gem 'fuubar', '~> 2.3.2'
- gem 'rspec-rails', ">= 3.5.2"
- gem 'shoulda-matchers'
- gem "factory_bot_rails", require: false
+ gem 'atomic'
+ gem 'awesome_print'
gem 'capybara', '>= 2.15.4'
gem 'database_cleaner', '0.7.1', require: false
- gem 'awesome_print'
- gem 'letter_opener', '>= 1.4.1'
- gem 'timecop'
- gem 'selenium-webdriver'
- gem 'rspec-retry'
+ gem "factory_bot_rails", require: false
+ gem 'fuubar', '~> 2.3.2'
gem 'json_spec', '~> 1.1.4'
- gem 'unicorn-rails'
- gem 'atomic'
gem 'knapsack'
+ gem 'letter_opener', '>= 1.4.1'
+ gem 'rspec-rails', ">= 3.5.2"
+ gem 'rspec-retry'
+ gem 'selenium-webdriver'
+ gem 'shoulda-matchers'
+ gem 'timecop'
+ gem 'unicorn-rails'
gem 'webdrivers', '3.8.1'
end
group :test do
- gem 'webmock'
gem 'simplecov', require: false
+ gem 'webmock'
# See spec/spec_helper.rb for instructions
- #gem 'perftools.rb'
+ # gem 'perftools.rb'
end
group :development do
gem 'byebug', '~> 9.0.0' # 9.1 requires ruby 2.2
- gem "newrelic_rpm", "~> 3.0"
- gem 'pry-byebug', '>= 3.4.3'
gem 'debugger-linecache'
gem 'guard'
- gem 'listen', '3.0.8' # 3.1.0 requires ruby 2.2
gem 'guard-livereload'
gem 'guard-rails'
gem 'guard-rspec', '~> 4.7.3'
+ gem 'listen', '3.0.8' # 3.1.0 requires ruby 2.2
+ gem "newrelic_rpm", "~> 3.0"
+ gem 'pry-byebug', '>= 3.4.3'
gem 'rubocop', '>= 0.49.1'
gem 'spring', '1.7.2'
gem 'spring-commands-rspec'
diff --git a/Rakefile b/Rakefile
old mode 100644
new mode 100755
diff --git a/app/controllers/admin/bulk_line_items_controller.rb b/app/controllers/admin/bulk_line_items_controller.rb
index c0c1b60b91..bea712bc41 100644
--- a/app/controllers/admin/bulk_line_items_controller.rb
+++ b/app/controllers/admin/bulk_line_items_controller.rb
@@ -22,9 +22,9 @@ module Admin
order.with_lock do
if @line_item.update_attributes(params[:line_item])
order.update_distribution_charge!
- render nothing: true, status: 204 # No Content, does not trigger ng resource auto-update
+ render nothing: true, status: :no_content # No Content, does not trigger ng resource auto-update
else
- render json: { errors: @line_item.errors }, status: 412
+ render json: { errors: @line_item.errors }, status: :precondition_failed
end
end
end
@@ -36,7 +36,7 @@ module Admin
authorize! :update, order
@line_item.destroy
- render nothing: true, status: 204 # No Content, does not trigger ng resource auto-update
+ render nothing: true, status: :no_content # No Content, does not trigger ng resource auto-update
end
private
diff --git a/app/controllers/admin/column_preferences_controller.rb b/app/controllers/admin/column_preferences_controller.rb
index 0a9300d71c..64c028b104 100644
--- a/app/controllers/admin/column_preferences_controller.rb
+++ b/app/controllers/admin/column_preferences_controller.rb
@@ -12,9 +12,9 @@ module Admin
render json: @cp_set.collection, each_serializer: Api::Admin::ColumnPreferenceSerializer
else
if @cp_set.errors.present?
- render json: { errors: @cp_set.errors }, status: 400
+ render json: { errors: @cp_set.errors }, status: :bad_request
else
- render nothing: true, status: 500
+ render nothing: true, status: :internal_server_error
end
end
end
@@ -23,7 +23,7 @@ module Admin
def load_collection
collection_hash = Hash[params[:column_preferences].each_with_index.map { |cp, i| [i, cp] }]
- collection_hash.reject!{ |i, cp| cp[:action_name] != params[:action_name] }
+ collection_hash.select!{ |_i, cp| cp[:action_name] == params[:action_name] }
@cp_set = ColumnPreferenceSet.new @column_preferences, collection_attributes: collection_hash
end
diff --git a/app/controllers/admin/contents_controller.rb b/app/controllers/admin/contents_controller.rb
index 44569a42e1..7443ac6717 100644
--- a/app/controllers/admin/contents_controller.rb
+++ b/app/controllers/admin/contents_controller.rb
@@ -16,7 +16,7 @@ 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 e5368077d7..b1fdac2e5c 100644
--- a/app/controllers/admin/customers_controller.rb
+++ b/app/controllers/admin/customers_controller.rb
@@ -34,7 +34,7 @@ module Admin
tag_rule_mapping = TagRule.mapping_for(Enterprise.where(id: @customer.enterprise))
render_as_json @customer, tag_rule_mapping: tag_rule_mapping
else
- render json: { errors: @customer.errors.full_messages }, status: 400
+ render json: { errors: @customer.errors.full_messages }, status: :bad_request
end
else
redirect_to '/unauthorized'
diff --git a/app/controllers/admin/enterprise_fees_controller.rb b/app/controllers/admin/enterprise_fees_controller.rb
index 46e2b535fb..1b1f3cee80 100644
--- a/app/controllers/admin/enterprise_fees_controller.rb
+++ b/app/controllers/admin/enterprise_fees_controller.rb
@@ -1,9 +1,8 @@
module Admin
class EnterpriseFeesController < ResourceController
- before_filter :load_enterprise_fee_set, :only => :index
+ before_filter :load_enterprise_fee_set, only: :index
before_filter :load_data
-
def index
@include_calculators = params[:include_calculators].present?
@enterprise = current_enterprise
@@ -34,18 +33,17 @@ module Admin
if params.key? :enterprise_id
redirect_path = main_app.admin_enterprise_fees_path(enterprise_id: params[:enterprise_id])
end
- redirect_to redirect_path, :notice => I18n.t(:enterprise_fees_update_notice)
+ redirect_to redirect_path, notice: I18n.t(:enterprise_fees_update_notice)
else
render :index
end
end
-
private
def load_enterprise_fee_set
- @enterprise_fee_set = EnterpriseFeeSet.new :collection => collection
+ @enterprise_fee_set = EnterpriseFeeSet.new collection: collection
end
def load_data
@@ -60,7 +58,7 @@ module Admin
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
- return EnterpriseFee.for_enterprises(enterprises).order('enterprise_id', 'fee_type', 'name')
+ 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 = collection.for_enterprise(current_enterprise) if current_enterprise
@@ -75,6 +73,5 @@ module Admin
def current_enterprise
Enterprise.find params[:enterprise_id] if params.key? :enterprise_id
end
-
end
end
diff --git a/app/controllers/admin/enterprise_relationships_controller.rb b/app/controllers/admin/enterprise_relationships_controller.rb
index 7ef435d7ed..0ffb648f44 100644
--- a/app/controllers/admin/enterprise_relationships_controller.rb
+++ b/app/controllers/admin/enterprise_relationships_controller.rb
@@ -12,7 +12,7 @@ module Admin
if @enterprise_relationship.save
render text: Api::Admin::EnterpriseRelationshipSerializer.new(@enterprise_relationship).to_json
else
- render status: 400, 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 8ffc2bad01..98810e2a64 100644
--- a/app/controllers/admin/enterprise_roles_controller.rb
+++ b/app/controllers/admin/enterprise_roles_controller.rb
@@ -13,7 +13,7 @@ module Admin
render text: Api::Admin::EnterpriseRoleSerializer.new(@enterprise_role).to_json
else
- render status: 400, 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 c59f610436..05be3d6de2 100644
--- a/app/controllers/admin/enterprises_controller.rb
+++ b/app/controllers/admin/enterprises_controller.rb
@@ -6,11 +6,11 @@ module Admin
prepend_before_filter :override_owner, only: :create
prepend_before_filter :override_sells, only: :create
- before_filter :load_enterprise_set, :only => :index
- before_filter :load_countries, :except => [:index, :register, :check_permalink]
- before_filter :load_methods_and_fees, :only => [:edit, :update]
- before_filter :load_groups, :only => [:new, :edit, :update, :create]
- before_filter :load_taxons, :only => [:new, :edit, :update, :create]
+ before_filter :load_enterprise_set, only: :index
+ before_filter :load_countries, except: [:index, :register, :check_permalink]
+ before_filter :load_methods_and_fees, only: [:edit, :update]
+ before_filter :load_groups, only: [:new, :edit, :update, :create]
+ before_filter :load_taxons, only: [:new, :edit, :update, :create]
before_filter :check_can_change_sells, only: :update
before_filter :check_can_change_bulk_sells, only: :bulk_update
before_filter :check_can_change_owner, only: :update
@@ -45,7 +45,7 @@ module Admin
flash[:success] = flash_message_for(@object, :successfully_updated)
respond_with(@object) do |format|
format.html { redirect_to location_after_save }
- format.js { render :layout => false }
+ format.js { render layout: false }
format.json { render_as_json @object, ams_prefix: 'index', spree_current_user: spree_current_user }
end
else
@@ -142,7 +142,7 @@ 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?
- return OpenFoodNetwork::OrderCyclePermissions.new(spree_current_user, @order_cycle).visible_enterprises
+ OpenFoodNetwork::OrderCyclePermissions.new(spree_current_user, @order_cycle).visible_enterprises
when :index
if spree_current_user.admin?
OpenFoodNetwork::Permissions.new(spree_current_user).
@@ -168,8 +168,8 @@ module Admin
end
def load_methods_and_fees
- @payment_methods = Spree::PaymentMethod.managed_by(spree_current_user).sort_by!{ |pm| [(@enterprise.payment_methods.include? pm) ? 0 : 1, pm.name] }
- @shipping_methods = Spree::ShippingMethod.managed_by(spree_current_user).sort_by!{ |sm| [(@enterprise.shipping_methods.include? sm) ? 0 : 1, sm.name] }
+ @payment_methods = Spree::PaymentMethod.managed_by(spree_current_user).sort_by!{ |pm| [@enterprise.payment_methods.include? pm ? 0 : 1, pm.name] }
+ @shipping_methods = Spree::ShippingMethod.managed_by(spree_current_user).sort_by!{ |sm| [@enterprise.shipping_methods.include? sm ? 0 : 1, sm.name] }
@enterprise_fees = EnterpriseFee.managed_by(spree_current_user).for_enterprise(@enterprise).order(:fee_type, :name).all
end
@@ -187,8 +187,8 @@ module Admin
# methods that are specific to each class do not become available until after the
# record is persisted. This problem is compounded by the use of calculators.
@object.transaction do
- tag_rules_attributes.select{ |i, attrs| attrs[:type].present? }.each do |i, attrs|
- rule = @object.tag_rules.find_by_id(attrs.delete :id) || attrs[:type].constantize.new(enterprise: @object)
+ tag_rules_attributes.select{ |_i, attrs| attrs[:type].present? }.each do |_i, attrs|
+ rule = @object.tag_rules.find_by_id(attrs.delete(:id)) || attrs[:type].constantize.new(enterprise: @object)
create_calculator_for(rule, attrs) if rule.type == "TagRule::DiscountOrder" && rule.calculator.nil?
rule.update_attributes(attrs)
end
@@ -204,13 +204,13 @@ module Admin
def create_calculator_for(rule, attrs)
if attrs[:calculator_type].present? && attrs[:calculator_attributes].present?
rule.update_attributes(calculator_type: attrs[:calculator_type])
- attrs[:calculator_attributes].merge!( { id: rule.calculator.id } )
+ attrs[:calculator_attributes].merge!( id: rule.calculator.id )
end
end
def check_can_change_bulk_sells
unless spree_current_user.admin?
- params[:enterprise_set][:collection_attributes].each do |i, enterprise_params|
+ params[:enterprise_set][:collection_attributes].each do |_i, enterprise_params|
enterprise_params.delete :sells unless spree_current_user == Enterprise.find_by_id(enterprise_params[:id]).owner
end
end
@@ -230,7 +230,7 @@ module Admin
unless spree_current_user.admin?
has_hub = spree_current_user.owned_enterprises.is_hub.any?
new_enterprise_is_producer = Enterprise.new(params[:enterprise]).is_primary_producer
- params[:enterprise][:sells] = (has_hub && !new_enterprise_is_producer) ? 'any' : 'none'
+ params[:enterprise][:sells] = has_hub && !new_enterprise_is_producer ? 'any' : 'none'
end
end
@@ -242,7 +242,7 @@ module Admin
def check_can_change_bulk_owner
unless spree_current_user.admin?
- params[:enterprise_set][:collection_attributes].each do |i, enterprise_params|
+ params[:enterprise_set][:collection_attributes].each do |_i, enterprise_params|
enterprise_params.delete :owner_id
end
end
@@ -273,7 +273,7 @@ module Admin
# Overriding method on Spree's resource controller
def location_after_save
- referer_path = OpenFoodNetwork::RefererParser::path(request.referer)
+ referer_path = OpenFoodNetwork::RefererParser.path(request.referer)
refered_from_producer_properties = referer_path =~ /\/producer_properties$/
if refered_from_producer_properties
diff --git a/app/controllers/admin/inventory_items_controller.rb b/app/controllers/admin/inventory_items_controller.rb
index 6fd382d0d5..4567c64632 100644
--- a/app/controllers/admin/inventory_items_controller.rb
+++ b/app/controllers/admin/inventory_items_controller.rb
@@ -1,6 +1,5 @@
module Admin
class InventoryItemsController < ResourceController
-
respond_to :json
respond_override update: { json: {
diff --git a/app/controllers/admin/manager_invitations_controller.rb b/app/controllers/admin/manager_invitations_controller.rb
index 5849aa2880..45898bd5eb 100644
--- a/app/controllers/admin/manager_invitations_controller.rb
+++ b/app/controllers/admin/manager_invitations_controller.rb
@@ -20,7 +20,7 @@ module Admin
if new_user
render json: { user: new_user.id }, status: :ok
else
- render json: { errors: t('admin.enterprises.invite_manager.error') }, status: 500
+ render json: { errors: t('admin.enterprises.invite_manager.error') }, status: :internal_server_error
end
end
diff --git a/app/controllers/admin/order_cycles_controller.rb b/app/controllers/admin/order_cycles_controller.rb
index 984cef4b61..03462e363e 100644
--- a/app/controllers/admin/order_cycles_controller.rb
+++ b/app/controllers/admin/order_cycles_controller.rb
@@ -53,7 +53,7 @@ module Admin
respond_to do |format|
flash[:notice] = I18n.t(:order_cycles_update_notice) if params[:reloading] == '1'
format.html { redirect_to main_app.edit_admin_order_cycle_path(@order_cycle) }
- format.json { render json: { :success => true } }
+ format.json { render json: { success: true } }
end
else
render json: { errors: @order_cycle.errors.full_messages }, status: :unprocessable_entity
@@ -82,20 +82,19 @@ module Admin
redirect_to main_app.admin_order_cycles_path, notice: I18n.t(:order_cycles_email_to_producers_notice)
end
-
protected
def collection
return Enterprise.where("1=0") unless json_request?
return order_cycles_from_set if params[:order_cycle_set]
ocs = if params[:as] == "distributor"
- OrderCycle.preload(:schedules).ransack(params[:q]).result.
- involving_managed_distributors_of(spree_current_user).order('updated_at DESC')
- elsif params[:as] == "producer"
- OrderCycle.preload(:schedules).ransack(params[:q]).result.
- involving_managed_producers_of(spree_current_user).order('updated_at DESC')
- else
- OrderCycle.preload(:schedules).ransack(params[:q]).result.accessible_by(spree_current_user)
+ OrderCycle.preload(:schedules).ransack(params[:q]).result.
+ involving_managed_distributors_of(spree_current_user).order('updated_at DESC')
+ elsif params[:as] == "producer"
+ OrderCycle.preload(:schedules).ransack(params[:q]).result.
+ involving_managed_producers_of(spree_current_user).order('updated_at DESC')
+ else
+ OrderCycle.preload(:schedules).ransack(params[:q]).result.accessible_by(spree_current_user)
end
ocs.undated |
@@ -115,7 +114,7 @@ module Admin
# Split ransack params into all those that currently exist and new ones to limit returned ocs to recent or undated
orders_close_at_gt = params[:q].andand.delete(:orders_close_at_gt) || 31.days.ago
params[:q] = {
- g: [ params.delete(:q) || {}, { m: 'or', orders_close_at_gt: orders_close_at_gt, orders_close_at_null: true } ]
+ g: [params.delete(:q) || {}, { m: 'or', orders_close_at_gt: orders_close_at_gt, orders_close_at_null: true }]
}
@collection = collection
end
@@ -158,7 +157,7 @@ module Admin
params[:order_cycle].delete :coordinator_id
unless Enterprise.managed_by(spree_current_user).include?(@order_cycle.coordinator)
- params[:order_cycle].delete_if{ |k,v| [:name, :orders_open_at, :orders_close_at].include? k.to_sym }
+ params[:order_cycle].delete_if{ |k, _v| [:name, :orders_open_at, :orders_close_at].include? k.to_sym }
end
end
@@ -173,7 +172,7 @@ module Admin
def order_cycles_from_set
remove_unauthorized_bulk_attrs
- OrderCycle.where(id: params[:order_cycle_set][:collection_attributes].map{ |k,v| v[:id] })
+ OrderCycle.where(id: params[:order_cycle_set][:collection_attributes].map{ |_k, v| v[:id] })
end
def order_cycle_set
diff --git a/app/controllers/admin/producer_properties_controller.rb b/app/controllers/admin/producer_properties_controller.rb
index aca3e3f418..7bc021c04e 100644
--- a/app/controllers/admin/producer_properties_controller.rb
+++ b/app/controllers/admin/producer_properties_controller.rb
@@ -4,7 +4,6 @@ module Admin
before_filter :load_properties
before_filter :setup_property, only: [:index]
-
private
def collection_url
diff --git a/app/controllers/admin/resource_controller.rb b/app/controllers/admin/resource_controller.rb
index 19a98dc337..6d68da1044 100644
--- a/app/controllers/admin/resource_controller.rb
+++ b/app/controllers/admin/resource_controller.rb
@@ -1,7 +1,7 @@
module Admin
class ResourceController < Spree::Admin::ResourceController
def model_class
- "#{controller_name.classify}".constantize
+ controller_name.classify.to_s.constantize
end
# URL helpers
@@ -22,7 +22,7 @@ module Admin
end
def object_url(object = nil, options = {})
- target = object ? object : @object
+ target = object || @object
if parent_data.present?
main_app.public_send "admin_#{model_name}_#{object_name}_url", parent, target, options
else
diff --git a/app/controllers/admin/stripe_connect_settings_controller.rb b/app/controllers/admin/stripe_connect_settings_controller.rb
index ad7892d8aa..270ba91528 100644
--- a/app/controllers/admin/stripe_connect_settings_controller.rb
+++ b/app/controllers/admin/stripe_connect_settings_controller.rb
@@ -18,7 +18,7 @@ module Admin
def update
Spree::Config.set(params[:settings])
resource = t('admin.controllers.stripe_connect_settings.resource')
- flash[:success] = t(:successfully_updated, :resource => resource)
+ flash[:success] = t(:successfully_updated, resource: resource)
redirect_to_edit
end
diff --git a/app/controllers/admin/tag_rules_controller.rb b/app/controllers/admin/tag_rules_controller.rb
index 25f5b177d6..c3f0730ccc 100644
--- a/app/controllers/admin/tag_rules_controller.rb
+++ b/app/controllers/admin/tag_rules_controller.rb
@@ -1,10 +1,9 @@
module Admin
class TagRulesController < ResourceController
-
respond_to :json
respond_override destroy: { json: {
- success: lambda { render nothing: true, :status => 204 }
+ success: lambda { render nothing: true, status: :no_content }
} }
def map_by_tag
@@ -16,7 +15,6 @@ module Admin
end
end
-
private
def collection_actions
diff --git a/app/controllers/admin/variant_overrides_controller.rb b/app/controllers/admin/variant_overrides_controller.rb
index 2680e66b32..e12b43825b 100644
--- a/app/controllers/admin/variant_overrides_controller.rb
+++ b/app/controllers/admin/variant_overrides_controller.rb
@@ -9,9 +9,7 @@ module Admin
before_filter :load_collection, only: [:bulk_update]
before_filter :load_spree_api_key, only: :index
-
- def index
- end
+ def index; end
def bulk_update
# Ensure we're authorised to update all variant overrides
@@ -22,9 +20,9 @@ module Admin
render json: @vo_set.collection, each_serializer: Api::Admin::VariantOverrideSerializer
else
if @vo_set.errors.present?
- render json: { errors: @vo_set.errors }, status: 400
+ render json: { errors: @vo_set.errors }, status: :bad_request
else
- render nothing: true, status: 500
+ render nothing: true, status: :internal_server_error
end
end
end
@@ -35,13 +33,12 @@ module Admin
@collection.each(&:reset_stock!)
if collection_errors.present?
- render json: { errors: collection_errors }, status: 400
+ render json: { errors: collection_errors }, status: :bad_request
else
render json: @collection, each_serializer: Api::Admin::VariantOverrideSerializer
end
end
-
private
def load_data
diff --git a/app/controllers/api/customers_controller.rb b/app/controllers/api/customers_controller.rb
index cbbe4ce35f..32b74b0e9d 100644
--- a/app/controllers/api/customers_controller.rb
+++ b/app/controllers/api/customers_controller.rb
@@ -10,7 +10,7 @@ module Api
authorize! :update, @customer
if @customer.update_attributes(params[:customer])
- render json: @customer, serializer: CustomerSerializer, status: 200
+ render json: @customer, serializer: CustomerSerializer, status: :ok
else
invalid_resource!(@customer)
end
diff --git a/app/controllers/api/enterprise_fees_controller.rb b/app/controllers/api/enterprise_fees_controller.rb
index 3d03b28515..c6216a1270 100644
--- a/app/controllers/api/enterprise_fees_controller.rb
+++ b/app/controllers/api/enterprise_fees_controller.rb
@@ -6,9 +6,9 @@ module Api
authorize! :destroy, enterprise_fee
if enterprise_fee.destroy
- render text: I18n.t(:successfully_removed), status: 204
+ render text: I18n.t(:successfully_removed), status: :no_content
else
- render text: enterprise_fee.errors.full_messages.first, status: 403
+ render text: enterprise_fee.errors.full_messages.first, status: :forbidden
end
end
diff --git a/app/controllers/api/enterprises_controller.rb b/app/controllers/api/enterprises_controller.rb
index 666eb0b034..72ea3d9655 100644
--- a/app/controllers/api/enterprises_controller.rb
+++ b/app/controllers/api/enterprises_controller.rb
@@ -1,6 +1,5 @@
module Api
class EnterprisesController < BaseController
-
before_filter :override_owner, only: [:create, :update]
before_filter :check_type, only: :update
before_filter :override_sells, only: [:create, :update]
@@ -17,7 +16,7 @@ module Api
@enterprise = Enterprise.new(params[:enterprise])
if @enterprise.save
- render text: @enterprise.id, :status => 201
+ render text: @enterprise.id, status: :created
else
invalid_resource!(@enterprise)
end
@@ -28,7 +27,7 @@ module Api
authorize! :update, @enterprise
if @enterprise.update_attributes(params[:enterprise])
- render text: @enterprise.id, :status => 200
+ render text: @enterprise.id, status: :ok
else
invalid_resource!(@enterprise)
end
@@ -38,10 +37,10 @@ module Api
@enterprise = Enterprise.find_by_permalink(params[:id]) || Enterprise.find(params[:id])
authorize! :update, @enterprise
- if params[:logo] && @enterprise.update_attributes( { logo: params[:logo] } )
- render text: @enterprise.logo.url(:medium), :status => 200
- elsif params[:promo] && @enterprise.update_attributes( { promo_image: params[:promo] } )
- render text: @enterprise.promo_image.url(:medium), :status => 200
+ if params[:logo] && @enterprise.update_attributes( logo: params[:logo] )
+ render text: @enterprise.logo.url(:medium), status: :ok
+ elsif params[:promo] && @enterprise.update_attributes( promo_image: params[:promo] )
+ render text: @enterprise.promo_image.url(:medium), status: :ok
else
invalid_resource!(@enterprise)
end
diff --git a/app/controllers/api/order_cycles_controller.rb b/app/controllers/api/order_cycles_controller.rb
index dd62c7f4d0..3522c690f2 100644
--- a/app/controllers/api/order_cycles_controller.rb
+++ b/app/controllers/api/order_cycles_controller.rb
@@ -10,13 +10,13 @@ module Api
def accessible
@order_cycles = if params[:as] == "distributor"
- OrderCycle.ransack(params[:q]).result.
- involving_managed_distributors_of(current_api_user).order('updated_at DESC')
- elsif params[:as] == "producer"
- OrderCycle.ransack(params[:q]).result.
- involving_managed_producers_of(current_api_user).order('updated_at DESC')
- else
- OrderCycle.ransack(params[:q]).result.accessible_by(current_api_user)
+ OrderCycle.ransack(params[:q]).result.
+ involving_managed_distributors_of(current_api_user).order('updated_at DESC')
+ elsif params[:as] == "producer"
+ OrderCycle.ransack(params[:q]).result.
+ involving_managed_producers_of(current_api_user).order('updated_at DESC')
+ else
+ OrderCycle.ransack(params[:q]).result.accessible_by(current_api_user)
end
render params[:template] || :bulk_index
diff --git a/app/controllers/api/statuses_controller.rb b/app/controllers/api/statuses_controller.rb
index 49a6f991ff..a2c0ea6350 100644
--- a/app/controllers/api/statuses_controller.rb
+++ b/app/controllers/api/statuses_controller.rb
@@ -3,10 +3,9 @@ module Api
respond_to :json
def job_queue
- render json: {alive: job_queue_alive?}
+ render json: { alive: job_queue_alive? }
end
-
private
def job_queue_alive?
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb
index 14179ca695..ece563a420 100644
--- a/app/controllers/application_controller.rb
+++ b/app/controllers/application_controller.rb
@@ -9,12 +9,16 @@ class ApplicationController < ActionController::Base
include EnterprisesHelper
def redirect_to(options = {}, response_status = {})
- ::Rails.logger.error("Redirected by #{caller(1).first rescue "unknown"}")
+ ::Rails.logger.error("Redirected by #{begin
+ caller(1).first
+ rescue StandardError
+ 'unknown'
+ end}")
super(options, response_status)
end
def set_checkout_redirect
- referer_path = OpenFoodNetwork::RefererParser::path(request.referer)
+ referer_path = OpenFoodNetwork::RefererParser.path(request.referer)
if referer_path
is_checkout_path_the_referer = [main_app.checkout_path].include?(referer_path)
session["spree_user_return_to"] = is_checkout_path_the_referer ? referer_path : root_path
@@ -28,13 +32,13 @@ class ApplicationController < ActionController::Base
def enable_embedded_styles
session[:embedded_shopfront] = true
- render json: {}, status: 200
+ render json: {}, status: :ok
end
def disable_embedded_styles
session.delete :embedded_shopfront
session.delete :shopfront_redirect
- render json: {}, status: 200
+ render json: {}, status: :ok
end
protected
@@ -45,7 +49,7 @@ class ApplicationController < ActionController::Base
end
def after_sign_out_path_for(_resource_or_scope)
- session[:shopfront_redirect] ? session[:shopfront_redirect] : root_path
+ session[:shopfront_redirect] || root_path
end
private
@@ -82,8 +86,8 @@ class ApplicationController < ActionController::Base
# This condition is more rigourous than required by development to avoid coupling this
# condition to every controller spec
if current_distributor && current_order &&
- current_distributor.respond_to?(:ready_for_checkout?) &&
- !current_distributor.ready_for_checkout?
+ current_distributor.respond_to?(:ready_for_checkout?) &&
+ !current_distributor.ready_for_checkout?
current_order.empty!
current_order.set_distribution! nil, nil
@@ -106,10 +110,10 @@ class ApplicationController < ActionController::Base
# Useful for rendering html within a JSON response, particularly if the specified
# template or partial then goes on to render further partials without specifying
# their format.
- def with_format(format, &block)
+ def with_format(format)
old_formats = formats
self.formats = [format]
- block.call
+ yield
self.formats = old_formats
nil
end
@@ -119,5 +123,4 @@ class ApplicationController < ActionController::Base
response.headers["Pragma"] = "no-cache"
response.headers["Expires"] = "Fri, 01 Jan 1990 00:00:00 GMT"
end
-
end
diff --git a/app/controllers/checkout_controller.rb b/app/controllers/checkout_controller.rb
index c0f9c0a21b..d303245197 100644
--- a/app/controllers/checkout_controller.rb
+++ b/app/controllers/checkout_controller.rb
@@ -40,15 +40,15 @@ class CheckoutController < Spree::CheckoutController
next if advance_order_state(@order)
- if @order.errors.present?
- flash[:error] = @order.errors.full_messages.to_sentence
- else
- flash[:error] = t(:payment_processing_failed)
- end
+ flash[:error] = if @order.errors.present?
+ @order.errors.full_messages.to_sentence
+ else
+ t(:payment_processing_failed)
+ end
update_failed
return
end
- return update_failed unless @order.state == "complete" || @order.completed?
+ return update_failed unless @order.state == "complete" || @order.completed?
set_default_bill_address
set_default_ship_address
@@ -59,10 +59,10 @@ class CheckoutController < Spree::CheckoutController
flash[:notice] = t(:order_processed_successfully)
respond_to do |format|
format.html do
- respond_with(@order, :location => order_path(@order))
+ respond_with(@order, location: order_path(@order))
end
format.json do
- render json: {path: order_path(@order)}, status: 200
+ render json: { path: order_path(@order) }, status: :ok
end
end
end
@@ -117,12 +117,11 @@ class CheckoutController < Spree::CheckoutController
" AND source_type = 'Spree::LineItem' AND spree_line_items.id IS NULL")
if phantom_fees.any?
- Bugsnag.notify(RuntimeError.new("Phantom Fees"), {
- phantom_fees: {
- phantom_total: phantom_fees.sum(&:amount).to_s,
- phantom_fees: phantom_fees.as_json
- }
- })
+ Bugsnag.notify(RuntimeError.new("Phantom Fees"),
+ phantom_fees: {
+ phantom_total: phantom_fees.sum(&:amount).to_s,
+ phantom_fees: phantom_fees.as_json
+ })
end
end
@@ -135,7 +134,7 @@ class CheckoutController < Spree::CheckoutController
if params[:payment_source].present? && source_params = params.delete(:payment_source)[params[:order][:payments_attributes].first[:payment_method_id].underscore]
params[:order][:payments_attributes].first[:source_attributes] = source_params
end
- if (params[:order][:payments_attributes])
+ if params[:order][:payments_attributes]
params[:order][:payments_attributes].first[:amount] = @order.total
end
if params[:order][:existing_card_id]
@@ -162,7 +161,7 @@ class CheckoutController < Spree::CheckoutController
render :edit
end
format.json do
- render json: {errors: @order.errors, flash: flash.to_hash}.to_json, status: 400
+ render json: { errors: @order.errors, flash: flash.to_hash }.to_json, status: :bad_request
end
end
end
@@ -182,9 +181,9 @@ class CheckoutController < Spree::CheckoutController
def load_order
@order = current_order
- redirect_to main_app.shop_path and return unless @order and @order.checkout_allowed?
- redirect_to_cart_path and return unless valid_order_line_items?
- redirect_to main_app.shop_path and return if @order.completed?
+ redirect_to(main_app.shop_path) && return unless @order && @order.checkout_allowed?
+ redirect_to_cart_path && return unless valid_order_line_items?
+ redirect_to(main_app.shop_path) && return if @order.completed?
before_address
setup_for_current_state
end
@@ -211,7 +210,7 @@ class CheckoutController < Spree::CheckoutController
end
format.json do
- render json: {path: cart_path}, status: 400
+ render json: { path: cart_path }, status: :bad_request
end
end
end
@@ -221,10 +220,10 @@ class CheckoutController < Spree::CheckoutController
payment_method_id = params[:order][:payments_attributes].first[:payment_method_id]
payment_method = Spree::PaymentMethod.find(payment_method_id)
- return unless payment_method.kind_of?(Spree::Gateway::PayPalExpress)
+ return unless payment_method.is_a?(Spree::Gateway::PayPalExpress)
- render json: {path: spree.paypal_express_path(payment_method_id: payment_method.id)},
- status: 200
+ render json: { path: spree.paypal_express_path(payment_method_id: payment_method.id) },
+ status: :ok
true
end
@@ -248,7 +247,7 @@ class CheckoutController < Spree::CheckoutController
flash[:error] = t(:spree_gateway_error_flash_for_checkout, error: error.message)
respond_to do |format|
format.html { render :edit }
- format.json { render json: { flash: flash.to_hash }, status: 400 }
+ format.json { render json: { flash: flash.to_hash }, status: :bad_request }
end
end
end
diff --git a/app/controllers/discourse_sso_controller.rb b/app/controllers/discourse_sso_controller.rb
index b313711554..17bf6a02e2 100644
--- a/app/controllers/discourse_sso_controller.rb
+++ b/app/controllers/discourse_sso_controller.rb
@@ -41,7 +41,7 @@ class DiscourseSsoController < ApplicationController
end
def require_config
- raise ActionController::RoutingError.new('Not Found') unless discourse_configured?
+ raise ActionController::RoutingError, 'Not Found' unless discourse_configured?
end
def require_activation?
diff --git a/app/controllers/enterprises_controller.rb b/app/controllers/enterprises_controller.rb
index 6a74f58b01..e33a10a296 100644
--- a/app/controllers/enterprises_controller.rb
+++ b/app/controllers/enterprises_controller.rb
@@ -43,14 +43,14 @@ class EnterprisesController < BaseController
def check_permalink
if Enterprise.find_by_permalink params[:permalink]
- render text: params[:permalink], status: 409 and return
+ render(text: params[:permalink], status: :conflict) && return
end
begin
- Rails.application.routes.recognize_path( "/#{ params[:permalink].to_s }" )
- render text: params[:permalink], status: 409
+ Rails.application.routes.recognize_path( "/#{params[:permalink]}" )
+ render text: params[:permalink], status: :conflict
rescue ActionController::RoutingError
- render text: params[:permalink], status: 200
+ render text: params[:permalink], status: :ok
end
end
diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb
index 94dcd7d49c..f8268cf464 100644
--- a/app/controllers/home_controller.rb
+++ b/app/controllers/home_controller.rb
@@ -12,7 +12,5 @@ class HomeController < BaseController
end
end
- def sell
- end
-
+ def sell; end
end
diff --git a/app/controllers/line_items_controller.rb b/app/controllers/line_items_controller.rb
index 45f0d497f2..9b0c588911 100644
--- a/app/controllers/line_items_controller.rb
+++ b/app/controllers/line_items_controller.rb
@@ -28,11 +28,11 @@ class LineItemsController < BaseController
def unauthorized
status = spree_current_user ? 403 : 401
- render nothing: true, status: status and return
+ render(nothing: true, status: status) && return
end
def not_found
- render nothing: true, status: 404 and return
+ render(nothing: true, status: :not_found) && return
end
def destroy_with_lock(item)
diff --git a/app/controllers/map_controller.rb b/app/controllers/map_controller.rb
index 46a6f5852a..91c591e628 100644
--- a/app/controllers/map_controller.rb
+++ b/app/controllers/map_controller.rb
@@ -1,6 +1,5 @@
class MapController < BaseController
layout 'darkswarm'
- def index
- end
+ def index; end
end
diff --git a/app/controllers/producers_controller.rb b/app/controllers/producers_controller.rb
index 21861b6fb8..efdd889aed 100644
--- a/app/controllers/producers_controller.rb
+++ b/app/controllers/producers_controller.rb
@@ -3,6 +3,5 @@ class ProducersController < BaseController
before_filter :enable_embedded_shopfront
- def index
- end
+ def index; end
end
diff --git a/app/controllers/shop_controller.rb b/app/controllers/shop_controller.rb
index c8c67f7672..de783a1eb3 100644
--- a/app/controllers/shop_controller.rb
+++ b/app/controllers/shop_controller.rb
@@ -10,18 +10,16 @@ class ShopController < BaseController
end
def products
- begin
- renderer = OpenFoodNetwork::CachedProductsRenderer.new(current_distributor,
- current_order_cycle)
+ renderer = OpenFoodNetwork::CachedProductsRenderer.new(current_distributor,
+ current_order_cycle)
- # If we add any more filtering logic, we should probably
- # move it all to a lib class like 'CachedProductsFilterer'
- products_json = filter(renderer.products_json)
+ # If we add any more filtering logic, we should probably
+ # move it all to a lib class like 'CachedProductsFilterer'
+ products_json = filter(renderer.products_json)
- render json: products_json
- rescue OpenFoodNetwork::CachedProductsRenderer::NoProducts
- render status: 404, json: ''
- end
+ render json: products_json
+ rescue OpenFoodNetwork::CachedProductsRenderer::NoProducts
+ render status: :not_found, json: ''
end
def order_cycle
@@ -31,7 +29,7 @@ class ShopController < BaseController
@current_order_cycle = oc
render partial: "json/order_cycle"
else
- render status: 404, json: ""
+ render status: :not_found, json: ""
end
else
render partial: "json/order_cycle"
diff --git a/app/controllers/spree/admin/base_controller_decorator.rb b/app/controllers/spree/admin/base_controller_decorator.rb
index 210598e341..1d5d6e476a 100644
--- a/app/controllers/spree/admin/base_controller_decorator.rb
+++ b/app/controllers/spree/admin/base_controller_decorator.rb
@@ -47,7 +47,6 @@ Spree::Admin::BaseController.class_eval do
end
end
-
private
def active_distributors_not_ready_for_checkout
@@ -74,7 +73,7 @@ Spree::Admin::BaseController.class_eval do
request.format.json?
end
- def render_as_json(data, options={})
+ def render_as_json(data, options = {})
ams_prefix = options.delete :ams_prefix
if [Array, ActiveRecord::Relation].include? data.class
render options.merge(json: data, each_serializer: serializer(ams_prefix))
diff --git a/app/controllers/spree/admin/general_settings_controller_decorator.rb b/app/controllers/spree/admin/general_settings_controller_decorator.rb
index 80cdb8fa9e..7e6c1fc71a 100644
--- a/app/controllers/spree/admin/general_settings_controller_decorator.rb
+++ b/app/controllers/spree/admin/general_settings_controller_decorator.rb
@@ -3,7 +3,6 @@ module Spree
GeneralSettingsController.class_eval do
end
-
module GeneralSettingsEditPreferences
def edit
super
diff --git a/app/controllers/spree/admin/images_controller_decorator.rb b/app/controllers/spree/admin/images_controller_decorator.rb
index c8ec1cf208..1f46d9eb54 100644
--- a/app/controllers/spree/admin/images_controller_decorator.rb
+++ b/app/controllers/spree/admin/images_controller_decorator.rb
@@ -2,5 +2,5 @@ Spree::Admin::ImagesController.class_eval do
# This will make resource controller redirect correctly after deleting product images.
# This can be removed after upgrading to Spree 2.1.
# See here https://github.com/spree/spree/commit/334a011d2b8e16355e4ae77ae07cd93f7cbc8fd1
- belongs_to 'spree/product', :find_by => :permalink
+ belongs_to 'spree/product', find_by: :permalink
end
diff --git a/app/controllers/spree/admin/orders/customer_details_controller_decorator.rb b/app/controllers/spree/admin/orders/customer_details_controller_decorator.rb
index 7f22b4808d..41a3d721b1 100644
--- a/app/controllers/spree/admin/orders/customer_details_controller_decorator.rb
+++ b/app/controllers/spree/admin/orders/customer_details_controller_decorator.rb
@@ -13,7 +13,7 @@ Spree::Admin::Orders::CustomerDetailsController.class_eval do
flash[:success] = Spree.t('customer_details_updated')
redirect_to admin_order_customer_path(@order)
else
- render :action => :edit
+ render action: :edit
end
end
diff --git a/app/controllers/spree/admin/orders_controller_decorator.rb b/app/controllers/spree/admin/orders_controller_decorator.rb
index 8ae465e05d..5479c172b3 100644
--- a/app/controllers/spree/admin/orders_controller_decorator.rb
+++ b/app/controllers/spree/admin/orders_controller_decorator.rb
@@ -3,7 +3,7 @@ require 'open_food_network/spree_api_key_loader'
Spree::Admin::OrdersController.class_eval do
include OpenFoodNetwork::SpreeApiKeyLoader
helper CheckoutHelper
- before_filter :load_spree_api_key, :only => :bulk_management
+ before_filter :load_spree_api_key, only: :bulk_management
before_filter :load_order, only: %i[show edit update fire resend invoice print print_ticket]
before_filter :load_distribution_choices, only: [:new, :edit, :update]
@@ -16,7 +16,7 @@ Spree::Admin::OrdersController.class_eval do
# fees! This is a quick fix for that.
# TODO: update fees when adding/removing line items
# instead of the update_distribution_charge method.
- after_filter :update_distribution_charge, :only => :update
+ after_filter :update_distribution_charge, only: :update
before_filter :require_distributor_abn, only: :invoice
@@ -43,7 +43,7 @@ Spree::Admin::OrdersController.class_eval do
def update
unless @order.update_attributes(params[:order]) && @order.line_items.present?
@order.errors.add(:line_items, Spree.t('errors.messages.blank')) if @order.line_items.empty?
- return redirect_to edit_admin_order_path(@order), :flash => { :error => @order.errors.full_messages.join(', ') }
+ return redirect_to edit_admin_order_path(@order), flash: { error: @order.errors.full_messages.join(', ') }
end
@order.update!
@@ -88,7 +88,7 @@ Spree::Admin::OrdersController.class_eval do
private
def require_distributor_abn
- unless @order.distributor.abn.present?
+ if @order.distributor.abn.blank?
flash[:error] = t(:must_have_valid_business_number, enterprise_name: @order.distributor.name)
respond_with(@order) { |format| format.html { redirect_to edit_admin_order_path(@order) } }
end
diff --git a/app/controllers/spree/admin/payment_methods_controller_decorator.rb b/app/controllers/spree/admin/payment_methods_controller_decorator.rb
index b7268276e7..fee939aa66 100644
--- a/app/controllers/spree/admin/payment_methods_controller_decorator.rb
+++ b/app/controllers/spree/admin/payment_methods_controller_decorator.rb
@@ -12,7 +12,7 @@ module Spree
def collection
return parent.public_send(controller_name) if parent_data.present?
collection = if model_class.respond_to?(:accessible_by) &&
- !current_ability.has_block?(params[:action], model_class)
+ !current_ability.has_block?(params[:action], model_class)
model_class.accessible_by(current_ability, action)
@@ -41,7 +41,7 @@ module Spree
@payment_method = PaymentMethod.find(params[:pm_id])
end
else
- @payment_method = params[:provider_type].constantize.new()
+ @payment_method = params[:provider_type].constantize.new
end
render partial: 'provider_settings'
end
@@ -54,16 +54,16 @@ module Spree
def load_data
if spree_current_user.admin? || Rails.env.test?
- @providers = Gateway.providers.sort{|p1, p2| p1.name <=> p2.name }
+ @providers = Gateway.providers.sort{ |p1, p2| p1.name <=> p2.name }
else
- @providers = Gateway.providers.reject{ |p| p.name.include? "Bogus" }.sort{|p1, p2| p1.name <=> p2.name }
+ @providers = Gateway.providers.reject{ |p| p.name.include? "Bogus" }.sort{ |p1, p2| p1.name <=> p2.name }
end
@providers.reject!{ |p| p.name.ends_with? "StripeConnect" } unless show_stripe?
@calculators = PaymentMethod.calculators.sort_by(&:name)
end
def load_hubs
- @hubs = Enterprise.managed_by(spree_current_user).is_distributor.sort_by!{ |d| [(@payment_method.has_distributor? d) ? 0 : 1, d.name] }
+ @hubs = Enterprise.managed_by(spree_current_user).is_distributor.sort_by!{ |d| [@payment_method.has_distributor? d ? 0 : 1, d.name] }
end
# Show Stripe as an option if enabled, or if the
diff --git a/app/controllers/spree/admin/payments_controller_decorator.rb b/app/controllers/spree/admin/payments_controller_decorator.rb
index 2ccefab819..3c6effc8b7 100644
--- a/app/controllers/spree/admin/payments_controller_decorator.rb
+++ b/app/controllers/spree/admin/payments_controller_decorator.rb
@@ -3,7 +3,7 @@ Spree::Admin::PaymentsController.class_eval do
def create
@payment = @order.payments.build(object_params)
- if @payment.payment_method.is_a?(Spree::Gateway) && @payment.payment_method.payment_profiles_supported? && params[:card].present? and params[:card] != 'new'
+ if @payment.payment_method.is_a?(Spree::Gateway) && @payment.payment_method.payment_profiles_supported? && params[:card].present? && (params[:card] != 'new')
@payment.source = CreditCard.find_by_id(params[:card])
end
@@ -17,16 +17,15 @@ Spree::Admin::PaymentsController.class_eval do
@payment.process!
flash[:success] = flash_message_for(@payment, :successfully_created)
- redirect_to admin_order_payments_path(@order)
+ redirect_to admin_order_payments_path(@order)
else
AdvanceOrderService.new(@order).call!
flash[:success] = Spree.t(:new_order_completed)
redirect_to edit_admin_order_url(@order)
end
-
rescue Spree::Core::GatewayError => e
- flash[:error] = "#{e.message}"
+ flash[:error] = e.message.to_s
redirect_to new_admin_order_payment_path(@order)
end
end
@@ -50,12 +49,11 @@ Spree::Admin::PaymentsController.class_eval do
redirect_to request.referer
end
-
private
# Only show payments for the order's distributor
def filter_payment_methods
- @payment_methods = @payment_methods.select{ |pm| pm.has_distributor? @order.distributor}
+ @payment_methods = @payment_methods.select{ |pm| pm.has_distributor? @order.distributor }
@payment_method ||= @payment_methods.first
end
end
diff --git a/app/controllers/spree/admin/products_controller_decorator.rb b/app/controllers/spree/admin/products_controller_decorator.rb
index 9be7949898..ed3f8039df 100644
--- a/app/controllers/spree/admin/products_controller_decorator.rb
+++ b/app/controllers/spree/admin/products_controller_decorator.rb
@@ -7,8 +7,8 @@ Spree::Admin::ProductsController.class_eval do
include EnterprisesHelper
before_filter :load_data
- before_filter :load_form_data, :only => [:index, :new, :create, :edit, :update]
- before_filter :load_spree_api_key, :only => [:index, :variant_overrides]
+ before_filter :load_form_data, only: [:index, :new, :create, :edit, :update]
+ before_filter :load_spree_api_key, only: [:index, :variant_overrides]
before_filter :strip_new_properties, only: [:create, :update]
respond_override create: { html: {
@@ -21,7 +21,8 @@ Spree::Admin::ProductsController.class_eval do
},
failure: lambda {
render :new
- } } }
+ }
+ } }
def index
@current_user = spree_current_user
@@ -41,8 +42,8 @@ Spree::Admin::ProductsController.class_eval do
end
def bulk_update
- collection_hash = Hash[params[:products].each_with_index.map { |p,i| [i,p] }]
- product_set = Spree::ProductSet.new({:collection_attributes => collection_hash})
+ collection_hash = Hash[params[:products].each_with_index.map { |p, i| [i, p] }]
+ product_set = Spree::ProductSet.new(collection_attributes: collection_hash)
params[:filters] ||= {}
bulk_index_query = params[:filters].reduce("") do |string, filter|
@@ -56,14 +57,13 @@ Spree::Admin::ProductsController.class_eval do
redirect_to "/api/products/bulk_products?page=1;per_page=500;#{bulk_index_query}"
else
if product_set.errors.present?
- render json: { errors: product_set.errors }, status: 400
+ render json: { errors: product_set.errors }, status: :bad_request
else
- render :nothing => true, :status => 500
+ render nothing: true, status: :internal_server_error
end
end
end
-
protected
def collection
@@ -100,7 +100,6 @@ Spree::Admin::ProductsController.class_eval do
[:index, :bulk_update]
end
-
private
def load_form_data
@@ -115,11 +114,11 @@ Spree::Admin::ProductsController.class_eval do
joins(:product).
where('spree_products.supplier_id IN (?)', editable_enterprises.collect(&:id)).
where('spree_variants.import_date IS NOT NULL').
- where(spree_variants: {is_master: false}).
- where(spree_variants: {deleted_at: nil}).
+ where(spree_variants: { is_master: false }).
+ where(spree_variants: { deleted_at: nil }).
order('spree_variants.import_date DESC')
- options = [{id: '0', name: ''}]
+ options = [{ id: '0', name: '' }]
import_dates.collect(&:import_date).map { |i| options.push(id: i.to_date, name: i.to_date.to_formatted_s(:long)) }
options
diff --git a/app/controllers/spree/admin/search_controller_decorator.rb b/app/controllers/spree/admin/search_controller_decorator.rb
index 7fb5659415..3e94b06dbb 100644
--- a/app/controllers/spree/admin/search_controller_decorator.rb
+++ b/app/controllers/spree/admin/search_controller_decorator.rb
@@ -1,28 +1,28 @@
Spree::Admin::SearchController.class_eval do
def known_users
- if exact_match = Spree.user_class.find_by_email(params[:q])
- @users = [exact_match]
- else
- @users = spree_current_user.known_users.ransack({
- :m => 'or',
- :email_start => params[:q],
- :ship_address_firstname_start => params[:q],
- :ship_address_lastname_start => params[:q],
- :bill_address_firstname_start => params[:q],
- :bill_address_lastname_start => params[:q]
- }).result.limit(10)
- end
+ @users = if exact_match = Spree.user_class.find_by_email(params[:q])
+ [exact_match]
+ else
+ spree_current_user.known_users.ransack(
+ m: 'or',
+ email_start: params[:q],
+ ship_address_firstname_start: params[:q],
+ ship_address_lastname_start: params[:q],
+ bill_address_firstname_start: params[:q],
+ bill_address_lastname_start: params[:q]
+ ).result.limit(10)
+ end
render json: @users, each_serializer: Api::Admin::UserSerializer
end
def customers
- if spree_current_user.enterprises.pluck(:id).include? params[:distributor_id].to_i
- @customers = Customer.ransack({m: 'or', email_start: params[:q], name_start: params[:q]})
- .result.where(enterprise_id: params[:distributor_id])
- else
- @customers = []
- end
+ @customers = if spree_current_user.enterprises.pluck(:id).include? params[:distributor_id].to_i
+ Customer.ransack(m: 'or', email_start: params[:q], name_start: params[:q])
+ .result.where(enterprise_id: params[:distributor_id])
+ else
+ []
+ end
render json: @customers, each_serializer: Api::Admin::CustomerSerializer
end
diff --git a/app/controllers/spree/admin/shipping_methods_controller_decorator.rb b/app/controllers/spree/admin/shipping_methods_controller_decorator.rb
index c5aba1955c..c4e24fb169 100644
--- a/app/controllers/spree/admin/shipping_methods_controller_decorator.rb
+++ b/app/controllers/spree/admin/shipping_methods_controller_decorator.rb
@@ -1,7 +1,7 @@
module Spree
module Admin
ShippingMethodsController.class_eval do
- before_filter :do_not_destroy_referenced_shipping_methods, :only => :destroy
+ before_filter :do_not_destroy_referenced_shipping_methods, only: :destroy
before_filter :load_hubs, only: [:new, :edit, :create, :update]
# Sort shipping methods by distributor name
@@ -20,17 +20,17 @@ module Spree
# Spree allows soft deletes of shipping_methods but our reports are not adapted to that.
# So, this method prevents the deletion (even soft) of shipping_methods that are referenced in orders.
def do_not_destroy_referenced_shipping_methods
- order = Order.joins(shipments: :shipping_rates).where( spree_shipping_rates: { :shipping_method_id => @object } ).first
+ order = Order.joins(shipments: :shipping_rates).where( spree_shipping_rates: { shipping_method_id: @object } ).first
if order
flash[:error] = I18n.t(:shipping_method_destroy_error, number: order.number)
- redirect_to collection_url and return
+ redirect_to(collection_url) && (return)
end
end
private
def load_hubs
- @hubs = Enterprise.managed_by(spree_current_user).is_distributor.sort_by!{ |d| [(@shipping_method.has_distributor? d) ? 0 : 1, d.name] }
+ @hubs = Enterprise.managed_by(spree_current_user).is_distributor.sort_by!{ |d| [@shipping_method.has_distributor? d ? 0 : 1, d.name] }
end
end
end
diff --git a/app/controllers/spree/admin/variants_controller_decorator.rb b/app/controllers/spree/admin/variants_controller_decorator.rb
index bb277a387a..7a519701f9 100644
--- a/app/controllers/spree/admin/variants_controller_decorator.rb
+++ b/app/controllers/spree/admin/variants_controller_decorator.rb
@@ -22,11 +22,11 @@ Spree::Admin::VariantsController.class_eval do
def destroy
@variant = Spree::Variant.find(params[:id])
- if VariantDeleter.new.delete(@variant) # This line changed
- flash[:success] = Spree.t('notice_messages.variant_deleted')
- else
- flash[:success] = Spree.t('notice_messages.variant_not_deleted')
- end
+ flash[:success] = if VariantDeleter.new.delete(@variant) # This line changed
+ Spree.t('notice_messages.variant_deleted')
+ else
+ Spree.t('notice_messages.variant_not_deleted')
+ end
respond_with(@variant) do |format|
format.html { redirect_to admin_product_variants_url(params[:product_id]) }
@@ -34,12 +34,11 @@ Spree::Admin::VariantsController.class_eval do
end
end
-
protected
def create_before
option_values = params[:new_variant]
- option_values.andand.each_value {|id| @object.option_values << OptionValue.find(id)}
+ option_values.andand.each_value { |id| @object.option_values << OptionValue.find(id) }
@object.save
end
end
diff --git a/app/controllers/spree/api/products_controller_decorator.rb b/app/controllers/spree/api/products_controller_decorator.rb
index 3fb8a0806c..906cbb3d0a 100644
--- a/app/controllers/spree/api/products_controller_decorator.rb
+++ b/app/controllers/spree/api/products_controller_decorator.rb
@@ -34,7 +34,7 @@ Spree::Api::ProductsController.class_eval do
@product = find_product(params[:product_id])
authorize! :delete, @product
@product.destroy
- respond_with(@product, :status => 204)
+ respond_with(@product, status: 204)
end
# POST /api/products/:product_id/clone
diff --git a/app/controllers/spree/checkout_controller_decorator.rb b/app/controllers/spree/checkout_controller_decorator.rb
index b01ffad30e..88d2268545 100644
--- a/app/controllers/spree/checkout_controller_decorator.rb
+++ b/app/controllers/spree/checkout_controller_decorator.rb
@@ -1,7 +1,6 @@
require 'open_food_network/address_finder'
Spree::CheckoutController.class_eval do
-
include CheckoutHelper
before_filter :enable_embedded_shopfront
diff --git a/app/controllers/spree/orders_controller_decorator.rb b/app/controllers/spree/orders_controller_decorator.rb
index 0a7d146748..aa40dde4a6 100644
--- a/app/controllers/spree/orders_controller_decorator.rb
+++ b/app/controllers/spree/orders_controller_decorator.rb
@@ -39,14 +39,14 @@ Spree::OrdersController.class_eval do
@order = order_to_update
unless @order
flash[:error] = t(:order_not_found)
- redirect_to root_path and return
+ redirect_to(root_path) && return
end
if @order.update_attributes(params[:order])
discard_empty_line_items
with_open_adjustments { update_totals_and_taxes }
- render :edit and return unless apply_coupon_code
+ render(:edit) && return unless apply_coupon_code
if @order == current_order
fire_event('spree.order.contents_changed')
@@ -56,7 +56,7 @@ Spree::OrdersController.class_eval do
respond_with(@order) do |format|
format.html do
- if params.has_key?(:checkout)
+ if params.key?(:checkout)
@order.next_transition.run_callbacks if @order.cart?
redirect_to checkout_state_path(@order.checkout_steps.first)
elsif @order.complete?
@@ -95,13 +95,13 @@ Spree::OrdersController.class_eval do
end
def filter_order_params
- if params[:order] and params[:order][:line_items_attributes]
+ if params[:order] && params[:order][:line_items_attributes]
params[:order][:line_items_attributes] = remove_missing_line_items(params[:order][:line_items_attributes])
end
end
def remove_missing_line_items(attrs)
- attrs.select do |i, line_item|
+ attrs.select do |_i, line_item|
Spree::LineItem.find_by_id(line_item[:id])
end
end
@@ -129,7 +129,6 @@ Spree::OrdersController.class_eval do
redirect_to request.referer || order_path(@order)
end
-
private
# Updates the various denormalized total attributes of the order and
@@ -185,7 +184,7 @@ Spree::OrdersController.class_eval do
return unless order_to_update.andand.complete?
items = params[:order][:line_items_attributes]
- .andand.select{ |k,attrs| attrs["quantity"].to_i > 0 }
+ .andand.select{ |_k, attrs| attrs["quantity"].to_i > 0 }
if items.empty?
flash[:error] = I18n.t(:orders_cannot_remove_the_final_item)
diff --git a/app/controllers/spree/paypal_controller_decorator.rb b/app/controllers/spree/paypal_controller_decorator.rb
index cc18c9fc7d..03d2b17d2a 100644
--- a/app/controllers/spree/paypal_controller_decorator.rb
+++ b/app/controllers/spree/paypal_controller_decorator.rb
@@ -4,7 +4,7 @@ Spree::PaypalController.class_eval do
after_filter :reset_order_when_complete, only: :confirm
def cancel
- flash[:notice] = Spree.t('flash.cancel', :scope => 'paypal')
+ flash[:notice] = Spree.t('flash.cancel', scope: 'paypal')
redirect_to main_app.checkout_path
end
diff --git a/app/controllers/spree/store_controller_decorator.rb b/app/controllers/spree/store_controller_decorator.rb
index d1d8fb8277..029a617aac 100644
--- a/app/controllers/spree/store_controller_decorator.rb
+++ b/app/controllers/spree/store_controller_decorator.rb
@@ -5,6 +5,6 @@ class Spree::StoreController
before_filter :set_locale
def unauthorized
- render 'shared/unauthorized', :status => 401
+ render 'shared/unauthorized', status: :unauthorized
end
end
diff --git a/app/controllers/stripe/callbacks_controller.rb b/app/controllers/stripe/callbacks_controller.rb
index 1b3cfec502..985596dc63 100644
--- a/app/controllers/stripe/callbacks_controller.rb
+++ b/app/controllers/stripe/callbacks_controller.rb
@@ -15,7 +15,7 @@ module Stripe
end
redirect_to main_app.edit_admin_enterprise_path(connector.enterprise, anchor: 'payment_methods')
rescue Stripe::StripeError => e
- render text: e.message, status: 500
+ render text: e.message, status: :internal_server_error
end
end
end
diff --git a/app/controllers/stripe/webhooks_controller.rb b/app/controllers/stripe/webhooks_controller.rb
index 19f8b608eb..f079dbc7f2 100644
--- a/app/controllers/stripe/webhooks_controller.rb
+++ b/app/controllers/stripe/webhooks_controller.rb
@@ -20,9 +20,9 @@ module Stripe
signature = request.headers["HTTP_STRIPE_SIGNATURE"]
@event = Webhook.construct_event(payload, signature, Stripe.endpoint_secret)
rescue JSON::ParserError
- render nothing: true, status: 400
+ render nothing: true, status: :bad_request
rescue Stripe::SignatureVerificationError
- render nothing: true, status: 401
+ render nothing: true, status: :unauthorized
end
# Stripe interprets a 4xx or 3xx response as a failure to receive the webhook,
diff --git a/app/controllers/user_passwords_controller.rb b/app/controllers/user_passwords_controller.rb
index e6b7610a13..37cceb6bfc 100644
--- a/app/controllers/user_passwords_controller.rb
+++ b/app/controllers/user_passwords_controller.rb
@@ -10,7 +10,7 @@ class UserPasswordsController < Spree::UserPasswordsController
if resource.errors.empty?
set_flash_message(:success, :send_instructions) if is_navigational_format?
- respond_with resource, :location => spree.login_path
+ respond_with resource, location: spree.login_path
else
respond_to do |format|
format.html do
diff --git a/app/helpers/admin/injection_helper.rb b/app/helpers/admin/injection_helper.rb
index a8fcac65a6..ecb5e1c20b 100644
--- a/app/helpers/admin/injection_helper.rb
+++ b/app/helpers/admin/injection_helper.rb
@@ -33,31 +33,31 @@ module Admin
admin_inject_json_ams "admin.shippingMethods", "shippingMethod", @shipping_method, Api::Admin::ShippingMethodSerializer
end
- def admin_inject_shops(opts={})
+ def admin_inject_shops(opts = {})
opts.reverse_merge!(module: 'admin.customers')
admin_inject_json_ams_array opts[:module], "shops", @shops, Api::Admin::IdNameSerializer
end
- def admin_inject_available_countries(opts={})
+ def admin_inject_available_countries(opts = {})
opts.reverse_merge!(module: 'admin.customers')
admin_inject_json_ams_array opts[:module], 'availableCountries', available_countries, Api::CountrySerializer
end
- def admin_inject_hubs(opts={})
+ def admin_inject_hubs(opts = {})
opts.reverse_merge!(module: 'ofn.admin')
admin_inject_json_ams_array opts[:module], "hubs", @hubs, Api::Admin::IdNameSerializer
end
- def admin_inject_producers(opts={})
+ def admin_inject_producers(opts = {})
opts.reverse_merge!(module: 'ofn.admin')
admin_inject_json_ams_array opts[:module], "producers", @producers, Api::Admin::IdNameSerializer
end
- def admin_inject_inventory_items(opts={module: 'ofn.admin'})
+ def admin_inject_inventory_items(opts = { module: 'ofn.admin' })
admin_inject_json_ams_array opts[:module], "inventoryItems", @inventory_items, Api::Admin::InventoryItemSerializer
end
- def admin_inject_column_preferences(opts={})
+ def admin_inject_column_preferences(opts = {})
opts.reverse_merge!(module: 'ofn.admin', action: "#{controller_name}_#{action_name}")
column_preferences = ColumnPreference.for(spree_current_user, opts[:action])
admin_inject_json_ams_array opts[:module], "columns", column_preferences, Api::Admin::ColumnPreferenceSerializer
@@ -69,22 +69,22 @@ module Admin
def admin_inject_enterprise_permissions
permissions =
- {can_manage_shipping_methods: can?(:manage_shipping_methods, @enterprise),
- can_manage_payment_methods: can?(:manage_payment_methods, @enterprise),
- can_manage_enterprise_fees: can?(:manage_enterprise_fees, @enterprise)}
+ { can_manage_shipping_methods: can?(:manage_shipping_methods, @enterprise),
+ can_manage_payment_methods: can?(:manage_payment_methods, @enterprise),
+ can_manage_enterprise_fees: can?(:manage_enterprise_fees, @enterprise) }
admin_inject_json "admin.enterprises", "enterprisePermissions", permissions
end
def admin_inject_hub_permissions
- render partial: "admin/json/injection_ams", locals: {ngModule: "admin.variantOverrides", name: "hubPermissions", json: @hub_permissions.to_json}
+ render partial: "admin/json/injection_ams", locals: { ngModule: "admin.variantOverrides", name: "hubPermissions", json: @hub_permissions.to_json }
end
def admin_inject_products
admin_inject_json_ams_array "ofn.admin", "products", @products, Api::Admin::ProductSerializer
end
- def admin_inject_tax_categories(opts={module: 'ofn.admin'})
+ def admin_inject_tax_categories(opts = { module: 'ofn.admin' })
admin_inject_json_ams_array opts[:module], "tax_categories", @tax_categories, Api::Admin::TaxCategorySerializer
end
@@ -101,7 +101,7 @@ module Admin
end
def admin_inject_order_cycle_instance
- render partial: "admin/json/injection_ams", locals: {ngModule: 'admin.orderCycles', name: 'ocInstance', json: "{coordinator_id: '#{@order_cycle.coordinator.id}'}"}
+ render partial: "admin/json/injection_ams", locals: { ngModule: 'admin.orderCycles', name: 'ocInstance', json: "{coordinator_id: '#{@order_cycle.coordinator.id}'}" }
end
def admin_inject_order_cycles
@@ -109,22 +109,22 @@ module Admin
end
def admin_inject_spree_api_key
- render partial: "admin/json/injection_ams", locals: {ngModule: 'admin.indexUtils', name: 'SpreeApiKey', json: "'#{@spree_api_key.to_s}'"}
+ render partial: "admin/json/injection_ams", locals: { ngModule: 'admin.indexUtils', name: 'SpreeApiKey', json: "'#{@spree_api_key}'" }
end
def admin_inject_json(ngModule, name, data)
json = data.to_json
- render partial: "admin/json/injection_ams", locals: {ngModule: ngModule, name: name, json: json}
+ render partial: "admin/json/injection_ams", locals: { ngModule: ngModule, name: name, json: json }
end
def admin_inject_json_ams(ngModule, name, data, serializer, opts = {})
- json = serializer.new(data, {scope: spree_current_user}.merge(opts)).to_json
- render partial: "admin/json/injection_ams", locals: {ngModule: ngModule, name: name, json: json}
+ json = serializer.new(data, { scope: spree_current_user }.merge(opts)).to_json
+ render partial: "admin/json/injection_ams", locals: { ngModule: ngModule, name: name, json: json }
end
def admin_inject_json_ams_array(ngModule, name, data, serializer, opts = {})
- json = ActiveModel::ArraySerializer.new(data, {each_serializer: serializer, scope: spree_current_user}.merge(opts)).to_json
- render partial: "admin/json/injection_ams", locals: {ngModule: ngModule, name: name, json: json}
+ json = ActiveModel::ArraySerializer.new(data, { each_serializer: serializer, scope: spree_current_user }.merge(opts)).to_json
+ render partial: "admin/json/injection_ams", locals: { ngModule: ngModule, name: name, json: json }
end
end
end
diff --git a/app/helpers/admin/orders_helper.rb b/app/helpers/admin/orders_helper.rb
index fa445739ad..9e16d27ed5 100644
--- a/app/helpers/admin/orders_helper.rb
+++ b/app/helpers/admin/orders_helper.rb
@@ -5,8 +5,8 @@ module Admin
# We exclude shipping method adjustments because they are displayed in a
# separate table together with the order line items.
def order_adjustments_for_display(order)
- order.adjustments.eligible.select do |adjustment|
- adjustment.originator_type != "Spree::ShippingMethod"
+ order.adjustments.eligible.reject do |adjustment|
+ adjustment.originator_type == "Spree::ShippingMethod"
end
end
end
diff --git a/app/helpers/angular_form_builder.rb b/app/helpers/angular_form_builder.rb
index 7d87395bc6..cfb5cdf354 100644
--- a/app/helpers/angular_form_builder.rb
+++ b/app/helpers/angular_form_builder.rb
@@ -1,32 +1,32 @@
class AngularFormBuilder < ActionView::Helpers::FormBuilder
- def ng_fields_for(record_name, *args, &block)
+ def ng_fields_for(record_name, *_args)
raise "Nested ng_fields_for is not yet supported" if @fields_for_record_name.present?
@fields_for_record_name = record_name
- block.call self
+ yield self
@fields_for_record_name = nil
end
def ng_text_field(method, options = {})
value = "{{ #{angular_model(method)} }}"
- options.reverse_merge!({'id' => angular_id(method)})
+ options.reverse_merge!('id' => angular_id(method))
@template.text_field_tag angular_name(method), value, options
end
- def ng_hidden_field(method, options = {})
+ def ng_hidden_field(method, _options = {})
value = "{{ #{angular_model(method)} }}"
- @template.hidden_field_tag angular_name(method), value, :id => angular_id(method)
+ @template.hidden_field_tag angular_name(method), value, id: angular_id(method)
end
def ng_select(method, choices, angular_field, options = {})
- options.reverse_merge!({'id' => angular_id(method), 'ng-model' => "#{angular_model(method)}"})
+ 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
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)}"})
+ 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
end
diff --git a/app/helpers/angular_form_helper.rb b/app/helpers/angular_form_helper.rb
index 2528e8bc7e..add7e5f121 100644
--- a/app/helpers/angular_form_helper.rb
+++ b/app/helpers/angular_form_helper.rb
@@ -1,10 +1,10 @@
module AngularFormHelper
- def ng_options_for_select(container, angular_field=nil)
+ def ng_options_for_select(container, _angular_field = nil)
return container if String === container
container.map do |element|
html_attributes = option_html_attributes(element)
- text, value = option_text_and_value(element).map { |item| item.to_s }
+ text, value = option_text_and_value(element).map(&:to_s)
%()
end.join("\n").html_safe
end
@@ -18,7 +18,6 @@ module AngularFormHelper
end
end
-
class ActionView::Helpers::InstanceTag
include AngularFormHelper
end
diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb
index f61a11727c..0142825667 100644
--- a/app/helpers/application_helper.rb
+++ b/app/helpers/application_helper.rb
@@ -8,13 +8,13 @@ module ApplicationHelper
def ng_form_for(name, *args, &block)
options = args.extract_options!
- form_for(name, *(args << options.merge(:builder => AngularFormBuilder)), &block)
+ form_for(name, *(args << options.merge(builder: AngularFormBuilder)), &block)
end
# Pass URL helper calls on to spree where applicable so that we don't need to use
# spree.foo_path in any view rendered from non-spree-namespaced controllers.
def method_missing(method, *args, &block)
- if (method.to_s.end_with?('_path') || method.to_s.end_with?('_url')) && spree.respond_to?(method)
+ if method.to_s.end_with?('_path', '_url') && spree.respond_to?(method)
spree.public_send(method, *args)
else
super
diff --git a/app/helpers/checkout_helper.rb b/app/helpers/checkout_helper.rb
index 4d64735cfc..4e9ff57a58 100644
--- a/app/helpers/checkout_helper.rb
+++ b/app/helpers/checkout_helper.rb
@@ -3,7 +3,7 @@ module CheckoutHelper
current_order.distributor.allow_guest_orders?
end
- def checkout_adjustments_for(order, opts={})
+ def checkout_adjustments_for(order, opts = {})
adjustments = order.adjustments.eligible
exclude = opts[:exclude] || {}
@@ -24,7 +24,7 @@ module CheckoutHelper
def display_checkout_admin_and_handling_adjustments_total_for(order)
adjustments = order.adjustments.eligible.where('originator_type = ? AND source_type != ? ', 'EnterpriseFee', 'Spree::LineItem')
- Spree::Money.new adjustments.sum(&:amount) , currency: order.currency
+ Spree::Money.new adjustments.sum(&:amount), currency: order.currency
end
def checkout_line_item_adjustments(order)
@@ -36,7 +36,7 @@ module CheckoutHelper
end
def display_checkout_subtotal(order)
- Spree::Money.new checkout_subtotal(order) , currency: order.currency
+ Spree::Money.new checkout_subtotal(order), currency: order.currency
end
def display_checkout_tax_total(order)
@@ -44,22 +44,22 @@ module CheckoutHelper
end
def display_checkout_taxes_hash(order)
- order.tax_adjustment_totals.each_with_object(Hash.new) do |(tax_rate, tax_amount), hash|
- hash[number_to_percentage(tax_rate.amount * 100, :precision => 1)] = Spree::Money.new tax_amount, currency: order.currency
+ order.tax_adjustment_totals.each_with_object({}) do |(tax_rate, tax_amount), hash|
+ hash[number_to_percentage(tax_rate.amount * 100, precision: 1)] = Spree::Money.new tax_amount, currency: order.currency
end
end
def display_line_item_tax_rates(line_item)
- line_item.tax_rates.map { |tr| number_to_percentage(tr.amount * 100, :precision => 1) }.join(", ")
+ line_item.tax_rates.map { |tr| number_to_percentage(tr.amount * 100, precision: 1) }.join(", ")
end
def display_adjustment_tax_rates(adjustment)
tax_rates = TaxRateFinder.tax_rates_of(adjustment)
- tax_rates.map { |tr| number_to_percentage(tr.amount * 100, :precision => 1) }.join(", ")
+ tax_rates.map { |tr| number_to_percentage(tr.amount * 100, precision: 1) }.join(", ")
end
def display_adjustment_amount(adjustment)
- Spree::Money.new(adjustment.amount, { :currency => adjustment.currency })
+ Spree::Money.new(adjustment.amount, currency: adjustment.currency)
end
def display_checkout_total_less_tax(order)
@@ -68,10 +68,10 @@ module CheckoutHelper
def validated_input(name, path, args = {})
attributes = {
- required: true,
- type: :text,
- name: path,
- id: path,
+ :required => true,
+ :type => :text,
+ :name => path,
+ :id => path,
"ng-model" => path,
"ng-class" => "{error: !fieldValid('#{path}')}"
}.merge args
@@ -81,8 +81,8 @@ module CheckoutHelper
def validated_select(name, path, options, args = {})
attributes = {
- required: true,
- id: path,
+ :required => true,
+ :id => path,
"ng-model" => path,
"ng-class" => "{error: !fieldValid('#{path}')}"
}.merge args
diff --git a/app/helpers/discourse_helper.rb b/app/helpers/discourse_helper.rb
index 1d813cf404..9e82c4d803 100644
--- a/app/helpers/discourse_helper.rb
+++ b/app/helpers/discourse_helper.rb
@@ -16,10 +16,10 @@ module DiscourseHelper
end
def discourse_url!
- discourse_url or raise 'Missing Discourse URL'
+ discourse_url || raise('Missing Discourse URL')
end
def discourse_sso_secret!
- ENV['DISCOURSE_SSO_SECRET'] or raise 'Missing SSO secret'
+ ENV['DISCOURSE_SSO_SECRET'] || raise('Missing SSO secret')
end
end
diff --git a/app/helpers/enterprises_helper.rb b/app/helpers/enterprises_helper.rb
index 899d6156bb..2a623f4bf1 100644
--- a/app/helpers/enterprises_helper.rb
+++ b/app/helpers/enterprises_helper.rb
@@ -11,7 +11,7 @@ module EnterprisesHelper
end
def available_shipping_methods
- return [] unless current_distributor.present?
+ return [] if current_distributor.blank?
shipping_methods = current_distributor.shipping_methods
applicator = OpenFoodNetwork::TagRuleApplicator.new(current_distributor, "FilterShippingMethods", current_customer.andand.tag_list)
@@ -21,7 +21,7 @@ module EnterprisesHelper
end
def available_payment_methods
- return [] unless current_distributor.present?
+ return [] if current_distributor.blank?
payment_methods = current_distributor.payment_methods.available(:front_end).all
filter = OpenFoodNetwork::AvailablePaymentMethodFilter.new
@@ -43,7 +43,7 @@ module EnterprisesHelper
order('is_primary_producer ASC, name')
end
- def enterprises_options enterprises
+ def enterprises_options(enterprises)
enterprises.map { |enterprise| [enterprise.name + ": " + enterprise.address.address1 + ", " + enterprise.address.city, enterprise.id.to_i] }
end
@@ -74,7 +74,7 @@ module EnterprisesHelper
name = t(:delete)
options = {}
options[:class] = "delete-resource"
- options[:data] = { :action => 'remove', :confirm => enterprise_confirm_delete_message(enterprise) }
+ options[:data] = { action: 'remove', confirm: enterprise_confirm_delete_message(enterprise) }
link_to_with_icon 'icon-trash', name, url, options
end
diff --git a/app/helpers/injection_helper.rb b/app/helpers/injection_helper.rb
index 60fc2bbde5..d3e3989d95 100644
--- a/app/helpers/injection_helper.rb
+++ b/app/helpers/injection_helper.rb
@@ -36,12 +36,12 @@ module InjectionHelper
def inject_available_shipping_methods
inject_json_ams "shippingMethods", available_shipping_methods,
- Api::ShippingMethodSerializer, current_order: current_order
+ Api::ShippingMethodSerializer, current_order: current_order
end
def inject_available_payment_methods
inject_json_ams "paymentMethods", available_payment_methods,
- Api::PaymentMethodSerializer, current_order: current_order
+ Api::PaymentMethodSerializer, current_order: current_order
end
def inject_taxons
@@ -57,7 +57,7 @@ module InjectionHelper
end
def inject_spree_api_key
- render partial: "json/injection_ams", locals: {name: 'spreeApiKey', json: "'#{@spree_api_key.to_s}'"}
+ render partial: "json/injection_ams", locals: { name: 'spreeApiKey', json: "'#{@spree_api_key}'" }
end
def inject_available_countries
@@ -65,7 +65,7 @@ module InjectionHelper
end
def inject_enterprise_attributes
- render partial: "json/injection_ams", locals: {name: 'enterpriseAttributes', json: "#{@enterprise_attributes.to_json}"}
+ render partial: "json/injection_ams", locals: { name: 'enterpriseAttributes', json: @enterprise_attributes.to_json.to_s }
end
def inject_orders
@@ -89,7 +89,7 @@ module InjectionHelper
end
def inject_json(name, partial, opts = {})
- render partial: "json/injection", locals: {name: name, partial: partial}.merge(opts)
+ render partial: "json/injection", locals: { name: name, partial: partial }.merge(opts)
end
def inject_json_ams(name, data, serializer, opts = {})
@@ -100,14 +100,13 @@ module InjectionHelper
serializer_instance = serializer.new(data, opts)
json = serializer_instance.to_json
- render partial: "json/injection_ams", locals: {name: name, json: json}
+ render partial: "json/injection_ams", locals: { name: name, json: json }
end
-
private
def enterprise_injection_data
@enterprise_injection_data ||= OpenFoodNetwork::EnterpriseInjectionData.new
- {data: @enterprise_injection_data}
+ { data: @enterprise_injection_data }
end
end
diff --git a/app/helpers/order_cycles_helper.rb b/app/helpers/order_cycles_helper.rb
index 8afca2b949..59ab6b8ff2 100644
--- a/app/helpers/order_cycles_helper.rb
+++ b/app/helpers/order_cycles_helper.rb
@@ -15,7 +15,7 @@ module OrderCyclesHelper
validated_enterprise_options permitted_producer_enterprises_for(order_cycle)
end
- def permitted_coordinating_enterprises_for(order_cycle)
+ def permitted_coordinating_enterprises_for(_order_cycle)
Enterprise.managed_by(spree_current_user).is_distributor.by_name
end
@@ -54,7 +54,7 @@ module OrderCyclesHelper
distance_of_time_in_words_to_now(orders_close_at)]
end
- def active_order_cycle_for_distributor?(distributor)
+ def active_order_cycle_for_distributor?(_distributor)
OrderCycle.active.with_distributor(@distributor).present?
end
@@ -80,7 +80,7 @@ module OrderCyclesHelper
private
- def validated_enterprise_options(enterprises, options={})
+ def validated_enterprise_options(enterprises, options = {})
enterprises.map do |e|
disabled_message = nil
if options[:shipping_and_payment_methods] && (e.shipping_methods.empty? || e.payment_methods.available.empty?)
@@ -94,7 +94,7 @@ module OrderCyclesHelper
end
if disabled_message
- ["#{e.name} (#{disabled_message})", e.id, {disabled: true}]
+ ["#{e.name} (#{disabled_message})", e.id, { disabled: true }]
else
[e.name, e.id]
end
diff --git a/app/helpers/serializer_helper.rb b/app/helpers/serializer_helper.rb
index 2e48e3741d..ab39e8c252 100644
--- a/app/helpers/serializer_helper.rb
+++ b/app/helpers/serializer_helper.rb
@@ -1,6 +1,6 @@
module SerializerHelper
def ids_to_objs(ids)
return [] if ids.blank?
- ids.map { |id| {id: id} }
+ ids.map { |id| { id: id } }
end
end
diff --git a/app/helpers/spree/admin/base_helper_decorator.rb b/app/helpers/spree/admin/base_helper_decorator.rb
index 99fde70676..95016b3c88 100644
--- a/app/helpers/spree/admin/base_helper_decorator.rb
+++ b/app/helpers/spree/admin/base_helper_decorator.rb
@@ -10,14 +10,13 @@ module Spree
end
alias_method_chain :preference_field_tag, :files
-
# Add support for options[:html], allowing additional HTML attributes
def link_to_remove_fields(name, f, options = {})
name = '' if options[:no_text]
options[:class] = '' unless options[:class]
options[:class] += 'no-text with-tip' if options[:no_text]
- html_options = {class: "remove_fields #{options[:class]}", data: {action: 'remove'}, title: t(:remove)}
+ html_options = { class: "remove_fields #{options[:class]}", data: { action: 'remove' }, title: t(:remove) }
html_options.merge!(options[:html]) if options.key? :html
link_to_with_icon('icon-trash', name, '#', html_options) + f.hidden_field(:_destroy)
diff --git a/app/helpers/spree/admin/navigation_helper_decorator.rb b/app/helpers/spree/admin/navigation_helper_decorator.rb
index 2dcdb1436c..eabf26e5e3 100644
--- a/app/helpers/spree/admin/navigation_helper_decorator.rb
+++ b/app/helpers/spree/admin/navigation_helper_decorator.rb
@@ -5,9 +5,7 @@ module Spree
def klass_for(name)
model_name = name.to_s
- ["Spree::#{model_name.classify}", model_name.classify, model_name.gsub('_', '/').classify].find do |t|
- t.safe_constantize
- end.try(:safe_constantize)
+ ["Spree::#{model_name.classify}", model_name.classify, model_name.tr('_', '/').classify].find(&:safe_constantize).try(:safe_constantize)
end
# Make it so that the Reports admin tab can be enabled/disabled through the cancan
@@ -27,11 +25,11 @@ module Spree
# TEMP: override method until it is fixed in Spree.
def tab_with_cancan_check(*args)
- options = {:label => args.first.to_s}
+ options = { label: args.first.to_s }
if args.last.is_a?(Hash)
options = options.merge(args.last)
end
- return '' if klass = klass_for(options[:label]) and cannot?(:admin, klass)
+ return '' if (klass = klass_for(options[:label])) && cannot?(:admin, klass)
tab_without_cancan_check(*args)
end
alias_method_chain :tab, :cancan_check
diff --git a/app/helpers/spree/admin/orders_helper_decorator.rb b/app/helpers/spree/admin/orders_helper_decorator.rb
index c804dab9ca..74cc53dcfb 100644
--- a/app/helpers/spree/admin/orders_helper_decorator.rb
+++ b/app/helpers/spree/admin/orders_helper_decorator.rb
@@ -18,9 +18,9 @@ module Spree
end
end
if @order.ready_to_ship?
- links << { name: t(:ship_order), url: fire_admin_order_path(@order, :e => 'ship'), method: 'put', icon: 'icon-truck', confirm: t(:are_you_sure) }
+ links << { name: t(:ship_order), url: fire_admin_order_path(@order, e: 'ship'), method: 'put', icon: 'icon-truck', confirm: t(:are_you_sure) }
end
- links << { name: t(:cancel_order), url: fire_admin_order_path(@order.number, { :e => 'cancel' }), icon: 'icon-trash', confirm: t(:are_you_sure) } if order.can_cancel?
+ links << { name: t(:cancel_order), url: fire_admin_order_path(@order.number, e: 'cancel'), icon: 'icon-trash', confirm: t(:are_you_sure) } if order.can_cancel?
links
end
end
diff --git a/app/helpers/spree/base_helper_decorator.rb b/app/helpers/spree/base_helper_decorator.rb
index fa058f9518..67ea0a711d 100644
--- a/app/helpers/spree/base_helper_decorator.rb
+++ b/app/helpers/spree/base_helper_decorator.rb
@@ -2,7 +2,7 @@ module Spree
module BaseHelper
# human readable list of variant options
# Override: Do not show out of stock text
- def variant_options(v, options={})
+ def variant_options(v, _options = {})
v.options_text
end
end
diff --git a/app/helpers/spree/orders_helper.rb b/app/helpers/spree/orders_helper.rb
index b7495daafc..4231f29613 100644
--- a/app/helpers/spree/orders_helper.rb
+++ b/app/helpers/spree/orders_helper.rb
@@ -22,7 +22,8 @@ module Spree
state: 'complete',
user_id: spree_current_user.id,
distributor_id: current_distributor.id,
- order_cycle_id: current_order_cycle.id)
+ order_cycle_id: current_order_cycle.id
+ )
end
def changeable_orders_link_path
diff --git a/app/helpers/spree/products_helper_decorator.rb b/app/helpers/spree/products_helper_decorator.rb
index 20e6eeb803..ac31d260b9 100644
--- a/app/helpers/spree/products_helper_decorator.rb
+++ b/app/helpers/spree/products_helper_decorator.rb
@@ -3,7 +3,7 @@ module Spree
# Return the price of the variant, overriding sprees price diff capability.
# This will allways return the variant price as if the show_variant_full_price is set.
def variant_price_diff(variant)
- "(#{Spree::Money.new(variant.price).to_s})"
+ "(#{Spree::Money.new(variant.price)})"
end
def product_has_variant_unit_option_type?(product)
diff --git a/app/helpers/spree/reports_helper.rb b/app/helpers/spree/reports_helper.rb
index 0875794f95..bc75cfb9e8 100644
--- a/app/helpers/spree/reports_helper.rb
+++ b/app/helpers/spree/reports_helper.rb
@@ -6,7 +6,7 @@ module Spree
order_cycles.map do |oc|
orders_open_at = oc.orders_open_at.andand.to_s(:short) || 'NA'
orders_close_at = oc.orders_close_at.andand.to_s(:short) || 'NA'
- [ "#{oc.name} (#{orders_open_at} - #{orders_close_at})".html_safe, oc.id ]
+ ["#{oc.name} (#{orders_open_at} - #{orders_close_at})".html_safe, oc.id]
end
end
diff --git a/app/jobs/products_cache_integrity_checker_job.rb b/app/jobs/products_cache_integrity_checker_job.rb
index 8861b5a5a9..1adf229c7c 100644
--- a/app/jobs/products_cache_integrity_checker_job.rb
+++ b/app/jobs/products_cache_integrity_checker_job.rb
@@ -14,7 +14,6 @@ ProductsCacheIntegrityCheckerJob = Struct.new(:distributor_id, :order_cycle_id)
end
end
-
private
def checker
diff --git a/app/mailers/enterprise_mailer.rb b/app/mailers/enterprise_mailer.rb
index 36a1b071a9..3ac2677a67 100644
--- a/app/mailers/enterprise_mailer.rb
+++ b/app/mailers/enterprise_mailer.rb
@@ -9,9 +9,9 @@ class EnterpriseMailer < Spree::BaseMailer
subject = t('enterprise_mailer.welcome.subject',
enterprise: @enterprise.name,
sitename: Spree::Config[:site_name])
- mail(:to => enterprise.contact.email,
- :from => from_address,
- :subject => subject)
+ mail(to: enterprise.contact.email,
+ from: from_address,
+ subject: subject)
end
end
diff --git a/app/mailers/spree/base_mailer_decorator.rb b/app/mailers/spree/base_mailer_decorator.rb
index 44e2b53614..e84b36e33e 100644
--- a/app/mailers/spree/base_mailer_decorator.rb
+++ b/app/mailers/spree/base_mailer_decorator.rb
@@ -9,6 +9,6 @@ Spree::BaseMailer.class_eval do
def roadie_options
# This lets us specify assets using relative paths in email templates
- super.merge(url_options: {host: URI(spree.root_url).host })
+ super.merge(url_options: { host: URI(spree.root_url).host })
end
end
diff --git a/app/mailers/spree/order_mailer_decorator.rb b/app/mailers/spree/order_mailer_decorator.rb
index d71b722384..bffc26ee46 100644
--- a/app/mailers/spree/order_mailer_decorator.rb
+++ b/app/mailers/spree/order_mailer_decorator.rb
@@ -17,10 +17,10 @@ Spree::OrderMailer.class_eval do
@order = find_order(order_or_order_id)
I18n.with_locale valid_locale(@order.user) do
subject = mail_subject(t('spree.order_mailer.confirm_email.subject'), resend)
- mail(:to => @order.email,
- :from => from_address,
- :subject => subject,
- :reply_to => @order.distributor.contact.email)
+ mail(to: @order.email,
+ from: from_address,
+ subject: subject,
+ reply_to: @order.distributor.contact.email)
end
end
@@ -28,9 +28,9 @@ Spree::OrderMailer.class_eval do
@order = find_order(order_or_order_id)
I18n.with_locale valid_locale(@order.user) do
subject = mail_subject(t('spree.order_mailer.confirm_email.subject'), resend)
- mail(:to => @order.distributor.contact.email,
- :from => from_address,
- :subject => subject)
+ mail(to: @order.distributor.contact.email,
+ from: from_address,
+ subject: subject)
end
end
diff --git a/app/mailers/spree/user_mailer_decorator.rb b/app/mailers/spree/user_mailer_decorator.rb
index f9e618e348..52266a60b0 100644
--- a/app/mailers/spree/user_mailer_decorator.rb
+++ b/app/mailers/spree/user_mailer_decorator.rb
@@ -4,8 +4,8 @@ Spree::UserMailer.class_eval do
def signup_confirmation(user)
@user = user
I18n.with_locale valid_locale(@user) do
- mail(:to => user.email, :from => from_address,
- :subject => t(:welcome_to) + Spree::Config[:site_name])
+ mail(to: user.email, from: from_address,
+ subject: t(:welcome_to) + Spree::Config[:site_name])
end
end
diff --git a/app/models/calculator/flat_percent_per_item.rb b/app/models/calculator/flat_percent_per_item.rb
index b18e1026bd..035dfe09bd 100644
--- a/app/models/calculator/flat_percent_per_item.rb
+++ b/app/models/calculator/flat_percent_per_item.rb
@@ -9,7 +9,7 @@ class Calculator::FlatPercentPerItem < Spree::Calculator
# item level first, then multiply by the item quantity.
extend Spree::LocalizedNumber
- preference :flat_percent, :decimal, :default => 0
+ preference :flat_percent, :decimal, default: 0
attr_accessible :preferred_flat_percent
@@ -25,7 +25,7 @@ class Calculator::FlatPercentPerItem < Spree::Calculator
raise ArgumentError, "object must respond to #price and #quantity"
end
- value = (li.price * BigDecimal(self.preferred_flat_percent.to_s) / 100.0).round(2)
+ value = (li.price * BigDecimal(preferred_flat_percent.to_s) / 100.0).round(2)
value * li.quantity
end
end
diff --git a/app/models/column_preference.rb b/app/models/column_preference.rb
index f6bba869f7..6cfdb0687d 100644
--- a/app/models/column_preference.rb
+++ b/app/models/column_preference.rb
@@ -25,7 +25,7 @@ class ColumnPreference < ActiveRecord::Base
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)
@@ -42,7 +42,7 @@ class ColumnPreference < ActiveRecord::Base
def self.known_actions
OpenFoodNetwork::ColumnPreferenceDefaults.private_instance_methods
- .select{|m| m.to_s.end_with?("_columns")}.map{ |m| m.to_s.sub /_columns$/, ''}
+ .select{ |m| m.to_s.end_with?("_columns") }.map{ |m| m.to_s.sub /_columns$/, '' }
end
# Arbitrary filtering of default_preferences
diff --git a/app/models/column_preference_set.rb b/app/models/column_preference_set.rb
index 32b9b85a1b..24508d7f9d 100644
--- a/app/models/column_preference_set.rb
+++ b/app/models/column_preference_set.rb
@@ -1,5 +1,5 @@
class ColumnPreferenceSet < ModelSet
- def initialize(collection, attributes={})
+ def initialize(collection, attributes = {})
super(ColumnPreference, collection, attributes, nil, nil )
end
end
diff --git a/app/models/concerns/order_shipment.rb b/app/models/concerns/order_shipment.rb
index 4eed5979af..f829550d98 100644
--- a/app/models/concerns/order_shipment.rb
+++ b/app/models/concerns/order_shipment.rb
@@ -36,7 +36,7 @@ module OrderShipment
shipping_rate = shipment.shipping_rates.find_by_shipping_method_id(shipping_method_id)
return unless shipping_rate
- shipment.selected_shipping_rate_id=(shipping_rate.id)
+ shipment.selected_shipping_rate_id = shipping_rate.id
shipment.shipping_method
end
end
diff --git a/app/models/content_configuration.rb b/app/models/content_configuration.rb
index 7b94504aed..971cea658c 100644
--- a/app/models/content_configuration.rb
+++ b/app/models/content_configuration.rb
@@ -54,7 +54,7 @@ class ContentConfiguration < Spree::Preferences::FileConfiguration
preference :footer_logo, :file
has_attached_file :footer_logo, default_url: "/assets/ofn-logo-footer.png"
- #Other
+ # Other
preference :footer_facebook_url, :string, default: "https://www.facebook.com/OpenFoodNet"
preference :footer_twitter_url, :string, default: "https://twitter.com/OpenFoodNet"
preference :footer_instagram_url, :string, default: ""
@@ -69,10 +69,10 @@ class ContentConfiguration < Spree::Preferences::FileConfiguration
[News](/)
[Calendar](/)
-EOS
+ EOS
preference :footer_about_url, :string, default: "http://www.openfoodnetwork.org/ofn-local/open-food-network-australia/"
- #User Guide
+ # User Guide
preference :user_guide_link, :string, default: 'https://guide.openfoodnetwork.org/'
end
diff --git a/app/models/coordinator_fee.rb b/app/models/coordinator_fee.rb
index 135ee821a9..99aefc2595 100644
--- a/app/models/coordinator_fee.rb
+++ b/app/models/coordinator_fee.rb
@@ -5,11 +5,9 @@ class CoordinatorFee < ActiveRecord::Base
after_save :refresh_products_cache
after_destroy :refresh_products_cache
-
private
def refresh_products_cache
order_cycle.refresh_products_cache
end
-
end
diff --git a/app/models/distributor_shipping_method.rb b/app/models/distributor_shipping_method.rb
index e765a23e50..5c69d18084 100644
--- a/app/models/distributor_shipping_method.rb
+++ b/app/models/distributor_shipping_method.rb
@@ -1,5 +1,5 @@
class DistributorShippingMethod < ActiveRecord::Base
- self.table_name = "distributors_shipping_methods"
+ self.table_name = "distributors_shipping_methods"
belongs_to :shipping_method, class_name: Spree::ShippingMethod
belongs_to :distributor, class_name: Enterprise, touch: true
end
diff --git a/app/models/enterprise.rb b/app/models/enterprise.rb
index f4fb79b5b1..162031889b 100644
--- a/app/models/enterprise.rb
+++ b/app/models/enterprise.rb
@@ -1,5 +1,5 @@
class Enterprise < ActiveRecord::Base
- SELLS = %w(unspecified none own any)
+ SELLS = %w(unspecified none own any).freeze
ENTERPRISE_SEARCH_RADIUS = 100
preference :shopfront_message, :text, default: ""
@@ -17,18 +17,18 @@ class Enterprise < ActiveRecord::Base
self.inheritance_column = nil
- acts_as_gmappable :process_geocoding => false
+ acts_as_gmappable process_geocoding: false
has_many :relationships_as_parent, class_name: 'EnterpriseRelationship', foreign_key: 'parent_id', dependent: :destroy
has_many :relationships_as_child, class_name: 'EnterpriseRelationship', foreign_key: 'child_id', dependent: :destroy
has_and_belongs_to_many :groups, class_name: 'EnterpriseGroup'
has_many :producer_properties, foreign_key: 'producer_id'
has_many :properties, through: :producer_properties
- has_many :supplied_products, :class_name => 'Spree::Product', :foreign_key => 'supplier_id', :dependent => :destroy
- has_many :distributed_orders, :class_name => 'Spree::Order', :foreign_key => 'distributor_id'
- belongs_to :address, :class_name => 'Spree::Address'
+ has_many :supplied_products, class_name: 'Spree::Product', foreign_key: 'supplier_id', dependent: :destroy
+ has_many :distributed_orders, class_name: 'Spree::Order', foreign_key: 'distributor_id'
+ belongs_to :address, class_name: 'Spree::Address'
has_many :enterprise_fees
- has_many :enterprise_roles, :dependent => :destroy
+ 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', foreign_key: 'distributor_id'
@@ -39,24 +39,24 @@ class Enterprise < ActiveRecord::Base
has_many :tag_rules
has_one :stripe_account, dependent: :destroy
- delegate :latitude, :longitude, :city, :state_name, :to => :address
+ delegate :latitude, :longitude, :city, :state_name, to: :address
accepts_nested_attributes_for :address
accepts_nested_attributes_for :producer_properties, allow_destroy: true, reject_if: lambda { |pp| pp[:property_name].blank? }
accepts_nested_attributes_for :tag_rules, allow_destroy: true, reject_if: lambda { |tag_rule| tag_rule[:preferred_customer_tags].blank? }
has_attached_file :logo,
- styles: { medium: "300x300>", small: "180x180>", thumb: "100x100>" },
- url: '/images/enterprises/logos/:id/:style/:basename.:extension',
- path: 'public/images/enterprises/logos/:id/:style/:basename.:extension'
+ styles: { medium: "300x300>", small: "180x180>", thumb: "100x100>" },
+ url: '/images/enterprises/logos/:id/:style/:basename.:extension',
+ path: 'public/images/enterprises/logos/:id/:style/:basename.:extension'
has_attached_file :promo_image,
- styles: { large: ["1200x260#", :jpg], medium: ["720x156#", :jpg], thumb: ["100x100>", :jpg] },
- url: '/images/enterprises/promo_images/:id/:style/:basename.:extension',
- path: 'public/images/enterprises/promo_images/:id/:style/:basename.:extension'
+ styles: { large: ["1200x260#", :jpg], medium: ["720x156#", :jpg], thumb: ["100x100>", :jpg] },
+ url: '/images/enterprises/promo_images/:id/:style/:basename.:extension',
+ path: 'public/images/enterprises/promo_images/:id/:style/:basename.:extension'
- validates_attachment_content_type :logo, :content_type => /\Aimage\/.*\Z/
- validates_attachment_content_type :promo_image, :content_type => /\Aimage\/.*\Z/
+ validates_attachment_content_type :logo, content_type: /\Aimage\/.*\Z/
+ validates_attachment_content_type :promo_image, content_type: /\Aimage\/.*\Z/
include Spree::Core::S3Support
supports_s3 :logo
@@ -64,13 +64,13 @@ class Enterprise < ActiveRecord::Base
validates :name, presence: true
validate :name_is_unique
- validates :sells, presence: true, inclusion: {in: SELLS}
+ validates :sells, presence: true, inclusion: { in: SELLS }
validates :address, presence: true, associated: true
- validates_presence_of :owner
+ validates :owner, presence: true
validates :permalink, uniqueness: true, presence: true
validate :shopfront_taxons
validate :enforce_ownership_limit, if: lambda { owner_id_changed? && !owner_id.nil? }
- validates_length_of :description, :maximum => 255
+ validates :description, length: { maximum: 255 }
before_validation :initialize_permalink, if: lambda { permalink.nil? }
before_validation :ensure_owner_is_manager, if: lambda { owner_id_changed? && !owner_id.nil? }
@@ -103,29 +103,29 @@ class Enterprise < ActiveRecord::Base
where("TRUE")
end
}
- scope :is_primary_producer, where(:is_primary_producer => true)
+ scope :is_primary_producer, where(is_primary_producer: true)
scope :is_distributor, where('sells != ?', 'none')
scope :is_hub, where(sells: 'any')
scope :supplying_variant_in, lambda { |variants|
- joins(:supplied_products => :variants_including_master).
+ joins(supplied_products: :variants_including_master).
where('spree_variants.id IN (?)', variants).
select('DISTINCT enterprises.*')
}
scope :with_order_cycles_as_supplier_outer,
- joins("LEFT OUTER JOIN exchanges ON (exchanges.sender_id = enterprises.id AND exchanges.incoming = 't')").
+ joins("LEFT OUTER JOIN exchanges ON (exchanges.sender_id = enterprises.id AND exchanges.incoming = 't')").
joins('LEFT OUTER JOIN order_cycles ON (order_cycles.id = exchanges.order_cycle_id)')
scope :with_order_cycles_as_distributor_outer,
- joins("LEFT OUTER JOIN exchanges ON (exchanges.receiver_id = enterprises.id AND exchanges.incoming = 'f')").
+ joins("LEFT OUTER JOIN exchanges ON (exchanges.receiver_id = enterprises.id AND exchanges.incoming = 'f')").
joins('LEFT OUTER JOIN order_cycles ON (order_cycles.id = exchanges.order_cycle_id)')
scope :with_order_cycles_outer,
- joins("LEFT OUTER JOIN exchanges ON (exchanges.receiver_id = enterprises.id OR exchanges.sender_id = enterprises.id)").
+ joins("LEFT OUTER JOIN exchanges ON (exchanges.receiver_id = enterprises.id OR exchanges.sender_id = enterprises.id)").
joins('LEFT OUTER JOIN order_cycles ON (order_cycles.id = exchanges.order_cycle_id)')
scope :with_order_cycles_and_exchange_variants_outer,
- with_order_cycles_as_distributor_outer.
+ with_order_cycles_as_distributor_outer.
joins('LEFT OUTER JOIN exchange_variants ON (exchange_variants.exchange_id = exchanges.id)').
joins('LEFT OUTER JOIN spree_variants ON (spree_variants.id = exchange_variants.variant_id)')
@@ -171,7 +171,7 @@ class Enterprise < ActiveRecord::Base
end
def contact
- contact = users.where(enterprise_roles: {receives_notifications: true}).first
+ contact = users.where(enterprise_roles: { receives_notifications: true }).first
contact || owner
end
@@ -202,7 +202,7 @@ class Enterprise < ActiveRecord::Base
(SELECT child_id FROM enterprise_relationships WHERE enterprise_relationships.parent_id=?)
OR enterprises.id IN
(SELECT parent_id FROM enterprise_relationships WHERE enterprise_relationships.child_id=?)
- ", self.id, self.id)
+ ", id, id)
end
def plus_relatives_and_oc_producers(order_cycles)
@@ -215,23 +215,23 @@ class Enterprise < ActiveRecord::Base
end
def distributors
- self.relatives_including_self.is_distributor
+ relatives_including_self.is_distributor
end
def suppliers
- self.relatives_including_self.is_primary_producer
+ relatives_including_self.is_primary_producer
end
def website
- strip_url read_attribute(:website)
+ strip_url self[:website]
end
def facebook
- strip_url read_attribute(:facebook)
+ strip_url self[:facebook]
end
def linkedin
- strip_url read_attribute(:linkedin)
+ strip_url self[:linkedin]
end
def inventory_variants
@@ -247,18 +247,18 @@ class Enterprise < ActiveRecord::Base
end
def is_distributor
- self.sells != "none"
+ sells != "none"
end
def is_hub
- self.sells == 'any'
+ sells == 'any'
end
# Simplify enterprise categories for frontend logic and icons, and maybe other things.
def category
# Make this crazy logic human readable so we can argue about it sanely.
- cat = self.is_primary_producer ? "producer_" : "non_producer_"
- cat << "sells_" + self.sells
+ cat = is_primary_producer ? "producer_" : "non_producer_"
+ cat << "sells_" + sells
# Map backend cases to front end cases.
case cat
@@ -301,15 +301,15 @@ class Enterprise < ActiveRecord::Base
test_permalink = test_permalink.parameterize
test_permalink = "my-enterprise" if test_permalink.blank?
existing = Enterprise.select(:permalink).order(:permalink).where("permalink LIKE ?", "#{test_permalink}%").map(&:permalink)
- unless existing.include?(test_permalink)
- test_permalink
- else
+ if existing.include?(test_permalink)
used_indices = existing.map do |p|
p.slice!(/^#{test_permalink}/)
p.match(/^\d+$/).to_s.to_i
end.select{ |p| p }
options = (1..existing.length).to_a - used_indices
test_permalink + options.first.to_s
+ else
+ test_permalink
end
end
@@ -335,7 +335,7 @@ class Enterprise < ActiveRecord::Base
end
def send_welcome_email
- Delayed::Job.enqueue WelcomeEnterpriseJob.new(self.id)
+ Delayed::Job.enqueue WelcomeEnterpriseJob.new(id)
end
def strip_url(url)
@@ -361,7 +361,7 @@ class Enterprise < ActiveRecord::Base
end
def set_default_contact
- update_contact self.owner_id
+ update_contact owner_id
end
def relate_to_owners_enterprises
@@ -408,8 +408,8 @@ class Enterprise < ActiveRecord::Base
end
def touch_distributors
- Enterprise.distributing_products(self.supplied_products).
- where('enterprises.id != ?', self.id).
- each(&:touch)
+ Enterprise.distributing_products(supplied_products).
+ where('enterprises.id != ?', id).
+ find_each(&:touch)
end
end
diff --git a/app/models/enterprise_fee.rb b/app/models/enterprise_fee.rb
index 3cfc88db6b..aaeb5101d4 100644
--- a/app/models/enterprise_fee.rb
+++ b/app/models/enterprise_fee.rb
@@ -10,20 +10,17 @@ class EnterpriseFee < ActiveRecord::Base
has_many :exchange_fees, dependent: :destroy
has_many :exchanges, through: :exchange_fees
-
after_save :refresh_products_cache
# After destroy, the products cache is refreshed via the after_destroy hook for
# coordinator_fees and exchange_fees
-
attr_accessible :enterprise_id, :fee_type, :name, :tax_category_id, :calculator_type, :inherits_tax_category
- FEE_TYPES = %w(packing transport admin sales fundraising)
- PER_ORDER_CALCULATORS = ['Spree::Calculator::FlatRate', 'Spree::Calculator::FlexiRate', 'Spree::Calculator::PriceSack']
+ FEE_TYPES = %w(packing transport admin sales fundraising).freeze
+ PER_ORDER_CALCULATORS = ['Spree::Calculator::FlatRate', 'Spree::Calculator::FlexiRate', 'Spree::Calculator::PriceSack'].freeze
-
- validates_inclusion_of :fee_type, :in => FEE_TYPES
- validates_presence_of :name
+ validates :fee_type, inclusion: { in: FEE_TYPES }
+ validates :name, presence: true
before_save :ensure_valid_tax_category_settings
@@ -49,7 +46,6 @@ class EnterpriseFee < ActiveRecord::Base
order.adjustments.where(originator_type: 'EnterpriseFee').destroy_all
end
-
private
def ensure_valid_tax_category_settings
@@ -61,7 +57,7 @@ class EnterpriseFee < ActiveRecord::Base
elsif inherits_tax_category_changed?
self.tax_category_id = nil if inherits_tax_category?
end
- return true
+ true
end
def refresh_products_cache
diff --git a/app/models/enterprise_fee_set.rb b/app/models/enterprise_fee_set.rb
index e7cf857936..ae7ff692ad 100644
--- a/app/models/enterprise_fee_set.rb
+++ b/app/models/enterprise_fee_set.rb
@@ -1,5 +1,5 @@
class EnterpriseFeeSet < ModelSet
- def initialize(attributes={})
+ def initialize(attributes = {})
super(EnterpriseFee, EnterpriseFee.all,
attributes,
proc { |attrs| attrs[:name].blank? })
diff --git a/app/models/enterprise_group.rb b/app/models/enterprise_group.rb
index 48a2ec5524..f3f70a2a6c 100644
--- a/app/models/enterprise_group.rb
+++ b/app/models/enterprise_group.rb
@@ -7,7 +7,7 @@ class EnterpriseGroup < ActiveRecord::Base
has_and_belongs_to_many :enterprises
belongs_to :owner, class_name: 'Spree::User', foreign_key: :owner_id, inverse_of: :owned_groups
- belongs_to :address, :class_name => 'Spree::Address'
+ belongs_to :address, class_name: 'Spree::Address'
accepts_nested_attributes_for :address
validates :address, presence: true, associated: true
before_validation :set_undefined_address_fields
@@ -28,20 +28,20 @@ class EnterpriseGroup < ActiveRecord::Base
attr_accessible :address_attributes
attr_accessible :email, :website, :facebook, :instagram, :linkedin, :twitter
- delegate :phone, :address1, :address2, :city, :zipcode, :state, :country, :to => :address
+ delegate :phone, :address1, :address2, :city, :zipcode, :state, :country, to: :address
has_attached_file :logo,
- styles: {medium: "100x100"},
- url: '/images/enterprise_groups/logos/:id/:style/:basename.:extension',
- path: 'public/images/enterprise_groups/logos/:id/:style/:basename.:extension'
+ styles: { medium: "100x100" },
+ url: '/images/enterprise_groups/logos/:id/:style/:basename.:extension',
+ path: 'public/images/enterprise_groups/logos/:id/:style/:basename.:extension'
has_attached_file :promo_image,
- styles: {large: ["1200x260#", :jpg]},
- url: '/images/enterprise_groups/promo_images/:id/:style/:basename.:extension',
- path: 'public/images/enterprise_groups/promo_images/:id/:style/:basename.:extension'
+ styles: { large: ["1200x260#", :jpg] },
+ url: '/images/enterprise_groups/promo_images/:id/:style/:basename.:extension',
+ path: 'public/images/enterprise_groups/promo_images/:id/:style/:basename.:extension'
- validates_attachment_content_type :logo, :content_type => /\Aimage\/.*\Z/
- validates_attachment_content_type :promo_image, :content_type => /\Aimage\/.*\Z/
+ validates_attachment_content_type :logo, content_type: /\Aimage\/.*\Z/
+ validates_attachment_content_type :promo_image, content_type: /\Aimage\/.*\Z/
include Spree::Core::S3Support
supports_s3 :logo
@@ -70,7 +70,7 @@ class EnterpriseGroup < ActiveRecord::Base
end
def unset_undefined_address_fields
- return unless address.present?
+ return if address.blank?
address.phone.sub!(/^#{I18n.t(:undefined)}$/, '')
address.address1.sub!(/^#{I18n.t(:undefined)}$/, '')
address.city.sub!(/^#{I18n.t(:undefined)}$/, '')
diff --git a/app/models/enterprise_relationship.rb b/app/models/enterprise_relationship.rb
index 7af3d180a3..f64acfe7ae 100644
--- a/app/models/enterprise_relationship.rb
+++ b/app/models/enterprise_relationship.rb
@@ -3,14 +3,14 @@ class EnterpriseRelationship < ActiveRecord::Base
belongs_to :child, class_name: 'Enterprise', touch: true
has_many :permissions, class_name: 'EnterpriseRelationshipPermission', dependent: :destroy
- validates_presence_of :parent_id, :child_id
- validates_uniqueness_of :child_id, scope: :parent_id, message: I18n.t('validation_msg_relationship_already_established')
+ validates :parent_id, :child_id, presence: true
+ validates :child_id, uniqueness: { scope: :parent_id, message: I18n.t('validation_msg_relationship_already_established') }
after_save :update_permissions_of_child_variant_overrides
before_destroy :revoke_all_child_variant_overrides
scope :with_enterprises,
- joins('LEFT JOIN enterprises AS parent_enterprises ON parent_enterprises.id = enterprise_relationships.parent_id').
+ joins('LEFT JOIN enterprises AS parent_enterprises ON parent_enterprises.id = enterprise_relationships.parent_id').
joins('LEFT JOIN enterprises AS child_enterprises ON child_enterprises.id = enterprise_relationships.child_id')
scope :involving_enterprises, ->(enterprises) {
@@ -30,7 +30,7 @@ class EnterpriseRelationship < ActiveRecord::Base
# Load an array of the relatives of each enterprise (ie. any enterprise related to it in
# either direction). This array is split into distributors and producers, and has the format:
# {enterprise_id => {distributors: [id, ...], producers: [id, ...]} }
- def self.relatives(activated_only=false)
+ def self.relatives(activated_only = false)
relationships = EnterpriseRelationship.includes(:child, :parent)
relatives = {}
@@ -44,8 +44,8 @@ class EnterpriseRelationship < ActiveRecord::Base
end
relationships.each do |r|
- relatives[r.parent_id] ||= {distributors: Set.new, producers: Set.new}
- relatives[r.child_id] ||= {distributors: Set.new, producers: Set.new}
+ relatives[r.parent_id] ||= { distributors: Set.new, producers: Set.new }
+ relatives[r.child_id] ||= { distributors: Set.new, producers: Set.new }
if !activated_only || r.child.activated?
relatives[r.parent_id][:producers] << r.child_id if r.child.is_primary_producer
diff --git a/app/models/enterprise_role.rb b/app/models/enterprise_role.rb
index e69d439c40..6f8c6c6ef5 100644
--- a/app/models/enterprise_role.rb
+++ b/app/models/enterprise_role.rb
@@ -1,9 +1,9 @@
class EnterpriseRole < ActiveRecord::Base
- belongs_to :user, :class_name => Spree.user_class
+ belongs_to :user, class_name: Spree.user_class
belongs_to :enterprise
- validates_presence_of :user_id, :enterprise_id
- validates_uniqueness_of :enterprise_id, scope: :user_id, message: I18n.t(:enterprise_role_uniqueness_error)
+ validates :user_id, :enterprise_id, presence: true
+ 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/enterprise_set.rb b/app/models/enterprise_set.rb
index 123a6b5eed..20da64b083 100644
--- a/app/models/enterprise_set.rb
+++ b/app/models/enterprise_set.rb
@@ -1,5 +1,5 @@
class EnterpriseSet < ModelSet
- def initialize(collection, attributes={})
+ def initialize(collection, attributes = {})
super(Enterprise, collection, attributes)
end
end
diff --git a/app/models/exchange.rb b/app/models/exchange.rb
index 06bbafc4c2..fec02642e3 100644
--- a/app/models/exchange.rb
+++ b/app/models/exchange.rb
@@ -11,8 +11,8 @@ class Exchange < ActiveRecord::Base
has_many :exchange_fees, dependent: :destroy
has_many :enterprise_fees, through: :exchange_fees
- validates_presence_of :order_cycle, :sender, :receiver
- validates_uniqueness_of :sender_id, scope: [:order_cycle_id, :receiver_id, :incoming]
+ validates :order_cycle, :sender, :receiver, presence: true
+ validates :sender_id, uniqueness: { scope: [:order_cycle_id, :receiver_id, :incoming] }
after_save :refresh_products_cache
after_destroy :refresh_products_cache_from_destroy
@@ -53,13 +53,12 @@ class Exchange < ActiveRecord::Base
end
}
-
def clone!(new_order_cycle)
- exchange = self.dup
+ exchange = dup
exchange.order_cycle = new_order_cycle
- exchange.enterprise_fee_ids = self.enterprise_fee_ids
- exchange.variant_ids = self.variant_ids
- exchange.tag_ids = self.tag_ids
+ exchange.enterprise_fee_ids = enterprise_fee_ids
+ exchange.variant_ids = variant_ids
+ exchange.tag_ids = tag_ids
exchange.save!
exchange
end
@@ -72,15 +71,15 @@ class Exchange < ActiveRecord::Base
incoming? ? sender : receiver
end
- def to_h(core_only=false)
- h = attributes.merge({ 'variant_ids' => variant_ids.sort, 'enterprise_fee_ids' => enterprise_fee_ids.sort })
+ def to_h(core_only = false)
+ h = attributes.merge('variant_ids' => variant_ids.sort, 'enterprise_fee_ids' => enterprise_fee_ids.sort)
h.reject! { |k| %w(id order_cycle_id created_at updated_at).include? k } if core_only
h
end
def eql?(e)
if e.respond_to? :to_h
- self.to_h(true) == e.to_h(true)
+ to_h(true) == e.to_h(true)
else
super e
end
diff --git a/app/models/exchange_fee.rb b/app/models/exchange_fee.rb
index 03fce8ce04..27636f2f28 100644
--- a/app/models/exchange_fee.rb
+++ b/app/models/exchange_fee.rb
@@ -2,11 +2,9 @@ class ExchangeFee < ActiveRecord::Base
belongs_to :exchange
belongs_to :enterprise_fee
-
after_save :refresh_products_cache
after_destroy :refresh_products_cache
-
private
def refresh_products_cache
diff --git a/app/models/exchange_variant.rb b/app/models/exchange_variant.rb
index c7812845c8..69e7bec7ba 100644
--- a/app/models/exchange_variant.rb
+++ b/app/models/exchange_variant.rb
@@ -1,4 +1,4 @@
class ExchangeVariant < ActiveRecord::Base
belongs_to :exchange
- belongs_to :variant, :class_name => 'Spree::Variant'
+ belongs_to :variant, class_name: 'Spree::Variant'
end
diff --git a/app/models/inventory_item.rb b/app/models/inventory_item.rb
index 85afce6722..8479f6a1a9 100644
--- a/app/models/inventory_item.rb
+++ b/app/models/inventory_item.rb
@@ -16,7 +16,6 @@ class InventoryItem < ActiveRecord::Base
after_save :refresh_products_cache
-
private
def refresh_products_cache
diff --git a/app/models/model_set.rb b/app/models/model_set.rb
index 0236a00776..62d7e08002 100644
--- a/app/models/model_set.rb
+++ b/app/models/model_set.rb
@@ -5,7 +5,7 @@ class ModelSet
attr_accessor :collection
- def initialize(klass, collection, attributes={}, reject_if=nil, delete_if=nil)
+ def initialize(klass, collection, attributes = {}, reject_if = nil, delete_if = nil)
@klass, @collection, @reject_if, @delete_if = klass, collection, reject_if, delete_if
# Set here first, to ensure that we apply collection_attributes to the right collection
@@ -17,7 +17,7 @@ class ModelSet
end
def collection_attributes=(collection_attributes)
- collection_attributes.each do |k, attributes|
+ collection_attributes.each do |_k, attributes|
# attributes == {:id => 123, :next_collection_at => '...'}
e = @collection.detect { |e| e.id.to_s == attributes[:id].to_s && !e.id.nil? }
if e.nil?
diff --git a/app/models/order_cycle.rb b/app/models/order_cycle.rb
index 07b71d606c..3f665b86fd 100644
--- a/app/models/order_cycle.rb
+++ b/app/models/order_cycle.rb
@@ -1,12 +1,12 @@
require 'open_food_network/scope_variant_to_hub'
class OrderCycle < ActiveRecord::Base
- belongs_to :coordinator, :class_name => 'Enterprise'
+ belongs_to :coordinator, class_name: 'Enterprise'
has_many :coordinator_fee_refs, class_name: 'CoordinatorFee'
has_many :coordinator_fees, through: :coordinator_fee_refs, source: :enterprise_fee
- has_many :exchanges, :dependent => :destroy
+ has_many :exchanges, dependent: :destroy
# These scope names are prepended with "cached_" because there are existing accessor methods
# :incoming_exchanges and :outgoing_exchanges.
@@ -20,7 +20,7 @@ class OrderCycle < ActiveRecord::Base
attr_accessor :incoming_exchanges, :outgoing_exchanges
- validates_presence_of :name, :coordinator_id
+ validates :name, :coordinator_id, presence: true
validate :orders_close_at_after_orders_open_at?
after_save :refresh_products_cache
@@ -119,13 +119,13 @@ class OrderCycle < ActiveRecord::Base
end
def clone!
- oc = self.dup
+ oc = dup
oc.name = I18n.t("models.order_cycle.cloned_order_cycle_name", order_cycle: oc.name)
oc.orders_open_at = oc.orders_close_at = nil
- oc.coordinator_fee_ids = self.coordinator_fee_ids
- oc.preferred_product_selection_from_coordinator_inventory_only = self.preferred_product_selection_from_coordinator_inventory_only
+ oc.coordinator_fee_ids = coordinator_fee_ids
+ oc.preferred_product_selection_from_coordinator_inventory_only = preferred_product_selection_from_coordinator_inventory_only
oc.save!
- self.exchanges.each { |e| e.clone!(oc) }
+ exchanges.each { |e| e.clone!(oc) }
oc.reload
end
@@ -138,15 +138,15 @@ class OrderCycle < ActiveRecord::Base
end
def supplied_variants
- self.exchanges.incoming.map(&:variants).flatten.uniq.reject(&:deleted?)
+ exchanges.incoming.map(&:variants).flatten.uniq.reject(&:deleted?)
end
def distributed_variants
- self.exchanges.outgoing.map(&:variants).flatten.uniq.reject(&:deleted?)
+ exchanges.outgoing.map(&:variants).flatten.uniq.reject(&:deleted?)
end
def variants_distributed_by(distributor)
- return Spree::Variant.where("1=0") unless distributor.present?
+ return Spree::Variant.where("1=0") if distributor.blank?
Spree::Variant.
joins(:exchanges).
merge(distributor.inventory_variants).
@@ -160,15 +160,15 @@ class OrderCycle < ActiveRecord::Base
end
def products
- self.variants.map(&:product).uniq
+ variants.map(&:product).uniq
end
def has_distributor?(distributor)
- self.distributors.include? distributor
+ distributors.include? distributor
end
def has_variant?(variant)
- self.variants.include? variant
+ variants.include? variant
end
def dated?
@@ -176,20 +176,20 @@ class OrderCycle < ActiveRecord::Base
end
def undated?
- self.orders_open_at.nil? || self.orders_close_at.nil?
+ orders_open_at.nil? || orders_close_at.nil?
end
def upcoming?
- self.orders_open_at && Time.zone.now < self.orders_open_at
+ orders_open_at && Time.zone.now < orders_open_at
end
def open?
- self.orders_open_at && self.orders_close_at &&
- Time.zone.now > self.orders_open_at && Time.zone.now < self.orders_close_at
+ orders_open_at && orders_close_at &&
+ Time.zone.now > orders_open_at && Time.zone.now < orders_close_at
end
def closed?
- self.orders_close_at && Time.zone.now > self.orders_close_at
+ orders_close_at && Time.zone.now > orders_close_at
end
def exchange_for_distributor(distributor)
diff --git a/app/models/order_cycle_set.rb b/app/models/order_cycle_set.rb
index ed37d7e7d1..9f4fb4433e 100644
--- a/app/models/order_cycle_set.rb
+++ b/app/models/order_cycle_set.rb
@@ -1,5 +1,5 @@
class OrderCycleSet < ModelSet
- def initialize(collection, attributes={})
+ def initialize(collection, attributes = {})
super(OrderCycle, collection, attributes)
end
end
diff --git a/app/models/order_updater.rb b/app/models/order_updater.rb
index 95d2b96cfb..553c93ca74 100644
--- a/app/models/order_updater.rb
+++ b/app/models/order_updater.rb
@@ -9,12 +9,12 @@ class OrderUpdater < SimpleDelegator
# https://github.com/spree/spree/commit/38b8456183d11fc1e00e395e7c9154c76ef65b85
# https://github.com/spree/spree/commit/7b264acff7824f5b3dc6651c106631d8f30b147a
def update_payment_state
- last_payment_state = order.payment_state
+ last_payment_state = order.payment_state
- order.payment_state = infer_payment_state
- track_payment_state_change(last_payment_state)
+ order.payment_state = infer_payment_state
+ track_payment_state_change(last_payment_state)
- order.payment_state
+ order.payment_state
end
def before_save_hook
diff --git a/app/models/producer_property.rb b/app/models/producer_property.rb
index a21b5eb5a3..5f299b344f 100644
--- a/app/models/producer_property.rb
+++ b/app/models/producer_property.rb
@@ -2,14 +2,13 @@ class ProducerProperty < ActiveRecord::Base
belongs_to :producer, class_name: 'Enterprise', touch: true
belongs_to :property, class_name: 'Spree::Property'
- default_scope order("#{self.table_name}.position")
+ default_scope order("#{table_name}.position")
after_save :refresh_products_cache
after_destroy :refresh_products_cache_from_destroy
-
scope :ever_sold_by, ->(shop) {
- joins(producer: {supplied_products: {variants: {exchanges: :order_cycle}}}).
+ joins(producer: { supplied_products: { variants: { exchanges: :order_cycle } } }).
merge(Exchange.outgoing).
merge(Exchange.to_enterprise(shop)).
select('DISTINCT producer_properties.*')
@@ -20,19 +19,17 @@ class ProducerProperty < ActiveRecord::Base
merge(OrderCycle.active)
}
-
def property_name
property.name if property
end
def property_name=(name)
- unless name.blank?
+ if name.present?
self.property = Spree::Property.find_by_name(name) ||
- Spree::Property.create(name: name, presentation: name)
+ Spree::Property.create(name: name, presentation: name)
end
end
-
private
def refresh_products_cache
@@ -42,5 +39,4 @@ class ProducerProperty < ActiveRecord::Base
def refresh_products_cache_from_destroy
OpenFoodNetwork::ProductsCache.producer_property_destroyed self
end
-
end
diff --git a/app/models/product_import/product_importer.rb b/app/models/product_import/product_importer.rb
index 1693cec8f5..e7a7f8792f 100644
--- a/app/models/product_import/product_importer.rb
+++ b/app/models/product_import/product_importer.rb
@@ -59,7 +59,7 @@ module ProductImport
def product_field_errors?
@entries.each do |entry|
- return true if entry.errors.messages.values.include? [I18n.t('admin.product_import.model.not_updatable')]
+ return true if entry.errors.messages.value?([I18n.t('admin.product_import.model.not_updatable')])
end
false
end
diff --git a/app/models/product_import/unit_converter.rb b/app/models/product_import/unit_converter.rb
index fcc8d3686a..e97cff43f9 100644
--- a/app/models/product_import/unit_converter.rb
+++ b/app/models/product_import/unit_converter.rb
@@ -32,7 +32,7 @@ module ProductImport
{
'g' => { scale: 1, unit: 'weight' },
'kg' => { scale: 1000, unit: 'weight' },
- 't' => { scale: 1000000, unit: 'weight' },
+ 't' => { scale: 1_000_000, unit: 'weight' },
'ml' => { scale: 0.001, unit: 'volume' },
'l' => { scale: 1, unit: 'volume' },
'kl' => { scale: 1000, unit: 'volume' }
diff --git a/app/models/spree/ability_decorator.rb b/app/models/spree/ability_decorator.rb
index 3d858dc7e6..5cbab5831e 100644
--- a/app/models/spree/ability_decorator.rb
+++ b/app/models/spree/ability_decorator.rb
@@ -32,14 +32,14 @@ class AbilityDecorator
# Users can manage products if they have an enterprise that is not a profile.
def can_manage_products?(user)
can_manage_enterprises?(user) &&
- user.enterprises.any? { |e| e.category != :hub_profile && e.producer_profile_only != true }
+ user.enterprises.any? { |e| e.category != :hub_profile && e.producer_profile_only != true }
end
# Users can manage order cycles if they manage a sells own/any enterprise
# OR if they manage a producer which is included in any order cycles
def can_manage_order_cycles?(user)
can_manage_orders?(user) ||
- OrderCycle.accessible_by(user).any?
+ OrderCycle.accessible_by(user).any?
end
# Users can manage orders if they have a sells own/any enterprise.
@@ -54,7 +54,7 @@ class AbilityDecorator
def add_shopping_abilities(user)
can [:destroy], Spree::LineItem do |item|
user == item.order.user &&
- item.order.changes_allowed?
+ item.order.changes_allowed?
end
can [:cancel], Spree::Order do |order|
@@ -71,7 +71,7 @@ class AbilityDecorator
end
# New users can create an enterprise, and gain other permissions from doing this.
- def add_base_abilities(user)
+ def add_base_abilities(_user)
can [:create], Enterprise
end
diff --git a/app/models/spree/adjustment_decorator.rb b/app/models/spree/adjustment_decorator.rb
index 13cf2827da..23790219e9 100644
--- a/app/models/spree/adjustment_decorator.rb
+++ b/app/models/spree/adjustment_decorator.rb
@@ -32,7 +32,7 @@ module Spree
end
def display_included_tax
- Spree::Money.new(included_tax, { :currency => currency })
+ Spree::Money.new(included_tax, currency: currency)
end
def has_tax?
diff --git a/app/models/spree/calculator/default_tax_decorator.rb b/app/models/spree/calculator/default_tax_decorator.rb
index a70bb4f8ba..ccc73abb9f 100644
--- a/app/models/spree/calculator/default_tax_decorator.rb
+++ b/app/models/spree/calculator/default_tax_decorator.rb
@@ -1,7 +1,6 @@
require 'open_food_network/enterprise_fee_calculator'
Spree::Calculator::DefaultTax.class_eval do
-
private
# Override this method to enable calculation of tax for
@@ -19,8 +18,9 @@ Spree::Calculator::DefaultTax.class_eval do
# Added this block, finds relevant fees for each line_item, calculates the tax on them, and returns the total tax
per_item_fees_total = order.line_items.sum do |line_item|
calculator.per_item_enterprise_fee_applicators_for(line_item.variant)
- .select { |applicator| (!applicator.enterprise_fee.inherits_tax_category && applicator.enterprise_fee.tax_category == rate.tax_category) ||
- (applicator.enterprise_fee.inherits_tax_category && line_item.product.tax_category == rate.tax_category)
+ .select { |applicator|
+ (!applicator.enterprise_fee.inherits_tax_category && applicator.enterprise_fee.tax_category == rate.tax_category) ||
+ (applicator.enterprise_fee.inherits_tax_category && line_item.product.tax_category == rate.tax_category)
}
.sum { |applicator| applicator.enterprise_fee.compute_amount(line_item) }
end
@@ -37,5 +37,4 @@ Spree::Calculator::DefaultTax.class_eval do
round_to_two_places(total * rate.amount)
end
end
-
end
diff --git a/app/models/spree/calculator/flat_percent_item_total_decorator.rb b/app/models/spree/calculator/flat_percent_item_total_decorator.rb
index 0393d300f7..ae95f59ca2 100644
--- a/app/models/spree/calculator/flat_percent_item_total_decorator.rb
+++ b/app/models/spree/calculator/flat_percent_item_total_decorator.rb
@@ -8,7 +8,7 @@ module Spree
def compute(object)
item_total = line_items_for(object).map(&:amount).sum
- value = item_total * BigDecimal(self.preferred_flat_percent.to_s) / 100.0
+ value = item_total * BigDecimal(preferred_flat_percent.to_s) / 100.0
(value * 100).round.to_f / 100
end
end
diff --git a/app/models/spree/calculator/flexi_rate_decorator.rb b/app/models/spree/calculator/flexi_rate_decorator.rb
index d2b0457b44..de112f4f0b 100644
--- a/app/models/spree/calculator/flexi_rate_decorator.rb
+++ b/app/models/spree/calculator/flexi_rate_decorator.rb
@@ -13,14 +13,14 @@ module Spree
def compute(object)
sum = 0
- max = self.preferred_max_items.to_i
+ max = preferred_max_items.to_i
items_count = line_items_for(object).map(&:quantity).sum
# check max value to avoid divide by 0 errors
unless max == 0
if items_count > max
- sum += (max - 1) * self.preferred_additional_item.to_f + self.preferred_first_item.to_f
+ sum += (max - 1) * preferred_additional_item.to_f + preferred_first_item.to_f
elsif items_count <= max
- sum += (items_count - 1) * self.preferred_additional_item.to_f + self.preferred_first_item.to_f
+ sum += (items_count - 1) * preferred_additional_item.to_f + preferred_first_item.to_f
end
end
diff --git a/app/models/spree/calculator/per_item_decorator.rb b/app/models/spree/calculator/per_item_decorator.rb
index 9f4ecb17c4..897b1217c4 100644
--- a/app/models/spree/calculator/per_item_decorator.rb
+++ b/app/models/spree/calculator/per_item_decorator.rb
@@ -10,14 +10,14 @@ module Spree
I18n.t(:flat_rate_per_item)
end
- def compute(object=nil)
+ def compute(object = nil)
return 0 if object.nil?
- self.preferred_amount * line_items_for(object).reduce(0) do |sum, value|
- if matching_products.blank? || matching_products.include?(value.product)
- value_to_add = value.quantity
- else
- value_to_add = 0
- end
+ preferred_amount * line_items_for(object).reduce(0) do |sum, value|
+ value_to_add = if matching_products.blank? || matching_products.include?(value.product)
+ value.quantity
+ else
+ 0
+ end
sum + value_to_add
end
end
diff --git a/app/models/spree/classification_decorator.rb b/app/models/spree/classification_decorator.rb
index a1dacdc84e..8cb9f7cc66 100644
--- a/app/models/spree/classification_decorator.rb
+++ b/app/models/spree/classification_decorator.rb
@@ -8,14 +8,14 @@ Spree::Classification.class_eval do
private
def refresh_products_cache
- product = Spree::Product.with_deleted.find(product_id) unless product.present?
+ product = Spree::Product.with_deleted.find(product_id) if product.blank?
product.refresh_products_cache
end
def dont_destroy_if_primary_taxon
if product.primary_taxon == taxon
- errors.add :base, I18n.t(:spree_classification_primary_taxon_error, taxon: taxon.name, product: product.name)
- return false
+ errors.add :base, I18n.t(:spree_classification_primary_taxon_error, taxon: taxon.name, product: product.name)
+ false
end
end
end
diff --git a/app/models/spree/gateway/migs.rb b/app/models/spree/gateway/migs.rb
index bfffc6de12..06f31c48e8 100644
--- a/app/models/spree/gateway/migs.rb
+++ b/app/models/spree/gateway/migs.rb
@@ -5,13 +5,12 @@ module Spree
attr_accessible :preferred_login, :preferred_password
-
def provider_class
ActiveMerchant::Billing::MigsGateway
end
def options_with_test_preference
- options_without_test_preference.merge(:test => self.preferred_test_mode)
+ options_without_test_preference.merge(test: preferred_test_mode)
end
alias_method_chain :options, :test_preference
diff --git a/app/models/spree/gateway/pin.rb b/app/models/spree/gateway/pin.rb
index 8cb3f73e85..127c2adeac 100644
--- a/app/models/spree/gateway/pin.rb
+++ b/app/models/spree/gateway/pin.rb
@@ -4,13 +4,12 @@ module Spree
attr_accessible :preferred_api_key
-
def provider_class
ActiveMerchant::Billing::PinGateway
end
def options_with_test_preference
- options_without_test_preference.merge(:test => self.preferred_test_mode)
+ options_without_test_preference.merge(test: preferred_test_mode)
end
alias_method_chain :options, :test_preference
diff --git a/app/models/spree/gateway/stripe_connect.rb b/app/models/spree/gateway/stripe_connect.rb
index 2f192eb655..9684288a9f 100644
--- a/app/models/spree/gateway/stripe_connect.rb
+++ b/app/models/spree/gateway/stripe_connect.rb
@@ -63,7 +63,7 @@ module Spree
# In this gateway, what we call 'secret_key' is the 'login'
def options
options = super
- options.merge(:login => Stripe.api_key)
+ options.merge(login: Stripe.api_key)
end
def options_for_purchase_or_auth(money, creditcard, gateway_options)
@@ -97,7 +97,7 @@ 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/gateway_decorator.rb b/app/models/spree/gateway_decorator.rb
index b87ef71621..c62702a321 100644
--- a/app/models/spree/gateway_decorator.rb
+++ b/app/models/spree/gateway_decorator.rb
@@ -4,6 +4,6 @@ Spree::Gateway.class_eval do
include Spree::PaymentMethodDistributors
# Default to live
- preference :server, :string, :default => 'live'
- preference :test_mode, :boolean, :default => false
+ preference :server, :string, default: 'live'
+ preference :test_mode, :boolean, default: false
end
diff --git a/app/models/spree/image_decorator.rb b/app/models/spree/image_decorator.rb
index 24056926b7..90f62854db 100644
--- a/app/models/spree/image_decorator.rb
+++ b/app/models/spree/image_decorator.rb
@@ -24,7 +24,6 @@ Spree::Image.class_eval do
reformat_styles
-
private
def refresh_products_cache
diff --git a/app/models/spree/line_item_decorator.rb b/app/models/spree/line_item_decorator.rb
index d64c02155d..c0eb6b7d36 100644
--- a/app/models/spree/line_item_decorator.rb
+++ b/app/models/spree/line_item_decorator.rb
@@ -6,13 +6,13 @@ Spree::LineItem.class_eval do
has_and_belongs_to_many :option_values, join_table: 'spree_option_values_line_items', class_name: 'Spree::OptionValue'
# Redefining here to add the inverse_of option
- belongs_to :order, :class_name => "Spree::Order", inverse_of: :line_items
+ belongs_to :order, class_name: "Spree::Order", inverse_of: :line_items
# Allows manual skipping of Stock::AvailabilityValidator
attr_accessor :skip_stock_check
attr_accessible :max_quantity, :final_weight_volume, :price
- attr_accessible :final_weight_volume, :price, :as => :api
+ attr_accessible :final_weight_volume, :price, as: :api
attr_accessible :skip_stock_check
before_save :calculate_final_weight_volume, if: :quantity_changed?, unless: :final_weight_volume_changed?
@@ -28,7 +28,7 @@ Spree::LineItem.class_eval do
scoped
else
# Find line items that are from orders distributed by the user or supplied by the user
- joins(:variant => :product).
+ joins(variant: :product).
joins(:order).
where('spree_orders.distributor_id IN (?) OR spree_products.supplier_id IN (?)', user.enterprises, user.enterprises).
select('spree_line_items.*')
@@ -61,7 +61,6 @@ Spree::LineItem.class_eval do
scope :without_tax, joins("LEFT OUTER JOIN spree_adjustments ON (spree_adjustments.adjustable_id=spree_line_items.id AND spree_adjustments.adjustable_type = 'Spree::LineItem' AND spree_adjustments.originator_type='Spree::TaxRate')").
where('spree_adjustments.id IS NULL')
-
def cap_quantity_at_stock!
scoper.scope(variant)
return if variant.on_demand
@@ -88,7 +87,7 @@ Spree::LineItem.class_eval do
end
def single_display_amount_with_adjustments
- Spree::Money.new(price_with_adjustments, { :currency => currency })
+ Spree::Money.new(price_with_adjustments, currency: currency)
end
def amount_with_adjustments
@@ -98,16 +97,14 @@ Spree::LineItem.class_eval do
end
def display_amount_with_adjustments
- Spree::Money.new(amount_with_adjustments, { :currency => currency })
+ Spree::Money.new(amount_with_adjustments, currency: currency)
end
def display_included_tax
- Spree::Money.new(included_tax, { :currency => currency })
+ Spree::Money.new(included_tax, currency: currency)
end
- def display_name
- variant.display_name
- end
+ delegate :display_name, to: :variant
def unit_value
return variant.unit_value if quantity == 0 || !final_weight_volume
diff --git a/app/models/spree/money_decorator.rb b/app/models/spree/money_decorator.rb
index e179343bc5..ae4ca7e497 100644
--- a/app/models/spree/money_decorator.rb
+++ b/app/models/spree/money_decorator.rb
@@ -1,6 +1,5 @@
Spree::Money.class_eval do
-
- # return the currency symbol (on it's own) for the current default currency
+ # return the currency symbol (on it's own) for the current default currency
def self.currency_symbol
Money.new(0, Spree::Config[:currency]).symbol
end
diff --git a/app/models/spree/option_type_decorator.rb b/app/models/spree/option_type_decorator.rb
index e3ca3b30de..2ebdece88c 100644
--- a/app/models/spree/option_type_decorator.rb
+++ b/app/models/spree/option_type_decorator.rb
@@ -3,7 +3,6 @@ module Spree
has_many :products, through: :product_option_types
after_save :refresh_products_cache
-
private
def refresh_products_cache
diff --git a/app/models/spree/option_value_decorator.rb b/app/models/spree/option_value_decorator.rb
index 5420af811c..48d88ff26e 100644
--- a/app/models/spree/option_value_decorator.rb
+++ b/app/models/spree/option_value_decorator.rb
@@ -3,7 +3,6 @@ module Spree
after_save :refresh_products_cache
around_destroy :refresh_products_cache_from_destroy
-
private
def refresh_products_cache
@@ -15,6 +14,5 @@ module Spree
yield
vs.each(&:refresh_products_cache)
end
-
end
end
diff --git a/app/models/spree/order_decorator.rb b/app/models/spree/order_decorator.rb
index f3aadce330..fec601be76 100644
--- a/app/models/spree/order_decorator.rb
+++ b/app/models/spree/order_decorator.rb
@@ -3,7 +3,7 @@ require 'open_food_network/feature_toggle'
require 'open_food_network/tag_rule_applicator'
require 'concerns/order_shipment'
-ActiveSupport::Notifications.subscribe('spree.order.contents_changed') do |name, start, finish, id, payload|
+ActiveSupport::Notifications.subscribe('spree.order.contents_changed') do |_name, _start, _finish, _id, payload|
payload[:order].reload.update_distribution_charge!
end
@@ -20,12 +20,12 @@ Spree::Order.class_eval do
# This change is done in Spree 2.1 (see https://github.com/spree/spree/commit/3fa44165c7825f79a2fa4eb79b99dc29944c5d55)
# When OFN gets to Spree 2.1, this can be removed
has_many :adjustments,
- as: :adjustable,
- dependent: :destroy,
- order: "#{Spree::Adjustment.table_name}.created_at ASC"
+ as: :adjustable,
+ dependent: :destroy,
+ order: "#{Spree::Adjustment.table_name}.created_at ASC"
validates :customer, presence: true, if: :require_customer?
- validate :products_available_from_new_distribution, :if => lambda { distributor_id_changed? || order_cycle_id_changed? }
+ validate :products_available_from_new_distribution, if: lambda { distributor_id_changed? || order_cycle_id_changed? }
validate :disallow_guest_order
attr_accessible :order_cycle_id, :distributor_id, :customer_id
@@ -126,11 +126,10 @@ Spree::Order.class_eval do
# Notify bugsnag if we get line items with a quantity of zero
if quantity == 0
- Bugsnag.notify(RuntimeError.new("Zero Quantity Line Item"), {
- current_item: current_item.as_json,
- line_items: line_items.map(&:id),
- variant: variant.as_json
- })
+ Bugsnag.notify(RuntimeError.new("Zero Quantity Line Item"),
+ current_item: current_item.as_json,
+ line_items: line_items.map(&:id),
+ variant: variant.as_json)
end
if current_item
@@ -188,7 +187,7 @@ Spree::Order.class_eval do
def set_distributor!(distributor)
self.distributor = distributor
- self.order_cycle = nil unless self.order_cycle.andand.has_distributor? distributor
+ self.order_cycle = nil unless order_cycle.andand.has_distributor? distributor
save!
end
@@ -279,11 +278,11 @@ Spree::Order.class_eval do
def tax_adjustments
adjustments.with_tax +
- line_items.includes(:adjustments).map {|li| li.adjustments.with_tax }.flatten
+ line_items.includes(:adjustments).map { |li| li.adjustments.with_tax }.flatten
end
def tax_adjustment_totals
- tax_adjustments.each_with_object(Hash.new) do |adjustment, hash|
+ tax_adjustments.each_with_object({}) do |adjustment, hash|
tax_rates = TaxRateFinder.tax_rates_of(adjustment)
tax_rates_hash = Hash[tax_rates.collect do |tax_rate|
tax_amount = tax_rates.one? ? adjustment.included_tax : tax_rate.compute_tax(adjustment.amount)
@@ -301,12 +300,12 @@ Spree::Order.class_eval do
end
def has_taxes_included
- not line_items.with_tax.empty?
+ !line_items.with_tax.empty?
end
# Overrride of Spree method, that allows us to send separate confirmation emails to user and shop owners
def deliver_order_confirmation_email
- unless subscription.present?
+ if subscription.blank?
Delayed::Job.enqueue ConfirmOrderJob.new(id)
end
end
diff --git a/app/models/spree/payment_decorator.rb b/app/models/spree/payment_decorator.rb
index 9c57df884a..29529d2d62 100644
--- a/app/models/spree/payment_decorator.rb
+++ b/app/models/spree/payment_decorator.rb
@@ -44,8 +44,7 @@ module Spree
end
alias_method_chain :actions, :pin_payment_adaptations
-
- def refund!(refund_amount=nil)
+ def refund!(refund_amount = nil)
protect_from_connection_error do
check_environment
@@ -60,12 +59,12 @@ module Spree
record_response(response)
if response.success?
- self.class.create({ :order => order,
- :source => self,
- :payment_method => payment_method,
- :amount => refund_amount.abs * -1,
- :response_code => response.authorization,
- :state => 'completed' }, :without_protection => true)
+ self.class.create({ order: order,
+ source: self,
+ payment_method: payment_method,
+ amount: refund_amount.abs * -1,
+ response_code: response.authorization,
+ state: 'completed' }, without_protection: true)
else
gateway_error(response)
end
@@ -84,7 +83,7 @@ module Spree
private
- def calculate_refund_amount(refund_amount=nil)
+ def calculate_refund_amount(refund_amount = nil)
refund_amount ||= credit_allowed >= order.outstanding_balance.abs ? order.outstanding_balance.abs : credit_allowed.abs
refund_amount.to_f
end
diff --git a/app/models/spree/payment_method_decorator.rb b/app/models/spree/payment_method_decorator.rb
index 1d3a502c13..69fa1e1f88 100644
--- a/app/models/spree/payment_method_decorator.rb
+++ b/app/models/spree/payment_method_decorator.rb
@@ -40,14 +40,14 @@ Spree::PaymentMethod.class_eval do
scope :by_name, order('spree_payment_methods.name ASC')
# Rewrite Spree's ruby-land class method as a scope
- scope :available, lambda { |display_on='both'|
+ scope :available, lambda { |display_on = 'both'|
where(active: true).
where('spree_payment_methods.display_on=? OR spree_payment_methods.display_on=? OR spree_payment_methods.display_on IS NULL', display_on, '').
where('spree_payment_methods.environment=? OR spree_payment_methods.environment=? OR spree_payment_methods.environment IS NULL', Rails.env, '')
}
def init
- unless reflections.keys.include? :calculator
+ unless reflections.key?(:calculator)
self.class.include Spree::Core::CalculatedAdjustments
end
@@ -55,7 +55,7 @@ Spree::PaymentMethod.class_eval do
end
def has_distributor?(distributor)
- self.distributors.include?(distributor)
+ distributors.include?(distributor)
end
def self.clean_name
diff --git a/app/models/spree/preference_decorator.rb b/app/models/spree/preference_decorator.rb
index 4a42a7dea7..e5ad7cbda2 100644
--- a/app/models/spree/preference_decorator.rb
+++ b/app/models/spree/preference_decorator.rb
@@ -12,7 +12,6 @@ module Spree
end
end
-
private
def product_selection_from_inventory_only_changed?
diff --git a/app/models/spree/preferences/file_configuration.rb b/app/models/spree/preferences/file_configuration.rb
index f918f52af5..5a95a42487 100644
--- a/app/models/spree/preferences/file_configuration.rb
+++ b/app/models/spree/preferences/file_configuration.rb
@@ -1,6 +1,5 @@
module Spree::Preferences
class FileConfiguration < Configuration
-
def self.preference(name, type, *args)
if type == :file
super "#{name}_file_name", :string, *args
@@ -22,7 +21,6 @@ module Spree::Preferences
end
alias :[] :get_preference
-
def preference_type(name)
if has_attachment? name
:file
@@ -34,14 +32,14 @@ module Spree::Preferences
# Spree's Configuration responds to preference methods via method_missing, but doesn't
# override respond_to?, which consequently reports those methods as unavailable. Paperclip
# errors if respond_to? isn't correct, so we override it here.
- def respond_to?(method, include_all=false)
- name = method.to_s.gsub('=', '')
+ def respond_to?(method, include_all = false)
+ name = method.to_s.delete('=')
super(self.class.preference_getter_method(name), include_all) || super(method, include_all)
end
def has_attachment?(name)
self.class.respond_to?(:attachment_definitions) &&
- self.class.attachment_definitions.keys.include?(name.to_sym)
+ self.class.attachment_definitions.key?(name.to_sym)
end
end
end
diff --git a/app/models/spree/price_decorator.rb b/app/models/spree/price_decorator.rb
index f50a86066b..79e809b8ba 100644
--- a/app/models/spree/price_decorator.rb
+++ b/app/models/spree/price_decorator.rb
@@ -2,7 +2,6 @@ module Spree
Price.class_eval do
after_save :refresh_products_cache
-
private
def refresh_products_cache
diff --git a/app/models/spree/product_decorator.rb b/app/models/spree/product_decorator.rb
index 718c9c3cbb..c7a41e5698 100644
--- a/app/models/spree/product_decorator.rb
+++ b/app/models/spree/product_decorator.rb
@@ -9,9 +9,9 @@ Spree::Product.class_eval do
# We have an after_destroy callback on Spree::ProductOptionType. However, if we
# don't specify dependent => destroy on this association, it is not called. See:
# https://github.com/rails/rails/issues/7618
- has_many :option_types, :through => :product_option_types, :dependent => :destroy
+ has_many :option_types, through: :product_option_types, dependent: :destroy
- belongs_to :supplier, :class_name => 'Enterprise', touch: true
+ belongs_to :supplier, class_name: 'Enterprise', touch: true
belongs_to :primary_taxon, class_name: 'Spree::Taxon'
delegate_belongs_to :master, :unit_value, :unit_description
@@ -22,17 +22,17 @@ Spree::Product.class_eval do
attr_accessible :variant_unit, :variant_unit_scale, :variant_unit_name, :unit_value
attr_accessible :inherits_properties, :sku
- validates_presence_of :supplier
+ validates :supplier, presence: true
validates :primary_taxon, presence: true
validates :tax_category_id, presence: true, if: "Spree::Config.products_require_tax_category"
- validates_presence_of :variant_unit
- validates_presence_of :variant_unit_scale,
- if: -> p { %w(weight volume).include? p.variant_unit }
- validates_presence_of :variant_unit_name,
- if: -> p { p.variant_unit == 'items' }
+ validates :variant_unit, presence: true
+ validates :variant_unit_scale,
+ presence: { if: ->(p) { %w(weight volume).include? p.variant_unit } }
+ validates :variant_unit_name,
+ presence: { if: ->(p) { p.variant_unit == 'items' } }
- after_initialize :set_available_on_to_now, :if => :new_record?
+ after_initialize :set_available_on_to_now, if: :new_record?
before_validation :sanitize_permalink
before_save :add_primary_taxon_to_taxons
after_save :remove_previous_primary_taxon_from_taxons
@@ -40,14 +40,13 @@ Spree::Product.class_eval do
after_save :update_units
after_save :refresh_products_cache
-
# -- Joins
scope :with_order_cycles_outer, joins('LEFT OUTER JOIN spree_variants AS o_spree_variants ON (o_spree_variants.product_id = spree_products.id)').
joins('LEFT OUTER JOIN exchange_variants AS o_exchange_variants ON (o_exchange_variants.variant_id = o_spree_variants.id)').
joins('LEFT OUTER JOIN exchanges AS o_exchanges ON (o_exchanges.id = o_exchange_variants.exchange_id)').
joins('LEFT OUTER JOIN order_cycles AS o_order_cycles ON (o_order_cycles.id = o_exchanges.order_cycle_id)')
- scope :with_order_cycles_inner, joins(:variants_including_master => {:exchanges => :order_cycle})
+ scope :with_order_cycles_inner, joins(variants_including_master: { exchanges: :order_cycle })
scope :visible_for, lambda { |enterprise|
joins('LEFT OUTER JOIN spree_variants AS o_spree_variants ON (o_spree_variants.product_id = spree_products.id)').
@@ -56,9 +55,8 @@ Spree::Product.class_eval do
select('DISTINCT spree_products.*')
}
-
# -- Scopes
- scope :in_supplier, lambda { |supplier| where(:supplier_id => supplier) }
+ scope :in_supplier, lambda { |supplier| where(supplier_id: supplier) }
# Products distributed via the given distributor through an OC
scope :in_distributor, lambda { |distributor|
@@ -82,15 +80,17 @@ Spree::Product.class_eval do
}
# Products distributed by the given order cycle
- scope :in_order_cycle, lambda { |order_cycle| with_order_cycles_inner.
- merge(Exchange.outgoing).
- where('order_cycles.id = ?', order_cycle)
+ scope :in_order_cycle, lambda { |order_cycle|
+ with_order_cycles_inner.
+ merge(Exchange.outgoing).
+ where('order_cycles.id = ?', order_cycle)
}
- scope :in_an_active_order_cycle, lambda { with_order_cycles_inner.
- merge(OrderCycle.active).
- merge(Exchange.outgoing).
- where('order_cycles.id IS NOT NULL')
+ scope :in_an_active_order_cycle, lambda {
+ with_order_cycles_inner.
+ merge(OrderCycle.active).
+ merge(Exchange.outgoing).
+ where('order_cycles.id IS NOT NULL')
}
scope :by_producer, joins(:supplier).order('enterprises.name')
@@ -111,13 +111,12 @@ Spree::Product.class_eval do
return where('spree_products.supplier_id IN (?)', [enterprise.id] | permitted_producer_ids)
}
-
# -- Methods
# Called by Spree::Product::duplicate before saving.
- def duplicate_extra(parent)
+ def duplicate_extra(_parent)
# Spree sets the SKU to "COPY OF #{parent sku}".
- self.master.sku = ''
+ master.sku = ''
end
def properties_including_inherited
@@ -129,8 +128,8 @@ Spree::Product.class_eval do
end
ps.
- sort_by { |pp| pp.position }.
- map { |pp| {id: pp.property.id, name: pp.property.presentation, value: pp.value} }
+ sort_by(&:position).
+ map { |pp| { id: pp.property.id, name: pp.property.presentation, value: pp.value } }
end
def in_distributor?(distributor)
@@ -178,7 +177,7 @@ Spree::Product.class_eval do
OpenFoodNetwork::ProductsCache.product_deleted(self) do
touch_distributors
- ExchangeVariant.where('exchange_variants.variant_id IN (?)', self.variants_including_master.with_deleted).destroy_all
+ ExchangeVariant.where('exchange_variants.variant_id IN (?)', variants_including_master.with_deleted).destroy_all
destroy_without_delete_from_order_cycles
end
@@ -186,12 +185,10 @@ Spree::Product.class_eval do
end
alias_method_chain :destroy, :delete_from_order_cycles
-
def refresh_products_cache
OpenFoodNetwork::ProductsCache.product_changed self
end
-
private
def set_available_on_to_now
@@ -225,10 +222,10 @@ Spree::Product.class_eval do
def ensure_standard_variant
if master.valid? && variants.empty?
- variant = self.master.dup
+ variant = master.dup
variant.product = self
variant.is_master = false
- self.variants << variant
+ variants << variant
end
end
@@ -250,7 +247,7 @@ Spree::Product.class_eval do
# and will be destroyed
rescue ActiveRecord::RecordInvalid
master.errors.each do |att, error|
- self.errors.add(att, error)
+ errors.add(att, error)
end
raise
end
diff --git a/app/models/spree/product_option_type_decorator.rb b/app/models/spree/product_option_type_decorator.rb
index 6410c014a4..8e5a909058 100644
--- a/app/models/spree/product_option_type_decorator.rb
+++ b/app/models/spree/product_option_type_decorator.rb
@@ -2,8 +2,8 @@ Spree::ProductOptionType.class_eval do
after_destroy :remove_option_values
def remove_option_values
- self.product.variants_including_master.each do |variant|
- option_values = variant.option_values.where(option_type_id: self.option_type)
+ product.variants_including_master.each do |variant|
+ option_values = variant.option_values.where(option_type_id: option_type)
variant.option_values.destroy(*option_values)
end
end
diff --git a/app/models/spree/product_property_decorator.rb b/app/models/spree/product_property_decorator.rb
index 47414e92dc..34432fb310 100644
--- a/app/models/spree/product_property_decorator.rb
+++ b/app/models/spree/product_property_decorator.rb
@@ -5,9 +5,6 @@ module Spree
after_save :refresh_products_cache
after_destroy :refresh_products_cache
-
- def refresh_products_cache
- product.refresh_products_cache
- end
+ delegate :refresh_products_cache, to: :product
end
end
diff --git a/app/models/spree/product_set.rb b/app/models/spree/product_set.rb
index c91241d494..8e23741775 100644
--- a/app/models/spree/product_set.rb
+++ b/app/models/spree/product_set.rb
@@ -1,5 +1,5 @@
class Spree::ProductSet < ModelSet
- def initialize(attributes={})
+ def initialize(attributes = {})
super(Spree::Product, [], attributes, proc { |attrs| attrs[:product_id].blank? })
end
@@ -85,13 +85,13 @@ class Spree::ProductSet < ModelSet
end
def create_variant(product, variant_attributes)
- on_hand = variant_attributes.delete(:on_hand)
- on_demand = variant_attributes.delete(:on_demand)
+ on_hand = variant_attributes.delete(:on_hand)
+ on_demand = variant_attributes.delete(:on_demand)
- variant = product.variants.create(variant_attributes)
+ variant = product.variants.create(variant_attributes)
- variant.on_demand = on_demand if on_demand.present?
- variant.on_hand = on_hand.to_i if on_hand.present?
+ variant.on_demand = on_demand if on_demand.present?
+ variant.on_hand = on_hand.to_i if on_hand.present?
end
def collection_attributes=(attributes)
diff --git a/app/models/spree/property_decorator.rb b/app/models/spree/property_decorator.rb
index 5950212149..20088ab243 100644
--- a/app/models/spree/property_decorator.rb
+++ b/app/models/spree/property_decorator.rb
@@ -9,7 +9,7 @@ module Spree
}
scope :ever_sold_by, ->(shop) {
- joins(products: {variants: {exchanges: :order_cycle}}).
+ joins(products: { variants: { exchanges: :order_cycle } }).
merge(Exchange.outgoing).
merge(Exchange.to_enterprise(shop)).
select('DISTINCT spree_properties.*')
@@ -20,7 +20,6 @@ module Spree
merge(OrderCycle.active)
}
-
after_save :refresh_products_cache
# When a Property is destroyed, dependent-destroy will destroy all ProductProperties,
diff --git a/app/models/spree/shipping_method_decorator.rb b/app/models/spree/shipping_method_decorator.rb
index 071802020b..c16e784daf 100644
--- a/app/models/spree/shipping_method_decorator.rb
+++ b/app/models/spree/shipping_method_decorator.rb
@@ -31,7 +31,6 @@ Spree::ShippingMethod.class_eval do
scope :by_name, order('spree_shipping_methods.name ASC')
-
# Return the services (pickup, delivery) that different distributors provide, in the format:
# {distributor_id => {pickup: true, delivery: false}, ...}
def self.services
@@ -42,7 +41,7 @@ Spree::ShippingMethod.class_eval do
select("distributor_id").
select("BOOL_OR(spree_shipping_methods.require_ship_address = 'f') AS pickup").
select("BOOL_OR(spree_shipping_methods.require_ship_address = 't') AS delivery").
- map { |sm| [sm.distributor_id.to_i, {pickup: sm.pickup == 't', delivery: sm.delivery == 't'}] }
+ map { |sm| [sm.distributor_id.to_i, { pickup: sm.pickup == 't', delivery: sm.delivery == 't' }] }
]
end
@@ -55,7 +54,7 @@ Spree::ShippingMethod.class_eval do
end
def has_distributor?(distributor)
- self.distributors.include?(distributor)
+ distributors.include?(distributor)
end
def adjustment_label
diff --git a/app/models/spree/stock/availability_validator_decorator.rb b/app/models/spree/stock/availability_validator_decorator.rb
index f687d6cd12..c3ee4c4818 100644
--- a/app/models/spree/stock/availability_validator_decorator.rb
+++ b/app/models/spree/stock/availability_validator_decorator.rb
@@ -40,7 +40,7 @@ Spree::Stock::AvailabilityValidator.class_eval do
def add_out_of_stock_error(line_item)
variant = line_item.variant
- display_name = %{#{variant.name}}
+ display_name = variant.name.to_s
display_name += %{(#{variant.options_text})} if variant.options_text.present?
line_item.errors[:quantity] << Spree.t(:out_of_stock,
scope: :order_populator,
diff --git a/app/models/spree/tax_rate_decorator.rb b/app/models/spree/tax_rate_decorator.rb
index a053394dbf..972cb72dab 100644
--- a/app/models/spree/tax_rate_decorator.rb
+++ b/app/models/spree/tax_rate_decorator.rb
@@ -42,7 +42,7 @@ module Spree
private
def with_tax_included_in_price
- old_included_in_price = self.included_in_price
+ old_included_in_price = included_in_price
self.included_in_price = true
calculator.calculable.included_in_price = true
diff --git a/app/models/spree/taxon_decorator.rb b/app/models/spree/taxon_decorator.rb
index f3868563b3..d5790b2c1d 100644
--- a/app/models/spree/taxon_decorator.rb
+++ b/app/models/spree/taxon_decorator.rb
@@ -1,17 +1,15 @@
Spree::Taxon.class_eval do
- has_many :classifications, :dependent => :destroy
+ has_many :classifications, dependent: :destroy
-
- self.attachment_definitions[:icon][:path] = 'public/images/spree/taxons/:id/:style/:basename.:extension'
- self.attachment_definitions[:icon][:url] = '/images/spree/taxons/:id/:style/:basename.:extension'
+ attachment_definitions[:icon][:path] = 'public/images/spree/taxons/:id/:style/:basename.:extension'
+ attachment_definitions[:icon][:url] = '/images/spree/taxons/:id/:style/:basename.:extension'
after_save :refresh_products_cache
-
# Indicate which filters should be used for this taxon
def applicable_filters
fs = []
- #fs << Spree::ProductFilters.distributor_filter if Spree::ProductFilters.respond_to? :distributor_filter
+ # fs << Spree::ProductFilters.distributor_filter if Spree::ProductFilters.respond_to? :distributor_filter
fs
end
@@ -21,7 +19,7 @@ Spree::Taxon.class_eval do
taxons = {}
Spree::Taxon.
- joins(:products => :supplier).
+ joins(products: :supplier).
select('spree_taxons.*, enterprises.id AS enterprise_id').
each do |t|
taxons[t.enterprise_id.to_i] ||= Set.new
@@ -36,7 +34,7 @@ Spree::Taxon.class_eval do
# or :current taxons (distributed in an open order cycle).
#
# Format: {enterprise_id => [taxon_id, ...]}
- def self.distributed_taxons(which_taxons=:all)
+ def self.distributed_taxons(which_taxons = :all)
ents_and_vars = ExchangeVariant.joins(exchange: :order_cycle).merge(Exchange.outgoing)
.select("DISTINCT variant_id, receiver_id AS enterprise_id")
@@ -46,14 +44,12 @@ Spree::Taxon.class_eval do
.select("DISTINCT spree_taxons.id, ents_and_vars.enterprise_id").joins(products: :variants_including_master)
.joins("INNER JOIN (#{ents_and_vars.to_sql}) AS ents_and_vars ON spree_variants.id = ents_and_vars.variant_id")
- taxons.inject({}) do |ts, t|
+ taxons.each_with_object({}) do |t, ts|
ts[t.enterprise_id.to_i] ||= Set.new
ts[t.enterprise_id.to_i] << t.id
- ts
end
end
-
private
def refresh_products_cache
diff --git a/app/models/spree/user_decorator.rb b/app/models/spree/user_decorator.rb
index bb888a1e7f..15d62b82f2 100644
--- a/app/models/spree/user_decorator.rb
+++ b/app/models/spree/user_decorator.rb
@@ -3,14 +3,14 @@ Spree.user_class.class_eval do
# If handle_asynchronously is called twice, we get an infinite job loop.
handle_asynchronously :send_reset_password_instructions unless method_defined? :send_reset_password_instructions_with_delay
- has_many :enterprise_roles, :dependent => :destroy
+ has_many :enterprise_roles, dependent: :destroy
has_many :enterprises, through: :enterprise_roles
has_many :owned_enterprises, class_name: 'Enterprise', foreign_key: :owner_id, inverse_of: :owner
has_many :owned_groups, class_name: 'EnterpriseGroup', foreign_key: :owner_id, inverse_of: :owner
has_many :customers
has_many :credit_cards
- accepts_nested_attributes_for :enterprise_roles, :allow_destroy => true
+ accepts_nested_attributes_for :enterprise_roles, allow_destroy: true
accepts_nested_attributes_for :bill_address
accepts_nested_attributes_for :ship_address
@@ -36,9 +36,9 @@ Spree.user_class.class_eval do
end
def build_enterprise_roles
- Enterprise.all.each do |enterprise|
- unless self.enterprise_roles.find_by_enterprise_id enterprise.id
- self.enterprise_roles.build(:enterprise => enterprise)
+ Enterprise.all.find_each do |enterprise|
+ unless enterprise_roles.find_by_enterprise_id enterprise.id
+ enterprise_roles.build(enterprise: enterprise)
end
end
end
diff --git a/app/models/spree/variant_decorator.rb b/app/models/spree/variant_decorator.rb
index 30f695f70b..44fcea1277 100644
--- a/app/models/spree/variant_decorator.rb
+++ b/app/models/spree/variant_decorator.rb
@@ -20,15 +20,15 @@ Spree::Variant.class_eval do
attr_accessible :unit_value, :unit_description, :images_attributes, :display_as, :display_name, :import_date
accepts_nested_attributes_for :images
- validates :unit_value, presence: true, if: -> (variant) {
+ validates :unit_value, presence: true, if: ->(variant) {
%w(weight volume).include?(variant.product.andand.variant_unit)
}
- validates :unit_description, presence: true, if: -> (variant) {
+ validates :unit_description, presence: true, if: ->(variant) {
variant.product.andand.variant_unit.present? && variant.unit_value.nil?
}
- before_validation :update_weight_from_unit_value, if: -> v { v.product.present? }
+ before_validation :update_weight_from_unit_value, if: ->(v) { v.product.present? }
after_save :update_units
after_save :refresh_products_cache
around_destroy :destruction
@@ -59,7 +59,7 @@ Spree::Variant.class_eval do
}
scope :not_hidden_for, lambda { |enterprise|
- return where("1=0") unless enterprise.present?
+ return where("1=0") if enterprise.blank?
joins("LEFT OUTER JOIN (SELECT * from inventory_items WHERE enterprise_id = #{sanitize enterprise.andand.id}) AS o_inventory_items ON o_inventory_items.variant_id = spree_variants.id")
.where("o_inventory_items.id IS NULL OR o_inventory_items.visible = (?)", true)
}
@@ -67,7 +67,7 @@ Spree::Variant.class_eval do
localize_number :price, :cost_price, :weight
scope :stockable_by, lambda { |enterprise|
- return where("1=0") unless enterprise.present?
+ return where("1=0") if enterprise.blank?
joins(:product).where(spree_products: { id: Spree::Product.stockable_by(enterprise).pluck(:id) })
}
@@ -76,8 +76,7 @@ Spree::Variant.class_eval do
def self.in_distributor(distributor)
where(id: ExchangeVariant.select(:variant_id).
joins(:exchange).
- where('exchanges.incoming = ? AND exchanges.receiver_id = ?', false, distributor)
- )
+ where('exchanges.incoming = ? AND exchanges.receiver_id = ?', false, distributor))
end
def self.indexed
@@ -115,7 +114,7 @@ Spree::Variant.class_eval do
private
def update_weight_from_unit_value
- self.weight = weight_from_unit_value if self.product.variant_unit == 'weight' && unit_value.present?
+ self.weight = weight_from_unit_value if product.variant_unit == 'weight' && unit_value.present?
end
def destruction
diff --git a/app/models/tag_rule.rb b/app/models/tag_rule.rb
index a5f2d93dee..fd1e744148 100644
--- a/app/models/tag_rule.rb
+++ b/app/models/tag_rule.rb
@@ -12,7 +12,7 @@ class TagRule < ActiveRecord::Base
scope :prioritised, -> { order('priority ASC') }
def self.mapping_for(enterprises)
- self.for(enterprises).inject({}) do |mapping, rule|
+ self.for(enterprises).each_with_object({}) do |rule, mapping|
rule.preferred_customer_tags.split(",").each do |tag|
if mapping[tag]
mapping[tag][:rules] += 1
@@ -20,7 +20,6 @@ class TagRule < ActiveRecord::Base
mapping[tag] = { text: tag, rules: 1 }
end
end
- mapping
end
end
end
diff --git a/app/models/variant_override_set.rb b/app/models/variant_override_set.rb
index 2d39d452fd..c64b4cdc32 100644
--- a/app/models/variant_override_set.rb
+++ b/app/models/variant_override_set.rb
@@ -1,5 +1,5 @@
class VariantOverrideSet < ModelSet
- def initialize(collection, attributes={})
+ def initialize(collection, attributes = {})
super(VariantOverride, collection, attributes, nil, proc { |attrs, tag_list| deletable?(attrs, tag_list) } )
end
@@ -7,12 +7,12 @@ class VariantOverrideSet < ModelSet
def deletable?(attrs, tag_list)
attrs['price'].blank? &&
- attrs['count_on_hand'].blank? &&
- attrs['default_stock'].blank? &&
- attrs['resettable'].blank? &&
- attrs['sku'].nil? &&
- attrs['on_demand'].nil? &&
- tag_list.empty?
+ attrs['count_on_hand'].blank? &&
+ attrs['default_stock'].blank? &&
+ attrs['resettable'].blank? &&
+ attrs['sku'].nil? &&
+ attrs['on_demand'].nil? &&
+ tag_list.empty?
end
def collection_to_delete
diff --git a/app/overrides/add_enterprise_fees_to_admin_configurations_menu.rb b/app/overrides/add_enterprise_fees_to_admin_configurations_menu.rb
index 5877cc1d73..81a162bb64 100644
--- a/app/overrides/add_enterprise_fees_to_admin_configurations_menu.rb
+++ b/app/overrides/add_enterprise_fees_to_admin_configurations_menu.rb
@@ -1,6 +1,6 @@
-Deface::Override.new(:virtual_path => "spree/admin/shared/_configuration_menu",
- :name => "add_enterprise_fees_to_admin_configurations_menu",
- :insert_bottom => "[data-hook='admin_configurations_sidebar_menu']",
- :text => "
<%= link_to I18n.t(:enterprise_fees), main_app.admin_enterprise_fees_path %>",
- :partial => 'enterprise_fees/admin_configurations_menu',
- :original => '8445a03cc903cacc832f395757ffcfaa7e99ca92')
+Deface::Override.new(virtual_path: "spree/admin/shared/_configuration_menu",
+ name: "add_enterprise_fees_to_admin_configurations_menu",
+ insert_bottom: "[data-hook='admin_configurations_sidebar_menu']",
+ text: "<%= link_to I18n.t(:enterprise_fees), main_app.admin_enterprise_fees_path %>",
+ partial: 'enterprise_fees/admin_configurations_menu',
+ original: '8445a03cc903cacc832f395757ffcfaa7e99ca92')
diff --git a/app/overrides/remove_search_bar.rb b/app/overrides/remove_search_bar.rb
index 3605bbeaed..84d84cdf04 100644
--- a/app/overrides/remove_search_bar.rb
+++ b/app/overrides/remove_search_bar.rb
@@ -1,3 +1,3 @@
-Deface::Override.new(:virtual_path => "spree/shared/_nav_bar",
- :remove => "#search-bar",
- :name => "search_removal")
+Deface::Override.new(virtual_path: "spree/shared/_nav_bar",
+ remove: "#search-bar",
+ name: "search_removal")
diff --git a/app/overrides/remove_side_bar.rb b/app/overrides/remove_side_bar.rb
index 2496d867d5..36f5a31f75 100644
--- a/app/overrides/remove_side_bar.rb
+++ b/app/overrides/remove_side_bar.rb
@@ -1,3 +1,3 @@
-Deface::Override.new(:virtual_path => "spree/shared/_sidebar",
- :remove => "#sidebar",
- :name => "sidebar_removal")
+Deface::Override.new(virtual_path: "spree/shared/_sidebar",
+ remove: "#sidebar",
+ name: "sidebar_removal")
diff --git a/app/overrides/set_auth_token_in_backend.rb b/app/overrides/set_auth_token_in_backend.rb
index 4428fe4c17..8dcbc5744c 100644
--- a/app/overrides/set_auth_token_in_backend.rb
+++ b/app/overrides/set_auth_token_in_backend.rb
@@ -1,5 +1,5 @@
-Deface::Override.new(:virtual_path => "spree/layouts/admin",
- :insert_bottom => "[data-hook='admin_inside_head']",
- :partial => "layouts/auth_token_script",
- :name => "set_auth_token_in_backend",
- :original => '6bc2c5de1c8f7542d033548557437c9fe4b3ba02')
+Deface::Override.new(virtual_path: "spree/layouts/admin",
+ insert_bottom: "[data-hook='admin_inside_head']",
+ partial: "layouts/auth_token_script",
+ name: "set_auth_token_in_backend",
+ original: '6bc2c5de1c8f7542d033548557437c9fe4b3ba02')
diff --git a/app/overrides/set_auth_token_in_frontend.rb b/app/overrides/set_auth_token_in_frontend.rb
index bcf087c456..aeb51d4194 100644
--- a/app/overrides/set_auth_token_in_frontend.rb
+++ b/app/overrides/set_auth_token_in_frontend.rb
@@ -1,5 +1,5 @@
-Deface::Override.new(:virtual_path => "spree/layouts/spree_application",
- :insert_bottom => "[data-hook='inside_head']",
- :partial => "layouts/auth_token_script",
- :name => "set_auth_token_in_frontend",
- :original => '5659ac7dbf6ac6469907b005b85285b894677815')
+Deface::Override.new(virtual_path: "spree/layouts/spree_application",
+ insert_bottom: "[data-hook='inside_head']",
+ partial: "layouts/auth_token_script",
+ name: "set_auth_token_in_frontend",
+ original: '5659ac7dbf6ac6469907b005b85285b894677815')
diff --git a/app/presenters/variant_presenter.rb b/app/presenters/variant_presenter.rb
index 61509de195..0f0da89a60 100644
--- a/app/presenters/variant_presenter.rb
+++ b/app/presenters/variant_presenter.rb
@@ -5,7 +5,7 @@ class VariantPresenter
@variant = variant
end
- delegate :id, :to => :variant
+ delegate :id, to: :variant
def image_url
@variant.images.first.attachment.url :mini if @variant.images.present?
diff --git a/app/serializers/api/address_serializer.rb b/app/serializers/api/address_serializer.rb
index 66e4267e1f..73069822c4 100644
--- a/app/serializers/api/address_serializer.rb
+++ b/app/serializers/api/address_serializer.rb
@@ -1,10 +1,10 @@
class Api::AddressSerializer < ActiveModel::Serializer
- #cached
- #delegate :cache_key, to: :object
+ # cached
+ # delegate :cache_key, to: :object
attributes :id, :zipcode, :city, :state_name, :state_id,
- :phone, :firstname, :lastname, :address1, :address2, :city, :country_id,
- :zipcode
+ :phone, :firstname, :lastname, :address1, :address2, :city, :country_id,
+ :zipcode
def state_name
object.state.andand.abbr
diff --git a/app/serializers/api/admin/calculator_serializer.rb b/app/serializers/api/admin/calculator_serializer.rb
index a6287edbb1..82e5459da4 100644
--- a/app/serializers/api/admin/calculator_serializer.rb
+++ b/app/serializers/api/admin/calculator_serializer.rb
@@ -1,11 +1,7 @@
class Api::Admin::CalculatorSerializer < ActiveModel::Serializer
attributes :name, :description
- def name
- object.name
- end
+ delegate :name, to: :object
- def description
- object.description
- end
+ delegate :description, to: :object
end
diff --git a/app/serializers/api/admin/customer_serializer.rb b/app/serializers/api/admin/customer_serializer.rb
index ea666f308f..f5fb4405be 100644
--- a/app/serializers/api/admin/customer_serializer.rb
+++ b/app/serializers/api/admin/customer_serializer.rb
@@ -10,7 +10,7 @@ class Api::Admin::CustomerSerializer < ActiveModel::Serializer
end
def name
- object.name.blank? ? object.bill_address.andand.full_name : object.name
+ object.name.presence || object.bill_address.andand.full_name
end
def tags
diff --git a/app/serializers/api/admin/enterprise_fee_serializer.rb b/app/serializers/api/admin/enterprise_fee_serializer.rb
index 7bf2ea4e14..2f7f7ca10e 100644
--- a/app/serializers/api/admin/enterprise_fee_serializer.rb
+++ b/app/serializers/api/admin/enterprise_fee_serializer.rb
@@ -16,10 +16,9 @@ class Api::Admin::EnterpriseFeeSerializer < ActiveModel::Serializer
result = nil
options[:controller].__send__(:with_format, :html) do
- result = options[:controller].render_to_string :partial => 'admin/enterprise_fees/calculator_settings', :locals => {:enterprise_fee => object}
+ result = options[:controller].render_to_string partial: 'admin/enterprise_fees/calculator_settings', locals: { enterprise_fee: object }
end
result.gsub('[0]', '[{{ $index }}]').gsub('_0_', '_{{ $index }}_')
end
-
end
diff --git a/app/serializers/api/admin/enterprise_serializer.rb b/app/serializers/api/admin/enterprise_serializer.rb
index 348bb75461..a4bba2b3d2 100644
--- a/app/serializers/api/admin/enterprise_serializer.rb
+++ b/app/serializers/api/admin/enterprise_serializer.rb
@@ -40,7 +40,7 @@ class Api::Admin::EnterpriseSerializer < ActiveModel::Serializer
tag_groups.each do |tag_group|
return tag_group if tag_group[:tags].length == tags.length && (tag_group[:tags] & tags) == tag_group[:tags]
end
- return { tags: tags, rules: [] }
+ { tags: tags, rules: [] }
end
private
diff --git a/app/serializers/api/admin/exchange_serializer.rb b/app/serializers/api/admin/exchange_serializer.rb
index 355b4109e8..43d7a08ac8 100644
--- a/app/serializers/api/admin/exchange_serializer.rb
+++ b/app/serializers/api/admin/exchange_serializer.rb
@@ -6,7 +6,7 @@ class Api::Admin::ExchangeSerializer < ActiveModel::Serializer
def variants
variants = object.incoming? ? visible_incoming_variants : visible_outgoing_variants
- Hash[ object.variants.merge(variants).map { |v| [v.id, true] } ]
+ Hash[object.variants.merge(variants).map { |v| [v.id, true] }]
end
private
diff --git a/app/serializers/api/admin/for_order_cycle/supplied_product_serializer.rb b/app/serializers/api/admin/for_order_cycle/supplied_product_serializer.rb
index 054fe44751..9a7bf4861b 100644
--- a/app/serializers/api/admin/for_order_cycle/supplied_product_serializer.rb
+++ b/app/serializers/api/admin/for_order_cycle/supplied_product_serializer.rb
@@ -15,9 +15,9 @@ class Api::Admin::ForOrderCycle::SuppliedProductSerializer < ActiveModel::Serial
def variants
variants = if order_cycle.prefers_product_selection_from_coordinator_inventory_only?
- object.variants.visible_for(order_cycle.coordinator)
- else
- object.variants
+ object.variants.visible_for(order_cycle.coordinator)
+ else
+ object.variants
end
variants.map { |variant| { id: variant.id, label: variant.full_name } }
end
diff --git a/app/serializers/api/admin/index_enterprise_serializer.rb b/app/serializers/api/admin/index_enterprise_serializer.rb
index ca544c97fa..d1d315d63d 100644
--- a/app/serializers/api/admin/index_enterprise_serializer.rb
+++ b/app/serializers/api/admin/index_enterprise_serializer.rb
@@ -21,5 +21,4 @@ class Api::Admin::IndexEnterpriseSerializer < ActiveModel::Serializer
def warnings
OpenFoodNetwork::EnterpriseIssueValidator.new(object).warnings
end
-
end
diff --git a/app/serializers/api/admin/order_cycle_serializer.rb b/app/serializers/api/admin/order_cycle_serializer.rb
index 919ab9de1f..4989530e37 100644
--- a/app/serializers/api/admin/order_cycle_serializer.rb
+++ b/app/serializers/api/admin/order_cycle_serializer.rb
@@ -26,7 +26,7 @@ class Api::Admin::OrderCycleSerializer < ActiveModel::Serializer
def exchanges
scoped_exchanges = OpenFoodNetwork::OrderCyclePermissions.new(options[:current_user], object).visible_exchanges.by_enterprise_name
- ActiveModel::ArraySerializer.new(scoped_exchanges, {each_serializer: Api::Admin::ExchangeSerializer, current_user: options[:current_user] })
+ ActiveModel::ArraySerializer.new(scoped_exchanges, each_serializer: Api::Admin::ExchangeSerializer, current_user: options[:current_user])
end
def editable_variants_for_incoming_exchanges
@@ -66,9 +66,9 @@ class Api::Admin::OrderCycleSerializer < ActiveModel::Serializer
# for shops. We need this here to allow hubs to restrict visible variants to only those in
# their inventory if they so choose
variants = if enterprise.prefers_product_selection_from_inventory_only?
- permissions.visible_variants_for_outgoing_exchanges_to(enterprise).visible_for(enterprise)
- else
- permissions.visible_variants_for_outgoing_exchanges_to(enterprise).not_hidden_for(enterprise)
+ permissions.visible_variants_for_outgoing_exchanges_to(enterprise).visible_for(enterprise)
+ else
+ permissions.visible_variants_for_outgoing_exchanges_to(enterprise).not_hidden_for(enterprise)
end.pluck(:id)
visible[enterprise.id] = variants if variants.any?
end
diff --git a/app/serializers/api/admin/tag_rule_serializer.rb b/app/serializers/api/admin/tag_rule_serializer.rb
index ca24a02638..61cbb7ad5f 100644
--- a/app/serializers/api/admin/tag_rule_serializer.rb
+++ b/app/serializers/api/admin/tag_rule_serializer.rb
@@ -1,10 +1,8 @@
class Api::Admin::TagRuleSerializer < ActiveModel::Serializer
- def serializable_hash
- rule_specific_serializer.serializable_hash
- end
+ delegate :serializable_hash, to: :rule_specific_serializer
def rule_specific_serializer
- "Api::Admin::#{object.class.to_s}Serializer".constantize.new(object)
+ "Api::Admin::#{object.class}Serializer".constantize.new(object)
end
end
diff --git a/app/serializers/api/currency_config_serializer.rb b/app/serializers/api/currency_config_serializer.rb
index 100a4a0b84..ac87f6d9a1 100644
--- a/app/serializers/api/currency_config_serializer.rb
+++ b/app/serializers/api/currency_config_serializer.rb
@@ -20,5 +20,4 @@ class Api::CurrencyConfigSerializer < ActiveModel::Serializer
def hide_cents
Spree::Config[:hide_cents]
end
-
end
diff --git a/app/serializers/api/image_serializer.rb b/app/serializers/api/image_serializer.rb
index fa67e9b1d5..3c787d2f7a 100644
--- a/app/serializers/api/image_serializer.rb
+++ b/app/serializers/api/image_serializer.rb
@@ -1,6 +1,6 @@
class Api::ImageSerializer < ActiveModel::Serializer
attributes :id, :alt, :small_url, :large_url
-
+
def small_url
object.attachment.url(:small, false)
end
diff --git a/app/serializers/api/order_serializer.rb b/app/serializers/api/order_serializer.rb
index 481d8ec213..68c8f6a549 100644
--- a/app/serializers/api/order_serializer.rb
+++ b/app/serializers/api/order_serializer.rb
@@ -29,15 +29,15 @@ module Api
end
def shipment_state
- object.shipment_state ? object.shipment_state : nil
+ object.shipment_state || nil
end
def payment_state
- object.payment_state ? object.payment_state : nil
+ object.payment_state || nil
end
def state
- object.state ? object.state : nil
+ object.state || nil
end
def path
diff --git a/app/serializers/api/product_serializer.rb b/app/serializers/api/product_serializer.rb
index dfb82cedf6..91ff62f52a 100644
--- a/app/serializers/api/product_serializer.rb
+++ b/app/serializers/api/product_serializer.rb
@@ -31,8 +31,8 @@ class Api::UncachedProductSerializer < ActiveModel::Serializer
end
class Api::CachedProductSerializer < ActiveModel::Serializer
- #cached
- #delegate :cache_key, to: :object
+ # cached
+ # delegate :cache_key, to: :object
include ActionView::Helpers::SanitizeHelper
attributes :id, :name, :permalink, :meta_keywords
@@ -48,12 +48,12 @@ class Api::CachedProductSerializer < ActiveModel::Serializer
has_many :images, serializer: Api::ImageSerializer
has_one :supplier, serializer: Api::IdSerializer
- #return an unformatted descripton
+ # return an unformatted descripton
def description
strip_tags object.description
end
- #return a sanitized html description
+ # return a sanitized html description
def description_html
d = sanitize(object.description, tags: "p, b, strong, em, i, a, u", attributes: "href, target")
d.to_s.html_safe
@@ -70,5 +70,4 @@ class Api::CachedProductSerializer < ActiveModel::Serializer
def master
options[:master_variants][object.id].andand.first
end
-
end
diff --git a/app/serializers/api/shipping_method_serializer.rb b/app/serializers/api/shipping_method_serializer.rb
index fc17366a89..26e6b71201 100644
--- a/app/serializers/api/shipping_method_serializer.rb
+++ b/app/serializers/api/shipping_method_serializer.rb
@@ -1,8 +1,8 @@
class Api::ShippingMethodSerializer < ActiveModel::Serializer
attributes :id, :require_ship_address, :name, :description,
- :price
+ :price
def price
- object.compute_amount(options[:current_order])
+ object.compute_amount(options[:current_order])
end
end
diff --git a/app/serializers/api/variant_serializer.rb b/app/serializers/api/variant_serializer.rb
index f4845dc6af..b7cc365120 100644
--- a/app/serializers/api/variant_serializer.rb
+++ b/app/serializers/api/variant_serializer.rb
@@ -3,9 +3,7 @@ class Api::VariantSerializer < ActiveModel::Serializer
attributes :options_text, :on_demand, :price, :fees, :price_with_fees, :product_name
attributes :tag_list
- def price
- object.price
- end
+ delegate :price, to: :object
def fees
options[:enterprise_fee_calculator].andand.indexed_fees_by_type_for(object) ||
diff --git a/app/services/mail_configuration.rb b/app/services/mail_configuration.rb
index 483e02eb90..32111aa205 100644
--- a/app/services/mail_configuration.rb
+++ b/app/services/mail_configuration.rb
@@ -4,7 +4,7 @@
class MailConfiguration
# @param entries [Hash] Spree Config entries
def self.entries=(entries)
- entries.each do | name, value |
+ entries.each do |name, value|
Spree::Config[name] = value
end
apply_mail_settings
diff --git a/app/services/order_cycle_distributed_variants.rb b/app/services/order_cycle_distributed_variants.rb
index abaa3303e4..73d999b536 100644
--- a/app/services/order_cycle_distributed_variants.rb
+++ b/app/services/order_cycle_distributed_variants.rb
@@ -1,7 +1,7 @@
class OrderCycleDistributedVariants
def initialize(order_cycle, distributor)
@order_cycle = order_cycle
- @distributor = distributor
+ @distributor = distributor
end
def distributes_order_variants?(order)
diff --git a/app/views/api/order_cycles/bulk_show.v1.rabl b/app/views/api/order_cycles/bulk_show.v1.rabl
index b012b879e2..e9bf675e6d 100644
--- a/app/views/api/order_cycles/bulk_show.v1.rabl
+++ b/app/views/api/order_cycles/bulk_show.v1.rabl
@@ -4,8 +4,8 @@ attributes :id, :name
node( :first_order ) { |order| order.orders_open_at.strftime("%F") }
node( :last_order ) { |order| (order.orders_close_at + 1.day).strftime("%F") }
node( :suppliers ) do |oc|
- partial 'api/enterprises/bulk_index', :object => oc.suppliers
+ partial 'api/enterprises/bulk_index', object: oc.suppliers
end
node( :distributors ) do |oc|
- partial 'api/enterprises/bulk_index', :object => oc.distributors
+ partial 'api/enterprises/bulk_index', object: oc.distributors
end
diff --git a/app/views/json/_current_order.rabl b/app/views/json/_current_order.rabl
index 167f94ea14..c8d6771644 100644
--- a/app/views/json/_current_order.rabl
+++ b/app/views/json/_current_order.rabl
@@ -3,7 +3,7 @@ attributes :id, :item_total
if current_order
child line_items: :line_items do
- attributes :id, :variant_id, :quantity, :price
+ attributes :id, :variant_id, :quantity, :price
end
node :cart_count do
diff --git a/app/views/json/_enterprises.rabl b/app/views/json/_enterprises.rabl
index 0f01743bfc..e76ab187f8 100644
--- a/app/views/json/_enterprises.rabl
+++ b/app/views/json/_enterprises.rabl
@@ -1,7 +1,7 @@
# TODO: This should be moved into the controller
# RABL is tricky to pass variables into: so we do this as a workaround for now
# I noticed some vague comments on Rabl github about this, but haven't looked into
-collection Enterprise.visible
+collection Enterprise.visible
extends 'json/partials/enterprise'
extends 'json/partials/producer'
extends 'json/partials/hub'
diff --git a/app/views/json/_groups.rabl b/app/views/json/_groups.rabl
index adf0e57709..e6eeda8ffb 100644
--- a/app/views/json/_groups.rabl
+++ b/app/views/json/_groups.rabl
@@ -14,5 +14,5 @@ node :promo_image do |group|
end
node :state do |group|
- group.state().andand.abbr
+ group.state.andand.abbr
end
diff --git a/app/views/json/_order_cycle.rabl b/app/views/json/_order_cycle.rabl
index 493dee1de2..0f5d0c990a 100644
--- a/app/views/json/_order_cycle.rabl
+++ b/app/views/json/_order_cycle.rabl
@@ -1,3 +1,3 @@
object current_order_cycle
attributes :orders_close_at
-attribute :id => :order_cycle_id
+attribute id: :order_cycle_id
diff --git a/app/views/json/_producer.rabl b/app/views/json/_producer.rabl
index 467011bb7a..b3f19267be 100644
--- a/app/views/json/_producer.rabl
+++ b/app/views/json/_producer.rabl
@@ -1,16 +1,14 @@
attributes :id, :name, :description, :long_description, :website, :instagram, :facebook, :linkedin, :twitter
-node :promo_image do |producer|
- producer.promo_image(:large)
+node :promo_image do |producer|
+ producer.promo_image(:large)
end
-node :logo do |producer|
- producer.logo(:medium)
+node :logo do |producer|
+ producer.logo(:medium)
end
node :path do |producer|
- main_app.producer_path(producer)
+ main_app.producer_path(producer)
end
-node :hash do |producer|
- producer.to_param
-end
+node :hash, &:to_param
diff --git a/app/views/json/partials/_enterprise.rabl b/app/views/json/partials/_enterprise.rabl
index ca99b9d14c..14f88244f3 100644
--- a/app/views/json/partials/_enterprise.rabl
+++ b/app/views/json/partials/_enterprise.rabl
@@ -8,9 +8,7 @@ child :address do
extends "json/partials/address"
end
-node :hash do |enterprise|
- enterprise.to_param
-end
+node :hash, &:to_param
node :logo do |enterprise|
enterprise.logo(:medium) if enterprise.logo?
@@ -21,7 +19,7 @@ node :promo_image do |enterprise|
end
node :icon do |e|
- if e.is_primary_producer and e.is_distributor
+ if e.is_primary_producer && e.is_distributor
image_path "map_003-producer-shop.svg"
elsif e.is_primary_producer
image_path "map_001-producer-only.svg"
diff --git a/app/views/json/partials/_hub.rabl b/app/views/json/partials/_hub.rabl
index 76c6729b37..c765271d39 100644
--- a/app/views/json/partials/_hub.rabl
+++ b/app/views/json/partials/_hub.rabl
@@ -8,10 +8,10 @@ node :path do |enterprise|
main_app.enterprise_shop_path(enterprise)
end
node :pickup do |hub|
- hub.shipping_methods.where(:require_ship_address => false).present?
+ hub.shipping_methods.where(require_ship_address: false).present?
end
node :delivery do |hub|
- hub.shipping_methods.where(:require_ship_address => true).present?
+ hub.shipping_methods.where(require_ship_address: true).present?
end
if @active_distributors
node :active do |hub|
diff --git a/app/views/json/partials/_producer.rabl b/app/views/json/partials/_producer.rabl
index 4e8a1daff7..f18f7e0c8d 100644
--- a/app/views/json/partials/_producer.rabl
+++ b/app/views/json/partials/_producer.rabl
@@ -2,7 +2,7 @@ child distributors: :hubs do
attributes :id
end
node :path do |producer|
- main_app.producer_path(producer)
+ main_app.producer_path(producer)
end
child supplied_taxons: :supplied_taxons do
diff --git a/app/views/spree/admin/variants/search.rabl b/app/views/spree/admin/variants/search.rabl
index b65ef4d768..62b91ccf9b 100644
--- a/app/views/spree/admin/variants/search.rabl
+++ b/app/views/spree/admin/variants/search.rabl
@@ -14,9 +14,7 @@ node(:name) do |v|
end
end
-node(:full_name) do |v|
- v.full_name
-end
+node(:full_name, &:full_name)
node(:producer_name) do |v|
v.product.supplier.name
@@ -30,12 +28,12 @@ node(:stock_location_name) do |v|
v.stock_items.first.stock_location.name
end
-child(:images => :images) do
+child(images: :images) do
attributes :mini_url
end
-child(:option_values => :option_values) do
- child(:option_type => :option_type) do
+child(option_values: :option_values) do
+ child(option_type: :option_type) do
attributes :name, :presentation
end
attributes :name, :presentation
diff --git a/app/views/spree/api/products/bulk_show.v1.rabl b/app/views/spree/api/products/bulk_show.v1.rabl
index 583418c07b..3baf5a5069 100644
--- a/app/views/spree/api/products/bulk_show.v1.rabl
+++ b/app/views/spree/api/products/bulk_show.v1.rabl
@@ -8,20 +8,20 @@ attributes :id, :name, :sku, :variant_unit, :variant_unit_scale, :variant_unit_n
attributes :on_hand, :price, :available_on, :permalink_live, :tax_category_id
# Infinity is not a valid JSON object, but Rails encodes it anyway
-node( :taxon_ids ) { |p| p.taxons.map{ |t| t.id }.join(",") }
+node( :taxon_ids ) { |p| p.taxons.map(&:id).join(",") }
node( :on_hand ) { |p| p.on_hand.nil? ? 0 : p.on_hand.to_f.finite? ? p.on_hand : t(:on_demand) }
node( :price ) { |p| p.price.nil? ? '0.0' : p.price }
node( :available_on ) { |p| p.available_on.blank? ? "" : p.available_on.strftime("%F %T") }
-node( :permalink_live ) { |p| p.permalink }
-node( :producer_id ) { |p| p.supplier_id }
-node( :category_id ) { |p| p.primary_taxon_id }
+node( :permalink_live, &:permalink )
+node( :producer_id, &:supplier_id )
+node( :category_id, &:primary_taxon_id )
node( :supplier ) do |p|
- partial 'api/enterprises/bulk_show', :object => p.supplier
+ partial 'api/enterprises/bulk_show', object: p.supplier
end
node( :variants ) do |p|
- partial 'spree/api/variants/bulk_index', :object => p.variants.reorder('spree_variants.id ASC')
+ partial 'spree/api/variants/bulk_index', object: p.variants.reorder('spree_variants.id ASC')
end
node( :master ) do |p|
- partial 'spree/api/variants/bulk_show', :object => p.master
+ partial 'spree/api/variants/bulk_show', object: p.master
end
diff --git a/config.ru b/config.ru
index c214fb16df..45a4379990 100644
--- a/config.ru
+++ b/config.ru
@@ -1,4 +1,4 @@
# This file is used by Rack-based servers to start the application.
-require ::File.expand_path('../config/environment', __FILE__)
+require ::File.expand_path('../config/environment', __FILE__)
run Openfoodnetwork::Application
diff --git a/engines/order_management/spec/services/order_management/reports/enterprise_fee_summary/report_service_spec.rb b/engines/order_management/spec/services/order_management/reports/enterprise_fee_summary/report_service_spec.rb
index 38a760dc96..72e69f4b4a 100644
--- a/engines/order_management/spec/services/order_management/reports/enterprise_fee_summary/report_service_spec.rb
+++ b/engines/order_management/spec/services/order_management/reports/enterprise_fee_summary/report_service_spec.rb
@@ -353,7 +353,7 @@ describe OrderManagement::Reports::EnterpriseFeeSummary::ReportService do
expect(totals.length).to eq(11)
entire_orders_text = i18n_translate("fee_calculated_on_transfer_through_entire_orders",
- distributor: "Sample Distributor")
+ distributor: "Sample Distributor")
various_tax_categories_text = i18n_translate("tax_category_various")
expected_result = [
diff --git a/lib/discourse/single_sign_on.rb b/lib/discourse/single_sign_on.rb
index 2e39f292a8..dd4567338d 100644
--- a/lib/discourse/single_sign_on.rb
+++ b/lib/discourse/single_sign_on.rb
@@ -3,20 +3,20 @@
module Discourse
class SingleSignOn
ACCESSORS = [:nonce, :name, :username, :email, :avatar_url, :avatar_force_update, :require_activation,
- :about_me, :external_id, :return_sso_url, :admin, :moderator, :suppress_welcome_message]
- FIXNUMS = []
- BOOLS = [:avatar_force_update, :admin, :moderator, :require_activation, :suppress_welcome_message]
+ :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
NONCE_EXPIRY_TIME = 10.minutes
attr_accessor(*ACCESSORS)
attr_accessor :sso_secret, :sso_url
def self.sso_secret
- raise RuntimeError, "sso_secret not implemented on class, be sure to set it on instance"
+ raise "sso_secret not implemented on class, be sure to set it on instance"
end
def self.sso_url
- raise RuntimeError, "sso_url not implemented on class, be sure to set it on instance"
+ raise "sso_url not implemented on class, be sure to set it on instance"
end
def self.parse(payload, sso_secret = nil)
@@ -25,11 +25,11 @@ module Discourse
parsed = Rack::Utils.parse_query(payload)
if sso.sign(parsed["sso"]) != parsed["sig"]
- diags = "\n\nsso: #{parsed["sso"]}\n\nsig: #{parsed["sig"]}\n\nexpected sig: #{sso.sign(parsed["sso"])}"
+ diags = "\n\nsso: #{parsed['sso']}\n\nsig: #{parsed['sig']}\n\nexpected sig: #{sso.sign(parsed['sso'])}"
if parsed["sso"] =~ /[^a-zA-Z0-9=\r\n\/+]/m
- raise RuntimeError, "The SSO field should be Base64 encoded, using only A-Z, a-z, 0-9, +, /, and = characters. Your input contains characters we don't understand as Base64, see http://en.wikipedia.org/wiki/Base64 #{diags}"
+ raise "The SSO field should be Base64 encoded, using only A-Z, a-z, 0-9, +, /, and = characters. Your input contains characters we don't understand as Base64, see http://en.wikipedia.org/wiki/Base64 #{diags}"
else
- raise RuntimeError, "Bad signature for payload #{diags}"
+ raise "Bad signature for payload #{diags}"
end
end
@@ -45,7 +45,7 @@ module Discourse
sso.public_send("#{k}=", val)
end
- decoded_hash.each do |k,v|
+ decoded_hash.each do |k, v|
# 1234567
# custom.
#
@@ -74,32 +74,31 @@ module Discourse
OpenSSL::HMAC.hexdigest("sha256", sso_secret, payload)
end
- def to_url(base_url=nil)
- base = "#{base_url || sso_url}"
+ def to_url(base_url = nil)
+ base = (base_url || sso_url).to_s
"#{base}#{base.include?('?') ? '&' : '?'}#{payload}"
end
def payload
payload = Base64.encode64(unsigned_payload)
- "sso=#{CGI::escape(payload)}&sig=#{sign(payload)}"
+ "sso=#{CGI.escape(payload)}&sig=#{sign(payload)}"
end
def unsigned_payload
payload = {}
ACCESSORS.each do |k|
- next if (val = public_send k) == nil
+ next if (val = public_send k).nil?
payload[k] = val
end
if @custom_fields
- @custom_fields.each do |k,v|
+ @custom_fields.each do |k, v|
payload["custom.#{k}"] = v.to_s
end
end
Rack::Utils.build_query(payload)
end
-
end
end
diff --git a/lib/open_food_network/bulk_coop_report.rb b/lib/open_food_network/bulk_coop_report.rb
index 1e0cf5e69d..05bd9aca41 100644
--- a/lib/open_food_network/bulk_coop_report.rb
+++ b/lib/open_food_network/bulk_coop_report.rb
@@ -22,26 +22,26 @@ module OpenFoodNetwork
@allocation_report.header
when "bulk_coop_packing_sheets"
[I18n.t(:report_header_customer),
- I18n.t(:report_header_product),
- I18n.t(:report_header_variant),
- I18n.t(:report_header_sum_total)]
+ I18n.t(:report_header_product),
+ I18n.t(:report_header_variant),
+ I18n.t(:report_header_sum_total)]
when "bulk_coop_customer_payments"
[I18n.t(:report_header_customer),
- I18n.t(:report_header_date_of_order),
- I18n.t(:report_header_total_cost),
- I18n.t(:report_header_amount_owing),
- I18n.t(:report_header_amount_paid)]
+ I18n.t(:report_header_date_of_order),
+ I18n.t(:report_header_total_cost),
+ I18n.t(:report_header_amount_owing),
+ I18n.t(:report_header_amount_paid)]
else
[I18n.t(:report_header_supplier),
- I18n.t(:report_header_product),
- I18n.t(:report_header_product),
- I18n.t(:report_header_bulk_unit_size),
- I18n.t(:report_header_variant),
- I18n.t(:report_header_weight),
- I18n.t(:report_header_sum_total),
- I18n.t(:report_header_sum_max_total),
- I18n.t(:report_header_units_required),
- I18n.t(:report_header_remainder)]
+ I18n.t(:report_header_product),
+ I18n.t(:report_header_product),
+ I18n.t(:report_header_bulk_unit_size),
+ I18n.t(:report_header_variant),
+ I18n.t(:report_header_weight),
+ I18n.t(:report_header_sum_total),
+ I18n.t(:report_header_sum_max_total),
+ I18n.t(:report_header_units_required),
+ I18n.t(:report_header_remainder)]
end
end
@@ -61,31 +61,31 @@ module OpenFoodNetwork
when "bulk_coop_allocation"
@allocation_report.rules
when "bulk_coop_packing_sheets"
- [ { group_by: proc { |li| li.product },
- sort_by: proc { |product| product.name } },
- { group_by: proc { |li| li.full_name },
- sort_by: proc { |full_name| full_name } },
- { group_by: proc { |li| li.order },
- sort_by: proc { |order| order.to_s } } ]
+ [{ group_by: proc { |li| li.product },
+ sort_by: proc { |product| product.name } },
+ { group_by: proc { |li| li.full_name },
+ sort_by: proc { |full_name| full_name } },
+ { group_by: proc { |li| li.order },
+ sort_by: proc { |order| order.to_s } }]
when "bulk_coop_customer_payments"
- [ { group_by: proc { |li| li.order },
- sort_by: proc { |order| order.completed_at } } ]
+ [{ group_by: proc { |li| li.order },
+ sort_by: proc { |order| order.completed_at } }]
else
- [ { group_by: proc { |li| li.product.supplier },
- sort_by: proc { |supplier| supplier.name } },
- { group_by: proc { |li| li.product },
- sort_by: proc { |product| product.name },
- summary_columns: [ proc { |lis| lis.first.product.supplier.name },
- proc { |lis| lis.first.product.name },
- 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) ) } ] },
- { group_by: proc { |li| li.full_name },
- sort_by: proc { |full_name| full_name } } ]
+ [{ group_by: proc { |li| li.product.supplier },
+ sort_by: proc { |supplier| supplier.name } },
+ { group_by: proc { |li| li.product },
+ sort_by: proc { |product| product.name },
+ summary_columns: [proc { |lis| lis.first.product.supplier.name },
+ proc { |lis| lis.first.product.name },
+ 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) ) }] },
+ { group_by: proc { |li| li.full_name },
+ sort_by: proc { |full_name| full_name } }]
end
end
@@ -96,26 +96,26 @@ module OpenFoodNetwork
when "bulk_coop_allocation"
@allocation_report.columns
when "bulk_coop_packing_sheets"
- [ proc { |lis| lis.first.order.bill_address.firstname + " " + lis.first.order.bill_address.lastname },
- proc { |lis| lis.first.product.name },
- proc { |lis| lis.first.full_name },
- proc { |lis| lis.sum { |li| li.quantity } } ]
+ [proc { |lis| lis.first.order.bill_address.firstname + " " + lis.first.order.bill_address.lastname },
+ proc { |lis| lis.first.product.name },
+ proc { |lis| lis.first.full_name },
+ proc { |lis| lis.sum(&:quantity) }]
when "bulk_coop_customer_payments"
- [ proc { |lis| lis.first.order.bill_address.firstname + " " + lis.first.order.bill_address.lastname },
- proc { |lis| lis.first.order.completed_at.to_s },
- proc { |lis| lis.map { |li| li.order }.uniq.sum { |o| o.total } },
- proc { |lis| lis.map { |li| li.order }.uniq.sum { |o| o.outstanding_balance } },
- proc { |lis| lis.map { |li| li.order }.uniq.sum { |o| o.payment_total } } ]
+ [proc { |lis| lis.first.order.bill_address.firstname + " " + lis.first.order.bill_address.lastname },
+ proc { |lis| lis.first.order.completed_at.to_s },
+ proc { |lis| lis.map(&:order).uniq.sum(&:total) },
+ proc { |lis| lis.map(&:order).uniq.sum(&:outstanding_balance) },
+ proc { |lis| lis.map(&:order).uniq.sum(&:payment_total) }]
else
- [ proc { |lis| lis.first.product.supplier.name },
- proc { |lis| lis.first.product.name },
- proc { |lis| lis.first.product.group_buy_unit_size || 0.0 },
- proc { |lis| lis.first.full_name },
- proc { |lis| lis.first.weight_from_unit_value || 0 },
- proc { |lis| lis.sum { |li| li.quantity } },
- proc { |lis| lis.sum { |li| li.max_quantity || 0 } },
- proc { |lis| "" },
- proc { |lis| "" } ]
+ [proc { |lis| lis.first.product.supplier.name },
+ proc { |lis| lis.first.product.name },
+ proc { |lis| lis.first.product.group_buy_unit_size || 0.0 },
+ proc { |lis| lis.first.full_name },
+ proc { |lis| lis.first.weight_from_unit_value || 0 },
+ proc { |lis| lis.sum(&:quantity) },
+ proc { |lis| lis.sum { |li| li.max_quantity || 0 } },
+ proc { |_lis| "" },
+ proc { |_lis| "" }]
end
end
diff --git a/lib/open_food_network/cached_products_renderer.rb b/lib/open_food_network/cached_products_renderer.rb
index ba96cea609..6d31705cd4 100644
--- a/lib/open_food_network/cached_products_renderer.rb
+++ b/lib/open_food_network/cached_products_renderer.rb
@@ -6,7 +6,7 @@ require 'open_food_network/products_renderer'
module OpenFoodNetwork
class CachedProductsRenderer
- class NoProducts < Exception; end
+ class NoProducts < RuntimeError; end
def initialize(distributor, order_cycle)
@distributor = distributor
@@ -14,16 +14,15 @@ module OpenFoodNetwork
end
def products_json
- raise NoProducts.new(I18n.t(:no_products)) if @distributor.nil? || @order_cycle.nil?
+ raise NoProducts, I18n.t(:no_products) if @distributor.nil? || @order_cycle.nil?
products_json = cached_products_json
- raise NoProducts.new(I18n.t(:no_products)) if products_json.nil?
+ raise NoProducts, I18n.t(:no_products) if products_json.nil?
products_json
end
-
private
def cached_products_json
diff --git a/lib/open_food_network/customers_report.rb b/lib/open_food_network/customers_report.rb
index 0a605b3596..92d2013ca6 100644
--- a/lib/open_food_network/customers_report.rb
+++ b/lib/open_food_network/customers_report.rb
@@ -10,18 +10,18 @@ module OpenFoodNetwork
def header
if is_mailing_list?
[I18n.t(:report_header_email),
- I18n.t(:report_header_first_name),
- I18n.t(:report_header_last_name),
- I18n.t(:report_header_suburb)]
+ I18n.t(:report_header_first_name),
+ I18n.t(:report_header_last_name),
+ I18n.t(:report_header_suburb)]
else
[I18n.t(:report_header_first_name),
- I18n.t(:report_header_last_name),
- I18n.t(:report_header_billing_address),
- I18n.t(:report_header_email),
- I18n.t(:report_header_phone),
- I18n.t(:report_header_hub),
- I18n.t(:report_header_hub_address),
- I18n.t(:report_header_shipping_method)]
+ I18n.t(:report_header_last_name),
+ I18n.t(:report_header_billing_address),
+ I18n.t(:report_header_email),
+ I18n.t(:report_header_phone),
+ I18n.t(:report_header_hub),
+ I18n.t(:report_header_hub_address),
+ I18n.t(:report_header_shipping_method)]
end
end
@@ -37,13 +37,13 @@ module OpenFoodNetwork
ba = order.billing_address
da = order.distributor.andand.address
[ba.firstname,
- ba.lastname,
- [ba.address1, ba.address2, ba.city].join(" "),
- order.email,
- ba.phone,
- order.distributor.andand.name,
- [da.andand.address1, da.andand.address2, da.andand.city].join(" "),
- order.shipping_method.andand.name]
+ ba.lastname,
+ [ba.address1, ba.address2, ba.city].join(" "),
+ order.email,
+ ba.phone,
+ order.distributor.andand.name,
+ [da.andand.address1, da.andand.address2, da.andand.city].join(" "),
+ order.shipping_method.andand.name]
end
end
end
diff --git a/lib/open_food_network/enterprise_fee_calculator.rb b/lib/open_food_network/enterprise_fee_calculator.rb
index b6816cc44b..08eec58899 100644
--- a/lib/open_food_network/enterprise_fee_calculator.rb
+++ b/lib/open_food_network/enterprise_fee_calculator.rb
@@ -2,7 +2,7 @@ require 'open_food_network/enterprise_fee_applicator'
module OpenFoodNetwork
class EnterpriseFeeCalculator
- def initialize(distributor=nil, order_cycle=nil)
+ def initialize(distributor = nil, order_cycle = nil)
@distributor = distributor
@order_cycle = order_cycle
end
@@ -18,11 +18,10 @@ module OpenFoodNetwork
def indexed_fees_by_type_for(variant)
load_enterprise_fees unless @indexed_enterprise_fees
- indexed_enterprise_fees_for(variant).inject({}) do |fees, enterprise_fee|
+ indexed_enterprise_fees_for(variant).each_with_object({}) do |enterprise_fee, fees|
fees[enterprise_fee.fee_type.to_sym] ||= 0
fees[enterprise_fee.fee_type.to_sym] += calculate_fee_for variant, enterprise_fee
- fees
- end.select { |fee_type, amount| amount > 0 }
+ end.select { |_fee_type, amount| amount > 0 }
end
def fees_for(variant)
@@ -32,11 +31,10 @@ module OpenFoodNetwork
end
def fees_by_type_for(variant)
- per_item_enterprise_fee_applicators_for(variant).inject({}) do |fees, applicator|
+ 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
- end.select { |fee_type, amount| amount > 0 }
+ end.select { |_fee_type, amount| amount > 0 }
end
def create_line_item_adjustments_for(line_item)
@@ -107,7 +105,7 @@ module OpenFoodNetwork
def per_item_enterprise_fees_with_exchange_details
EnterpriseFee.
per_item.
- joins(:exchanges => :exchange_variants).
+ joins(exchanges: :exchange_variants).
where('exchanges.order_cycle_id = ?', @order_cycle.id).
merge(Exchange.supplying_to(@distributor)).
select('enterprise_fees.*, exchange_variants.variant_id AS variant_id')
diff --git a/lib/open_food_network/enterprise_issue_validator.rb b/lib/open_food_network/enterprise_issue_validator.rb
index 252d03f836..0b81db7381 100644
--- a/lib/open_food_network/enterprise_issue_validator.rb
+++ b/lib/open_food_network/enterprise_issue_validator.rb
@@ -10,20 +10,24 @@ module OpenFoodNetwork
def issues
issues = []
- issues << {
- description: I18n.t('admin.enterprise_issues.has_no_shipping_methods', enterprise: @enterprise.name),
- link: "#{I18n.t('admin.enterprise_issues.create_new')}"
- } unless shipping_methods_ok?
+ unless shipping_methods_ok?
+ issues << {
+ description: I18n.t('admin.enterprise_issues.has_no_shipping_methods', enterprise: @enterprise.name),
+ link: "#{I18n.t('admin.enterprise_issues.create_new')}"
+ }
+ end
- issues << {
- description: I18n.t('admin.enterprise_issues.has_no_payment_methods', enterprise: @enterprise.name),
- link: "#{I18n.t('admin.enterprise_issues.create_new')}"
- } unless payment_methods_ok?
+ unless payment_methods_ok?
+ issues << {
+ description: I18n.t('admin.enterprise_issues.has_no_payment_methods', enterprise: @enterprise.name),
+ link: "#{I18n.t('admin.enterprise_issues.create_new')}"
+ }
+ end
issues
end
- def issues_summary(opts={})
+ def issues_summary(opts = {})
if !opts[:confirmation_only] && !shipping_methods_ok? && !payment_methods_ok?
I18n.t(:no_shipping_or_payment)
elsif !opts[:confirmation_only] && !shipping_methods_ok?
@@ -36,15 +40,16 @@ module OpenFoodNetwork
def warnings
warnings = []
- warnings << {
- description: I18n.t('admin.enterprise_issues.not_visible', enterprise: @enterprise.name),
- link: "#{I18n.t(:edit)}"
- } unless @enterprise.visible
+ unless @enterprise.visible
+ warnings << {
+ description: I18n.t('admin.enterprise_issues.not_visible', enterprise: @enterprise.name),
+ link: "#{I18n.t(:edit)}"
+ }
+ end
warnings
end
-
private
def shipping_methods_ok?
diff --git a/lib/open_food_network/feature_toggle.rb b/lib/open_food_network/feature_toggle.rb
index 23bcb00c8b..9acbfe0c8d 100644
--- a/lib/open_food_network/feature_toggle.rb
+++ b/lib/open_food_network/feature_toggle.rb
@@ -1,13 +1,13 @@
module OpenFoodNetwork
class FeatureToggle
- def self.enabled? feature
+ def self.enabled?(feature)
!!features.with_indifferent_access[feature]
end
private
def self.features
- {connect_learn_homepage: false}
+ { connect_learn_homepage: false }
end
end
end
diff --git a/lib/open_food_network/group_buy_report.rb b/lib/open_food_network/group_buy_report.rb
index bc3ef23d8d..2cd4f23c20 100644
--- a/lib/open_food_network/group_buy_report.rb
+++ b/lib/open_food_network/group_buy_report.rb
@@ -12,7 +12,7 @@ module OpenFoodNetwork
end
class GroupBuyReport
- def initialize orders
+ def initialize(orders)
@orders = orders
end
@@ -30,16 +30,15 @@ module OpenFoodNetwork
def variants_and_quantities
variants_and_quantities = []
- line_items = @orders.map { |o| o.line_items }.flatten
+ line_items = @orders.map(&:line_items).flatten
supplier_groups = line_items.group_by { |li| li.variant.product.supplier }
- supplier_groups.each do |supplier, line_items_by_supplier|
+ supplier_groups.each do |_supplier, line_items_by_supplier|
product_groups = line_items_by_supplier.group_by { |li| li.variant.product }
product_groups.each do |product, line_items_by_product|
-
# Cycle thorugh variant of a product
- variant_groups = line_items_by_product.group_by { |li| li.variant }
+ variant_groups = line_items_by_product.group_by(&:variant)
variant_groups.each do |variant, line_items_by_variant|
- sum_quantities = line_items_by_variant.sum { |li| li.quantity }
+ sum_quantities = line_items_by_variant.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)
end
diff --git a/lib/open_food_network/integrity_checker.rb b/lib/open_food_network/integrity_checker.rb
index ff34f661dc..4bf4444c14 100644
--- a/lib/open_food_network/integrity_checker.rb
+++ b/lib/open_food_network/integrity_checker.rb
@@ -12,7 +12,6 @@ require 'rspec/autorun'
# Ref: http://pluralsight.com/training/Courses/TableOfContents/database-your-friend
-
describe "data integrity" do
it "has no deleted variants in order cycles" do
# When a variant is soft deleted, it should be removed from all order cycles
diff --git a/lib/open_food_network/lettuce_share_report.rb b/lib/open_food_network/lettuce_share_report.rb
index 7bfcf26ec4..18f6482173 100644
--- a/lib/open_food_network/lettuce_share_report.rb
+++ b/lib/open_food_network/lettuce_share_report.rb
@@ -20,7 +20,7 @@ module OpenFoodNetwork
def table
return [] unless @render_table
- variants.select { |v| v.in_stock? }
+ variants.select(&:in_stock?)
.map do |variant|
[
variant.product.name,
@@ -37,7 +37,6 @@ module OpenFoodNetwork
end
end
-
private
def gst(variant)
@@ -75,6 +74,5 @@ module OpenFoodNetwork
"#{p[:name]} - #{p[:value]}"
end.join(', ')
end
-
end
end
diff --git a/lib/open_food_network/locking.rb b/lib/open_food_network/locking.rb
index 30dec63b0b..02bf2e1358 100644
--- a/lib/open_food_network/locking.rb
+++ b/lib/open_food_network/locking.rb
@@ -1,8 +1,8 @@
module OpenFoodNetwork::Locking
# http://rhnh.net/2010/06/30/acts-as-list-will-break-in-production
def with_isolation_level_serializable
- self.transaction do
- self.connection.execute "SET SESSION CHARACTERISTICS AS TRANSACTION ISOLATION LEVEL SERIALIZABLE"
+ transaction do
+ connection.execute "SET SESSION CHARACTERISTICS AS TRANSACTION ISOLATION LEVEL SERIALIZABLE"
yield
end
end
diff --git a/lib/open_food_network/option_value_namer.rb b/lib/open_food_network/option_value_namer.rb
index 6a77d9cb35..1d387c3f29 100644
--- a/lib/open_food_network/option_value_namer.rb
+++ b/lib/open_food_network/option_value_namer.rb
@@ -11,12 +11,12 @@ module OpenFoodNetwork
name_fields = []
name_fields << "#{value}#{separator}#{unit}" if value.present? && unit.present?
- name_fields << @variant.unit_description if @variant.unit_description.present?
+ name_fields << @variant.unit_description if @variant.unit_description.present?
name_fields.join ' '
end
def value
- value, _ = option_value_value_unit
+ value, = option_value_value_unit
value
end
@@ -25,7 +25,6 @@ module OpenFoodNetwork
unit
end
-
private
def value_scaled?
@@ -61,12 +60,12 @@ module OpenFoodNetwork
end
def scale_for_unit_value
- units = {'weight' => {1.0 => 'g', 1000.0 => 'kg', 1000000.0 => 'T'},
- 'volume' => {0.001 => 'mL', 1.0 => 'L', 1000.0 => 'kL'}}
+ units = { 'weight' => { 1.0 => 'g', 1000.0 => 'kg', 1_000_000.0 => 'T' },
+ 'volume' => { 0.001 => 'mL', 1.0 => 'L', 1000.0 => 'kL' } }
# Find the largest available unit where unit_value comes to >= 1 when expressed in it.
# If there is none available where this is true, use the smallest available unit.
- unit = units[@variant.product.variant_unit].select { |scale, unit_name|
+ unit = units[@variant.product.variant_unit].select { |scale, _unit_name|
@variant.unit_value / scale >= 1
}.to_a.last
unit = units[@variant.product.variant_unit].first if unit.nil?
diff --git a/lib/open_food_network/order_and_distributor_report.rb b/lib/open_food_network/order_and_distributor_report.rb
index 29b9772c96..d0b00d08b0 100644
--- a/lib/open_food_network/order_and_distributor_report.rb
+++ b/lib/open_food_network/order_and_distributor_report.rb
@@ -1,6 +1,5 @@
module OpenFoodNetwork
class OrderAndDistributorReport
-
def initialize(user, params = {}, render_table = false)
@params = params
@user = user
diff --git a/lib/open_food_network/order_cycle_form_applicator.rb b/lib/open_food_network/order_cycle_form_applicator.rb
index 80e68881d4..a5bec43bef 100644
--- a/lib/open_food_network/order_cycle_form_applicator.rb
+++ b/lib/open_food_network/order_cycle_form_applicator.rb
@@ -22,12 +22,12 @@ module OpenFoodNetwork
if exchange_exists?(exchange[:enterprise_id], @order_cycle.coordinator_id, true)
update_exchange(exchange[:enterprise_id], @order_cycle.coordinator_id, true,
- {variant_ids: variant_ids, enterprise_fee_ids: enterprise_fee_ids,
- receival_instructions: exchange[:receival_instructions]})
+ variant_ids: variant_ids, enterprise_fee_ids: enterprise_fee_ids,
+ receival_instructions: exchange[:receival_instructions] )
else
add_exchange(exchange[:enterprise_id], @order_cycle.coordinator_id, true,
- {variant_ids: variant_ids, enterprise_fee_ids: enterprise_fee_ids,
- receival_instructions: exchange[:receival_instructions],})
+ variant_ids: variant_ids, enterprise_fee_ids: enterprise_fee_ids,
+ receival_instructions: exchange[:receival_instructions], )
end
end
@@ -38,35 +38,34 @@ module OpenFoodNetwork
if exchange_exists?(@order_cycle.coordinator_id, exchange[:enterprise_id], false)
update_exchange(@order_cycle.coordinator_id, exchange[:enterprise_id], false,
- {variant_ids: variant_ids,
- enterprise_fee_ids: enterprise_fee_ids,
- pickup_time: exchange[:pickup_time],
- pickup_instructions: exchange[:pickup_instructions],
- tag_list: exchange[:tag_list]})
+ variant_ids: variant_ids,
+ enterprise_fee_ids: enterprise_fee_ids,
+ pickup_time: exchange[:pickup_time],
+ pickup_instructions: exchange[:pickup_instructions],
+ tag_list: exchange[:tag_list] )
else
add_exchange(@order_cycle.coordinator_id, exchange[:enterprise_id], false,
- {variant_ids: variant_ids,
- enterprise_fee_ids: enterprise_fee_ids,
- pickup_time: exchange[:pickup_time],
- pickup_instructions: exchange[:pickup_instructions],
- tag_list: exchange[:tag_list]})
+ variant_ids: variant_ids,
+ enterprise_fee_ids: enterprise_fee_ids,
+ pickup_time: exchange[:pickup_time],
+ pickup_instructions: exchange[:pickup_instructions],
+ tag_list: exchange[:tag_list] )
end
end
destroy_untouched_exchanges
end
-
private
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)
+ def add_exchange(sender_id, receiver_id, incoming, attrs = {})
+ attrs = attrs.reverse_merge(sender_id: sender_id, receiver_id: receiver_id, incoming: incoming)
exchange = @order_cycle.exchanges.build attrs
if manages_coordinator?
@@ -75,8 +74,8 @@ module OpenFoodNetwork
end
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
+ 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
unless manages_coordinator? || manager_for(exchange)
attrs.delete :enterprise_fee_ids
@@ -121,12 +120,12 @@ module OpenFoodNetwork
@manages_coordinator = Enterprise.managed_by(@spree_current_user).include? @order_cycle.coordinator
end
- def editable_variant_ids_for_incoming_exchange_between(sender, receiver)
+ def editable_variant_ids_for_incoming_exchange_between(sender, _receiver)
OpenFoodNetwork::OrderCyclePermissions.new(@spree_current_user, @order_cycle).
editable_variants_for_incoming_exchanges_from(sender).pluck(:id)
end
- def editable_variant_ids_for_outgoing_exchange_between(sender, receiver)
+ def editable_variant_ids_for_outgoing_exchange_between(_sender, receiver)
OpenFoodNetwork::OrderCyclePermissions.new(@spree_current_user, @order_cycle).
editable_variants_for_outgoing_exchanges_to(receiver).pluck(:id)
end
@@ -140,7 +139,7 @@ module OpenFoodNetwork
receiver = @order_cycle.coordinator
exchange = find_exchange(sender.id, receiver.id, true)
- requested_ids = attrs[:variants].select{ |k,v| v }.keys.map(&:to_i) # Only the ids the user has requested
+ requested_ids = attrs[:variants].select{ |_k, v| v }.keys.map(&:to_i) # Only the ids the user has requested
existing_ids = exchange.present? ? exchange.variants.pluck(:id) : [] # The ids that already exist
editable_ids = editable_variant_ids_for_incoming_exchange_between(sender, receiver) # The ids we are allowed to add/remove
@@ -157,7 +156,7 @@ module OpenFoodNetwork
receiver = Enterprise.find(attrs[:enterprise_id])
exchange = find_exchange(sender.id, receiver.id, false)
- requested_ids = attrs[:variants].select{ |k,v| v }.keys.map(&:to_i) # Only the ids the user has requested
+ requested_ids = attrs[:variants].select{ |_k, v| v }.keys.map(&:to_i) # Only the ids the user has requested
existing_ids = exchange.present? ? exchange.variants.pluck(:id) : [] # The ids that already exist
editable_ids = editable_variant_ids_for_outgoing_exchange_between(sender, receiver) # The ids we are allowed to add/remove
@@ -175,7 +174,7 @@ module OpenFoodNetwork
end
def variants_to_a(variants)
- variants.select { |k, v| v }.keys.map(&:to_i).sort
+ variants.select { |_k, v| v }.keys.map(&:to_i).sort
end
end
end
diff --git a/lib/open_food_network/order_cycle_management_report.rb b/lib/open_food_network/order_cycle_management_report.rb
index d58a6d5dbf..82ddcd8623 100644
--- a/lib/open_food_network/order_cycle_management_report.rb
+++ b/lib/open_food_network/order_cycle_management_report.rb
@@ -99,7 +99,7 @@ module OpenFoodNetwork
def filter_to_payment_method(orders)
if params[:payment_method_in].present?
- orders.joins(payments: :payment_method).where(spree_payments: { payment_method_id: params[:payment_method_in]})
+ orders.joins(payments: :payment_method).where(spree_payments: { payment_method_id: params[:payment_method_in] })
else
orders
end
diff --git a/lib/open_food_network/order_cycle_permissions.rb b/lib/open_food_network/order_cycle_permissions.rb
index 3320309a19..a75c27bad6 100644
--- a/lib/open_food_network/order_cycle_permissions.rb
+++ b/lib/open_food_network/order_cycle_permissions.rb
@@ -12,7 +12,7 @@ module OpenFoodNetwork
# NOTE: the enterprises a given user can see actually in the OC interface depend on the relationships
# of their enterprises to the coordinator of the order cycle, rather than on the order cycle itself
def visible_enterprises
- return Enterprise.where("1=0") unless @coordinator.present?
+ return Enterprise.where("1=0") if @coordinator.blank?
if managed_enterprises.include? @coordinator
coordinator_permitted = [@coordinator]
all_active = []
@@ -74,8 +74,8 @@ module OpenFoodNetwork
# Find the exchanges of an order cycle that an admin can manage
def visible_exchanges
ids = order_cycle_exchange_ids_involving_my_enterprises |
- order_cycle_exchange_ids_distributing_my_variants |
- order_cycle_exchange_ids_with_distributable_variants
+ order_cycle_exchange_ids_distributing_my_variants |
+ order_cycle_exchange_ids_with_distributable_variants
Exchange.where(id: ids, order_cycle_id: @order_cycle)
end
@@ -192,7 +192,6 @@ module OpenFoodNetwork
end
end
-
private
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 b63b994407..a5da5085b9 100644
--- a/lib/open_food_network/order_grouper.rb
+++ b/lib/open_food_network/order_grouper.rb
@@ -18,26 +18,26 @@ module OpenFoodNetwork
def group_and_sort(rule, remaining_rules, items)
branch = {}
groups = items.group_by { |item| rule[:group_by].call(item) }
- sorted_groups = groups.sort_by { |key, value| rule[:sort_by].call(key) }
+ sorted_groups = groups.sort_by { |key, _value| rule[:sort_by].call(key) }
sorted_groups.each do |property, items_by_property|
branch[property] = build_tree(items_by_property, remaining_rules)
- branch[property][:summary_row] = { items: items_by_property, columns: rule[:summary_columns] } unless rule[:summary_columns] == nil || is_leaf_node(branch[property])
+ branch[property][:summary_row] = { items: items_by_property, columns: rule[:summary_columns] } unless rule[:summary_columns].nil? || is_leaf_node(branch[property])
end
branch
end
def build_table(groups)
rows = []
- unless is_leaf_node(groups)
+ if is_leaf_node(groups)
+ rows << @column_constructors.map { |column_constructor| column_constructor.call(groups) }
+ else
groups.each do |key, group|
- unless key == :summary_row
- build_table(group).each { |g| rows << g }
- else
+ if key == :summary_row
rows << group[:columns].map { |cols| cols.call(group[:items]) }
+ else
+ build_table(group).each { |g| rows << g }
end
end
- else
- rows << @column_constructors.map { |column_constructor| column_constructor.call(groups) }
end
rows
end
diff --git a/lib/open_food_network/orders_and_fulfillments_report.rb b/lib/open_food_network/orders_and_fulfillments_report.rb
index 2f766bd640..b90ba7b799 100644
--- a/lib/open_food_network/orders_and_fulfillments_report.rb
+++ b/lib/open_food_network/orders_and_fulfillments_report.rb
@@ -16,34 +16,34 @@ module OpenFoodNetwork
when "order_cycle_supplier_totals"
[I18n.t(:report_header_producer), I18n.t(:report_header_product), I18n.t(:report_header_variant), I18n.t(:report_header_amount),
- I18n.t(:report_header_total_units), I18n.t(:report_header_curr_cost_per_unit), I18n.t(:report_header_total_cost),
- I18n.t(:report_header_status), I18n.t(:report_header_incoming_transport)]
+ I18n.t(:report_header_total_units), I18n.t(:report_header_curr_cost_per_unit), I18n.t(:report_header_total_cost),
+ I18n.t(:report_header_status), I18n.t(:report_header_incoming_transport)]
when "order_cycle_supplier_totals_by_distributor"
[I18n.t(:report_header_producer), I18n.t(:report_header_product), I18n.t(:report_header_variant), I18n.t(:report_header_to_hub),
- I18n.t(:report_header_amount), I18n.t(:report_header_curr_cost_per_unit), I18n.t(:report_header_total_cost),
- I18n.t(:report_header_shipping_method)]
+ I18n.t(:report_header_amount), I18n.t(:report_header_curr_cost_per_unit), I18n.t(:report_header_total_cost),
+ I18n.t(:report_header_shipping_method)]
when "order_cycle_distributor_totals_by_supplier"
[I18n.t(:report_header_hub), I18n.t(:report_header_producer), I18n.t(:report_header_product), I18n.t(:report_header_variant),
- I18n.t(:report_header_amount), I18n.t(:report_header_curr_cost_per_unit), I18n.t(:report_header_total_cost),
- I18n.t(:report_header_total_shipping_cost), I18n.t(:report_header_shipping_method)]
+ I18n.t(:report_header_amount), I18n.t(:report_header_curr_cost_per_unit), I18n.t(:report_header_total_cost),
+ I18n.t(:report_header_total_shipping_cost), I18n.t(:report_header_shipping_method)]
when "order_cycle_customer_totals"
[I18n.t(:report_header_hub), I18n.t(:report_header_customer), I18n.t(:report_header_email), I18n.t(:report_header_phone),
- I18n.t(:report_header_producer), I18n.t(:report_header_product), I18n.t(:report_header_variant), I18n.t(:report_header_amount),
- I18n.t(:report_header_item_price, currency: currency_symbol),
- I18n.t(:report_header_item_fees_price, currency: currency_symbol),
- I18n.t(:report_header_admin_handling_fees, currency: currency_symbol),
- I18n.t(:report_header_ship_price, currency: currency_symbol),
- I18n.t(:report_header_pay_fee_price, currency: currency_symbol),
- I18n.t(:report_header_total_price, currency: currency_symbol),
- I18n.t(:report_header_paid), I18n.t(:report_header_shipping), I18n.t(:report_header_delivery),
- I18n.t(:report_header_ship_street), I18n.t(:report_header_ship_street_2), I18n.t(:report_header_ship_city), I18n.t(:report_header_ship_postcode), I18n.t(:report_header_ship_state),
- I18n.t(:report_header_comments), I18n.t(:report_header_sku),
- I18n.t(:report_header_order_cycle), I18n.t(:report_header_payment_method), I18n.t(:report_header_customer_code), I18n.t(:report_header_tags),
- I18n.t(:report_header_billing_street), I18n.t(:report_header_billing_street_2), I18n.t(:report_header_billing_city), I18n.t(:report_header_billing_postcode), I18n.t(:report_header_billing_state),]
+ I18n.t(:report_header_producer), I18n.t(:report_header_product), I18n.t(:report_header_variant), I18n.t(:report_header_amount),
+ I18n.t(:report_header_item_price, currency: currency_symbol),
+ I18n.t(:report_header_item_fees_price, currency: currency_symbol),
+ I18n.t(:report_header_admin_handling_fees, currency: currency_symbol),
+ I18n.t(:report_header_ship_price, currency: currency_symbol),
+ I18n.t(:report_header_pay_fee_price, currency: currency_symbol),
+ I18n.t(:report_header_total_price, currency: currency_symbol),
+ I18n.t(:report_header_paid), I18n.t(:report_header_shipping), I18n.t(:report_header_delivery),
+ I18n.t(:report_header_ship_street), I18n.t(:report_header_ship_street_2), I18n.t(:report_header_ship_city), I18n.t(:report_header_ship_postcode), I18n.t(:report_header_ship_state),
+ I18n.t(:report_header_comments), I18n.t(:report_header_sku),
+ I18n.t(:report_header_order_cycle), I18n.t(:report_header_payment_method), I18n.t(:report_header_customer_code), I18n.t(:report_header_tags),
+ I18n.t(:report_header_billing_street), I18n.t(:report_header_billing_street_2), I18n.t(:report_header_billing_city), I18n.t(:report_header_billing_postcode), I18n.t(:report_header_billing_state),]
else
[I18n.t(:report_header_producer), I18n.t(:report_header_product), I18n.t(:report_header_variant),
- I18n.t(:report_header_amount), I18n.t(:report_header_curr_cost_per_unit), I18n.t(:report_header_total_cost),
- I18n.t(:report_header_status), I18n.t(:report_header_incoming_transport)]
+ I18n.t(:report_header_amount), I18n.t(:report_header_curr_cost_per_unit), I18n.t(:report_header_total_cost),
+ I18n.t(:report_header_status), I18n.t(:report_header_incoming_transport)]
end
end
@@ -59,141 +59,141 @@ module OpenFoodNetwork
def rules
case params[:report_type]
when "order_cycle_supplier_totals"
- [ { group_by: proc { |line_item| line_item.product.supplier },
- sort_by: proc { |supplier| supplier.name } },
- { group_by: proc { |line_item| line_item.product },
- sort_by: proc { |product| product.name } },
- { group_by: proc { |line_item| line_item.full_name },
- sort_by: proc { |full_name| full_name } } ]
+ [{ group_by: proc { |line_item| line_item.product.supplier },
+ sort_by: proc { |supplier| supplier.name } },
+ { group_by: proc { |line_item| line_item.product },
+ sort_by: proc { |product| product.name } },
+ { group_by: proc { |line_item| line_item.full_name },
+ sort_by: proc { |full_name| full_name } }]
when "order_cycle_supplier_totals_by_distributor"
- [ { group_by: proc { |line_item| line_item.product.supplier },
- sort_by: proc { |supplier| supplier.name } },
- { group_by: proc { |line_item| line_item.product },
- sort_by: proc { |product| product.name } },
- { group_by: proc { |line_item| line_item.full_name },
- sort_by: proc { |full_name| full_name },
- summary_columns: [ proc { |line_items| "" },
- proc { |line_items| "" },
- proc { |line_items| "" },
- proc { |line_items| I18n.t('admin.reports.total') },
- proc { |line_items| "" },
- proc { |line_items| "" },
- proc { |line_items| line_items.sum { |li| li.amount } },
- proc { |line_items| "" } ] },
- { group_by: proc { |line_item| line_item.order.distributor },
- sort_by: proc { |distributor| distributor.name } } ]
+ [{ group_by: proc { |line_item| line_item.product.supplier },
+ sort_by: proc { |supplier| supplier.name } },
+ { group_by: proc { |line_item| line_item.product },
+ sort_by: proc { |product| product.name } },
+ { group_by: proc { |line_item| line_item.full_name },
+ sort_by: proc { |full_name| full_name },
+ summary_columns: [proc { |_line_items| "" },
+ proc { |_line_items| "" },
+ proc { |_line_items| "" },
+ proc { |_line_items| I18n.t('admin.reports.total') },
+ proc { |_line_items| "" },
+ proc { |_line_items| "" },
+ proc { |line_items| line_items.sum(&:amount) },
+ proc { |_line_items| "" }] },
+ { group_by: proc { |line_item| line_item.order.distributor },
+ sort_by: proc { |distributor| distributor.name } }]
when "order_cycle_distributor_totals_by_supplier"
- [ { group_by: proc { |line_item| line_item.order.distributor },
- sort_by: proc { |distributor| distributor.name },
- summary_columns: [ proc { |line_items| "" },
- proc { |line_items| I18n.t('admin.reports.total') },
- proc { |line_items| "" },
- proc { |line_items| "" },
- proc { |line_items| "" },
- proc { |line_items| "" },
- proc { |line_items| line_items.sum { |li| li.amount } },
- proc { |line_items| line_items.map { |li| li.order }.uniq.sum { |o| o.ship_total } },
- proc { |line_items| "" } ] },
- { group_by: proc { |line_item| line_item.product.supplier },
- sort_by: proc { |supplier| supplier.name } },
- { group_by: proc { |line_item| line_item.product },
- sort_by: proc { |product| product.name } },
- { group_by: proc { |line_item| line_item.full_name },
- sort_by: proc { |full_name| full_name } } ]
+ [{ group_by: proc { |line_item| line_item.order.distributor },
+ sort_by: proc { |distributor| distributor.name },
+ summary_columns: [proc { |_line_items| "" },
+ proc { |_line_items| I18n.t('admin.reports.total') },
+ proc { |_line_items| "" },
+ proc { |_line_items| "" },
+ proc { |_line_items| "" },
+ proc { |_line_items| "" },
+ proc { |line_items| line_items.sum(&:amount) },
+ proc { |line_items| line_items.map(&:order).uniq.sum(&:ship_total) },
+ proc { |_line_items| "" }] },
+ { group_by: proc { |line_item| line_item.product.supplier },
+ sort_by: proc { |supplier| supplier.name } },
+ { group_by: proc { |line_item| line_item.product },
+ sort_by: proc { |product| product.name } },
+ { group_by: proc { |line_item| line_item.full_name },
+ sort_by: proc { |full_name| full_name } }]
when "order_cycle_customer_totals"
- [ { group_by: proc { |line_item| line_item.order.distributor },
- sort_by: proc { |distributor| distributor.name } },
- { group_by: proc { |line_item| line_item.order },
- sort_by: proc { |order| order.bill_address.full_name_reverse },
- summary_columns: [
- proc { |line_items| line_items.first.order.distributor.name },
- proc { |line_items| line_items.first.order.bill_address.full_name },
- proc { |line_items| "" },
- proc { |line_items| "" },
- proc { |line_items| "" },
- proc { |line_items| I18n.t('admin.reports.total') },
- proc { |line_items| "" },
+ [{ group_by: proc { |line_item| line_item.order.distributor },
+ sort_by: proc { |distributor| distributor.name } },
+ { group_by: proc { |line_item| line_item.order },
+ sort_by: proc { |order| order.bill_address.full_name_reverse },
+ summary_columns: [
+ proc { |line_items| line_items.first.order.distributor.name },
+ proc { |line_items| line_items.first.order.bill_address.full_name },
+ proc { |_line_items| "" },
+ proc { |_line_items| "" },
+ proc { |_line_items| "" },
+ proc { |_line_items| I18n.t('admin.reports.total') },
+ proc { |_line_items| "" },
- proc { |line_items| "" },
- proc { |line_items| line_items.sum(&:amount) },
- proc { |line_items| line_items.sum(&:amount_with_adjustments) },
- proc { |line_items| line_items.first.order.admin_and_handling_total },
- proc { |line_items| line_items.first.order.ship_total },
- proc { |line_items| line_items.first.order.payment_fee },
- proc { |line_items| line_items.first.order.total },
- proc { |line_items| line_items.first.order.paid? ? I18n.t(:yes) : I18n.t(:no) },
+ proc { |_line_items| "" },
+ proc { |line_items| line_items.sum(&:amount) },
+ proc { |line_items| line_items.sum(&:amount_with_adjustments) },
+ proc { |line_items| line_items.first.order.admin_and_handling_total },
+ proc { |line_items| line_items.first.order.ship_total },
+ proc { |line_items| line_items.first.order.payment_fee },
+ proc { |line_items| line_items.first.order.total },
+ proc { |line_items| line_items.first.order.paid? ? I18n.t(:yes) : I18n.t(:no) },
- proc { |line_items| "" },
- proc { |line_items| "" },
+ proc { |_line_items| "" },
+ proc { |_line_items| "" },
- proc { |line_items| "" },
- proc { |line_items| "" },
- proc { |line_items| "" },
- proc { |line_items| "" },
- proc { |line_items| "" },
+ proc { |_line_items| "" },
+ proc { |_line_items| "" },
+ proc { |_line_items| "" },
+ proc { |_line_items| "" },
+ proc { |_line_items| "" },
- proc { |line_items| line_items.first.order.special_instructions } ,
- proc { |line_items| "" },
+ proc { |line_items| line_items.first.order.special_instructions },
+ proc { |_line_items| "" },
- proc { |line_items| line_items.first.order.order_cycle.andand.name },
- proc { |line_items|
- line_items.first.order.payments.first.andand.payment_method.andand.name
- },
- proc { |line_items| "" },
- proc { |line_items| "" },
- proc { |line_items| "" },
- proc { |line_items| "" },
- proc { |line_items| "" },
- proc { |line_items| "" },
- proc { |line_items| "" }
- ] },
- { group_by: proc { |line_item| line_item.product },
- sort_by: proc { |product| product.name } },
- { group_by: proc { |line_item| line_item.variant },
- sort_by: proc { |variant| variant.full_name } },
- { group_by: proc { |line_item| line_item.full_name },
- sort_by: proc { |full_name| full_name } } ]
+ proc { |line_items| line_items.first.order.order_cycle.andand.name },
+ proc { |line_items|
+ line_items.first.order.payments.first.andand.payment_method.andand.name
+ },
+ proc { |_line_items| "" },
+ proc { |_line_items| "" },
+ proc { |_line_items| "" },
+ proc { |_line_items| "" },
+ proc { |_line_items| "" },
+ proc { |_line_items| "" },
+ proc { |_line_items| "" }
+ ] },
+ { group_by: proc { |line_item| line_item.product },
+ sort_by: proc { |product| product.name } },
+ { group_by: proc { |line_item| line_item.variant },
+ sort_by: proc { |variant| variant.full_name } },
+ { group_by: proc { |line_item| line_item.full_name },
+ sort_by: proc { |full_name| full_name } }]
else
- [ { group_by: proc { |line_item| line_item.product.supplier },
- sort_by: proc { |supplier| supplier.name } },
- { group_by: proc { |line_item| line_item.product },
- sort_by: proc { |product| product.name } },
- { group_by: proc { |line_item| line_item.full_name },
- sort_by: proc { |full_name| full_name } } ]
+ [{ group_by: proc { |line_item| line_item.product.supplier },
+ sort_by: proc { |supplier| supplier.name } },
+ { group_by: proc { |line_item| line_item.product },
+ sort_by: proc { |product| product.name } },
+ { group_by: proc { |line_item| line_item.full_name },
+ sort_by: proc { |full_name| full_name } }]
end
end
def columns
case params[:report_type]
when "order_cycle_supplier_totals"
- [ proc { |line_items| line_items.first.product.supplier.name },
- proc { |line_items| line_items.first.product.name },
- proc { |line_items| line_items.first.full_name },
- proc { |line_items| line_items.sum { |li| li.quantity } },
- proc { |line_items| total_units(line_items) },
- proc { |line_items| line_items.first.price },
- proc { |line_items| line_items.sum { |li| li.amount } },
- proc { |line_items| "" },
- proc { |line_items| I18n.t(:report_header_incoming_transport) } ]
+ [proc { |line_items| line_items.first.product.supplier.name },
+ proc { |line_items| line_items.first.product.name },
+ proc { |line_items| line_items.first.full_name },
+ proc { |line_items| line_items.sum(&:quantity) },
+ proc { |line_items| total_units(line_items) },
+ proc { |line_items| line_items.first.price },
+ proc { |line_items| line_items.sum(&:amount) },
+ proc { |_line_items| "" },
+ proc { |_line_items| I18n.t(:report_header_incoming_transport) }]
when "order_cycle_supplier_totals_by_distributor"
- [ proc { |line_items| line_items.first.product.supplier.name },
- proc { |line_items| line_items.first.product.name },
- proc { |line_items| line_items.first.full_name },
- proc { |line_items| line_items.first.order.distributor.name },
- proc { |line_items| line_items.sum { |li| li.quantity } },
- proc { |line_items| line_items.first.price },
- proc { |line_items| line_items.sum { |li| li.amount } },
- proc { |line_items| I18n.t(:report_header_shipping_method) } ]
+ [proc { |line_items| line_items.first.product.supplier.name },
+ proc { |line_items| line_items.first.product.name },
+ proc { |line_items| line_items.first.full_name },
+ proc { |line_items| line_items.first.order.distributor.name },
+ proc { |line_items| line_items.sum(&:quantity) },
+ proc { |line_items| line_items.first.price },
+ proc { |line_items| line_items.sum(&:amount) },
+ proc { |_line_items| I18n.t(:report_header_shipping_method) }]
when "order_cycle_distributor_totals_by_supplier"
- [ proc { |line_items| line_items.first.order.distributor.name },
- proc { |line_items| line_items.first.product.supplier.name },
- proc { |line_items| line_items.first.product.name },
- proc { |line_items| line_items.first.full_name },
- proc { |line_items| line_items.sum { |li| li.quantity } },
- proc { |line_items| line_items.first.price },
- proc { |line_items| line_items.sum { |li| li.amount } },
- proc { |line_items| "" },
- proc { |line_items| I18n.t(:report_header_shipping_method) } ]
+ [proc { |line_items| line_items.first.order.distributor.name },
+ proc { |line_items| line_items.first.product.supplier.name },
+ proc { |line_items| line_items.first.product.name },
+ proc { |line_items| line_items.first.full_name },
+ proc { |line_items| line_items.sum(&:quantity) },
+ proc { |line_items| line_items.first.price },
+ proc { |line_items| line_items.sum(&:amount) },
+ proc { |_line_items| "" },
+ proc { |_line_items| I18n.t(:report_header_shipping_method) }]
when "order_cycle_customer_totals"
rsa = proc { |line_items| line_items.first.order.shipping_method.andand.delivery? }
[
@@ -205,13 +205,13 @@ module OpenFoodNetwork
proc { |line_items| line_items.first.product.name },
proc { |line_items| line_items.first.full_name },
- proc { |line_items| line_items.sum { |li| li.quantity } },
- proc { |line_items| line_items.sum { |li| li.amount } },
- proc { |line_items| line_items.sum { |li| li.amount_with_adjustments } },
- proc { |line_items| "" },
- proc { |line_items| "" },
- proc { |line_items| "" },
- proc { |line_items| "" },
+ proc { |line_items| line_items.sum(&:quantity) },
+ proc { |line_items| line_items.sum(&:amount) },
+ proc { |line_items| line_items.sum(&:amount_with_adjustments) },
+ proc { |_line_items| "" },
+ proc { |_line_items| "" },
+ proc { |_line_items| "" },
+ proc { |_line_items| "" },
proc { |line_items| line_items.all? { |li| li.order.paid? } ? I18n.t(:yes) : I18n.t(:no) },
proc { |line_items| line_items.first.order.shipping_method.andand.name },
@@ -223,7 +223,7 @@ module OpenFoodNetwork
proc { |line_items| line_items.first.order.ship_address.andand.zipcode if rsa.call(line_items) },
proc { |line_items| line_items.first.order.ship_address.andand.state if rsa.call(line_items) },
- proc { |line_items| "" },
+ proc { |_line_items| "" },
proc { |line_items| line_items.first.variant.sku },
proc { |line_items| line_items.first.order.order_cycle.andand.name },
@@ -238,14 +238,14 @@ module OpenFoodNetwork
proc { |line_items| line_items.first.order.bill_address.andand.state }
]
else
- [ proc { |line_items| line_items.first.product.supplier.name },
- proc { |line_items| line_items.first.product.name },
- proc { |line_items| line_items.first.full_name },
- proc { |line_items| line_items.sum { |li| li.quantity } },
- proc { |line_items| line_items.first.price },
- proc { |line_items| line_items.sum { |li| li.quantity * li.price } },
- proc { |line_items| "" },
- proc { |line_items| I18n.t(:report_header_incoming_transport) } ]
+ [proc { |line_items| line_items.first.product.supplier.name },
+ proc { |line_items| line_items.first.product.name },
+ proc { |line_items| line_items.first.full_name },
+ proc { |line_items| line_items.sum(&:quantity) },
+ proc { |line_items| line_items.first.price },
+ proc { |line_items| line_items.sum { |li| li.quantity * li.price } },
+ proc { |_line_items| "" },
+ proc { |_line_items| I18n.t(:report_header_incoming_transport) }]
end
end
diff --git a/lib/open_food_network/packing_report.rb b/lib/open_food_network/packing_report.rb
index 6f29fa7bc9..c46911e363 100644
--- a/lib/open_food_network/packing_report.rb
+++ b/lib/open_food_network/packing_report.rb
@@ -50,59 +50,59 @@ module OpenFoodNetwork
if is_by_customer?
[
{ group_by: proc { |line_item| line_item.order.distributor },
- sort_by: proc { |distributor| distributor.name } },
+ sort_by: proc { |distributor| distributor.name } },
{ group_by: proc { |line_item| line_item.order },
- sort_by: proc { |order| order.bill_address.lastname },
- summary_columns: [ proc { |line_items| "" },
- proc { |line_items| "" },
- proc { |line_items| "" },
- proc { |line_items| "" },
- proc { |line_items| "" },
- proc { |line_items| I18n.t('admin.reports.total_items') },
- proc { |line_items| "" },
- proc { |line_items| line_items.sum { |li| li.quantity } },
- proc { |line_items| "" } ] },
+ sort_by: proc { |order| order.bill_address.lastname },
+ summary_columns: [proc { |_line_items| "" },
+ proc { |_line_items| "" },
+ proc { |_line_items| "" },
+ proc { |_line_items| "" },
+ proc { |_line_items| "" },
+ proc { |_line_items| I18n.t('admin.reports.total_items') },
+ proc { |_line_items| "" },
+ proc { |line_items| line_items.sum(&:quantity) },
+ proc { |_line_items| "" }] },
{ group_by: proc { |line_item| line_item.product.supplier },
sort_by: proc { |supplier| supplier.name } },
{ group_by: proc { |line_item| line_item.product },
- sort_by: proc { |product| product.name } },
+ sort_by: proc { |product| product.name } },
{ group_by: proc { |line_item| line_item.full_name },
sort_by: proc { |full_name| full_name } }
]
else
- [ { group_by: proc { |line_item| line_item.order.distributor },
- sort_by: proc { |distributor| distributor.name } },
- { group_by: proc { |line_item| line_item.product.supplier },
- sort_by: proc { |supplier| supplier.name },
- summary_columns: [ proc { |line_items| "" },
- proc { |line_items| "" },
- proc { |line_items| "" },
- proc { |line_items| "" },
- proc { |line_items| "" },
- proc { |line_items| I18n.t('admin.reports.total_items') },
- proc { |line_items| "" },
- proc { |line_items| line_items.sum { |li| li.quantity } },
- proc { |line_items| "" } ] },
- { group_by: proc { |line_item| line_item.product },
- sort_by: proc { |product| product.name } },
- { group_by: proc { |line_item| line_item.full_name },
- sort_by: proc { |full_name| full_name } },
- { group_by: proc { |line_item| line_item.order },
- sort_by: proc { |order| order.bill_address.lastname } } ]
+ [{ group_by: proc { |line_item| line_item.order.distributor },
+ sort_by: proc { |distributor| distributor.name } },
+ { group_by: proc { |line_item| line_item.product.supplier },
+ sort_by: proc { |supplier| supplier.name },
+ summary_columns: [proc { |_line_items| "" },
+ proc { |_line_items| "" },
+ proc { |_line_items| "" },
+ proc { |_line_items| "" },
+ proc { |_line_items| "" },
+ proc { |_line_items| I18n.t('admin.reports.total_items') },
+ proc { |_line_items| "" },
+ proc { |line_items| line_items.sum(&:quantity) },
+ proc { |_line_items| "" }] },
+ { group_by: proc { |line_item| line_item.product },
+ sort_by: proc { |product| product.name } },
+ { group_by: proc { |line_item| line_item.full_name },
+ sort_by: proc { |full_name| full_name } },
+ { group_by: proc { |line_item| line_item.order },
+ sort_by: proc { |order| order.bill_address.lastname } }]
end
end
def columns
if is_by_customer?
- [ proc { |line_items| line_items.first.order.distributor.name },
- proc { |line_items| customer_code(line_items.first.order.email) },
- proc { |line_items| line_items.first.order.bill_address.firstname },
- proc { |line_items| line_items.first.order.bill_address.lastname },
- proc { |line_items| line_items.first.product.supplier.name },
- proc { |line_items| line_items.first.product.name },
- proc { |line_items| line_items.first.full_name },
- proc { |line_items| line_items.sum { |li| li.quantity } },
- proc { |line_items| is_temperature_controlled?(line_items.first) }]
+ [proc { |line_items| line_items.first.order.distributor.name },
+ proc { |line_items| customer_code(line_items.first.order.email) },
+ proc { |line_items| line_items.first.order.bill_address.firstname },
+ proc { |line_items| line_items.first.order.bill_address.lastname },
+ proc { |line_items| line_items.first.product.supplier.name },
+ proc { |line_items| line_items.first.product.name },
+ proc { |line_items| line_items.first.full_name },
+ proc { |line_items| line_items.sum(&:quantity) },
+ proc { |line_items| is_temperature_controlled?(line_items.first) }]
else
[
proc { |line_items| line_items.first.order.distributor.name },
@@ -112,7 +112,7 @@ module OpenFoodNetwork
proc { |line_items| line_items.first.order.bill_address.lastname },
proc { |line_items| line_items.first.product.name },
proc { |line_items| line_items.first.full_name },
- proc { |line_items| line_items.sum { |li| li.quantity } },
+ proc { |line_items| line_items.sum(&:quantity) },
proc { |line_items| is_temperature_controlled?(line_items.first) }
]
end
diff --git a/lib/open_food_network/paperclippable.rb b/lib/open_food_network/paperclippable.rb
index 580f8507b2..4bb6396695 100644
--- a/lib/open_food_network/paperclippable.rb
+++ b/lib/open_food_network/paperclippable.rb
@@ -38,11 +38,11 @@ module OpenFoodNetwork
def errors
obj = Object.new
- def obj.[](key) [] end
+ def obj.[](_key) [] end
def obj.full_messages() [] end
- def obj.any?() false end
+ def obj.any?() false end
obj
end
end
diff --git a/lib/open_food_network/payments_report.rb b/lib/open_food_network/payments_report.rb
index fc46422011..b57b457693 100644
--- a/lib/open_food_network/payments_report.rb
+++ b/lib/open_food_network/payments_report.rb
@@ -40,7 +40,7 @@ module OpenFoodNetwork
def table_items
return [] unless @render_table
orders = search.result
- payments = orders.map { |o| o.payments.select { |payment| payment.completed? } }.flatten # Only select completed payments
+ payments = orders.map { |o| o.payments.select(&:completed?) }.flatten # Only select completed payments
case params[:report_type]
when "payments_by_payment_type"
payments
@@ -56,60 +56,60 @@ module OpenFoodNetwork
def rules
case params[:report_type]
when "payments_by_payment_type"
- [ { group_by: proc { |payment| payment.order.payment_state },
- sort_by: proc { |payment_state| payment_state } },
- { group_by: proc { |payment| payment.order.distributor },
- sort_by: proc { |distributor| distributor.name } },
- { group_by: proc { |payment| Spree::PaymentMethod.unscoped { payment.payment_method } },
- sort_by: proc { |method| method.name } } ]
+ [{ group_by: proc { |payment| payment.order.payment_state },
+ sort_by: proc { |payment_state| payment_state } },
+ { group_by: proc { |payment| payment.order.distributor },
+ sort_by: proc { |distributor| distributor.name } },
+ { group_by: proc { |payment| Spree::PaymentMethod.unscoped { payment.payment_method } },
+ sort_by: proc { |method| method.name } }]
when "itemised_payment_totals"
- [ { group_by: proc { |order| order.payment_state },
- sort_by: proc { |payment_state| payment_state } },
- { group_by: proc { |order| order.distributor },
- sort_by: proc { |distributor| distributor.name } } ]
+ [{ group_by: proc { |order| order.payment_state },
+ sort_by: proc { |payment_state| payment_state } },
+ { group_by: proc { |order| order.distributor },
+ sort_by: proc { |distributor| distributor.name } }]
when "payment_totals"
- [ { group_by: proc { |order| order.payment_state },
- sort_by: proc { |payment_state| payment_state } },
- { group_by: proc { |order| order.distributor },
- sort_by: proc { |distributor| distributor.name } } ]
+ [{ group_by: proc { |order| order.payment_state },
+ sort_by: proc { |payment_state| payment_state } },
+ { group_by: proc { |order| order.distributor },
+ sort_by: proc { |distributor| distributor.name } }]
else
- [ { group_by: proc { |payment| payment.order.payment_state },
- sort_by: proc { |payment_state| payment_state } },
- { group_by: proc { |payment| payment.order.distributor },
- sort_by: proc { |distributor| distributor.name } },
- { group_by: proc { |payment| payment.payment_method },
- sort_by: proc { |method| method.name } } ]
+ [{ group_by: proc { |payment| payment.order.payment_state },
+ sort_by: proc { |payment_state| payment_state } },
+ { group_by: proc { |payment| payment.order.distributor },
+ sort_by: proc { |distributor| distributor.name } },
+ { group_by: proc { |payment| payment.payment_method },
+ sort_by: proc { |method| method.name } }]
end
end
def columns
case params[:report_type]
when "payments_by_payment_type"
- [ proc { |payments| payments.first.order.payment_state },
- proc { |payments| payments.first.order.distributor.name },
- proc { |payments| payments.first.payment_method.name },
- proc { |payments| payments.sum { |payment| payment.amount } } ]
+ [proc { |payments| payments.first.order.payment_state },
+ proc { |payments| payments.first.order.distributor.name },
+ proc { |payments| payments.first.payment_method.name },
+ proc { |payments| payments.sum(&:amount) }]
when "itemised_payment_totals"
- [ proc { |orders| orders.first.payment_state },
- proc { |orders| orders.first.distributor.name },
- proc { |orders| orders.sum { |o| o.item_total } },
- proc { |orders| orders.sum { |o| o.ship_total } },
- proc { |orders| orders.sum { |o| o.outstanding_balance } },
- proc { |orders| orders.sum { |o| o.total } } ]
+ [proc { |orders| orders.first.payment_state },
+ proc { |orders| orders.first.distributor.name },
+ proc { |orders| orders.sum(&:item_total) },
+ proc { |orders| orders.sum(&:ship_total) },
+ proc { |orders| orders.sum(&:outstanding_balance) },
+ proc { |orders| orders.sum(&:total) }]
when "payment_totals"
- [ proc { |orders| orders.first.payment_state },
- proc { |orders| orders.first.distributor.name },
- proc { |orders| orders.sum { |o| o.item_total } },
- proc { |orders| orders.sum { |o| o.ship_total } },
- proc { |orders| orders.sum { |o| o.total } },
- proc { |orders| orders.sum { |o| o.payments.select { |payment| payment.completed? && (payment.payment_method.name.to_s.include? "EFT") }.sum { |payment| payment.amount } } },
- proc { |orders| orders.sum { |o| o.payments.select { |payment| payment.completed? && (payment.payment_method.name.to_s.include? "PayPal") }.sum{ |payment| payment.amount } } },
- proc { |orders| orders.sum { |o| o.outstanding_balance } } ]
+ [proc { |orders| orders.first.payment_state },
+ proc { |orders| orders.first.distributor.name },
+ proc { |orders| orders.sum(&:item_total) },
+ proc { |orders| orders.sum(&:ship_total) },
+ proc { |orders| orders.sum(&:total) },
+ proc { |orders| orders.sum { |o| o.payments.select { |payment| payment.completed? && (payment.payment_method.name.to_s.include? "EFT") }.sum(&:amount) } },
+ proc { |orders| orders.sum { |o| o.payments.select { |payment| payment.completed? && (payment.payment_method.name.to_s.include? "PayPal") }.sum(&:amount) } },
+ proc { |orders| orders.sum(&:outstanding_balance) }]
else
- [ proc { |payments| payments.first.order.payment_state },
- proc { |payments| payments.first.order.distributor.name },
- proc { |payments| payments.first.payment_method.name },
- proc { |payments| payments.sum { |payment| payment.amount } } ]
+ [proc { |payments| payments.first.order.payment_state },
+ proc { |payments| payments.first.order.distributor.name },
+ proc { |payments| payments.first.payment_method.name },
+ proc { |payments| payments.sum(&:amount) }]
end
end
end
diff --git a/lib/open_food_network/permissions.rb b/lib/open_food_network/permissions.rb
index d303af5681..eec62ed775 100644
--- a/lib/open_food_network/permissions.rb
+++ b/lib/open_food_network/permissions.rb
@@ -45,8 +45,8 @@ module OpenFoodNetwork
EnterpriseRelationship.
permitting(hubs).
with_permission(:create_variant_overrides).
- group_by { |er| er.child_id }.
- map { |child_id, ers| [child_id, ers.map { |er| er.parent_id }] }
+ group_by(&:child_id).
+ map { |child_id, ers| [child_id, ers.map(&:parent_id)] }
]
# Allow a producer hub to override it's own products without explicit permission
@@ -181,22 +181,22 @@ module OpenFoodNetwork
@coordinated_order_cycles = OrderCycle.managed_by(@user)
end
- def related_enterprises_granting(permission, options={})
+ def related_enterprises_granting(permission, options = {})
parent_ids = EnterpriseRelationship.
permitting(options[:to] || managed_enterprises).
with_permission(permission).
pluck(:parent_id)
- (options[:scope] || Enterprise).where('enterprises.id IN (?)', parent_ids)
+ (options[:scope] || Enterprise).where('enterprises.id IN (?)', parent_ids)
end
- def related_enterprises_granted(permission, options={})
+ def related_enterprises_granted(permission, options = {})
child_ids = EnterpriseRelationship.
permitted_by(options[:by] || managed_enterprises).
with_permission(permission).
pluck(:child_id)
- (options[:scope] || Enterprise).where('enterprises.id IN (?)', child_ids)
+ (options[:scope] || Enterprise).where('enterprises.id IN (?)', child_ids)
end
def managed_enterprise_products
diff --git a/lib/open_food_network/products_and_inventory_report.rb b/lib/open_food_network/products_and_inventory_report.rb
index 16d94dafb7..53ee7d1c65 100644
--- a/lib/open_food_network/products_and_inventory_report.rb
+++ b/lib/open_food_network/products_and_inventory_report.rb
@@ -36,7 +36,7 @@ module OpenFoodNetwork
end
def sku_for(variant)
- return variant.sku unless variant.sku.blank?
+ return variant.sku if variant.sku.present?
variant.product.sku
end
end
diff --git a/lib/open_food_network/products_cache.rb b/lib/open_food_network/products_cache.rb
index 99e15f070b..b1118cd80d 100644
--- a/lib/open_food_network/products_cache.rb
+++ b/lib/open_food_network/products_cache.rb
@@ -99,7 +99,6 @@ module OpenFoodNetwork
end
end
-
private
def self.exchanges_featuring_variants(variants, distributor: nil)
@@ -141,7 +140,7 @@ module OpenFoodNetwork
def self.refresh_distributor_fee(enterprise_fee)
enterprise_fee.exchange_fees.
- joins(:exchange => :order_cycle).
+ joins(exchange: :order_cycle).
merge(Exchange.outgoing).
merge(OrderCycle.dated).
merge(OrderCycle.not_closed).
diff --git a/lib/open_food_network/products_cache_integrity_checker.rb b/lib/open_food_network/products_cache_integrity_checker.rb
index 8098124feb..a47ea804e5 100644
--- a/lib/open_food_network/products_cache_integrity_checker.rb
+++ b/lib/open_food_network/products_cache_integrity_checker.rb
@@ -15,7 +15,6 @@ module OpenFoodNetwork
@diff ||= Diffy::Diff.new pretty(cached_json), pretty(rendered_json)
end
-
private
def cached_json
diff --git a/lib/open_food_network/products_renderer.rb b/lib/open_food_network/products_renderer.rb
index ef9afb3b1e..6cc4307eea 100644
--- a/lib/open_food_network/products_renderer.rb
+++ b/lib/open_food_network/products_renderer.rb
@@ -2,7 +2,7 @@ require 'open_food_network/scope_product_to_hub'
module OpenFoodNetwork
class ProductsRenderer
- class NoProducts < Exception; end
+ class NoProducts < RuntimeError; end
def initialize(distributor, order_cycle)
@distributor = distributor
@@ -21,14 +21,12 @@ module OpenFoodNetwork
current_distributor: @distributor,
variants: variants_for_shop_by_id,
master_variants: master_variants_for_shop_by_id,
- enterprise_fee_calculator: enterprise_fee_calculator,
- ).to_json
+ enterprise_fee_calculator: enterprise_fee_calculator,).to_json
else
- raise NoProducts.new
+ raise NoProducts
end
end
-
private
def load_products
@@ -75,10 +73,9 @@ module OpenFoodNetwork
end
def index_by_product_id(variants)
- variants.inject({}) do |vs, v|
+ variants.each_with_object({}) do |v, vs|
vs[v.product_id] ||= []
vs[v.product_id] << v
- vs
end
end
end
diff --git a/lib/open_food_network/rack_request_blocker.rb b/lib/open_food_network/rack_request_blocker.rb
index 71f1c450e2..99ec116b2e 100644
--- a/lib/open_food_network/rack_request_blocker.rb
+++ b/lib/open_food_network/rack_request_blocker.rb
@@ -5,7 +5,6 @@ require 'atomic'
# Rack middleware that keeps track of the number of active requests and can block new requests.
class RackRequestBlocker
-
@@num_active_requests = Atomic.new(0)
@@block_requests = Atomic.new(false)
@@ -41,20 +40,20 @@ class RackRequestBlocker
end
def self.wait_for_requests_complete
- self.block_requests!
+ block_requests!
max_wait_time = 30
polling_interval = 0.01
wait_until = Time.now + max_wait_time.seconds
- while true
- return if self.num_active_requests == 0
+ loop do
+ return if num_active_requests == 0
if Time.now > wait_until
- raise "Failed waiting for completing requests, #{self.num_active_requests} running."
+ raise "Failed waiting for completing requests, #{num_active_requests} running."
else
sleep(polling_interval)
end
end
ensure
- self.allow_requests!
+ allow_requests!
end
private
@@ -63,7 +62,7 @@ class RackRequestBlocker
@@block_requests.value
end
- def block_request(env)
+ def block_request(_env)
[503, {}, []]
end
diff --git a/lib/open_food_network/reports/bulk_coop_allocation_report.rb b/lib/open_food_network/reports/bulk_coop_allocation_report.rb
index 2909649fb9..f132e642df 100644
--- a/lib/open_food_network/reports/bulk_coop_allocation_report.rb
+++ b/lib/open_food_network/reports/bulk_coop_allocation_report.rb
@@ -19,17 +19,17 @@ module OpenFoodNetwork::Reports
end
organise do
- group { |li| li.product }
+ group(&:product)
sort(&:name)
summary_row do
- column { |lis| I18n.t('admin.reports.total') }
+ column { |_lis| I18n.t('admin.reports.total') }
column { |lis| product_name(lis) }
column { |lis| group_buy_unit_size_f(lis) }
- column { |lis| "" }
- column { |lis| "" }
- column { |lis| "" }
- column { |lis| "" }
+ column { |_lis| "" }
+ column { |_lis| "" }
+ column { |_lis| "" }
+ column { |_lis| "" }
column { |lis| total_amount(lis) }
column { |lis| total_available(lis) }
column { |lis| remainder(lis) }
@@ -37,12 +37,12 @@ module OpenFoodNetwork::Reports
end
organise do
- group { |li| li.full_name }
+ group(&:full_name)
sort { |full_name| full_name }
organise do
- group { |li| li.order }
- sort { |order| order.to_s }
+ group(&:order)
+ sort(&:to_s)
end
end
end
@@ -56,9 +56,9 @@ module OpenFoodNetwork::Reports
column { |lis| OpenFoodNetwork::OptionValueNamer.new(lis.first).unit }
column { |lis| lis.first.weight_from_unit_value || 0 }
column { |lis| total_amount(lis) }
- column { |lis| "" }
- column { |lis| "" }
- column { |lis| "" }
+ column { |_lis| "" }
+ column { |_lis| "" }
+ column { |_lis| "" }
end
end
end
diff --git a/lib/open_food_network/reports/bulk_coop_report.rb b/lib/open_food_network/reports/bulk_coop_report.rb
index b743b64e29..0bbefcab35 100644
--- a/lib/open_food_network/reports/bulk_coop_report.rb
+++ b/lib/open_food_network/reports/bulk_coop_report.rb
@@ -2,12 +2,9 @@ require 'open_food_network/reports/report'
module OpenFoodNetwork::Reports
class BulkCoopReport < Report
-
-
private
class << self
-
def supplier_name(lis)
lis.first.variant.product.supplier.name
end
diff --git a/lib/open_food_network/reports/bulk_coop_supplier_report.rb b/lib/open_food_network/reports/bulk_coop_supplier_report.rb
index d5b0039529..ae4ed3da37 100644
--- a/lib/open_food_network/reports/bulk_coop_supplier_report.rb
+++ b/lib/open_food_network/reports/bulk_coop_supplier_report.rb
@@ -23,17 +23,17 @@ module OpenFoodNetwork::Reports
sort(&:name)
organise do
- group { |li| li.product }
+ group(&:product)
sort(&:name)
summary_row do
column { |lis| supplier_name(lis) }
column { |lis| product_name(lis) }
column { |lis| group_buy_unit_size_f(lis) }
- column { |lis| "" }
- column { |lis| "" }
- column { |lis| "" }
- column { |lis| "" }
+ column { |_lis| "" }
+ column { |_lis| "" }
+ column { |_lis| "" }
+ column { |_lis| "" }
column { |lis| total_amount(lis) }
column { |lis| units_required(lis) }
column { |lis| remainder(lis) }
@@ -41,7 +41,7 @@ module OpenFoodNetwork::Reports
end
organise do
- group { |li| li.full_name }
+ group(&:full_name)
sort { |full_name| full_name }
end
end
@@ -56,9 +56,9 @@ module OpenFoodNetwork::Reports
column { |lis| OpenFoodNetwork::OptionValueNamer.new(lis.first).unit }
column { |lis| lis.first.weight_from_unit_value || 0 }
column { |lis| total_amount(lis) }
- column { |lis| '' }
- column { |lis| '' }
- column { |lis| '' }
+ column { |_lis| '' }
+ column { |_lis| '' }
+ column { |_lis| '' }
end
end
end
diff --git a/lib/open_food_network/reports/report.rb b/lib/open_food_network/reports/report.rb
index 2bf0a48fbb..2933b7cec6 100644
--- a/lib/open_food_network/reports/report.rb
+++ b/lib/open_food_network/reports/report.rb
@@ -7,18 +7,18 @@ module OpenFoodNetwork::Reports
# -- API
def header
- self._header
+ _header
end
def columns
- self._columns.to_a
+ _columns.to_a
end
def rules
# Flatten linked list and return as hashes
rules = []
- rule = self._rules_head
+ rule = _rules_head
while rule
rules << rule
rule = rule.next
@@ -34,12 +34,12 @@ module OpenFoodNetwork::Reports
def self.columns(&block)
self._columns = Row.new
- Blockenspiel.invoke block, self._columns
+ Blockenspiel.invoke block, _columns
end
def self.organise(&block)
self._rules_head = Rule.new
- Blockenspiel.invoke block, self._rules_head
+ Blockenspiel.invoke block, _rules_head
end
end
end
diff --git a/lib/open_food_network/reports/rule.rb b/lib/open_food_network/reports/rule.rb
index e2f94f32a2..372c52b249 100644
--- a/lib/open_food_network/reports/rule.rb
+++ b/lib/open_food_network/reports/rule.rb
@@ -24,8 +24,8 @@ module OpenFoodNetwork::Reports
end
def to_h
- h = {group_by: @group, sort_by: @sort}
- h.merge!({summary_columns: @summary_row.to_a}) if @summary_row
+ h = { group_by: @group, sort_by: @sort }
+ h[:summary_columns] = @summary_row.to_a if @summary_row
h
end
end
diff --git a/lib/open_food_network/sales_tax_report.rb b/lib/open_food_network/sales_tax_report.rb
index 02f0651ecf..4763c4ebff 100644
--- a/lib/open_food_network/sales_tax_report.rb
+++ b/lib/open_food_network/sales_tax_report.rb
@@ -14,10 +14,10 @@ module OpenFoodNetwork
when "tax_rates"
[I18n.t(:report_header_order_number),
I18n.t(:report_header_total_excl_vat, currency_symbol: currency_symbol)] +
- relevant_rates.map { |rate| "%.1f%% (%s)" % [rate.amount.to_f * 100, currency_symbol] } +
- [I18n.t(:report_header_total_tax, currency_symbol: currency_symbol),
- I18n.t(:report_header_total_incl_vat, currency_symbol: currency_symbol)]
- else
+ relevant_rates.map { |rate| "%.1f%% (%s)" % [rate.amount.to_f * 100, currency_symbol] } +
+ [I18n.t(:report_header_total_tax, currency_symbol: currency_symbol),
+ I18n.t(:report_header_total_incl_vat, currency_symbol: currency_symbol)]
+ else
[I18n.t(:report_header_order_number),
I18n.t(:report_header_date),
I18n.t(:report_header_items),
@@ -63,7 +63,6 @@ module OpenFoodNetwork
end
end
-
private
def relevant_rates
@@ -72,7 +71,7 @@ module OpenFoodNetwork
end
def totals_of(line_items)
- totals = {items: 0, items_total: 0.0, taxable_total: 0.0, sales_tax: 0.0}
+ totals = { items: 0, items_total: 0.0, taxable_total: 0.0, sales_tax: 0.0 }
line_items.each do |line_item|
totals[:items] += line_item.quantity
@@ -86,7 +85,7 @@ module OpenFoodNetwork
end
end
- totals.each_pair do |k, v|
+ totals.each_pair do |k, _v|
totals[k] = totals[k].round(2)
end
diff --git a/lib/open_food_network/scope_product_to_hub.rb b/lib/open_food_network/scope_product_to_hub.rb
index f06eea430b..a8707b7032 100644
--- a/lib/open_food_network/scope_product_to_hub.rb
+++ b/lib/open_food_network/scope_product_to_hub.rb
@@ -13,7 +13,6 @@ module OpenFoodNetwork
product.instance_variable_set :@variant_overrides, @variant_overrides
end
-
module ScopeProductToHub
def variants_distributed_by(order_cycle, distributor)
super.each { |v| ScopeVariantToHub.new(@hub, @variant_overrides).scope(v) }
diff --git a/lib/open_food_network/tag_rule_applicator.rb b/lib/open_food_network/tag_rule_applicator.rb
index 803b426f69..fe5584f6b7 100644
--- a/lib/open_food_network/tag_rule_applicator.rb
+++ b/lib/open_food_network/tag_rule_applicator.rb
@@ -2,7 +2,7 @@ module OpenFoodNetwork
class TagRuleApplicator
attr_reader :enterprise, :rule_class, :customer_tags
- def initialize(enterprise, rule_type, customer_tags=[])
+ def initialize(enterprise, rule_type, customer_tags = [])
raise "Enterprise cannot be nil" if enterprise.nil?
raise "Rule Type cannot be nil" if rule_type.nil?
diff --git a/lib/open_food_network/users_and_enterprises_report.rb b/lib/open_food_network/users_and_enterprises_report.rb
index 3b5701d07b..c110453be2 100644
--- a/lib/open_food_network/users_and_enterprises_report.rb
+++ b/lib/open_food_network/users_and_enterprises_report.rb
@@ -6,8 +6,8 @@ module OpenFoodNetwork
@compile_table = compile_table
# Convert arrays of ids to comma delimited strings
- @params[:enterprise_id_in] = @params[:enterprise_id_in].join(',') if @params[:enterprise_id_in].kind_of? Array
- @params[:user_id_in] = @params[:user_id_in].join(',') if @params[:user_id_in].kind_of? Array
+ @params[:enterprise_id_in] = @params[:enterprise_id_in].join(',') if @params[:enterprise_id_in].is_a? Array
+ @params[:user_id_in] = @params[:user_id_in].join(',') if @params[:user_id_in].is_a? Array
end
def header
@@ -82,7 +82,7 @@ module OpenFoodNetwork
end
def users_and_enterprises
- sort( owners_and_enterprises.concat managers_and_enterprises )
+ sort( owners_and_enterprises.concat(managers_and_enterprises) )
end
def filter_by_int_list_if_present(query, filtered_field_name, int_list)
@@ -97,13 +97,13 @@ module OpenFoodNetwork
end
def sort(results)
- results.sort do |a,b|
+ results.sort do |a, b|
if a["created_at"].nil? || b["created_at"].nil?
- [ (a["created_at"].nil? ? 0 : 1), a["name"], b["relationship_type"], a["user_email"] ] <=>
- [ (b["created_at"].nil? ? 0 : 1), b["name"], a["relationship_type"], b["user_email"] ]
+ [(a["created_at"].nil? ? 0 : 1), a["name"], b["relationship_type"], a["user_email"]] <=>
+ [(b["created_at"].nil? ? 0 : 1), b["name"], a["relationship_type"], b["user_email"]]
else
- [ DateTime.parse(b["created_at"]), a["name"], b["relationship_type"], a["user_email"] ] <=>
- [ DateTime.parse(a["created_at"]), b["name"], a["relationship_type"], b["user_email"] ]
+ [DateTime.parse(b["created_at"]), a["name"], b["relationship_type"], a["user_email"]] <=>
+ [DateTime.parse(a["created_at"]), b["name"], a["relationship_type"], b["user_email"]]
end
end
end
diff --git a/lib/open_food_network/variant_and_line_item_naming.rb b/lib/open_food_network/variant_and_line_item_naming.rb
index 148dadaf67..cf6778a3e9 100644
--- a/lib/open_food_network/variant_and_line_item_naming.rb
+++ b/lib/open_food_network/variant_and_line_item_naming.rb
@@ -8,11 +8,11 @@ module OpenFoodNetwork
module VariantAndLineItemNaming
# Copied and modified from Spree::Variant
def options_text
- values = self.option_values.joins(:option_type).order("#{Spree::OptionType.table_name}.position asc")
+ values = option_values.joins(:option_type).order("#{Spree::OptionType.table_name}.position asc")
- values.map!(&:presentation) # This line changed
+ values.map!(&:presentation) # This line changed
- values.to_sentence({ :words_connector => ", ", :two_words_connector => ", " })
+ values.to_sentence(words_connector: ", ", two_words_connector: ", ")
end
def product_and_full_name
@@ -39,34 +39,34 @@ module OpenFoodNetwork
end
def unit_to_display
- return options_text if !self.has_attribute?(:display_as) || display_as.blank?
+ return options_text if !has_attribute?(:display_as) || display_as.blank?
display_as
end
def update_units
delete_unit_option_values
- option_type = self.product.variant_unit_option_type
+ 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 || Spree::OptionValue.create!({option_type: option_type, name: name, presentation: name}, without_protection: true)
+ 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 }, without_protection: true)
option_values << ov
end
end
def delete_unit_option_values
- ovs = self.option_values.where(option_type_id: Spree::Product.all_variant_unit_option_types)
- self.option_values.destroy ovs
+ ovs = option_values.where(option_type_id: Spree::Product.all_variant_unit_option_types)
+ option_values.destroy ovs
end
def weight_from_unit_value
- (unit_value || 0) / 1000 if self.product.variant_unit == 'weight'
+ (unit_value || 0) / 1000 if product.variant_unit == 'weight'
end
private
def option_value_name
- if self.has_attribute?(:display_as) && display_as.present?
+ if has_attribute?(:display_as) && display_as.present?
display_as
else
option_value_namer = OpenFoodNetwork::OptionValueNamer.new self
diff --git a/lib/open_food_network/xero_invoices_report.rb b/lib/open_food_network/xero_invoices_report.rb
index b27291f535..02edcb28c0 100644
--- a/lib/open_food_network/xero_invoices_report.rb
+++ b/lib/open_food_network/xero_invoices_report.rb
@@ -4,11 +4,11 @@ module OpenFoodNetwork
@user = user
@opts = opts.
- reject { |k, v| v.blank? }.
- reverse_merge({report_type: 'summary',
+ reject { |_k, v| v.blank? }.
+ reverse_merge( report_type: 'summary',
invoice_date: Time.zone.today,
due_date: Time.zone.today + 1.month,
- account_code: 'food sales'})
+ account_code: 'food sales' )
@compile_table = compile_table
end
@@ -39,7 +39,6 @@ module OpenFoodNetwork
rows.compact
end
-
private
def detail_rows_for_order(order, invoice_number, opts)
@@ -88,7 +87,7 @@ module OpenFoodNetwork
def summary_rows_for_order(order, invoice_number, opts)
rows = []
- rows += produce_summary_rows(order, invoice_number, opts) unless detail?
+ rows += produce_summary_rows(order, invoice_number, opts) unless detail?
rows += fee_summary_rows(order, invoice_number, opts)
rows += shipping_summary_rows(order, invoice_number, opts)
rows += payment_summary_rows(order, invoice_number, opts)
@@ -120,11 +119,11 @@ module OpenFoodNetwork
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={})
+ def summary_row(order, description, amount, invoice_number, tax_type, opts = {})
row order, '', description, '1', amount, invoice_number, tax_type, opts
end
- def row(order, sku, description, quantity, amount, invoice_number, tax_type, opts={})
+ def row(order, sku, description, quantity, amount, invoice_number, tax_type, opts = {})
return nil if amount == 0
[order.bill_address.andand.full_name,
@@ -166,7 +165,7 @@ module OpenFoodNetwork
end
def invoice_number_for(order, i)
- @opts[:initial_invoice_number] ? @opts[:initial_invoice_number].to_i+i : order.number
+ @opts[:initial_invoice_number] ? @opts[:initial_invoice_number].to_i + i : order.number
end
def total_untaxable_products(order)
diff --git a/lib/spree/api/testing_support/helpers_decorator.rb b/lib/spree/api/testing_support/helpers_decorator.rb
index 6f74490301..eb8e1f107d 100644
--- a/lib/spree/api/testing_support/helpers_decorator.rb
+++ b/lib/spree/api/testing_support/helpers_decorator.rb
@@ -2,6 +2,6 @@ require 'spree/api/testing_support/helpers'
Spree::Api::TestingSupport::Helpers.class_eval do
def current_api_user
- @current_api_user ||= Spree::LegacyUser.new(:email => "spree@example.com", :enterprises => [])
+ @current_api_user ||= Spree::LegacyUser.new(email: "spree@example.com", enterprises: [])
end
end
diff --git a/lib/spree/api/testing_support/setup.rb b/lib/spree/api/testing_support/setup.rb
index 2ec1bcecef..f07b152999 100644
--- a/lib/spree/api/testing_support/setup.rb
+++ b/lib/spree/api/testing_support/setup.rb
@@ -4,7 +4,7 @@ module Spree
module Setup
def sign_in_as_user!
let!(:current_api_user) do
- user = Spree::LegacyUser.new(:email => "spree@example.com")
+ user = Spree::LegacyUser.new(email: "spree@example.com")
user.stub(:has_spree_role?).with("admin").and_return(false)
user.stub(:enterprises) { [] }
user.stub(:owned_groups) { [] }
@@ -31,7 +31,7 @@ module Spree
def sign_in_as_admin!
let!(:current_api_user) do
- user = Spree::LegacyUser.new(:email => "spree@example.com")
+ user = Spree::LegacyUser.new(email: "spree@example.com")
user.stub(:has_spree_role?).with("admin").and_return(true)
# Stub enterprises, needed for cancan ability checks
diff --git a/lib/spree/core/controller_helpers/order_decorator.rb b/lib/spree/core/controller_helpers/order_decorator.rb
index eb9ad451eb..cb644bb701 100644
--- a/lib/spree/core/controller_helpers/order_decorator.rb
+++ b/lib/spree/core/controller_helpers/order_decorator.rb
@@ -15,7 +15,6 @@ Spree::Core::ControllerHelpers::Order.class_eval do
end
alias_method_chain :current_order, :scoped_variants
-
# Override definition in spree/auth/app/controllers/spree/base_controller_decorator.rb
# Do not attempt to merge incomplete and current orders. Instead, destroy the incomplete orders.
def set_current_order
diff --git a/lib/spree/core/controller_helpers/respond_with_decorator.rb b/lib/spree/core/controller_helpers/respond_with_decorator.rb
index 4910591b9c..522247ea01 100644
--- a/lib/spree/core/controller_helpers/respond_with_decorator.rb
+++ b/lib/spree/core/controller_helpers/respond_with_decorator.rb
@@ -1,22 +1,24 @@
module ActionController
class Base
def respond_with(*resources, &block)
- raise "In order to use respond_with, first you need to declare the formats your " <<
- "controller responds to in the class level" if self.class.mimes_for_respond_to.empty?
+ if self.class.mimes_for_respond_to.empty?
+ raise "In order to use respond_with, first you need to declare the formats your " \
+ "controller responds to in the class level"
+ end
if collector = retrieve_collector_from_mimes(&block)
options = resources.size == 1 ? {} : resources.extract_options!
# Fix spree issues #3531 and #2210 (patch provided by leiyangyou)
- if defined_response = collector.response and !(Spree::BaseController.spree_responders[self.class.to_s.to_sym].try(:[], action_name.to_sym))
+ if (defined_response = collector.response) && !Spree::BaseController.spree_responders[self.class.to_s.to_sym].try(:[], action_name.to_sym)
if action = options.delete(:action)
- render :action => action
+ render action: action
else
defined_response.call
end
else
# The action name is needed for processing
- options.merge!(:action_name => action_name.to_sym)
+ options[:action_name] = action_name.to_sym
# If responder is not specified then pass in Spree::Responder
(options.delete(:responder) || Spree::Responder).call(self, resources, options)
end
diff --git a/lib/spree/money_decorator.rb b/lib/spree/money_decorator.rb
index 0194925d4e..10ecce8034 100644
--- a/lib/spree/money_decorator.rb
+++ b/lib/spree/money_decorator.rb
@@ -1,5 +1,4 @@
Spree::Money.class_eval do
-
# return the currency symbol (on its own) for the current default currency
def self.currency_symbol
Money.new(0, Spree::Config[:currency]).symbol
@@ -10,7 +9,7 @@ Spree::Money.class_eval do
to_s
end
- def to_html(options = { :html => true })
+ def to_html(options = { html: true })
output = @money.format(@options.merge(options))
if options[:html]
# 1) prevent blank, breaking spaces
@@ -20,7 +19,7 @@ Spree::Money.class_eval do
output
end
- def format(options={})
+ def format(options = {})
@money.format(@options.merge!(options))
end
end
diff --git a/lib/spree/product_filters.rb b/lib/spree/product_filters.rb
index 407d7e07f5..b0b9189663 100644
--- a/lib/spree/product_filters.rb
+++ b/lib/spree/product_filters.rb
@@ -2,19 +2,18 @@ module Spree
module ProductFilters
if Enterprise.table_exists?
Spree::Product.scope :distributor_any,
- lambda {|*opts|
- conds = opts.map {|o| ProductFilters.distributor_filter[:conds][o]}.reject {|c| c.nil?}
- Spree::Product.joins(:distributors).conditions_any(conds)
- }
+ lambda { |*opts|
+ conds = opts.map { |o| ProductFilters.distributor_filter[:conds][o] }.reject(&:nil?)
+ Spree::Product.joins(:distributors).conditions_any(conds)
+ }
def ProductFilters.distributor_filter
distributors = Enterprise.is_distributor.map(&:name).compact.uniq
- conds = Hash[*distributors.map { |d| [d, "#{Enterprise.table_name}.name = '#{d}'"] }.flatten]
- { :name => "Group",
- :scope => :distributor_any,
- :conds => conds,
- :labels => (distributors.sort).map { |k| [k, k] }
- }
+ conds = Hash[*distributors.map { |d| [d, "#{Enterprise.table_name}.name = '#{d}'"] }.flatten]
+ { name: "Group",
+ scope: :distributor_any,
+ conds: conds,
+ labels: distributors.sort.map { |k| [k, k] } }
end
end
end
diff --git a/lib/stripe/account_connector.rb b/lib/stripe/account_connector.rb
index 9d0c8d3ddb..0213479bcb 100644
--- a/lib/stripe/account_connector.rb
+++ b/lib/stripe/account_connector.rb
@@ -15,7 +15,7 @@ module Stripe
return false if connection_cancelled_by_user?
raise StripeError, params["error_description"] unless params["code"]
- raise CanCan::AccessDenied unless state.keys.include? "enterprise_id"
+ raise CanCan::AccessDenied unless state.key?("enterprise_id")
# Local authorisation issue, so request disconnection from Stripe
deauthorize unless user_has_permission_to_connect?
diff --git a/lib/stripe/webhook_handler.rb b/lib/stripe/webhook_handler.rb
index 231eb78b03..24121afe19 100644
--- a/lib/stripe/webhook_handler.rb
+++ b/lib/stripe/webhook_handler.rb
@@ -18,7 +18,7 @@ module Stripe
end
def known_event?
- event_mappings.keys.include? @event.type
+ event_mappings.key?(@event.type)
end
def deauthorize
diff --git a/lib/tasks/cache.rake b/lib/tasks/cache.rake
index a88e745153..535f19079b 100644
--- a/lib/tasks/cache.rake
+++ b/lib/tasks/cache.rake
@@ -3,15 +3,14 @@ require 'open_food_network/products_cache_integrity_checker'
namespace :ofn do
namespace :cache do
desc 'check the integrity of the products cache'
- task :check_products_integrity => :environment do
+ task check_products_integrity: :environment do
Exchange.cachable.each do |exchange|
Delayed::Job.enqueue ProductsCacheIntegrityCheckerJob.new(exchange.receiver_id, exchange.order_cycle_id), priority: 20
end
end
-
desc 'warm the products cache'
- task :warm_products => :environment do
+ task warm_products: :environment do
Exchange.cachable.each do |exchange|
Delayed::Job.enqueue RefreshProductsCacheJob.new(exchange.receiver_id, exchange.order_cycle_id), priority: 10
end
diff --git a/lib/tasks/data.rake b/lib/tasks/data.rake
index 9ae0984e3a..d8224d05eb 100644
--- a/lib/tasks/data.rake
+++ b/lib/tasks/data.rake
@@ -1,25 +1,24 @@
namespace :ofn do
namespace :data do
desc "Adding relationships based on recent order cycles"
- task :create_order_cycle_relationships => :environment do
+ task create_order_cycle_relationships: :environment do
input = request_months
# For each order cycle which was modified within the past 3 months
OrderCycle.where('updated_at > ?', Date.current - input.months).each do |order_cycle|
# Cycle through the incoming exchanges
order_cycle.exchanges.incoming.each do |exchange|
- unless 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
- unless relationship.present?
- puts "CREATING: #{exchange.sender.name} TO #{exchange.receiver.name}"
- 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)
- puts "PERMITTING: #{exchange.sender.name} TO #{exchange.receiver.name}"
- relationship.permissions.create!(name: :add_to_order_cycle)
- end
+ 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
+ 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)
+ end
+ # And that P-OC is granted
+ unless relationship.has_permission?(:add_to_order_cycle)
+ puts "PERMITTING: #{exchange.sender.name} TO #{exchange.receiver.name}"
+ relationship.permissions.create!(name: :add_to_order_cycle)
end
end
@@ -28,7 +27,7 @@ namespace :ofn do
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
- unless relationship.present?
+ 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)
end
@@ -43,18 +42,17 @@ namespace :ofn do
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).uniq
producers.each do |producer|
- unless 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
- unless relationship.present?
- puts "CREATING: #{producer.name} TO #{exchange.receiver.name}"
- 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)
- puts "PERMITTING: #{producer.name} TO #{exchange.receiver.name}"
- relationship.permissions.create!(name: :add_to_order_cycle)
- end
+ 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
+ if relationship.blank?
+ puts "CREATING: #{producer.name} TO #{exchange.receiver.name}"
+ 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)
+ puts "PERMITTING: #{producer.name} TO #{exchange.receiver.name}"
+ relationship.permissions.create!(name: :add_to_order_cycle)
end
end
end
@@ -84,7 +82,9 @@ namespace :ofn do
end
def is_integer?(value)
- return true if Integer(value) rescue false
+ return true if Integer(value)
+ rescue StandardError
+ false
end
end
end
diff --git a/lib/tasks/dev.rake b/lib/tasks/dev.rake
index aee1352874..4677a1786c 100644
--- a/lib/tasks/dev.rake
+++ b/lib/tasks/dev.rake
@@ -267,11 +267,11 @@ namespace :ofn do
enterprise2 = Enterprise.find_by_name('Enterprise 2')
enterprise2.sells = 'any'
enterprise2.shipping_methods << FactoryBot.create(:shipping_method,
- name: 'Pickup',
- zone: zone,
- require_ship_address: true,
- calculator_type: 'Calculator::Weight',
- distributors: [enterprise2])
+ name: 'Pickup',
+ zone: zone,
+ require_ship_address: true,
+ calculator_type: 'Calculator::Weight',
+ distributors: [enterprise2])
enterprise2.payment_methods << Spree::PaymentMethod.last
enterprise2.save!
diff --git a/lib/tasks/enterprises.rake b/lib/tasks/enterprises.rake
index 547e179c2a..caca6041a1 100644
--- a/lib/tasks/enterprises.rake
+++ b/lib/tasks/enterprises.rake
@@ -3,7 +3,7 @@ require 'csv'
namespace :ofn do
namespace :dev do
desc 'export enterprises to CSV'
- task :export_enterprises => :environment do
+ task export_enterprises: :environment do
CSV.open('db/enterprises.csv', 'wb') do |csv|
csv << enterprise_header
enterprises.each do |enterprise|
@@ -12,7 +12,6 @@ namespace :ofn do
end
end
-
private
def enterprises
diff --git a/lib/tasks/karma.rake b/lib/tasks/karma.rake
index 7cc245cfa4..4f57d21220 100644
--- a/lib/tasks/karma.rake
+++ b/lib/tasks/karma.rake
@@ -1,11 +1,11 @@
ENV["RAILS_ENV"] ||= 'test'
-namespace :karma do
- task :start => :environment do |_task|
+namespace :karma do
+ task start: :environment do |_task|
with_tmp_config :start
end
- task :run => :environment do |_task|
+ task run: :environment do |_task|
with_tmp_config :start, "--single-run"
end
@@ -23,7 +23,7 @@ namespace :karma do
def application_spec_files
sprockets = Rails.application.assets
sprockets.append_path Rails.root.join("spec/javascripts")
- Rails.application.assets.find_asset("application_spec.js").to_a.map {|e| e.pathname.to_s }
+ Rails.application.assets.find_asset("application_spec.js").to_a.map { |e| e.pathname.to_s }
end
def unit_js(files)
diff --git a/spec/controllers/admin/bulk_line_items_controller_spec.rb b/spec/controllers/admin/bulk_line_items_controller_spec.rb
index da67920e8e..e3d5536022 100644
--- a/spec/controllers/admin/bulk_line_items_controller_spec.rb
+++ b/spec/controllers/admin/bulk_line_items_controller_spec.rb
@@ -20,7 +20,7 @@ describe Admin::BulkLineItemsController, type: :controller do
before { allow(controller).to receive_messages spree_current_user: create_enterprise_user }
it "should deny me access to the index action" do
- spree_get :index, :format => :json
+ spree_get :index, format: :json
expect(response).to redirect_to spree.unauthorized_path
end
end
@@ -32,7 +32,7 @@ describe Admin::BulkLineItemsController, type: :controller do
context "when no ransack params are passed in" do
before do
- spree_get :index, :format => :json
+ spree_get :index, format: :json
end
it "retrieves a list of line_items with appropriate attributes, including line items with appropriate attributes" do
@@ -57,7 +57,7 @@ describe Admin::BulkLineItemsController, type: :controller do
context "when ransack params are passed in for line items" do
before do
- spree_get :index, :format => :json, q: { order_id_eq: order2.id }
+ spree_get :index, format: :json, q: { order_id_eq: order2.id }
end
it "retrives a list of line items which match the criteria" do
@@ -67,7 +67,7 @@ describe Admin::BulkLineItemsController, type: :controller do
context "when ransack params are passed in for orders" do
before do
- spree_get :index, :format => :json, q: { order: { completed_at_gt: 2.hours.ago } }
+ spree_get :index, format: :json, q: { order: { completed_at_gt: 2.hours.ago } }
end
it "retrives a list of line items whose orders match the criteria" do
@@ -91,7 +91,7 @@ describe Admin::BulkLineItemsController, type: :controller do
context "producer enterprise" do
before do
allow(controller).to receive_messages spree_current_user: supplier.owner
- spree_get :index, :format => :json
+ spree_get :index, format: :json
end
it "does not display line items for which my enterprise is a supplier" do
@@ -102,7 +102,7 @@ describe Admin::BulkLineItemsController, type: :controller do
context "coordinator enterprise" do
before do
allow(controller).to receive_messages spree_current_user: coordinator.owner
- spree_get :index, :format => :json
+ spree_get :index, format: :json
end
it "retrieves a list of line_items" do
@@ -114,7 +114,7 @@ describe Admin::BulkLineItemsController, type: :controller do
context "hub enterprise" do
before do
allow(controller).to receive_messages spree_current_user: distributor1.owner
- spree_get :index, :format => :json
+ spree_get :index, format: :json
end
it "retrieves a list of line_items" do
diff --git a/spec/controllers/admin/column_preferences_controller_spec.rb b/spec/controllers/admin/column_preferences_controller_spec.rb
index 0c1c33a9bd..acc3c194a5 100644
--- a/spec/controllers/admin/column_preferences_controller_spec.rb
+++ b/spec/controllers/admin/column_preferences_controller_spec.rb
@@ -3,7 +3,6 @@ require 'spec_helper'
describe Admin::ColumnPreferencesController, type: :controller do
include AuthenticationWorkflow
-
describe "bulk_update" do
let!(:user1) { create(:user) }
let!(:user2) { create(:user) }
@@ -12,11 +11,12 @@ describe Admin::ColumnPreferencesController, type: :controller do
context "json" do
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 }
- ]
+ 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 }
+ ]
}
context "where I don't own the preferences submitted" do
diff --git a/spec/controllers/admin/enterprises_controller_spec.rb b/spec/controllers/admin/enterprises_controller_spec.rb
index b244047eb4..21ce30942e 100644
--- a/spec/controllers/admin/enterprises_controller_spec.rb
+++ b/spec/controllers/admin/enterprises_controller_spec.rb
@@ -20,7 +20,7 @@ module Admin
describe "creating an enterprise" do
let(:country) { Spree::Country.find_by_name 'Australia' }
let(:state) { Spree::State.find_by_name 'Victoria' }
- let(:enterprise_params) { {enterprise: {name: 'zzz', permalink: 'zzz', is_primary_producer: '0', address_attributes: {address1: 'a', city: 'a', zipcode: 'a', country_id: country.id, state_id: state.id}}} }
+ let(:enterprise_params) { { enterprise: { name: 'zzz', permalink: 'zzz', is_primary_producer: '0', address_attributes: { address1: 'a', city: 'a', zipcode: 'a', country_id: country.id, state_id: state.id } } } }
it "grants management permission if the current user is an enterprise user" do
allow(controller).to receive_messages spree_current_user: distributor_manager
@@ -127,7 +127,7 @@ module Admin
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
@@ -144,14 +144,13 @@ module Admin
context "when a submitted property does not already exist" do
it "does not create a new property, or product property" do
- spree_put :update, {
- id: producer,
- enterprise: {
- producer_properties_attributes: {
- '0' => { property_name: 'a different name', value: 'something' }
- }
- }
- }
+ spree_put :update,
+ id: producer,
+ enterprise: {
+ producer_properties_attributes: {
+ '0' => { property_name: 'a different name', value: 'something' }
+ }
+ }
expect(Spree::Property.count).to be 1
expect(ProducerProperty.count).to be 0
property_names = producer.reload.properties.map(&:name)
@@ -161,14 +160,13 @@ module Admin
context "when a submitted property exists" do
it "adds a product property" do
- spree_put :update, {
- id: producer,
- enterprise: {
- producer_properties_attributes: {
- '0' => { property_name: 'A nice name', value: 'something' }
- }
- }
- }
+ spree_put :update,
+ id: producer,
+ enterprise: {
+ producer_properties_attributes: {
+ '0' => { property_name: 'A nice name', value: 'something' }
+ }
+ }
expect(Spree::Property.count).to be 1
expect(ProducerProperty.count).to be 1
property_names = producer.reload.properties.map(&:name)
@@ -187,40 +185,38 @@ module Admin
context "discount order rules" do
it "updates the existing rule with new attributes" do
- spree_put :update, {
- id: enterprise,
- enterprise: {
- tag_rules_attributes: {
- '0' => {
- id: tag_rule,
- type: "TagRule::DiscountOrder",
- preferred_customer_tags: "some,new,tags",
- calculator_type: "Spree::Calculator::FlatPercentItemTotal",
- calculator_attributes: { id: tag_rule.calculator.id, preferred_flat_percent: "15" }
- }
- }
- }
- }
+ spree_put :update,
+ id: enterprise,
+ enterprise: {
+ tag_rules_attributes: {
+ '0' => {
+ id: tag_rule,
+ type: "TagRule::DiscountOrder",
+ preferred_customer_tags: "some,new,tags",
+ calculator_type: "Spree::Calculator::FlatPercentItemTotal",
+ calculator_attributes: { id: tag_rule.calculator.id, preferred_flat_percent: "15" }
+ }
+ }
+ }
tag_rule.reload
expect(tag_rule.preferred_customer_tags).to eq "some,new,tags"
expect(tag_rule.calculator.preferred_flat_percent).to eq 15
end
it "creates new rules with new attributes" do
- spree_put :update, {
- id: enterprise,
- enterprise: {
- tag_rules_attributes: {
- '0' => {
- id: "",
- type: "TagRule::DiscountOrder",
- preferred_customer_tags: "tags,are,awesome",
- calculator_type: "Spree::Calculator::FlatPercentItemTotal",
- calculator_attributes: { id: "", preferred_flat_percent: "24" }
- }
- }
- }
- }
+ spree_put :update,
+ id: enterprise,
+ enterprise: {
+ tag_rules_attributes: {
+ '0' => {
+ id: "",
+ type: "TagRule::DiscountOrder",
+ preferred_customer_tags: "tags,are,awesome",
+ calculator_type: "Spree::Calculator::FlatPercentItemTotal",
+ calculator_attributes: { id: "", preferred_flat_percent: "24" }
+ }
+ }
+ }
expect(tag_rule.reload).to be
new_tag_rule = TagRule::DiscountOrder.last
expect(new_tag_rule.preferred_customer_tags).to eq "tags,are,awesome"
@@ -251,7 +247,7 @@ module Admin
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
@@ -269,7 +265,6 @@ module Admin
expect(profile_enterprise.sells).to eq 'any'
end
-
it "allows owner to be changed" do
allow(controller).to receive_messages spree_current_user: admin_user
update_params = { id: distributor, enterprise: { owner_id: distributor_manager } }
@@ -281,7 +276,7 @@ module Admin
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
@@ -299,7 +294,7 @@ module Admin
end
it "does not allow access" do
- spree_post :register, { id: enterprise.id, sells: 'none' }
+ spree_post :register, id: enterprise.id, sells: 'none'
expect(response).to redirect_to spree.unauthorized_path
end
end
@@ -311,7 +306,7 @@ module Admin
end
it "does not allow access" do
- spree_post :register, { id: enterprise.id, sells: 'none' }
+ spree_post :register, id: enterprise.id, sells: 'none'
expect(response).to redirect_to spree.unauthorized_path
end
end
@@ -323,7 +318,7 @@ module Admin
context "setting 'sells' to 'none'" do
it "is allowed" do
- spree_post :register, { id: enterprise, sells: 'none' }
+ spree_post :register, id: enterprise, sells: 'none'
expect(response).to redirect_to spree.admin_path
expect(flash[:success]).to eq "Congratulations! Registration for #{enterprise.name} is complete!"
expect(enterprise.reload.sells).to eq 'none'
@@ -332,7 +327,7 @@ module Admin
context "setting producer_profile_only" do
it "is ignored" do
- spree_post :register, { id: enterprise, sells: 'none', producer_profile_only: true }
+ spree_post :register, id: enterprise, sells: 'none', producer_profile_only: true
expect(response).to redirect_to spree.admin_path
expect(enterprise.reload.producer_profile_only).to be false
end
@@ -345,25 +340,25 @@ module Admin
end
it "is allowed" do
- spree_post :register, { id: enterprise, sells: 'own' }
+ spree_post :register, id: enterprise, sells: 'own'
expect(response).to redirect_to spree.admin_path
- expect(flash[:success]).to eq "Congratulations! Registration for #{enterprise.name} is complete!"
+ expect(flash[:success]).to eq "Congratulations! Registration for #{enterprise.name} is complete!"
expect(enterprise.reload.sells).to eq 'own'
end
end
context "setting 'sells' to any" do
it "is allowed" do
- spree_post :register, { id: enterprise, sells: 'any' }
+ spree_post :register, id: enterprise, sells: 'any'
expect(response).to redirect_to spree.admin_path
- expect(flash[:success]).to eq "Congratulations! Registration for #{enterprise.name} is complete!"
+ expect(flash[:success]).to eq "Congratulations! Registration for #{enterprise.name} is complete!"
expect(enterprise.reload.sells).to eq 'any'
end
end
context "settiing 'sells' to 'unspecified'" do
it "is not allowed" do
- spree_post :register, { id: enterprise, sells: 'unspecified' }
+ spree_post :register, id: enterprise, sells: 'unspecified'
expect(response).to render_template :welcome
expect(flash[:error]).to eq "Please select a package"
end
@@ -506,7 +501,7 @@ module Admin
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
spree_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 4828f5c662..741f329663 100644
--- a/spec/controllers/admin/inventory_items_controller_spec.rb
+++ b/spec/controllers/admin/inventory_items_controller_spec.rb
@@ -44,7 +44,7 @@ describe Admin::InventoryItemsController, type: :controller do
context "with acceptable data" do
it "allows me to create the inventory item" do
- expect{ spree_post :create, params }.to change{InventoryItem.count}.by(1)
+ expect{ spree_post :create, params }.to change{ InventoryItem.count }.by(1)
inventory_item = InventoryItem.last
expect(inventory_item.enterprise).to eq enterprise
expect(inventory_item.variant).to eq variant
@@ -57,7 +57,7 @@ describe Admin::InventoryItemsController, type: :controller do
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)
+ expect{ spree_post :create, bad_params }.to change{ InventoryItem.count }.by(0)
expect(response.body).to eq Hash[:errors, ["Visible must be true or false"]].to_json
end
end
@@ -118,7 +118,7 @@ describe Admin::InventoryItemsController, type: :controller do
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)
+ expect{ spree_put :update, bad_params }.to change{ InventoryItem.count }.by(0)
expect(response.body).to eq Hash[:errors, ["Visible must be true or false"]].to_json
end
end
diff --git a/spec/controllers/admin/manager_invitations_controller_spec.rb b/spec/controllers/admin/manager_invitations_controller_spec.rb
index e8e4d733cf..7d03361daa 100644
--- a/spec/controllers/admin/manager_invitations_controller_spec.rb
+++ b/spec/controllers/admin/manager_invitations_controller_spec.rb
@@ -18,7 +18,7 @@ module Admin
end
it "returns an error" do
- spree_post :create, {email: existing_user.email, enterprise_id: enterprise.id}
+ spree_post :create, email: existing_user.email, enterprise_id: enterprise.id
expect(response.status).to eq 422
expect(json_response['errors']).to eq I18n.t('admin.enterprises.invite_manager.user_already_exists')
@@ -39,11 +39,11 @@ module Admin
expect(Delayed::Job).to receive(:enqueue).with(manager_invitation)
- spree_post :create, { email: 'un.registered@email.com', enterprise_id: enterprise.id }
+ spree_post :create, email: 'un.registered@email.com', enterprise_id: enterprise.id
end
it "returns the user id" do
- spree_post :create, { email: 'un.registered@email.com', enterprise_id: enterprise.id }
+ spree_post :create, email: 'un.registered@email.com', enterprise_id: enterprise.id
new_user = Spree::User.find_by_email('un.registered@email.com')
expect(json_response['user']).to eq new_user.id
@@ -59,7 +59,7 @@ module Admin
end
it "returns success code" do
- spree_post :create, {email: 'an@email.com', enterprise_id: enterprise.id}
+ spree_post :create, email: 'an@email.com', enterprise_id: enterprise.id
new_user = Spree::User.find_by_email('an@email.com')
@@ -75,7 +75,7 @@ module Admin
end
it "returns unauthorized response" do
- spree_post :create, {email: 'another@email.com', enterprise_id: enterprise.id}
+ spree_post :create, email: 'another@email.com', enterprise_id: enterprise.id
new_user = Spree::User.find_by_email('another@email.com')
diff --git a/spec/controllers/admin/order_cycles_controller_spec.rb b/spec/controllers/admin/order_cycles_controller_spec.rb
index aaa2356bb3..4df355f595 100644
--- a/spec/controllers/admin/order_cycles_controller_spec.rb
+++ b/spec/controllers/admin/order_cycles_controller_spec.rb
@@ -277,7 +277,6 @@ module Admin
end
end
-
describe "notifying producers" do
let(:user) { create_enterprise_user }
let(:admin_user) do
@@ -293,18 +292,17 @@ module Admin
it "enqueues a job" do
expect do
- spree_post :notify_producers, {id: order_cycle.id}
+ spree_post :notify_producers, id: order_cycle.id
end.to enqueue_job OrderCycleNotificationJob
end
it "redirects back to the order cycles path with a success message" do
- spree_post :notify_producers, {id: order_cycle.id}
+ spree_post :notify_producers, id: order_cycle.id
expect(response).to redirect_to admin_order_cycles_path
expect(flash[:notice]).to eq('Emails to be sent to producers have been queued for sending.')
end
end
-
describe "destroy" do
let(:distributor) { create(:distributor_enterprise, owner: distributor_owner) }
let(:oc) { create(:simple_order_cycle, coordinator: distributor) }
@@ -336,6 +334,5 @@ module Admin
end
end
end
-
end
end
diff --git a/spec/controllers/admin/stripe_connect_settings_controller_spec.rb b/spec/controllers/admin/stripe_connect_settings_controller_spec.rb
index 267e583586..11cebea66e 100644
--- a/spec/controllers/admin/stripe_connect_settings_controller_spec.rb
+++ b/spec/controllers/admin/stripe_connect_settings_controller_spec.rb
@@ -41,7 +41,7 @@ describe Admin::StripeConnectSettingsController, type: :controller do
context "and the request to retrieve Stripe account info fails" do
before do
stub_request(:get, "https://api.stripe.com/v1/account").
- to_return(:status => 401, :body => "{\"error\": {\"message\": \"Invalid API Key provided: sk_test_****xxxx\"}}")
+ to_return(status: 401, body: "{\"error\": {\"message\": \"Invalid API Key provided: sk_test_****xxxx\"}}")
end
it "sets the account status to :auth_fail_error" do
@@ -54,7 +54,7 @@ describe Admin::StripeConnectSettingsController, type: :controller do
context "and the request to retrieve Stripe account info succeeds" do
before do
stub_request(:get, "https://api.stripe.com/v1/account").
- to_return(:status => 200, :body => "{ \"id\": \"acct_1234\", \"business_name\": \"OFN\" }")
+ to_return(status: 200, body: "{ \"id\": \"acct_1234\", \"business_name\": \"OFN\" }")
end
it "sets the account status to :ok, loads settings into Struct" do
diff --git a/spec/controllers/admin/subscription_line_items_controller_spec.rb b/spec/controllers/admin/subscription_line_items_controller_spec.rb
index 2b42a20df7..d60c581ab5 100644
--- a/spec/controllers/admin/subscription_line_items_controller_spec.rb
+++ b/spec/controllers/admin/subscription_line_items_controller_spec.rb
@@ -3,7 +3,6 @@ require 'spec_helper'
describe Admin::SubscriptionLineItemsController, type: :controller do
include AuthenticationWorkflow
-
describe "build" do
let(:user) { create(:user) }
let!(:shop) { create(:enterprise, owner: user) }
@@ -42,7 +41,7 @@ describe Admin::SubscriptionLineItemsController, type: :controller do
before { params.merge!(shop_id: shop.id) }
context "but the shop doesn't have permission to sell product in question" do
- let!(:outgoing_exchange) { }
+ let!(:outgoing_exchange) {}
it "returns an error" do
spree_post :build, params
diff --git a/spec/controllers/admin/subscriptions_controller_spec.rb b/spec/controllers/admin/subscriptions_controller_spec.rb
index 6d570bce86..cf4af7c921 100644
--- a/spec/controllers/admin/subscriptions_controller_spec.rb
+++ b/spec/controllers/admin/subscriptions_controller_spec.rb
@@ -179,7 +179,7 @@ describe Admin::SubscriptionsController, type: :controller do
params.merge!(
bill_address: address.attributes.except('id'),
ship_address: address.attributes.except('id'),
- subscription_line_items: [{ quantity: 2, variant_id: variant.id}]
+ subscription_line_items: [{ quantity: 2, variant_id: variant.id }]
)
end
@@ -345,7 +345,7 @@ describe Admin::SubscriptionsController, type: :controller do
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
diff --git a/spec/controllers/admin/tag_rules_controller_spec.rb b/spec/controllers/admin/tag_rules_controller_spec.rb
index fa95650479..b4da011923 100644
--- a/spec/controllers/admin/tag_rules_controller_spec.rb
+++ b/spec/controllers/admin/tag_rules_controller_spec.rb
@@ -1,7 +1,6 @@
require 'spec_helper'
describe Admin::TagRulesController, type: :controller do
-
describe "destroy" do
context "json" do
let(:format) { :json }
@@ -29,7 +28,7 @@ describe Admin::TagRulesController, type: :controller do
allow(controller).to receive(:spree_current_user) { enterprise.owner }
end
- it { expect{ spree_delete :destroy, params }.to change{TagRule.count}.by(-1) }
+ it { expect{ spree_delete :destroy, params }.to change{ TagRule.count }.by(-1) }
end
end
end
diff --git a/spec/controllers/admin/variant_overrides_controller_spec.rb b/spec/controllers/admin/variant_overrides_controller_spec.rb
index 77fb5de915..0d721e7d9a 100644
--- a/spec/controllers/admin/variant_overrides_controller_spec.rb
+++ b/spec/controllers/admin/variant_overrides_controller_spec.rb
@@ -11,7 +11,7 @@ describe Admin::VariantOverridesController, type: :controller do
let(:variant) { create(:variant) }
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 +47,7 @@ describe Admin::VariantOverridesController, type: :controller do
spree_put :bulk_update, format: format, variant_overrides: variant_override_params
expect(assigns[:hubs]).to eq [hub]
expect(assigns[:producers]).to eq [variant.product.supplier]
- expect(assigns[:hub_permissions]).to eq Hash[hub.id,[variant.product.supplier.id]]
+ expect(assigns[:hub_permissions]).to eq Hash[hub.id, [variant.product.supplier.id]]
expect(assigns[:inventory_items]).to eq [inventory_item]
end
@@ -61,7 +61,7 @@ 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
spree_put :bulk_update, format: format, variant_overrides: variant_override_params
@@ -134,7 +134,7 @@ describe Admin::VariantOverridesController, type: :controller do
spree_put :bulk_reset, params
expect(assigns[:hubs]).to eq [hub]
expect(assigns[:producers]).to eq [producer]
- expect(assigns[:hub_permissions]).to eq Hash[hub.id,[producer.id]]
+ expect(assigns[:hub_permissions]).to eq Hash[hub.id, [producer.id]]
expect(assigns[:inventory_items]).to eq []
end
@@ -157,7 +157,7 @@ describe Admin::VariantOverridesController, type: :controller do
it "does not reset count_on_hand for variant_overrides not in params" do
expect {
spree_put :bulk_reset, params
- }.to_not change{variant_override3.reload.count_on_hand}
+ }.to_not change{ variant_override3.reload.count_on_hand }
end
end
end
diff --git a/spec/controllers/api/order_cycles_controller_spec.rb b/spec/controllers/api/order_cycles_controller_spec.rb
index f24170de10..64f813f5a4 100644
--- a/spec/controllers/api/order_cycles_controller_spec.rb
+++ b/spec/controllers/api/order_cycles_controller_spec.rb
@@ -21,7 +21,7 @@ module Api
sign_in_as_user!
it "should deny me access to managed order cycles" do
- spree_get :managed, { :format => :json }
+ spree_get :managed, format: :json
assert_unauthorized!
end
end
@@ -30,8 +30,8 @@ module Api
sign_in_as_enterprise_user! [:coordinator]
it "retrieves a list of variants with appropriate attributes" do
- get :managed, { :format => :json }
- keys = json_response.first.keys.map{ |key| key.to_sym }
+ get :managed, format: :json
+ keys = json_response.first.keys.map(&:to_sym)
expect(attributes.all?{ |attr| keys.include? attr }).to eq(true)
end
end
@@ -40,8 +40,8 @@ module Api
sign_in_as_admin!
it "retrieves a list of variants with appropriate attributes" do
- get :managed, { :format => :json }
- keys = json_response.first.keys.map{ |key| key.to_sym }
+ get :managed, format: :json
+ keys = json_response.first.keys.map(&:to_sym)
expect(attributes.all?{ |attr| keys.include? attr }).to eq(true)
end
end
@@ -81,7 +81,7 @@ module Api
end
it "gives me access" do
- spree_get :accessible, { :template => 'bulk_index', :format => :json }
+ spree_get :accessible, template: 'bulk_index', format: :json
expect(json_response.length).to eq(1)
expect(json_response[0]['id']).to eq(order_cycle.id)
@@ -94,7 +94,7 @@ module Api
end
it "does not give me access" do
- spree_get :accessible, { :template => 'bulk_index', :format => :json }
+ spree_get :accessible, template: 'bulk_index', format: :json
expect(json_response.length).to eq(0)
end
end
@@ -105,7 +105,7 @@ module Api
end
it "gives me access" do
- spree_get :accessible, { :template => 'bulk_index', :format => :json }
+ spree_get :accessible, template: 'bulk_index', format: :json
expect(json_response.length).to eq(1)
expect(json_response[0]['id']).to eq(order_cycle.id)
diff --git a/spec/controllers/api/orders_controller_spec.rb b/spec/controllers/api/orders_controller_spec.rb
index 9101437308..9c11b8bd0b 100644
--- a/spec/controllers/api/orders_controller_spec.rb
+++ b/spec/controllers/api/orders_controller_spec.rb
@@ -32,19 +32,19 @@ module Api
let!(:order5) { create(:order, state: 'cart', completed_at: nil) }
let!(:line_item1) do
create(:line_item_with_shipment, order: order1,
- product: create(:product, supplier: supplier))
+ product: create(:product, supplier: supplier))
end
let!(:line_item2) do
create(:line_item_with_shipment, order: order2,
- product: create(:product, supplier: supplier))
+ product: create(:product, supplier: supplier))
end
let!(:line_item3) do
create(:line_item_with_shipment, order: order2,
- product: create(:product, supplier: supplier))
+ product: create(:product, supplier: supplier))
end
let!(:line_item4) do
create(:line_item_with_shipment, order: order3,
- product: create(:product, supplier: supplier))
+ product: create(:product, supplier: supplier))
end
let!(:regular_user) { create(:user) }
let!(:admin_user) { create(:admin_user) }
diff --git a/spec/controllers/api/statuses_controller_spec.rb b/spec/controllers/api/statuses_controller_spec.rb
index 48d30d6db7..b0082ca696 100644
--- a/spec/controllers/api/statuses_controller_spec.rb
+++ b/spec/controllers/api/statuses_controller_spec.rb
@@ -9,21 +9,21 @@ module Api
Spree::Config.last_job_queue_heartbeat_at = Time.now
spree_get :job_queue
expect(response).to be_success
- expect(response.body).to eq({alive: true}.to_json)
+ expect(response.body).to eq({ alive: true }.to_json)
end
it "returns dead otherwise" do
Spree::Config.last_job_queue_heartbeat_at = 10.minutes.ago
spree_get :job_queue
expect(response).to be_success
- expect(response.body).to eq({alive: false}.to_json)
+ expect(response.body).to eq({ alive: false }.to_json)
end
it "returns dead when no heartbeat recorded" do
Spree::Config.last_job_queue_heartbeat_at = nil
spree_get :job_queue
expect(response).to be_success
- expect(response.body).to eq({alive: false}.to_json)
+ expect(response.body).to eq({ alive: false }.to_json)
end
end
end
diff --git a/spec/controllers/base_controller_spec.rb b/spec/controllers/base_controller_spec.rb
index 6da68b59e1..43feeaf6c3 100644
--- a/spec/controllers/base_controller_spec.rb
+++ b/spec/controllers/base_controller_spec.rb
@@ -1,6 +1,6 @@
require 'spec_helper'
-describe BaseController, :type => :controller do
+describe BaseController, type: :controller do
let(:oc) { instance_double(OrderCycle, id: 1) }
let(:order) { instance_double(Spree::Order) }
controller(BaseController) do
diff --git a/spec/controllers/checkout_controller_spec.rb b/spec/controllers/checkout_controller_spec.rb
index 09fce7e779..e7bd7cee2b 100644
--- a/spec/controllers/checkout_controller_spec.rb
+++ b/spec/controllers/checkout_controller_spec.rb
@@ -44,7 +44,7 @@ describe CheckoutController, type: :controller do
allow(order).to receive(:distributor).and_return(distributor)
order.order_cycle = order_cycle
- allow(OrderCycleDistributedVariants).to receive(:new).with(order_cycle, distributor).and_return(order_cycle_distributed_variants)
+ allow(OrderCycleDistributedVariants).to receive(:new).with(order_cycle, distributor).and_return(order_cycle_distributed_variants)
end
it "redirects when some items are out of stock" do
@@ -124,17 +124,17 @@ describe CheckoutController, type: :controller do
it "does not fail to update" do
expect(controller).to_not receive(:clear_ship_address)
- spree_post :update, order: {shipping_method_id: test_shipping_method_id}
+ spree_post :update, order: { shipping_method_id: test_shipping_method_id }
end
it "does not send shipping_method_id to the order model as an attribute" do
expect(order).to receive(:update_attributes).with({})
- spree_post :update, order: {shipping_method_id: test_shipping_method_id}
+ spree_post :update, order: { shipping_method_id: test_shipping_method_id }
end
it "selects the shipping_method in the order" do
expect(order).to receive(:select_shipping_method).with(test_shipping_method_id)
- spree_post :update, order: {shipping_method_id: test_shipping_method_id}
+ spree_post :update, order: { shipping_method_id: test_shipping_method_id }
end
end
@@ -188,14 +188,14 @@ describe CheckoutController, type: :controller do
it "returns errors" do
spree_post :update, format: :json, order: {}
expect(response.status).to eq(400)
- expect(response.body).to eq({errors: assigns[:order].errors, flash: {}}.to_json)
+ expect(response.body).to eq({ errors: assigns[:order].errors, flash: {} }.to_json)
end
it "returns flash" do
allow(order).to receive(:update_attributes).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
@@ -207,7 +207,7 @@ describe CheckoutController, type: :controller do
spree_post :update, format: :json, order: {}
expect(response.status).to eq(200)
- expect(response.body).to eq({path: spree.order_path(order)}.to_json)
+ expect(response.body).to eq({ path: spree.order_path(order) }.to_json)
end
describe "stale object handling" do
@@ -256,7 +256,7 @@ describe CheckoutController, type: :controller do
expect(Spree::PaymentMethod).to receive(:find).with(payment_method.id.to_s) { payment_method }
allow(order).to receive(:update_attributes) { true }
allow(order).to receive(:state) { "payment" }
- spree_post :update, order: {payments_attributes: [{payment_method_id: payment_method.id}]}
+ spree_post :update, order: { payments_attributes: [{ payment_method_id: payment_method.id }] }
end
end
diff --git a/spec/controllers/enterprises_controller_spec.rb b/spec/controllers/enterprises_controller_spec.rb
index e2140db927..16db10ebfb 100644
--- a/spec/controllers/enterprises_controller_spec.rb
+++ b/spec/controllers/enterprises_controller_spec.rb
@@ -4,7 +4,6 @@ describe EnterprisesController, type: :controller do
describe "shopping for a distributor" do
let(:order) { controller.current_order(true) }
-
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 ) }
@@ -15,7 +14,7 @@ describe EnterprisesController, type: :controller do
end
it "sets the shop as the distributor on the order when shopping for the distributor" do
- spree_get :shop, {id: distributor}
+ spree_get :shop, id: distributor
expect(controller.current_order.distributor).to eq(distributor)
expect(controller.current_order.order_cycle).to be_nil
@@ -23,11 +22,11 @@ describe EnterprisesController, type: :controller do
it "sorts order cycles by the distributor's preferred ordering attr" do
distributor.update_attribute(:preferred_shopfront_order_cycle_order, 'orders_close_at')
- spree_get :shop, {id: distributor}
+ spree_get :shop, id: distributor
expect(assigns(:order_cycles)).to eq([order_cycle1, order_cycle2].sort_by(&:orders_close_at))
distributor.update_attribute(:preferred_shopfront_order_cycle_order, 'orders_open_at')
- spree_get :shop, {id: distributor}
+ spree_get :shop, id: distributor
expect(assigns(:order_cycles)).to eq([order_cycle1, order_cycle2].sort_by(&:orders_open_at))
end
@@ -39,33 +38,33 @@ describe EnterprisesController, type: :controller do
it "shows order cycles allowed by the rules" do
create(:filter_order_cycles_tag_rule,
- enterprise: distributor,
- preferred_customer_tags: "wholesale",
- preferred_exchange_tags: "wholesale",
- preferred_matched_order_cycles_visibility: 'visible')
+ enterprise: distributor,
+ preferred_customer_tags: "wholesale",
+ preferred_exchange_tags: "wholesale",
+ preferred_matched_order_cycles_visibility: 'visible')
create(:filter_order_cycles_tag_rule,
- enterprise: distributor,
- is_default: true,
- preferred_exchange_tags: "wholesale",
- preferred_matched_order_cycles_visibility: 'hidden')
+ enterprise: distributor,
+ is_default: true,
+ preferred_exchange_tags: "wholesale",
+ preferred_matched_order_cycles_visibility: 'hidden')
- spree_get :shop, {id: distributor}
+ spree_get :shop, id: distributor
expect(assigns(:order_cycles)).to include order_cycle1, order_cycle2, order_cycle3
allow(controller).to receive(:spree_current_user) { user }
- spree_get :shop, {id: distributor}
+ spree_get :shop, id: distributor
expect(assigns(:order_cycles)).to include order_cycle1, order_cycle2, order_cycle3
oc3_exchange.update_attribute(:tag_list, "wholesale")
- spree_get :shop, {id: distributor}
+ spree_get :shop, id: distributor
expect(assigns(:order_cycles)).to include order_cycle1, order_cycle2
expect(assigns(:order_cycles)).not_to include order_cycle3
customer.update_attribute(:tag_list, ["wholesale"])
- spree_get :shop, {id: distributor}
+ spree_get :shop, id: distributor
expect(assigns(:order_cycles)).to include order_cycle1, order_cycle2, order_cycle3
end
end
@@ -74,7 +73,7 @@ describe EnterprisesController, type: :controller do
line_item = create(:line_item)
controller.current_order.line_items << line_item
- spree_get :shop, {id: distributor}
+ spree_get :shop, id: distributor
expect(controller.current_order.distributor).to eq(distributor)
expect(controller.current_order.order_cycle).to be_nil
@@ -87,7 +86,7 @@ describe EnterprisesController, type: :controller do
line_item = create(:line_item, variant: product.variants.first)
controller.current_order.line_items << line_item
- spree_get :shop, {id: current_distributor}
+ spree_get :shop, id: current_distributor
expect(controller.current_order.distributor).to eq current_distributor
expect(controller.current_order.line_items.first.variant).to eq product.variants.first
@@ -107,7 +106,7 @@ describe EnterprisesController, type: :controller do
end
it "redirects to the cart" do
- spree_get :shop, {id: current_distributor}
+ spree_get :shop, id: current_distributor
expect(response).to redirect_to spree.cart_path
end
@@ -116,7 +115,7 @@ describe EnterprisesController, type: :controller do
it "sets order cycle if only one is available at the chosen distributor" do
order_cycle2.destroy
- spree_get :shop, {id: distributor}
+ spree_get :shop, id: distributor
expect(controller.current_order.distributor).to eq(distributor)
expect(controller.current_order.order_cycle).to eq(order_cycle1)
@@ -127,16 +126,16 @@ describe EnterprisesController, type: :controller do
# let(:enterprise) { create(:enterprise, permalink: 'enterprise_permalink') }
it "responds with status of 200 when the route does not exist" do
- spree_get :check_permalink, { permalink: 'some_nonexistent_route', format: :js }
+ spree_get :check_permalink, permalink: 'some_nonexistent_route', format: :js
expect(response.status).to be 200
end
it "responds with status of 409 when the permalink matches an existing route" do
# spree_get :check_permalink, { permalink: 'enterprise_permalink', format: :js }
# expect(response.status).to be 409
- spree_get :check_permalink, { permalink: 'map', format: :js }
+ spree_get :check_permalink, permalink: 'map', format: :js
expect(response.status).to be 409
- spree_get :check_permalink, { permalink: '', format: :js }
+ spree_get :check_permalink, permalink: '', format: :js
expect(response.status).to be 409
end
end
diff --git a/spec/controllers/line_items_controller_spec.rb b/spec/controllers/line_items_controller_spec.rb
index a7c9fc5225..2a4dbd8835 100644
--- a/spec/controllers/line_items_controller_spec.rb
+++ b/spec/controllers/line_items_controller_spec.rb
@@ -19,7 +19,7 @@ describe LineItemsController, type: :controller do
end
it "lists items bought by the user from the same shop in the same order_cycle" do
- get :bought, { format: :json }
+ get :bought, format: :json
expect(response.status).to eq 200
json_response = JSON.parse(response.body)
expect(json_response.length).to eq completed_order.line_items(:reload).count
diff --git a/spec/controllers/shop_controller_spec.rb b/spec/controllers/shop_controller_spec.rb
index a0a9587447..64b4e9281b 100644
--- a/spec/controllers/shop_controller_spec.rb
+++ b/spec/controllers/shop_controller_spec.rb
@@ -83,7 +83,6 @@ describe ShopController, type: :controller do
end
end
-
describe "returning products" do
let(:order_cycle) { create(:simple_order_cycle, distributors: [distributor]) }
let(:exchange) { order_cycle.exchanges.to_enterprises(distributor).outgoing.first }
@@ -125,7 +124,7 @@ describe ShopController, type: :controller do
it "does not attempt to apply any rules" do
controller.send(:filtered_json, products_json)
- expect(expect(controller).to_not have_received(:filter))
+ expect(expect(controller).to_not(have_received(:filter)))
end
it "returns products as JSON" do
@@ -154,20 +153,22 @@ describe ShopController, type: :controller do
context "when FilterProducts tag rules are in effect" do
let(:customer) { create(:customer, user: user, enterprise: distributor) }
- let!(:tag_rule) { create(:filter_products_tag_rule,
- enterprise: distributor,
- preferred_customer_tags: "member",
- preferred_variant_tags: "members-only")
+ let!(:tag_rule) {
+ create(:filter_products_tag_rule,
+ enterprise: distributor,
+ preferred_customer_tags: "member",
+ preferred_variant_tags: "members-only")
}
- let!(:default_tag_rule) { create(:filter_products_tag_rule,
- enterprise: distributor,
- is_default: true,
- preferred_variant_tags: "members-only")
+ let!(:default_tag_rule) {
+ create(:filter_products_tag_rule,
+ enterprise: distributor,
+ is_default: true,
+ preferred_variant_tags: "members-only")
}
let(:product1) { { "id" => 1, "name" => 'product 1', "variants" => [{ "id" => 4, "tag_list" => ["members-only"] }] } }
- let(:product2) { { "id" => 2, "name" => 'product 2', "variants" => [{ "id" => 5, "tag_list" => ["members-only"] }, {"id" => 9, "tag_list" => ["something"]}] } }
+ let(:product2) { { "id" => 2, "name" => 'product 2', "variants" => [{ "id" => 5, "tag_list" => ["members-only"] }, { "id" => 9, "tag_list" => ["something"] }] } }
let(:product3) { { "id" => 3, "name" => 'product 3', "variants" => [{ "id" => 6, "tag_list" => ["something-else"] }] } }
- let(:product2_without_v5) { { "id" => 2, "name" => 'product 2', "variants" => [{"id" => 9, "tag_list" => ["something"]}] } }
+ let(:product2_without_v5) { { "id" => 2, "name" => 'product 2', "variants" => [{ "id" => 9, "tag_list" => ["something"] }] } }
let!(:products_array) { [product1, product2, product3] }
let!(:products_json) { JSON.unparse( products_array ) }
diff --git a/spec/controllers/spree/admin/adjustments_controller_spec.rb b/spec/controllers/spree/admin/adjustments_controller_spec.rb
index c161fcd5ed..fc60008c00 100644
--- a/spec/controllers/spree/admin/adjustments_controller_spec.rb
+++ b/spec/controllers/spree/admin/adjustments_controller_spec.rb
@@ -12,7 +12,7 @@ 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
@@ -22,7 +22,7 @@ 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
@@ -36,7 +36,7 @@ module Spree
let(:adjustment) { create(:adjustment, adjustable: order, amount: 1100, included_tax: 100) }
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
@@ -46,7 +46,7 @@ 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
diff --git a/spec/controllers/spree/admin/base_controller_spec.rb b/spec/controllers/spree/admin/base_controller_spec.rb
index e9e2edb6ec..fa6899781d 100644
--- a/spec/controllers/spree/admin/base_controller_spec.rb
+++ b/spec/controllers/spree/admin/base_controller_spec.rb
@@ -19,10 +19,10 @@ describe Spree::Admin::BaseController, type: :controller do
expect(controller.
send(:active_distributors_not_ready_for_checkout_message, [distributor])).
to eq(
- "The hub My Hub is listed in an active order cycle, " +
- "but does not have valid shipping and payment methods. " +
- "Until you set these up, customers will not be able to shop at this hub."
- )
+ "The hub My Hub is listed in an active order cycle, " \
+ "but does not have valid shipping and payment methods. " \
+ "Until you set these up, customers will not be able to shop at this hub."
+ )
end
it "generates an error message when there are several distributors" do
@@ -31,10 +31,10 @@ describe Spree::Admin::BaseController, type: :controller do
expect(controller.
send(:active_distributors_not_ready_for_checkout_message, [d1, d2])).
to eq(
- "The hubs Hub One, Hub Two are listed in an active order cycle, " +
- "but do not have valid shipping and payment methods. " +
- "Until you set these up, customers will not be able to shop at these hubs."
- )
+ "The hubs Hub One, Hub Two are listed in an active order cycle, " \
+ "but do not have valid shipping and payment methods. " \
+ "Until you set these up, customers will not be able to shop at these hubs."
+ )
end
end
@@ -47,7 +47,7 @@ describe Spree::Admin::BaseController, type: :controller do
it "passes a prefix to the serializer method and renders with serializer" do
expect(controller).to receive(:serializer).with(prefix) { "SerializerClass" }
- expect(controller).to receive(:render).with({ json: data, serializer: "SerializerClass" })
+ expect(controller).to receive(:render).with(json: data, serializer: "SerializerClass")
controller.send(:render_as_json, data, ams_prefix: prefix)
end
end
@@ -57,7 +57,7 @@ describe Spree::Admin::BaseController, type: :controller do
it "does not pass a prefix to the serializer method and renders with serializer" do
expect(controller).to receive(:serializer).with(prefix) { "SerializerClass" }
- expect(controller).to receive(:render).with({ json: data, serializer: "SerializerClass" })
+ expect(controller).to receive(:render).with(json: data, serializer: "SerializerClass")
controller.send(:render_as_json, data, ams_prefix: prefix)
end
end
@@ -71,7 +71,7 @@ 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
@@ -81,7 +81,7 @@ 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
@@ -90,8 +90,8 @@ 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;
+ class Api::Admin::AllowedPrefixBaseSerializer; end;
+ class Api::Admin::BaseSerializer; end;
allow(controller).to receive(:ams_prefix_whitelist) { [:allowed_prefix] }
end
@@ -104,7 +104,7 @@ describe Spree::Admin::BaseController, type: :controller do
context "and the prefix does not appear in the whitelist" do
it "raises an error" do
- expect{controller.send(:serializer, 'other_prefix')}.to raise_error RuntimeError
+ expect{ controller.send(:serializer, 'other_prefix') }.to raise_error RuntimeError
end
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 14176aa0e7..c62d0a0f9c 100644
--- a/spec/controllers/spree/admin/orders/customer_details_controller_spec.rb
+++ b/spec/controllers/spree/admin/orders/customer_details_controller_spec.rb
@@ -11,15 +11,15 @@ describe Spree::Admin::Orders::CustomerDetailsController, type: :controller do
let!(:shipment) { create(:shipment) }
let!(:order) {
create(
- :order_with_totals_and_distribution,
- state: 'cart',
- shipments: [shipment],
- payments: [create(:payment)],
- distributor: distributor,
- user: nil,
- email: nil,
- bill_address: nil,
- ship_address: nil,
+ :order_with_totals_and_distribution,
+ state: 'cart',
+ shipments: [shipment],
+ payments: [create(:payment)],
+ distributor: distributor,
+ user: nil,
+ email: nil,
+ bill_address: nil,
+ ship_address: nil,
)
}
let(:address_params) {
diff --git a/spec/controllers/spree/admin/orders_controller_spec.rb b/spec/controllers/spree/admin/orders_controller_spec.rb
index 061112e0cb..aa54f46264 100644
--- a/spec/controllers/spree/admin/orders_controller_spec.rb
+++ b/spec/controllers/spree/admin/orders_controller_spec.rb
@@ -154,7 +154,7 @@ describe Spree::Admin::OrdersController, type: :controller do
it "should allow me to send order invoices" do
expect do
spree_get :invoice, params
- end.to_not change{Spree::OrderMailer.deliveries.count}
+ end.to_not change{ Spree::OrderMailer.deliveries.count }
expect(response).to redirect_to spree.edit_admin_order_path(order)
expect(flash[:error]).to eq "#{distributor.name} must have a valid ABN before invoices can be sent."
end
@@ -170,7 +170,7 @@ describe Spree::Admin::OrdersController, type: :controller do
it "should allow me to send order invoices" do
expect do
spree_get :invoice, params
- end.to change{Spree::OrderMailer.deliveries.count}.by(1)
+ end.to change{ Spree::OrderMailer.deliveries.count }.by(1)
expect(response).to redirect_to spree.edit_admin_order_path(order)
end
end
diff --git a/spec/controllers/spree/admin/payment_methods_controller_spec.rb b/spec/controllers/spree/admin/payment_methods_controller_spec.rb
index 102ce719a3..c5811f4fe7 100644
--- a/spec/controllers/spree/admin/payment_methods_controller_spec.rb
+++ b/spec/controllers/spree/admin/payment_methods_controller_spec.rb
@@ -59,7 +59,7 @@ describe Spree::Admin::PaymentMethodsController, type: :controller do
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
@@ -80,10 +80,9 @@ describe Spree::Admin::PaymentMethodsController, type: :controller do
context "without an altered provider type" do
it "renders provider settings with same payment method" do
- spree_get :show_provider_preferences, {
- pm_id: payment_method.id,
- provider_type: "Spree::PaymentMethod::Check"
- }
+ spree_get :show_provider_preferences,
+ pm_id: payment_method.id,
+ provider_type: "Spree::PaymentMethod::Check"
expect(assigns(:payment_method)).to eq payment_method
expect(response).to render_template partial: '_provider_settings'
end
@@ -91,10 +90,9 @@ describe Spree::Admin::PaymentMethodsController, type: :controller do
context "with an altered provider type" do
it "renders provider settings with a different payment method" do
- spree_get :show_provider_preferences, {
- pm_id: payment_method.id,
- provider_type: "Spree::Gateway::Bogus"
- }
+ spree_get :show_provider_preferences,
+ pm_id: payment_method.id,
+ provider_type: "Spree::Gateway::Bogus"
expect(assigns(:payment_method)).not_to eq payment_method
expect(response).to render_template partial: '_provider_settings'
end
@@ -107,10 +105,9 @@ describe Spree::Admin::PaymentMethodsController, type: :controller do
end
it "renders unauthorised" do
- spree_get :show_provider_preferences, {
- pm_id: payment_method.id,
- provider_type: "Spree::PaymentMethod::Check"
- }
+ spree_get :show_provider_preferences,
+ pm_id: payment_method.id,
+ provider_type: "Spree::PaymentMethod::Check"
expect(assigns(:payment_method)).to eq payment_method
expect(flash[:error]).to eq "Authorization Failure"
end
@@ -119,10 +116,9 @@ describe Spree::Admin::PaymentMethodsController, type: :controller do
context "on a new payment method" do
it "renders provider settings with a new payment method of type" do
- spree_get :show_provider_preferences, {
- pm_id: "",
- provider_type: "Spree::Gateway::Bogus"
- }
+ spree_get :show_provider_preferences,
+ pm_id: "",
+ provider_type: "Spree::Gateway::Bogus"
expect(assigns(:payment_method)).to be_a_new Spree::Gateway::Bogus
expect(response).to render_template partial: '_provider_settings'
end
diff --git a/spec/controllers/spree/admin/payments_controller_spec.rb b/spec/controllers/spree/admin/payments_controller_spec.rb
index 367e6c6f6b..55b20d3484 100644
--- a/spec/controllers/spree/admin/payments_controller_spec.rb
+++ b/spec/controllers/spree/admin/payments_controller_spec.rb
@@ -11,7 +11,7 @@ describe Spree::Admin::PaymentsController, type: :controller do
end
context "#create" do
- let!(:payment_method) { create(:payment_method, distributors: [ shop ]) }
+ let!(:payment_method) { create(:payment_method, distributors: [shop]) }
let!(:order) do
create(:order_with_totals_and_distribution, distributor: shop, state: "payment")
end
@@ -41,7 +41,6 @@ describe Spree::Admin::PaymentsController, type: :controller do
# let!(:credit_card) { create(:credit_card, gateway_customer_profile_id: "cus_1", gateway_payment_profile_id: 'card_2') }
let!(:payment) { create(:payment, order: order, state: 'completed', payment_method: payment_method, response_code: 'ch_1a2b3c', amount: order.total) }
-
before do
allow(Stripe).to receive(:api_key) { "sk_test_12345" }
end
@@ -50,7 +49,7 @@ describe Spree::Admin::PaymentsController, type: :controller do
before do
stub_request(:post, "https://api.stripe.com/v1/charges/ch_1a2b3c/refunds").
with(basic_auth: ["sk_test_12345", ""]).
- to_return(:status => 200, :body => JSON.generate(id: 're_123', object: 'refund', status: 'succeeded') )
+ to_return(status: 200, body: JSON.generate(id: 're_123', object: 'refund', status: 'succeeded') )
end
it "voids the payment" do
@@ -69,7 +68,7 @@ describe Spree::Admin::PaymentsController, type: :controller do
before do
stub_request(:post, "https://api.stripe.com/v1/charges/ch_1a2b3c/refunds").
with(basic_auth: ["sk_test_12345", ""]).
- to_return(:status => 200, :body => JSON.generate(error: { message: "Bup-bow!"}) )
+ to_return(status: 200, body: JSON.generate(error: { message: "Bup-bow!" }) )
end
it "does not void the payment" do
@@ -97,7 +96,6 @@ describe Spree::Admin::PaymentsController, type: :controller do
let!(:payment_method) { create(:stripe_payment_method, distributors: [shop]) }
let!(:payment) { create(:payment, order: order, state: 'completed', payment_method: payment_method, response_code: 'ch_1a2b3c', amount: order.total + 5) }
-
before do
allow(Stripe).to receive(:api_key) { "sk_test_12345" }
end
@@ -106,7 +104,7 @@ describe Spree::Admin::PaymentsController, type: :controller do
before do
stub_request(:post, "https://api.stripe.com/v1/charges/ch_1a2b3c/refunds").
with(basic_auth: ["sk_test_12345", ""]).
- to_return(:status => 200, :body => JSON.generate(id: 're_123', object: 'refund', status: 'succeeded') )
+ to_return(status: 200, body: JSON.generate(id: 're_123', object: 'refund', status: 'succeeded') )
end
it "partially refunds the payment" do
@@ -125,7 +123,7 @@ describe Spree::Admin::PaymentsController, type: :controller do
before do
stub_request(:post, "https://api.stripe.com/v1/charges/ch_1a2b3c/refunds").
with(basic_auth: ["sk_test_12345", ""]).
- to_return(:status => 200, :body => JSON.generate(error: { message: "Bup-bow!"}) )
+ to_return(status: 200, body: JSON.generate(error: { message: "Bup-bow!" }) )
end
it "does not void the payment" do
diff --git a/spec/controllers/spree/admin/products_controller_spec.rb b/spec/controllers/spree/admin/products_controller_spec.rb
index ba680bf050..1f6356b98b 100644
--- a/spec/controllers/spree/admin/products_controller_spec.rb
+++ b/spec/controllers/spree/admin/products_controller_spec.rb
@@ -11,9 +11,8 @@ describe Spree::Admin::ProductsController, type: :controller do
before do
login_as_enterprise_user [s_managed]
- spree_post :bulk_update, {
- "products" => [{"id" => product.id, "name" => "Pine nuts"}]
- }
+ spree_post :bulk_update,
+ "products" => [{ "id" => product.id, "name" => "Pine nuts" }]
end
it "denies access" do
@@ -42,29 +41,27 @@ describe Spree::Admin::ProductsController, type: :controller do
before { login_as_enterprise_user([producer]) }
it 'fails' do
- spree_post :bulk_update, {
- "products" => [
- {
- "id" => product.id,
- "variant_unit" => "weight",
- "variant_unit_scale" => 1
- }
- ]
- }
+ spree_post :bulk_update,
+ "products" => [
+ {
+ "id" => product.id,
+ "variant_unit" => "weight",
+ "variant_unit_scale" => 1
+ }
+ ]
expect(response).to have_http_status(400)
end
it 'does not redirect to bulk_products' do
- spree_post :bulk_update, {
- "products" => [
- {
- "id" => product.id,
- "variant_unit" => "weight",
- "variant_unit_scale" => 1
- }
- ]
- }
+ spree_post :bulk_update,
+ "products" => [
+ {
+ "id" => product.id,
+ "variant_unit" => "weight",
+ "variant_unit_scale" => 1
+ }
+ ]
expect(response).not_to redirect_to(
'/api/products/bulk_products?page=1;per_page=500;'
@@ -98,26 +95,25 @@ describe Spree::Admin::ProductsController, type: :controller do
before { login_as_enterprise_user([producer]) }
it 'does not fail' do
- spree_post :bulk_update, {
- "products" => [
- {
- "id" => another_product.id,
- "variants_attributes" => [{}]
- },
- {
- "id" => product.id,
- "variants_attributes" => [
- {
- "on_hand" => 2,
- "price" => "5.0",
- "unit_value" => 4,
- "unit_description" => "",
- "display_name" => "name"
- }
- ]
- }
- ]
- }
+ spree_post :bulk_update,
+ "products" => [
+ {
+ "id" => another_product.id,
+ "variants_attributes" => [{}]
+ },
+ {
+ "id" => product.id,
+ "variants_attributes" => [
+ {
+ "on_hand" => 2,
+ "price" => "5.0",
+ "unit_value" => 4,
+ "unit_description" => "",
+ "display_name" => "name"
+ }
+ ]
+ }
+ ]
expect(response).to have_http_status(:found)
end
@@ -143,12 +139,12 @@ describe Spree::Admin::ProductsController, type: :controller do
end
it "redirects to products when the user hits 'create'" do
- spree_post :create, { product: product_attrs, button: 'create' }
+ spree_post :create, product: product_attrs, button: 'create'
expect(response).to redirect_to spree.admin_products_path
end
it "redirects to new when the user hits 'add_another'" do
- spree_post :create, { product: product_attrs, button: 'add_another' }
+ spree_post :create, product: product_attrs, button: 'add_another'
expect(response).to redirect_to spree.new_admin_product_path
end
end
@@ -167,14 +163,13 @@ describe Spree::Admin::ProductsController, type: :controller do
context "when a submitted property does not already exist" do
it "does not create a new property, or product property" do
- spree_put :update, {
- id: product,
- product: {
- product_properties_attributes: {
- '0' => { property_name: 'a different name', value: 'something' }
- }
- }
- }
+ spree_put :update,
+ id: product,
+ product: {
+ product_properties_attributes: {
+ '0' => { property_name: 'a different name', value: 'something' }
+ }
+ }
expect(Spree::Property.count).to be 1
expect(Spree::ProductProperty.count).to be 0
property_names = product.reload.properties.map(&:name)
@@ -184,14 +179,13 @@ describe Spree::Admin::ProductsController, type: :controller do
context "when a submitted property exists" do
it "adds a product property" do
- spree_put :update, {
- id: product,
- product: {
- product_properties_attributes: {
- '0' => { property_name: 'A nice name', value: 'something' }
- }
- }
- }
+ spree_put :update,
+ id: product,
+ product: {
+ product_properties_attributes: {
+ '0' => { property_name: 'A nice name', value: 'something' }
+ }
+ }
expect(Spree::Property.count).to be 1
expect(Spree::ProductProperty.count).to be 1
property_names = product.reload.properties.map(&:name)
diff --git a/spec/controllers/spree/admin/reports_controller_spec.rb b/spec/controllers/spree/admin/reports_controller_spec.rb
index f964aa8863..6af65dbb82 100644
--- a/spec/controllers/spree/admin/reports_controller_spec.rb
+++ b/spec/controllers/spree/admin/reports_controller_spec.rb
@@ -1,7 +1,6 @@
require 'spec_helper'
describe Spree::Admin::ReportsController, type: :controller do
-
# Given two distributors and two suppliers
let(:bill_address) { create(:address) }
let(:ship_address) { create(:address) }
@@ -70,7 +69,7 @@ describe Spree::Admin::ReportsController, type: :controller do
describe 'Orders & Fulfillment' do
it "shows all orders in order cycles I coordinate" do
- spree_post :orders_and_fulfillment, {q: {}}
+ spree_post :orders_and_fulfillment, q: {}
expect(resulting_orders).to include orderA1, orderA2
expect(resulting_orders).not_to include orderB1, orderB2
@@ -98,7 +97,7 @@ describe Spree::Admin::ReportsController, type: :controller do
let!(:present_objects) { [orderA1, orderA2, orderB1, orderB2] }
it "only shows orders that I have access to" do
- spree_post :bulk_coop, {q: {}}
+ spree_post :bulk_coop, q: {}
expect(resulting_orders).to include(orderA1, orderB1)
expect(resulting_orders).not_to include(orderA2)
@@ -123,7 +122,7 @@ describe Spree::Admin::ReportsController, type: :controller do
let!(:present_objects) { [orderA1, orderA2, orderB1, orderB2] }
it "only shows orders that I distribute" do
- spree_post :orders_and_fulfillment, {q: {}}
+ spree_post :orders_and_fulfillment, q: {}
expect(resulting_orders).to include orderA1, orderB1
expect(resulting_orders).not_to include orderA2, orderB2
@@ -134,7 +133,7 @@ describe Spree::Admin::ReportsController, type: :controller do
let!(:present_objects) { [orderA1, orderB1] }
it "only shows the selected order cycle" do
- spree_post :orders_and_fulfillment, q: {order_cycle_id_in: [ocA.id.to_s]}
+ spree_post :orders_and_fulfillment, q: { order_cycle_id_in: [ocA.id.to_s] }
expect(resulting_orders).to include(orderA1)
expect(resulting_orders).not_to include(orderB1)
@@ -166,7 +165,7 @@ describe Spree::Admin::ReportsController, type: :controller do
end
it "only shows product line items that I am supplying" do
- spree_post :bulk_coop, {q: {}}
+ spree_post :bulk_coop, q: {}
expect(resulting_products).to include product1
expect(resulting_products).not_to include product2, product3
@@ -191,14 +190,14 @@ describe Spree::Admin::ReportsController, type: :controller do
end
it "only shows product line items that I am supplying" do
- spree_post :orders_and_fulfillment, {q: {}}
+ spree_post :orders_and_fulfillment, q: {}
expect(resulting_products).to include product1
expect(resulting_products).not_to include product2, product3
end
it "only shows the selected order cycle" do
- spree_post :orders_and_fulfillment, q: {order_cycle_id_eq: ocA.id}
+ spree_post :orders_and_fulfillment, q: { order_cycle_id_eq: ocA.id }
expect(resulting_orders_prelim).to include(orderA1)
expect(resulting_orders_prelim).not_to include(orderB1)
@@ -250,7 +249,7 @@ describe Spree::Admin::ReportsController, type: :controller do
it "creates a ProductAndInventoryReport" do
expect(OpenFoodNetwork::ProductsAndInventoryReport).to receive(:new)
- .with(@admin_user, {"test" => "foo", "controller" => "spree/admin/reports", "action" => "products_and_inventory"}, false)
+ .with(@admin_user, { "test" => "foo", "controller" => "spree/admin/reports", "action" => "products_and_inventory" }, false)
.and_return(report = double(:report))
allow(report).to receive(:header).and_return []
allow(report).to receive(:table).and_return []
@@ -264,9 +263,9 @@ describe Spree::Admin::ReportsController, type: :controller do
it "should have report types for customers" do
expect(subject.report_types[:customers]).to eq([
- ["Mailing List", :mailing_list],
- ["Addresses", :addresses]
- ])
+ ["Mailing List", :mailing_list],
+ ["Addresses", :addresses]
+ ])
end
context "with distributors and suppliers" do
@@ -301,7 +300,7 @@ describe Spree::Admin::ReportsController, type: :controller do
it "creates a CustomersReport" do
expect(OpenFoodNetwork::CustomersReport).to receive(:new)
- .with(@admin_user, {"test" => "foo", "controller" => "spree/admin/reports", "action" => "customers"}, false)
+ .with(@admin_user, { "test" => "foo", "controller" => "spree/admin/reports", "action" => "customers" }, false)
.and_return(report = double(:report))
allow(report).to receive(:header).and_return []
allow(report).to receive(:table).and_return []
@@ -322,7 +321,7 @@ describe Spree::Admin::ReportsController, type: :controller do
end
it "shows report data" do
- spree_post :users_and_enterprises, {q: {}}
+ spree_post :users_and_enterprises, q: {}
expect(assigns(:report).table.empty?).to be false
end
end
diff --git a/spec/controllers/spree/admin/search_controller_spec.rb b/spec/controllers/spree/admin/search_controller_spec.rb
index 59490cec5b..48fffbabcd 100644
--- a/spec/controllers/spree/admin/search_controller_spec.rb
+++ b/spec/controllers/spree/admin/search_controller_spec.rb
@@ -47,12 +47,12 @@ describe Spree::Admin::SearchController, type: :controller do
it 'returns a list of customers of the enterprise' do
expect(@results.size).to eq 2
- expect(@results.find { |c| c['id'] == customer_1.id}).to be_truthy
- expect(@results.find { |c| c['id'] == customer_2.id}).to be_truthy
+ expect(@results.find { |c| c['id'] == customer_1.id }).to be_truthy
+ expect(@results.find { |c| c['id'] == customer_2.id }).to be_truthy
end
it 'does not return the customer of other enterprises' do
- expect(@results.find { |c| c['id'] == customer_3.id}).to be_nil
+ expect(@results.find { |c| c['id'] == customer_3.id }).to be_nil
p customer_3
p enterprise
end
diff --git a/spec/controllers/spree/admin/shipping_methods_controller_spec.rb b/spec/controllers/spree/admin/shipping_methods_controller_spec.rb
index c823d2cff6..d705972c87 100644
--- a/spec/controllers/spree/admin/shipping_methods_controller_spec.rb
+++ b/spec/controllers/spree/admin/shipping_methods_controller_spec.rb
@@ -10,7 +10,7 @@ describe Spree::Admin::ShippingMethodsController, type: :controller do
login_as_admin
expect(shipping_method.deleted_at).to be_nil
- spree_delete :destroy, {"id" => shipping_method.id}
+ spree_delete :destroy, "id" => shipping_method.id
expect(shipping_method.reload.deleted_at).not_to be_nil
end
@@ -23,7 +23,7 @@ describe Spree::Admin::ShippingMethodsController, type: :controller do
login_as_admin
expect(order.shipping_method.deleted_at).to be_nil
- spree_delete :destroy, {"id" => order.shipping_method.id}
+ spree_delete :destroy, "id" => order.shipping_method.id
expect(order.shipping_method.reload.deleted_at).to be_nil
end
diff --git a/spec/controllers/spree/api/line_items_controller_spec.rb b/spec/controllers/spree/api/line_items_controller_spec.rb
index 6a63fe617f..cda1a5a81e 100644
--- a/spec/controllers/spree/api/line_items_controller_spec.rb
+++ b/spec/controllers/spree/api/line_items_controller_spec.rb
@@ -8,12 +8,12 @@ module Spree
allow(controller).to receive(:spree_current_user) { current_api_user }
end
- #test that when a line item is updated, an order's fees are updated too
+ # test that when a line item is updated, an order's fees are updated too
context "as an admin user" do
sign_in_as_admin!
let(:order) { FactoryBot.create(:order, state: 'complete', completed_at: Time.zone.now) }
- let(:line_item) { FactoryBot.create(:line_item_with_shipment, order: order,final_weight_volume: 500) }
+ let(:line_item) { FactoryBot.create(:line_item_with_shipment, order: order, final_weight_volume: 500) }
context "as a line item is updated" do
before { allow(controller).to receive(:order) { order } }
diff --git a/spec/controllers/spree/api/products_controller_spec.rb b/spec/controllers/spree/api/products_controller_spec.rb
index 821af72cff..89fb08c40c 100644
--- a/spec/controllers/spree/api/products_controller_spec.rb
+++ b/spec/controllers/spree/api/products_controller_spec.rb
@@ -24,7 +24,7 @@ module Spree
end
it "should deny me access to managed products" do
- spree_get :managed, { :template => 'bulk_index', :format => :json }
+ spree_get :managed, template: 'bulk_index', format: :json
assert_unauthorized!
end
end
@@ -37,20 +37,20 @@ module Spree
end
it "retrieves a list of managed products" do
- spree_get :managed, { :template => 'bulk_index', :format => :json }
- keys = json_response.first.keys.map{ |key| key.to_sym }
+ spree_get :managed, template: 'bulk_index', format: :json
+ keys = json_response.first.keys.map(&:to_sym)
expect(attributes.all?{ |attr| keys.include? attr }).to eq(true)
end
it "soft deletes my products" do
- spree_delete :soft_delete, {product_id: product1.to_param, format: :json}
+ spree_delete :soft_delete, product_id: product1.to_param, format: :json
expect(response.status).to eq(204)
expect { product1.reload }.not_to raise_error
expect(product1.deleted_at).not_to be_nil
end
it "is denied access to soft deleting another enterprises' product" do
- spree_delete :soft_delete, {product_id: product_other_supplier.to_param, format: :json}
+ spree_delete :soft_delete, product_id: product_other_supplier.to_param, format: :json
assert_unauthorized!
expect { product_other_supplier.reload }.not_to raise_error
expect(product_other_supplier.deleted_at).to be_nil
@@ -64,14 +64,14 @@ module Spree
end
it "retrieves a list of managed products" do
- spree_get :managed, { :template => 'bulk_index', :format => :json }
- keys = json_response.first.keys.map{ |key| key.to_sym }
+ spree_get :managed, template: 'bulk_index', format: :json
+ keys = json_response.first.keys.map(&:to_sym)
expect(attributes.all?{ |attr| keys.include? attr }).to eq(true)
end
it "retrieves a list of products with appropriate attributes" do
- spree_get :index, { :template => 'bulk_index', :format => :json }
- keys = json_response.first.keys.map{ |key| key.to_sym }
+ spree_get :index, template: 'bulk_index', format: :json
+ keys = json_response.first.keys.map(&:to_sym)
expect(attributes.all?{ |attr| keys.include? attr }).to eq(true)
end
@@ -79,7 +79,7 @@ module Spree
FactoryBot.create(:product, supplier: supplier)
FactoryBot.create(:product, supplier: supplier)
- spree_get :index, { :template => 'bulk_index', :format => :json }
+ spree_get :index, template: 'bulk_index', format: :json
ids = json_response.map{ |product| product['id'] }
expect(ids[0]).to be < ids[1]
@@ -87,29 +87,29 @@ module Spree
end
it "formats available_on to 'yyyy-mm-dd hh:mm'" do
- spree_get :index, { :template => 'bulk_index', :format => :json }
+ spree_get :index, template: 'bulk_index', format: :json
expect(json_response.map{ |product| product['available_on'] }.all?{ |a| a.match("^\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2}$") }).to eq(true)
end
it "returns permalink as permalink_live" do
- spree_get :index, { :template => 'bulk_index', :format => :json }
+ spree_get :index, template: 'bulk_index', format: :json
expect(json_response.detect{ |product| product['id'] == product1.id }['permalink_live']).to eq(product1.permalink)
end
it "should allow available_on to be nil" do
- spree_get :index, { :template => 'bulk_index', :format => :json }
+ spree_get :index, template: 'bulk_index', format: :json
expect(json_response.size).to eq(1)
product5 = FactoryBot.create(:product)
product5.available_on = nil
product5.save!
- spree_get :index, { :template => 'bulk_index', :format => :json }
+ spree_get :index, template: 'bulk_index', format: :json
expect(json_response.size).to eq(2)
end
it "soft deletes a product" do
- spree_delete :soft_delete, {product_id: product1.to_param, format: :json}
+ spree_delete :soft_delete, product_id: product1.to_param, format: :json
expect(response.status).to eq(204)
expect { product1.reload }.not_to raise_error
expect(product1.deleted_at).not_to be_nil
@@ -159,7 +159,6 @@ module Spree
.to receive(:has_spree_role?).with("admin").and_return(true)
end
-
it 'responds with a successful response' do
spree_post :clone, product_id: product1.id, format: :json
expect(response.status).to eq(201)
diff --git a/spec/controllers/spree/api/variants_controller_spec.rb b/spec/controllers/spree/api/variants_controller_spec.rb
index 11bdff7ad0..19f4bccc95 100644
--- a/spec/controllers/spree/api/variants_controller_spec.rb
+++ b/spec/controllers/spree/api/variants_controller_spec.rb
@@ -18,8 +18,8 @@ module Spree
sign_in_as_user!
it "retrieves a list of variants with appropriate attributes" do
- spree_get :index, { :template => 'bulk_index', :format => :json }
- keys = json_response.first.keys.map{ |key| key.to_sym }
+ spree_get :index, template: 'bulk_index', format: :json
+ keys = json_response.first.keys.map(&:to_sym)
expect(attributes.all?{ |attr| keys.include? attr }).to eq(true)
end
@@ -27,7 +27,7 @@ module Spree
product = create(:product)
variant = product.master
- spree_delete :soft_delete, {variant_id: variant.to_param, product_id: product.to_param, format: :json}
+ spree_delete :soft_delete, variant_id: variant.to_param, product_id: product.to_param, format: :json
assert_unauthorized!
expect { variant.reload }.not_to raise_error
expect(variant.deleted_at).to be_nil
@@ -43,14 +43,14 @@ module Spree
let(:variant_other) { product_other.master }
it "soft deletes a variant" do
- spree_delete :soft_delete, {variant_id: variant.to_param, product_id: product.to_param, format: :json}
+ spree_delete :soft_delete, variant_id: variant.to_param, product_id: product.to_param, format: :json
expect(response.status).to eq(204)
expect { variant.reload }.not_to raise_error
expect(variant.deleted_at).to be_present
end
it "is denied access to soft deleting another enterprises' variant" do
- spree_delete :soft_delete, {variant_id: variant_other.to_param, product_id: product_other.to_param, format: :json}
+ spree_delete :soft_delete, variant_id: variant_other.to_param, product_id: product_other.to_param, format: :json
assert_unauthorized!
expect { variant.reload }.not_to raise_error
expect(variant.deleted_at).to be_nil
@@ -73,7 +73,7 @@ module Spree
let(:variant) { product.master }
it "soft deletes a variant" do
- spree_delete :soft_delete, {variant_id: variant.to_param, product_id: product.to_param, format: :json}
+ spree_delete :soft_delete, variant_id: variant.to_param, product_id: product.to_param, format: :json
expect(response.status).to eq(204)
expect { variant.reload }.not_to raise_error
expect(variant.deleted_at).not_to be_nil
@@ -83,7 +83,7 @@ module Spree
product = create(:product)
variant = product.variants.first
- spree_delete :soft_delete, {variant_id: variant.to_param, product_id: product.to_param, format: :json}
+ spree_delete :soft_delete, variant_id: variant.to_param, product_id: product.to_param, format: :json
expect(variant.reload).to_not be_deleted
expect(assigns(:variant).errors[:product]).to include "must have at least one variant"
diff --git a/spec/controllers/spree/checkout_controller_spec.rb b/spec/controllers/spree/checkout_controller_spec.rb
index b91c19f744..f568ae806a 100644
--- a/spec/controllers/spree/checkout_controller_spec.rb
+++ b/spec/controllers/spree/checkout_controller_spec.rb
@@ -2,7 +2,6 @@ require 'spec_helper'
require 'spree/api/testing_support/helpers'
require 'support/request/authentication_workflow'
-
describe Spree::CheckoutController, type: :controller do
context 'rendering edit from within spree for the current checkout state' do
let(:order) { controller.current_order(true) }
diff --git a/spec/controllers/spree/orders_controller_spec.rb b/spec/controllers/spree/orders_controller_spec.rb
index 18fe0645bb..8c73e38a05 100644
--- a/spec/controllers/spree/orders_controller_spec.rb
+++ b/spec/controllers/spree/orders_controller_spec.rb
@@ -185,9 +185,9 @@ describe Spree::OrdersController, type: :controller do
order = subject.current_order(true)
li = order.add_variant(create(:simple_product, on_hand: 110).variants.first)
spree_get :update, order: { line_items_attributes: {
- "0" => {quantity: "0", id: "9999"},
- "1" => {quantity: "99", id: li.id}
- }}
+ "0" => { quantity: "0", id: "9999" },
+ "1" => { quantity: "99", id: li.id }
+ } }
expect(response.status).to eq(302)
expect(li.reload.quantity).to eq(99)
end
@@ -198,13 +198,13 @@ describe Spree::OrdersController, type: :controller do
li = order.add_variant(create(:simple_product).master)
attrs = {
- "0" => {quantity: "0", id: "9999"},
- "1" => {quantity: "99", id: li.id}
+ "0" => { quantity: "0", id: "9999" },
+ "1" => { quantity: "99", id: li.id }
}
- expect(controller.remove_missing_line_items(attrs)).to eq({
- "1" => {quantity: "99", id: li.id}
- })
+ expect(controller.remove_missing_line_items(attrs)).to eq(
+ "1" => { quantity: "99", id: li.id }
+ )
end
it "keeps the adjustments' previous state" do
@@ -214,7 +214,7 @@ describe Spree::OrdersController, type: :controller do
spree_get :update, order: { line_items_attributes: {
"1" => { quantity: "99", id: line_item.id }
- }}
+ } }
expect(adjustment.state).to eq('open')
end
@@ -246,12 +246,11 @@ describe Spree::OrdersController, type: :controller do
end
it "updates the fees" do
- spree_post :update, {
- order: { line_items_attributes: {
- "0" => { id: line_item1.id, quantity: 1 },
- "1" => { id: line_item2.id, quantity: 0 }
- } }
- }
+ spree_post :update,
+ order: { line_items_attributes: {
+ "0" => { id: line_item1.id, quantity: 1 },
+ "1" => { id: line_item2.id, quantity: 0 }
+ } }
expect(order.line_items.count).to eq 1
expect(order.adjustment_total).to eq((item_num - 1) * (shipping_fee + payment_fee))
@@ -259,12 +258,11 @@ describe Spree::OrdersController, type: :controller do
end
it "keeps the adjustments' previous state" do
- spree_post :update, {
- order: { line_items_attributes: {
- "0" => { id: line_item1.id, quantity: 1 },
- "1" => { id: line_item2.id, quantity: 0 }
- } }
- }
+ spree_post :update,
+ order: { line_items_attributes: {
+ "0" => { id: line_item1.id, quantity: 1 },
+ "1" => { id: line_item2.id, quantity: 0 }
+ } }
# The second adjustment (shipping adjustment) is open before the update
# so, restoring its state leaves it open.
@@ -286,9 +284,10 @@ describe Spree::OrdersController, type: :controller do
order.update_distribution_charge!
order
end
- let(:params) { { order: { line_items_attributes: {
- "0" => { id: order.line_items.first.id, quantity: 2 }
- } } } }
+ let(:params) {
+ { order: { line_items_attributes: {
+ "0" => { id: order.line_items.first.id, quantity: 2 }
+ } } } }
before do
allow(subject).to receive(:spree_current_user) { order.user }
@@ -308,10 +307,11 @@ describe Spree::OrdersController, type: :controller do
describe "request to remove items from a completed order" do
let(:order) { create(:completed_order_with_totals, line_items_count: 2) }
- let(:params) { { order: { line_items_attributes: {
+ let(:params) {
+ { order: { line_items_attributes: {
"0" => { id: order.line_items.first.id, quantity: 1 },
"1" => { id: order.line_items.second.id, quantity: 0 }
- } } } }
+ } } } }
before { allow(subject).to receive(:order_to_update) { order } }
@@ -338,7 +338,7 @@ describe Spree::OrdersController, type: :controller do
describe "#order_to_update" do
let!(:current_order) { double(:current_order) }
- let(:params) { { } }
+ let(:params) { {} }
before do
allow(controller).to receive(:current_order) { current_order }
@@ -353,7 +353,7 @@ describe Spree::OrdersController, type: :controller do
context "when an order_id is given in params" do
before do
- params.merge!({id: order.number})
+ params.merge!(id: order.number)
end
context "and the order is not complete" do
@@ -379,7 +379,6 @@ describe Spree::OrdersController, type: :controller do
before { allow(controller).to receive(:can?).with(:update, order) { true } }
context "and the order is not editable" do
-
it "returns nil" do
expect(controller.send(:order_to_update)).to eq nil
end
@@ -447,7 +446,6 @@ describe Spree::OrdersController, type: :controller do
end
end
-
private
def num_items_in_cart
diff --git a/spec/controllers/spree/user_sessions_controller_spec.rb b/spec/controllers/spree/user_sessions_controller_spec.rb
index a6109e4011..60cbbb7d03 100644
--- a/spec/controllers/spree/user_sessions_controller_spec.rb
+++ b/spec/controllers/spree/user_sessions_controller_spec.rb
@@ -13,7 +13,7 @@ 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 +22,7 @@ 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/user_confirmations_controller_spec.rb b/spec/controllers/user_confirmations_controller_spec.rb
index 366884d30d..9920330161 100644
--- a/spec/controllers/user_confirmations_controller_spec.rb
+++ b/spec/controllers/user_confirmations_controller_spec.rb
@@ -16,7 +16,6 @@ describe UserConfirmationsController, type: :controller do
context "confirming a user" do
context "that has already been confirmed" do
-
before do
spree_get :show, confirmation_token: confirmed_token
end
@@ -62,7 +61,7 @@ describe UserConfirmationsController, type: :controller do
before { setup_email }
it "redirects the user to login" do
- spree_post :create, { spree_user: { email: unconfirmed_user.email } }
+ spree_post :create, spree_user: { email: unconfirmed_user.email }
expect(response).to redirect_to login_path
expect(flash[:success]).to eq I18n.t('devise.user_confirmations.spree_user.confirmation_sent')
end
@@ -70,7 +69,7 @@ describe UserConfirmationsController, type: :controller do
it "sends the confirmation email" do
performing_deliveries do
expect do
- spree_post :create, { spree_user: { email: unconfirmed_user.email } }
+ spree_post :create, spree_user: { email: unconfirmed_user.email }
end.to send_confirmation_instructions
end
end
diff --git a/spec/controllers/user_passwords_controller_spec.rb b/spec/controllers/user_passwords_controller_spec.rb
index 189b1983f6..90234ffd0d 100644
--- a/spec/controllers/user_passwords_controller_spec.rb
+++ b/spec/controllers/user_passwords_controller_spec.rb
@@ -19,7 +19,7 @@ describe UserPasswordsController, type: :controller do
end
it "redirects to login when data is valid" do
- spree_post :create, spree_user: { email: user.email}
+ spree_post :create, spree_user: { email: user.email }
expect(response).to be_redirect
end
end
@@ -54,7 +54,7 @@ describe UserPasswordsController, type: :controller do
end
it "returns error when user is unconfirmed" do
- xhr :post, :create, spree_user: {email: unconfirmed_user.email}, use_route: :spree
+ xhr :post, :create, 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/controllers/user_registrations_controller_spec.rb b/spec/controllers/user_registrations_controller_spec.rb
index ae2f671a2e..a90906da51 100644
--- a/spec/controllers/user_registrations_controller_spec.rb
+++ b/spec/controllers/user_registrations_controller_spec.rb
@@ -24,10 +24,10 @@ describe UserRegistrationsController, type: :controller do
end
it "returns validation errors" do
- xhr :post, :create, spree_user: {}, :use_route => :spree
+ xhr :post, :create, spree_user: {}, use_route: :spree
expect(response.status).to eq(401)
json = JSON.parse(response.body)
- expect(json).to eq({"email" => ["can't be blank"], "password" => ["can't be blank"]})
+ expect(json).to eq("email" => ["can't be blank"], "password" => ["can't be blank"])
end
it "returns error when emailing fails" do
@@ -38,14 +38,14 @@ describe UserRegistrationsController, type: :controller do
expect(response.status).to eq(401)
json = JSON.parse(response.body)
- expect(json).to eq({"message" => I18n.t('devise.user_registrations.spree_user.unknown_error')})
+ expect(json).to eq("message" => I18n.t('devise.user_registrations.spree_user.unknown_error'))
end
it "returns 200 when registration succeeds" do
xhr :post, :create, spree_user: user_params, use_route: :spree
expect(response.status).to eq(200)
json = JSON.parse(response.body)
- expect(json).to eq({"email" => "test@test.com"})
+ expect(json).to eq("email" => "test@test.com")
expect(controller.spree_current_user).to be_nil
end
diff --git a/spec/features/admin/adjustments_spec.rb b/spec/features/admin/adjustments_spec.rb
index 5adac5271c..2d93981487 100644
--- a/spec/features/admin/adjustments_spec.rb
+++ b/spec/features/admin/adjustments_spec.rb
@@ -1,9 +1,9 @@
require "spec_helper"
-feature %q{
+feature '
As an administrator
I want to manage adjustments on orders
-}, js: true do
+', js: true do
include AuthenticationWorkflow
include WebHelper
diff --git a/spec/features/admin/bulk_order_management_spec.rb b/spec/features/admin/bulk_order_management_spec.rb
index f137b335de..5ce4c2cd78 100644
--- a/spec/features/admin/bulk_order_management_spec.rb
+++ b/spec/features/admin/bulk_order_management_spec.rb
@@ -1,9 +1,9 @@
require 'spec_helper'
-feature %q{
+feature '
As an Administrator
I want to be able to manage orders in bulk
-} , js: true do
+', js: true do
include AdminHelper
include AuthenticationWorkflow
include WebHelper
@@ -48,9 +48,9 @@ feature %q{
end
it "displays a column for user's full name" do
- expect(page).to have_selector "th.full_name", text: "NAME", :visible => true
- expect(page).to have_selector "td.full_name", text: o1.bill_address.full_name, :visible => true
- expect(page).to have_selector "td.full_name", text: "", :visible => true
+ expect(page).to have_selector "th.full_name", text: "NAME", visible: true
+ expect(page).to have_selector "td.full_name", text: o1.bill_address.full_name, visible: true
+ expect(page).to have_selector "td.full_name", text: "", visible: true
end
it "displays a column for order date" do
@@ -60,27 +60,27 @@ feature %q{
end
it "displays a column for producer" do
- expect(page).to have_selector "th.producer", text: "PRODUCER", :visible => true
- expect(page).to have_selector "td.producer", text: li1.product.supplier.name, :visible => true
- expect(page).to have_selector "td.producer", text: li2.product.supplier.name, :visible => true
+ expect(page).to have_selector "th.producer", text: "PRODUCER", visible: true
+ expect(page).to have_selector "td.producer", text: li1.product.supplier.name, visible: true
+ expect(page).to have_selector "td.producer", text: li2.product.supplier.name, visible: true
end
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 "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
end
it "displays a field for quantity" do
- expect(page).to have_selector "th.quantity", text: "QUANTITY", :visible => true
- expect(page).to have_field "quantity", with: li1.quantity.to_s, :visible => true
- expect(page).to have_field "quantity", with: li2.quantity.to_s, :visible => true
+ expect(page).to have_selector "th.quantity", text: "QUANTITY", visible: true
+ expect(page).to have_field "quantity", with: li1.quantity.to_s, visible: true
+ expect(page).to have_field "quantity", with: li2.quantity.to_s, visible: true
end
it "displays a column for max quantity" do
- expect(page).to have_selector "th.max", text: "MAX", :visible => true
- expect(page).to have_selector "td.max", text: li1.max_quantity.to_s, :visible => true
- expect(page).to have_selector "td.max", text: li2.max_quantity.to_s, :visible => true
+ expect(page).to have_selector "th.max", text: "MAX", visible: true
+ expect(page).to have_selector "td.max", text: li1.max_quantity.to_s, visible: true
+ expect(page).to have_selector "td.max", text: li2.max_quantity.to_s, visible: true
end
end
@@ -126,7 +126,7 @@ feature %q{
context "tracking changes" do
let!(:o1) { create(:order_with_distributor, state: 'complete', completed_at: Time.zone.now ) }
- let!(:li1) { create(:line_item_with_shipment, order: o1, :quantity => 5 ) }
+ let!(:li1) { create(:line_item_with_shipment, order: o1, quantity: 5 ) }
before :each do
visit_bulk_order_management
@@ -134,7 +134,7 @@ feature %q{
it "adds the class 'ng-dirty' to input elements when value is altered" do
expect(page).to have_no_css "input[name='quantity'].ng-dirty"
- fill_in "quantity", :with => 2
+ fill_in "quantity", with: 2
expect(page).to have_css "input[name='quantity'].ng-dirty"
end
end
@@ -150,7 +150,7 @@ feature %q{
context "when acceptable data is sent to the server" do
it "displays an update button which submits pending changes" do
expect(page).to have_no_selector "#save-bar"
- fill_in "quantity", :with => 2
+ fill_in "quantity", with: 2
expect(page).to have_selector "input[name='quantity'].ng-dirty"
expect(page).to have_selector "#save-bar", text: "You have unsaved changes"
click_button "Save Changes"
@@ -163,7 +163,7 @@ feature %q{
it "displays an update button which submits pending changes" do
expect(page).to have_no_selector "#save-bar"
line_item = order.line_items.first
- fill_in "quantity", :with => line_item.variant.on_hand + line_item.quantity + 10
+ fill_in "quantity", with: line_item.variant.on_hand + line_item.quantity + 10
expect(page).to have_selector "input[name='quantity'].ng-dirty"
expect(page).to have_selector "#save-bar", text: "You have unsaved changes"
click_button "Save Changes"
@@ -183,9 +183,9 @@ feature %q{
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)}
+ before { v1.update_attribute(:on_hand, 100) }
context "modifying the weight/volume of a line item" do
it "price is altered" do
@@ -193,7 +193,7 @@ feature %q{
toggle_columns "Weight/Volume", "Price"
within "tr#li_#{li1.id}" do
expect(page).to have_field "price", with: "50.00"
- fill_in "final_weight_volume", :with => 2000
+ fill_in "final_weight_volume", with: 2000
expect(page).to have_field "price", with: "100.00"
end
click_button "Save Changes"
@@ -209,9 +209,9 @@ feature %q{
visit_bulk_order_management
toggle_columns "Price"
within "tr#li_#{li1.id}" do
- expect(page).to have_field "price", with: "#{format("%.2f",li1.price * 5)}"
- fill_in "quantity", :with => 6
- expect(page).to have_field "price", with: "#{format("%.2f",li1.price * 6)}"
+ expect(page).to have_field "price", with: format('%.2f', li1.price * 5).to_s
+ fill_in "quantity", with: 6
+ expect(page).to have_field "price", with: format('%.2f', li1.price * 6).to_s
end
end
end
@@ -221,9 +221,9 @@ feature %q{
visit_bulk_order_management
toggle_columns "Weight/Volume"
within "tr#li_#{li1.id}" do
- expect(page).to have_field "final_weight_volume", with: "#{li1.final_weight_volume.round}"
- fill_in "quantity", :with => 6
- expect(page).to have_field "final_weight_volume", with: "#{((li1.final_weight_volume*6)/5).round}"
+ 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
end
end
end
@@ -232,21 +232,21 @@ feature %q{
it "shows a column display toggle button, which shows a list of columns when clicked" do
visit_bulk_order_management
- expect(page).to have_selector "th", :text => "NAME"
+ 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 => "PRODUCER"
- 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"
+ 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"
+ expect(page).to have_selector "th", text: "MAX"
toggle_columns "Producer"
- expect(page).to have_no_selector "th", :text => "PRODUCER"
- expect(page).to have_selector "th", :text => "NAME"
+ 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 => "PRODUCT: UNIT"
- expect(page).to have_selector "th", :text => "QUANTITY"
- expect(page).to have_selector "th", :text => "MAX"
+ 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"
end
end
@@ -435,7 +435,7 @@ feature %q{
expect(page).to have_selector "tr#li_#{li1.id}"
expect(page).to have_selector "tr#li_#{li2.id}"
expect(page).to have_selector "tr#li_#{li3.id}"
- fill_in "quick_search", :with => o1.email
+ fill_in "quick_search", with: o1.email
expect(page).to have_selector "tr#li_#{li1.id}"
expect(page).to have_no_selector "tr#li_#{li2.id}"
expect(page).to have_no_selector "tr#li_#{li3.id}"
@@ -447,10 +447,10 @@ feature %q{
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 ) }
- let!(:li4) { create(:line_item_with_shipment, order: o4, :quantity => 4 ) }
+ 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 ) }
+ let!(:li4) { create(:line_item_with_shipment, order: o4, quantity: 4 ) }
before :each do
visit_bulk_order_management
@@ -492,13 +492,13 @@ feature %q{
context "when the form is dirty" do
before do
within("tr#li_#{li2.id} td.quantity") do
- page.fill_in "quantity", :with => (li2.quantity + 1).to_s
+ page.fill_in "quantity", with: (li2.quantity + 1).to_s
end
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
- fill_in "start_date_filter", :with => (Date.current - 9).strftime("%F %T")
+ fill_in "start_date_filter", with: (Date.current - 9).strftime("%F %T")
end
expect(page).to have_no_selector "#save-bar"
within("tr#li_#{li2.id} td.quantity") do
@@ -508,7 +508,7 @@ feature %q{
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
- fill_in "start_date_filter", :with => (Date.current - 9).strftime("%F %T")
+ fill_in "start_date_filter", with: (Date.current - 9).strftime("%F %T")
end
expect(page).to have_selector "#save-bar"
within("tr#li_#{li2.id} td.quantity") do
@@ -556,7 +556,7 @@ feature %q{
check "bulk"
end
find("div#bulk-actions-dropdown").click
- find("div#bulk-actions-dropdown div.menu_item", :text => "Delete Selected" ).click
+ find("div#bulk-actions-dropdown div.menu_item", text: "Delete Selected" ).click
expect(page).to have_selector "tr#li_#{li1.id}"
expect(page).to have_no_selector "tr#li_#{li2.id}"
end
@@ -579,7 +579,7 @@ feature %q{
fill_in "quick_search", with: o1.number
expect(page).to have_no_selector "tr#li_#{li2.id}"
find("div#bulk-actions-dropdown").click
- find("div#bulk-actions-dropdown div.menu_item", :text => "Delete Selected" ).click
+ find("div#bulk-actions-dropdown div.menu_item", text: "Delete Selected" ).click
expect(page).to have_no_selector "tr#li_#{li1.id}"
fill_in "quick_search", with: ''
wait_until { request_monitor_finished 'LineItemsCtrl' }
@@ -602,7 +602,7 @@ feature %q{
end
it "shows an edit button for line_items, which takes the user to the standard edit page for the order" do
- expect(page).to have_selector "a.edit-order", :count => 2
+ 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
@@ -637,14 +637,14 @@ feature %q{
end
it "removes a line item when the relevant delete button is clicked" do
- expect(page).to have_selector "a.delete-line-item", :count => 2
+ expect(page).to have_selector "a.delete-line-item", count: 2
accept_alert do
find("tr#li_#{li1.id} a.delete-line-item").click
end
- expect(page).to have_no_selector "a.delete-line-item", :count => 2
- expect(page).to have_selector "a.delete-line-item", :count => 1
+ expect(page).to have_no_selector "a.delete-line-item", count: 2
+ expect(page).to have_selector "a.delete-line-item", count: 1
visit_bulk_order_management
- expect(page).to have_selector "a.delete-line-item", :count => 1
+ expect(page).to have_selector "a.delete-line-item", count: 1
end
end
end
@@ -668,7 +668,7 @@ feature %q{
end
it "displays group buy calc box" do
- expect(page).to have_selector "div#group_buy_calculation", :visible => true
+ expect(page).to have_selector "div#group_buy_calculation", visible: true
within "div#group_buy_calculation" do
expect(page).to have_text "Group Buy Unit Size"
@@ -681,19 +681,19 @@ feature %q{
expect(page).to have_text "0.8"
expect(page).to have_text "Max Fulfilled Units"
expect(page).to have_text "1.8"
- expect(page).to have_selector "div.shared_resource", :visible => true
+ expect(page).to have_selector "div.shared_resource", visible: true
within "div.shared_resource" do
- expect(page).to have_selector "span", :text => "Shared Resource?"
+ expect(page).to have_selector "span", text: "Shared Resource?"
expect(page).to have_selector "input#shared_resource"
end
end
end
it "all line items of the same variant" do
- expect(page).to have_no_selector "tr#li_#{li1.id}", :visible => true
- expect(page).to have_no_selector "tr#li_#{li2.id}", :visible => true
- expect(page).to have_selector "tr#li_#{li3.id}", :visible => true
- expect(page).to have_selector "tr#li_#{li4.id}", :visible => true
+ expect(page).to have_no_selector "tr#li_#{li1.id}", visible: true
+ expect(page).to have_no_selector "tr#li_#{li2.id}", visible: true
+ expect(page).to have_selector "tr#li_#{li3.id}", visible: true
+ expect(page).to have_selector "tr#li_#{li4.id}", visible: true
end
context "clicking 'Clear' in group buy box" do
@@ -702,11 +702,11 @@ feature %q{
end
it "shows all products and clears group buy box" do
- expect(page).to have_no_selector "div#group_buy_calculation", :visible => true
- expect(page).to have_selector "tr#li_#{li1.id}", :visible => true
- expect(page).to have_selector "tr#li_#{li2.id}", :visible => true
- expect(page).to have_selector "tr#li_#{li3.id}", :visible => true
- expect(page).to have_selector "tr#li_#{li4.id}", :visible => true
+ expect(page).to have_no_selector "div#group_buy_calculation", visible: true
+ expect(page).to have_selector "tr#li_#{li1.id}", visible: true
+ expect(page).to have_selector "tr#li_#{li2.id}", visible: true
+ expect(page).to have_selector "tr#li_#{li3.id}", visible: true
+ expect(page).to have_selector "tr#li_#{li4.id}", visible: true
end
end
end
@@ -739,8 +739,8 @@ feature %q{
it "shows only line item from orders that I distribute, and not those that I supply" do
visit_bulk_order_management
- expect(page).to have_selector "tr#li_#{line_item_distributed.id}", :visible => true
- expect(page).to have_no_selector "tr#li_#{line_item_not_distributed.id}", :visible => true
+ expect(page).to have_selector "tr#li_#{line_item_distributed.id}", visible: true
+ expect(page).to have_no_selector "tr#li_#{line_item_not_distributed.id}", visible: true
end
end
diff --git a/spec/features/admin/bulk_product_update_spec.rb b/spec/features/admin/bulk_product_update_spec.rb
index 430b5b3344..715e551668 100644
--- a/spec/features/admin/bulk_product_update_spec.rb
+++ b/spec/features/admin/bulk_product_update_spec.rb
@@ -1,9 +1,9 @@
require 'spec_helper'
-feature %q{
+feature '
As an Administrator
I want to be able to manage products in bulk
-} , js: true do
+', js: true do
include AdminHelper
include AuthenticationWorkflow
include WebHelper
@@ -19,8 +19,8 @@ feature %q{
visit spree.admin_products_path
- expect(page).to have_field "product_name", with: p1.name, :visible => true
- expect(page).to have_field "product_name", with: p2.name, :visible => true
+ expect(page).to have_field "product_name", with: p1.name, visible: true
+ expect(page).to have_field "product_name", with: p2.name, visible: true
end
it "displays a message when number of products is zero" do
@@ -38,13 +38,13 @@ feature %q{
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
p1 = FactoryBot.create(:product, available_on: Date.current)
- p2 = FactoryBot.create(:product, available_on: Date.current-1)
+ p2 = FactoryBot.create(:product, available_on: Date.current - 1)
visit spree.admin_products_path
toggle_columns "Available On"
@@ -76,9 +76,9 @@ feature %q{
find("a.view-variants").click
expect(page).to have_no_selector "span[name='on_hand']", text: "On demand", visible: true
- expect(page).to have_field "variant_on_hand", with: "4"
+ expect(page).to have_field "variant_on_hand", with: "4"
expect(page).to have_no_field "variant_on_hand", with: "", visible: true
- expect(page).to have_selector "span[name='variant_on_hand']", text: "On demand"
+ expect(page).to have_selector "span[name='variant_on_hand']", text: "On demand"
end
it "displays a select box for the unit of measure for the product's variants" do
@@ -110,7 +110,7 @@ feature %q{
visit spree.admin_products_path
expect(page).to have_selector "a.view-variants", count: 2
- all("a.view-variants").each { |e| e.click }
+ all("a.view-variants").each(&:click)
expect(page).to have_field "product_name", with: v1.product.name
expect(page).to have_field "product_name", with: v2.product.name
@@ -131,14 +131,13 @@ feature %q{
visit spree.admin_products_path
expect(page).to have_selector "a.view-variants", count: 1
- all("a.view-variants").each { |e| e.click }
+ all("a.view-variants").each(&:click)
- expect(page).to have_selector "span[name='on_hand']", text: p1.variants.sum{ |v| v.on_hand }.to_s
+ expect(page).to have_selector "span[name='on_hand']", text: p1.variants.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
-
it "displays a price input (for each variant) for each product" do
p1 = FactoryBot.create(:product, price: 2.0)
v1 = FactoryBot.create(:variant, product: p1, is_master: false, price: 12.75)
@@ -146,7 +145,7 @@ feature %q{
visit spree.admin_products_path
expect(page).to have_selector "a.view-variants", count: 1
- all("a.view-variants").each { |e| e.click }
+ all("a.view-variants").each(&:click)
expect(page).to have_field "price", with: "2.0", visible: false
expect(page).to have_field "variant_price", with: "12.75"
@@ -160,7 +159,7 @@ feature %q{
visit spree.admin_products_path
expect(page).to have_selector "a.view-variants", count: 1
- all("a.view-variants").each { |e| e.click }
+ all("a.view-variants").each(&:click)
expect(page).to have_field "variant_unit_value_with_description", with: "1.2 (small bag)"
expect(page).to have_field "variant_unit_value_with_description", with: "4.8 (large bag)"
@@ -169,7 +168,6 @@ feature %q{
end
end
-
scenario "creating a new product" do
create(:stock_location, backorderable_default: false)
@@ -184,11 +182,11 @@ feature %q{
find("a", text: "NEW PRODUCT").click
expect(page).to have_content 'NEW PRODUCT'
- fill_in 'product_name', :with => 'Big Bag Of Apples'
- select supplier.name, :from => 'product_supplier_id'
+ fill_in 'product_name', with: 'Big Bag Of Apples'
+ select supplier.name, from: 'product_supplier_id'
select 'Weight (g)', from: 'product_variant_unit_with_scale'
fill_in 'product_unit_value_with_description', with: '100'
- fill_in 'product_price', :with => '10.00'
+ fill_in 'product_price', with: '10.00'
select taxon.name, from: 'product_primary_taxon_id'
select shipping_category.name, from: 'product_shipping_category_id'
click_button 'Create'
@@ -198,7 +196,6 @@ feature %q{
expect(page).to have_field "product_name", with: 'Big Bag Of Apples'
end
-
scenario "creating new variants" do
# Given a product without variants or a unit
p = FactoryBot.create(:product, variant_unit: 'weight', variant_unit_scale: 1000)
@@ -268,8 +265,8 @@ feature %q{
expect(page).to have_field "product_sku", with: p.sku
fill_in "product_name", with: "Big Bag Of Potatoes"
- select s2.name, :from => 'producer_id'
- fill_in "available_on", with: (3.days.ago.beginning_of_day).strftime("%F %T")
+ select s2.name, from: 'producer_id'
+ fill_in "available_on", with: 3.days.ago.beginning_of_day.strftime("%F %T")
select "Weight (kg)", from: "variant_unit_with_scale"
select2_select t1.name, from: "p#{p.id}_category_id"
uncheck "inherits_properties"
@@ -314,7 +311,7 @@ feature %q{
s1 = FactoryBot.create(:supplier_enterprise)
s2 = FactoryBot.create(:supplier_enterprise)
p = FactoryBot.create(:product, supplier: s1, available_on: Date.current, variant_unit: 'volume', variant_unit_scale: 0.001,
- price: 3.0, unit_value: 0.25, unit_description: '(bottle)' )
+ price: 3.0, unit_value: 0.25, unit_description: '(bottle)' )
v = p.variants.first
v.update_attribute(:sku, "VARIANTSKU")
v.update_attribute(:on_demand, false)
@@ -411,7 +408,7 @@ feature %q{
end
scenario "updating a product after cloning a product" do
- p = FactoryBot.create(:product, :name => "product 1")
+ p = FactoryBot.create(:product, name: "product 1")
quick_login_as_admin
visit spree.admin_products_path
@@ -419,7 +416,7 @@ feature %q{
expect(page).to have_selector "a.clone-product", count: 1
find("a.clone-product").click
- fill_in "product_name", :with => "new product name"
+ fill_in "product_name", with: "new product name"
within "#save-bar" do
click_button 'Save Changes'
@@ -433,8 +430,8 @@ feature %q{
scenario "updating when a filter has been applied" do
s1 = create(:supplier_enterprise)
s2 = create(:supplier_enterprise)
- p1 = FactoryBot.create(:simple_product, :name => "product1", supplier: s1)
- p2 = FactoryBot.create(:simple_product, :name => "product2", supplier: s2)
+ p1 = FactoryBot.create(:simple_product, name: "product1", supplier: s1)
+ p2 = FactoryBot.create(:simple_product, name: "product2", supplier: s2)
quick_login_as_admin
visit spree.admin_products_path
@@ -442,7 +439,7 @@ feature %q{
select2_select s1.name, from: "producer_filter"
expect(page).to have_no_field "product_name", with: p2.name
- fill_in "product_name", :with => "new product1"
+ fill_in "product_name", with: "new product1"
within "#save-bar" do
click_button 'Save Changes'
@@ -461,14 +458,13 @@ feature %q{
let!(:v2) { p2.variants.first }
let!(:v3) { FactoryBot.create(:variant, product: p2 ) }
-
before do
quick_login_as_admin
visit spree.admin_products_path
end
it "shows a delete button for products, which deletes the appropriate product when clicked" do
- expect(page).to have_selector "a.delete-product", :count => 2
+ expect(page).to have_selector "a.delete-product", count: 2
within "tr#p_#{p1.id}" do
accept_alert do
@@ -476,18 +472,18 @@ feature %q{
end
end
- expect(page).to have_selector "a.delete-product", :count => 1
+ expect(page).to have_selector "a.delete-product", count: 1
visit spree.admin_products_path
- expect(page).to have_selector "a.delete-product", :count => 1
+ expect(page).to have_selector "a.delete-product", count: 1
end
it "shows a delete button for variants, which deletes the appropriate variant when clicked" do
expect(page).to have_selector "a.view-variants"
- all("a.view-variants").each { |e| e.click }
+ all("a.view-variants").each(&:click)
- expect(page).to have_selector "a.delete-variant", :count => 3
+ expect(page).to have_selector "a.delete-variant", count: 3
within "tr#v_#{v3.id}" do
accept_alert do
@@ -495,13 +491,13 @@ feature %q{
end
end
- expect(page).to have_selector "a.delete-variant", :count => 2
+ expect(page).to have_selector "a.delete-variant", count: 2
visit spree.admin_products_path
expect(page).to have_selector "a.view-variants"
- all("a.view-variants").select { |e| e.visible? }.each { |e| e.click }
+ all("a.view-variants").select(&:visible?).each(&:click)
- expect(page).to have_selector "a.delete-variant", :count => 2
+ expect(page).to have_selector "a.delete-variant", count: 2
end
end
@@ -517,7 +513,7 @@ feature %q{
end
it "shows an edit button for products, which takes the user to the standard edit page for that product" do
- expect(page).to have_selector "a.edit-product", :count => 2
+ expect(page).to have_selector "a.edit-product", count: 2
within "tr#p_#{p1.id}" do
find("a.edit-product").click
@@ -528,9 +524,9 @@ feature %q{
it "shows an edit button for variants, which takes the user to the standard edit page for that variant" do
expect(page).to have_selector "a.view-variants"
- all("a.view-variants").each { |e| e.click }
+ all("a.view-variants").each(&:click)
- expect(page).to have_selector "a.edit-variant", :count => 2
+ expect(page).to have_selector "a.edit-variant", count: 2
within "tr#v_#{v1.id}" do
find("a.edit-variant").click
@@ -542,27 +538,27 @@ feature %q{
describe "using clone buttons" do
it "shows a clone button for products, which duplicates the product and adds it to the page when clicked" do
- p1 = FactoryBot.create(:product, :name => "P1")
- p2 = FactoryBot.create(:product, :name => "P2")
- p3 = FactoryBot.create(:product, :name => "P3")
+ p1 = FactoryBot.create(:product, name: "P1")
+ p2 = FactoryBot.create(:product, name: "P2")
+ p3 = FactoryBot.create(:product, name: "P3")
quick_login_as_admin
visit spree.admin_products_path
- expect(page).to have_selector "a.clone-product", :count => 3
+ expect(page).to have_selector "a.clone-product", count: 3
within "tr#p_#{p1.id}" do
find("a.clone-product").click
end
- expect(page).to have_selector "a.clone-product", :count => 4
+ expect(page).to have_selector "a.clone-product", count: 4
expect(page).to have_field "product_name", with: "COPY OF #{p1.name}"
- expect(page).to have_select "producer_id", selected: "#{p1.supplier.name}"
+ expect(page).to have_select "producer_id", selected: p1.supplier.name.to_s
visit spree.admin_products_path
- expect(page).to have_selector "a.clone-product", :count => 4
+ expect(page).to have_selector "a.clone-product", count: 4
expect(page).to have_field "product_name", with: "COPY OF #{p1.name}"
- expect(page).to have_select "producer_id", selected: "#{p1.supplier.name}"
+ expect(page).to have_select "producer_id", selected: p1.supplier.name.to_s
end
end
end
@@ -577,19 +573,19 @@ feature %q{
toggle_columns "Available On"
- expect(page).to have_selector "th", :text => "NAME"
- expect(page).to have_selector "th", :text => "PRODUCER"
- expect(page).to have_selector "th", :text => "PRICE"
- expect(page).to have_selector "th", :text => "ON HAND"
- expect(page).to have_selector "th", :text => "AV. ON"
+ expect(page).to have_selector "th", text: "NAME"
+ expect(page).to have_selector "th", text: "PRODUCER"
+ expect(page).to have_selector "th", text: "PRICE"
+ expect(page).to have_selector "th", text: "ON HAND"
+ expect(page).to have_selector "th", text: "AV. ON"
toggle_columns /^.{0,1}Producer$/
- expect(page).to have_no_selector "th", :text => "PRODUCER"
- expect(page).to have_selector "th", :text => "NAME"
- expect(page).to have_selector "th", :text => "PRICE"
- expect(page).to have_selector "th", :text => "ON HAND"
- expect(page).to have_selector "th", :text => "AV. ON"
+ expect(page).to have_no_selector "th", text: "PRODUCER"
+ expect(page).to have_selector "th", text: "NAME"
+ expect(page).to have_selector "th", text: "PRICE"
+ expect(page).to have_selector "th", text: "ON HAND"
+ expect(page).to have_selector "th", text: "AV. ON"
end
end
@@ -597,8 +593,8 @@ feature %q{
it "displays basic filtering controls which filter the product list" do
s1 = create(:supplier_enterprise)
s2 = create(:supplier_enterprise)
- p1 = FactoryBot.create(:simple_product, :name => "product1", supplier: s1)
- p2 = FactoryBot.create(:simple_product, :name => "product2", supplier: s2)
+ p1 = FactoryBot.create(:simple_product, name: "product1", supplier: s1)
+ p2 = FactoryBot.create(:simple_product, name: "product2", supplier: s2)
quick_login_as_admin
visit spree.admin_products_path
@@ -642,7 +638,7 @@ feature %q{
let!(:supplier_permitted_relationship) do
create(:enterprise_relationship, parent: supplier_permitted, child: supplier_managed1,
- permissions_list: [:manage_products])
+ permissions_list: [:manage_products])
end
before do
@@ -717,8 +713,8 @@ feature %q{
expect(page).to have_field "available_on", with: p.available_on.strftime("%F %T")
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")
+ select supplier_managed2.name, from: 'producer_id'
+ fill_in "available_on", with: 3.days.ago.beginning_of_day.strftime("%F %T")
select "Weight (kg)", from: "variant_unit_with_scale"
find("a.view-variants").click
diff --git a/spec/features/admin/caching_spec.rb b/spec/features/admin/caching_spec.rb
index 22d372e19b..dd96a37d8c 100644
--- a/spec/features/admin/caching_spec.rb
+++ b/spec/features/admin/caching_spec.rb
@@ -38,6 +38,5 @@ feature 'Caching' do
# Then I should see some status information
page.should have_content "Error"
end
-
end
end
diff --git a/spec/features/admin/content_spec.rb b/spec/features/admin/content_spec.rb
index daf4cb516a..5e4f0b7d67 100644
--- a/spec/features/admin/content_spec.rb
+++ b/spec/features/admin/content_spec.rb
@@ -1,9 +1,9 @@
require 'spec_helper'
-feature %q{
+feature '
As a site administrator
I want to configure the site content
-} do
+' do
include AuthenticationWorkflow
include WebHelper
diff --git a/spec/features/admin/customers_spec.rb b/spec/features/admin/customers_spec.rb
index da7d9ce942..492aa4e124 100644
--- a/spec/features/admin/customers_spec.rb
+++ b/spec/features/admin/customers_spec.rb
@@ -24,7 +24,7 @@ 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"
@@ -81,7 +81,7 @@ feature 'Customers' do
end
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}
+ }.to_not change{ Customer.count }
expect{
within "tr#c_#{customer2.id}" do
@@ -90,7 +90,7 @@ feature 'Customers' do
end
end
expect(page).to have_no_selector "tr#c_#{customer2.id}"
- }.to change{Customer.count}.by(-1)
+ }.to change{ Customer.count }.by(-1)
end
it "allows updating of attributes" do
@@ -203,7 +203,7 @@ feature 'Customers' do
expect(customer4.reload.bill_address.address1).to eq 'New Address1'
first('#bill-address-link').click
-
+
expect(page).to have_content 'Edit Billing Address'
expect(page).to_not have_content 'Please input all of the required fields'
end
@@ -269,21 +269,21 @@ feature 'Customers' do
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"
- }.to_not change{Customer.of(managed_distributor1).count}
+ }.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"
- }.to_not change{Customer.of(managed_distributor1).count}
+ }.to_not change{ Customer.of(managed_distributor1).count }
# When a new valid email is used
expect{
fill_in 'email', with: "new@email.com"
click_button 'Add Customer'
expect(page).not_to have_selector "#new-customer-dialog"
- }.to change{Customer.of(managed_distributor1).count}.from(2).to(3)
+ }.to change{ Customer.of(managed_distributor1).count }.from(2).to(3)
end
end
end
diff --git a/spec/features/admin/enterprise_fees_spec.rb b/spec/features/admin/enterprise_fees_spec.rb
index 84565da98c..bf7a226955 100644
--- a/spec/features/admin/enterprise_fees_spec.rb
+++ b/spec/features/admin/enterprise_fees_spec.rb
@@ -1,9 +1,9 @@
require 'spec_helper'
-feature %q{
+feature '
As an administrator
I want to manage enterprise fees
-}, js: true do
+', js: true do
include AuthenticationWorkflow
include WebHelper
@@ -167,8 +167,8 @@ feature %q{
within(".side_menu") { click_link 'Enterprise Fees' }
click_link "Manage Enterprise Fees"
expect(page).to have_select('enterprise_fee_set_collection_attributes_0_enterprise_id',
- selected: 'Second Distributor',
- options: ['', 'First Distributor', 'Second Distributor'])
+ selected: 'Second Distributor',
+ options: ['', 'First Distributor', 'Second Distributor'])
end
end
end
diff --git a/spec/features/admin/enterprise_groups_spec.rb b/spec/features/admin/enterprise_groups_spec.rb
index 61751e80c8..328161687f 100644
--- a/spec/features/admin/enterprise_groups_spec.rb
+++ b/spec/features/admin/enterprise_groups_spec.rb
@@ -1,9 +1,9 @@
require 'spec_helper'
-feature %q{
+feature '
As an administrator
I want to manage enterprise groups
-} do
+' do
include AuthenticationWorkflow
include WebHelper
@@ -40,8 +40,8 @@ feature %q{
fill_in 'enterprise_group_address_attributes_address1', with: 'My Street'
fill_in 'enterprise_group_address_attributes_city', with: 'Block'
fill_in 'enterprise_group_address_attributes_zipcode', with: '0000'
- select2_select 'Australia', :from => 'enterprise_group_address_attributes_country_id'
- select2_select 'Victoria', :from => 'enterprise_group_address_attributes_state_id'
+ select2_select 'Australia', from: 'enterprise_group_address_attributes_country_id'
+ select2_select 'Victoria', from: 'enterprise_group_address_attributes_state_id'
click_button 'Create'
page.should have_content 'Enterprise group "EGEGEG" has been successfully created!'
diff --git a/spec/features/admin/enterprise_relationships_spec.rb b/spec/features/admin/enterprise_relationships_spec.rb
index de77f79dd2..dc5769c3b7 100644
--- a/spec/features/admin/enterprise_relationships_spec.rb
+++ b/spec/features/admin/enterprise_relationships_spec.rb
@@ -1,13 +1,12 @@
require 'spec_helper'
-feature %q{
+feature '
As an Administrator
I want to manage relationships between enterprises
-}, js: true do
+', js: true do
include AuthenticationWorkflow
include WebHelper
-
context "as a site administrator" do
before { quick_login_as_admin }
@@ -28,11 +27,10 @@ feature %q{
page.should have_relationship e1, e2, ['to add to order cycle']
page.should have_relationship e2, e3, ['to manage products']
page.should have_relationship e3, e4,
- ['to add to order cycle', 'to manage products']
+ ['to add to order cycle', 'to manage products']
end
end
-
scenario "creating a relationship" do
e1 = create(:enterprise, name: 'One')
e2 = create(:enterprise, name: 'Two')
@@ -56,7 +54,6 @@ feature %q{
er.permissions.map(&:name).should match_array ['add_to_order_cycle', 'edit_profile', 'create_variant_overrides']
end
-
scenario "attempting to create a relationship with invalid data" do
e1 = create(:enterprise, name: 'One')
e2 = create(:enterprise, name: 'Two')
@@ -91,7 +88,6 @@ feature %q{
end
end
-
context "as an enterprise user" do
let!(:d1) { create(:distributor_enterprise) }
let!(:d2) { create(:distributor_enterprise) }
@@ -119,10 +115,9 @@ feature %q{
end
end
-
private
- def have_relationship(parent, child, perms=[])
+ def have_relationship(parent, child, perms = [])
perms = perms.join(' ')
have_table_row [parent.name, 'permits', child.name, perms, '']
diff --git a/spec/features/admin/enterprise_roles_spec.rb b/spec/features/admin/enterprise_roles_spec.rb
index d0aa59c766..99ece94d3c 100644
--- a/spec/features/admin/enterprise_roles_spec.rb
+++ b/spec/features/admin/enterprise_roles_spec.rb
@@ -1,14 +1,13 @@
require 'spec_helper'
-feature %q{
+feature '
As an Administrator
I want to manage relationships between users and enterprises
-}, js: true do
+', js: true do
include AuthenticationWorkflow
include WebHelper
include OpenFoodNetwork::EmailHelper
-
context "as a site administrator" do
before { login_to_admin_section }
diff --git a/spec/features/admin/enterprise_user_spec.rb b/spec/features/admin/enterprise_user_spec.rb
index 1408fddc02..cc6f9e20f2 100644
--- a/spec/features/admin/enterprise_user_spec.rb
+++ b/spec/features/admin/enterprise_user_spec.rb
@@ -1,9 +1,9 @@
require "spec_helper"
-feature %q{
+feature '
As a Super User
I want to setup users to manage an enterprise
-} do
+' do
include AuthenticationWorkflow
include WebHelper
diff --git a/spec/features/admin/enterprises/index_spec.rb b/spec/features/admin/enterprises/index_spec.rb
index 0c10df718e..364387207d 100644
--- a/spec/features/admin/enterprises/index_spec.rb
+++ b/spec/features/admin/enterprises/index_spec.rb
@@ -137,7 +137,6 @@ feature 'Enterprises Index' do
expect(find("#content-header")).to have_link "New Enterprise"
end
-
it "does not give me an option to change or update the package and producer properties of enterprises I manage" do
visit admin_enterprises_path
diff --git a/spec/features/admin/enterprises_spec.rb b/spec/features/admin/enterprises_spec.rb
index 549b97f782..ac2c0b462b 100644
--- a/spec/features/admin/enterprises_spec.rb
+++ b/spec/features/admin/enterprises_spec.rb
@@ -1,9 +1,9 @@
require "spec_helper"
-feature %q{
+feature '
As an administrator
I want to manage enterprises
-} do
+' do
include AuthenticationWorkflow
include WebHelper
@@ -37,18 +37,18 @@ feature %q{
page.should_not have_checked_field "enterprise_shipping_method_ids_#{shipping_method.id}"
# Filling in details
- fill_in 'enterprise_name', :with => 'Eaterprises'
+ fill_in 'enterprise_name', with: 'Eaterprises'
select2_select admin.email, from: 'enterprise_owner_id'
- fill_in 'enterprise_contact_name', :with => 'Kirsten or Ren'
- fill_in 'enterprise_phone', :with => '0413 897 321'
- fill_in 'enterprise_email_address', :with => 'info@eaterprises.com.au'
- fill_in 'enterprise_website', :with => 'http://eaterprises.com.au'
+ fill_in 'enterprise_contact_name', with: 'Kirsten or Ren'
+ fill_in 'enterprise_phone', with: '0413 897 321'
+ fill_in 'enterprise_email_address', with: 'info@eaterprises.com.au'
+ fill_in 'enterprise_website', with: 'http://eaterprises.com.au'
- fill_in 'enterprise_address_attributes_address1', :with => '35 Ballantyne St'
- fill_in 'enterprise_address_attributes_city', :with => 'Thornbury'
- fill_in 'enterprise_address_attributes_zipcode', :with => '3072'
+ fill_in 'enterprise_address_attributes_address1', with: '35 Ballantyne St'
+ fill_in 'enterprise_address_attributes_city', with: 'Thornbury'
+ fill_in 'enterprise_address_attributes_zipcode', with: '3072'
# default country (Australia in this test) should be selected by default
select2_select 'Victoria', from: 'enterprise_address_attributes_state_id'
@@ -73,7 +73,7 @@ feature %q{
first("a", text: 'Settings').click
end
- fill_in 'enterprise_name', :with => 'Eaterprises'
+ fill_in 'enterprise_name', with: 'Eaterprises'
fill_in 'enterprise_permalink', with: 'eaterprises-permalink'
page.should have_selector '.available'
choose 'Own'
@@ -97,7 +97,7 @@ feature %q{
accept_alert do
click_link "About"
end
- fill_in 'enterprise_description', :with => 'Connecting farmers and eaters'
+ fill_in 'enterprise_description', with: 'Connecting farmers and eaters'
description_input = page.find("text-angular#enterprise_long_description div[id^='taTextElement']")
description_input.native.send_keys('This is an interesting long description')
@@ -142,31 +142,31 @@ feature %q{
accept_alert do
click_link "Contact"
end
- fill_in 'enterprise_contact_name', :with => 'Kirsten or Ren'
- fill_in 'enterprise_phone', :with => '0413 897 321'
- fill_in 'enterprise_email_address', :with => 'info@eaterprises.com.au'
- fill_in 'enterprise_website', :with => 'http://eaterprises.com.au'
+ fill_in 'enterprise_contact_name', with: 'Kirsten or Ren'
+ fill_in 'enterprise_phone', with: '0413 897 321'
+ fill_in 'enterprise_email_address', with: 'info@eaterprises.com.au'
+ fill_in 'enterprise_website', with: 'http://eaterprises.com.au'
accept_alert do
click_link "Social"
end
- fill_in 'enterprise_twitter', :with => '@eaterprises'
+ fill_in 'enterprise_twitter', with: '@eaterprises'
accept_alert do
click_link "Business Details"
end
- fill_in 'enterprise_abn', :with => '09812309823'
- fill_in 'enterprise_acn', :with => ''
+ fill_in 'enterprise_abn', with: '09812309823'
+ fill_in 'enterprise_acn', with: ''
choose 'Yes' # enterprise_charges_sales_tax
accept_alert do
click_link "Address"
end
- fill_in 'enterprise_address_attributes_address1', :with => '35 Ballantyne St'
- fill_in 'enterprise_address_attributes_city', :with => 'Thornbury'
- fill_in 'enterprise_address_attributes_zipcode', :with => '3072'
+ fill_in 'enterprise_address_attributes_address1', with: '35 Ballantyne St'
+ fill_in 'enterprise_address_attributes_city', with: 'Thornbury'
+ fill_in 'enterprise_address_attributes_zipcode', with: '3072'
# default country (Australia in this test) should be selected by default
- select2_select 'Victoria', :from => 'enterprise_address_attributes_state_id'
+ select2_select 'Victoria', from: 'enterprise_address_attributes_state_id'
accept_alert do
click_link "Shop Preferences"
@@ -180,7 +180,7 @@ feature %q{
click_button 'Update'
flash_message.should == 'Enterprise "Eaterprises" has been successfully updated!'
- page.should have_field 'enterprise_name', :with => 'Eaterprises'
+ page.should have_field 'enterprise_name', with: 'Eaterprises'
@enterprise.reload
expect(@enterprise.owner).to eq user
expect(page).to have_checked_field "enterprise_visible_true"
@@ -281,7 +281,6 @@ feature %q{
end
end
-
describe "inventory settings", js: true do
let!(:enterprise) { create(:distributor_enterprise) }
let!(:product) { create(:simple_product) }
@@ -392,7 +391,7 @@ feature %q{
visit admin_enterprises_path
within("tbody#e_#{distributor1.id}") { click_link 'Settings' }
- fill_in 'enterprise_name', :with => 'Eaterprises'
+ fill_in 'enterprise_name', with: 'Eaterprises'
# Because poltergist does not support form onchange event
# We need trigger the change manually
@@ -408,7 +407,7 @@ feature %q{
visit admin_enterprises_path
within("tbody#e_#{distributor3.id}") { click_link 'Settings' }
- fill_in 'enterprise_name', :with => 'Eaterprises'
+ fill_in 'enterprise_name', with: 'Eaterprises'
# Because poltergist does not support form onchange event
# We need trigger the change manually
diff --git a/spec/features/admin/image_settings_spec.rb b/spec/features/admin/image_settings_spec.rb
index a83a072235..d97442632b 100644
--- a/spec/features/admin/image_settings_spec.rb
+++ b/spec/features/admin/image_settings_spec.rb
@@ -1,17 +1,17 @@
require 'spec_helper'
-feature %q{
+feature '
As an admin
I want to manage image formats
-} do
+' do
include AuthenticationWorkflow
include WebHelper
before(:all) do
- styles = {"mini" => "48x48>",
- "small" => "100x100>",
- "product" => "240x240>",
- "large" => "600x600>"}
+ styles = { "mini" => "48x48>",
+ "small" => "100x100>",
+ "product" => "240x240>",
+ "large" => "600x600>" }
Spree::Config[:attachment_styles] = ActiveSupport::JSON.encode(styles)
Spree::Image.attachment_definitions[:attachment][:styles] = ActiveSupport::JSON.decode(Spree::Config[:attachment_styles])
diff --git a/spec/features/admin/order_cycles_spec.rb b/spec/features/admin/order_cycles_spec.rb
index 7f2df5eb61..a8d3c715ec 100644
--- a/spec/features/admin/order_cycles_spec.rb
+++ b/spec/features/admin/order_cycles_spec.rb
@@ -1,9 +1,9 @@
require 'spec_helper'
-feature %q{
+feature '
As an administrator
I want to manage order cycles
-}, js: true do
+', js: true do
include AdminHelper
include AuthenticationWorkflow
include WebHelper
@@ -11,19 +11,19 @@ feature %q{
scenario "listing and filtering order cycles" do
# Given some order cycles (created in an arbitrary order)
oc4 = create(:simple_order_cycle, name: 'oc4',
- orders_open_at: 2.day.from_now, orders_close_at: 1.month.from_now)
+ orders_open_at: 2.days.from_now, orders_close_at: 1.month.from_now)
oc2 = create(:simple_order_cycle, name: 'oc2', orders_close_at: 1.month.from_now)
oc6 = create(:simple_order_cycle, name: 'oc6',
- orders_open_at: 1.month.ago, orders_close_at: 3.weeks.ago)
+ orders_open_at: 1.month.ago, orders_close_at: 3.weeks.ago)
oc3 = create(:simple_order_cycle, name: 'oc3',
- orders_open_at: 1.day.from_now, orders_close_at: 1.month.from_now)
+ orders_open_at: 1.day.from_now, orders_close_at: 1.month.from_now)
oc5 = create(:simple_order_cycle, name: 'oc5',
- orders_open_at: 1.month.ago, orders_close_at: 2.weeks.ago)
+ orders_open_at: 1.month.ago, orders_close_at: 2.weeks.ago)
oc1 = create(:order_cycle, name: 'oc1')
oc0 = create(:simple_order_cycle, name: 'oc0',
- orders_open_at: nil, orders_close_at: nil)
+ orders_open_at: nil, orders_close_at: nil)
oc7 = create(:simple_order_cycle, name: 'oc7',
- orders_open_at: 2.months.ago, orders_close_at: 5.weeks.ago)
+ orders_open_at: 2.months.ago, orders_close_at: 5.weeks.ago)
schedule1 = create(:schedule, name: 'Schedule1', order_cycles: [oc1, oc3])
create(:proxy_order, subscription: create(:subscription, schedule: schedule1), order_cycle: oc1)
@@ -150,8 +150,8 @@ feature %q{
end
context "with specific time" do
- let(:order_cycle_opening_time) { Time.zone.local(2040, 11, 06, 06, 00, 00).strftime("%F %T %z") }
- let(:order_cycle_closing_time) { Time.zone.local(2040, 11, 13, 17, 00, 00).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 "creating an order cycle", js: true do
# Given coordinating, supplying and distributing enterprises with some products with variants
@@ -324,7 +324,7 @@ feature %q{
# And I add a supplier and some products
select 'My supplier', from: 'new_supplier_id'
click_button 'Add supplier'
- page.all("table.exchanges tr.supplier td.products").each { |e| e.click }
+ page.all("table.exchanges tr.supplier td.products").each(&:click)
page.should 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)
@@ -357,7 +357,7 @@ feature %q{
find(:css, "tags-input .tags input").set "wholesale\n"
end
- page.all("table.exchanges tr.distributor td.products").each { |e| e.click }
+ page.all("table.exchanges tr.distributor td.products").each(&:click)
uncheck "order_cycle_outgoing_exchange_2_variants_#{v1.id}"
check "order_cycle_outgoing_exchange_2_variants_#{v2.id}"
@@ -434,8 +434,8 @@ feature %q{
page.should have_content "COORDINATOR #{oc.coordinator.name}"
# And I should see the suppliers
- page.should have_selector 'td.supplier_name', :text => oc.suppliers.first.name
- page.should have_selector 'td.supplier_name', :text => oc.suppliers.last.name
+ page.should have_selector 'td.supplier_name', text: oc.suppliers.first.name
+ page.should have_selector 'td.supplier_name', text: oc.suppliers.last.name
page.should have_field 'order_cycle_incoming_exchange_0_receival_instructions', with: 'instructions 0'
page.should have_field 'order_cycle_incoming_exchange_1_receival_instructions', with: 'instructions 1'
@@ -444,24 +444,24 @@ feature %q{
page.all('table.exchanges tbody tr.supplier').each_with_index do |row, i|
row.find('td.products').click
- products_panel = page.all('table.exchanges tr.panel-row .exchange-supplied-products').select { |r| r.visible? }.first
+ products_panel = page.all('table.exchanges tr.panel-row .exchange-supplied-products').select(&:visible?).first
products_panel.should have_selector "input[name='order_cycle_incoming_exchange_#{i}_select_all_variants']"
row.find('td.products').click
end
# And the suppliers should have fees
- supplier = oc.suppliers.sort_by(&:name).first
+ supplier = oc.suppliers.min_by(&:name)
page.should have_select 'order_cycle_incoming_exchange_0_enterprise_fees_0_enterprise_id', selected: supplier.name
page.should have_select 'order_cycle_incoming_exchange_0_enterprise_fees_0_enterprise_fee_id', selected: supplier.enterprise_fees.first.name
- supplier = oc.suppliers.sort_by(&:name).last
+ supplier = oc.suppliers.max_by(&:name)
page.should have_select 'order_cycle_incoming_exchange_1_enterprise_fees_0_enterprise_id', selected: supplier.name
page.should have_select 'order_cycle_incoming_exchange_1_enterprise_fees_0_enterprise_fee_id', selected: supplier.enterprise_fees.first.name
# And I should see the distributors
- page.should have_selector 'td.distributor_name', :text => oc.distributors.first.name
- page.should have_selector 'td.distributor_name', :text => oc.distributors.last.name
+ page.should have_selector 'td.distributor_name', text: oc.distributors.first.name
+ page.should have_selector 'td.distributor_name', text: oc.distributors.last.name
page.should have_field 'order_cycle_outgoing_exchange_0_pickup_time', with: 'time 0'
page.should have_field 'order_cycle_outgoing_exchange_0_pickup_instructions', with: 'instructions 0'
@@ -472,23 +472,22 @@ feature %q{
page.all('table.exchanges tbody tr.distributor').each_with_index do |row, i|
row.find('td.products').click
- products_panel = page.all('table.exchanges tr.panel-row .exchange-distributed-products').select { |r| r.visible? }.first
+ products_panel = page.all('table.exchanges tr.panel-row .exchange-distributed-products').select(&:visible?).first
products_panel.should have_selector "input[name='order_cycle_outgoing_exchange_#{i}_select_all_variants']"
row.find('td.products').click
end
# And the distributors should have fees
- distributor = oc.distributors.sort_by(&:id).first
+ distributor = oc.distributors.min_by(&:id)
page.should have_select 'order_cycle_outgoing_exchange_0_enterprise_fees_0_enterprise_id', selected: distributor.name
page.should have_select 'order_cycle_outgoing_exchange_0_enterprise_fees_0_enterprise_fee_id', selected: distributor.enterprise_fees.first.name
- distributor = oc.distributors.sort_by(&:id).last
+ distributor = oc.distributors.max_by(&:id)
page.should have_select 'order_cycle_outgoing_exchange_1_enterprise_fees_0_enterprise_id', selected: distributor.name
page.should have_select 'order_cycle_outgoing_exchange_1_enterprise_fees_0_enterprise_fee_id', selected: distributor.enterprise_fees.first.name
end
-
scenario "editing an order cycle with an exchange between the same enterprise" do
c = create(:distributor_enterprise, is_primary_producer: true)
@@ -515,10 +514,8 @@ feature %q{
oc1 = create(:simple_order_cycle)
oc2 = create(:simple_order_cycle)
oc3 = create(:simple_order_cycle,
- orders_open_at: Time.zone.local(2040, 12, 12, 12, 12, 12),
- orders_close_at: Time.zone.local(2041, 12, 12, 12, 12, 12)
- )
-
+ orders_open_at: Time.zone.local(2040, 12, 12, 12, 12, 12),
+ orders_close_at: Time.zone.local(2041, 12, 12, 12, 12, 12))
# When I go to the order cycles page
quick_login_as_admin
@@ -591,7 +588,6 @@ feature %q{
expect(occ.name).to eq "COPY OF #{oc.name}"
end
-
scenario "removing a master variant from an order cycle when further variants have been added" do
# Given a product with a variant, with its master variant included in the order cycle
# (this usually happens when a product is added to an order cycle, then variants are added
@@ -616,7 +612,6 @@ feature %q{
ExchangeVariant.where(exchange_id: exchange_ids, variant_id: p.master.id).should be_empty
end
-
describe "ensuring that hubs in order cycles have valid shipping and payment methods" do
context "when they don't" do
let(:hub) { create(:distributor_enterprise) }
@@ -685,8 +680,8 @@ feature %q{
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_path
click_link "Order Cycles"
@@ -767,7 +762,7 @@ feature %q{
# editable, but at this point we cannot distiguish between visible and editable
# variants.
- 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' )
visit edit_admin_order_cycle_path(oc)
@@ -795,7 +790,7 @@ feature %q{
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)
@@ -844,7 +839,7 @@ feature %q{
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) )
@@ -860,7 +855,7 @@ feature %q{
serializer = Api::Admin::OrderCycleSerializer.new(oc, current_user: new_user)
allow(Api::Admin::OrderCycleSerializer).to receive(:new) { serializer }
allow(serializer).to receive(:editable_variants_for_outgoing_exchanges) do
- { "#{distributor_managed.id}" => [v1.id] }
+ { distributor_managed.id.to_s => [v1.id] }
end
visit edit_admin_order_cycle_path(oc)
@@ -912,7 +907,7 @@ feature %q{
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) )
@@ -928,7 +923,7 @@ feature %q{
serializer = Api::Admin::OrderCycleSerializer.new(oc, current_user: new_user)
allow(Api::Admin::OrderCycleSerializer).to receive(:new) { serializer }
allow(serializer).to receive(:editable_variants_for_incoming_exchanges) do
- { "#{supplier_managed.id}" => [v1.id] }
+ { supplier_managed.id.to_s => [v1.id] }
end
visit edit_admin_order_cycle_path(oc)
@@ -966,7 +961,6 @@ feature %q{
end
end
-
describe "simplified interface for enterprise users selling only their own produce" do
let(:user) { create_enterprise_user }
let(:enterprise) { create(:enterprise, is_primary_producer: true, sells: 'own') }
@@ -1027,8 +1021,8 @@ feature %q{
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, 06, 00, 00).strftime("%F %T %z")
- expect(page).to have_input "oc#{oc.id}[orders_close_at]", value: Time.zone.local(2040, 10, 24, 17, 00, 00).strftime("%F %T %z")
+ 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")
+ 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")
# And it should have some variants selected
oc.exchanges.incoming.first.variants.count.should == 2
@@ -1120,8 +1114,8 @@ feature %q{
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, 06, 00, 00).strftime("%F %T %z")
- expect(page).to have_input "oc#{oc.id}[orders_close_at]", value: Time.zone.local(2040, 10, 24, 17, 00, 00).strftime("%F %T %z")
+ 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")
+ 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")
# And it should have a variant selected
oc.exchanges.incoming.first.variants.should == [v2]
@@ -1148,7 +1142,6 @@ feature %q{
expect(page).to_not have_selector "tr.order-cycle-#{order_cycle.id}"
end
-
private
def wait_for_edit_form_to_load_order_cycle(order_cycle)
diff --git a/spec/features/admin/orders_spec.rb b/spec/features/admin/orders_spec.rb
index f6748903e6..3b54d31cdb 100644
--- a/spec/features/admin/orders_spec.rb
+++ b/spec/features/admin/orders_spec.rb
@@ -1,10 +1,10 @@
require "spec_helper"
include ActionView::Helpers::NumberHelper
-feature %q{
+feature '
As an administrator
I want to manage orders
-}, js: true do
+', js: true do
include AuthenticationWorkflow
include WebHelper
include CheckoutHelper
@@ -73,7 +73,7 @@ feature %q{
expect(page).to have_content 'ADD PRODUCT'
targetted_select2_search @product.name, from: '#add_variant_id', dropdown_css: '.select2-drop'
find('button.add_variant').click
- page.has_selector? "table.index tbody[data-hook='admin_order_form_line_items'] tr" # Wait for JS
+ page.has_selector? "table.index tbody[data-hook='admin_order_form_line_items'] tr" # Wait for JS
expect(page).to have_selector 'td', text: @product.name
click_button 'Update'
@@ -123,7 +123,6 @@ feature %q{
expect(page).to have_content "Distributor or order cycle cannot supply the products in your cart"
end
-
scenario "can't add products to an order outside the order's hub and order cycle" do
product = create(:simple_product)
@@ -164,7 +163,7 @@ feature %q{
new_order_with_distribution(@distributor, @order_cycle)
targetted_select2_search @product.name, from: '#add_variant_id', dropdown_css: '.select2-drop'
find('button.add_variant').click
- page.has_selector? "table.index tbody[data-hook='admin_order_form_line_items'] tr" # Wait for JS
+ page.has_selector? "table.index tbody[data-hook='admin_order_form_line_items'] tr" # Wait for JS
click_button 'Update'
expect(page).to have_selector 'h1.page-title', text: "Customer Details"
@@ -282,7 +281,7 @@ feature %q{
expect(page).to have_link "Resend Confirmation", 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
@@ -372,7 +371,7 @@ feature %q{
targetted_select2_search product.name, from: '#add_variant_id', dropdown_css: '.select2-drop'
find('button.add_variant').click
- page.has_selector? "table.index tbody[data-hook='admin_order_form_line_items'] tr" # Wait for JS
+ page.has_selector? "table.index tbody[data-hook='admin_order_form_line_items'] tr" # Wait for JS
expect(page).to have_selector 'td', text: product.name
expect(page).to have_select2 'order_distributor_id', with_options: [distributor1.name]
diff --git a/spec/features/admin/overview_spec.rb b/spec/features/admin/overview_spec.rb
index 47e8d878a7..b1ff6e12e6 100644
--- a/spec/features/admin/overview_spec.rb
+++ b/spec/features/admin/overview_spec.rb
@@ -1,9 +1,9 @@
require 'spec_helper'
-feature %q{
+feature '
As a backend user
I want to be given information about the state of my enterprises, products and order cycles
-}, js: true do
+', js: true do
include AuthenticationWorkflow
include WebHelper
include ::Spree::TestingSupport::AuthorizationHelpers
diff --git a/spec/features/admin/payment_method_spec.rb b/spec/features/admin/payment_method_spec.rb
index e53af5e1bf..5b932d3122 100644
--- a/spec/features/admin/payment_method_spec.rb
+++ b/spec/features/admin/payment_method_spec.rb
@@ -1,9 +1,9 @@
require "spec_helper"
-feature %q{
+feature '
As a Super Admin
I want to be able to set a distributor on each payment method
-} do
+' do
include AuthenticationWorkflow
include WebHelper
@@ -19,7 +19,7 @@ feature %q{
click_link 'Payment Methods'
click_link 'New Payment Method'
- fill_in 'payment_method_name', :with => 'Cheque payment method'
+ fill_in 'payment_method_name', with: 'Cheque payment method'
check "payment_method_distributor_ids_#{@distributors[0].id}"
click_button 'Create'
@@ -75,7 +75,7 @@ feature %q{
visit spree.edit_admin_payment_method_path pm
- fill_in 'payment_method_name', :with => 'New PM Name'
+ fill_in 'payment_method_name', with: 'New PM Name'
find(:css, "tags-input .tags input").set "member\n"
uncheck "payment_method_distributor_ids_#{@distributors[0].id}"
@@ -142,7 +142,7 @@ feature %q{
it "creates payment methods" do
visit spree.new_admin_payment_method_path
- fill_in 'payment_method_name', :with => 'Cheque payment method'
+ fill_in 'payment_method_name', with: 'Cheque payment method'
check "payment_method_distributor_ids_#{distributor1.id}"
find(:css, "tags-input .tags input").set "local\n"
diff --git a/spec/features/admin/product_import_spec.rb b/spec/features/admin/product_import_spec.rb
index 35d6cb4c29..7277a6ac47 100644
--- a/spec/features/admin/product_import_spec.rb
+++ b/spec/features/admin/product_import_spec.rb
@@ -239,7 +239,6 @@ feature "Product Import", js: true do
expect(big_bag.product.id).to eq small_bag.product.id
end
-
it "can import items into inventory" do
csv_data = CSV.generate do |csv|
csv << ["name", "distributor", "producer", "category", "on_hand", "price", "units"]
@@ -437,7 +436,7 @@ feature "Product Import", js: true do
proceed_to_validation
# Check that all rows are validated.
- heading = "120 #{I18n.t("admin.product_import.import.products_to_create")}"
+ heading = "120 #{I18n.t('admin.product_import.import.products_to_create')}"
find(".panel-header", text: heading).click
expect(page).to have_content "Imported Product 10"
expect(page).to have_content "Imported Product 60"
diff --git a/spec/features/admin/products_spec.rb b/spec/features/admin/products_spec.rb
index af8112584e..61b5b19945 100644
--- a/spec/features/admin/products_spec.rb
+++ b/spec/features/admin/products_spec.rb
@@ -1,19 +1,18 @@
require "spec_helper"
-feature %q{
+feature '
As an admin
I want to set a supplier and distributor(s) for a product
-} do
+' do
include AuthenticationWorkflow
include WebHelper
-
let!(:taxon) { create(:taxon) }
let!(:stock_location) { create(:stock_location, backorderable_default: false) }
let!(:shipping_category) { create(:shipping_category, name: 'Test Shipping Category') }
background do
- @supplier = create(:supplier_enterprise, :name => 'New supplier')
+ @supplier = create(:supplier_enterprise, name: 'New supplier')
@distributors = (1..3).map { create(:distributor_enterprise) }
@enterprise_fees = (0..2).map { |i| create(:enterprise_fee, enterprise: @distributors[i]) }
end
@@ -98,7 +97,7 @@ feature %q{
@new_user.enterprise_roles.build(enterprise: @supplier2).save
@new_user.enterprise_roles.build(enterprise: @distributors[0]).save
create(:enterprise_relationship, parent: @supplier_permitted, child: @supplier2,
- permissions_list: [:manage_products])
+ permissions_list: [:manage_products])
quick_login_as @new_user
end
@@ -109,11 +108,11 @@ feature %q{
visit spree.admin_products_path
click_link 'New Product'
- fill_in 'product_name', :with => 'A new product !!!'
- fill_in 'product_price', :with => '19.99'
+ fill_in 'product_name', with: 'A new product !!!'
+ fill_in 'product_price', with: '19.99'
page.should have_selector('#product_supplier_id')
- select 'Another Supplier', :from => 'product_supplier_id'
+ select 'Another Supplier', from: 'product_supplier_id'
select 'Weight (g)', from: 'product_variant_unit_with_scale'
fill_in 'product_unit_value_with_description', with: '500'
select taxon.name, from: "product_primary_taxon_id"
@@ -154,7 +153,7 @@ feature %q{
visit spree.edit_admin_product_path product
within('#sidebar') { click_link 'Group Buy Options' }
choose('product_group_buy_1')
- fill_in 'Bulk unit size', :with => '10'
+ fill_in 'Bulk unit size', with: '10'
click_button 'Update'
@@ -168,8 +167,8 @@ feature %q{
product = product = create(:simple_product, supplier: @supplier2)
visit spree.edit_admin_product_path product
within('#sidebar') { click_link 'Search' }
- fill_in 'Product Search Keywords', :with => 'Product Search Keywords'
- fill_in 'Notes', :with => 'Just testing Notes'
+ fill_in 'Product Search Keywords', with: 'Product Search Keywords'
+ fill_in 'Notes', with: 'Just testing Notes'
click_button 'Update'
expect(flash_message).to eq("Product \"#{product.name}\" has been successfully updated!")
product.reload
@@ -199,11 +198,10 @@ feature %q{
expect(p.reload.property('fooprop')).to be_nil
end
-
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', __FILE__))
- Spree::Image.create({:viewable_id => product.master.id, :viewable_type => 'Spree::Variant', :alt => "position 1", :attachment => image, :position => 1})
+ 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)
visit spree.admin_product_images_path(product)
page.should have_selector "table[data-hook='images_table'] td img"
diff --git a/spec/features/admin/reports_spec.rb b/spec/features/admin/reports_spec.rb
index 5460567da8..4d1f6b36d9 100644
--- a/spec/features/admin/reports_spec.rb
+++ b/spec/features/admin/reports_spec.rb
@@ -1,9 +1,9 @@
require "spec_helper"
-feature %q{
+feature '
As an administrator
I want numbers, all the numbers!
-} do
+' do
include AuthenticationWorkflow
include WebHelper
@@ -11,8 +11,8 @@ feature %q{
context "As an enterprise user" do
let(:user) do
create_enterprise_user(enterprises: [
- create(:distributor_enterprise)
- ])
+ create(:distributor_enterprise)
+ ])
end
it "does not show super admin only reports" do
login_to_admin_as user
@@ -98,8 +98,8 @@ feature %q{
let(:bill_address1) { create(:address, lastname: "Aman") }
let(:bill_address2) { create(:address, lastname: "Bman") }
- let(:distributor_address) { create(:address, :address1 => "distributor address", :city => 'The Shire', :zipcode => "1234") }
- let(:distributor) { create(:distributor_enterprise, :address => distributor_address) }
+ 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) }
let(:supplier) { create(:supplier_enterprise, name: "Supplier") }
@@ -115,14 +115,13 @@ feature %q{
create(:line_item_with_shipment, variant: variant_1, quantity: 1, order: order1)
create(:line_item_with_shipment, variant: variant_2, quantity: 3, order: order1)
create(:line_item_with_shipment, variant: product_2.master, quantity: 3, order: order2)
-
end
scenario "Pack By Customer" do
click_link "Pack By Customer"
fill_in 'q_completed_at_gt', with: '2013-04-25 13:00:00'
fill_in 'q_completed_at_lt', with: '2013-04-25 16:00:00'
- #select 'Pack By Customer', from: 'report_type'
+ # select 'Pack By Customer', from: 'report_type'
click_button 'Search'
rows = find("table#listing_orders").all("thead tr")
@@ -137,7 +136,7 @@ feature %q{
click_link "Pack By Supplier"
fill_in 'q_completed_at_gt', with: '2013-04-25 13:00:00'
fill_in 'q_completed_at_lt', with: '2013-04-25 16:00:00'
- #select 'Pack By Customer', from: 'report_type'
+ # select 'Pack By Customer', from: 'report_type'
click_button 'Search'
rows = find("table#listing_orders").all("thead tr")
@@ -149,7 +148,6 @@ feature %q{
end
end
-
scenario "orders and distributors report" do
quick_login_as_admin
visit spree.admin_reports_path
@@ -221,7 +219,7 @@ feature %q{
click_button 'Search'
# Then I should see the relevant order
- expect(page).to have_content "#{order1.number}"
+ expect(page).to have_content order1.number.to_s
# And the totals and sales tax should be correct
expect(page).to have_content "1512.99" # items total
@@ -249,19 +247,19 @@ feature %q{
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) { create(:distributor_enterprise, :address => distributor_address) }
+ 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! }
Timecop.travel(Time.zone.local(2013, 4, 25, 16, 0, 0)) { order2.finalize! }
- create(:line_item_with_shipment, :product => product, :order => order1)
- create(:line_item_with_shipment, :product => product, :order => order2)
+ create(:line_item_with_shipment, product: product, order: order1)
+ create(:line_item_with_shipment, product: product, order: order2)
end
it "is precise to time of day, not just date" do
@@ -311,8 +309,8 @@ feature %q{
variant2.update_column(:sku, "sku2")
variant3.on_hand = 9
variant3.update_column(:sku, "")
- variant1.option_values = [create(:option_value, :presentation => "Test")]
- variant2.option_values = [create(:option_value, :presentation => "Something")]
+ variant1.option_values = [create(:option_value, presentation: "Test")]
+ variant2.option_values = [create(:option_value, presentation: "Something")]
end
it "shows products and inventory report" do
@@ -362,20 +360,20 @@ feature %q{
table = rows.map { |r| r.all("th,td").map { |c| c.text.strip }[0..2] }
expect(table.sort).to eq([
- [ "User", "Relationship", "Enterprise" ],
- [ enterprise1.owner.email, "owns", enterprise1.name ],
- [ enterprise1.owner.email, "manages", enterprise1.name ],
- [ enterprise2.owner.email, "owns", enterprise2.name ],
- [ enterprise2.owner.email, "manages", enterprise2.name ],
- [ enterprise3.owner.email, "owns", enterprise3.name ],
- [ enterprise3.owner.email, "manages", enterprise3.name ],
- [ enterprise1.owner.email, "manages", enterprise3.name ]
+ ["User", "Relationship", "Enterprise"],
+ [enterprise1.owner.email, "owns", enterprise1.name],
+ [enterprise1.owner.email, "manages", enterprise1.name],
+ [enterprise2.owner.email, "owns", enterprise2.name],
+ [enterprise2.owner.email, "manages", enterprise2.name],
+ [enterprise3.owner.email, "owns", enterprise3.name],
+ [enterprise3.owner.email, "manages", enterprise3.name],
+ [enterprise1.owner.email, "manages", enterprise3.name]
].sort)
end
it "filters the list" do
select enterprise3.name, from: "enterprise_id_in"
- select enterprise1.owner.email, from: "user_id_in"
+ select enterprise1.owner.email, from: "user_id_in"
click_button "Search"
@@ -383,8 +381,8 @@ feature %q{
table = rows.map { |r| r.all("th,td").map { |c| c.text.strip }[0..2] }
expect(table.sort).to eq([
- [ "User", "Relationship", "Enterprise" ],
- [ enterprise1.owner.email, "manages", enterprise3.name ]
+ ["User", "Relationship", "Enterprise"],
+ [enterprise1.owner.email, "manages", enterprise3.name]
].sort)
end
end
@@ -460,7 +458,7 @@ feature %q{
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,
@@ -503,22 +501,22 @@ feature %q{
%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={})
+ def xero_invoice_summary_row(description, amount, tax_type, opts = {})
xero_invoice_row '', description, amount, '1', tax_type, opts
end
- def xero_invoice_li_row(line_item, opts={})
+ 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
end
- def xero_invoice_adjustment_row(adjustment, opts={})
+ def xero_invoice_adjustment_row(adjustment, opts = {})
tax_type = adjustment.has_tax? ? 'GST on Income' : 'GST Free Income'
xero_invoice_row('', adjustment.label, adjustment.amount, '1', tax_type, opts)
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: country.name, invoice_number: order1.number, order_number: order1.number, invoice_date: '2015-04-26', due_date: '2015-05-26', account_code: 'food sales'})
+ 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: country.name, 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/shipping_methods_spec.rb b/spec/features/admin/shipping_methods_spec.rb
index 7e22886ffb..53e58c595a 100644
--- a/spec/features/admin/shipping_methods_spec.rb
+++ b/spec/features/admin/shipping_methods_spec.rb
@@ -46,12 +46,11 @@ feature 'shipping methods' do
it "at checkout, user can only see shipping methods for their current distributor (checkout spec)"
-
scenario "deleting a shipping method" do
visit_delete spree.admin_shipping_method_path(@sm)
expect(page).to have_content "Shipping method \"#{@sm.name}\" has been successfully removed!"
- expect(Spree::ShippingMethod.where(:id => @sm.id)).to be_empty
+ expect(Spree::ShippingMethod.where(id: @sm.id)).to be_empty
end
scenario "deleting a shipping method referenced by an order" do
@@ -98,7 +97,7 @@ feature 'shipping methods' do
expect(page).to have_css 'div#shipping_method_zones_field'
expect(page).to have_field 'shipping_method_require_ship_address_true', checked: true
- fill_in 'shipping_method_name', :with => 'Teleport'
+ fill_in 'shipping_method_name', with: 'Teleport'
check "shipping_method_distributor_ids_#{distributor1.id}"
check "shipping_method_shipping_categories_"
diff --git a/spec/features/admin/tag_rules_spec.rb b/spec/features/admin/tag_rules_spec.rb
index 591d8cde26..a01ecb99fc 100644
--- a/spec/features/admin/tag_rules_spec.rb
+++ b/spec/features/admin/tag_rules_spec.rb
@@ -239,7 +239,7 @@ feature 'Tag Rules', js: true do
within "#tr_0" do first("a.delete-tag-rule").click end
end
expect(page).to have_no_selector "#tr_0"
- end.to change{TagRule.count}.by(-2)
+ end.to change{ TagRule.count }.by(-2)
end
end
end
diff --git a/spec/features/admin/tax_settings_spec.rb b/spec/features/admin/tax_settings_spec.rb
index 4b2dd4486c..7a11c98ba6 100644
--- a/spec/features/admin/tax_settings_spec.rb
+++ b/spec/features/admin/tax_settings_spec.rb
@@ -8,11 +8,11 @@ feature 'Account and Billing Settings' do
let!(:admin) { create(:admin_user) }
before do
- Spree::Config.set({
+ Spree::Config.set(
products_require_tax_category: false,
shipment_inc_vat: false,
shipping_tax_rate: 0
- })
+ )
end
before do
diff --git a/spec/features/admin/variant_overrides_spec.rb b/spec/features/admin/variant_overrides_spec.rb
index 7a2b55de62..a159cd79bf 100644
--- a/spec/features/admin/variant_overrides_spec.rb
+++ b/spec/features/admin/variant_overrides_spec.rb
@@ -1,11 +1,11 @@
require 'spec_helper'
-feature %q{
+feature "
As an Administrator
With products I can add to my hub's inventory
I want to override the stock level and price of those products
Without affecting other hubs that share the same products
-}, js: true do
+", js: true do
include AdminHelper
include AuthenticationWorkflow
include WebHelper
@@ -16,11 +16,13 @@ feature %q{
let!(:producer_managed) { create(:supplier_enterprise) }
let!(:producer_related) { create(:supplier_enterprise) }
let!(:producer_unrelated) { create(:supplier_enterprise) }
- let!(:er1) { create(:enterprise_relationship, parent: producer, child: hub,
- permissions_list: [:create_variant_overrides])
+ let!(:er1) {
+ create(:enterprise_relationship, parent: producer, child: hub,
+ permissions_list: [:create_variant_overrides])
}
- let!(:er2) { create(:enterprise_relationship, parent: producer_related, child: hub,
- permissions_list: [:create_variant_overrides])
+ let!(:er2) {
+ create(:enterprise_relationship, parent: producer_related, child: hub,
+ permissions_list: [:create_variant_overrides])
}
context "as an enterprise user" do
@@ -28,8 +30,9 @@ feature %q{
before { quick_login_as user }
describe "selecting a hub" do
- let!(:er1) { create(:enterprise_relationship, parent: hub2, child: producer_managed,
- permissions_list: [:add_to_order_cycle])
+ let!(:er1) {
+ create(:enterprise_relationship, parent: hub2, child: producer_managed,
+ permissions_list: [:add_to_order_cycle])
} # This er should not confer ability to create VOs for hub2
it "displays a list of hub choices (ie. only those managed by the user)" do
@@ -56,7 +59,6 @@ feature %q{
let!(:product_unrelated) { create(:simple_product, supplier: producer_unrelated) }
-
before do
# Remove 'S' option value
variant.option_values.first.destroy
@@ -217,7 +219,7 @@ feature %q{
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) { 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) }
diff --git a/spec/features/admin/variants_spec.rb b/spec/features/admin/variants_spec.rb
index 578944be17..8b38350466 100644
--- a/spec/features/admin/variants_spec.rb
+++ b/spec/features/admin/variants_spec.rb
@@ -1,9 +1,9 @@
require 'spec_helper'
-feature %q{
+feature '
As an admin
I want to manage product variants
-} do
+' do
include AuthenticationWorkflow
include WebHelper
@@ -24,8 +24,7 @@ feature %q{
page.should have_content "Variant \"#{p.name}\" has been successfully created!"
end
-
- scenario "editing unit value and description for a variant", js:true do
+ scenario "editing unit value and description for a variant", js: true do
# Given a product with unit-related option types, with a variant
p = create(:simple_product, variant_unit: "weight", variant_unit_scale: "1")
v = p.variants.first
@@ -50,7 +49,7 @@ feature %q{
fill_in "unit_value_human", with: "123"
fill_in "variant_unit_description", with: "bar"
click_button 'Update'
- page.should have_content %Q(Variant "#{p.name}" has been successfully updated!)
+ page.should have_content %(Variant "#{p.name}" has been successfully updated!)
# Then the unit value and description should have been saved
v.reload
@@ -58,7 +57,7 @@ feature %q{
v.unit_description.should == 'bar'
end
- describe "editing on hand and on demand values", js:true do
+ describe "editing on hand and on demand values", js: true do
let(:product) { create(:simple_product) }
let(:variant) { product.variants.first }
@@ -74,7 +73,7 @@ feature %q{
fill_in "variant_on_hand", with: "123"
click_button 'Update'
- page.should have_content %Q(Variant "#{product.name}" has been successfully updated!)
+ page.should have_content %(Variant "#{product.name}" has been successfully updated!)
end
it "allows changing the on_demand value" do
@@ -85,7 +84,7 @@ feature %q{
page.should have_field "variant_on_hand", with: "Infinity", disabled: true
click_button 'Update'
- page.should have_content %Q(Variant "#{product.name}" has been successfully updated!)
+ page.should have_content %(Variant "#{product.name}" has been successfully updated!)
end
it "memorizes on_hand value previously entered if enabling and disabling on_demand" do
@@ -114,12 +113,11 @@ feature %q{
page.should_not have_selector "tr#spree_variant_#{v.id}"
-
v.reload
v.deleted_at.should_not be_nil
end
- scenario "editing display name for a variant", js:true do
+ scenario "editing display name for a variant", js: true do
p = create(:simple_product)
v = p.variants.first
@@ -136,7 +134,7 @@ feature %q{
fill_in "variant_display_name", with: "Display Name"
fill_in "variant_display_as", with: "Display As This"
click_button 'Update'
- page.should have_content %Q(Variant "#{p.name}" has been successfully updated!)
+ page.should have_content %(Variant "#{p.name}" has been successfully updated!)
# Then the displayed values should have been saved
v.reload
diff --git a/spec/features/consumer/account/cards_spec.rb b/spec/features/consumer/account/cards_spec.rb
index 2b63d3bd3c..2b2008b049 100644
--- a/spec/features/consumer/account/cards_spec.rb
+++ b/spec/features/consumer/account/cards_spec.rb
@@ -16,10 +16,10 @@ feature "Credit Cards", js: true do
Spree::Config.set(stripe_connect_enabled: true)
stub_request(:get, "https://api.stripe.com/v1/customers/cus_AZNMJ").
- to_return(:status => 200, :body => JSON.generate(id: "cus_AZNMJ"))
+ to_return(status: 200, body: JSON.generate(id: "cus_AZNMJ"))
stub_request(:delete, "https://api.stripe.com/v1/customers/cus_AZNMJ").
- to_return(:status => 200, :body => JSON.generate(deleted: true, id: "cus_AZNMJ"))
+ to_return(status: 200, body: JSON.generate(deleted: true, id: "cus_AZNMJ"))
end
it "passes the smoke test" do
diff --git a/spec/features/consumer/account_spec.rb b/spec/features/consumer/account_spec.rb
index 1ea86078b5..23494f6a2c 100644
--- a/spec/features/consumer/account_spec.rb
+++ b/spec/features/consumer/account_spec.rb
@@ -1,14 +1,14 @@
require 'spec_helper'
-feature %q{
+feature '
As a consumer
I want to view my order history with each hub
and view any outstanding balance.
-}, js: true do
+', js: true do
include UIComponentHelper
include AuthenticationWorkflow
- let(:user) { create(:user)}
+ let(:user) { create(:user) }
let!(:distributor1) { create(:distributor_enterprise) }
let!(:distributor2) { create(:distributor_enterprise) }
let!(:distributor_credit) { create(:distributor_enterprise) }
@@ -21,10 +21,10 @@ feature %q{
context "with completed orders" do
let(:order_cycle) { create(:simple_order_cycle) }
- let!(:d1o1) { create(:completed_order_with_totals, distributor: distributor1, user: user, total: 10000, 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!(: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) }
before do
credit_order.update!
@@ -58,7 +58,7 @@ feature %q{
# It reveals table of orders for distributors when clicked
expand_active_table_node distributor1.name
- expect(page).to have_link "Order " + d1o1.number, href:"/orders/#{d1o1.number}"
+ expect(page).to have_link "Order " + d1o1.number, href: "/orders/#{d1o1.number}"
expand_active_table_node distributor2.name
expect(page).not_to have_content "Order " + d1o1.number.to_s
@@ -84,7 +84,7 @@ feature %q{
context "without any completed orders" do
it "displays an appropriate message" do
visit "/account"
- expect(page).to have_content {t :you_have_no_orders_yet}
+ expect(page).to have_content { t :you_have_no_orders_yet }
end
end
end
diff --git a/spec/features/consumer/cookies_spec.rb b/spec/features/consumer/cookies_spec.rb
index d86b89f4ad..19ec64eba0 100644
--- a/spec/features/consumer/cookies_spec.rb
+++ b/spec/features/consumer/cookies_spec.rb
@@ -2,7 +2,6 @@ require 'spec_helper'
feature "Cookies", js: true do
describe "banner" do
-
# keeps banner toggle config unchanged
around do |example|
original_banner_toggle = Spree::Config[:cookies_consent_banner_toggle]
@@ -36,7 +35,7 @@ feature "Cookies", js: true do
scenario "does not show after cookies are accepted, and policy page is opened through the footer, and closed again (bug #2599)" do
accept_cookies_and_wait
expect_not_visible_cookies_banner
-
+
click_footer_cookies_policy_link_and_wait
expect_visible_cookies_policy_page
expect_not_visible_cookies_banner
@@ -67,7 +66,6 @@ feature "Cookies", js: true do
end
describe "policy page" do
-
# keeps config unchanged
around do |example|
original_matomo_config = Spree::Config[:cookies_policy_matomo_section]
@@ -108,7 +106,7 @@ feature "Cookies", js: true do
visit_cookies_policy_page
expect(page).to have_content matomo_opt_out_iframe
expect(page).to have_selector("iframe")
- end
+ end
end
context "with Matomo integration disabled" do
@@ -128,11 +126,11 @@ feature "Cookies", js: true do
end
def expect_visible_cookies_banner
- expect(page).to have_css("button", :text => accept_cookies_button_text, :visible => true)
+ expect(page).to have_css("button", text: accept_cookies_button_text, visible: true)
end
def expect_not_visible_cookies_banner
- expect(page).to have_no_css("button", :text => accept_cookies_button_text, :visible => true)
+ expect(page).to have_no_css("button", text: accept_cookies_button_text, visible: true)
end
def accept_cookies_button_text
@@ -150,12 +148,12 @@ feature "Cookies", js: true do
end
def click_banner_cookies_policy_link_and_wait
- find("p.ng-binding > a", :text => "cookies policy").click
+ find("p.ng-binding > a", text: "cookies policy").click
sleep 2
end
def click_footer_cookies_policy_link_and_wait
- find("div > a", :text => "cookies policy").click
+ find("div > a", text: "cookies policy").click
sleep 2
end
diff --git a/spec/features/consumer/footer_links_spec.rb b/spec/features/consumer/footer_links_spec.rb
index 0baa0d7d56..80bfec90f7 100644
--- a/spec/features/consumer/footer_links_spec.rb
+++ b/spec/features/consumer/footer_links_spec.rb
@@ -24,7 +24,7 @@ feature "Footer Links", js: true do
scenario "showing configured privacy policy link" do
Spree::Config[:privacy_policy_url] = "link_to_privacy_policy"
visit root_path
- expect(page).to have_link "privacy policy", :href => "link_to_privacy_policy"
+ expect(page).to have_link "privacy policy", href: "link_to_privacy_policy"
end
end
end
diff --git a/spec/features/consumer/groups_spec.rb b/spec/features/consumer/groups_spec.rb
index 4a5f166d7d..c59835c344 100644
--- a/spec/features/consumer/groups_spec.rb
+++ b/spec/features/consumer/groups_spec.rb
@@ -13,7 +13,7 @@ feature 'Groups', js: true do
end
it "searches by URL" do
- visit groups_path(anchor: "/?query=xyzzy")
+ visit groups_path(anchor: "/?query=xyzzy")
expect(page).to have_content "No groups found"
end
diff --git a/spec/features/consumer/multilingual_spec.rb b/spec/features/consumer/multilingual_spec.rb
index 4e6ac07d8f..99ba5a3202 100644
--- a/spec/features/consumer/multilingual_spec.rb
+++ b/spec/features/consumer/multilingual_spec.rb
@@ -125,7 +125,7 @@ feature 'Multilingual', js: true do
expect(page).to have_content 'SHOPS'
find('ul.right li.language-switcher').click
- within'ul.right li.language-switcher ul.dropdown' do
+ within 'ul.right li.language-switcher ul.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'
diff --git a/spec/features/consumer/producers_spec.rb b/spec/features/consumer/producers_spec.rb
index 514c71d7c4..8ba7585804 100644
--- a/spec/features/consumer/producers_spec.rb
+++ b/spec/features/consumer/producers_spec.rb
@@ -1,10 +1,10 @@
require 'spec_helper'
-feature %q{
+feature '
As a consumer
I want to see a list of producers
So that I can shop at hubs distributing their products
-}, js: true do
+', js: true do
include WebHelper
include UIComponentHelper
@@ -29,7 +29,6 @@ feature %q{
producer2.set_producer_property 'Fair Trade', 'FT123'
end
-
it "searches by URL" do
visit producers_path(anchor: "/?query=xyzzy")
expect(page).to have_content "Sorry, no results found for xyzzy"
diff --git a/spec/features/consumer/registration_spec.rb b/spec/features/consumer/registration_spec.rb
index efbb9deca0..bff616e5f0 100644
--- a/spec/features/consumer/registration_spec.rb
+++ b/spec/features/consumer/registration_spec.rb
@@ -56,7 +56,6 @@ feature "Registration", js: true do
click_button "Continue"
expect(page).to have_content 'Who is responsible for managing My Awesome Enterprise?'
-
# Filling in Contact Details
fill_in 'enterprise_contact', with: 'Saskia Munroe'
page.should have_field 'enterprise_email_address', with: user.email
@@ -184,7 +183,7 @@ feature "Registration", js: true do
# Link appears to be unresponsive for a while, so keep clicking it until it works
using_wait_time 0.5 do
10.times do
- find("a", text: "Login").click()
+ find("a", text: "Login").click
break if page.has_selector? "dd.active", text: "Login"
end
end
diff --git a/spec/features/consumer/shopping/cart_spec.rb b/spec/features/consumer/shopping/cart_spec.rb
index b76f713292..d054bf3d1b 100644
--- a/spec/features/consumer/shopping/cart_spec.rb
+++ b/spec/features/consumer/shopping/cart_spec.rb
@@ -49,8 +49,10 @@ feature "full-page cart", js: true do
describe "admin and handling flat fees" do
context "when there are fees" do
- let(:handling_fee) { create(:enterprise_fee, calculator: Spree::Calculator::FlatRate.new(preferred_amount: 1),
- enterprise: order_cycle.coordinator, fee_type: 'admin') }
+ let(:handling_fee) {
+ create(:enterprise_fee, calculator: Spree::Calculator::FlatRate.new(preferred_amount: 1),
+ enterprise: order_cycle.coordinator, fee_type: 'admin')
+ }
before do
add_enterprise_fee handling_fee
@@ -85,8 +87,10 @@ feature "full-page cart", js: true do
describe "admin weight calculated fees" do
context "order with 2 line items" do
- let(:admin_fee) { create(:enterprise_fee, calculator: Calculator::Weight.new(preferred_per_kg: 1),
- enterprise: order_cycle.coordinator, fee_type: 'admin') }
+ let(:admin_fee) {
+ create(:enterprise_fee, calculator: Calculator::Weight.new(preferred_per_kg: 1),
+ enterprise: order_cycle.coordinator, fee_type: 'admin')
+ }
before do
product_with_fee.variants.first.update_attributes(unit_value: '2000.0')
@@ -132,7 +136,7 @@ feature "full-page cart", js: true do
it "prevents me from entering an invalid value" do
# Given we have 2 on hand, and we've loaded the page after that fact
- variant.update_attributes!({ on_hand: 2, on_demand: false })
+ variant.update_attributes!(on_hand: 2, on_demand: false)
visit spree.cart_path
accept_alert 'Insufficient stock available, only 2 remaining' do
diff --git a/spec/features/consumer/shopping/checkout_spec.rb b/spec/features/consumer/shopping/checkout_spec.rb
index 18d3818030..a9a23512e8 100644
--- a/spec/features/consumer/shopping/checkout_spec.rb
+++ b/spec/features/consumer/shopping/checkout_spec.rb
@@ -164,18 +164,18 @@ feature "As a consumer I want to check out my cart", js: true, retry: 3 do
let!(:saved_card) do
create(:credit_card,
- user_id: user.id,
- month: "01",
- year: "2025",
- cc_type: "visa",
- number: "1111111111111111",
- payment_method_id: stripe_pm.id,
- gateway_customer_profile_id: "i_am_saved")
+ user_id: user.id,
+ month: "01",
+ year: "2025",
+ cc_type: "visa",
+ number: "1111111111111111",
+ payment_method_id: stripe_pm.id,
+ gateway_customer_profile_id: "i_am_saved")
end
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} }
+ let(:response_mock) { { id: "ch_1234", object: "charge", amount: 2000 } }
before do
allow(Stripe).to receive(:api_key) { "sk_test_12345" }
@@ -265,15 +265,15 @@ feature "As a consumer I want to check out my cart", js: true, retry: 3 do
page.should have_content "Local"
create(:filter_shipping_methods_tag_rule,
- enterprise: distributor,
- preferred_customer_tags: "local",
- preferred_shipping_method_tags: "local",
- preferred_matched_shipping_methods_visibility: 'visible')
- create(:filter_shipping_methods_tag_rule,
- enterprise: distributor,
- is_default: true,
- preferred_shipping_method_tags: "local",
- preferred_matched_shipping_methods_visibility: 'hidden')
+ enterprise: distributor,
+ preferred_customer_tags: "local",
+ preferred_shipping_method_tags: "local",
+ preferred_matched_shipping_methods_visibility: 'visible')
+ create(:filter_shipping_methods_tag_rule,
+ enterprise: distributor,
+ is_default: true,
+ preferred_shipping_method_tags: "local",
+ preferred_matched_shipping_methods_visibility: 'hidden')
visit checkout_path
checkout_as_guest
@@ -444,7 +444,7 @@ feature "As a consumer I want to check out my cart", js: true, retry: 3 do
it "takes us to the order confirmation page when submitted with a valid credit card" do
fill_in 'Card Number', with: "4111111111111111"
select 'February', from: 'secrets.card_month'
- select (Date.current.year+1).to_s, from: 'secrets.card_year'
+ select (Date.current.year + 1).to_s, from: 'secrets.card_year'
fill_in 'Security Code', with: '123'
place_order
@@ -458,7 +458,7 @@ feature "As a consumer I want to check out my cart", js: true, retry: 3 do
it "shows the payment processing failed message when submitted with an invalid credit card" do
fill_in 'Card Number', with: "9999999988887777"
select 'February', from: 'secrets.card_month'
- select (Date.current.year+1).to_s, from: 'secrets.card_year'
+ select (Date.current.year + 1).to_s, from: 'secrets.card_year'
fill_in 'Security Code', with: '123'
place_order
diff --git a/spec/features/consumer/shopping/embedded_groups_spec.rb b/spec/features/consumer/shopping/embedded_groups_spec.rb
index 788bd2970e..171e60965e 100644
--- a/spec/features/consumer/shopping/embedded_groups_spec.rb
+++ b/spec/features/consumer/shopping/embedded_groups_spec.rb
@@ -36,7 +36,6 @@ feature "Using embedded shopfront functionality", js: true do
it "doesn't display contact details when embedded" do
on_embedded_page do
within 'div#group-page' do
-
expect(page).to have_no_selector 'div.contact-container'
expect(page).to have_no_content '#{group.address.address1}'
end
diff --git a/spec/features/consumer/shopping/orders_spec.rb b/spec/features/consumer/shopping/orders_spec.rb
index b8bf8fe149..50ad7d7563 100644
--- a/spec/features/consumer/shopping/orders_spec.rb
+++ b/spec/features/consumer/shopping/orders_spec.rb
@@ -15,11 +15,10 @@ feature "Order Management", js: true do
let!(:order) do
create(:order_with_credit_payment,
- customer: customer,
- user: user,
- distributor: distributor,
- order_cycle: order_cycle
- )
+ customer: customer,
+ user: user,
+ distributor: distributor,
+ order_cycle: order_cycle)
end
before do
diff --git a/spec/features/consumer/shopping/products_spec.rb b/spec/features/consumer/shopping/products_spec.rb
index f844634a7e..5872e4c3a2 100644
--- a/spec/features/consumer/shopping/products_spec.rb
+++ b/spec/features/consumer/shopping/products_spec.rb
@@ -30,7 +30,7 @@ feature "As a consumer I want to view products", js: true do
product.save!
visit shop_path
- select "monday", :from => "order_cycle_id"
+ select "monday", from: "order_cycle_id"
click_link product.name
expect(page).to have_selector '.reveal-modal'
@@ -46,7 +46,7 @@ feature "As a consumer I want to view products", js: true do
product.save!
visit shop_path
- select "monday", :from => "order_cycle_id"
+ select "monday", from: "order_cycle_id"
click_link product.name
expect(page).to have_selector '.reveal-modal'
diff --git a/spec/features/consumer/shopping/shopping_spec.rb b/spec/features/consumer/shopping/shopping_spec.rb
index abf1cc7d51..cc85757b71 100644
--- a/spec/features/consumer/shopping/shopping_spec.rb
+++ b/spec/features/consumer/shopping/shopping_spec.rb
@@ -7,7 +7,6 @@ feature "As a consumer I want to shop with a distributor", js: true do
include UIComponentHelper
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) }
@@ -71,9 +70,9 @@ feature "As a consumer I want to shop with a distributor", js: true do
add_variant_to_order_cycle(exchange1, variant)
visit shop_path
page.should_not have_content product.name
- Spree::Order.last.order_cycle.should == nil
+ Spree::Order.last.order_cycle.should.nil?
- select "frogs", :from => "order_cycle_id"
+ select "frogs", from: "order_cycle_id"
page.should have_selector "products"
page.should have_content "Next order closing in 2 days"
Spree::Order.last.order_cycle.should == oc1
@@ -186,7 +185,7 @@ feature "As a consumer I want to shop with a distributor", js: true do
it "uses the adjusted price" do
enterprise_fee1 = create(:enterprise_fee, amount: 20)
- enterprise_fee2 = create(:enterprise_fee, amount: 3)
+ enterprise_fee2 = create(:enterprise_fee, amount: 3)
exchange.enterprise_fees = [enterprise_fee1, enterprise_fee2]
exchange.save
visit shop_path
@@ -205,7 +204,7 @@ feature "As a consumer I want to shop with a distributor", js: true do
it "filters search results properly" do
visit shop_path
- select "frogs", :from => "order_cycle_id"
+ select "frogs", from: "order_cycle_id"
fill_in "search", with: "74576345634XXXXXX"
page.should have_content "Sorry, no results found"
@@ -222,7 +221,7 @@ feature "As a consumer I want to shop with a distributor", js: true do
it "returns search results for products where the search term matches one of the product's variant names" do
visit shop_path
- select "frogs", :from => "order_cycle_id"
+ select "frogs", from: "order_cycle_id"
fill_in "search", with: "Badg" # For variant with display_name "Badgers"
@@ -232,9 +231,7 @@ feature "As a consumer I want to shop with a distributor", js: true do
page.should_not have_content product2.name
page.should_not have_content variant3.display_name
end
-
end
-
end
describe "group buy products" do
diff --git a/spec/features/consumer/shopping/variant_overrides_spec.rb b/spec/features/consumer/shopping/variant_overrides_spec.rb
index 5aaa0d1ac9..ca08f5f1df 100644
--- a/spec/features/consumer/shopping/variant_overrides_spec.rb
+++ b/spec/features/consumer/shopping/variant_overrides_spec.rb
@@ -103,7 +103,6 @@ feature "shopping with variant overrides defined", js: true, retry: 3 do
end
end
-
describe "creating orders" do
it "creates the order with the correct prices" do
fill_in "variants[#{product1_variant1.id}]", with: "2"
@@ -158,7 +157,6 @@ feature "shopping with variant overrides defined", js: true, retry: 3 do
end
end
-
private
def complete_checkout
@@ -192,8 +190,8 @@ feature "shopping with variant overrides defined", js: true, retry: 3 do
end
def click_checkout
- show_cart
- wait_until_enabled 'li.cart a.button'
- first(:link, 'Checkout now').click
+ show_cart
+ wait_until_enabled 'li.cart a.button'
+ first(:link, 'Checkout now').click
end
end
diff --git a/spec/features/consumer/shops_spec.rb b/spec/features/consumer/shops_spec.rb
index 5e28f8ae50..ea919341eb 100644
--- a/spec/features/consumer/shops_spec.rb
+++ b/spec/features/consumer/shops_spec.rb
@@ -22,7 +22,6 @@ feature 'Shops', js: true do
expect(page).to have_content "Sorry, no results found for xyzzy"
end
-
describe "listing shops" do
before do
visit shops_path
@@ -141,7 +140,7 @@ feature 'Shops', js: true do
describe "closed shops" do
it "shows taxons for any order cycle" do
visit shops_path
- click_link_and_ensure('Show closed shops', -> { page.has_selector? '.active_table_node'})
+ click_link_and_ensure('Show closed shops', -> { page.has_selector? '.active_table_node' })
expand_active_table_node shop.name
expect(page).to have_selector '.fat-taxons', text: 'Closed'
end
@@ -203,7 +202,6 @@ feature 'Shops', js: true do
end
end
-
private
def click_link_and_ensure(link_text, check)
diff --git a/spec/helpers/checkout_helper_spec.rb b/spec/helpers/checkout_helper_spec.rb
index 5dc45a3399..17d6911e6e 100644
--- a/spec/helpers/checkout_helper_spec.rb
+++ b/spec/helpers/checkout_helper_spec.rb
@@ -1,13 +1,12 @@
require 'spec_helper'
-
describe CheckoutHelper, type: :helper do
it "generates html for validated inputs" do
expect(helper).to receive(:render).with(
"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)
diff --git a/spec/helpers/enterprises_helper_spec.rb b/spec/helpers/enterprises_helper_spec.rb
index 68a3ad0906..0933abb748 100644
--- a/spec/helpers/enterprises_helper_spec.rb
+++ b/spec/helpers/enterprises_helper_spec.rb
@@ -32,15 +32,17 @@ describe EnterprisesHelper, type: :helper do
context "when FilterShippingMethods tag rules are in effect" do
let(:customer) { create(:customer, user: user, enterprise: distributor) }
- let!(:tag_rule) { create(:filter_shipping_methods_tag_rule,
- enterprise: distributor,
- preferred_customer_tags: "local",
- preferred_shipping_method_tags: "local-delivery")
+ let!(:tag_rule) {
+ create(:filter_shipping_methods_tag_rule,
+ enterprise: distributor,
+ preferred_customer_tags: "local",
+ preferred_shipping_method_tags: "local-delivery")
}
- let!(:default_tag_rule) { create(:filter_shipping_methods_tag_rule,
- enterprise: distributor,
- is_default: true,
- preferred_shipping_method_tags: "local-delivery")
+ let!(:default_tag_rule) {
+ create(:filter_shipping_methods_tag_rule,
+ enterprise: distributor,
+ is_default: true,
+ preferred_shipping_method_tags: "local-delivery")
}
let!(:tagged_sm) { sm1 }
let!(:untagged_sm) { sm2 }
@@ -117,8 +119,8 @@ describe EnterprisesHelper, type: :helper do
end
describe "loading available payment methods" do
- let!(:pm1) { create(:payment_method, distributors: [distributor])}
- let!(:pm2) { create(:payment_method, distributors: [some_other_distributor])}
+ let!(:pm1) { create(:payment_method, distributors: [distributor]) }
+ let!(:pm2) { create(:payment_method, distributors: [some_other_distributor]) }
context "when the order has no current_distributor" do
before do
@@ -141,15 +143,17 @@ describe EnterprisesHelper, type: :helper do
context "when FilterPaymentMethods tag rules are in effect" do
let(:customer) { create(:customer, user: user, enterprise: distributor) }
- let!(:tag_rule) { create(:filter_payment_methods_tag_rule,
- enterprise: distributor,
- preferred_customer_tags: "trusted",
- preferred_payment_method_tags: "trusted")
+ let!(:tag_rule) {
+ create(:filter_payment_methods_tag_rule,
+ enterprise: distributor,
+ preferred_customer_tags: "trusted",
+ preferred_payment_method_tags: "trusted")
}
- let!(:default_tag_rule) { create(:filter_payment_methods_tag_rule,
- enterprise: distributor,
- is_default: true,
- preferred_payment_method_tags: "trusted")
+ let!(:default_tag_rule) {
+ create(:filter_payment_methods_tag_rule,
+ enterprise: distributor,
+ is_default: true,
+ preferred_payment_method_tags: "trusted")
}
let(:tagged_pm) { pm1 }
let(:untagged_pm) { pm2 }
diff --git a/spec/helpers/groups_helper_spec.rb b/spec/helpers/groups_helper_spec.rb
index 2acc68a7ef..8220a12507 100644
--- a/spec/helpers/groups_helper_spec.rb
+++ b/spec/helpers/groups_helper_spec.rb
@@ -1,17 +1,17 @@
require 'spec_helper'
describe GroupsHelper, type: :helper do
- describe "ext_url" do
- it "adds prefix if missing" do
- expect(helper.ext_url("http://example.com/", "http://example.com/bla")).to eq("http://example.com/bla")
- expect(helper.ext_url("http://example.com/", "bla")).to eq("http://example.com/bla")
- end
- end
- describe "strip_url" do
- it "removes http(s)://" do
- expect(helper.strip_url("http://example.com/")).to eq("example.com/")
- expect(helper.strip_url("https://example.com/")).to eq("example.com/")
- expect(helper.strip_url("example.com")).to eq("example.com")
- end
- end
+ describe "ext_url" do
+ it "adds prefix if missing" do
+ expect(helper.ext_url("http://example.com/", "http://example.com/bla")).to eq("http://example.com/bla")
+ expect(helper.ext_url("http://example.com/", "bla")).to eq("http://example.com/bla")
+ end
+ end
+ describe "strip_url" do
+ it "removes http(s)://" do
+ expect(helper.strip_url("http://example.com/")).to eq("example.com/")
+ expect(helper.strip_url("https://example.com/")).to eq("example.com/")
+ expect(helper.strip_url("example.com")).to eq("example.com")
+ end
+ end
end
diff --git a/spec/helpers/injection_helper_spec.rb b/spec/helpers/injection_helper_spec.rb
index 0e23bc6473..204f5977a6 100644
--- a/spec/helpers/injection_helper_spec.rb
+++ b/spec/helpers/injection_helper_spec.rb
@@ -5,10 +5,10 @@ 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: 10000)}
- 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)}
+ 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!(:d2o1) { create(:completed_order_with_totals, distributor: distributor2, user_id: user.id) }
it "will inject via AMS" do
expect(helper.inject_json_ams("test", [enterprise], Api::IdSerializer)).to match /#{enterprise.id}/
diff --git a/spec/helpers/order_cycles_helper_spec.rb b/spec/helpers/order_cycles_helper_spec.rb
index 079198cc8d..5e4f852297 100644
--- a/spec/helpers/order_cycles_helper_spec.rb
+++ b/spec/helpers/order_cycles_helper_spec.rb
@@ -31,7 +31,7 @@ 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
@@ -42,25 +42,25 @@ describe OrderCyclesHelper, type: :helper do
it "returns enterprises without shipping methods as disabled" do
create(:payment_method, distributors: [e])
expect(helper.send(:validated_enterprise_options, [e], shipping_and_payment_methods: true))
- .to eq [['enterprise (no shipping methods)', e.id, {disabled: true}]]
+ .to eq [['enterprise (no shipping methods)', e.id, { disabled: true }]]
end
it "returns enterprises without payment methods as disabled" do
create(:shipping_method, distributors: [e])
expect(helper.send(:validated_enterprise_options, [e], shipping_and_payment_methods: true))
- .to eq [['enterprise (no payment methods)', e.id, {disabled: true}]]
+ .to eq [['enterprise (no payment methods)', e.id, { disabled: true }]]
end
it "returns enterprises with unavailable payment methods as disabled" do
create(:shipping_method, distributors: [e])
create(:payment_method, distributors: [e], active: false)
expect(helper.send(:validated_enterprise_options, [e], shipping_and_payment_methods: true))
- .to eq [['enterprise (no payment methods)', e.id, {disabled: true}]]
+ .to eq [['enterprise (no payment methods)', e.id, { disabled: true }]]
end
it "returns enterprises with neither shipping nor payment methods as disabled" do
expect(helper.send(:validated_enterprise_options, [e], shipping_and_payment_methods: true))
- .to eq [['enterprise (no shipping or payment methods)', e.id, {disabled: true}]]
+ .to eq [['enterprise (no shipping or payment methods)', e.id, { disabled: true }]]
end
end
@@ -79,7 +79,7 @@ describe OrderCyclesHelper, type: :helper do
it "gives me the pickup time for any order cycle" do
d = create(:distributor_enterprise, name: 'Green Grass')
oc1 = create(:simple_order_cycle, name: 'oc 1', distributors: [d])
- oc2= create(:simple_order_cycle, name: 'oc 1', distributors: [d])
+ oc2 = create(:simple_order_cycle, name: 'oc 1', distributors: [d])
exchange = Exchange.find(oc2.exchanges.to_enterprises(d).outgoing.first.id)
exchange.update_attribute :pickup_time, "turtles"
diff --git a/spec/helpers/shared_helper_spec.rb b/spec/helpers/shared_helper_spec.rb
index 5c763f4238..1a2fced894 100644
--- a/spec/helpers/shared_helper_spec.rb
+++ b/spec/helpers/shared_helper_spec.rb
@@ -1,7 +1,6 @@
require 'spec_helper'
describe SharedHelper, type: :helper do
-
it "does not require emptying the cart when it is empty" do
d = double(:distributor)
order = double(:order, line_items: [])
diff --git a/spec/helpers/shop_helper_spec.rb b/spec/helpers/shop_helper_spec.rb
index 5ee1585526..0cc4f546d3 100644
--- a/spec/helpers/shop_helper_spec.rb
+++ b/spec/helpers/shop_helper_spec.rb
@@ -1,6 +1,5 @@
require 'spec_helper'
describe ShopHelper, type: :helper do
-
it "should build order cycle select options" do
d = create(:distributor_enterprise)
o1 = create(:simple_order_cycle, distributors: [d])
diff --git a/spec/helpers/spree/orders_helper_spec.rb b/spec/helpers/spree/orders_helper_spec.rb
index 9c1787f16e..4def72324d 100644
--- a/spec/helpers/spree/orders_helper_spec.rb
+++ b/spec/helpers/spree/orders_helper_spec.rb
@@ -1,7 +1,6 @@
require 'spec_helper'
describe Spree::OrdersHelper, type: :helper do
-
describe "#changeable_orders" do
let(:complete_orders) { double(:complete_orders, where: "some_orders") }
@@ -22,7 +21,7 @@ describe Spree::OrdersHelper, type: :helper do
let(:current_order_cycle) { double(:current_order_cycle, id: 1) }
context "when the current_distributor allows order changes" do
- before { allow(current_distributor).to receive(:allow_order_changes?) { true} }
+ before { allow(current_distributor).to receive(:allow_order_changes?) { true } }
it { expect(helper.changeable_orders).to eq "some_orders" }
end
diff --git a/spec/jobs/heartbeat_job_spec.rb b/spec/jobs/heartbeat_job_spec.rb
index 7e9a61babe..4744eaeb38 100644
--- a/spec/jobs/heartbeat_job_spec.rb
+++ b/spec/jobs/heartbeat_job_spec.rb
@@ -16,7 +16,6 @@ describe HeartbeatJob do
end
end
-
private
def run_job
diff --git a/spec/jobs/subscription_placement_job_spec.rb b/spec/jobs/subscription_placement_job_spec.rb
index 72a0ed6899..f211385964 100644
--- a/spec/jobs/subscription_placement_job_spec.rb
+++ b/spec/jobs/subscription_placement_job_spec.rb
@@ -64,7 +64,7 @@ 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) }
diff --git a/spec/lib/open_food_network/cached_products_renderer_spec.rb b/spec/lib/open_food_network/cached_products_renderer_spec.rb
index 61de635f20..82d9302016 100644
--- a/spec/lib/open_food_network/cached_products_renderer_spec.rb
+++ b/spec/lib/open_food_network/cached_products_renderer_spec.rb
@@ -22,7 +22,7 @@ module OpenFoodNetwork
before do
allow(ProductsRenderer)
.to receive(:new)
- .with(distributor, order_cycle) { products_renderer }
+ .with(distributor, order_cycle) { products_renderer }
end
context "products cache toggle" do
@@ -46,7 +46,7 @@ module OpenFoodNetwork
end
it "returns the cached JSON" do
- expect(cached_products_renderer.products_json).to eq 'products'
+ expect(cached_products_renderer.products_json).to eq 'products'
end
end
end
@@ -92,7 +92,7 @@ module OpenFoodNetwork
allow(ProductsRenderer)
.to receive(:new)
- .with(distributor, order_cycle) { products_renderer }
+ .with(distributor, order_cycle) { products_renderer }
end
describe "when there are products" do
@@ -114,7 +114,7 @@ module OpenFoodNetwork
allow(ProductsRenderer)
.to receive(:new)
- .with(distributor, order_cycle) { products_renderer }
+ .with(distributor, order_cycle) { products_renderer }
end
it "raises an error" do
diff --git a/spec/lib/open_food_network/customers_report_spec.rb b/spec/lib/open_food_network/customers_report_spec.rb
index 686686f662..14b3024d7e 100644
--- a/spec/lib/open_food_network/customers_report_spec.rb
+++ b/spec/lib/open_food_network/customers_report_spec.rb
@@ -22,13 +22,13 @@ module OpenFoodNetwork
it "builds a table from a list of variants" do
order = double(:order, email: "test@test.com")
address = double(:billing_address, firstname: "Firsty",
- lastname: "Lasty", city: "Suburbia")
+ lastname: "Lasty", city: "Suburbia")
allow(order).to receive(:billing_address).and_return address
allow(subject).to receive(:orders).and_return [order]
expect(subject.table).to eq([[
- "test@test.com", "Firsty", "Lasty", "Suburbia"
- ]])
+ "test@test.com", "Firsty", "Lasty", "Suburbia"
+ ]])
end
end
@@ -49,12 +49,12 @@ module OpenFoodNetwork
allow(subject).to receive(:orders).and_return [o]
expect(subject.table).to eq([[
- a.firstname, a.lastname,
- [a.address1, a.address2, a.city].join(" "),
- o.email, a.phone, d.name,
- [d.address.address1, d.address.address2, d.address.city].join(" "),
- o.shipping_method.name
- ]])
+ a.firstname, a.lastname,
+ [a.address1, a.address2, a.city].join(" "),
+ o.email, a.phone, d.name,
+ [d.address.address1, d.address.address2, d.address.city].join(" "),
+ o.shipping_method.name
+ ]])
end
end
diff --git a/spec/lib/open_food_network/enterprise_fee_calculator_spec.rb b/spec/lib/open_food_network/enterprise_fee_calculator_spec.rb
index 5f6ef36ed6..c1e361503e 100644
--- a/spec/lib/open_food_network/enterprise_fee_calculator_spec.rb
+++ b/spec/lib/open_food_network/enterprise_fee_calculator_spec.rb
@@ -15,21 +15,23 @@ module OpenFoodNetwork
describe "calculating fees for a variant" do
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_fee2) { create(:enterprise_fee, amount: 3) }
let(:enterprise_fee3) { create(:enterprise_fee, calculator: Spree::Calculator::FlatRate.new(preferred_amount: 2)) }
describe "supplier fees" do
- let!(:exchange1) { create(:exchange, order_cycle: order_cycle, sender: supplier1, receiver: coordinator, incoming: true,
- enterprise_fees: [enterprise_fee1], variants: [product1.master])
+ let!(:exchange1) {
+ create(:exchange, order_cycle: order_cycle, sender: supplier1, receiver: coordinator, incoming: true,
+ enterprise_fees: [enterprise_fee1], variants: [product1.master])
}
- let!(:exchange2) { create(:exchange, order_cycle: order_cycle, sender: supplier2, receiver: coordinator, incoming: true,
- enterprise_fees: [enterprise_fee2], variants: [product2.master])
+ let!(:exchange2) {
+ create(:exchange, order_cycle: order_cycle, sender: supplier2, receiver: coordinator, incoming: true,
+ enterprise_fees: [enterprise_fee2], variants: [product2.master])
}
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)
- end
+ end
it "calculates via indexed computation" do
expect(EnterpriseFeeCalculator.new(distributor, order_cycle).indexed_fees_for(product1.master)).to eq(20)
@@ -38,8 +40,9 @@ module OpenFoodNetwork
end
describe "coordinator fees" do
- let!(:exchange) { create(:exchange, order_cycle: order_cycle, sender: coordinator, receiver: distributor, incoming: false,
- enterprise_fees: [], variants: [product1.master])
+ let!(:exchange) {
+ create(:exchange, order_cycle: order_cycle, sender: coordinator, receiver: distributor, incoming: false,
+ enterprise_fees: [], variants: [product1.master])
}
before do
@@ -56,8 +59,9 @@ module OpenFoodNetwork
end
describe "distributor fees" do
- let!(:exchange) { create(:exchange, order_cycle: order_cycle, sender: coordinator, receiver: distributor, incoming: false,
- enterprise_fees: [enterprise_fee1, enterprise_fee2, enterprise_fee3], variants: [product1.master])
+ let!(:exchange) {
+ create(:exchange, order_cycle: order_cycle, sender: coordinator, receiver: distributor, incoming: false,
+ enterprise_fees: [enterprise_fee1, enterprise_fee2, enterprise_fee3], variants: [product1.master])
}
it "sums via regular computation" do
@@ -72,8 +76,9 @@ module OpenFoodNetwork
describe "summing percentage fees for the variant" do
let!(:enterprise_fee1) { create(:enterprise_fee, amount: 20, fee_type: "admin", calculator: ::Calculator::FlatPercentPerItem.new(preferred_flat_percent: 20)) }
- let!(:exchange) { create(:exchange, order_cycle: order_cycle, sender: coordinator, receiver: distributor, incoming: false,
- enterprise_fees: [enterprise_fee1], variants: [product1.master])
+ 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
@@ -92,31 +97,32 @@ module OpenFoodNetwork
let!(:ef_packing) { create(:enterprise_fee, fee_type: 'packing', amount: 7.89) }
let!(:ef_transport) { create(:enterprise_fee, fee_type: 'transport', amount: 0.12) }
let!(:ef_fundraising) { create(:enterprise_fee, fee_type: 'fundraising', amount: 3.45) }
- let!(:exchange) { create(:exchange, order_cycle: order_cycle,
- sender: coordinator, receiver: distributor, incoming: false,
- enterprise_fees: [ef_admin, ef_sales, ef_packing, ef_transport, ef_fundraising],
- variants: [product1.master])
+ let!(:exchange) {
+ create(:exchange, order_cycle: order_cycle,
+ sender: coordinator, receiver: distributor, incoming: false,
+ enterprise_fees: [ef_admin, ef_sales, ef_packing, ef_transport, ef_fundraising],
+ variants: [product1.master])
}
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
@@ -150,7 +156,6 @@ module OpenFoodNetwork
end
end
-
describe "indexed fee retrieval" do
subject { EnterpriseFeeCalculator.new distributor, order_cycle }
let(:order_cycle) { create(:simple_order_cycle, coordinator_fees: [ef_coordinator]) }
@@ -162,7 +167,7 @@ module OpenFoodNetwork
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(:v) { create(:variant) }
- let(:indexed_variants) { {v.id => v} }
+ let(:indexed_variants) { { v.id => v } }
let(:indexed_enterprise_fees) { subject.instance_variable_get(:@indexed_enterprise_fees) }
before { subject.instance_variable_set(:@indexed_enterprise_fees, {}) }
@@ -190,14 +195,14 @@ module OpenFoodNetwork
it "loads exchange fees" do
subject.send(:load_exchange_fees, exchange_fees)
- expect(indexed_enterprise_fees).to eq({v.id => [ef_exchange]})
+ expect(indexed_enterprise_fees).to eq(v.id => [ef_exchange])
end
end
describe "loading coordinator fees" do
it "loads coordinator fees" do
subject.send(:load_coordinator_fees)
- expect(indexed_enterprise_fees).to eq({v.id => [ef_coordinator]})
+ expect(indexed_enterprise_fees).to eq(v.id => [ef_coordinator])
end
end
end
@@ -212,7 +217,6 @@ module OpenFoodNetwork
let(:outgoing_exchange) { double(:exchange, role: 'distributor') }
let(:applicator) { double(:enterprise_fee_applicator) }
-
describe "for a line item" do
let(:variant) { double(:variant) }
let(:line_item) { double(:line_item, variant: variant, order: order) }
diff --git a/spec/lib/open_food_network/feature_toggle_spec.rb b/spec/lib/open_food_network/feature_toggle_spec.rb
index 857a46a04f..d00c44527c 100644
--- a/spec/lib/open_food_network/feature_toggle_spec.rb
+++ b/spec/lib/open_food_network/feature_toggle_spec.rb
@@ -3,12 +3,12 @@ require 'open_food_network/feature_toggle'
module OpenFoodNetwork
describe FeatureToggle do
it "returns true when feature is on" do
- allow(FeatureToggle).to receive(:features).and_return({foo: true})
+ allow(FeatureToggle).to receive(:features).and_return(foo: true)
expect(FeatureToggle.enabled?(:foo)).to be true
end
it "returns false when feature is off" do
- allow(FeatureToggle).to receive(:features).and_return({foo: false})
+ allow(FeatureToggle).to receive(:features).and_return(foo: false)
expect(FeatureToggle.enabled?(:foo)).to be false
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 94735e0886..209ed881be 100644
--- a/spec/lib/open_food_network/group_buy_report_spec.rb
+++ b/spec/lib/open_food_network/group_buy_report_spec.rb
@@ -2,12 +2,11 @@ require 'spec_helper'
module OpenFoodNetwork
describe GroupBuyReport do
-
before(:each) do
@orders = []
bill_address = create(:address)
- distributor_address = create(:address, :address1 => "distributor address", :city => 'The Shire', :zipcode => "1234")
- distributor = create(:distributor_enterprise, :address => distributor_address)
+ distributor_address = create(:address, address1: "distributor address", city: 'The Shire', zipcode: "1234")
+ distributor = create(:distributor_enterprise, address: distributor_address)
@supplier1 = create(:supplier_enterprise)
@variant1 = create(:variant)
@@ -15,30 +14,30 @@ module OpenFoodNetwork
@variant1.product.save!
shipping_instructions = "pick up on thursday please!"
- order1 = create(:order, :distributor => distributor, :bill_address => bill_address, :special_instructions => shipping_instructions)
- line_item11 = create(:line_item, :variant => @variant1, :order => order1)
+ order1 = create(:order, distributor: distributor, bill_address: bill_address, special_instructions: shipping_instructions)
+ line_item11 = create(:line_item, variant: @variant1, order: order1)
order1.line_items << line_item11
@orders << order1
- order2 = create(:order, :distributor => distributor, :bill_address => bill_address, :special_instructions => shipping_instructions)
- line_item21 = create(:line_item, :variant => @variant1, :order => order2)
+ order2 = create(:order, distributor: distributor, bill_address: bill_address, special_instructions: shipping_instructions)
+ line_item21 = create(:line_item, variant: @variant1, order: order2)
order2.line_items << line_item21
@variant2 = create(:variant)
@variant2.product.supplier = @supplier1
@variant2.product.save!
- line_item22 = create(:line_item, :variant => @variant2, :order => order2)
+ line_item22 = create(:line_item, variant: @variant2, order: order2)
order2.line_items << line_item22
@orders << order2
@supplier2 = create(:supplier_enterprise)
- @variant3 = create(:variant, :weight => nil)
+ @variant3 = create(:variant, weight: nil)
@variant3.product.supplier = @supplier2
@variant3.product.save!
- order3 = create(:order, :distributor => distributor, :bill_address => bill_address, :special_instructions => shipping_instructions)
- line_item31 = create(:line_item, :variant => @variant3, :order => order3)
+ order3 = create(:order, distributor: distributor, bill_address: bill_address, special_instructions: shipping_instructions)
+ line_item31 = create(:line_item, variant: @variant3, order: order3)
order3.line_items << line_item31
@orders << order3
end
@@ -54,12 +53,12 @@ module OpenFoodNetwork
table = subject.table
- line_items = @orders.map{ |o| o.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 { |li| li.quantity }.sum
+ 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
@@ -73,7 +72,7 @@ module OpenFoodNetwork
end
end
- it "should split and group line items from multiple suppliers and of multiple variants" do
+ it "should split and group line items from multiple suppliers and of multiple variants" do
subject = GroupBuyReport.new @orders
table_row_objects = subject.variants_and_quantities
@@ -82,8 +81,8 @@ module OpenFoodNetwork
product_rows = table_row_objects.select { |r| r.class == OpenFoodNetwork::GroupBuyProductRow }
supplier_groups = variant_rows.group_by { |r| r.variant.product.supplier }
- variant_groups = variant_rows.group_by { |r| r.variant }
- product_groups = product_rows.group_by { |r| r.product }
+ variant_groups = variant_rows.group_by(&:variant)
+ product_groups = product_rows.group_by(&:product)
expect(supplier_groups.length).to eq(2)
expect(variant_groups.length).to eq(3)
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 69032c7898..d4853f6be0 100644
--- a/spec/lib/open_food_network/lettuce_share_report_spec.rb
+++ b/spec/lib/open_food_network/lettuce_share_report_spec.rb
@@ -39,8 +39,8 @@ 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) { create(:distributor_enterprise, :address => hub_address) }
+ 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) }
@@ -61,12 +61,11 @@ module OpenFoodNetwork
variant2_override
variant3_override
allow(report).to receive(:child_variants) { Spree::Variant.where(id: [variant, variant2, variant3]) }
- allow(report).to receive(:params) { {distributor_id: hub.id} }
+ allow(report).to receive(:params) { { distributor_id: hub.id } }
rows = report.table
expect(rows.count).to eq 2
expect(rows.map{ |row| row[0] }).to include variant.product.name, variant2.product.name
end
-
end
end
end
diff --git a/spec/lib/open_food_network/option_value_namer_spec.rb b/spec/lib/open_food_network/option_value_namer_spec.rb
index fbef09a8e0..1e3ec2944c 100644
--- a/spec/lib/open_food_network/option_value_namer_spec.rb
+++ b/spec/lib/open_food_network/option_value_namer_spec.rb
@@ -64,7 +64,6 @@ module OpenFoodNetwork
allow(v).to receive(:product) { p }
allow(v).to receive(:unit_value) { 100 }
-
expect(subject.send(:option_value_value_unit)).to eq [100, 'g']
end
@@ -85,7 +84,7 @@ module OpenFoodNetwork
end
it "generates values for all weight scales" do
- [[1.0, 'g'], [1000.0, 'kg'], [1000000.0, 'T']].each do |scale, unit|
+ [[1.0, 'g'], [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) { 100 * scale }
diff --git a/spec/lib/open_food_network/order_and_distributor_report_spec.rb b/spec/lib/open_food_network/order_and_distributor_report_spec.rb
index e2d00b1437..0d7dd1ea50 100644
--- a/spec/lib/open_food_network/order_and_distributor_report_spec.rb
+++ b/spec/lib/open_food_network/order_and_distributor_report_spec.rb
@@ -37,27 +37,27 @@ module OpenFoodNetwork
table = subject.table
expect(table[0]).to eq([
- order.reload.created_at,
- order.id,
- bill_address.full_name,
- order.email,
- bill_address.phone,
- bill_address.city,
- line_item.product.sku,
- line_item.product.name,
- line_item.options_text,
- line_item.quantity,
- line_item.max_quantity,
- line_item.price * line_item.quantity,
- line_item.distribution_fee,
- payment_method.name,
- distributor.name,
- distributor.address.address1,
- distributor.address.city,
- distributor.address.zipcode,
- shipping_method.name,
- shipping_instructions
- ])
+ order.reload.created_at,
+ order.id,
+ bill_address.full_name,
+ order.email,
+ bill_address.phone,
+ bill_address.city,
+ line_item.product.sku,
+ line_item.product.name,
+ line_item.options_text,
+ line_item.quantity,
+ line_item.max_quantity,
+ line_item.price * line_item.quantity,
+ line_item.distribution_fee,
+ payment_method.name,
+ distributor.name,
+ distributor.address.address1,
+ distributor.address.city,
+ distributor.address.zipcode,
+ shipping_method.name,
+ shipping_instructions
+ ])
end
end
end
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 2ba8775657..5bc83d4f0e 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
@@ -11,15 +11,15 @@ 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(: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!
@@ -29,15 +29,15 @@ 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(: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!
@@ -47,19 +47,19 @@ 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)],
- :incoming_exchanges => [incoming_exchange],
- :outgoing_exchanges => [])
+ coordinator_id: coordinator_id,
+ 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(: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!
@@ -69,19 +69,19 @@ 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)],
- :incoming_exchanges => [],
- :outgoing_exchanges => [outgoing_exchange])
+ coordinator_id: coordinator_id,
+ 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(: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!
@@ -91,13 +91,13 @@ 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,
- :exchanges => [exchange],
- :incoming_exchanges => [],
- :outgoing_exchanges => [])
+ coordinator_id: coordinator_id,
+ exchanges: [exchange],
+ incoming_exchanges: [],
+ outgoing_exchanges: [])
applicator = OrderCycleFormApplicator.new(oc, user)
@@ -110,7 +110,7 @@ module OpenFoodNetwork
it "compares exchanges by id only" do
e1 = double(:exchange1, id: 1, foo: 1)
e2 = double(:exchange2, id: 1, foo: 2)
- oc = double(:order_cycle, :exchanges => [e1])
+ oc = double(:order_cycle, exchanges: [e1])
applicator = OrderCycleFormApplicator.new(oc, user)
applicator.instance_eval do
@@ -160,25 +160,23 @@ module OpenFoodNetwork
let!(:coordinator) { oc.coordinator }
let!(:applicator) { OrderCycleFormApplicator.new(oc, user) }
let(:ids) do
- applicator.send(:outgoing_exchange_variant_ids, {
- :enterprise_id => enterprise.id,
- :variants => {
- "#{v1.id}" => true,
- "#{v2.id}" => true,
- "#{v3.id}" => true,
- "#{v5.id}" => false,
- "#{v6.id}" => false,
- "#{v7.id}" => true,
- "#{v8.id}" => true,
- "#{v9.id}" => true
- }
- })
+ applicator.send(:outgoing_exchange_variant_ids,
+ enterprise_id: enterprise.id,
+ variants: {
+ v1.id.to_s => true,
+ v2.id.to_s => true,
+ v3.id.to_s => true,
+ v5.id.to_s => false,
+ v6.id.to_s => false,
+ v7.id.to_s => true,
+ v8.id.to_s => true,
+ v9.id.to_s => true
+ })
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(: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
@@ -222,21 +220,20 @@ module OpenFoodNetwork
let!(:coordinator) { oc.coordinator }
let!(:applicator) { OrderCycleFormApplicator.new(oc, user) }
let(:ids) do
- applicator.send(:incoming_exchange_variant_ids, {
- :enterprise_id => enterprise.id,
- :variants => {
- "#{v1.id}" => true,
- "#{v2.id}" => true,
- "#{v3.id}" => true,
- "#{v4.id}" => false,
- "#{v5.id}" => false,
- "#{v6.id}" => false
- }
- })
+ applicator.send(:incoming_exchange_variant_ids,
+ enterprise_id: enterprise.id,
+ variants: {
+ v1.id.to_s => true,
+ v2.id.to_s => true,
+ v3.id.to_s => true,
+ v4.id.to_s => false,
+ v5.id.to_s => false,
+ v6.id.to_s => false
+ })
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
@@ -301,9 +298,9 @@ module OpenFoodNetwork
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, 999999, exchange.incoming)).to be false
- expect(applicator.send(:exchange_exists?, 999999, exchange.receiver_id, exchange.incoming)).to be false
- expect(applicator.send(:exchange_exists?, 999999, 888888, 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
describe "adding exchanges" do
@@ -321,7 +318,7 @@ 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
@@ -339,7 +336,7 @@ 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
@@ -369,7 +366,7 @@ 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
@@ -389,7 +386,7 @@ 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
@@ -409,7 +406,7 @@ 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
@@ -447,7 +444,7 @@ module OpenFoodNetwork
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 44e4ca7c01..8ed4add63b 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
@@ -50,7 +50,6 @@ module OpenFoodNetwork
expect(subject.orders).to eq([o1])
end
-
it "does not show orders through a hub that the current user does not manage" do
# Given a supplier enterprise with an order for one of its products
supplier.enterprise_roles.create!(user: user)
@@ -109,8 +108,8 @@ module OpenFoodNetwork
it "should do all the filters at once" do
allow(subject).to receive(:params).and_return(order_cycle_id: oc1.id,
- shipping_method_name: sm1.name,
- payment_method_name: pm1.name)
+ shipping_method_name: sm1.name,
+ payment_method_name: pm1.name)
expect(subject.filter(orders)).to eq([order1])
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 016599e7a2..d9299995df 100644
--- a/spec/lib/open_food_network/order_cycle_permissions_spec.rb
+++ b/spec/lib/open_food_network/order_cycle_permissions_spec.rb
@@ -316,7 +316,6 @@ module OpenFoodNetwork
end
end
-
describe "as the manager of a hub" do
let!(:ex_in) { create(:exchange, order_cycle: oc, sender: producer, receiver: coordinator, incoming: true) }
@@ -431,7 +430,6 @@ module OpenFoodNetwork
end
end
-
describe "finding the variants within a hypothetical exchange between two enterprises which are visible to a user" do
let!(:producer1) { create(:supplier_enterprise) }
let!(:producer2) { create(:supplier_enterprise) }
diff --git a/spec/lib/open_food_network/order_grouper_spec.rb b/spec/lib/open_food_network/order_grouper_spec.rb
index 7579200381..8e2e00aa21 100644
--- a/spec/lib/open_food_network/order_grouper_spec.rb
+++ b/spec/lib/open_food_network/order_grouper_spec.rb
@@ -2,16 +2,15 @@ require 'spec_helper'
module OpenFoodNetwork
describe OrderGrouper do
-
before(:each) do
- @items = [1, 2, 3, 4]
+ @items = [1, 2, 3, 4]
end
context "constructing the table" do
it "should build a tree then build a table" do
- rules = [ { group_by: Proc.new { |sentence| sentence.paragraph.chapter }, sort_by: Proc.new { |chapter| chapter.name }, summary_columns: [Proc.new { |is| is.first.paragraph.chapter.name }, Proc.new { |is| "TOTAL" }, Proc.new { |is| "" }, Proc.new { |is| is.sum {|i| i.property1 } } ] },
- { group_by: Proc.new { |sentence| sentence.paragraph }, sort_by: Proc.new { |paragraph| paragraph.name } } ]
- columns = [Proc.new { |is| is.first.paragraph.chapter.name }, Proc.new { |is| is.first.paragraph.name }, Proc.new { |is| is.first.name }, Proc.new { |is| is.sum {|i| i.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
@@ -21,7 +20,6 @@ module OpenFoodNetwork
subject.table(@items)
end
-
end
context "grouping items without rules" do
@@ -31,14 +29,13 @@ module OpenFoodNetwork
column2 = double(:col2)
columns = [column1, column2]
subject = OrderGrouper.new rules, columns
-
+
expect(rules).to receive(:clone).and_return(rules)
expect(subject.build_tree(@items, rules)).to eq(@items)
end
end
context "grouping items with rules" do
-
before(:each) do
@rule1 = double(:rule1)
rule2 = double(:rule2)
@@ -48,7 +45,7 @@ module OpenFoodNetwork
column2 = double(:col2)
@columns = [column1, column2]
end
-
+
it "builds branches by removing a rule from 'rules' and running group_and_sort" do
subject = OrderGrouper.new @rules, @columns
@@ -79,7 +76,7 @@ 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)
@@ -96,12 +93,12 @@ module OpenFoodNetwork
rule1 = double(:rule1)
rule2 = double(:rule2)
@rules = [rule1, rule2]
- @column1 = double(:col1, :call => "Column1")
- @column2 = double(:col2, :call => "Column2")
+ @column1 = double(:col1, call: "Column1")
+ @column2 = double(:col2, call: "Column2")
@columns = [@column1, @column2]
- sumcol1 = double(:sumcol1, :call => "SumColumn1")
- sumcol2 = double(:sumcol2, :call => "SumColumn2")
+ sumcol1 = double(:sumcol1, call: "SumColumn1")
+ sumcol2 = double(:sumcol2, call: "SumColumn2")
@sumcols = [sumcol1, sumcol2]
item1 = double(:item1)
@@ -119,13 +116,13 @@ module OpenFoodNetwork
expect(subject.build_table(@items1)).to eq([["Column1", "Column2"]])
end
-
+
it "should return a row for each key-value pair when given a Hash" do
groups = { items1: @items1, items2: @items2, items3: @items3 }
subject = OrderGrouper.new @rules, @columns
- #subject.should_receive(:build_table).exactly(2).times
+ # subject.should_receive(:build_table).exactly(2).times
expected_return = []
groups.length.times { expected_return << ["Column1", "Column2"] }
@@ -138,12 +135,12 @@ module OpenFoodNetwork
subject = OrderGrouper.new @rules, @columns
expected_return = []
- groups.each do |key, group|
- if key == :summary_row
- expected_return << ["SumColumn1", "SumColumn2"]
- else
- expected_return << ["Column1", "Column2"]
- end
+ groups.each do |key, _group|
+ expected_return << if key == :summary_row
+ ["SumColumn1", "SumColumn2"]
+ else
+ ["Column1", "Column2"]
+ end
end
expect(subject.build_table(groups)).to eq(expected_return)
end
diff --git a/spec/lib/open_food_network/permissions_spec.rb b/spec/lib/open_food_network/permissions_spec.rb
index 0c8e9ee018..39a15954cb 100644
--- a/spec/lib/open_food_network/permissions_spec.rb
+++ b/spec/lib/open_food_network/permissions_spec.rb
@@ -96,7 +96,7 @@ module OpenFoodNetwork
it "compiles the list from variant_override_enterprises_per_hub" do
allow(permissions).to receive(:variant_override_enterprises_per_hub) do
- {1 => [e1.id], 2 => [e1.id, e2.id]}
+ { 1 => [e1.id], 2 => [e1.id, e2.id] }
end
expect(permissions.variant_override_producers).to match_array [e1, e2]
@@ -106,8 +106,9 @@ module OpenFoodNetwork
describe "finding enterprises for which variant overrides can be created, for each hub" do
let!(:hub) { create(:distributor_enterprise) }
let!(:producer) { create(:supplier_enterprise) }
- let!(:er) { create(:enterprise_relationship, parent: producer, child: hub,
- permissions_list: [:create_variant_overrides])
+ let!(:er) {
+ create(:enterprise_relationship, parent: producer, child: hub,
+ permissions_list: [:create_variant_overrides])
}
before do
@@ -117,33 +118,34 @@ module OpenFoodNetwork
it "returns enterprises as hub_id => [producer, ...]" do
expect(permissions.variant_override_enterprises_per_hub).to eq(
- {hub.id => [producer.id]}
+ hub.id => [producer.id]
)
end
it "returns only permissions relating to managed hubs" do
create(:enterprise_relationship, parent: e1, child: e2,
- permissions_list: [:create_variant_overrides])
+ permissions_list: [:create_variant_overrides])
expect(permissions.variant_override_enterprises_per_hub).to eq(
- {hub.id => [producer.id]}
+ hub.id => [producer.id]
)
end
it "returns only create_variant_overrides permissions" do
allow(permissions).to receive(:managed_enterprises) { Enterprise.where(id: [hub, e2]) }
create(:enterprise_relationship, parent: e1, child: e2,
- permissions_list: [:manage_products])
+ permissions_list: [:manage_products])
expect(permissions.variant_override_enterprises_per_hub).to eq(
- {hub.id => [producer.id]}
+ hub.id => [producer.id]
)
end
describe "hubs connected to the user by relationships only" do
let!(:producer_managed) { create(:supplier_enterprise) }
- let!(:er_oc) { create(:enterprise_relationship, parent: hub, child: producer_managed,
- permissions_list: [:add_to_order_cycle, :create_variant_overrides])
+ let!(:er_oc) {
+ create(:enterprise_relationship, parent: hub, child: producer_managed,
+ permissions_list: [:add_to_order_cycle, :create_variant_overrides])
}
before do
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 a0efbdddd8..97cb4de17b 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
@@ -14,24 +14,24 @@ module OpenFoodNetwork
it "Should return headers" do
expect(subject.header).to eq([
- "Supplier",
- "Producer Suburb",
- "Product",
- "Product Properties",
- "Taxons",
- "Variant Value",
- "Price",
- "Group Buy Unit Quantity",
- "Amount",
- "SKU"
- ])
+ "Supplier",
+ "Producer Suburb",
+ "Product",
+ "Product Properties",
+ "Taxons",
+ "Variant Value",
+ "Price",
+ "Group Buy Unit Quantity",
+ "Amount",
+ "SKU"
+ ])
end
it "should build a table from a list of variants" do
variant = double(:variant, sku: "sku",
- full_name: "Variant Name",
- count_on_hand: 10,
- price: 100)
+ full_name: "Variant Name",
+ 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, :name).and_return("Product Name")
@@ -41,17 +41,17 @@ module OpenFoodNetwork
allow(subject).to receive(:variants).and_return [variant]
expect(subject.table).to eq([[
- "Supplier",
- "A city",
- "Product Name",
- "property1, property2",
- "taxon1, taxon2",
- "Variant Name",
- 100,
- 21,
- "",
- "sku"
- ]])
+ "Supplier",
+ "A city",
+ "Product Name",
+ "property1, property2",
+ "taxon1, taxon2",
+ "Variant Name",
+ 100,
+ 21,
+ "",
+ "sku"
+ ]])
end
it "fetches variants for some params" do
@@ -180,7 +180,8 @@ module OpenFoodNetwork
order_cycle_id: order_cycle.id,
supplier_id: supplier.id,
distributor_id: distributor.id,
- report_type: 'inventory')
+ report_type: 'inventory'
+ )
subject.filter(variants)
end
end
diff --git a/spec/lib/open_food_network/products_cache_spec.rb b/spec/lib/open_food_network/products_cache_spec.rb
index 84c06ff2d4..47d18fa8ba 100644
--- a/spec/lib/open_food_network/products_cache_spec.rb
+++ b/spec/lib/open_food_network/products_cache_spec.rb
@@ -128,7 +128,6 @@ module OpenFoodNetwork
end
end
-
describe "when a variant override is destroyed" do
let(:vo) { double(:variant_override) }
@@ -138,7 +137,6 @@ module OpenFoodNetwork
end
end
-
describe "when a producer property is changed" do
let(:s) { create(:supplier_enterprise) }
let(:pp) { s.producer_properties.last }
@@ -172,7 +170,6 @@ module OpenFoodNetwork
end
end
-
describe "when a producer property is destroyed" do
let(:producer_property) { double(:producer_property) }
@@ -182,7 +179,6 @@ module OpenFoodNetwork
end
end
-
describe "when an order cycle is changed" do
let(:variant) { create(:variant) }
let(:s) { create(:supplier_enterprise) }
@@ -228,7 +224,6 @@ module OpenFoodNetwork
end
end
-
describe "when an exchange is changed" do
let(:s) { create(:supplier_enterprise) }
let(:c) { create(:distributor_enterprise) }
@@ -283,7 +278,6 @@ module OpenFoodNetwork
end
end
-
describe "when an exchange is destroyed" do
let(:exchange) { double(:exchange) }
@@ -293,7 +287,6 @@ module OpenFoodNetwork
end
end
-
describe "when an enterprise fee is changed" do
let(:s) { create(:supplier_enterprise) }
let(:c) { create(:distributor_enterprise) }
@@ -303,7 +296,6 @@ module OpenFoodNetwork
let(:ef_coord) { create(:enterprise_fee, order_cycles: [oc]) }
let(:oc) { create(:open_order_cycle, coordinator: c) }
-
describe "updating exchanges when it's a supplier fee" do
let(:v) { create(:variant) }
let!(:ex1) { create(:exchange, order_cycle: oc, sender: s, receiver: c, incoming: true, variants: [v], enterprise_fees: [ef]) }
@@ -343,14 +335,12 @@ module OpenFoodNetwork
end
end
-
it "updates order cycles when it's a coordinator fee" do
ef_coord
expect(ProductsCache).to receive(:order_cycle_changed).with(oc).once
ProductsCache.enterprise_fee_changed ef_coord
end
-
describe "updating exchanges when it's a distributor fee" do
let(:ex0) { create(:exchange, order_cycle: oc, sender: s, receiver: c, incoming: true, enterprise_fees: [ef]) }
let(:ex1) { create(:exchange, order_cycle: oc, sender: c, receiver: d1, incoming: false, enterprise_fees: [ef]) }
diff --git a/spec/lib/open_food_network/products_renderer_spec.rb b/spec/lib/open_food_network/products_renderer_spec.rb
index 47564f3aec..e7ee727c41 100644
--- a/spec/lib/open_food_network/products_renderer_spec.rb
+++ b/spec/lib/open_food_network/products_renderer_spec.rb
@@ -24,13 +24,13 @@ module OpenFoodNetwork
end
it "sorts products by the distributor's preferred taxon list" do
- allow(distributor).to receive(:preferred_shopfront_taxon_order) {"#{t1.id},#{t2.id}"}
+ allow(distributor).to receive(:preferred_shopfront_taxon_order) { "#{t1.id},#{t2.id}" }
products = pr.send(:load_products)
expect(products).to eq([p2, p4, p1, p3])
end
it "alphabetizes products by name when taxon list is not set" do
- allow(distributor).to receive(:preferred_shopfront_taxon_order) {""}
+ allow(distributor).to receive(:preferred_shopfront_taxon_order) { "" }
products = pr.send(:load_products)
expect(products).to eq([p1, p2, p3, p4])
end
diff --git a/spec/lib/open_food_network/referer_parser_spec.rb b/spec/lib/open_food_network/referer_parser_spec.rb
index d8a077c53f..58c677faf1 100644
--- a/spec/lib/open_food_network/referer_parser_spec.rb
+++ b/spec/lib/open_food_network/referer_parser_spec.rb
@@ -3,7 +3,6 @@ require 'spec_helper'
module OpenFoodNetwork
describe RefererParser do
-
it "handles requests without referer" do
expect(RefererParser.path(nil)).to be_nil
end
diff --git a/spec/lib/open_food_network/reports/report_spec.rb b/spec/lib/open_food_network/reports/report_spec.rb
index 6ee0f75aec..64baf06ba6 100644
--- a/spec/lib/open_food_network/reports/report_spec.rb
+++ b/spec/lib/open_food_network/reports/report_spec.rb
@@ -1,10 +1,10 @@
require 'open_food_network/reports/report'
module OpenFoodNetwork::Reports
- P1 = Proc.new { |o| o[:one] }
- P2 = Proc.new { |o| o[:two] }
- P3 = Proc.new { |o| o[:three] }
- P4 = Proc.new { |o| o[:four] }
+ P1 = proc { |o| o[:one] }
+ P2 = proc { |o| o[:two] }
+ P3 = proc { |o| o[:three] }
+ P4 = proc { |o| o[:four] }
class TestReport < Report
header 'One', 'Two', 'Three', 'Four'
@@ -37,7 +37,6 @@ module OpenFoodNetwork::Reports
column { |o| my_helper(o) }
end
-
private
def self.my_helper(o)
@@ -45,12 +44,11 @@ module OpenFoodNetwork::Reports
end
end
-
describe Report do
let(:report) { TestReport.new }
let(:helper_report) { HelperReport.new }
let(:rules_head) { TestReport._rules_head }
- let(:data) { {one: 1, two: 2, three: 3, four: 4} }
+ let(:data) { { one: 1, two: 2, three: 3, four: 4 } }
it "returns the header" do
expect(report.header).to eq(%w(One Two Three Four))
@@ -92,8 +90,8 @@ module OpenFoodNetwork::Reports
describe "outputting rules" do
it "outputs the rules" do
- expect(report.rules).to eq([{group_by: P1, sort_by: P2},
- {group_by: P3, sort_by: P4, summary_columns: [P1, P4]}])
+ expect(report.rules).to eq([{ group_by: P1, sort_by: P2 },
+ { group_by: P3, sort_by: P4, summary_columns: [P1, P4] }])
end
end
end
diff --git a/spec/lib/open_food_network/reports/row_spec.rb b/spec/lib/open_food_network/reports/row_spec.rb
index 9881e4c2dc..cd945a97d2 100644
--- a/spec/lib/open_food_network/reports/row_spec.rb
+++ b/spec/lib/open_food_network/reports/row_spec.rb
@@ -3,7 +3,7 @@ require 'open_food_network/reports/row'
module OpenFoodNetwork::Reports
describe Row do
let(:row) { Row.new }
- let(:proc) { Proc.new {} }
+ let(:proc) { proc {} }
it "can define a number of columns and return them as an array" do
row.column(&proc)
diff --git a/spec/lib/open_food_network/reports/rule_spec.rb b/spec/lib/open_food_network/reports/rule_spec.rb
index a8428e037a..94223d1891 100644
--- a/spec/lib/open_food_network/reports/rule_spec.rb
+++ b/spec/lib/open_food_network/reports/rule_spec.rb
@@ -3,16 +3,16 @@ require 'open_food_network/reports/rule'
module OpenFoodNetwork::Reports
describe Rule do
let(:rule) { Rule.new }
- let(:proc) { Proc.new {} }
+ let(:proc) { proc {} }
it "can define a group proc and return it in a hash" do
rule.group(&proc)
- expect(rule.to_h).to eq({group_by: proc, sort_by: nil})
+ expect(rule.to_h).to eq(group_by: proc, sort_by: nil)
end
it "can define a sort proc and return it in a hash" do
rule.sort(&proc)
- expect(rule.to_h).to eq({group_by: nil, sort_by: proc})
+ expect(rule.to_h).to eq(group_by: nil, sort_by: proc)
end
it "can define a nested rule" do
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 88fc808826..faaab2306f 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
@@ -116,7 +116,7 @@ module OpenFoodNetwork
context "when an override exists" do
before { vo }
-
+
context "when variant in stock" do
it "returns true if VO in stock" do
scoper.scope v
@@ -127,12 +127,12 @@ module OpenFoodNetwork
vo.update_attribute :count_on_hand, 0
scoper.scope v
expect(v.in_stock?).to eq(false)
- end
+ end
end
context "when variant out of stock" do
before { v.on_hand = 0 }
-
+
it "returns true if VO in stock" do
scoper.scope v
expect(v.in_stock?).to eq(true)
@@ -142,7 +142,7 @@ module OpenFoodNetwork
vo.update_attribute :count_on_hand, 0
scoper.scope v
expect(v.in_stock?).to eq(false)
- end
+ end
end
end
diff --git a/spec/lib/open_food_network/subscription_summarizer_spec.rb b/spec/lib/open_food_network/subscription_summarizer_spec.rb
index 973ec7620c..38855ccab5 100644
--- a/spec/lib/open_food_network/subscription_summarizer_spec.rb
+++ b/spec/lib/open_food_network/subscription_summarizer_spec.rb
@@ -21,7 +21,7 @@ module OpenFoodNetwork
let(:summary) { double(:summary) }
before do
- summarizer.instance_variable_set(:@summaries, { 123 => summary })
+ summarizer.instance_variable_set(:@summaries, 123 => summary)
end
it "returns the existing summary object" do
diff --git a/spec/lib/open_food_network/subscription_summary_spec.rb b/spec/lib/open_food_network/subscription_summary_spec.rb
index 7d72e4f4ba..f5b0cd8d71 100644
--- a/spec/lib/open_food_network/subscription_summary_spec.rb
+++ b/spec/lib/open_food_network/subscription_summary_spec.rb
@@ -54,7 +54,7 @@ module OpenFoodNetwork
end
describe "#order_count" do
- let(:order_ids) { [1,2,3,4,5,6,7] }
+ let(:order_ids) { [1, 2, 3, 4, 5, 6, 7] }
it "counts the number of items in the order_ids instance_variable" do
summary.instance_variable_set(:@order_ids, order_ids)
expect(summary.order_count).to be 7
@@ -62,7 +62,7 @@ module OpenFoodNetwork
end
describe "#success_count" do
- let(:success_ids) { [1,2,3,4,5,6,7] }
+ let(:success_ids) { [1, 2, 3, 4, 5, 6, 7] }
it "counts the number of items in the success_ids instance_variable" do
summary.instance_variable_set(:@success_ids, success_ids)
expect(summary.success_count).to be 7
@@ -70,8 +70,8 @@ module OpenFoodNetwork
end
describe "#issue_count" do
- let(:order_ids) { [1,3,5,7,9] }
- let(:success_ids) { [1,2,3,4,5] }
+ let(:order_ids) { [1, 3, 5, 7, 9] }
+ let(:success_ids) { [1, 2, 3, 4, 5] }
it "counts the number of items in order_ids that are not in success_ids" do
summary.instance_variable_set(:@order_ids, order_ids)
@@ -112,8 +112,8 @@ module OpenFoodNetwork
let(:issues) { { type: { 7 => "message", 8 => "message" } } }
before do
- summary.instance_variable_set(:@order_ids, [1,3,5,7,9])
- summary.instance_variable_set(:@success_ids, [1,2,3,4,5])
+ summary.instance_variable_set(:@order_ids, [1, 3, 5, 7, 9])
+ summary.instance_variable_set(:@success_ids, [1, 2, 3, 4, 5])
summary.instance_variable_set(:@issues, issues)
end
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 97551df96e..3f9186dc16 100644
--- a/spec/lib/open_food_network/tag_rule_applicator_spec.rb
+++ b/spec/lib/open_food_network/tag_rule_applicator_spec.rb
@@ -3,27 +3,27 @@ require 'open_food_network/tag_rule_applicator'
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!(: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!(: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
let(:applicator) { OpenFoodNetwork::TagRuleApplicator.new(nil, "FilterProducts", ["tag1"]) }
- it { expect{applicator}.to raise_error "Enterprise cannot be nil" }
+ it { expect{ applicator }.to raise_error "Enterprise cannot be nil" }
end
context "when rule_type is nil" do
let(:applicator) { OpenFoodNetwork::TagRuleApplicator.new(enterprise, nil, ["tag1"]) }
- it { expect{applicator}.to raise_error "Rule Type cannot be nil" }
+ it { expect{ applicator }.to raise_error "Rule Type cannot be nil" }
end
context "when rule_type does not match an existing rule type" do
let(:applicator) { OpenFoodNetwork::TagRuleApplicator.new(enterprise, "FilterSomething", ["tag1"]) }
- it { expect{applicator}.to raise_error NameError }
+ it { expect{ applicator }.to raise_error NameError }
end
context "when enterprise and rule_type are present" do
@@ -58,9 +58,9 @@ module OpenFoodNetwork
context "when customer_tags are present" do
let!(:customer_tags) { ["tag1"] }
- let(:rules) { applicator.send(:rules)}
- let(:customer_rules) { applicator.send(:customer_rules)}
- let(:default_rules) { applicator.send(:default_rules)}
+ let(:rules) { applicator.send(:rules) }
+ let(:customer_rules) { applicator.send(:customer_rules) }
+ let(:default_rules) { applicator.send(:default_rules) }
it "stores enterprise, rule_class and customer_tags as instance variables" do
expect(applicator.enterprise).to eq enterprise
@@ -181,8 +181,8 @@ module OpenFoodNetwork
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(: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] } }
@@ -217,11 +217,10 @@ module OpenFoodNetwork
end
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
@@ -229,7 +228,7 @@ module OpenFoodNetwork
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
diff --git a/spec/lib/open_food_network/user_balance_calculator_spec.rb b/spec/lib/open_food_network/user_balance_calculator_spec.rb
index d933ea8f73..021e0376ea 100644
--- a/spec/lib/open_food_network/user_balance_calculator_spec.rb
+++ b/spec/lib/open_food_network/user_balance_calculator_spec.rb
@@ -7,19 +7,23 @@ module OpenFoodNetwork
let!(:user1) { create(:user) }
let!(:hub1) { create(:distributor_enterprise) }
- let!(:o1) { create(:order_with_totals_and_distribution,
- user: user1, distributor: hub1,
- completed_at: 1.day.ago)
- } #total=13 (10 + 3 shipping fee)
- let!(:o2) { create(:order_with_totals_and_distribution,
- user: user1, distributor: hub1,
- completed_at: 1.day.ago)
- } #total=13 (10 + 3 shipping fee)
- let!(:p1) { create(:payment, order: o1, amount: 15.00,
- state: "completed")
+ let!(:o1) {
+ create(:order_with_totals_and_distribution,
+ user: user1, distributor: hub1,
+ completed_at: 1.day.ago)
+ } # total=13 (10 + 3 shipping fee)
+ let!(:o2) {
+ create(:order_with_totals_and_distribution,
+ user: user1, distributor: hub1,
+ completed_at: 1.day.ago)
+ } # total=13 (10 + 3 shipping fee)
+ let!(:p1) {
+ create(:payment, order: o1, amount: 15.00,
+ state: "completed")
}
- let!(:p2) { create(:payment, order: o2, amount: 2.00,
- state: "completed")
+ let!(:p2) {
+ create(:payment, order: o2, amount: 2.00,
+ state: "completed")
}
it "finds the correct balance for this email and enterprise" do
@@ -28,12 +32,14 @@ module OpenFoodNetwork
context "with another hub" do
let!(:hub2) { create(:distributor_enterprise) }
- let!(:o3) { create(:order_with_totals_and_distribution,
- user: user1, distributor: hub2,
- completed_at: 1.day.ago)
- } #total=13 (10 + 3 shipping fee)
- let!(:p3) { create(:payment, order: o3, amount: 15.00,
- state: "completed")
+ let!(:o3) {
+ create(:order_with_totals_and_distribution,
+ user: user1, distributor: hub2,
+ completed_at: 1.day.ago)
+ } # total=13 (10 + 3 shipping fee)
+ let!(:p3) {
+ create(:payment, order: o3, amount: 15.00,
+ state: "completed")
}
it "does not find the balance for other enterprises" do
@@ -43,12 +49,14 @@ module OpenFoodNetwork
context "with another user" do
let!(:user2) { create(:user) }
- let!(:o4) { create(:order_with_totals_and_distribution,
- user: user2, distributor: hub1,
- completed_at: 1.day.ago)
- } #total=13 (10 + 3 shipping fee)
- let!(:p3) { create(:payment, order: o4, amount: 20.00,
- state: "completed")
+ let!(:o4) {
+ create(:order_with_totals_and_distribution,
+ user: user2, distributor: hub1,
+ completed_at: 1.day.ago)
+ } # total=13 (10 + 3 shipping fee)
+ let!(:p3) {
+ create(:payment, order: o4, amount: 20.00,
+ state: "completed")
}
it "does not find the balance for other users" do
@@ -57,12 +65,14 @@ module OpenFoodNetwork
end
context "with canceled orders" do
- let!(:o4) { create(:order_with_totals_and_distribution,
- user: user1, distributor: hub1,
- completed_at: 1.day.ago, state: "canceled")
- } #total=10
- let!(:p4) { create(:payment, order: o4, amount: 20.00,
- state: "completed")
+ let!(:o4) {
+ create(:order_with_totals_and_distribution,
+ user: user1, distributor: hub1,
+ completed_at: 1.day.ago, state: "canceled")
+ } # total=10
+ let!(:p4) {
+ create(:payment, order: o4, amount: 20.00,
+ state: "completed")
}
it "does not include canceled orders in the balance" do
diff --git a/spec/lib/open_food_network/users_and_enterprises_report_spec.rb b/spec/lib/open_food_network/users_and_enterprises_report_spec.rb
index 7410a9cc1c..28ab6bfc28 100644
--- a/spec/lib/open_food_network/users_and_enterprises_report_spec.rb
+++ b/spec/lib/open_food_network/users_and_enterprises_report_spec.rb
@@ -31,7 +31,7 @@ module OpenFoodNetwork
{ "created_at" => "2015-01-01", "name" => "bbb" },
{ "created_at" => "2015-01-02", "name" => "aaa" }
]
- expect(subject.sort uae_mock).to eq [ uae_mock[1], uae_mock[0] ]
+ expect(subject.sort(uae_mock)).to eq [uae_mock[1], uae_mock[0]]
end
it "then sorts by name" do
@@ -39,7 +39,7 @@ module OpenFoodNetwork
{ "name" => "aaa", "relationship_type" => "bbb", "user_email" => "bbb" },
{ "name" => "bbb", "relationship_type" => "aaa", "user_email" => "aaa" }
]
- expect(subject.sort uae_mock).to eq [ uae_mock[0], uae_mock[1] ]
+ expect(subject.sort(uae_mock)).to eq [uae_mock[0], uae_mock[1]]
end
it "then sorts by relationship type (reveresed)" do
@@ -48,7 +48,7 @@ module OpenFoodNetwork
{ "name" => "aaa", "relationship_type" => "aaa", "user_email" => "aaa" },
{ "name" => "aaa", "relationship_type" => "bbb", "user_email" => "aaa" }
]
- expect(subject.sort uae_mock).to eq [ uae_mock[2], uae_mock[0], uae_mock[1] ]
+ expect(subject.sort(uae_mock)).to eq [uae_mock[2], uae_mock[0], uae_mock[1]]
end
it "then sorts by user_email" do
@@ -57,7 +57,7 @@ module OpenFoodNetwork
{ "name" => "aaa", "relationship_type" => "aaa", "user_email" => "aaa" },
{ "name" => "aaa", "relationship_type" => "aaa", "user_email" => "bbb" }
]
- expect(subject.sort uae_mock).to eq [ uae_mock[0], uae_mock[1], uae_mock[2] ]
+ expect(subject.sort(uae_mock)).to eq [uae_mock[0], uae_mock[1], uae_mock[2]]
end
end
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 d2a437d57f..cf2ef55a8a 100644
--- a/spec/lib/open_food_network/xero_invoices_report_spec.rb
+++ b/spec/lib/open_food_network/xero_invoices_report_spec.rb
@@ -44,12 +44,12 @@ module OpenFoodNetwork
end
it "displays fee summary rows when summary report" do
- allow(report).to receive(:detail?) { false }
+ allow(report).to receive(:detail?) { false }
expect(summary_rows).to include 'fee'
end
it "displays fee summary rows when detail report" do
- allow(report).to receive(:detail?) { true }
+ allow(report).to receive(:detail?) { true }
expect(summary_rows).to include 'fee'
end
diff --git a/spec/lib/spree/product_filters_spec.rb b/spec/lib/spree/product_filters_spec.rb
index 5573ef0407..5829d9f450 100644
--- a/spec/lib/spree/product_filters_spec.rb
+++ b/spec/lib/spree/product_filters_spec.rb
@@ -5,7 +5,7 @@ describe Spree::ProductFilters do
it "provides filtering for all distributors" do
3.times { create(:distributor_enterprise) }
Enterprise.is_distributor.sort.map { |d| [d.name, d.name] }.each do |distributor|
- expect(Spree::ProductFilters.distributor_filter[:labels]).to include distributor
+ expect(Spree::ProductFilters.distributor_filter[:labels]).to include distributor
end
end
end
diff --git a/spec/lib/stripe/account_connector_spec.rb b/spec/lib/stripe/account_connector_spec.rb
index 1b5721ba33..6b04b0fa1c 100644
--- a/spec/lib/stripe/account_connector_spec.rb
+++ b/spec/lib/stripe/account_connector_spec.rb
@@ -55,7 +55,7 @@ module Stripe
before do
stub_request(:post, "https://connect.stripe.com/oauth/token").
- with(body: {"code"=>"code", "grant_type"=>"authorization_code"}).
+ with(body: { "code" => "code", "grant_type" => "authorization_code" }).
to_return(status: 200, body: JSON.generate(token_response) )
end
diff --git a/spec/mailers/enterprise_mailer_spec.rb b/spec/mailers/enterprise_mailer_spec.rb
index ab92a123d2..9c6477e872 100644
--- a/spec/mailers/enterprise_mailer_spec.rb
+++ b/spec/mailers/enterprise_mailer_spec.rb
@@ -13,11 +13,11 @@ describe EnterpriseMailer do
describe "#welcome" do
it "sends a welcome email when given an enterprise" do
- EnterpriseMailer.welcome(enterprise).deliver
+ EnterpriseMailer.welcome(enterprise).deliver
- mail = ActionMailer::Base.deliveries.first
- expect(mail.subject)
- .to eq "#{enterprise.name} is now on #{Spree::Config[:site_name]}"
+ mail = ActionMailer::Base.deliveries.first
+ expect(mail.subject)
+ .to eq "#{enterprise.name} is now on #{Spree::Config[:site_name]}"
end
end
diff --git a/spec/mailers/order_mailer_spec.rb b/spec/mailers/order_mailer_spec.rb
index aaa436cea6..0e39568ba9 100644
--- a/spec/mailers/order_mailer_spec.rb
+++ b/spec/mailers/order_mailer_spec.rb
@@ -15,12 +15,12 @@ describe Spree::OrderMailer do
ActionMailer::Base.deliveries = []
@bill_address = create(:address)
- @distributor_address = create(:address, :address1 => "distributor address", :city => 'The Shire', :zipcode => "1234")
- @distributor = create(:distributor_enterprise, :address => @distributor_address)
+ @distributor_address = create(:address, address1: "distributor address", city: 'The Shire', zipcode: "1234")
+ @distributor = create(:distributor_enterprise, address: @distributor_address)
product = create(:product)
@shipping_instructions = "pick up on thursday please!"
- ship_address = create(:address, :address1 => "distributor address", :city => 'The Shire', :zipcode => "1234")
- @order1 = create(:order, :distributor => @distributor, :bill_address => @bill_address, ship_address: ship_address, :special_instructions => @shipping_instructions)
+ ship_address = create(:address, address1: "distributor address", city: 'The Shire', zipcode: "1234")
+ @order1 = create(:order, distributor: @distributor, bill_address: @bill_address, ship_address: ship_address, special_instructions: @shipping_instructions)
ActionMailer::Base.deliveries = []
end
diff --git a/spec/mailers/producer_mailer_spec.rb b/spec/mailers/producer_mailer_spec.rb
index 5d2b13f45f..c74998c3ab 100644
--- a/spec/mailers/producer_mailer_spec.rb
+++ b/spec/mailers/producer_mailer_spec.rb
@@ -75,7 +75,6 @@ describe ProducerMailer, type: :mailer do
.to have_selector("td", text: "$30.00")
end
-
it "displays tax totals for each product" do
# Tax for p1 line items
expect(body_as_html(mail).find("table.order-summary tr", text: p1.name))
@@ -102,7 +101,6 @@ describe ProducerMailer, type: :mailer do
end.to change(ActionMailer::Base.deliveries, :count).by(0)
end
-
private
def body_lines_including(mail, s)
diff --git a/spec/models/column_preference_spec.rb b/spec/models/column_preference_spec.rb
index 5950a341c2..264bc3af93 100644
--- a/spec/models/column_preference_spec.rb
+++ b/spec/models/column_preference_spec.rb
@@ -10,18 +10,19 @@ describe ColumnPreference, type: :model do
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(:defaults) { {
- col1: { name: "col1", visible: false },
- col2: { name: "col2", visible: true },
- col3: { name: "col3", visible: false },
- } }
+ let(:defaults) {
+ {
+ col1: { name: "col1", visible: false },
+ col2: { name: "col2", visible: true },
+ col3: { name: "col3", visible: false },
+ } }
context "when the user has preferences stored for the given action" do
before do
allow(ColumnPreference).to receive(:some_action_columns) { defaults }
end
- let(:preferences) { ColumnPreference.for(user, :some_action)}
+ let(:preferences) { ColumnPreference.for(user, :some_action) }
it "builds an entry for each column listed in the defaults" do
expect(preferences.count).to eq 3
@@ -43,7 +44,7 @@ describe ColumnPreference, type: :model do
allow(ColumnPreference).to receive(:some_action_columns) { defaults }
end
- let(:preferences) { ColumnPreference.for(create(:user), :some_action)}
+ let(:preferences) { ColumnPreference.for(create(:user), :some_action) }
it "builds an entry for each column listed in the defaults" do
expect(preferences.count).to eq 3
diff --git a/spec/models/concerns/variant_stock_spec.rb b/spec/models/concerns/variant_stock_spec.rb
index 0c521ac3e6..489737ec18 100644
--- a/spec/models/concerns/variant_stock_spec.rb
+++ b/spec/models/concerns/variant_stock_spec.rb
@@ -64,7 +64,7 @@ describe VariantStock do
expect { variant.on_hand = 3 }
.to raise_error(StandardError)
end
- end
+ end
end
context 'when track_inventory_levels is not set' do
@@ -146,7 +146,7 @@ describe VariantStock do
expect(variant.can_supply?(0)).to eq(true)
end
it "returns true for large quantity" do
- expect(variant.can_supply?(100000)).to eq(true)
+ expect(variant.can_supply?(100_000)).to eq(true)
end
end
@@ -161,7 +161,7 @@ describe VariantStock do
it "returns false for number above stock level" do
expect(variant.can_supply?(variant.total_on_hand + 1)).to eq(false)
- end
+ end
end
context 'when variant out of stock' do
diff --git a/spec/models/content_configuration_spec.rb b/spec/models/content_configuration_spec.rb
index f1eba22219..3de4fdfdfe 100644
--- a/spec/models/content_configuration_spec.rb
+++ b/spec/models/content_configuration_spec.rb
@@ -10,7 +10,7 @@ describe ContentConfiguration do
end
def image_exist?(default_url)
- image_path = default_url.gsub(/\/assets\//,'/assets/images/')
+ image_path = default_url.gsub(/\/assets\//, '/assets/images/')
File.exist?(File.join(Rails.root, 'app', image_path))
end
end
diff --git a/spec/models/customer_spec.rb b/spec/models/customer_spec.rb
index 106ec3bcf7..217748bb6d 100644
--- a/spec/models/customer_spec.rb
+++ b/spec/models/customer_spec.rb
@@ -24,14 +24,14 @@ describe Customer, type: :model do
it 'updates the shipping address' do
expect(customer.shipping_address).to be_nil
- ship_address = {firstname: 'fname',
- lastname: 'lname',
- zipcode: "3127",
- city: "Melbourne",
- state_id: 1,
- phone: "455500146",
- address1: "U 3/32 Florence Road Surrey Hills2",
- country_id: 1}
+ ship_address = { firstname: 'fname',
+ lastname: 'lname',
+ zipcode: "3127",
+ city: "Melbourne",
+ state_id: 1,
+ phone: "455500146",
+ address1: "U 3/32 Florence Road Surrey Hills2",
+ country_id: 1 }
customer.update_attributes!(ship_address_attributes: ship_address)
expect(customer.ship_address.city).to eq 'Melbourne'
diff --git a/spec/models/enterprise_fee_spec.rb b/spec/models/enterprise_fee_spec.rb
index 317715aafb..c36b100332 100644
--- a/spec/models/enterprise_fee_spec.rb
+++ b/spec/models/enterprise_fee_spec.rb
@@ -37,8 +37,7 @@ describe EnterpriseFee do
let(:tax_category) { create(:tax_category) }
let(:enterprise_fee) { create(:enterprise_fee, tax_category_id: nil, inherits_tax_category: true) }
-
- it "maintains valid tax_category settings" do
+ it "maintains valid tax_category settings" do
# Changing just tax_category, when inheriting
# tax_category is changed, inherits.. set to false
enterprise_fee.assign_attributes(tax_category_id: tax_category.id)
@@ -133,11 +132,11 @@ describe EnterpriseFee do
it "does not clear adjustments from another originator" do
order = create(:order)
tax_rate = create(:tax_rate, calculator: build(:calculator))
- order.adjustments.create({:amount => 12.34,
- :source => order,
- :originator => tax_rate,
- :state => 'closed',
- :label => 'hello' }, :without_protection => true)
+ order.adjustments.create({ amount: 12.34,
+ source: order,
+ originator: tax_rate,
+ state: 'closed',
+ label: 'hello' }, without_protection: true)
expect do
EnterpriseFee.clear_all_adjustments_on_order order
diff --git a/spec/models/enterprise_relationship_spec.rb b/spec/models/enterprise_relationship_spec.rb
index 11fd9fe79a..d014ba963e 100644
--- a/spec/models/enterprise_relationship_spec.rb
+++ b/spec/models/enterprise_relationship_spec.rb
@@ -95,11 +95,11 @@ describe EnterpriseRelationship do
it "finds relationships that grant a particular permission" do
er1 = create(:enterprise_relationship, parent: e1, child: e2,
- permissions_list: ['one', 'two'])
+ permissions_list: ['one', 'two'])
er2 = create(:enterprise_relationship, parent: e2, child: e3,
- permissions_list: ['two', 'three'])
+ permissions_list: ['two', 'three'])
er3 = create(:enterprise_relationship, parent: e3, child: e1,
- permissions_list: ['three', 'four'])
+ permissions_list: ['three', 'four'])
expect(EnterpriseRelationship.with_permission('two')).to match_array [er1, er2]
end
@@ -119,8 +119,8 @@ describe EnterpriseRelationship do
it "categorises enterprises into distributors and producers" do
e2.update_attribute :is_primary_producer, true
expect(EnterpriseRelationship.relatives).to eq(
- {e1.id => {distributors: Set.new([e2.id]), producers: Set.new([e1.id, e2.id])},
- e2.id => {distributors: Set.new([e2.id]), producers: Set.new([e2.id, e1.id])}}
+ e1.id => { distributors: Set.new([e2.id]), producers: Set.new([e1.id, e2.id]) },
+ e2.id => { distributors: Set.new([e2.id]), producers: Set.new([e2.id, e1.id]) }
)
end
@@ -147,8 +147,8 @@ 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!(: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))) }
@@ -188,8 +188,8 @@ 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!(: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) }
let!(:vo2) { create(:variant_override, hub: hub, variant: create(:variant, product: create(:product, supplier: producer)), permission_revoked_at: Time.now) }
let!(:vo3) { create(:variant_override, hub: hub, variant: create(:variant, product: create(:product, supplier: some_other_producer)), permission_revoked_at: Time.now) }
diff --git a/spec/models/enterprise_spec.rb b/spec/models/enterprise_spec.rb
index 1a31a4d5cb..c648031e88 100644
--- a/spec/models/enterprise_spec.rb
+++ b/spec/models/enterprise_spec.rb
@@ -119,7 +119,7 @@ describe Enterprise do
it "requires an owner" do
expect{
e = create(:enterprise, owner: nil)
- }.to raise_error ActiveRecord::RecordInvalid, "Validation failed: Owner can't be blank"
+ }.to raise_error ActiveRecord::RecordInvalid, "Validation failed: Owner can't be blank"
end
describe "name uniqueness" do
@@ -185,7 +185,7 @@ describe Enterprise do
end
describe "delegations" do
- #subject { FactoryBot.create(:distributor_enterprise, :address => FactoryBot.create(:address)) }
+ # subject { FactoryBot.create(:distributor_enterprise, :address => FactoryBot.create(:address)) }
it { is_expected.to delegate(:latitude).to(:address) }
it { is_expected.to delegate(:longitude).to(:address) }
@@ -315,7 +315,7 @@ 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
@@ -425,7 +425,6 @@ describe Enterprise do
end
end
-
describe "when a new hub is created" do
it "it creates links to the hub, from all producers owned by the same user, granting add_to_order_cycle and create_variant_overrides permissions" do
producer1
@@ -436,7 +435,6 @@ describe Enterprise do
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
hub1
hub2
@@ -456,8 +454,7 @@ describe Enterprise do
end
end
-
- def should_have_enterprise_relationship(opts={})
+ def should_have_enterprise_relationship(opts = {})
er = EnterpriseRelationship.where(parent_id: opts[:from], child_id: opts[:to]).last
expect(er).not_to be_nil
if opts[:with] == :all_permissions
@@ -529,7 +526,7 @@ describe Enterprise do
describe "provide enterprise category" do
let(:producer_sell_all) { build(:enterprise, is_primary_producer: true, sells: "any") }
let(:producer_sell_own) { build(:enterprise, is_primary_producer: true, sells: "own") }
- let(:producer_sell_none) { build(:enterprise, is_primary_producer: true, sells: "none") }
+ let(:producer_sell_none) { build(:enterprise, is_primary_producer: true, sells: "none") }
let(:non_producer_sell_all) { build(:enterprise, is_primary_producer: false, sells: "any") }
let(:non_producer_sell_own) { build(:enterprise, is_primary_producer: false, sells: "own") }
let(:non_producer_sell_none) { build(:enterprise, is_primary_producer: false, sells: "none") }
diff --git a/spec/models/exchange_spec.rb b/spec/models/exchange_spec.rb
index 2a55ee5991..bd59675911 100644
--- a/spec/models/exchange_spec.rb
+++ b/spec/models/exchange_spec.rb
@@ -17,7 +17,7 @@ describe Exchange do
e1 = create(:exchange)
e2 = build(:exchange,
- :order_cycle => e1.order_cycle, :sender => e1.sender, :receiver => e1.receiver, :incoming => e1.incoming)
+ order_cycle: e1.order_cycle, sender: e1.sender, receiver: e1.receiver, incoming: e1.incoming)
expect(e2).not_to be_valid
e2.incoming = !e2.incoming
@@ -36,7 +36,7 @@ describe Exchange do
e = create(:exchange)
p = create(:product)
- e.exchange_variants.create(:variant => p.master)
+ e.exchange_variants.create(variant: p.master)
expect(e.variants.count).to eq(1)
end
@@ -44,7 +44,7 @@ describe Exchange do
e = create(:exchange)
f = create(:enterprise_fee)
- e.exchange_fees.create(:enterprise_fee => f)
+ e.exchange_fees.create(enterprise_fee: f)
expect(e.enterprise_fees.count).to eq(1)
end
@@ -301,25 +301,25 @@ describe Exchange do
it "converts to a hash" do
expect(exchange.to_h).to eq(
- {'id' => exchange.id, 'order_cycle_id' => oc.id,
+ 'id' => exchange.id, 'order_cycle_id' => oc.id,
'sender_id' => exchange.sender_id, 'receiver_id' => exchange.receiver_id,
'incoming' => exchange.incoming,
'variant_ids' => exchange.variant_ids.sort,
'enterprise_fee_ids' => exchange.enterprise_fee_ids.sort,
'pickup_time' => exchange.pickup_time, 'pickup_instructions' => exchange.pickup_instructions,
'receival_instructions' => exchange.receival_instructions,
- 'created_at' => exchange.created_at, 'updated_at' => exchange.updated_at}
+ 'created_at' => exchange.created_at, 'updated_at' => exchange.updated_at
)
end
it "converts to a hash of core attributes only" do
expect(exchange.to_h(true)).to eq(
- {'sender_id' => exchange.sender_id, 'receiver_id' => exchange.receiver_id,
- 'incoming' => exchange.incoming,
- 'variant_ids' => exchange.variant_ids.sort,
- 'enterprise_fee_ids' => exchange.enterprise_fee_ids.sort,
- 'pickup_time' => exchange.pickup_time, 'pickup_instructions' => exchange.pickup_instructions,
- 'receival_instructions' => exchange.receival_instructions}
+ 'sender_id' => exchange.sender_id, 'receiver_id' => exchange.receiver_id,
+ 'incoming' => exchange.incoming,
+ 'variant_ids' => exchange.variant_ids.sort,
+ 'enterprise_fee_ids' => exchange.enterprise_fee_ids.sort,
+ 'pickup_time' => exchange.pickup_time, 'pickup_instructions' => exchange.pickup_instructions,
+ 'receival_instructions' => exchange.receival_instructions
)
end
end
@@ -329,8 +329,8 @@ describe Exchange do
e1 = Exchange.new
e2 = Exchange.new
- allow(e1).to receive(:to_h) { {'sender_id' => 456} }
- allow(e2).to receive(:to_h) { {'sender_id' => 456} }
+ allow(e1).to receive(:to_h) { { 'sender_id' => 456 } }
+ allow(e2).to receive(:to_h) { { 'sender_id' => 456 } }
expect(e1.eql?(e2)).to be true
end
diff --git a/spec/models/model_set_spec.rb b/spec/models/model_set_spec.rb
index bac8047fa4..17c877e1da 100644
--- a/spec/models/model_set_spec.rb
+++ b/spec/models/model_set_spec.rb
@@ -3,8 +3,8 @@ require 'spec_helper'
describe ModelSet do
describe "updating" do
it "creates new models" do
- attrs = {collection_attributes: {'1' => {name: 's1'},
- '2' => {name: 's2'}}}
+ attrs = { collection_attributes: { '1' => { name: 's1' },
+ '2' => { name: 's2' } } }
ms = ModelSet.new(EnterpriseRelationshipPermission, EnterpriseRelationshipPermission.all, attrs)
@@ -13,13 +13,12 @@ describe ModelSet do
expect(EnterpriseRelationshipPermission.where(name: ['s1', 's2']).count).to eq(2)
end
-
it "updates existing models" do
e1 = create(:enterprise_group)
e2 = create(:enterprise_group)
- attrs = {collection_attributes: {'1' => {id: e1.id, name: 'e1zz', description: 'foo'},
- '2' => {id: e2.id, name: 'e2yy', description: 'bar'}}}
+ attrs = { collection_attributes: { '1' => { id: e1.id, name: 'e1zz', description: 'foo' },
+ '2' => { id: e2.id, name: 'e2yy', description: 'bar' } } }
ms = ModelSet.new(EnterpriseGroup, EnterpriseGroup.all, attrs)
@@ -28,13 +27,12 @@ describe ModelSet do
expect(EnterpriseGroup.where(name: ['e1zz', 'e2yy']).count).to eq(2)
end
-
it "destroys deleted models" do
e1 = create(:enterprise)
e2 = create(:enterprise)
- attrs = {collection_attributes: {'1' => {id: e1.id, name: 'deleteme'},
- '2' => {id: e2.id, name: 'e2'}}}
+ attrs = { collection_attributes: { '1' => { id: e1.id, name: 'deleteme' },
+ '2' => { id: e2.id, name: 'e2' } } }
ms = ModelSet.new(Enterprise, Enterprise.all, attrs, nil,
proc { |attrs| attrs['name'] == 'deleteme' })
@@ -45,9 +43,8 @@ describe ModelSet do
expect(Enterprise.where(id: e2.id)).to be_present
end
-
it "ignores deletable new records" do
- attrs = {collection_attributes: {'1' => {name: 'deleteme'}}}
+ attrs = { collection_attributes: { '1' => { name: 'deleteme' } } }
ms = ModelSet.new(Enterprise, Enterprise.all, attrs, nil,
proc { |attrs| attrs['name'] == 'deleteme' })
diff --git a/spec/models/order_cycle_spec.rb b/spec/models/order_cycle_spec.rb
index 619f022c5d..98aa6d4b4a 100644
--- a/spec/models/order_cycle_spec.rb
+++ b/spec/models/order_cycle_spec.rb
@@ -90,7 +90,7 @@ describe OrderCycle do
end
it "finds the soonest opening order cycles" do
- oc1 = create(:simple_order_cycle, orders_open_at: 1.weeks.from_now)
+ oc1 = create(:simple_order_cycle, orders_open_at: 1.week.from_now)
oc2 = create(:simple_order_cycle, orders_open_at: 2.hours.from_now)
oc3 = create(:simple_order_cycle, orders_open_at: 1.hour.ago)
@@ -99,7 +99,7 @@ describe OrderCycle do
it "finds the soonest closing order cycles" do
oc1 = create(:simple_order_cycle, orders_close_at: 2.hours.ago)
- oc2 = create(:simple_order_cycle, orders_close_at: 2.hour.from_now)
+ oc2 = create(:simple_order_cycle, orders_close_at: 2.hours.from_now)
oc3 = create(:simple_order_cycle, orders_close_at: 1.hour.from_now)
expect(OrderCycle.soonest_closing).to eq([oc3, oc2])
@@ -129,9 +129,9 @@ describe OrderCycle do
oc = create(:simple_order_cycle)
e1 = create(:exchange, incoming: true,
- order_cycle: oc, receiver: oc.coordinator, sender: create(:enterprise))
+ order_cycle: oc, receiver: oc.coordinator, sender: create(:enterprise))
e2 = create(:exchange, incoming: true,
- order_cycle: oc, receiver: oc.coordinator, sender: create(:enterprise))
+ order_cycle: oc, receiver: oc.coordinator, sender: create(:enterprise))
expect(oc.suppliers).to match_array [e1.sender, e2.sender]
end
@@ -140,9 +140,9 @@ describe OrderCycle do
oc = create(:simple_order_cycle)
e1 = create(:exchange, incoming: false,
- order_cycle: oc, sender: oc.coordinator, receiver: create(:enterprise))
+ order_cycle: oc, sender: oc.coordinator, receiver: create(:enterprise))
e2 = create(:exchange, incoming: false,
- order_cycle: oc, sender: oc.coordinator, receiver: create(:enterprise))
+ order_cycle: oc, sender: oc.coordinator, receiver: create(:enterprise))
expect(oc.distributors).to match_array [e1.receiver, e2.receiver]
end
@@ -170,14 +170,17 @@ describe OrderCycle do
let(:oc) { create(:simple_order_cycle) }
let(:d1) { create(:enterprise) }
let(:d2) { create(:enterprise) }
- let!(:e0) { create(:exchange, incoming: true,
- order_cycle: oc, sender: create(:enterprise), receiver: oc.coordinator)
+ let!(:e0) {
+ create(:exchange, incoming: true,
+ order_cycle: oc, sender: create(:enterprise), receiver: oc.coordinator)
}
- let!(:e1) { create(:exchange, incoming: false,
- order_cycle: oc, sender: oc.coordinator, receiver: d1)
+ let!(:e1) {
+ create(:exchange, incoming: false,
+ order_cycle: oc, sender: oc.coordinator, receiver: d1)
}
- let!(:e2) { create(:exchange, incoming: false,
- order_cycle: oc, sender: oc.coordinator, receiver: d2)
+ let!(:e2) {
+ create(:exchange, incoming: false,
+ order_cycle: oc, sender: oc.coordinator, receiver: d2)
}
let!(:p0) { create(:simple_product) }
let!(:p1) { create(:simple_product) }
@@ -408,7 +411,7 @@ 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.days.ago, orders_close_at: 11.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
@@ -438,10 +441,10 @@ describe OrderCycle do
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_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_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/order_updater_spec.rb b/spec/models/order_updater_spec.rb
index 6e985c14fb..ac21b555f1 100644
--- a/spec/models/order_updater_spec.rb
+++ b/spec/models/order_updater_spec.rb
@@ -120,8 +120,8 @@ describe OrderUpdater do
let(:shipment) { create(:shipment_with, :shipping_method, shipping_method: shipping_method) }
before do
- order.distributor = distributor
- order.shipments = [shipment]
+ order.distributor = distributor
+ order.shipments = [shipment]
end
context 'when shipping method is pickup' do
diff --git a/spec/models/producer_property_spec.rb b/spec/models/producer_property_spec.rb
index d515a00fe4..66be85b985 100644
--- a/spec/models/producer_property_spec.rb
+++ b/spec/models/producer_property_spec.rb
@@ -66,8 +66,8 @@ describe ProducerProperty do
let!(:oc) { create(:simple_order_cycle, distributors: [shop], variants: [product.variants.first, product2.variants.first]) }
it "doesn't return duplicates" do
- expect(ProducerProperty.currently_sold_by(shop).to_a.count).to eq 1
- expect(ProducerProperty.ever_sold_by(shop).to_a.count).to eq 1
+ expect(ProducerProperty.currently_sold_by(shop).to_a.size).to eq 1
+ expect(ProducerProperty.ever_sold_by(shop).to_a.size).to eq 1
end
end
end
diff --git a/spec/models/product_importer_spec.rb b/spec/models/product_importer_spec.rb
index ee598a0282..f746f2fb4e 100644
--- a/spec/models/product_importer_spec.rb
+++ b/spec/models/product_importer_spec.rb
@@ -698,7 +698,7 @@ describe ProductImport::ProductImporter do
csv << ["Carrots", "User Enterprise", "Vegetables", "5", "3.20", "500", "g", tax_category.id, "", shipping_category.name]
csv << ["Potatoes", "User Enterprise", "Vegetables", "6", "6.50", "1", "kg", "", "", shipping_category.name]
end
- settings = {enterprise.id.to_s => {
+ settings = { enterprise.id.to_s => {
'import_into' => 'product_list',
'defaults' => {
'on_hand' => {
@@ -722,7 +722,7 @@ describe ProductImport::ProductImporter do
'value' => '2020-01-01'
}
}
- }}
+ } }
@importer = import_data csv_data, settings: settings
@@ -756,7 +756,7 @@ end
private
-def import_data(csv_data, args={})
+def import_data(csv_data, args = {})
import_user = args[:import_user] || admin
import_into = args[:import_into] || 'product_list'
start_row = args[:start] || 1
diff --git a/spec/models/proxy_order_spec.rb b/spec/models/proxy_order_spec.rb
index 3bbf428afc..145c2aecde 100644
--- a/spec/models/proxy_order_spec.rb
+++ b/spec/models/proxy_order_spec.rb
@@ -77,10 +77,12 @@ describe ProxyOrder, type: :model do
describe "resume" do
let!(:shipment) { create(:shipment) }
- let(:order) { create(:order_with_totals, ship_address: create(:address),
- shipments: [shipment],
- payments: [create(:payment)],
- distributor: shipment.shipping_method.distributors.first) }
+ let(:order) {
+ create(:order_with_totals, ship_address: create(:address),
+ shipments: [shipment],
+ payments: [create(:payment)],
+ distributor: shipment.shipping_method.distributors.first)
+ }
let(:proxy_order) { create(:proxy_order, order: order, canceled_at: Time.zone.now) }
let(:order_cycle) { proxy_order.order_cycle }
@@ -199,6 +201,6 @@ describe ProxyOrder, type: :model do
# We still need to use be_within, because the Database timestamp is not as
# accurate as the Rails timestamp. If we use `eq`, we have differing nano
# seconds.
- expect(subject.reload.canceled_at).to be_within(2.second).of Time.zone.now
+ expect(subject.reload.canceled_at).to be_within(2.seconds).of Time.zone.now
end
end
diff --git a/spec/models/spree/ability_spec.rb b/spec/models/spree/ability_spec.rb
index 02ac8d628c..9e3cde5c82 100644
--- a/spec/models/spree/ability_spec.rb
+++ b/spec/models/spree/ability_spec.rb
@@ -118,7 +118,6 @@ module Spree
end
describe 'Roles' do
-
# create enterprises
let(:s1) { create(:supplier_enterprise) }
let(:s2) { create(:supplier_enterprise) }
@@ -450,7 +449,7 @@ module Spree
user
end
- let(:oc1) { create(:simple_order_cycle, {coordinator: d1}) }
+ let(:oc1) { create(:simple_order_cycle, coordinator: d1) }
let(:oc2) { create(:simple_order_cycle) }
it "should be able to read/write OrderCycles they are the co-ordinator of" do
diff --git a/spec/models/spree/adjustment_spec.rb b/spec/models/spree/adjustment_spec.rb
index d4ca03788e..bed9737151 100644
--- a/spec/models/spree/adjustment_spec.rb
+++ b/spec/models/spree/adjustment_spec.rb
@@ -66,7 +66,6 @@ module Spree
let(:shipping_method) { create(:shipping_method_with, :flat_rate) }
let(:shipment) { create(:shipment_with, :shipping_method, shipping_method: shipping_method, order: order) }
-
describe "the shipping charge" do
it "is the adjustment amount" do
order.shipments = [shipment]
@@ -193,7 +192,7 @@ module Spree
describe "when the tax rate does not include the tax in the price" do
before do
fee_tax_rate.update_attribute :included_in_price, false
- order.reload.create_tax_charge! # Updating line_item or order has the same effect
+ order.reload.create_tax_charge! # Updating line_item or order has the same effect
order.update_distribution_charge!
end
@@ -262,7 +261,7 @@ module Spree
describe "when the tax rate does not include the tax in the price" do
before do
product_tax_rate.update_attribute :included_in_price, false
- order.reload.create_tax_charge! # Updating line_item or order has the same effect
+ order.reload.create_tax_charge! # Updating line_item or order has the same effect
order.update_distribution_charge!
end
diff --git a/spec/models/spree/calculator/flat_rate_spec.rb b/spec/models/spree/calculator/flat_rate_spec.rb
index be8c4911c7..3e3bba064b 100644
--- a/spec/models/spree/calculator/flat_rate_spec.rb
+++ b/spec/models/spree/calculator/flat_rate_spec.rb
@@ -3,7 +3,7 @@ require 'spec_helper'
describe Spree::Calculator::FlatRate do
let(:calculator) { Spree::Calculator::FlatRate.new }
- before { allow(calculator).to receive_messages :preferred_amount => 10 }
+ before { allow(calculator).to receive_messages preferred_amount: 10 }
context "extends LocalizedNumber" do
it_behaves_like "a model using the LocalizedNumber module", [:preferred_amount]
diff --git a/spec/models/spree/calculator/flexi_rate_spec.rb b/spec/models/spree/calculator/flexi_rate_spec.rb
index b821f4fc74..0440e87ca8 100644
--- a/spec/models/spree/calculator/flexi_rate_spec.rb
+++ b/spec/models/spree/calculator/flexi_rate_spec.rb
@@ -11,19 +11,19 @@ describe Spree::Calculator::FlexiRate do
end
context 'when nb of items ordered is above preferred max' do
- let(:quantity) { 4.0 }
+ let(:quantity) { 4.0 }
- it "returns the first item rate" do
- expect(calculator.compute(line_item).round(2)).to eq(4.0)
- end
+ it "returns the first item rate" do
+ expect(calculator.compute(line_item).round(2)).to eq(4.0)
+ end
end
context 'when nb of items ordered is below preferred max' do
- let(:quantity) { 2.0 }
+ let(:quantity) { 2.0 }
- it "returns the first item rate" do
- expect(calculator.compute(line_item).round(2)).to eq(3.0)
- end
+ it "returns the first item rate" do
+ expect(calculator.compute(line_item).round(2)).to eq(3.0)
+ end
end
it "allows creation of new object with all the attributes" do
diff --git a/spec/models/spree/gateway/stripe_connect_spec.rb b/spec/models/spree/gateway/stripe_connect_spec.rb
index eb9bacdd2c..3213dd84f9 100644
--- a/spec/models/spree/gateway/stripe_connect_spec.rb
+++ b/spec/models/spree/gateway/stripe_connect_spec.rb
@@ -10,7 +10,7 @@ describe Spree::Gateway::StripeConnect, type: :model do
end
end
- let(:stripe_account_id) { "acct_123" }
+ let(:stripe_account_id) { "acct_123" }
before do
allow(Stripe).to receive(:api_key) { "sk_test_123456" }
@@ -63,7 +63,7 @@ describe Spree::Gateway::StripeConnect, type: :model do
before do
stub_request(:post, "https://api.stripe.com/v1/tokens")
- .with(body: { "card" => "card123", "customer" => "customer123"})
+ .with(body: { "card" => "card123", "customer" => "customer123" })
.to_return(body: JSON.generate(token_mock))
end
diff --git a/spec/models/spree/gateway_tagging_spec.rb b/spec/models/spree/gateway_tagging_spec.rb
index 53f1aa26eb..2a5eb5c23e 100644
--- a/spec/models/spree/gateway_tagging_spec.rb
+++ b/spec/models/spree/gateway_tagging_spec.rb
@@ -21,7 +21,6 @@ end
module Spree
describe "PaymentMethod and descendants" do
-
let(:shop) { create(:enterprise) }
let(:valid_subject) do
# Supply required parameters so that it can be saved to attach taggings.
diff --git a/spec/models/spree/image_spec.rb b/spec/models/spree/image_spec.rb
index 63350817b8..ee256cf7cb 100644
--- a/spec/models/spree/image_spec.rb
+++ b/spec/models/spree/image_spec.rb
@@ -3,15 +3,15 @@ require 'spec_helper'
module Spree
describe Image do
describe "attachment definitions" do
- let(:name_str) { {"mini" => "48x48>"} }
- let(:formatted) { {mini: ["48x48>", "png"]} }
+ let(:name_str) { { "mini" => "48x48>" } }
+ let(:formatted) { { mini: ["48x48>", "png"] } }
it "converts style names to symbols" do
- expect(Image.format_styles(name_str)).to eq({:mini => "48x48>"})
+ expect(Image.format_styles(name_str)).to eq(mini: "48x48>")
end
it "converts formats to symbols" do
- expect(Image.format_styles(formatted)).to eq({:mini => ["48x48>", :png]})
+ expect(Image.format_styles(formatted)).to eq(mini: ["48x48>", :png])
end
end
diff --git a/spec/models/spree/line_item_spec.rb b/spec/models/spree/line_item_spec.rb
index dd449501ca..c073f8c8a5 100644
--- a/spec/models/spree/line_item_spec.rb
+++ b/spec/models/spree/line_item_spec.rb
@@ -14,12 +14,12 @@ module Spree
let(:li1) { create(:line_item, order: o, product: p1) }
let(:li2) { create(:line_item, order: o, product: p2) }
- let(:p3) {create(:product, name: 'Clear Honey') }
- let(:p4) {create(:product, name: 'Apricots') }
- let(:v1) {create(:variant, product: p3, unit_value: 500) }
- let(:v2) {create(:variant, product: p3, unit_value: 250) }
- let(:v3) {create(:variant, product: p4, unit_value: 500, display_name: "ZZ") }
- let(:v4) {create(:variant, product: p4, unit_value: 500, display_name: "aa") }
+ let(:p3) { create(:product, name: 'Clear Honey') }
+ let(:p4) { create(:product, name: 'Apricots') }
+ let(:v1) { create(:variant, product: p3, unit_value: 500) }
+ let(:v2) { create(:variant, product: p3, unit_value: 250) }
+ let(:v3) { create(:variant, product: p4, unit_value: 500, display_name: "ZZ") }
+ let(:v4) { create(:variant, product: p4, unit_value: 500, display_name: "aa") }
let(:li3) { create(:line_item, order: o, product: p3, variant: v1) }
let(:li4) { create(:line_item, order: o, product: p3, variant: v2) }
let(:li5) { create(:line_item, order: o, product: p4, variant: v3) }
@@ -55,7 +55,7 @@ module Spree
end
it "finds line items sorted by name and unit_value" do
- expect(o.line_items.sorted_by_name_and_unit_value).to eq([li6,li5,li4,li3])
+ expect(o.line_items.sorted_by_name_and_unit_value).to eq([li6, li5, li4, li3])
end
it "finds line items from a given order cycle" do
@@ -134,7 +134,7 @@ module Spree
describe "tracking stock when quantity is changed" do
context "when the order is already complete" do
- let(:shop) { create(:distributor_enterprise)}
+ let(:shop) { create(:distributor_enterprise) }
let(:order) { create(:completed_order_with_totals, distributor: shop) }
let!(:line_item) { order.reload.line_items.first }
let!(:variant) { line_item.variant }
@@ -144,14 +144,14 @@ 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
@@ -159,7 +159,7 @@ module Spree
describe "tracking stock when a line item is destroyed" do
context "when the order is already complete" do
- let(:shop) { create(:distributor_enterprise)}
+ let(:shop) { create(:distributor_enterprise) }
let(:order) { create(:completed_order_with_totals, distributor: shop) }
let!(:line_item) { order.reload.line_items.first }
let!(:variant) { line_item.variant }
@@ -169,14 +169,14 @@ module Spree
it "restores stock to the variant override" do
expect(vo.reload.count_on_hand).to eq 3
- expect{line_item.destroy}.to_not change{Spree::Variant.find(variant.id).on_hand}
+ expect{ line_item.destroy }.to_not change{ Spree::Variant.find(variant.id).on_hand }
expect(vo.reload.count_on_hand).to eq 4
end
end
context "when a variant override does not apply" do
it "restores stock to the variant" do
- expect{line_item.destroy}.to change{Spree::Variant.find(variant.id).on_hand}.by(1)
+ expect{ line_item.destroy }.to change{ Spree::Variant.find(variant.id).on_hand }.by(1)
end
end
end
@@ -320,7 +320,7 @@ module Spree
context "and quantity is changed" do
before do
- attrs.merge!( quantity: 4 )
+ attrs[:quantity] = 4
li.update_attributes(attrs)
end
@@ -348,7 +348,7 @@ module Spree
context "and a final_weight_volume has been set" do
before do
expect(li.final_weight_volume).to eq 3000
- attrs.merge!( quantity: 4 )
+ attrs[:quantity] = 4
li.update_attributes(attrs)
end
@@ -360,7 +360,7 @@ module Spree
context "and a final_weight_volume has not been set" do
before do
li.update_attributes(final_weight_volume: nil)
- attrs.merge!( quantity: 1 )
+ attrs[:quantity] = 1
li.update_attributes(attrs)
end
@@ -376,7 +376,7 @@ module Spree
context "and a final_weight_volume has been set" do
before do
expect(li.final_weight_volume).to eq 0
- attrs.merge!( quantity: 4 )
+ attrs[:quantity] = 4
li.update_attributes(attrs)
end
@@ -388,7 +388,7 @@ module Spree
context "and a final_weight_volume has not been set" do
before do
li.update_attributes(final_weight_volume: nil)
- attrs.merge!( quantity: 1 )
+ attrs[:quantity] = 1
li.update_attributes(attrs)
end
@@ -405,7 +405,7 @@ module Spree
describe "generating the full name" do
let(:li) { LineItem.new }
- context "when display_name is blank" do
+ context "when display_name is blank" do
before do
allow(li).to receive(:unit_to_display) { 'unit_to_display' }
allow(li).to receive(:display_name) { '' }
diff --git a/spec/models/spree/order_spec.rb b/spec/models/spree/order_spec.rb
index f14c5ff1cf..b39bad4ccc 100644
--- a/spec/models/spree/order_spec.rb
+++ b/spec/models/spree/order_spec.rb
@@ -19,7 +19,7 @@ describe Spree::Order do
it "does nothing when the line item is not found" do
p = create(:simple_product)
- subject.set_variant_attributes(p.master, {'max_quantity' => '3'}.with_indifferent_access)
+ subject.set_variant_attributes(p.master, { 'max_quantity' => '3' }.with_indifferent_access)
end
end
@@ -139,7 +139,7 @@ describe Spree::Order do
end
describe "an order without shipping method" do
- let(:order) { create(:order) }
+ let(:order) { create(:order) }
it "cannot be shipped" do
expect(order.ready_to_ship?).to eq(false)
@@ -161,7 +161,7 @@ describe Spree::Order do
end
describe "a paid order without a shipment" do
- let(:order) { create(:order) }
+ let(:order) { create(:order) }
before do
order.payment_state = 'paid'
@@ -459,7 +459,7 @@ describe Spree::Order do
line_item1 = create(:line_item, order: subject, variant: variant1)
line_item2 = create(:line_item, order: subject, variant: variant2)
subject.reload
- subject.line_items = [line_item1,line_item2]
+ subject.line_items = [line_item1, line_item2]
end
it "allows the change when all variants in the order are provided by the new distributor in the new order cycle" do
@@ -478,7 +478,7 @@ describe Spree::Order do
subject.distributor = new_distributor
expect(subject).not_to be_valid
- expect(subject.errors.messages).to eq({:base => ["Distributor or order cycle cannot supply the products in your cart"]})
+ expect(subject.errors.messages).to eq(base: ["Distributor or order cycle cannot supply the products in your cart"])
end
end
@@ -520,7 +520,7 @@ describe Spree::Order do
let!(:order) { create(:order, distributor: distributor) }
context "when an email address is available for the order" do
- before { allow(order).to receive(:email_for_customer) { "existing@email.com" }}
+ before { allow(order).to receive(:email_for_customer) { "existing@email.com" } }
context "and a customer for order.distributor and order#email_for_customer already exists" do
let!(:customer) { create(:customer, enterprise: distributor, email: "existing@email.com" ) }
@@ -545,7 +545,7 @@ describe Spree::Order do
context "when an email address is not available for the order" do
let!(:customer) { create(:customer, enterprise: distributor) }
- before { allow(order).to receive(:email_for_customer) { nil }}
+ before { allow(order).to receive(:email_for_customer) { nil } }
it "does not set the customer and returns nil" do
result = order.send(:associate_customer)
@@ -576,7 +576,7 @@ describe Spree::Order do
it "links the customer customer to the order" do
expect(order.customer).to be_nil
- expect{order.send(:ensure_customer)}.to_not change{Customer.count}
+ expect{ order.send(:ensure_customer) }.to_not change{ Customer.count }
expect(order.customer).to eq customer
end
end
@@ -588,7 +588,7 @@ describe Spree::Order do
}
it "creates a new customer with defaut name and addresses" do
expect(order.customer).to be_nil
- expect{order.send(:ensure_customer)}.to change{Customer.count}.by 1
+ expect{ order.send(:ensure_customer) }.to change{ Customer.count }.by 1
expect(order.customer).to be_a Customer
expect(order.customer.name).to eq order.bill_address.full_name
@@ -614,8 +614,8 @@ describe Spree::Order do
end
it "returns a validation error" do
- expect{order.next}.to change(order.errors, :count).from(0).to(1)
- expect(order.errors.messages[:base]).to eq [ I18n.t('devise.failure.already_registered') ]
+ expect{ order.next }.to change(order.errors, :count).from(0).to(1)
+ expect(order.errors.messages[:base]).to eq [I18n.t('devise.failure.already_registered')]
expect(order.state).to eq 'cart'
end
end
@@ -659,7 +659,7 @@ describe Spree::Order do
end
it "does not attempt to update such adjustments" do
- order.update_attributes(line_items_attributes: [{id: order.line_items.first.id, quantity: 0}])
+ order.update_attributes(line_items_attributes: [{ id: order.line_items.first.id, quantity: 0 }])
# Check if fees got updated
order.reload
diff --git a/spec/models/spree/payment_method_spec.rb b/spec/models/spree/payment_method_spec.rb
index 1a75f8a17a..396b9f1ab0 100644
--- a/spec/models/spree/payment_method_spec.rb
+++ b/spec/models/spree/payment_method_spec.rb
@@ -11,7 +11,7 @@ module Spree
end
it "raises errors when required fields are missing" do
- pm = PaymentMethod.new()
+ pm = PaymentMethod.new
pm.save
expect(pm.errors.to_a).to eq(["Name can't be blank", "At least one hub must be selected"])
end
diff --git a/spec/models/spree/payment_spec.rb b/spec/models/spree/payment_spec.rb
index 234df727a1..46a493fa96 100644
--- a/spec/models/spree/payment_spec.rb
+++ b/spec/models/spree/payment_spec.rb
@@ -24,7 +24,7 @@ module Spree
context "for Pin Payments" do
let(:d) { create(:distributor_enterprise) }
- let(:pin) { Gateway::Pin.create! name: 'pin', distributor_ids: [d.id]}
+ let(:pin) { Gateway::Pin.create! name: 'pin', distributor_ids: [d.id] }
let(:payment) { create(:payment, source: create(:credit_card), payment_method: pin) }
it "does not void" do
@@ -47,8 +47,8 @@ module Spree
describe "refunding" do
let(:payment) { create(:payment) }
- let(:success) { double(:success? => true, authorization: 'abc123') }
- let(:failure) { double(:success? => false) }
+ let(:success) { double(success?: true, authorization: 'abc123') }
+ let(:failure) { double(success?: false) }
it "always checks the environment" do
allow(payment.payment_method).to receive(:refund) { success }
diff --git a/spec/models/spree/product_spec.rb b/spec/models/spree/product_spec.rb
index de144a2dc6..b178056706 100644
--- a/spec/models/spree/product_spec.rb
+++ b/spec/models/spree/product_spec.rb
@@ -2,7 +2,6 @@ require 'spec_helper'
module Spree
describe Product do
-
describe "associations" do
it { is_expected.to belong_to(:supplier) }
it { is_expected.to belong_to(:primary_taxon) }
@@ -109,7 +108,7 @@ module Spree
it "only duplicates master with after_save when no standard variants exist" do
expect(product).to receive :ensure_standard_variant
product.name = "Something else"
- expect{product.save!}.to_not change{product.variants.count}
+ expect{ product.save! }.to_not change{ product.variants.count }
end
end
@@ -380,7 +379,7 @@ 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
@@ -390,7 +389,7 @@ 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
@@ -401,7 +400,7 @@ 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
@@ -412,7 +411,7 @@ 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
@@ -435,14 +434,14 @@ module Spree
pb = Spree::Property.create! name: 'B', presentation: 'B'
pc = Spree::Property.create! name: 'C', presentation: 'C'
- product.product_properties.create!({property_id: pa.id, value: '1', position: 1}, {without_protection: true})
- product.product_properties.create!({property_id: pc.id, value: '3', position: 3}, {without_protection: true})
- supplier.producer_properties.create!({property_id: pb.id, value: '2', position: 2}, {without_protection: true})
+ product.product_properties.create!({ property_id: pa.id, value: '1', position: 1 }, without_protection: true)
+ product.product_properties.create!({ property_id: pc.id, value: '3', position: 3 }, without_protection: true)
+ supplier.producer_properties.create!({ property_id: pb.id, value: '2', position: 2 }, without_protection: true)
expect(product.properties_including_inherited).to eq(
- [{id: pa.id, name: "A", value: '1'},
- {id: pb.id, name: "B", value: '2'},
- {id: pc.id, name: "C", value: '3'}]
+ [{ id: pa.id, name: "A", value: '1' },
+ { id: pb.id, name: "B", value: '2' },
+ { id: pc.id, name: "C", value: '3' }]
)
end
end
@@ -453,8 +452,8 @@ module Spree
d2 = create(:distributor_enterprise)
p1 = create(:product)
p2 = create(:product)
- oc1 = create(:simple_order_cycle, :distributors => [d1], :variants => [p1.master])
- oc2 = create(:simple_order_cycle, :distributors => [d2], :variants => [p2.master])
+ oc1 = create(:simple_order_cycle, distributors: [d1], variants: [p1.master])
+ oc2 = create(:simple_order_cycle, distributors: [d2], variants: [p2.master])
expect(p1).to be_in_distributor d1
expect(p1).not_to be_in_distributor d2
@@ -465,8 +464,8 @@ module Spree
d2 = create(:distributor_enterprise)
p1 = create(:product)
p2 = create(:product)
- oc1 = create(:simple_order_cycle, :distributors => [d1], :variants => [p1.master])
- oc2 = create(:simple_order_cycle, :distributors => [d2], :variants => [p2.master])
+ oc1 = create(:simple_order_cycle, distributors: [d1], variants: [p1.master])
+ oc2 = create(:simple_order_cycle, distributors: [d2], variants: [p2.master])
expect(p1).to be_in_order_cycle oc1
expect(p1).not_to be_in_order_cycle oc2
@@ -475,10 +474,11 @@ module Spree
describe "variant units" do
context "when the product already has a variant unit set (and all required option types exist)" do
- let!(:p) { create(:simple_product,
- variant_unit: 'weight',
- variant_unit_scale: 1,
- variant_unit_name: nil)
+ let!(:p) {
+ create(:simple_product,
+ variant_unit: 'weight',
+ variant_unit_scale: 1,
+ variant_unit_name: nil)
}
let!(:ot_volume) { create(:option_type, name: 'unit_volume', presentation: 'Volume') }
@@ -500,7 +500,7 @@ module Spree
expect(v.option_values.map(&:name).include?("1L")).to eq(false)
expect(v.option_values.map(&:name).include?("1g")).to eq(true)
- expect {
+ expect {
p.update_attributes!(variant_unit: 'volume', variant_unit_scale: 0.001)
}.to change(p.master.option_values(true), :count).by(0)
v.reload
@@ -515,7 +515,7 @@ module Spree
expect(p.master.option_values.map(&:name).include?("1L")).to eq(false)
expect(p.master.option_values.map(&:name).include?("1g")).to eq(true)
- expect {
+ expect {
p.update_attributes!(variant_unit: 'volume', variant_unit_scale: 0.001)
}.to change(p.master.option_values(true), :count).by(0)
p.reload
@@ -667,7 +667,7 @@ 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.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)
@@ -675,9 +675,9 @@ module Spree
end
context "when all variants have import date" do
- let!(:variant_a) { create(:variant, product: product, import_date: reference_time - 2.hour) }
+ 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.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/property_spec.rb b/spec/models/spree/property_spec.rb
index 29046a8782..509b98cc1f 100644
--- a/spec/models/spree/property_spec.rb
+++ b/spec/models/spree/property_spec.rb
@@ -27,7 +27,7 @@ module Spree
end
it "doesn't return duplicates" do
- expect(Spree::Property.applied_by(producer).to_a.count).to eq 1
+ expect(Spree::Property.applied_by(producer).to_a.size).to eq 1
end
end
@@ -89,8 +89,8 @@ module Spree
end
it "doesn't return duplicates" do
- expect(Property.currently_sold_by(shop).to_a.count).to eq 1
- expect(Property.ever_sold_by(shop).to_a.count).to eq 1
+ expect(Property.currently_sold_by(shop).to_a.size).to eq 1
+ expect(Property.ever_sold_by(shop).to_a.size).to eq 1
end
end
end
diff --git a/spec/models/spree/shipping_method_spec.rb b/spec/models/spree/shipping_method_spec.rb
index 2b77f06767..c345afd683 100644
--- a/spec/models/spree/shipping_method_spec.rb
+++ b/spec/models/spree/shipping_method_spec.rb
@@ -65,15 +65,15 @@ module Spree
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})
+ expect(ShippingMethod.services[d1.id]).to eq(pickup: true, delivery: true)
end
it "reports when only pickup is available" do
- expect(ShippingMethod.services[d2.id]).to eq({pickup: true, delivery: false})
+ expect(ShippingMethod.services[d2.id]).to eq(pickup: true, delivery: false)
end
it "reports when only delivery is available" do
- expect(ShippingMethod.services[d3.id]).to eq({pickup: false, delivery: true})
+ expect(ShippingMethod.services[d3.id]).to eq(pickup: false, delivery: true)
end
it "returns no entry when no service is available" do
diff --git a/spec/models/spree/tax_rate_spec.rb b/spec/models/spree/tax_rate_spec.rb
index 2ee7e24b4e..a51b0fa34f 100644
--- a/spec/models/spree/tax_rate_spec.rb
+++ b/spec/models/spree/tax_rate_spec.rb
@@ -59,7 +59,7 @@ module Spree
it "restores both values when an exception is raised" do
expect do
- tax_rate.send(:with_tax_included_in_price) { raise Exception.new 'oops' }
+ tax_rate.send(:with_tax_included_in_price) { raise Exception, 'oops' }
end.to raise_error 'oops'
expect(tax_rate.included_in_price).to be false
diff --git a/spec/models/spree/taxon_spec.rb b/spec/models/spree/taxon_spec.rb
index cfb7505555..5c52dd0173 100644
--- a/spec/models/spree/taxon_spec.rb
+++ b/spec/models/spree/taxon_spec.rb
@@ -25,7 +25,7 @@ module Spree
let!(:p1) { create(:simple_product, supplier: e, taxons: [t1, t2]) }
it "finds taxons" do
- expect(Taxon.supplied_taxons).to eq({e.id => Set.new(p1.taxons.map(&:id))})
+ expect(Taxon.supplied_taxons).to eq(e.id => Set.new(p1.taxons.map(&:id)))
end
end
@@ -36,11 +36,11 @@ module Spree
let!(:p_closed) { create(:simple_product, primary_taxon: t2) }
it "finds all distributed taxons" do
- expect(Taxon.distributed_taxons(:all)).to eq({e.id => Set.new([t1.id, t2.id])})
+ expect(Taxon.distributed_taxons(:all)).to eq(e.id => Set.new([t1.id, t2.id]))
end
it "finds currently distributed taxons" do
- expect(Taxon.distributed_taxons(:current)).to eq({e.id => Set.new([t1.id])})
+ expect(Taxon.distributed_taxons(:current)).to eq(e.id => Set.new([t1.id]))
end
end
end
diff --git a/spec/models/spree/variant_spec.rb b/spec/models/spree/variant_spec.rb
index 3fbc6f80f5..50e5b973bf 100644
--- a/spec/models/spree/variant_spec.rb
+++ b/spec/models/spree/variant_spec.rb
@@ -65,14 +65,17 @@ module Spree
let(:p_external) { create(:simple_product) }
let(:v_external) { create(:variant, product: p_external) }
- let!(:ex_in) { create(:exchange, order_cycle: oc, sender: s, receiver: oc.coordinator,
- incoming: true, variants: [v1, v2])
+ let!(:ex_in) {
+ create(:exchange, order_cycle: oc, sender: s, receiver: oc.coordinator,
+ incoming: true, variants: [v1, v2])
}
- let!(:ex_out1) { create(:exchange, order_cycle: oc, sender: oc.coordinator, receiver: d1,
- incoming: false, variants: [v1])
+ let!(:ex_out1) {
+ create(:exchange, order_cycle: oc, sender: oc.coordinator, receiver: d1,
+ incoming: false, variants: [v1])
}
- let!(:ex_out2) { create(:exchange, order_cycle: oc, sender: oc.coordinator, receiver: d2,
- incoming: false, variants: [v2])
+ let!(:ex_out2) {
+ create(:exchange, order_cycle: oc, sender: oc.coordinator, receiver: d2,
+ incoming: false, variants: [v2])
}
it "returns variants in the order cycle and distributor" do
@@ -202,7 +205,7 @@ module Spree
it "indexes variants by id" do
expect(Variant.where(id: [v1, v2, v3]).indexed).to eq(
- {v1.id => v1, v2.id => v2, v3.id => v3}
+ v1.id => v1, v2.id => v2, v3.id => v3
)
end
end
@@ -240,7 +243,6 @@ module Spree
end
end
-
describe "calculating the fees" do
it "delegates to EnterpriseFeeCalculator" do
distributor = double(:distributor)
@@ -253,7 +255,6 @@ module Spree
end
end
-
describe "calculating fees broken down by fee type" do
it "delegates to EnterpriseFeeCalculator" do
distributor = double(:distributor)
@@ -267,7 +268,6 @@ module Spree
end
end
-
context "when the product has variants" do
let!(:product) { create(:simple_product) }
let!(:variant) { create(:variant, product: product) }
diff --git a/spec/models/tag_rule/discount_order_spec.rb b/spec/models/tag_rule/discount_order_spec.rb
index 07264cca8f..d4e30a6d95 100644
--- a/spec/models/tag_rule/discount_order_spec.rb
+++ b/spec/models/tag_rule/discount_order_spec.rb
@@ -7,7 +7,7 @@ describe TagRule::DiscountOrder, type: :model do
let(:subject) { double(:subject) }
before do
- tag_rule.context = {subject: subject}
+ tag_rule.context = { subject: subject }
allow(tag_rule).to receive(:customer_tags_match?) { true }
allow(subject).to receive(:class) { Spree::Order }
end
@@ -31,19 +31,19 @@ describe TagRule::DiscountOrder, type: :model do
pending "determining whether a the rule has already been applied to an order" do
let!(:order) { create(:order) }
- let!(:adjustment) { order.adjustments.create({:amount => 12.34, :source => order, :originator => tag_rule, :label => 'discount' }, :without_protection => true) }
+ let!(:adjustment) { order.adjustments.create({ amount: 12.34, source: order, originator: tag_rule, label: 'discount' }, without_protection: true) }
before do
- tag_rule.context = {subject: order}
+ tag_rule.context = { subject: order }
end
context "where adjustments originating from the rule already exist" do
- it { expect(tag_rule.send(:already_applied?)).to be true}
+ it { expect(tag_rule.send(:already_applied?)).to be true }
end
context "where existing adjustments originate from other rules" do
- before { adjustment.update_attribute(:originator_id,create(:tag_rule).id) }
- it { expect(tag_rule.send(:already_applied?)).to be false}
+ before { adjustment.update_attribute(:originator_id, create(:tag_rule).id) }
+ it { expect(tag_rule.send(:already_applied?)).to be false }
end
end
@@ -56,7 +56,7 @@ describe TagRule::DiscountOrder, type: :model do
before do
order.update_distribution_charge!
tag_rule.calculator.update_attribute(:preferred_flat_percent, -10.00)
- tag_rule.context = {subject: order}
+ tag_rule.context = { subject: order }
end
context "in a simple scenario" do
diff --git a/spec/models/tag_rule/filter_order_cycles_spec.rb b/spec/models/tag_rule/filter_order_cycles_spec.rb
index 4c08af7c7f..56153e704b 100644
--- a/spec/models/tag_rule/filter_order_cycles_spec.rb
+++ b/spec/models/tag_rule/filter_order_cycles_spec.rb
@@ -15,7 +15,7 @@ describe TagRule::FilterOrderCycles, type: :model do
end
context "when the exchange is not nil" do
- let(:exchange_object) { double(:exchange, tag_list: ["member","local","volunteer"]) }
+ let(:exchange_object) { double(:exchange, tag_list: ["member", "local", "volunteer"]) }
before do
allow(tag_rule).to receive(:exchange_for) { exchange_object }
diff --git a/spec/models/tag_rule/filter_payment_methods_spec.rb b/spec/models/tag_rule/filter_payment_methods_spec.rb
index d8d30cefaa..6b61ba0230 100644
--- a/spec/models/tag_rule/filter_payment_methods_spec.rb
+++ b/spec/models/tag_rule/filter_payment_methods_spec.rb
@@ -5,14 +5,13 @@ describe TagRule::FilterPaymentMethods, type: :model do
describe "determining whether tags match for a given payment method" do
context "when the payment method is nil" do
-
it "returns false" do
expect(tag_rule.send(:tags_match?, nil)).to be false
end
end
context "when the payment method is not nil" do
- let(:payment_method) { create(:payment_method, tag_list: ["member","local","volunteer"]) }
+ let(:payment_method) { create(:payment_method, tag_list: ["member", "local", "volunteer"]) }
context "when the rule has no preferred payment method tags specified" do
before { allow(tag_rule).to receive(:preferred_payment_method_tags) { "" } }
diff --git a/spec/models/tag_rule/filter_products_spec.rb b/spec/models/tag_rule/filter_products_spec.rb
index 0008db456d..0519dc00dc 100644
--- a/spec/models/tag_rule/filter_products_spec.rb
+++ b/spec/models/tag_rule/filter_products_spec.rb
@@ -5,14 +5,13 @@ describe TagRule::FilterProducts, type: :model do
describe "determining whether tags match for a given variant" do
context "when the variant is nil" do
-
it "returns false" do
expect(tag_rule.send(:tags_match?, nil)).to be false
end
end
context "when the variant is not nil" do
- let(:variant_object) { { "tag_list" => ["member","local","volunteer"] } }
+ let(:variant_object) { { "tag_list" => ["member", "local", "volunteer"] } }
context "when the rule has no preferred variant tags specified" do
before { allow(tag_rule).to receive(:preferred_variant_tags) { "" } }
diff --git a/spec/models/tag_rule/filter_shipping_methods_spec.rb b/spec/models/tag_rule/filter_shipping_methods_spec.rb
index ff90ed8428..58a1ee4854 100644
--- a/spec/models/tag_rule/filter_shipping_methods_spec.rb
+++ b/spec/models/tag_rule/filter_shipping_methods_spec.rb
@@ -5,14 +5,13 @@ describe TagRule::FilterShippingMethods, type: :model do
describe "determining whether tags match for a given shipping method" do
context "when the shipping method is nil" do
-
it "returns false" do
expect(tag_rule.send(:tags_match?, nil)).to be false
end
end
context "when the shipping method is not nil" do
- let(:shipping_method) { create(:shipping_method, tag_list: ["member","local","volunteer"]) }
+ let(:shipping_method) { create(: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) { "" } }
diff --git a/spec/models/variant_override_spec.rb b/spec/models/variant_override_spec.rb
index 403b977e0c..c93a8bd3c7 100644
--- a/spec/models/variant_override_spec.rb
+++ b/spec/models/variant_override_spec.rb
@@ -37,8 +37,10 @@ describe VariantOverride do
describe "validation" do
describe "ensuring that on_demand and count_on_hand are compatible" do
- let(:variant_override) { build(:variant_override, hub: hub, variant: variant,
- on_demand: on_demand, count_on_hand: count_on_hand) }
+ let(:variant_override) {
+ build(:variant_override, hub: hub, variant: variant,
+ on_demand: on_demand, count_on_hand: count_on_hand)
+ }
context "when using producer stock settings" do
let(:on_demand) { nil }
diff --git a/spec/performance/orders_controller_spec.rb b/spec/performance/orders_controller_spec.rb
index e151e4f506..5f6aac9e15 100644
--- a/spec/performance/orders_controller_spec.rb
+++ b/spec/performance/orders_controller_spec.rb
@@ -17,12 +17,12 @@ describe Spree::OrdersController, type: :controller, performance: true do
describe "adding products to cart" do
it "adds products to cart" do
puts "Pre-populating first product"
- spree_post :populate, variants: {products[0].variants.first.id => 1}
+ spree_post :populate, variants: { products[0].variants.first.id => 1 }
result = Benchmark.measure do
(1..num_products).each do |num_products|
puts "Populating #{num_products} products"
- variants = Hash[ products.map { |p| [p.variants.first.id, 1] }.first(num_products) ]
+ variants = Hash[products.map { |p| [p.variants.first.id, 1] }.first(num_products)]
spree_post :populate, variants: variants
end
end
diff --git a/spec/performance/shop_controller_spec.rb b/spec/performance/shop_controller_spec.rb
index 396abb574d..81073104e7 100644
--- a/spec/performance/shop_controller_spec.rb
+++ b/spec/performance/shop_controller_spec.rb
@@ -13,7 +13,7 @@ describe ShopController, type: :controller, performance: true do
describe "fetching products" do
let(:exchange) { order_cycle.exchanges.to_enterprises(d).outgoing.first }
- let(:image) { File.open(File.expand_path('../../../app/assets/images/logo-white.png', __FILE__)) }
+ let(:image) { File.open(File.expand_path('../../app/assets/images/logo-white.png', __dir__)) }
let(:cache_key_patterns) do
[
'api\/taxon_serializer\/spree\/taxons',
diff --git a/spec/requests/checkout/failed_checkout_spec.rb b/spec/requests/checkout/failed_checkout_spec.rb
index 345b6a86df..f45efe3951 100644
--- a/spec/requests/checkout/failed_checkout_spec.rb
+++ b/spec/requests/checkout/failed_checkout_spec.rb
@@ -16,7 +16,7 @@ describe "checking out an order that initially fails", type: :request do
let(:params) do
{ format: :json, order: {
shipping_method_id: shipping_method.id,
- payments_attributes: [{payment_method_id: payment_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")
} }
diff --git a/spec/requests/checkout/paypal_spec.rb b/spec/requests/checkout/paypal_spec.rb
index fc35f47071..8952afdb56 100644
--- a/spec/requests/checkout/paypal_spec.rb
+++ b/spec/requests/checkout/paypal_spec.rb
@@ -32,7 +32,7 @@ describe "checking out an order with a paypal express payment method", type: :re
set_order order
stub_request(:post, "https://api-3t.sandbox.paypal.com/2.0/")
- .to_return(:status => 200, :body => mocked_xml_response )
+ .to_return(status: 200, body: mocked_xml_response )
end
context "with a flat percent calculator" do
@@ -54,7 +54,7 @@ describe "checking out an order with a paypal express payment method", type: :re
get spree.confirm_paypal_path, params
# Processing was successful, order is complete
- expect(response).to redirect_to spree.order_path(order, :token => order.token)
+ expect(response).to redirect_to spree.order_path(order, token: order.token)
expect(order.reload.complete?).to be true
# We have only one payment, and one transaction fee
diff --git a/spec/requests/checkout/stripe_connect_spec.rb b/spec/requests/checkout/stripe_connect_spec.rb
index cd5eceb796..d1ec739df9 100644
--- a/spec/requests/checkout/stripe_connect_spec.rb
+++ b/spec/requests/checkout/stripe_connect_spec.rb
@@ -20,7 +20,7 @@ describe "checking out an order with a Stripe Connect payment method", type: :re
let(:params) do
{ format: :json, order: {
shipping_method_id: shipping_method.id,
- payments_attributes: [{payment_method_id: payment_method.id, source_attributes: { gateway_payment_profile_id: token, cc_type: "visa", last_digits: "4242", month: 10, year: 2025, first_name: 'Jill', last_name: 'Jeffreys' }}],
+ payments_attributes: [{ payment_method_id: payment_method.id, source_attributes: { gateway_payment_profile_id: token, cc_type: "visa", last_digits: "4242", month: 10, year: 2025, first_name: 'Jill', last_name: 'Jeffreys' } }],
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")
} }
@@ -38,7 +38,7 @@ describe "checking out an order with a Stripe Connect payment method", type: :re
end
context "when a new card is submitted" do
- let(:store_response_mock) { { status: 200, body: JSON.generate(id: customer_id, default_card: card_id, sources: { data: [{id: "1"}] }) } }
+ let(:store_response_mock) { { status: 200, body: JSON.generate(id: customer_id, default_card: card_id, sources: { data: [{ id: "1" }] }) } }
let(:token_response_mock) { { status: 200, body: JSON.generate(id: new_token) } }
let(:charge_response_mock) { { status: 200, body: JSON.generate(id: "ch_1234", object: "charge", amount: 2000) } }
@@ -67,7 +67,7 @@ describe "checking out an order with a Stripe Connect payment method", type: :re
end
context "when the charge request returns an error message" do
- let(:charge_response_mock) { { status: 402, body: JSON.generate(error: { message: "charge-failure"}) } }
+ let(:charge_response_mock) { { status: 402, body: JSON.generate(error: { message: "charge-failure" }) } }
it "should not process the payment" do
put update_checkout_path, params
@@ -85,12 +85,12 @@ describe "checking out an order with a Stripe Connect payment method", type: :re
# Saves the card against the user
stub_request(:post, "https://api.stripe.com/v1/customers")
- .with(basic_auth: ["sk_test_12345", ""], body: { card: token, email: order.email})
+ .with(basic_auth: ["sk_test_12345", ""], body: { card: token, email: order.email })
.to_return(store_response_mock)
# Requests a token from the newly saved card
stub_request(:post, "https://api.stripe.com/v1/tokens")
- .with(:body => { card: card_id, customer: customer_id})
+ .with(body: { card: card_id, customer: customer_id })
.to_return(token_response_mock)
# Charges the card
@@ -115,7 +115,7 @@ describe "checking out an order with a Stripe Connect payment method", type: :re
end
context "when the store request returns an error message" do
- let(:store_response_mock) { { status: 402, body: JSON.generate(error: { message: "store-failure"}) } }
+ let(:store_response_mock) { { status: 402, body: JSON.generate(error: { message: "store-failure" }) } }
it "should not process the payment" do
put update_checkout_path, params
@@ -127,7 +127,7 @@ describe "checking out an order with a Stripe Connect payment method", type: :re
end
context "when the charge request returns an error message" do
- let(:charge_response_mock) { { status: 402, body: JSON.generate(error: { message: "charge-failure"}) } }
+ let(:charge_response_mock) { { status: 402, body: JSON.generate(error: { message: "charge-failure" }) } }
it "should not process the payment" do
put update_checkout_path, params
@@ -139,7 +139,7 @@ describe "checking out an order with a Stripe Connect payment method", type: :re
end
context "when the token request returns an error message" do
- let(:token_response_mock) { { status: 402, body: JSON.generate(error: { message: "token-failure"}) } }
+ let(:token_response_mock) { { status: 402, body: JSON.generate(error: { message: "token-failure" }) } }
# Note, no requests have been stubbed
it "should not process the payment" do
@@ -177,7 +177,7 @@ describe "checking out an order with a Stripe Connect payment method", type: :re
# Requests a token
stub_request(:post, "https://api.stripe.com/v1/tokens")
- .with(:body => {"card" => card_id, "customer" => customer_id})
+ .with(body: { "card" => card_id, "customer" => customer_id })
.to_return(token_response_mock)
# Charges the card
@@ -203,7 +203,7 @@ describe "checking out an order with a Stripe Connect payment method", type: :re
end
context "when the charge request returns an error message" do
- let(:charge_response_mock) { { status: 402, body: JSON.generate(error: { message: "charge-failure"}) } }
+ let(:charge_response_mock) { { status: 402, body: JSON.generate(error: { message: "charge-failure" }) } }
it "should not process the payment" do
put update_checkout_path, params
@@ -215,7 +215,7 @@ describe "checking out an order with a Stripe Connect payment method", type: :re
end
context "when the token request returns an error message" do
- let(:token_response_mock) { { status: 402, body: JSON.generate(error: { message: "token-error"}) } }
+ let(:token_response_mock) { { status: 402, body: JSON.generate(error: { message: "token-error" }) } }
it "should not process the payment" do
put update_checkout_path, params
diff --git a/spec/serializers/admin/customer_serializer_spec.rb b/spec/serializers/admin/customer_serializer_spec.rb
index 7d46f8aa83..02c97e3948 100644
--- a/spec/serializers/admin/customer_serializer_spec.rb
+++ b/spec/serializers/admin/customer_serializer_spec.rb
@@ -11,8 +11,8 @@ describe Api::Admin::CustomerSerializer do
expect(result['email']).to eq customer.email
tags = result['tags']
expect(tags.length).to eq 3
- expect(tags[0]).to eq({ "text" => 'one', "rules" => nil })
- expect(tags[1]).to eq({ "text" => 'two', "rules" => 1 })
+ expect(tags[0]).to eq("text" => 'one', "rules" => nil)
+ expect(tags[1]).to eq("text" => 'two', "rules" => 1)
expect(result['bill_address']['id']).to eq customer.bill_address.id
expect(result['bill_address']['address1']).to eq customer.bill_address.address1
diff --git a/spec/serializers/admin/enterprise_serializer_spec.rb b/spec/serializers/admin/enterprise_serializer_spec.rb
index fab8f50731..3216e1966a 100644
--- a/spec/serializers/admin/enterprise_serializer_spec.rb
+++ b/spec/serializers/admin/enterprise_serializer_spec.rb
@@ -3,8 +3,8 @@ require "spec_helper"
describe Api::Admin::EnterpriseSerializer do
let(:enterprise) { create(:distributor_enterprise) }
it "serializes an enterprise" do
- serializer = Api::Admin::EnterpriseSerializer.new enterprise
- expect(serializer.to_json).to match enterprise.name
+ serializer = Api::Admin::EnterpriseSerializer.new enterprise
+ expect(serializer.to_json).to match enterprise.name
end
context "for logo" do
diff --git a/spec/serializers/admin/exchange_serializer_spec.rb b/spec/serializers/admin/exchange_serializer_spec.rb
index 31ab38fb86..6998159fb1 100644
--- a/spec/serializers/admin/exchange_serializer_spec.rb
+++ b/spec/serializers/admin/exchange_serializer_spec.rb
@@ -9,7 +9,6 @@ describe Api::Admin::ExchangeSerializer do
let(:permitted_variants) { Spree::Variant.where(id: [v1, v2]) }
let(:serializer) { Api::Admin::ExchangeSerializer.new exchange }
-
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) }
diff --git a/spec/serializers/admin/for_order_cycle/enterprise_serializer_spec.rb b/spec/serializers/admin/for_order_cycle/enterprise_serializer_spec.rb
index 03e580c6ed..f33f33d0a5 100644
--- a/spec/serializers/admin/for_order_cycle/enterprise_serializer_spec.rb
+++ b/spec/serializers/admin/for_order_cycle/enterprise_serializer_spec.rb
@@ -39,7 +39,6 @@ describe Api::Admin::ForOrderCycle::EnterpriseSerializer do
end
end
-
context "when order cycle shows all available products" do
before do
allow(order_cycle).to receive(:prefers_product_selection_from_coordinator_inventory_only?) { false }
@@ -55,5 +54,4 @@ describe Api::Admin::ForOrderCycle::EnterpriseSerializer do
end
end
end
-
end
diff --git a/spec/serializers/admin/for_order_cycle/supplied_product_serializer_spec.rb b/spec/serializers/admin/for_order_cycle/supplied_product_serializer_spec.rb
index 16c562120e..57da9767c4 100644
--- a/spec/serializers/admin/for_order_cycle/supplied_product_serializer_spec.rb
+++ b/spec/serializers/admin/for_order_cycle/supplied_product_serializer_spec.rb
@@ -2,10 +2,10 @@ describe Api::Admin::ForOrderCycle::EnterpriseSerializer do
let(:coordinator) { create(:distributor_enterprise) }
let(:order_cycle) { double(:order_cycle, coordinator: coordinator) }
let!(:product) { create(:simple_product) }
- let!(:non_inventory_variant) { product.variants.first }
- let!(:inventory_variant) { create(:variant, product: product.reload) }
+ 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!(: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
@@ -20,7 +20,6 @@ describe Api::Admin::ForOrderCycle::EnterpriseSerializer do
end
end
-
context "when order cycle shows all available products" do
before do
allow(order_cycle).to receive(:prefers_product_selection_from_coordinator_inventory_only?) { false }
@@ -34,5 +33,4 @@ describe Api::Admin::ForOrderCycle::EnterpriseSerializer do
end
end
end
-
end
diff --git a/spec/serializers/admin/variant_override_serializer_spec.rb b/spec/serializers/admin/variant_override_serializer_spec.rb
index 42e0e8f909..22fa5ef3cf 100644
--- a/spec/serializers/admin/variant_override_serializer_spec.rb
+++ b/spec/serializers/admin/variant_override_serializer_spec.rb
@@ -2,7 +2,7 @@ describe Api::Admin::VariantOverrideSerializer do
let(:variant) { create(:variant) }
let(:hub) { create(:distributor_enterprise) }
let(:price) { 77.77 }
- let(:count_on_hand) { 11111 }
+ let(:count_on_hand) { 11_111 }
let(:variant_override) { create(:variant_override, variant: variant, hub: hub, price: price, count_on_hand: count_on_hand) }
it "serializes a variant override" do
diff --git a/spec/serializers/credit_card_serializer_spec.rb b/spec/serializers/credit_card_serializer_spec.rb
index 31786903c8..86cdef796a 100644
--- a/spec/serializers/credit_card_serializer_spec.rb
+++ b/spec/serializers/credit_card_serializer_spec.rb
@@ -4,7 +4,6 @@ describe Api::CreditCardSerializer do
let(:card) { create(:credit_card) }
let(:serializer) { Api::CreditCardSerializer.new card }
-
it "serializes a credit card" do
expect(serializer.to_json).to match card.last_digits.to_s
end
diff --git a/spec/serializers/enterprise_serializer_spec.rb b/spec/serializers/enterprise_serializer_spec.rb
index c332008d17..7eb6ee3adc 100644
--- a/spec/serializers/enterprise_serializer_spec.rb
+++ b/spec/serializers/enterprise_serializer_spec.rb
@@ -4,13 +4,14 @@ describe Api::EnterpriseSerializer do
let(:serializer) { Api::EnterpriseSerializer.new enterprise, data: data }
let(:enterprise) { create(:distributor_enterprise) }
let(:taxon) { create(:taxon) }
- let(:data) { OpenStruct.new(earliest_closing_times: {},
- active_distributors: [],
- all_distributed_taxons: {enterprise.id => [123]},
- current_distributed_taxons: {enterprise.id => [123]},
- supplied_taxons: {enterprise.id => [456]},
- shipping_method_services: {},
- relatives: {enterprise.id => {producers: [123], distributors: [456]}})
+ let(:data) {
+ OpenStruct.new(earliest_closing_times: {},
+ active_distributors: [],
+ all_distributed_taxons: { enterprise.id => [123] },
+ current_distributed_taxons: { enterprise.id => [123] },
+ supplied_taxons: { enterprise.id => [456] },
+ shipping_method_services: {},
+ relatives: { enterprise.id => { producers: [123], distributors: [456] } })
}
it "serializes an enterprise" do
@@ -18,13 +19,13 @@ describe Api::EnterpriseSerializer do
end
it "serializes taxons as ids only" do
- expect(serializer.serializable_hash[:taxons]).to eq([{id: 123}])
- expect(serializer.serializable_hash[:supplied_taxons]).to eq([{id: 456}])
+ expect(serializer.serializable_hash[:taxons]).to eq([{ id: 123 }])
+ expect(serializer.serializable_hash[:supplied_taxons]).to eq([{ id: 456 }])
end
it "serializes producers and hubs as ids only" do
- expect(serializer.serializable_hash[:producers]).to eq([{id: 123}])
- expect(serializer.serializable_hash[:hubs]).to eq([{id: 456}])
+ expect(serializer.serializable_hash[:producers]).to eq([{ id: 123 }])
+ expect(serializer.serializable_hash[:hubs]).to eq([{ id: 456 }])
end
it "serializes icons" do
diff --git a/spec/serializers/variant_serializer_spec.rb b/spec/serializers/variant_serializer_spec.rb
index 583412ff56..cd42514e99 100644
--- a/spec/serializers/variant_serializer_spec.rb
+++ b/spec/serializers/variant_serializer_spec.rb
@@ -6,8 +6,8 @@ describe Api::VariantSerializer do
it "includes the expected attributes" do
expect(subject.attributes.keys).
- to include(
- :id,
+ to include(
+ :id,
:name_to_display,
:is_master,
:on_hand,
@@ -21,6 +21,6 @@ describe Api::VariantSerializer do
:price_with_fees,
:product_name,
:tag_list # Used to apply tag rules
- )
+ )
end
end
diff --git a/spec/services/advance_order_service_spec.rb b/spec/services/advance_order_service_spec.rb
index 36d2eed834..58a2fcb03a 100644
--- a/spec/services/advance_order_service_spec.rb
+++ b/spec/services/advance_order_service_spec.rb
@@ -19,9 +19,9 @@ describe AdvanceOrderService do
end
describe "transition from delivery" do
- let!(:shipping_method_a) { create(:shipping_method, distributors: [ distributor ]) }
- let!(:shipping_method_b) { create(:shipping_method, distributors: [ distributor ]) }
- let!(:shipping_method_c) { create(:shipping_method, distributors: [ distributor ]) }
+ let!(:shipping_method_a) { create(:shipping_method, distributors: [distributor]) }
+ let!(:shipping_method_b) { create(:shipping_method, distributors: [distributor]) }
+ let!(:shipping_method_c) { create(:shipping_method, distributors: [distributor]) }
before do
# Create shipping rates for available shipping methods.
diff --git a/spec/services/cart_service_spec.rb b/spec/services/cart_service_spec.rb
index 3fd70c27fe..8a01a8cdb0 100644
--- a/spec/services/cart_service_spec.rb
+++ b/spec/services/cart_service_spec.rb
@@ -242,7 +242,7 @@ describe CartService do
end
it "delegates to OrderCycleDistributedVariants, returning false and erroring otherwise" do
- expect(order_cycle_distributed_variants).to receive(:available_variants).and_return([])
+ expect(order_cycle_distributed_variants).to receive(:available_variants).and_return([])
expect(cart_service.send(:check_variant_available_under_distribution, variant)).to be false
expect(cart_service.errors.to_a).to eq(["That product is not available from the chosen distributor or order cycle."])
diff --git a/spec/services/mail_configuration_spec.rb b/spec/services/mail_configuration_spec.rb
index b93bff9b28..c91cb7469a 100644
--- a/spec/services/mail_configuration_spec.rb
+++ b/spec/services/mail_configuration_spec.rb
@@ -21,13 +21,13 @@ describe MailConfiguration do
end
it 'sets config entries in the Spree Config' do
- described_class.entries= entries
+ described_class.entries = entries
expect(Spree::Config[:smtp_username]).to eq("smtp_username")
expect(Spree::Config[:mail_auth_type]).to eq("login")
end
it 'initializes the mail settings' do
- described_class.entries= entries
+ described_class.entries = entries
expect(Spree::Core::MailSettings).to have_received(:init)
end
end
diff --git a/spec/services/order_cycle_distributed_variants_spec.rb b/spec/services/order_cycle_distributed_variants_spec.rb
index 8b92e7905b..f93e72e67f 100644
--- a/spec/services/order_cycle_distributed_variants_spec.rb
+++ b/spec/services/order_cycle_distributed_variants_spec.rb
@@ -3,7 +3,7 @@ require 'spec_helper'
describe OrderCycleDistributedVariants do
let(:order) { double(:order) }
let(:distributor) { double(:distributor) }
- let(:order_cycle) { double(:order_cycle) }
+ let(:order_cycle) { double(:order_cycle) }
let(:subject) { OrderCycleDistributedVariants.new(order_cycle, distributor) }
let(:product) { double(:product) }
diff --git a/spec/services/order_syncer_spec.rb b/spec/services/order_syncer_spec.rb
index 0b37490fb2..3d1e7068b9 100644
--- a/spec/services/order_syncer_spec.rb
+++ b/spec/services/order_syncer_spec.rb
@@ -374,7 +374,7 @@ describe OrderSyncer do
before { variant.update_attribute(:on_hand, 2) }
context "when quantity is within available stock" do
- let(:params) { { subscription_line_items_attributes: [{ id: sli.id, quantity: 2}] } }
+ let(:params) { { subscription_line_items_attributes: [{ id: sli.id, quantity: 2 }] } }
let(:syncer) { OrderSyncer.new(subscription) }
it "updates the line_item quantities and totals on all orders" do
@@ -388,7 +388,7 @@ describe OrderSyncer do
end
context "when quantity is greater than available stock" do
- let(:params) { { subscription_line_items_attributes: [{ id: sli.id, quantity: 3}] } }
+ let(:params) { { subscription_line_items_attributes: [{ id: sli.id, quantity: 3 }] } }
let(:syncer) { OrderSyncer.new(subscription) }
it "updates the line_item quantities and totals on all orders" do
@@ -402,7 +402,7 @@ describe OrderSyncer do
end
context "where the quantity of the item on an initialised order has already been changed" do
- let(:params) { { subscription_line_items_attributes: [{ id: sli.id, quantity: 3}] } }
+ let(:params) { { subscription_line_items_attributes: [{ id: sli.id, quantity: 3 }] } }
let(:syncer) { OrderSyncer.new(subscription) }
let(:changed_line_item) { order.line_items.find_by_variant_id(sli.variant_id) }
@@ -440,7 +440,7 @@ describe OrderSyncer do
let(:subscription) { create(:subscription, with_items: true, with_proxy_orders: true) }
let(:order) { subscription.proxy_orders.first.initialise_order! }
let(:variant) { create(:variant) }
- 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 }] } }
let(:syncer) { OrderSyncer.new(subscription) }
it "adds the line item and updates the total on all orders" do
diff --git a/spec/services/subscription_form_spec.rb b/spec/services/subscription_form_spec.rb
index 8d9d0b879d..ebd66f55b3 100644
--- a/spec/services/subscription_form_spec.rb
+++ b/spec/services/subscription_form_spec.rb
@@ -37,9 +37,9 @@ describe SubscriptionForm do
begins_at: 4.days.ago,
ends_at: 14.days.from_now,
subscription_line_items_attributes: [
- {variant_id: variant1.id, quantity: 1, price_estimate: 7.0},
- {variant_id: variant2.id, quantity: 2, price_estimate: 8.0},
- {variant_id: variant3.id, quantity: 3, price_estimate: 9.0}
+ { variant_id: variant1.id, quantity: 1, price_estimate: 7.0 },
+ { variant_id: variant2.id, quantity: 2, price_estimate: 8.0 },
+ { variant_id: variant3.id, quantity: 3, price_estimate: 9.0 }
]
} }
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
index 1add45e58f..cad940fac8 100644
--- a/spec/spec_helper.rb
+++ b/spec/spec_helper.rb
@@ -10,7 +10,7 @@ require 'pry' unless ENV['CI']
# use Knapsack, and this provides the option to disable it when running the tests in CI services.
unless ENV['DISABLE_KNAPSACK']
require 'knapsack'
- Knapsack.tracker.config({enable_time_offset_warning: false}) unless ENV['CI']
+ Knapsack.tracker.config(enable_time_offset_warning: false) unless ENV['CI']
Knapsack::Adapters::RSpecAdapter.bind
end
@@ -35,7 +35,7 @@ WebMock.disable_net_connect!({
# Requires supporting ruby files with custom matchers and macros, etc,
# in spec/support/ and its subdirectories.
-Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
+Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f }
require 'spree/testing_support/controller_requests'
require 'spree/testing_support/capybara_ext'
require 'spree/api/testing_support/setup'
@@ -87,18 +87,18 @@ RSpec.configure do |config|
config.infer_base_class_for_anonymous_controllers = false
# Filters
- config.filter_run_excluding :skip => true, :future => true, :to_figure_out => true
+ config.filter_run_excluding skip: true, future: true, to_figure_out: true
# Retry
config.verbose_retry = true
# 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, js: 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
+ config.after(:each, js: true) do
Capybara.reset_sessions!
RackRequestBlocker.wait_for_requests_complete
end
@@ -112,10 +112,10 @@ RSpec.configure do |config|
config.before(:all) { restart_phantomjs }
# 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 = Spree::Config[:default_country_id]
- checkout_zone = Spree::Config[:checkout_zone]
+ checkout_zone = Spree::Config[:checkout_zone]
currency = Spree::Config[:currency]
# Ensure we start with consistent config settings
config.before(:each) do
@@ -137,12 +137,12 @@ RSpec.configure do |config|
config.include Spree::UrlHelpers
config.include Spree::CheckoutHelpers
config.include Spree::MoneyHelper
- config.include Spree::TestingSupport::ControllerRequests, :type => :controller
+ config.include Spree::TestingSupport::ControllerRequests, type: :controller
config.include Spree::TestingSupport::Preferences
- config.include Devise::TestHelpers, :type => :controller
- config.extend Spree::Api::TestingSupport::Setup, :type => :controller
- config.include Spree::Api::TestingSupport::Helpers, :type => :controller
- config.include OpenFoodNetwork::ControllerHelper, :type => :controller
+ config.include Devise::TestHelpers, type: :controller
+ config.extend Spree::Api::TestingSupport::Setup, type: :controller
+ config.include Spree::Api::TestingSupport::Helpers, type: :controller
+ config.include OpenFoodNetwork::ControllerHelper, type: :controller
config.include Features::DatepickerHelper, type: :feature
config.include OpenFoodNetwork::FeatureToggleHelper
config.include OpenFoodNetwork::FiltersHelper
@@ -175,12 +175,12 @@ RSpec.configure do |config|
# bundle exec pprof.rb --text /tmp/rspec_profile
#
- #require 'perftools'
- #config.before :suite do
+ # require 'perftools'
+ # config.before :suite do
# PerfTools::CpuProfiler.start("/tmp/rspec_profile")
- #end
+ # end
#
- #config.after :suite do
+ # config.after :suite do
# PerfTools::CpuProfiler.stop
- #end
+ # end
end
diff --git a/spec/support/cancan_helper.rb b/spec/support/cancan_helper.rb
index 96e4ca1cdc..332c93a19f 100644
--- a/spec/support/cancan_helper.rb
+++ b/spec/support/cancan_helper.rb
@@ -8,26 +8,26 @@ module Spree
ability = Ability.new(user)
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({}){|_, i| _.merge({i=>true}) } if ability_hash.is_a? Array # e.g.: [:create, :read] => {:create=>true, :read=>true}
- ability_hash.each do |action, true_or_false|
+ ability_hash = { ability_hash => true } if ability_hash.is_a? Symbol # e.g.: :create => {:create => true}
+ ability_hash = ability_hash.inject({}){ |_, i| _.merge(i => true) } if ability_hash.is_a? Array # e.g.: [:create, :read] => {:create=>true, :read=>true}
+ ability_hash.each do |action, _true_or_false|
@ability_result[action] = ability.can?(action, target)
end
- !ability_hash.diff(@ability_result).any?
+ ability_hash.diff(@ability_result).none?
end
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({}){|_, i| _.merge({i=>true}) } if ability_hash.is_a? Array # e.g.: [:create, :read] => {:create=>true, :read=>true}
+ ability_hash, options = expected
+ ability_hash = { ability_hash => true } if ability_hash.is_a? Symbol # e.g.: :create
+ ability_hash = ability_hash.inject({}){ |_, i| _.merge(i => true) } if ability_hash.is_a? Array # e.g.: [:create, :read] => {:create=>true, :read=>true}
target = options[:for]
message = "expected User:#{user} to have ability:#{ability_hash} for #{target}, but actual result is #{@ability_result}"
end
- #to clean up output of RSpec Documentation format
+ # to clean up output of RSpec Documentation format
description do
target = expected.last[:for]
- "have ability #{ability_hash.keys.join(", ")} for #{target.class.name}"
+ "have ability #{ability_hash.keys.join(', ')} for #{target.class.name}"
end
end
end
diff --git a/spec/support/delayed_job_helper.rb b/spec/support/delayed_job_helper.rb
index db094f98b8..a08f493cb6 100644
--- a/spec/support/delayed_job_helper.rb
+++ b/spec/support/delayed_job_helper.rb
@@ -26,7 +26,6 @@ module OpenFoodNetwork
Delayed::Job.delete_all
end
-
# expect { foo }.to enqueue_job MyJob, field1: 'foo', field2: 'bar'
RSpec::Matchers.define :enqueue_job do |klass, options = {}|
match do |event_proc|
@@ -59,11 +58,11 @@ module OpenFoodNetwork
end
end
- failure_message do |event_proc|
+ failure_message do |_event_proc|
@exception || "expected #{klass} to be enqueued matching #{options.inspect} (#{@jobs_created.count} others enqueued)"
end
- failure_message_when_negated do |event_proc|
+ failure_message_when_negated do |_event_proc|
@exception || "expected #{klass} to not be enqueued matching #{options.inspect}"
end
diff --git a/spec/support/matchers/delegate_matchers.rb b/spec/support/matchers/delegate_matchers.rb
index f036127a2b..6af4ac68bd 100644
--- a/spec/support/matchers/delegate_matchers.rb
+++ b/spec/support/matchers/delegate_matchers.rb
@@ -26,15 +26,14 @@ RSpec::Matchers.define :delegate do |method|
"delegate :#{@method} to its #{@to}#{@prefix ? ' with prefix' : ''}"
end
- failure_message do |text|
+ failure_message do |_text|
"expected #{@delegator} to delegate :#{@method} to its #{@to}#{@prefix ? ' with prefix' : ''}"
end
- failure_message_when_negated do |text|
+ failure_message_when_negated do |_text|
"expected #{@delegator} not to delegate :#{@method} to its #{@to}#{@prefix ? ' with prefix' : ''}"
end
chain(:to) { |receiver| @to = receiver }
chain(:with_prefix) { @prefix = true }
-
end
diff --git a/spec/support/matchers/flash_message_matchers.rb b/spec/support/matchers/flash_message_matchers.rb
index b781fc1811..af9398425a 100644
--- a/spec/support/matchers/flash_message_matchers.rb
+++ b/spec/support/matchers/flash_message_matchers.rb
@@ -8,7 +8,7 @@ RSpec::Matchers.define :have_flash_message do |message|
node.has_selector?(".flash", text: message_substring_regex, visible: false)
end
- failure_message do |actual|
+ failure_message do |_actual|
"expected to find flash message ##{@message}"
end
@@ -21,7 +21,7 @@ RSpec::Matchers.define :have_flash_message do |message|
node.has_no_selector?(".flash", text: message_substring_regex, visible: false)
end
- failure_message_when_negated do |actual|
+ failure_message_when_negated do |_actual|
"expected not to find flash message ##{@message}"
end
diff --git a/spec/support/matchers/select2_matchers.rb b/spec/support/matchers/select2_matchers.rb
index 5e57f05d73..ff7b6b8afe 100644
--- a/spec/support/matchers/select2_matchers.rb
+++ b/spec/support/matchers/select2_matchers.rb
@@ -1,5 +1,4 @@
-RSpec::Matchers.define :have_select2 do |id, options={}|
-
+RSpec::Matchers.define :have_select2 do |id, options = {}|
# TODO: Implement other have_select options
# http://www.rubydoc.info/github/jnicklas/capybara/Capybara/Node/Matchers#has_select%3F-instance_method
# TODO: Instead of passing in id, use a more general locator
@@ -7,7 +6,7 @@ RSpec::Matchers.define :have_select2 do |id, options={}|
match do |node|
@id, @options, @node = id, options, node
- #id = find_label_by_text(locator)
+ # id = find_label_by_text(locator)
from = "#s2id_#{id}"
results = []
@@ -27,7 +26,7 @@ RSpec::Matchers.define :have_select2 do |id, options={}|
results.all?
end
- failure_message do |actual|
+ failure_message do |_actual|
message = "expected to find select2 ##{@id}"
message += " with #{@options.inspect}" if @options.any?
message
@@ -36,7 +35,7 @@ RSpec::Matchers.define :have_select2 do |id, options={}|
match_when_negated do |node|
@id, @options, @node = id, options, node
- #id = find_label_by_text(locator)
+ # id = find_label_by_text(locator)
from = "#s2id_#{id}"
results = []
@@ -49,8 +48,8 @@ RSpec::Matchers.define :have_select2 do |id, options={}|
if results.none?
results << all_options_absent(from, options[:with_options]) if options.key? :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
+ # 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
if (options.keys & %i(selected options without_options)).any?
@@ -60,7 +59,7 @@ RSpec::Matchers.define :have_select2 do |id, options={}|
results.any?
end
- failure_message_when_negated do |actual|
+ failure_message_when_negated do |_actual|
message = "expected not to find select2 ##{@id}"
message += " with #{@options.inspect}" if @options.any?
message
diff --git a/spec/support/matchers/table_matchers.rb b/spec/support/matchers/table_matchers.rb
index 7b3d7ebf96..e5594c53f7 100644
--- a/spec/support/matchers/table_matchers.rb
+++ b/spec/support/matchers/table_matchers.rb
@@ -1,5 +1,4 @@
RSpec::Matchers.define :have_table_row do |row|
-
match do |node|
@row = row
rows_under(node).include? row # Robust check of columns
@@ -10,11 +9,11 @@ RSpec::Matchers.define :have_table_row do |row|
!rows_under(node).include? row # Robust check of columns
end
- failure_message do |text|
+ failure_message do |_text|
"expected to find table row #{@row}"
end
- failure_message_when_negated do |text|
+ failure_message_when_negated do |_text|
"expected not to find table row #{@row}"
end
@@ -23,11 +22,8 @@ RSpec::Matchers.define :have_table_row do |row|
end
end
-
-
# find("#my-table").should match_table [[...]]
RSpec::Matchers.define :match_table do |expected_table|
-
match do |node|
rows = node.
all("tr").
@@ -58,8 +54,7 @@ RSpec::Matchers.define :match_table do |expected_table|
@failure_message.nil?
end
- failure_message do |text|
+ failure_message do |_text|
@failure_message
end
-
end
diff --git a/spec/support/performance_helper.rb b/spec/support/performance_helper.rb
index ebcb8d8825..2f2b42cb8e 100644
--- a/spec/support/performance_helper.rb
+++ b/spec/support/performance_helper.rb
@@ -1,7 +1,7 @@
module OpenFoodNetwork
module PerformanceHelper
def multi_benchmark(num_samples, cache_key_patterns: [])
- results = (0..num_samples).map do |i|
+ results = (0..num_samples).map do |_i|
ActiveRecord::Base.connection.query_cache.clear
delete_cache_keys(cache_key_patterns)
diff --git a/spec/support/request/authentication_workflow.rb b/spec/support/request/authentication_workflow.rb
index 7806676781..214c901d77 100644
--- a/spec/support/request/authentication_workflow.rb
+++ b/spec/support/request/authentication_workflow.rb
@@ -8,11 +8,11 @@ module AuthenticationWorkflow
def quick_login_as_admin
admin_role = Spree::Role.find_or_create_by_name!('admin')
admin_user = create(:user,
- :password => 'passw0rd',
- :password_confirmation => 'passw0rd',
- :remember_me => false,
- :persistence_token => 'pass',
- :login => 'admin@ofn.org')
+ password: 'passw0rd',
+ password_confirmation: 'passw0rd',
+ remember_me: false,
+ persistence_token: 'pass',
+ login: 'admin@ofn.org')
admin_user.spree_roles << admin_role
quick_login_as admin_user
@@ -32,24 +32,25 @@ module AuthenticationWorkflow
new_user
end
- def login_to_admin_as user
+ def login_to_admin_as(user)
quick_login_as user
visit spree.admin_path
- #visit spree.admin_path
- #fill_in 'spree_user_email', :with => user.email
- #fill_in 'spree_user_password', :with => user.password
- #click_button 'Login'
+ # visit spree.admin_path
+ # fill_in 'spree_user_email', :with => user.email
+ # fill_in 'spree_user_password', :with => user.password
+ # click_button 'Login'
end
def login_to_consumer_section
user_role = Spree::Role.find_or_create_by_name!('user')
- user = create_enterprise_user({
- :email => 'someone@ofn.org',
- :password => 'passw0rd',
- :password_confirmation => 'passw0rd',
- :remember_me => false,
- :persistence_token => 'pass',
- :login => 'someone@ofn.org'})
+ user = create_enterprise_user(
+ email: 'someone@ofn.org',
+ password: 'passw0rd',
+ password_confirmation: 'passw0rd',
+ remember_me: false,
+ persistence_token: 'pass',
+ login: 'someone@ofn.org'
+ )
user.spree_roles << user_role
@@ -65,7 +66,7 @@ module AuthenticationWorkflow
end
RSpec.configure do |config|
- config.extend AuthenticationWorkflow, :type => :feature
+ config.extend AuthenticationWorkflow, type: :feature
# rspec-rails 3 will no longer automatically infer an example group's spec type
# from the file location. You can explicitly opt-in to the feature using this
diff --git a/spec/support/request/distribution_helper.rb b/spec/support/request/distribution_helper.rb
index 7a565cb2b9..cd9a5fe8dc 100644
--- a/spec/support/request/distribution_helper.rb
+++ b/spec/support/request/distribution_helper.rb
@@ -1,6 +1,6 @@
module OpenFoodNetwork
module DistributionHelper
- def select_distribution(distributor, order_cycle=nil)
+ def select_distribution(distributor, order_cycle = nil)
create_enterprise_group_for distributor
visit root_path
click_link distributor.name
diff --git a/spec/support/request/menu_helper.rb b/spec/support/request/menu_helper.rb
index b9595e0a8c..da8f1ad399 100644
--- a/spec/support/request/menu_helper.rb
+++ b/spec/support/request/menu_helper.rb
@@ -4,6 +4,6 @@ module MenuHelper
end
def have_login_modal
- have_selector ".login-modal"
+ have_selector ".login-modal"
end
end
diff --git a/spec/support/request/shop_workflow.rb b/spec/support/request/shop_workflow.rb
index 98b0a52d86..ff5909f267 100644
--- a/spec/support/request/shop_workflow.rb
+++ b/spec/support/request/shop_workflow.rb
@@ -13,12 +13,12 @@ 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)
cart_service = CartService.new(order)
- cart_service.populate(variants: {product.variants.first.id => quantity})
+ cart_service.populate(variants: { product.variants.first.id => quantity })
# Recalculate fee totals
order.update_distribution_charge!
diff --git a/spec/support/request/ui_component_helper.rb b/spec/support/request/ui_component_helper.rb
index cc304a9364..277d8ee88c 100644
--- a/spec/support/request/ui_component_helper.rb
+++ b/spec/support/request/ui_component_helper.rb
@@ -58,7 +58,7 @@ module UIComponentHelper
have_content "An email with instructions on resetting your password has been sent!"
end
- def have_in_cart name
+ def have_in_cart(name)
show_cart
within "li.cart" do
have_content name
@@ -95,7 +95,7 @@ module UIComponentHelper
end
def open_active_table_row
- page.find("hub:first-child .active_table_row:first-child").click()
+ page.find("hub:first-child .active_table_row:first-child").click
end
def expand_active_table_node(name)
@@ -104,6 +104,6 @@ module UIComponentHelper
def follow_active_table_node(name)
expand_active_table_node(name)
- page.find(".active_table_node a", text: "#{name}").click
+ page.find(".active_table_node a", text: name.to_s).click
end
end
diff --git a/spec/support/request/web_helper.rb b/spec/support/request/web_helper.rb
index 837483544f..803e70a832 100644
--- a/spec/support/request/web_helper.rb
+++ b/spec/support/request/web_helper.rb
@@ -11,12 +11,12 @@ module WebHelper
# use_short_wait
# ...
# end
- def use_short_wait(seconds=2)
+ def use_short_wait(seconds = 2)
around { |example| Capybara.using_wait_time(seconds) { example.run } }
end
end
- def have_input(name, opts={})
+ def have_input(name, opts = {})
selector = "[name='#{name}']"
selector += "[placeholder='#{opts[:placeholder]}']" if opts.key? :placeholder
@@ -29,14 +29,14 @@ module WebHelper
def fill_in_fields(field_values)
field_values.each do |key, value|
begin
- fill_in key, :with => value
+ fill_in key, with: value
rescue Capybara::ElementNotFound
find_field(key).select(value)
end
end
end
- def select_by_value(value, options={})
+ def select_by_value(value, options = {})
from = options.delete :from
page.find_by_id(from).find("option[value='#{value}']").select_option
end
@@ -45,8 +45,8 @@ module WebHelper
find('.flash', visible: false).text(:all).strip
end
- def handle_js_confirm(accept=true)
- page.execute_script "window.confirm = function(msg) { return #{!!accept }; }"
+ def handle_js_confirm(accept = true)
+ page.execute_script "window.confirm = function(msg) { return #{!!accept}; }"
yield
end
@@ -71,10 +71,10 @@ module WebHelper
# eg. script_content with: 'my-script.com'
# Returns nil if not found
# Raises an exception if multiple matching blocks are found
- def script_content(opts={})
+ def script_content(opts = {})
elems = page.all('script', visible: false)
- elems = elems.to_a.select { |e| e.text(:all).include? opts[:with] } if opts[:with]
+ elems = elems.to_a.select { |e| e.text(:all).include? opts[:with] } if opts[:with]
if elems.none?
nil
@@ -87,7 +87,7 @@ module WebHelper
# http://www.elabs.se/blog/53-why-wait_until-was-removed-from-capybara
# Do not use this without good reason. Capybara's built-in waiting is very effective.
- def wait_until(secs=nil)
+ def wait_until(secs = nil)
require "timeout"
Timeout.timeout(secs || Capybara.default_max_wait_time) do
sleep(0.1) until value = yield
@@ -110,7 +110,7 @@ module WebHelper
#
# This overrides the method in Spree.
def targetted_select2_search(value, options)
- page.execute_script %Q{$('#{options[:from]}').select2('open')}
+ page.execute_script %{$('#{options[:from]}').select2('open')}
page.execute_script "$('#{options[:dropdown_css]} input.select2-input').val('#{value}').trigger('keyup-change');"
select_select2_result(options[:select_text] || value)
end
@@ -135,28 +135,28 @@ module WebHelper
end
def targetted_select2_search_async(value, options)
- page.execute_script %Q{$('#{options[:from]}').select2('open')}
+ page.execute_script %{$('#{options[:from]}').select2('open')}
page.execute_script "$('#{options[:dropdown_css]} input.select2-input').val('#{value}').trigger('keyup-change');"
select_select2_result_async(value)
end
def select_select2_result_async(value)
- while (page.has_selector? "div.select2-searching") do
+ while page.has_selector? "div.select2-searching"
return if page.has_selector? "div.select2-no-results"
sleep 0.2
end
- page.execute_script(%Q{$("div.select2-result-label:contains('#{value}')").mouseup()})
+ page.execute_script(%{$("div.select2-result-label:contains('#{value}')").mouseup()})
end
def accept_js_alert
page.driver.browser.switch_to.alert.accept
end
- def angular_http_requests_finished(controller=nil)
+ def angular_http_requests_finished(controller = nil)
page.evaluate_script("#{angular_scope(controller)}.injector().get('$http').pendingRequests.length == 0")
end
- def request_monitor_finished(controller=nil)
+ def request_monitor_finished(controller = nil)
page.evaluate_script("#{angular_scope(controller)}.scope().RequestMonitor.loading == false")
end
@@ -164,7 +164,7 @@ module WebHelper
# Takes an optional angular controller name eg: "LineItemsCtrl",
# otherwise finds the first object in the DOM with an angular scope
- def angular_scope(controller=nil)
+ def angular_scope(controller = nil)
element = controller ? "[ng-controller=#{controller}]" : '.ng-scope'
"angular.element(document.querySelector('#{element}'))"
end
diff --git a/spec/support/seeds.rb b/spec/support/seeds.rb
index ed08b26561..0a603a03e0 100644
--- a/spec/support/seeds.rb
+++ b/spec/support/seeds.rb
@@ -6,10 +6,10 @@
# You can add more entries here if you need them for your tests.
if Spree::Country.scoped.empty?
- Spree::Country.create!({"name"=>"Australia", "iso3"=>"AUS", "iso"=>"AU", "iso_name"=>"AUSTRALIA", "numcode"=>"36"}, :without_protection => true)
+ Spree::Country.create!({ "name" => "Australia", "iso3" => "AUS", "iso" => "AU", "iso_name" => "AUSTRALIA", "numcode" => "36" }, without_protection: true)
country = Spree::Country.find_by_name('Australia')
- Spree::State.create!({"name"=>"Victoria", "abbr"=>"Vic", :country=>country}, :without_protection => true)
- Spree::State.create!({"name"=>"New South Wales", "abbr"=>"NSW", :country=>country}, :without_protection => true)
+ Spree::State.create!({ "name" => "Victoria", "abbr" => "Vic", :country => country }, without_protection: true)
+ Spree::State.create!({ "name" => "New South Wales", "abbr" => "NSW", :country => country }, without_protection: true)
end
# Since the country seeding differs from other environments, the default