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.

Added `test-prof` gem for testing/development (#12519)

Damian Legawiec9ba90fc1e00b
diff --git a/common_spree_dependencies.rb b/common_spree_dependencies.rb
index ae746f5287..2bbb8282c5 100644
--- a/common_spree_dependencies.rb
+++ b/common_spree_dependencies.rb
@@ -37,8 +37,10 @@ group :test do
gem 'rswag-specs'
gem 'jsonapi-rspec'
gem 'simplecov'
+ gem 'stackprof'
gem 'webmock'
gem 'timecop'
+ gem 'test-prof'
gem 'rails-controller-testing'
end
diff --git a/core/spec/models/spree/store_spec.rb b/core/spec/models/spree/store_spec.rb
index 05445037ed..4d6ace3af9 100644
--- a/core/spec/models/spree/store_spec.rb
+++ b/core/spec/models/spree/store_spec.rb
@@ -140,7 +140,7 @@ describe Spree::Store, type: :model do
end
context 'when code is already taken' do
- let(:default_store) { Spree::Store.default }
+ let(:default_store) { described_class.default }
let(:store) { build(:store, name: 'Store', code: default_store.code) }
it 'generates a new code' do
@@ -228,7 +228,7 @@ describe Spree::Store, type: :model do
context 'Validations' do
describe '#code' do
- let(:default_store) { Spree::Store.default }
+ let(:default_store) { described_class.default }
it 'cannot create 2 stores with the same code' do
new_store = create(:store, name: default_store.code)
@@ -300,7 +300,7 @@ describe Spree::Store, type: :model do
let!(:store_2) { create(:store, default: true) }
it 'returns the already existing default store' do
- expect(Spree::Store.default).to eq(store_2)
+ expect(described_class.default).to eq(store_2)
end
it "ensures there is a default if one doesn't exist yet" do
@@ -687,16 +687,16 @@ describe Spree::Store, type: :model do
end
context 'without an attached favicon image' do
- let(:store) { Spree::Store.default }
+ let(:store) { build(:store) }
it 'returns a blank favicon' do
- expect(favicon).to be(nil)
+ expect(favicon).to be_nil
end
end
end
describe '#can_be_deleted?' do
- let(:default_store) { Spree::Store.default }
+ let(:default_store) { described_class.default }
it 'cannot delete the only store' do
expect(default_store.can_be_deleted?).to eq(false)
diff --git a/core/spec/models/spree/variant_spec.rb b/core/spec/models/spree/variant_spec.rb
index 35bf7f40e8..96a66b983c 100644
--- a/core/spec/models/spree/variant_spec.rb
+++ b/core/spec/models/spree/variant_spec.rb
@@ -1,8 +1,8 @@
require 'spec_helper'
describe Spree::Variant, type: :model do
- let!(:store) { Spree::Store.default }
- let!(:variant) { create(:variant, product: create(:base_product, stores: [store])) }
+ let(:store) { Spree::Store.default }
+ let(:variant) { create(:variant, product: create(:base_product, stores: [store])) }
let(:master_variant) { create(:master_variant) }
it_behaves_like 'default_price'
@@ -771,6 +771,8 @@ describe Spree::Variant, type: :model do
end
describe '#can_supply?' do
+ before { variant }
+
it 'calls out to quantifier' do
expect(Spree::Stock::Quantifier).to receive(:new).and_return(quantifier = double)
expect(quantifier).to receive(:can_supply?).with(10)
@@ -910,16 +912,18 @@ describe Spree::Variant, type: :model do
context 'when tax category is deleted also in product' do
let(:tax_category) { create(:tax_category) }
- let!(:default_tax_category) { create(:tax_category, is_default: true) }
- let(:product) { create(:product, tax_category: tax_category) }
- let(:variant) { build(:variant, product: product, tax_category: tax_category) }
-
- before do
- tax_category.destroy
- product.reload
- end
+ let!(:product) { create(:product, tax_category: tax_category) }
+ let!(:variant) { create(:variant, product: product, tax_category: tax_category) }
context 'with default tax category' do
+ let!(:default_tax_category) { create(:tax_category, is_default: true) }
+
+ before do
+ tax_category.destroy
+ product.reload
+ variant.reload
+ end
+
it 'returns the default tax category' do
expect(variant.tax_category).to eq(default_tax_category)
end
@@ -927,11 +931,13 @@ describe Spree::Variant, type: :model do
context 'without default tax category' do
before do
- default_tax_category.destroy
+ tax_category.destroy
+ product.reload
+ variant.reload
end
it 'returns nil' do
- expect(variant.tax_category).to eq(nil)
+ expect(variant.reload.tax_category).to eq(nil)
end
end
end