Skip to content

Commit

Permalink
fix auto_close_and_send_min_quantity
Browse files Browse the repository at this point in the history
  • Loading branch information
paroga committed Oct 12, 2018
1 parent 4eef0f0 commit 4137992
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/models/order.rb
Expand Up @@ -278,7 +278,7 @@ def do_end_action!
send_to_supplier!(created_by)
elsif auto_close_and_send_min_quantity?
finish!(created_by)
send_to_supplier!(created_by) if order.sum >= order.supplier.min_order_quantity
send_to_supplier!(created_by) if sum >= supplier.min_order_quantity.to_r
end
end

Expand Down
8 changes: 8 additions & 0 deletions spec/models/order_spec.rb
Expand Up @@ -16,6 +16,14 @@
expect(order).to be_finished
end

it 'sends mail if min_order_quantity has been reached' do
create :user, groups: [create(:ordergroup)]
create :order, created_by: User.first, starts: Date.yesterday, ends: 1.hour.ago, end_action: :auto_close_and_send_min_quantity

Order.finish_ended!
expect(ActionMailer::Base.deliveries.count).to eq 1
end

it 'needs a supplier' do
expect(build(:order, supplier: nil)).to be_invalid
end
Expand Down

0 comments on commit 4137992

Please sign in to comment.