Skip to content

Commit

Permalink
Validate presence of distributor and order_cycle in set_distribution …
Browse files Browse the repository at this point in the history
…step
  • Loading branch information
jibees committed Apr 18, 2023
1 parent 88fa689 commit 0e40e1e
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
2 changes: 2 additions & 0 deletions app/controllers/spree/admin/orders_controller.rb
Expand Up @@ -30,6 +30,8 @@ def set_distribution
on_update

@order.update(order_params)
return unless @order.valid?(:set_distribution_step)

@order.save
redirect_to spree.admin_order_customer_path(@order)
end
Expand Down
2 changes: 2 additions & 0 deletions app/models/spree/order.rb
Expand Up @@ -97,6 +97,8 @@ def states
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

Expand Down
22 changes: 22 additions & 0 deletions spec/system/admin/order_spec.rb
Expand Up @@ -89,6 +89,28 @@ def new_order_with_distribution(distributor, order_cycle)
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)
Expand Down

0 comments on commit 0e40e1e

Please sign in to comment.