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.
This commit is contained in:
Maikel Linke
2019-09-09 14:45:17 +10:00
parent 452593b6f1
commit f0ee4aab01
2 changed files with 37 additions and 0 deletions

View File

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

View File

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