diff --git a/app/controllers/admin/order_cycles_controller.rb b/app/controllers/admin/order_cycles_controller.rb index 08556bd458..18ec545de2 100644 --- a/app/controllers/admin/order_cycles_controller.rb +++ b/app/controllers/admin/order_cycles_controller.rb @@ -62,7 +62,7 @@ module Admin end def clone - @order_cycle = OrderCycle.find params[:order_cycle_id] + @order_cycle = OrderCycle.find params[:id] @order_cycle.clone! redirect_to main_app.admin_order_cycles_path, :notice => "Your order cycle #{@order_cycle.name} has been cloned." end diff --git a/app/models/spree/ability_decorator.rb b/app/models/spree/ability_decorator.rb index c6e187e205..9b2647f45e 100644 --- a/app/models/spree/ability_decorator.rb +++ b/app/models/spree/ability_decorator.rb @@ -34,7 +34,7 @@ class AbilityDecorator user.enterprises.include? payment_method.distributor end - can [:admin, :index, :read, :edit, :update], OrderCycle do |order_cycle| + can [:admin, :index, :read, :edit, :update, :clone], OrderCycle do |order_cycle| user.enterprises.include? order_cycle.coordinator end diff --git a/app/views/admin/order_cycles/index.html.haml b/app/views/admin/order_cycles/index.html.haml index 745e19e92c..8ae14a8ee7 100644 --- a/app/views/admin/order_cycles/index.html.haml +++ b/app/views/admin/order_cycles/index.html.haml @@ -38,5 +38,5 @@ - order_cycle.variants.each do |v| = image_tag(v.images.first.attachment.url(:mini)) if v.images.present? %td.actions - = link_to '', main_app.admin_order_cycle_clone_path(order_cycle), class: 'clone-order-cycle icon-copy no-text' + = link_to '', main_app.clone_admin_order_cycle_path(order_cycle), class: 'clone-order-cycle icon-copy no-text' = f.submit 'Update' diff --git a/config/routes.rb b/config/routes.rb index b828c2a902..1a70152f5e 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -19,7 +19,7 @@ Openfoodweb::Application.routes.draw do namespace :admin do resources :order_cycles do post :bulk_update, :on => :collection, :as => :bulk_update - get :clone + get :clone, on: :member end resources :enterprises do diff --git a/spec/features/admin/order_cycles_spec.rb b/spec/features/admin/order_cycles_spec.rb index 0e03b69858..01c1b6acad 100644 --- a/spec/features/admin/order_cycles_spec.rb +++ b/spec/features/admin/order_cycles_spec.rb @@ -426,6 +426,18 @@ feature %q{ order_cycle.coordinator.should == distributor1 end + scenario "cloning an order cycle" do + oc = create(:simple_order_cycle) + + click_link "Order Cycles" + first('a.clone-order-cycle').click + flash_message.should == "Your order cycle #{oc.name} has been cloned." + + # Then I should have clone of the order cycle + occ = OrderCycle.last + occ.name.should == "COPY OF #{oc.name}" + end + end end diff --git a/spec/models/ability_spec.rb b/spec/models/ability_spec.rb index b31258bfc2..b8140d29d7 100644 --- a/spec/models/ability_spec.rb +++ b/spec/models/ability_spec.rb @@ -126,11 +126,11 @@ module Spree let(:oc2) { create(:simple_order_cycle) } it "should be able to read/write OrderCycles they are the co-ordinator of" do - should have_ability([:admin, :index, :read, :edit], for: oc1) + should have_ability([:admin, :index, :read, :edit, :update, :clone], for: oc1) end it "should not be able to read/write OrderCycles they are not the co-ordinator of" do - should_not have_ability([:admin, :index, :read, :create, :edit], for: oc2) + should_not have_ability([:admin, :index, :read, :create, :edit, :update, :clone], for: oc2) end it "should be able to create OrderCycles" do