Skip to content

Commit

Permalink
4515 - Deactivated partners should not appear in the dropdown when pr…
Browse files Browse the repository at this point in the history
…oducing a new distribution. (#4639)

* Filters out deactive partners on new distribution

This commit adds in a conditional check to the _form partial that
checks where the partial is coming from. If it is being rendered from
the 'new' view, it will then generate a partner list that filters out
the deactivated partners. If it is being rendered from anywhere else,
it will generate the complete partner list unfiltered.

[Ticket: 4515]

* Updates the re-render of create on a fail to also filter out the deactivated partners

* Adds in unit tests for distribution dropdown

* Removed unneeded variable declaration for unit tests

* Moves the partner_list query from the view into
the controller actions

* Moved rspec tests from 'system' to 'requests'
  • Loading branch information
ewoknock committed Sep 12, 2024
1 parent ff587ae commit 50e00e8
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 1 deletion.
5 changes: 5 additions & 0 deletions app/controllers/distributions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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|
Expand Down Expand Up @@ -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|
Expand Down Expand Up @@ -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?
Expand Down
2 changes: 1 addition & 1 deletion app/views/distributions/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -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?" %>

Expand Down
36 changes: 36 additions & 0 deletions spec/requests/distributions_requests_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 50e00e8

Please sign in to comment.