remember what member ordered when deleted in balancing screen

This commit is contained in:
wvengen 2013-09-17 14:19:46 +02:00
parent 1bb257c41b
commit f224735718
2 changed files with 34 additions and 1 deletions

View file

@ -65,7 +65,13 @@ class Finance::GroupOrderArticlesController < ApplicationController
def destroy def destroy
group_order_article = GroupOrderArticle.find(params[:id]) group_order_article = GroupOrderArticle.find(params[:id])
group_order_article.destroy # only destroy if quantity and tolerance was zero already, so that we don't
# lose what the user ordered, if any
if group_order_article.quantity > 0 or group_order_article.tolerance >0
group_order_article.update_attribute(:result, 0)
else
group_order_article.destroy
end
update_summaries(group_order_article) update_summaries(group_order_article)
@order_article = group_order_article.order_article @order_article = group_order_article.order_article

View file

@ -76,6 +76,33 @@ describe 'settling an order', :type => :feature do
expect(OrderArticle.exists?(oa.id)).to be_false expect(OrderArticle.exists?(oa.id)).to be_false
end end
it 'keeps ordered quantities when GroupOrderArticle is deleted from resulting order' do
click_link article.name
expect(page).to have_selector("#group_order_article_#{goa1.id}")
within("#group_order_article_#{goa1.id}") do
click_link I18n.t('ui.delete')
end
expect(page).to_not have_selector("#group_order_article_#{goa1.id}")
expect(OrderArticle.exists?(oa.id)).to be_true
expect(GroupOrderArticle.exists?(goa1.id)).to be_true
goa1.reload
expect(goa1.result).to eq(0)
expect(goa1.quantity).to eq(3)
expect(goa1.tolerance).to eq(0)
end
it 'deletes a GroupOrderArticle with no ordered amounts' do
goa1.update_attributes({:quantity => 0, :tolerance => 0})
click_link article.name
expect(page).to have_selector("#group_order_article_#{goa1.id}")
within("#group_order_article_#{goa1.id}") do
click_link I18n.t('ui.delete')
end
expect(page).to_not have_selector("#group_order_article_#{goa1.id}")
expect(OrderArticle.exists?(oa.id)).to be_true
expect(GroupOrderArticle.exists?(goa1.id)).to be_false
end
end end
end end