remember member order when order article is deleted + test

This commit is contained in:
wvengen 2013-09-13 15:37:30 +02:00
parent ee31c0c2af
commit 1bb257c41b
2 changed files with 35 additions and 1 deletions

View file

@ -42,6 +42,14 @@ class Finance::OrderArticlesController < ApplicationController
def destroy def destroy
@order_article = OrderArticle.find(params[:id]) @order_article = OrderArticle.find(params[:id])
# only destroy if there are no associated GroupOrders; if we would, the requested
# quantity and tolerance would be gone. Instead of destroying, we set all result
# quantities to zero.
if @order_article.group_order_articles.count == 0
@order_article.destroy @order_article.destroy
else
@order_article.group_order_articles.each { |goa| goa.update_attribute(:result, 0) }
@order_article.update_results!
end
end end
end end

View file

@ -50,6 +50,32 @@ describe 'settling an order', :type => :feature do
end end
end end
it 'keeps ordered quantities when article is deleted from resulting order' do
within("#order_article_#{oa.id}") do
click_link I18n.t('ui.delete')
page.driver.browser.switch_to.alert.accept
end
expect(page).to_not have_selector("#order_article_#{oa.id}")
expect(OrderArticle.exists?(oa.id)).to be_true
oa.reload
expect(oa.quantity).to eq(4)
expect(oa.tolerance).to eq(0)
expect(oa.units_to_order).to eq(0)
expect(goa1.reload.result).to eq(0)
expect(goa2.reload.result).to eq(0)
end
it 'deletes an OrderArticle with no GroupOrderArticles' do
goa1.destroy
goa2.destroy
within("#order_article_#{oa.id}") do
click_link I18n.t('ui.delete')
page.driver.browser.switch_to.alert.accept
end
expect(page).to_not have_selector("#order_article_#{oa.id}")
expect(OrderArticle.exists?(oa.id)).to be_false
end
end end
end end