diff --git a/app/assets/javascripts/admin/bulk_product_update.js.coffee b/app/assets/javascripts/admin/bulk_product_update.js.coffee index 58c8d72f7c..bda2951281 100644 --- a/app/assets/javascripts/admin/bulk_product_update.js.coffee +++ b/app/assets/javascripts/admin/bulk_product_update.js.coffee @@ -149,6 +149,9 @@ productsApp.controller "AdminBulkProductsCtrl", [ $scope.minPage = -> Math.max(1,Math.min($scope.totalPages()-4,$scope.currentPage-2)) $scope.maxPage = -> Math.min($scope.totalPages(),Math.max(5,$scope.currentPage+2)) + $scope.$watch 'perPage', (newVal, oldVal) -> + $scope.currentPage = $scope.totalPages() if newVal != oldVal && $scope.totalPages() < $scope.currentPage + $scope.initialise = (spree_api_key) -> authorise_api_reponse = "" dataFetcher("/api/users/authorise_api?token=" + spree_api_key).then (data) -> diff --git a/spec/features/admin/bulk_product_update_spec.rb b/spec/features/admin/bulk_product_update_spec.rb index 66effcd295..5ea1a3ebe1 100644 --- a/spec/features/admin/bulk_product_update_spec.rb +++ b/spec/features/admin/bulk_product_update_spec.rb @@ -564,6 +564,19 @@ feature %q{ click_link "2" page.all("input[name='product_name']").select{ |e| e.visible? }.all?{ |e| e.value == "page2product" }.should == true end + + it "moves the user to the last available page when changing perPage value causes user to become orphaned" do + 51.times { FactoryGirl.create(:product) } + login_to_admin_section + + visit '/admin/products/bulk_edit' + + select '25', :from => 'perPage' + click_link "3" + select '50', :from => 'perPage' + page.first("div.pagenav span.page.current").should have_text "2" + page.all("input[name='product_name']").select{ |e| e.visible? }.length.should == 1 + end end end