diff --git a/.rubocop_manual_todo.yml b/.rubocop_manual_todo.yml index ace78ed248..94fdd0bd31 100644 --- a/.rubocop_manual_todo.yml +++ b/.rubocop_manual_todo.yml @@ -21,12 +21,10 @@ Layout/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/enterprise_roles_controller.rb - app/controllers/admin/enterprises_controller.rb @@ -38,9 +36,6 @@ Layout/LineLength: - app/controllers/admin/variant_overrides_controller.rb - app/controllers/api/enterprise_attachment_controller.rb - app/controllers/api/product_images_controller.rb - - app/controllers/spree/admin/adjustments_controller_decorator.rb - - app/controllers/spree/admin/orders_controller_decorator.rb - - app/controllers/spree/credit_cards_controller.rb - app/controllers/spree/paypal_controller_decorator.rb - app/controllers/stripe/callbacks_controller.rb - app/helpers/angular_form_builder.rb @@ -50,8 +45,6 @@ Layout/LineLength: - app/helpers/injection_helper.rb - app/helpers/markdown_helper.rb - app/helpers/order_cycles_helper.rb - - app/helpers/shop_helper.rb - - app/helpers/spree/admin/base_helper_decorator.rb - app/helpers/spree/orders_helper.rb - app/jobs/subscription_confirm_job.rb - app/mailers/subscription_mailer.rb @@ -66,9 +59,6 @@ Layout/LineLength: - app/models/enterprise_role.rb - app/models/inventory_item.rb - app/models/product_import/entry_processor.rb - - app/models/product_import/entry_validator.rb - - app/models/product_import/product_importer.rb - - app/models/product_import/spreadsheet_data.rb - app/models/product_import/spreadsheet_entry.rb - app/models/product_import/unit_converter.rb - app/models/proxy_order.rb @@ -85,19 +75,23 @@ Layout/LineLength: - app/models/spree/payment_method_decorator.rb - app/models/spree/product_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/tax_rate_decorator.rb - app/models/spree/user.rb - app/models/subscription.rb - app/models/variant_override.rb - app/models/variant_override_set.rb + - app/serializers/api/admin/subscription_line_item_serializer.rb - app/services/cart_service.rb - app/services/default_stock_location.rb - app/services/embedded_page_service.rb - app/services/order_cycle_form.rb - app/services/order_factory.rb - - app/services/variants_stock_levels.rb + - engines/order_management/app/services/order_management/subscriptions/validator.rb - engines/web/app/helpers/web/cookies_policy_helper.rb + - engines/web/config/routes.rb + - engines/web/spec/features/consumer/cookies_spec.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 @@ -112,12 +106,12 @@ Layout/LineLength: - lib/open_food_network/payments_report.rb - lib/open_food_network/reports/bulk_coop_allocation_report.rb - lib/open_food_network/sales_tax_report.rb + - lib/open_food_network/scope_variants_for_search.rb - lib/open_food_network/variant_and_line_item_naming.rb - lib/open_food_network/xero_invoices_report.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/data.rake - lib/tasks/enterprises.rake - spec/controllers/admin/bulk_line_items_controller_spec.rb @@ -151,19 +145,21 @@ Layout/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/orders/customer_details_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/payment_methods_controller_spec.rb - spec/controllers/spree/admin/products_controller_spec.rb - spec/controllers/spree/admin/reports_controller_spec.rb - spec/controllers/spree/admin/variants_controller_spec.rb - spec/controllers/spree/credit_cards_controller_spec.rb - spec/controllers/spree/orders_controller_spec.rb - - spec/controllers/spree/user_sessions_controller_spec.rb - spec/controllers/spree/users_controller_spec.rb + - spec/controllers/spree/user_sessions_controller_spec.rb - spec/controllers/stripe/callbacks_controller_spec.rb - spec/controllers/stripe/webhooks_controller_spec.rb - spec/controllers/user_confirmations_controller_spec.rb + - spec/factories/order_factory.rb + - spec/factories.rb - spec/features/admin/adjustments_spec.rb - spec/features/admin/bulk_order_management_spec.rb - spec/features/admin/bulk_product_update_spec.rb @@ -171,13 +167,19 @@ Layout/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 + - spec/features/admin/order_cycles/complex_creating_specific_time_spec.rb + - spec/features/admin/order_cycles/complex_editing_multiple_product_pages_spec.rb + - spec/features/admin/order_cycles/complex_editing_spec.rb + - spec/features/admin/order_cycles/complex_updating_specific_time_spec.rb + - spec/features/admin/order_cycles/list_spec.rb + - spec/features/admin/order_cycles/simple_spec.rb + - spec/features/admin/order_spec.rb - spec/features/admin/overview_spec.rb - spec/features/admin/payment_method_spec.rb - spec/features/admin/product_import_spec.rb @@ -193,9 +195,11 @@ Layout/LineLength: - spec/features/consumer/account/settings_spec.rb - spec/features/consumer/account_spec.rb - spec/features/consumer/authentication_spec.rb - - spec/features/consumer/cookies_spec.rb + - spec/features/consumer/caching/darkwarm_caching_spec.rb + - spec/features/consumer/caching/shops_caching_spec.rb - spec/features/consumer/groups_spec.rb - spec/features/consumer/multilingual_spec.rb + - spec/features/consumer/producers_spec.rb - spec/features/consumer/registration_spec.rb - spec/features/consumer/shopping/cart_spec.rb - spec/features/consumer/shopping/checkout_auth_spec.rb @@ -234,6 +238,7 @@ Layout/LineLength: - spec/lib/open_food_network/products_and_inventory_report_spec.rb - spec/lib/open_food_network/scope_variant_to_hub_spec.rb - spec/lib/open_food_network/tag_rule_applicator_spec.rb + - spec/lib/open_food_network/user_balance_calculator_spec.rb - spec/lib/open_food_network/users_and_enterprises_report_spec.rb - spec/lib/open_food_network/xero_invoices_report_spec.rb - spec/lib/stripe/account_connector_spec.rb @@ -254,8 +259,8 @@ Layout/LineLength: - spec/models/exchange_spec.rb - spec/models/model_set_spec.rb - spec/models/order_cycle_spec.rb - - spec/models/producer_property_spec.rb - spec/models/product_importer_spec.rb + - spec/models/product_import/reset_absent_spec.rb - spec/models/proxy_order_spec.rb - spec/models/spree/ability_spec.rb - spec/models/spree/adjustment_spec.rb @@ -269,10 +274,9 @@ Layout/LineLength: - spec/models/spree/payment_spec.rb - spec/models/spree/product_set_spec.rb - spec/models/spree/product_spec.rb - - spec/models/spree/property_spec.rb - spec/models/spree/shipping_method_spec.rb - - spec/models/spree/tax_rate_spec.rb - spec/models/spree/taxon_spec.rb + - spec/models/spree/tax_rate_spec.rb - spec/models/spree/user_spec.rb - spec/models/spree/variant_spec.rb - spec/models/stripe_account_spec.rb @@ -285,10 +289,10 @@ Layout/LineLength: - spec/performance/orders_controller_spec.rb - spec/performance/shop_controller_spec.rb - spec/requests/checkout/failed_checkout_spec.rb + - spec/requests/checkout/stripe_sca_spec.rb - spec/requests/embedded_shopfronts_headers_spec.rb - spec/serializers/api/admin/customer_serializer_spec.rb - spec/serializers/api/admin/exchange_serializer_spec.rb - - spec/serializers/api/admin/for_order_cycle/enterprise_serializer_spec.rb - spec/serializers/api/admin/for_order_cycle/supplied_product_serializer_spec.rb - spec/serializers/api/admin/order_cycle_serializer_spec.rb - spec/serializers/api/admin/subscription_customer_serializer_spec.rb @@ -297,6 +301,7 @@ Layout/LineLength: - spec/serializers/api/enterprise_shopfront_serializer_spec.rb - spec/serializers/api/order_serializer_spec.rb - spec/services/cart_service_spec.rb + - spec/services/checkout/form_data_adapter_spec.rb - spec/services/embedded_page_service_spec.rb - spec/services/exchange_products_renderer_spec.rb - spec/services/order_cycle_distributed_products_spec.rb @@ -304,16 +309,17 @@ Layout/LineLength: - spec/services/order_cycle_form_spec.rb - spec/services/order_factory_spec.rb - spec/services/order_syncer_spec.rb + - spec/services/order_tax_adjustments_fetcher_spec.rb - spec/services/permissions/order_spec.rb - - spec/services/product_tag_rules_filterer_spec.rb + - spec/services/permitted_attributes/order_cycle_spec.rb - spec/services/products_renderer_spec.rb + - spec/services/product_tag_rules_filterer_spec.rb - spec/spec_helper.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/request/authentication_workflow.rb - spec/support/request/shop_workflow.rb - spec/support/request/web_helper.rb - spec/support/seeds.rb @@ -327,7 +333,6 @@ Metrics/AbcSize: - 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 - app/controllers/admin/stripe_accounts_controller.rb - app/controllers/admin/subscription_line_items_controller.rb - app/controllers/admin/subscriptions_controller.rb @@ -337,14 +342,12 @@ Metrics/AbcSize: - app/controllers/api/shipments_controller.rb - app/controllers/api/taxons_controller.rb - app/controllers/api/variants_controller.rb - - app/controllers/base_controller.rb - app/controllers/cart_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/image_settings_controller.rb - - app/controllers/spree/admin/orders/customer_details_controller.rb - app/controllers/spree/admin/orders_controller.rb + - app/controllers/spree/admin/orders/customer_details_controller.rb - app/controllers/spree/admin/overview_controller.rb - app/controllers/spree/admin/payment_methods_controller.rb - app/controllers/spree/admin/payments_controller.rb @@ -354,13 +357,12 @@ Metrics/AbcSize: - app/controllers/spree/admin/search_controller.rb - app/controllers/spree/admin/taxons_controller.rb - app/controllers/spree/admin/users_controller.rb - - app/controllers/spree/admin/variants_controller.rb - app/controllers/spree/credit_cards_controller.rb - app/controllers/spree/orders_controller.rb - app/controllers/spree/user_passwords_controller.rb - app/controllers/spree/user_registrations_controller.rb - - app/controllers/spree/user_sessions_controller.rb - app/controllers/spree/users_controller.rb + - app/controllers/spree/user_sessions_controller.rb - app/controllers/stripe/callbacks_controller.rb - app/controllers/user_confirmations_controller.rb - app/controllers/user_passwords_controller.rb @@ -368,18 +370,19 @@ Metrics/AbcSize: - app/helpers/checkout_helper.rb - app/helpers/i18n_helper.rb - app/helpers/order_cycles_helper.rb - - app/helpers/spree/admin/navigation_helper.rb - app/helpers/spree/admin/base_helper.rb + - app/helpers/spree/admin/navigation_helper.rb - app/helpers/spree/admin/zones_helper.rb - app/helpers/spree/orders_helper.rb - app/models/calculator/flat_percent_per_item.rb - app/models/column_preference.rb - - app/models/enterprise.rb - app/models/enterprise_group.rb + - app/models/enterprise.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/product_import/product_importer.rb - app/models/proxy_order.rb - app/models/spree/ability_decorator.rb - app/models/spree/calculator/default_tax_decorator.rb @@ -389,12 +392,13 @@ Metrics/AbcSize: - app/models/spree/payment_decorator.rb - app/models/spree/product_decorator.rb - app/models/spree/taxon_decorator.rb + - app/models/spree/tax_rate_decorator.rb - app/serializers/api/admin/enterprise_serializer.rb - - app/serializers/api/admin/order_cycle_serializer.rb - app/serializers/api/product_serializer.rb - app/serializers/api/variant_serializer.rb - app/services/cart_service.rb - app/services/create_order_cycle.rb + - app/services/order_cycle_form.rb - app/services/order_syncer.rb - engines/order_management/app/services/order_management/subscriptions/validator.rb - lib/active_merchant/billing/gateways/stripe_decorator.rb @@ -414,7 +418,6 @@ Metrics/AbcSize: - 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/rack_request_blocker.rb - lib/open_food_network/reports/line_items.rb - lib/open_food_network/sales_tax_report.rb - lib/open_food_network/users_and_enterprises_report.rb @@ -425,15 +428,17 @@ Metrics/AbcSize: - lib/spree/localized_number.rb - lib/stripe/account_connector.rb - lib/tasks/enterprises.rake + - lib/tasks/sample_data/order_factory.rb - lib/tasks/sample_data/product_factory.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_paypal_spec.rb + - spec/features/consumer/shopping/shopping_spec.rb - spec/features/consumer/shopping/variant_overrides_spec.rb - spec/models/enterprise_spec.rb - spec/models/product_importer_spec.rb - - spec/services/restart_checkout_spec.rb + - spec/services/order_checkout_restart_spec.rb - spec/support/performance_helper.rb Metrics/BlockLength: @@ -454,13 +459,14 @@ Metrics/BlockLength: Exclude: - lib/tasks/data.rake - spec/controllers/spree/admin/invoices_controller_spec.rb - - spec/factories.rb - spec/factories/enterprise_factory.rb - spec/factories/order_cycle_factory.rb - spec/factories/order_factory.rb - spec/factories/product_factory.rb + - spec/factories.rb - spec/factories/shipping_method_factory.rb - spec/factories/subscription_factory.rb + - spec/factories/user_factory.rb - spec/factories/variant_factory.rb - spec/features/consumer/shopping/embedded_shopfronts_spec.rb - spec/lib/open_food_network/group_buy_report_spec.rb @@ -480,14 +486,13 @@ Metrics/CyclomaticComplexity: - app/helpers/checkout_helper.rb - app/helpers/i18n_helper.rb - app/helpers/order_cycles_helper.rb - - app/helpers/spree/admin/navigation_helper.rb - app/helpers/spree/admin/base_helper.rb + - app/helpers/spree/admin/navigation_helper.rb - app/models/enterprise.rb - app/models/enterprise_relationship.rb - - app/models/product_import/entry_processor.rb - - app/models/product_import/entry_validator.rb - app/models/spree/ability_decorator.rb - app/models/spree/payment_decorator.rb + - app/models/spree/payment_method_decorator.rb - app/models/spree/product_decorator.rb - app/models/variant_override_set.rb - app/services/cart_service.rb @@ -512,8 +517,6 @@ Metrics/PerceivedComplexity: - app/helpers/order_cycles_helper.rb - app/helpers/spree/admin/navigation_helper.rb - app/models/enterprise_relationship.rb - - app/models/product_import/entry_processor.rb - - app/models/product_import/entry_validator.rb - app/models/spree/ability_decorator.rb - app/models/spree/order_decorator.rb - app/models/spree/product_decorator.rb @@ -529,6 +532,7 @@ Metrics/PerceivedComplexity: Metrics/MethodLength: Max: 10 Exclude: + - app/controllers/admin/contents_controller.rb - app/controllers/admin/customers_controller.rb - app/controllers/admin/enterprise_fees_controller.rb - app/controllers/admin/enterprises_controller.rb @@ -540,12 +544,11 @@ Metrics/MethodLength: - app/controllers/api/shipments_controller.rb - app/controllers/api/taxons_controller.rb - app/controllers/api/variants_controller.rb - - app/controllers/base_controller.rb - app/controllers/cart_controller.rb - app/controllers/shop_controller.rb - app/controllers/spree/admin/image_settings_controller.rb - - app/controllers/spree/admin/orders/customer_details_controller.rb - app/controllers/spree/admin/orders_controller.rb + - app/controllers/spree/admin/orders/customer_details_controller.rb - app/controllers/spree/admin/payment_methods_controller.rb - app/controllers/spree/admin/payments_controller.rb - app/controllers/spree/admin/products_controller.rb @@ -564,9 +567,9 @@ Metrics/MethodLength: - app/controllers/user_registrations_controller.rb - app/helpers/checkout_helper.rb - app/helpers/order_cycles_helper.rb - - app/helpers/spree/admin/navigation_helper.rb - app/helpers/spree/admin/base_helper.rb - - app/jobs/subscription_placement_job.rb + - app/helpers/spree/admin/navigation_helper.rb + - app/mailers/producer_mailer.rb - app/models/column_preference.rb - app/models/enterprise.rb - app/models/enterprise_relationship.rb @@ -585,6 +588,7 @@ Metrics/MethodLength: - app/serializers/api/admin/order_cycle_serializer.rb - app/serializers/api/cached_enterprise_serializer.rb - app/services/order_cycle_form.rb + - app/services/permitted_attributes/checkout.rb - engines/order_management/app/services/order_management/reports/enterprise_fee_summary/scope.rb - lib/active_merchant/billing/gateways/stripe_payment_intents.rb - lib/discourse/single_sign_on.rb @@ -616,6 +620,9 @@ Metrics/MethodLength: - lib/spree/core/controller_helpers/respond_with_decorator.rb - lib/spree/localized_number.rb - lib/stripe/profile_storer.rb + - lib/tasks/data/truncate_data.rb + - lib/tasks/sample_data/group_factory.rb + - lib/tasks/sample_data/order_factory.rb - lib/tasks/sample_data/product_factory.rb - spec/features/consumer/shopping/checkout_paypal_spec.rb - spec/features/consumer/shopping/variant_overrides_spec.rb @@ -627,16 +634,16 @@ Metrics/ClassLength: Exclude: - app/controllers/admin/enterprises_controller.rb - app/controllers/admin/order_cycles_controller.rb + - app/controllers/admin/schedules_controller.rb - app/controllers/admin/subscriptions_controller.rb - app/controllers/api/products_controller.rb - app/controllers/application_controller.rb - app/controllers/checkout_controller.rb - - app/controllers/spree/admin/base_controller.rb - app/controllers/spree/admin/orders_controller.rb - app/controllers/spree/admin/payment_methods_controller.rb + - app/controllers/spree/admin/products_controller.rb - app/controllers/spree/admin/reports_controller.rb - app/controllers/spree/admin/resource_controller.rb - - app/controllers/spree/admin/products_controller.rb - app/controllers/spree/admin/users_controller.rb - app/controllers/spree/orders_controller.rb - app/models/enterprise.rb @@ -667,8 +674,8 @@ Metrics/ModuleLength: Exclude: - app/helpers/admin/injection_helper.rb - app/helpers/injection_helper.rb - - app/helpers/spree/admin/navigation_helper.rb - app/helpers/spree/admin/base_helper.rb + - app/helpers/spree/admin/navigation_helper.rb - engines/order_management/spec/services/order_management/subscriptions/estimator_spec.rb - engines/order_management/spec/services/order_management/subscriptions/form_spec.rb - engines/order_management/spec/services/order_management/subscriptions/proxy_order_syncer_spec.rb @@ -692,6 +699,7 @@ Metrics/ModuleLength: - spec/lib/open_food_network/products_and_inventory_report_spec.rb - spec/lib/open_food_network/scope_variant_to_hub_spec.rb - spec/lib/open_food_network/tag_rule_applicator_spec.rb + - spec/lib/open_food_network/user_balance_calculator_spec.rb - spec/lib/open_food_network/users_and_enterprises_report_spec.rb - spec/models/spree/ability_spec.rb - spec/models/spree/adjustment_spec.rb diff --git a/.rubocop_styleguide.yml b/.rubocop_styleguide.yml index eb73f8a511..f592e4eb31 100644 --- a/.rubocop_styleguide.yml +++ b/.rubocop_styleguide.yml @@ -40,6 +40,12 @@ Layout/MultilineMethodCallIndentation: Layout/LineLength: Max: 100 +Lint/RaiseException: + Enabled: true + +Lint/StructNewOverride: + Enabled: true + ## TEMPORARY/CONTESTED SETTINGS # # These are still to be decided upon, but recommended for inclusion by diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 1c482dbc82..753aaee48e 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,114 +1,24 @@ # This configuration was generated by # `rubocop --auto-gen-config --exclude-limit 1400` -# on 2020-02-22 11:23:29 +0000 using RuboCop version 0.80.0. +# on 2020-06-22 13:28:10 +0100 using RuboCop version 0.81.0. # The point is for the user to remove these configuration records # one by one as the offenses are removed from the code base. # Note that changes in the inspected code, or installation of new # versions of RuboCop, may require this file to be generated again. -# Offense count: 6 -# Cop supports --auto-correct. -Layout/EmptyLineAfterGuardClause: - Exclude: - - 'lib/open_food_network/bulk_coop_report.rb' - - 'lib/open_food_network/orders_and_fulfillments_report.rb' - - 'lib/open_food_network/packing_report.rb' - -# Offense count: 2 -# Cop supports --auto-correct. -Layout/EmptyLines: - Exclude: - - 'app/models/spree/adjustment_decorator.rb' - - 'spec/features/admin/order_cycles_spec.rb' - -# Offense count: 1 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle. -# SupportedStyles: empty_lines, no_empty_lines -Layout/EmptyLinesAroundBlockBody: - Exclude: - - 'spec/controllers/api/orders_controller_spec.rb' - -# Offense count: 1 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyleAlignWith, AutoCorrect, Severity. -# SupportedStylesAlignWith: keyword, variable, start_of_line -Layout/EndAlignment: - Exclude: - - 'lib/open_food_network/permalink_generator.rb' - -# Offense count: 2 -# Cop supports --auto-correct. -# Configuration parameters: AllowMultipleStyles, EnforcedHashRocketStyle, EnforcedColonStyle, EnforcedLastArgumentHashStyle. -# SupportedHashRocketStyles: key, separator, table -# SupportedColonStyles: key, separator, table -# SupportedLastArgumentHashStyles: always_inspect, always_ignore, ignore_implicit, ignore_explicit -Layout/HashAlignment: - Exclude: - - 'spec/lib/open_food_network/orders_and_fulfillments_report/customer_totals_report_spec.rb' - -# Offense count: 8 -# Cop supports --auto-correct. -# Configuration parameters: AllowDoxygenCommentStyle, AllowGemfileRubyComment. -Layout/LeadingCommentSpace: - Exclude: - - 'Gemfile' - - 'app/helpers/application_helper.rb' - - 'app/models/enterprise.rb' - -# Offense count: 3 +# Offense count: 139 # Cop supports --auto-correct. # Configuration parameters: AutoCorrect, AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns. # URISchemes: http, https Layout/LineLength: - Max: 115 - -# Offense count: 1 -# Cop supports --auto-correct. -Layout/SpaceAfterColon: - Exclude: - - 'lib/open_food_network/order_cycle_form_applicator.rb' + Max: 268 # Offense count: 2 -# Cop supports --auto-correct. -# Configuration parameters: AllowForAlignment, EnforcedStyleForExponentOperator. -# SupportedStylesForExponentOperator: space, no_space -Layout/SpaceAroundOperators: - Exclude: - - 'app/services/cart_service.rb' - - 'spec/support/cancan_helper.rb' - -# Offense count: 2 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBraces. -# SupportedStyles: space, no_space, compact -# SupportedStylesForEmptyBraces: space, no_space -Layout/SpaceInsideHashLiteralBraces: - Exclude: - - 'spec/controllers/checkout_controller_spec.rb' - -# Offense count: 2 -Lint/AmbiguousOperator: - Exclude: - - 'spec/controllers/api/enterprise_fees_controller_spec.rb' - - 'spec/controllers/spree/admin/payments_controller_spec.rb' - -# Offense count: 2 -Lint/Debugger: - Exclude: - - 'app/services/order_factory.rb' - -# Offense count: 1 -Lint/DuplicateHashKey: - Exclude: - - 'spec/models/calculator/weight_spec.rb' - -# Offense count: 4 Lint/DuplicateMethods: Exclude: - 'lib/discourse/single_sign_on.rb' -# Offense count: 10 +# Offense count: 9 Lint/IneffectiveAccessModifier: Exclude: - 'app/models/column_preference.rb' @@ -117,31 +27,6 @@ Lint/IneffectiveAccessModifier: - 'lib/open_food_network/feature_toggle.rb' - 'spec/lib/open_food_network/reports/report_spec.rb' -# Offense count: 1 -Lint/InterpolationCheck: - Exclude: - - 'spec/features/consumer/shopping/embedded_groups_spec.rb' - -# Offense count: 3 -# Cop supports --auto-correct. -Lint/NonDeterministicRequireOrder: - Exclude: - - 'engines/order_management/spec/spec_helper.rb' - - 'engines/web/spec/spec_helper.rb' - - 'spec/spec_helper.rb' - -# Offense count: 3 -Lint/ShadowingOuterLocalVariable: - Exclude: - - 'app/models/model_set.rb' - - 'spec/models/model_set_spec.rb' - -# Offense count: 2 -# Configuration parameters: AllowKeywordBlockArguments. -Lint/UnderscorePrefixedVariableName: - Exclude: - - 'spec/support/cancan_helper.rb' - # Offense count: 5 # Configuration parameters: ContextCreatingMethods, MethodCreatingMethods. Lint/UselessAccessModifier: @@ -152,21 +37,10 @@ Lint/UselessAccessModifier: - 'lib/open_food_network/reports/bulk_coop_report.rb' - 'spec/lib/open_food_network/reports/report_spec.rb' -# Offense count: 1 -Lint/UselessAssignment: - Exclude: - - 'spec/**/*' - - 'app/models/enterprise.rb' - -# Offense count: 1 -# Configuration parameters: CheckForMethodsWithNoSideEffects. -Lint/Void: - Exclude: - - 'app/serializers/api/enterprise_serializer.rb' - -# Offense count: 1 +# Offense count: 6 +# Configuration parameters: IgnoredMethods. Metrics/AbcSize: - Max: 16 + Max: 37 # Offense count: 1 # Configuration parameters: CountComments, ExcludedMethods. @@ -174,6 +48,21 @@ Metrics/AbcSize: Metrics/BlockLength: Max: 27 +# Offense count: 1 +# Configuration parameters: CountComments. +Metrics/ClassLength: + Max: 101 + +# Offense count: 1 +# Configuration parameters: IgnoredMethods. +Metrics/CyclomaticComplexity: + Max: 7 + +# Offense count: 6 +# Configuration parameters: CountComments, ExcludedMethods. +Metrics/MethodLength: + Max: 20 + # Offense count: 1 # Configuration parameters: CountComments. Metrics/ModuleLength: @@ -195,26 +84,15 @@ Naming/HeredocDelimiterNaming: Exclude: - 'app/models/content_configuration.rb' -# Offense count: 3 +# Offense count: 4 # Configuration parameters: EnforcedStyleForLeadingUnderscores. # SupportedStylesForLeadingUnderscores: disallowed, required, optional Naming/MemoizedInstanceVariableName: Exclude: + - 'app/mailers/producer_mailer.rb' - 'lib/open_food_network/address_finder.rb' -# Offense count: 7 -# Configuration parameters: MinNameLength, AllowNamesEndingInNumbers, AllowedNames, ForbiddenNames. -# AllowedNames: io, id, to, by, on, in, at, ip, db, os, pp -Naming/MethodParameterName: - Exclude: - - 'app/helpers/spree/base_helper_decorator.rb' - - 'engines/order_management/app/services/order_management/subscriptions/validator.rb' - - 'lib/open_food_network/reports/bulk_coop_report.rb' - - 'lib/open_food_network/xero_invoices_report.rb' - - 'spec/lib/open_food_network/reports/report_spec.rb' - - 'spec/mailers/producer_mailer_spec.rb' - -# Offense count: 22 +# Offense count: 19 # Configuration parameters: NamePrefix, ForbiddenPrefixes, AllowedMethods, MethodDefinitionMacros. # NamePrefix: is_, has_, have_ # ForbiddenPrefixes: is_, has_, have_ @@ -232,7 +110,6 @@ Naming/PredicateName: - 'app/models/spree/order_decorator.rb' - 'app/models/spree/payment_method_decorator.rb' - 'app/models/spree/preferences/file_configuration.rb' - - 'app/models/spree/product_decorator.rb' - 'app/models/spree/shipping_method_decorator.rb' - 'lib/open_food_network/customers_report.rb' - 'lib/open_food_network/order_cycle_management_report.rb' @@ -240,143 +117,6 @@ Naming/PredicateName: - 'lib/open_food_network/packing_report.rb' - 'lib/tasks/data.rake' -# Offense count: 154 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, Include. -# SupportedStyles: action, filter -# Include: app/controllers/**/*.rb -Rails/ActionFilter: - Exclude: - - 'app/controllers/admin/column_preferences_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/enterprises_controller.rb' - - 'app/controllers/admin/order_cycles_controller.rb' - - 'app/controllers/admin/producer_properties_controller.rb' - - 'app/controllers/admin/product_import_controller.rb' - - 'app/controllers/admin/schedules_controller.rb' - - 'app/controllers/admin/stripe_connect_settings_controller.rb' - - 'app/controllers/admin/subscription_line_items_controller.rb' - - 'app/controllers/admin/subscriptions_controller.rb' - - 'app/controllers/admin/variant_overrides_controller.rb' - - 'app/controllers/api/base_controller.rb' - - 'app/controllers/api/enterprise_attachment_controller.rb' - - 'app/controllers/api/enterprises_controller.rb' - - 'app/controllers/api/shipments_controller.rb' - - 'app/controllers/api/variants_controller.rb' - - 'app/controllers/application_controller.rb' - - 'app/controllers/base_controller.rb' - - 'app/controllers/cart_controller.rb' - - 'app/controllers/checkout_controller.rb' - - 'app/controllers/discourse_sso_controller.rb' - - 'app/controllers/enterprises_controller.rb' - - 'app/controllers/home_controller.rb' - - 'app/controllers/line_items_controller.rb' - - 'app/controllers/producers_controller.rb' - - 'app/controllers/registration_controller.rb' - - 'app/controllers/shop_controller.rb' - - 'app/controllers/shops_controller.rb' - - 'app/controllers/spree/admin/adjustments_controller.rb' - - 'app/controllers/spree/admin/base_controller.rb' - - 'app/controllers/spree/admin/images_controller.rb' - - 'app/controllers/spree/admin/mail_methods_controller.rb' - - 'app/controllers/spree/admin/orders/customer_details_controller.rb' - - 'app/controllers/spree/admin/orders_controller.rb' - - 'app/controllers/spree/admin/payment_methods_controller.rb' - - 'app/controllers/spree/admin/payments_controller.rb' - - 'app/controllers/spree/admin/product_properties_controller.rb' - - 'app/controllers/spree/admin/products_controller.rb' - - 'app/controllers/spree/admin/reports/enterprise_fee_summaries_controller.rb' - - 'app/controllers/spree/admin/reports_controller.rb' - - 'app/controllers/spree/admin/resource_controller.rb' - - 'app/controllers/spree/admin/search_controller.rb' - - 'app/controllers/spree/admin/shipping_methods_controller.rb' - - 'app/controllers/spree/admin/states_controller.rb' - - 'app/controllers/spree/admin/tax_rates_controller.rb' - - 'app/controllers/spree/admin/users_controller.rb' - - 'app/controllers/spree/admin/zones_controller.rb' - - 'app/controllers/spree/orders_controller.rb' - - 'app/controllers/spree/store_controller.rb' - - 'app/controllers/spree/user_registrations_controller.rb' - - 'app/controllers/spree/user_sessions_controller.rb' - - 'app/controllers/spree/users_controller.rb' - - 'app/controllers/stripe/webhooks_controller.rb' - - 'app/controllers/user_passwords_controller.rb' - - 'app/controllers/user_registrations_controller.rb' - -# Offense count: 192 -# Cop supports --auto-correct. -Rails/ActiveRecordAliases: - Exclude: - - 'app/controllers/admin/bulk_line_items_controller.rb' - - 'app/controllers/admin/enterprises_controller.rb' - - 'app/controllers/admin/subscriptions_controller.rb' - - 'app/controllers/api/customers_controller.rb' - - 'app/controllers/api/enterprise_attachment_controller.rb' - - 'app/controllers/api/enterprises_controller.rb' - - 'app/controllers/api/product_images_controller.rb' - - 'app/controllers/api/products_controller.rb' - - 'app/controllers/api/shipments_controller.rb' - - 'app/controllers/api/taxons_controller.rb' - - 'app/controllers/api/variants_controller.rb' - - 'app/controllers/checkout_controller.rb' - - 'app/controllers/spree/admin/orders/customer_details_controller.rb' - - 'app/controllers/spree/admin/orders_controller.rb' - - 'app/controllers/spree/admin/payment_methods_controller.rb' - - 'app/controllers/spree/admin/resource_controller.rb' - - 'app/controllers/spree/admin/taxons_controller.rb' - - 'app/controllers/spree/admin/users_controller.rb' - - 'app/controllers/spree/credit_cards_controller.rb' - - 'app/controllers/spree/orders_controller.rb' - - 'app/controllers/spree/users_controller.rb' - - 'app/helpers/i18n_helper.rb' - - 'app/jobs/subscription_placement_job.rb' - - 'app/models/spree/adjustment_decorator.rb' - - 'app/models/spree/line_item_decorator.rb' - - 'app/models/spree/product_set.rb' - - 'app/services/line_item_syncer.rb' - - 'app/services/order_factory.rb' - - 'app/services/order_syncer.rb' - - 'app/services/user_default_address_setter.rb' - - 'lib/open_food_network/order_cycle_form_applicator.rb' - - 'lib/open_food_network/subscription_payment_updater.rb' - - 'lib/stripe/profile_storer.rb' - - 'spec/controllers/admin/proxy_orders_controller_spec.rb' - - 'spec/controllers/admin/subscriptions_controller_spec.rb' - - 'spec/controllers/api/orders_controller_spec.rb' - - 'spec/controllers/line_items_controller_spec.rb' - - 'spec/controllers/spree/admin/payment_methods_controller_spec.rb' - - 'spec/controllers/spree/orders_controller_spec.rb' - - 'spec/features/admin/order_cycles_spec.rb' - - 'spec/features/admin/subscriptions_spec.rb' - - 'spec/features/admin/variant_overrides_spec.rb' - - 'spec/features/admin/variants_spec.rb' - - 'spec/features/consumer/account_spec.rb' - - 'spec/features/consumer/registration_spec.rb' - - 'spec/features/consumer/shopping/cart_spec.rb' - - 'spec/features/consumer/shopping/orders_spec.rb' - - 'spec/features/consumer/shopping/shopping_spec.rb' - - 'spec/jobs/subscription_confirm_job_spec.rb' - - 'spec/jobs/subscription_placement_job_spec.rb' - - 'spec/lib/open_food_network/proxy_order_syncer_spec.rb' - - 'spec/models/customer_spec.rb' - - 'spec/models/enterprise_caching_spec.rb' - - 'spec/models/exchange_spec.rb' - - 'spec/models/order_cycle_spec.rb' - - 'spec/models/producer_property_spec.rb' - - 'spec/models/proxy_order_spec.rb' - - 'spec/models/spree/adjustment_spec.rb' - - 'spec/models/spree/credit_card_spec.rb' - - 'spec/models/spree/line_item_spec.rb' - - 'spec/models/spree/order_spec.rb' - - 'spec/models/spree/product_spec.rb' - - 'spec/models/spree/user_spec.rb' - - 'spec/models/spree/variant_spec.rb' - - 'spec/requests/checkout/stripe_connect_spec.rb' - - 'spec/services/order_syncer_spec.rb' - - 'spec/services/subscription_estimator_spec.rb' - # Offense count: 1 # Configuration parameters: EnforcedStyle. # SupportedStyles: strict, flexible @@ -384,17 +124,13 @@ Rails/Date: Exclude: - 'app/models/order_cycle.rb' -# Offense count: 5 +# Offense count: 1 # Cop supports --auto-correct. # Configuration parameters: Whitelist. # Whitelist: find_by_sql Rails/DynamicFindBy: Exclude: - 'app/controllers/spree/admin/orders/customer_details_controller.rb' - - 'app/controllers/spree/admin/orders_controller.rb' - - 'app/controllers/spree/admin/payments_controller.rb' - - 'app/controllers/spree/admin/products_controller.rb' - - 'spec/support/request/web_helper.rb' # Offense count: 16 # Configuration parameters: EnforcedStyle. @@ -426,19 +162,25 @@ Rails/FindBy: - 'app/models/product_import/spreadsheet_data.rb' - 'app/models/spree/user.rb' -# Offense count: 7 +# Offense count: 1 +# Cop supports --auto-correct. +# Configuration parameters: Include. +# Include: app/models/**/*.rb +Rails/FindEach: + Exclude: + - 'app/models/spree/order_decorator.rb' + +# Offense count: 5 # Configuration parameters: Include. # Include: app/models/**/*.rb Rails/HasAndBelongsToMany: Exclude: - 'app/models/enterprise.rb' - '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' -# Offense count: 24 +# Offense count: 25 # Configuration parameters: Include. # Include: app/models/**/*.rb Rails/HasManyOrHasOneDependent: @@ -449,13 +191,13 @@ Rails/HasManyOrHasOneDependent: - 'app/models/spree/adjustment_decorator.rb' - 'app/models/spree/order_decorator.rb' - 'app/models/spree/payment_method_decorator.rb' - - 'app/models/spree/property_decorator.rb' + - 'app/models/spree/property.rb' - 'app/models/spree/shipping_method_decorator.rb' - 'app/models/spree/user.rb' - 'app/models/spree/variant_decorator.rb' - 'app/models/subscription.rb' -# Offense count: 83 +# Offense count: 84 # Configuration parameters: Include. # Include: app/helpers/**/*.rb Rails/HelperInstanceVariable: @@ -471,12 +213,30 @@ Rails/HelperInstanceVariable: - 'app/helpers/spree/admin/orders_helper.rb' - 'app/helpers/spree/orders_helper.rb' -# Offense count: 1 +# Offense count: 35 # Configuration parameters: Include. -# Include: app/**/*.rb, config/**/*.rb, db/**/*.rb, lib/**/*.rb -Rails/Output: +# Include: app/controllers/**/*.rb +Rails/LexicallyScopedActionFilter: Exclude: - - 'app/services/order_factory.rb' + - 'app/controllers/admin/enterprise_groups_controller.rb' + - 'app/controllers/admin/enterprises_controller.rb' + - 'app/controllers/admin/order_cycles_controller.rb' + - 'app/controllers/admin/producer_properties_controller.rb' + - 'app/controllers/admin/product_import_controller.rb' + - 'app/controllers/admin/schedules_controller.rb' + - 'app/controllers/admin/subscriptions_controller.rb' + - 'app/controllers/registration_controller.rb' + - 'app/controllers/spree/admin/adjustments_controller.rb' + - 'app/controllers/spree/admin/payment_methods_controller.rb' + - 'app/controllers/spree/admin/payments_controller.rb' + - 'app/controllers/spree/admin/product_properties_controller.rb' + - 'app/controllers/spree/admin/products_controller.rb' + - 'app/controllers/spree/admin/search_controller.rb' + - 'app/controllers/spree/admin/shipping_methods_controller.rb' + - 'app/controllers/spree/admin/users_controller.rb' + - 'app/controllers/spree/admin/zones_controller.rb' + - 'app/controllers/spree/users_controller.rb' + - 'app/controllers/user_passwords_controller.rb' # Offense count: 12 Rails/OutputSafety: @@ -490,13 +250,14 @@ Rails/OutputSafety: - 'app/helpers/spree/reports_helper.rb' - 'app/serializers/api/product_serializer.rb' - 'lib/spree/money_decorator.rb' - - 'spec/features/admin/orders_spec.rb' + - 'spec/features/admin/order_print_ticket_spec.rb' # Offense count: 2 # Configuration parameters: Include. # Include: **/Rakefile, **/*.rake Rails/RakeEnvironment: Exclude: + - 'lib/capistrano/tasks/**/*.rake' - 'lib/tasks/specs.rake' # Offense count: 9 @@ -507,7 +268,7 @@ Rails/ReflectionClassName: - 'app/models/enterprise_role.rb' - 'app/models/subscription.rb' -# Offense count: 213 +# Offense count: 227 # Configuration parameters: Blacklist, Whitelist. # Blacklist: decrement!, decrement_counter, increment!, increment_counter, toggle!, touch, update_all, update_attribute, update_column, update_columns, update_counters Rails/SkipsModelValidations: @@ -527,10 +288,13 @@ Rails/SkipsModelValidations: - 'app/models/spree/credit_card_decorator.rb' - 'app/models/spree/order_decorator.rb' - 'app/models/spree/payment_decorator.rb' + - 'app/models/spree/shipping_method_decorator.rb' - 'app/models/subscription.rb' - 'app/models/variant_override.rb' - 'app/services/order_factory.rb' + - 'engines/order_management/spec/performance/order_management/subscriptions/proxy_order_syncer_spec.rb' - 'engines/order_management/spec/services/order_management/reports/enterprise_fee_summary/report_service_spec.rb' + - 'engines/order_management/spec/services/order_management/subscriptions/stripe_payment_setup_spec.rb' - 'lib/tasks/data/anonymize_data.rake' - 'lib/tasks/sample_data/product_factory.rb' - 'lib/tasks/users.rake' @@ -552,9 +316,12 @@ Rails/SkipsModelValidations: - 'spec/features/admin/bulk_order_management_spec.rb' - 'spec/features/admin/bulk_product_update_spec.rb' - 'spec/features/admin/configuration/tax_rates_spec.rb' - - 'spec/features/admin/order_cycles_spec.rb' - - 'spec/features/admin/orders_spec.rb' + - 'spec/features/admin/order_cycles/complex_editing_spec.rb' + - 'spec/features/admin/order_cycles/simple_spec.rb' + - 'spec/features/admin/order_spec.rb' + - 'spec/features/admin/payments_spec.rb' - 'spec/features/admin/reports_spec.rb' + - 'spec/features/consumer/caching/shops_caching_spec.rb' - 'spec/features/consumer/shopping/checkout_spec.rb' - 'spec/features/consumer/shopping/products_spec.rb' - 'spec/features/consumer/shopping/shopping_spec.rb' @@ -566,7 +333,7 @@ Rails/SkipsModelValidations: - 'spec/lib/open_food_network/permissions_spec.rb' - 'spec/lib/open_food_network/products_and_inventory_report_spec.rb' - 'spec/lib/open_food_network/scope_variant_to_hub_spec.rb' - - 'spec/lib/open_food_network/subscription_payment_updater_spec.rb' + - 'spec/lib/stripe/credit_card_cloner_spec.rb' - 'spec/models/calculator/weight_spec.rb' - 'spec/models/concerns/variant_stock_spec.rb' - 'spec/models/enterprise_relationship_spec.rb' @@ -574,18 +341,27 @@ Rails/SkipsModelValidations: - '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/variant_spec.rb' - 'spec/models/tag_rule/discount_order_spec.rb' - - 'spec/performance/proxy_order_syncer_spec.rb' - 'spec/serializers/api/admin/subscription_line_item_serializer_spec.rb' + - 'spec/services/cache_service_spec.rb' + - 'spec/services/order_cart_reset_spec.rb' + - 'spec/services/order_checkout_restart_spec.rb' - 'spec/services/order_cycle_distributed_products_spec.rb' - 'spec/services/order_factory_spec.rb' - 'spec/services/order_syncer_spec.rb' - 'spec/services/product_tag_rules_filterer_spec.rb' - 'spec/services/products_renderer_spec.rb' - - 'spec/services/restart_checkout_spec.rb' - 'spec/support/request/shop_workflow.rb' + - 'spec/views/spree/shared/_order_details.html.haml_spec.rb' + +# Offense count: 2 +# Configuration parameters: Include. +# Include: app/models/**/*.rb +Rails/UniqueValidationWithoutIndex: + Exclude: + - 'app/models/customer.rb' + - 'app/models/exchange.rb' # Offense count: 1 # Configuration parameters: Environments. @@ -600,13 +376,12 @@ Style/CaseEquality: - 'app/helpers/angular_form_helper.rb' - 'spec/models/spree/payment_spec.rb' -# Offense count: 76 +# Offense count: 75 # Cop supports --auto-correct. # Configuration parameters: AutoCorrect, EnforcedStyle. # SupportedStyles: nested, compact Style/ClassAndModuleChildren: Exclude: - - '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' @@ -685,29 +460,15 @@ Style/ClassVars: Exclude: - 'lib/open_food_network/rack_request_blocker.rb' -# Offense count: 1 -Style/CommentedKeyword: - Exclude: - - 'app/controllers/application_controller.rb' - -# Offense count: 1 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, SingleLineConditionsOnly, IncludeTernaryExpressions. -# SupportedStyles: assign_to_condition, assign_inside_condition -Style/ConditionalAssignment: - Exclude: - - 'app/controllers/api/taxons_controller.rb' - -# Offense count: 6 +# Offense count: 4 # Configuration parameters: EnforcedStyle. # SupportedStyles: annotated, template, unannotated Style/FormatStringToken: Exclude: - - 'app/helpers/order_cycles_helper.rb' - 'lib/open_food_network/sales_tax_report.rb' - 'spec/features/admin/bulk_order_management_spec.rb' -# Offense count: 920 +# Offense count: 874 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyle. # SupportedStyles: always, always_true, never @@ -742,7 +503,6 @@ Style/FrozenStringLiteralComment: - 'app/controllers/admin/variant_overrides_controller.rb' - 'app/controllers/api/base_controller.rb' - 'app/controllers/api/customers_controller.rb' - - 'app/controllers/api/enterprise_attachment_controller.rb' - 'app/controllers/api/enterprise_fees_controller.rb' - 'app/controllers/api/enterprises_controller.rb' - 'app/controllers/api/logos_controller.rb' @@ -786,7 +546,6 @@ Style/FrozenStringLiteralComment: - 'app/controllers/spree/admin/product_properties_controller.rb' - 'app/controllers/spree/admin/products_controller.rb' - 'app/controllers/spree/admin/properties_controller.rb' - - 'app/controllers/spree/admin/reports/enterprise_fee_summaries_controller.rb' - 'app/controllers/spree/admin/reports_controller.rb' - 'app/controllers/spree/admin/resource_controller.rb' - 'app/controllers/spree/admin/return_authorizations_controller.rb' @@ -847,7 +606,6 @@ Style/FrozenStringLiteralComment: - 'app/helpers/spree/api/api_helpers.rb' - 'app/helpers/spree/base_helper_decorator.rb' - 'app/helpers/spree/orders_helper.rb' - - 'app/helpers/spree/products_helper_decorator.rb' - 'app/helpers/spree/reports_helper.rb' - 'app/helpers/spree_currency_helper.rb' - 'app/jobs/confirm_order_job.rb' @@ -935,7 +693,6 @@ Style/FrozenStringLiteralComment: - 'app/models/spree/gateway_decorator.rb' - 'app/models/spree/image_decorator.rb' - 'app/models/spree/line_item_decorator.rb' - - 'app/models/spree/money_decorator.rb' - 'app/models/spree/option_type_decorator.rb' - 'app/models/spree/order_decorator.rb' - 'app/models/spree/payment_decorator.rb' @@ -947,9 +704,7 @@ Style/FrozenStringLiteralComment: - 'app/models/spree/product_property_decorator.rb' - 'app/models/spree/product_set.rb' - 'app/models/spree/property.rb' - - 'app/models/spree/property_decorator.rb' - 'app/models/spree/shipment_decorator.rb' - - 'app/models/spree/shipping_category_decorator.rb' - 'app/models/spree/shipping_method_decorator.rb' - 'app/models/spree/stock/availability_validator_decorator.rb' - 'app/models/spree/stock_location_decorator.rb' @@ -1072,8 +827,6 @@ Style/FrozenStringLiteralComment: - 'app/services/permissions/order.rb' - 'app/services/product_tag_rules_filterer.rb' - 'app/services/products_renderer.rb' - - 'app/services/reset_order_service.rb' - - 'app/services/restart_checkout.rb' - 'app/services/search_orders.rb' - 'app/services/tax_rate_finder.rb' - 'app/services/upload_sanitizer.rb' @@ -1112,7 +865,6 @@ Style/FrozenStringLiteralComment: - 'engines/order_management/lib/order_management/engine.rb' - 'engines/order_management/lib/order_management/version.rb' - 'engines/order_management/order_management.gemspec' - - 'engines/order_management/spec/performance/order_management/subscriptions/proxy_order_syncer_spec.rb' - 'engines/order_management/spec/services/order_management/reports/enterprise_fee_summary/authorizer_spec.rb' - 'engines/order_management/spec/services/order_management/reports/enterprise_fee_summary/parameters_spec.rb' - 'engines/order_management/spec/services/order_management/reports/enterprise_fee_summary/permissions_spec.rb' @@ -1120,7 +872,6 @@ Style/FrozenStringLiteralComment: - 'engines/order_management/spec/services/order_management/reports/enterprise_fee_summary/renderers/html_renderer_spec.rb' - 'engines/order_management/spec/services/order_management/reports/enterprise_fee_summary/report_data/enterprise_fee_type_total_spec.rb' - 'engines/order_management/spec/services/order_management/reports/enterprise_fee_summary/report_service_spec.rb' - - 'engines/order_management/spec/spec_helper.rb' - 'engines/web/app/controllers/web/angular_templates_controller.rb' - 'engines/web/app/controllers/web/api/cookies_consent_controller.rb' - 'engines/web/app/controllers/web/application_controller.rb' @@ -1131,7 +882,6 @@ Style/FrozenStringLiteralComment: - 'engines/web/lib/web/engine.rb' - 'engines/web/lib/web/version.rb' - 'engines/web/spec/helpers/cookies_policy_helper_spec.rb' - - 'engines/web/spec/spec_helper.rb' - 'engines/web/web.gemspec' - 'lib/discourse/single_sign_on.rb' - 'lib/open_food_network/address_finder.rb' @@ -1184,7 +934,6 @@ Style/FrozenStringLiteralComment: - 'lib/open_food_network/scope_variant_to_hub.rb' - 'lib/open_food_network/scope_variants_for_search.rb' - 'lib/open_food_network/spree_api_key_loader.rb' - - 'lib/open_food_network/subscription_payment_updater.rb' - 'lib/open_food_network/tag_rule_applicator.rb' - 'lib/open_food_network/user_balance_calculator.rb' - 'lib/open_food_network/users_and_enterprises_report.rb' @@ -1204,7 +953,6 @@ Style/FrozenStringLiteralComment: - 'lib/stripe/webhook_handler.rb' - 'lib/tasks/data.rake' - 'lib/tasks/data/anonymize_data.rake' - - 'lib/tasks/data/truncate_data.rake' - 'lib/tasks/enterprises.rake' - 'lib/tasks/karma.rake' - 'lib/tasks/missing_payments.rake' @@ -1245,7 +993,6 @@ Style/FrozenStringLiteralComment: - 'spec/controllers/api/customers_controller_spec.rb' - 'spec/controllers/api/enterprise_fees_controller_spec.rb' - 'spec/controllers/api/enterprises_controller_spec.rb' - - 'spec/controllers/api/exchange_products_controller_spec.rb' - 'spec/controllers/api/logos_controller_spec.rb' - 'spec/controllers/api/order_cycles_controller_spec.rb' - 'spec/controllers/api/orders_controller_spec.rb' @@ -1278,7 +1025,6 @@ Style/FrozenStringLiteralComment: - 'spec/controllers/spree/admin/payment_methods_controller_spec.rb' - 'spec/controllers/spree/admin/payments_controller_spec.rb' - 'spec/controllers/spree/admin/products_controller_spec.rb' - - 'spec/controllers/spree/admin/reports/enterprise_fee_summaries_controller_spec.rb' - 'spec/controllers/spree/admin/reports_controller_spec.rb' - 'spec/controllers/spree/admin/search_controller_spec.rb' - 'spec/controllers/spree/admin/shipping_methods_controller_spec.rb' @@ -1333,14 +1079,11 @@ Style/FrozenStringLiteralComment: - 'spec/features/admin/external_services_spec.rb' - 'spec/features/admin/image_settings_spec.rb' - 'spec/features/admin/multilingual_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/payments_spec.rb' - 'spec/features/admin/product_import_spec.rb' - 'spec/features/admin/products_spec.rb' - - 'spec/features/admin/reports/enterprise_fee_summaries_spec.rb' - 'spec/features/admin/reports/packing_report_spec.rb' - 'spec/features/admin/reports_spec.rb' - 'spec/features/admin/schedules_spec.rb' @@ -1356,7 +1099,6 @@ Style/FrozenStringLiteralComment: - 'spec/features/consumer/account_spec.rb' - 'spec/features/consumer/authentication_spec.rb' - 'spec/features/consumer/confirm_invitation_spec.rb' - - 'spec/features/consumer/cookies_spec.rb' - 'spec/features/consumer/footer_links_spec.rb' - 'spec/features/consumer/groups_spec.rb' - 'spec/features/consumer/multilingual_spec.rb' @@ -1384,7 +1126,6 @@ Style/FrozenStringLiteralComment: - 'spec/helpers/injection_helper_spec.rb' - 'spec/helpers/navigation_helper_spec.rb' - 'spec/helpers/order_cycles_helper_spec.rb' - - 'spec/helpers/products_helper_spec.rb' - 'spec/helpers/serializer_helper_spec.rb' - 'spec/helpers/shared_helper_spec.rb' - 'spec/helpers/shop_helper_spec.rb' @@ -1431,7 +1172,6 @@ Style/FrozenStringLiteralComment: - 'spec/lib/open_food_network/sales_tax_report_spec.rb' - 'spec/lib/open_food_network/scope_variant_to_hub_spec.rb' - 'spec/lib/open_food_network/scope_variants_to_search_spec.rb' - - 'spec/lib/open_food_network/subscription_payment_updater_spec.rb' - 'spec/lib/open_food_network/tag_rule_applicator_spec.rb' - 'spec/lib/open_food_network/user_balance_calculator_spec.rb' - 'spec/lib/open_food_network/users_and_enterprises_report_spec.rb' @@ -1465,7 +1205,6 @@ Style/FrozenStringLiteralComment: - 'spec/models/model_set_spec.rb' - 'spec/models/order_cycle_spec.rb' - 'spec/models/order_updater_spec.rb' - - 'spec/models/producer_property_spec.rb' - 'spec/models/product_import/entry_processor_spec.rb' - 'spec/models/product_import/inventory_reset_strategy_spec.rb' - 'spec/models/product_import/reset_absent_spec.rb' @@ -1494,7 +1233,6 @@ Style/FrozenStringLiteralComment: - 'spec/models/spree/price_spec.rb' - 'spec/models/spree/product_set_spec.rb' - 'spec/models/spree/product_spec.rb' - - 'spec/models/spree/property_spec.rb' - 'spec/models/spree/shipment_spec.rb' - 'spec/models/spree/shipping_method_spec.rb' - 'spec/models/spree/stock/availability_validator_spec.rb' @@ -1563,8 +1301,6 @@ Style/FrozenStringLiteralComment: - 'spec/services/permissions/order_spec.rb' - 'spec/services/product_tag_rules_filterer_spec.rb' - 'spec/services/products_renderer_spec.rb' - - 'spec/services/reset_order_service_spec.rb' - - 'spec/services/restart_checkout_spec.rb' - 'spec/services/search_orders_spec.rb' - 'spec/services/tax_rate_finder_spec.rb' - 'spec/services/upload_sanitizer_spec.rb' @@ -1573,7 +1309,6 @@ Style/FrozenStringLiteralComment: - 'spec/support/ability_helper.rb' - 'spec/support/api_helper.rb' - 'spec/support/cancan_helper.rb' - - 'spec/support/controller_hacks.rb' - 'spec/support/controller_helper.rb' - 'spec/support/delayed_job_helper.rb' - 'spec/support/downloads_helper.rb' @@ -1614,18 +1349,19 @@ Style/FrozenStringLiteralComment: - 'spec/views/spree/admin/orders/edit.html.haml_spec.rb' - 'spec/views/spree/admin/orders/index.html.haml_spec.rb' -# Offense count: 50 +# Offense count: 51 # 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/api/shipments_controller.rb' - 'app/controllers/application_controller.rb' - - 'app/controllers/base_controller.rb' - 'app/controllers/checkout_controller.rb' - 'app/controllers/home_controller.rb' - 'app/controllers/spree/orders_controller.rb' + - 'app/controllers/spree/paypal_controller_decorator.rb' - 'app/models/enterprise.rb' - 'app/models/enterprise_group.rb' - 'app/models/producer_property.rb' @@ -1645,48 +1381,19 @@ Style/GuardClause: - 'spec/support/request/distribution_helper.rb' - 'spec/support/request/shop_workflow.rb' -# Offense count: 3 -# Configuration parameters: AllowIfModifier. -Style/IfInsideElse: - Exclude: - - 'app/controllers/admin/column_preferences_controller.rb' - - 'app/controllers/admin/variant_overrides_controller.rb' - - 'app/controllers/api/taxons_controller.rb' - -# Offense count: 1 -# Cop supports --auto-correct. -# Configuration parameters: InverseMethods, InverseBlocks. -Style/InverseMethods: - Exclude: - - 'lib/open_food_network/reports/line_items.rb' - # Offense count: 1 Style/MissingRespondToMissing: Exclude: - 'app/helpers/application_helper.rb' -# Offense count: 5 +# Offense count: 4 Style/MixinUsage: Exclude: - 'lib/open_food_network/orders_and_fulfillments_report.rb' - - 'spec/features/admin/orders_spec.rb' - 'spec/lib/open_food_network/bulk_coop_report_spec.rb' - 'spec/lib/open_food_network/order_cycle_management_report_spec.rb' - 'spec/lib/open_food_network/packing_report_spec.rb' -# Offense count: 1 -Style/MultipleComparison: - Exclude: - - 'spec/models/product_importer_spec.rb' - -# Offense count: 1 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle. -# SupportedStyles: both, prefix, postfix -Style/NegatedUnless: - Exclude: - - 'app/services/cart_service.rb' - # Offense count: 41 # Cop supports --auto-correct. # Configuration parameters: AutoCorrect, EnforcedStyle, IgnoredMethods. @@ -1719,25 +1426,7 @@ Style/NumericPredicate: - 'lib/spree/money_decorator.rb' - 'lib/tasks/sample_data.rake' -# Offense count: 16 -# Cop supports --auto-correct. -# Configuration parameters: ConvertCodeThatCanStartToReturnNil, AllowedMethods. -# AllowedMethods: present?, blank?, presence, try, try! -Style/SafeNavigation: - Exclude: - - 'app/controllers/spree/admin/payments_controller.rb' - - 'app/controllers/spree/credit_cards_controller.rb' - - 'app/controllers/spree/orders_controller.rb' - - 'app/helpers/i18n_helper.rb' - - 'app/helpers/shop_helper.rb' - - 'app/models/producer_property.rb' - - 'app/models/product_import/entry_validator.rb' - - 'app/models/product_import/product_importer.rb' - - 'app/models/proxy_order.rb' - - 'lib/discourse/single_sign_on.rb' - - 'spec/factories.rb' - -# Offense count: 232 +# Offense count: 231 Style/Send: Exclude: - 'app/models/spree/shipping_method_decorator.rb' @@ -1757,7 +1446,6 @@ Style/Send: - 'spec/lib/open_food_network/permissions_spec.rb' - 'spec/lib/open_food_network/products_and_inventory_report_spec.rb' - 'spec/lib/open_food_network/sales_tax_report_spec.rb' - - 'spec/lib/open_food_network/subscription_payment_updater_spec.rb' - 'spec/lib/open_food_network/tag_rule_applicator_spec.rb' - 'spec/lib/open_food_network/xero_invoices_report_spec.rb' - 'spec/lib/stripe/webhook_handler_spec.rb' diff --git a/Gemfile b/Gemfile index a9d3c89755..a389ced8fb 100644 --- a/Gemfile +++ b/Gemfile @@ -33,7 +33,7 @@ gem 'httparty', '~> 0.18' # Used to check alerts in spree_core, this is not used gem 'json', '>= 1.7.7' gem 'money', '5.1.1' gem 'paranoia', '~> 2.0' -gem 'ransack', '~> 1.2.3' +gem 'ransack', '~> 1.8.10' gem 'state_machine', '1.2.0' gem 'stringex', '~> 1.5.1' @@ -79,7 +79,7 @@ gem 'actionpack-action_caching' # Once Rails is updated to 5.x we should bump directly to 0.10.x gem "active_model_serializers", "0.8.4" gem 'activerecord-session_store' -gem 'acts-as-taggable-on', '~> 3.4' +gem 'acts-as-taggable-on', '~> 4.0' gem 'angularjs-file-upload-rails', '~> 2.4.1' gem 'custom_error_message', github: 'jeremydurham/custom-err-msg' gem 'dalli' diff --git a/Gemfile.lock b/Gemfile.lock index a4dbce97bc..4df2b827b1 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -124,8 +124,8 @@ GEM multi_json (~> 1.3) thread_safe (~> 0.1) tzinfo (~> 0.3.37) - acts-as-taggable-on (3.5.0) - activerecord (>= 3.2, < 5) + acts-as-taggable-on (4.0.0) + activerecord (>= 4.0) acts_as_list (0.2.0) activerecord (>= 3.0) addressable (2.7.0) @@ -406,7 +406,7 @@ GEM fuubar (2.5.0) rspec-core (~> 3.0) ruby-progressbar (~> 1.4) - geocoder (1.5.2) + geocoder (1.6.3) get_process_mem (0.2.5) ffi (~> 1.0) gmaps4rails (2.1.2) @@ -499,8 +499,6 @@ GEM paypal-sdk-merchant (1.106.1) paypal-sdk-core (~> 0.2.3) pg (0.21.0) - polyamorous (1.0.0) - activerecord (>= 3.0) power_assert (1.2.0) pry (0.12.2) coderay (~> 1.1.0) @@ -539,12 +537,11 @@ GEM rainbow (3.0.0) raindrops (0.19.1) rake (13.0.1) - ransack (1.2.3) - actionpack (>= 3.0) - activerecord (>= 3.0) - activesupport (>= 3.0) + ransack (1.8.10) + actionpack (>= 3.0, < 5.2) + activerecord (>= 3.0, < 5.2) + activesupport (>= 3.0, < 5.2) i18n - polyamorous (~> 1.0.0) rb-fsevent (0.10.3) rb-inotify (0.10.1) ffi (~> 1.0) @@ -696,7 +693,7 @@ DEPENDENCIES activerecord-import activerecord-postgresql-adapter activerecord-session_store - acts-as-taggable-on (~> 3.4) + acts-as-taggable-on (~> 4.0) acts_as_list (= 0.2.0) andand angular-rails-templates (~> 0.3.0) @@ -772,7 +769,7 @@ DEPENDENCIES rails (~> 4.0.13) rails-i18n (~> 4.0) rails_safe_tasks (~> 1.0) - ransack (~> 1.2.3) + ransack (~> 1.8.10) redcarpet roadie-rails (~> 1.3.0) roo (~> 2.8.3) diff --git a/app/assets/stylesheets/darkswarm/cart-page.css.scss b/app/assets/stylesheets/darkswarm/cart-page.css.scss index b2b17fa0bb..7f715f4aab 100644 --- a/app/assets/stylesheets/darkswarm/cart-page.css.scss +++ b/app/assets/stylesheets/darkswarm/cart-page.css.scss @@ -10,6 +10,8 @@ } #cart-detail { + width: 100%; + .cart-item-delete, .bought-item-delete { a { diff --git a/app/controllers/admin/bulk_line_items_controller.rb b/app/controllers/admin/bulk_line_items_controller.rb index 5437be7c45..99e3b68998 100644 --- a/app/controllers/admin/bulk_line_items_controller.rb +++ b/app/controllers/admin/bulk_line_items_controller.rb @@ -28,7 +28,7 @@ module Admin # See https://github.com/rails/rails/blob/3-2-stable/activerecord/lib/active_record/locking/pessimistic.rb#L69 # and https://www.postgresql.org/docs/current/static/sql-select.html#SQL-FOR-UPDATE-SHARE order.with_lock do - if @line_item.update_attributes(line_item_params) + if @line_item.update(line_item_params) order.update_distribution_charge! render nothing: true, status: :no_content # No Content, does not trigger ng resource auto-update else diff --git a/app/controllers/admin/column_preferences_controller.rb b/app/controllers/admin/column_preferences_controller.rb index ee21a14131..4951a2ce5d 100644 --- a/app/controllers/admin/column_preferences_controller.rb +++ b/app/controllers/admin/column_preferences_controller.rb @@ -1,6 +1,6 @@ module Admin class ColumnPreferencesController < ResourceController - before_filter :load_collection, only: [:bulk_update] + before_action :load_collection, only: [:bulk_update] respond_to :json @@ -9,12 +9,10 @@ module Admin if @cp_set.save render json: @cp_set.collection, each_serializer: Api::Admin::ColumnPreferenceSerializer + elsif @cp_set.errors.present? + render json: { errors: @cp_set.errors }, status: :bad_request else - if @cp_set.errors.present? - render json: { errors: @cp_set.errors }, status: :bad_request - else - render nothing: true, status: :internal_server_error - end + render nothing: true, status: :internal_server_error end end diff --git a/app/controllers/admin/customers_controller.rb b/app/controllers/admin/customers_controller.rb index 667c62aad0..c79811ab2e 100644 --- a/app/controllers/admin/customers_controller.rb +++ b/app/controllers/admin/customers_controller.rb @@ -2,7 +2,7 @@ require 'open_food_network/address_finder' module Admin class CustomersController < ResourceController - before_filter :load_managed_shops, only: :index, if: :html_request? + before_action :load_managed_shops, only: :index, if: :html_request? respond_to :json respond_override update: { json: { diff --git a/app/controllers/admin/enterprise_fees_controller.rb b/app/controllers/admin/enterprise_fees_controller.rb index 47372fa5f4..56187450a7 100644 --- a/app/controllers/admin/enterprise_fees_controller.rb +++ b/app/controllers/admin/enterprise_fees_controller.rb @@ -1,7 +1,7 @@ module Admin class EnterpriseFeesController < ResourceController - before_filter :load_enterprise_fee_set, only: :index - before_filter :load_data + before_action :load_enterprise_fee_set, only: :index + before_action :load_data def index @include_calculators = params[:include_calculators].present? diff --git a/app/controllers/admin/enterprise_groups_controller.rb b/app/controllers/admin/enterprise_groups_controller.rb index 471d56d5ab..9d5bc6c665 100644 --- a/app/controllers/admin/enterprise_groups_controller.rb +++ b/app/controllers/admin/enterprise_groups_controller.rb @@ -1,7 +1,7 @@ module Admin class EnterpriseGroupsController < ResourceController - before_filter :load_data, except: :index - before_filter :load_object_data, only: [:new, :edit, :create, :update] + before_action :load_data, except: :index + before_action :load_object_data, only: [:new, :edit, :create, :update] def index @enterprise_groups = @enterprise_groups.managed_by(spree_current_user) diff --git a/app/controllers/admin/enterprises_controller.rb b/app/controllers/admin/enterprises_controller.rb index 8b8901e211..333926a728 100644 --- a/app/controllers/admin/enterprises_controller.rb +++ b/app/controllers/admin/enterprises_controller.rb @@ -5,22 +5,22 @@ require 'open_food_network/order_cycle_permissions' module Admin class EnterprisesController < ResourceController # These need to run before #load_resource so that @object is initialised with sanitised values - prepend_before_filter :override_owner, only: :create - prepend_before_filter :override_sells, only: :create + prepend_before_action :override_owner, only: :create + prepend_before_action :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 :check_can_change_sells, only: :update - before_filter :check_can_change_bulk_sells, only: :bulk_update - before_filter :check_can_change_owner, only: :update - before_filter :check_can_change_bulk_owner, only: :bulk_update - before_filter :check_can_change_managers, only: :update - before_filter :strip_new_properties, only: [:create, :update] - before_filter :load_properties, only: [:edit, :update] - before_filter :setup_property, only: [:edit] + before_action :load_enterprise_set, only: :index + before_action :load_countries, except: [:index, :register, :check_permalink] + before_action :load_methods_and_fees, only: [:edit, :update] + before_action :load_groups, only: [:new, :edit, :update, :create] + before_action :load_taxons, only: [:new, :edit, :update, :create] + before_action :check_can_change_sells, only: :update + before_action :check_can_change_bulk_sells, only: :bulk_update + before_action :check_can_change_owner, only: :update + before_action :check_can_change_bulk_owner, only: :bulk_update + before_action :check_can_change_managers, only: :update + before_action :strip_new_properties, only: [:create, :update] + before_action :load_properties, only: [:edit, :update] + before_action :setup_property, only: [:edit] helper 'spree/products' include OrderCyclesHelper @@ -47,7 +47,7 @@ module Admin tag_rules_attributes = params[object_name].delete :tag_rules_attributes update_tag_rules(tag_rules_attributes) if tag_rules_attributes.present? update_enterprise_notifications - if @object.update_attributes(enterprise_params) + if @object.update(enterprise_params) invoke_callbacks(:update, :after) flash[:success] = flash_message_for(@object, :successfully_updated) respond_with(@object) do |format| @@ -71,7 +71,7 @@ module Admin attributes = { sells: params[:sells], visible: true } - if @enterprise.update_attributes(attributes) + if @enterprise.update(attributes) flash[:success] = I18n.t(:enterprise_register_success_notice, enterprise: @enterprise.name) redirect_to admin_dashboard_path else @@ -214,7 +214,7 @@ module Admin 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) + rule.update(attrs) end end end @@ -227,7 +227,7 @@ 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]) + rule.update(calculator_type: attrs[:calculator_type]) attrs[:calculator_attributes].merge!( id: rule.calculator.id ) end end diff --git a/app/controllers/admin/order_cycles_controller.rb b/app/controllers/admin/order_cycles_controller.rb index 8b488c8bda..4441403ef0 100644 --- a/app/controllers/admin/order_cycles_controller.rb +++ b/app/controllers/admin/order_cycles_controller.rb @@ -2,12 +2,12 @@ module Admin class OrderCyclesController < ResourceController include OrderCyclesHelper - prepend_before_filter :set_order_cycle_id, only: [:incoming, :outgoing] - before_filter :load_data_for_index, only: :index - before_filter :require_coordinator, only: :new - before_filter :remove_protected_attrs, only: [:update] - before_filter :require_order_cycle_set_params, only: [:bulk_update] - around_filter :protect_invalid_destroy, only: :destroy + prepend_before_action :set_order_cycle_id, only: [:incoming, :outgoing] + before_action :load_data_for_index, only: :index + before_action :require_coordinator, only: :new + before_action :remove_protected_attrs, only: [:update] + before_action :require_order_cycle_set_params, only: [:bulk_update] + around_action :protect_invalid_destroy, only: :destroy def index respond_to do |format| diff --git a/app/controllers/admin/producer_properties_controller.rb b/app/controllers/admin/producer_properties_controller.rb index f83911d6a4..2227d45a8f 100644 --- a/app/controllers/admin/producer_properties_controller.rb +++ b/app/controllers/admin/producer_properties_controller.rb @@ -1,8 +1,8 @@ module Admin class ProducerPropertiesController < ResourceController - before_filter :load_enterprise - before_filter :load_properties - before_filter :setup_property, only: [:index] + before_action :load_enterprise + before_action :load_properties + before_action :setup_property, only: [:index] private diff --git a/app/controllers/admin/product_import_controller.rb b/app/controllers/admin/product_import_controller.rb index f35c00a913..8a5b5834b9 100644 --- a/app/controllers/admin/product_import_controller.rb +++ b/app/controllers/admin/product_import_controller.rb @@ -2,7 +2,7 @@ require 'roo' module Admin class ProductImportController < Spree::Admin::BaseController - before_filter :validate_upload_presence, except: %i[index guide validate_data] + before_action :validate_upload_presence, except: %i[index guide validate_data] def index @product_categories = Spree::Taxon.order('name ASC').pluck(:name).uniq diff --git a/app/controllers/admin/schedules_controller.rb b/app/controllers/admin/schedules_controller.rb index 9532e4db9e..cdf6829e54 100644 --- a/app/controllers/admin/schedules_controller.rb +++ b/app/controllers/admin/schedules_controller.rb @@ -3,10 +3,10 @@ require 'order_management/subscriptions/proxy_order_syncer' module Admin class SchedulesController < ResourceController - before_filter :adapt_params, only: [:update] - before_filter :editable_order_cycle_ids_for_create, only: [:create] - before_filter :editable_order_cycle_ids_for_update, only: [:update] - before_filter :check_dependent_subscriptions, only: [:destroy] + before_action :adapt_params, only: [:update] + before_action :editable_order_cycle_ids_for_create, only: [:create] + before_action :editable_order_cycle_ids_for_update, only: [:update] + before_action :check_dependent_subscriptions, only: [:destroy] update.after :sync_subscriptions_for_update respond_to :json diff --git a/app/controllers/admin/stripe_connect_settings_controller.rb b/app/controllers/admin/stripe_connect_settings_controller.rb index bbe75b7806..6f54722fc0 100644 --- a/app/controllers/admin/stripe_connect_settings_controller.rb +++ b/app/controllers/admin/stripe_connect_settings_controller.rb @@ -4,7 +4,7 @@ module Admin class StripeConnectSettingsController < Spree::Admin::BaseController StripeConnectSettings = Struct.new(:stripe_connect_enabled) - before_filter :load_settings, only: [:edit] + before_action :load_settings, only: [:edit] def edit return @stripe_account = { status: :empty_api_key_error_html } if Stripe.api_key.blank? diff --git a/app/controllers/admin/subscription_line_items_controller.rb b/app/controllers/admin/subscription_line_items_controller.rb index c52cca1c3b..573cfec5f2 100644 --- a/app/controllers/admin/subscription_line_items_controller.rb +++ b/app/controllers/admin/subscription_line_items_controller.rb @@ -4,9 +4,9 @@ require 'open_food_network/scope_variant_to_hub' module Admin class SubscriptionLineItemsController < ResourceController - before_filter :load_build_context, only: [:build] - before_filter :ensure_shop, only: [:build] - before_filter :ensure_variant, only: [:build] + before_action :load_build_context, only: [:build] + before_action :ensure_shop, only: [:build] + before_action :ensure_variant, only: [:build] respond_to :json diff --git a/app/controllers/admin/subscriptions_controller.rb b/app/controllers/admin/subscriptions_controller.rb index 11163b6830..c2c45bcef3 100644 --- a/app/controllers/admin/subscriptions_controller.rb +++ b/app/controllers/admin/subscriptions_controller.rb @@ -2,12 +2,12 @@ require 'open_food_network/permissions' module Admin class SubscriptionsController < ResourceController - before_filter :load_shops, only: [:index] - before_filter :load_form_data, only: [:new, :edit] - before_filter :strip_banned_attrs, only: [:update] - before_filter :wrap_nested_attrs, only: [:create, :update] - before_filter :check_for_open_orders, only: [:cancel, :pause] - before_filter :check_for_canceled_orders, only: [:unpause] + before_action :load_shops, only: [:index] + before_action :load_form_data, only: [:new, :edit] + before_action :strip_banned_attrs, only: [:update] + before_action :wrap_nested_attrs, only: [:create, :update] + before_action :check_for_open_orders, only: [:cancel, :pause] + before_action :check_for_canceled_orders, only: [:unpause] respond_to :json def index @@ -52,7 +52,7 @@ module Admin @subscription.proxy_orders.placed_and_open.each(&:cancel) end - @subscription.update_attributes(paused_at: Time.zone.now) + @subscription.update(paused_at: Time.zone.now) render_as_json @subscription end diff --git a/app/controllers/admin/variant_overrides_controller.rb b/app/controllers/admin/variant_overrides_controller.rb index 31aff8ce8c..f32af6650f 100644 --- a/app/controllers/admin/variant_overrides_controller.rb +++ b/app/controllers/admin/variant_overrides_controller.rb @@ -5,9 +5,9 @@ module Admin include OpenFoodNetwork::SpreeApiKeyLoader include EnterprisesHelper - prepend_before_filter :load_data - before_filter :load_collection, only: [:bulk_update] - before_filter :load_spree_api_key, only: :index + prepend_before_action :load_data + before_action :load_collection, only: [:bulk_update] + before_action :load_spree_api_key, only: :index def index; end @@ -18,12 +18,10 @@ module Admin if @vo_set.save # Return saved VOs with IDs render json: @vo_set.collection, each_serializer: Api::Admin::VariantOverrideSerializer + elsif @vo_set.errors.present? + render json: { errors: @vo_set.errors }, status: :bad_request else - if @vo_set.errors.present? - render json: { errors: @vo_set.errors }, status: :bad_request - else - render nothing: true, status: :internal_server_error - end + render nothing: true, status: :internal_server_error end end diff --git a/app/controllers/api/base_controller.rb b/app/controllers/api/base_controller.rb index f591154d4c..344dd89174 100644 --- a/app/controllers/api/base_controller.rb +++ b/app/controllers/api/base_controller.rb @@ -11,9 +11,9 @@ module Api attr_accessor :current_api_user - before_filter :set_content_type - before_filter :authenticate_user - after_filter :set_jsonp_format + before_action :set_content_type + before_action :authenticate_user + after_action :set_jsonp_format rescue_from Exception, with: :error_during_processing rescue_from CanCan::AccessDenied, with: :unauthorized diff --git a/app/controllers/api/customers_controller.rb b/app/controllers/api/customers_controller.rb index 99c5834578..172d4580b8 100644 --- a/app/controllers/api/customers_controller.rb +++ b/app/controllers/api/customers_controller.rb @@ -11,7 +11,7 @@ module Api @customer = Customer.find(params[:id]) authorize! :update, @customer - if @customer.update_attributes(params[:customer]) + if @customer.update(params[:customer]) render json: @customer, serializer: CustomerSerializer, status: :ok else invalid_resource!(@customer) diff --git a/app/controllers/api/enterprise_attachment_controller.rb b/app/controllers/api/enterprise_attachment_controller.rb index 3f5f61e5dd..d9b619ab8e 100644 --- a/app/controllers/api/enterprise_attachment_controller.rb +++ b/app/controllers/api/enterprise_attachment_controller.rb @@ -7,14 +7,14 @@ module Api class MissingImplementationError < StandardError; end class UnknownEnterpriseAuthorizationActionError < StandardError; end - before_filter :load_enterprise + before_action :load_enterprise respond_to :json def destroy return respond_with_conflict(error: destroy_attachment_does_not_exist_error_message) unless @enterprise.public_send("#{attachment_name}?") - @enterprise.update_attributes!(attachment_name => nil) + @enterprise.update!(attachment_name => nil) render json: @enterprise, serializer: Admin::EnterpriseSerializer, spree_current_user: spree_current_user end diff --git a/app/controllers/api/enterprises_controller.rb b/app/controllers/api/enterprises_controller.rb index b4456c5ae4..5b8d2f2bc4 100644 --- a/app/controllers/api/enterprises_controller.rb +++ b/app/controllers/api/enterprises_controller.rb @@ -1,9 +1,9 @@ module Api class EnterprisesController < Api::BaseController - before_filter :override_owner, only: [:create, :update] - before_filter :check_type, only: :update - before_filter :override_sells, only: [:create, :update] - before_filter :override_visible, only: [:create, :update] + before_action :override_owner, only: [:create, :update] + before_action :check_type, only: :update + before_action :override_sells, only: [:create, :update] + before_action :override_visible, only: [:create, :update] respond_to :json def create @@ -25,7 +25,7 @@ module Api @enterprise = Enterprise.find_by(permalink: params[:id]) || Enterprise.find(params[:id]) authorize! :update, @enterprise - if @enterprise.update_attributes(params[:enterprise]) + if @enterprise.update(params[:enterprise]) render text: @enterprise.id, status: :ok else invalid_resource!(@enterprise) @@ -36,9 +36,9 @@ 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] ) + if params[:logo] && @enterprise.update( logo: params[:logo] ) render text: @enterprise.logo.url(:medium), status: :ok - elsif params[:promo] && @enterprise.update_attributes( promo_image: params[:promo] ) + elsif params[:promo] && @enterprise.update( promo_image: params[:promo] ) render text: @enterprise.promo_image.url(:medium), status: :ok else invalid_resource!(@enterprise) diff --git a/app/controllers/api/order_cycles_controller.rb b/app/controllers/api/order_cycles_controller.rb index 77689932e0..42c2df4d9a 100644 --- a/app/controllers/api/order_cycles_controller.rb +++ b/app/controllers/api/order_cycles_controller.rb @@ -4,7 +4,7 @@ module Api include ApiActionCaching skip_authorization_check - skip_before_filter :authenticate_user, :ensure_api_key, only: [:taxons, :properties] + skip_before_action :authenticate_user, :ensure_api_key, only: [:taxons, :properties] caches_action :taxons, :properties, expires_in: CacheService::FILTERS_EXPIRY, diff --git a/app/controllers/api/product_images_controller.rb b/app/controllers/api/product_images_controller.rb index e7551aeea7..e688a03e6e 100644 --- a/app/controllers/api/product_images_controller.rb +++ b/app/controllers/api/product_images_controller.rb @@ -11,7 +11,7 @@ module Api render json: @image, serializer: ImageSerializer, status: :created else @image = @product.images.first - @image.update_attributes(attachment: params[:file]) + @image.update(attachment: params[:file]) render json: @image, serializer: ImageSerializer, status: :ok end end diff --git a/app/controllers/api/products_controller.rb b/app/controllers/api/products_controller.rb index 49246bc624..bc99830dcd 100644 --- a/app/controllers/api/products_controller.rb +++ b/app/controllers/api/products_controller.rb @@ -32,7 +32,7 @@ module Api def update authorize! :update, Spree::Product @product = find_product(params[:id]) - if @product.update_attributes(params[:product]) + if @product.update(params[:product]) render json: @product, serializer: Api::Admin::ProductSerializer, status: :ok else invalid_resource!(@product) diff --git a/app/controllers/api/shipments_controller.rb b/app/controllers/api/shipments_controller.rb index d7623da0c7..99f03bef7a 100644 --- a/app/controllers/api/shipments_controller.rb +++ b/app/controllers/api/shipments_controller.rb @@ -4,8 +4,8 @@ module Api class ShipmentsController < Api::BaseController respond_to :json - before_filter :find_order - before_filter :find_and_update_shipment, only: [:ship, :ready, :add, :remove] + before_action :find_order + before_action :find_and_update_shipment, only: [:ship, :ready, :add, :remove] def create variant = scoped_variant(params[:variant_id]) @@ -30,7 +30,7 @@ module Api @shipment.adjustment.open end - @shipment.update_attributes(params[:shipment]) + @shipment.update(params[:shipment]) if unlock == 'yes' @shipment.adjustment.close @@ -88,7 +88,7 @@ module Api def find_and_update_shipment @shipment = @order.shipments.find_by!(number: params[:id]) - @shipment.update_attributes(params[:shipment]) + @shipment.update(params[:shipment]) @shipment.reload end diff --git a/app/controllers/api/shops_controller.rb b/app/controllers/api/shops_controller.rb index 66740c5cbd..48ed28e47a 100644 --- a/app/controllers/api/shops_controller.rb +++ b/app/controllers/api/shops_controller.rb @@ -6,7 +6,7 @@ module Api skip_authorization_check only: [:show, :closed_shops] def show - enterprise = Enterprise.find_by_id(params[:id]) + enterprise = Enterprise.find_by(id: params[:id]) render text: Api::EnterpriseShopfrontSerializer.new(enterprise).to_json, status: :ok end diff --git a/app/controllers/api/taxons_controller.rb b/app/controllers/api/taxons_controller.rb index 68d9a6fdd8..f6693fbaee 100644 --- a/app/controllers/api/taxons_controller.rb +++ b/app/controllers/api/taxons_controller.rb @@ -5,15 +5,13 @@ module Api skip_authorization_check only: [:index, :show, :jstree] def index - if taxonomy - @taxons = taxonomy.root.children - else - if params[:ids] - @taxons = Spree::Taxon.where(id: params[:ids].split(",")) - else - @taxons = Spree::Taxon.ransack(params[:q]).result - end - end + @taxons = if taxonomy + taxonomy.root.children + elsif params[:ids] + Spree::Taxon.where(id: params[:ids].split(",")) + else + Spree::Taxon.ransack(params[:q]).result + end render json: @taxons, each_serializer: Api::TaxonSerializer end @@ -44,7 +42,7 @@ module Api def update authorize! :update, Spree::Taxon - if taxon.update_attributes(params[:taxon]) + if taxon.update(params[:taxon]) render json: taxon, serializer: Api::TaxonSerializer, status: :ok else invalid_resource!(taxon) diff --git a/app/controllers/api/variants_controller.rb b/app/controllers/api/variants_controller.rb index f0e31e0035..af1f41d7b0 100644 --- a/app/controllers/api/variants_controller.rb +++ b/app/controllers/api/variants_controller.rb @@ -3,7 +3,7 @@ module Api respond_to :json skip_authorization_check only: [:index, :show] - before_filter :product + before_action :product def index @variants = scope.includes(option_values: :option_type).ransack(params[:q]).result @@ -28,7 +28,7 @@ module Api def update authorize! :update, Spree::Variant @variant = scope.find(params[:id]) - if @variant.update_attributes(params[:variant]) + if @variant.update(params[:variant]) render json: @variant, serializer: Api::VariantSerializer, status: :ok else invalid_resource!(@product) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 5e2777feac..17585a7237 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -4,8 +4,8 @@ require_dependency 'spree/authentication_helpers' class ApplicationController < ActionController::Base protect_from_forgery - prepend_before_filter :restrict_iframes - before_filter :set_cache_headers # prevent cart emptying via cache when using back button #1213 + prepend_before_action :restrict_iframes + before_action :set_cache_headers # prevent cart emptying via cache when using back button #1213 include EnterprisesHelper include Spree::AuthenticationHelpers @@ -99,8 +99,7 @@ class ApplicationController < ActionController::Base if current_distributor_closed? current_order.empty! current_order.set_distribution! nil, nil - flash[:info] = "The hub you have selected is temporarily closed for orders. "\ - "Please try again later." + flash[:info] = I18n.t('order_cycles_closed_for_hub') redirect_to main_app.root_url end end @@ -117,7 +116,7 @@ class ApplicationController < ActionController::Base session[:expired_order_cycle_id] = current_order_cycle.id current_order.empty! current_order.set_order_cycle! nil - flash[:info] = "The order cycle you've selected has just closed. Please try again!" + flash[:info] = I18n.t('order_cycle_closed') redirect_to main_app.root_url end end @@ -134,7 +133,8 @@ class ApplicationController < ActionController::Base nil end - def set_cache_headers # https://jacopretorius.net/2014/01/force-page-to-reload-on-browser-back-in-rails.html + # See https://jacopretorius.net/2014/01/force-page-to-reload-on-browser-back-in-rails.html + def set_cache_headers response.headers["Cache-Control"] = "no-cache, no-store, max-age=0, must-revalidate" response.headers["Pragma"] = "no-cache" response.headers["Expires"] = "Fri, 01 Jan 1990 00:00:00 GMT" diff --git a/app/controllers/base_controller.rb b/app/controllers/base_controller.rb index fdbe51634d..6cf878a077 100644 --- a/app/controllers/base_controller.rb +++ b/app/controllers/base_controller.rb @@ -14,8 +14,8 @@ class BaseController < ApplicationController helper 'spree/base' - before_filter :set_locale - before_filter :check_order_cycle_expiry + before_action :set_locale + before_action :check_order_cycle_expiry private diff --git a/app/controllers/cart_controller.rb b/app/controllers/cart_controller.rb index b2cf8c04b7..997573899c 100644 --- a/app/controllers/cart_controller.rb +++ b/app/controllers/cart_controller.rb @@ -1,7 +1,7 @@ require 'spree/core/controller_helpers/order_decorator' class CartController < BaseController - before_filter :check_authorization + before_action :check_authorization def populate order = current_order(true) diff --git a/app/controllers/checkout_controller.rb b/app/controllers/checkout_controller.rb index ac3f63e60d..8616f4f6ad 100644 --- a/app/controllers/checkout_controller.rb +++ b/app/controllers/checkout_controller.rb @@ -13,22 +13,22 @@ class CheckoutController < Spree::StoreController # We need pessimistic locking to avoid race conditions. # Otherwise we fail on duplicate indexes or end up with negative stock. - prepend_around_filter CurrentOrderLocker, only: :update + prepend_around_action CurrentOrderLocker, only: :update - prepend_before_filter :check_hub_ready_for_checkout - prepend_before_filter :check_order_cycle_expiry - prepend_before_filter :require_order_cycle - prepend_before_filter :require_distributor_chosen + prepend_before_action :check_hub_ready_for_checkout + prepend_before_action :check_order_cycle_expiry + prepend_before_action :require_order_cycle + prepend_before_action :require_distributor_chosen - before_filter :load_order + before_action :load_order - before_filter :ensure_order_not_completed - before_filter :ensure_checkout_allowed - before_filter :ensure_sufficient_stock_lines + before_action :ensure_order_not_completed + before_action :ensure_checkout_allowed + before_action :ensure_sufficient_stock_lines - before_filter :associate_user - before_filter :check_authorization - before_filter :enable_embedded_shopfront + before_action :associate_user + before_action :check_authorization + before_action :enable_embedded_shopfront helper 'spree/orders' @@ -45,7 +45,7 @@ class CheckoutController < Spree::StoreController def update params_adapter = Checkout::FormDataAdapter.new(permitted_params, @order, spree_current_user) - return update_failed unless @order.update_attributes(params_adapter.params[:order]) + return update_failed unless @order.update(params_adapter.params[:order]) fire_event('spree.checkout.update') @@ -91,6 +91,7 @@ class CheckoutController < Spree::StoreController redirect_to(main_app.shop_path) && return if redirect_to_shop? redirect_to_cart_path && return unless valid_order_line_items? + before_address setup_for_current_state end diff --git a/app/controllers/discourse_sso_controller.rb b/app/controllers/discourse_sso_controller.rb index 17bf6a02e2..bd4abd052c 100644 --- a/app/controllers/discourse_sso_controller.rb +++ b/app/controllers/discourse_sso_controller.rb @@ -4,7 +4,7 @@ class DiscourseSsoController < ApplicationController include SharedHelper include DiscourseHelper - before_filter :require_config + before_action :require_config def login if require_activation? diff --git a/app/controllers/enterprises_controller.rb b/app/controllers/enterprises_controller.rb index 98fe17f0a7..6d640b5d7b 100644 --- a/app/controllers/enterprises_controller.rb +++ b/app/controllers/enterprises_controller.rb @@ -7,10 +7,10 @@ class EnterprisesController < BaseController include SerializerHelper # These prepended filters are in the reverse order of execution - prepend_before_filter :set_order_cycles, :require_distributor_chosen, :reset_order, only: :shop + prepend_before_action :set_order_cycles, :require_distributor_chosen, :reset_order, only: :shop - before_filter :clean_permalink, only: :check_permalink - before_filter :enable_embedded_shopfront + before_action :clean_permalink, only: :check_permalink + before_action :enable_embedded_shopfront respond_to :js, only: :permalink_checker diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb index afde45d3bd..c585b63839 100644 --- a/app/controllers/home_controller.rb +++ b/app/controllers/home_controller.rb @@ -1,7 +1,7 @@ class HomeController < BaseController layout 'darkswarm' - before_filter :enable_embedded_shopfront + before_action :enable_embedded_shopfront def index if ContentConfig.home_show_stats diff --git a/app/controllers/line_items_controller.rb b/app/controllers/line_items_controller.rb index 219b836ab4..28b8d4a324 100644 --- a/app/controllers/line_items_controller.rb +++ b/app/controllers/line_items_controller.rb @@ -1,7 +1,7 @@ class LineItemsController < BaseController respond_to :json - before_filter :load_line_item, only: :destroy + before_action :load_line_item, only: :destroy def bought respond_with bought_items, each_serializer: Api::LineItemSerializer diff --git a/app/controllers/producers_controller.rb b/app/controllers/producers_controller.rb index a5f4752c49..108143e5e3 100644 --- a/app/controllers/producers_controller.rb +++ b/app/controllers/producers_controller.rb @@ -1,7 +1,7 @@ class ProducersController < BaseController layout 'darkswarm' - before_filter :enable_embedded_shopfront + before_action :enable_embedded_shopfront def index @enterprises = Enterprise diff --git a/app/controllers/registration_controller.rb b/app/controllers/registration_controller.rb index 5a21d28a44..71e621f077 100644 --- a/app/controllers/registration_controller.rb +++ b/app/controllers/registration_controller.rb @@ -2,8 +2,8 @@ require 'open_food_network/spree_api_key_loader' class RegistrationController < BaseController include OpenFoodNetwork::SpreeApiKeyLoader - before_filter :load_spree_api_key, only: [:index] - before_filter :check_user, except: :authenticate + before_action :load_spree_api_key, only: [:index] + before_action :check_user, except: :authenticate layout 'registration' def index diff --git a/app/controllers/shop_controller.rb b/app/controllers/shop_controller.rb index 7aa5e4e796..c5f90a2856 100644 --- a/app/controllers/shop_controller.rb +++ b/app/controllers/shop_controller.rb @@ -1,7 +1,7 @@ class ShopController < BaseController layout "darkswarm" - before_filter :require_distributor_chosen, :set_order_cycles, except: :changeable_orders_alert - before_filter :enable_embedded_shopfront + before_action :require_distributor_chosen, :set_order_cycles, except: :changeable_orders_alert + before_action :enable_embedded_shopfront def show redirect_to main_app.enterprise_shop_path(current_distributor) diff --git a/app/controllers/shops_controller.rb b/app/controllers/shops_controller.rb index b57c6f5063..d644a5010f 100644 --- a/app/controllers/shops_controller.rb +++ b/app/controllers/shops_controller.rb @@ -1,7 +1,7 @@ class ShopsController < BaseController layout 'darkswarm' - before_filter :enable_embedded_shopfront + before_action :enable_embedded_shopfront def index @enterprises = ShopsListService.new.open_shops diff --git a/app/controllers/spree/admin/adjustments_controller.rb b/app/controllers/spree/admin/adjustments_controller.rb index dc9596d242..b0301aff0f 100644 --- a/app/controllers/spree/admin/adjustments_controller.rb +++ b/app/controllers/spree/admin/adjustments_controller.rb @@ -4,9 +4,9 @@ module Spree belongs_to 'spree/order', find_by: :number destroy.after :reload_order - prepend_before_filter :set_included_tax, only: [:create, :update] - before_filter :set_default_tax_rate, only: :edit - before_filter :enable_updates, only: :update + prepend_before_action :set_included_tax, only: [:create, :update] + before_action :set_default_tax_rate, only: :edit + before_action :enable_updates, only: :update private diff --git a/app/controllers/spree/admin/base_controller.rb b/app/controllers/spree/admin/base_controller.rb index ed0c5cffbb..7ce02d4a38 100644 --- a/app/controllers/spree/admin/base_controller.rb +++ b/app/controllers/spree/admin/base_controller.rb @@ -8,9 +8,9 @@ module Spree include I18nHelper - before_filter :authorize_admin - before_filter :set_locale - before_filter :warn_invalid_order_cycles, if: :html_request? + before_action :authorize_admin + before_action :set_locale + before_action :warn_invalid_order_cycles, if: :html_request? # Warn the user when they have an active order cycle with hubs that are not ready # for checkout (ie. does not have valid shipping and payment methods). diff --git a/app/controllers/spree/admin/images_controller.rb b/app/controllers/spree/admin/images_controller.rb index 168f01466d..8f47fe3576 100644 --- a/app/controllers/spree/admin/images_controller.rb +++ b/app/controllers/spree/admin/images_controller.rb @@ -6,7 +6,7 @@ module Spree # See here https://github.com/spree/spree/commit/334a011d2b8e16355e4ae77ae07cd93f7cbc8fd1 belongs_to 'spree/product', find_by: :permalink - before_filter :load_data + before_action :load_data create.before :set_viewable update.before :set_viewable diff --git a/app/controllers/spree/admin/mail_methods_controller.rb b/app/controllers/spree/admin/mail_methods_controller.rb index a21e3afe7d..aba6ad239f 100644 --- a/app/controllers/spree/admin/mail_methods_controller.rb +++ b/app/controllers/spree/admin/mail_methods_controller.rb @@ -1,7 +1,7 @@ module Spree module Admin class MailMethodsController < Spree::Admin::BaseController - after_filter :initialize_mail_settings + after_action :initialize_mail_settings def update params.each do |name, value| diff --git a/app/controllers/spree/admin/orders/customer_details_controller.rb b/app/controllers/spree/admin/orders/customer_details_controller.rb index 7503e42833..82c0c2347e 100644 --- a/app/controllers/spree/admin/orders/customer_details_controller.rb +++ b/app/controllers/spree/admin/orders/customer_details_controller.rb @@ -2,9 +2,9 @@ module Spree module Admin module Orders class CustomerDetailsController < Spree::Admin::BaseController - before_filter :load_order - before_filter :check_authorization - before_filter :set_guest_checkout_status, only: :update + before_action :load_order + before_action :check_authorization + before_action :set_guest_checkout_status, only: :update def show edit @@ -18,7 +18,7 @@ module Spree end def update - if @order.update_attributes(order_params) + if @order.update(order_params) if params[:guest_checkout] == "false" @order.associate_user!(Spree.user_class.find_by(email: @order.email)) end diff --git a/app/controllers/spree/admin/orders_controller.rb b/app/controllers/spree/admin/orders_controller.rb index 9625ebe29d..22715108e9 100644 --- a/app/controllers/spree/admin/orders_controller.rb +++ b/app/controllers/spree/admin/orders_controller.rb @@ -7,21 +7,21 @@ module Spree include OpenFoodNetwork::SpreeApiKeyLoader helper CheckoutHelper - before_filter :load_order, only: [:edit, :update, :fire, :resend, + before_action :load_order, only: [:edit, :update, :fire, :resend, :invoice, :print, :print_ticket] - before_filter :load_distribution_choices, only: [:new, :edit, :update] + before_action :load_distribution_choices, only: [:new, :edit, :update] # Ensure that the distributor is set for an order when - before_filter :ensure_distribution, only: :new + before_action :ensure_distribution, only: :new # After updating an order, the fees should be updated as well # Currently, adding or deleting line items does not trigger updating the # 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_action :update_distribution_charge, only: :update - before_filter :require_distributor_abn, only: :invoice + before_action :require_distributor_abn, only: :invoice respond_to :html, :json @@ -44,7 +44,7 @@ module Spree end def update - unless @order.update_attributes(order_params) && @order.line_items.present? + unless @order.update(order_params) && @order.line_items.present? if @order.line_items.empty? @order.errors.add(:line_items, Spree.t('errors.messages.blank')) end @@ -117,7 +117,7 @@ module Spree def load_order if params[:id] @order = Order.includes(:adjustments, :shipments, line_items: :adjustments). - find_by_number!(params[:id]) + find_by!(number: params[:id]) end authorize! action, @order end diff --git a/app/controllers/spree/admin/payment_methods_controller.rb b/app/controllers/spree/admin/payment_methods_controller.rb index a142eb6eb1..8825e4ea69 100644 --- a/app/controllers/spree/admin/payment_methods_controller.rb +++ b/app/controllers/spree/admin/payment_methods_controller.rb @@ -1,10 +1,10 @@ module Spree module Admin class PaymentMethodsController < ResourceController - skip_before_filter :load_resource, only: [:create, :show_provider_preferences] - before_filter :load_data - before_filter :validate_payment_method_provider, only: [:create] - before_filter :load_hubs, only: [:new, :edit, :update] + skip_before_action :load_resource, only: [:create, :show_provider_preferences] + before_action :load_data + before_action :validate_payment_method_provider, only: [:create] + before_action :load_hubs, only: [:new, :edit, :update] create.before :load_hubs respond_to :html @@ -40,7 +40,7 @@ module Spree @payment_method = PaymentMethod.find(params[:id]) end - if @payment_method.update_attributes(params_for_update) + if @payment_method.update(params_for_update) invoke_callbacks(:update, :after) flash[:success] = Spree.t(:successfully_updated, resource: Spree.t(:payment_method)) redirect_to edit_admin_payment_method_path(@payment_method) diff --git a/app/controllers/spree/admin/payments_controller.rb b/app/controllers/spree/admin/payments_controller.rb index ae73760d8d..215f69972a 100644 --- a/app/controllers/spree/admin/payments_controller.rb +++ b/app/controllers/spree/admin/payments_controller.rb @@ -3,10 +3,10 @@ module Spree module Admin class PaymentsController < Spree::Admin::BaseController - before_filter :load_order, except: [:show] - before_filter :load_payment, only: [:fire, :show] - before_filter :load_data - before_filter :can_transition_to_payment + before_action :load_order, except: [:show] + before_action :load_payment, only: [:fire, :show] + before_action :load_data + before_action :can_transition_to_payment respond_to :html @@ -122,7 +122,7 @@ module Spree end def load_order - @order = Order.find_by_number!(params[:order_id]) + @order = Order.find_by!(number: params[:order_id]) authorize! action, @order @order end diff --git a/app/controllers/spree/admin/product_properties_controller.rb b/app/controllers/spree/admin/product_properties_controller.rb index d5a783192d..b236b7be7e 100644 --- a/app/controllers/spree/admin/product_properties_controller.rb +++ b/app/controllers/spree/admin/product_properties_controller.rb @@ -2,8 +2,8 @@ module Spree module Admin class ProductPropertiesController < ResourceController belongs_to 'spree/product', find_by: :permalink - before_filter :find_properties - before_filter :setup_property, only: [:index] + before_action :find_properties + before_action :setup_property, only: [:index] private diff --git a/app/controllers/spree/admin/products_controller.rb b/app/controllers/spree/admin/products_controller.rb index a6099cf021..707a65b3f1 100644 --- a/app/controllers/spree/admin/products_controller.rb +++ b/app/controllers/spree/admin/products_controller.rb @@ -13,10 +13,10 @@ module Spree create.before :create_before update.before :update_before - 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 :strip_new_properties, only: [:create, :update] + before_action :load_data + before_action :load_form_data, only: [:index, :new, :create, :edit, :update] + before_action :load_spree_api_key, only: [:index, :variant_overrides] + before_action :strip_new_properties, only: [:create, :update] respond_override create: { html: { success: lambda { @@ -96,7 +96,7 @@ module Spree protected def find_resource - Product.find_by_permalink!(params[:id]) + Product.find_by!(permalink: params[:id]) end def location_after_save diff --git a/app/controllers/spree/admin/reports_controller.rb b/app/controllers/spree/admin/reports_controller.rb index d576e048c5..a19795ca6d 100644 --- a/app/controllers/spree/admin/reports_controller.rb +++ b/app/controllers/spree/admin/reports_controller.rb @@ -27,9 +27,9 @@ module Spree helper_method :render_content? - before_filter :cache_search_state + before_action :cache_search_state # Fetches user's distributors, suppliers and order_cycles - before_filter :load_data, + before_action :load_data, only: [:customers, :products_and_inventory, :order_cycle_management, :packing] respond_to :html diff --git a/app/controllers/spree/admin/resource_controller.rb b/app/controllers/spree/admin/resource_controller.rb index 8b7c0cde12..fce4dc1e4c 100644 --- a/app/controllers/spree/admin/resource_controller.rb +++ b/app/controllers/spree/admin/resource_controller.rb @@ -4,7 +4,7 @@ module Spree module Admin class ResourceController < Spree::Admin::BaseController helper_method :new_object_url, :edit_object_url, :object_url, :collection_url - before_filter :load_resource, except: [:update_positions] + before_action :load_resource, except: [:update_positions] rescue_from ActiveRecord::RecordNotFound, with: :resource_not_found rescue_from CanCan::AccessDenied, with: :unauthorized @@ -28,7 +28,7 @@ module Spree def update invoke_callbacks(:update, :before) - if @object.update_attributes(permitted_resource_params) + if @object.update(permitted_resource_params) invoke_callbacks(:update, :after) flash[:success] = flash_message_for(@object, :successfully_updated) respond_with(@object) do |format| diff --git a/app/controllers/spree/admin/search_controller.rb b/app/controllers/spree/admin/search_controller.rb index 1d0f05fc1f..0be57cb0b3 100644 --- a/app/controllers/spree/admin/search_controller.rb +++ b/app/controllers/spree/admin/search_controller.rb @@ -2,7 +2,7 @@ module Spree module Admin class SearchController < Spree::Admin::BaseController # http://spreecommerce.com/blog/2010/11/02/json-hijacking-vulnerability/ - before_filter :check_json_authenticity, only: :index + before_action :check_json_authenticity, only: :index respond_to :json def known_users diff --git a/app/controllers/spree/admin/shipping_methods_controller.rb b/app/controllers/spree/admin/shipping_methods_controller.rb index fe3bdb5d86..5fa427772e 100644 --- a/app/controllers/spree/admin/shipping_methods_controller.rb +++ b/app/controllers/spree/admin/shipping_methods_controller.rb @@ -1,10 +1,10 @@ module Spree module Admin class ShippingMethodsController < ResourceController - before_filter :load_data, except: [:index] - before_filter :set_shipping_category, only: [:create, :update] - before_filter :set_zones, only: [:create, :update] - before_filter :load_hubs, only: [:new, :edit, :create, :update] + before_action :load_data, except: [:index] + before_action :set_shipping_category, only: [:create, :update] + before_action :set_zones, only: [:create, :update] + before_action :load_hubs, only: [:new, :edit, :create, :update] # Sort shipping methods by distributor name def collection diff --git a/app/controllers/spree/admin/states_controller.rb b/app/controllers/spree/admin/states_controller.rb index 91b7672df2..09d7244439 100644 --- a/app/controllers/spree/admin/states_controller.rb +++ b/app/controllers/spree/admin/states_controller.rb @@ -2,7 +2,7 @@ module Spree module Admin class StatesController < ResourceController belongs_to 'spree/country' - before_filter :load_data + before_action :load_data def index respond_with(@collection) do |format| diff --git a/app/controllers/spree/admin/tax_rates_controller.rb b/app/controllers/spree/admin/tax_rates_controller.rb index 0f828abfee..b9948710d3 100644 --- a/app/controllers/spree/admin/tax_rates_controller.rb +++ b/app/controllers/spree/admin/tax_rates_controller.rb @@ -1,7 +1,7 @@ module Spree module Admin class TaxRatesController < ResourceController - before_filter :load_data + before_action :load_data update.after :update_after create.after :create_after diff --git a/app/controllers/spree/admin/taxons_controller.rb b/app/controllers/spree/admin/taxons_controller.rb index fab6eaeb12..0b171567d2 100644 --- a/app/controllers/spree/admin/taxons_controller.rb +++ b/app/controllers/spree/admin/taxons_controller.rb @@ -81,7 +81,7 @@ module Spree @update_children = true end - if @taxon.update_attributes(taxon_params) + if @taxon.update(taxon_params) flash[:success] = flash_message_for(@taxon, :successfully_updated) end diff --git a/app/controllers/spree/admin/users_controller.rb b/app/controllers/spree/admin/users_controller.rb index d70aaa8d9b..e6ffeaa6cd 100644 --- a/app/controllers/spree/admin/users_controller.rb +++ b/app/controllers/spree/admin/users_controller.rb @@ -3,11 +3,11 @@ module Spree class UsersController < ResourceController rescue_from Spree::User::DestroyWithOrdersError, with: :user_destroy_with_orders_error - after_filter :sign_in_if_change_own_password, only: :update + after_action :sign_in_if_change_own_password, only: :update # http://spreecommerce.com/blog/2010/11/02/json-hijacking-vulnerability/ - before_filter :check_json_authenticity, only: :index - before_filter :load_roles, only: [:edit, :new, :update, :create, + before_action :check_json_authenticity, only: :index + before_action :load_roles, only: [:edit, :new, :update, :create, :generate_api_key, :clear_api_key] def index @@ -41,7 +41,7 @@ module Spree roles = params[:user].delete("spree_role_ids") end - if @user.update_attributes(user_params) + if @user.update(user_params) if roles @user.spree_roles = roles.reject(&:blank?).collect{ |r| Spree::Role.find(r) } end diff --git a/app/controllers/spree/admin/zones_controller.rb b/app/controllers/spree/admin/zones_controller.rb index d8bef6a215..301c32ec70 100644 --- a/app/controllers/spree/admin/zones_controller.rb +++ b/app/controllers/spree/admin/zones_controller.rb @@ -1,7 +1,7 @@ module Spree module Admin class ZonesController < ResourceController - before_filter :load_data, except: [:index] + before_action :load_data, except: [:index] def new @zone.zone_members.build diff --git a/app/controllers/spree/credit_cards_controller.rb b/app/controllers/spree/credit_cards_controller.rb index 84e4189ef9..a1c2e60ea5 100644 --- a/app/controllers/spree/credit_cards_controller.rb +++ b/app/controllers/spree/credit_cards_controller.rb @@ -26,7 +26,7 @@ module Spree authorize! :update, @credit_card - if @credit_card.update_attributes(credit_card_params) + if @credit_card.update(credit_card_params) render json: @credit_card, serializer: ::Api::CreditCardSerializer, status: :ok else update_failed @@ -60,12 +60,12 @@ module Spree def destroy_at_stripe stripe_customer = Stripe::Customer.retrieve(@credit_card.gateway_customer_profile_id, {}) - stripe_customer.delete if stripe_customer + stripe_customer&.delete end def stripe_account_id StripeAccount. - find_by_enterprise_id(@credit_card.payment_method.preferred_enterprise_id). + find_by(enterprise_id: @credit_card.payment_method.preferred_enterprise_id). andand. stripe_user_id end diff --git a/app/controllers/spree/orders_controller.rb b/app/controllers/spree/orders_controller.rb index 9c3889c8df..85939fe1ad 100644 --- a/app/controllers/spree/orders_controller.rb +++ b/app/controllers/spree/orders_controller.rb @@ -8,22 +8,22 @@ module Spree ssl_required :show - before_filter :check_authorization + before_action :check_authorization rescue_from ActiveRecord::RecordNotFound, with: :render_404 helper 'spree/products', 'spree/orders' respond_to :html respond_to :json - before_filter :update_distribution, only: :update - before_filter :filter_order_params, only: :update - before_filter :enable_embedded_shopfront + before_action :update_distribution, only: :update + before_action :filter_order_params, only: :update + before_action :enable_embedded_shopfront - prepend_before_filter :require_order_authentication, only: :show - prepend_before_filter :require_order_cycle, only: :edit - prepend_before_filter :require_distributor_chosen, only: :edit - before_filter :check_hub_ready_for_checkout, only: :edit - before_filter :check_at_least_one_line_item, only: :update + prepend_before_action :require_order_authentication, only: :show + prepend_before_action :require_order_cycle, only: :edit + prepend_before_action :require_distributor_chosen, only: :edit + before_action :check_hub_ready_for_checkout, only: :edit + before_action :check_at_least_one_line_item, only: :update def show @order = Spree::Order.find_by!(number: params[:id]) @@ -74,7 +74,7 @@ module Spree redirect_to(main_app.root_path) && return end - if @order.update_attributes(order_params) + if @order.update(order_params) discard_empty_line_items with_open_adjustments { update_totals_and_taxes } @@ -166,7 +166,7 @@ module Spree # recalculates the shipment taxes def update_totals_and_taxes @order.updater.update_totals - @order.shipment.ensure_correct_adjustment_with_included_tax if @order.shipment + @order.shipment&.ensure_correct_adjustment_with_included_tax end # Sets the adjustments to open to perform the block's action and restores diff --git a/app/controllers/spree/paypal_controller_decorator.rb b/app/controllers/spree/paypal_controller_decorator.rb index a239ca7e0a..cb9409af16 100644 --- a/app/controllers/spree/paypal_controller_decorator.rb +++ b/app/controllers/spree/paypal_controller_decorator.rb @@ -1,8 +1,10 @@ +# frozen_string_literal: true + Spree::PaypalController.class_eval do - before_filter :enable_embedded_shopfront - before_filter :destroy_orphaned_paypal_payments, only: :confirm - after_filter :reset_order_when_complete, only: :confirm - before_filter :permit_parameters! + before_action :enable_embedded_shopfront + before_action :destroy_orphaned_paypal_payments, only: :confirm + after_action :reset_order_when_complete, only: :confirm + before_action :permit_parameters! def cancel flash[:notice] = Spree.t('flash.cancel', scope: 'paypal') diff --git a/app/controllers/spree/store_controller.rb b/app/controllers/spree/store_controller.rb index 42b2dd337f..cc4dd9d537 100644 --- a/app/controllers/spree/store_controller.rb +++ b/app/controllers/spree/store_controller.rb @@ -5,7 +5,7 @@ module Spree include Spree::Core::ControllerHelpers::Order include I18nHelper - before_filter :set_locale + before_action :set_locale def unauthorized render 'shared/unauthorized', status: :unauthorized diff --git a/app/controllers/spree/user_registrations_controller.rb b/app/controllers/spree/user_registrations_controller.rb index 36f0852cef..a55d327ae2 100644 --- a/app/controllers/spree/user_registrations_controller.rb +++ b/app/controllers/spree/user_registrations_controller.rb @@ -8,8 +8,8 @@ module Spree include Spree::Core::ControllerHelpers::SSL ssl_required - before_filter :check_permissions, only: [:edit, :update] - skip_before_filter :require_no_authentication + before_action :check_permissions, only: [:edit, :update] + skip_before_action :require_no_authentication # GET /resource/sign_up def new diff --git a/app/controllers/spree/user_sessions_controller.rb b/app/controllers/spree/user_sessions_controller.rb index f46fdb99fd..82ca577fc3 100644 --- a/app/controllers/spree/user_sessions_controller.rb +++ b/app/controllers/spree/user_sessions_controller.rb @@ -10,7 +10,7 @@ module Spree ssl_required :new, :create, :destroy, :update ssl_allowed :login_bar - before_filter :set_checkout_redirect, only: :create + before_action :set_checkout_redirect, only: :create def create authenticate_spree_user! diff --git a/app/controllers/spree/users_controller.rb b/app/controllers/spree/users_controller.rb index 03aced66c8..f524f8d465 100644 --- a/app/controllers/spree/users_controller.rb +++ b/app/controllers/spree/users_controller.rb @@ -2,15 +2,15 @@ module Spree class UsersController < Spree::StoreController layout 'darkswarm' ssl_required - skip_before_filter :set_current_order, only: :show - prepend_before_filter :load_object, only: [:show, :edit, :update] - prepend_before_filter :authorize_actions, only: :new + skip_before_action :set_current_order, only: :show + prepend_before_action :load_object, only: [:show, :edit, :update] + prepend_before_action :authorize_actions, only: :new include Spree::Core::ControllerHelpers include I18nHelper - before_filter :set_locale - before_filter :enable_embedded_shopfront + before_action :set_locale + before_action :enable_embedded_shopfront # Ignores invoice orders, only order where state: 'complete' def show @@ -39,7 +39,7 @@ module Spree end def update - if @user.update_attributes(user_params) + if @user.update(user_params) if params[:user][:password].present? # this logic needed b/c devise wants to log us out after password changes Spree::User.reset_password_by_token(params[:user]) diff --git a/app/controllers/stripe/webhooks_controller.rb b/app/controllers/stripe/webhooks_controller.rb index f079dbc7f2..ce607fd8e7 100644 --- a/app/controllers/stripe/webhooks_controller.rb +++ b/app/controllers/stripe/webhooks_controller.rb @@ -3,7 +3,7 @@ require 'stripe/webhook_handler' module Stripe class WebhooksController < BaseController protect_from_forgery except: :create - before_filter :verify_webhook + before_action :verify_webhook # POST /stripe/webhooks def create diff --git a/app/controllers/user_passwords_controller.rb b/app/controllers/user_passwords_controller.rb index 2db2dc81a4..e467e915e2 100644 --- a/app/controllers/user_passwords_controller.rb +++ b/app/controllers/user_passwords_controller.rb @@ -1,7 +1,7 @@ class UserPasswordsController < Spree::UserPasswordsController layout 'darkswarm' - before_filter :set_admin_redirect, only: :edit + before_action :set_admin_redirect, only: :edit def create render_unconfirmed_response && return if user_unconfirmed? diff --git a/app/controllers/user_registrations_controller.rb b/app/controllers/user_registrations_controller.rb index 2e9870b37e..873d7d4036 100644 --- a/app/controllers/user_registrations_controller.rb +++ b/app/controllers/user_registrations_controller.rb @@ -3,10 +3,10 @@ require 'open_food_network/error_logger' class UserRegistrationsController < Spree::UserRegistrationsController I18N_SCOPE = 'devise.user_registrations.spree_user'.freeze - before_filter :set_checkout_redirect, only: :create + before_action :set_checkout_redirect, only: :create include I18nHelper - before_filter :set_locale + before_action :set_locale # POST /resource/sign_up def create diff --git a/app/helpers/angular_form_helper.rb b/app/helpers/angular_form_helper.rb index add7e5f121..af21be3595 100644 --- a/app/helpers/angular_form_helper.rb +++ b/app/helpers/angular_form_helper.rb @@ -18,6 +18,10 @@ module AngularFormHelper end end -class ActionView::Helpers::InstanceTag - include AngularFormHelper +module ActionView + module Helpers + class InstanceTag + include AngularFormHelper + end + end end diff --git a/app/helpers/i18n_helper.rb b/app/helpers/i18n_helper.rb index 3293d42d98..a04405ac97 100644 --- a/app/helpers/i18n_helper.rb +++ b/app/helpers/i18n_helper.rb @@ -2,13 +2,13 @@ module I18nHelper def set_locale # Save a given locale if params[:locale] && available_locale?(params[:locale]) - spree_current_user.update_attributes!(locale: params[:locale]) if spree_current_user + spree_current_user&.update!(locale: params[:locale]) cookies[:locale] = params[:locale] end # After logging in, check if the user chose a locale before if spree_current_user && spree_current_user.locale.nil? && cookies[:locale] - spree_current_user.update_attributes!(locale: params[:locale]) + spree_current_user.update!(locale: params[:locale]) end I18n.locale = spree_current_user.andand.locale || cookies[:locale] || I18n.default_locale diff --git a/app/helpers/spree/base_helper_decorator.rb b/app/helpers/spree/base_helper_decorator.rb index 0125347d58..edab056346 100644 --- a/app/helpers/spree/base_helper_decorator.rb +++ b/app/helpers/spree/base_helper_decorator.rb @@ -2,13 +2,13 @@ module Spree module BaseHelper # human readable list of variant options # Override: Do not show out of stock text - def variant_options(v, _options = {}) - v.options_text + def variant_options(variant, _options = {}) + variant.options_text end # Overriden to eager-load :states def available_countries - checkout_zone = Zone.find_by_name(Spree::Config[:checkout_zone]) + checkout_zone = Zone.find_by(name: Spree::Config[:checkout_zone]) countries = if checkout_zone && checkout_zone.kind == 'country' checkout_zone.country_list diff --git a/app/jobs/subscription_placement_job.rb b/app/jobs/subscription_placement_job.rb index adfbe5cba1..8b5df2b159 100644 --- a/app/jobs/subscription_placement_job.rb +++ b/app/jobs/subscription_placement_job.rb @@ -54,7 +54,7 @@ class SubscriptionPlacementJob end unavailable_stock_lines_for(order).each do |line_item| changes[line_item.id] = changes[line_item.id] || line_item.quantity - line_item.update_attributes(quantity: 0) + line_item.update(quantity: 0) end changes end diff --git a/app/models/model_set.rb b/app/models/model_set.rb index 62d7e08002..1d5d7dbda3 100644 --- a/app/models/model_set.rb +++ b/app/models/model_set.rb @@ -19,11 +19,14 @@ class ModelSet def collection_attributes=(collection_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? + found_element = @collection.detect do |element| + element.id.to_s == attributes[:id].to_s && !element.id.nil? + end + + if found_element.nil? @collection << @klass.new(attributes) unless @reject_if.andand.call(attributes) else - e.assign_attributes(attributes.except(:id)) + found_element.assign_attributes(attributes.except(:id)) end end end diff --git a/app/models/producer_property.rb b/app/models/producer_property.rb index 75f3d98f17..278118871d 100644 --- a/app/models/producer_property.rb +++ b/app/models/producer_property.rb @@ -5,7 +5,7 @@ class ProducerProperty < ActiveRecord::Base default_scope { order("#{table_name}.position") } def property_name - property.name if property + property&.name end def property_name=(name) diff --git a/app/models/product_import/entry_validator.rb b/app/models/product_import/entry_validator.rb index fa2380c07b..ce5af3091b 100644 --- a/app/models/product_import/entry_validator.rb +++ b/app/models/product_import/entry_validator.rb @@ -46,7 +46,10 @@ module ProductImport else category_validation(entry) tax_and_shipping_validation(entry, 'tax', entry.tax_category, @spreadsheet_data.tax_index) - tax_and_shipping_validation(entry, 'shipping', entry.shipping_category, @spreadsheet_data.shipping_index) + tax_and_shipping_validation(entry, + 'shipping', + entry.shipping_category, + @spreadsheet_data.shipping_index) shipping_presence_validation(entry) product_validation(entry) end @@ -68,8 +71,12 @@ module ProductImport 'variant_unit_scale', 'primary_taxon_id') ) new_variant.save - new_variant.on_demand = entry.attributes['on_demand'] if entry.attributes['on_demand'].present? - new_variant.on_hand = entry.attributes['on_hand'] if entry.attributes['on_hand'].present? + if entry.attributes['on_demand'].present? + new_variant.on_demand = entry.attributes['on_demand'] + end + if entry.attributes['on_hand'].present? + new_variant.on_hand = entry.attributes['on_hand'] + end new_variant.product_id = product_id check_on_hand_nil(entry, new_variant) @@ -154,21 +161,28 @@ module ProductImport def unit_fields_validation(entry) unit_types = ['g', 'kg', 't', 'ml', 'l', 'kl', ''] - unless entry.units && entry.units.present? - mark_as_invalid(entry, attribute: 'units', error: I18n.t('admin.product_import.model.blank')) + unless entry.units&.present? + mark_as_invalid(entry, attribute: 'units', + error: I18n.t('admin.product_import.model.blank')) end return if import_into_inventory? # unit_type must be valid type - if entry.unit_type && entry.unit_type.present? + if entry.unit_type&.present? unit_type = entry.unit_type.to_s.strip.downcase - mark_as_invalid(entry, attribute: 'unit_type', error: I18n.t('admin.product_import.model.incorrect_value')) unless unit_types.include?(unit_type) + unless unit_types.include?(unit_type) + mark_as_invalid(entry, attribute: 'unit_type', + error: I18n.t('admin.product_import.model.incorrect_value')) + end return end # variant_unit_name must be present if unit_type not present - mark_as_invalid(entry, attribute: 'variant_unit_name', error: I18n.t('admin.product_import.model.conditional_blank')) unless entry.variant_unit_name && entry.variant_unit_name.present? + return if entry.variant_unit_name&.present? + + mark_as_invalid(entry, attribute: 'variant_unit_name', + error: I18n.t('admin.product_import.model.conditional_blank')) end def variant_of_product_validation(entry) @@ -200,12 +214,15 @@ module ProductImport producer_name = entry.producer if producer_name.blank? - mark_as_invalid(entry, attribute: "producer", error: I18n.t('admin.product_import.model.blank')) + mark_as_invalid(entry, attribute: "producer", + error: I18n.t('admin.product_import.model.blank')) return end unless @spreadsheet_data.producers_index[producer_name] - mark_as_invalid(entry, attribute: "producer", error: "\"#{producer_name}\" #{I18n.t('admin.product_import.model.not_found')}") + model_not_found = I18n.t('admin.product_import.model.not_found') + mark_as_invalid(entry, attribute: "producer", + error: "\"#{producer_name}\" #{model_not_found}") return end @@ -214,7 +231,9 @@ module ProductImport @spreadsheet_data.producers_index[producer_name] ) - mark_as_invalid(entry, attribute: "producer", error: "\"#{producer_name}\": #{I18n.t('admin.product_import.model.inventory_no_permission')}") + inventory_no_permission = I18n.t('admin.product_import.model.inventory_no_permission') + mark_as_invalid(entry, attribute: "producer", + error: "\"#{producer_name}\": #{inventory_no_permission}") return end @@ -222,10 +241,13 @@ module ProductImport end def inventory_validation(entry) - products = Spree::Product.where(supplier_id: entry.producer_id, name: entry.name, deleted_at: nil) + products = Spree::Product.where(supplier_id: entry.producer_id, + name: entry.name, + deleted_at: nil) if products.empty? - mark_as_invalid(entry, attribute: 'name', error: I18n.t('admin.product_import.model.no_product')) + mark_as_invalid(entry, attribute: 'name', + error: I18n.t('admin.product_import.model.no_product')) return end @@ -240,11 +262,13 @@ module ProductImport end end - mark_as_invalid(entry, attribute: 'product', error: I18n.t('admin.product_import.model.not_found')) + mark_as_invalid(entry, attribute: 'product', + error: I18n.t('admin.product_import.model.not_found')) end def entry_matches_existing_variant?(entry, existing_variant) - existing_variant.display_name == entry.display_name && existing_variant.unit_value == entry.unit_value.to_f + existing_variant.display_name == entry.display_name && + existing_variant.unit_value == entry.unit_value.to_f end def category_validation(entry) @@ -258,7 +282,9 @@ module ProductImport if @spreadsheet_data.categories_index[category_name] entry.primary_taxon_id = @spreadsheet_data.categories_index[category_name] else - mark_as_invalid(entry, attribute: "category", error: I18n.t(:error_not_found_in_database, name: category_name)) + mark_as_invalid(entry, attribute: "category", + error: I18n.t(:error_not_found_in_database, + name: category_name)) end end @@ -268,12 +294,16 @@ module ProductImport if index.key? category entry.public_send("#{type}_category_id=", index[category]) else - mark_as_invalid(entry, attribute: "#{type}_category", error: I18n.t('admin.product_import.model.not_found')) + mark_as_invalid(entry, attribute: "#{type}_category", + error: I18n.t('admin.product_import.model.not_found')) end end def shipping_presence_validation(entry) - mark_as_invalid(entry, attribute: "shipping_category", error: I18n.t(:error_required)) unless entry.shipping_category_id + return if entry.shipping_category_id + + mark_as_invalid(entry, attribute: "shipping_category", + error: I18n.t(:error_required)) end def product_validation(entry) @@ -289,7 +319,8 @@ module ProductImport products.each { |product| product_field_errors(entry, product) } products.flat_map(&:variants).each do |existing_variant| - if entry_matches_existing_variant?(entry, existing_variant) && existing_variant.deleted_at.nil? + if entry_matches_existing_variant?(entry, existing_variant) && + existing_variant.deleted_at.nil? return mark_as_existing_variant(entry, existing_variant) end end @@ -330,10 +361,12 @@ module ProductImport def product_field_errors(entry, existing_product) EntryValidator.non_updatable_fields.each do |display_name, attribute| - next if attributes_match?(attribute, existing_product, entry) || attributes_blank?(attribute, existing_product, entry) + next if attributes_match?(attribute, existing_product, entry) || + attributes_blank?(attribute, existing_product, entry) next if ignore_when_updating_product?(attribute) - mark_as_invalid(entry, attribute: display_name, error: I18n.t('admin.product_import.model.not_updatable')) + mark_as_invalid(entry, attribute: display_name, + error: I18n.t('admin.product_import.model.not_updatable')) end end @@ -372,12 +405,14 @@ module ProductImport def inventory_permission?(enterprise_id, producer_id) @current_user.admin? || - ( @inventory_permissions[enterprise_id] && - @inventory_permissions[enterprise_id].include?(producer_id) ) + @inventory_permissions[enterprise_id]&.include?(producer_id) end def mark_as_invalid(entry, options = {}) - entry.errors.add(options[:attribute], options[:error]) if options[:attribute] && options[:error] + if options[:attribute] && options[:error] + entry.errors.add(options[:attribute], options[:error]) + end + entry.product_validations = options[:product_validations] if options[:product_validations] end diff --git a/app/models/product_import/product_importer.rb b/app/models/product_import/product_importer.rb index 85600d0407..75e9d78846 100644 --- a/app/models/product_import/product_importer.rb +++ b/app/models/product_import/product_importer.rb @@ -2,7 +2,7 @@ # and begins the processing of the spreadsheet entries by the other product import classes. # As spreadsheets can contain any number of entries (1000+), the import is split into smaller chunks # of 100 items, and processed sequentially over a number of requests to avoid server timeouts. -# The various bits of collated information such as file upload status, per-item errors or user feedback +# The various bits of collated info such as file upload status, per-item errors or user feedback # on the saving process are made available to the controller through this object. require 'roo' @@ -59,7 +59,8 @@ module ProductImport def product_field_errors? @entries.each do |entry| - return true if entry.errors.messages.value?([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 @@ -190,7 +191,7 @@ module ProductImport end def staged_import? - @import_settings && @import_settings.key?(:start) && @import_settings.key?(:end) + @import_settings&.key?(:start) && @import_settings&.key?(:end) end def init_permissions @@ -224,7 +225,7 @@ module ProductImport end def rows - return [] unless @sheet && @sheet.last_row + return [] unless @sheet&.last_row (2..@sheet.last_row).map do |i| @sheet.row(i) diff --git a/app/models/proxy_order.rb b/app/models/proxy_order.rb index a7342c9702..bece28a65d 100644 --- a/app/models/proxy_order.rb +++ b/app/models/proxy_order.rb @@ -33,7 +33,7 @@ class ProxyOrder < ActiveRecord::Base transaction do update_column(:canceled_at, Time.zone.now) - order.cancel if order + order&.cancel true end end @@ -43,7 +43,7 @@ class ProxyOrder < ActiveRecord::Base transaction do update_column(:canceled_at, nil) - order.resume if order + order&.resume true end end diff --git a/app/models/spree/adjustment_decorator.rb b/app/models/spree/adjustment_decorator.rb index dbbaa6ae95..cba3b3e879 100644 --- a/app/models/spree/adjustment_decorator.rb +++ b/app/models/spree/adjustment_decorator.rb @@ -32,7 +32,11 @@ module Spree end def set_absolute_included_tax!(tax) + # This rubocop issue can only be fixed when Adjustment#update! is brought from Spree to OFN + # and renamed to something else, then AR's update! can be used instead of update_attributes! + # rubocop:disable Rails/ActiveRecordAliases update_attributes! included_tax: tax.round(2) + # rubocop:enable Rails/ActiveRecordAliases end def display_included_tax diff --git a/app/models/spree/gateway/stripe_sca.rb b/app/models/spree/gateway/stripe_sca.rb index 5a07fe1b3c..21fa698c3b 100644 --- a/app/models/spree/gateway/stripe_sca.rb +++ b/app/models/spree/gateway/stripe_sca.rb @@ -27,7 +27,7 @@ module Spree end def stripe_account_id - StripeAccount.find_by_enterprise_id(preferred_enterprise_id).andand.stripe_user_id + StripeAccount.find_by(enterprise_id: preferred_enterprise_id).andand.stripe_user_id end # NOTE: the name of this method is determined by Spree::Payment::Processing @@ -110,7 +110,7 @@ module Spree def fetch_payment(creditcard, gateway_options) order_number = gateway_options[:order_id].split('-').first - Spree::Order.find_by_number(order_number).payments.merge(creditcard.payments).last + Spree::Order.find_by(number: order_number).payments.merge(creditcard.payments).last end def failed_activemerchant_billing_response(error_message) diff --git a/app/models/spree/line_item_decorator.rb b/app/models/spree/line_item_decorator.rb index 5d22c0fbc4..c58b072892 100644 --- a/app/models/spree/line_item_decorator.rb +++ b/app/models/spree/line_item_decorator.rb @@ -87,7 +87,7 @@ Spree::LineItem.class_eval do scoper.scope(variant) return if variant.on_demand - update_attributes!(quantity: variant.on_hand) if quantity > variant.on_hand + update!(quantity: variant.on_hand) if quantity > variant.on_hand end def has_tax? diff --git a/app/models/spree/product_set.rb b/app/models/spree/product_set.rb index 5de24ddc52..4731c44bf7 100644 --- a/app/models/spree/product_set.rb +++ b/app/models/spree/product_set.rb @@ -5,7 +5,7 @@ class Spree::ProductSet < ModelSet def save @collection_hash.each_value.all? do |product_attributes| - update_attributes(product_attributes) + update_product_attributes(product_attributes) end end @@ -18,19 +18,19 @@ class Spree::ProductSet < ModelSet private # A separate method of updating products was required due to an issue with - # the way Rails' assign_attributes and updates_attributes behave when + # the way Rails' assign_attributes and update behave when # delegated attributes of a nested object are updated via the parent object # (ie. price of variants). Updating such attributes by themselves did not # work using: # - # product.update_attributes(variants_attributes: [{ id: y, price: xx.x }]) + # product.update(variants_attributes: [{ id: y, price: xx.x }]) # - # and so an explicit call to update attributes on each individual variant was + # and so an explicit call to update on each individual variant was # required. ie: # - # variant.update_attributes( { price: xx.x } ) + # variant.update( { price: xx.x } ) # - def update_attributes(attributes) + def update_product_attributes(attributes) split_taxon_ids!(attributes) product = find_model(@collection, attributes[:id]) @@ -99,7 +99,7 @@ class Spree::ProductSet < ModelSet def create_or_update_variant(product, variant_attributes) variant = find_model(product.variants_including_master, variant_attributes[:id]) if variant.present? - variant.update_attributes(variant_attributes.except(:id)) + variant.update(variant_attributes.except(:id)) else create_variant(product, variant_attributes) end diff --git a/app/models/spree/variant_decorator.rb b/app/models/spree/variant_decorator.rb index 96853a28f2..41b1a4eb76 100644 --- a/app/models/spree/variant_decorator.rb +++ b/app/models/spree/variant_decorator.rb @@ -90,9 +90,7 @@ Spree::Variant.class_eval do end def self.indexed - Hash[ - scoped.map { |v| [v.id, v] } - ] + scoped.index_by(&:id) end def self.active(currency = nil) diff --git a/app/models/variant_override.rb b/app/models/variant_override.rb index b975f7b043..f2630d98a1 100644 --- a/app/models/variant_override.rb +++ b/app/models/variant_override.rb @@ -27,9 +27,7 @@ class VariantOverride < ActiveRecord::Base localize_number :price def self.indexed(hub) - Hash[ - for_hubs(hub).preload(:variant).map { |vo| [vo.variant, vo] } - ] + for_hubs(hub).preload(:variant).index_by(&:variant) end def stock_overridden? diff --git a/app/serializers/api/enterprise_serializer.rb b/app/serializers/api/enterprise_serializer.rb index fa0b09762a..94dbda5ada 100644 --- a/app/serializers/api/enterprise_serializer.rb +++ b/app/serializers/api/enterprise_serializer.rb @@ -2,7 +2,9 @@ require 'open_food_network/property_merge' class Api::EnterpriseSerializer < ActiveModel::Serializer # We reference this here because otherwise the serializer complains about its absence + # rubocop:disable Lint/Void Api::IdSerializer + # rubocop:enable Lint/Void def serializable_hash cached_serializer_hash.merge uncached_serializer_hash diff --git a/app/services/cart_service.rb b/app/services/cart_service.rb index 9df85cfe45..d46e2478ca 100644 --- a/app/services/cart_service.rb +++ b/app/services/cart_service.rb @@ -127,7 +127,7 @@ class CartService li = line_item_for_variant loaded_variant li_added = li.nil? && (variant_data[:quantity].to_i > 0 || variant_data[:max_quantity].to_i > 0) - li_quantity_changed = li.present? && li.quantity.to_i != variant_data[:quantity].to_i + li_quantity_changed = li.present? && li.quantity.to_i != variant_data[:quantity].to_i li_max_quantity_changed = li.present? && li.max_quantity.to_i != variant_data[:max_quantity].to_i li_added || li_quantity_changed || li_max_quantity_changed diff --git a/app/services/line_item_syncer.rb b/app/services/line_item_syncer.rb index e190db0be5..68b86d6a97 100644 --- a/app/services/line_item_syncer.rb +++ b/app/services/line_item_syncer.rb @@ -64,8 +64,8 @@ class LineItemSyncer def update_quantity(line_item, sli) if line_item.quantity == sli.quantity_was - return line_item.update_attributes(quantity: sli.quantity, - skip_stock_check: skip_stock_check?(line_item.order)) + return line_item.update(quantity: sli.quantity, + skip_stock_check: skip_stock_check?(line_item.order)) end line_item.quantity == sli.quantity end diff --git a/app/services/order_checkout_restart.rb b/app/services/order_checkout_restart.rb index 6b5cb6724f..5ca7d2bf78 100644 --- a/app/services/order_checkout_restart.rb +++ b/app/services/order_checkout_restart.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Resets the passed order to cart state while clearing associated payments and shipments class OrderCheckoutRestart def initialize(order) diff --git a/app/services/order_factory.rb b/app/services/order_factory.rb index a7845618b0..bb2a99d018 100644 --- a/app/services/order_factory.rb +++ b/app/services/order_factory.rb @@ -66,7 +66,7 @@ class OrderFactory end def set_addresses - @order.update_attributes(attrs.slice(:bill_address_attributes, :ship_address_attributes)) + @order.update(attrs.slice(:bill_address_attributes, :ship_address_attributes)) end def create_shipment diff --git a/app/services/order_syncer.rb b/app/services/order_syncer.rb index 97f8066a03..98e4fc9a53 100644 --- a/app/services/order_syncer.rb +++ b/app/services/order_syncer.rb @@ -49,7 +49,7 @@ class OrderSyncer return order_update_issues.add(order, I18n.t('bill_address')) end - order.bill_address.update_attributes(bill_address.attributes.slice(*relevant_address_attrs)) + order.bill_address.update(bill_address.attributes.slice(*relevant_address_attrs)) end def update_payment_for(order) @@ -123,7 +123,7 @@ class OrderSyncer def save_ship_address_in_order(order) return unless ship_address_updatable?(order) - order.ship_address.update_attributes(ship_address.attributes.slice(*relevant_address_attrs)) + order.ship_address.update(ship_address.attributes.slice(*relevant_address_attrs)) end def pending_shipment_with?(order, shipping_method_id) diff --git a/app/services/user_default_address_setter.rb b/app/services/user_default_address_setter.rb index 812af8f61b..7a83078290 100644 --- a/app/services/user_default_address_setter.rb +++ b/app/services/user_default_address_setter.rb @@ -26,13 +26,13 @@ class UserDefaultAddressSetter private def set_bill_address_attributes(object, new_address) - object.update_attributes( + object.update( bill_address_attributes: new_address.merge('id' => object.bill_address.andand.id) ) end def set_ship_address_attributes(object, new_address) - object.update_attributes( + object.update( ship_address_attributes: new_address.merge('id' => object.ship_address.andand.id) ) end diff --git a/app/views/spree/admin/payment_methods/index.html.haml b/app/views/spree/admin/payment_methods/index.html.haml index ab1333f2c5..adb14d5caa 100644 --- a/app/views/spree/admin/payment_methods/index.html.haml +++ b/app/views/spree/admin/payment_methods/index.html.haml @@ -32,7 +32,7 @@ - method.distributors.each do |distributor| = distributor.name %br/ - %td= method.type + %td= method.class.clean_name %td.align-center= method.environment.to_s.titleize %td.align-center= method.display_on.blank? ? t('.both') : t('.' + method.display_on.to_s) %td.align-center= method.active ? t('.active_yes') : t('.active_no') diff --git a/config/locales/en.yml b/config/locales/en.yml index 27cf49f93b..4b62644980 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -302,6 +302,7 @@ en: on_hand: "On Hand" "on hand": "On Hand" ship: "Ship" + shipping_category: "Shipping Category" actions: create_and_add_another: "Create and Add Another" @@ -2203,6 +2204,7 @@ See the %{link} to find out more about %{sitename}'s features and to start using hub_sidebar_at_least: "At least one hub must be selected" hub_sidebar_blue: "blue" hub_sidebar_red: "red" + order_cycles_closed_for_hub: "The hub you have selected is temporarily closed for orders. Please try again later." report_customers_distributor: "Distributor" report_customers_supplier: "Supplier" report_customers_cycle: "Order Cycle" @@ -2441,6 +2443,7 @@ See the %{link} to find out more about %{sitename}'s features and to start using order_cycles_email_to_producers_notice: 'Emails to be sent to producers have been queued for sending.' order_cycles_no_permission_to_coordinate_error: "None of your enterprises have permission to coordinate an order cycle" order_cycles_no_permission_to_create_error: "You don't have permission to create an order cycle coordinated by that enterprise" + order_cycle_closed: "The order cycle you've selected has just closed. Please try again!" back_to_orders_list: "Back to order list" no_orders_found: "No Orders Found" order_information: "Order Information" @@ -2918,6 +2921,7 @@ See the %{link} to find out more about %{sitename}'s features and to start using last: "Last" spree: + more: "More" your_order_is_empty_add_product: "Your order is empty, please search for and add a product above" add_product: "Add Product" name_or_sku: "Name or SKU (enter at least first 4 characters of product name)" diff --git a/config/locales/en_FR.yml b/config/locales/en_FR.yml index e1eaf0fd19..7e58bae598 100644 --- a/config/locales/en_FR.yml +++ b/config/locales/en_FR.yml @@ -1147,13 +1147,18 @@ en_FR: menu: cart: cart: "Cart" + cart_sidebar: + checkout: "Checkout" + edit_cart: "Edit cart" + items_in_cart_singular: "%{num} item in your cart" + items_in_cart_plural: "%{num} item in your cart" + close: "Close" + cart_empty: "Your cart is empty" + take_me_shopping: "Take me shopping!" signed_in: profile: "Profile" mobile_menu: cart: "Cart" - joyride: - checkout: "Checkout now" - already_ordered_products: "Already ordered in this order cycle" register_call: selling_on_ofn: "Interested in getting on the Open Food Network?" register: "Register here" diff --git a/config/locales/en_US.yml b/config/locales/en_US.yml index d21e17ed10..7917bbc6e6 100644 --- a/config/locales/en_US.yml +++ b/config/locales/en_US.yml @@ -33,6 +33,10 @@ en_US: taken: "There's already an account registered for this email. Please login to reset your password." spree/order: no_card: There are no authorized credit cards available to charge + spree/credit_card: + attributes: + base: + card_expired: "has expired" order_cycle: attributes: orders_close_at: @@ -321,6 +325,7 @@ en_US: show_n_more: Show %{num} more choose: "Choose..." please_select: Please select... + column_save_as_default: Save As Default columns: Columns actions: Actions viewing: "Viewing: %{current_view_name}" @@ -365,7 +370,10 @@ en_US: title: "Matomo Settings" matomo_url: "Matomo URL" matomo_site_id: "Matomo Site ID" + matomo_tag_manager_url: "Matomo Tag Manager URL" + info_html: "Matomo is a Web and Mobile Analytics application. You can either host Matomo on-premises or use a cloud-hosted service. See matomo.org for more information." config_instructions_html: "Here you can configure the OFN Matomo integration. The Matomo URL below should point to the Matomo instance where the user tracking information will be sent to; if it is left empty, Matomo user tracking will be disabled. The Site ID field is not mandatory but useful if you are tracking more than one website on a single Matomo instance; it can be found on the Matomo instance console." + config_instructions_tag_manager_html: "Setting the Matomo Tag Manager URL enables Matomo Tag Manager. This tool allows you to set up analytics events. The Matomo Tag Manager URL is copied from the Install Code section of Matomo Tag Manager. Ensure you select the right container and environment as these options change the URL." customers: index: new_customer: "New Customer" @@ -471,6 +479,7 @@ en_US: line_number: "Line %{number}:" encoding_error: "Please check the language setting of your source file and ensure it is saved with UTF-8 encoding" unexpected_error: "Product Import encountered an unexpected error when opening the file: %{error_message}" + malformed_csv: "Product Import encountered a malformed CSV: %{error_message}" index: notice: "Notice" beta_notice: "This feature is still in beta: you may experience some errors while using it. Please don't hesitate to contact support." @@ -683,6 +692,7 @@ en_US: ofn_uid_tip: The unique id used to identify the enterprise on Open Food Network. shipping_methods: name: "Name" + applies: "Active?" manage: "Manage Shipping Methods" create_button: "Create New Shipping Method" create_one_button: "Create One Now" @@ -861,6 +871,7 @@ en_US: incoming: "Incoming" supplier: "Supplier" products: "Products" + receival_details: "Receival Details" fees: "Fees" save: "Save" save_and_next: "Save and Next" @@ -1136,13 +1147,18 @@ en_US: menu: cart: cart: "Cart" + cart_sidebar: + checkout: "Checkout" + edit_cart: "Edit cart" + items_in_cart_singular: "%{num} item in your cart" + items_in_cart_plural: "%{num} items in your cart" + close: "Close" + cart_empty: "Your cart is empty" + take_me_shopping: "Let's go shopping!" signed_in: profile: "Profile" mobile_menu: cart: "Cart" - joyride: - checkout: "Checkout now" - already_ordered_products: "Already ordered in this order cycle" register_call: selling_on_ofn: "Interested in selling through the Open Food Network?" register: "Register here" @@ -1170,7 +1186,11 @@ en_US: signup: "signup" contact: "contact" require_customer_login: "Only approved customers can access this shop." + require_login_html: "If you're already an approved customer, %{login} or %{signup} to proceed." + require_login_2_html: "Want to start shopping here? Please %{contact} %{enterprise} and ask about joining." require_customer_html: "If you'd like to start shopping here, please %{contact} %{enterprise} to ask about joining." + select_oc: + select_oc_html: "Please choose when you want your order, to see what products are available." card_could_not_be_updated: Card could not be updated card_could_not_be_saved: card could not be saved spree_gateway_error_flash_for_checkout: "There was a problem with your payment information: %{error}" @@ -1530,12 +1550,17 @@ en_US: orders_changeable_orders_alert_html: This order has been confirmed, but you can make changes until %{oc_close}. products_clear: Clear products_showing: "Showing:" + products_results_for: "Results for" products_or: "or" products_and: "and" + products_filters_in: "in" products_with: with + products_search: "Search..." products_filter_by: "Filter by" products_filter_selected: "selected" + products_filter_heading: "Filters" products_filter_clear: "Clear" + products_filter_done: "Done" products_loading: "Loading products..." products_updating_cart: "Updating cart..." products_cart_empty: "Cart empty" @@ -1546,6 +1571,8 @@ en_US: products_update_error_msg: "Saving failed." products_update_error_data: "Save failed due to invalid data:" products_changes_saved: "Changes saved." + products_no_results_html: "Sorry, no results found for %{query}" + products_clear_search: "Clear search" search_no_results_html: "Sorry, no results found for %{query}. Try another search?" components_profiles_popover: "Profiles do not have a shopfront on the Open Food Network, but may have their own physical or online shop elsewhere" components_profiles_show: "Show profiles" @@ -1901,6 +1928,7 @@ en_US: admin_enterprise_relationships_permits: "permits" admin_enterprise_relationships_seach_placeholder: "Search" admin_enterprise_relationships_button_create: "Create" + admin_enterprise_relationships_to: "to" admin_enterprise_groups: "Enterprise Groups" admin_enterprise_groups_name: "Name" admin_enterprise_groups_owner: "Owner" @@ -2306,6 +2334,10 @@ en_US: resolve_errors: Please resolve the following errors more_items: "+ %{count} More" default_card_updated: Default Card Updated + cart: + add_to_cart_failed: > + There was a problem adding this product to the cart. Perhaps it has become + unavailable or the shop is closing. admin: enterprise_limit_reached: "You have reached the standard limit of enterprises per account. Write to %{contact_email} if you need to increase it." modals: @@ -2621,6 +2653,9 @@ en_US: tub: one: "tub" other: "tubs" + punnet: + one: "baskets" + other: "baskets" packet: one: "packet" other: "packets" @@ -2785,6 +2820,12 @@ en_US: void: "Void" login: "Login" password: "Password" + signature: "Signature" + solution: "Solution" + landing_page: "Landing Page" + server: "Server" + test_mode: "Test Mode" + logourl: "Logourl" configurations: "Configurations" general_settings: "General Settings" site_name: "Site Name" @@ -2901,6 +2942,12 @@ en_US: options: "Options" actions: update: "Update" + shared: + error_messages: + errors_prohibited_this_record_from_being_saved: + one: "1 error prohibited this record from being saved:" + other: "%{count} errors prohibited this record from being saved:" + there_were_problems_with_the_following_fields: "There were problems with the following fields" errors: messages: blank: "can't be blank" @@ -3043,6 +3090,8 @@ en_US: zone: "Zone" calculator: "Calculator" display: "Display" + both: "Both Checkout and Back office" + back_end: "Back office only" no_shipping_methods_found: "No shipping methods found" new: new_shipping_method: "New Shipping Method" @@ -3054,6 +3103,9 @@ en_US: form: categories: "Categories" zones: "Zones" + both: "Both Checkout and Back office" + back_end: "Back office only" + deactivation_warning: "De-activating a shipping method can make the shipping method disappear from your list. Alternatively, you can hide a shipping method from the checkout page by setting the option 'Display' to 'back office only'." payment_methods: index: payment_methods: "Payment Methods" @@ -3065,8 +3117,11 @@ en_US: display: "Display" active: "Active" both: "Both" + front_end: "Checkout only" + back_end: "Back office only" active_yes: "Yes" active_no: "No" + no_payment_methods_found: "No payment methods found" new: new_payment_method: "New Payment Method" back_to_payment_methods_list: "Back To Payment Methods List" @@ -3095,7 +3150,11 @@ en_US: active: "Active" active_yes: "Yes" active_no: "No" + both: "Both Checkout and Back office" + front_end: "Checkout only" + back_end: "Back office only" tags: "Tags" + deactivation_warning: "De-activating a payment method can make the payment method disappear from your list. Alternatively, you can hide a payment method from the checkout page by setting the option 'Display' to 'back office only'." providers: provider: "Provider" payments: @@ -3192,10 +3251,13 @@ en_US: new: new_variant: "New Variant" form: + cost_price: "Cost Price" sku: "SKU" price: "Price" display_as: "Display As" display_name: "Display Name" + display_as_placeholder: 'For example, 2 kg' + display_name_placeholder: 'For example, Tomatoes' autocomplete: out_of_stock: "Out of Stock" producer_name: "Producer" @@ -3235,6 +3297,7 @@ en_US: format: '%Y-%m-%d' js_format: 'yy-mm-dd' orders: + error_flash_for_unavailable_items: "An item in your cart has become unavailable. Please update the selected quantities." edit: login_to_view_order: "Please log in to view your order." bought: @@ -3262,6 +3325,14 @@ en_US: invalid: Invalid order_mailer: cancel_email: + customer_greeting: "Dear %{name}," + instructions_html: "Your order with %{distributor} has been CANCELED. Please retain this cancellation information for your records." + dont_cancel: "If you have changed your mind or don't wish to cancel this order please contact %{email}" + order_summary_canceled_html: "Order Summary #%{number} [CANCELED]" + details: "Here are the details of what you ordered:" + unpaid_order: "Your order was unpaid so no refund has been made" + paid_order: "Your order was paid so %{distributor} has refunded the full amount" + credit_order: "Your order was paid so your account has been credited" subject: "Cancellation of Order" confirm_email: subject: "Order Confirmation" diff --git a/config/locales/fr.yml b/config/locales/fr.yml index 1e2e368003..8935f5a339 100644 --- a/config/locales/fr.yml +++ b/config/locales/fr.yml @@ -1149,13 +1149,18 @@ fr: menu: cart: cart: "Panier" + cart_sidebar: + checkout: "Etape suivante (coordonnées)" + edit_cart: "Modifier le panier" + items_in_cart_singular: "%{num} élément dans le panier" + items_in_cart_plural: "%{num} éléments dans le panier" + close: "Fermer" + cart_empty: "Le panier est vide" + take_me_shopping: "Continuer mes achats" signed_in: profile: "Profil" mobile_menu: cart: "Panier" - joyride: - checkout: "Poursuivre la commande" - already_ordered_products: "Déjà commandé dans ce cycle de vente" register_call: selling_on_ofn: "Vous souhaitez proposer vos produits sur Open Food France?" register: "Démarrez ici" diff --git a/config/locales/tr.yml b/config/locales/tr.yml index f9777fb9cd..87598248e1 100644 --- a/config/locales/tr.yml +++ b/config/locales/tr.yml @@ -370,7 +370,10 @@ tr: title: "Matomo Ayarları" matomo_url: "Matomo URL'si" matomo_site_id: "Matomo Site Kimliği" + matomo_tag_manager_url: "Matomo Tag Manager URL" + info_html: "Matomo, Web ve Mobil Analitik uygulamasıdır. Daha fazla bilgi için matomo.org sitesini ziyaret edin." config_instructions_html: "Burada OFN Matomo entegrasyonunu yapılandırabilirsiniz. Aşağıdaki Matomo URL'si, kullanıcı izleme bilgilerinin gönderileceği Matomo örneğini göstermelidir; boş bırakılırsa Matomo kullanıcı takibi devre dışı bırakılır. Site Kimliği alanı zorunlu değildir, ancak tek bir Matomo örneğinde birden fazla web sitesini izliyorsanız yararlıdır; Matomo örnek konsolunda bulunabilir." + config_instructions_tag_manager_html: "Setting the Matomo Tag Manager URL enables Matomo Tag Manager. This tool allows you to set up analytics events. The Matomo Tag Manager URL is copied from the Install Code section of Matomo Tag Manager. Ensure you select the right container and environment as these options change the URL." customers: index: new_customer: "Yeni Müşteri" @@ -476,6 +479,7 @@ tr: line_number: "%{number}. satır:" encoding_error: "Lütfen kaynak dosyanızın dil ayarını kontrol edin ve UTF-8 kodlamasıyla kaydedildiğinden emin olun" unexpected_error: "Ürün içe aktarımında dosyayı açarken beklenmeyen bir hatayla karşılaşıldı: %{error_message}" + malformed_csv: "Ürün içe aktarımında CSV biçim hatası ile karşılaşıldı: %{error_message}" index: notice: "Dikkat" beta_notice: "Bu özellik hala beta sürümündedir: kullanırken bazı hatalarla karşılaşabilirsiniz. Lütfen teknik destek için iletişime geçmekten çekinmeyin." @@ -2939,7 +2943,7 @@ tr: errors_prohibited_this_record_from_being_saved: one: "1 hata kaydedilmesini engelledi:" other: "%{count}hata kaydedilmeyi engelledi:" - there_were_problems_with_the_following_fields: "Gösterilen alanlar ile ilgili sorun oluştu:" + there_were_problems_with_the_following_fields: "Belirtilen alanlar ile ilgili sorun oluştu:" errors: messages: blank: "boş olamaz" @@ -3251,7 +3255,7 @@ tr: display_as_placeholder: 'örn. 2 kg' display_name_placeholder: 'örn. Domates' autocomplete: - out_of_stock: "Stok tükendi" + out_of_stock: "Tükendi" producer_name: "Üretici" unit: "Birim" shared: diff --git a/db/migrate/20200623140437_fix_preferences_keys.rb b/db/migrate/20200623140437_fix_preferences_keys.rb new file mode 100644 index 0000000000..3f024ee278 --- /dev/null +++ b/db/migrate/20200623140437_fix_preferences_keys.rb @@ -0,0 +1,16 @@ +class FixPreferencesKeys < ActiveRecord::Migration + def up + unmigrated_preferences = Spree::Preference.exists?(['key NOT LIKE ?', '/%']) + return unless unmigrated_preferences + + new_preferences = Spree::Preference.where("key LIKE '/%'") + new_preferences.delete_all + + Spree::Preference.update_all("key = '/' || key") + + Rails.cache.clear + end + + def down + end +end diff --git a/db/migrate/20200624091611_make_timestamps_nullable.rb b/db/migrate/20200624091611_make_timestamps_nullable.rb new file mode 100644 index 0000000000..32ea61ac43 --- /dev/null +++ b/db/migrate/20200624091611_make_timestamps_nullable.rb @@ -0,0 +1,251 @@ +class MakeTimestampsNullable < ActiveRecord::Migration + def up + change_column_null :customers, :created_at, true + change_column_null :customers, :updated_at, true + change_column_null :delayed_jobs, :created_at, true + change_column_null :delayed_jobs, :updated_at, true + change_column_null :distributors_shipping_methods, :created_at, true + change_column_null :distributors_shipping_methods, :updated_at, true + change_column_null :enterprise_fees, :created_at, true + change_column_null :enterprise_fees, :updated_at, true + change_column_null :enterprises, :created_at, true + change_column_null :enterprises, :updated_at, true + change_column_null :exchange_fees, :created_at, true + change_column_null :exchange_fees, :updated_at, true + change_column_null :exchange_variants, :created_at, true + change_column_null :exchange_variants, :updated_at, true + change_column_null :exchanges, :created_at, true + change_column_null :exchanges, :updated_at, true + change_column_null :inventory_items, :created_at, true + change_column_null :inventory_items, :updated_at, true + change_column_null :order_cycle_schedules, :created_at, true + change_column_null :order_cycle_schedules, :updated_at, true + change_column_null :order_cycles, :created_at, true + change_column_null :order_cycles, :updated_at, true + change_column_null :producer_properties, :created_at, true + change_column_null :producer_properties, :updated_at, true + change_column_null :proxy_orders, :created_at, true + change_column_null :proxy_orders, :updated_at, true + change_column_null :schedules, :created_at, true + change_column_null :schedules, :updated_at, true + change_column_null :sessions, :created_at, true + change_column_null :sessions, :updated_at, true + change_column_null :spree_activators, :created_at, true + change_column_null :spree_activators, :updated_at, true + change_column_null :spree_addresses, :created_at, true + change_column_null :spree_addresses, :updated_at, true + change_column_null :spree_adjustments, :created_at, true + change_column_null :spree_adjustments, :updated_at, true + change_column_null :spree_calculators, :created_at, true + change_column_null :spree_calculators, :updated_at, true + change_column_null :spree_configurations, :created_at, true + change_column_null :spree_configurations, :updated_at, true + change_column_null :spree_credit_cards, :created_at, true + change_column_null :spree_credit_cards, :updated_at, true + change_column_null :spree_gateways, :created_at, true + change_column_null :spree_gateways, :updated_at, true + change_column_null :spree_inventory_units, :created_at, true + change_column_null :spree_inventory_units, :updated_at, true + change_column_null :spree_line_items, :created_at, true + change_column_null :spree_line_items, :updated_at, true + change_column_null :spree_log_entries, :created_at, true + change_column_null :spree_log_entries, :updated_at, true + change_column_null :spree_option_types, :created_at, true + change_column_null :spree_option_types, :updated_at, true + change_column_null :spree_option_values, :created_at, true + change_column_null :spree_option_values, :updated_at, true + change_column_null :spree_orders, :created_at, true + change_column_null :spree_orders, :updated_at, true + change_column_null :spree_payment_methods, :created_at, true + change_column_null :spree_payment_methods, :updated_at, true + change_column_null :spree_payments, :created_at, true + change_column_null :spree_payments, :updated_at, true + change_column_null :spree_preferences, :created_at, true + change_column_null :spree_preferences, :updated_at, true + change_column_null :spree_product_option_types, :created_at, true + change_column_null :spree_product_option_types, :updated_at, true + change_column_null :spree_product_properties, :created_at, true + change_column_null :spree_product_properties, :updated_at, true + change_column_null :spree_products, :created_at, true + change_column_null :spree_products, :updated_at, true + change_column_null :spree_promotion_rules, :created_at, true + change_column_null :spree_promotion_rules, :updated_at, true + change_column_null :spree_properties, :created_at, true + change_column_null :spree_properties, :updated_at, true + change_column_null :spree_return_authorizations, :created_at, true + change_column_null :spree_return_authorizations, :updated_at, true + change_column_null :spree_shipments, :created_at, true + change_column_null :spree_shipments, :updated_at, true + change_column_null :spree_shipping_categories, :created_at, true + change_column_null :spree_shipping_categories, :updated_at, true + change_column_null :spree_shipping_method_categories, :created_at, true + change_column_null :spree_shipping_method_categories, :updated_at, true + change_column_null :spree_shipping_methods, :created_at, true + change_column_null :spree_shipping_methods, :updated_at, true + change_column_null :spree_shipping_rates, :created_at, true + change_column_null :spree_shipping_rates, :updated_at, true + change_column_null :spree_skrill_transactions, :created_at, true + change_column_null :spree_skrill_transactions, :updated_at, true + change_column_null :spree_state_changes, :created_at, true + change_column_null :spree_state_changes, :updated_at, true + change_column_null :spree_stock_items, :created_at, true + change_column_null :spree_stock_items, :updated_at, true + change_column_null :spree_stock_locations, :created_at, true + change_column_null :spree_stock_locations, :updated_at, true + change_column_null :spree_stock_movements, :created_at, true + change_column_null :spree_stock_movements, :updated_at, true + change_column_null :spree_stock_transfers, :created_at, true + change_column_null :spree_stock_transfers, :updated_at, true + change_column_null :spree_tax_categories, :created_at, true + change_column_null :spree_tax_categories, :updated_at, true + change_column_null :spree_tax_rates, :created_at, true + change_column_null :spree_tax_rates, :updated_at, true + change_column_null :spree_taxonomies, :created_at, true + change_column_null :spree_taxonomies, :updated_at, true + change_column_null :spree_taxons, :created_at, true + change_column_null :spree_taxons, :updated_at, true + change_column_null :spree_tokenized_permissions, :created_at, true + change_column_null :spree_tokenized_permissions, :updated_at, true + change_column_null :spree_users, :created_at, true + change_column_null :spree_users, :updated_at, true + change_column_null :spree_zone_members, :created_at, true + change_column_null :spree_zone_members, :updated_at, true + change_column_null :spree_zones, :created_at, true + change_column_null :spree_zones, :updated_at, true + change_column_null :stripe_accounts, :created_at, true + change_column_null :stripe_accounts, :updated_at, true + change_column_null :subscription_line_items, :created_at, true + change_column_null :subscription_line_items, :updated_at, true + change_column_null :subscriptions, :created_at, true + change_column_null :subscriptions, :updated_at, true + change_column_null :tag_rules, :created_at, true + change_column_null :tag_rules, :updated_at, true + change_column_null :column_preferences, :created_at, true + change_column_null :column_preferences, :updated_at, true + end + + def down + change_column_null :customers, :created_at, false + change_column_null :customers, :updated_at, false + change_column_null :delayed_jobs, :created_at, false + change_column_null :delayed_jobs, :updated_at, false + change_column_null :distributors_shipping_methods, :created_at, false + change_column_null :distributors_shipping_methods, :updated_at, false + change_column_null :enterprise_fees, :created_at, false + change_column_null :enterprise_fees, :updated_at, false + change_column_null :enterprises, :created_at, false + change_column_null :enterprises, :updated_at, false + change_column_null :exchange_fees, :created_at, false + change_column_null :exchange_fees, :updated_at, false + change_column_null :exchange_variants, :created_at, false + change_column_null :exchange_variants, :updated_at, false + change_column_null :exchanges, :created_at, false + change_column_null :exchanges, :updated_at, false + change_column_null :inventory_items, :created_at, false + change_column_null :inventory_items, :updated_at, false + change_column_null :order_cycle_schedules, :created_at, false + change_column_null :order_cycle_schedules, :updated_at, false + change_column_null :order_cycles, :created_at, false + change_column_null :order_cycles, :updated_at, false + change_column_null :producer_properties, :created_at, false + change_column_null :producer_properties, :updated_at, false + change_column_null :proxy_orders, :created_at, false + change_column_null :proxy_orders, :updated_at, false + change_column_null :schedules, :created_at, false + change_column_null :schedules, :updated_at, false + change_column_null :sessions, :created_at, false + change_column_null :sessions, :updated_at, false + change_column_null :spree_activators, :created_at, false + change_column_null :spree_activators, :updated_at, false + change_column_null :spree_addresses, :created_at, false + change_column_null :spree_addresses, :updated_at, false + change_column_null :spree_adjustments, :created_at, false + change_column_null :spree_adjustments, :updated_at, false + change_column_null :spree_calculators, :created_at, false + change_column_null :spree_calculators, :updated_at, false + change_column_null :spree_configurations, :created_at, false + change_column_null :spree_configurations, :updated_at, false + change_column_null :spree_credit_cards, :created_at, false + change_column_null :spree_credit_cards, :updated_at, false + change_column_null :spree_gateways, :created_at, false + change_column_null :spree_gateways, :updated_at, false + change_column_null :spree_inventory_units, :created_at, false + change_column_null :spree_inventory_units, :updated_at, false + change_column_null :spree_line_items, :created_at, false + change_column_null :spree_line_items, :updated_at, false + change_column_null :spree_log_entries, :created_at, false + change_column_null :spree_log_entries, :updated_at, false + change_column_null :spree_option_types, :created_at, false + change_column_null :spree_option_types, :updated_at, false + change_column_null :spree_option_values, :created_at, false + change_column_null :spree_option_values, :updated_at, false + change_column_null :spree_orders, :created_at, false + change_column_null :spree_orders, :updated_at, false + change_column_null :spree_payment_methods, :created_at, false + change_column_null :spree_payment_methods, :updated_at, false + change_column_null :spree_payments, :created_at, false + change_column_null :spree_payments, :updated_at, false + change_column_null :spree_preferences, :created_at, false + change_column_null :spree_preferences, :updated_at, false + change_column_null :spree_product_option_types, :created_at, false + change_column_null :spree_product_option_types, :updated_at, false + change_column_null :spree_product_properties, :created_at, false + change_column_null :spree_product_properties, :updated_at, false + change_column_null :spree_products, :created_at, false + change_column_null :spree_products, :updated_at, false + change_column_null :spree_promotion_rules, :created_at, false + change_column_null :spree_promotion_rules, :updated_at, false + change_column_null :spree_properties, :created_at, false + change_column_null :spree_properties, :updated_at, false + change_column_null :spree_return_authorizations, :created_at, false + change_column_null :spree_return_authorizations, :updated_at, false + change_column_null :spree_shipments, :created_at, false + change_column_null :spree_shipments, :updated_at, false + change_column_null :spree_shipping_categories, :created_at, false + change_column_null :spree_shipping_categories, :updated_at, false + change_column_null :spree_shipping_method_categories, :created_at, false + change_column_null :spree_shipping_method_categories, :updated_at, false + change_column_null :spree_shipping_methods, :created_at, false + change_column_null :spree_shipping_methods, :updated_at, false + change_column_null :spree_shipping_rates, :created_at, false + change_column_null :spree_shipping_rates, :updated_at, false + change_column_null :spree_skrill_transactions, :created_at, false + change_column_null :spree_skrill_transactions, :updated_at, false + change_column_null :spree_state_changes, :created_at, false + change_column_null :spree_state_changes, :updated_at, false + change_column_null :spree_stock_items, :created_at, false + change_column_null :spree_stock_items, :updated_at, false + change_column_null :spree_stock_locations, :created_at, false + change_column_null :spree_stock_locations, :updated_at, false + change_column_null :spree_stock_movements, :created_at, false + change_column_null :spree_stock_movements, :updated_at, false + change_column_null :spree_stock_transfers, :created_at, false + change_column_null :spree_stock_transfers, :updated_at, false + change_column_null :spree_tax_categories, :created_at, false + change_column_null :spree_tax_categories, :updated_at, false + change_column_null :spree_tax_rates, :created_at, false + change_column_null :spree_tax_rates, :updated_at, false + change_column_null :spree_taxonomies, :created_at, false + change_column_null :spree_taxonomies, :updated_at, false + change_column_null :spree_taxons, :created_at, false + change_column_null :spree_taxons, :updated_at, false + change_column_null :spree_tokenized_permissions, :created_at, false + change_column_null :spree_tokenized_permissions, :updated_at, false + change_column_null :spree_users, :created_at, false + change_column_null :spree_users, :updated_at, false + change_column_null :spree_zone_members, :created_at, false + change_column_null :spree_zone_members, :updated_at, false + change_column_null :spree_zones, :created_at, false + change_column_null :spree_zones, :updated_at, false + change_column_null :stripe_accounts, :created_at, false + change_column_null :stripe_accounts, :updated_at, false + change_column_null :subscription_line_items, :created_at, false + change_column_null :subscription_line_items, :updated_at, false + change_column_null :subscriptions, :created_at, false + change_column_null :subscriptions, :updated_at, false + change_column_null :tag_rules, :created_at, false + change_column_null :tag_rules, :updated_at, false + change_column_null :column_preferences, :created_at, false + change_column_null :column_preferences, :updated_at, false + end +end diff --git a/db/schema.rb b/db/schema.rb index e2ec79428a..930e3e955d 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20200508101630) do +ActiveRecord::Schema.define(version: 20200624091611) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -273,8 +273,8 @@ ActiveRecord::Schema.define(version: 20200508101630) do add_index "inventory_items", ["enterprise_id", "variant_id"], name: "index_inventory_items_on_enterprise_id_and_variant_id", unique: true, using: :btree create_table "order_cycle_schedules", force: true do |t| - t.integer "order_cycle_id", null: false - t.integer "schedule_id", null: false + t.integer "order_cycle_id", null: false + t.integer "schedule_id", null: false t.datetime "created_at" t.datetime "updated_at" end @@ -570,8 +570,8 @@ ActiveRecord::Schema.define(version: 20200508101630) do add_index "spree_orders", ["completed_at", "user_id", "created_by_id", "created_at"], name: "spree_orders_completed_at_user_id_created_by_id_created_at_idx", using: :btree add_index "spree_orders", ["customer_id"], name: "index_spree_orders_on_customer_id", using: :btree - add_index "spree_orders", ["number"], name: "index_orders_on_number", using: :btree add_index "spree_orders", ["distributor_id"], name: "index_spree_orders_on_distributor_id", using: :btree + add_index "spree_orders", ["number"], name: "index_orders_on_number", using: :btree add_index "spree_orders", ["order_cycle_id"], name: "index_spree_orders_on_order_cycle_id", using: :btree add_index "spree_orders", ["user_id"], name: "index_spree_orders_on_user_id", using: :btree @@ -644,9 +644,9 @@ ActiveRecord::Schema.define(version: 20200508101630) do add_index "spree_preferences", ["key"], name: "index_spree_preferences_on_key", unique: true, using: :btree create_table "spree_prices", force: true do |t| - t.integer "variant_id", null: false - t.decimal "amount", precision: 8, scale: 2 - t.string "currency" + t.integer "variant_id", null: false + t.decimal "amount", precision: 8, scale: 2 + t.string "currency" t.datetime "deleted_at" end @@ -723,7 +723,7 @@ ActiveRecord::Schema.define(version: 20200508101630) do add_index "spree_products", ["permalink"], name: "index_products_on_permalink", using: :btree add_index "spree_products", ["permalink"], name: "permalink_idx_unique", unique: true, using: :btree add_index "spree_products", ["primary_taxon_id"], name: "index_spree_products_on_primary_taxon_id", using: :btree - add_index "spree_products", ["supplier_id"], name: "index_spree_products_on_supplier_id" + add_index "spree_products", ["supplier_id"], name: "index_spree_products_on_supplier_id", using: :btree create_table "spree_products_promotion_rules", id: false, force: true do |t| t.integer "product_id" @@ -1189,9 +1189,9 @@ ActiveRecord::Schema.define(version: 20200508101630) do add_index "variant_overrides", ["variant_id", "hub_id"], name: "index_variant_overrides_on_variant_id_and_hub_id", using: :btree create_table "versions", force: true do |t| - t.string "item_type", null: false - t.integer "item_id", null: false - t.string "event", null: false + t.string "item_type", null: false + t.integer "item_id", null: false + t.string "event", null: false t.string "whodunnit" t.text "object" t.datetime "created_at" diff --git a/engines/catalog/app/controllers/catalog/application_controller.rb b/engines/catalog/app/controllers/catalog/application_controller.rb index f92c5371fa..44da2f7147 100644 --- a/engines/catalog/app/controllers/catalog/application_controller.rb +++ b/engines/catalog/app/controllers/catalog/application_controller.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Catalog class ApplicationController < ActionController::Base protect_from_forgery with: :exception diff --git a/engines/catalog/catalog.gemspec b/engines/catalog/catalog.gemspec index 1dd0e4fed2..a20f6d0e04 100644 --- a/engines/catalog/catalog.gemspec +++ b/engines/catalog/catalog.gemspec @@ -1,3 +1,5 @@ +# frozen_string_literal: true + $LOAD_PATH.push File.expand_path('lib', __dir__) require "catalog/version" diff --git a/engines/catalog/config/routes.rb b/engines/catalog/config/routes.rb index 166898de46..6b9f597c94 100644 --- a/engines/catalog/config/routes.rb +++ b/engines/catalog/config/routes.rb @@ -1,2 +1,4 @@ +# frozen_string_literal: true + Openfoodnetwork::Application.routes.prepend do end diff --git a/engines/catalog/lib/catalog.rb b/engines/catalog/lib/catalog.rb index 9082a273df..3329f3d038 100644 --- a/engines/catalog/lib/catalog.rb +++ b/engines/catalog/lib/catalog.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "catalog/engine" module Catalog diff --git a/engines/catalog/lib/catalog/engine.rb b/engines/catalog/lib/catalog/engine.rb index d3a6e33bd7..a2c4e634bb 100644 --- a/engines/catalog/lib/catalog/engine.rb +++ b/engines/catalog/lib/catalog/engine.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Catalog class Engine < ::Rails::Engine isolate_namespace Catalog diff --git a/engines/catalog/lib/catalog/version.rb b/engines/catalog/lib/catalog/version.rb index 288c406a2b..e1b6f7298d 100644 --- a/engines/catalog/lib/catalog/version.rb +++ b/engines/catalog/lib/catalog/version.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Catalog - VERSION = "0.0.1".freeze + VERSION = "0.0.1" end diff --git a/engines/catalog/spec/spec_helper.rb b/engines/catalog/spec/spec_helper.rb index 9cfd0bc717..3492f4f944 100644 --- a/engines/catalog/spec/spec_helper.rb +++ b/engines/catalog/spec/spec_helper.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "../../spec/spec_helper.rb" -Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f } +Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].sort.each { |f| require f } diff --git a/engines/order_management/app/controllers/order_management/reports/enterprise_fee_summaries_controller.rb b/engines/order_management/app/controllers/order_management/reports/enterprise_fee_summaries_controller.rb index 08b6c602c5..7cc1376034 100644 --- a/engines/order_management/app/controllers/order_management/reports/enterprise_fee_summaries_controller.rb +++ b/engines/order_management/app/controllers/order_management/reports/enterprise_fee_summaries_controller.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module OrderManagement module Reports class EnterpriseFeeSummariesController < Spree::Admin::BaseController diff --git a/engines/order_management/app/services/order_management/subscriptions/payment_setup.rb b/engines/order_management/app/services/order_management/subscriptions/payment_setup.rb index 6d90236466..fea4da84e5 100644 --- a/engines/order_management/app/services/order_management/subscriptions/payment_setup.rb +++ b/engines/order_management/app/services/order_management/subscriptions/payment_setup.rb @@ -11,7 +11,7 @@ module OrderManagement payment = create_payment return if @order.errors.any? - payment.update_attributes(amount: @order.outstanding_balance) + payment.update(amount: @order.outstanding_balance) payment end diff --git a/engines/order_management/app/services/order_management/subscriptions/stripe_payment_setup.rb b/engines/order_management/app/services/order_management/subscriptions/stripe_payment_setup.rb index 37e3a097f3..6a5cf33acb 100644 --- a/engines/order_management/app/services/order_management/subscriptions/stripe_payment_setup.rb +++ b/engines/order_management/app/services/order_management/subscriptions/stripe_payment_setup.rb @@ -45,7 +45,7 @@ module OrderManagement end def use_saved_credit_card - @payment.update_attributes(source: saved_credit_card) + @payment.update(source: saved_credit_card) end end end diff --git a/engines/order_management/spec/controllers/order_management/reports/enterprise_fee_summaries_controller_spec.rb b/engines/order_management/spec/controllers/order_management/reports/enterprise_fee_summaries_controller_spec.rb index 3282bd7258..da66c005f4 100644 --- a/engines/order_management/spec/controllers/order_management/reports/enterprise_fee_summaries_controller_spec.rb +++ b/engines/order_management/spec/controllers/order_management/reports/enterprise_fee_summaries_controller_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "spec_helper" describe OrderManagement::Reports::EnterpriseFeeSummariesController, type: :controller do diff --git a/engines/order_management/spec/features/order_management/reports/enterprise_fee_summaries_spec.rb b/engines/order_management/spec/features/order_management/reports/enterprise_fee_summaries_spec.rb index 7930ea75a3..553d78d093 100644 --- a/engines/order_management/spec/features/order_management/reports/enterprise_fee_summaries_spec.rb +++ b/engines/order_management/spec/features/order_management/reports/enterprise_fee_summaries_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "spec_helper" feature "enterprise fee summaries", js: true do diff --git a/engines/order_management/spec/services/order_management/subscriptions/estimator_spec.rb b/engines/order_management/spec/services/order_management/subscriptions/estimator_spec.rb index 63032465d6..9e7bd15c06 100644 --- a/engines/order_management/spec/services/order_management/subscriptions/estimator_spec.rb +++ b/engines/order_management/spec/services/order_management/subscriptions/estimator_spec.rb @@ -13,12 +13,12 @@ module OrderManagement let(:estimator) { Estimator.new(subscription) } before do - sli1.update_attributes(price_estimate: 4.0) - sli2.update_attributes(price_estimate: 5.0) - sli3.update_attributes(price_estimate: 6.0) - sli1.variant.update_attributes(price: 1.0) - sli2.variant.update_attributes(price: 2.0) - sli3.variant.update_attributes(price: 3.0) + sli1.update(price_estimate: 4.0) + sli2.update(price_estimate: 5.0) + sli3.update(price_estimate: 6.0) + sli1.variant.update(price: 1.0) + sli2.variant.update(price: 2.0) + sli3.variant.update(price: 3.0) # Simulating assignment of attrs from params sli1.assign_attributes(price_estimate: 7.0) @@ -91,9 +91,9 @@ module OrderManagement before do allow(estimator).to receive(:assign_price_estimates) - sli1.update_attributes(price_estimate: 4.0) - sli2.update_attributes(price_estimate: 5.0) - sli3.update_attributes(price_estimate: 6.0) + sli1.update(price_estimate: 4.0) + sli2.update(price_estimate: 5.0) + sli3.update(price_estimate: 6.0) end context "using flat rate calculators" do diff --git a/engines/order_management/spec/services/order_management/subscriptions/proxy_order_syncer_spec.rb b/engines/order_management/spec/services/order_management/subscriptions/proxy_order_syncer_spec.rb index 8af99f27f5..45fbdf7df9 100644 --- a/engines/order_management/spec/services/order_management/subscriptions/proxy_order_syncer_spec.rb +++ b/engines/order_management/spec/services/order_management/subscriptions/proxy_order_syncer_spec.rb @@ -144,7 +144,7 @@ module OrderManagement context "for an oc included in the relevant schedule" do context "and the proxy order has already been placed" do - before { proxy_order.update_attributes(placed_at: 5.minutes.ago) } + before { proxy_order.update(placed_at: 5.minutes.ago) } context "the oc is closed (ie. closed before opens_at)" do let(:oc) { closed_oc } @@ -292,7 +292,7 @@ module OrderManagement end context "and the proxy order has already been placed" do - before { proxy_order.update_attributes(placed_at: 5.minutes.ago) } + before { proxy_order.update(placed_at: 5.minutes.ago) } context "the oc is closed (ie. closed before opens_at)" do let(:oc) { closed_oc } diff --git a/engines/web/spec/features/consumer/cookies_spec.rb b/engines/web/spec/features/consumer/cookies_spec.rb index 19ec64eba0..5b55ece1fb 100644 --- a/engines/web/spec/features/consumer/cookies_spec.rb +++ b/engines/web/spec/features/consumer/cookies_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' feature "Cookies", js: true do diff --git a/lib/discourse/single_sign_on.rb b/lib/discourse/single_sign_on.rb index 31d5d06989..7f44b352a2 100644 --- a/lib/discourse/single_sign_on.rb +++ b/lib/discourse/single_sign_on.rb @@ -92,10 +92,8 @@ module Discourse payload[k] = val end - if @custom_fields - @custom_fields.each do |k, v| - payload["custom.#{k}"] = v.to_s - end + @custom_fields&.each do |k, v| + payload["custom.#{k}"] = v.to_s end Rack::Utils.build_query(payload) diff --git a/lib/open_food_network/order_cycle_form_applicator.rb b/lib/open_food_network/order_cycle_form_applicator.rb index f42fd427a9..960508f06d 100644 --- a/lib/open_food_network/order_cycle_form_applicator.rb +++ b/lib/open_food_network/order_cycle_form_applicator.rb @@ -83,7 +83,7 @@ module OpenFoodNetwork remove_unauthorized_exchange_attributes(exchange, attrs) variant_ids = attrs.delete :variant_ids - exchange.update_attributes!(attrs) + exchange.update!(attrs) ExchangeVariantBulkUpdater.new(exchange).update!(variant_ids) unless variant_ids.nil? @touched_exchanges << exchange diff --git a/lib/open_food_network/orders_and_fulfillments_report.rb b/lib/open_food_network/orders_and_fulfillments_report.rb index f386be439a..ed7850d644 100644 --- a/lib/open_food_network/orders_and_fulfillments_report.rb +++ b/lib/open_food_network/orders_and_fulfillments_report.rb @@ -27,6 +27,7 @@ module OpenFoodNetwork def table_items return [] unless @render_table + report_line_items.list(report.line_item_includes) end @@ -92,6 +93,7 @@ module OpenFoodNetwork def order_permissions return @order_permissions unless @order_permissions.nil? + @order_permissions = ::Permissions::Order.new(@user, options[:q]) end diff --git a/lib/open_food_network/packing_report.rb b/lib/open_food_network/packing_report.rb index cecec8cff8..88a3582083 100644 --- a/lib/open_food_network/packing_report.rb +++ b/lib/open_food_network/packing_report.rb @@ -43,6 +43,7 @@ module OpenFoodNetwork def table_items return [] unless @render_table + report_line_items.list(line_item_includes) end @@ -128,6 +129,7 @@ module OpenFoodNetwork def order_permissions return @order_permissions unless @order_permissions.nil? + @order_permissions = ::Permissions::Order.new(@user, @params[:q]) end diff --git a/lib/open_food_network/reports/line_items.rb b/lib/open_food_network/reports/line_items.rb index 93c5fba9de..e086fe5c2b 100644 --- a/lib/open_food_network/reports/line_items.rb +++ b/lib/open_food_network/reports/line_items.rb @@ -24,8 +24,8 @@ module OpenFoodNetwork editable_line_items = editable_line_items(line_items) - line_items.select{ |li| - !editable_line_items.include? li + line_items.reject{ |li| + editable_line_items.include? li }.each do |line_item| # TODO We should really be hiding customer code here too, but until we # have an actual association between order and customer, it's a bit tricky diff --git a/lib/open_food_network/xero_invoices_report.rb b/lib/open_food_network/xero_invoices_report.rb index 6a05c3e296..2d6bc80f71 100644 --- a/lib/open_food_network/xero_invoices_report.rb +++ b/lib/open_food_network/xero_invoices_report.rb @@ -175,8 +175,8 @@ module OpenFoodNetwork adjustment.adjustable.is_a?(Spree::Order) ? adjustment.adjustable : nil end - def invoice_number_for(order, i) - @opts[:initial_invoice_number] ? @opts[:initial_invoice_number].to_i + i : order.number + def invoice_number_for(order, idx) + @opts[:initial_invoice_number] ? @opts[:initial_invoice_number].to_i + idx : order.number end def total_untaxable_products(order) diff --git a/lib/stripe/profile_storer.rb b/lib/stripe/profile_storer.rb index eb5212a1d2..f3176fcf9a 100644 --- a/lib/stripe/profile_storer.rb +++ b/lib/stripe/profile_storer.rb @@ -15,7 +15,7 @@ module Stripe if response.success? attrs = source_attrs_from(response) - @payment.source.update_attributes!(attrs) + @payment.source.update!(attrs) else @payment.__send__(:gateway_error, response.message) end diff --git a/lib/tasks/sample_data/order_factory.rb b/lib/tasks/sample_data/order_factory.rb index bc5c9f3675..29d4cf03c6 100644 --- a/lib/tasks/sample_data/order_factory.rb +++ b/lib/tasks/sample_data/order_factory.rb @@ -73,7 +73,7 @@ class OrderFactory end def delivery_shipping_method_id - @distributor.shipping_methods.find_by(name: "Home delivery").id + @distributor.shipping_methods.find_by(name: "Home delivery Fredo's Farm Hub").id end def order_address diff --git a/spec/controllers/admin/proxy_orders_controller_spec.rb b/spec/controllers/admin/proxy_orders_controller_spec.rb index d827732558..1d612e2c57 100644 --- a/spec/controllers/admin/proxy_orders_controller_spec.rb +++ b/spec/controllers/admin/proxy_orders_controller_spec.rb @@ -27,7 +27,7 @@ describe Admin::ProxyOrdersController, type: :controller do context 'as an enterprise user' do context "without authorisation" do let!(:shop2) { create(:distributor_enterprise) } - before { shop2.update_attributes(owner: user) } + before { shop2.update(owner: user) } it 'redirects to unauthorized' do spree_put :cancel, params @@ -36,7 +36,7 @@ describe Admin::ProxyOrdersController, type: :controller do end context "with authorisation" do - before { shop.update_attributes(owner: user) } + before { shop.update(owner: user) } context "when cancellation succeeds" do it 'renders the cancelled proxy_order as json' do @@ -49,7 +49,7 @@ describe Admin::ProxyOrdersController, type: :controller do end context "when cancellation fails" do - before { order_cycle.update_attributes(orders_close_at: 1.day.ago) } + before { order_cycle.update(orders_close_at: 1.day.ago) } it "shows an error" do spree_get :cancel, params @@ -96,7 +96,7 @@ describe Admin::ProxyOrdersController, type: :controller do context 'as an enterprise user' do context "without authorisation" do let!(:shop2) { create(:distributor_enterprise) } - before { shop2.update_attributes(owner: user) } + before { shop2.update(owner: user) } it 'redirects to unauthorized' do spree_put :resume, params @@ -105,7 +105,7 @@ describe Admin::ProxyOrdersController, type: :controller do end context "with authorisation" do - before { shop.update_attributes(owner: user) } + before { shop.update(owner: user) } context "when resuming succeeds" do it 'renders the resumed proxy_order as json' do @@ -118,7 +118,7 @@ describe Admin::ProxyOrdersController, type: :controller do end context "when resuming fails" do - before { order_cycle.update_attributes(orders_close_at: 1.day.ago) } + before { order_cycle.update(orders_close_at: 1.day.ago) } it "shows an error" do spree_get :resume, params diff --git a/spec/controllers/admin/subscriptions_controller_spec.rb b/spec/controllers/admin/subscriptions_controller_spec.rb index 445ec70ff7..c7f0e207a4 100644 --- a/spec/controllers/admin/subscriptions_controller_spec.rb +++ b/spec/controllers/admin/subscriptions_controller_spec.rb @@ -23,7 +23,7 @@ describe Admin::SubscriptionsController, type: :controller do end context 'as an enterprise user' do - before { shop.update_attributes(owner: user) } + before { shop.update(owner: user) } let!(:not_enabled_shop) { create(:distributor_enterprise, owner: user) } context "where I manage a shop that is set up for subscriptions" do @@ -60,7 +60,7 @@ describe Admin::SubscriptionsController, type: :controller do end context 'as an enterprise user' do - before { shop.update_attributes(owner: user) } + before { shop.update(owner: user) } let!(:shop2) { create(:distributor_enterprise, owner: user) } let!(:subscription2) { create(:subscription, shop: shop2) } @@ -357,7 +357,7 @@ describe Admin::SubscriptionsController, type: :controller do end context 'where the specified variants are available from the shop' do - before { outgoing_exchange.update_attributes(variants: [variant1, variant2]) } + before { outgoing_exchange.update(variants: [variant1, variant2]) } it 'creates subscription line items for the subscription' do expect{ spree_post :update, params }.to change{ subscription.subscription_line_items.count }.by(1) @@ -397,7 +397,7 @@ describe Admin::SubscriptionsController, type: :controller do context 'as an enterprise user' do context "without authorisation" do let!(:shop2) { create(:distributor_enterprise) } - before { shop2.update_attributes(owner: user) } + before { shop2.update(owner: user) } it 'redirects to unauthorized' do spree_put :cancel, params @@ -406,7 +406,7 @@ describe Admin::SubscriptionsController, type: :controller do end context "with authorisation" do - before { shop.update_attributes(owner: user) } + before { shop.update(owner: user) } context "when at least one associated order is still 'open'" do let(:order_cycle) { subscription.order_cycles.first } @@ -496,7 +496,7 @@ describe Admin::SubscriptionsController, type: :controller do context 'as an enterprise user' do context "without authorisation" do let!(:shop2) { create(:distributor_enterprise) } - before { shop2.update_attributes(owner: user) } + before { shop2.update(owner: user) } it 'redirects to unauthorized' do spree_put :pause, params @@ -505,7 +505,7 @@ describe Admin::SubscriptionsController, type: :controller do end context "with authorisation" do - before { shop.update_attributes(owner: user) } + before { shop.update(owner: user) } context "when at least one associated order is still 'open'" do let(:order_cycle) { subscription.order_cycles.first } @@ -595,7 +595,7 @@ describe Admin::SubscriptionsController, type: :controller do context 'as an enterprise user' do context "without authorisation" do let!(:shop2) { create(:distributor_enterprise) } - before { shop2.update_attributes(owner: user) } + before { shop2.update(owner: user) } it 'redirects to unauthorized' do spree_put :unpause, params @@ -604,7 +604,7 @@ describe Admin::SubscriptionsController, type: :controller do end context "with authorisation" do - before { shop.update_attributes(owner: user) } + before { shop.update(owner: user) } context "when at least one order in an open order cycle is 'complete'" do let(:order_cycle) { subscription.order_cycles.first } diff --git a/spec/controllers/api/enterprise_fees_controller_spec.rb b/spec/controllers/api/enterprise_fees_controller_spec.rb index e528983579..8991e5fcde 100644 --- a/spec/controllers/api/enterprise_fees_controller_spec.rb +++ b/spec/controllers/api/enterprise_fees_controller_spec.rb @@ -17,7 +17,7 @@ module Api describe "destroy" do it "removes the fee" do expect { spree_delete :destroy, id: unreferenced_fee.id, format: :json } - .to change { EnterpriseFee.count }.by -1 + .to change { EnterpriseFee.count }.by(-1) end end end diff --git a/spec/controllers/api/enterprises_controller_spec.rb b/spec/controllers/api/enterprises_controller_spec.rb index 1b3382274e..b6e42967dc 100644 --- a/spec/controllers/api/enterprises_controller_spec.rb +++ b/spec/controllers/api/enterprises_controller_spec.rb @@ -63,7 +63,7 @@ describe Api::EnterprisesController, type: :controller do before do allow(Enterprise) .to receive(:find_by).with({ permalink: enterprise.id.to_s }) { enterprise } - allow(enterprise).to receive(:update_attributes).and_return(true) + allow(enterprise).to receive(:update).and_return(true) end it "I can update enterprise image" do @@ -83,8 +83,6 @@ describe Api::EnterprisesController, type: :controller do end describe "submitting a valid image" do - before { allow(enterprise).to receive(:update_attributes).and_return(true) } - it "I can't update enterprise image" do api_post :update_image, logo: 'a logo', id: enterprise.id assert_unauthorized! diff --git a/spec/controllers/api/orders_controller_spec.rb b/spec/controllers/api/orders_controller_spec.rb index 69438ec2da..726756734d 100644 --- a/spec/controllers/api/orders_controller_spec.rb +++ b/spec/controllers/api/orders_controller_spec.rb @@ -69,7 +69,6 @@ module Api it "retrieves a list of orders with appropriate attributes, including line items with appropriate attributes" do - returns_orders(json_response) end @@ -213,7 +212,7 @@ module Api before { allow(controller).to receive(:spree_current_user) { order.distributor.owner } } it "can view an order not in a standard state" do - order.update_attributes(completed_at: nil, state: 'shipped') + order.update(completed_at: nil, state: 'shipped') get :show, id: order.number expect_order end diff --git a/spec/controllers/base_controller_spec.rb b/spec/controllers/base_controller_spec.rb index 43feeaf6c3..ee7dcb4bcc 100644 --- a/spec/controllers/base_controller_spec.rb +++ b/spec/controllers/base_controller_spec.rb @@ -20,6 +20,6 @@ describe BaseController, type: :controller do expect(session[:expired_order_cycle_id]).to eq oc.id expect(response).to redirect_to root_url - expect(flash[:info]).to eq "The order cycle you've selected has just closed. Please try again!" + expect(flash[:info]).to eq I18n.t('order_cycle_closed') end end diff --git a/spec/controllers/checkout_controller_spec.rb b/spec/controllers/checkout_controller_spec.rb index a07f37ff3d..ecb18971db 100644 --- a/spec/controllers/checkout_controller_spec.rb +++ b/spec/controllers/checkout_controller_spec.rb @@ -33,7 +33,7 @@ describe CheckoutController, type: :controller do get :edit expect(response).to redirect_to root_url - expect(flash[:info]).to eq("The hub you have selected is temporarily closed for orders. Please try again later.") + expect(flash[:info]).to eq(I18n.t('order_cycles_closed_for_hub')) end describe "redirection to cart and stripe" do @@ -102,13 +102,13 @@ describe CheckoutController, type: :controller do it "set shipping_address_from_distributor when re-rendering edit" do expect(order.updater).to receive(:shipping_address_from_distributor) - allow(order).to receive(:update_attributes).and_return false + allow(order).to receive(:update).and_return false spree_post :update, format: :json, order: {} end it "set shipping_address_from_distributor when the order state cannot be advanced" do expect(order.updater).to receive(:shipping_address_from_distributor) - allow(order).to receive(:update_attributes).and_return true + allow(order).to receive(:update).and_return true allow(order).to receive(:next).and_return false spree_post :update, format: :json, order: {} end @@ -120,7 +120,7 @@ describe CheckoutController, type: :controller do # stub order and OrderCompletionReset allow(OrderCompletionReset).to receive(:new).with(controller, order) { reset_order_service } allow(reset_order_service).to receive(:call) - allow(order).to receive(:update_attributes).and_return true + allow(order).to receive(:update).and_return true allow(controller).to receive(:current_order).and_return order # make order workflow pass through delivery @@ -139,7 +139,7 @@ describe CheckoutController, type: :controller do end it "does not send shipping_method_id to the order model as an attribute" do - expect(order).to receive(:update_attributes).with({}) + expect(order).to receive(:update).with({}) spree_post :update, order: { shipping_method_id: test_shipping_method_id } end @@ -153,7 +153,7 @@ describe CheckoutController, type: :controller do before do order.state = 'complete' order.save! - allow(order).to receive(:update_attributes).and_return(true) + allow(order).to receive(:update).and_return(true) allow(order).to receive(:next).and_return(true) allow(order).to receive(:set_distributor!).and_return(true) end @@ -204,7 +204,7 @@ describe CheckoutController, type: :controller do end it "returns errors and flash if order.next fails" do - allow(order).to receive(:update_attributes).and_return true + allow(order).to receive(:update).and_return true allow(order).to receive(:next).and_return false spree_post :update, format: :json, order: {} expect(response.body).to eq({ errors: assigns[:order].errors, flash: { error: "Payment could not be processed, please check the details you entered" } }.to_json) @@ -214,7 +214,7 @@ describe CheckoutController, type: :controller do allow(OrderCompletionReset).to receive(:new).with(controller, order) { reset_order_service } expect(reset_order_service).to receive(:call) - allow(order).to receive(:update_attributes).and_return true + allow(order).to receive(:update).and_return true allow(order).to receive(:state).and_return "complete" spree_post :update, format: :json, order: {} @@ -223,11 +223,11 @@ describe CheckoutController, type: :controller do end it "returns an error on unexpected failure" do - allow(order).to receive(:update_attributes).and_raise + allow(order).to receive(:update).and_raise spree_post :update, format: :json, order: {} expect(response.status).to eq(400) - expect(response.body).to eq({ errors: {}, flash: {error: I18n.t("checkout.failed")} }.to_json) + expect(response.body).to eq({ errors: {}, flash: { error: I18n.t("checkout.failed") } }.to_json) end describe "stale object handling" do @@ -235,7 +235,7 @@ describe CheckoutController, type: :controller do allow(OrderCompletionReset).to receive(:new).with(controller, order) { reset_order_service } expect(reset_order_service).to receive(:call) - allow(order).to receive(:update_attributes).and_return true + allow(order).to receive(:update).and_return true allow(controller).to receive(:state_callback) # The first time, raise a StaleObjectError. The second time, succeed. @@ -251,7 +251,7 @@ describe CheckoutController, type: :controller do end it "tries a maximum of 3 times before giving up and returning an error" do - allow(order).to receive(:update_attributes).and_return true + allow(order).to receive(:update).and_return true allow(order).to receive(:next) { raise ActiveRecord::StaleObjectError.new(Spree::Variant.new, 'update') } spree_post :update, format: :json, order: {} @@ -265,7 +265,7 @@ describe CheckoutController, type: :controller do allow(controller).to receive(:current_distributor) { distributor } allow(controller).to receive(:current_order_cycle) { order_cycle } allow(controller).to receive(:current_order) { order } - allow(order).to receive(:update_attributes) { true } + allow(order).to receive(:update) { true } allow(order).to receive(:state) { "payment" } end diff --git a/spec/controllers/enterprises_controller_spec.rb b/spec/controllers/enterprises_controller_spec.rb index f67972563f..c33815d1b1 100644 --- a/spec/controllers/enterprises_controller_spec.rb +++ b/spec/controllers/enterprises_controller_spec.rb @@ -148,16 +148,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 + xhr :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 + xhr :get, :check_permalink, permalink: 'map', format: :js expect(response.status).to be 409 - spree_get :check_permalink, permalink: '', format: :js + xhr :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 116a05ef2f..815903abc0 100644 --- a/spec/controllers/line_items_controller_spec.rb +++ b/spec/controllers/line_items_controller_spec.rb @@ -132,7 +132,7 @@ describe LineItemsController, type: :controller do let!(:exchange) { create(:exchange, incoming: true, sender: variant.product.supplier, receiver: order_cycle.coordinator, variants: [variant], enterprise_fees: [enterprise_fee]) } let!(:order) do order = create(:completed_order_with_totals, user: user, distributor: distributor, order_cycle: order_cycle, line_items_count: 1) - order.reload.line_items.first.update_attributes(variant_id: variant.id) + order.reload.line_items.first.update(variant_id: variant.id) while !order.completed? do break unless order.next! end order.update_distribution_charge! order diff --git a/spec/controllers/spree/admin/payment_methods_controller_spec.rb b/spec/controllers/spree/admin/payment_methods_controller_spec.rb index ff23298c44..dfc7dd307e 100644 --- a/spec/controllers/spree/admin/payment_methods_controller_spec.rb +++ b/spec/controllers/spree/admin/payment_methods_controller_spec.rb @@ -69,7 +69,7 @@ module Spree end context "as a user that manages the existing stripe account holder" do - before { enterprise2.update_attributes!(owner_id: user.id) } + before { enterprise2.update!(owner_id: user.id) } it "allows the stripe account holder to be updated" do spree_put :update, params diff --git a/spec/controllers/spree/admin/payments_controller_spec.rb b/spec/controllers/spree/admin/payments_controller_spec.rb index aeb9156ef2..6c7c2eeb50 100644 --- a/spec/controllers/spree/admin/payments_controller_spec.rb +++ b/spec/controllers/spree/admin/payments_controller_spec.rb @@ -255,7 +255,7 @@ describe Spree::Admin::PaymentsController, type: :controller do expect(payment.reload.state).to eq 'completed' order.reload expect(order.payment_total).to eq order.total + 5 - expect(order.outstanding_balance).to eq -5 + expect(order.outstanding_balance).to eq(-5) expect(flash[:error]).to eq "Bup-bow!" end end diff --git a/spec/controllers/spree/orders_controller_spec.rb b/spec/controllers/spree/orders_controller_spec.rb index 783c868366..cee76bdc39 100644 --- a/spec/controllers/spree/orders_controller_spec.rb +++ b/spec/controllers/spree/orders_controller_spec.rb @@ -116,7 +116,7 @@ describe Spree::OrdersController, type: :controller do spree_get :edit expect(response).to redirect_to root_url - expect(flash[:info]).to eq("The hub you have selected is temporarily closed for orders. Please try again later.") + expect(flash[:info]).to eq(I18n.t('order_cycles_closed_for_hub')) end describe "when an item is in the cart" do @@ -155,7 +155,7 @@ describe Spree::OrdersController, type: :controller do describe "when an item has insufficient stock" do before do - variant.update_attributes! on_hand: 3 + variant.update! on_hand: 3 end it "displays a flash message when we view the cart" do @@ -279,7 +279,7 @@ describe Spree::OrdersController, type: :controller do let!(:exchange) { create(:exchange, incoming: true, sender: variant.product.supplier, receiver: order_cycle.coordinator, variants: [variant], enterprise_fees: [enterprise_fee]) } let!(:order) do order = create(:completed_order_with_totals, line_items_count: 1, user: user, distributor: distributor, order_cycle: order_cycle) - order.reload.line_items.first.update_attributes(variant_id: variant.id) + order.reload.line_items.first.update(variant_id: variant.id) while !order.completed? do break unless order.next! end order.update_distribution_charge! order diff --git a/spec/controllers/spree/paypal_controller_spec.rb b/spec/controllers/spree/paypal_controller_spec.rb index 90f97fcb7d..9f630e892d 100644 --- a/spec/controllers/spree/paypal_controller_spec.rb +++ b/spec/controllers/spree/paypal_controller_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' module Spree diff --git a/spec/factories.rb b/spec/factories.rb index d13757cb2a..ad3c804c92 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -44,9 +44,7 @@ FactoryBot.define do subscription order_cycle { subscription.order_cycles.first } before(:create) do |proxy_order, _proxy| - if proxy_order.order - proxy_order.order.update_attribute(:order_cycle_id, proxy_order.order_cycle_id) - end + proxy_order.order&.update_attribute(:order_cycle_id, proxy_order.order_cycle_id) end end diff --git a/spec/factories/enterprise_factory.rb b/spec/factories/enterprise_factory.rb index 5382e0fd94..2504ccb815 100644 --- a/spec/factories/enterprise_factory.rb +++ b/spec/factories/enterprise_factory.rb @@ -17,7 +17,7 @@ FactoryBot.define do proxy.users.each do |user| enterprise.users << user unless enterprise.users.include?(user) end - enterprise.update_attributes logo: proxy.logo, promo_image: proxy.promo_image + enterprise.update logo: proxy.logo, promo_image: proxy.promo_image end end diff --git a/spec/features/admin/order_cycles/complex_creating_specific_time_spec.rb b/spec/features/admin/order_cycles/complex_creating_specific_time_spec.rb index 69774fb043..39130fa434 100644 --- a/spec/features/admin/order_cycles/complex_creating_specific_time_spec.rb +++ b/spec/features/admin/order_cycles/complex_creating_specific_time_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' feature ' diff --git a/spec/features/admin/order_cycles/complex_editing_exchange_same_enterprise_spec.rb b/spec/features/admin/order_cycles/complex_editing_exchange_same_enterprise_spec.rb index d6ef3554fa..484dd21f40 100644 --- a/spec/features/admin/order_cycles/complex_editing_exchange_same_enterprise_spec.rb +++ b/spec/features/admin/order_cycles/complex_editing_exchange_same_enterprise_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' feature ' diff --git a/spec/features/admin/order_cycles/complex_editing_spec.rb b/spec/features/admin/order_cycles/complex_editing_spec.rb index 0b6b9d8ac0..72eb521554 100644 --- a/spec/features/admin/order_cycles/complex_editing_spec.rb +++ b/spec/features/admin/order_cycles/complex_editing_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' feature ' diff --git a/spec/features/admin/order_cycles/complex_updating_specific_time_spec.rb b/spec/features/admin/order_cycles/complex_updating_specific_time_spec.rb index 2e569fc0ce..258caa1080 100644 --- a/spec/features/admin/order_cycles/complex_updating_specific_time_spec.rb +++ b/spec/features/admin/order_cycles/complex_updating_specific_time_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' feature ' diff --git a/spec/features/admin/order_cycles/list_spec.rb b/spec/features/admin/order_cycles/list_spec.rb index ba5f2d4048..d675984dd8 100644 --- a/spec/features/admin/order_cycles/list_spec.rb +++ b/spec/features/admin/order_cycles/list_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' feature ' diff --git a/spec/features/admin/order_cycles/simple_spec.rb b/spec/features/admin/order_cycles/simple_spec.rb index 979dc0be8b..0d6872c19c 100644 --- a/spec/features/admin/order_cycles/simple_spec.rb +++ b/spec/features/admin/order_cycles/simple_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' feature ' @@ -300,11 +302,11 @@ feature ' # Incoming exchange ex_in = oc.exchanges.where(sender_id: supplier_managed, receiver_id: distributor_managed, incoming: true).first - ex_in.update_attributes(variant_ids: [v1.id, v2.id]) + ex_in.update(variant_ids: [v1.id, v2.id]) # Outgoing exchange ex_out = oc.exchanges.where(sender_id: distributor_managed, receiver_id: distributor_managed, incoming: false).first - ex_out.update_attributes(variant_ids: [v1.id, v2.id]) + ex_out.update(variant_ids: [v1.id, v2.id]) # Stub editable_variants_for_outgoing_exchanges method so we can test permissions serializer = Api::Admin::OrderCycleSerializer.new(oc, current_user: new_user) @@ -368,11 +370,11 @@ feature ' # Incoming exchange ex_in = oc.exchanges.where(sender_id: supplier_managed, receiver_id: distributor_managed, incoming: true).first - ex_in.update_attributes(variant_ids: [v1.id, v2.id]) + ex_in.update(variant_ids: [v1.id, v2.id]) # Outgoing exchange ex_out = oc.exchanges.where(sender_id: distributor_managed, receiver_id: my_distributor, incoming: false).first - ex_out.update_attributes(variant_ids: [v1.id, v2.id]) + ex_out.update(variant_ids: [v1.id, v2.id]) # Stub editable_variants_for_incoming_exchanges method so we can test permissions serializer = Api::Admin::OrderCycleSerializer.new(oc, current_user: new_user) @@ -503,7 +505,7 @@ feature ' fee = create(:enterprise_fee, name: 'my fee', enterprise: enterprise) oc = create(:simple_order_cycle, suppliers: [enterprise], coordinator: enterprise, distributors: [enterprise], variants: [v1], coordinator_fees: [fee]) ex = oc.exchanges.outgoing.first - ex.update_attributes! pickup_time: 'pickup time', pickup_instructions: 'pickup instructions' + ex.update! pickup_time: 'pickup time', pickup_instructions: 'pickup instructions' # When I edit it quick_login_as_admin @@ -536,7 +538,7 @@ feature ' fee2 = create(:enterprise_fee, name: 'that fee', enterprise: enterprise) oc = create(:simple_order_cycle, suppliers: [enterprise], coordinator: enterprise, distributors: [enterprise], variants: [v1], coordinator_fees: [fee1]) ex = oc.exchanges.outgoing.first - ex.update_attributes! pickup_time: 'pickup time', pickup_instructions: 'pickup instructions' + ex.update! pickup_time: 'pickup time', pickup_instructions: 'pickup instructions' # When I edit it quick_login_as_admin @@ -613,4 +615,4 @@ feature ' page.find("table.exchanges tr.supplier-#{supplier.id} td.products").click check "order_cycle_incoming_exchange_#{exchange_no}_variants_#{variant.id}" end -end \ No newline at end of file +end diff --git a/spec/features/admin/order_cycles_complex_nav_check_spec.rb b/spec/features/admin/order_cycles_complex_nav_check_spec.rb index 8e6e4366fc..4d89e16bb1 100644 --- a/spec/features/admin/order_cycles_complex_nav_check_spec.rb +++ b/spec/features/admin/order_cycles_complex_nav_check_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' feature ' @@ -15,7 +17,7 @@ feature ' visit edit_admin_order_cycle_path(oc) wait_for_edit_form_to_load_order_cycle(oc) - + expect(page).to have_selector '.wizard-progress .current a', text: '1. GENERAL SETTINGS' expect(page.find('#order_cycle_name').value).to eq(oc.name) expect(page).to have_button("Save", disabled: true) diff --git a/spec/features/admin/order_spec.rb b/spec/features/admin/order_spec.rb index 934b7f02f9..0017d6b72a 100644 --- a/spec/features/admin/order_spec.rb +++ b/spec/features/admin/order_spec.rb @@ -252,7 +252,7 @@ feature ' href: spree.resend_admin_order_path(order) expect(page).to have_link "Send Invoice", href: spree.invoice_admin_order_path(order) expect(page).to have_link "Print Invoice", href: spree.print_admin_order_path(order) - expect(page).to have_link "Cancel Order", href: spree.fire_admin_order_path(order, e: 'cancel') + expect(page).to have_link "Cancel Order", href: spree.fire_admin_order_path(order, e: 'cancel') end end diff --git a/spec/features/admin/orders_spec.rb b/spec/features/admin/orders_spec.rb index d5d1313b22..ea50ddb082 100644 --- a/spec/features/admin/orders_spec.rb +++ b/spec/features/admin/orders_spec.rb @@ -39,16 +39,16 @@ feature ' end scenario "filter by multiple order cycles" do - order_cycle_2 = create(:simple_order_cycle, name: 'Two') - order_cycle_3 = create(:simple_order_cycle, name: 'Three') - order_cycle_4 = create(:simple_order_cycle, name: 'Four') + order_cycle2 = create(:simple_order_cycle, name: 'Two') + order_cycle3 = create(:simple_order_cycle, name: 'Three') + order_cycle4 = create(:simple_order_cycle, name: 'Four') - order_2 = create(:order_with_credit_payment, user: user, distributor: distributor, - order_cycle: order_cycle_2) - order_3 = create(:order_with_credit_payment, user: user, distributor: distributor, - order_cycle: order_cycle_3) - order_4 = create(:order_with_credit_payment, user: user, distributor: distributor, - order_cycle: order_cycle_4) + order2 = create(:order_with_credit_payment, user: user, distributor: distributor, + order_cycle: order_cycle2) + order3 = create(:order_with_credit_payment, user: user, distributor: distributor, + order_cycle: order_cycle3) + order4 = create(:order_with_credit_payment, user: user, distributor: distributor, + order_cycle: order_cycle4) quick_login_as_admin visit 'admin/orders' @@ -59,10 +59,9 @@ feature ' page.find('.filter-actions .button.icon-search').click # Order 2 and 3 should show, but not 4 - expect(page).to have_content order_2.number - expect(page).to have_content order_3.number - expect(page).to_not have_content order_4.number - + expect(page).to have_content order2.number + expect(page).to have_content order3.number + expect(page).to_not have_content order4.number end context "with a capturable order" do diff --git a/spec/features/admin/subscriptions_spec.rb b/spec/features/admin/subscriptions_spec.rb index a8dc01ed22..61d5f59bcd 100644 --- a/spec/features/admin/subscriptions_spec.rb +++ b/spec/features/admin/subscriptions_spec.rb @@ -19,9 +19,9 @@ feature 'Subscriptions' do let!(:subscription_unmanaged) { create(:subscription, shop: shop_unmanaged, with_items: true, with_proxy_orders: true) } before do - subscription.update_attributes(shipping_fee_estimate: 3.5) + subscription.update(shipping_fee_estimate: 3.5) subscription.subscription_line_items.each do |sli| - sli.update_attributes(price_estimate: 5) + sli.update(price_estimate: 5) end end @@ -412,7 +412,7 @@ feature 'Subscriptions' do let(:order) { proxy_order.initialise_order! } let(:line_item) { order.line_items.first } - before { line_item.update_attributes(quantity: 3) } + before { line_item.update(quantity: 3) } it "reports issues encountered during the update" do visit edit_admin_subscription_path(subscription) diff --git a/spec/features/admin/variant_overrides_spec.rb b/spec/features/admin/variant_overrides_spec.rb index 5f48c35fd2..1fb6e15981 100644 --- a/spec/features/admin/variant_overrides_spec.rb +++ b/spec/features/admin/variant_overrides_spec.rb @@ -471,8 +471,8 @@ feature " end first_variant = inventory_items.first.variant last_variant = inventory_items.last.variant - first_variant.product.update_attributes!(name: "A First Product") - last_variant.product.update_attributes!(name: "Z Last Product") + first_variant.product.update!(name: "A First Product") + last_variant.product.update!(name: "Z Last Product") quick_login_as supplier.users.first visit admin_inventory_path diff --git a/spec/features/admin/variants_spec.rb b/spec/features/admin/variants_spec.rb index 450fb96621..700c375954 100644 --- a/spec/features/admin/variants_spec.rb +++ b/spec/features/admin/variants_spec.rb @@ -29,7 +29,7 @@ feature ' # Given a product with unit-related option types, with a variant product = create(:simple_product, variant_unit: "weight", variant_unit_scale: "1") variant = product.variants.first - variant.update_attributes( unit_value: 1, unit_description: 'foo' ) + variant.update( unit_value: 1, unit_description: 'foo' ) # And the product has option types for the unit-related and non-unit-related option values product.option_types << variant.option_values.first.option_type @@ -60,7 +60,7 @@ feature ' scenario "can update unit_description when variant_unit is items" do product = create(:simple_product, variant_unit: "items", variant_unit_name: "bunches") variant = product.variants.first - variant.update_attributes(unit_description: 'foo') + variant.update(unit_description: 'foo') login_to_admin_section visit spree.edit_admin_product_variant_path(product, variant) diff --git a/spec/features/consumer/account_spec.rb b/spec/features/consumer/account_spec.rb index b0139c7f6f..bdba76c971 100644 --- a/spec/features/consumer/account_spec.rb +++ b/spec/features/consumer/account_spec.rb @@ -76,7 +76,7 @@ feature ' context "when there is at least one changeable order" do before do - distributor1.update_attributes(allow_order_changes: true) + distributor1.update(allow_order_changes: true) end it "shows such orders in a section labelled 'Open Orders'" do @@ -86,7 +86,7 @@ feature ' expect(page).to have_link d1o1.number, href: spree.order_path(d1o1) expect(page).to have_link d1o2.number, href: spree.order_path(d1o2) expect(page).to have_link(distributor1.name, - href: "#{distributor1.permalink}/shop", count: 2) + href: "#{distributor1.permalink}/shop", count: 2) expect(page).to have_link I18n.t('spree.users.open_orders.cancel'), href: spree.cancel_order_path(d1o1) expect(page).to have_link I18n.t('spree.users.open_orders.cancel'), href: spree.cancel_order_path(d1o2) end diff --git a/spec/features/consumer/registration_spec.rb b/spec/features/consumer/registration_spec.rb index ed0c2f96b1..0e9f1b221c 100644 --- a/spec/features/consumer/registration_spec.rb +++ b/spec/features/consumer/registration_spec.rb @@ -132,7 +132,7 @@ feature "Registration", js: true do context "when the user has no more remaining enterprises" do before do - user.update_attributes(enterprise_limit: 0) + user.update(enterprise_limit: 0) end it "displays the limit reached page" do diff --git a/spec/features/consumer/shopping/cart_spec.rb b/spec/features/consumer/shopping/cart_spec.rb index e7785dcdb4..194b202d26 100644 --- a/spec/features/consumer/shopping/cart_spec.rb +++ b/spec/features/consumer/shopping/cart_spec.rb @@ -123,8 +123,8 @@ feature "full-page cart", js: true do } before do - product_with_fee.variants.first.update_attributes(unit_value: '2000.0') - product_with_tax.variants.first.update_attributes(unit_value: '5000.0') + product_with_fee.variants.first.update(unit_value: '2000.0') + product_with_tax.variants.first.update(unit_value: '5000.0') add_enterprise_fee admin_fee @@ -167,7 +167,7 @@ feature "full-page cart", js: true do describe "when on_hand is zero but variant is on demand" do it "allows updating the quantity" do - variant.update_attributes!(on_hand: 0, on_demand: true) + variant.update!(on_hand: 0, on_demand: true) visit main_app.cart_path fill_in "order_line_items_attributes_0_quantity", with: '5' @@ -179,8 +179,8 @@ feature "full-page cart", js: true do it "prevents user from entering invalid values" do add_product_to_cart order, product_with_fee - variant.update_attributes!(on_hand: 2, on_demand: false) - variant2.update_attributes!(on_hand: 3, on_demand: false) + variant.update!(on_hand: 2, on_demand: false) + variant2.update!(on_hand: 3, on_demand: false) visit main_app.cart_path accept_alert 'Insufficient stock available, only 2 remaining' do @@ -200,10 +200,10 @@ feature "full-page cart", js: true do it "shows the quantities saved, not those submitted" do # Given we load the page with 3 on hand, then the number available drops to 2 - variant.update_attributes! on_demand: false - variant.update_attributes! on_hand: 3 + variant.update! on_demand: false + variant.update! on_hand: 3 visit main_app.cart_path - variant.update_attributes! on_hand: 2 + variant.update! on_hand: 2 accept_alert do fill_in "order_line_items_attributes_0_quantity", with: '4' @@ -217,7 +217,7 @@ feature "full-page cart", js: true do describe "full UX for correcting selected quantities with insufficient stock" do before do add_product_to_cart order, product_with_tax, quantity: 5 - variant.update_attributes! on_hand: 4, on_demand: false + variant.update! on_hand: 4, on_demand: false end it "gives clear user feedback during the correcting process" do diff --git a/spec/features/consumer/shopping/embedded_groups_spec.rb b/spec/features/consumer/shopping/embedded_groups_spec.rb index 171e60965e..f64749cacc 100644 --- a/spec/features/consumer/shopping/embedded_groups_spec.rb +++ b/spec/features/consumer/shopping/embedded_groups_spec.rb @@ -37,7 +37,7 @@ feature "Using embedded shopfront functionality", js: true 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}' + expect(page).to have_no_content group.address.address1.to_s end end end diff --git a/spec/features/consumer/shopping/orders_spec.rb b/spec/features/consumer/shopping/orders_spec.rb index 2bb40d6dd5..4f2a379c12 100644 --- a/spec/features/consumer/shopping/orders_spec.rb +++ b/spec/features/consumer/shopping/orders_spec.rb @@ -105,7 +105,7 @@ feature "Order Management", js: true do let!(:item3) { create(:line_item, order: order) } before do - order.shipment.shipping_method.calculator.update_attributes(preferred_amount: 5.0) + order.shipment.shipping_method.calculator.update(preferred_amount: 5.0) order.save order.reload @@ -119,7 +119,7 @@ feature "Order Management", js: true do context "when the distributor doesn't allow changes to be made to orders" do before do - order.distributor.update_attributes(allow_order_changes: false) + order.distributor.update(allow_order_changes: false) end it "doesn't show form elements for editing the order" do @@ -136,7 +136,7 @@ feature "Order Management", js: true do setup_email end before do - order.distributor.update_attributes(allow_order_changes: true) + order.distributor.update(allow_order_changes: true) end it "allows quantity to be changed, items to be removed and the order to be cancelled" do diff --git a/spec/features/consumer/shopping/shopping_spec.rb b/spec/features/consumer/shopping/shopping_spec.rb index b5a0769e8c..b947b23d3d 100644 --- a/spec/features/consumer/shopping/shopping_spec.rb +++ b/spec/features/consumer/shopping/shopping_spec.rb @@ -222,7 +222,7 @@ feature "As a consumer I want to shop with a distributor", js: true do context "when the distributor has no available payment/shipping methods" do before do - distributor.update_attributes shipping_methods: [], payment_methods: [] + distributor.update shipping_methods: [], payment_methods: [] end # Display only shops are a very useful hack that is described in the user guide @@ -310,7 +310,7 @@ feature "As a consumer I want to shop with a distributor", js: true do end it "lets us add a quantity greater than on_hand value if product is on_demand" do - variant.update_attributes on_hand: 5, on_demand: true + variant.update on_hand: 5, on_demand: true visit shop_path fill_in "variants[#{variant.id}]", with: '10' @@ -319,7 +319,7 @@ feature "As a consumer I want to shop with a distributor", js: true do end it "alerts us when we enter a quantity greater than the stock available" do - variant.update_attributes on_hand: 5 + variant.update on_hand: 5 visit shop_path accept_alert 'Insufficient stock available, only 5 remaining' do @@ -333,7 +333,7 @@ feature "As a consumer I want to shop with a distributor", js: true do it "stops the attempt, shows an error message and refreshes the products asynchronously" do expect(page).to have_content "Product" - variant.update_attributes! on_hand: 0 + variant.update! on_hand: 0 # -- Messaging expect(page).to have_input "variants[#{variant.id}]" @@ -360,7 +360,7 @@ feature "As a consumer I want to shop with a distributor", js: true do it 'does not show out of stock modal if product is on_demand' do expect(page).to have_content "Product" - variant.update_attributes! on_hand: 0, on_demand: true + variant.update! on_hand: 0, on_demand: true expect(page).to have_input "variants[#{variant.id}]" fill_in "variants[#{variant.id}]", with: '1' @@ -376,7 +376,7 @@ feature "As a consumer I want to shop with a distributor", js: true do # -- Place in cart so we can set max_quantity, then make out of stock fill_in "variants[#{variant.id}]", with: '1' wait_until { !cart_dirty } - variant.update_attributes! on_hand: 0 + variant.update! on_hand: 0 # -- Messaging fill_in "variant_attributes[#{variant.id}][max_quantity]", with: '1' @@ -403,7 +403,7 @@ feature "As a consumer I want to shop with a distributor", js: true do fill_in "variants[#{variant.id}]", with: '2' wait_until { !cart_dirty } - variant.update_attributes! on_hand: 1 + variant.update! on_hand: 1 fill_in "variants[#{variant2.id}]", with: '1' wait_until { !cart_dirty } @@ -421,7 +421,7 @@ feature "As a consumer I want to shop with a distributor", js: true do fill_in "variants[#{variant.id}]", with: '2' fill_in "variant_attributes[#{variant.id}][max_quantity]", with: '3' wait_until { !cart_dirty } - variant.update_attributes! on_hand: 1 + variant.update! on_hand: 1 fill_in "variants[#{variant2.id}]", with: '1' wait_until { !cart_dirty } diff --git a/spec/helpers/spree/admin/reports_helper_spec.rb b/spec/helpers/spree/admin/reports_helper_spec.rb index 9ef4976750..46f8070a4c 100644 --- a/spec/helpers/spree/admin/reports_helper_spec.rb +++ b/spec/helpers/spree/admin/reports_helper_spec.rb @@ -2,7 +2,6 @@ require 'spec_helper' - describe Spree::ReportsHelper, type: :helper do describe "#report_payment_method_options" do let(:order_with_payments) { create(:order_ready_to_ship) } diff --git a/spec/jobs/job_logger_spec.rb b/spec/jobs/job_logger_spec.rb index bdeec0432a..de7a12c946 100644 --- a/spec/jobs/job_logger_spec.rb +++ b/spec/jobs/job_logger_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe JobLogger do @@ -14,7 +16,7 @@ describe JobLogger do describe JobLogger::Formatter do describe '#call' do it 'outputs timestamps, progname and message' do - timestamp = DateTime.new(2020,5,6, 22, 36, 0) + timestamp = DateTime.new(2020, 5, 6, 22, 36, 0) log_line = JobLogger::Formatter.new.call(nil, timestamp, 'progname', 'message') expect(log_line).to eq("2020-05-06T22:36:00+0000: message\n") end diff --git a/spec/jobs/subscription_confirm_job_spec.rb b/spec/jobs/subscription_confirm_job_spec.rb index a061d0fbd4..603da10a10 100644 --- a/spec/jobs/subscription_confirm_job_spec.rb +++ b/spec/jobs/subscription_confirm_job_spec.rb @@ -27,22 +27,22 @@ describe SubscriptionConfirmJob do end it "returns proxy orders for paused subscriptions" do - subscription.update_attributes!(paused_at: 1.minute.ago) + subscription.update!(paused_at: 1.minute.ago) expect(proxy_orders).to include proxy_order end it "returns proxy orders for cancelled subscriptions" do - subscription.update_attributes!(canceled_at: 1.minute.ago) + subscription.update!(canceled_at: 1.minute.ago) expect(proxy_orders).to include proxy_order end it "ignores proxy orders where the OC closed more than 1 hour ago" do - proxy_order.update_attributes!(order_cycle_id: order_cycle2.id) + proxy_order.update!(order_cycle_id: order_cycle2.id) expect(proxy_orders).to_not include proxy_order end it "ignores cancelled proxy orders" do - proxy_order.update_attributes!(canceled_at: 5.minutes.ago) + proxy_order.update!(canceled_at: 5.minutes.ago) expect(proxy_orders).to_not include proxy_order end @@ -53,17 +53,17 @@ describe SubscriptionConfirmJob do end it "ignores proxy orders without an associated order" do - proxy_order.update_attributes!(order_id: nil) + proxy_order.update!(order_id: nil) expect(proxy_orders).to_not include proxy_order end it "ignores proxy orders that haven't been placed yet" do - proxy_order.update_attributes!(placed_at: nil) + proxy_order.update!(placed_at: nil) expect(proxy_orders).to_not include proxy_order end it "ignores proxy orders that have already been confirmed" do - proxy_order.update_attributes!(confirmed_at: 1.second.ago) + proxy_order.update!(confirmed_at: 1.second.ago) expect(proxy_orders).to_not include proxy_order end diff --git a/spec/jobs/subscription_placement_job_spec.rb b/spec/jobs/subscription_placement_job_spec.rb index e43343e795..fc7ca9177c 100644 --- a/spec/jobs/subscription_placement_job_spec.rb +++ b/spec/jobs/subscription_placement_job_spec.rb @@ -13,27 +13,27 @@ describe SubscriptionPlacementJob do it "ignores proxy orders where the OC has closed" do expect(job.send(:proxy_orders)).to include proxy_order - proxy_order.update_attributes!(order_cycle_id: order_cycle2.id) + proxy_order.update!(order_cycle_id: order_cycle2.id) expect(job.send(:proxy_orders)).to_not include proxy_order end it "ignores proxy orders for paused or cancelled subscriptions" do expect(job.send(:proxy_orders)).to include proxy_order - subscription.update_attributes!(paused_at: 1.minute.ago) + subscription.update!(paused_at: 1.minute.ago) expect(job.send(:proxy_orders)).to_not include proxy_order - subscription.update_attributes!(paused_at: nil) + subscription.update!(paused_at: nil) expect(job.send(:proxy_orders)).to include proxy_order - subscription.update_attributes!(canceled_at: 1.minute.ago) + subscription.update!(canceled_at: 1.minute.ago) expect(job.send(:proxy_orders)).to_not include proxy_order end it "ignores proxy orders that have been marked as cancelled or placed" do expect(job.send(:proxy_orders)).to include proxy_order - proxy_order.update_attributes!(canceled_at: 5.minutes.ago) + proxy_order.update!(canceled_at: 5.minutes.ago) expect(job.send(:proxy_orders)).to_not include proxy_order - proxy_order.update_attributes!(canceled_at: nil) + proxy_order.update!(canceled_at: nil) expect(job.send(:proxy_orders)).to include proxy_order - proxy_order.update_attributes!(placed_at: 5.minutes.ago) + proxy_order.update!(placed_at: 5.minutes.ago) expect(job.send(:proxy_orders)).to_not include proxy_order end end diff --git a/spec/lib/open_food_network/orders_and_fulfillments_report/customer_totals_report_spec.rb b/spec/lib/open_food_network/orders_and_fulfillments_report/customer_totals_report_spec.rb index 628279c260..6bae6da8a1 100644 --- a/spec/lib/open_food_network/orders_and_fulfillments_report/customer_totals_report_spec.rb +++ b/spec/lib/open_food_network/orders_and_fulfillments_report/customer_totals_report_spec.rb @@ -18,7 +18,7 @@ RSpec.describe OpenFoodNetwork::OrdersAndFulfillmentsReport::CustomerTotalsRepor context "viewing the report" do let!(:order) do create(:completed_order_with_totals, line_items_count: 1, user: customer.user, - customer: customer, distributor: distributor) + customer: customer, distributor: distributor) end it "generates the report" do @@ -39,17 +39,17 @@ RSpec.describe OpenFoodNetwork::OrdersAndFulfillmentsReport::CustomerTotalsRepor it 'includes the order number and date in item rows' do order_number_and_date_fields = report_table.first[33..34] expect(order_number_and_date_fields).to eq([ - order.number, - order.completed_at.strftime("%F %T"), - ]) + order.number, + order.completed_at.strftime("%F %T"), + ]) end it 'includes the order number and date in total rows' do order_number_and_date_fields = report_table.last[33..34] expect(order_number_and_date_fields).to eq([ - order.number, - order.completed_at.strftime("%F %T"), - ]) + order.number, + order.completed_at.strftime("%F %T"), + ]) end end @@ -65,7 +65,7 @@ RSpec.describe OpenFoodNetwork::OrdersAndFulfillmentsReport::CustomerTotalsRepor } let!(:order) do create(:completed_order_with_totals, line_items_count: 1, user: customer.user, - customer: customer, distributor: distributor) + customer: customer, distributor: distributor) end before do @@ -82,7 +82,7 @@ RSpec.describe OpenFoodNetwork::OrdersAndFulfillmentsReport::CustomerTotalsRepor context 'when a variant override applies' do let!(:order) do create(:completed_order_with_totals, line_items_count: 1, user: customer.user, - customer: customer, distributor: distributor) + customer: customer, distributor: distributor) end let(:overidden_sku) { 'magical_sku' } diff --git a/spec/lib/tasks/data/truncate_data_rake_spec.rb b/spec/lib/tasks/data/truncate_data_rake_spec.rb index fff40d5b1f..d2f86fc826 100644 --- a/spec/lib/tasks/data/truncate_data_rake_spec.rb +++ b/spec/lib/tasks/data/truncate_data_rake_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' require 'rake' @@ -19,8 +21,8 @@ describe 'truncate_data.rake' do create(:order, order_cycle: old_order_cycle) recent_order_cycle = create( :order_cycle, - orders_open_at: 1.months.ago, - orders_close_at: 1.months.ago + 1.day, + orders_open_at: 1.month.ago, + orders_close_at: 1.month.ago + 1.day, ) create(:order, order_cycle: recent_order_cycle) diff --git a/spec/lib/tasks/data/truncate_data_spec.rb b/spec/lib/tasks/data/truncate_data_spec.rb index 850b9bb9a8..9be42752cd 100644 --- a/spec/lib/tasks/data/truncate_data_spec.rb +++ b/spec/lib/tasks/data/truncate_data_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' require 'tasks/data/truncate_data' @@ -92,7 +94,7 @@ describe TruncateData do ) create(:order, order_cycle: old_order_cycle) recent_order_cycle = create( - :order_cycle, orders_open_at: 1.months.ago, orders_close_at: 1.months.ago + 1.day + :order_cycle, orders_open_at: 1.month.ago, orders_close_at: 1.month.ago + 1.day ) create(:order, order_cycle: recent_order_cycle) @@ -127,4 +129,3 @@ describe TruncateData do end end end - diff --git a/spec/mailers/producer_mailer_spec.rb b/spec/mailers/producer_mailer_spec.rb index 2449d450c0..66dd425f95 100644 --- a/spec/mailers/producer_mailer_spec.rb +++ b/spec/mailers/producer_mailer_spec.rb @@ -116,8 +116,8 @@ describe ProducerMailer, type: :mailer do private - def body_lines_including(mail, s) - mail.body.to_s.lines.select { |line| line.include? s } + def body_lines_including(mail, str) + mail.body.to_s.lines.select { |line| line.include? str } end def body_as_html(mail) diff --git a/spec/models/customer_spec.rb b/spec/models/customer_spec.rb index 217748bb6d..6a35547e1d 100644 --- a/spec/models/customer_spec.rb +++ b/spec/models/customer_spec.rb @@ -32,7 +32,7 @@ describe Customer, type: :model do phone: "455500146", address1: "U 3/32 Florence Road Surrey Hills2", country_id: 1 } - customer.update_attributes!(ship_address_attributes: ship_address) + customer.update!(ship_address_attributes: ship_address) expect(customer.ship_address.city).to eq 'Melbourne' expect(customer.ship_address.firstname).to eq 'fname' diff --git a/spec/models/enterprise_caching_spec.rb b/spec/models/enterprise_caching_spec.rb index 2fe4bd3f7a..6160481c91 100644 --- a/spec/models/enterprise_caching_spec.rb +++ b/spec/models/enterprise_caching_spec.rb @@ -32,7 +32,7 @@ describe Enterprise do it "touches enterprise when the supplier of a product changes" do expect { - product.update_attributes!(supplier: supplier2) + product.update!(supplier: supplier2) }.to change { enterprise.reload.updated_at } end end @@ -67,7 +67,7 @@ describe Enterprise do it "touches enterprise when the supplier of a product changes" do expect { - product.update_attributes!(supplier: supplier2) + product.update!(supplier: supplier2) }.to change { enterprise.reload.updated_at } end end diff --git a/spec/models/exchange_spec.rb b/spec/models/exchange_spec.rb index bb34404469..b6c2f80b9c 100644 --- a/spec/models/exchange_spec.rb +++ b/spec/models/exchange_spec.rb @@ -152,8 +152,8 @@ describe Exchange do end it "correctly determines direction of exchanges between the same enterprise" do - incoming_exchange.update_attributes sender: coordinator, incoming: true - outgoing_exchange.update_attributes receiver: coordinator, incoming: false + incoming_exchange.update sender: coordinator, incoming: true + outgoing_exchange.update receiver: coordinator, incoming: false expect(Exchange.incoming).to eq([incoming_exchange]) expect(Exchange.outgoing).to eq([outgoing_exchange]) end diff --git a/spec/models/model_set_spec.rb b/spec/models/model_set_spec.rb index 17c877e1da..7c4334e786 100644 --- a/spec/models/model_set_spec.rb +++ b/spec/models/model_set_spec.rb @@ -31,10 +31,10 @@ describe ModelSet do e1 = create(:enterprise) e2 = create(:enterprise) - attrs = { collection_attributes: { '1' => { id: e1.id, name: 'deleteme' }, - '2' => { id: e2.id, name: 'e2' } } } + attributes = { collection_attributes: { '1' => { id: e1.id, name: 'deleteme' }, + '2' => { id: e2.id, name: 'e2' } } } - ms = ModelSet.new(Enterprise, Enterprise.all, attrs, nil, + ms = ModelSet.new(Enterprise, Enterprise.all, attributes, nil, proc { |attrs| attrs['name'] == 'deleteme' }) expect { ms.save }.to change(Enterprise, :count).by(-1) @@ -44,9 +44,9 @@ describe ModelSet do end it "ignores deletable new records" do - attrs = { collection_attributes: { '1' => { name: 'deleteme' } } } + attributes = { collection_attributes: { '1' => { name: 'deleteme' } } } - ms = ModelSet.new(Enterprise, Enterprise.all, attrs, nil, + ms = ModelSet.new(Enterprise, Enterprise.all, attributes, nil, proc { |attrs| attrs['name'] == 'deleteme' }) expect { ms.save }.to change(Enterprise, :count).by(0) diff --git a/spec/models/order_cycle_spec.rb b/spec/models/order_cycle_spec.rb index 21cad530a9..e329297f91 100644 --- a/spec/models/order_cycle_spec.rb +++ b/spec/models/order_cycle_spec.rb @@ -319,7 +319,7 @@ describe OrderCycle do end it "reports status when an order cycle is undated" do - oc.update_attributes!(orders_open_at: nil, orders_close_at: nil) + oc.update!(orders_open_at: nil, orders_close_at: nil) expect(oc).to be_undated expect(oc).not_to be_dated @@ -329,7 +329,7 @@ describe OrderCycle do end it "reports status when an order cycle is partially dated - opening time only" do - oc.update_attributes!(orders_close_at: nil) + oc.update!(orders_close_at: nil) expect(oc).to be_undated expect(oc).not_to be_dated @@ -339,7 +339,7 @@ describe OrderCycle do end it "reports status when an order cycle is partially dated - closing time only" do - oc.update_attributes!(orders_open_at: nil) + oc.update!(orders_open_at: nil) expect(oc).to be_undated expect(oc).not_to be_dated diff --git a/spec/models/product_importer_spec.rb b/spec/models/product_importer_spec.rb index 910272f940..89008c54f9 100644 --- a/spec/models/product_importer_spec.rb +++ b/spec/models/product_importer_spec.rb @@ -764,7 +764,7 @@ def filter(type, entries) valid_count += 1 if type == 'valid' && (validates_as != '') valid_count += 1 if type == 'invalid' && (validates_as == '') - valid_count += 1 if type == 'create_product' && (validates_as == 'new_product' || validates_as == 'new_variant') + valid_count += 1 if type == 'create_product' && ['new_product', 'new_variant'].include?(validates_as) valid_count += 1 if type == 'update_product' && validates_as == 'existing_variant' valid_count += 1 if type == 'create_inventory' && validates_as == 'new_inventory_item' valid_count += 1 if type == 'update_inventory' && validates_as == 'existing_inventory_item' diff --git a/spec/models/proxy_order_spec.rb b/spec/models/proxy_order_spec.rb index 77bd5a989c..ee6e30cbdc 100644 --- a/spec/models/proxy_order_spec.rb +++ b/spec/models/proxy_order_spec.rb @@ -12,7 +12,7 @@ describe ProxyOrder, type: :model do context "when the order cycle is not yet closed" do let(:proxy_order) { create(:proxy_order, subscription: subscription, order: order, order_cycle: order_cycle) } - before { order_cycle.update_attributes(orders_open_at: 1.day.ago, orders_close_at: 3.days.from_now) } + before { order_cycle.update(orders_open_at: 1.day.ago, orders_close_at: 3.days.from_now) } context "and an order has not been initialised" do let(:order) { nil } @@ -50,7 +50,7 @@ describe ProxyOrder, type: :model do context "when the order cycle is already closed" do let(:proxy_order) { create(:proxy_order, subscription: subscription, order: order, order_cycle: order_cycle) } - before { order_cycle.update_attributes(orders_open_at: 3.days.ago, orders_close_at: 1.minute.ago) } + before { order_cycle.update(orders_open_at: 3.days.ago, orders_close_at: 1.minute.ago) } context "and an order has not been initialised" do let(:order) { nil } @@ -91,7 +91,7 @@ describe ProxyOrder, type: :model do end context "when the order cycle is not yet closed" do - before { order_cycle.update_attributes(orders_open_at: 1.day.ago, orders_close_at: 3.days.from_now) } + before { order_cycle.update(orders_open_at: 1.day.ago, orders_close_at: 3.days.from_now) } context "and the order has not been initialised" do let(:order) { nil } @@ -131,7 +131,7 @@ describe ProxyOrder, type: :model do end context "when the order cycle is already closed" do - before { order_cycle.update_attributes(orders_open_at: 3.days.ago, orders_close_at: 1.minute.ago) } + before { order_cycle.update(orders_open_at: 3.days.ago, orders_close_at: 1.minute.ago) } context "and the order has not been initialised" do let(:order) { nil } @@ -188,7 +188,7 @@ describe ProxyOrder, type: :model do let(:existing_order) { create(:order) } before do - proxy_order.update_attributes(order: existing_order) + proxy_order.update(order: existing_order) end it "returns the existing order" do diff --git a/spec/models/spree/adjustment_spec.rb b/spec/models/spree/adjustment_spec.rb index bed9737151..57047457ac 100644 --- a/spec/models/spree/adjustment_spec.rb +++ b/spec/models/spree/adjustment_spec.rb @@ -117,7 +117,7 @@ module Spree end it "records 0% tax on shipments when the distributor does not charge sales tax" do - order.distributor.update_attributes! charges_sales_tax: false + order.distributor.update! charges_sales_tax: false order.shipments = [shipment] expect(order.adjustments.first.included_tax).to eq(0) diff --git a/spec/models/spree/calculator/price_sack_spec.rb b/spec/models/spree/calculator/price_sack_spec.rb index 05c7a8cb8a..703bea1531 100644 --- a/spec/models/spree/calculator/price_sack_spec.rb +++ b/spec/models/spree/calculator/price_sack_spec.rb @@ -72,7 +72,6 @@ describe Spree::Calculator::PriceSack do expect(calculator.compute(line_item)).to eq(1) end end - end context "extends LocalizedNumber" do diff --git a/spec/models/spree/credit_card_spec.rb b/spec/models/spree/credit_card_spec.rb index 99f04e1362..845b1dd84a 100644 --- a/spec/models/spree/credit_card_spec.rb +++ b/spec/models/spree/credit_card_spec.rb @@ -46,7 +46,7 @@ module Spree context "without specifying it as the default" do it "keeps the existing default" do - card2.update_attributes!(stored_card_attrs) + card2.update!(stored_card_attrs) expect(card1.reload.is_default).to be true expect(card2.reload.is_default).to be false @@ -55,7 +55,7 @@ module Spree context "and I specify it as the default" do it "switches the default to the updated card" do - card2.update_attributes!(stored_default_card_attrs) + card2.update!(stored_default_card_attrs) expect(card1.reload.is_default).to be false expect(card2.reload.is_default).to be true @@ -101,7 +101,7 @@ module Spree # The checkout first creates a one-time card and then converts it # to a re-usable card. # This imitates Stripe::ProfileStorer. - card1.update_attributes!(store_card_profile_attrs) + card1.update!(store_card_profile_attrs) expect(card1.reload.is_default).to be true end end diff --git a/spec/models/spree/gateway_tagging_spec.rb b/spec/models/spree/gateway_tagging_spec.rb index 2a5eb5c23e..35b08ae9bb 100644 --- a/spec/models/spree/gateway_tagging_spec.rb +++ b/spec/models/spree/gateway_tagging_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "spec_helper" # We extended Spree::PaymentMethod to be taggable. Unfortunately, an inheritance diff --git a/spec/models/spree/line_item_spec.rb b/spec/models/spree/line_item_spec.rb index 2b538d2967..ca4a5353d9 100644 --- a/spec/models/spree/line_item_spec.rb +++ b/spec/models/spree/line_item_spec.rb @@ -39,10 +39,10 @@ module Spree let!(:adjustment1) { create(:adjustment, originator: tax_rate, label: "TR", amount: 123, included_tax: 10.00) } before do - li1 - li2 - li1.adjustments << adjustment1 - end + li1 + li2 + li1.adjustments << adjustment1 + end it "finds line items with tax" do expect(LineItem.with_tax).to eq([li1]) @@ -67,7 +67,7 @@ module Spree let!(:li) { create(:line_item, variant: v, quantity: 10, max_quantity: 10) } before do - v.update_attributes! on_hand: 5 + v.update! on_hand: 5 end it "caps quantity" do @@ -89,7 +89,7 @@ module Spree end it "does nothing for on_demand items" do - v.update_attributes! on_demand: true + v.update! on_demand: true li.cap_quantity_at_stock! li.reload expect(li.quantity).to eq 10 @@ -97,7 +97,7 @@ module Spree end it "caps at zero when stock is negative" do - v.update_attributes! on_hand: -2 + v.update! on_hand: -2 li.cap_quantity_at_stock! expect(li.reload.quantity).to eq 0 end @@ -107,7 +107,7 @@ module Spree let!(:vo) { create(:variant_override, hub: hub, variant: v, count_on_hand: 2) } before do - li.order.update_attributes(distributor_id: hub.id) + li.order.update(distributor_id: hub.id) # li#scoper is memoised, and this makes it difficult to update test conditions # so we reset it after the line_item is created for each spec @@ -120,10 +120,10 @@ module Spree end context "when count on hand is negative" do - before { vo.update_attributes(count_on_hand: -3) } + before { vo.update(count_on_hand: -3) } it "caps at zero" do - v.update_attributes(on_hand: -2) + v.update(on_hand: -2) li.cap_quantity_at_stock! expect(li.reload.quantity).to eq 0 end @@ -260,7 +260,7 @@ module Spree end context "when the stock on the variant is not sufficient" do - before { v.update_attributes(on_hand: 4) } + before { v.update(on_hand: 4) } context "when no variant override is in place" do it { expect(li.sufficient_stock?).to be false } @@ -274,7 +274,7 @@ module Spree end context "and stock on the variant override is not sufficient" do - before { vo.update_attributes(count_on_hand: 4) } + before { vo.update(count_on_hand: 4) } it { expect(li.sufficient_stock?).to be false } end @@ -375,7 +375,7 @@ module Spree context "and quantity is not changed" do before do - li.update_attributes(attrs) + li.update(attrs) end it "uses the value given" do @@ -386,7 +386,7 @@ module Spree context "and quantity is changed" do before do attrs[:quantity] = 4 - li.update_attributes(attrs) + li.update(attrs) end it "uses the value given" do @@ -400,7 +400,7 @@ module Spree context "and quantity is not changed" do before do - li.update_attributes(attrs) + li.update(attrs) end it "does not change final_weight_volume" do @@ -414,7 +414,7 @@ module Spree before do expect(li.final_weight_volume).to eq 3000 attrs[:quantity] = 4 - li.update_attributes(attrs) + li.update(attrs) end it "scales the final_weight_volume based on the change in quantity" do @@ -424,9 +424,9 @@ module Spree context "and a final_weight_volume has not been set" do before do - li.update_attributes(final_weight_volume: nil) + li.update(final_weight_volume: nil) attrs[:quantity] = 1 - li.update_attributes(attrs) + li.update(attrs) end it "calculates a final_weight_volume from the variants unit_value" do @@ -436,13 +436,13 @@ module Spree end context "from 0" do - before { li.update_attributes(quantity: 0) } + before { li.update(quantity: 0) } context "and a final_weight_volume has been set" do before do expect(li.final_weight_volume).to eq 0 attrs[:quantity] = 4 - li.update_attributes(attrs) + li.update(attrs) end it "recalculates a final_weight_volume from the variants unit_value" do @@ -452,9 +452,9 @@ module Spree context "and a final_weight_volume has not been set" do before do - li.update_attributes(final_weight_volume: nil) + li.update(final_weight_volume: nil) attrs[:quantity] = 1 - li.update_attributes(attrs) + li.update(attrs) end it "calculates a final_weight_volume from the variants unit_value" do diff --git a/spec/models/spree/order_spec.rb b/spec/models/spree/order_spec.rb index 2151634bde..11ac15fa27 100644 --- a/spec/models/spree/order_spec.rb +++ b/spec/models/spree/order_spec.rb @@ -658,7 +658,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(line_items_attributes: [{ id: order.line_items.first.id, quantity: 0 }]) # Check if fees got updated order.reload @@ -685,7 +685,7 @@ describe Spree::Order do it "removes transaction fees" do # Change the payment method - order.payments.first.update_attributes(payment_method_id: payment_method.id) + order.payments.first.update(payment_method_id: payment_method.id) order.save # Check if fees got updated @@ -780,7 +780,7 @@ describe Spree::Order do let!(:order_cycle) { proxy_order.order_cycle } context "and order_cycle has no order_close_at set" do - before { order.order_cycle.update_attributes(orders_close_at: nil) } + before { order.order_cycle.update(orders_close_at: nil) } it "requires a payment" do expect(order.payment_required?).to be true @@ -788,7 +788,7 @@ describe Spree::Order do end context "and the order_cycle has closed" do - before { order.order_cycle.update_attributes(orders_close_at: 5.minutes.ago) } + before { order.order_cycle.update(orders_close_at: 5.minutes.ago) } it "returns the payments on the order" do expect(order.payment_required?).to be true @@ -796,7 +796,7 @@ describe Spree::Order do end context "and the order_cycle has not yet closed" do - before { order.order_cycle.update_attributes(orders_close_at: 5.minutes.from_now) } + before { order.order_cycle.update(orders_close_at: 5.minutes.from_now) } it "returns an empty array" do expect(order.payment_required?).to be false diff --git a/spec/models/spree/product_spec.rb b/spec/models/spree/product_spec.rb index 4309d105c9..95504faf3a 100644 --- a/spec/models/spree/product_spec.rb +++ b/spec/models/spree/product_spec.rb @@ -531,13 +531,13 @@ module Spree let!(:ot_volume) { create(:option_type, name: 'unit_volume', presentation: 'Volume') } it "removes the old option type and assigns the new one" do - p.update_attributes!(variant_unit: 'volume', variant_unit_scale: 0.001) + p.update!(variant_unit: 'volume', variant_unit_scale: 0.001) expect(p.option_types).to eq([ot_volume]) end it "does not remove and re-add the option type if it is not changed" do expect(p.option_types).to receive(:delete).never - p.update_attributes!(name: 'foo') + p.update!(name: 'foo') end it "removes the related option values from all its variants and replaces them" do @@ -548,7 +548,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 { - p.update_attributes!(variant_unit: 'volume', variant_unit_scale: 0.001) + p.update!(variant_unit: 'volume', variant_unit_scale: 0.001) }.to change(p.master.option_values(true), :count).by(0) v.reload expect(v.option_values.map(&:name).include?("1L")).to eq(true) @@ -557,13 +557,13 @@ module Spree it "removes the related option values from its master variant and replaces them" do ot = Spree::OptionType.find_by name: 'unit_weight' - p.master.update_attributes!(unit_value: 1) + p.master.update!(unit_value: 1) p.reload 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 { - p.update_attributes!(variant_unit: 'volume', variant_unit_scale: 0.001) + p.update!(variant_unit: 'volume', variant_unit_scale: 0.001) }.to change(p.master.option_values(true), :count).by(0) p.reload expect(p.master.option_values.map(&:name).include?("1L")).to eq(true) diff --git a/spec/models/spree/shipping_method_spec.rb b/spec/models/spree/shipping_method_spec.rb index 94501eaa4e..57d2ae3274 100644 --- a/spec/models/spree/shipping_method_spec.rb +++ b/spec/models/spree/shipping_method_spec.rb @@ -116,7 +116,7 @@ module Spree let(:add_distributor) { shipping_method.distributors << distributor } it "is touched when applied to a distributor" do - expect{ add_distributor }.to change { shipping_method.reload.updated_at} + expect{ add_distributor }.to change { shipping_method.reload.updated_at } end end end diff --git a/spec/models/spree/tax_rate_spec.rb b/spec/models/spree/tax_rate_spec.rb index e2f7e7eb65..888b25c890 100644 --- a/spec/models/spree/tax_rate_spec.rb +++ b/spec/models/spree/tax_rate_spec.rb @@ -61,7 +61,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, 'oops' } + tax_rate.send(:with_tax_included_in_price) { raise StandardError, 'oops' } end.to raise_error 'oops' expect(tax_rate.included_in_price).to be false diff --git a/spec/models/spree/user_spec.rb b/spec/models/spree/user_spec.rb index 0a5d8c439b..0e48621452 100644 --- a/spec/models/spree/user_spec.rb +++ b/spec/models/spree/user_spec.rb @@ -13,7 +13,7 @@ describe Spree.user_class do old_bill_address = user.bill_address new_bill_address = create(:address, firstname: 'abc') - user.update_attributes(bill_address_attributes: new_bill_address.clone.attributes.merge('id' => old_bill_address.id)) + user.update(bill_address_attributes: new_bill_address.clone.attributes.merge('id' => old_bill_address.id)) expect(user.bill_address.id).to eq old_bill_address.id expect(user.bill_address.firstname).to eq new_bill_address.firstname @@ -22,7 +22,7 @@ describe Spree.user_class do it 'creates new shipping address' do new_ship_address = create(:address, firstname: 'abc') - user.update_attributes(ship_address_attributes: new_ship_address.clone.attributes) + user.update(ship_address_attributes: new_ship_address.clone.attributes) expect(user.ship_address.id).not_to eq new_ship_address.id expect(user.ship_address.firstname).to eq new_ship_address.firstname diff --git a/spec/models/spree/variant_spec.rb b/spec/models/spree/variant_spec.rb index d4889e6b4f..7a3b2ac85c 100644 --- a/spec/models/spree/variant_spec.rb +++ b/spec/models/spree/variant_spec.rb @@ -366,8 +366,8 @@ module Spree p = create(:simple_product, variant_unit: 'volume') v = create(:variant, product: p, weight: nil) - p.update_attributes! variant_unit: 'weight', variant_unit_scale: 1 - v.update_attributes! unit_value: 10, unit_description: 'foo' + p.update! variant_unit: 'weight', variant_unit_scale: 1 + v.update! unit_value: 10, unit_description: 'foo' expect(v.reload.weight).to eq(0.01) end @@ -376,8 +376,8 @@ module Spree p = create(:simple_product, variant_unit: 'volume') v = create(:variant, product: p, weight: 123) - p.update_attributes! variant_unit: 'volume', variant_unit_scale: 1 - v.update_attributes! unit_value: 10, unit_description: 'foo' + p.update! variant_unit: 'volume', variant_unit_scale: 1 + v.update! unit_value: 10, unit_description: 'foo' expect(v.reload.weight).to eq(123) end @@ -386,11 +386,11 @@ module Spree p = create(:simple_product, variant_unit: 'volume') v = create(:variant, product: p, weight: 123) - p.update_attributes! variant_unit: 'weight', variant_unit_scale: 1 + p.update! variant_unit: 'weight', variant_unit_scale: 1 # Although invalid, this calls the before_validation callback, which would # error if not handling unit_value == nil case - expect(v.update_attributes(unit_value: nil, unit_description: 'foo')).to be false + expect(v.update(unit_value: nil, unit_description: 'foo')).to be false expect(v.reload.weight).to eq(123) end @@ -404,7 +404,7 @@ module Spree ov_orig = v.option_values.last expect { - v.update_attributes!(unit_value: 10, unit_description: 'foo') + v.update!(unit_value: 10, unit_description: 'foo') }.to change(Spree::OptionValue, :count).by(1) expect(v.option_values).not_to include ov_orig @@ -423,7 +423,7 @@ module Spree ov_new = v0.option_values.last expect { - v.update_attributes!(unit_value: 10, unit_description: 'foo') + v.update!(unit_value: 10, unit_description: 'foo') }.to change(Spree::OptionValue, :count).by(0) expect(v.option_values).not_to include ov_orig @@ -437,7 +437,7 @@ module Spree it "requests the name of the new option_value from OptionValueName" do expect_any_instance_of(OpenFoodNetwork::OptionValueNamer).to receive(:name).exactly(1).times.and_call_original - v.update_attributes(unit_value: 10, unit_description: 'foo') + v.update(unit_value: 10, unit_description: 'foo') ov = v.option_values.last expect(ov.name).to eq("10g foo") end @@ -449,7 +449,7 @@ module Spree it "does not request the name of the new option_value from OptionValueName" do expect_any_instance_of(OpenFoodNetwork::OptionValueNamer).not_to receive(:name) - v.update_attributes!(unit_value: 10, unit_description: 'foo') + v.update!(unit_value: 10, unit_description: 'foo') ov = v.option_values.last expect(ov.name).to eq("FOOS!") end @@ -500,7 +500,7 @@ module Spree end it "saves without infinite loop" do - expect(variant1.update_attributes(cost_price: 1)).to be_truthy + expect(variant1.update(cost_price: 1)).to be_truthy end end end diff --git a/spec/requests/checkout/stripe_connect_spec.rb b/spec/requests/checkout/stripe_connect_spec.rb index 697664b806..5c1561c13c 100644 --- a/spec/requests/checkout/stripe_connect_spec.rb +++ b/spec/requests/checkout/stripe_connect_spec.rb @@ -67,7 +67,7 @@ describe "checking out an order with a Stripe Connect payment method", type: :re allow(order_cycle_distributed_variants).to receive(:distributes_order_variants?) { true } allow(Stripe).to receive(:api_key) { "sk_test_12345" } - order.update_attributes(distributor_id: enterprise.id, order_cycle_id: order_cycle.id) + order.update(distributor_id: enterprise.id, order_cycle_id: order_cycle.id) order.reload.update_totals set_order order end diff --git a/spec/requests/checkout/stripe_sca_spec.rb b/spec/requests/checkout/stripe_sca_spec.rb index b3eb02014d..e590b3f601 100644 --- a/spec/requests/checkout/stripe_sca_spec.rb +++ b/spec/requests/checkout/stripe_sca_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe "checking out an order with a Stripe SCA payment method", type: :request do @@ -62,12 +64,12 @@ describe "checking out an order with a Stripe SCA payment method", type: :reques } end let(:payment_intent_response_mock) do - { status: 200, body: JSON.generate(object: "payment_intent", amount: 2000, charges: { data: [{ id: "ch_1234", amount: 2000 }]}) } + { status: 200, body: JSON.generate(object: "payment_intent", amount: 2000, charges: { data: [{ id: "ch_1234", amount: 2000 }] }) } end let(:payment_intent_authorize_response_mock) do { status: 200, body: JSON.generate(id: payment_intent_id, object: "payment_intent", amount: 2000, status: "requires_capture", last_payment_error: nil, - charges: { data: [{ id: "ch_1234", amount: 2000 }]}) } + charges: { data: [{ id: "ch_1234", amount: 2000 }] }) } end before do @@ -76,7 +78,7 @@ describe "checking out an order with a Stripe SCA payment method", type: :reques allow(order_cycle_distributed_variants).to receive(:distributes_order_variants?) { true } allow(Stripe).to receive(:api_key) { "sk_test_12345" } - order.update_attributes(distributor_id: enterprise.id, order_cycle_id: order_cycle.id) + order.update(distributor_id: enterprise.id, order_cycle_id: order_cycle.id) order.reload.update_totals set_order order @@ -145,10 +147,10 @@ describe "checking out an order with a Stripe SCA payment method", type: :reques context "when saving a card or using a stored card is involved" do let(:hubs_payment_method_response_mock) do - { - status: 200, - body: JSON.generate(id: hubs_stripe_payment_method, customer: customer_id) - } + { + status: 200, + body: JSON.generate(id: hubs_stripe_payment_method, customer: customer_id) + } end let(:customer_response_mock) do { @@ -315,8 +317,8 @@ describe "checking out an order with a Stripe SCA payment method", type: :reques context "when the stripe API sends a url for the authorization of the transaction" do let(:payment_intent_authorize_response_mock) do { status: 200, body: JSON.generate(id: payment_intent_id, object: "payment_intent", - next_source_action: { type: "authorize_with_url", authorize_with_url: { url: stripe_redirect_url }}, - status: "requires_source_action" )} + next_source_action: { type: "authorize_with_url", authorize_with_url: { url: stripe_redirect_url } }, + status: "requires_source_action" ) } end it "redirects the user to the authorization stripe url" do diff --git a/spec/serializers/api/admin/order_serializer_spec.rb b/spec/serializers/api/admin/order_serializer_spec.rb index 513e764e54..a29db28d24 100644 --- a/spec/serializers/api/admin/order_serializer_spec.rb +++ b/spec/serializers/api/admin/order_serializer_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "spec_helper" describe Api::Admin::OrderSerializer do diff --git a/spec/services/cache_service_spec.rb b/spec/services/cache_service_spec.rb index 68d77b7f1e..e329e6e8d5 100644 --- a/spec/services/cache_service_spec.rb +++ b/spec/services/cache_service_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe CacheService do diff --git a/spec/services/cart_service_spec.rb b/spec/services/cart_service_spec.rb index 397014e08a..0ff59b2b53 100644 --- a/spec/services/cart_service_spec.rb +++ b/spec/services/cart_service_spec.rb @@ -15,8 +15,10 @@ describe CartService do context "end-to-end" do let(:order) { create(:order, distributor: distributor, order_cycle: order_cycle) } let(:distributor) { create(:distributor_enterprise) } - let(:order_cycle) { create(:simple_order_cycle, distributors: [distributor], - variants: [variant]) } + let(:order_cycle) { + create(:simple_order_cycle, distributors: [distributor], + variants: [variant]) + } let(:cart_service) { CartService.new(order) } let(:variant) { create(:variant) } @@ -92,7 +94,7 @@ describe CartService do let!(:variant) { create(:variant) } it "returns true when item is not in cart and a quantity is specified" do - variant_data = { variant_id: variant.id, quantity: '2'} + variant_data = { variant_id: variant.id, quantity: '2' } expect(cart_service).to receive(:line_item_for_variant).with(variant).and_return(nil) expect(cart_service.send(:varies_from_cart, variant_data, variant )).to be true diff --git a/spec/services/order_checkout_restart_spec.rb b/spec/services/order_checkout_restart_spec.rb index 540a6a7637..f74a427c02 100644 --- a/spec/services/order_checkout_restart_spec.rb +++ b/spec/services/order_checkout_restart_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe OrderCheckoutRestart do diff --git a/spec/services/order_completion_reset_spec.rb b/spec/services/order_completion_reset_spec.rb index 0aab4b2fcc..de05203181 100644 --- a/spec/services/order_completion_reset_spec.rb +++ b/spec/services/order_completion_reset_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe OrderCompletionReset do diff --git a/spec/services/order_syncer_spec.rb b/spec/services/order_syncer_spec.rb index 21790656ad..9990425f6a 100644 --- a/spec/services/order_syncer_spec.rb +++ b/spec/services/order_syncer_spec.rb @@ -175,7 +175,7 @@ describe OrderSyncer do context "when the bill_address on the order doesn't match that on the subscription" do before do - order.bill_address.update_attributes!(firstname: "Jane") + order.bill_address.update!(firstname: "Jane") order.update! end @@ -220,7 +220,7 @@ describe OrderSyncer do context "when the bill_address on the order doesn't match that on the subscription" do before do - order.bill_address.update_attributes!(firstname: "Jane") + order.bill_address.update!(firstname: "Jane") order.update! end @@ -348,7 +348,7 @@ describe OrderSyncer do context "when the ship address on the order doesn't match that on the subscription" do before do - order.ship_address.update_attributes(firstname: "Jane") + order.ship_address.update(firstname: "Jane") order.update! end @@ -441,7 +441,7 @@ describe OrderSyncer do before { variant.update_attribute(:on_hand, 3) } context "when the changed line_item quantity matches the new quantity on the subscription line item" do - before { changed_line_item.update_attributes(quantity: 3) } + before { changed_line_item.update(quantity: 3) } it "does not change the quantity, and doesn't add the order to order_update_issues" do expect(order.reload.total.to_f).to eq 99.95 @@ -454,7 +454,7 @@ describe OrderSyncer do end context "when the changed line_item quantity doesn't match the new quantity on the subscription line item" do - before { changed_line_item.update_attributes(quantity: 2) } + before { changed_line_item.update(quantity: 2) } it "does not change the quantity, and adds the order to order_update_issues" do expect(order.reload.total.to_f).to eq 79.96 diff --git a/spec/services/order_tax_adjustments_fetcher_spec.rb b/spec/services/order_tax_adjustments_fetcher_spec.rb index e56e40d5af..2b06e5c4a2 100644 --- a/spec/services/order_tax_adjustments_fetcher_spec.rb +++ b/spec/services/order_tax_adjustments_fetcher_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "spec_helper" describe OrderTaxAdjustmentsFetcher do diff --git a/spec/services/permissions/order_spec.rb b/spec/services/permissions/order_spec.rb index 88e3666aca..61b3840139 100644 --- a/spec/services/permissions/order_spec.rb +++ b/spec/services/permissions/order_spec.rb @@ -13,7 +13,7 @@ module Permissions let(:order_cart) { create(:order, order_cycle: order_cycle, distributor: distributor, state: 'cart' ) } let(:order_from_last_year) { create(:completed_order_with_totals, order_cycle: order_cycle, distributor: distributor, - completed_at: Time.zone.now - 1.year) + completed_at: Time.zone.now - 1.year) } before { allow(OpenFoodNetwork::Permissions).to receive(:new) { basic_permissions } } diff --git a/spec/services/permitted_attributes/order_cycle_spec.rb b/spec/services/permitted_attributes/order_cycle_spec.rb index f91f358aab..5940e9bb62 100644 --- a/spec/services/permitted_attributes/order_cycle_spec.rb +++ b/spec/services/permitted_attributes/order_cycle_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' module PermittedAttributes @@ -37,6 +39,6 @@ module PermittedAttributes expect(exchange_variants["7"]).to be true expect(exchange_variants["12"]).to be true end - end + end end end diff --git a/spec/services/variant_overrides_indexed_spec.rb b/spec/services/variant_overrides_indexed_spec.rb index 15af405683..62cc1e6228 100644 --- a/spec/services/variant_overrides_indexed_spec.rb +++ b/spec/services/variant_overrides_indexed_spec.rb @@ -1,7 +1,9 @@ +# frozen_string_literal: true + require 'spec_helper' describe VariantOverridesIndexed do - subject(:variant_overrides) { described_class.new([variant.id],[distributor.id]) } + subject(:variant_overrides) { described_class.new([variant.id], [distributor.id]) } let(:distributor) { create(:distributor_enterprise) } let(:variant) { create(:variant) } diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 3c60e24f65..9ea40e8c66 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -43,7 +43,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")].sort.each { |f| require f } require 'spree/testing_support/capybara_ext' require 'spree/api/testing_support/setup' require 'spree/testing_support/authorization_helpers' diff --git a/spec/support/cancan_helper.rb b/spec/support/cancan_helper.rb index 332c93a19f..fb9b122664 100644 --- a/spec/support/cancan_helper.rb +++ b/spec/support/cancan_helper.rb @@ -9,7 +9,7 @@ module Spree target = options[:for] @ability_result = {} ability_hash = { ability_hash => true } if ability_hash.is_a? Symbol # e.g.: :create => {:create => true} - ability_hash = ability_hash.inject({}){ |_, i| _.merge(i => true) } if ability_hash.is_a? Array # e.g.: [:create, :read] => {:create=>true, :read=>true} + ability_hash = ability_hash.inject({}){ |member, i| member.merge(i => true) } if ability_hash.is_a? Array # e.g.: [:create, :read] => {:create=>true, :read=>true} ability_hash.each do |action, _true_or_false| @ability_result[action] = ability.can?(action, target) end @@ -18,10 +18,10 @@ module Spree failure_message do |user| ability_hash, options = expected - ability_hash = { ability_hash => true } if ability_hash.is_a? Symbol # e.g.: :create - ability_hash = ability_hash.inject({}){ |_, 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}" + ability_hash = { ability_hash => true } if ability_hash.is_a? Symbol # e.g.: :create + ability_hash = ability_hash.inject({}){ |member, i| member.merge(i => true) } if ability_hash.is_a? Array # e.g.: [:create, :read] => {:create=>true, :read=>true} + 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 diff --git a/spec/support/controller_requests_helper.rb b/spec/support/controller_requests_helper.rb index d9dee19e2f..fa02ed71d1 100644 --- a/spec/support/controller_requests_helper.rb +++ b/spec/support/controller_requests_helper.rb @@ -39,10 +39,10 @@ module ControllerRequestsHelper def process_json_action(action, params = {}, session = nil, flash = nil, method = "get") process_action_with_route(action, - params.reverse_merge!(format: :json), - session, - flash, - method) + params.reverse_merge!(format: :json), + session, + flash, + method) end def process_action_with_route(action, params = {}, session = nil, flash = nil, method = "GET") diff --git a/spec/support/request/authentication_workflow.rb b/spec/support/request/authentication_workflow.rb index 0eb32e3e7a..e07327d3e7 100644 --- a/spec/support/request/authentication_workflow.rb +++ b/spec/support/request/authentication_workflow.rb @@ -29,7 +29,7 @@ module AuthenticationWorkflow new_user = build(:user, attrs) new_user.spree_roles = [Spree::Role.find_or_create_by!(name: 'user')] new_user.save - if attrs.has_key? :enterprises + if attrs.key? :enterprises attrs[:enterprises].each do |enterprise| enterprise.users << new_user end diff --git a/spec/support/request/web_helper.rb b/spec/support/request/web_helper.rb index b03f7d9d39..732e306a29 100644 --- a/spec/support/request/web_helper.rb +++ b/spec/support/request/web_helper.rb @@ -38,7 +38,7 @@ module WebHelper def select_by_value(value, options = {}) from = options.delete :from - page.find_by_id(from).find("option[value='#{value}']").select_option + page.find_by(id: from).find("option[value='#{value}']").select_option end def flash_message diff --git a/spec/views/spree/admin/orders/invoice.html.haml_spec.rb b/spec/views/spree/admin/orders/invoice.html.haml_spec.rb index 8d7a82c129..32c3dd169d 100644 --- a/spec/views/spree/admin/orders/invoice.html.haml_spec.rb +++ b/spec/views/spree/admin/orders/invoice.html.haml_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "spec_helper" describe "spree/admin/orders/invoice.html.haml" do @@ -41,7 +43,7 @@ describe "spree/admin/orders/invoice.html.haml" do end it "displays shipping info" do - order.shipping_method.update_attributes!( + order.shipping_method.update!( name: "Home delivery", require_ship_address: true, ) @@ -62,7 +64,7 @@ describe "spree/admin/orders/invoice.html.haml" do it "hides billing address for pickups" do order.ship_address = adas_address - order.shipping_method.update_attributes!( + order.shipping_method.update!( name: "Pickup", require_ship_address: false, ) diff --git a/spec/views/spree/admin/payment_methods/index.html.haml_spec.rb b/spec/views/spree/admin/payment_methods/index.html.haml_spec.rb new file mode 100644 index 0000000000..84007bf961 --- /dev/null +++ b/spec/views/spree/admin/payment_methods/index.html.haml_spec.rb @@ -0,0 +1,28 @@ +require "spec_helper" + +describe "spree/admin/payment_methods/index.html.haml" do + before do + controller.singleton_class.class_eval do + helper_method :new_object_url, :edit_object_url, :object_url + + def new_object_url() "" end + + def edit_object_url(object, options = {}) "" end + + def object_url(object = nil, options = {}) "" end + end + + assign(:payment_methods, [ + create(:payment_method), + create(:payment_method) + ]) + end + + describe "payment methods index page" do + it "shows only the providers of the existing payment methods" do + render + + expect(rendered).to have_content "Cash/EFT/etc. (payments for which automatic validation is not required)", count: 2 + end + end +end diff --git a/spec/views/spree/shared/_order_details.html.haml_spec.rb b/spec/views/spree/shared/_order_details.html.haml_spec.rb index 3bd04caf7c..ac6d788f24 100644 --- a/spec/views/spree/shared/_order_details.html.haml_spec.rb +++ b/spec/views/spree/shared/_order_details.html.haml_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "spec_helper" describe "spree/shared/_order_details.html.haml" do