Finally presence of distributor and order_cycle in set_distribution step

This commit is contained in:
Jean-Baptiste Bellet
2023-04-18 11:23:29 +02:00
parent 88fa689cbc
commit 0c2d33151a
3 changed files with 26 additions and 0 deletions

View File

@@ -30,6 +30,8 @@ module Spree
on_update
@order.update(order_params)
return unless @order.valid?(:set_distribution_step)
@order.save
redirect_to spree.admin_order_customer_path(@order)
end

View File

@@ -97,6 +97,8 @@ module Spree
validates :email, presence: true,
format: /\A([\w.%+\-']+)@([\w\-]+\.)+(\w{2,})\z/i,
if: :require_email
validates :order_cycle, presence: true, on: :set_distribution_step
validates :distributor, presence: true, on: :set_distribution_step
make_permalink field: :number

View File

@@ -89,6 +89,28 @@ describe '
click_button 'Update'
end
context "can't create an order without selecting a distributor nor an order cycle" do
before do
login_as_admin
visit spree.admin_orders_path
click_link 'New Order'
end
it 'shows error when distributor is not selected' do
click_button 'Next'
expect(page).to have_content "Order cycle can't be blank"
expect(page).to have_content "Distributor can't be blank"
end
it 'shows error when order cycle is not selected' do
select2_select distributor.name, from: 'order_distributor_id'
click_button 'Next'
expect(page).to have_content "Order cycle can't be blank"
end
end
it "can add a product to an existing order" do
login_as_admin
visit spree.edit_admin_order_path(order)