diff --git a/app/controllers/admin/order_cycles_controller.rb b/app/controllers/admin/order_cycles_controller.rb index 4974b44891..6eef8e5a09 100644 --- a/app/controllers/admin/order_cycles_controller.rb +++ b/app/controllers/admin/order_cycles_controller.rb @@ -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 diff --git a/app/views/admin/order_cycles/index.html.haml b/app/views/admin/order_cycles/index.html.haml index cb20497993..4da96504cd 100644 --- a/app/views/admin/order_cycles/index.html.haml +++ b/app/views/admin/order_cycles/index.html.haml @@ -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' diff --git a/spec/requests/admin/order_cycles_spec.rb b/spec/requests/admin/order_cycles_spec.rb index ea2e2401b5..69debf6378 100644 --- a/spec/requests/admin/order_cycles_spec.rb +++ b/spec/requests/admin/order_cycles_spec.rb @@ -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