Bulk update order cycle opening/closing times

This commit is contained in:
Rohan Mitchell
2012-12-02 15:43:05 +11:00
parent 25a2732253
commit a0c40607ec
3 changed files with 35 additions and 2 deletions

View File

@@ -52,6 +52,14 @@ module Admin
end
end
def bulk_update
@order_cycle_set = OrderCycleSet.new(params[:order_cycle_set])
if @order_cycle_set.save
redirect_to main_app.admin_order_cycles_path, :notice => 'Order cycles have been updated.'
else
render :index
end
end
private

View File

@@ -23,8 +23,8 @@
- order_cycle = order_cycle_form.object
%tr
%td= link_to order_cycle.name, main_app.edit_admin_order_cycle_path(order_cycle)
%td= order_cycle_form.text_field :orders_open_at, :class => 'datepicker', :value => order_cycle.orders_open_at
%td= order_cycle_form.text_field :orders_close_at, :class => 'datepicker', :value => order_cycle.orders_close_at
%td= order_cycle_form.text_field :orders_open_at, :class => 'datetimepicker', :value => order_cycle.orders_open_at
%td= order_cycle_form.text_field :orders_close_at, :class => 'datetimepicker', :value => order_cycle.orders_close_at
%td= order_cycle.coordinator.name
%td
- order_cycle.suppliers.each do |s|
@@ -38,3 +38,4 @@
- order_cycle.variants.each do |v|
= image_tag(v.images.first.attachment.url(:mini)) if v.images.present?
%td
= f.submit 'Update'

View File

@@ -55,4 +55,28 @@ feature %q{
page.should have_selector "input[value='2012-11-13 17:00:00 UTC']"
page.should have_content 'My coordinator'
end
scenario "updating many order cycle opening/closing times at once" do
# Given three order cycles
3.times { create(:order_cycle) }
# When I go to the order cycles page
login_to_admin_section
click_link 'Order Cycles'
# And I fill in some new opening/closing times and save them
fill_in 'order_cycle_set_collection_attributes_0_orders_open_at', :with => '2012-12-01 12:00:00'
fill_in 'order_cycle_set_collection_attributes_0_orders_close_at', :with => '2012-12-01 12:00:01'
fill_in 'order_cycle_set_collection_attributes_1_orders_open_at', :with => '2012-12-01 12:00:02'
fill_in 'order_cycle_set_collection_attributes_1_orders_close_at', :with => '2012-12-01 12:00:03'
fill_in 'order_cycle_set_collection_attributes_2_orders_open_at', :with => '2012-12-01 12:00:04'
fill_in 'order_cycle_set_collection_attributes_2_orders_close_at', :with => '2012-12-01 12:00:05'
click_button 'Update'
# Then my times should have been saved
flash_message.should == 'Order cycles have been updated.'
OrderCycle.all.map { |oc| oc.orders_open_at.sec }.should == [0, 2, 4]
OrderCycle.all.map { |oc| oc.orders_close_at.sec }.should == [1, 3, 5]
end
end