Calculator 'None' is the default one for both shipping and payment method

+ update specs as well

Update shipping_method.rb
This commit is contained in:
Jean-Baptiste Bellet
2023-01-10 11:38:36 +01:00
parent a793fc9f99
commit 7015cb30c3
3 changed files with 15 additions and 4 deletions

View File

@@ -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)

View File

@@ -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?

View File

@@ -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!")