From 5bd1e9c37c3fcbe9b969ffc753be4c82d9105f08 Mon Sep 17 00:00:00 2001 From: Matt-Yorkley <9029026+Matt-Yorkley@users.noreply.github.com> Date: Sat, 9 Jan 2021 17:04:58 +0000 Subject: [PATCH 01/50] Add rails-controller-testing gem ``` Spree::Admin::PaymentMethodsController#create and #update can create a payment method of a valid type Failure/Error: expect(response).to redirect_to spree.edit_admin_payment_method_path(assigns(:payment_method)) NoMethodError: assigns has been extracted to a gem. To continue using it, add `gem 'rails-controller-testing'` to your Gemfile. # ./spec/controllers/spree/admin/payment_methods_controller_spec.rb:41:in `block (3 levels) in ' ``` --- Gemfile | 1 + 1 file changed, 1 insertion(+) diff --git a/Gemfile b/Gemfile index 14a96e6f5a1..02f70db2c3b 100644 --- a/Gemfile +++ b/Gemfile @@ -168,6 +168,7 @@ group :test do gem 'simplecov', require: false gem 'test-prof' gem 'webmock' + gem 'rails-controller-testing' # See spec/spec_helper.rb for instructions # gem 'perftools.rb' end From 2fdb1861a6ff097b2ddbb5d646ca799269196128 Mon Sep 17 00:00:00 2001 From: Matt-Yorkley <9029026+Matt-Yorkley@users.noreply.github.com> Date: Sat, 9 Jan 2021 18:43:51 +0000 Subject: [PATCH 02/50] Fix uses of ActionController::TestResponse in specs This class has moved / changed slightly. --- .../enterprise_fee_summary/renderers/csv_renderer_spec.rb | 2 +- spec/services/embedded_page_service_spec.rb | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/engines/order_management/spec/services/order_management/reports/enterprise_fee_summary/renderers/csv_renderer_spec.rb b/engines/order_management/spec/services/order_management/reports/enterprise_fee_summary/renderers/csv_renderer_spec.rb index 686f6102a81..69ef97e8681 100644 --- a/engines/order_management/spec/services/order_management/reports/enterprise_fee_summary/renderers/csv_renderer_spec.rb +++ b/engines/order_management/spec/services/order_management/reports/enterprise_fee_summary/renderers/csv_renderer_spec.rb @@ -12,7 +12,7 @@ # Context which will be passed to the renderer. The response object is not automatically prepared, # so this has to be assigned explicitly. - let!(:response) { ActionController::TestResponse.new } + let!(:response) { ActionDispatch::TestResponse.new } let!(:controller) do ActionController::Base.new.tap do |controller_mock| controller_mock.instance_variable_set(:@_response, response) diff --git a/spec/services/embedded_page_service_spec.rb b/spec/services/embedded_page_service_spec.rb index a6d7997976a..1d85ab69c30 100644 --- a/spec/services/embedded_page_service_spec.rb +++ b/spec/services/embedded_page_service_spec.rb @@ -6,8 +6,8 @@ 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') } - let(:response) { ActionController::TestResponse.new(200, 'X-Frame-Options' => 'DENY', 'Content-Security-Policy' => "frame-ancestors 'none'") } + let(:request) { ActionController::TestRequest.new({'HTTP_HOST' => 'ofn-instance.com', 'HTTP_REFERER' => 'https://embedding-enterprise.com'}, nil) } + let(:response) { ActionDispatch::TestResponse.new(200, 'X-Frame-Options' => 'DENY', 'Content-Security-Policy' => "frame-ancestors 'none'") } let(:service) { EmbeddedPageService.new(params, session, request, response) } before do @@ -23,7 +23,7 @@ it "sets the response headers to enables embedding requests from the embedding site" do expect(response.headers).to_not include 'X-Frame-Options' => 'DENY' - expect(response.headers).to include 'Content-Security-Policy' => "frame-ancestors 'self' embedding-enterprise.com" + expect(response.headers).to eq 'Content-Security-Policy' => "frame-ancestors 'self' embedding-enterprise.com" end it "sets session variables" do @@ -63,7 +63,7 @@ end context "when the request's referer is malformed" do - let(:request) { ActionController::TestRequest.new('HTTP_HOST' => 'ofn-instance.com', 'HTTP_REFERER' => 'hello') } + let(:request) { ActionController::TestRequest.new({'HTTP_HOST' => 'ofn-instance.com', 'HTTP_REFERER' => 'hello'}, nil) } before do service.embed! end From ed09db6003ab26f68fd4824de3da2a40c5bd36ef Mon Sep 17 00:00:00 2001 From: Matt-Yorkley <9029026+Matt-Yorkley@users.noreply.github.com> Date: Sat, 9 Jan 2021 20:50:40 +0000 Subject: [PATCH 03/50] Fix broken specs related to accessing params hash --- app/controllers/user_passwords_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/user_passwords_controller.rb b/app/controllers/user_passwords_controller.rb index a27d8a5eb36..9314f5f41d6 100644 --- a/app/controllers/user_passwords_controller.rb +++ b/app/controllers/user_passwords_controller.rb @@ -6,7 +6,7 @@ class UserPasswordsController < Spree::UserPasswordsController def create render_unconfirmed_response && return if user_unconfirmed? - self.resource = resource_class.send_reset_password_instructions(params[resource_name]) + self.resource = resource_class.send_reset_password_instructions(raw_params[resource_name]) if resource.errors.empty? set_flash_message(:success, :send_instructions) if is_navigational_format? From 0f1142b5c447cbdada31cf1d104ff11f543183c5 Mon Sep 17 00:00:00 2001 From: Matt-Yorkley <9029026+Matt-Yorkley@users.noreply.github.com> Date: Sat, 9 Jan 2021 21:21:53 +0000 Subject: [PATCH 04/50] Fix more broken specs related to accessing params hash --- .../spree/admin/reports_controller.rb | 32 +++++++++---------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/app/controllers/spree/admin/reports_controller.rb b/app/controllers/spree/admin/reports_controller.rb index 046d86204e9..682d50250c1 100644 --- a/app/controllers/spree/admin/reports_controller.rb +++ b/app/controllers/spree/admin/reports_controller.rb @@ -46,19 +46,19 @@ def index def customers @report_types = report_types[:customers] @report_type = params[:report_type] - @report = OpenFoodNetwork::CustomersReport.new spree_current_user, params, render_content? + @report = OpenFoodNetwork::CustomersReport.new spree_current_user, raw_params, render_content? render_report(@report.header, @report.table, params[:csv], "customers_#{timestamp}.csv") end def order_cycle_management - params[:q] ||= {} + raw_params[:q] ||= {} @report_types = report_types[:order_cycle_management] @report_type = params[:report_type] # -- Build Report with Order Grouper @report = OpenFoodNetwork::OrderCycleManagementReport.new spree_current_user, - params, + raw_params, render_content? @table = @report.table_items @@ -67,13 +67,13 @@ def order_cycle_management end def packing - params[:q] ||= {} + raw_params[:q] ||= {} @report_types = report_types[:packing] @report_type = params[:report_type] # -- Build Report with Order Grouper - @report = OpenFoodNetwork::PackingReport.new spree_current_user, params, render_content? + @report = OpenFoodNetwork::PackingReport.new spree_current_user, raw_params, render_content? @table = order_grouper_table render_report(@report.header, @table, params[:csv], "packing_#{timestamp}.csv") @@ -81,7 +81,7 @@ def packing def orders_and_distributors @report = OpenFoodNetwork::OrderAndDistributorReport.new spree_current_user, - params, + raw_params, render_content? @search = @report.search csv_file_name = "orders_and_distributors_#{timestamp}.csv" @@ -91,7 +91,7 @@ def orders_and_distributors def sales_tax @distributors = my_distributors @report_type = params[:report_type] - @report = OpenFoodNetwork::SalesTaxReport.new spree_current_user, params, render_content? + @report = OpenFoodNetwork::SalesTaxReport.new spree_current_user, raw_params, render_content? render_report(@report.header, @report.table, params[:csv], "sales_tax.csv") end @@ -101,7 +101,7 @@ def payments @report_type = params[:report_type] # -- Build Report with Order Grouper - @report = OpenFoodNetwork::PaymentsReport.new spree_current_user, params, render_content? + @report = OpenFoodNetwork::PaymentsReport.new spree_current_user, raw_params, render_content? @table = order_grouper_table csv_file_name = "payments_#{timestamp}.csv" @@ -109,7 +109,7 @@ def payments end def orders_and_fulfillment - params[:q] ||= orders_and_fulfillment_default_filters + raw_params[:q] ||= orders_and_fulfillment_default_filters # -- Prepare Form Options permissions = OpenFoodNetwork::Permissions.new(spree_current_user) @@ -127,7 +127,7 @@ def orders_and_fulfillment # -- Build Report with Order Grouper @report = OpenFoodNetwork::OrdersAndFulfillmentsReport.new spree_current_user, - params, + raw_params, render_content? @table = order_grouper_table csv_file_name = "#{params[:report_type]}_#{timestamp}.csv" @@ -139,11 +139,11 @@ def products_and_inventory @report_types = report_types[:products_and_inventory] @report = if params[:report_type] != 'lettuce_share' OpenFoodNetwork::ProductsAndInventoryReport.new spree_current_user, - params, + raw_params, render_content? else OpenFoodNetwork::LettuceShareReport.new spree_current_user, - params, + raw_params, render_content? end @@ -154,19 +154,19 @@ def products_and_inventory end def users_and_enterprises - @report = OpenFoodNetwork::UsersAndEnterprisesReport.new params, render_content? + @report = OpenFoodNetwork::UsersAndEnterprisesReport.new raw_params, render_content? render_report(@report.header, @report.table, params[:csv], "users_and_enterprises_#{timestamp}.csv") end def xero_invoices - params[:q] ||= {} + raw_params[:q] ||= {} @distributors = my_distributors @order_cycles = my_order_cycles @report = OpenFoodNetwork::XeroInvoicesReport.new(spree_current_user, - params, + raw_params, render_content?) render_report(@report.header, @report.table, params[:csv], "xero_invoices_#{timestamp}.csv") end @@ -198,7 +198,7 @@ def cache_search_state :invoice_date, :due_date ] - @searching = search_keys.any? { |key| params.key? key } + @searching = search_keys.any? { |key| raw_params.key? key } end # We don't want to render data unless search params are supplied. From 009844bfe79923254a2f7bd7d0054c7bfc80be5c Mon Sep 17 00:00:00 2001 From: Matt-Yorkley <9029026+Matt-Yorkley@users.noreply.github.com> Date: Sat, 9 Jan 2021 21:22:31 +0000 Subject: [PATCH 05/50] Update expected params in reports controller tests --- spec/controllers/spree/admin/reports_controller_spec.rb | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/spec/controllers/spree/admin/reports_controller_spec.rb b/spec/controllers/spree/admin/reports_controller_spec.rb index f9a08038b5d..c2f4fbbe7ae 100644 --- a/spec/controllers/spree/admin/reports_controller_spec.rb +++ b/spec/controllers/spree/admin/reports_controller_spec.rb @@ -227,7 +227,9 @@ it "creates a ProductAndInventoryReport" do expect(OpenFoodNetwork::ProductsAndInventoryReport).to receive(:new) - .with(@admin_user, { "test" => "foo", "controller" => "spree/admin/reports", "action" => "products_and_inventory" }, false) + .with(@admin_user, + { "test" => "foo", "controller" => "spree/admin/reports", + "action" => "products_and_inventory", "use_route" => "main_app" }, false) .and_return(report = double(:report)) allow(report).to receive(:header).and_return [] allow(report).to receive(:table).and_return [] @@ -278,7 +280,8 @@ it "creates a CustomersReport" do expect(OpenFoodNetwork::CustomersReport).to receive(:new) - .with(@admin_user, { "test" => "foo", "controller" => "spree/admin/reports", "action" => "customers" }, false) + .with(@admin_user, { "test" => "foo", "controller" => "spree/admin/reports", + "action" => "customers", "use_route" => "main_app" }, false) .and_return(report = double(:report)) allow(report).to receive(:header).and_return [] allow(report).to receive(:table).and_return [] From c5feb19e5bc98369bee2c2086239944c058ce6a8 Mon Sep 17 00:00:00 2001 From: Matt-Yorkley <9029026+Matt-Yorkley@users.noreply.github.com> Date: Sat, 9 Jan 2021 22:16:01 +0000 Subject: [PATCH 06/50] Fix use of ActiveRecord::Type::Boolean#type_cast_from_database This method longer exists. --- lib/open_food_network/users_and_enterprises_report.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/open_food_network/users_and_enterprises_report.rb b/lib/open_food_network/users_and_enterprises_report.rb index 24a92bdf2f5..4a88e2f5f9d 100644 --- a/lib/open_food_network/users_and_enterprises_report.rb +++ b/lib/open_food_network/users_and_enterprises_report.rb @@ -122,7 +122,7 @@ def sort(results) end def to_bool(value) - ActiveRecord::Type::Boolean.new.type_cast_from_database(value) + ActiveRecord::Type::Boolean.new.cast(value) end def to_local_datetime(date) From 7bf4f8803419caf9fc5d1efe73bd0d1ca6cdaea6 Mon Sep 17 00:00:00 2001 From: Matt-Yorkley <9029026+Matt-Yorkley@users.noreply.github.com> Date: Sat, 9 Jan 2021 22:29:57 +0000 Subject: [PATCH 07/50] Fix params issues in Api::TaxonsController --- app/controllers/api/base_controller.rb | 1 + app/controllers/api/taxons_controller.rb | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/app/controllers/api/base_controller.rb b/app/controllers/api/base_controller.rb index 54feee38029..3ec78c85d4d 100644 --- a/app/controllers/api/base_controller.rb +++ b/app/controllers/api/base_controller.rb @@ -4,6 +4,7 @@ module Api class BaseController < ActionController::Metal + include RawParams include ActionController::StrongParameters include ActionController::RespondWith include Spree::Api::ControllerSetup diff --git a/app/controllers/api/taxons_controller.rb b/app/controllers/api/taxons_controller.rb index a70677b8574..491cf759549 100644 --- a/app/controllers/api/taxons_controller.rb +++ b/app/controllers/api/taxons_controller.rb @@ -8,9 +8,9 @@ def index @taxons = if taxonomy taxonomy.root.children elsif params[:ids] - Spree::Taxon.where(id: params[:ids].split(",")) + Spree::Taxon.where(id: raw_params[:ids].split(",")) else - Spree::Taxon.ransack(params[:q]).result + Spree::Taxon.ransack(raw_params[:q]).result end render json: @taxons, each_serializer: Api::TaxonSerializer end From af8d497433394cd92426c9564f0f1dcce1249b5f Mon Sep 17 00:00:00 2001 From: Matt-Yorkley <9029026+Matt-Yorkley@users.noreply.github.com> Date: Sat, 9 Jan 2021 23:25:04 +0000 Subject: [PATCH 08/50] Fix handling of params in variant overrides bulk update actions --- app/controllers/admin/variant_overrides_controller.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/controllers/admin/variant_overrides_controller.rb b/app/controllers/admin/variant_overrides_controller.rb index ba591bd967b..284f581b5b4 100644 --- a/app/controllers/admin/variant_overrides_controller.rb +++ b/app/controllers/admin/variant_overrides_controller.rb @@ -103,13 +103,13 @@ def collection_errors end def variant_overrides_params - params.require(:variant_overrides).map do |variant_override| - variant_override.permit( + params.permit( + variant_overrides: [ :id, :variant_id, :hub_id, :price, :count_on_hand, :sku, :on_demand, :default_stock, :resettable, :tag_list - ) - end + ] + ).to_h[:variant_overrides] end end end From dcf982c1c3b5896c6f0e477bd23859b4a3c9d4f3 Mon Sep 17 00:00:00 2001 From: Matt-Yorkley <9029026+Matt-Yorkley@users.noreply.github.com> Date: Sun, 10 Jan 2021 00:51:16 +0000 Subject: [PATCH 09/50] Fix params mangling issues in SubscriptionsController --- app/controllers/admin/subscriptions_controller.rb | 9 ++++----- .../app/services/order_management/subscriptions/form.rb | 6 ++++-- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/app/controllers/admin/subscriptions_controller.rb b/app/controllers/admin/subscriptions_controller.rb index adfb0404bdd..298d74b8762 100644 --- a/app/controllers/admin/subscriptions_controller.rb +++ b/app/controllers/admin/subscriptions_controller.rb @@ -57,14 +57,13 @@ def pause end def unpause - params[:subscription][:paused_at] = nil - save_form_and_render + save_form_and_render(true, unpause: true) end private - def save_form_and_render(render_issues = true) - form = OrderManagement::Subscriptions::Form.new(@subscription, subscription_params) + def save_form_and_render(render_issues = true, options = {}) + form = OrderManagement::Subscriptions::Form.new(@subscription, subscription_params, options) unless form.save render json: { errors: form.json_errors }, status: :unprocessable_entity return @@ -156,7 +155,7 @@ def ams_prefix_whitelist end def subscription_params - PermittedAttributes::Subscription.new(params).call + @subscription_params ||= PermittedAttributes::Subscription.new(params).call end end end diff --git a/engines/order_management/app/services/order_management/subscriptions/form.rb b/engines/order_management/app/services/order_management/subscriptions/form.rb index 2e354835be9..8ea469d8b36 100644 --- a/engines/order_management/app/services/order_management/subscriptions/form.rb +++ b/engines/order_management/app/services/order_management/subscriptions/form.rb @@ -11,19 +11,21 @@ class Form delegate :json_errors, :valid?, to: :validator delegate :order_update_issues, to: :order_syncer - def initialize(subscription, subscription_params = {}) + def initialize(subscription, subscription_params = {}, options = {}) @subscription = subscription @subscription_params = subscription_params + @options = options @estimator = OrderManagement::Subscriptions::Estimator.new(subscription) @validator = OrderManagement::Subscriptions::Validator.new(subscription) @order_syncer = OrderSyncer.new(subscription) end def save - subscription.assign_attributes(subscription_params) + subscription.assign_attributes(subscription_params.to_h) return false unless valid? subscription.transaction do + subscription.paused_at = nil if @options[:unpause] estimator.estimate! proxy_order_syncer.sync! order_syncer.sync! From 5e3d646f8c10488f077a5d81ee652f28a51ff06a Mon Sep 17 00:00:00 2001 From: Matt-Yorkley <9029026+Matt-Yorkley@users.noreply.github.com> Date: Sun, 10 Jan 2021 11:05:27 +0000 Subject: [PATCH 10/50] Fix params access in reports views --- app/helpers/application_helper.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index c23fc9fab29..d41d47bbb8e 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -1,4 +1,6 @@ module ApplicationHelper + include RawParams + def feature?(feature, user = nil) OpenFoodNetwork::FeatureToggle.enabled?(feature, user) end From ff722e69696863b265c06361858019a995eda747 Mon Sep 17 00:00:00 2001 From: Matt-Yorkley <9029026+Matt-Yorkley@users.noreply.github.com> Date: Sun, 10 Jan 2021 17:18:52 +0000 Subject: [PATCH 11/50] Fix cookie issues in i18n helper spec --- spec/helpers/i18n_helper_spec.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/spec/helpers/i18n_helper_spec.rb b/spec/helpers/i18n_helper_spec.rb index f12f0032d0a..c91b22f6afe 100644 --- a/spec/helpers/i18n_helper_spec.rb +++ b/spec/helpers/i18n_helper_spec.rb @@ -4,6 +4,11 @@ describe I18nHelper, type: :helper do let(:user) { create(:user) } + let(:cookies) { {} } + + before do + allow(helper).to receive(:cookies) { cookies } + end # In the real world, the helper is called in every request and sets # I18n.locale to the chosen locale or the default. For testing purposes we @@ -134,7 +139,7 @@ it "remembers the chosen locale on another computer" do allow(helper).to receive(:params) { { locale: "es" } } helper.set_locale - expect(cookies[:locale]).to eq "es" + expect(cookies.fetch(:locale)).to eq "es" # switch computer / browser or loose cookies cookies.delete :locale From fd1b14ca4a584c8025e454834b15f39dfb7fe3bd Mon Sep 17 00:00:00 2001 From: Matt-Yorkley <9029026+Matt-Yorkley@users.noreply.github.com> Date: Sun, 10 Jan 2021 18:56:43 +0000 Subject: [PATCH 12/50] Fix string/integer issues in states controller spec --- spec/controllers/api/states_controller_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/controllers/api/states_controller_spec.rb b/spec/controllers/api/states_controller_spec.rb index 81313c3153a..548fcb0ad1a 100644 --- a/spec/controllers/api/states_controller_spec.rb +++ b/spec/controllers/api/states_controller_spec.rb @@ -33,14 +33,14 @@ module Api end it "paginates when page parameter is passed through" do - expect(@scope).to receive(:page).with(1).and_return(@scope) + expect(@scope).to receive(:page).with("1").and_return(@scope) expect(@scope).to receive(:per).with(nil) api_get :index, page: 1 end it "paginates when per_page parameter is passed through" do expect(@scope).to receive(:page).with(nil).and_return(@scope) - expect(@scope).to receive(:per).with(25) + expect(@scope).to receive(:per).with("25") api_get :index, per_page: 25 end end From f28cd4a4e5c6b03e370c5608fc506e3235606359 Mon Sep 17 00:00:00 2001 From: Matt-Yorkley <9029026+Matt-Yorkley@users.noreply.github.com> Date: Sun, 10 Jan 2021 21:02:25 +0000 Subject: [PATCH 13/50] Adapt checkout FormDataAdapter --- app/controllers/checkout_controller.rb | 2 +- app/services/checkout/form_data_adapter.rb | 20 ++++++++++---------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/app/controllers/checkout_controller.rb b/app/controllers/checkout_controller.rb index 4e3a22415ba..4022925385d 100644 --- a/app/controllers/checkout_controller.rb +++ b/app/controllers/checkout_controller.rb @@ -46,7 +46,7 @@ def edit def update params_adapter = Checkout::FormDataAdapter.new(permitted_params, @order, spree_current_user) - return action_failed unless @order.update(params_adapter.params[:order]) + return action_failed unless @order.update(params_adapter.params[:order] || {}) checkout_workflow(params_adapter.shipping_method_id) rescue Spree::Core::GatewayError => e diff --git a/app/services/checkout/form_data_adapter.rb b/app/services/checkout/form_data_adapter.rb index 851f52e919d..f5550126d1a 100644 --- a/app/services/checkout/form_data_adapter.rb +++ b/app/services/checkout/form_data_adapter.rb @@ -6,7 +6,7 @@ class FormDataAdapter attr_reader :params, :shipping_method_id def initialize(params, order, current_user) - @params = params.dup + @params = params.deep_dup.to_h.with_indifferent_access @order = order @current_user = current_user @@ -16,9 +16,9 @@ def initialize(params, order, current_user) set_amount_in_payments_attributes - construct_saved_card_attributes if @params[:order][:existing_card_id] + construct_saved_card_attributes if @params.dig(:order, :existing_card_id) - @shipping_method_id = @params[:order].delete(:shipping_method_id) + @shipping_method_id = @params[:order]&.delete(:shipping_method_id) end private @@ -30,7 +30,7 @@ def move_payment_source_to_payment_attributes! return unless @params[:payment_source].present? && payment_source_params = delete_payment_source_params! - @params[:order][:payments_attributes].first[:source_attributes] = payment_source_params + @params.dig(:order, :payments_attributes).first[:source_attributes] = payment_source_params end # Ensures cc_type is always passed to the model by inferring the type when @@ -45,7 +45,7 @@ def fill_in_card_type def payment_source_attributes @payment_source_attributes ||= - params[:order][:payments_attributes]&.first&.dig(:source_attributes) + @params.dig(:order, :payments_attributes)&.first&.dig(:source_attributes) end def card_brand(number) @@ -54,14 +54,14 @@ def card_brand(number) def delete_payment_source_params! @params.delete(:payment_source)[ - @params[:order][:payments_attributes].first[:payment_method_id].underscore + @params.dig(:order, :payments_attributes).first[:payment_method_id].underscore ] end def set_amount_in_payments_attributes - return unless @params[:order][:payments_attributes] + return unless @params.dig(:order, :payments_attributes) - @params[:order][:payments_attributes].first[:amount] = @order.total + @params.dig(:order, :payments_attributes).first[:amount] = @order.total end def construct_saved_card_attributes @@ -70,7 +70,7 @@ def construct_saved_card_attributes add_to_payment_attributes(existing_card_id) - @params[:order][:payments_attributes].first.delete :source_attributes + @params.dig(:order, :payments_attributes).first.delete :source_attributes end def add_to_payment_attributes(existing_card_id) @@ -79,7 +79,7 @@ def add_to_payment_attributes(existing_card_id) raise Spree::Core::GatewayError, I18n.t(:invalid_credit_card) end - @params[:order][:payments_attributes].first[:source] = credit_card + @params.dig(:order, :payments_attributes).first[:source] = credit_card end end end From 304da48d50cbcb848042afd420576d5935eabc76 Mon Sep 17 00:00:00 2001 From: Matt-Yorkley <9029026+Matt-Yorkley@users.noreply.github.com> Date: Sat, 23 Jan 2021 08:57:53 +0000 Subject: [PATCH 14/50] Remove dual boot --- Gemfile | 42 +- Gemfile.lock | 397 +++------- Gemfile_next.lock | 680 ------------------ ...ction_dispatch_request_deep_munge_patch.rb | 1 - config/initializers/db2fog.rb | 17 - config/initializers/js_template_helpers.rb | 12 +- lib/action_dispatch/request.rb | 69 -- 7 files changed, 125 insertions(+), 1093 deletions(-) delete mode 100644 Gemfile_next.lock delete mode 100644 config/initializers/action_dispatch_request_deep_munge_patch.rb delete mode 100644 config/initializers/db2fog.rb delete mode 100644 lib/action_dispatch/request.rb diff --git a/Gemfile b/Gemfile index 02f70db2c3b..bbac8c37727 100644 --- a/Gemfile +++ b/Gemfile @@ -4,38 +4,15 @@ source 'https://rubygems.org' ruby "2.4.4" git_source(:github) { |repo_name| "https://github.com/#{repo_name}.git" } -plugin 'bootboot', '~> 0.1.1' unless Bundler.settings[:frozen] -Plugin.__send__(:load_plugin, 'bootboot') if Plugin.installed?('bootboot') +gem 'rails', '> 5.0', '< 5.1' -if ENV['DEPENDENCIES_NEXT'] - enable_dual_booting if Plugin.installed?('bootboot') - - # This will only be loaded when running - # bundler command prefixed with `DEPENDENCIES_NEXT=1 - gem 'rails', '> 5.0', '< 5.1' - - gem 'activemerchant', '>= 1.78.0' - gem 'angular-rails-templates', '>= 0.3.0', '< 1.1.0' - gem 'awesome_nested_set' - gem 'rails-controller-testing' - gem 'ransack', '2.3.0' - gem 'responders' -else - gem 'rails', '~> 4.2' - - gem 'activemerchant', '~> 1.78.0' - gem 'angular-rails-templates', '~> 0.3.0' - gem 'awesome_nested_set', '~> 3.4.0' - gem 'ransack', '~> 1.8.10' - gem 'responders', '~> 2.0' - - gem 'db2fog' - gem 'unicorn' - - group :test do - gem 'test_after_commit' # needed to test Devise callbacks - end -end +gem 'activemerchant', '>= 1.78.0' +gem 'angular-rails-templates', '>= 0.3.0' +gem 'awesome_nested_set' +gem 'ransack', '2.3.0' +gem 'responders' +gem 'sass', '<= 4.7.1' +gem 'sass-rails', '< 6.0.0' gem 'i18n' gem 'i18n-js', '~> 3.8.1' @@ -116,15 +93,12 @@ gem 'test-unit', '~> 3.4' gem 'coffee-rails', '~> 4.2.2' gem 'compass-rails' -gem 'libv8', '< 8' gem 'mini_racer', '0.2.15' gem 'uglifier', '>= 1.0.3' gem 'angular_rails_csrf' gem 'foundation-icons-sass-rails' -gem 'sass', '<= 4.7.1' -gem 'sass-rails', '< 6.0.0' gem 'foundation-rails', '= 5.5.2.1' diff --git a/Gemfile.lock b/Gemfile.lock index 87b227d2983..25b34d8cba0 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -37,46 +37,48 @@ PATH GEM remote: https://rubygems.org/ specs: - CFPropertyList (2.3.6) - actionmailer (4.2.11.3) - actionpack (= 4.2.11.3) - actionview (= 4.2.11.3) - activejob (= 4.2.11.3) + 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) mail (~> 2.5, >= 2.5.4) - rails-dom-testing (~> 1.0, >= 1.0.5) - actionpack (4.2.11.3) - actionview (= 4.2.11.3) - activesupport (= 4.2.11.3) - rack (~> 1.6) - rack-test (~> 0.6.2) - rails-dom-testing (~> 1.0, >= 1.0.5) + 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) + rails-dom-testing (~> 2.0) rails-html-sanitizer (~> 1.0, >= 1.0.2) actionpack-action_caching (1.2.1) actionpack (>= 4.0.0) - actionview (4.2.11.3) - activesupport (= 4.2.11.3) + actionview (5.0.7.2) + activesupport (= 5.0.7.2) builder (~> 3.1) erubis (~> 2.7.0) - rails-dom-testing (~> 1.0, >= 1.0.5) + rails-dom-testing (~> 2.0) rails-html-sanitizer (~> 1.0, >= 1.0.3) active_model_serializers (0.8.4) activemodel (>= 3.0) - activejob (4.2.11.3) - activesupport (= 4.2.11.3) - globalid (>= 0.3.0) - activemerchant (1.78.0) - activesupport (>= 3.2.14, < 6.x) + activejob (5.0.7.2) + activesupport (= 5.0.7.2) + globalid (>= 0.3.6) + activemerchant (1.107.4) + activesupport (>= 4.2) builder (>= 2.1.2, < 4.0.0) i18n (>= 0.6.9) nokogiri (~> 1.4) - activemodel (4.2.11.3) - activesupport (= 4.2.11.3) - builder (~> 3.1) - activerecord (4.2.11.3) - activemodel (= 4.2.11.3) - activesupport (= 4.2.11.3) - arel (~> 6.0) - activerecord-import (1.0.8) + 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) + activerecord-import (1.0.7) activerecord (>= 3.2) activerecord-postgresql-adapter (0.0.1) pg @@ -86,10 +88,10 @@ GEM multi_json (~> 1.11, >= 1.11.2) rack (>= 1.5.2, < 3) railties (>= 4.0) - activesupport (4.2.11.3) - i18n (~> 0.7) + activesupport (5.0.7.2) + concurrent-ruby (~> 1.0, >= 1.0.2) + i18n (>= 0.7, < 2) minitest (~> 5.1) - thread_safe (~> 0.3, >= 0.3.4) tzinfo (~> 1.1) acts-as-taggable-on (4.0.0) activerecord (>= 4.0) @@ -97,19 +99,16 @@ GEM activerecord (>= 3.0) addressable (2.7.0) public_suffix (>= 2.0.2, < 5.0) - aliyun-sdk (0.8.0) - nokogiri (~> 1.6) - rest-client (~> 2.0) andand (1.3.3) - angular-rails-templates (0.3.0) - railties (>= 3.1) - sprockets (~> 2.0) + angular-rails-templates (1.1.0) + railties (>= 4.2, < 7) + sprockets (>= 3.0, < 5) tilt angular_rails_csrf (4.2.0) railties (>= 3, < 7) angularjs-file-upload-rails (2.4.1) angularjs-rails (1.5.5) - arel (6.0.4) + arel (7.1.4) ast (2.4.2) atomic (1.1.101) awesome_nested_set (3.4.0) @@ -165,10 +164,8 @@ GEM sass (>= 3.3.0, < 3.5) compass-import-once (1.0.5) sass (>= 3.2, < 3.5) - compass-rails (4.0.0) + compass-rails (2.0.1) compass (~> 1.0.0) - sass-rails (< 5.1) - sprockets (< 4.0) concurrent-ruby (1.1.8) crack (0.4.5) rexml @@ -178,10 +175,6 @@ GEM daemons (1.3.1) dalli (2.7.11) database_cleaner (1.99.0) - db2fog (0.9.0) - activerecord (>= 3.2.0, < 5.0) - fog (~> 1.0) - rails (>= 3.2.0, < 5.0) ddtrace (0.46.0) msgpack debugger-linecache (1.2.0) @@ -207,12 +200,8 @@ GEM devise (>= 4.0.0, < 5.0.0) diff-lcs (1.4.4) docile (1.3.4) - domain_name (0.5.20190701) - unf (>= 0.0.5, < 1.0.0) - dry-inflector (0.1.2) erubis (2.7.0) eventmachine (1.2.7) - excon (0.78.0) execjs (2.7.0) factory_bot (5.2.0) activesupport (>= 4.2.0) @@ -225,157 +214,6 @@ GEM ffi (1.13.1) figaro (1.2.0) thor (>= 0.14.0, < 2) - fission (0.5.0) - CFPropertyList (~> 2.2) - fog (1.41.0) - fog-aliyun (>= 0.1.0) - fog-atmos - fog-aws (>= 0.6.0) - fog-brightbox (~> 0.4) - fog-cloudatcost (~> 0.1.0) - fog-core (~> 1.45) - fog-digitalocean (>= 0.3.0) - fog-dnsimple (~> 1.0) - fog-dynect (~> 0.0.2) - fog-ecloud (~> 0.1) - fog-google (<= 0.1.0) - fog-internet-archive - fog-joyent - fog-json - fog-local - fog-openstack - fog-powerdns (>= 0.1.1) - fog-profitbricks - fog-rackspace - fog-radosgw (>= 0.0.2) - fog-riakcs - fog-sakuracloud (>= 0.0.4) - fog-serverlove - fog-softlayer - fog-storm_on_demand - fog-terremark - fog-vmfusion - fog-voxel - fog-vsphere (>= 0.4.0) - fog-xenserver - fog-xml (~> 0.1.1) - ipaddress (~> 0.5) - json (>= 1.8, < 2.0) - fog-aliyun (0.3.19) - aliyun-sdk (~> 0.8.0) - fog-core - fog-json - ipaddress (~> 0.8) - xml-simple (~> 1.1) - fog-atmos (0.1.0) - fog-core - fog-xml - fog-aws (2.0.1) - fog-core (~> 1.38) - fog-json (~> 1.0) - fog-xml (~> 0.1) - ipaddress (~> 0.8) - fog-brightbox (0.16.1) - dry-inflector - fog-core - fog-json - mime-types - fog-cloudatcost (0.1.2) - fog-core (~> 1.36) - fog-json (~> 1.0) - fog-xml (~> 0.1) - ipaddress (~> 0.8) - fog-core (1.45.0) - builder - excon (~> 0.58) - formatador (~> 0.2) - fog-digitalocean (0.4.0) - fog-core - fog-json - fog-xml - ipaddress (>= 0.5) - fog-dnsimple (1.0.0) - fog-core (~> 1.38) - fog-json (~> 1.0) - fog-dynect (0.0.3) - fog-core - fog-json - fog-xml - fog-ecloud (0.3.0) - fog-core - fog-xml - fog-google (0.1.0) - fog-core - fog-json - fog-xml - fog-internet-archive (0.0.2) - fog-core - fog-json - fog-xml - fog-joyent (0.0.1) - fog-core (~> 1.42) - fog-json (>= 1.0) - fog-json (1.2.0) - fog-core - multi_json (~> 1.10) - fog-local (0.6.0) - fog-core (>= 1.27, < 3.0) - fog-openstack (0.3.10) - fog-core (>= 1.45, <= 2.1.0) - fog-json (>= 1.0) - ipaddress (>= 0.8) - fog-powerdns (0.2.0) - fog-core - fog-json - fog-xml - fog-profitbricks (4.1.1) - fog-core (~> 1.42) - fog-json (~> 1.0) - fog-rackspace (0.1.6) - fog-core (>= 1.35) - fog-json (>= 1.0) - fog-xml (>= 0.1) - ipaddress (>= 0.8) - fog-radosgw (0.0.5) - fog-core (>= 1.21.0) - fog-json - fog-xml (>= 0.0.1) - fog-riakcs (0.1.0) - fog-core - fog-json - fog-xml - fog-sakuracloud (1.7.5) - fog-core - fog-json - fog-serverlove (0.1.2) - fog-core - fog-json - fog-softlayer (1.1.4) - fog-core - fog-json - fog-storm_on_demand (0.1.1) - fog-core - fog-json - fog-terremark (0.1.0) - fog-core - fog-xml - fog-vmfusion (0.1.0) - fission - fog-core - fog-voxel (0.1.0) - fog-core - fog-xml - fog-vsphere (3.4.0) - fog-core - rbvmomi (>= 1.9, < 3) - fog-xenserver (1.0.0) - fog-core - fog-xml - xmlrpc - fog-xml (0.1.3) - fog-core - nokogiri (>= 1.5.11, < 2.0.0) - formatador (0.2.5) foundation-icons-sass-rails (3.0.0) railties (>= 3.1.1) sass-rails (>= 3.1.1) @@ -394,22 +232,17 @@ GEM good_migrations (0.0.2) activerecord (>= 3.1) railties (>= 3.1) - haml (5.2.1) + haml (5.2.0) temple (>= 0.8.0) tilt hashdiff (1.0.1) highline (2.0.3) - hike (1.2.3) - http-accept (1.7.0) - http-cookie (1.0.3) - domain_name (~> 0.5) - i18n (0.9.5) + i18n (1.8.5) concurrent-ruby (~> 1.0) i18n-js (3.8.1) i18n (>= 0.6.6) immigrant (0.3.6) activerecord (>= 3.0) - ipaddress (0.8.3) jquery-migrate-rails (1.2.1) jquery-rails (4.4.0) rails-dom-testing (>= 1, < 3) @@ -443,7 +276,7 @@ GEM addressable (~> 2.3) letter_opener (1.7.0) launchy (~> 2.2) - libv8 (7.3.492.27.1) + libv8 (8.4.255.0) loofah (2.9.0) crass (~> 1.0.2) nokogiri (>= 1.5.9) @@ -452,7 +285,7 @@ GEM method_source (1.0.0) mime-types (3.3.1) mime-types-data (~> 3.2015) - mime-types-data (3.2020.0512) + mime-types-data (3.2020.1104) mini_mime (1.0.2) mini_portile2 (2.4.0) mini_racer (0.2.15) @@ -466,7 +299,9 @@ GEM multi_json (1.15.0) multi_xml (0.6.0) multipart-post (2.1.1) - netrc (0.11.0) + mustermann (1.1.1) + ruby2_keywords (~> 0.0.1) + nio4r (2.5.2) nokogiri (1.10.10) mini_portile2 (~> 2.4.0) oauth2 (1.4.4) @@ -475,7 +310,6 @@ GEM multi_json (~> 1.3) multi_xml (~> 0.5) rack (>= 1.2, < 3) - optimist (3.0.1) orm_adapter (0.5.0) paper_trail (10.3.1) activerecord (>= 4.2) @@ -497,6 +331,8 @@ GEM paypal-sdk-merchant (1.117.2) paypal-sdk-core (~> 0.3.0) pg (0.21.0) + polyamorous (2.3.0) + activerecord (>= 5.0) power_assert (2.0.0) pry (0.13.1) coderay (~> 1.1) @@ -505,60 +341,59 @@ GEM byebug (~> 11.0) pry (~> 0.13.0) public_suffix (4.0.6) - rack (1.6.13) + rack (2.2.3) rack-mini-profiler (2.3.1) rack (>= 1.2.0) - rack-protection (1.5.5) + rack-protection (2.1.0) rack rack-rewrite (1.5.1) rack-ssl (1.4.1) rack rack-test (0.6.3) rack (>= 1.0) - rails (4.2.11.3) - actionmailer (= 4.2.11.3) - actionpack (= 4.2.11.3) - actionview (= 4.2.11.3) - activejob (= 4.2.11.3) - activemodel (= 4.2.11.3) - activerecord (= 4.2.11.3) - activesupport (= 4.2.11.3) - bundler (>= 1.3.0, < 2.0) - railties (= 4.2.11.3) - sprockets-rails - rails-deprecated_sanitizer (1.0.4) - activesupport (>= 4.2.0.alpha) - rails-dom-testing (1.0.9) - activesupport (>= 4.2.0, < 5.0) - nokogiri (~> 1.6) - rails-deprecated_sanitizer (>= 1.0.1) + 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) + bundler (>= 1.3.0) + railties (= 5.0.7.2) + sprockets-rails (>= 2.0.0) + rails-controller-testing (1.0.5) + actionpack (>= 5.0.1.rc1) + actionview (>= 5.0.1.rc1) + activesupport (>= 5.0.1.rc1) + rails-dom-testing (2.0.3) + activesupport (>= 4.2.0) + nokogiri (>= 1.6) rails-html-sanitizer (1.3.0) loofah (~> 2.3) - rails-i18n (4.0.9) - i18n (~> 0.7) - railties (~> 4.0) + rails-i18n (5.1.3) + i18n (>= 0.7, < 2) + railties (>= 5.0, < 6) rails_safe_tasks (1.0.0) - railties (4.2.11.3) - actionpack (= 4.2.11.3) - activesupport (= 4.2.11.3) + railties (5.0.7.2) + actionpack (= 5.0.7.2) + activesupport (= 5.0.7.2) + method_source rake (>= 0.8.7) thor (>= 0.18.1, < 2.0) rainbow (3.0.0) raindrops (0.19.1) rake (13.0.3) - ransack (1.8.10) - actionpack (>= 3.0, < 5.2) - activerecord (>= 3.0, < 5.2) - activesupport (>= 3.0, < 5.2) + ransack (2.3.0) + actionpack (>= 5.0) + activerecord (>= 5.0) + activesupport (>= 5.0) i18n + polyamorous (= 2.3.0) rb-fsevent (0.10.4) rb-inotify (0.10.1) ffi (~> 1.0) - rbvmomi (2.4.1) - builder (~> 3.0) - json (>= 1.8) - nokogiri (~> 1.5) - optimist (~> 3.0) redcarpet (3.5.1) regexp_parser (1.8.2) request_store (1.5.0) @@ -566,11 +401,6 @@ GEM responders (2.4.1) actionpack (>= 4.2.0, < 6.0) railties (>= 4.2.0, < 6.0) - rest-client (2.1.0) - http-accept (>= 1.7.0, < 2.0) - http-cookie (>= 1.0.2, < 2.0) - mime-types (>= 1.16, < 4.0) - netrc (~> 0.8) rexml (3.2.4) roadie (3.5.1) css_parser (~> 1.4) @@ -634,6 +464,7 @@ GEM rubocop (>= 0.90.0, < 2.0) ruby-progressbar (1.11.0) ruby-rc4 (0.1.5) + ruby2_keywords (0.0.2) rubyzip (2.3.0) sass (3.4.25) sass-rails (5.0.7) @@ -650,26 +481,26 @@ GEM rubyzip (>= 1.2.2) shoulda-matchers (4.5.1) activesupport (>= 4.2.0) - simplecov (0.18.5) + simplecov (0.17.1) docile (~> 1.1) - simplecov-html (~> 0.11) - simplecov-html (0.12.3) - sinatra (1.4.8) - rack (~> 1.5) - rack-protection (~> 1.4) - tilt (>= 1.3, < 3) + json (>= 1.8, < 3) + simplecov-html (~> 0.10.0) + simplecov-html (0.10.2) + sinatra (2.1.0) + mustermann (~> 1.0) + rack (~> 2.2) + rack-protection (= 2.1.0) + tilt (~> 2.0) spring (2.1.1) spring-commands-rspec (1.0.4) spring (>= 0.9.1) - sprockets (2.12.5) - hike (~> 1.2) - multi_json (~> 1.0) - rack (~> 1.0) - tilt (~> 1.1, != 1.3.0) - sprockets-rails (2.3.3) - actionpack (>= 3.0) - activesupport (>= 3.0) - sprockets (>= 2.8, < 4.0) + sprockets (3.7.2) + concurrent-ruby (~> 1.0) + rack (> 1, < 3) + sprockets-rails (3.2.2) + actionpack (>= 4.0) + activesupport (>= 4.0) + sprockets (>= 3.0.0) state_machines (0.5.0) state_machines-activemodel (0.7.1) activemodel (>= 4.1) @@ -683,19 +514,14 @@ GEM test-prof (0.11.3) test-unit (3.4.0) power_assert - test_after_commit (1.2.2) - activerecord (>= 3.2, < 5.0) thor (0.20.3) thread_safe (0.3.6) - tilt (1.4.1) + tilt (2.0.10) timecop (0.9.4) tzinfo (1.2.9) thread_safe (~> 0.1) uglifier (4.2.0) execjs (>= 0.3.0, < 3) - unf (0.1.4) - unf_ext - unf_ext (0.0.7.7) unicode-display_width (2.0.0) unicorn (5.8.0) kgio (~> 2.6) @@ -707,8 +533,8 @@ GEM get_process_mem (~> 0) unicorn (>= 4, < 6) uniform_notifier (1.14.1) - warden (1.2.7) - rack (>= 1.0) + warden (1.2.9) + rack (>= 2.0.9) webdrivers (4.6.0) nokogiri (~> 1.6) rubyzip (>= 1.3.0) @@ -717,13 +543,15 @@ GEM addressable (>= 2.3.6) crack (>= 0.3.2) hashdiff (>= 0.4.0, < 2.0.0) + websocket-driver (0.6.5) + websocket-extensions (>= 0.1.0) + websocket-extensions (0.1.5) whenever (1.0.0) chronic (>= 0.6.3) wicked_pdf (2.1.0) activesupport - wkhtmltopdf-binary (0.12.5) + wkhtmltopdf-binary (0.12.6.5) xml-simple (1.1.8) - xmlrpc (0.3.0) xpath (3.2.0) nokogiri (~> 1.8) @@ -733,19 +561,19 @@ PLATFORMS DEPENDENCIES actionpack-action_caching active_model_serializers (= 0.8.4) - activemerchant (~> 1.78.0) + activemerchant (>= 1.78.0) activerecord-import activerecord-postgresql-adapter activerecord-session_store acts-as-taggable-on (~> 4.0) acts_as_list (= 0.9.19) andand - angular-rails-templates (~> 0.3.0) + angular-rails-templates (>= 0.3.0) angular_rails_csrf angularjs-file-upload-rails (~> 2.4.1) angularjs-rails (= 1.5.5) atomic - awesome_nested_set (~> 3.4.0) + awesome_nested_set awesome_print aws-sdk (= 1.67.0) bugsnag @@ -761,7 +589,6 @@ DEPENDENCIES daemons dalli database_cleaner - db2fog ddtrace debugger-linecache delayed_job_active_record @@ -794,7 +621,6 @@ DEPENDENCIES kaminari (~> 1.2.1) knapsack letter_opener (>= 1.4.1) - libv8 (< 8) mini_racer (= 0.2.15) monetize (~> 1.10) oauth2 (~> 1.4.4) @@ -810,12 +636,13 @@ DEPENDENCIES rack-mini-profiler (< 3.0.0) rack-rewrite rack-ssl - rails (~> 4.2) + rails (> 5.0, < 5.1) + rails-controller-testing rails-i18n rails_safe_tasks (~> 1.0) - ransack (~> 1.8.10) + ransack (= 2.3.0) redcarpet - responders (~> 2.0) + responders roadie-rails (~> 1.3.0) roo (~> 2.8.3) rspec-rails (>= 3.5.2) @@ -836,10 +663,8 @@ DEPENDENCIES stripe test-prof test-unit (~> 3.4) - test_after_commit timecop uglifier (>= 1.0.3) - unicorn unicorn-rails unicorn-worker-killer web! diff --git a/Gemfile_next.lock b/Gemfile_next.lock deleted file mode 100644 index 89d0c97464a..00000000000 --- a/Gemfile_next.lock +++ /dev/null @@ -1,680 +0,0 @@ -GIT - remote: https://github.com/jeremydurham/custom-err-msg.git - revision: 3a8ec9dddc7a5b0aab7c69a6060596de300c68f4 - specs: - custom_error_message (1.1.1) - -GIT - remote: https://github.com/openfoodfoundation/ofn-qz.git - revision: 467f6ea1c44529c7c91cac4c8211bbd863588c0b - branch: ofn-rails-4 - specs: - ofn-qz (0.1.0) - -PATH - remote: engines/catalog - specs: - catalog (0.0.1) - -PATH - remote: engines/dfc_provider - specs: - dfc_provider (0.0.1) - active_model_serializers (~> 0.8.4) - jwt (~> 2.2) - rspec (~> 3.9) - -PATH - remote: engines/order_management - specs: - order_management (0.0.1) - -PATH - remote: engines/web - specs: - web (0.0.1) - -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) - 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) - 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) - builder (~> 3.1) - erubis (~> 2.7.0) - 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) - globalid (>= 0.3.6) - activemerchant (1.107.4) - 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) - activerecord-import (1.0.7) - activerecord (>= 3.2) - activerecord-postgresql-adapter (0.0.1) - pg - activerecord-session_store (1.1.3) - actionpack (>= 4.0) - activerecord (>= 4.0) - multi_json (~> 1.11, >= 1.11.2) - rack (>= 1.5.2, < 3) - railties (>= 4.0) - activesupport (5.0.7.2) - concurrent-ruby (~> 1.0, >= 1.0.2) - i18n (>= 0.7, < 2) - minitest (~> 5.1) - tzinfo (~> 1.1) - acts-as-taggable-on (4.0.0) - activerecord (>= 4.0) - acts_as_list (0.9.19) - activerecord (>= 3.0) - addressable (2.7.0) - public_suffix (>= 2.0.2, < 5.0) - andand (1.3.3) - angular-rails-templates (1.0.2) - railties (>= 4.2, < 6) - sprockets (>= 3.0, < 5) - tilt - angular_rails_csrf (4.2.0) - railties (>= 3, < 7) - angularjs-file-upload-rails (2.4.1) - angularjs-rails (1.5.5) - arel (7.1.4) - ast (2.4.1) - atomic (1.1.101) - awesome_nested_set (3.2.1) - activerecord (>= 4.0.0, < 7.0) - awesome_print (1.8.0) - aws-sdk (1.67.0) - aws-sdk-v1 (= 1.67.0) - aws-sdk-v1 (1.67.0) - json (~> 1.4) - nokogiri (~> 1) - bcrypt (3.1.16) - bugsnag (6.18.0) - concurrent-ruby (~> 1.0) - builder (3.2.4) - bullet (6.1.4) - activesupport (>= 3.0.0) - uniform_notifier (~> 1.11) - byebug (11.0.1) - cancancan (1.7.1) - capybara (3.15.0) - addressable - mini_mime (>= 0.1.3) - nokogiri (~> 1.8) - rack (>= 1.6.0) - rack-test (>= 0.6.3) - regexp_parser (~> 1.2) - xpath (~> 3.2) - childprocess (3.0.0) - chronic (0.10.2) - chunky_png (1.3.14) - climate_control (0.2.0) - cocaine (0.5.8) - climate_control (>= 0.0.3, < 1.0) - coderay (1.1.3) - coffee-rails (4.2.2) - coffee-script (>= 2.2.0) - railties (>= 4.0.0) - coffee-script (2.4.1) - coffee-script-source - execjs - coffee-script-source (1.12.2) - combine_pdf (1.0.19) - ruby-rc4 (>= 0.1.5) - compass (1.0.3) - chunky_png (~> 1.2) - compass-core (~> 1.0.2) - compass-import-once (~> 1.0.5) - rb-fsevent (>= 0.9.3) - rb-inotify (>= 0.9) - sass (>= 3.3.13, < 3.5) - compass-core (1.0.3) - multi_json (~> 1.0) - sass (>= 3.3.0, < 3.5) - compass-import-once (1.0.5) - sass (>= 3.2, < 3.5) - compass-rails (2.0.1) - compass (~> 1.0.0) - concurrent-ruby (1.1.8) - crack (0.4.4) - crass (1.0.6) - css_parser (1.7.1) - addressable - daemons (1.3.1) - dalli (2.7.11) - database_cleaner (1.8.5) - ddtrace (0.43.0) - msgpack - debugger-linecache (1.2.0) - delayed_job (4.1.8) - activesupport (>= 3.0, < 6.1) - delayed_job_active_record (4.1.4) - activerecord (>= 3.0, < 6.1) - delayed_job (>= 3.0, < 5) - delayed_job_web (1.4.3) - activerecord (> 3.0.0) - delayed_job (> 2.0.3) - rack-protection (>= 1.5.5) - sinatra (>= 1.4.4) - devise (4.7.3) - bcrypt (~> 3.0) - orm_adapter (~> 0.1) - railties (>= 4.1.0) - responders - warden (~> 1.2.3) - devise-encryptable (0.2.0) - devise (>= 2.1.0) - devise-token_authenticatable (1.1.0) - devise (>= 4.0.0, < 5.0.0) - diff-lcs (1.4.4) - docile (1.3.2) - erubis (2.7.0) - eventmachine (1.2.7) - execjs (2.7.0) - factory_bot (5.2.0) - activesupport (>= 4.2.0) - factory_bot_rails (5.2.0) - factory_bot (~> 5.2.0) - railties (>= 4.2.0) - faraday (1.0.1) - multipart-post (>= 1.2, < 3) - ffaker (2.11.0) - ffi (1.13.1) - figaro (1.2.0) - thor (>= 0.14.0, < 2) - foundation-icons-sass-rails (3.0.0) - railties (>= 3.1.1) - sass-rails (>= 3.1.1) - foundation-rails (5.5.2.1) - railties (>= 3.1.0) - sass (>= 3.3.0, < 3.5) - fuubar (2.5.1) - rspec-core (~> 3.0) - ruby-progressbar (~> 1.4) - geocoder (1.6.4) - get_process_mem (0.2.7) - ffi (~> 1.0) - globalid (0.4.2) - activesupport (>= 4.2.0) - gmaps4rails (2.1.2) - good_migrations (0.0.2) - activerecord (>= 3.1) - railties (>= 3.1) - haml (5.2.0) - temple (>= 0.8.0) - tilt - hashdiff (1.0.1) - highline (2.0.3) - i18n (1.8.7) - concurrent-ruby (~> 1.0) - i18n-js (3.8.0) - i18n (>= 0.6.6) - immigrant (0.3.6) - activerecord (>= 3.0) - jaro_winkler (1.5.4) - jquery-migrate-rails (1.2.1) - jquery-rails (4.4.0) - rails-dom-testing (>= 1, < 3) - railties (>= 4.2.0) - thor (>= 0.14, < 2.0) - jquery-ui-rails (4.2.1) - railties (>= 3.2.16) - json (1.8.6) - json-schema (2.8.1) - addressable (>= 2.4) - json_spec (1.1.5) - multi_json (~> 1.0) - rspec (>= 2.0, < 4.0) - jwt (2.2.2) - kaminari (1.2.1) - activesupport (>= 4.1.0) - kaminari-actionview (= 1.2.1) - kaminari-activerecord (= 1.2.1) - kaminari-core (= 1.2.1) - kaminari-actionview (1.2.1) - actionview - kaminari-core (= 1.2.1) - kaminari-activerecord (1.2.1) - activerecord - kaminari-core (= 1.2.1) - kaminari-core (1.2.1) - kgio (2.11.3) - knapsack (1.20.0) - rake - launchy (2.4.3) - addressable (~> 2.3) - letter_opener (1.7.0) - launchy (~> 2.2) - libv8 (7.3.492.27.1) - loofah (2.9.0) - crass (~> 1.0.2) - nokogiri (>= 1.5.9) - mail (2.7.1) - mini_mime (>= 0.1.1) - method_source (1.0.0) - mime-types (3.3.1) - mime-types-data (~> 3.2015) - mime-types-data (3.2020.1104) - mini_mime (1.0.2) - mini_portile2 (2.4.0) - mini_racer (0.2.15) - libv8 (> 7.3) - minitest (5.14.3) - monetize (1.10.0) - money (~> 6.12) - money (6.14.0) - i18n (>= 0.6.4, <= 2) - msgpack (1.3.3) - multi_json (1.15.0) - multi_xml (0.6.0) - multipart-post (2.1.1) - mustermann (1.1.1) - ruby2_keywords (~> 0.0.1) - nio4r (2.5.2) - nokogiri (1.10.10) - mini_portile2 (~> 2.4.0) - oauth2 (1.4.4) - faraday (>= 0.8, < 2.0) - jwt (>= 1.0, < 3.0) - multi_json (~> 1.3) - multi_xml (~> 0.5) - rack (>= 1.2, < 3) - orm_adapter (0.5.0) - paper_trail (10.3.1) - activerecord (>= 4.2) - request_store (~> 1.1) - paperclip (3.4.2) - activemodel (>= 3.0.0) - activerecord (>= 3.0.0) - activesupport (>= 3.0.0) - cocaine (~> 0.5.0) - mime-types - parallel (1.19.2) - paranoia (2.4.2) - activerecord (>= 4.0, < 6.1) - parser (2.7.2.0) - ast (~> 2.4.1) - paypal-sdk-core (0.3.4) - multi_json (~> 1.0) - xml-simple - paypal-sdk-merchant (1.117.2) - paypal-sdk-core (~> 0.3.0) - pg (0.21.0) - polyamorous (2.3.0) - activerecord (>= 5.0) - power_assert (1.2.0) - pry (0.13.1) - coderay (~> 1.1) - method_source (~> 1.0) - pry-byebug (3.9.0) - byebug (~> 11.0) - pry (~> 0.13.0) - public_suffix (4.0.6) - rack (2.2.3) - rack-mini-profiler (2.0.2) - rack (>= 1.2.0) - rack-protection (2.1.0) - rack - 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) - bundler (>= 1.3.0) - railties (= 5.0.7.2) - sprockets-rails (>= 2.0.0) - rails-controller-testing (1.0.5) - actionpack (>= 5.0.1.rc1) - actionview (>= 5.0.1.rc1) - activesupport (>= 5.0.1.rc1) - rails-dom-testing (2.0.3) - activesupport (>= 4.2.0) - nokogiri (>= 1.6) - rails-html-sanitizer (1.3.0) - loofah (~> 2.3) - rails-i18n (5.1.3) - 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) - method_source - rake (>= 0.8.7) - thor (>= 0.18.1, < 2.0) - rainbow (3.0.0) - raindrops (0.19.1) - rake (13.0.3) - ransack (2.3.0) - actionpack (>= 5.0) - activerecord (>= 5.0) - activesupport (>= 5.0) - i18n - polyamorous (= 2.3.0) - rb-fsevent (0.10.4) - rb-inotify (0.10.1) - ffi (~> 1.0) - redcarpet (3.5.0) - regexp_parser (1.8.2) - request_store (1.5.0) - rack (>= 1.4) - responders (2.4.1) - actionpack (>= 4.2.0, < 6.0) - railties (>= 4.2.0, < 6.0) - rexml (3.2.4) - roadie (3.5.1) - css_parser (~> 1.4) - nokogiri (~> 1.8) - roadie-rails (1.3.0) - railties (>= 3.0, < 5.3) - roadie (~> 3.1) - roo (2.8.3) - nokogiri (~> 1) - rubyzip (>= 1.3.0, < 3.0.0) - rspec (3.10.0) - rspec-core (~> 3.10.0) - rspec-expectations (~> 3.10.0) - rspec-mocks (~> 3.10.0) - rspec-core (3.10.0) - rspec-support (~> 3.10.0) - rspec-expectations (3.10.0) - diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.10.0) - rspec-mocks (3.10.0) - diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.10.0) - rspec-rails (4.0.1) - actionpack (>= 4.2) - activesupport (>= 4.2) - railties (>= 4.2) - rspec-core (~> 3.9) - rspec-expectations (~> 3.9) - rspec-mocks (~> 3.9) - rspec-support (~> 3.9) - rspec-retry (0.6.2) - rspec-core (> 3.3) - rspec-support (3.10.0) - rswag (2.3.1) - rswag-api (= 2.3.1) - rswag-specs (= 2.3.1) - rswag-ui (= 2.3.1) - rswag-api (2.3.1) - railties (>= 3.1, < 7.0) - rswag-specs (2.3.1) - activesupport (>= 3.1, < 7.0) - json-schema (~> 2.2) - railties (>= 3.1, < 7.0) - rswag-ui (2.3.1) - actionpack (>= 3.1, < 7.0) - railties (>= 3.1, < 7.0) - rubocop (0.81.0) - jaro_winkler (~> 1.5.1) - parallel (~> 1.10) - parser (>= 2.7.0.1) - rainbow (>= 2.2.2, < 4.0) - rexml - ruby-progressbar (~> 1.7) - unicode-display_width (>= 1.4.0, < 2.0) - rubocop-rails (2.5.2) - activesupport - rack (>= 1.1) - rubocop (>= 0.72.0) - ruby-progressbar (1.10.1) - ruby-rc4 (0.1.5) - ruby2_keywords (0.0.2) - rubyzip (1.3.0) - sass (3.4.25) - sass-rails (5.0.7) - railties (>= 4.0.0, < 6) - sass (~> 3.1) - sprockets (>= 2.8, < 4.0) - sprockets-rails (>= 2.0, < 4.0) - tilt (>= 1.1, < 3) - select2-rails (3.4.9) - sass-rails - thor (~> 0.14) - selenium-webdriver (3.142.7) - childprocess (>= 0.5, < 4.0) - rubyzip (>= 1.2.2) - shoulda-matchers (4.0.1) - activesupport (>= 4.2.0) - simplecov (0.17.1) - docile (~> 1.1) - json (>= 1.8, < 3) - simplecov-html (~> 0.10.0) - simplecov-html (0.10.2) - sinatra (2.1.0) - mustermann (~> 1.0) - rack (~> 2.2) - rack-protection (= 2.1.0) - tilt (~> 2.0) - spring (2.0.2) - activesupport (>= 4.2) - spring-commands-rspec (1.0.4) - spring (>= 0.9.1) - sprockets (3.7.2) - concurrent-ruby (~> 1.0) - rack (> 1, < 3) - sprockets-rails (3.2.2) - actionpack (>= 4.0) - activesupport (>= 4.0) - sprockets (>= 3.0.0) - state_machines (0.5.0) - state_machines-activemodel (0.7.1) - activemodel (>= 4.1) - state_machines (>= 0.5.0) - state_machines-activerecord (0.6.0) - activerecord (>= 4.1) - state_machines-activemodel (>= 0.5.0) - stringex (2.8.5) - stripe (5.28.0) - temple (0.8.2) - test-prof (0.7.5) - test-unit (3.3.7) - power_assert - thor (0.20.3) - thread_safe (0.3.6) - tilt (2.0.10) - timecop (0.9.2) - tzinfo (1.2.9) - thread_safe (~> 0.1) - uglifier (4.2.0) - execjs (>= 0.3.0, < 3) - unicode-display_width (1.7.0) - unicorn (5.7.0) - kgio (~> 2.6) - raindrops (~> 0.7) - unicorn-rails (2.2.1) - rack - unicorn - unicorn-worker-killer (0.4.4) - get_process_mem (~> 0) - unicorn (>= 4, < 6) - uniform_notifier (1.14.1) - warden (1.2.9) - rack (>= 2.0.9) - webdrivers (4.2.0) - nokogiri (~> 1.6) - rubyzip (>= 1.3.0) - selenium-webdriver (>= 3.0, < 4.0) - webmock (3.10.0) - addressable (>= 2.3.6) - crack (>= 0.3.2) - hashdiff (>= 0.4.0, < 2.0.0) - websocket-driver (0.6.5) - websocket-extensions (>= 0.1.0) - websocket-extensions (0.1.5) - whenever (1.0.0) - chronic (>= 0.6.3) - wicked_pdf (2.1.0) - activesupport - wkhtmltopdf-binary (0.12.6.5) - xml-simple (1.1.8) - xpath (3.2.0) - nokogiri (~> 1.8) - -PLATFORMS - ruby - -DEPENDENCIES - actionpack-action_caching - active_model_serializers (= 0.8.4) - activemerchant (>= 1.78.0) - activerecord-import - activerecord-postgresql-adapter - activerecord-session_store - acts-as-taggable-on (~> 4.0) - acts_as_list (= 0.9.19) - andand - angular-rails-templates (>= 0.3.0, < 1.1.0) - angular_rails_csrf - angularjs-file-upload-rails (~> 2.4.1) - angularjs-rails (= 1.5.5) - atomic - awesome_nested_set - awesome_print - aws-sdk (= 1.67.0) - bugsnag - bullet - byebug - cancancan (~> 1.7.0) - capybara - catalog! - coffee-rails (~> 4.2.2) - combine_pdf - compass-rails - custom_error_message! - daemons - dalli - database_cleaner - ddtrace - debugger-linecache - delayed_job_active_record - delayed_job_web - devise - devise-encryptable - devise-token_authenticatable - dfc_provider! - eventmachine (>= 1.2.3) - factory_bot_rails (= 5.2.0) - ffaker - figaro - foundation-icons-sass-rails - foundation-rails (= 5.5.2.1) - fuubar (~> 2.5.1) - geocoder - gmaps4rails - good_migrations - haml - highline (= 2.0.3) - i18n - i18n-js (~> 3.8.0) - immigrant - jquery-migrate-rails - jquery-rails (= 4.4.0) - jquery-ui-rails (~> 4.2) - json - json_spec (~> 1.1.4) - jwt (~> 2.2) - kaminari (~> 1.2.1) - knapsack - letter_opener (>= 1.4.1) - libv8 (< 8) - mini_racer (= 0.2.15) - monetize (~> 1.10) - oauth2 (~> 1.4.4) - ofn-qz! - order_management! - paper_trail (~> 10.3.1) - paperclip (~> 3.4.1) - paranoia (~> 2.4) - paypal-sdk-merchant (= 1.117.2) - pg (~> 0.21.0) - pry - pry-byebug - rack-mini-profiler (< 3.0.0) - rack-rewrite - rack-ssl - rails (> 5.0, < 5.1) - rails-controller-testing - rails-i18n - rails_safe_tasks (~> 1.0) - ransack (= 2.3.0) - redcarpet - responders - roadie-rails (~> 1.3.0) - roo (~> 2.8.3) - rspec-rails (>= 3.5.2) - rspec-retry - rswag - rubocop - rubocop-rails - sass (<= 4.7.1) - sass-rails (< 6.0.0) - select2-rails (~> 3.4.7) - selenium-webdriver - shoulda-matchers - simplecov - spring - spring-commands-rspec - state_machines-activerecord - stringex (~> 2.8.5) - stripe - test-prof - test-unit (~> 3.3) - timecop - uglifier (>= 1.0.3) - unicorn-rails - unicorn-worker-killer - web! - webdrivers - webmock - whenever - wicked_pdf - wkhtmltopdf-binary - -RUBY VERSION - ruby 2.4.4p296 - -BUNDLED WITH - 1.17.3 diff --git a/config/initializers/action_dispatch_request_deep_munge_patch.rb b/config/initializers/action_dispatch_request_deep_munge_patch.rb deleted file mode 100644 index 3bc93d6a07b..00000000000 --- a/config/initializers/action_dispatch_request_deep_munge_patch.rb +++ /dev/null @@ -1 +0,0 @@ -require "action_dispatch/request" unless ENV['DEPENDENCIES_NEXT'] diff --git a/config/initializers/db2fog.rb b/config/initializers/db2fog.rb deleted file mode 100644 index 5da84a30e42..00000000000 --- a/config/initializers/db2fog.rb +++ /dev/null @@ -1,17 +0,0 @@ -unless ENV['DEPENDENCIES_NEXT'] - require_relative 'spree' - - # See: https://github.com/itbeaver/db2fog - DB2Fog.config = { - :aws_access_key_id => Spree::Config[:s3_access_key], - :aws_secret_access_key => Spree::Config[:s3_secret], - :directory => ENV['S3_BACKUPS_BUCKET'], - :provider => 'AWS' - } - - region = ENV['S3_BACKUPS_REGION'] || ENV['S3_REGION'] - - # If no region is defined we leave this config key undefined (instead of nil), - # so that db2fog correctly applies it's default - DB2Fog.config[:region] = region if region -end diff --git a/config/initializers/js_template_helpers.rb b/config/initializers/js_template_helpers.rb index 7ff1e9a0b0b..80c03580ff7 100644 --- a/config/initializers/js_template_helpers.rb +++ b/config/initializers/js_template_helpers.rb @@ -1,14 +1,14 @@ # Make helpers (#t in particular) available to javascript templates # https://github.com/pitr/angular-rails-templates/issues/45#issuecomment-43229086 -if ENV['DEPENDENCIES_NEXT'] +# if ENV['DEPENDENCIES_NEXT'] Rails.application.config.assets.configure do |env| env.context_class.class_eval do include ActionView::Helpers::TranslationHelper end end -else - Rails.application.assets.context_class.class_eval do - include ActionView::Helpers::TranslationHelper - end -end +# else +# Rails.application.assets.context_class.class_eval do +# include ActionView::Helpers::TranslationHelper +# end +# end diff --git a/lib/action_dispatch/request.rb b/lib/action_dispatch/request.rb deleted file mode 100644 index b6f659e7dd5..00000000000 --- a/lib/action_dispatch/request.rb +++ /dev/null @@ -1,69 +0,0 @@ -# frozen_string_literal: true - -# This patch fixes the Rails issue where ActionDispatch::Request#deep_munge was converting empty -# array paramters into nils, see https://github.com/rails/rails/issues/13420 -# -# Before this patch: -# -# | JSON | Hash | -# |----------------------------------|-------------------------| -# | { "person": [] } | { 'person' => nil } | -# -# After patch: -# -# | JSON | Hash | -# |----------------------------------|-------------------------| -# | { "person": [] } | { 'person' => [] } | -# -# The issue started in Rails v4.0.0.beta1: -# -# https://github.com/rails/rails/commit/8e577fe560d5756fcc67840ba304d79ada6804e4 -# -# This patch can be removed on or after Rails v5.0.0.beta1 when the issue was fixed: -# -# https://github.com/rails/rails/commit/8f8ccb9901cab457c6e1d52bdb25acf658fd5777 -# -# Credit: -# -# https://gist.github.com/victorblasco/f675b4cbaf9c0bc19f81 - -module ActionDispatch - class Request < Rack::Request - class Utils # :nodoc: - mattr_accessor :perform_deep_munge - self.perform_deep_munge = true - - class << self - # Remove nils from the params hash - def deep_munge(hash, keys = []) - return hash unless perform_deep_munge - - hash.each do |key, value| - deep_munge_value(key, value, keys) - end - - hash - end - - def deep_munge_value(key, value, keys) - keys << key - case value - when Array - value.grep(Hash) { |x| deep_munge(x, keys) } - value.compact! - - # This patch removes the following lines - # if v.empty? - # hash[k] = nil - # ActiveSupport::Notifications.instrument("deep_munge.action_controller", - # keys: keys) - # end - when Hash - deep_munge(value, keys) - end - keys.pop - end - end - end - end -end From 31df28b348471209d75ceb1e3fa2d54fec340349 Mon Sep 17 00:00:00 2001 From: Matt-Yorkley <9029026+Matt-Yorkley@users.noreply.github.com> Date: Sun, 10 Jan 2021 21:28:47 +0000 Subject: [PATCH 15/50] Fix params mangling in Api::ProductController --- app/controllers/api/products_controller.rb | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/app/controllers/api/products_controller.rb b/app/controllers/api/products_controller.rb index 0dd2d26d607..d8fab1067a5 100644 --- a/app/controllers/api/products_controller.rb +++ b/app/controllers/api/products_controller.rb @@ -7,6 +7,8 @@ class ProductsController < Api::BaseController respond_to :json DEFAULT_PER_PAGE = 15 + before_action :set_default_available_on, only: :create + skip_authorization_check only: [:show, :bulk_products, :overridable] def show @@ -16,8 +18,8 @@ def show def create authorize! :create, Spree::Product - params[:product][:available_on] ||= Time.zone.now @product = Spree::Product.new(product_params) + begin if @product.save render json: @product, serializer: Api::Admin::ProductSerializer, status: :created @@ -146,7 +148,12 @@ def query_params_with_defaults end def product_params - params.require(:product).permit PermittedAttributes::Product.attributes + @product_params ||= + params.permit(product: PermittedAttributes::Product.attributes)[:product].to_h + end + + def set_default_available_on + product_params[:available_on] ||= Time.zone.now end end end From dcecfaea87e0237f3b8c7d34f7635a55940a9940 Mon Sep 17 00:00:00 2001 From: Matt-Yorkley <9029026+Matt-Yorkley@users.noreply.github.com> Date: Sat, 23 Jan 2021 09:19:11 +0000 Subject: [PATCH 16/50] Fix params issues in OrderCyclescontroller spec --- app/controllers/admin/order_cycles_controller.rb | 8 +++++--- spec/controllers/admin/order_cycles_controller_spec.rb | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/app/controllers/admin/order_cycles_controller.rb b/app/controllers/admin/order_cycles_controller.rb index 3482be399fc..77eab671421 100644 --- a/app/controllers/admin/order_cycles_controller.rb +++ b/app/controllers/admin/order_cycles_controller.rb @@ -199,10 +199,12 @@ def protect_invalid_destroy end def remove_protected_attrs - params[:order_cycle].delete :coordinator_id + return unless order_cycle_params[:order_cycle] + + order_cycle_params[:order_cycle].delete :coordinator_id unless Enterprise.managed_by(spree_current_user).include?(@order_cycle.coordinator) - params[:order_cycle].delete_if do |k, _v| + order_cycle_params[:order_cycle].delete_if do |k, _v| [:name, :orders_open_at, :orders_close_at].include? k.to_sym end end @@ -238,7 +240,7 @@ def ams_prefix_whitelist end def order_cycle_params - PermittedAttributes::OrderCycle.new(params).call + @order_cycle_params ||= PermittedAttributes::OrderCycle.new(params).call.to_h.with_indifferent_access end def order_cycle_bulk_params diff --git a/spec/controllers/admin/order_cycles_controller_spec.rb b/spec/controllers/admin/order_cycles_controller_spec.rb index 96eba697b0b..65fdedbd749 100644 --- a/spec/controllers/admin/order_cycles_controller_spec.rb +++ b/spec/controllers/admin/order_cycles_controller_spec.rb @@ -187,7 +187,7 @@ def build_resource it "can update preference product_selection_from_coordinator_inventory_only" do expect(OrderCycleForm).to receive(:new). with(order_cycle, - { "preferred_product_selection_from_coordinator_inventory_only" => true }, + { "preferred_product_selection_from_coordinator_inventory_only" => "true" }, anything) { form_mock } allow(form_mock).to receive(:save) { true } From 2ac4ace3e8961eba6d74310c378260324c01dcf0 Mon Sep 17 00:00:00 2001 From: Matt-Yorkley <9029026+Matt-Yorkley@users.noreply.github.com> Date: Sat, 23 Jan 2021 09:21:27 +0000 Subject: [PATCH 17/50] Fix params issues in UserPasswordsController --- app/controllers/spree/user_passwords_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/spree/user_passwords_controller.rb b/app/controllers/spree/user_passwords_controller.rb index 244cf93c768..2ecc0342924 100644 --- a/app/controllers/spree/user_passwords_controller.rb +++ b/app/controllers/spree/user_passwords_controller.rb @@ -25,7 +25,7 @@ class UserPasswordsController < Devise::PasswordsController # respond_with resource, :location => spree.login_path # def create - self.resource = resource_class.send_reset_password_instructions(params[resource_name]) + self.resource = resource_class.send_reset_password_instructions(raw_params[resource_name]) if resource.errors.empty? set_flash_message(:notice, :send_instructions) if is_navigational_format? From 29c34060e95fbbd872360b0d9a2a2cec44ec06ed Mon Sep 17 00:00:00 2001 From: Matt-Yorkley <9029026+Matt-Yorkley@users.noreply.github.com> Date: Sat, 23 Jan 2021 10:58:48 +0000 Subject: [PATCH 18/50] Add tight pinning on wkhtmltopdf-binary gem version --- Gemfile | 2 +- Gemfile.lock | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Gemfile b/Gemfile index bbac8c37727..5b3dc70f9b5 100644 --- a/Gemfile +++ b/Gemfile @@ -81,7 +81,7 @@ gem 'roadie-rails', '~> 1.3.0' gem 'combine_pdf' gem 'wicked_pdf' -gem 'wkhtmltopdf-binary' +gem 'wkhtmltopdf-binary', '0.12.5' # We need to upgrade our CI before we can bump this :/ gem 'immigrant' gem 'roo', '~> 2.8.3' diff --git a/Gemfile.lock b/Gemfile.lock index 25b34d8cba0..9b98f71dc44 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -550,7 +550,7 @@ GEM chronic (>= 0.6.3) wicked_pdf (2.1.0) activesupport - wkhtmltopdf-binary (0.12.6.5) + wkhtmltopdf-binary (0.12.5) xml-simple (1.1.8) xpath (3.2.0) nokogiri (~> 1.8) @@ -672,7 +672,7 @@ DEPENDENCIES webmock whenever wicked_pdf - wkhtmltopdf-binary + wkhtmltopdf-binary (= 0.12.5) RUBY VERSION ruby 2.4.4p296 From 1911d2595960bf032db2ef5446e69f0ae8484d22 Mon Sep 17 00:00:00 2001 From: Matt-Yorkley <9029026+Matt-Yorkley@users.noreply.github.com> Date: Sat, 23 Jan 2021 12:31:55 +0000 Subject: [PATCH 19/50] Fix Sets::ModelSet spec --- app/services/sets/model_set.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/services/sets/model_set.rb b/app/services/sets/model_set.rb index 87e2ef4655c..4cafcd924b8 100644 --- a/app/services/sets/model_set.rb +++ b/app/services/sets/model_set.rb @@ -13,6 +13,7 @@ def initialize(klass, collection, attributes = {}, reject_if = nil, delete_if = # Set here first, to ensure that we apply collection_attributes to the right collection @collection = attributes[:collection] if attributes[:collection] + @collection = @collection.to_a attributes.each do |name, value| public_send("#{name}=", value) From e46fe3735b2aaa8e54c8bdc3018a7e13d844b39f Mon Sep 17 00:00:00 2001 From: Matt-Yorkley <9029026+Matt-Yorkley@users.noreply.github.com> Date: Sat, 23 Jan 2021 14:24:37 +0000 Subject: [PATCH 20/50] Fix params issue in controller specs --- spec/spec_helper.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 9245a5bb95c..ea11c5f95cd 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -143,6 +143,9 @@ def restart_driver ActionController::Base.perform_caching = caching end + # Fix encoding issue in Rails 5.0; allows passing empty arrays or hashes as params. + config.before(:each, type: :controller) { @request.env["CONTENT_TYPE"] = 'application/json' } + # Show javascript errors in test output with `js_debug: true` config.after(:each, :js_debug) do errors = page.driver.browser.manage.logs.get(:browser) From ec597aab1a9bd91f30434110d875e332e604df54 Mon Sep 17 00:00:00 2001 From: Matt-Yorkley <9029026+Matt-Yorkley@users.noreply.github.com> Date: Sat, 23 Jan 2021 14:28:31 +0000 Subject: [PATCH 21/50] Fix params issue in ReportsController expectation --- spec/controllers/spree/admin/reports_controller_spec.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/spec/controllers/spree/admin/reports_controller_spec.rb b/spec/controllers/spree/admin/reports_controller_spec.rb index c2f4fbbe7ae..964ea31d62c 100644 --- a/spec/controllers/spree/admin/reports_controller_spec.rb +++ b/spec/controllers/spree/admin/reports_controller_spec.rb @@ -228,7 +228,7 @@ it "creates a ProductAndInventoryReport" do expect(OpenFoodNetwork::ProductsAndInventoryReport).to receive(:new) .with(@admin_user, - { "test" => "foo", "controller" => "spree/admin/reports", + { "test" => "foo", "controller" => "spree/admin/reports", "report" => {}, "action" => "products_and_inventory", "use_route" => "main_app" }, false) .and_return(report = double(:report)) allow(report).to receive(:header).and_return [] @@ -281,7 +281,8 @@ it "creates a CustomersReport" do expect(OpenFoodNetwork::CustomersReport).to receive(:new) .with(@admin_user, { "test" => "foo", "controller" => "spree/admin/reports", - "action" => "customers", "use_route" => "main_app" }, false) + "action" => "customers", "use_route" => "main_app", + "report" => {} }, false) .and_return(report = double(:report)) allow(report).to receive(:header).and_return [] allow(report).to receive(:table).and_return [] From 0393ea4219e16064088ce2dc7e2591b50c336cd8 Mon Sep 17 00:00:00 2001 From: Matt-Yorkley <9029026+Matt-Yorkley@users.noreply.github.com> Date: Sat, 23 Jan 2021 15:45:04 +0000 Subject: [PATCH 22/50] Update variant params in CartController --- app/controllers/cart_controller.rb | 3 ++- spec/controllers/cart_controller_spec.rb | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/app/controllers/cart_controller.rb b/app/controllers/cart_controller.rb index f4ab6abf29b..f3a0de59eaa 100644 --- a/app/controllers/cart_controller.rb +++ b/app/controllers/cart_controller.rb @@ -50,7 +50,8 @@ def populate_variant_attributes def populate_variant_attributes_from_variant(order) params[:variant_attributes].each do |variant_id, attributes| - order.set_variant_attributes(Spree::Variant.find(variant_id), attributes) + permitted = attributes.permit(:quantity, :max_quantity).to_h.with_indifferent_access + order.set_variant_attributes(Spree::Variant.find(variant_id), permitted) end end diff --git a/spec/controllers/cart_controller_spec.rb b/spec/controllers/cart_controller_spec.rb index 8605dc8adf1..b3f6d46c8f4 100644 --- a/spec/controllers/cart_controller_spec.rb +++ b/spec/controllers/cart_controller_spec.rb @@ -110,11 +110,11 @@ order = subject.current_order(true) allow(order).to receive(:distributor) { distributor } allow(order).to receive(:order_cycle) { order_cycle } - expect(order).to receive(:set_variant_attributes).with(variant, max_quantity: '3') + expect(order).to receive(:set_variant_attributes).with(variant, max_quantity: "3") allow(controller).to receive(:current_order).and_return(order) expect do - spree_post :populate, variants: { variant.id => 1 }, variant_attributes: { variant.id => { max_quantity: 3 } } + spree_post :populate, variants: { variant.id => 1 }, variant_attributes: { variant.id => { max_quantity: "3" } } end.to change(Spree::LineItem, :count).by(1) end end From bd408e02b019ef240443aab7ea329953004b71bc Mon Sep 17 00:00:00 2001 From: Matt-Yorkley <9029026+Matt-Yorkley@users.noreply.github.com> Date: Sat, 23 Jan 2021 16:30:36 +0000 Subject: [PATCH 23/50] Update OrderCyclesController params usage --- .../admin/order_cycles_controller.rb | 36 +++++++++++-------- .../admin/order_cycles_controller_spec.rb | 13 ++++--- 2 files changed, 30 insertions(+), 19 deletions(-) diff --git a/app/controllers/admin/order_cycles_controller.rb b/app/controllers/admin/order_cycles_controller.rb index 77eab671421..d4ba8d0b1a8 100644 --- a/app/controllers/admin/order_cycles_controller.rb +++ b/app/controllers/admin/order_cycles_controller.rb @@ -101,7 +101,7 @@ def notify_producers def collection return Enterprise.where("1=0") unless json_request? - return order_cycles_from_set if params[:order_cycle_set] + return order_cycles_from_set if params[:order_cycle_set].present? ocs = order_cycles ocs.undated | ocs.soonest_closing | ocs.soonest_opening | ocs.closed @@ -126,7 +126,7 @@ def order_cycles def order_cycles_as_distributor OrderCycle. preload(:schedules). - ransack(params[:q]). + ransack(raw_params[:q]). result. involving_managed_distributors_of(spree_current_user). order('updated_at DESC') @@ -135,7 +135,7 @@ def order_cycles_as_distributor def order_cycles_as_producer OrderCycle. preload(:schedules). - ransack(params[:q]). + ransack(raw_params[:q]). result. involving_managed_producers_of(spree_current_user). order('updated_at DESC') @@ -144,7 +144,7 @@ def order_cycles_as_producer def order_cycles_as_both OrderCycle. preload(:schedules). - ransack(params[:q]). + ransack(raw_params[:q]). result. visible_by(spree_current_user) end @@ -153,9 +153,9 @@ def load_data_for_index if json_request? # Split ransack params into all those that currently exist and new ones # to limit returned ocs to recent or undated - orders_close_at_gt = params[:q].andand.delete(:orders_close_at_gt) || 31.days.ago - params[:q] = { - g: [params.delete(:q) || {}, { m: 'or', + orders_close_at_gt = raw_params[:q].andand.delete(:orders_close_at_gt) || 31.days.ago + raw_params[:q] = { + g: [raw_params.delete(:q) || {}, { m: 'or', orders_close_at_gt: orders_close_at_gt, orders_close_at_null: true }] } @@ -199,29 +199,34 @@ def protect_invalid_destroy end def remove_protected_attrs - return unless order_cycle_params[:order_cycle] + return if order_cycle_params.blank? - order_cycle_params[:order_cycle].delete :coordinator_id + order_cycle_params.delete :coordinator_id unless Enterprise.managed_by(spree_current_user).include?(@order_cycle.coordinator) - order_cycle_params[:order_cycle].delete_if do |k, _v| + order_cycle_params.delete_if do |k, _v| [:name, :orders_open_at, :orders_close_at].include? k.to_sym end end end def remove_unauthorized_bulk_attrs - params[:order_cycle_set][:collection_attributes].each do |i, hash| + (order_cycle_params.dig(:order_cycle_set, :collection_attributes) || []).each do |i, hash| order_cycle = OrderCycle.find(hash[:id]) unless Enterprise.managed_by(spree_current_user).include?(order_cycle.andand.coordinator) - params[:order_cycle_set][:collection_attributes].delete i + order_cycle_params[:order_cycle_set][:collection_attributes].delete i end end end def order_cycles_from_set remove_unauthorized_bulk_attrs - OrderCycle.where(id: params[:order_cycle_set][:collection_attributes].map{ |_k, v| v[:id] }) + collection_attributes = order_cycle_params.dig(:order_cycle_set, :collection_attributes) + return if collection_attributes.blank? + + OrderCycle.where( + id: collection_attributes.map{ |_k, v| v[:id] } + ) end def order_cycle_set @@ -229,7 +234,7 @@ def order_cycle_set end def require_order_cycle_set_params - return if params[:order_cycle_set] + return if order_cycle_params[:order_cycle_set] render json: { errors: t('admin.order_cycles.bulk_update.no_data') }, status: :unprocessable_entity @@ -240,7 +245,8 @@ def ams_prefix_whitelist end def order_cycle_params - @order_cycle_params ||= PermittedAttributes::OrderCycle.new(params).call.to_h.with_indifferent_access + @order_cycle_params ||= PermittedAttributes::OrderCycle.new(params).call. + to_h.with_indifferent_access end def order_cycle_bulk_params diff --git a/spec/controllers/admin/order_cycles_controller_spec.rb b/spec/controllers/admin/order_cycles_controller_spec.rb index 65fdedbd749..216631ce055 100644 --- a/spec/controllers/admin/order_cycles_controller_spec.rb +++ b/spec/controllers/admin/order_cycles_controller_spec.rb @@ -187,7 +187,7 @@ def build_resource it "can update preference product_selection_from_coordinator_inventory_only" do expect(OrderCycleForm).to receive(:new). with(order_cycle, - { "preferred_product_selection_from_coordinator_inventory_only" => "true" }, + { "preferred_product_selection_from_coordinator_inventory_only" => true }, anything) { form_mock } allow(form_mock).to receive(:save) { true } @@ -207,7 +207,7 @@ def build_resource let!(:outgoing_exchange) { create(:exchange, order_cycle: order_cycle, sender: coordinator, receiver: hub, incoming: false, variants: [v]) } let(:allowed) { { incoming_exchanges: [], outgoing_exchanges: [] } } - let(:restricted) { { name: 'some name', orders_open_at: 1.day.from_now, orders_close_at: 1.day.ago } } + let(:restricted) { { name: 'some name', orders_open_at: 1.day.from_now.to_s, orders_close_at: 1.day.ago.to_s } } let(:params) { { format: :json, id: order_cycle.id, order_cycle: allowed.merge(restricted) } } let(:form_mock) { instance_double(OrderCycleForm, save: true) } @@ -267,8 +267,13 @@ def build_resource end context "when a validation error occurs" do - before do - params[:order_cycle_set][:collection_attributes]['0'][:orders_open_at] = Date.current + 25.days + let(:params) do + { format: :json, order_cycle_set: { collection_attributes: { '0' => { + id: oc.id, + name: "Updated Order Cycle", + orders_open_at: Date.current + 25.days, + orders_close_at: Date.current + 21.days, + } } } } end it "returns an error message" do From 190770b9df3bb96e86e8a72465dac5e047aa5720 Mon Sep 17 00:00:00 2001 From: Matt-Yorkley <9029026+Matt-Yorkley@users.noreply.github.com> Date: Sat, 23 Jan 2021 18:19:22 +0000 Subject: [PATCH 24/50] Update query filter params handling --- app/controllers/spree/admin/images_controller.rb | 4 ++-- app/controllers/spree/admin/products_controller.rb | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/controllers/spree/admin/images_controller.rb b/app/controllers/spree/admin/images_controller.rb index 587dd8e0cae..0757a78bf79 100644 --- a/app/controllers/spree/admin/images_controller.rb +++ b/app/controllers/spree/admin/images_controller.rb @@ -19,7 +19,7 @@ def new end def create - @url_filters = ::ProductFilters.new.extract(params) + @url_filters = ::ProductFilters.new.extract(request.query_parameters) set_viewable @object.attributes = permitted_resource_params @@ -36,7 +36,7 @@ def edit end def update - @url_filters = ::ProductFilters.new.extract(params) + @url_filters = ::ProductFilters.new.extract(request.query_parameters) set_viewable if @object.update(permitted_resource_params) diff --git a/app/controllers/spree/admin/products_controller.rb b/app/controllers/spree/admin/products_controller.rb index 1cc3f5ae6d4..89361465a91 100644 --- a/app/controllers/spree/admin/products_controller.rb +++ b/app/controllers/spree/admin/products_controller.rb @@ -54,7 +54,7 @@ def index end def edit - @url_filters = ::ProductFilters.new.extract(params) + @url_filters = ::ProductFilters.new.extract(request.query_parameters) end def update From 83278b17dbaa444434c948946b80f5029cf92589 Mon Sep 17 00:00:00 2001 From: Matt-Yorkley <9029026+Matt-Yorkley@users.noreply.github.com> Date: Sun, 24 Jan 2021 13:09:15 +0000 Subject: [PATCH 25/50] Fix test controller issue --- spec/controllers/admin/schedules_controller_spec.rb | 2 ++ .../spree/admin/return_authorizations_controller_spec.rb | 3 +++ spec/support/controller_helper.rb | 8 ++++++++ 3 files changed, 13 insertions(+) diff --git a/spec/controllers/admin/schedules_controller_spec.rb b/spec/controllers/admin/schedules_controller_spec.rb index e6981bcfe69..2718d75b657 100644 --- a/spec/controllers/admin/schedules_controller_spec.rb +++ b/spec/controllers/admin/schedules_controller_spec.rb @@ -96,7 +96,9 @@ expect(syncer_mock).to receive(:sync!).exactly(2).times spree_put :update, format: :json, id: coordinated_schedule.id, order_cycle_ids: [coordinated_order_cycle.id, coordinated_order_cycle2.id] + reset_controller_environment spree_put :update, format: :json, id: coordinated_schedule.id, order_cycle_ids: [coordinated_order_cycle.id] + reset_controller_environment spree_put :update, format: :json, id: coordinated_schedule.id, order_cycle_ids: [coordinated_order_cycle.id] end end diff --git a/spec/controllers/spree/admin/return_authorizations_controller_spec.rb b/spec/controllers/spree/admin/return_authorizations_controller_spec.rb index 4930f78fc96..79a5a9fb7ff 100644 --- a/spec/controllers/spree/admin/return_authorizations_controller_spec.rb +++ b/spec/controllers/spree/admin/return_authorizations_controller_spec.rb @@ -33,6 +33,9 @@ module Admin expect(return_authorization.amount.to_s).to eq "20.2" expect(return_authorization.reason.to_s).to eq "broken" + # Reset the test controller between requests + reset_controller_environment + # Update return authorization spree_put :update, id: return_authorization.id, return_authorization: { amount: "10.2", reason: "half broken" } diff --git a/spec/support/controller_helper.rb b/spec/support/controller_helper.rb index 622afe37f6c..df64e2a438f 100644 --- a/spec/support/controller_helper.rb +++ b/spec/support/controller_helper.rb @@ -24,5 +24,13 @@ def controller_login_as_enterprise_user(enterprises) allow(controller).to receive_messages(spree_current_user: @enterprise_user) end + + def reset_controller_environment + # Rails 5.0 introduced a bug in controller tests (fixed in 5.2) where the controller's + # environment is essentially cached if multiple requests are made in the same `it` block, + # meaning subsequent requests will not be handled well. This resets the environment. + # This edge case is quite rare though; normally we only do one request per test. + @request.env.delete("RAW_POST_DATA") + end end end From ccf0556711c4135010dc5dde53e08991fedfa0f1 Mon Sep 17 00:00:00 2001 From: Matt-Yorkley <9029026+Matt-Yorkley@users.noreply.github.com> Date: Sun, 24 Jan 2021 15:21:10 +0000 Subject: [PATCH 26/50] Fix params mangling in Admin::EnterprisesController --- .../admin/enterprises_controller.rb | 25 ++++++++++--------- 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/app/controllers/admin/enterprises_controller.rb b/app/controllers/admin/enterprises_controller.rb index 48d6ee6a42e..87a3dff2243 100644 --- a/app/controllers/admin/enterprises_controller.rb +++ b/app/controllers/admin/enterprises_controller.rb @@ -247,31 +247,31 @@ def check_can_change_bulk_sells def check_can_change_sells unless spree_current_user.admin? || spree_current_user == @enterprise.owner - params[:enterprise].delete :sells + enterprise_params.delete :sells end end def override_owner - params[:enterprise][:owner_id] = spree_current_user.id unless spree_current_user.admin? + enterprise_params[:owner_id] = spree_current_user.id unless spree_current_user.admin? end def override_sells unless spree_current_user.admin? has_hub = spree_current_user.owned_enterprises.is_hub.any? new_enterprise_is_producer = Enterprise.new(enterprise_params).is_primary_producer - params[:enterprise][:sells] = has_hub && !new_enterprise_is_producer ? 'any' : 'none' + enterprise_params[:sells] = has_hub && !new_enterprise_is_producer ? 'any' : 'none' end end def check_can_change_owner unless ( spree_current_user == @enterprise.owner ) || spree_current_user.admin? - params[:enterprise].delete :owner_id + enterprise_params.delete :owner_id end end def check_can_change_bulk_owner unless spree_current_user.admin? - params[:sets_enterprise_set][:collection_attributes].each do |_i, enterprise_params| + bulk_params[:collection_attributes].each do |_i, enterprise_params| enterprise_params.delete :owner_id end end @@ -279,15 +279,15 @@ def check_can_change_bulk_owner def check_can_change_managers unless ( spree_current_user == @enterprise.owner ) || spree_current_user.admin? - params[:enterprise].delete :user_ids + enterprise_params.delete :user_ids end end def strip_new_properties - unless spree_current_user.admin? || params[:enterprise][:producer_properties_attributes].nil? + unless spree_current_user.admin? || params.dig(:enterprise, :producer_properties_attributes).nil? names = Spree::Property.pluck(:name) - params[:enterprise][:producer_properties_attributes].each do |key, property| - params[:enterprise][:producer_properties_attributes].delete key unless names.include? property[:property_name] + enterprise_params[:producer_properties_attributes].each do |key, property| + enterprise_params[:producer_properties_attributes].delete key unless names.include? property[:property_name] end end end @@ -319,13 +319,14 @@ def ams_prefix_whitelist end def enterprise_params - PermittedAttributes::Enterprise.new(params).call + @enterprise_params ||= PermittedAttributes::Enterprise.new(params).call. + to_h.with_indifferent_access end def bulk_params - params.require(:sets_enterprise_set).permit( + @bulk_params ||= params.require(:sets_enterprise_set).permit( collection_attributes: PermittedAttributes::Enterprise.attributes - ) + ).to_h.with_indifferent_access end # Used in Admin::ResourceController#create From 4ff56ce625e7827f1c0ba9c6c28cde7c1566105c Mon Sep 17 00:00:00 2001 From: Matt-Yorkley <9029026+Matt-Yorkley@users.noreply.github.com> Date: Sun, 24 Jan 2021 19:52:12 +0000 Subject: [PATCH 27/50] Update deprecated use of #uniq in OrderCyle scopes --- app/models/order_cycle.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/models/order_cycle.rb b/app/models/order_cycle.rb index 2b20033de65..93451f081ca 100644 --- a/app/models/order_cycle.rb +++ b/app/models/order_cycle.rb @@ -13,8 +13,8 @@ class OrderCycle < ActiveRecord::Base has_many :cached_incoming_exchanges, -> { where incoming: true }, class_name: "Exchange" has_many :cached_outgoing_exchanges, -> { where incoming: false }, class_name: "Exchange" - has_many :suppliers, -> { uniq }, source: :sender, through: :cached_incoming_exchanges - has_many :distributors, -> { uniq }, source: :receiver, through: :cached_outgoing_exchanges + has_many :suppliers, -> { distinct }, source: :sender, through: :cached_incoming_exchanges + has_many :distributors, -> { distinct }, source: :receiver, through: :cached_outgoing_exchanges has_many :schedules, through: :order_cycle_schedules has_many :order_cycle_schedules From 688b3c98d7ca313fcfe5775872d3db3465307b78 Mon Sep 17 00:00:00 2001 From: Matt-Yorkley <9029026+Matt-Yorkley@users.noreply.github.com> Date: Sun, 24 Jan 2021 20:10:36 +0000 Subject: [PATCH 28/50] Use strong params in variants search --- app/controllers/spree/admin/variants_controller.rb | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/app/controllers/spree/admin/variants_controller.rb b/app/controllers/spree/admin/variants_controller.rb index d7a501728be..2177080a8f3 100644 --- a/app/controllers/spree/admin/variants_controller.rb +++ b/app/controllers/spree/admin/variants_controller.rb @@ -54,7 +54,7 @@ def create end def search - scoper = OpenFoodNetwork::ScopeVariantsForSearch.new(params) + scoper = OpenFoodNetwork::ScopeVariantsForSearch.new(variant_search_params) @variants = scoper.search render json: @variants, each_serializer: ::Api::Admin::VariantSerializer end @@ -109,6 +109,12 @@ def variant_params def permitted_resource_params variant_params end + + def variant_search_params + params.permit( + :q, :distributor_id, :order_cycle_id, :schedule_id, :eligible_for_subscriptions + ).to_h.with_indifferent_access + end end end end From 6087a4b9691beedff3d7975d85835d74f292e47e Mon Sep 17 00:00:00 2001 From: Matt-Yorkley <9029026+Matt-Yorkley@users.noreply.github.com> Date: Sun, 24 Jan 2021 21:00:30 +0000 Subject: [PATCH 29/50] Fix rendering of javascript template The erb tags in this partial were not being parsed as erb, breaking various other things on the page. --- app/views/spree/admin/orders/_form.html.haml | 2 +- .../{_update_order_state.js => _update_order_state.js.erb} | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename app/views/spree/admin/shared/{_update_order_state.js => _update_order_state.js.erb} (100%) diff --git a/app/views/spree/admin/orders/_form.html.haml b/app/views/spree/admin/orders/_form.html.haml index 6bc77012bcf..6f027218953 100644 --- a/app/views/spree/admin/orders/_form.html.haml +++ b/app/views/spree/admin/orders/_form.html.haml @@ -26,4 +26,4 @@ var shipments = []; - @order.shipments.each do |shipment| shipments.push(#{shipment.to_json(:root => false, :include => [:inventory_units, :stock_location]).html_safe}); - = render :partial => 'spree/admin/shared/update_order_state', :handlers => [:js] + = render :partial => 'spree/admin/shared/update_order_state', :handlers => [:erb] diff --git a/app/views/spree/admin/shared/_update_order_state.js b/app/views/spree/admin/shared/_update_order_state.js.erb similarity index 100% rename from app/views/spree/admin/shared/_update_order_state.js rename to app/views/spree/admin/shared/_update_order_state.js.erb From e11d1e6cdb1e9991ff2980a6f888683b6e5c1db7 Mon Sep 17 00:00:00 2001 From: Matt-Yorkley <9029026+Matt-Yorkley@users.noreply.github.com> Date: Sun, 24 Jan 2021 21:43:39 +0000 Subject: [PATCH 30/50] Add strong params to Spree::Admin::SearchController --- .../spree/admin/search_controller.rb | 22 +++++++++++-------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/app/controllers/spree/admin/search_controller.rb b/app/controllers/spree/admin/search_controller.rb index 0be57cb0b38..802667a352e 100644 --- a/app/controllers/spree/admin/search_controller.rb +++ b/app/controllers/spree/admin/search_controller.rb @@ -6,7 +6,7 @@ class SearchController < Spree::Admin::BaseController respond_to :json def known_users - @users = if exact_match = Spree.user_class.find_by(email: params[:q]) + @users = if exact_match = Spree.user_class.find_by(email: search_params[:q]) [exact_match] else spree_current_user.known_users.ransack(ransack_hash).result.limit(10) @@ -17,11 +17,11 @@ def known_users def customers @customers = [] - if spree_current_user.enterprises.pluck(:id).include? params[:distributor_id].to_i + if spree_current_user.enterprises.pluck(:id).include? search_params[:distributor_id].to_i @customers = Customer. - ransack(m: 'or', email_start: params[:q], name_start: params[:q]). + ransack(m: 'or', email_start: search_params[:q], name_start: search_params[:q]). result. - where(enterprise_id: params[:distributor_id]) + where(enterprise_id: search_params[:distributor_id].to_i) end render json: @customers, each_serializer: ::Api::Admin::CustomerSerializer end @@ -31,13 +31,17 @@ def customers def ransack_hash { m: 'or', - email_start: params[:q], - ship_address_firstname_start: params[:q], - ship_address_lastname_start: params[:q], - bill_address_firstname_start: params[:q], - bill_address_lastname_start: params[:q] + email_start: search_params[:q], + ship_address_firstname_start: search_params[:q], + ship_address_lastname_start: search_params[:q], + bill_address_firstname_start: search_params[:q], + bill_address_lastname_start: search_params[:q] } end + + def search_params + params.permit(:q, :distributor_id).to_h.with_indifferent_access + end end end end From 95b5586f9bf78fe46b3e80a8709181d391a3e434 Mon Sep 17 00:00:00 2001 From: Matt-Yorkley <9029026+Matt-Yorkley@users.noreply.github.com> Date: Sun, 24 Jan 2021 21:49:10 +0000 Subject: [PATCH 31/50] Using strings for keys in FormAdapter spec --- .../checkout/form_data_adapter_spec.rb | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/spec/services/checkout/form_data_adapter_spec.rb b/spec/services/checkout/form_data_adapter_spec.rb index fdd6085d4ca..30aaab21384 100644 --- a/spec/services/checkout/form_data_adapter_spec.rb +++ b/spec/services/checkout/form_data_adapter_spec.rb @@ -4,23 +4,23 @@ describe Checkout::FormDataAdapter do describe '#params' do - let(:params) { { order: { order_id: "123" } } } + let(:params) { { "order" => { "order_id" => "123" } } } let(:order) { create(:order) } let(:user) { create(:user) } let(:adapter) { Checkout::FormDataAdapter.new(params, order, user) } it "returns the :order item in the params provided" do - expect(adapter.params[:order]).to eq params[:order] + expect(adapter.params[:order]).to eq params["order"] end describe "when payment_attributes are provided" do - before { params[:order][:payments_attributes] = [{ payment_method_id: "123" }] } + before { params["order"]["payments_attributes"] = [{ "payment_method_id" => "123" }] } describe "and source attributes are provided" do - let(:source_attributes) { { payment_method_name: "Pay at the farm" } } + let(:source_attributes) { { "payment_method_name" => "Pay at the farm" } } - before { params[:payment_source] = { "123" => source_attributes } } + before { params["payment_source"] = { "123" => source_attributes } } it "moves payment source attributes to the order payment attributes" do expect(adapter.params[:order][:payments_attributes]. @@ -38,7 +38,8 @@ describe "and a credit card is provided" do before do - params[:order][:payments_attributes].first[:source_attributes] = { number: "4444333322221111" } + params["order"]["payments_attributes"].first["source_attributes"] = + { "number" => "4444333322221111" } end it "fills in missing credit card brand" do @@ -46,23 +47,23 @@ end it "leaves an existing credit card brand" do - params[:order][:payments_attributes].first[:source_attributes][:cc_type] = "test" + params["order"]["payments_attributes"].first["source_attributes"]["cc_type"] = "test" expect(adapter.params[:order][:payments_attributes].first[:source_attributes][:cc_type]).to eq "test" end it "doesn't touch the credit card brand without a number" do - params[:order][:payments_attributes].first[:source_attributes][:number] = "" + params["order"]["payments_attributes"].first["source_attributes"]["number"] = "" expect(adapter.params[:order][:payments_attributes].first[:source_attributes].key?(:cc_type)).to eq false end end describe "and existing credit card is provided" do - before { params[:order][:existing_card_id] = credit_card.id } + before { params["order"]["existing_card_id"] = credit_card.id } describe "and credit card is owned by current user" do let(:credit_card) { create(:credit_card, user_id: user.id) } - before { params[:order][:existing_card_id] = credit_card.id } + before { params["order"]["existing_card_id"] = credit_card.id } it "adds card details to payment attributes" do expect(adapter.params[:order][:payments_attributes].first[:source][:id]).to eq credit_card.id From aea8d1dc99a0cf2bab0ef054f954bc95b169168b Mon Sep 17 00:00:00 2001 From: Matt-Yorkley <9029026+Matt-Yorkley@users.noreply.github.com> Date: Sun, 24 Jan 2021 22:21:28 +0000 Subject: [PATCH 32/50] Fix appending to Relation in in EnterpriseFeesController --- app/controllers/admin/enterprise_fees_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/admin/enterprise_fees_controller.rb b/app/controllers/admin/enterprise_fees_controller.rb index 73880badf47..992918d26e0 100644 --- a/app/controllers/admin/enterprise_fees_controller.rb +++ b/app/controllers/admin/enterprise_fees_controller.rb @@ -10,7 +10,7 @@ def index blank_enterprise_fee = EnterpriseFee.new blank_enterprise_fee.enterprise = current_enterprise - 3.times { @collection << blank_enterprise_fee } + 3.times { @collection.to_a << blank_enterprise_fee } respond_to do |format| format.html From 3748d92bc846dae3f8c11bf1a7736d1b0ea64d69 Mon Sep 17 00:00:00 2001 From: Matt-Yorkley <9029026+Matt-Yorkley@users.noreply.github.com> Date: Sun, 24 Jan 2021 22:30:10 +0000 Subject: [PATCH 33/50] Fix modifying taxons in ShopsCaching spec This was triggering an error via the callback Spree::Product#remove_previous_primary_taxon_from_taxons --- spec/features/consumer/caching/shops_caching_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/features/consumer/caching/shops_caching_spec.rb b/spec/features/consumer/caching/shops_caching_spec.rb index 6f718687531..f9684c2378a 100644 --- a/spec/features/consumer/caching/shops_caching_spec.rb +++ b/spec/features/consumer/caching/shops_caching_spec.rb @@ -73,7 +73,7 @@ expect(page).to have_content taxon.name expect(page).to have_content property.presentation - product.update_attribute(:taxons, [taxon2]) + product.taxons << taxon2 product.update_attribute(:primary_taxon, taxon2) product.update_attribute(:properties, [property2]) From 9e83cb65dba56c9d417ee4beb0e04e781bec9924 Mon Sep 17 00:00:00 2001 From: Matt-Yorkley <9029026+Matt-Yorkley@users.noreply.github.com> Date: Sun, 24 Jan 2021 22:51:20 +0000 Subject: [PATCH 34/50] Set concurrency spec to pending It's not working at all in Rails 5. There's new concurrency modules in Rails 5, we should investigate them... --- spec/controllers/checkout_controller_concurrency_spec.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/spec/controllers/checkout_controller_concurrency_spec.rb b/spec/controllers/checkout_controller_concurrency_spec.rb index 061fd8deaea..0804bc74923 100644 --- a/spec/controllers/checkout_controller_concurrency_spec.rb +++ b/spec/controllers/checkout_controller_concurrency_spec.rb @@ -44,7 +44,10 @@ allow(controller).to receive(:current_order_cycle).and_return(order.order_cycle) end - it "handles two concurrent orders successfully" do + # This spec does not seem to be running in two threads in Rails 5. There are errors for the + # same response headers being set twice, possibly indicating that there is only one response + # as opposed to two separate requests in two threads? + xit "handles two concurrent orders successfully" do # New threads start running straight away. The breakpoint is after loading # the order and before advancing the order's state and making payments. breakpoint.lock From c2c8dbfb38a8feca521f776203e2c70f3ca9ec7b Mon Sep 17 00:00:00 2001 From: Matt-Yorkley <9029026+Matt-Yorkley@users.noreply.github.com> Date: Sun, 24 Jan 2021 23:16:40 +0000 Subject: [PATCH 35/50] Add strong params in Api::ExchangeProductsController and deal with boolean issue --- .../api/exchange_products_controller.rb | 21 ++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/app/controllers/api/exchange_products_controller.rb b/app/controllers/api/exchange_products_controller.rb index 5b2e0f154de..e1821b36b3e 100644 --- a/app/controllers/api/exchange_products_controller.rb +++ b/app/controllers/api/exchange_products_controller.rb @@ -18,7 +18,7 @@ class ExchangeProductsController < Api::BaseController # In this case parameters are: enterprise_id, order_cycle_id and incoming # (order_cycle_id is not necessary for incoming exchanges) def index - if params[:exchange_id].present? + if exchange_params[:exchange_id].present? load_data_from_exchange else load_data_from_other_params @@ -59,7 +59,7 @@ def paginated_products end def load_data_from_exchange - exchange = Exchange.find_by(id: params[:exchange_id]) + exchange = Exchange.find_by(id: exchange_params[:exchange_id]) @order_cycle = exchange.order_cycle @incoming = exchange.incoming @@ -67,14 +67,16 @@ def load_data_from_exchange end def load_data_from_other_params - @enterprise = Enterprise.find_by(id: params[:enterprise_id]) + @enterprise = Enterprise.find_by(id: exchange_params[:enterprise_id]) - if params[:order_cycle_id] - @order_cycle = OrderCycle.find_by(id: params[:order_cycle_id]) - elsif !params[:incoming] + # This will be a string (eg "true") when it arrives via params, but we want a boolean + @incoming = ActiveModel::Type::Boolean.new.cast exchange_params[:incoming] + + if exchange_params[:order_cycle_id] + @order_cycle = OrderCycle.find_by(id: exchange_params[:order_cycle_id]) + elsif !@incoming raise "order_cycle_id is required to list products for new outgoing exchange" end - @incoming = params[:incoming] end def render_paginated_products(paginated_products) @@ -89,5 +91,10 @@ def render_paginated_products(paginated_products) pagination: pagination_data(paginated_products) } end + + def exchange_params + params.permit(:enterprise_id, :exchange_id, :order_cycle_id, :incoming). + to_h.with_indifferent_access + end end end From bbbce4e6c92c243070274d4ea73ffcbf2627ab2f Mon Sep 17 00:00:00 2001 From: Matt-Yorkley <9029026+Matt-Yorkley@users.noreply.github.com> Date: Wed, 3 Feb 2021 20:47:05 +0000 Subject: [PATCH 36/50] Fix params issues in Api::EnterprisesController --- app/controllers/api/enterprises_controller.rb | 23 ++++++++++--------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/app/controllers/api/enterprises_controller.rb b/app/controllers/api/enterprises_controller.rb index 1c7c567ef89..dfbde81f312 100644 --- a/app/controllers/api/enterprises_controller.rb +++ b/app/controllers/api/enterprises_controller.rb @@ -11,7 +11,7 @@ def create # params[:user_ids] breaks the enterprise creation # We remove them from params and save them after creating the enterprise - user_ids = params[:enterprise].delete(:user_ids) + user_ids = enterprise_params.delete(:user_ids) @enterprise = Enterprise.new(enterprise_params) if @enterprise.save @enterprise.user_ids = user_ids @@ -48,30 +48,31 @@ def update_image private def override_owner - params[:enterprise][:owner_id] = current_api_user.id + enterprise_params[:owner_id] = current_api_user.id end def check_type - params[:enterprise].delete :type unless current_api_user.admin? + enterprise_params.delete :type unless current_api_user.admin? end def override_sells has_hub = current_api_user.owned_enterprises.is_hub.any? - new_enterprise_is_producer = !!params[:enterprise][:is_primary_producer] + new_enterprise_is_producer = !!enterprise_params[:is_primary_producer] - params[:enterprise][:sells] = if has_hub && !new_enterprise_is_producer - 'any' - else - 'unspecified' - end + enterprise_params[:sells] = if has_hub && !new_enterprise_is_producer + 'any' + else + 'unspecified' + end end def override_visible - params[:enterprise][:visible] = false + enterprise_params[:visible] = false end def enterprise_params - PermittedAttributes::Enterprise.new(params).call + @enterprise_params ||= PermittedAttributes::Enterprise.new(params).call. + to_h.with_indifferent_access end end end From 64b52527fdc3ac4179b5b72e2664980660cc4a41 Mon Sep 17 00:00:00 2001 From: Matt-Yorkley <9029026+Matt-Yorkley@users.noreply.github.com> Date: Wed, 3 Feb 2021 22:04:39 +0000 Subject: [PATCH 37/50] Fix params issues in Admin::SubsciptionsController --- .../admin/subscriptions_controller.rb | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/app/controllers/admin/subscriptions_controller.rb b/app/controllers/admin/subscriptions_controller.rb index 298d74b8762..aa1fd18db34 100644 --- a/app/controllers/admin/subscriptions_controller.rb +++ b/app/controllers/admin/subscriptions_controller.rb @@ -105,22 +105,22 @@ def load_form_data # Wrap :subscription_line_items_attributes in :subscription root def wrap_nested_attrs - if params[:subscription_line_items].is_a? Array - attributes = params[:subscription_line_items].map do |sli| + if raw_params[:subscription_line_items].is_a? Array + attributes = raw_params[:subscription_line_items].map do |sli| sli.slice(*SubscriptionLineItem.attribute_names + ["_destroy"]) end - params[:subscription][:subscription_line_items_attributes] = attributes + subscription_params[:subscription_line_items_attributes] = attributes end wrap_bill_address_attrs if params[:bill_address] wrap_ship_address_attrs if params[:ship_address] end def wrap_bill_address_attrs - params[:subscription][:bill_address_attributes] = params[:bill_address].slice(*Spree::Address.attribute_names) + subscription_params[:bill_address_attributes] = raw_params[:bill_address].slice(*Spree::Address.attribute_names) end def wrap_ship_address_attrs - params[:subscription][:ship_address_attributes] = params[:ship_address].slice(*Spree::Address.attribute_names) + subscription_params[:ship_address_attributes] = raw_params[:ship_address].slice(*Spree::Address.attribute_names) end def check_for_open_orders @@ -140,8 +140,8 @@ def check_for_canceled_orders end def strip_banned_attrs - params[:subscription].delete :schedule_id - params[:subscription].delete :customer_id + subscription_params.delete :schedule_id + subscription_params.delete :customer_id end # Overriding Spree method to load data from params here so that @@ -155,7 +155,8 @@ def ams_prefix_whitelist end def subscription_params - @subscription_params ||= PermittedAttributes::Subscription.new(params).call + @subscription_params ||= PermittedAttributes::Subscription.new(params).call. + to_h.with_indifferent_access end end end From 4c2871e57211d6ae19288892a5100a2985a3c100 Mon Sep 17 00:00:00 2001 From: Matt-Yorkley <9029026+Matt-Yorkley@users.noreply.github.com> Date: Wed, 3 Feb 2021 23:57:16 +0000 Subject: [PATCH 38/50] Refactor and fix params issues in Admin::OrderCyclesController --- .../admin/order_cycles_controller.rb | 22 ++++++++----------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/app/controllers/admin/order_cycles_controller.rb b/app/controllers/admin/order_cycles_controller.rb index d4ba8d0b1a8..56c317f0fb8 100644 --- a/app/controllers/admin/order_cycles_controller.rb +++ b/app/controllers/admin/order_cycles_controller.rb @@ -210,23 +210,19 @@ def remove_protected_attrs end end - def remove_unauthorized_bulk_attrs - (order_cycle_params.dig(:order_cycle_set, :collection_attributes) || []).each do |i, hash| + def authorized_order_cycles + managed_ids = managed_enterprises.map(&:id) + + (order_cycle_bulk_params[:collection_attributes] || []).keep_if do |_index, hash| order_cycle = OrderCycle.find(hash[:id]) - unless Enterprise.managed_by(spree_current_user).include?(order_cycle.andand.coordinator) - order_cycle_params[:order_cycle_set][:collection_attributes].delete i - end + managed_ids.include?(order_cycle.andand.coordinator_id) end end def order_cycles_from_set - remove_unauthorized_bulk_attrs - collection_attributes = order_cycle_params.dig(:order_cycle_set, :collection_attributes) - return if collection_attributes.blank? + return if authorized_order_cycles.blank? - OrderCycle.where( - id: collection_attributes.map{ |_k, v| v[:id] } - ) + OrderCycle.where(id: authorized_order_cycles.map{ |_k, v| v[:id] }) end def order_cycle_set @@ -234,7 +230,7 @@ def order_cycle_set end def require_order_cycle_set_params - return if order_cycle_params[:order_cycle_set] + return if params[:order_cycle_set].present? render json: { errors: t('admin.order_cycles.bulk_update.no_data') }, status: :unprocessable_entity @@ -252,7 +248,7 @@ def order_cycle_params def order_cycle_bulk_params params.require(:order_cycle_set).permit( collection_attributes: [:id] + PermittedAttributes::OrderCycle.basic_attributes - ) + ).to_h.with_indifferent_access end end end From 4542a3464ef765bfd565f00c9ff144423e478aa9 Mon Sep 17 00:00:00 2001 From: Matt-Yorkley <9029026+Matt-Yorkley@users.noreply.github.com> Date: Fri, 5 Feb 2021 14:55:39 +0000 Subject: [PATCH 39/50] Fix params in Admin::ProductsController --- .../spree/admin/products_controller.rb | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/app/controllers/spree/admin/products_controller.rb b/app/controllers/spree/admin/products_controller.rb index 89361465a91..17244f2a90c 100644 --- a/app/controllers/spree/admin/products_controller.rb +++ b/app/controllers/spree/admin/products_controller.rb @@ -75,12 +75,12 @@ def update end def bulk_update - product_set = product_set_from_params(params) + product_set = product_set_from_params product_set.collection.each { |p| authorize! :update, p } if product_set.save - redirect_to main_app.bulk_products_api_products_path( bulk_index_query(params) ) + redirect_to main_app.bulk_products_api_products_path(bulk_index_query) elsif product_set.errors.present? render json: { errors: product_set.errors }, status: :bad_request else @@ -161,15 +161,14 @@ def collection_actions private - def product_set_from_params(_params) - collection_hash = Hash[products_params.each_with_index.map { |p, i| [i, p] }] + def product_set_from_params + collection_hash = Hash[products_bulk_params[:products].each_with_index.map { |p, i| [i, p] }] Sets::ProductSet.new(collection_attributes: collection_hash) end - def products_params - params.require(:products).map do |product| - product.permit(::PermittedAttributes::Product.attributes) - end + def products_bulk_params + params.permit(products: ::PermittedAttributes::Product.attributes). + to_h.with_indifferent_access end def permitted_resource_params @@ -178,8 +177,8 @@ def permitted_resource_params params.require(:product).permit(::PermittedAttributes::Product.attributes) end - def bulk_index_query(params) - (params[:filters] || {}).merge(page: params[:page], per_page: params[:per_page]) + def bulk_index_query + (raw_params[:filters] || {}).merge(page: raw_params[:page], per_page: raw_params[:per_page]) end def load_form_data From c827d772363f98fb155347f19d2c5fee938587a1 Mon Sep 17 00:00:00 2001 From: Matt-Yorkley <9029026+Matt-Yorkley@users.noreply.github.com> Date: Fri, 5 Feb 2021 15:42:05 +0000 Subject: [PATCH 40/50] Fix reloading completed_order_with_fees factory --- spec/factories/order_factory.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/spec/factories/order_factory.rb b/spec/factories/order_factory.rb index 378251bda6e..7e75d7a05fe 100644 --- a/spec/factories/order_factory.rb +++ b/spec/factories/order_factory.rb @@ -218,6 +218,7 @@ order.reload while !order.completed? do break unless order.next! end + order.reload end end end From 25139178b587f181fa0a22bb9835b35bdb214765 Mon Sep 17 00:00:00 2001 From: Matt-Yorkley <9029026+Matt-Yorkley@users.noreply.github.com> Date: Fri, 5 Feb 2021 16:29:20 +0000 Subject: [PATCH 41/50] Fix appending to collection (take 2) --- app/controllers/admin/enterprise_fees_controller.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/controllers/admin/enterprise_fees_controller.rb b/app/controllers/admin/enterprise_fees_controller.rb index 992918d26e0..f506dfa0935 100644 --- a/app/controllers/admin/enterprise_fees_controller.rb +++ b/app/controllers/admin/enterprise_fees_controller.rb @@ -10,7 +10,9 @@ def index blank_enterprise_fee = EnterpriseFee.new blank_enterprise_fee.enterprise = current_enterprise - 3.times { @collection.to_a << blank_enterprise_fee } + + @collection = @collection.to_a + 3.times { @collection << blank_enterprise_fee } respond_to do |format| format.html From 8d8df447c6908cc2483d8cd003370d567bc46192 Mon Sep 17 00:00:00 2001 From: Matt-Yorkley <9029026+Matt-Yorkley@users.noreply.github.com> Date: Tue, 9 Feb 2021 10:49:30 +0000 Subject: [PATCH 42/50] Remove debugging --- spec/models/enterprise_caching_spec.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/spec/models/enterprise_caching_spec.rb b/spec/models/enterprise_caching_spec.rb index bfd241227ec..01c14980461 100644 --- a/spec/models/enterprise_caching_spec.rb +++ b/spec/models/enterprise_caching_spec.rb @@ -16,7 +16,6 @@ let(:producer_property) { enterprise.producer_properties.last } before do - pp enterprise.updated_at product.set_property 'Organic', 'NASAA 12345' enterprise.set_producer_property 'Biodynamic', 'ASDF 4321' end From 7924865ff8a0d4ff2cda57d86bacfbe1d9996648 Mon Sep 17 00:00:00 2001 From: Matt-Yorkley <9029026+Matt-Yorkley@users.noreply.github.com> Date: Tue, 9 Feb 2021 11:13:21 +0000 Subject: [PATCH 43/50] Set clearer version --- Gemfile | 2 +- Gemfile.lock | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Gemfile b/Gemfile index 5b3dc70f9b5..c332cac4ab4 100644 --- a/Gemfile +++ b/Gemfile @@ -4,7 +4,7 @@ source 'https://rubygems.org' ruby "2.4.4" git_source(:github) { |repo_name| "https://github.com/#{repo_name}.git" } -gem 'rails', '> 5.0', '< 5.1' +gem 'rails', '~> 5.0.0' gem 'activemerchant', '>= 1.78.0' gem 'angular-rails-templates', '>= 0.3.0' diff --git a/Gemfile.lock b/Gemfile.lock index 9b98f71dc44..85b0e5303cd 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -636,7 +636,7 @@ DEPENDENCIES rack-mini-profiler (< 3.0.0) rack-rewrite rack-ssl - rails (> 5.0, < 5.1) + rails (~> 5.0.0) rails-controller-testing rails-i18n rails_safe_tasks (~> 1.0) From 6c00fe44ae411e73d6c0f60749647c8f64afae2d Mon Sep 17 00:00:00 2001 From: Matt-Yorkley <9029026+Matt-Yorkley@users.noreply.github.com> Date: Sat, 13 Feb 2021 16:11:49 +0000 Subject: [PATCH 44/50] Revert order permissions changes --- app/services/permissions/order.rb | 32 ++++++++++++------------------- 1 file changed, 12 insertions(+), 20 deletions(-) diff --git a/app/services/permissions/order.rb b/app/services/permissions/order.rb index f71e46024f0..8dbbca41bef 100644 --- a/app/services/permissions/order.rb +++ b/app/services/permissions/order.rb @@ -63,36 +63,28 @@ def visible_orders_where_values # Any orders placed through any hub that I manage def managed_orders_where_values - query = Spree::Order. - where(distributor_id: @permissions.managed_enterprises.select("enterprises.id")) - - apply_where_clause(query).reduce(:and) + Spree::Order. + where(distributor_id: @permissions.managed_enterprises.select("enterprises.id")). + where_clause.__send__(:predicates). + reduce(:and) end # Any order that is placed through an order cycle one of my managed enterprises coordinates def coordinated_orders_where_values - query = Spree::Order. - where(order_cycle_id: @permissions.coordinated_order_cycles.select(:id)) - - apply_where_clause(query).reduce(:and) + Spree::Order. + where(order_cycle_id: @permissions.coordinated_order_cycles.select(:id)). + where_clause.__send__(:predicates). + reduce(:and) end def produced_orders_where_values - query = Spree::Order.with_line_items_variants_and_products_outer. + Spree::Order.with_line_items_variants_and_products_outer. where( distributor_id: granted_distributor_ids, spree_products: { supplier_id: enterprises_with_associated_orders } - ) - - apply_where_clause(query).reduce(:and) - end - - def apply_where_clause(query) - if ENV['DEPENDENCIES_NEXT'] - query.where_clause.__send__(:predicates) - else - query.where_values - end + ). + where_clause.__send__(:predicates). + reduce(:and) end def enterprises_with_associated_orders From 096b693461cb6fc73f8b360868754b8b7be6f385 Mon Sep 17 00:00:00 2001 From: Matt-Yorkley <9029026+Matt-Yorkley@users.noreply.github.com> Date: Sat, 13 Feb 2021 17:13:45 +0000 Subject: [PATCH 45/50] Update Gemfile.lock --- Gemfile.lock | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 85b0e5303cd..a7fedccba35 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -232,7 +232,7 @@ GEM good_migrations (0.0.2) activerecord (>= 3.1) railties (>= 3.1) - haml (5.2.0) + haml (5.2.1) temple (>= 0.8.0) tilt hashdiff (1.0.1) @@ -481,11 +481,10 @@ GEM rubyzip (>= 1.2.2) shoulda-matchers (4.5.1) activesupport (>= 4.2.0) - simplecov (0.17.1) + simplecov (0.18.5) docile (~> 1.1) - json (>= 1.8, < 3) - simplecov-html (~> 0.10.0) - simplecov-html (0.10.2) + simplecov-html (~> 0.11) + simplecov-html (0.12.3) sinatra (2.1.0) mustermann (~> 1.0) rack (~> 2.2) From 7bc63e6e815eb5e1ee7d7e8f370783f8d44d2c54 Mon Sep 17 00:00:00 2001 From: Matt-Yorkley <9029026+Matt-Yorkley@users.noreply.github.com> Date: Mon, 15 Feb 2021 18:23:50 +0000 Subject: [PATCH 46/50] Re-add db2fog Turns out it works with Rails 5 --- Gemfile | 2 ++ Gemfile.lock | 30 ++++++++++++++++++++++++++++++ config/initializers/db2fog.rb | 15 +++++++++++++++ 3 files changed, 47 insertions(+) create mode 100644 config/initializers/db2fog.rb diff --git a/Gemfile b/Gemfile index c332cac4ab4..80f4e20c3e4 100644 --- a/Gemfile +++ b/Gemfile @@ -20,6 +20,8 @@ gem 'rails-i18n' gem 'rails_safe_tasks', '~> 1.0' gem "activerecord-import" +gem "db2fog", github: "openfoodfoundation/db2fog", branch: "rails-5" +gem "fog-aws", ">= 0.6.0" gem "catalog", path: "./engines/catalog" gem 'dfc_provider', path: './engines/dfc_provider' diff --git a/Gemfile.lock b/Gemfile.lock index a7fedccba35..e3d7d1e8ca3 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -4,6 +4,16 @@ GIT specs: custom_error_message (1.1.1) +GIT + remote: https://github.com/openfoodfoundation/db2fog.git + revision: 8ceef362c64e6573d62d26db5ebb0c0f33cd3d61 + branch: rails-5 + specs: + db2fog (0.9.1) + activerecord (>= 3.2.0, < 6.0) + fog-core (~> 1.0) + rails (>= 3.2.0, < 6.0) + GIT remote: https://github.com/openfoodfoundation/ofn-qz.git revision: 467f6ea1c44529c7c91cac4c8211bbd863588c0b @@ -202,6 +212,7 @@ GEM docile (1.3.4) erubis (2.7.0) eventmachine (1.2.7) + excon (0.79.0) execjs (2.7.0) factory_bot (5.2.0) activesupport (>= 4.2.0) @@ -214,6 +225,22 @@ GEM ffi (1.13.1) figaro (1.2.0) thor (>= 0.14.0, < 2) + fog-aws (2.0.1) + fog-core (~> 1.38) + fog-json (~> 1.0) + fog-xml (~> 0.1) + ipaddress (~> 0.8) + fog-core (1.45.0) + builder + excon (~> 0.58) + formatador (~> 0.2) + fog-json (1.2.0) + fog-core + multi_json (~> 1.10) + fog-xml (0.1.3) + fog-core + nokogiri (>= 1.5.11, < 2.0.0) + formatador (0.2.5) foundation-icons-sass-rails (3.0.0) railties (>= 3.1.1) sass-rails (>= 3.1.1) @@ -243,6 +270,7 @@ GEM i18n (>= 0.6.6) immigrant (0.3.6) activerecord (>= 3.0) + ipaddress (0.8.3) jquery-migrate-rails (1.2.1) jquery-rails (4.4.0) rails-dom-testing (>= 1, < 3) @@ -588,6 +616,7 @@ DEPENDENCIES daemons dalli database_cleaner + db2fog! ddtrace debugger-linecache delayed_job_active_record @@ -600,6 +629,7 @@ DEPENDENCIES factory_bot_rails (= 5.2.0) ffaker figaro + fog-aws (>= 0.6.0) foundation-icons-sass-rails foundation-rails (= 5.5.2.1) fuubar (~> 2.5.1) diff --git a/config/initializers/db2fog.rb b/config/initializers/db2fog.rb new file mode 100644 index 00000000000..ba5b9c7e1d9 --- /dev/null +++ b/config/initializers/db2fog.rb @@ -0,0 +1,15 @@ +require_relative 'spree' + +# See: https://github.com/itbeaver/db2fog +DB2Fog.config = { + :aws_access_key_id => Spree::Config[:s3_access_key], + :aws_secret_access_key => Spree::Config[:s3_secret], + :directory => ENV['S3_BACKUPS_BUCKET'], + :provider => 'AWS' +} + +region = ENV['S3_BACKUPS_REGION'] || ENV['S3_REGION'] + +# If no region is defined we leave this config key undefined (instead of nil), +# so that db2fog correctly applies it's default +DB2Fog.config[:region] = region if region From 04a13a4f6f4c6da2009d2977f6312867e9b066cf Mon Sep 17 00:00:00 2001 From: Matt-Yorkley <9029026+Matt-Yorkley@users.noreply.github.com> Date: Tue, 23 Feb 2021 11:25:30 +0000 Subject: [PATCH 47/50] Update Boolean typecasting to Rails 5 version --- app/controllers/spree/admin/tax_rates_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/spree/admin/tax_rates_controller.rb b/app/controllers/spree/admin/tax_rates_controller.rb index cd261ec718a..9e75426b93b 100644 --- a/app/controllers/spree/admin/tax_rates_controller.rb +++ b/app/controllers/spree/admin/tax_rates_controller.rb @@ -18,7 +18,7 @@ def requires_transition? end def included_changed? - ActiveRecord::Type::Boolean.new.type_cast_from_user( + ActiveRecord::Type::Boolean.new.cast( permitted_resource_params[:included_in_price] ) != @tax_rate.included_in_price end From ac37db7e00788e90f3d17b0f0381ebec9319276e Mon Sep 17 00:00:00 2001 From: Matt-Yorkley <9029026+Matt-Yorkley@users.noreply.github.com> Date: Tue, 23 Feb 2021 13:34:11 +0000 Subject: [PATCH 48/50] Update test setup in OrderCycleManagement report --- .../order_cycle_management_report_spec.rb | 33 +++++-------------- 1 file changed, 9 insertions(+), 24 deletions(-) diff --git a/spec/lib/open_food_network/order_cycle_management_report_spec.rb b/spec/lib/open_food_network/order_cycle_management_report_spec.rb index 7e31c66e3cc..7e6afa240b2 100644 --- a/spec/lib/open_food_network/order_cycle_management_report_spec.rb +++ b/spec/lib/open_food_network/order_cycle_management_report_spec.rb @@ -164,11 +164,9 @@ module OpenFoodNetwork let!(:order) do create( - :order, + :completed_order_with_totals, distributor: distributor, - completed_at: 1.day.ago, - state: 'complete', - total: 10.0 + completed_at: 1.day.ago ) end @@ -180,50 +178,37 @@ module OpenFoodNetwork '', order.email, order.billing_address.phone, + order.shipment.shipping_method.name, nil, nil, - nil, - -10.0 + -order.total ]]) end end context 'when the report type is not payment_methods' do let(:params) { {} } - - let(:shipping_method) { create(:shipping_method) } - let(:shipment) { create(:shipment_with, :shipping_method, shipping_method: shipping_method) } - let!(:order) do create( - :order, + :completed_order_with_totals, distributor: distributor, - completed_at: 1.day.ago, - shipments: [shipment] + completed_at: 1.day.ago ) end - before do - line_item = create(:line_item, order: order, price: 10.0, quantity: 1) - - order.state = 'complete' - order.ship_address = order.address_from_distributor - order.save! - end - it 'returns rows with delivery information' do expect(subject.table_items).to eq([[ order.ship_address.firstname, order.ship_address.lastname, order.distributor.name, - nil, + "", "#{order.ship_address.address1} #{order.ship_address.address2} #{order.ship_address.city}", order.ship_address.zipcode, order.ship_address.phone, - shipping_method.name, + order.shipment.shipping_method.name, nil, nil, - -10.0, + -order.total, false, order.special_instructions ]]) From 6bb85e9acde5107543ebb9f4f7c954624c4081b9 Mon Sep 17 00:00:00 2001 From: Matt-Yorkley <9029026+Matt-Yorkley@users.noreply.github.com> Date: Thu, 4 Mar 2021 18:29:20 +0000 Subject: [PATCH 49/50] Fix payment and shipment states issue For some reason the order objects were stale here when calling order.update! from either a payment or shipment callback, which was overwriting those states as nil on the order. --- app/models/spree/payment.rb | 3 +-- app/models/spree/shipment.rb | 2 +- spec/features/consumer/shopping/checkout_spec.rb | 4 ++++ spec/models/spree/shipment_spec.rb | 2 +- 4 files changed, 7 insertions(+), 4 deletions(-) diff --git a/app/models/spree/payment.rb b/app/models/spree/payment.rb index 0896defdc36..e45730583b7 100644 --- a/app/models/spree/payment.rb +++ b/app/models/spree/payment.rb @@ -199,8 +199,7 @@ def invalidate_old_payments end def update_order - order.payments.reload - order.update! + order.reload.update! end # Necessary because some payment gateways will refuse payments with diff --git a/app/models/spree/shipment.rb b/app/models/spree/shipment.rb index bf4d9815f1c..173c3bebe81 100644 --- a/app/models/spree/shipment.rb +++ b/app/models/spree/shipment.rb @@ -337,7 +337,7 @@ def update_adjustment_included_tax end def update_order - order.update! + order.reload.update! end end end diff --git a/spec/features/consumer/shopping/checkout_spec.rb b/spec/features/consumer/shopping/checkout_spec.rb index ee739cbe390..20e141e2629 100644 --- a/spec/features/consumer/shopping/checkout_spec.rb +++ b/spec/features/consumer/shopping/checkout_spec.rb @@ -338,6 +338,10 @@ order = Spree::Order.complete.first expect(order.special_instructions).to eq "SpEcIaL NoTeS" + # Shipment and payments states should be set + expect(order.payment_state).to eq "balance_due" + expect(order.shipment_state).to eq "pending" + # And the Spree tax summary should not be displayed expect(page).not_to have_content product.tax_category.name diff --git a/spec/models/spree/shipment_spec.rb b/spec/models/spree/shipment_spec.rb index 0c4f85c4cdb..73599214724 100644 --- a/spec/models/spree/shipment_spec.rb +++ b/spec/models/spree/shipment_spec.rb @@ -425,7 +425,7 @@ context "update_order" do it "should update order" do - expect(order).to receive(:update!) + expect(order).to receive_message_chain(:reload, :update!) shipment.__send__(:update_order) end end From 321da76005bbc94cf24a50d8082fcc942693c1c7 Mon Sep 17 00:00:00 2001 From: Matt-Yorkley <9029026+Matt-Yorkley@users.noreply.github.com> Date: Thu, 4 Mar 2021 19:16:50 +0000 Subject: [PATCH 50/50] Update regression test This error is no longer thrown by the payment object creation --- spec/models/spree/order_spec.rb | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/spec/models/spree/order_spec.rb b/spec/models/spree/order_spec.rb index 4e789af5640..61c492ab514 100644 --- a/spec/models/spree/order_spec.rb +++ b/spec/models/spree/order_spec.rb @@ -1202,20 +1202,11 @@ expect { order.next! }.to change { order.state }.from("delivery").to("payment") end - it "advances to complete state despite error" do + # Regression test for https://github.com/openfoodfoundation/openfoodnetwork/issues/3924 + it "advances to complete state without error" do advance_to_delivery_state(order) - # advance to payment state order.next! - create(:payment, order: order) - # https://github.com/openfoodfoundation/openfoodnetwork/issues/3924 - observed_error = ActiveRecord::RecordNotUnique.new( - "PG::UniqueViolation", - StandardError.new - ) - expect(order.shipment).to receive(:save).and_call_original - expect(order.shipment).to receive(:save).and_call_original - expect(order.shipment).to receive(:save).and_raise(observed_error) expect { order.next! }.to change { order.state }.from("payment").to("complete") end