mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-05 02:41:33 +00:00
Merge pull request #9946 from filipefurtad0/fixes_minor_build_issues
Fixes minor issues in the build
This commit is contained in:
2
.github/workflows/build.yml
vendored
2
.github/workflows/build.yml
vendored
@@ -130,4 +130,4 @@ jobs:
|
||||
run: yarn jest
|
||||
|
||||
- name: Run all other tests
|
||||
run: bundle exec rake ofn:specs:run:excluding_folders["models,controllers,serializers,features,lib,migrations,system"]
|
||||
run: bundle exec rspec --exclude-pattern "./models/**/*_spec.rb, ./controllers/**/*_spec.rb, ./serializers/**/*_spec.rb, ./lib/**/*_spec.rb, ./migrations/**/*_spec.rb, ./system/**/*_spec.rb"
|
||||
|
||||
@@ -83,7 +83,7 @@ Then the main application tests can be run with:
|
||||
|
||||
The tests of all custom engines can be run with:
|
||||
|
||||
bundle exec rake ofn:specs:engines:rspec
|
||||
bundle exec rspec ./engines
|
||||
|
||||
Note: If your OS is not explicitly supported in the setup guides then not all tests may pass. However, you may still be able to develop.
|
||||
|
||||
|
||||
@@ -1,78 +0,0 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
namespace :ofn do
|
||||
namespace :specs do
|
||||
namespace :run do
|
||||
def spec_folders
|
||||
Pathname("spec/").children.select(&:directory?).map { |p|
|
||||
p.split.last.to_s
|
||||
} - %w(support factories javascripts performance)
|
||||
end
|
||||
|
||||
def execute_rspec_for_pattern(pattern)
|
||||
system "bundle exec rspec --profile --pattern \"#{pattern}\""
|
||||
end
|
||||
|
||||
def execute_rspec_for_spec_folder(folder)
|
||||
execute_rspec_for_pattern("spec/#{folder}/{,/*/**}/*_spec.rb")
|
||||
end
|
||||
|
||||
def execute_rspec_for_spec_folders(folders)
|
||||
folders = folders.join(",")
|
||||
execute_rspec_for_pattern("spec/{#{folders}}/{,/*/**}/*_spec.rb")
|
||||
end
|
||||
|
||||
desc "Run Rspec tests excluding folders"
|
||||
task :excluding_folders, [:folders] => :environment do |_task, args|
|
||||
success = execute_rspec_for_spec_folders(
|
||||
spec_folders - (args[:folders].split(",") + args.extras)
|
||||
)
|
||||
abort "Failure when running tests" unless success
|
||||
end
|
||||
end
|
||||
|
||||
namespace :engines do
|
||||
def detect_engine_paths
|
||||
Pathname("engines/").children.select(&:directory?)
|
||||
end
|
||||
|
||||
def engine_name_for_engine(engine_path)
|
||||
engine_path.basename.to_path
|
||||
end
|
||||
|
||||
def execute_rspec_for_engine(engine_path)
|
||||
system "DISABLE_KNAPSACK=true bundle exec rspec #{engine_path.expand_path}/spec"
|
||||
end
|
||||
|
||||
engine_paths = detect_engine_paths
|
||||
|
||||
engine_paths.each do |engine_path|
|
||||
engine_name = engine_name_for_engine(engine_path)
|
||||
|
||||
namespace engine_name do
|
||||
desc "Run RSpec tests for engine \"#{engine_name}\""
|
||||
task rspec: :environment do
|
||||
success = execute_rspec_for_engine(engine_path)
|
||||
abort "Failure when running tests for engine \"#{engine_name}\"" unless success
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
namespace :all do
|
||||
desc "Run RSpec tests for all engines"
|
||||
task rspec: :environment do
|
||||
success = true
|
||||
|
||||
engine_paths.each do |engine_path|
|
||||
success = !!execute_rspec_for_engine(engine_path) && success
|
||||
end
|
||||
|
||||
abort "Failure encountered when running tests for engines" unless success
|
||||
end
|
||||
end
|
||||
|
||||
desc "Alias for openfoodnetwork:specs:engines:all:rspec"
|
||||
task rspec: "all:rspec"
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1,32 +0,0 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'spec_helper'
|
||||
|
||||
describe InjectionHelper, type: :helper, performance: true do
|
||||
let(:oc) { create(:simple_order_cycle) }
|
||||
let(:relative_supplier) { create(:supplier_enterprise) }
|
||||
let(:relative_distributor) { create(:distributor_enterprise) }
|
||||
|
||||
before do
|
||||
50.times do
|
||||
e = create(:enterprise)
|
||||
oc.distributors << e
|
||||
create(:enterprise_relationship, parent: e, child: relative_supplier)
|
||||
create(:enterprise_relationship, parent: e, child: relative_distributor)
|
||||
end
|
||||
end
|
||||
|
||||
it "is performant in injecting enterprises" do
|
||||
results = []
|
||||
4.times do |i|
|
||||
ActiveRecord::Base.connection.query_cache.clear
|
||||
Rails.cache.delete_matched('api\/cached_enterprise_serializer\/enterprises')
|
||||
result = Benchmark.measure { helper.inject_enterprises }
|
||||
results << result.total if i.positive?
|
||||
puts result
|
||||
end
|
||||
|
||||
avg = (results.sum / results.count * 1000).round(0)
|
||||
puts avg
|
||||
end
|
||||
end
|
||||
@@ -1,39 +0,0 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'spec_helper'
|
||||
|
||||
describe Spree::OrdersController, type: :controller, performance: true do
|
||||
let(:distributor) { create(:distributor_enterprise) }
|
||||
let(:order_cycle) {
|
||||
create(:simple_order_cycle, distributors: [distributor], variants: products.map { |p|
|
||||
p.variants.first
|
||||
} )
|
||||
}
|
||||
let(:products) { (0...num_products).map { create(:product) } }
|
||||
let(:order) { subject.current_order(true) }
|
||||
let(:num_products) { 20 }
|
||||
|
||||
before do
|
||||
order.set_distribution! distributor, order_cycle
|
||||
controller.stub(:current_order) { order }
|
||||
|
||||
Spree::Config.currency = 'AUD'
|
||||
end
|
||||
|
||||
describe "adding products to cart" do
|
||||
it "adds products to cart" do
|
||||
puts "Pre-populating first product"
|
||||
spree_post :populate, variants: { products[0].variants.first.id => 1 }
|
||||
|
||||
result = Benchmark.measure do
|
||||
(1..num_products).each do |num_products|
|
||||
puts "Populating #{num_products} products"
|
||||
variants = Hash[products.map { |p| [p.variants.first.id, 1] }.first(num_products)]
|
||||
spree_post :populate, variants: variants
|
||||
end
|
||||
end
|
||||
|
||||
puts result
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1,50 +0,0 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'spec_helper'
|
||||
|
||||
describe ShopController, type: :controller, performance: true do
|
||||
include FileHelper
|
||||
|
||||
let(:d) { create(:distributor_enterprise) }
|
||||
let(:enterprise_fee) { create(:enterprise_fee) }
|
||||
let(:order_cycle) {
|
||||
create(:simple_order_cycle, distributors: [d], coordinator_fees: [enterprise_fee])
|
||||
}
|
||||
|
||||
before do
|
||||
allow(controller).to receive(:current_distributor) { d }
|
||||
allow(controller).to receive(:current_order_cycle) { order_cycle }
|
||||
Spree::Config.currency = 'AUD'
|
||||
end
|
||||
|
||||
describe "fetching products" do
|
||||
let(:exchange) { order_cycle.exchanges.to_enterprises(d).outgoing.first }
|
||||
let(:image) { white_logo_file }
|
||||
let(:cache_key_patterns) do
|
||||
[
|
||||
'api\/taxon_serializer\/spree\/taxons',
|
||||
'enterprise'
|
||||
]
|
||||
end
|
||||
|
||||
before do
|
||||
11.times do
|
||||
p = create(:simple_product)
|
||||
p.set_property 'Organic Certified', 'NASAA 12345'
|
||||
v1 = create(:variant, product: p)
|
||||
v2 = create(:variant, product: p)
|
||||
Spree::Image.create! viewable_id: p.master.id, viewable_type: 'Spree::Variant',
|
||||
attachment: image
|
||||
|
||||
exchange.variants << [v1, v2]
|
||||
end
|
||||
end
|
||||
|
||||
it "returns products via json" do
|
||||
results = multi_benchmark(3, cache_key_patterns: cache_key_patterns) do
|
||||
get :products, xhr: true
|
||||
expect(response.status).to eq 200
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user