Skip to content

Commit

Permalink
Merge branch 'main' into 4473-expand-reminder-date-possibilities
Browse files Browse the repository at this point in the history
  • Loading branch information
jlandiseigsti authored Sep 12, 2024
2 parents 64f7499 + 50e00e8 commit 93cdebc
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 93cdebc

Please sign in to comment.