diff --git a/app/controllers/distributions_controller.rb b/app/controllers/distributions_controller.rb index f7f0e0d62a..a56003a716 100644 --- a/app/controllers/distributions_controller.rb +++ b/app/controllers/distributions_controller.rb @@ -115,6 +115,8 @@ def create @distribution.initialize_request_items end @items = current_organization.items.alphabetized + @partner_list = current_organization.partners.where.not(status: 'deactivated').alphabetized + if Event.read_events?(current_organization) inventory = View::Inventory.new(@distribution.organization_id) @storage_locations = current_organization.storage_locations.active_locations.alphabetized.select do |storage_loc| @@ -147,6 +149,8 @@ def new @distribution.copy_from_donation(params[:donation_id], params[:storage_location_id]) end @items = current_organization.items.alphabetized + @partner_list = current_organization.partners.where.not(status: 'deactivated').alphabetized + if Event.read_events?(current_organization) inventory = View::Inventory.new(current_organization.id) @storage_locations = current_organization.storage_locations.active_locations.alphabetized.select do |storage_loc| @@ -175,6 +179,7 @@ def edit current_user.has_role?(Role::ORG_ADMIN, current_organization) @distribution.line_items.build if @distribution.line_items.size.zero? @items = current_organization.items.alphabetized + @partner_list = current_organization.partners.alphabetized @audit_warning = current_organization.audits .where(storage_location_id: @distribution.storage_location_id) .where("updated_at > ?", @distribution.created_at).any? diff --git a/app/views/distributions/_form.html.erb b/app/views/distributions/_form.html.erb index b72329f950..f28782234c 100644 --- a/app/views/distributions/_form.html.erb +++ b/app/views/distributions/_form.html.erb @@ -9,7 +9,7 @@ <% end %> <%= f.association :partner, - collection: current_organization.partners.alphabetized, + collection: @partner_list, label: "Partner", error: "Which partner is this distribution going to?" %> diff --git a/spec/requests/distributions_requests_spec.rb b/spec/requests/distributions_requests_spec.rb index a5b6243cfc..34e06e4af5 100644 --- a/spec/requests/distributions_requests_spec.rb +++ b/spec/requests/distributions_requests_spec.rb @@ -129,6 +129,21 @@ expect(response).to have_http_status(400) expect(response).to have_error end + + context "Deactivated partners should not be displayed in partner dropdown" do + before do + create(:partner, name: 'Active Partner', organization: organization, status: "approved") + create(:partner, name: 'Deactivated Partner', organization: organization, status: "deactivated") + end + + it "should not display deactivated partners after error and re-render of form" do + post distributions_path(distribution: { comment: nil, partner_id: nil, storage_location_id: nil }, format: :turbo_stream) + expect(response).to have_http_status(400) + expect(response).to have_error + expect(response.body).not_to include("Deactivated Partner") + expect(response.body).to include("Active Partner") + end + end end describe "GET #new" do @@ -179,6 +194,19 @@ end end + context "Deactivated partners should not be displayed in partner dropdown" do + before do + create(:partner, name: 'Active Partner', organization: organization, status: "approved") + create(:partner, name: 'Deactivated Partner', organization: organization, status: "deactivated") + end + + it "should not display deactivated partners on new distribution" do + get new_distribution_path(default_params) + expect(response.body).not_to include("Deactivated Partner") + expect(response.body).to include("Active Partner") + end + end + context 'with units' do before(:each) do Flipper.enable(:enable_packs) @@ -464,6 +492,14 @@ expect(response.body).not_to include("You’ve had an audit since this distribution was started.") end + it "should display deactivated partners in partner dropdown" do + create(:partner, name: 'Active Partner', organization: organization, status: "approved") + create(:partner, name: 'Deactivated Partner', organization: organization, status: "deactivated") + get edit_distribution_path(id: distribution.id) + expect(response.body).to include("Deactivated Partner") + expect(response.body).to include("Active Partner") + end + context 'with units' do let!(:request) { create(:request,