From ade35f2fa2a872bfad4dcf5d1965805e5ac907a2 Mon Sep 17 00:00:00 2001 From: Ahmed Ejaz Date: Sun, 15 Jun 2025 18:14:57 +0500 Subject: [PATCH] Fixes specs and update code respectively --- app/models/spree/line_item.rb | 2 +- lib/reporting/line_items.rb | 2 +- .../scope_variants_for_search_spec.rb | 2 -- .../reports/orders_and_distributors_report_spec.rb | 1 - .../producer_actions_spec.rb | 4 ++-- spec/views/spree/admin/orders/edit.html.haml_spec.rb | 12 ++++++++---- 6 files changed, 12 insertions(+), 11 deletions(-) rename spec/system/admin/orders/{ => having_producer_products}/producer_actions_spec.rb (98%) diff --git a/app/models/spree/line_item.rb b/app/models/spree/line_item.rb index 92bca503f5..fed86cd802 100644 --- a/app/models/spree/line_item.rb +++ b/app/models/spree/line_item.rb @@ -109,7 +109,7 @@ module Spree } scope :editable_by_producers, ->(enterprises_ids) { - joins(:variant, order: :distributor).where( + joins(variant: :supplier, order: :distributor).where( distributor: { enable_producers_to_edit_orders: true }, spree_variants: { supplier_id: enterprises_ids } ) diff --git a/lib/reporting/line_items.rb b/lib/reporting/line_items.rb index 0073b66d50..6b0750ab0d 100644 --- a/lib/reporting/line_items.rb +++ b/lib/reporting/line_items.rb @@ -17,7 +17,7 @@ module Reporting def list(line_item_includes = [variant: [:supplier, :product]]) line_items = order_permissions.visible_line_items.in_orders(orders.result) - .order("supplier.name", "product.name", "variant.display_name", "variant.unit_description") + .order("supplier.name", "product.name", "spree_variants.display_name", "spree_variants.unit_description") if @params[:supplier_id_in].present? line_items = line_items.supplied_by_any(@params[:supplier_id_in]) diff --git a/spec/lib/open_food_network/scope_variants_for_search_spec.rb b/spec/lib/open_food_network/scope_variants_for_search_spec.rb index 943539c169..ccbed15dd0 100644 --- a/spec/lib/open_food_network/scope_variants_for_search_spec.rb +++ b/spec/lib/open_food_network/scope_variants_for_search_spec.rb @@ -70,8 +70,6 @@ RSpec.describe OpenFoodNetwork::ScopeVariantsForSearch do "Enterprise Load", "VariantOverride Load", "SQL", - "Enterprise Pluck", - "Enterprise Load" ] expect(result).to include v4 diff --git a/spec/lib/reports/orders_and_distributors_report_spec.rb b/spec/lib/reports/orders_and_distributors_report_spec.rb index 07c68b55ea..98f4943f29 100644 --- a/spec/lib/reports/orders_and_distributors_report_spec.rb +++ b/spec/lib/reports/orders_and_distributors_report_spec.rb @@ -151,7 +151,6 @@ RSpec.describe Reporting::Reports::OrdersAndDistributors::Base do subject # build context first expect { subject.table_rows }.to query_database [ - "Enterprise Pluck", "SQL", "Spree::LineItem Load", "Spree::PaymentMethod Load", diff --git a/spec/system/admin/orders/producer_actions_spec.rb b/spec/system/admin/orders/having_producer_products/producer_actions_spec.rb similarity index 98% rename from spec/system/admin/orders/producer_actions_spec.rb rename to spec/system/admin/orders/having_producer_products/producer_actions_spec.rb index 88e8d5bd34..d8e8a93dda 100644 --- a/spec/system/admin/orders/producer_actions_spec.rb +++ b/spec/system/admin/orders/having_producer_products/producer_actions_spec.rb @@ -19,7 +19,7 @@ RSpec.describe 'As a producer who have the ability to update orders' do o = create( :completed_order_with_totals, distributor:, order_cycle:, - user: supplier1_ent_user, line_items_count: 1 + line_items_count: 1 ) o.line_items.first.update_columns(variant_id: supplier1_v1.id) o @@ -28,7 +28,7 @@ RSpec.describe 'As a producer who have the ability to update orders' do o = create( :completed_order_with_totals, distributor:, order_cycle:, - user: supplier2_ent_user, line_items_count: 1 + line_items_count: 1 ) o.line_items.first.update_columns(variant_id: supplier2_v1.id) o diff --git a/spec/views/spree/admin/orders/edit.html.haml_spec.rb b/spec/views/spree/admin/orders/edit.html.haml_spec.rb index ca22a3c226..d53fa5abb7 100644 --- a/spec/views/spree/admin/orders/edit.html.haml_spec.rb +++ b/spec/views/spree/admin/orders/edit.html.haml_spec.rb @@ -14,14 +14,19 @@ RSpec.describe "spree/admin/orders/edit.html.haml" do Spree::Config[:enable_invoices?] = original_config end + let(:current_test_user) { create(:admin_user) } + before do controller.singleton_class.class_eval do + attr_accessor :current_test_user + def current_ability - Spree::Ability.new(Spree::User.new) + Spree::Ability.new(current_test_user) end end - allow(view).to receive_messages spree_current_user: create(:admin_user) + controller.current_test_user = current_test_user + allow(view).to receive_messages spree_current_user: current_test_user end context "when order is complete" do @@ -54,7 +59,6 @@ RSpec.describe "spree/admin/orders/edit.html.haml" do it "doesn't display a table of out of stock line items" do render - expect(rendered).not_to have_content "Out of Stock" expect(rendered).not_to have_selector ".insufficient-stock-items", text: out_of_stock_line_item.variant.display_name end @@ -96,7 +100,7 @@ RSpec.describe "spree/admin/orders/edit.html.haml" do it "doesn't display a table of out of stock line items" do render - expect(rendered).not_to have_content "Out of Stock" + expect(rendered).not_to have_selector ".insufficient-stock-items" end end