Bulk product update rewrite: basic integration test passing

This commit is contained in:
Rob H
2013-05-15 16:00:54 +05:30
committed by Rohan Mitchell
parent 246c6de495
commit 1e64dab9f7
4 changed files with 21 additions and 5 deletions

View File

@@ -1,3 +1,9 @@
var productsApp = angular.module('bulk_product_update', [])
productsApp.config(["$httpProvider", function(provider) {
provider.defaults.headers.common['X-CSRF-Token'] = $('meta[name=csrf-token]').attr('content');
}]);
function AdminBulkProductsCtrl($scope, $timeout, $http) {
$scope.refreshSuppliers = function(){
$http.get('/enterprises/suppliers.json').success(function(data) {
@@ -24,8 +30,7 @@ function AdminBulkProductsCtrl($scope, $timeout, $http) {
$http({
method: 'POST',
url: '/admin/products/bulk_update',
data: productsToSubmit,
headers: {'Content-Type': 'application/json', 'Accept': 'application/json'}
data: productsToSubmit
})
.success(function(data){
if (angular.toJson($scope.products) == angular.toJson(data)){
@@ -67,8 +72,6 @@ function AdminBulkProductsCtrl($scope, $timeout, $http) {
}
}
var productsApp = angular.module('bulk_product_update', [])
function sortByID(array){
var sortedArray = [];
for (var i in array){

View File

@@ -10,6 +10,18 @@ Spree::Admin::ProductsController.class_eval do
end
end
def bulk_update
@collection_hash = Hash[params[:_json].each_with_index.map { |p,i| [i,p] }]
@collection_attributes = { :collection_attributes => @collection_hash }
@product_set = Spree::ProductSet.new(@collection_attributes)
if @product_set.save
redirect_to bulk_index_admin_products_url :format => :json
else
render :nothing => true
end
end
protected
def location_after_save
if URI(request.referer).path == '/admin/products/bulk_index'

View File

@@ -35,6 +35,7 @@ Spree::Core::Engine.routes.prepend do
namespace :admin do
resources :products do
get :bulk_index, :on => :collection, :as => :bulk_index
post :bulk_update, :on => :collection, :as => :bulk_update
end
end

View File

@@ -64,7 +64,7 @@ feature %q{
fill_in "product_name", with: "Big Bag Of Potatoes"
click_button 'Update'
page.find("div#update-status-message").should have_content "Updating complete"
page.find("span#update-status-message").should have_content "Update complete"
click_link 'Bulk Product Edit'
page.should have_field "product_name", with: "Big Bag Of Potatoes"