diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 8c549c6624..4dc6b7b7a5 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -126,6 +126,6 @@ def storage_location_for_source(source_object) end def default_location(source_object) - current_organization.default_storage_location || source_object.storage_location_id.presence || current_organization.intake_location + source_object.storage_location_id.presence || current_organization.default_storage_location || current_organization.intake_location end end diff --git a/spec/helpers/application_helper_spec.rb b/spec/helpers/application_helper_spec.rb index cd7e87ddef..8598e2e01a 100644 --- a/spec/helpers/application_helper_spec.rb +++ b/spec/helpers/application_helper_spec.rb @@ -151,6 +151,14 @@ def current_organization; end it { is_expected.to eq(2) } end + context "returns source object's storage_location_id even when org has different default" do + let(:organization) { build(:organization, default_storage_location: 42) } + let(:purchase) { build(:purchase, storage_location_id: 1) } + subject { helper.default_location(purchase) } + + it { is_expected.to eq(1) } + end + context "returns current_organization intake_location if storage_location_id is not present" do let(:organization) { build(:organization, intake_location: 1) } let(:purchase) { build(:purchase, storage_location_id: nil) }