From e4be757d96f366a10f5f477f2076a10bca438516 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Bellet Date: Mon, 4 Jul 2022 15:18:14 +0200 Subject: [PATCH] use the `can_invoice` method that check both ABN and configuration boolean + specs Specify an empty ABN number + update specs --- .../spree/admin/orders_controller.rb | 2 +- spec/system/admin/order_spec.rb | 33 +++++++++++-------- 2 files changed, 21 insertions(+), 14 deletions(-) diff --git a/app/controllers/spree/admin/orders_controller.rb b/app/controllers/spree/admin/orders_controller.rb index ccce49e27b..0030d969ea 100644 --- a/app/controllers/spree/admin/orders_controller.rb +++ b/app/controllers/spree/admin/orders_controller.rb @@ -126,7 +126,7 @@ module Spree end def require_distributor_abn - return if @order.distributor.abn.present? + return if @order.distributor.can_invoice? flash[:error] = t(:must_have_valid_business_number, enterprise_name: @order.distributor.name) diff --git a/spec/system/admin/order_spec.rb b/spec/system/admin/order_spec.rb index 12c83e26d6..6093131b71 100644 --- a/spec/system/admin/order_spec.rb +++ b/spec/system/admin/order_spec.rb @@ -480,18 +480,31 @@ describe ' end context "Check send/print invoice links" do - context "when abn number is not mandatory to send/print invoices" do + + shared_examples_for 'can send/print invoices' do before do - Spree::Config[:enterprise_number_required_on_invoices?] = false + visit spree.edit_admin_order_path(order) + find("#links-dropdown .ofn-drop-down").click end - it "should display normal links" do - visit spree.edit_admin_order_path(order) - - find("#links-dropdown .ofn-drop-down").click + it 'shows the right links' do expect(page).to have_link "Send Invoice", href: spree.invoice_admin_order_path(order) expect(page).to have_link "Print Invoice", href: spree.print_admin_order_path(order) end + + it 'can send invoices' do + click_link "Send Invoice" + expect(page).to have_content "Invoice email has been sent" + end + end + + context "when abn number is not mandatory to send/print invoices" do + before do + Spree::Config[:enterprise_number_required_on_invoices?] = false + distributor1.update_attribute(:abn, "") + end + + it_should_behave_like 'can send/print invoices' end context "when abn number is mandatory to send/print invoices" do @@ -504,13 +517,7 @@ describe ' distributor1.update_attribute(:abn, '12345678') end - it "should display normal links" do - visit spree.edit_admin_order_path(order) - - find("#links-dropdown .ofn-drop-down").click - expect(page).to have_link "Send Invoice", href: spree.invoice_admin_order_path(order) - expect(page).to have_link "Print Invoice", href: spree.print_admin_order_path(order) - end + it_should_behave_like 'can send/print invoices' end context "and a abn number is not set on the distributor" do