From e816228959103e5576b92aa4d15d3ae2907503e1 Mon Sep 17 00:00:00 2001 From: David Cook Date: Fri, 21 Jul 2023 14:19:24 +1000 Subject: [PATCH] Sort products by name in ascending order The order is specified above in fetch_products. I'm guessing this line was unintentional? Original requirment doesn't say ascending but I think it's safe to assume (issue#10694). --- app/reflexes/products_reflex.rb | 2 +- spec/system/admin/products_v3/products_spec.rb | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/app/reflexes/products_reflex.rb b/app/reflexes/products_reflex.rb index 443ac5f0d3..295341bc02 100644 --- a/app/reflexes/products_reflex.rb +++ b/app/reflexes/products_reflex.rb @@ -96,7 +96,7 @@ class ProductsReflex < ApplicationReflex end def ransack_query - query = { s: "name desc" } + query = {} query.merge!(supplier_id_in: @producer_id) if @producer_id.present? if @search_term.present? query.merge!(Spree::Variant::SEARCH_KEY => @search_term) diff --git a/spec/system/admin/products_v3/products_spec.rb b/spec/system/admin/products_v3/products_spec.rb index 4e7b7ecc97..915de05c64 100644 --- a/spec/system/admin/products_v3/products_spec.rb +++ b/spec/system/admin/products_v3/products_spec.rb @@ -23,6 +23,21 @@ describe 'As an admin, I can see the new product page' do expect(page).to have_content "Bulk Edit Products" end + describe "sorting" do + let!(:product_z) { create(:simple_product, name: "Zucchini") } + let!(:product_a) { create(:simple_product, name: "Apples") } + + before do + visit admin_products_v3_index_url + end + + it "Should sort products alphabetically by default" do + expect(page).to have_selector "table.products tbody tr td", text: "Apples" + # other products push later one to next page + expect(page).not_to have_selector "table.products tbody tr td", text: "Zucchini" + end + end + describe "pagination" do before do visit admin_products_v3_index_url