Enterprise manager can clone an order cycle

This commit is contained in:
Rohan Mitchell
2013-08-22 17:11:53 +10:00
parent f1fa90d7c3
commit 8a092697ee
6 changed files with 18 additions and 6 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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'

View File

@@ -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

View File

@@ -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

View File

@@ -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