From 138f00876bd424a4885f0b17eb43628f3cad5f89 Mon Sep 17 00:00:00 2001 From: Matt-Yorkley <9029026+Matt-Yorkley@users.noreply.github.com> Date: Thu, 4 Mar 2021 13:15:44 +0000 Subject: [PATCH 01/31] Update Rails to 5.2 --- Gemfile | 2 +- Gemfile.lock | 98 ++++++++++++++++++++++++++++------------------------ 2 files changed, 54 insertions(+), 46 deletions(-) diff --git a/Gemfile b/Gemfile index a4a9aa0de4..91cd7d17d1 100644 --- a/Gemfile +++ b/Gemfile @@ -4,7 +4,7 @@ source 'https://rubygems.org' ruby "2.5.8" git_source(:github) { |repo_name| "https://github.com/#{repo_name}.git" } -gem 'rails', '~> 5.0.0' +gem 'rails', '~> 5.2' gem 'activemerchant', '>= 1.78.0' gem 'angular-rails-templates', '>= 0.3.0' diff --git a/Gemfile.lock b/Gemfile.lock index c297ebae04..8eb0e08023 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -47,47 +47,47 @@ PATH GEM remote: https://rubygems.org/ specs: - actioncable (5.0.7.2) - actionpack (= 5.0.7.2) - nio4r (>= 1.2, < 3.0) - websocket-driver (~> 0.6.1) - actionmailer (5.0.7.2) - actionpack (= 5.0.7.2) - actionview (= 5.0.7.2) - activejob (= 5.0.7.2) + actioncable (5.2.4.5) + actionpack (= 5.2.4.5) + nio4r (~> 2.0) + websocket-driver (>= 0.6.1) + actionmailer (5.2.4.5) + actionpack (= 5.2.4.5) + actionview (= 5.2.4.5) + activejob (= 5.2.4.5) mail (~> 2.5, >= 2.5.4) rails-dom-testing (~> 2.0) - actionpack (5.0.7.2) - actionview (= 5.0.7.2) - activesupport (= 5.0.7.2) - rack (~> 2.0) - rack-test (~> 0.6.3) + actionpack (5.2.4.5) + actionview (= 5.2.4.5) + activesupport (= 5.2.4.5) + rack (~> 2.0, >= 2.0.8) + rack-test (>= 0.6.3) rails-dom-testing (~> 2.0) rails-html-sanitizer (~> 1.0, >= 1.0.2) actionpack-action_caching (1.2.1) actionpack (>= 4.0.0) - actionview (5.0.7.2) - activesupport (= 5.0.7.2) + actionview (5.2.4.5) + activesupport (= 5.2.4.5) builder (~> 3.1) - erubis (~> 2.7.0) + erubi (~> 1.4) rails-dom-testing (~> 2.0) rails-html-sanitizer (~> 1.0, >= 1.0.3) active_model_serializers (0.8.4) activemodel (>= 3.0) - activejob (5.0.7.2) - activesupport (= 5.0.7.2) + activejob (5.2.4.5) + activesupport (= 5.2.4.5) globalid (>= 0.3.6) activemerchant (1.119.0) activesupport (>= 4.2) builder (>= 2.1.2, < 4.0.0) i18n (>= 0.6.9) nokogiri (~> 1.4) - activemodel (5.0.7.2) - activesupport (= 5.0.7.2) - activerecord (5.0.7.2) - activemodel (= 5.0.7.2) - activesupport (= 5.0.7.2) - arel (~> 7.0) + activemodel (5.2.4.5) + activesupport (= 5.2.4.5) + activerecord (5.2.4.5) + activemodel (= 5.2.4.5) + activesupport (= 5.2.4.5) + arel (>= 9.0) activerecord-import (1.0.8) activerecord (>= 3.2) activerecord-postgresql-adapter (0.0.1) @@ -98,7 +98,11 @@ GEM multi_json (~> 1.11, >= 1.11.2) rack (>= 1.5.2, < 3) railties (>= 4.0) - activesupport (5.0.7.2) + activestorage (5.2.4.5) + actionpack (= 5.2.4.5) + activerecord (= 5.2.4.5) + marcel (~> 0.3.1) + activesupport (5.2.4.5) concurrent-ruby (~> 1.0, >= 1.0.2) i18n (>= 0.7, < 2) minitest (~> 5.1) @@ -118,7 +122,7 @@ GEM railties (>= 3, < 7) angularjs-file-upload-rails (2.4.1) angularjs-rails (1.5.5) - arel (7.1.4) + arel (9.0.0) ast (2.4.2) atomic (1.1.101) awesome_nested_set (3.4.0) @@ -328,10 +332,13 @@ GEM nokogiri (>= 1.5.9) mail (2.7.1) mini_mime (>= 0.1.1) + marcel (0.3.3) + mimemagic (~> 0.3.2) method_source (1.0.0) mime-types (3.3.1) mime-types-data (~> 3.2015) mime-types-data (3.2020.1104) + mimemagic (0.3.5) mini_mime (1.0.3) mini_portile2 (2.5.1) mini_racer (0.4.0) @@ -347,7 +354,7 @@ GEM multipart-post (2.1.1) mustermann (1.1.1) ruby2_keywords (~> 0.0.1) - nio4r (2.5.2) + nio4r (2.5.7) nokogiri (1.11.3) mini_portile2 (~> 2.5.0) racc (~> 1.4) @@ -397,19 +404,20 @@ GEM rack-rewrite (1.5.1) rack-ssl (1.4.1) rack - rack-test (0.6.3) - rack (>= 1.0) - rails (5.0.7.2) - actioncable (= 5.0.7.2) - actionmailer (= 5.0.7.2) - actionpack (= 5.0.7.2) - actionview (= 5.0.7.2) - activejob (= 5.0.7.2) - activemodel (= 5.0.7.2) - activerecord (= 5.0.7.2) - activesupport (= 5.0.7.2) + rack-test (1.1.0) + rack (>= 1.0, < 3) + rails (5.2.4.5) + actioncable (= 5.2.4.5) + actionmailer (= 5.2.4.5) + actionpack (= 5.2.4.5) + actionview (= 5.2.4.5) + activejob (= 5.2.4.5) + activemodel (= 5.2.4.5) + activerecord (= 5.2.4.5) + activestorage (= 5.2.4.5) + activesupport (= 5.2.4.5) bundler (>= 1.3.0) - railties (= 5.0.7.2) + railties (= 5.2.4.5) sprockets-rails (>= 2.0.0) rails-controller-testing (1.0.5) actionpack (>= 5.0.1.rc1) @@ -424,12 +432,12 @@ GEM i18n (>= 0.7, < 2) railties (>= 5.0, < 6) rails_safe_tasks (1.0.0) - railties (5.0.7.2) - actionpack (= 5.0.7.2) - activesupport (= 5.0.7.2) + railties (5.2.4.5) + actionpack (= 5.2.4.5) + activesupport (= 5.2.4.5) method_source rake (>= 0.8.7) - thor (>= 0.18.1, < 2.0) + thor (>= 0.19.0, < 2.0) rainbow (3.0.0) raindrops (0.19.1) rake (13.0.3) @@ -596,7 +604,7 @@ GEM addressable (>= 2.3.6) crack (>= 0.3.2) hashdiff (>= 0.4.0, < 2.0.0) - websocket-driver (0.6.5) + websocket-driver (0.7.3) websocket-extensions (>= 0.1.0) websocket-extensions (0.1.5) whenever (1.0.0) @@ -695,7 +703,7 @@ DEPENDENCIES rack-mini-profiler (< 3.0.0) rack-rewrite rack-ssl - rails (~> 5.0.0) + rails (~> 5.2) rails-controller-testing rails-i18n rails_safe_tasks (~> 1.0) From 943c00c924eb35430741ca922f6bfb79b10266ab Mon Sep 17 00:00:00 2001 From: Matt-Yorkley <9029026+Matt-Yorkley@users.noreply.github.com> Date: Thu, 4 Mar 2021 13:22:27 +0000 Subject: [PATCH 02/31] WIP - Update loading of helpers in controllers Rails has changed the way helpers are loaded. It's a bit weird. It was throwing lots of errors, and recommended using this setting, but now requires that all helpers are loaded explicitly. I'm not sure about this. --- app/controllers/application_controller.rb | 12 ++++++++++++ app/controllers/base_controller.rb | 2 -- app/controllers/spree/admin/base_controller.rb | 5 +++++ config/application.rb | 2 ++ .../admin/shared/_order_links.html.haml_spec.rb | 1 + 5 files changed, 20 insertions(+), 2 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 399d1ae9e1..dfa0ea9a65 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -13,6 +13,18 @@ class ApplicationController < ActionController::Base self.responder = ApplicationResponder respond_to :html + helper 'spree/base' + helper 'spree/orders' + helper 'shared' + helper 'enterprises' + helper 'order_cycles' + helper 'order' + helper 'shop' + helper 'injection' + helper 'markdown' + helper 'footer_links' + helper 'discourse' + protect_from_forgery include Spree::Core::ControllerHelpers::Auth diff --git a/app/controllers/base_controller.rb b/app/controllers/base_controller.rb index 8ea4718cb5..312dee2063 100644 --- a/app/controllers/base_controller.rb +++ b/app/controllers/base_controller.rb @@ -13,8 +13,6 @@ class BaseController < ApplicationController include I18nHelper include OrderCyclesHelper - helper 'spree/base' - before_action :set_locale before_action :check_order_cycle_expiry diff --git a/app/controllers/spree/admin/base_controller.rb b/app/controllers/spree/admin/base_controller.rb index 395baa538e..6a53ad204a 100644 --- a/app/controllers/spree/admin/base_controller.rb +++ b/app/controllers/spree/admin/base_controller.rb @@ -3,7 +3,12 @@ module Spree class BaseController < ApplicationController ssl_required + helper 'shared' helper 'spree/admin/navigation' + helper 'spree/admin/orders' + helper 'admin/injection' + helper 'admin/orders' + layout '/spree/layouts/admin' include I18nHelper diff --git a/config/application.rb b/config/application.rb index 20fe4aa4b8..45c68a66b3 100644 --- a/config/application.rb +++ b/config/application.rb @@ -198,6 +198,8 @@ module Openfoodnetwork config.active_job.queue_adapter = :delayed_job + config.action_controller.include_all_helpers = false + config.generators.template_engine = :haml end end diff --git a/spec/views/spree/admin/shared/_order_links.html.haml_spec.rb b/spec/views/spree/admin/shared/_order_links.html.haml_spec.rb index 264a81976b..b15eb93f02 100644 --- a/spec/views/spree/admin/shared/_order_links.html.haml_spec.rb +++ b/spec/views/spree/admin/shared/_order_links.html.haml_spec.rb @@ -4,6 +4,7 @@ require "spec_helper" describe "spree/admin/shared/_order_links.html.haml" do helper Spree::BaseHelper # required to make pretty_time work + helper Spree::Admin::OrdersHelper before do order = create(:order) From 5fc60f53ba7e49bb2ce8febb1167d9ccd9007e29 Mon Sep 17 00:00:00 2001 From: Matt-Yorkley <9029026+Matt-Yorkley@users.noreply.github.com> Date: Wed, 24 Mar 2021 16:34:35 +0000 Subject: [PATCH 03/31] Update mimemagic gem! The package maintainer nuked this gem last night as part of a major licence change for the repo, and chaos ensued. It's a dependency for ActiveStorage which is now part of Rails. Versions *above* 0.3.5 are now available, and work. All versions below 0.3.6 have been removed without warning (currently used by ~576,971 repos on Github!) D: --- Gemfile | 1 + Gemfile.lock | 1 + 2 files changed, 2 insertions(+) diff --git a/Gemfile b/Gemfile index 91cd7d17d1..4ac3cfdd4a 100644 --- a/Gemfile +++ b/Gemfile @@ -75,6 +75,7 @@ gem 'dalli' gem 'figaro' gem 'geocoder' gem 'gmaps4rails' +gem 'mimemagic', '> 0.3.5' gem 'paper_trail', '~> 10.3.1' gem 'paperclip', '~> 3.4.1' gem 'rack-rewrite' diff --git a/Gemfile.lock b/Gemfile.lock index 8eb0e08023..cb61287d8f 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -688,6 +688,7 @@ DEPENDENCIES kaminari (~> 1.2.1) knapsack letter_opener (>= 1.4.1) + mimemagic (> 0.3.5) mini_racer (= 0.4.0) monetize (~> 1.11) oauth2 (~> 1.4.7) From f8743971151f3be0a9d69df3f267d41da5b68f11 Mon Sep 17 00:00:00 2001 From: Matt-Yorkley <9029026+Matt-Yorkley@users.noreply.github.com> Date: Wed, 24 Mar 2021 18:22:56 +0000 Subject: [PATCH 04/31] Fix errors in PermittedAttributes::OrderCycle --- .../permitted_attributes/order_cycle.rb | 17 +---------------- 1 file changed, 1 insertion(+), 16 deletions(-) diff --git a/app/services/permitted_attributes/order_cycle.rb b/app/services/permitted_attributes/order_cycle.rb index f46a4c63d2..987bd3adf2 100644 --- a/app/services/permitted_attributes/order_cycle.rb +++ b/app/services/permitted_attributes/order_cycle.rb @@ -35,23 +35,8 @@ module PermittedAttributes :tag_list, tags: [:text], enterprise_fee_ids: [], - variants: permitted_variant_ids + variants: {} ] end - - # In rails 5 we will be able to permit random hash keys simply with :variants => {} - # See https://github.com/rails/rails/commit/e86524c0c5a26ceec92895c830d1355ae47a7034 - # - # Until then, we need to create an array of variant IDs in order to permit them - def permitted_variant_ids - variant_ids(@params[:order_cycle][:incoming_exchanges]) + - variant_ids(@params[:order_cycle][:outgoing_exchanges]) - end - - def variant_ids(exchange_params) - return [] unless exchange_params - - exchange_params.map { |exchange| exchange[:variants].map { |key, _value| key } }.flatten - end end end From 1b4930de8f0c3a1785c3b37b92ba99e6321715d8 Mon Sep 17 00:00:00 2001 From: Luis Ramos Date: Fri, 26 Mar 2021 22:12:21 +0000 Subject: [PATCH 05/31] Fix mimemagic 036 yank issue --- Gemfile.lock | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index cb61287d8f..01bfd3586a 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -220,7 +220,6 @@ GEM diff-lcs (1.4.4) docile (1.3.5) erubi (1.10.0) - erubis (2.7.0) eventmachine (1.2.7) excon (0.79.0) execjs (2.7.0) @@ -338,7 +337,9 @@ GEM mime-types (3.3.1) mime-types-data (~> 3.2015) mime-types-data (3.2020.1104) - mimemagic (0.3.5) + mimemagic (0.3.10) + nokogiri (~> 1) + rake mini_mime (1.0.3) mini_portile2 (2.5.1) mini_racer (0.4.0) From b0787e83b29827dab8f1b4f67bc0a5dfa5bfa71e Mon Sep 17 00:00:00 2001 From: Matt-Yorkley <9029026+Matt-Yorkley@users.noreply.github.com> Date: Sat, 27 Mar 2021 13:06:27 +0000 Subject: [PATCH 06/31] Add checkout helper Fixes: Failure/Error: super ActionView::Template::Error: undefined method `checkout_adjustments_for' for #<#:0x000055f4bd845c30> # ./app/helpers/application_helper.rb:20:in `method_missing' # ./app/views/spree/admin/orders/_invoice_table.html.haml:26:in `_app_views_spree_admin_orders__invoice_table_html_haml___3617932924646213210_47254819384740' # ./app/views/spree/admin/orders/invoice.html.haml:67:in `_app_views_spree_admin_orders_invoice_html_haml__1476001169744481148_47254819971700' # ./app/services/invoice_renderer.rb:8:in `render_to_string' # ./app/controllers/spree/admin/orders_controller.rb:81:in `invoice' # ./spec/support/controller_requests_helper.rb:49:in `process_action_with_route' # ./spec/support/controller_requests_helper.rb:23:in `spree_get' # ./spec/controllers/spree/admin/orders/invoices_spec.rb:58:in `block (6 levels) in ' # ------------------ # --- Caused by: --- # NoMethodError: # undefined method `checkout_adjustments_for' for #<#:0x000055f4bd845c30> # ./app/helpers/application_helper.rb:20:in `method_missing' --- app/controllers/application_controller.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index dfa0ea9a65..2055c0df16 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -24,6 +24,7 @@ class ApplicationController < ActionController::Base helper 'markdown' helper 'footer_links' helper 'discourse' + helper 'checkout' protect_from_forgery From e6a3041f457580ea0aa62ffdf7cd68a7c8e79318 Mon Sep 17 00:00:00 2001 From: Matt-Yorkley <9029026+Matt-Yorkley@users.noreply.github.com> Date: Sat, 27 Mar 2021 13:10:25 +0000 Subject: [PATCH 07/31] Add admin/enterprises helper Fixes: Failure/Error: super ActionView::Template::Error: undefined method `add_check_if_single' for #<#:0x00007f446cdd68e8> # ./app/helpers/application_helper.rb:20:in `method_missing' # ./app/views/spree/admin/shared/_hubs_sidebar.html.haml:16:in `block in _app_views_spree_admin_shared__hubs_sidebar_html_haml___1973426344114200431_69965928779540' # ./app/views/spree/admin/shared/_hubs_sidebar.html.haml:11:in `each' # ./app/views/spree/admin/shared/_hubs_sidebar.html.haml:11:in `_app_views_spree_admin_shared__hubs_sidebar_html_haml___1973426344114200431_69965928779540' # ./app/views/spree/admin/payment_methods/edit.html.haml:15:in `block in _app_views_spree_admin_payment_methods_edit_html_haml__571217921761730685_69965930474120' # ./app/views/spree/admin/payment_methods/edit.html.haml:11:in `_app_views_spree_admin_payment_methods_edit_html_haml__571217921761730685_69965930474120' # ./app/controllers/admin/resource_controller.rb:23:in `block (2 levels) in edit' # ./lib/spree/core/controller_helpers/respond_with.rb:24:in `respond_with' # ./app/controllers/admin/resource_controller.rb:22:in `edit' # ./lib/open_food_network/rack_request_blocker.rb:36:in `call' # ------------------ # --- Caused by: --- # NoMethodError: # undefined method `add_check_if_single' for #<#:0x00007f446cdd68e8> # ./app/helpers/application_helper.rb:20:in `method_missing' --- app/controllers/spree/admin/base_controller.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/controllers/spree/admin/base_controller.rb b/app/controllers/spree/admin/base_controller.rb index 6a53ad204a..1eeabc6225 100644 --- a/app/controllers/spree/admin/base_controller.rb +++ b/app/controllers/spree/admin/base_controller.rb @@ -8,6 +8,7 @@ module Spree helper 'spree/admin/orders' helper 'admin/injection' helper 'admin/orders' + helper 'admin/enterprises' layout '/spree/layouts/admin' From b7aeceaf67e36efefbec6fbfc2b83503673b9490 Mon Sep 17 00:00:00 2001 From: Matt-Yorkley <9029026+Matt-Yorkley@users.noreply.github.com> Date: Sat, 27 Mar 2021 13:14:14 +0000 Subject: [PATCH 08/31] Add enterprise_fees helper Fixes: Failure/Error: super ActionView::Template::Error: undefined method `angular_id' for #<#:0x00007f57c55754f8> # ./app/helpers/application_helper.rb:20:in `method_missing' # ./app/views/admin/enterprise_fees/index.html.haml:32:in `block (2 levels) in _app_views_admin_enterprise_fees_index_html_haml__3854507252304647884_70007474860840' # ./app/helpers/angular_form_builder.rb:6:in `ng_fields_for' # ./app/views/admin/enterprise_fees/index.html.haml:28:in `block in _app_views_admin_enterprise_fees_index_html_haml__3854507252304647884_70007474860840' # ./app/helpers/application_helper.rb:11:in `ng_form_for' # ./app/views/admin/enterprise_fees/index.html.haml:4:in `_app_views_admin_enterprise_fees_index_html_haml__3854507252304647884_70007474860840' # ./lib/open_food_network/rack_request_blocker.rb:36:in `call' # ------------------ # --- Caused by: --- # NoMethodError: # undefined method `angular_id' for #<#:0x00007f57c55754f8> # ./app/helpers/application_helper.rb:20:in `method_missing' --- app/controllers/spree/admin/base_controller.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/controllers/spree/admin/base_controller.rb b/app/controllers/spree/admin/base_controller.rb index 1eeabc6225..fb6d15083f 100644 --- a/app/controllers/spree/admin/base_controller.rb +++ b/app/controllers/spree/admin/base_controller.rb @@ -9,6 +9,7 @@ module Spree helper 'admin/injection' helper 'admin/orders' helper 'admin/enterprises' + helper 'enterprise_fees' layout '/spree/layouts/admin' From 26688dda36e314135d52f19db3608c5f31f09033 Mon Sep 17 00:00:00 2001 From: Matt-Yorkley <9029026+Matt-Yorkley@users.noreply.github.com> Date: Sat, 27 Mar 2021 13:15:20 +0000 Subject: [PATCH 09/31] Add angular_form helper Fixes: Failure/Error: super ActionView::Template::Error: undefined method `ng_options_for_select' for #<#:0x000055783fbebec0> Did you mean? options_for_select # ./app/helpers/application_helper.rb:20:in `method_missing' # ./app/helpers/angular_form_builder.rb:26:in `ng_select' # ./app/views/admin/enterprise_fees/index.html.haml:34:in `block (2 levels) in _app_views_admin_enterprise_fees_index_html_haml__800455454875182851_46987476952700' # ./app/helpers/angular_form_builder.rb:6:in `ng_fields_for' # ./app/views/admin/enterprise_fees/index.html.haml:28:in `block in _app_views_admin_enterprise_fees_index_html_haml__800455454875182851_46987476952700' # ./app/helpers/application_helper.rb:11:in `ng_form_for' # ./app/views/admin/enterprise_fees/index.html.haml:4:in `_app_views_admin_enterprise_fees_index_html_haml__800455454875182851_46987476952700' # ./lib/open_food_network/rack_request_blocker.rb:36:in `call' # ------------------ # --- Caused by: --- # NoMethodError: # undefined method `ng_options_for_select' for #<#:0x000055783fbebec0> # Did you mean? options_for_select # ./app/helpers/application_helper.rb:20:in `method_missing' --- app/controllers/spree/admin/base_controller.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/controllers/spree/admin/base_controller.rb b/app/controllers/spree/admin/base_controller.rb index fb6d15083f..f218fe9f96 100644 --- a/app/controllers/spree/admin/base_controller.rb +++ b/app/controllers/spree/admin/base_controller.rb @@ -10,6 +10,7 @@ module Spree helper 'admin/orders' helper 'admin/enterprises' helper 'enterprise_fees' + helper 'angular_form' layout '/spree/layouts/admin' From e9b6f89ae0f95178b9aa4e187fd2b55407aabb70 Mon Sep 17 00:00:00 2001 From: Matt-Yorkley <9029026+Matt-Yorkley@users.noreply.github.com> Date: Sat, 27 Mar 2021 13:24:39 +0000 Subject: [PATCH 10/31] Update params syntax in engine controller specs --- .../reports/bulk_coop_controller_spec.rb | 32 +++++++++++-------- ...nterprise_fee_summaries_controller_spec.rb | 14 +++++--- 2 files changed, 29 insertions(+), 17 deletions(-) diff --git a/engines/order_management/spec/controllers/order_management/reports/bulk_coop_controller_spec.rb b/engines/order_management/spec/controllers/order_management/reports/bulk_coop_controller_spec.rb index 4476edd9cf..cc8552dc46 100644 --- a/engines/order_management/spec/controllers/order_management/reports/bulk_coop_controller_spec.rb +++ b/engines/order_management/spec/controllers/order_management/reports/bulk_coop_controller_spec.rb @@ -25,10 +25,12 @@ describe OrderManagement::Reports::BulkCoopController, type: :controller do describe "#create" do context "when the parameters are valid" do it "sends the generated report in the correct format" do - post :create, report: { - start_at: "2018-10-09 07:30:00", - report_type: "bulk_coop_supplier_report" - }, report_format: "csv" + post :create, params: { + report: { + start_at: "2018-10-09 07:30:00", + report_type: "bulk_coop_supplier_report" + }, report_format: "csv" + } expect(response).to be_success expect(response.body).not_to be_blank @@ -38,10 +40,12 @@ describe OrderManagement::Reports::BulkCoopController, type: :controller do context "when the parameters are invalid" do it "renders the report form with an error" do - post :create, report: { - start_at: "invalid_date", - report_type: "bulk_coop_supplier_report" - }, report_format: "csv" + post :create, params: { + report: { + start_at: "invalid_date", + report_type: "bulk_coop_supplier_report" + }, report_format: "csv" + } expect(flash[:error]).to eq(I18n.t("invalid_filter_parameters", scope: i18n_scope)) expect(response).to render_template(new_template_path) @@ -55,10 +59,12 @@ describe OrderManagement::Reports::BulkCoopController, type: :controller do let(:current_user) { distributor.owner } it "renders the report form with an error" do - post :create, report: { - distributor_ids: [other_distributor.id], - report_type: "bulk_coop_supplier_report" - }, report_format: "csv" + post :create, params: { + report: { + distributor_ids: [other_distributor.id], + report_type: "bulk_coop_supplier_report" + }, report_format: "csv" + } expect(flash[:error]).to eq(report_klass::Authorizer.parameter_not_allowed_error_message) expect(response).to render_template(new_template_path) @@ -72,7 +78,7 @@ describe OrderManagement::Reports::BulkCoopController, type: :controller do let(:current_user) { distributor.owner } it "applies permissions to report" do - post :create, report: {}, report_format: "csv" + post :create, params: { report: {}, report_format: "csv" } expect(assigns(:permissions).allowed_distributors.to_a).to eq([distributor]) 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 da66c005f4..5008cd65d2 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 @@ -25,7 +25,9 @@ describe OrderManagement::Reports::EnterpriseFeeSummariesController, type: :cont describe "#create" do context "when the parameters are valid" do it "sends the generated report in the correct format" do - post :create, report: { start_at: "2018-10-09 07:30:00" }, report_format: "csv" + post :create, params: { + report: { start_at: "2018-10-09 07:30:00" }, report_format: "csv" + } expect(response).to be_success expect(response.body).not_to be_blank @@ -35,7 +37,9 @@ describe OrderManagement::Reports::EnterpriseFeeSummariesController, type: :cont context "when the parameters are invalid" do it "renders the report form with an error" do - post :create, report: { start_at: "invalid date" }, report_format: "csv" + post :create, params: { + report: { start_at: "invalid date" }, report_format: "csv" + } expect(flash[:error]).to eq(I18n.t("invalid_filter_parameters", scope: i18n_scope)) expect(response).to render_template(new_template_path) @@ -49,7 +53,9 @@ describe OrderManagement::Reports::EnterpriseFeeSummariesController, type: :cont let(:current_user) { distributor.owner } it "renders the report form with an error" do - post :create, report: { distributor_ids: [other_distributor.id] }, report_format: "csv" + post :create, params: { + report: { distributor_ids: [other_distributor.id] }, report_format: "csv" + } expect(flash[:error]).to eq(report_klass::Authorizer.parameter_not_allowed_error_message) expect(response).to render_template(new_template_path) @@ -66,7 +72,7 @@ describe OrderManagement::Reports::EnterpriseFeeSummariesController, type: :cont let(:current_user) { distributor.owner } it "applies permissions to report" do - post :create, report: {}, report_format: "csv" + post :create, params: { report: {}, report_format: "csv" } expect(assigns(:permissions).allowed_order_cycles.to_a).to eq([order_cycle]) end From c1402fe4f25df0de25a235199eb121e14f89c2a8 Mon Sep 17 00:00:00 2001 From: Luis Ramos Date: Mon, 29 Mar 2021 21:49:22 +0100 Subject: [PATCH 11/31] Upgrade state_machines --- Gemfile.lock | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 01bfd3586a..4057b1d797 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -560,12 +560,12 @@ GEM activesupport (>= 4.0) sprockets (>= 3.0.0) state_machines (0.5.0) - state_machines-activemodel (0.7.1) - activemodel (>= 4.1) + state_machines-activemodel (0.8.0) + activemodel (>= 5.1) state_machines (>= 0.5.0) - state_machines-activerecord (0.6.0) - activerecord (>= 4.1) - state_machines-activemodel (>= 0.5.0) + state_machines-activerecord (0.8.0) + activerecord (>= 5.1) + state_machines-activemodel (>= 0.8.0) stringex (2.8.5) stripe (5.30.0) temple (0.8.2) From c08bc743d35334644b4369b0dcab5fc0f25c8b55 Mon Sep 17 00:00:00 2001 From: Luis Ramos Date: Thu, 8 Apr 2021 00:34:06 +0100 Subject: [PATCH 12/31] Replace usage of changed? with saved_change_to_ --- app/models/spree/product.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/models/spree/product.rb b/app/models/spree/product.rb index 6bd6cbc3dd..267ed1693d 100755 --- a/app/models/spree/product.rb +++ b/app/models/spree/product.rb @@ -433,7 +433,7 @@ module Spree end def update_units - return unless variant_unit_changed? + return unless saved_change_to_variant_unit? option_types.delete self.class.all_variant_unit_option_types option_types << variant_unit_option_type if variant_unit.present? @@ -449,7 +449,7 @@ module Spree end def remove_previous_primary_taxon_from_taxons - return unless primary_taxon_id_changed? && primary_taxon_id_was + return unless saved_change_to_primary_taxon_id? && primary_taxon_id_was taxons.destroy(primary_taxon_id_was) end @@ -465,7 +465,7 @@ module Spree # Spree creates a permalink already but our implementation fixes an edge case. def sanitize_permalink - return unless permalink.blank? || permalink_changed? + return unless permalink.blank? || saved_change_to_permalink? requested = permalink.presence || permalink_was.presence || name.presence || 'product' self.permalink = create_unique_permalink(requested.parameterize) From d381b2a544d6307ea23e7a1d421ab3996f43095a Mon Sep 17 00:00:00 2001 From: Andy Brett Date: Thu, 8 Apr 2021 13:47:40 -0700 Subject: [PATCH 13/31] Use saved_change_to prefix to check for changes --- app/models/spree/credit_card.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/spree/credit_card.rb b/app/models/spree/credit_card.rb index ef51c4898b..afa2353d79 100644 --- a/app/models/spree/credit_card.rb +++ b/app/models/spree/credit_card.rb @@ -147,7 +147,7 @@ module Spree end def default_card_needs_updating? - is_default_changed? || gateway_customer_profile_id_changed? + saved_change_to_is_default? || gateway_customer_profile_id_changed? end def ensure_single_default_card From 52525dc437da0f50faf7375d54a2c1b04ce64155 Mon Sep 17 00:00:00 2001 From: Andy Brett Date: Thu, 8 Apr 2021 13:57:29 -0700 Subject: [PATCH 14/31] Fix /spec/models/spree/product_spec.rb:118 --- app/models/spree/product.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/spree/product.rb b/app/models/spree/product.rb index 267ed1693d..c1152e1462 100755 --- a/app/models/spree/product.rb +++ b/app/models/spree/product.rb @@ -465,7 +465,7 @@ module Spree # Spree creates a permalink already but our implementation fixes an edge case. def sanitize_permalink - return unless permalink.blank? || saved_change_to_permalink? + return unless permalink.blank? || saved_change_to_permalink? || permalink_changed? requested = permalink.presence || permalink_was.presence || name.presence || 'product' self.permalink = create_unique_permalink(requested.parameterize) From be0eb5f5f986bb4790d3d03a728a54ffbc49abb2 Mon Sep 17 00:00:00 2001 From: Andy Brett Date: Thu, 8 Apr 2021 14:39:30 -0700 Subject: [PATCH 15/31] ignore nil in payment report spec expectation --- spec/features/admin/reports/payments_report_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/features/admin/reports/payments_report_spec.rb b/spec/features/admin/reports/payments_report_spec.rb index 11c828593e..8ed50fcf70 100644 --- a/spec/features/admin/reports/payments_report_spec.rb +++ b/spec/features/admin/reports/payments_report_spec.rb @@ -56,7 +56,7 @@ describe "Payments Reports" do order.ship_total.to_f + other_order.ship_total.to_f, order.outstanding_balance.to_f + other_order.outstanding_balance.to_f, order.total.to_f + other_order.total.to_f - ].join(" ")) + ].compact.join(" ")) end end From d255ca22f53ff289123331b45e38fca8dfe6d253 Mon Sep 17 00:00:00 2001 From: Andy Brett Date: Thu, 8 Apr 2021 19:42:05 -0700 Subject: [PATCH 16/31] use new attribute_changed method for taxons take 2 --- app/models/spree/product.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/models/spree/product.rb b/app/models/spree/product.rb index c1152e1462..a2ae860d9f 100755 --- a/app/models/spree/product.rb +++ b/app/models/spree/product.rb @@ -449,9 +449,9 @@ module Spree end def remove_previous_primary_taxon_from_taxons - return unless saved_change_to_primary_taxon_id? && primary_taxon_id_was + return unless saved_change_to_primary_taxon_id? && primary_taxon_id_before_last_save - taxons.destroy(primary_taxon_id_was) + taxons.destroy(primary_taxon_id_before_last_save) end def ensure_standard_variant From ea5f9c67477b8e59bc393af331c8c6bd22264c04 Mon Sep 17 00:00:00 2001 From: Andy Brett Date: Fri, 9 Apr 2021 10:28:37 -0700 Subject: [PATCH 17/31] Revert "Fix cart_service_spec to adapt to the actual usage of it from cart_controller, params are now sent inside a Parameters object, not as a hash" This reverts commit bb465b5715cdad836d6cfea91e99be033afbb215. --- spec/services/cart_service_spec.rb | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/spec/services/cart_service_spec.rb b/spec/services/cart_service_spec.rb index 51e8f2b882..b8144f867b 100644 --- a/spec/services/cart_service_spec.rb +++ b/spec/services/cart_service_spec.rb @@ -27,8 +27,7 @@ describe CartService do describe "#populate" do it "adds a variant" do cart_service.populate( - ActionController::Parameters.new({ variants: { variant.id.to_s => { quantity: '1', - max_quantity: '2' } } }), + { variants: { variant.id.to_s => { quantity: '1', max_quantity: '2' } } }, true ) li = order.find_line_item_by_variant(variant) @@ -42,8 +41,7 @@ describe CartService do order.add_variant variant, 1, 2 cart_service.populate( - ActionController::Parameters.new({ variants: { variant.id.to_s => { quantity: '2', - max_quantity: '3' } } }), + { variants: { variant.id.to_s => { quantity: '2', max_quantity: '3' } } }, true ) li = order.find_line_item_by_variant(variant) @@ -56,7 +54,7 @@ describe CartService do it "removes a variant" do order.add_variant variant, 1, 2 - cart_service.populate(ActionController::Parameters.new({ variants: {} }), true) + cart_service.populate({ variants: {} }, true) order.line_items.reload li = order.find_line_item_by_variant(variant) expect(li).not_to be @@ -69,7 +67,7 @@ describe CartService do it "does not add the deleted variant to the cart" do variant.delete - cart_service.populate(ActionController::Parameters.new({ variants: { variant.id.to_s => { quantity: '2' } } }), true) + cart_service.populate({ variants: { variant.id.to_s => { quantity: '2' } } }, true) expect(relevant_line_item).to be_nil expect(cart_service.errors.count).to be 0 @@ -84,7 +82,7 @@ describe CartService do it "removes the line_item from the cart" do variant.delete - cart_service.populate(ActionController::Parameters.new({ variants: { variant.id.to_s => { quantity: '3' } } }), true) + cart_service.populate({ variants: { variant.id.to_s => { quantity: '3' } } }, true) expect(Spree::LineItem.where(id: relevant_line_item).first).to be_nil expect(cart_service.errors.count).to be 0 From 203dbb7a8b2417fdb7506559b39d8f59c2cc0471 Mon Sep 17 00:00:00 2001 From: Andy Brett Date: Fri, 9 Apr 2021 10:28:39 -0700 Subject: [PATCH 18/31] Revert "Switch from map, that does not exist in ActionController::Parameters, to each" This reverts commit 69a15d4f041b692ca02241239760af231aa318c7. --- app/services/cart_service.rb | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/app/services/cart_service.rb b/app/services/cart_service.rb index c4f3b5a5c0..35dcb720f0 100644 --- a/app/services/cart_service.rb +++ b/app/services/cart_service.rb @@ -106,15 +106,13 @@ class CartService end def read_variants_hash(data) - variants_array = [] - (data[:variants] || []).each do |variant_id, quantity| - if quantity.is_a?(ActionController::Parameters) - variants_array.push({ variant_id: variant_id, quantity: quantity[:quantity], max_quantity: quantity[:max_quantity] }) + (data[:variants] || []).map do |variant_id, quantity| + if quantity.is_a?(Hash) + { variant_id: variant_id, quantity: quantity[:quantity], max_quantity: quantity[:max_quantity] } else - variants_array.push({ variant_id: variant_id, quantity: quantity }) + { variant_id: variant_id, quantity: quantity } end end - variants_array end def cart_remove(variant_id) From f5a7ff0f0abf566f28822b7037a2d60b18bafd10 Mon Sep 17 00:00:00 2001 From: Luis Ramos Date: Thu, 8 Apr 2021 00:03:53 +0100 Subject: [PATCH 19/31] Switch from map, that does not exist in ActionController::Parameters, to each --- app/services/cart_service.rb | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/app/services/cart_service.rb b/app/services/cart_service.rb index 35dcb720f0..c4f3b5a5c0 100644 --- a/app/services/cart_service.rb +++ b/app/services/cart_service.rb @@ -106,13 +106,15 @@ class CartService end def read_variants_hash(data) - (data[:variants] || []).map do |variant_id, quantity| - if quantity.is_a?(Hash) - { variant_id: variant_id, quantity: quantity[:quantity], max_quantity: quantity[:max_quantity] } + variants_array = [] + (data[:variants] || []).each do |variant_id, quantity| + if quantity.is_a?(ActionController::Parameters) + variants_array.push({ variant_id: variant_id, quantity: quantity[:quantity], max_quantity: quantity[:max_quantity] }) else - { variant_id: variant_id, quantity: quantity } + variants_array.push({ variant_id: variant_id, quantity: quantity }) end end + variants_array end def cart_remove(variant_id) From aaf4710694c2676d7a0f8d4969cccf6506562963 Mon Sep 17 00:00:00 2001 From: Luis Ramos Date: Thu, 8 Apr 2021 21:26:01 +0100 Subject: [PATCH 20/31] Fix cart_service_spec to adapt to the actual usage of it from cart_controller, params are now sent inside a Parameters object, not as a hash --- spec/services/cart_service_spec.rb | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/spec/services/cart_service_spec.rb b/spec/services/cart_service_spec.rb index b8144f867b..51e8f2b882 100644 --- a/spec/services/cart_service_spec.rb +++ b/spec/services/cart_service_spec.rb @@ -27,7 +27,8 @@ describe CartService do describe "#populate" do it "adds a variant" do cart_service.populate( - { variants: { variant.id.to_s => { quantity: '1', max_quantity: '2' } } }, + ActionController::Parameters.new({ variants: { variant.id.to_s => { quantity: '1', + max_quantity: '2' } } }), true ) li = order.find_line_item_by_variant(variant) @@ -41,7 +42,8 @@ describe CartService do order.add_variant variant, 1, 2 cart_service.populate( - { variants: { variant.id.to_s => { quantity: '2', max_quantity: '3' } } }, + ActionController::Parameters.new({ variants: { variant.id.to_s => { quantity: '2', + max_quantity: '3' } } }), true ) li = order.find_line_item_by_variant(variant) @@ -54,7 +56,7 @@ describe CartService do it "removes a variant" do order.add_variant variant, 1, 2 - cart_service.populate({ variants: {} }, true) + cart_service.populate(ActionController::Parameters.new({ variants: {} }), true) order.line_items.reload li = order.find_line_item_by_variant(variant) expect(li).not_to be @@ -67,7 +69,7 @@ describe CartService do it "does not add the deleted variant to the cart" do variant.delete - cart_service.populate({ variants: { variant.id.to_s => { quantity: '2' } } }, true) + cart_service.populate(ActionController::Parameters.new({ variants: { variant.id.to_s => { quantity: '2' } } }), true) expect(relevant_line_item).to be_nil expect(cart_service.errors.count).to be 0 @@ -82,7 +84,7 @@ describe CartService do it "removes the line_item from the cart" do variant.delete - cart_service.populate({ variants: { variant.id.to_s => { quantity: '3' } } }, true) + cart_service.populate(ActionController::Parameters.new({ variants: { variant.id.to_s => { quantity: '3' } } }), true) expect(Spree::LineItem.where(id: relevant_line_item).first).to be_nil expect(cart_service.errors.count).to be 0 From 705666ecd0d39225cde40d3d0cffcd7ac4f68a87 Mon Sep 17 00:00:00 2001 From: Andy Brett Date: Fri, 9 Apr 2021 15:30:46 -0700 Subject: [PATCH 21/31] fix /spec/models/spree/credit_card_spec.rb:301 --- app/models/spree/credit_card.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/spree/credit_card.rb b/app/models/spree/credit_card.rb index afa2353d79..eb31597d5b 100644 --- a/app/models/spree/credit_card.rb +++ b/app/models/spree/credit_card.rb @@ -147,7 +147,7 @@ module Spree end def default_card_needs_updating? - saved_change_to_is_default? || gateway_customer_profile_id_changed? + saved_change_to_is_default? || saved_change_to_gateway_customer_profile_id? end def ensure_single_default_card From 47a58091008c9d30dc7894a0ae5804b3f46a5fb4 Mon Sep 17 00:00:00 2001 From: Luis Ramos Date: Fri, 9 Apr 2021 23:51:51 +0100 Subject: [PATCH 22/31] Fix rspec syntax --- spec/requests/large_request_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/requests/large_request_spec.rb b/spec/requests/large_request_spec.rb index 5631ef4f05..979b6c941d 100644 --- a/spec/requests/large_request_spec.rb +++ b/spec/requests/large_request_spec.rb @@ -7,7 +7,7 @@ require 'spec_helper' RSpec.describe 'A very large request', type: :request do it 'should not overflow cookies' do - get '/admin', foo: 'x' * ActionDispatch::Cookies::MAX_COOKIE_SIZE + get '/admin', params: { foo: 'x' * ActionDispatch::Cookies::MAX_COOKIE_SIZE } expect(response.status).to eq(302) # HTTP status 302 - Found ## Use the newer syntax if rspec gets upgraded # expect(response).to have_http_status(:redirect) From 279c15c306150784ff067281e0f854d82d8cda54 Mon Sep 17 00:00:00 2001 From: Luis Ramos Date: Sat, 10 Apr 2021 00:10:40 +0100 Subject: [PATCH 23/31] Adapt spec to rails 5.2 --- spec/services/embedded_page_service_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/services/embedded_page_service_spec.rb b/spec/services/embedded_page_service_spec.rb index 1d85ab69c3..20cb156969 100644 --- a/spec/services/embedded_page_service_spec.rb +++ b/spec/services/embedded_page_service_spec.rb @@ -6,7 +6,7 @@ describe EmbeddedPageService do let(:enterprise_slug) { 'test-enterprise' } let(:params) { { controller: 'enterprises', action: 'shop', id: enterprise_slug, embedded_shopfront: true } } let(:session) { {} } - let(:request) { ActionController::TestRequest.new({'HTTP_HOST' => 'ofn-instance.com', 'HTTP_REFERER' => 'https://embedding-enterprise.com'}, nil) } + let(:request) { ActionController::TestRequest.new({'HTTP_HOST' => 'ofn-instance.com', 'HTTP_REFERER' => 'https://embedding-enterprise.com'}, nil, nil) } let(:response) { ActionDispatch::TestResponse.new(200, 'X-Frame-Options' => 'DENY', 'Content-Security-Policy' => "frame-ancestors 'none'") } let(:service) { EmbeddedPageService.new(params, session, request, response) } @@ -63,7 +63,7 @@ describe EmbeddedPageService do end context "when the request's referer is malformed" do - let(:request) { ActionController::TestRequest.new({'HTTP_HOST' => 'ofn-instance.com', 'HTTP_REFERER' => 'hello'}, nil) } + let(:request) { ActionController::TestRequest.new({'HTTP_HOST' => 'ofn-instance.com', 'HTTP_REFERER' => 'hello'}, nil, nil) } before do service.embed! end From ac53df37d931dce895af045a8dfc4425ec7b54ff Mon Sep 17 00:00:00 2001 From: Matt-Yorkley <9029026+Matt-Yorkley@users.noreply.github.com> Date: Sat, 10 Apr 2021 13:01:10 +0100 Subject: [PATCH 24/31] Fix callback in LineItem #changed? here was not working as before, and the code was never getting past this guard in various places where previously it did. This meant the callback was effectively disabled, and order.update! was not being called when it should be. --- app/models/spree/line_item.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/spree/line_item.rb b/app/models/spree/line_item.rb index 97cd7dd888..6b17d87ca1 100644 --- a/app/models/spree/line_item.rb +++ b/app/models/spree/line_item.rb @@ -226,7 +226,7 @@ module Spree end def update_order - return unless changed? || destroyed? + return unless saved_change_to_quantity? || destroyed? # update the order totals, etc. order.create_tax_charge! From 1de68d091a35a12371c7f57bafd3bbb651fc36dd Mon Sep 17 00:00:00 2001 From: Matt-Yorkley <9029026+Matt-Yorkley@users.noreply.github.com> Date: Sat, 10 Apr 2021 18:42:07 +0100 Subject: [PATCH 25/31] Update guard clause in line item callbacks (take two) The `changed?` method is more accurately replaced by `saved_changes.present?` In some cases here (where the object had just been saved for the first time) the guard clause was still stopping execution unexpectedly. --- app/models/spree/line_item.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/spree/line_item.rb b/app/models/spree/line_item.rb index 6b17d87ca1..61bed0c1d0 100644 --- a/app/models/spree/line_item.rb +++ b/app/models/spree/line_item.rb @@ -226,7 +226,7 @@ module Spree end def update_order - return unless saved_change_to_quantity? || destroyed? + return unless saved_changes.present? || destroyed? # update the order totals, etc. order.create_tax_charge! From ab65b01fcf7a9ba396d6feb459b78c83f0a49b74 Mon Sep 17 00:00:00 2001 From: Matt-Yorkley <9029026+Matt-Yorkley@users.noreply.github.com> Date: Sat, 10 Apr 2021 18:05:46 +0100 Subject: [PATCH 26/31] Rename payments helper --- .rubocop_todo.yml | 1 - app/helpers/spree/admin/payments_helper.rb | 11 ----------- app/helpers/spree/payment_methods_helper.rb | 9 +++++++++ app/mailers/spree/order_mailer.rb | 2 +- app/mailers/subscription_mailer.rb | 2 +- spec/services/bulk_invoice_service_spec.rb | 4 ++-- spec/services/invoice_renderer_spec.rb | 4 ++-- 7 files changed, 15 insertions(+), 18 deletions(-) delete mode 100644 app/helpers/spree/admin/payments_helper.rb create mode 100644 app/helpers/spree/payment_methods_helper.rb diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 6f3bbb554b..1013c35643 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -931,7 +931,6 @@ Style/FrozenStringLiteralComment: - 'app/helpers/spree/admin/base_helper.rb' - 'app/helpers/spree/admin/general_settings_helper.rb' - 'app/helpers/spree/admin/orders_helper.rb' - - 'app/helpers/spree/admin/payments_helper.rb' - 'app/helpers/spree/admin/taxons_helper.rb' - 'app/helpers/spree/admin/zones_helper.rb' - 'app/helpers/spree/orders_helper.rb' diff --git a/app/helpers/spree/admin/payments_helper.rb b/app/helpers/spree/admin/payments_helper.rb deleted file mode 100644 index 529ef90adf..0000000000 --- a/app/helpers/spree/admin/payments_helper.rb +++ /dev/null @@ -1,11 +0,0 @@ -module Spree - module Admin - module PaymentsHelper - def payment_method_name(payment) - # hack to allow us to retrieve the name of a "deleted" payment method - id = payment.payment_method_id - Spree::PaymentMethod.find_with_destroyed(id).name - end - end - end -end diff --git a/app/helpers/spree/payment_methods_helper.rb b/app/helpers/spree/payment_methods_helper.rb new file mode 100644 index 0000000000..00abd77eef --- /dev/null +++ b/app/helpers/spree/payment_methods_helper.rb @@ -0,0 +1,9 @@ +module Spree + module PaymentMethodsHelper + def payment_method_name(payment) + # hack to allow us to retrieve the name of a "deleted" payment method + id = payment.payment_method_id + Spree::PaymentMethod.find_with_destroyed(id).name + end + end +end diff --git a/app/mailers/spree/order_mailer.rb b/app/mailers/spree/order_mailer.rb index 00002715c3..a8056c1778 100644 --- a/app/mailers/spree/order_mailer.rb +++ b/app/mailers/spree/order_mailer.rb @@ -4,7 +4,7 @@ module Spree class OrderMailer < BaseMailer helper 'checkout' helper SpreeCurrencyHelper - helper Spree::Admin::PaymentsHelper + helper Spree::PaymentMethodsHelper helper OrderHelper helper MailerHelper include I18nHelper diff --git a/app/mailers/subscription_mailer.rb b/app/mailers/subscription_mailer.rb index dd20008bfc..90efc9ee40 100644 --- a/app/mailers/subscription_mailer.rb +++ b/app/mailers/subscription_mailer.rb @@ -3,7 +3,7 @@ class SubscriptionMailer < Spree::BaseMailer helper MailerHelper helper ShopMailHelper helper OrderHelper - helper Spree::Admin::PaymentsHelper + helper Spree::PaymentMethodsHelper include I18nHelper def confirmation_email(order) diff --git a/spec/services/bulk_invoice_service_spec.rb b/spec/services/bulk_invoice_service_spec.rb index 78a324f0f2..b145dc8501 100644 --- a/spec/services/bulk_invoice_service_spec.rb +++ b/spec/services/bulk_invoice_service_spec.rb @@ -1,11 +1,11 @@ # frozen_string_literal: false require 'spec_helper' -require 'spree/admin/payments_helper' +require 'spree/payment_methods_helper' describe BulkInvoiceService do include ActiveJob::TestHelper - include Spree::Admin::PaymentsHelper + include Spree::PaymentMethodsHelper let(:service) { BulkInvoiceService.new } diff --git a/spec/services/invoice_renderer_spec.rb b/spec/services/invoice_renderer_spec.rb index cb861d2da6..2818ee8926 100644 --- a/spec/services/invoice_renderer_spec.rb +++ b/spec/services/invoice_renderer_spec.rb @@ -1,10 +1,10 @@ # frozen_string_literal: true require 'spec_helper' -require 'spree/admin/payments_helper' +require 'spree/payment_methods_helper' describe InvoiceRenderer do - include Spree::Admin::PaymentsHelper + include Spree::PaymentMethodsHelper let(:service) { described_class.new } let(:order) do From 31fc6201fce440110fa4d9d4cfae409bb185fc39 Mon Sep 17 00:00:00 2001 From: Matt-Yorkley <9029026+Matt-Yorkley@users.noreply.github.com> Date: Sat, 10 Apr 2021 18:06:23 +0100 Subject: [PATCH 27/31] Include payment method helper in ApplicationController --- app/controllers/application_controller.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 2055c0df16..fb08a08549 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -15,6 +15,7 @@ class ApplicationController < ActionController::Base helper 'spree/base' helper 'spree/orders' + helper 'spree/payment_methods' helper 'shared' helper 'enterprises' helper 'order_cycles' From 4888f1cd06880fa8bc6d9aa9273f569a801f69c8 Mon Sep 17 00:00:00 2001 From: Matt-Yorkley <9029026+Matt-Yorkley@users.noreply.github.com> Date: Sat, 10 Apr 2021 20:35:30 +0100 Subject: [PATCH 28/31] Stub OrderPaymentFinder to return correct object OrderPaymentFinder was re-fetching the payment object from the database, so the subsequent line that stubs #authorize! on that payment was not being applied to the correct object. --- spec/services/checkout/stripe_redirect_spec.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/spec/services/checkout/stripe_redirect_spec.rb b/spec/services/checkout/stripe_redirect_spec.rb index 05b46dfe25..6d5830e3c9 100644 --- a/spec/services/checkout/stripe_redirect_spec.rb +++ b/spec/services/checkout/stripe_redirect_spec.rb @@ -38,6 +38,8 @@ describe Checkout::StripeRedirect do it "returns the redirect path" do stripe_payment = create(:payment, payment_method_id: payment_method.id) order.payments << stripe_payment + allow(OrderPaymentFinder).to receive_message_chain(:new, :last_pending_payment). + and_return(stripe_payment) allow(stripe_payment).to receive(:authorize!) do # Authorization moves the payment state from checkout/processing to pending stripe_payment.state = 'pending' From a645b8c58f7072e0e0bfbb18f93d02365da096c6 Mon Sep 17 00:00:00 2001 From: Matt-Yorkley <9029026+Matt-Yorkley@users.noreply.github.com> Date: Tue, 27 Apr 2021 17:58:46 +0100 Subject: [PATCH 29/31] Re-apply previous 5.2 commit: Don't reload payments in after_save callback This causes issues in master, but is needed in the 5.2 branch. --- app/models/spree/payment.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/spree/payment.rb b/app/models/spree/payment.rb index e9173d59a1..d16e428922 100644 --- a/app/models/spree/payment.rb +++ b/app/models/spree/payment.rb @@ -201,7 +201,7 @@ module Spree end def update_order - order.reload.update! + order.update! end # Necessary because some payment gateways will refuse payments with From aa013ef76a3bd08ae75178ae5d6b2a8b8e2706fa Mon Sep 17 00:00:00 2001 From: Matt-Yorkley <9029026+Matt-Yorkley@users.noreply.github.com> Date: Fri, 30 Apr 2021 15:13:18 +0100 Subject: [PATCH 30/31] Update redirect_back syntax for Rails 5 Introduced in 5.0, the old syntax is removed in 5.2 --- app/controllers/spree/admin/orders_controller.rb | 6 ++++-- .../spree/admin/return_authorizations_controller.rb | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/app/controllers/spree/admin/orders_controller.rb b/app/controllers/spree/admin/orders_controller.rb index bb4e1943d1..3eb0116d46 100644 --- a/app/controllers/spree/admin/orders_controller.rb +++ b/app/controllers/spree/admin/orders_controller.rb @@ -68,14 +68,16 @@ module Spree rescue Spree::Core::GatewayError => e flash[:error] = e.message.to_s ensure - redirect_to :back + redirect_back fallback_location: spree.admin_dashboard_path end def resend Spree::OrderMailer.confirm_email_for_customer(@order.id, true).deliver_later flash[:success] = t('admin.orders.order_email_resent') - respond_with(@order) { |format| format.html { redirect_to :back } } + respond_with(@order) do |format| + format.html { redirect_back(fallback_location: spree.admin_dashboard_path) } + end end def invoice diff --git a/app/controllers/spree/admin/return_authorizations_controller.rb b/app/controllers/spree/admin/return_authorizations_controller.rb index 094dd37d4a..313227f368 100644 --- a/app/controllers/spree/admin/return_authorizations_controller.rb +++ b/app/controllers/spree/admin/return_authorizations_controller.rb @@ -8,7 +8,7 @@ module Spree def fire @return_authorization.public_send("#{params[:e]}!") flash[:success] = Spree.t(:return_authorization_updated) - redirect_to :back + redirect_back fallback_location: spree.admin_dashboard_path end protected From e2a411c23cab80138fe4e2778dc4907bc2eac002 Mon Sep 17 00:00:00 2001 From: Matt-Yorkley <9029026+Matt-Yorkley@users.noreply.github.com> Date: Fri, 30 Apr 2021 17:59:06 +0100 Subject: [PATCH 31/31] Add map helper to RegistrationController Fixes 3 errors including: Registration Terms of Service agreement if accepting Terms of Service is not required allows registration as normal Failure/Error: super ActionView::Template::Error: undefined method `using_google_maps?' for #<#:0x00007fd499dd0ae8> # ./app/helpers/application_helper.rb:20:in `method_missing' # ./app/views/registration/steps/_details.html.haml:60:in `_app_views_registration_steps__details_html_haml___1911121144363058234_70275472163280' # ./app/views/registration/index.html.haml:12:in `block in _app_views_registration_index_html_haml__993897347679518865_70275545598940' # ./app/views/registration/index.html.haml:11:in `each' # ./app/views/registration/index.html.haml:11:in `_app_views_registration_index_html_haml__993897347679518865_70275545598940' # ./lib/open_food_network/rack_request_blocker.rb:36:in `call' # ------------------ # --- Caused by: --- # NoMethodError: # undefined method `using_google_maps?' for #<#:0x00007fd499dd0ae8> # ./app/helpers/application_helper.rb:20:in `method_missing' --- app/controllers/registration_controller.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/controllers/registration_controller.rb b/app/controllers/registration_controller.rb index 71e621f077..11f37fec13 100644 --- a/app/controllers/registration_controller.rb +++ b/app/controllers/registration_controller.rb @@ -2,9 +2,12 @@ require 'open_food_network/spree_api_key_loader' class RegistrationController < BaseController include OpenFoodNetwork::SpreeApiKeyLoader + + layout 'registration' + helper 'map' + before_action :load_spree_api_key, only: [:index] before_action :check_user, except: :authenticate - layout 'registration' def index @enterprise_attributes = { sells: 'none' }