BPUR: match product supplier on clone

This commit is contained in:
Rob H
2013-06-26 22:42:59 +05:30
committed by Rohan Mitchell
parent c826b18584
commit 19fbbb8374
3 changed files with 9 additions and 4 deletions

View File

@@ -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);
});
});

View File

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

View File

@@ -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" } ] } ] );
});
});
});