mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-31 21:37:16 +00:00
Merge pull request #6079 from arku/perf/test-prof-setup
Set up test_prof gem
This commit is contained in:
1
Gemfile
1
Gemfile
@@ -156,6 +156,7 @@ end
|
||||
|
||||
group :test do
|
||||
gem 'simplecov', require: false
|
||||
gem 'test-prof'
|
||||
gem 'webmock'
|
||||
# See spec/spec_helper.rb for instructions
|
||||
# gem 'perftools.rb'
|
||||
|
||||
@@ -661,6 +661,7 @@ GEM
|
||||
stringex (1.5.1)
|
||||
stripe (5.25.0)
|
||||
temple (0.8.2)
|
||||
test-prof (0.7.5)
|
||||
test-unit (3.3.6)
|
||||
power_assert
|
||||
thor (0.20.3)
|
||||
@@ -811,6 +812,7 @@ DEPENDENCIES
|
||||
state_machine (= 1.2.0)
|
||||
stringex (~> 1.5.1)
|
||||
stripe
|
||||
test-prof
|
||||
test-unit (~> 3.3)
|
||||
timecop
|
||||
truncate_html (= 0.9.2)
|
||||
|
||||
@@ -6,12 +6,12 @@ FactoryBot.define do
|
||||
promo_image {}
|
||||
end
|
||||
|
||||
owner { FactoryBot.create :user }
|
||||
owner factory: :user
|
||||
sequence(:name) { |n| "Enterprise #{n}" }
|
||||
sells 'any'
|
||||
description 'enterprise'
|
||||
long_description '<p>Hello, world!</p><p>This is a paragraph.</p>'
|
||||
address { FactoryBot.create(:address) }
|
||||
address
|
||||
|
||||
after(:create) do |enterprise, proxy|
|
||||
proxy.users.each do |user|
|
||||
|
||||
@@ -1,18 +1,18 @@
|
||||
FactoryBot.define do
|
||||
factory :filter_order_cycles_tag_rule, class: TagRule::FilterOrderCycles do
|
||||
enterprise { FactoryBot.create :distributor_enterprise }
|
||||
enterprise factory: :distributor_enterprise
|
||||
end
|
||||
|
||||
factory :filter_shipping_methods_tag_rule, class: TagRule::FilterShippingMethods do
|
||||
enterprise { FactoryBot.create :distributor_enterprise }
|
||||
enterprise factory: :distributor_enterprise
|
||||
end
|
||||
|
||||
factory :filter_products_tag_rule, class: TagRule::FilterProducts do
|
||||
enterprise { FactoryBot.create :distributor_enterprise }
|
||||
enterprise factory: :distributor_enterprise
|
||||
end
|
||||
|
||||
factory :filter_payment_methods_tag_rule, class: TagRule::FilterPaymentMethods do
|
||||
enterprise { FactoryBot.create :distributor_enterprise }
|
||||
enterprise factory: :distributor_enterprise
|
||||
end
|
||||
|
||||
factory :tag_rule, class: TagRule::DiscountOrder do
|
||||
|
||||
@@ -288,7 +288,7 @@ describe OrderCycle do
|
||||
end
|
||||
|
||||
describe "checking status" do
|
||||
let(:oc) { create(:simple_order_cycle) }
|
||||
let(:oc) { build_stubbed(:simple_order_cycle) }
|
||||
|
||||
it "reports status when an order cycle is upcoming" do
|
||||
Timecop.freeze(oc.orders_open_at - 1.second) do
|
||||
@@ -319,7 +319,8 @@ describe OrderCycle do
|
||||
end
|
||||
|
||||
it "reports status when an order cycle is undated" do
|
||||
oc.update!(orders_open_at: nil, orders_close_at: nil)
|
||||
oc.orders_open_at = nil
|
||||
oc.orders_close_at = nil
|
||||
|
||||
expect(oc).to be_undated
|
||||
expect(oc).not_to be_dated
|
||||
@@ -329,7 +330,7 @@ describe OrderCycle do
|
||||
end
|
||||
|
||||
it "reports status when an order cycle is partially dated - opening time only" do
|
||||
oc.update!(orders_close_at: nil)
|
||||
oc.orders_close_at = nil
|
||||
|
||||
expect(oc).to be_undated
|
||||
expect(oc).not_to be_dated
|
||||
@@ -339,7 +340,7 @@ describe OrderCycle do
|
||||
end
|
||||
|
||||
it "reports status when an order cycle is partially dated - closing time only" do
|
||||
oc.update!(orders_open_at: nil)
|
||||
oc.orders_open_at = nil
|
||||
|
||||
expect(oc).to be_undated
|
||||
expect(oc).not_to be_dated
|
||||
|
||||
@@ -2,11 +2,11 @@ require 'spec_helper'
|
||||
|
||||
module Spree
|
||||
describe Classification do
|
||||
let!(:product) { create(:simple_product) }
|
||||
let!(:taxon) { create(:taxon) }
|
||||
let(:classification) { create(:classification, taxon: taxon, product: product) }
|
||||
let(:product) { build_stubbed(:simple_product) }
|
||||
let(:taxon) { build_stubbed(:taxon) }
|
||||
|
||||
it "won't destroy if classification is the primary taxon" do
|
||||
classification = Classification.new(taxon: taxon, product: product)
|
||||
product.primary_taxon = taxon
|
||||
expect(classification.destroy).to be false
|
||||
expect(classification.errors.messages[:base]).to eq(["Taxon #{taxon.name} is the primary taxon of #{product.name} and cannot be deleted"])
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe Spree::Order do
|
||||
describe Spree::Order::Checkout do
|
||||
let(:order) { Spree::Order.new }
|
||||
|
||||
context "with default state machine" do
|
||||
@@ -15,8 +15,6 @@ describe Spree::Order do
|
||||
|
||||
it "has the following transitions" do
|
||||
transitions.each do |transition|
|
||||
puts transition.keys.first
|
||||
puts transition.values.first
|
||||
transition = Spree::Order.find_transition(from: transition.keys.first,
|
||||
to: transition.values.first)
|
||||
expect(transition).to_not be_nil
|
||||
@@ -302,12 +300,12 @@ describe Spree::Order do
|
||||
end
|
||||
|
||||
describe 'event :restart_checkout' do
|
||||
let(:order) { create(:order) }
|
||||
let(:order) { build_stubbed(:order) }
|
||||
|
||||
context 'when the order is not complete' do
|
||||
before { allow(order).to receive(:completed?) { false } }
|
||||
|
||||
it 'does transition to cart state' do
|
||||
it 'transitions to cart state' do
|
||||
expect(order.state).to eq('cart')
|
||||
end
|
||||
end
|
||||
|
||||
@@ -54,7 +54,7 @@ describe Spree::Order do
|
||||
end
|
||||
|
||||
it "does nothing when the line item is not found" do
|
||||
p = create(:simple_product)
|
||||
p = build_stubbed(:simple_product)
|
||||
subject.set_variant_attributes(p.master, { 'max_quantity' => '3' }.with_indifferent_access)
|
||||
end
|
||||
end
|
||||
@@ -823,10 +823,14 @@ describe Spree::Order do
|
||||
end
|
||||
|
||||
describe '#restart_checkout!' do
|
||||
let(:order) { build(:order, line_items: [build(:line_item)]) }
|
||||
|
||||
context 'when the order is complete' do
|
||||
before { order.completed_at = Time.zone.now }
|
||||
let(:order) do
|
||||
build_stubbed(
|
||||
:order,
|
||||
completed_at: Time.zone.now,
|
||||
line_items: [build_stubbed(:line_item)]
|
||||
)
|
||||
end
|
||||
|
||||
it 'raises' do
|
||||
expect { order.restart_checkout! }
|
||||
@@ -835,7 +839,13 @@ describe Spree::Order do
|
||||
end
|
||||
|
||||
context 'when the is not complete' do
|
||||
before { order.completed_at = nil }
|
||||
let(:order) do
|
||||
build(
|
||||
:order,
|
||||
completed_at: nil,
|
||||
line_items: [build(:line_item)]
|
||||
)
|
||||
end
|
||||
|
||||
it 'transitions to :cart state' do
|
||||
order.restart_checkout!
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe TagRule::FilterOrderCycles, type: :model do
|
||||
let!(:tag_rule) { create(:filter_order_cycles_tag_rule) }
|
||||
let!(:tag_rule) { build_stubbed(:filter_order_cycles_tag_rule) }
|
||||
|
||||
describe "determining whether tags match for a given exchange" do
|
||||
context "when the exchange is nil" do
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe TagRule::FilterPaymentMethods, type: :model do
|
||||
let!(:tag_rule) { create(:filter_payment_methods_tag_rule) }
|
||||
let!(:tag_rule) { build_stubbed(:filter_payment_methods_tag_rule) }
|
||||
|
||||
describe "determining whether tags match for a given payment method" do
|
||||
context "when the payment method is nil" do
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe TagRule::FilterProducts, type: :model do
|
||||
let!(:tag_rule) { create(:filter_products_tag_rule) }
|
||||
let!(:tag_rule) { build_stubbed(:filter_products_tag_rule) }
|
||||
|
||||
describe "determining whether tags match for a given variant" do
|
||||
context "when the variant is nil" do
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe TagRule::FilterShippingMethods, type: :model do
|
||||
let!(:tag_rule) { create(:filter_shipping_methods_tag_rule) }
|
||||
let!(:tag_rule) { build_stubbed(:filter_shipping_methods_tag_rule) }
|
||||
|
||||
describe "determining whether tags match for a given shipping method" do
|
||||
context "when the shipping method is nil" do
|
||||
@@ -11,7 +11,7 @@ describe TagRule::FilterShippingMethods, type: :model do
|
||||
end
|
||||
|
||||
context "when the shipping method is not nil" do
|
||||
let(:shipping_method) { create(:shipping_method, tag_list: ["member", "local", "volunteer"]) }
|
||||
let(:shipping_method) { build_stubbed(:shipping_method, tag_list: ["member", "local", "volunteer"]) }
|
||||
|
||||
context "when the rule has no preferred shipping method tags specified" do
|
||||
before { allow(tag_rule).to receive(:preferred_shipping_method_tags) { "" } }
|
||||
|
||||
@@ -42,10 +42,15 @@ describe VariantOverride do
|
||||
|
||||
describe "validation" do
|
||||
describe "ensuring that on_demand and count_on_hand are compatible" do
|
||||
let(:variant_override) {
|
||||
build(:variant_override, hub: hub, variant: variant,
|
||||
on_demand: on_demand, count_on_hand: count_on_hand)
|
||||
}
|
||||
let(:variant_override) do
|
||||
build_stubbed(
|
||||
:variant_override,
|
||||
hub: build_stubbed(:distributor_enterprise),
|
||||
variant: build_stubbed(:variant),
|
||||
on_demand: on_demand,
|
||||
count_on_hand: count_on_hand
|
||||
)
|
||||
end
|
||||
|
||||
context "when using producer stock settings" do
|
||||
let(:on_demand) { nil }
|
||||
@@ -62,7 +67,7 @@ describe VariantOverride do
|
||||
let(:count_on_hand) { 1 }
|
||||
|
||||
it "is invalid" do
|
||||
expect(variant_override.save).to be_falsey
|
||||
expect(variant_override).not_to be_valid
|
||||
error_message = I18n.t("using_producer_stock_settings_but_count_on_hand_set",
|
||||
scope: [i18n_scope_for_error, "count_on_hand"])
|
||||
expect(variant_override.errors[:count_on_hand]).to eq([error_message])
|
||||
@@ -139,7 +144,14 @@ describe VariantOverride do
|
||||
end
|
||||
|
||||
describe "with price" do
|
||||
let(:variant_override) { build_stubbed(:variant_override, variant: variant, hub: hub, price: 12.34) }
|
||||
let(:variant_override) do
|
||||
build_stubbed(
|
||||
:variant_override,
|
||||
variant: build_stubbed(:variant),
|
||||
hub: build_stubbed(:distributor_enterprise),
|
||||
price: 12.34
|
||||
)
|
||||
end
|
||||
|
||||
it "returns the numeric price" do
|
||||
expect(variant_override.price).to eq(12.34)
|
||||
@@ -147,7 +159,15 @@ describe VariantOverride do
|
||||
end
|
||||
|
||||
describe "with nil count on hand" do
|
||||
let(:variant_override) { build_stubbed(:variant_override, variant: variant, hub: hub, count_on_hand: nil, on_demand: true) }
|
||||
let(:variant_override) do
|
||||
build_stubbed(
|
||||
:variant_override,
|
||||
variant: build_stubbed(:variant),
|
||||
hub: build_stubbed(:distributor_enterprise),
|
||||
count_on_hand: nil,
|
||||
on_demand: true
|
||||
)
|
||||
end
|
||||
|
||||
describe "stock_overridden?" do
|
||||
it "returns false" do
|
||||
@@ -164,7 +184,14 @@ describe VariantOverride do
|
||||
end
|
||||
|
||||
describe "with count on hand" do
|
||||
let(:variant_override) { create(:variant_override, variant: variant, hub: hub, count_on_hand: 12) }
|
||||
let(:variant_override) do
|
||||
build_stubbed(
|
||||
:variant_override,
|
||||
variant: build_stubbed(:variant),
|
||||
hub: build_stubbed(:distributor_enterprise),
|
||||
count_on_hand: 12
|
||||
)
|
||||
end
|
||||
|
||||
it "returns the numeric count on hand" do
|
||||
expect(variant_override.count_on_hand).to eq(12)
|
||||
@@ -177,6 +204,15 @@ describe VariantOverride do
|
||||
end
|
||||
|
||||
describe "move_stock!" do
|
||||
let(:variant_override) do
|
||||
create(
|
||||
:variant_override,
|
||||
variant: variant,
|
||||
hub: hub,
|
||||
count_on_hand: 12
|
||||
)
|
||||
end
|
||||
|
||||
it "does nothing for quantity zero" do
|
||||
variant_override.move_stock!(0)
|
||||
expect(variant_override.reload.count_on_hand).to eq(12)
|
||||
@@ -196,12 +232,24 @@ describe VariantOverride do
|
||||
|
||||
describe "checking default stock value is present" do
|
||||
it "returns true when a default stock level has been set" do
|
||||
vo = build_stubbed(:variant_override, variant: variant, hub: hub, count_on_hand: 12, default_stock: 20)
|
||||
vo = build_stubbed(
|
||||
:variant_override,
|
||||
variant: build_stubbed(:variant),
|
||||
hub: build_stubbed(:distributor_enterprise),
|
||||
count_on_hand: 12,
|
||||
default_stock: 20
|
||||
)
|
||||
expect(vo.default_stock?).to be true
|
||||
end
|
||||
|
||||
it "returns false when the override has no default stock level" do
|
||||
vo = build_stubbed(:variant_override, variant: variant, hub: hub, count_on_hand: 12, default_stock: nil)
|
||||
vo = build_stubbed(
|
||||
:variant_override,
|
||||
variant: build_stubbed(:variant),
|
||||
hub: build_stubbed(:distributor_enterprise),
|
||||
count_on_hand: 12,
|
||||
default_stock: nil
|
||||
)
|
||||
expect(vo.default_stock?).to be false
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user