From f0ee4aab0101c5b343b98bead8e080e0048ee854 Mon Sep 17 00:00:00 2001 From: Maikel Linke Date: Mon, 9 Sep 2019 14:45:17 +1000 Subject: [PATCH] Restore old pagination API for products It's still used by the inventory page. This is an easy fix that I can deploy without risk. A rewrite of the inventory pagination should follow. --- app/controllers/api/products_controller.rb | 3 ++ spec/features/admin/inventory_spec.rb | 34 ++++++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 spec/features/admin/inventory_spec.rb diff --git a/app/controllers/api/products_controller.rb b/app/controllers/api/products_controller.rb index 6a90cdf954..13abb37ff5 100644 --- a/app/controllers/api/products_controller.rb +++ b/app/controllers/api/products_controller.rb @@ -127,6 +127,9 @@ module Api render text: { products: serializer, + # This line is used by the PagedFetcher JS service (inventory). + pages: products.num_pages, + # This hash is used by the BulkProducts JS service. pagination: pagination_data(products) }.to_json end diff --git a/spec/features/admin/inventory_spec.rb b/spec/features/admin/inventory_spec.rb new file mode 100644 index 0000000000..d2ea04ad74 --- /dev/null +++ b/spec/features/admin/inventory_spec.rb @@ -0,0 +1,34 @@ +require "spec_helper" + +feature "Managing inventory", js: true do + include AdminHelper + include AuthenticationWorkflow + include WebHelper + + it "shows more than 100 products" do + supplier = create(:supplier_enterprise, sells: "own") + inventory_items = (1..101).map do + product = create(:simple_product, supplier: supplier) + InventoryItem.create!( + enterprise: supplier, + variant: product.variants.first, + visible: true + ) + end + first_variant = inventory_items.first.variant + last_variant = inventory_items.last.variant + first_variant.product.update_attributes!(name: "A First Product") + last_variant.product.update_attributes!(name: "Z Last Product") + quick_login_as supplier.users.first + visit admin_inventory_path + + expect(page).to have_text first_variant.name + expect(page).to have_selector "tr.product", count: 10 + expect(page).to have_button "Show more" + expect(page).to have_button "Show all (91 More)" + + click_button "Show all (91 More)" + expect(page).to have_selector "tr.product", count: 101 + expect(page).to have_text last_variant.name + end +end