From 19fbbb837406d96e443a71cc0143cf97c259769c Mon Sep 17 00:00:00 2001 From: Rob H Date: Wed, 26 Jun 2013 22:42:59 +0530 Subject: [PATCH] BPUR: match product supplier on clone --- app/assets/javascripts/admin/bulk_product_update.js | 1 + spec/features/admin/bulk_product_update_spec.rb | 2 ++ spec/javascripts/unit/bulk_product_update_spec.js | 10 ++++++---- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/app/assets/javascripts/admin/bulk_product_update.js b/app/assets/javascripts/admin/bulk_product_update.js index e524cdc6b6..17ca8b9957 100644 --- a/app/assets/javascripts/admin/bulk_product_update.js +++ b/app/assets/javascripts/admin/bulk_product_update.js @@ -224,6 +224,7 @@ productsApp.controller('AdminBulkProductsCtrl', function($scope, $timeout, $http var id = data.product.id; dataFetcher("/admin/products/bulk_index.json?q[id_eq]="+id).then(function(data){ var newProduct = data[0]; + $scope.matchSupplier(newProduct); $scope.products.push(newProduct); }); }); diff --git a/spec/features/admin/bulk_product_update_spec.rb b/spec/features/admin/bulk_product_update_spec.rb index df3e70fc94..77ec1dd23f 100644 --- a/spec/features/admin/bulk_product_update_spec.rb +++ b/spec/features/admin/bulk_product_update_spec.rb @@ -384,11 +384,13 @@ feature %q{ page.should have_selector "a.clone-product", :count => 4 page.should have_field "product_name", with: "COPY OF #{p1.name}" + page.should have_select "supplier", selected: "#{p1.supplier.name}" visit '/admin/products/bulk_edit' page.should have_selector "a.clone-product", :count => 4 page.should have_field "product_name", with: "COPY OF #{p1.name}" + page.should have_select "supplier", selected: "#{p1.supplier.name}" end end end diff --git a/spec/javascripts/unit/bulk_product_update_spec.js b/spec/javascripts/unit/bulk_product_update_spec.js index b6399e81aa..8e33351773 100644 --- a/spec/javascripts/unit/bulk_product_update_spec.js +++ b/spec/javascripts/unit/bulk_product_update_spec.js @@ -428,13 +428,15 @@ describe("AdminBulkProductsCtrl", function(){ httpBackend.flush(); }); - it("adds the newly created product to scope.products", function(){ + it("adds the newly created product to scope.products and matches supplier", function(){ + spyOn(scope, "matchSupplier").andCallThrough(); scope.products = [ { id: 13, permalink_live: "oranges" } ]; - httpBackend.expectGET('/admin/products/oranges/clone.json').respond(200, { product: { id: 17, name: "new_product", variants: [ { id: 3, name: "V1" } ] } } ); - httpBackend.expectGET('/admin/products/bulk_index.json?q[id_eq]=17').respond(200, [ { id: 17, name: "new_product", variants: [ { id: 3, name: "V1" } ] } ] ); + httpBackend.expectGET('/admin/products/oranges/clone.json').respond(200, { product: { id: 17, name: "new_product", supplier: { id: 6 }, variants: [ { id: 3, name: "V1" } ] } } ); + httpBackend.expectGET('/admin/products/bulk_index.json?q[id_eq]=17').respond(200, [ { id: 17, name: "new_product", supplier: { id: 6 }, variants: [ { id: 3, name: "V1" } ] } ] ); scope.cloneProduct(scope.products[0]); httpBackend.flush(); - expect(scope.products).toEqual( [ { id: 13, permalink_live: "oranges" }, { id: 17, name: "new_product", variants: [ { id: 3, name: "V1" } ] } ] ); + expect(scope.matchSupplier).toHaveBeenCalledWith( { id: 17, name: "new_product", supplier: { id: 6 }, variants: [ { id: 3, name: "V1" } ] } ); + expect(scope.products).toEqual( [ { id: 13, permalink_live: "oranges" }, { id: 17, name: "new_product", supplier: { id: 6 }, variants: [ { id: 3, name: "V1" } ] } ] ); }); }); });