added product sorting

This commit is contained in:
Yih Yang
2020-10-29 22:06:35 +08:00
parent 9a03428412
commit e3d1f5256b
2 changed files with 13 additions and 1 deletions

View File

@@ -31,7 +31,7 @@ class ExchangeProductsRenderer
end
def supplied_products(enterprises_query_matcher)
products_relation = Spree::Product.where(supplier_id: enterprises_query_matcher)
products_relation = Spree::Product.where(supplier_id: enterprises_query_matcher).order(:name)
filter_visible(products_relation)
end

View File

@@ -14,6 +14,12 @@ describe ExchangeProductsRenderer do
expect(products.first.supplier.name).to eq exchange.variants.first.product.supplier.name
end
it "loads products in order" do
sorted_products_names = products.pluck(:name).sort
expect(products.pluck(:name)).to eq(sorted_products_names)
end
end
describe "for an outgoing exchange" do
@@ -27,6 +33,12 @@ describe ExchangeProductsRenderer do
expect(suppliers).to include products.second.supplier.name
end
it "loads products in order" do
sorted_products_names = products.pluck(:name).sort
expect(products.pluck(:name)).to eq(sorted_products_names)
end
context "showing products from coordinator inventory only" do
before { order_cycle.update prefers_product_selection_from_coordinator_inventory_only: true }