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.

Require Product and Payment Method to be assigned to at least one store

Damian Legawiecb44f54e97f3a
diff --git a/api/app/controllers/spree/api/v1/products_controller.rb b/api/app/controllers/spree/api/v1/products_controller.rb
index cdee655e9a..d34e3a45c0 100644
--- a/api/app/controllers/spree/api/v1/products_controller.rb
+++ b/api/app/controllers/spree/api/v1/products_controller.rb
@@ -64,7 +64,7 @@ module Spree
params[:product][:available_on] ||= Time.current
set_up_shipping_category
- options = { variants_attrs: variants_params, options_attrs: option_types_params }
+ options = { store: current_store, variants_attrs: variants_params, options_attrs: option_types_params }
@product = Core::Importer::Product.new(nil, product_params, options).create
if @product.persisted?
@@ -77,7 +77,7 @@ module Spree
def update
authorize! :update, @product
- options = { variants_attrs: variants_params, options_attrs: option_types_params }
+ options = { store: current_store, variants_attrs: variants_params, options_attrs: option_types_params }
@product = Core::Importer::Product.new(@product, product_params, options).update
if @product.errors.empty?
diff --git a/api/spec/controllers/spree/api/base_controller_spec.rb b/api/spec/controllers/spree/api/base_controller_spec.rb
index 7cb29e85ec..e4f47ee009 100644
--- a/api/spec/controllers/spree/api/base_controller_spec.rb
+++ b/api/spec/controllers/spree/api/base_controller_spec.rb
@@ -5,6 +5,9 @@ end
describe Spree::Api::BaseController, type: :controller do
render_views
+
+ let(:store) { Spree::Store.default }
+
controller(Spree::Api::BaseController) do
def index
render plain: { 'products' => [] }.to_json
@@ -71,7 +74,7 @@ describe Spree::Api::BaseController, type: :controller do
it 'handles record invalid exceptions' do
expect(subject).to receive(:authenticate_user).and_return(true)
expect(subject).to receive(:load_user_roles).and_return(true)
- resource = Spree::Product.new
+ resource = Spree::Product.new(stores: [store])
resource.valid? # get some errors
expect(subject).to receive(:index).and_raise(ActiveRecord::RecordInvalid.new(resource))
get :index, params: { token: 'exception-message' }
diff --git a/api/spec/controllers/spree/api/v1/classifications_controller_spec.rb b/api/spec/controllers/spree/api/v1/classifications_controller_spec.rb
index 430e5f941a..e198857622 100644
--- a/api/spec/controllers/spree/api/v1/classifications_controller_spec.rb
+++ b/api/spec/controllers/spree/api/v1/classifications_controller_spec.rb
@@ -6,7 +6,7 @@ module Spree
taxon = create(:taxon)
3.times do
- product = create(:product)
+ product = create(:product, stores: Spree::Store.all)
product.taxons << taxon
end
taxon
diff --git a/api/spec/controllers/spree/api/v1/images_controller_spec.rb b/api/spec/controllers/spree/api/v1/images_controller_spec.rb
index c877e37637..94e34445ed 100644
--- a/api/spec/controllers/spree/api/v1/images_controller_spec.rb
+++ b/api/spec/controllers/spree/api/v1/images_controller_spec.rb
@@ -4,7 +4,7 @@ module Spree
describe Api::V1::ImagesController, type: :controller do
render_views
- let!(:product) { create(:product) }
+ let!(:product) { create(:product, stores: Spree::Store.all) }
let!(:attributes) do
[:id, :position, :attachment_content_type,
:attachment_file_name, :type, :attachment_updated_at, :attachment_width,
diff --git a/api/spec/controllers/spree/api/v1/line_items_controller_spec.rb b/api/spec/controllers/spree/api/v1/line_items_controller_spec.rb
index 881f0a5da0..f9f22cdb61 100644
--- a/api/spec/controllers/spree/api/v1/line_items_controller_spec.rb
+++ b/api/spec/controllers/spree/api/v1/line_items_controller_spec.rb
@@ -17,7 +17,7 @@ module Spree
let!(:order) { create(:order_with_line_items, line_items_count: 1) }
- let(:product) { create(:product) }
+ let(:product) { create(:product, stores: Spree::Store.all) }
let(:attributes) { [:id, :quantity, :price, :variant, :total, :display_amount, :single_display_amount] }
let(:resource_scoping) { { order_id: order.to_param } }
let(:admin_role) { create(:admin_role) }
diff --git a/api/spec/controllers/spree/api/v1/product_properties_controller_spec.rb b/api/spec/controllers/spree/api/v1/product_properties_controller_spec.rb
index 04e2291d49..355daf79d1 100644
--- a/api/spec/controllers/spree/api/v1/product_properties_controller_spec.rb
+++ b/api/spec/controllers/spree/api/v1/product_properties_controller_spec.rb
@@ -5,7 +5,7 @@ module Spree
describe Api::V1::ProductPropertiesController, type: :controller do
render_views
- let!(:product) { create(:product) }
+ let!(:product) { create(:product, stores: Spree::Store.all) }
let!(:property_1) { product.product_properties.create(property_name: 'My Property 1', value: 'my value 1', position: 0) }
let(:attributes) { [:id, :product_id, :property_id, :value, :property_name] }
diff --git a/api/spec/controllers/spree/api/v1/products_controller_spec.rb b/api/spec/controllers/spree/api/v1/products_controller_spec.rb
index 8f017bee92..a55bdc9271 100644
--- a/api/spec/controllers/spree/api/v1/products_controller_spec.rb
+++ b/api/spec/controllers/spree/api/v1/products_controller_spec.rb
@@ -5,8 +5,10 @@ module Spree
describe Api::V1::ProductsController, type: :controller do
render_views
- let!(:product) { create(:product) }
- let!(:inactive_product) { create(:product, available_on: Time.current.tomorrow, name: 'inactive') }
+ let(:store) { Spree::Store.default }
+
+ let!(:product) { create(:product, stores: [store]) }
+ let!(:inactive_product) { create(:product, available_on: Time.current.tomorrow, name: 'inactive', stores: [store]) }
let(:base_attributes) { Api::ApiHelpers.product_attributes }
let(:show_attributes) { base_attributes.dup.push(:has_variants) }
let(:new_attributes) { base_attributes }
@@ -31,7 +33,7 @@ module Spree
context 'as a normal user' do
context 'with caching enabled' do
before do
- create(:product) # product_2
+ create(:product, stores: [store]) # product_2
ActionController::Base.perform_caching = true
end
@@ -74,7 +76,7 @@ module Spree
end
it 'retrieves a list of products by ids string' do
- second_product = create(:product)
+ second_product = create(:product, stores: [store])
api_get :index, ids: [product.id, second_product.id].join(',')
expect(json_response['products'].first).to have_attributes(show_attributes)
expect(json_response['products'][1]).to have_attributes(show_attributes)
@@ -95,7 +97,7 @@ module Spree
end
context 'pagination' do
- before { create(:product) }
+ before { create(:product, stores: [store]) }
it 'can select the next page of products' do
api_get :index, page: 2, per_page: 1
@@ -115,7 +117,7 @@ module Spree
end
it 'can search for products' do
- create(:product, name: 'The best product in the world')
+ create(:product, name: 'The best product in the world', stores: [store])
api_get :index, q: { name_cont: 'best' }
expect(json_response['products'].first).to have_attributes(show_attributes)
expect(json_response['count']).to eq(1)
@@ -123,8 +125,8 @@ module Spree
# regression test for https://github.com/spree/spree/issues/8207
it 'can sort products by date' do
- first_product = create(:product, created_at: Time.current - 1.month)
- create(:product, created_at: Time.current) # second_product
+ first_product = create(:product, created_at: Time.current - 1.month, stores: [store])
+ create(:product, created_at: Time.current, stores: [store]) # second_product
api_get :index, q: { s: 'created_at asc' }
expect(json_response['products'].first['id']).to eq(first_product.id)
end
@@ -175,7 +177,7 @@ module Spree
end
context 'finds a product by slug first then by id' do
- let!(:other_product) { create(:product, slug: 'these-are-not-the-droids-you-are-looking-for') }
+ let!(:other_product) { create(:product, slug: 'these-are-not-the-droids-you-are-looking-for', stores:[store]) }
before do
product.update_column(:slug, "#{other_product.id}-and-1-ways")
@@ -230,7 +232,7 @@ module Spree
# Regression test for #1626
context 'deleted products' do
before do
- create(:product, deleted_at: 1.day.ago)
+ create(:product, deleted_at: 1.day.ago, stores: [store])
end
it 'does not include deleted products' do
diff --git a/api/spec/controllers/spree/api/v1/return_authorizations_controller_spec.rb b/api/spec/controllers/spree/api/v1/return_authorizations_controller_spec.rb
index 08a90e2130..e5dda78a9d 100644
--- a/api/spec/controllers/spree/api/v1/return_authorizations_controller_spec.rb
+++ b/api/spec/controllers/spree/api/v1/return_authorizations_controller_spec.rb
@@ -6,7 +6,7 @@ module Spree
let!(:order) { create(:shipped_order) }
- let(:product) { create(:product) }
+ let(:product) { create(:product, stores: Spree::Store.all) }
let(:attributes) { [:id, :memo, :state] }
let(:resource_scoping) { { order_id: order.to_param } }
diff --git a/api/spec/controllers/spree/api/v1/unauthenticated_products_controller_spec.rb b/api/spec/controllers/spree/api/v1/unauthenticated_products_controller_spec.rb
index a4649f4630..1b673ca713 100644
--- a/api/spec/controllers/spree/api/v1/unauthenticated_products_controller_spec.rb
+++ b/api/spec/controllers/spree/api/v1/unauthenticated_products_controller_spec.rb
@@ -5,7 +5,7 @@ module Spree
describe Api::V1::ProductsController, type: :controller do
render_views
- let!(:product) { create(:product) }
+ let!(:product) { create(:product, stores: Spree::Store.all) }
let(:attributes) { [:id, :name, :description, :price, :available_on, :slug, :meta_description, :meta_keywords, :taxon_ids] }
context 'without authentication' do
diff --git a/api/spec/controllers/spree/api/v1/variants_controller_spec.rb b/api/spec/controllers/spree/api/v1/variants_controller_spec.rb
index 1bbff32486..d72388e133 100644
--- a/api/spec/controllers/spree/api/v1/variants_controller_spec.rb
+++ b/api/spec/controllers/spree/api/v1/variants_controller_spec.rb
@@ -5,7 +5,7 @@ module Spree
render_views
let(:option_value) { create(:option_value) }
- let!(:product) { create(:product) }
+ let!(:product) { create(:product, stores: Spree::Store.all) }
let!(:variant) do
variant = product.master
variant.option_values << option_value
diff --git a/api/spec/requests/ransackable_attributes_spec.rb b/api/spec/requests/ransackable_attributes_spec.rb
index d84e95c903..84a692fc0a 100644
--- a/api/spec/requests/ransackable_attributes_spec.rb
+++ b/api/spec/requests/ransackable_attributes_spec.rb
@@ -1,6 +1,7 @@
require 'spec_helper'
describe 'Ransackable Attributes' do
+ let(:store) { Spree::Store.default }
let(:user) { create(:user).tap(&:generate_spree_api_key!) }
let(:order) { create(:order_with_line_items, user: user) }
@@ -28,7 +29,7 @@ describe 'Ransackable Attributes' do
context 'it maintains desired association behavior' do
it 'allows filtering of variants product name' do
- product = create(:product, name: 'Fritos')
+ product = create(:product, name: 'Fritos', stores: [store])
variant = create(:variant, product: product)
other_variant = create(:variant)
@@ -42,8 +43,8 @@ describe 'Ransackable Attributes' do
context 'filtering by attributes' do
it 'most attributes are not filterable by default' do
- create(:product, meta_title: 'special product')
- create(:product)
+ create(:product, meta_title: 'special product', stores: [store])
+ create(:product, stores: [store])
get '/api/v1/products?q[meta_title_cont]=special', params: { token: user.spree_api_key }
@@ -52,8 +53,8 @@ describe 'Ransackable Attributes' do
end
it 'id is filterable by default' do
- product = create(:product)
- other_product = create(:product)
+ product = create(:product, stores: [store])
+ other_product = create(:product, stores: [store])
get "/api/v1/products?q[id_eq]=#{product.id}", params: { token: user.spree_api_key }
@@ -65,8 +66,8 @@ describe 'Ransackable Attributes' do
context 'filtering by whitelisted attributes' do
it 'filtering is supported for whitelisted attributes' do
- product = create(:product, name: 'Fritos')
- other_product = create(:product)
+ product = create(:product, name: 'Fritos', stores: [store])
+ other_product = create(:product, stores: [store])
get '/api/v1/products?q[name_cont]=fritos', params: { token: user.spree_api_key }
diff --git a/api/spec/requests/spree/api/v2/resource_includes_spec.rb b/api/spec/requests/spree/api/v2/resource_includes_spec.rb
index eeff471d9c..8d8ecf2e7a 100644
--- a/api/spec/requests/spree/api/v2/resource_includes_spec.rb
+++ b/api/spec/requests/spree/api/v2/resource_includes_spec.rb
@@ -1,8 +1,9 @@
require 'spec_helper'
describe 'API v2 JSON API Resource Includes Spec', type: :request do
- let!(:products) { create_list(:product, 5) }
- let!(:product) { create(:product) }
+ let(:store) { Spree::Store.default }
+ let!(:products) { create_list(:product, 5, stores: [store]) }
+ let!(:product) { create(:product, stores: [store]) }
let!(:product_option_type) { create(:product_option_type, product: product) }
let!(:option_value) { create(:option_value, option_type: product_option_type.option_type) }
let(:default_variant) { product.master }
diff --git a/api/spec/requests/spree/api/v2/storefront/sparse_fields_spec.rb b/api/spec/requests/spree/api/v2/storefront/sparse_fields_spec.rb
index dba8abb805..cb1725bb4a 100644
--- a/api/spec/requests/spree/api/v2/storefront/sparse_fields_spec.rb
+++ b/api/spec/requests/spree/api/v2/storefront/sparse_fields_spec.rb
@@ -1,7 +1,8 @@
require 'spec_helper'
describe 'API v2 JSON API Sparse Fields Spec', type: :request do
- let!(:product) { create(:product_with_option_types) }
+ let(:store) { Spree::Store.default }
+ let!(:product) { create(:product_with_option_types, stores: [store]) }
shared_examples 'no sparse fields requested' do
it 'returns all attributes' do
diff --git a/backend/spec/controllers/spree/admin/products_controller_spec.rb b/backend/spec/controllers/spree/admin/products_controller_spec.rb
index f57bfb185d..38833d2b57 100644
--- a/backend/spec/controllers/spree/admin/products_controller_spec.rb
+++ b/backend/spec/controllers/spree/admin/products_controller_spec.rb
@@ -8,7 +8,7 @@ describe Spree::Admin::ProductsController, type: :controller do
# Regression test for #1259
it 'can find a product by SKU' do
- product = create(:product, sku: 'ABC123')
+ product = create(:product, sku: 'ABC123', stores: Spree::Store.all)
get :index, params: { q: { sku_start: 'ABC123' } }
expect(assigns[:collection]).not_to be_empty
expect(assigns[:collection]).to include(product)
@@ -17,7 +17,7 @@ describe Spree::Admin::ProductsController, type: :controller do
# regression test for #1370
context 'adding properties to a product' do
- let!(:product) { create(:product) }
+ let!(:product) { create(:product, stores: Spree::Store.all) }
specify do
put :update, params: {
@@ -150,7 +150,7 @@ describe Spree::Admin::ProductsController, type: :controller do
end
context 'stock' do
- let(:product) { create(:product) }
+ let(:product) { create(:product, stores: Spree::Store.all) }
it 'restricts stock location based on accessible attributes' do
expect(Spree::StockLocation).to receive(:accessible_by).and_return([])
diff --git a/backend/spec/controllers/spree/admin/variants_controller_spec.rb b/backend/spec/controllers/spree/admin/variants_controller_spec.rb
index c0edb3cf40..5ec7249218 100644
--- a/backend/spec/controllers/spree/admin/variants_controller_spec.rb
+++ b/backend/spec/controllers/spree/admin/variants_controller_spec.rb
@@ -6,7 +6,7 @@ module Spree
stub_authorization!
describe '#index' do
- let(:product) { create(:product) }
+ let(:product) { create(:product, stores: Spree::Store.all) }
let!(:variant_1) { create(:variant, product: product) }
let!(:variant_2) { create(:variant, product: product) }
diff --git a/backend/spec/features/admin/configuration/stock_movement_spec.rb b/backend/spec/features/admin/configuration/stock_movement_spec.rb
index 7991df0c05..5919224315 100644
--- a/backend/spec/features/admin/configuration/stock_movement_spec.rb
+++ b/backend/spec/features/admin/configuration/stock_movement_spec.rb
@@ -2,6 +2,7 @@ require 'spec_helper'
describe 'Stock Movements', type: :feature do
stub_authorization!
+ let(:store) { Spree::Store.default }
let!(:stock_location) { create(:stock_location_with_items) }
let(:stock_item) { stock_location.stock_items.first }
let!(:stock_movement) { create(:stock_movement, stock_item: stock_item, quantity: 10) }
@@ -22,7 +23,7 @@ describe 'Stock Movements', type: :feature do
end
describe 'creation', js: true do
- let!(:product) { create(:product_in_stock) }
+ let!(:product) { create(:product_in_stock, stores: [store]) }
before do
visit spree.admin_stock_location_stock_movements_path(stock_location.id)
diff --git a/backend/spec/features/admin/orders/customer_details_spec.rb b/backend/spec/features/admin/orders/customer_details_spec.rb
index c3efc9b3d2..f5826411e0 100644
--- a/backend/spec/features/admin/orders/customer_details_spec.rb
+++ b/backend/spec/features/admin/orders/customer_details_spec.rb
@@ -7,7 +7,7 @@ describe 'Customer Details', type: :feature, js: true do
let!(:country) { store.default_country }
let!(:state) { create(:state, name: 'Alabama', country: country, abbr: 'AL') }
let!(:order) { create(:order, state: 'complete', completed_at: '2011-02-01 12:36:15') }
- let!(:product) { create(:product_in_stock) }
+ let!(:product) { create(:product_in_stock, stores: [store]) }
# We need a unique name that will appear for the customer dropdown
let!(:ship_address) { create(:address, country: country, state: state, first_name: 'Rumpelstiltskin') }
let!(:bill_address) { create(:address, country: country, state: state, first_name: 'Rumpelstiltskin') }
diff --git a/backend/spec/features/admin/orders/new_order_spec.rb b/backend/spec/features/admin/orders/new_order_spec.rb
index ae2c847fe6..8607813bd6 100644
--- a/backend/spec/features/admin/orders/new_order_spec.rb
+++ b/backend/spec/features/admin/orders/new_order_spec.rb
@@ -1,7 +1,7 @@
require 'spec_helper'
describe 'New Order', type: :feature do
- let!(:product) { create(:product_in_stock) }
+ let!(:product) { create(:product_in_stock, stores: [store]) }
let!(:state) { create(:state) }
let!(:user) { create(:user, ship_address: create(:address), bill_address: create(:address)) }
let(:order) { Spree::Order.last }
diff --git a/backend/spec/features/admin/products/edit/images_spec.rb b/backend/spec/features/admin/products/edit/images_spec.rb
index b8600afeb5..0f6c3078e4 100644
--- a/backend/spec/features/admin/products/edit/images_spec.rb
+++ b/backend/spec/features/admin/products/edit/images_spec.rb
@@ -15,7 +15,7 @@ describe 'Product Images', type: :feature, js: true do
context 'uploading, editing, and deleting an image' do
it 'allows an admin to upload and edit an image for a product' do
- create(:product)
+ create(:product, stores: Spree::Store.all)
visit spree.admin_products_path
click_icon(:edit)
@@ -66,7 +66,7 @@ describe 'Product Images', type: :feature, js: true do
end
it 'does not see variant column when product has no variants', js: false do
- product = create(:product)
+ product = create(:product, stores: Spree::Store.all)
create_image(product, File.open(file_path))
visit spree.admin_product_images_path(product)
diff --git a/backend/spec/features/admin/products/edit/properties_spec.rb b/backend/spec/features/admin/products/edit/properties_spec.rb
index 8f652c9414..0be8dd8be6 100644
--- a/backend/spec/features/admin/products/edit/properties_spec.rb
+++ b/backend/spec/features/admin/products/edit/properties_spec.rb
@@ -4,7 +4,7 @@ describe 'Product Properties', type: :feature, js: true do
stub_authorization!
before do
- create(:product)
+ create(:product, stores: Spree::Store.all)
visit spree.admin_products_path
end
diff --git a/backend/spec/features/admin/products/edit/stores_spec.rb b/backend/spec/features/admin/products/edit/stores_spec.rb
index 263cf54b21..3b8ea66256 100644
--- a/backend/spec/features/admin/products/edit/stores_spec.rb
+++ b/backend/spec/features/admin/products/edit/stores_spec.rb
@@ -4,7 +4,7 @@ describe 'Product Stores', type: :feature, js: true do
stub_authorization!
before do
- create(:product)
+ create(:product, stores: Spree::Store.all)
create(:store, name: 'First store', code: 'first')
create(:store, name: 'Second store', code: 'second')
diff --git a/backend/spec/features/admin/products/edit/taxons_spec.rb b/backend/spec/features/admin/products/edit/taxons_spec.rb
index fd191b4e58..8c85b1dab1 100644
--- a/backend/spec/features/admin/products/edit/taxons_spec.rb
+++ b/backend/spec/features/admin/products/edit/taxons_spec.rb
@@ -7,7 +7,7 @@ describe 'Product Taxons', type: :feature, js: true do
it 'allows an admin to manage taxons' do
taxon_1 = create(:taxon)
taxon_2 = create(:taxon, name: 'Clothing')
- product = create(:product)
+ product = create(:product, stores: Spree::Store.all)
product.taxons << taxon_1
visit spree.admin_products_path
diff --git a/backend/spec/features/admin/products/edit/variants_spec.rb b/backend/spec/features/admin/products/edit/variants_spec.rb
index 2c4480b081..38f4d5c8be 100644
--- a/backend/spec/features/admin/products/edit/variants_spec.rb
+++ b/backend/spec/features/admin/products/edit/variants_spec.rb
@@ -4,7 +4,7 @@ describe 'Product Variants', type: :feature, js: true do
stub_authorization!
before do
- create(:product)
+ create(:product, stores: Spree::Store.all)
create(:store, default: true, default_currency: 'USD')
visit spree.admin_products_path
end
diff --git a/backend/spec/features/admin/products/products_spec.rb b/backend/spec/features/admin/products/products_spec.rb
index 245d611874..66b0db9f9e 100644
--- a/backend/spec/features/admin/products/products_spec.rb
+++ b/backend/spec/features/admin/products/products_spec.rb
@@ -295,7 +295,7 @@ describe 'Products', type: :feature do
context 'cloning a product', js: true do
it 'allows an admin to clone a product' do
- create(:product)
+ create(:product, stores: Spree::Store.all)
visit spree.admin_products_path
within_row(1) do
@@ -326,7 +326,7 @@ describe 'Products', type: :feature do
end
context 'updating a product' do
- let(:product) { create(:product) }
+ let(:product) { create(:product, stores: Spree::Store.all) }
let(:prototype) do
size = build_option_type_with_values('size', %w(Small Medium Large))
@@ -413,7 +413,7 @@ describe 'Products', type: :feature do
end
context 'deleting a product', js: true do
- let!(:product) { create(:product) }
+ let!(:product) { create(:product, stores: Spree::Store.all) }
it 'is still viewable' do
visit spree.admin_products_path
@@ -454,7 +454,7 @@ describe 'Products', type: :feature do
end
context 'editing product compare at price', js: true do
- let!(:product) { create(:product) }
+ let!(:product) { create(:product, stores: Spree::Store.all) }
it 'lets admin edit compare at price for product' do
visit spree.admin_products_path
@@ -476,7 +476,7 @@ describe 'Products', type: :feature do
custom_authorization! do |_user|
can [:admin, :update, :read], Spree::Product
end
- let!(:product) { create(:product) }
+ let!(:product) { create(:product, stores: Spree::Store.all) }
it 'only displays accessible links on index' do
visit spree.admin_products_path
diff --git a/backend/spec/features/admin/products/properties_spec.rb b/backend/spec/features/admin/products/properties_spec.rb
index bb4b3eaa17..c3983a2f9e 100644
--- a/backend/spec/features/admin/products/properties_spec.rb
+++ b/backend/spec/features/admin/products/properties_spec.rb
@@ -92,7 +92,7 @@ describe 'Properties', type: :feature, js: true do
context 'linking a property to a product' do
before do
- create(:product)
+ create(:product, stores: Spree::Store.all)
visit spree.admin_products_path
click_icon :edit
within('#sidebar') do
diff --git a/backend/spec/features/admin/products/variant_prices_spec.rb b/backend/spec/features/admin/products/variant_prices_spec.rb
index 3e9c8e7758..33a104c304 100644
--- a/backend/spec/features/admin/products/variant_prices_spec.rb
+++ b/backend/spec/features/admin/products/variant_prices_spec.rb
@@ -4,7 +4,7 @@ describe 'Variant Prices', type: :feature, js: true do
stub_authorization!
let!(:store) { create(:store, default: true, supported_currencies: 'USD,EUR') }
let!(:store2) { create(:store, default: false, default_currency: 'GBP') }
- let!(:product) { create(:product) }
+ let!(:product) { create(:product, stores: Spree::Store.all) }
context 'with USD and EUR as currencies' do
it 'allows to save a price for each currency' do
diff --git a/backend/spec/features/admin/stock_transfer_spec.rb b/backend/spec/features/admin/stock_transfer_spec.rb
index eed419fa62..bf5a34596c 100644
--- a/backend/spec/features/admin/stock_transfer_spec.rb
+++ b/backend/spec/features/admin/stock_transfer_spec.rb
@@ -51,7 +51,7 @@ describe 'Stock Transfers', type: :feature, js: true do
create(:stock_location_with_items, name: 'NY') # source_location
create(:stock_location, name: 'SF') # destination_location
- product = create(:product)
+ product = create(:product, stores: Spree::Store.all)
Spree::StockLocation.first.stock_items.where(variant_id: product.master.id).first.adjust_count_on_hand(0)
visit spree.admin_stock_transfers_path
diff --git a/backend/spec/features/admin/taxons_spec.rb b/backend/spec/features/admin/taxons_spec.rb
index 39c4cd94d0..cefb13ab52 100644
--- a/backend/spec/features/admin/taxons_spec.rb
+++ b/backend/spec/features/admin/taxons_spec.rb
@@ -30,7 +30,7 @@ describe 'Taxonomies and taxons', type: :feature, js: true do
it 'admin should be able to remove a product from a taxon', js: true do
taxon_1 = create(:taxon, name: 'Clothing')
- product = create(:product)
+ product = create(:product, stores: Spree::Store.all)
product.taxons << taxon_1
visit spree.admin_taxons_path
diff --git a/core/app/models/concerns/spree/multiple_stores_resource.rb b/core/app/models/concerns/spree/multiple_stores_resource.rb
index ae57b02b05..f840b7e7c9 100644
--- a/core/app/models/concerns/spree/multiple_stores_resource.rb
+++ b/core/app/models/concerns/spree/multiple_stores_resource.rb
@@ -4,6 +4,21 @@ module Spree
included do
scope :for_store, ->(store) { joins(:stores).where(Store.table_name => { id: store.id }) }
+
+ validate :must_have_one_store, unless: :disable_store_presence_validation?
+ end
+
+ protected
+
+ def must_have_one_store
+ return if stores.any?
+
+ errors.add(:stores, Spree.t(:must_have_one_store))
+ end
+
+ # this can be overriden on model basis
+ def disable_store_presence_validation?
+ false
end
end
end
diff --git a/core/config/locales/en.yml b/core/config/locales/en.yml
index 17e2c7fcff..c04ae1d203 100644
--- a/core/config/locales/en.yml
+++ b/core/config/locales/en.yml
@@ -1091,6 +1091,7 @@ en:
move_stock_between_locations: Move Stock Between Locations
my_account: My Account
my_orders: My Orders
+ must_have_one_store: Must have at least one Store associated
name: Name
name_on_card: Name on card
name_or_sku: Name or SKU (enter at least first 3 characters of product name)
diff --git a/core/lib/spree/core/importer/product.rb b/core/lib/spree/core/importer/product.rb
index 6d7c5707e4..62ccd9c705 100644
--- a/core/lib/spree/core/importer/product.rb
+++ b/core/lib/spree/core/importer/product.rb
@@ -2,10 +2,12 @@ module Spree
module Core
module Importer
class Product
- attr_reader :product, :product_attrs, :variants_attrs, :options_attrs
+ attr_reader :product, :product_attrs, :variants_attrs, :options_attrs, :store
def initialize(product, product_params, options = {})
+ @store = options[:store] || Spree::Store.default
@product = product || Spree::Product.new(product_params)
+ @product.stores << @store if @product.stores.exclude?(@store)
@product_attrs = product_params.to_h
@variants_attrs = (options[:variants_attrs] || []).map(&:to_h)
diff --git a/core/lib/spree/core/product_duplicator.rb b/core/lib/spree/core/product_duplicator.rb
index 8021a2c6ed..f5ae3c0b03 100644
--- a/core/lib/spree/core/product_duplicator.rb
+++ b/core/lib/spree/core/product_duplicator.rb
@@ -28,6 +28,7 @@ module Spree
product.dup.tap do |new_product|
new_product.name = "COPY OF #{product.name}"
new_product.taxons = product.taxons
+ new_product.stores = product.stores
new_product.created_at = nil
new_product.deleted_at = nil
new_product.updated_at = nil
diff --git a/core/lib/spree/testing_support/factories/line_item_factory.rb b/core/lib/spree/testing_support/factories/line_item_factory.rb
index 1ea33ae6df..629c74117e 100644
--- a/core/lib/spree/testing_support/factories/line_item_factory.rb
+++ b/core/lib/spree/testing_support/factories/line_item_factory.rb
@@ -4,9 +4,7 @@ FactoryBot.define do
quantity { 1 }
price { BigDecimal('10.00') }
currency { order.currency }
- transient do
- association :product
- end
+ product { create(:product, stores: [order.store]) }
variant { product.master }
end
end
diff --git a/core/lib/spree/testing_support/factories/payment_method_factory.rb b/core/lib/spree/testing_support/factories/payment_method_factory.rb
index 316c97222e..5d953a5f51 100644
--- a/core/lib/spree/testing_support/factories/payment_method_factory.rb
+++ b/core/lib/spree/testing_support/factories/payment_method_factory.rb
@@ -26,7 +26,7 @@ FactoryBot.define do
name { 'Credit Card' }
end
- factory :store_credit_payment_method, class: Spree::PaymentMethod::StoreCredit do
+ factory :store_credit_payment_method, parent: :payment_method, class: Spree::PaymentMethod::StoreCredit do
type { 'Spree::PaymentMethod::StoreCredit' }
name { 'Store Credit' }
description { 'Store Credit' }
diff --git a/core/lib/spree/testing_support/factories/product_factory.rb b/core/lib/spree/testing_support/factories/product_factory.rb
index 397e9f81ee..b5e3846d5f 100644
--- a/core/lib/spree/testing_support/factories/product_factory.rb
+++ b/core/lib/spree/testing_support/factories/product_factory.rb
@@ -9,19 +9,16 @@ FactoryBot.define do
deleted_at { nil }
shipping_category { |r| Spree::ShippingCategory.first || r.association(:shipping_category) }
- transient do
- with_store { true }
- end
-
# ensure stock item will be created for this products master
- before(:create) { create(:stock_location) unless Spree::StockLocation.any? }
+ # also attach this product to the default store if no stores are passed in
+ before(:create) do |product|
+ create(:stock_location) unless Spree::StockLocation.any?
- before(:create) do |product, evaluator|
- if evaluator.with_store && product.stores.empty?
+ if product.stores.empty?
default_store = Spree::Store.default.persisted? ? Spree::Store.default : nil
- store = default_store || create(:store, default: true)
+ store = default_store || create(:store)
- product.stores << store
+ product.stores << [store]
end
end
diff --git a/core/lib/spree/testing_support/factories/product_property_factory.rb b/core/lib/spree/testing_support/factories/product_property_factory.rb
index 9844faea47..4dca3fc7af 100644
--- a/core/lib/spree/testing_support/factories/product_property_factory.rb
+++ b/core/lib/spree/testing_support/factories/product_property_factory.rb
@@ -1,6 +1,6 @@
FactoryBot.define do
factory :product_property, class: Spree::ProductProperty do
- product
+ product { create(:product, stores: [create(:store)]) }
property
end
end
diff --git a/core/lib/spree/testing_support/factories/stock_location_factory.rb b/core/lib/spree/testing_support/factories/stock_location_factory.rb
index 8384ae4751..1ca9bb78c9 100644
--- a/core/lib/spree/testing_support/factories/stock_location_factory.rb
+++ b/core/lib/spree/testing_support/factories/stock_location_factory.rb
@@ -17,8 +17,9 @@ FactoryBot.define do
after(:create) do |stock_location, _evaluator|
# variant will add itself to all stock_locations in an after_create
# creating a product will automatically create a master variant
- product_1 = create(:product)
- product_2 = create(:product)
+ store = create(:store)
+ product_1 = create(:product, stores: [store])
+ product_2 = create(:product, stores: [store])
stock_location.stock_items.where(variant_id: product_1.master.id).first.adjust_count_on_hand(10)
stock_location.stock_items.where(variant_id: product_2.master.id).first.adjust_count_on_hand(20)
diff --git a/core/lib/spree/testing_support/factories/variant_factory.rb b/core/lib/spree/testing_support/factories/variant_factory.rb
index cf2e794ec0..ab1b4debc4 100644
--- a/core/lib/spree/testing_support/factories/variant_factory.rb
+++ b/core/lib/spree/testing_support/factories/variant_factory.rb
@@ -12,7 +12,7 @@ FactoryBot.define do
is_master { 0 }
track_inventory { true }
- product { |p| p.association(:base_product) }
+ product { |p| p.association(:base_product, stores: [create(:store)]) }
option_values { [create(:option_value)] }
# ensure stock item will be created for this variant
@@ -20,7 +20,7 @@ FactoryBot.define do
factory :variant do
# on_hand 5
- product { |p| p.association(:product) }
+ product { |p| p.association(:product, stores: [create(:store)]) }
end
factory :master_variant do
diff --git a/core/spec/finders/spree/variants/option_types_finder_spec.rb b/core/spec/finders/spree/variants/option_types_finder_spec.rb
index ae859ffa4d..da5f83d347 100644
--- a/core/spec/finders/spree/variants/option_types_finder_spec.rb
+++ b/core/spec/finders/spree/variants/option_types_finder_spec.rb
@@ -5,7 +5,7 @@ describe Spree::Variants::OptionTypesFinder do
let(:option_type_1) { create :option_type, position: 2 }
let(:option_type_2) { create :option_type, position: 1 }
- let(:product) { create :product, option_types: [option_type_1, option_type_2] }
+ let(:product) { create :product, option_types: [option_type_1, option_type_2], stores: [create(:store)] }
let!(:variant_1) { create :variant, product: product, option_values: [option_value_1_1, option_value_2_2] }
let!(:variant_2) { create :variant, product: product, option_values: [option_value_1_2, option_value_2_1] }
diff --git a/core/spec/helpers/base_helper_spec.rb b/core/spec/helpers/base_helper_spec.rb
index 8f6f09292e..c01368191e 100644
--- a/core/spec/helpers/base_helper_spec.rb
+++ b/core/spec/helpers/base_helper_spec.rb
@@ -180,7 +180,7 @@ describe Spree::BaseHelper, type: :helper do
# controller_name is used by this method to infer what it is supposed
# to be generating meta_data_tags for
text = FFaker::Lorem.paragraphs(2).join(' ')
- @test = Spree::Product.new(description: text)
+ @test = Spree::Product.new(description: text, stores: [current_store])
tags = Nokogiri::HTML.parse(meta_data_tags)
content = tags.css('meta[name=description]').first['content']
assert content.length <= 160, 'content length is not truncated to 160 characters'
@@ -191,7 +191,7 @@ describe Spree::BaseHelper, type: :helper do
let(:current_currency) { 'USD' }
let(:image) { create(:image, position: 1) }
let(:product) do
- create(:product).tap { |product| product.master.images << image }
+ create(:product, stores: [current_store]).tap { |product| product.master.images << image }
end
it 'renders open graph meta data tags for PDP' do
@@ -244,7 +244,7 @@ describe Spree::BaseHelper, type: :helper do
end
describe '#display_price' do
- let!(:product) { create(:product) }
+ let!(:product) { create(:product, stores: [current_store]) }
let(:current_currency) { 'USD' }
let(:current_price_options) { { tax_zone: current_tax_zone } }
@@ -307,7 +307,7 @@ describe Spree::BaseHelper, type: :helper do
end
describe '#default_image_for_product_or_variant' do
- let(:product) { build :product }
+ let(:product) { build :product, stores: [current_store] }
let(:variant) { build :variant, product: product }
subject(:default_image) { default_image_for_product_or_variant(product_or_variant) }
diff --git a/core/spec/helpers/products_helper_spec.rb b/core/spec/helpers/products_helper_spec.rb
index 0324a5e970..ad37c7f346 100644
--- a/core/spec/helpers/products_helper_spec.rb
+++ b/core/spec/helpers/products_helper_spec.rb
@@ -4,7 +4,9 @@ module Spree
describe ProductsHelper, type: :helper do
include ProductsHelper
- let(:product) { create(:product) }
+ let(:store) { create(:store) }
+
+ let(:product) { create(:product, stores: [store]) }
let(:currency) { 'USD' }
before do
@@ -199,7 +201,7 @@ THIS IS THE BEST PRODUCT EVER!
let(:zone) { Spree::Zone.new }
let(:price_options) { { tax_zone: zone } }
- let!(:products) { create_list(:product, 5) }
+ let!(:products) { create_list(:product, 5, stores: [store]) }
let(:product_ids) { products.map(&:id).join('-') }
let(:taxon) { create(:taxon) }
@@ -259,7 +261,7 @@ THIS IS THE BEST PRODUCT EVER!
context '#cache_key_for_product' do
subject(:cache_key) { helper.cache_key_for_product(product) }
- let(:product) { Spree::Product.new }
+ let(:product) { store.products.new }
let(:price_options) { { tax_zone: zone } }
before do
@@ -335,7 +337,7 @@ THIS IS THE BEST PRODUCT EVER!
context '#available_status' do
subject(:status) { helper.available_status(product) }
- let(:product) { create(:product) }
+ let(:product) { create(:product, stores: [store]) }
context 'product is available' do
it 'has available status' do
diff --git a/core/spec/lib/spree/core/importer/order_spec.rb b/core/spec/lib/spree/core/importer/order_spec.rb
index 1634f95798..cead9c0619 100644
--- a/core/spec/lib/spree/core/importer/order_spec.rb
+++ b/core/spec/lib/spree/core/importer/order_spec.rb
@@ -3,28 +3,18 @@ require 'spec_helper'
module Spree
module Core
describe Importer::Order do
- let!(:country) { create(:country, iso: 'US', iso3: 'USA') }
+ let(:store) { create(:store, default_country: create(:country, iso: 'US')) }
+ let!(:country) { store.default_country }
let!(:state) { country.states.first || create(:state, country: country) }
let!(:stock_location) { create(:stock_location, admin_name: 'Admin Name') }
- let(:user) { stub_model(LegacyUser, email: '[email protected]') }
+ let(:user) { create(:user) }
let(:shipping_method) { create(:shipping_method) }
- let(:payment_method) { create(:check_payment_method) }
+ let(:payment_method) { create(:check_payment_method, stores: [store]) }
- let(:product) do
- product = Spree::Product.create(name: 'Test',
- sku: 'TEST-1',
- price: 33.22, available_on: Time.current - 1.day)
- product.shipping_category = create(:shipping_category)
- product.save
- product
- end
+ let(:product) { create(:product_in_stock, stores: [store], name: 'Test', sku: 'TEST-1', price: 33.22) }
- let(:variant) do
- variant = product.master
- variant.stock_items.each { |si| si.update_attribute(:count_on_hand, 10) }
- variant
- end
+ let(:variant) { product.master }
let(:sku) { variant.sku }
let(:variant_id) { variant.id }
@@ -100,7 +90,6 @@ module Spree
expect(Importer::Order).to receive(:ensure_variant_id_from_params).and_return(variant_id: variant.id,
quantity: 5)
order = Importer::Order.import(user, params)
- expect(order.user).to eq(nil)
line_item = order.line_items.first
expect(line_item.quantity).to eq(5)
expect(line_item.variant_id).to eq(variant_id)
diff --git a/core/spec/models/spree/ability_spec.rb b/core/spec/models/spree/ability_spec.rb
index 6ffb527bdf..cc790920b1 100644
--- a/core/spec/models/spree/ability_spec.rb
+++ b/core/spec/models/spree/ability_spec.rb
@@ -18,6 +18,7 @@ class FooAbility
end
describe Spree::Ability, type: :model do
+ let(:store) { create(:store) }
let(:user) { build(:user) }
let(:ability) { Spree::Ability.new(user) }
let(:token) { nil }
@@ -69,9 +70,9 @@ describe Spree::Ability, type: :model do
context 'for admin protected resources' do
let(:resource) { Object.new }
let(:resource_shipment) { Spree::Shipment.new }
- let(:resource_product) { Spree::Product.new }
+ let(:resource_product) { store.products.new }
let(:resource_user) { create :user }
- let(:resource_order) { Spree::Order.new }
+ let(:resource_order) { store.orders.new }
let(:fakedispatch_user) { Spree.user_class.create }
let(:fakedispatch_ability) { Spree::Ability.new(fakedispatch_user) }
@@ -189,7 +190,7 @@ describe Spree::Ability, type: :model do
end
context 'for Product' do
- let(:resource) { Spree::Product.new }
+ let(:resource) { store.products.new }
context 'requested by any user' do
it_behaves_like 'read only'
@@ -197,7 +198,7 @@ describe Spree::Ability, type: :model do
end
context 'for ProductProperty' do
- let(:resource) { Spree::Product.new }
+ let(:resource) { store.products.new }
context 'requested by any user' do
it_behaves_like 'read only'
@@ -205,7 +206,7 @@ describe Spree::Ability, type: :model do
end
context 'for Property' do
- let(:resource) { Spree::Product.new }
+ let(:resource) { store.products.new }
context 'requested by any user' do
it_behaves_like 'read only'
diff --git a/core/spec/models/spree/classification_spec.rb b/core/spec/models/spree/classification_spec.rb
index 2149a902f0..7517d84ce3 100644
--- a/core/spec/models/spree/classification_spec.rb
+++ b/core/spec/models/spree/classification_spec.rb
@@ -2,18 +2,20 @@ require 'spec_helper'
module Spree
describe Classification, type: :model do
+ let(:store) { create(:store) }
+
# Regression test for #3494
let(:taxon_with_5_products) do
products = []
5.times do
- products << create(:base_product)
+ products << create(:base_product, stores: [store])
end
create(:taxon, products: products)
end
it 'cannot link the same taxon to the same product more than once' do
- product = create(:product)
+ product = create(:product, stores: [store])
taxon = create(:taxon)
expect { product.taxons << taxon }.not_to raise_error
expect { product.taxons << taxon }.to raise_error(ActiveRecord::RecordInvalid)
diff --git a/core/spec/models/spree/line_item_spec.rb b/core/spec/models/spree/line_item_spec.rb
index cbd729ceea..a8b76340b2 100644
--- a/core/spec/models/spree/line_item_spec.rb
+++ b/core/spec/models/spree/line_item_spec.rb
@@ -1,11 +1,10 @@
require 'spec_helper'
describe Spree::LineItem, type: :model do
- let(:order) { create :order_with_line_items, line_items_count: 1 }
+ let!(:store) { create(:store) }
+ let(:order) { create :order_with_line_items, line_items_count: 1, store: store }
let(:line_item) { order.line_items.first }
- before { create(:store) }
-
describe 'Validations' do
describe 'ensure_proper_currency' do
context 'order is present' do
@@ -174,7 +173,7 @@ describe Spree::LineItem, type: :model do
describe '#update_price' do
let(:currency) { 'EUR' }
let(:order) { create(:order, currency: currency) }
- let(:product) { create(:product_in_stock) }
+ let(:product) { create(:product_in_stock, stores: [store]) }
let!(:line_item) { create(:line_item, order_id: order.id, currency: currency, product: product, variant: product.master) }
let!(:price) { create(:price, currency: currency, variant: product.master, amount: 12) }
diff --git a/core/spec/models/spree/menu_item_spec.rb b/core/spec/models/spree/menu_item_spec.rb
index 054c91ac15..6e8d870a6f 100644
--- a/core/spec/models/spree/menu_item_spec.rb
+++ b/core/spec/models/spree/menu_item_spec.rb
@@ -105,7 +105,7 @@ describe Spree::MenuItem, type: :model do
end
describe '#link' do
- let(:product) { create(:product) }
+ let(:product) { create(:product, stores: [store]) }
let(:taxon) { create(:taxon) }
let(:item_url) { create(:menu_item, name: 'URL To Random Site', item_type: 'Link', menu: menu, linked_resource_type: 'URL', destination: 'https://some-other-website.com') }
let(:item_empty_url) { create(:menu_item, name: 'URL To Random Site', item_type: 'Link', menu: menu, linked_resource_type: 'URL', destination: nil) }
diff --git a/core/spec/models/spree/order_spec.rb b/core/spec/models/spree/order_spec.rb
index cd0b56c49c..c777d71458 100644
--- a/core/spec/models/spree/order_spec.rb
+++ b/core/spec/models/spree/order_spec.rb
@@ -8,7 +8,7 @@ end
describe Spree::Order, type: :model do
let(:user) { stub_model(Spree::LegacyUser, email: '[email protected]') }
- let(:store) { create(:store, default: true) }
+ let!(:store) { create(:store, default: true) }
let(:order) { stub_model(Spree::Order, user: user, store: store) }
before do
@@ -1191,8 +1191,8 @@ describe Spree::Order, type: :model do
describe '#collect_backend_payment_methods' do
let!(:order) { create(:order_with_line_items, line_items_count: 2) }
- let!(:credit_card_payment_method) { create(:simple_credit_card_payment_method, display_on: 'both') }
- let!(:store_credit_payment_method) { create(:store_credit_payment_method, display_on: 'both') }
+ let!(:credit_card_payment_method) { create(:simple_credit_card_payment_method, display_on: 'both', stores: [store]) }
+ let!(:store_credit_payment_method) { create(:store_credit_payment_method, display_on: 'both', stores: [store]) }
it { expect(order.collect_backend_payment_methods).to include(credit_card_payment_method) }
it { expect(order.collect_backend_payment_methods).not_to include(store_credit_payment_method) }
diff --git a/core/spec/models/spree/order_updater_spec.rb b/core/spec/models/spree/order_updater_spec.rb
index 939ca253e4..abcd6dac32 100644
--- a/core/spec/models/spree/order_updater_spec.rb
+++ b/core/spec/models/spree/order_updater_spec.rb
@@ -3,7 +3,7 @@ require 'spree/testing_support/order_walkthrough'
module Spree
describe OrderUpdater, type: :model do
- let(:order) { Spree::Order.create }
+ let(:order) { create(:order) }
let(:updater) { Spree::OrderUpdater.new(order) }
context 'order totals' do
@@ -202,7 +202,7 @@ module Spree
previous_state: nil,
next_state: 'shipped',
name: 'shipment',
- user_id: nil
+ user_id: order.user_id
)
order.state_changed('shipment')
diff --git a/core/spec/models/spree/payment_method_spec.rb b/core/spec/models/spree/payment_method_spec.rb
index 5f573bf7a1..7cba681137 100644
--- a/core/spec/models/spree/payment_method_spec.rb
+++ b/core/spec/models/spree/payment_method_spec.rb
@@ -138,4 +138,12 @@ describe Spree::PaymentMethod, type: :model do
expect(eligible).to be true
end
end
+
+ describe '#ensure_store_presence' do
+ let(:valid_payment_method) { build(:payment_method, stores: [create(:store)]) }
+ let(:invalid_payment_mthod) { build(:payment_method, stores: []) }
+
+ it { expect(valid_payment_method).to be_valid }
+ it { expect(invalid_payment_mthod).not_to be_valid }
+ end
end
diff --git a/core/spec/models/spree/product/scopes_spec.rb b/core/spec/models/spree/product/scopes_spec.rb
index deeb0667c9..b15b72e689 100644
--- a/core/spec/models/spree/product/scopes_spec.rb
+++ b/core/spec/models/spree/product/scopes_spec.rb
@@ -1,36 +1,37 @@
require 'spec_helper'
describe 'Product scopes', type: :model do
- let!(:product) { create(:product) }
+ let(:store) { create(:store) }
+ let!(:product) { create(:product, stores: [store]) }
describe '#available' do
context 'when discontinued' do
- let!(:discontinued_product) { create(:product, discontinue_on: Time.current - 1.day) }
+ let!(:discontinued_product) { create(:product, discontinue_on: Time.current - 1.day, stores:[store]) }
it { expect(Spree::Product.available).not_to include(discontinued_product) }
end
context 'when not discontinued' do
- let!(:product_2) { create(:product, discontinue_on: Time.current + 1.day) }
+ let!(:product_2) { create(:product, discontinue_on: Time.current + 1.day, stores: [store]) }
it { expect(Spree::Product.available).to include(product_2) }
end
context 'when available' do
- let!(:product_2) { create(:product, available_on: Time.current - 1.day) }
+ let!(:product_2) { create(:product, available_on: Time.current - 1.day,stores: [store]) }
it { expect(Spree::Product.available).to include(product_2) }
end
context 'when not available' do
- let!(:unavailable_product) { create(:product, available_on: Time.current + 1.day) }
+ let!(:unavailable_product) { create(:product, available_on: Time.current + 1.day,stores: [store]) }
it { expect(Spree::Product.available).not_to include(unavailable_product) }
end
context 'different currency' do
let!(:price_eur) { create(:price, variant: product.master, currency: 'EUR') }
- let!(:product_2) { create(:product) }
+ let!(:product_2) { create(:product, stores: [store]) }
it { expect(Spree::Product.available(nil, 'EUR')).to include(product) }
it { expect(Spree::Product.available(nil, 'EUR')).not_to include(product_2) }
@@ -43,11 +44,11 @@ describe 'Product scopes', type: :model do
let(:taxon_1) { create(:taxon) }
let(:taxon_2) { create(:taxon) }
- let!(:product_1) { create(:product, currency: 'GBP', taxons: [taxon_1]) }
- let!(:product_2) { create(:product, currency: 'GBP', taxons: [taxon_2]) }
+ let!(:product_1) { create(:product, currency: 'GBP', taxons: [taxon_1], stores: [store]) }
+ let!(:product_2) { create(:product, currency: 'GBP', taxons: [taxon_2], stores: [store]) }
before do
- create(:product, currency: 'USD', taxons: [create(:taxon)])
+ create(:product, currency: 'USD', taxons: [create(:taxon)], stores: [store])
end
context 'when giving a taxon' do
@@ -85,7 +86,7 @@ describe 'Product scopes', type: :model do
context 'orders products based on their ordering within the classifications' do
let(:other_taxon) { create(:taxon, products: [product]) }
- let!(:product_2) { create(:product, taxons: [@child_taxon, other_taxon]) }
+ let!(:product_2) { create(:product, taxons: [@child_taxon, other_taxon], stores: [store]) }
it 'by initial ordering' do
expect(Spree::Product.in_taxon(@child_taxon)).to eq([product, product_2])
@@ -175,12 +176,12 @@ describe 'Product scopes', type: :model do
context 'with_property_values' do
subject(:with_property_values) { Spree::Product.method(:with_property_values) }
- let!(:product_2) { create(:product, product_properties: [product_2_property]) }
+ let!(:product_2) { create(:product, product_properties: [product_2_property], stores: [store]) }
let(:product_2_property) { create(:product_property, property: property, value: value_2) }
let(:value_2) { 'Beta 10%' }
before do
- create(:product, product_properties: [create(:product_property, property: property, value: '20% Gamma')])
+ create(:product, product_properties: [create(:product_property, property: property, value: '20% Gamma')], stores: [store])
end
it 'finds by property values' do
@@ -232,9 +233,9 @@ describe 'Product scopes', type: :model do
end
context '#search_by_name' do
- let!(:first_product) { create(:product, name: 'First product') }
- let!(:second_product) { create(:product, name: 'Second product') }
- let!(:third_product) { create(:product, name: 'Other second product') }
+ let!(:first_product) { create(:product, name: 'First product', stores: [store]) }
+ let!(:second_product) { create(:product, name: 'Second product',stores: [store]) }
+ let!(:third_product) { create(:product, name: 'Other second product',stores: [store]) }
it 'shows product whose name contains phrase' do
result = Spree::Product.search_by_name('First').to_a
@@ -268,30 +269,30 @@ describe 'Product scopes', type: :model do
let(:child_taxon_2) { create(:taxon, parent: parent_taxon) }
let(:child_taxon_2_1) { create(:taxon, parent: child_taxon_2) }
- let!(:product_1) { create(:product) }
+ let!(:product_1) { create(:product, stores: [store]) }
let!(:classification_1_1) { create(:classification, position: 5, product: product_1, taxon: parent_taxon) }
let!(:classification_1_2) { create(:classification, position: 4, product: product_1, taxon: child_taxon_1_1) }
- let!(:product_2) { create(:product) }
+ let!(:product_2) { create(:product, stores: [store]) }
let!(:classification_2_1) { create(:classification, position: 1, product: product_2, taxon: parent_taxon) }
let!(:classification_2_2) { create(:classification, position: 2, product: product_2, taxon: child_taxon_2_1) }
- let!(:product_3) { create(:product) }
+ let!(:product_3) { create(:product, stores: [store]) }
let!(:classification_3_1) { create(:classification, position: 3, product: product_3, taxon: child_taxon_1) }
let!(:classification_3_2) { create(:classification, position: 4, product: product_3, taxon: child_taxon_2_1) }
- let!(:product_4) { create(:product) }
+ let!(:product_4) { create(:product, stores: [store]) }
let!(:classification_4_1) { create(:classification, position: 2, product: product_4, taxon: child_taxon_2) }
- let!(:product_5) { create(:product) }
+ let!(:product_5) { create(:product, stores: [store]) }
let!(:classification_5_1) { create(:classification, position: 1, product: product_5, taxon: child_taxon_1_1) }
- let!(:product_6) { create(:product) }
+ let!(:product_6) { create(:product, stores: [store]) }
let!(:classification_6_1) { create(:classification, position: 6, product: product_6, taxon: child_taxon_2) }
let!(:classification_6_2) { create(:classification, position: 3, product: product_6, taxon: child_taxon_1) }
before do
- create_list(:product, 3, taxons: [create(:taxon)])
+ create_list(:product, 3, taxons: [create(:taxon)], stores: [store])
end
it 'orders products by ascending taxons minimum position' do
@@ -309,17 +310,12 @@ describe 'Product scopes', type: :model do
describe '#for_store' do
subject(:products_by_store) { Spree::Product.for_store(store) }
- let(:store) { create(:store) }
-
- let!(:product_1) { create(:product, stores: [store]) }
- let!(:product_2) { create(:product, stores: [store]) }
-
before do
create_list(:product, 3, stores: [create(:store)])
end
it 'returns products assigned to a store' do
- expect(products_by_store).to contain_exactly(product_1, product_2)
+ expect(products_by_store).to contain_exactly(product)
end
end
end
diff --git a/core/spec/models/spree/product_duplicator_spec.rb b/core/spec/models/spree/product_duplicator_spec.rb
index bd4812000a..eefcce0e90 100644
--- a/core/spec/models/spree/product_duplicator_spec.rb
+++ b/core/spec/models/spree/product_duplicator_spec.rb
@@ -2,7 +2,8 @@ require 'spec_helper'
module Spree
describe Spree::ProductDuplicator, type: :model do
- let!(:product) { create(:product, properties: [create(:property, name: 'MyProperty')]) }
+ let(:store) { create(:store) }
+ let!(:product) { create(:product, properties: [create(:property, name: 'MyProperty')], stores: [store]) }
let!(:duplicator) { Spree::ProductDuplicator.new(product) }
let(:file) { File.open(File.expand_path('../../fixtures/thinking-cat.jpg', __dir__)) }
@@ -84,6 +85,12 @@ module Spree
end
end
+ context 'stores' do
+ let!(:new_product) { duplicator.duplicate }
+
+ it { expect(new_product.stores).to eq [store] }
+ end
+
context 'with variants' do
let(:option_type) { create(:option_type, name: 'MyOptionType') }
let(:option_value1) { create(:option_value, name: 'OptionValue1', option_type: option_type) }
diff --git a/core/spec/models/spree/product_filter_spec.rb b/core/spec/models/spree/product_filter_spec.rb
index 57fce5f83f..cec94eb99d 100644
--- a/core/spec/models/spree/product_filter_spec.rb
+++ b/core/spec/models/spree/product_filter_spec.rb
@@ -2,9 +2,11 @@ require 'spec_helper'
require 'spree/core/product_filters'
describe 'product filters', type: :model do
+ let(:store) { create(:store) }
+
# Regression test for #1709
context 'finds products filtered by brand' do
- let(:product) { create(:product) }
+ let(:product) { create(:product, stores: [store]) }
before do
Spree::Property.create!(name: 'brand', presentation: 'brand')
@@ -20,7 +22,7 @@ describe 'product filters', type: :model do
end
it 'sorts products without brand specified' do
product.set_property('brand', 'Nike')
- create(:product).set_property('brand', nil)
+ create(:product, stores: [store]).set_property('brand', nil)
expect { Spree::Core::ProductFilters.brand_filter[:labels] }.not_to raise_error
end
end
diff --git a/core/spec/models/spree/product_spec.rb b/core/spec/models/spree/product_spec.rb
index 3509de50e7..8bb8f45854 100644
--- a/core/spec/models/spree/product_spec.rb
+++ b/core/spec/models/spree/product_spec.rb
@@ -8,8 +8,10 @@ module ThirdParty
end
describe Spree::Product, type: :model do
+ let!(:store) { create(:store) }
+
context 'product instance' do
- let(:product) { create(:product) }
+ let(:product) { create(:product, stores: [store]) }
let(:variant) { create(:variant, product: product) }
%w[purchasable backorderable in_stock].each do |method_name|
@@ -32,7 +34,7 @@ describe Spree::Product, type: :model do
context '#duplicate' do
before do
- allow(product).to receive_messages taxons: [create(:taxon)]
+ allow(product).to receive_messages taxons: [create(:taxon)], stores: [store]
end
it 'duplicates product' do
@@ -40,6 +42,7 @@ describe Spree::Product, type: :model do
expect(clone.name).to eq('COPY OF ' + product.name)
expect(clone.master.sku).to eq('COPY OF ' + product.master.sku)
expect(clone.taxons).to eq(product.taxons)
+ expect(clone.stores).to eq(product.stores)
expect(clone.images.size).to eq(product.images.size)
end
@@ -236,19 +239,19 @@ describe Spree::Product, type: :model do
it 'validates slug uniqueness' do
existing_product = product
- new_product = create(:product)
+ new_product = create(:product, stores: [store])
new_product.slug = existing_product.slug
expect(new_product.valid?).to eq false
end
it "falls back to 'name-sku' for slug if regular name-based slug already in use" do
- product1 = build(:product)
+ product1 = build(:product, stores: [store])
product1.name = 'test'
product1.sku = '123'
product1.save!
- product2 = build(:product)
+ product2 = build(:product, stores: [store])
product2.name = 'test'
product2.sku = '456'
product2.save!
@@ -299,7 +302,7 @@ describe Spree::Product, type: :model do
context 'history' do
before do
- @product = create(:product)
+ @product = create(:product, stores: [store])
end
it 'keeps the history when the product is destroyed' do
@@ -343,7 +346,7 @@ describe Spree::Product, type: :model do
end
context 'properties' do
- let(:product) { create(:product) }
+ let(:product) { create(:product, stores: [store]) }
it 'properly assigns properties' do
product.set_property('the_prop', 'value1')
@@ -416,9 +419,9 @@ describe Spree::Product, type: :model do
end
end
- context '#create' do
+ describe '#create' do
let!(:prototype) { create(:prototype) }
- let!(:product) { Spree::Product.new(name: 'Foo', price: 1.99, shipping_category_id: create(:shipping_category).id) }
+ let!(:product) { build(:product, name: 'Foo', price: 1.99, shipping_category: create(:shipping_category), stores: [store]) }
before { product.prototype_id = prototype.id }
@@ -491,7 +494,7 @@ describe Spree::Product, type: :model do
end
context '#images' do
- let(:product) { create(:product) }
+ let(:product) { create(:product, stores: [store]) }
let(:file) { File.open(File.expand_path('../../fixtures/thinking-cat.jpg', __dir__)) }
let(:params) { { viewable_id: product.master.id, viewable_type: 'Spree::Variant', alt: 'position 2', position: 2 } }
@@ -531,7 +534,7 @@ describe Spree::Product, type: :model do
end
context '#total_on_hand' do
- let(:product) { create(:product) }
+ let(:product) { create(:product, stores: [store]) }
it 'is infinite if track_inventory_levels is false' do
Spree::Config[:track_inventory_levels] = false
@@ -559,19 +562,19 @@ describe Spree::Product, type: :model do
context '#validate_master when duplicate SKUs entered' do
subject { second_product }
- let!(:first_product) { create(:product, sku: 'a-sku') }
- let(:second_product) { build(:product, sku: 'a-sku') }
+ let!(:first_product) { create(:product, sku: 'a-sku', stores: [store]) }
+ let(:second_product) { build(:product, sku: 'a-sku', stores: [store]) }
it { is_expected.to be_invalid }
end
it 'initializes a master variant when building a product' do
- product = Spree::Product.new
+ product = store.products.new
expect(product.master.is_master).to be true
end
context '#discontinue!' do
- let(:product) { create(:product, sku: 'a-sku') }
+ let(:product) { create(:product, sku: 'a-sku', stores: [store]) }
it 'sets the discontinued' do
product.discontinue!
@@ -601,7 +604,7 @@ describe Spree::Product, type: :model do
context '#brand' do
let(:taxonomy) { create(:taxonomy, name: I18n.t('spree.taxonomy_brands_name')) }
- let(:product) { create(:product, taxons: [taxonomy.taxons.first]) }
+ let(:product) { create(:product, taxons: [taxonomy.taxons.first], stores: [store]) }
it 'fetches Brand Taxon' do
expect(product.brand).to eql(taxonomy.taxons.first)
@@ -610,7 +613,7 @@ describe Spree::Product, type: :model do
context '#category' do
let(:taxonomy) { create(:taxonomy, name: I18n.t('spree.taxonomy_categories_name')) }
- let(:product) { create(:product, taxons: [taxonomy.taxons.first]) }
+ let(:product) { create(:product, taxons: [taxonomy.taxons.first], stores: [store]) }
it 'fetches Category Taxon' do
expect(product.category).to eql(taxonomy.taxons.first)
@@ -618,7 +621,7 @@ describe Spree::Product, type: :model do
end
context '#backordered?' do
- let!(:product) { create(:product) }
+ let!(:product) { create(:product, stores: [store]) }
it 'returns true when out of stock and backorderable' do
expect(product.backordered?).to eq(true)
@@ -636,8 +639,8 @@ describe Spree::Product, type: :model do
end
describe '#ensure_no_line_items' do
- let(:product) { create(:product) }
- let!(:line_item) { create(:line_item, variant: product.master) }
+ let(:product) { create(:product, stores: [store]) }
+ let!(:line_item) { create(:line_item, variant: product.master, product: product) }
it 'adds error on product destroy' do
expect(product.destroy).to eq false
@@ -646,7 +649,7 @@ describe Spree::Product, type: :model do
end
context '#default_variant' do
- let(:product) { create(:product) }
+ let(:product) { create(:product, stores: [store]) }
context 'track inventory levels' do
context 'product has variants' do
@@ -707,7 +710,7 @@ describe Spree::Product, type: :model do
end
context '#default_variant_id' do
- let(:product) { create(:product) }
+ let(:product) { create(:product, stores: [store]) }
context 'product has variants' do
let!(:variant) { create(:variant, product: product) }
@@ -725,7 +728,7 @@ describe Spree::Product, type: :model do
end
describe '#default_variant_cache_key' do
- let(:product) { create(:product) }
+ let(:product) { create(:product, stores: [store]) }
let(:key) { product.send(:default_variant_cache_key) }
context 'with inventory tracking' do
@@ -756,4 +759,12 @@ describe Spree::Product, type: :model do
it { expect { product.valid? }.to change(product, :slug).to('my-slug') }
end
end
+
+ describe '#ensure_store_presence' do
+ let(:valid_product) { build(:product, stores: [create(:store)]) }
+ let(:invalid_product) { build(:product, stores: []) }
+
+ it { expect(valid_product).to be_valid }
+ it { expect(invalid_product).not_to be_valid }
+ end
end
diff --git a/core/spec/models/spree/promotion/rules/taxon_spec.rb b/core/spec/models/spree/promotion/rules/taxon_spec.rb
index e8a0b17871..3d59fcf102 100644
--- a/core/spec/models/spree/promotion/rules/taxon_spec.rb
+++ b/core/spec/models/spree/promotion/rules/taxon_spec.rb
@@ -3,10 +3,12 @@ require 'spec_helper'
describe Spree::Promotion::Rules::Taxon, type: :model do
let(:rule) { subject }
+ let(:store) { create(:store) }
+
context '#elegible?(order)' do
let(:taxon) { create :taxon, name: 'first' }
let(:taxon2) { create :taxon, name: 'second' }
- let(:order) { create :order_with_line_items }
+ let(:order) { create :order_with_line_items, store: store }
before do
rule.save
@@ -34,7 +36,7 @@ describe Spree::Promotion::Rules::Taxon, type: :model do
end
it 'does not act on a product in another taxon' do
- order.line_items << create(:line_item, product: create(:product, taxons: [taxon2]))
+ order.line_items << create(:line_item, product: create(:product, taxons: [taxon2], stores: [store]))
expect(rule).not_to be_actionable(order.line_items.last)
end
end
diff --git a/core/spec/models/spree/promotion_handler/cart_spec.rb b/core/spec/models/spree/promotion_handler/cart_spec.rb
index 60c254b26d..024ee40835 100644
--- a/core/spec/models/spree/promotion_handler/cart_spec.rb
+++ b/core/spec/models/spree/promotion_handler/cart_spec.rb
@@ -34,7 +34,7 @@ module Spree
end
context 'promotion has item total rule' do
- let(:shirt) { create(:product) }
+ let(:shirt) { create(:product, stores: [order.store]) }
let!(:rule) { Promotion::Rules::ItemTotal.create(preferred_operator_min: 'gt', preferred_amount_min: 50, preferred_operator_max: 'lt', preferred_amount_max: 150, promotion: promotion) }
before do
@@ -70,7 +70,7 @@ module Spree
end
context 'promotion has item total rule' do
- let(:shirt) { create(:product) }
+ let(:shirt) { create(:product, stores: [order.store]) }
let!(:rule) { Promotion::Rules::ItemTotal.create(preferred_operator_min: 'gt', preferred_amount_min: 50, preferred_operator_max: 'lt', preferred_amount_max: 150, promotion: promotion) }
before do
diff --git a/core/spec/models/spree/promotion_handler/coupon_spec.rb b/core/spec/models/spree/promotion_handler/coupon_spec.rb
index 8ffa74271e..d9f4a52dc1 100644
--- a/core/spec/models/spree/promotion_handler/coupon_spec.rb
+++ b/core/spec/models/spree/promotion_handler/coupon_spec.rb
@@ -5,7 +5,8 @@ module Spree
describe Coupon, type: :model do
subject { Coupon.new(order) }
- let(:order) { double('Order', coupon_code: '10off').as_null_object }
+ let(:store) { create(:store) }
+ let(:order) { double('Order', coupon_code: '10off', store: store).as_null_object }
it 'returns self in apply' do
expect(subject.apply).to be_a Coupon
@@ -72,7 +73,7 @@ module Spree
end
context 'with a per-item adjustment action' do
- let(:order) { create(:order_with_line_items, line_items_count: 3) }
+ let(:order) { create(:order_with_line_items, line_items_count: 3, store: store) }
context 'right coupon given' do
context 'with correct coupon code casing' do
@@ -115,7 +116,7 @@ module Spree
end
context 'coexists with a non coupon code promo' do
- let!(:order) { create(:order) }
+ let!(:order) { create(:order, store: store) }
before do
allow(order).to receive_messages coupon_code: '10off'
@@ -138,7 +139,7 @@ module Spree
let!(:action) { Promotion::Actions::FreeShipping.create(promotion: promotion) }
context 'right coupon code given' do
- let(:order) { create(:order_with_line_items, line_items_count: 3) }
+ let(:order) { create(:order_with_line_items, line_items_count: 3, store: store) }
before { allow(order).to receive_messages coupon_code: '10off' }
@@ -163,7 +164,7 @@ module Spree
let!(:action) { Promotion::Actions::CreateAdjustment.create(promotion: promotion, calculator: calculator) }
context 'right coupon given' do
- let(:order) { create(:order) }
+ let(:order) { create(:order, store: store) }
let(:calculator) { Calculator::FlatRate.new(preferred_amount: 10) }
before do
@@ -197,7 +198,7 @@ module Spree
subject.apply
expect(subject.successful?).to be true
- order_2 = create(:order)
+ order_2 = create(:order, store: store)
allow(order_2).to receive_messages coupon_code: '10off'
coupon = Coupon.new(order_2)
coupon.apply
@@ -219,7 +220,7 @@ module Spree
end
context 'for an order with taxable line items' do
- let!(:order) { create(:order, line_items_price: 0.0) }
+ let!(:order) { create(:order, line_items_price: 0.0, store: store) }
let!(:zone) { create(:zone_with_country, default_tax: true) }
let!(:tax_category) { create(:tax_category, name: 'Taxable Foo') }
let!(:rate) { create(:tax_rate, amount: 0.10, tax_category: tax_category, zone: zone) }
@@ -227,7 +228,7 @@ module Spree
before { allow(order).to receive(:coupon_code).and_return '10off' }
context 'and the product price is less than promo discount' do
- let(:product_list) { create_list(:product, 3, tax_category: tax_category, price: 9.0) }
+ let(:product_list) { create_list(:product, 3, tax_category: tax_category, price: 9.0, stores: [store]) }
before { product_list.each { |item| Spree::Cart::AddItem.call(order: order, variant: item.master) } }
@@ -243,7 +244,7 @@ module Spree
end
context 'and the product price is greater than promo discount' do
- let(:product_list) { create_list(:product, 3, tax_category: tax_category, price: 11.0) }
+ let(:product_list) { create_list(:product, 3, tax_category: tax_category, price: 11.0, stores: [store]) }
before { product_list.each { |item| Spree::Cart::AddItem.call(order: order, variant: item.master, quantity: 2) } }
@@ -260,7 +261,7 @@ module Spree
context 'and multiple quantity per line item' do
let(:promotion) { create(:promotion, :with_line_item_adjustment, adjustment_rate: 20, code: '20off') }
- let(:product_list) { create_list(:product, 3, tax_category: tax_category, price: 10.0) }
+ let(:product_list) { create_list(:product, 3, tax_category: tax_category, price: 10.0, stores: [store]) }
before do
allow(order).to receive(:coupon_code).and_return '20off'
@@ -282,7 +283,7 @@ module Spree
context 'with a CreateLineItems action' do
let!(:variant) { create(:variant) }
let!(:action) { Promotion::Actions::CreateLineItems.create(promotion: promotion) }
- let(:order) { create(:order) }
+ let(:order) { create(:order, store: store) }
before do
action.promotion_action_line_items.create(
diff --git a/core/spec/models/spree/promotion_spec.rb b/core/spec/models/spree/promotion_spec.rb
index 018925b669..1cb5c5693e 100644
--- a/core/spec/models/spree/promotion_spec.rb
+++ b/core/spec/models/spree/promotion_spec.rb
@@ -1,6 +1,7 @@
require 'spec_helper'
describe Spree::Promotion, type: :model do
+ let(:store) { create(:store) }
let(:promotion) { Spree::Promotion.new }
describe 'validations' do
@@ -385,7 +386,7 @@ describe Spree::Promotion, type: :model do
end
context '#products' do
- let(:product) { create(:product) }
+ let(:product) { create(:product, stores: [store]) }
let(:promotion) { create(:promotion) }
context 'when it has product rules with products associated' do
diff --git a/core/spec/models/spree/property_spec.rb b/core/spec/models/spree/property_spec.rb
index 93988c3115..5849c1b983 100644
--- a/core/spec/models/spree/property_spec.rb
+++ b/core/spec/models/spree/property_spec.rb
@@ -1,6 +1,8 @@
require 'spec_helper'
describe Spree::Property, type: :model do
+ let(:store) { create(:store) }
+
context 'setting filter param' do
subject { build(:property, name: 'Brand Name') }
@@ -73,8 +75,8 @@ describe Spree::Property, type: :model do
describe '#ensure_product_properties_have_filter_params' do
let(:property) { create(:property) }
- let(:product) { create(:product) }
- let(:product_2) { create(:product) }
+ let(:product) { create(:product, stores: [store]) }
+ let(:product_2) { create(:product, stores: [store]) }
let(:product_property) { create(:product_property, property: property, product: product) }
let(:product_property_2) { create(:product_property, property: property, product: product_2, value: 'Test Test') }
diff --git a/core/spec/models/spree/reimbursement_spec.rb b/core/spec/models/spree/reimbursement_spec.rb
index 670b457b98..24295e1e64 100644
--- a/core/spec/models/spree/reimbursement_spec.rb
+++ b/core/spec/models/spree/reimbursement_spec.rb
@@ -6,8 +6,8 @@ describe Spree::Reimbursement, type: :model do
let(:total) { 100.50 }
let(:currency) { 'USD' }
- let(:order) { Spree::Order.new(currency: currency) }
- let(:reimbursement) { Spree::Reimbursement.new(total: total, order: order) }
+ let(:order) { build(:order) }
+ let(:reimbursement) { described_class.new(total: total, order: order) }
it 'returns the value as a Spree::Money instance' do
expect(subject).to eq Spree::Money.new(total)
@@ -24,8 +24,8 @@ describe Spree::Reimbursement, type: :model do
let(:total) { 100.50 }
let(:currency) { 'USD' }
let(:store) { create(:store) }
- let(:order) { Spree::Order.new(currency: currency, store: store) }
- let(:reimbursement) { Spree::Reimbursement.new(total: total, order: order) }
+ let(:order) { build(:order, store: store, currency: currency) }
+ let(:reimbursement) { described_class.new(total: total, order: order) }
it 'returns order store' do
expect(subject).to eq(store)
@@ -40,11 +40,12 @@ describe Spree::Reimbursement, type: :model do
let!(:tax_rate) { nil }
let!(:tax_zone) { create(:zone_with_country, default_tax: true) }
- let(:order) { create(:order_with_line_items, state: 'payment', line_items_count: 1, line_items_price: line_items_price, shipment_cost: 0) }
+ let(:store) { create(:store) }
+ let(:order) { create(:shipped_order, line_items_count: 1, line_items_price: line_items_price, shipment_cost: 0, store: store) }
let(:line_items_price) { BigDecimal(10) }
let(:line_item) { order.line_items.first }
let(:inventory_unit) { line_item.inventory_units.first }
- let(:payment) { build(:payment, amount: payment_amount, order: order, state: 'completed') }
+ let(:payment) { order.payments.first }
let(:payment_amount) { order.total }
let(:customer_return) { build(:customer_return, return_items: [return_item]) }
let(:return_item) { build(:return_item, inventory_unit: inventory_unit) }
@@ -56,17 +57,6 @@ describe Spree::Reimbursement, type: :model do
let(:store_credit_reimbursement_type) { create(:reimbursement_type, name: 'StoreCredit', type: 'Spree::ReimbursementType::StoreCredit') }
before do
- order.shipments.each do |shipment|
- shipment.inventory_units.update_all state: 'shipped'
- shipment.update_column('state', 'shipped')
- end
- order.reload
- order.update_with_updater!
- if payment
- payment.save!
- order.next! # confirm
- end
- order.next! # completed
customer_return.save!
return_item.accept!
end
diff --git a/core/spec/models/spree/return_item/exchange_variant_eligibility/same_product_spec.rb b/core/spec/models/spree/return_item/exchange_variant_eligibility/same_product_spec.rb
index 48fe215a31..481f32b367 100644
--- a/core/spec/models/spree/return_item/exchange_variant_eligibility/same_product_spec.rb
+++ b/core/spec/models/spree/return_item/exchange_variant_eligibility/same_product_spec.rb
@@ -3,10 +3,12 @@ require 'spec_helper'
module Spree
module ReturnItem::ExchangeVariantEligibility
describe SameProduct, type: :model do
+ let(:store) { create(:store) }
+
describe '.eligible_variants' do
context 'product has no variants' do
it 'returns the master variant for the same product' do
- product = create(:product)
+ product = create(:product, stores: [store])
product.master.stock_items.first.update_column(:count_on_hand, 10)
expect(SameProduct.eligible_variants(product.master)).to eq [product.master]
@@ -15,7 +17,7 @@ module Spree
context 'product has variants' do
it 'returns all variants for the same product' do
- product = create(:product, variants: Array.new(3) { create(:variant) })
+ product = create(:product, variants: Array.new(3) { create(:variant) }, stores: [store])
product.variants.map { |v| v.stock_items.first.update_column(:count_on_hand, 10) }
expect(SameProduct.eligible_variants(product.variants.first).sort).to eq product.variants.sort
@@ -29,7 +31,7 @@ module Spree
end
it 'only returns variants that are on hand or backorderable' do
- product = create(:product, variants: Array.new(3) { create(:variant) })
+ product = create(:product, variants: Array.new(3) { create(:variant) }, stores: [store])
in_stock_variant = product.variants.first
backorderable_variant = product.variants.second
not_backorderable_variant = product.variants.third
diff --git a/core/spec/models/spree/stock/coordinator_spec.rb b/core/spec/models/spree/stock/coordinator_spec.rb
index 6d34976e18..901ba84c60 100644
--- a/core/spec/models/spree/stock/coordinator_spec.rb
+++ b/core/spec/models/spree/stock/coordinator_spec.rb
@@ -5,7 +5,8 @@ module Spree
describe Coordinator, type: :model do
subject { Coordinator.new(order) }
- let(:order) { create(:order_with_line_items) }
+ let(:store) { create(:store) }
+ let(:order) { create(:order_with_line_items, store: store) }
context 'packages' do
it 'builds, prioritizes and estimates' do
@@ -36,11 +37,11 @@ module Spree
context 'build packages' do
let!(:stock_location1) { create(:stock_location, backorderable_default: false) }
let!(:stock_location2) { create(:stock_location, backorderable_default: false) }
- let!(:product) { create(:product) }
+ let!(:product) { create(:product, stores: [store]) }
let!(:order) do
product.stock_items.map { |stock_item| stock_item.adjust_count_on_hand(1) }
- line_item = create(:line_item, product: product, quantity: 2)
+ line_item = create(:line_item, product: product, variant: product.master, quantity: 2)
line_item.order
end
diff --git a/core/spec/models/spree/store_product_spec.rb b/core/spec/models/spree/store_product_spec.rb
index d170f15981..3246dac80b 100644
--- a/core/spec/models/spree/store_product_spec.rb
+++ b/core/spec/models/spree/store_product_spec.rb
@@ -2,35 +2,36 @@ require 'spec_helper'
describe Spree::StoreProduct, type: :model do
let!(:store) { create(:store) }
- let!(:product) { create(:product, with_store: false) }
+ let!(:another_store) { create(:store) }
+ let!(:product) { create(:product, stores: [store]) }
context 'assigning store' do
- subject(:assign_store) { product.stores << store }
+ subject(:assign_store) { product.stores << another_store }
it 'touches product' do
expect { assign_store }.to change(product, :updated_at)
end
it 'touches store' do
- expect { assign_store }.to change(store, :updated_at)
+ expect { assign_store }.to change(another_store, :updated_at)
end
it 'increases Store Product count' do
- expect { assign_store }.to change(described_class, :count).from(0).to(1)
+ expect { assign_store }.to change(described_class, :count).from(1).to(2)
end
end
context 'unassignes store' do
- subject(:unassign_store) { product.stores.destroy(store) }
+ subject(:unassign_store) { product.stores.destroy(another_store) }
- before { product.stores << store }
+ before { product.stores << another_store }
it 'touches product' do
expect { unassign_store }.to change(product, :updated_at)
end
it 'decreases Store Product count' do
- expect { unassign_store }.to change(described_class, :count).from(1).to(0)
+ expect { unassign_store }.to change(described_class, :count).from(2).to(1)
end
it 'does not remove store' do
diff --git a/core/spec/models/spree/variant_spec.rb b/core/spec/models/spree/variant_spec.rb
index 6f8828e09e..19a4173c60 100644
--- a/core/spec/models/spree/variant_spec.rb
+++ b/core/spec/models/spree/variant_spec.rb
@@ -1,6 +1,7 @@
require 'spec_helper'
describe Spree::Variant, type: :model do
+ let!(:store) { create(:store) }
let!(:variant) { create(:variant) }
let(:master_variant) { create(:master_variant) }
@@ -73,7 +74,7 @@ describe Spree::Variant, type: :model do
end
context 'after create' do
- let!(:product) { create(:product) }
+ let!(:product) { create(:product, stores: [store]) }
it 'propagate to stock items' do
expect_any_instance_of(Spree::StockLocation).to receive(:propagate_variant)
@@ -109,8 +110,8 @@ describe Spree::Variant, type: :model do
describe 'scope' do
describe '.eligible' do
context 'when only master variants' do
- let!(:product_1) { create(:product) }
- let!(:product_2) { create(:product) }
+ let!(:product_1) { create(:product, stores: [store]) }
+ let!(:product_2) { create(:product, stores: [store]) }
it 'returns all of them' do
expect(Spree::Variant.eligible).to include(product_1.master)
@@ -119,7 +120,7 @@ describe Spree::Variant, type: :model do
end
context 'when product has more than 1 variant' do
- let!(:product) { create(:product) }
+ let!(:product) { create(:product, stores: [store]) }
let!(:variant) { create(:variant, product: product) }
it 'filters master variant out' do
diff --git a/core/spec/presenters/spree/variants/option_types_presenter_spec.rb b/core/spec/presenters/spree/variants/option_types_presenter_spec.rb
index e055eeb806..1deaf40edc 100644
--- a/core/spec/presenters/spree/variants/option_types_presenter_spec.rb
+++ b/core/spec/presenters/spree/variants/option_types_presenter_spec.rb
@@ -4,7 +4,7 @@ describe Spree::Variants::OptionTypesPresenter do
let(:option_type_1) { create :option_type, position: 2 }
let(:option_type_2) { create :option_type, position: 1 }
- let(:product) { create :product, option_types: [option_type_1, option_type_2] }
+ let(:product) { create :product, option_types: [option_type_1, option_type_2], stores: [create(:store)] }
let(:product_2) { create :product, option_types: [option_type_1, option_type_2] }
let!(:variant_0) { create :variant, product: product, option_values: [option_value_1_0, option_value_2_0] }
diff --git a/core/spec/services/spree/cart/set_quantity_spec.rb b/core/spec/services/spree/cart/set_quantity_spec.rb
index 1abbf03ea5..a2d9cdf402 100644
--- a/core/spec/services/spree/cart/set_quantity_spec.rb
+++ b/core/spec/services/spree/cart/set_quantity_spec.rb
@@ -4,8 +4,9 @@ module Spree
describe Cart::SetQuantity do
subject { described_class }
- let!(:order) { Spree::Order.create }
- let!(:line_item) { create(:line_item, order: order) }
+ let(:store) { create(:store) }
+ let(:order) { create(:order, store: store) }
+ let(:line_item) { create(:line_item, order: order) }
context 'with non-backorderable item' do
before do
diff --git a/frontend/spec/features/caching/products_spec.rb b/frontend/spec/features/caching/products_spec.rb
index cf568d036b..d30148f3dd 100644
--- a/frontend/spec/features/caching/products_spec.rb
+++ b/frontend/spec/features/caching/products_spec.rb
@@ -1,8 +1,8 @@
# require 'spec_helper'
# describe 'products', type: :feature, caching: true do
-# let!(:product) { create(:product) }
-# let!(:product2) { create(:product) }
+# let!(:product) { create(:product, stores: Spree::Store.all) }
+# let!(:product2) { create(:product, stores: Spree::Store.all) }
# let!(:taxonomy) { create(:taxonomy) }
# after { Timecop.return }
diff --git a/frontend/spec/features/cart_spec.rb b/frontend/spec/features/cart_spec.rb
index 0db1588074..5b617fb2fa 100644
--- a/frontend/spec/features/cart_spec.rb
+++ b/frontend/spec/features/cart_spec.rb
@@ -5,8 +5,9 @@ describe 'Cart', type: :feature, inaccessible: true, js: true do
after { Timecop.return }
- let!(:variant) { create(:variant) }
- let!(:product) { variant.product }
+ let(:store) { Spree::Store.default }
+ let(:product) { create(:product, stores: [store]) }
+ let!(:variant) { create(:variant, product: product) }
let(:order) { Spree::Order.incomplete.last }
def apply_coupon(code)
@@ -120,12 +121,10 @@ describe 'Cart', type: :feature, inaccessible: true, js: true do
end
context 'switching currency' do
- let!(:product) { create(:product, stores: [store]) }
- let(:store) { create(:store, default: true, supported_currencies: 'USD,EUR,GBP') }
-
before do
- create(:price, variant: product.master, currency: 'EUR', amount: 16.00)
- create(:price, variant: product.master, currency: 'GBP', amount: 23.00)
+ store.update!(supported_currencies: 'USD,EUR,GBP')
+ create(:price, variant: variant, currency: 'EUR', amount: 16.00)
+ create(:price, variant: variant, currency: 'GBP', amount: 23.00)
add_to_cart(product)
end
diff --git a/frontend/spec/features/delivery_spec.rb b/frontend/spec/features/delivery_spec.rb
index 2cd24f4dcd..4c0b3c02dd 100644
--- a/frontend/spec/features/delivery_spec.rb
+++ b/frontend/spec/features/delivery_spec.rb
@@ -27,7 +27,7 @@ describe 'Delivery', type: :feature, inaccessible: true, js: true do
end
before do
- create(:product) # product 2
+ create(:product, stores: Spree::Store.all) # product 2
shipping_method.calculator.preferred_amount = 10
shipping_method.calculator.save
end
diff --git a/frontend/spec/features/free_shipping_promotions_spec.rb b/frontend/spec/features/free_shipping_promotions_spec.rb
index 7ae243bb61..271eff0c9b 100644
--- a/frontend/spec/features/free_shipping_promotions_spec.rb
+++ b/frontend/spec/features/free_shipping_promotions_spec.rb
@@ -21,7 +21,7 @@ describe 'Free shipping promotions', type: :feature, js: true do
end
context 'free shipping promotion automatically applied' do
- let!(:mug) { create(:product, name: 'RoR Mug', price: 20) }
+ let!(:mug) { create(:product, name: 'RoR Mug', price: 20, stores: [store]) }
let(:promotion) do
create(:promotion,
name: 'Free Shipping',
@@ -51,7 +51,7 @@ describe 'Free shipping promotions', type: :feature, js: true do
include_context 'proceed to payment step'
context 'when order total is less than defined range' do
- let!(:mug) { create(:product, name: 'RoR Mug', price: 5) }
+ let!(:mug) { create(:product, name: 'RoR Mug', price: 5, stores: [store]) }
it 'does not apply the free shipping promotion' do
page.has_text? 'SHIPPING: $10.00'
@@ -60,7 +60,7 @@ describe 'Free shipping promotions', type: :feature, js: true do
end
context 'when order total is greater than defined range' do
- let!(:mug) { create(:product, name: 'RoR Mug', price: 60) }
+ let!(:mug) { create(:product, name: 'RoR Mug', price: 60, stores: [store]) }
it 'applies the free shipping promotion' do
page.has_text? 'SHIPPING: FREE'
diff --git a/frontend/spec/features/locale_spec.rb b/frontend/spec/features/locale_spec.rb
index 2a52d09451..795891e66f 100644
--- a/frontend/spec/features/locale_spec.rb
+++ b/frontend/spec/features/locale_spec.rb
@@ -18,7 +18,7 @@ describe 'setting locale', type: :feature, js: true do
let!(:fr_menu_item_product) { create(:menu_item, name: 'Product in French', menu_id: fr_main_menu.id, linked_resource_type: 'Spree::Product') }
let!(:taxon_x) { create(:taxon) }
- let!(:prod_x) { create(:product_in_stock, taxons: [taxon_x]) }
+ let!(:prod_x) { create(:product_in_stock, taxons: [taxon_x], stores: [store]) }
before do
store.update(default_locale: 'en', supported_locales: 'en,fr')
@@ -131,7 +131,7 @@ describe 'setting locale', type: :feature, js: true do
context 'via URL' do
let!(:taxon) { create(:taxon) }
- let!(:product) { create(:product_in_stock, taxons: [taxon]) }
+ let!(:product) { create(:product_in_stock, taxons: [taxon], stores: [store]) }
context 'cart page' do
before do
diff --git a/frontend/spec/features/product_prices_spec.rb b/frontend/spec/features/product_prices_spec.rb
index a3bf269aaf..006ebfb57f 100644
--- a/frontend/spec/features/product_prices_spec.rb
+++ b/frontend/spec/features/product_prices_spec.rb
@@ -4,7 +4,7 @@ describe 'Product with prices in multiple currencies', type: :feature, js: true
context 'currency switcher' do
context 'with USD, EUR and GBP as currencies' do
let!(:store) { create(:store, default: true, supported_currencies: 'USD,EUR,GBP') }
- let!(:product) { create(:product) }
+ let!(:product) { create(:product, stores: Spree::Store.all) }
before do
create(:price, variant: product.master, currency: 'EUR', amount: 16.00)
diff --git a/frontend/spec/features/products_filtering_spec.rb b/frontend/spec/features/products_filtering_spec.rb
index 67897ae4ae..f8096b24af 100644
--- a/frontend/spec/features/products_filtering_spec.rb
+++ b/frontend/spec/features/products_filtering_spec.rb
@@ -1,6 +1,7 @@
require 'spec_helper'
describe 'Products filtering', :js do
+ let(:store) { Spree::Store.default }
let!(:taxon) { create :taxon }
let!(:size) { create :option_type, name: 'size', presentation: 'Size' }
@@ -19,10 +20,10 @@ describe 'Products filtering', :js do
let!(:property_3) { create :property, name: 'collection', presentation: 'Collection', filterable: true }
- let!(:product_1) { create :product, name: 'First shirt', option_types: [size, color], product_properties: [zeta_brand], taxons: [taxon] }
+ let!(:product_1) { create :product, name: 'First shirt', option_types: [size, color], product_properties: [zeta_brand], taxons: [taxon], stores: [store] }
let!(:variant_1_1) { create :variant, product: product_1, option_values: [s_size, green_color] }
- let!(:product_2) { create :product, name: 'Second shirt', option_types: [size], product_properties: [wilson_manufacturer, alpha_brand], taxons: [taxon] }
+ let!(:product_2) { create :product, name: 'Second shirt', option_types: [size], product_properties: [wilson_manufacturer, alpha_brand], taxons: [taxon], stores: [store] }
let!(:variant_2_1) { create :variant, product: product_2, option_values: [m_size] }
def visit_taxons_page(taxon)
@@ -131,7 +132,7 @@ describe 'Products filtering', :js do
let!(:length) { create :option_type, name: 'length', presentation: 'Length', filterable: true }
let!(:mini_length) { create :option_value, option_type: length, name: 'mini', presentation: 'MINI' }
- let!(:product_3) { create :product, stores: [create(:store)], taxons: [taxon], option_types: [length] }
+ let!(:product_3) { create :product, taxons: [taxon], stores: [create(:store)], option_types: [length] }
let!(:variant_3) { create :variant, product: product_3, option_values: [mini_length] }
it 'does not display option types for products assigned to the other store' do
@@ -160,7 +161,7 @@ describe 'Products filtering', :js do
let!(:material) { create :property, :material, filterable: true }
let!(:cotton_material) { create :product_property, value: 'Cotton', property: material }
- let!(:product_3) { create :product, stores: [create(:store)], taxons: [taxon], product_properties: [cotton_material] }
+ let!(:product_3) { create :product, taxons: [taxon], stores: [create(:store)], product_properties: [cotton_material] }
it 'does not display properties for products assigned to the other store' do
visit spree.nested_taxons_path(taxon)
@@ -266,7 +267,7 @@ describe 'Products filtering', :js do
let!(:gamma_brand) { create(:product_property, value: 'Gamma', property: brand) }
let!(:xl_size) { create(:option_value, option_type: size, name: 'xl', presentation: 'XL') }
- let!(:product_3) { create(:product, name: '3rd shirt', product_properties: [gamma_brand], taxons: [taxon], currency: eur) }
+ let!(:product_3) { create(:product, name: '3rd shirt', product_properties: [gamma_brand], taxons: [taxon], stores: [store], currency: eur) }
let!(:variant_3) { create(:variant, product: product_3, currency: eur, option_values: [xl_size]) }
it 'correctly displays filterable properties' do
@@ -379,7 +380,7 @@ describe 'Products filtering', :js do
expect(page).to have_filter_with(value: 'Zeta')
expect(page).to have_filter_with(value: 'Alpha')
- create(:product, name: '3rd shirt', product_properties: [cotton_material], taxons: [taxon])
+ create(:product, name: '3rd shirt', product_properties: [cotton_material], taxons: [taxon], stores: [store])
visit_taxons_page(taxon)
@@ -396,7 +397,7 @@ describe 'Products filtering', :js do
expect(page).to have_filter_with(value: 'S')
expect(page).to have_filter_with(value: 'M')
- product = create(:product, name: '3rd shirt', taxons: [taxon])
+ product = create(:product, name: '3rd shirt', taxons: [taxon], stores: [store])
create(:variant, product: product, option_values: [xl_size])
visit_taxons_page(taxon)
diff --git a/frontend/spec/helpers/taxons_helper_spec.rb b/frontend/spec/helpers/taxons_helper_spec.rb
index 58a82ffb6e..c84fad80c6 100644
--- a/frontend/spec/helpers/taxons_helper_spec.rb
+++ b/frontend/spec/helpers/taxons_helper_spec.rb
@@ -5,9 +5,9 @@ describe Spree::TaxonsHelper, type: :helper do
it '#taxon_preview' do
taxon = create(:taxon)
child_taxon = create(:taxon, parent: taxon)
- product_1 = create(:product)
- product_2 = create(:product)
- product_3 = create(:product)
+ product_1 = create(:product, stores: Spree::Store.all)
+ product_2 = create(:product, stores: Spree::Store.all)
+ product_3 = create(:product, stores: Spree::Store.all)
taxon.products << product_1
taxon.products << product_2
child_taxon.products << product_3
diff --git a/frontend/spec/support/shared_contexts/checkout_address_book.rb b/frontend/spec/support/shared_contexts/checkout_address_book.rb
index 6a925e8c00..5046f2311a 100644
--- a/frontend/spec/support/shared_contexts/checkout_address_book.rb
+++ b/frontend/spec/support/shared_contexts/checkout_address_book.rb
@@ -15,7 +15,7 @@ shared_context 'checkout address book' do
config.alternative_shipping_phone = false
end
- product = create(:product_in_stock, name: 'Ruby on Rails Mug', price: 13.99)
+ product = create(:product_in_stock, name: 'Ruby on Rails Mug', price: 13.99, stores: [@store])
add_to_cart(product)
end
diff --git a/frontend/spec/support/shared_contexts/custom_products.rb b/frontend/spec/support/shared_contexts/custom_products.rb
index df36f02d09..ed5ae72185 100644
--- a/frontend/spec/support/shared_contexts/custom_products.rb
+++ b/frontend/spec/support/shared_contexts/custom_products.rb
@@ -12,15 +12,16 @@ shared_context 'custom products' do
apache_taxon = FactoryBot.create(:taxon, name: 'Apache', parent_id: root.id)
rails_taxon = FactoryBot.create(:taxon, name: 'Ruby on Rails', parent_id: root.id)
ruby_taxon = FactoryBot.create(:taxon, name: 'Ruby', parent_id: root.id)
+ store = Spree::Store.default
- FactoryBot.create(:custom_product, name: 'Ruby on Rails Ringer T-Shirt', price: '159.99', taxons: [rails_taxon, clothing_taxon])
- FactoryBot.create(:custom_product, name: 'Ruby on Rails Mug', price: '55.99', taxons: [rails_taxon, mugs_taxon, trending_taxon])
- FactoryBot.create(:custom_product, name: 'Ruby on Rails Tote', price: '55.99', taxons: [rails_taxon, bags_taxon, trending_taxon])
- FactoryBot.create(:custom_product, name: 'Ruby on Rails Bag', price: '102.99', taxons: [rails_taxon, bags_taxon])
- FactoryBot.create(:custom_product, name: 'Ruby on Rails Baseball Jersey', price: '190.99', taxons: [rails_taxon, clothing_taxon])
- FactoryBot.create(:custom_product, name: 'Ruby on Rails Stein', price: '156.99', taxons: [rails_taxon, mugs_taxon])
- FactoryBot.create(:custom_product, name: 'Ruby on Rails Jr. Spaghetti', price: '190.99', taxons: [rails_taxon, clothing_taxon])
- FactoryBot.create(:custom_product, name: 'Ruby Baseball Jersey', price: '250.99', taxons: [ruby_taxon, clothing_taxon])
- FactoryBot.create(:custom_product, name: 'Apache Baseball Jersey', price: '250.99', taxons: [apache_taxon, clothing_taxon])
+ FactoryBot.create(:custom_product, name: 'Ruby on Rails Ringer T-Shirt', price: '159.99', taxons: [rails_taxon, clothing_taxon], stores: [store])
+ FactoryBot.create(:custom_product, name: 'Ruby on Rails Mug', price: '55.99', taxons: [rails_taxon, mugs_taxon, trending_taxon], stores: [store])
+ FactoryBot.create(:custom_product, name: 'Ruby on Rails Tote', price: '55.99', taxons: [rails_taxon, bags_taxon, trending_taxon], stores: [store])
+ FactoryBot.create(:custom_product, name: 'Ruby on Rails Bag', price: '102.99', taxons: [rails_taxon, bags_taxon], stores: [store])
+ FactoryBot.create(:custom_product, name: 'Ruby on Rails Baseball Jersey', price: '190.99', taxons: [rails_taxon, clothing_taxon], stores: [store])
+ FactoryBot.create(:custom_product, name: 'Ruby on Rails Stein', price: '156.99', taxons: [rails_taxon, mugs_taxon], stores: [store])
+ FactoryBot.create(:custom_product, name: 'Ruby on Rails Jr. Spaghetti', price: '190.99', taxons: [rails_taxon, clothing_taxon], stores: [store])
+ FactoryBot.create(:custom_product, name: 'Ruby Baseball Jersey', price: '250.99', taxons: [ruby_taxon, clothing_taxon], stores: [store])
+ FactoryBot.create(:custom_product, name: 'Apache Baseball Jersey', price: '250.99', taxons: [apache_taxon, clothing_taxon], stores: [store])
end
end
diff --git a/guides/src/content/developer/3_customization/api_v1.md b/guides/src/content/developer/3_customization/api_v1.md
index 9fa22561c6..8e454ec3e4 100644
--- a/guides/src/content/developer/3_customization/api_v1.md
+++ b/guides/src/content/developer/3_customization/api_v1.md
@@ -135,7 +135,7 @@ module Spree
# 8.00 it's a example value. Use any other value that your wish!
let!(:product) { create(:product, sale_price: 8.00) }
- let!(:other_product) { create(:product) }
+ let!(:other_product) { create(:product, stores: Spree::Store.all) }
let!(:user) { create(:user) }
before do
diff --git a/sample/db/samples/payment_methods.rb b/sample/db/samples/payment_methods.rb
index e5bf545c5f..2395389f16 100644
--- a/sample/db/samples/payment_methods.rb
+++ b/sample/db/samples/payment_methods.rb
@@ -2,16 +2,16 @@ cc_payment_method = Spree::Gateway::Bogus.where(
name: 'Credit Card',
description: 'Bogus payment gateway.',
active: true
-).first_or_create!
+).first_or_initialize
-cc_payment_method.store_ids = Spree::Store.ids
-cc_payment_method.save!
+cc_payment_method.stores = Spree::Store.all
+cc_payment_method.save
check_paymemt_method = Spree::PaymentMethod::Check.where(
name: 'Check',
description: 'Pay by check.',
active: true
-).first_or_create!
+).first_or_initialize
-check_paymemt_method.store_ids = Spree::Store.ids
-check_paymemt_method.save!
+check_paymemt_method.stores = Spree::Store.all
+check_paymemt_method.save
diff --git a/sample/db/samples/products.rb b/sample/db/samples/products.rb
index 7cec89eb13..79c9f7cace 100644
--- a/sample/db/samples/products.rb
+++ b/sample/db/samples/products.rb
@@ -4,6 +4,7 @@ Spree::Sample.load_sample('tax_categories')
Spree::Sample.load_sample('shipping_categories')
Spree::Sample.load_sample('option_types')
Spree::Sample.load_sample('taxons')
+Spree::Sample.load_sample('stores')
default_shipping_category = Spree::ShippingCategory.find_by!(name: 'Default')
clothing_tax_category = Spree::TaxCategory.find_by!(name: 'Clothing')
@@ -35,6 +36,7 @@ PRODUCTS.each do |(parent_name, taxon_name, product_name)|
product.sku = [taxon_name.delete(' '), product_name.delete(' '), product.price].join('_')
product.taxons << parent unless product.taxons.include?(parent)
product.taxons << taxon unless product.taxons.include?(taxon)
+ product.stores = Spree::Store.all
end
end