mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-04-06 07:29:16 +00:00
Fix Ruboxop issue
This commit is contained in:
@@ -45,7 +45,7 @@ class Enterprise < ApplicationRecord
|
||||
has_many :distributed_orders, class_name: 'Spree::Order',
|
||||
foreign_key: 'distributor_id',
|
||||
dependent: :restrict_with_exception
|
||||
|
||||
|
||||
belongs_to :address, class_name: 'Spree::Address'
|
||||
belongs_to :business_address, optional: true, class_name: 'Spree::Address', dependent: :destroy
|
||||
has_many :enterprise_fees, dependent: :restrict_with_exception
|
||||
|
||||
@@ -25,7 +25,9 @@ module Spree
|
||||
variants_display_name
|
||||
variants_supplier_name).join('_or_')}_cont".freeze
|
||||
|
||||
belongs_to :product, -> { with_deleted }, required: true, touch: true, class_name: 'Spree::Product'
|
||||
belongs_to :product, -> {
|
||||
with_deleted
|
||||
}, touch: true, class_name: 'Spree::Product', optional: false
|
||||
belongs_to :tax_category, class_name: 'Spree::TaxCategory'
|
||||
belongs_to :shipping_category, class_name: 'Spree::ShippingCategory', optional: false
|
||||
belongs_to :primary_taxon, class_name: 'Spree::Taxon', touch: true, optional: false
|
||||
|
||||
@@ -2,7 +2,8 @@
|
||||
|
||||
require 'open_food_network/scope_product_to_hub'
|
||||
|
||||
class ProductsRenderer
|
||||
|
||||
class ProductsRenderer # rubocop:disable Metrics/ClassLength
|
||||
include Pagy::Backend
|
||||
|
||||
class NoProducts < RuntimeError; end
|
||||
@@ -63,7 +64,8 @@ class ProductsRenderer
|
||||
distributed_products.products_supplier_relation
|
||||
end
|
||||
|
||||
def filter(query)
|
||||
# TODO: refactor to address CyclomaticComplexity
|
||||
def filter(query) # rubocop:disable Metrics/CyclomaticComplexity
|
||||
supplier_properties = args[:q]&.slice("with_variants_supplier_properties")
|
||||
|
||||
ransack_results = query.ransack(args[:q]).result.to_a
|
||||
|
||||
@@ -145,8 +145,8 @@ RSpec.describe Api::V0::VariantsController, type: :controller do
|
||||
it "can create a new variant" do
|
||||
original_number_of_variants = variant.product.variants.count
|
||||
api_post :create, variant: { sku: "12345", unit_value: "1", unit_description: "L",
|
||||
price: "1",primary_taxon_id: taxon.id,
|
||||
supplier_id: variant.supplier.id},
|
||||
price: "1", primary_taxon_id: taxon.id,
|
||||
supplier_id: variant.supplier.id },
|
||||
product_id: variant.product.id
|
||||
|
||||
expect(attributes.all?{ |attr| json_response.include? attr.to_s }).to eq(true)
|
||||
|
||||
@@ -79,7 +79,7 @@ module Spree
|
||||
variant: { supplier_id: new_producer.id }
|
||||
)
|
||||
|
||||
expect(order_cycle.reload.distributed_variants).to_not include variant
|
||||
expect(order_cycle.reload.distributed_variants).not_to include variant
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -510,14 +510,14 @@ module Spree
|
||||
producer_a = create(:enterprise, name: "a_cooperative")
|
||||
producer_g = create(:enterprise, name: "g_cooperative")
|
||||
|
||||
product_1 = create(:product, supplier_id: producer_z.id)
|
||||
product_2 = create(:product, supplier_id: producer_a.id)
|
||||
product_3 = create(:product, supplier_id: producer_g.id)
|
||||
product1 = create(:product, supplier_id: producer_z.id)
|
||||
product2 = create(:product, supplier_id: producer_a.id)
|
||||
product3 = create(:product, supplier_id: producer_g.id)
|
||||
|
||||
expect(Product.by_producer).to match_array([
|
||||
product_2,
|
||||
product_3,
|
||||
product_1,
|
||||
product2,
|
||||
product3,
|
||||
product1,
|
||||
])
|
||||
end
|
||||
end
|
||||
|
||||
@@ -45,7 +45,6 @@ module Spree
|
||||
let!(:product) { create(:simple_product, primary_taxon_id: taxon1.id) }
|
||||
let(:variant) { product.variants.first }
|
||||
|
||||
|
||||
it "is touched when assignment of primary_taxon on a variant changes" do
|
||||
expect do
|
||||
variant.update(primary_taxon: taxon2)
|
||||
|
||||
@@ -27,7 +27,7 @@ RSpec.describe Spree::Variant do
|
||||
variant = build(:variant, shipping_category: nil)
|
||||
|
||||
expect(variant).to be_valid
|
||||
expect(variant.shipping_category).to_not be_nil
|
||||
expect(variant.shipping_category).not_to be_nil
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -23,8 +23,7 @@ RSpec.describe ProductsRenderer do
|
||||
variants: [
|
||||
create(:variant, supplier: cakes_supplier, primary_taxon: cakes),
|
||||
create(:variant, supplier: fruits_supplier, primary_taxon: cakes)
|
||||
]
|
||||
)
|
||||
])
|
||||
}
|
||||
let!(:product_cherries) {
|
||||
create(:product, name: "cherries", primary_taxon_id: fruits.id,
|
||||
|
||||
@@ -240,7 +240,7 @@ RSpec.describe Sets::ProductSet do
|
||||
}.to change { variant.supplier }.to(producer).
|
||||
and change { order_cycle.distributed_variants.count }.by(-1)
|
||||
|
||||
expect(order_cycle.distributed_variants).to_not include variant
|
||||
expect(order_cycle.distributed_variants).not_to include variant
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -488,13 +488,13 @@ RSpec.describe 'As an enterprise user, I can manage my products', feature: :admi
|
||||
let(:supplier_permitted) { create(:supplier_enterprise, name: 'Supplier Permitted') }
|
||||
let(:distributor_managed) { create(:distributor_enterprise, name: 'Distributor Managed') }
|
||||
let(:distributor_unmanaged) { create(:distributor_enterprise, name: 'Distributor Unmanaged') }
|
||||
let!(:product_supplied) { create(:product, supplier: supplier_managed1, price: 10.0) }
|
||||
let!(:product_not_supplied) { create(:product, supplier: supplier_unmanaged) }
|
||||
let!(:product_supplied) { create(:product, supplier_id: supplier_managed1.id, price: 10.0) }
|
||||
let!(:product_not_supplied) { create(:product, supplier_id: supplier_unmanaged.id) }
|
||||
let!(:product_supplied_permitted) {
|
||||
create(:product, name: 'Product Permitted', supplier: supplier_permitted, price: 10.0)
|
||||
create(:product, name: 'Product Permitted', supplier_id: supplier_permitted.id, price: 10.0)
|
||||
}
|
||||
let(:product_supplied_inactive) {
|
||||
create(:product, supplier: supplier_managed1, price: 10.0)
|
||||
create(:product, supplier_id: supplier_managed1.id, price: 10.0)
|
||||
}
|
||||
|
||||
let!(:supplier_permitted_relationship) do
|
||||
|
||||
@@ -389,7 +389,9 @@ RSpec.describe '
|
||||
supplier_id: supplier.id)
|
||||
}
|
||||
let(:variant1) { product1.variants.first }
|
||||
let(:variant2) { create(:variant, product: product1, price: 80.0, primary_taxon: taxon, supplier:) }
|
||||
let(:variant2) {
|
||||
create(:variant, product: product1, price: 80.0, primary_taxon: taxon, supplier:)
|
||||
}
|
||||
let(:variant3) { product2.variants.first }
|
||||
|
||||
before do
|
||||
|
||||
@@ -48,7 +48,8 @@ RSpec.describe "
|
||||
|
||||
context "when inventory_items exist for variants" do
|
||||
let!(:product) {
|
||||
create(:simple_product, supplier_id: producer.id, variant_unit: 'weight', variant_unit_scale: 1)
|
||||
create(:simple_product, supplier_id: producer.id, variant_unit: 'weight',
|
||||
variant_unit_scale: 1)
|
||||
}
|
||||
let!(:variant) { create(:variant, product:, unit_value: 1, price: 1.23, on_hand: 12) }
|
||||
let!(:inventory_item) { create(:inventory_item, enterprise: hub, variant: ) }
|
||||
@@ -58,7 +59,8 @@ RSpec.describe "
|
||||
variant_unit_scale: 1)
|
||||
}
|
||||
let!(:variant_managed) {
|
||||
create(:variant, product: product_managed, supplier: producer_managed, unit_value: 3, price: 3.65, on_hand: 2)
|
||||
create(:variant, product: product_managed, supplier: producer_managed, unit_value: 3,
|
||||
price: 3.65, on_hand: 2)
|
||||
}
|
||||
let!(:inventory_item_managed) {
|
||||
create(:inventory_item, enterprise: hub, variant: variant_managed )
|
||||
@@ -66,7 +68,8 @@ RSpec.describe "
|
||||
|
||||
let!(:product_related) { create(:simple_product, supplier_id: producer_related.id) }
|
||||
let!(:variant_related) {
|
||||
create(:variant, product: product_related, supplier: producer_related, unit_value: 2, price: 2.34, on_hand: 23)
|
||||
create(:variant, product: product_related, supplier: producer_related, unit_value: 2,
|
||||
price: 2.34, on_hand: 23)
|
||||
}
|
||||
let!(:inventory_item_related) {
|
||||
create(:inventory_item, enterprise: hub, variant: variant_related )
|
||||
@@ -476,7 +479,8 @@ RSpec.describe "
|
||||
|
||||
describe "when inventory_items do not exist for variants" do
|
||||
let!(:product) {
|
||||
create(:simple_product, supplier_id: producer.id, variant_unit: 'weight', variant_unit_scale: 1)
|
||||
create(:simple_product, supplier_id: producer.id, variant_unit: 'weight',
|
||||
variant_unit_scale: 1)
|
||||
}
|
||||
let!(:variant1) {
|
||||
create(:variant, product:, unit_value: 1, price: 1.23, on_hand: 12)
|
||||
|
||||
@@ -296,7 +296,8 @@ RSpec.describe "As a consumer I want to shop with a distributor" do
|
||||
display_as: 'displayedunderthename')
|
||||
end
|
||||
let(:product2) {
|
||||
create(:simple_product, supplier_id: supplier.id, name: "Meercats", meta_keywords: "Wild Fresh")
|
||||
create(:simple_product, supplier_id: supplier.id, name: "Meercats",
|
||||
meta_keywords: "Wild Fresh")
|
||||
}
|
||||
let(:variant3) {
|
||||
create(:variant, product: product2, supplier:, price: 40, display_name: "Ferrets")
|
||||
@@ -338,8 +339,8 @@ RSpec.describe "As a consumer I want to shop with a distributor" do
|
||||
it "returns results when successful" do
|
||||
visit shop_path
|
||||
# When we see the Add button, it means product are loaded on the page
|
||||
expect(page).to have_content("Add", count: 4)
|
||||
|
||||
expect(page).to have_content("Add", count: 4)
|
||||
|
||||
fill_in "search", with: "74576345634XXXXXX"
|
||||
expect(page).to have_content "Sorry, no results found"
|
||||
expect(page).not_to have_content 'Meercats'
|
||||
|
||||
Reference in New Issue
Block a user