mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Create a "None" calculator for shipping and payment methods
Only for payment and shipping methods
This commit is contained in:
13
app/models/calculator/none.rb
Normal file
13
app/models/calculator/none.rb
Normal file
@@ -0,0 +1,13 @@
|
||||
# frozen_string_literal: false
|
||||
|
||||
module Calculator
|
||||
class None < Spree::Calculator
|
||||
def self.description
|
||||
I18n.t(:none)
|
||||
end
|
||||
|
||||
def compute(_object = nil)
|
||||
0
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -116,7 +116,8 @@ module Openfoodnetwork
|
||||
Calculator::FlexiRate,
|
||||
Calculator::PerItem,
|
||||
Calculator::PriceSack,
|
||||
Calculator::Weight
|
||||
Calculator::Weight,
|
||||
Calculator::None
|
||||
]
|
||||
|
||||
app.config.spree.calculators.add_class('enterprise_fees')
|
||||
@@ -135,7 +136,8 @@ module Openfoodnetwork
|
||||
Calculator::FlatRate,
|
||||
Calculator::FlexiRate,
|
||||
Calculator::PerItem,
|
||||
Calculator::PriceSack
|
||||
Calculator::PriceSack,
|
||||
Calculator::None
|
||||
]
|
||||
|
||||
app.config.spree.calculators.add_class('tax_rates')
|
||||
|
||||
@@ -251,6 +251,14 @@ describe '
|
||||
let!(:payment_method) { create(:payment_method, calculator: calculator) }
|
||||
before { login_as_admin_and_visit spree.edit_admin_payment_method_path payment_method }
|
||||
|
||||
it "handle the 'None' calculator" do
|
||||
select2_select "None", from: 'calc_type'
|
||||
click_button 'Update'
|
||||
expect(page).to have_content("Payment Method has been successfully updated!")
|
||||
expect(payment_method.reload.calculator_type).to eq "Calculator::None"
|
||||
expect(page).to have_select "calc_type", selected: "None"
|
||||
end
|
||||
|
||||
context "using Flat Percent calculator" do
|
||||
before { select2_select "Flat Percent", from: 'calc_type' }
|
||||
|
||||
|
||||
@@ -83,6 +83,15 @@ describe 'shipping methods' do
|
||||
|
||||
expect(@shipping_method.reload.calculator_type).to eq("Calculator::PerItem")
|
||||
end
|
||||
|
||||
it "handle when updating calculator type to 'None'" do
|
||||
visit spree.edit_admin_shipping_method_path(@shipping_method)
|
||||
|
||||
select2_select 'None', from: 'calc_type'
|
||||
click_button 'Update'
|
||||
|
||||
expect(@shipping_method.reload.calculator_type).to eq "Calculator::None"
|
||||
end
|
||||
end
|
||||
|
||||
context "as an enterprise user", js: true do
|
||||
|
||||
Reference in New Issue
Block a user