Skip to content

Commit

Permalink
[Fixes #1086] Allows cloning of deleted products
Browse files Browse the repository at this point in the history
  • Loading branch information
LBRapid authored and BDQ committed Feb 3, 2012
1 parent 4179b9d commit 768b1cb
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
8 changes: 5 additions & 3 deletions core/app/models/spree/product.rb
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,12 @@ def duplicate
image_dup = lambda { |i| j = i.dup; j.attachment = i.attachment.clone; j }
p.images = self.images.map { |i| image_dup.call i }

variant = self.master.dup
variant.sku = 'COPY OF ' + self.master.sku
#variant = self.master.dup
master = Spree::Variant.find_by_product_id_and_is_master(self.id, true)
variant = master.dup
variant.sku = 'COPY OF ' + master.sku
variant.deleted_at = nil
variant.images = self.master.images.map { |i| image_dup.call i }
variant.images = master.images.map { |i| image_dup.call i }
p.master = variant

if self.has_variants?
Expand Down
16 changes: 15 additions & 1 deletion core/spec/requests/admin/products/products_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,14 +86,28 @@
end
end

context "cloning a product" do
context "cloning a product", :js => true do
it "should allow an admin to clone a product" do
Factory(:product, :name => 'apache baseball cap', :available_on => '2011-01-01 01:01:01', :sku => "A100")

click_link "Products"
within('table#listing_products tr:nth-child(2)') { click_link "Clone" }
page.should have_content("Product has been cloned")
end

context "cloning a deleted product" do
it "should allow an admin to clone a deleted product" do
Factory(:product, :name => 'apache baseball cap', :available_on => '2011-01-01 01:01:01', :sku => "A100", :deleted_at => '2011-05-01 01:01:01')

click_link "Products"
check "Show Deleted"
click_button "Search"

page.should have_content("apache baseball cap")
within('table#listing_products tr:nth-child(2)') { click_link "Clone" }
page.should have_content("Product has been cloned")
end
end
end

context "uploading a product image" do
Expand Down

0 comments on commit 768b1cb

Please sign in to comment.