diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 378129593e..39510bf5f5 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,6 +1,6 @@ # This configuration was generated by # `rubocop --auto-gen-config --exclude-limit 1400` -# on 2018-09-19 19:24:45 +0200 using RuboCop version 0.57.2. +# on 2018-10-25 13:57:32 +1100 using RuboCop version 0.57.2. # The point is for the user to remove these configuration records # one by one as the offenses are removed from the code base. # Note that changes in the inspected code, or installation of new @@ -57,7 +57,7 @@ Layout/AlignHash: - 'spec/models/spree/shipping_method_spec.rb' - 'spec/models/spree/variant_spec.rb' -# Offense count: 62 +# Offense count: 60 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyle, IndentationWidth. # SupportedStyles: with_first_parameter, with_fixed_indentation @@ -67,7 +67,6 @@ Layout/AlignParameters: - 'app/models/enterprise.rb' - 'app/models/enterprise_group.rb' - 'app/models/enterprise_relationship.rb' - - 'app/models/spree/variant_decorator.rb' - 'app/serializers/api/address_serializer.rb' - 'app/serializers/api/enterprise_serializer.rb' - 'app/serializers/api/shipping_method_serializer.rb' @@ -126,7 +125,7 @@ Layout/ElseAlignment: - 'app/serializers/api/admin/order_cycle_serializer.rb' - 'lib/open_food_network/sales_tax_report.rb' -# Offense count: 201 +# Offense count: 197 # Cop supports --auto-correct. Layout/EmptyLines: Exclude: @@ -182,7 +181,6 @@ Layout/EmptyLines: - 'app/serializers/api/enterprise_serializer.rb' - 'lib/open_food_network/cached_products_renderer.rb' - 'lib/open_food_network/enterprise_fee_applicator.rb' - - 'lib/open_food_network/enterprise_fee_calculator.rb' - 'lib/open_food_network/enterprise_issue_validator.rb' - 'lib/open_food_network/integrity_checker.rb' - 'lib/open_food_network/lettuce_share_report.rb' @@ -201,7 +199,6 @@ Layout/EmptyLines: - 'lib/tasks/cache.rake' - 'lib/tasks/dev.rake' - 'lib/tasks/enterprises.rake' - - 'lib/tasks/users.rake' - 'spec/archive/features/consumer/checkout_spec.rb' - 'spec/controllers/admin/column_preferences_controller_spec.rb' - 'spec/controllers/admin/enterprises_controller_spec.rb' @@ -220,7 +217,6 @@ Layout/EmptyLines: - 'spec/features/admin/enterprises_spec.rb' - 'spec/features/admin/order_cycles_spec.rb' - 'spec/features/admin/orders_spec.rb' - - 'spec/features/admin/payment_method_spec.rb' - 'spec/features/admin/product_import_spec.rb' - 'spec/features/admin/products_spec.rb' - 'spec/features/admin/reports_spec.rb' @@ -268,7 +264,7 @@ Layout/EmptyLinesAroundArguments: Exclude: - 'spec/archive/features/consumer/checkout_spec.rb' -# Offense count: 61 +# Offense count: 59 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyle. # SupportedStyles: empty_lines, no_empty_lines @@ -285,7 +281,6 @@ Layout/EmptyLinesAroundBlockBody: - 'lib/open_food_network/group_buy_report.rb' - 'lib/spree/money_decorator.rb' - 'lib/tasks/dev.rake' - - 'lib/tasks/users.rake' - 'spec/controllers/admin/order_cycles_controller_spec.rb' - 'spec/controllers/admin/tag_rules_controller_spec.rb' - 'spec/controllers/spree/admin/orders_controller_spec.rb' @@ -315,7 +310,6 @@ Layout/EmptyLinesAroundBlockBody: - 'spec/lib/open_food_network/user_balance_calculator_spec.rb' - 'spec/models/billable_period_spec.rb' - 'spec/models/product_distribution_spec.rb' - - 'spec/models/product_import/product_list_spec.rb' - 'spec/models/spree/ability_spec.rb' - 'spec/models/spree/product_spec.rb' - 'spec/models/tag_rule/filter_payment_methods_spec.rb' @@ -368,7 +362,7 @@ Layout/EndAlignment: - 'app/serializers/api/admin/for_order_cycle/supplied_product_serializer.rb' - 'app/serializers/api/admin/order_cycle_serializer.rb' -# Offense count: 49 +# Offense count: 47 # Cop supports --auto-correct. # Configuration parameters: AllowForAlignment, ForceEqualSignAlignment. Layout/ExtraSpacing: @@ -378,7 +372,6 @@ Layout/ExtraSpacing: - 'app/helpers/admin/injection_helper.rb' - 'app/models/enterprise.rb' - 'app/models/spree/classification_decorator.rb' - - 'app/models/spree/product_set.rb' - 'app/serializers/api/enterprise_serializer.rb' - 'config.ru' - 'lib/open_food_network/bulk_coop_report.rb' @@ -394,7 +387,6 @@ Layout/ExtraSpacing: - 'spec/features/admin/reports_spec.rb' - 'spec/features/consumer/groups_spec.rb' - 'spec/features/consumer/shopping/shopping_spec.rb' - - 'spec/helpers/cookies_policy_helper_spec.rb' - 'spec/lib/open_food_network/enterprise_fee_calculator_spec.rb' - 'spec/lib/open_food_network/reports/rule_spec.rb' - 'spec/models/enterprise_fee_spec.rb' @@ -444,7 +436,7 @@ Layout/IndentationConsistency: - 'spec/models/spree/line_item_spec.rb' - 'spec/models/spree/product_spec.rb' -# Offense count: 20 +# Offense count: 19 # Cop supports --auto-correct. # Configuration parameters: Width, IgnoredPatterns. Layout/IndentationWidth: @@ -455,7 +447,6 @@ Layout/IndentationWidth: - 'app/serializers/api/admin/for_order_cycle/enterprise_serializer.rb' - 'app/serializers/api/admin/for_order_cycle/supplied_product_serializer.rb' - 'app/serializers/api/admin/order_cycle_serializer.rb' - - 'lib/discourse/single_sign_on.rb' - 'spec/features/consumer/shopping/variant_overrides_spec.rb' - 'spec/helpers/admin/business_model_configuration_helper_spec.rb' - 'spec/helpers/groups_helper_spec.rb' @@ -472,7 +463,7 @@ Layout/LeadingBlankLines: Exclude: - 'lib/tasks/dev.rake' -# Offense count: 46 +# Offense count: 44 # Cop supports --auto-correct. Layout/LeadingCommentSpace: Exclude: @@ -484,7 +475,6 @@ Layout/LeadingCommentSpace: - 'app/serializers/api/address_serializer.rb' - 'app/serializers/api/enterprise_serializer.rb' - 'app/serializers/api/product_serializer.rb' - - 'lib/tasks/users.rake' - 'spec/archive/features/consumer/checkout_spec.rb' - 'spec/controllers/spree/api/line_items_controller_spec.rb' - 'spec/features/admin/products_spec.rb' @@ -554,7 +544,7 @@ Layout/MultilineMethodCallIndentation: - 'spec/lib/open_food_network/cached_products_renderer_spec.rb' - 'spec/serializers/variant_serializer_spec.rb' -# Offense count: 28 +# Offense count: 26 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyle, IndentationWidth. # SupportedStyles: aligned, indented @@ -566,7 +556,6 @@ Layout/MultilineOperationIndentation: - 'app/helpers/enterprises_helper.rb' - 'app/models/producer_property.rb' - 'app/models/spree/ability_decorator.rb' - - 'app/models/spree/product_set.rb' - 'app/models/variant_override_set.rb' - 'lib/open_food_network/accounts_and_billing_settings_validator.rb' - 'lib/open_food_network/order_cycle_permissions.rb' @@ -666,7 +655,7 @@ Layout/SpaceAroundEqualsInParameterDefault: - 'spec/support/request/distribution_helper.rb' - 'spec/support/request/web_helper.rb' -# Offense count: 57 +# Offense count: 55 # Cop supports --auto-correct. # Configuration parameters: AllowForAlignment. Layout/SpaceAroundOperators: @@ -674,7 +663,6 @@ Layout/SpaceAroundOperators: - 'app/controllers/checkout_controller.rb' - 'app/helpers/admin/business_model_configuration_helper.rb' - 'app/jobs/update_billable_periods.rb' - - 'app/models/spree/address_decorator.rb' - 'app/overrides/remove_search_bar.rb' - 'app/overrides/remove_side_bar.rb' - 'app/overrides/replace_shipping_address_form_with_distributor_details.rb' @@ -687,7 +675,6 @@ Layout/SpaceAroundOperators: - 'spec/features/admin/bulk_product_update_spec.rb' - 'spec/features/consumer/shopping/checkout_spec.rb' - 'spec/helpers/checkout_helper_spec.rb' - - 'spec/helpers/cookies_policy_helper_spec.rb' - 'spec/helpers/order_cycles_helper_spec.rb' - 'spec/jobs/update_billable_periods_spec.rb' - 'spec/lib/open_food_network/order_grouper_spec.rb' @@ -799,7 +786,7 @@ Layout/SpaceInsideBlockBraces: - 'spec/spec_helper.rb' - 'spec/support/cancan_helper.rb' -# Offense count: 734 +# Offense count: 728 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBraces. # SupportedStyles: space, no_space, compact @@ -843,7 +830,6 @@ Layout/SpaceInsideHashLiteralBraces: - 'lib/open_food_network/sales_tax_report.rb' - 'lib/open_food_network/variant_and_line_item_naming.rb' - 'lib/open_food_network/xero_invoices_report.rb' - - 'lib/tasks/users.rake' - 'spec/controllers/admin/accounts_and_billing_settings_controller_spec.rb' - 'spec/controllers/admin/business_model_configuration_controller_spec.rb' - 'spec/controllers/admin/enterprises_controller_spec.rb' @@ -949,13 +935,12 @@ Layout/TrailingBlankLines: Exclude: - 'spec/controllers/cart_controller_spec.rb' -# Offense count: 64 +# Offense count: 60 # Cop supports --auto-correct. # Configuration parameters: AllowInHeredoc. Layout/TrailingWhitespace: Exclude: - 'app/models/distributor_shipping_method.rb' - - 'app/models/spree/calculator/default_tax_decorator.rb' - 'app/models/spree/money_decorator.rb' - 'app/models/spree/product_decorator.rb' - 'app/serializers/api/image_serializer.rb' @@ -968,7 +953,6 @@ Layout/TrailingWhitespace: - 'spec/features/admin/customers_spec.rb' - 'spec/features/admin/variant_overrides_spec.rb' - 'spec/features/consumer/cookies_spec.rb' - - 'spec/helpers/cookies_policy_helper_spec.rb' - 'spec/helpers/enterprises_helper_spec.rb' - 'spec/lib/open_food_network/enterprise_fee_calculator_spec.rb' - 'spec/lib/open_food_network/group_buy_report_spec.rb' @@ -979,7 +963,6 @@ Layout/TrailingWhitespace: - 'spec/serializers/admin/enterprise_serializer_spec.rb' - 'spec/serializers/enterprise_serializer_spec.rb' - 'spec/support/request/menu_helper.rb' - - 'spec/views/json/producers.json.rabl_spec.rb' # Offense count: 1 Lint/AmbiguousOperator: @@ -1027,11 +1010,10 @@ Lint/ScriptPermission: Exclude: - 'Rakefile' -# Offense count: 5 +# Offense count: 3 Lint/ShadowingOuterLocalVariable: Exclude: - 'app/models/model_set.rb' - - 'app/models/spree/product_set.rb' - 'spec/models/model_set_spec.rb' # Offense count: 6 @@ -1111,7 +1093,7 @@ Lint/UselessAccessModifier: - 'lib/open_food_network/reports/bulk_coop_report.rb' - 'spec/lib/open_food_network/reports/report_spec.rb' -# Offense count: 246 +# Offense count: 242 # Configuration parameters: CheckForMethodsWithNoSideEffects. Lint/Void: Exclude: @@ -1126,7 +1108,6 @@ Lint/Void: - 'spec/controllers/spree/admin/variants_controller_spec.rb' - 'spec/controllers/spree/api/products_controller_spec.rb' - 'spec/controllers/spree/api/variants_controller_spec.rb' - - 'spec/controllers/user_registrations_controller_spec.rb' - 'spec/features/admin/bulk_product_update_spec.rb' - 'spec/features/admin/enterprise_groups_spec.rb' - 'spec/features/admin/enterprises/index_spec.rb' @@ -1167,11 +1148,11 @@ Lint/Void: - 'spec/serializers/enterprise_serializer_spec.rb' - 'spec/support/request/web_helper.rb' -# Offense count: 195 +# Offense count: 192 Metrics/AbcSize: Max: 293 -# Offense count: 1010 +# Offense count: 1039 # Configuration parameters: CountComments, ExcludedMethods. Metrics/BlockLength: Max: 787 @@ -1186,17 +1167,17 @@ Metrics/BlockNesting: Metrics/ClassLength: Max: 331 -# Offense count: 38 +# Offense count: 36 Metrics/CyclomaticComplexity: Max: 23 -# Offense count: 6683 +# Offense count: 2717 # Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns. # URISchemes: http, https Metrics/LineLength: - Max: 623 + Max: 619 -# Offense count: 163 +# Offense count: 161 # Configuration parameters: CountComments. Metrics/MethodLength: Max: 95 @@ -1211,7 +1192,7 @@ Metrics/ModuleLength: Metrics/ParameterLists: Max: 8 -# Offense count: 30 +# Offense count: 28 Metrics/PerceivedComplexity: Max: 21 @@ -1318,10 +1299,11 @@ Performance/DoubleStartEndWith: Exclude: - 'app/helpers/application_helper.rb' -# Offense count: 4 +# Offense count: 5 # Cop supports --auto-correct. Performance/InefficientHashSearch: Exclude: + - 'app/models/product_import/product_importer.rb' - 'app/models/spree/payment_method_decorator.rb' - 'app/models/spree/preferences/file_configuration.rb' - 'lib/stripe/account_connector.rb' @@ -1358,11 +1340,10 @@ Performance/StringReplacement: - 'app/helpers/spree/admin/navigation_helper_decorator.rb' - 'app/models/spree/preferences/file_configuration.rb' -# Offense count: 5 +# Offense count: 4 # Cop supports --auto-correct. Performance/UnneededSort: Exclude: - - 'app/models/spree/product_decorator.rb' - 'spec/features/admin/order_cycles_spec.rb' # Offense count: 11 @@ -1431,7 +1412,7 @@ Rails/HasAndBelongsToMany: - 'app/models/spree/line_item_decorator.rb' - 'app/models/spree/payment_method_decorator.rb' -# Offense count: 29 +# Offense count: 28 # Configuration parameters: Include. # Include: app/models/**/*.rb Rails/HasManyOrHasOneDependent: @@ -1441,7 +1422,6 @@ Rails/HasManyOrHasOneDependent: - 'app/models/customer.rb' - 'app/models/enterprise.rb' - 'app/models/order_cycle.rb' - - 'app/models/spree/address_decorator.rb' - 'app/models/spree/adjustment_decorator.rb' - 'app/models/spree/order_decorator.rb' - 'app/models/spree/payment_method_decorator.rb' @@ -1491,7 +1471,7 @@ Rails/OutputSafety: - 'lib/spree/money_decorator.rb' - 'spec/features/admin/orders_spec.rb' -# Offense count: 7 +# Offense count: 10 # Cop supports --auto-correct. Rails/PluralizationGrammar: Exclude: @@ -1499,6 +1479,7 @@ Rails/PluralizationGrammar: - 'spec/jobs/update_account_invoices_spec.rb' - 'spec/jobs/update_billable_periods_spec.rb' - 'spec/models/order_cycle_spec.rb' + - 'spec/models/spree/product_spec.rb' # Offense count: 1 # Cop supports --auto-correct. @@ -1566,7 +1547,7 @@ Rails/UnknownEnv: Exclude: - 'lib/open_food_network/cached_products_renderer.rb' -# Offense count: 21 +# Offense count: 19 # Cop supports --auto-correct. # Configuration parameters: Include. # Include: app/models/**/*.rb @@ -1580,10 +1561,9 @@ Rails/Validation: - 'app/models/order_cycle.rb' - 'app/models/product_distribution.rb' - 'app/models/spree/product_decorator.rb' - - 'app/models/spree/variant_decorator.rb' - 'app/models/variant_override.rb' -# Offense count: 20 +# Offense count: 18 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyle. # SupportedStyles: always, conditionals @@ -1598,20 +1578,18 @@ Style/AndOr: - 'app/helpers/spree/admin/navigation_helper_decorator.rb' - 'app/models/spree/adjustment_decorator.rb' - 'app/models/spree/order_decorator.rb' - - 'app/models/spree/product_set.rb' - 'app/views/json/partials/_enterprise.rabl' - 'lib/spree/core/controller_helpers/respond_with_decorator.rb' -# Offense count: 2 +# Offense count: 1 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyle. # SupportedStyles: percent_q, bare_percent Style/BarePercentLiterals: Exclude: - 'spec/features/admin/variants_spec.rb' - - 'spec/support/request/web_helper.rb' -# Offense count: 207 +# Offense count: 212 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyle. # SupportedStyles: braces, no_braces, context_dependent @@ -1659,6 +1637,7 @@ Style/BracesAroundHashParameters: - 'spec/controllers/spree/api/variants_controller_spec.rb' - 'spec/controllers/spree/orders_controller_spec.rb' - 'spec/controllers/user_confirmations_controller_spec.rb' + - 'spec/controllers/user_registrations_controller_spec.rb' - 'spec/features/admin/accounts_and_billing_settings_spec.rb' - 'spec/features/admin/business_model_configuration_spec.rb' - 'spec/features/admin/order_cycles_spec.rb' @@ -1802,7 +1781,7 @@ Style/CommentedKeyword: Exclude: - 'app/controllers/application_controller.rb' -# Offense count: 4 +# Offense count: 6 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyle, SingleLineConditionsOnly, IncludeTernaryExpressions. # SupportedStyles: assign_to_condition, assign_inside_condition @@ -1810,6 +1789,7 @@ Style/ConditionalAssignment: Exclude: - 'app/controllers/checkout_controller.rb' - 'app/controllers/spree/admin/search_controller_decorator.rb' + - 'app/models/spree/calculator/per_item_decorator.rb' - 'app/models/spree/line_item_decorator.rb' - 'spec/lib/open_food_network/order_grouper_spec.rb' @@ -1863,7 +1843,7 @@ Style/FormatStringToken: - 'lib/open_food_network/sales_tax_report.rb' - 'spec/models/enterprise_spec.rb' -# Offense count: 79 +# Offense count: 80 # Configuration parameters: MinBodyLength. Style/GuardClause: Exclude: @@ -1911,7 +1891,7 @@ Style/GuardClause: - 'spec/support/request/distribution_helper.rb' - 'spec/support/request/shop_workflow.rb' -# Offense count: 930 +# Offense count: 924 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyle, UseHashRocketsWithSymbolValues, PreferHashRocketsForNonAlnumEndingSymbols. # SupportedStyles: ruby19, hash_rockets, no_mixed_keys, ruby19_no_mixed_keys @@ -1955,7 +1935,6 @@ Style/HashSyntax: - 'app/models/open_food_network/calculator/weight.rb' - 'app/models/order_cycle.rb' - 'app/models/product_distribution.rb' - - 'app/models/spree/address_decorator.rb' - 'app/models/spree/adjustment_decorator.rb' - 'app/models/spree/classification_decorator.rb' - 'app/models/spree/gateway/migs.rb' @@ -1967,7 +1946,6 @@ Style/HashSyntax: - 'app/models/spree/payment_decorator.rb' - 'app/models/spree/payment_method_decorator.rb' - 'app/models/spree/product_decorator.rb' - - 'app/models/spree/product_set.rb' - 'app/models/spree/taxon_decorator.rb' - 'app/models/spree/user_decorator.rb' - 'app/overrides/add_distributor_details_js_to_product.rb' @@ -2302,7 +2280,7 @@ Style/RedundantReturn: - 'app/models/spree/classification_decorator.rb' - 'app/serializers/api/admin/enterprise_serializer.rb' -# Offense count: 98 +# Offense count: 96 # Cop supports --auto-correct. Style/RedundantSelf: Exclude: @@ -2313,7 +2291,6 @@ Style/RedundantSelf: - 'app/models/open_food_network/calculator/weight.rb' - 'app/models/order_cycle.rb' - 'app/models/producer_property.rb' - - 'app/models/spree/address_decorator.rb' - 'app/models/spree/calculator/flat_percent_item_total_decorator.rb' - 'app/models/spree/calculator/flexi_rate_decorator.rb' - 'app/models/spree/calculator/per_item_decorator.rb' @@ -2359,7 +2336,56 @@ Style/RescueModifier: - 'app/controllers/spree/admin/orders_controller_decorator.rb' - 'lib/tasks/data.rake' -# Offense count: 5 +# Offense count: 268 +Style/Send: + Exclude: + - 'spec/controllers/admin/subscriptions_controller_spec.rb' + - 'spec/controllers/checkout_controller_spec.rb' + - 'spec/controllers/shop_controller_spec.rb' + - 'spec/controllers/spree/admin/base_controller_spec.rb' + - 'spec/controllers/spree/orders_controller_spec.rb' + - 'spec/helpers/order_cycles_helper_spec.rb' + - 'spec/jobs/refresh_products_cache_job_spec.rb' + - 'spec/jobs/subscription_confirm_job_spec.rb' + - 'spec/jobs/subscription_placement_job_spec.rb' + - 'spec/lib/open_food_network/address_finder_spec.rb' + - 'spec/lib/open_food_network/enterprise_fee_applicator_spec.rb' + - 'spec/lib/open_food_network/enterprise_fee_calculator_spec.rb' + - 'spec/lib/open_food_network/lettuce_share_report_spec.rb' + - 'spec/lib/open_food_network/option_value_namer_spec.rb' + - 'spec/lib/open_food_network/order_cycle_form_applicator_spec.rb' + - 'spec/lib/open_food_network/permissions_spec.rb' + - 'spec/lib/open_food_network/products_and_inventory_report_spec.rb' + - 'spec/lib/open_food_network/products_cache_spec.rb' + - 'spec/lib/open_food_network/products_renderer_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/subscription_summarizer_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' + - 'spec/models/enterprise_spec.rb' + - 'spec/models/exchange_spec.rb' + - 'spec/models/order_cycle_spec.rb' + - 'spec/models/product_distribution_spec.rb' + - 'spec/models/spree/gateway/stripe_connect_spec.rb' + - 'spec/models/spree/line_item_spec.rb' + - 'spec/models/spree/order_spec.rb' + - 'spec/models/spree/payment_spec.rb' + - 'spec/models/spree/preference_spec.rb' + - 'spec/models/spree/tax_rate_spec.rb' + - 'spec/models/tag_rule/discount_order_spec.rb' + - 'spec/models/tag_rule/filter_order_cycles_spec.rb' + - 'spec/models/tag_rule/filter_payment_methods_spec.rb' + - 'spec/models/tag_rule/filter_products_spec.rb' + - 'spec/models/tag_rule/filter_shipping_methods_spec.rb' + - 'spec/services/cart_service_spec.rb' + - 'spec/spec_helper.rb' + - 'spec/support/localized_number_helper.rb' + - 'spec/support/matchers/delegate_matchers.rb' + - 'spec/support/request/web_helper.rb' + +# Offense count: 3 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyle. # SupportedStyles: require_parentheses, require_no_parentheses @@ -2468,7 +2494,7 @@ Style/UnneededInterpolation: - 'spec/lib/open_food_network/order_cycle_form_applicator_spec.rb' - 'spec/support/request/ui_component_helper.rb' -# Offense count: 23 +# Offense count: 22 # Cop supports --auto-correct. Style/UnneededPercentQ: Exclude: @@ -2494,10 +2520,3 @@ Style/UnneededPercentQ: - 'spec/features/admin/variants_spec.rb' - 'spec/features/consumer/account_spec.rb' - 'spec/features/consumer/producers_spec.rb' - - 'spec/support/request/web_helper.rb' - -# Offense count: 6683 -# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns. -# URISchemes: http, https -Metrics/LineLength: - Max: 623 diff --git a/app/controllers/admin/variant_overrides_controller.rb b/app/controllers/admin/variant_overrides_controller.rb index 4a49f53c7c..f7145e84c7 100644 --- a/app/controllers/admin/variant_overrides_controller.rb +++ b/app/controllers/admin/variant_overrides_controller.rb @@ -61,10 +61,8 @@ module Admin def inventory_import_dates import_dates = VariantOverride. - select('DISTINCT variant_overrides.import_date'). - where('variant_overrides.hub_id IN (?) - AND variant_overrides.import_date IS NOT NULL', editable_enterprises.collect(&:id)). - order('import_date DESC') + distinct_import_dates. + for_hubs(editable_enterprises.collect(&:id)) options = [{ id: '0', name: 'All' }] import_dates.collect(&:import_date).map { |i| options.push(id: i.to_date, name: i.to_date.to_formatted_s(:long)) } diff --git a/app/controllers/spree/admin/orders_controller_decorator.rb b/app/controllers/spree/admin/orders_controller_decorator.rb index 7d199d5de7..0aa3ebab68 100644 --- a/app/controllers/spree/admin/orders_controller_decorator.rb +++ b/app/controllers/spree/admin/orders_controller_decorator.rb @@ -61,12 +61,7 @@ Spree::Admin::OrdersController.class_eval do format.json do render json: { orders: ActiveModel::ArraySerializer.new(@orders, each_serializer: Api::Admin::OrderSerializer), - pagination: { - results: @orders.total_count, - pages: @orders.num_pages.to_i, - page: params[:page].to_i, - per_page: params[:per_page].to_i - } + pagination: pagination_data } end end @@ -115,7 +110,30 @@ Spree::Admin::OrdersController.class_eval do @search.result.includes([:user, :shipments, :payments]).distributed_by_user(spree_current_user) end - @search.result.page(params[:page]).per(params[:per_page] || Spree::Config[:orders_per_page]) + search_results + end + + def search_results + if using_pagination? + @search.result.page(params[:page]).per(params[:per_page] || Spree::Config[:orders_per_page]) + else + @search.result + end + end + + def using_pagination? + params[:per_page] + end + + def pagination_data + if using_pagination? + { + results: @orders.total_count, + pages: @orders.num_pages, + page: params[:page].to_i, + per_page: params[:per_page].to_i + } + end end def require_distributor_abn diff --git a/app/models/product_import/entry_processor.rb b/app/models/product_import/entry_processor.rb index 22bae53907..98a23d06fb 100644 --- a/app/models/product_import/entry_processor.rb +++ b/app/models/product_import/entry_processor.rb @@ -135,7 +135,7 @@ module ProductImport @inventory_created += 1 @updated_ids.push new_item.id else - @importer.errors.add("#{I18n.t('admin.product_import.model.line')} #{line_number}:", new_item.errors.full_messages) + assign_errors new_item.errors.full_messages, entry.line_number end end @@ -149,7 +149,7 @@ module ProductImport @inventory_updated += 1 @updated_ids.push existing_item.id else - @importer.errors.add("#{I18n.t('admin.product_import.model.line')} #{line_number}:", existing_item.errors.full_messages) + assign_errors existing_item.errors.full_messages, entry.line_number end end @@ -173,7 +173,7 @@ module ProductImport @products_created += 1 @updated_ids.push product.variants.first.id else - @importer.errors.add("#{I18n.t('admin.product_import.model.line')} #{line_number}:", product.errors.full_messages) + assign_errors product.errors.full_messages, entry.line_number end @already_created[entry.supplier_id] = { entry.name => product.id } @@ -188,11 +188,19 @@ module ProductImport @updated_ids.push variant.id true else - @importer.errors.add("#{I18n.t('admin.product_import.model.line')} #{line_number}:", variant.errors.full_messages) + assign_errors variant.errors.full_messages, entry.line_number false end end + def assign_errors(errors, line_number) + @importer.errors.add( + I18n.t('admin.product_import.model.line_number', + number: line_number), + errors + ) + end + def assign_defaults(object, entry) # Assigns a default value for a specified field e.g. category='Vegetables', setting this value # either for all entries (overwrite_all), or only for those entries where the field was blank diff --git a/app/models/spree/address_decorator.rb b/app/models/spree/address_decorator.rb index db092f5eb2..ff7c1f0665 100644 --- a/app/models/spree/address_decorator.rb +++ b/app/models/spree/address_decorator.rb @@ -1,35 +1,27 @@ Spree::Address.class_eval do - has_one :enterprise + has_one :enterprise, dependent: :restrict belongs_to :country, class_name: "Spree::Country" after_save :touch_enterprise geocoded_by :geocode_address - delegate :name, :to => :state, :prefix => true, :allow_nil => true + delegate :name, to: :state, prefix: true, allow_nil: true def geocode_address - geocode_address = [address1, address2, zipcode, city, country.andand.name, state.andand.name] - filtered_address = geocode_address.select{ |field| !field.nil? && field != '' } - filtered_address.compact.join(', ') + render_address([address1, address2, zipcode, city, country.andand.name, state.andand.name]) end def full_address - full_address = [address1, address2, city, zipcode, state.andand.name] - filtered_address = full_address.select{ |field| !field.nil? && field != '' } - filtered_address.compact.join(', ') + render_address([address1, address2, city, zipcode, state.andand.name]) end def address_part1 - address_part1 = [address1, address2] - filtered_address = address_part1.select{ |field| !field.nil? && field != '' } - filtered_address.compact.join(', ') + render_address([address1, address2]) end def address_part2 - address_part2= [city, zipcode, state.andand.name] - filtered_address = address_part2.select{ |field| !field.nil? && field != '' } - filtered_address.compact.join(', ') + render_address([city, zipcode, state.andand.name]) end private @@ -38,26 +30,7 @@ Spree::Address.class_eval do enterprise.andand.touch end - # We have a hard-to-track-down bug around invalid addresses with all-nil fields finding - # their way into the database. I don't know what the source of them is, so this patch - # is designed to track them down. - # This is intended to be a temporary investigative measure, and should be removed from the - # code base shortly. If it's past 17-10-2013, take it out. - # - #-- Rohan, 17-9-2913 - def create - if self.zipcode.nil? - Bugsnag.notify RuntimeError.new('Creating a Spree::Address with nil values') - end - - super - end - - def update(attribute_names = @attributes.keys) - if self.zipcode.nil? - Bugsnag.notify RuntimeError.new('Updating a Spree::Address with nil values') - end - - super(attribute_names) + def render_address(parts) + parts.select(&:present?).join(', ') end end diff --git a/app/models/variant_override.rb b/app/models/variant_override.rb index a6a5dfe8ed..89d2fdcd13 100644 --- a/app/models/variant_override.rb +++ b/app/models/variant_override.rb @@ -3,8 +3,6 @@ class VariantOverride < ActiveRecord::Base acts_as_taggable - attr_accessor :import_date - belongs_to :hub, class_name: 'Enterprise' belongs_to :variant, class_name: 'Spree::Variant' @@ -21,6 +19,12 @@ class VariantOverride < ActiveRecord::Base where(hub_id: hubs) } + scope :distinct_import_dates, lambda { + select('DISTINCT variant_overrides.import_date'). + where('variant_overrides.import_date IS NOT NULL'). + order('import_date DESC') + } + localize_number :price def self.indexed(hub) diff --git a/config/initializers/geocoder.rb b/config/initializers/geocoder.rb new file mode 100644 index 0000000000..35b5510d5e --- /dev/null +++ b/config/initializers/geocoder.rb @@ -0,0 +1,6 @@ +# Google requires an API key with a billing account to use their API. +# The key is stored in config/application.yml. +Geocoder.configure( + use_https: true, + api_key: ENV.fetch('GOOGLE_MAPS_API_KEY', nil) +) diff --git a/config/initializers/spree.rb b/config/initializers/spree.rb index 5c60a92778..72ca8bb14c 100644 --- a/config/initializers/spree.rb +++ b/config/initializers/spree.rb @@ -24,6 +24,9 @@ Spree.config do |config| config.order_updater_decorator = OrderUpdater end +# Don't log users out when setting a new password +Spree::Auth::Config[:signout_after_password_change] = false + # TODO Work out why this is necessary # Seems like classes within OFN module become 'uninitialized' when server reloads # unless the empty module is explicity 'registered' here. Something to do with autoloading? diff --git a/config/initializers/stripe.rb b/config/initializers/stripe.rb index 8237b0dcab..d4dc8950e0 100644 --- a/config/initializers/stripe.rb +++ b/config/initializers/stripe.rb @@ -4,6 +4,8 @@ # a bit cleaner than accessing keys in different ways. module Stripe class << self + # Returns the value of Stripe.publishable_key and Stripe.endpoint_secret. + # Attribute values can also be set by doing Stripe.publishable_key = attr_accessor :publishable_key, :endpoint_secret end end diff --git a/config/locales/en.yml b/config/locales/en.yml index f8f944527e..cc481d650c 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -519,7 +519,7 @@ en: products_no_permission: you do not have permission to manage products for this enterprise inventory_no_permission: you do not have permission to create inventory for this producer none_saved: did not save any products successfully - line: Line + line_number: "Line %{number}:" index: select_file: Select a spreadsheet to upload spreadsheet: Spreadsheet diff --git a/config/locales/en_GB.yml b/config/locales/en_GB.yml index 14021d1398..8a89b35ac7 100644 --- a/config/locales/en_GB.yml +++ b/config/locales/en_GB.yml @@ -55,6 +55,7 @@ en_GB: user_registrations: spree_user: signed_up_but_unconfirmed: "A message with a confirmation link has been sent to your email address. Please open the link to activate your account." + unknown_error: "Something went wrong while creating your account. Check your email address and try again." failure: invalid: | Invalid email or password. @@ -64,6 +65,9 @@ en_GB: user_passwords: spree_user: updated_not_active: "Your password has been reset, but your email has not been confirmed yet." + models: + order_cycle: + cloned_order_cycle_name: "COPY OF %{order_cycle}" enterprise_mailer: confirmation_instructions: subject: "Please confirm the email address for %{enterprise}" @@ -71,9 +75,26 @@ en_GB: subject: "%{enterprise} is now on %{sitename}" invite_manager: subject: "%{enterprise} has invited you to be a manager" + order_mailer: + cancel_email: + dear_customer: "Dear Customer," + instructions: "Your order has been CANCELED. Please retain this cancellation information for your records." + order_summary_canceled: "Order Summary [CANCELED]" + subject: "Cancellation of Order" + subtotal: "Subtotal: %{subtotal}" + total: "Order Total: %{total}" producer_mailer: order_cycle: subject: "Order cycle report for %{producer}" + shipment_mailer: + shipped_email: + dear_customer: "Dear Customer," + instructions: "Your order has been shipped" + shipment_summary: "Shipment Summary" + subject: "Shipment Notification" + thanks: "Thank you for your order with us." + track_information: "Tracking Information: %{tracking}" + track_link: "Tracking Link: %{url}" subscription_mailer: placement_summary_email: subject: A summary of recently placed subscription orders @@ -438,11 +459,12 @@ en_GB: conditional_blank: can't be blank if unit_type is blank no_product: did not match any products in the database not_found: not found in database + not_updatable: cannot be updated on existing products via product import blank: can't be blank products_no_permission: you do not have permission to manage products for this enterprise inventory_no_permission: you do not have permission to create inventory for this producer none_saved: did not save any products successfully - line: Line + line_number: "Line %{number}:" index: select_file: Select a spreadsheet to upload spreadsheet: Spreadsheet @@ -496,6 +518,11 @@ en_GB: inventory_to_reset: Existing inventory items will have their stock reset to zero line: Line item_line: Item line + import_review: + not_updatable_tip: "The following fields cannot be updated via bulk import for existing products:" + fields_ignored: These fields will be ignored when the imported products are saved. + entries_table: + not_updatable: This field is not updatable via bulk import on existing products save_results: final_results: Import final results products_created: Products created @@ -536,9 +563,6 @@ en_GB: controls: back_to_my_inventory: Back to my inventory orders: - index: - capture: "Capture" - ship: "Ship" invoice_email_sent: 'Invoice email has been sent' order_email_resent: 'Order email has been resent' bulk_management: @@ -745,7 +769,7 @@ en_GB: change_type_form: producer_profile: Producer Profile connect_ofn: Connect through OFN - always_free: ALWAYS FREE + always_free: Plans starting from £1/month producer_description_text: Add your products to Open Food Network, allowing hubs to stock your products in their stores. producer_shop: Producer Shop sell_your_produce: Sell your own produce @@ -782,6 +806,14 @@ en_GB: new: title: New Enterprise back_link: Back to enterprises list + remove_logo: + remove: "Remove Image" + removed_successfully: "Logo removed successfully" + immediate_removal_warning: "The logo will be removed immediately after you confirm." + remove_promo_image: + remove: "Remove Image" + removed_successfully: "Promo image removed successfully" + immediate_removal_warning: "The promo image will be removed immediately after you confirm." welcome: welcome_title: Welcome to the Open Food Network! welcome_text: You have successfully created a @@ -815,7 +847,10 @@ en_GB: coordinator_fees: add: Add coordinator fee filters: + search_by_order_cycle_name: "Search by Order Cycle name..." involving: "Involving" + any_enterprise: "Any Enterprise" + any_schedule: "Any Schedule" form: incoming: Incoming supplier: Supplier @@ -1020,6 +1055,11 @@ en_GB: stripe_connect_fail: Sorry, the connection of your Stripe account failed stripe_connect_settings: resource: Stripe Connect configuration + api: + enterprise_logo: + destroy_attachment_does_not_exist: "Logo does not exist" + enterprise_promo_image: + destroy_attachment_does_not_exist: "Promo image does not exist" checkout: already_ordered: cart: "cart" @@ -1105,6 +1145,8 @@ en_GB: menu_2_url: "/map" menu_3_title: "Services" menu_3_url: "https://about.openfoodnetwork.org.uk/services" + menu_4_title: "Groups" + menu_4_url: "/groups" menu_5_title: "About" menu_5_url: "https://about.openfoodnetwork.org.uk" menu_6_title: "Blog" @@ -1126,6 +1168,7 @@ en_GB: footer_email: "Email" footer_links_md: "Links" footer_about_url: "About URL" + user_guide_link: "User Guide Link" name: Name first_name: First Name last_name: Last Name @@ -1218,6 +1261,7 @@ en_GB: statistics_cookies_desc: "The following are not strictly necessary, but help to provide you with the best user experience by allowing us to analyse user behaviour, identify which features you use most, or don’t use, understand user experience issues, etc." statistics_cookies_analytics_desc_html: "To collect and analyse platform usage data, we use Google Analytics." statistics_cookies_matomo_desc_html: "To collect and analyse platform usage data, we use Matomo (ex Piwik), an open source analytics tool that is GDPR compliant and protects your privacy." + statistics_cookies_matomo_optout: "Would you like to opt-out of Matomo analytics? We use Matomo to help us improve our service, but we don't collect any personal data." cookie_analytics_utma_desc: "Used to distinguish users and sessions. The cookie is created when the javascript library executes and no existing __utma cookies exists. The cookie is updated every time data is sent to Google Analytics." cookie_analytics_utmt_desc: "Used to throttle request rate." cookie_analytics_utmb_desc: "Used to determine new sessions/visits. The cookie is created when the javascript library executes and no existing __utmb cookies exists. The cookie is updated every time data is sent to Google Analytics." @@ -2285,13 +2329,13 @@ en_GB: saving: SAVING enterprise_package: hub_profile: Hub Profile - hub_profile_cost: "COST: Pay What You Can" + hub_profile_cost: "COST: Plans starting from £1/month" hub_profile_text1: > People can find and contact you on the Open Food Network. Your enterprise will be visible on the map, and will be searchable in listings. hub_profile_text2: > - Having a profile, and making connections within your local food system - through the Open Food Network will always be free. + As a producer, making connections within your local food system through + the Open Food Network will always be free. hub_shop: Hub Shop hub_shop_text1: > Your enterprise is the backbone of your local food system. You aggregate @@ -2311,7 +2355,7 @@ en_GB: Click on an option to see more detailed information about each package, and hit the red SAVE button when you are done! profile_only: Profile Only - profile_only_cost: "COST: Pay What You Can" + profile_only_cost: "COST: Plans starting from £1/month" profile_only_text1: > A profile makes you visible and contactable to others and is a way to share your story. @@ -2342,7 +2386,7 @@ en_GB: so no matter your situation, we want to provide the tools you need to run your organisation or local food business. get_listing: Get a listing - always_free: Pay What You Can + always_free: Plans starting from £1/month sell_produce_others: Sell produce from others sell_own_produce: Sell your own produce sell_both: Sell produce from self and others @@ -2374,6 +2418,9 @@ en_GB: resolve: Resolve new_tag_rule_dialog: select_rule_type: "Select a rule type:" + orders: + index: + per_page: "%{results} per page" resend_user_email_confirmation: resend: "Resend" sending: "Resend..." @@ -2422,7 +2469,9 @@ en_GB: This will set stock level to zero on all products for this enterprise that are not present in the uploaded file. order_cycles: + create_failure: "Failed to create order cycle" update_success: 'Your order cycle has been updated.' + update_failure: "Failed to update order cycle" no_distributors: There are no distributors in this order cycle. This order cycle will not be visible to customers until you add one. Would you like to continue saving this order cycle?' enterprises: producer: "Producer" @@ -2443,8 +2492,22 @@ en_GB: my_account: "My account" date: "Date" time: "Time" + layouts: + admin: + header: + store: Store admin: + product_properties: + index: + inherits_properties_checkbox_hint: "Inherit properties from %{supplier}? (unless overridden above)" orders: + index: + listing_orders: "Listing Orders" + capture: "Capture" + ship: "Ship" + edit: "Edit" + next: "Next" + no_orders_found: "No Orders Found" invoice: issued_on: Issued on tax_invoice: TAX INVOICE diff --git a/config/locales/en_US.yml b/config/locales/en_US.yml index d1f41a8849..c6573470f5 100644 --- a/config/locales/en_US.yml +++ b/config/locales/en_US.yml @@ -55,6 +55,7 @@ en_US: user_registrations: spree_user: signed_up_but_unconfirmed: "A message with a confirmation link has been sent to your email address. Please open the link to activate your account." + unknown_error: "Oops! Something went wrong while creating your account. Please check your email address and try again." failure: invalid: | Invalid email or password. @@ -147,7 +148,7 @@ en_US: cancel_order: "Cancel Order" confirm_send_invoice: "An invoice for this order will be sent to the customer. Are you sure you want to continue?" confirm_resend_order_confirmation: "Are you sure you want to resend the order confirmation email?" - must_have_valid_business_number: " %{enterprise_name}must have a company registration # before invoices can be sent." + must_have_valid_business_number: " %{enterprise_name}must have a Tax ID or W9 before invoices can be sent." invoice: "Invoice" percentage_of_sales: "%{percentage} of sales" capped_at_cap: "capped at %{cap}" @@ -458,11 +459,12 @@ en_US: conditional_blank: can't be blank if unit_type is blank no_product: did not match any products in the database not_found: not found in database + not_updatable: cannot be updated on existing products via product import blank: can't be blank products_no_permission: you do not have permission to manage products for this enterprise inventory_no_permission: you do not have permission to create inventory for this producer none_saved: did not save any products successfully - line: Line + line_number: "Line %{number}:" index: select_file: Select a spreadsheet to upload spreadsheet: Spreadsheet @@ -498,6 +500,7 @@ en_US: no_name: No name blank_supplier: some products have blank supplier name reset_absent?: Reset absent products + reset_absent_tip: Set stock to zero for all existing products not present in the file overwrite_all: Overwrite all overwrite_empty: Overwrite if empty default_stock: Set stock level @@ -505,6 +508,7 @@ en_US: default_shipping_cat: Set shipping category default_available_date: Set available date validation_overview: Import validation overview + entries_found: Entries found in imported file entries_with_errors: Items contain errors and will not be imported products_to_create: Products will be created products_to_update: Products will be updated @@ -514,6 +518,9 @@ en_US: inventory_to_reset: Existing inventory items will have their stock reset to zero line: Line item_line: Item line + import_review: + not_updatable_tip: "The following fields cannot be updated via bulk import for existing products:" + fields_ignored: These fields will be ignored when the imported products are saved. save_results: final_results: Import final results products_created: Products created @@ -554,9 +561,6 @@ en_US: controls: back_to_my_inventory: Back to my inventory orders: - index: - capture: "Capture" - ship: "Ship" invoice_email_sent: 'Invoice email has been sent' order_email_resent: 'Order email has been resent' bulk_management: @@ -597,7 +601,7 @@ en_US: desc_long: About Us desc_long_placeholder: Tell customers about yourself. This information appears on your public profile. business_details: - abn: Tax ID Number + abn: Tax ID Number or EIN (optional) abn_placeholder: eg. 123456789 acn: Legal Business Name acn_placeholder: eg. Martin's Produce LLC @@ -1124,7 +1128,7 @@ en_US: tax_total: "Total tax (%{rate}):" total_excl_tax: "Total (Excl. tax):" total_incl_tax: "Total (Incl. tax):" - abn: "Tax ID No." + abn: "Tax ID Number or EIN (optional)" acn: "Legal Business Name" invoice_issued_on: "Invoice issued on:" order_number: "Invoice number:" @@ -1786,7 +1790,7 @@ en_US: enterprise_long_desc_placeholder: "This is your opportunity to tell the story of your enterprise - what makes you different and wonderful? We'd suggest keeping your description to under 600 characters or 150 words." enterprise_long_desc_length: "%{num} characters / up to 600 recommended" enterprise_limit: Enterprise Limit - enterprise_abn: "Tax ID No." + enterprise_abn: "Tax ID Number or EIN (optional)" enterprise_abn_placeholder: "eg. 123456789" enterprise_acn: "Legal Business Name" enterprise_acn_placeholder: "eg. Justins Produce LLC" @@ -2283,7 +2287,7 @@ en_US: unsaved_changes: You have unsaved changes all_changes_saved_successfully: All changes saved successfully oh_no: "Oh no! I was unable to save your changes." - unauthorized: "You are unauthorised to access this page." + unauthorized: "You are unauthorized to access this page." error: Error unavailable: Unavailable profile: Profile @@ -2492,6 +2496,12 @@ en_US: index: inherits_properties_checkbox_hint: "Inherit properties from %{supplier}? (unless overridden above)" orders: + index: + capture: "Capture" + ship: "Ship" + edit: "Edit" + next: "Next" + no_orders_found: "No Orders Found" invoice: issued_on: Issued on tax_invoice: TAX INVOICE @@ -2551,6 +2561,7 @@ en_US: inherits_properties?: Inherits Properties? available_on: Available On av_on: "Av. On" + import_date: "Import Date" products_variant: variant_has_n_overrides: "This variant has %{n} override(s)" new_variant: "New variant" @@ -2598,6 +2609,8 @@ en_US: js_format: 'yy-mm-dd' inventory: Inventory orders: + edit: + login_to_view_order: "Please log in to view your order." bought: item: "Already ordered in this cycle" order_mailer: @@ -2689,5 +2702,15 @@ en_US: total: Total paid?: Paid? view: View + saved_cards: + default?: Default? + delete?: Delete? + cards: + authorised_shops: Authorized Shops + authorised_shops_popover: This is the list of shops which are permitted to charge your default credit card for any subscriptions (ie. repeating orders) you may have. Your card details will be kept secure and will not be shared with shop owners. You will always be notified when you are charged. + saved_cards_popover: This is the list of cards you have opted to save for later use. Your 'default' will be selected automatically when you checkout an order, and can be charged by any shops you have allowed to do so (see right). + authorised_shops: + shop_name: "Shop Name" + allow_charges?: "Allow Charges?" localized_number: invalid_format: has an invalid format. Please enter a number. diff --git a/spec/features/consumer/account/settings_spec.rb b/spec/features/consumer/account/settings_spec.rb index 64cdff0f05..aaea521671 100644 --- a/spec/features/consumer/account/settings_spec.rb +++ b/spec/features/consumer/account/settings_spec.rb @@ -4,18 +4,22 @@ feature "Account Settings", js: true do include AuthenticationWorkflow describe "as a logged in user" do - let(:user) { create(:user, email: 'old@email.com') } + let(:user) do + create(:user, + email: 'old@email.com', + password: 'OriginalPassword', + password_confirmation: 'OriginalPassword') + end before do create(:mail_method) quick_login_as user - end - - it "allows me to update my account details" do visit "/account" - click_link I18n.t('spree.users.show.tabs.settings') expect(page).to have_content I18n.t('spree.users.form.account_settings') + end + + it "allows the user to update their email address" do fill_in 'user_email', with: 'new@email.com' expect do @@ -32,5 +36,17 @@ feature "Account Settings", js: true do click_link I18n.t('spree.users.show.tabs.settings') expect(page).to have_content I18n.t('spree.users.show.unconfirmed_email', unconfirmed_email: 'new@email.com') end + + it "allows the user to change their password" do + initial_password = user.encrypted_password + + fill_in 'user_password', with: 'NewPassword' + fill_in 'user_password_confirmation', with: 'NewPassword' + + click_button I18n.t(:update) + expect(find(".alert-box.success").text.strip).to eq "#{I18n.t(:account_updated)} ×" + + expect(user.reload.encrypted_password).to_not eq initial_password + end end end diff --git a/spec/models/spree/addresses_spec.rb b/spec/models/spree/addresses_spec.rb index f453218610..5d78cadcf2 100644 --- a/spec/models/spree/addresses_spec.rb +++ b/spec/models/spree/addresses_spec.rb @@ -1,31 +1,44 @@ require 'spec_helper' describe Spree::Address do + let(:address) { build(:address) } + let(:enterprise_address) { build(:address, enterprise: build(:enterprise)) } + describe "associations" do - it { should have_one(:enterprise) } + it { is_expected.to have_one(:enterprise) } end describe "delegation" do - it { should delegate(:name).to(:state).with_prefix } + it { is_expected.to delegate(:name).to(:state).with_prefix } + end + + describe "destroy" do + it "can be deleted" do + expect { address.destroy }.to_not raise_error + end + + it "cannot be deleted with associated enterprise" do + expect do + enterprise_address.destroy + end.to raise_error ActiveRecord::DeleteRestrictionError + end end describe "geocode address" do - let(:address) { FactoryBot.build(:address) } - it "should include address1, address2, zipcode, city, state and country" do - address.geocode_address.should include(address.address1) - address.geocode_address.should include(address.address2) - address.geocode_address.should include(address.zipcode) - address.geocode_address.should include(address.city) - address.geocode_address.should include(address.state.name) - address.geocode_address.should include(address.country.name) + expect(address.geocode_address).to include(address.address1) + expect(address.geocode_address).to include(address.address2) + expect(address.geocode_address).to include(address.zipcode) + expect(address.geocode_address).to include(address.city) + expect(address.geocode_address).to include(address.state.name) + expect(address.geocode_address).to include(address.country.name) end it "should not include empty fields" do address.address2 = nil address.city = "" - address.geocode_address.split(',').length.should eql(4) + expect(address.geocode_address.split(',').length).to eql(4) end end @@ -33,40 +46,27 @@ describe Spree::Address do let(:address) { FactoryBot.build(:address) } it "should include address1, address2, zipcode, city and state" do - address.full_address.should include(address.address1) - address.full_address.should include(address.address2) - address.full_address.should include(address.zipcode) - address.full_address.should include(address.city) - address.full_address.should include(address.state.name) - address.full_address.should_not include(address.country.name) + expect(address.full_address).to include(address.address1) + expect(address.full_address).to include(address.address2) + expect(address.full_address).to include(address.zipcode) + expect(address.full_address).to include(address.city) + expect(address.full_address).to include(address.state.name) + expect(address.full_address).not_to include(address.country.name) end it "should not include empty fields" do address.address2 = nil address.city = "" - address.full_address.split(',').length.should eql(3) + expect(address.full_address.split(',').length).to eql(3) end end describe "setters" do it "lets us set a country" do - expect { Spree::Address.new.country = "A country" }.to raise_error ActiveRecord::AssociationTypeMismatch - end - end - - describe "notifying bugsnag when saved with missing data" do - it "notifies on create" do - Bugsnag.should_receive(:notify) - a = Spree::Address.new zipcode: nil - a.save validate: false - end - - it "notifies on update" do - Bugsnag.should_receive(:notify) - a = create(:address) - a.zipcode = nil - a.save validate: false + expect do + Spree::Address.new.country = "A country" + end.to raise_error ActiveRecord::AssociationTypeMismatch end end end diff --git a/spec/models/variant_override_spec.rb b/spec/models/variant_override_spec.rb index 0a07fdd1af..bb799f8603 100644 --- a/spec/models/variant_override_spec.rb +++ b/spec/models/variant_override_spec.rb @@ -7,10 +7,9 @@ describe VariantOverride do describe "scopes" do let(:hub1) { create(:distributor_enterprise) } let(:hub2) { create(:distributor_enterprise) } - let(:v) { create(:variant) } - let!(:vo1) { create(:variant_override, hub: hub1, variant: v) } - let!(:vo2) { create(:variant_override, hub: hub2, variant: v) } - let!(:vo3) { create(:variant_override, hub: hub1, variant: v, permission_revoked_at: Time.now) } + let!(:vo1) { create(:variant_override, hub: hub1, variant: variant, import_date: Time.zone.now.yesterday) } + let!(:vo2) { create(:variant_override, hub: hub2, variant: variant, import_date: Time.zone.now) } + let!(:vo3) { create(:variant_override, hub: hub1, variant: variant, permission_revoked_at: Time.now) } it "ignores variant_overrides with revoked_permissions by default" do expect(VariantOverride.all).to_not include vo3 @@ -21,10 +20,17 @@ describe VariantOverride do VariantOverride.for_hubs([hub1, hub2]).should match_array [vo1, vo2] end + it "fetches import dates for hubs in descending order" do + import_dates = VariantOverride.distinct_import_dates.pluck :import_date + + expect(import_dates[0].to_i).to eq(vo2.import_date.to_i) + expect(import_dates[1].to_i).to eq(vo1.import_date.to_i) + end + describe "fetching variant overrides indexed by variant" do it "gets indexed variant overrides for one hub" do - VariantOverride.indexed(hub1).should == {v => vo1} - VariantOverride.indexed(hub2).should == {v => vo2} + VariantOverride.indexed(hub1).should == {variant => vo1} + VariantOverride.indexed(hub2).should == {variant => vo2} end end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 0a60d4f807..a4765ec963 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -119,6 +119,7 @@ RSpec.configure do |config| spree_config.auto_capture = true end + Spree::Auth::Config[:signout_after_password_change] = false Spree::Api::Config[:requires_authentication] = true end