Fix 500 when bulk updating order cycles with no data

This commit is contained in:
Rohan Mitchell
2015-06-30 11:23:13 +10:00
parent d67b34c2bd
commit d0b7a0795d
2 changed files with 14 additions and 6 deletions

View File

@@ -65,8 +65,8 @@ module Admin
end
def bulk_update
@order_cycle_set = OrderCycleSet.new(params[:order_cycle_set])
if @order_cycle_set.save
@order_cycle_set = params[:order_cycle_set] && OrderCycleSet.new(params[:order_cycle_set])
if @order_cycle_set.andand.save
redirect_to main_app.admin_order_cycles_path, :notice => 'Order cycles have been updated.'
else
render :index
@@ -132,10 +132,12 @@ module Admin
end
def remove_unauthorized_bulk_attrs
params[:order_cycle_set][:collection_attributes].each do |i, hash|
order_cycle = OrderCycle.find(hash[:id])
unless Enterprise.managed_by(spree_current_user).include?(order_cycle.andand.coordinator)
params[:order_cycle_set][:collection_attributes].delete i
if params.key? :order_cycle_set
params[:order_cycle_set][:collection_attributes].each do |i, hash|
order_cycle = OrderCycle.find(hash[:id])
unless Enterprise.managed_by(spree_current_user).include?(order_cycle.andand.coordinator)
params[:order_cycle_set][:collection_attributes].delete i
end
end
end
end

View File

@@ -75,6 +75,12 @@ module Admin
expect(oc.orders_open_at.to_date).to eq Date.today - 21.days
expect(oc.orders_close_at.to_date).to eq Date.today + 21.days
end
it "does nothing when no data is supplied" do
expect do
spree_put :bulk_update
end.to change(oc, :orders_open_at).by(0)
end
end
context "when I do not manage the coordinator of an order cycle" do