Skip to content

armgit / spree

Public Imported from GitHub
0

Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.

Fix broken test on orders and add test for Products index and filter.

Matthew Kennedyb7accbbd1af1
diff --git a/backend/app/controllers/spree/admin/orders_controller.rb b/backend/app/controllers/spree/admin/orders_controller.rb
index fc4d52e688..6c5612c18c 100644
--- a/backend/app/controllers/spree/admin/orders_controller.rb
+++ b/backend/app/controllers/spree/admin/orders_controller.rb
@@ -45,10 +45,10 @@ module Spree
params[:q][:completed_at_lt] = params[:q].delete(:created_at_lt)
end
- @search = if params[:q][:all_stores] == '1' || !current_store.present?
+ @search = if params[:q][:all_stores] == '1'
Spree::Order.preload(:user).accessible_by(current_ability, :index).ransack(params[:q])
else
- scope.preload(:user).accessible_by(current_ability, :index).ransack(params[:q])
+ Spree::Order.preload(:user).where(store_id: current_store.id).accessible_by(current_ability, :index).ransack(params[:q])
end
# lazy loading other models here (via includes) may result in an invalid query
diff --git a/backend/spec/features/admin/products/products_spec.rb b/backend/spec/features/admin/products/products_spec.rb
index c9facafc69..d02fe75c85 100644
--- a/backend/spec/features/admin/products/products_spec.rb
+++ b/backend/spec/features/admin/products/products_spec.rb
@@ -3,6 +3,7 @@ require 'spec_helper'
describe 'Products', type: :feature do
let(:store) { Spree::Store.default }
+ let(:other_store) { create(:store)}
context 'as admin user' do
stub_authorization!
@@ -20,6 +21,7 @@ describe 'Products', type: :feature do
before do
create(:product, name: 'apache baseball cap', price: 10)
create(:product, name: 'zomg shirt', price: 5)
+ create(:product, name: 'Long T-Shirt', price: 15, stores: [other_store])
end
it 'lists existing products with correct sorting by name' do
@@ -45,6 +47,12 @@ describe 'Products', type: :feature do
within_row(1) { expect(page).to have_content('zomg shirt') }
within_row(2) { expect(page).to have_content('apache baseball cap') }
end
+
+ it 'does not list the product that belongs to other store' do
+ visit spree.admin_products_path
+
+ expect(page).not_to have_content('Long T-Shirt')
+ end
end
context 'currency displaying' do
@@ -88,6 +96,24 @@ describe 'Products', type: :feature do
expect(page).not_to have_content('apache baseball cap')
end
+ it 'filter is able to show products for all stores' do
+ create(:product, name: 'apache baseball cap')
+ create(:product, name: 'zomg shirt')
+ create(:product, name: 'Long T-Shirt', price: 15, stores: [other_store])
+
+ visit spree.admin_products_path
+ expect(page).to have_content('zomg shirt')
+ expect(page).to have_content('apache baseball cap')
+ expect(page).not_to have_content('Long T-Shirt')
+
+ find('label', text: 'Show Products for all stores').click
+ click_on 'Search'
+
+ expect(page).to have_content('zomg shirt')
+ expect(page).to have_content('apache baseball cap')
+ expect(page).to have_content('Long T-Shirt')
+ end
+
it 'is able to search products by their properties' do
create(:product, name: 'apache baseball cap', sku: 'A100')
create(:product, name: 'apache baseball cap2', sku: 'B100')