From 7015cb30c3c765a6728fb35f8d4ce8d164b865d0 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Bellet Date: Tue, 10 Jan 2023 11:38:36 +0100 Subject: [PATCH] Calculator 'None' is the default one for both shipping and payment method + update specs as well Update shipping_method.rb --- app/models/spree/payment_method.rb | 2 +- app/models/spree/shipping_method.rb | 6 ++++++ spec/system/admin/payment_method_spec.rb | 11 ++++++++--- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/app/models/spree/payment_method.rb b/app/models/spree/payment_method.rb index d09c3c7c4c..f90a526f7c 100644 --- a/app/models/spree/payment_method.rb +++ b/app/models/spree/payment_method.rb @@ -113,7 +113,7 @@ module Spree end def init - self.calculator ||= ::Calculator::FlatRate.new(preferred_amount: 0) + self.calculator ||= ::Calculator::None.new end def has_distributor?(distributor) diff --git a/app/models/spree/shipping_method.rb b/app/models/spree/shipping_method.rb index 589bc8ce8c..9c568fcd21 100644 --- a/app/models/spree/shipping_method.rb +++ b/app/models/spree/shipping_method.rb @@ -32,6 +32,8 @@ module Spree validate :at_least_one_shipping_category validates :display_on, inclusion: { in: DISPLAY_ON_OPTIONS.values }, allow_nil: true + after_initialize :init + after_save :touch_distributors scope :managed_by, lambda { |user| @@ -110,6 +112,10 @@ module Spree where(display_on: [nil, ""]) end + def init + self.calculator ||= ::Calculator::None.new + end + private def no_active_or_upcoming_order_cycle_distributors_with_only_one_shipping_method? diff --git a/spec/system/admin/payment_method_spec.rb b/spec/system/admin/payment_method_spec.rb index 6210f6b72e..55b2a412ec 100644 --- a/spec/system/admin/payment_method_spec.rb +++ b/spec/system/admin/payment_method_spec.rb @@ -247,10 +247,13 @@ describe ' end describe "Setting transaction fees", js: true do - let(:calculator) { build(:calculator) } - let!(:payment_method) { create(:payment_method, calculator: calculator) } + let!(:payment_method) { create(:payment_method) } before { login_as_admin_and_visit spree.edit_admin_payment_method_path payment_method } + it "set by default 'None' as calculator" do + expect(page).to have_select "calc_type", selected: "None" + end + it "handle the 'None' calculator" do select2_select "None", from: 'calc_type' click_button 'Update' @@ -273,9 +276,11 @@ describe ' end context "using Flat Rate (per order) calculator" do - # flat rate per order is the default calculator; no need select it and update page + before { select2_select "Flat Rate (per order)", from: 'calc_type' } it "inserts values which persist" do + expect(page).to have_content("you must save first before") + click_button 'Update' fill_in "Amount", with: 2.2 click_button 'Update' expect(page).to have_content("Payment Method has been successfully updated!")