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