From bf3a652bf145e04e5e20a8a12005c5186fbbe1bf Mon Sep 17 00:00:00 2001 From: Leni Kadali <52788034+lenikadali@users.noreply.github.com> Date: Mon, 14 Oct 2024 22:04:43 +0300 Subject: [PATCH] Make purchase helper pick default storage location Changed the purchase helper to use the default storage location of the organization first, before using any other storage locations that are available. Also added a (failing) spec to check that we can see the option on the page. Should be fixed in the next commit --- app/helpers/purchases_helper.rb | 2 +- spec/requests/purchases_requests_spec.rb | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/app/helpers/purchases_helper.rb b/app/helpers/purchases_helper.rb index ea6a5b4ffc..39e13ba56e 100644 --- a/app/helpers/purchases_helper.rb +++ b/app/helpers/purchases_helper.rb @@ -5,6 +5,6 @@ def purchased_from(purchase) end def new_purchase_default_location(purchase) - purchase.storage_location_id.presence || current_organization.intake_location + current_organization.default_storage_location || purchase.storage_location_id.presence || current_organization.intake_location end end diff --git a/spec/requests/purchases_requests_spec.rb b/spec/requests/purchases_requests_spec.rb index d60b23f484..4ec48d77c7 100644 --- a/spec/requests/purchases_requests_spec.rb +++ b/spec/requests/purchases_requests_spec.rb @@ -1,5 +1,6 @@ RSpec.describe "Purchases", type: :request do let(:organization) { create(:organization) } + let(:storage_location) { create(:storage_location, organization: organization) } let(:user) { create(:user, organization: organization) } let(:organization_admin) { create(:organization_admin, organization: organization) } @@ -48,11 +49,13 @@ describe "GET #new" do subject do + organization.update!(default_storage_location: storage_location) get new_purchase_path response end it { is_expected.to be_successful } + it { is_expected.to include(storage_location.name) } end describe "POST#create" do