From de7bbd10c30b93180071176d4608e7da138e796b Mon Sep 17 00:00:00 2001 From: yahyaelganayni1 Date: Mon, 7 Jul 2025 19:45:22 +0300 Subject: [PATCH 01/29] Refactor item creation and update logic in ItemsController --- app/controllers/items_controller.rb | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/app/controllers/items_controller.rb b/app/controllers/items_controller.rb index 6a807efab7..704ea2db73 100644 --- a/app/controllers/items_controller.rb +++ b/app/controllers/items_controller.rb @@ -31,11 +31,11 @@ def index end def create - create = if Flipper.enabled?(:enable_packs) - ItemCreateService.new(organization_id: current_organization.id, item_params: item_params, request_unit_ids:) - else - ItemCreateService.new(organization_id: current_organization.id, item_params: item_params) - end + create = ItemCreateService.new( + organization_id: current_organization.id, + item_params: item_params, + request_unit_ids: request_unit_ids + ) result = create.call if result.success? @@ -182,11 +182,7 @@ def request_unit_ids # We need to update both the item and the request_units together and fail together def update_item - if Flipper.enabled?(:enable_packs) - update_item_and_request_units - else - @item.save - end + update_item_and_request_units end def update_item_and_request_units From 5c470625687014cc3bda9ca2938d6acb813291d4 Mon Sep 17 00:00:00 2001 From: yahyaelganayni1 Date: Mon, 7 Jul 2025 19:47:49 +0300 Subject: [PATCH 02/29] Refactor fetch_items method to simplify item unit fetching logic --- app/controllers/partners/requests_controller.rb | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/app/controllers/partners/requests_controller.rb b/app/controllers/partners/requests_controller.rb index 0595a0f342..3fc3a8e781 100644 --- a/app/controllers/partners/requests_controller.rb +++ b/app/controllers/partners/requests_controller.rb @@ -80,13 +80,11 @@ def partner_request_params def fetch_items @requestable_items = PartnerFetchRequestableItemsService.new(partner_id: partner.id).call - if Flipper.enabled?(:enable_packs) - # hash of (item ID => hash of (request unit name => request unit plural name)) - item_ids = @requestable_items.to_h.values - if item_ids.present? - @item_units = Item.where(id: item_ids).to_h do |i| - [i.id, i.request_units.to_h { |u| [u.name, u.name.pluralize] }] - end + # Packs are always enabled, so always fetch item units + item_ids = @requestable_items.to_h.values + if item_ids.present? + @item_units = Item.where(id: item_ids).to_h do |i| + [i.id, i.request_units.to_h { |u| [u.name, u.name.pluralize] }] end end end From 460a58e7099122604f99e4c80a8fa506bcd90a85 Mon Sep 17 00:00:00 2001 From: yahyaelganayni1 Date: Mon, 7 Jul 2025 19:49:03 +0300 Subject: [PATCH 03/29] Simplify name_with_unit method by removing Flipper condition for request_unit --- app/models/partners/item_request.rb | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/app/models/partners/item_request.rb b/app/models/partners/item_request.rb index 544d8f04af..823801d04b 100644 --- a/app/models/partners/item_request.rb +++ b/app/models/partners/item_request.rb @@ -37,11 +37,7 @@ def request_unit_is_supported end def name_with_unit(quantity_override = nil) - if Flipper.enabled?(:enable_packs) && request_unit.present? - "#{item&.name || name} - #{request_unit.pluralize(quantity_override || quantity.to_i)}" - else - item&.name || name - end + "#{item&.name || name} - #{request_unit.pluralize(quantity_override || quantity.to_i)}" end end end From 4b5a1fc0cf7888ed40ac4300611af762dfbb37b3 Mon Sep 17 00:00:00 2001 From: yahyaelganayni1 Date: Mon, 7 Jul 2025 20:04:25 +0300 Subject: [PATCH 04/29] Refactor ItemCreateService to always sync request units in call method --- app/services/item_create_service.rb | 5 +---- spec/services/item_create_service_spec.rb | 5 +++-- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/app/services/item_create_service.rb b/app/services/item_create_service.rb index 01159d33e4..5450e36492 100644 --- a/app/services/item_create_service.rb +++ b/app/services/item_create_service.rb @@ -8,10 +8,7 @@ def initialize(organization_id:, item_params:, request_unit_ids: []) def call new_item = organization.items.new(item_params) new_item.save! - if Flipper.enabled?(:enable_packs) - new_item.sync_request_units!(@request_unit_ids) - end - + new_item.sync_request_units!(@request_unit_ids) Result.new(value: new_item) rescue StandardError => e Result.new(error: e) diff --git a/spec/services/item_create_service_spec.rb b/spec/services/item_create_service_spec.rb index 8c8d3eb555..3de3fe7cce 100644 --- a/spec/services/item_create_service_spec.rb +++ b/spec/services/item_create_service_spec.rb @@ -1,11 +1,12 @@ RSpec.describe ItemCreateService, type: :service do describe '#call' do - subject { described_class.new(organization_id: organization_id, item_params: item_params).call } + subject { described_class.new(organization_id: organization_id, item_params: item_params, request_unit_ids: request_unit_ids).call } let(:organization_id) { organization.id } let(:item_params) { { fake: 'param' } } + let(:request_unit_ids) { [] } let(:organization) { create(:organization) } let(:fake_organization_items) { instance_double('organization.items') } - let(:fake_organization_item) { instance_double(Item, id: 99_999, save!: -> {}) } + let(:fake_organization_item) { instance_double(Item, id: 99_999, save!: -> {}, sync_request_units!: true) } let(:fake_organization_storage_locations) do [ instance_double(StorageLocation, id: 'fake-id-1'), From 22a9528a960ab64c84dc14a102f96dec812e20a5 Mon Sep 17 00:00:00 2001 From: yahyaelganayni1 Date: Mon, 7 Jul 2025 20:06:43 +0300 Subject: [PATCH 05/29] Refactor OrganizationUpdateService to streamline request unit handling --- app/services/organization_update_service.rb | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/app/services/organization_update_service.rb b/app/services/organization_update_service.rb index d462a895ce..9173732671 100644 --- a/app/services/organization_update_service.rb +++ b/app/services/organization_update_service.rb @@ -18,15 +18,13 @@ def update(organization, params) org_params["partner_form_fields"] = org_params["partner_form_fields"].compact_blank end - if Flipper.enabled?(:enable_packs) - request_unit_names = org_params[:request_unit_names] || [] - # Find or create units for the organization - request_unit_ids = request_unit_names.compact_blank.map do |request_unit_name| - Unit.find_or_create_by(organization: organization, name: request_unit_name).id - end - org_params.delete(:request_unit_names) - org_params[:request_unit_ids] = request_unit_ids + request_unit_names = org_params[:request_unit_names] || [] + # Find or create units for the organization + request_unit_ids = request_unit_names.compact_blank.map do |request_unit_name| + Unit.find_or_create_by(organization: organization, name: request_unit_name).id end + org_params.delete(:request_unit_names) + org_params[:request_unit_ids] = request_unit_ids result = organization.update(org_params) From 127e577d477319cd2898617798493ca5d42e64f8 Mon Sep 17 00:00:00 2001 From: yahyaelganayni1 Date: Mon, 7 Jul 2025 20:15:56 +0300 Subject: [PATCH 06/29] Remove Flipper condition from has_custom_units method for simplified unit check --- app/pdfs/picklists_pdf.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/pdfs/picklists_pdf.rb b/app/pdfs/picklists_pdf.rb index 9aea947f02..8d36a6073f 100644 --- a/app/pdfs/picklists_pdf.rb +++ b/app/pdfs/picklists_pdf.rb @@ -134,7 +134,7 @@ def compute_and_render end def has_custom_units?(line_items) - Flipper.enabled?(:enable_packs) && line_items.any? { |line_item| line_item.request_unit } + line_items.any? { |line_item| line_item.request_unit } end def data_with_units(line_items) From 647a66db69063c0662413f22f3166b23ca482d09 Mon Sep 17 00:00:00 2001 From: yahyaelganayni1 Date: Wed, 9 Jul 2025 14:28:47 +0300 Subject: [PATCH 07/29] Remove Flipper condition for request_units input in item form --- app/views/items/_form.html.erb | 2 -- 1 file changed, 2 deletions(-) diff --git a/app/views/items/_form.html.erb b/app/views/items/_form.html.erb index 7af1f6e98e..5196a04190 100644 --- a/app/views/items/_form.html.erb +++ b/app/views/items/_form.html.erb @@ -43,11 +43,9 @@ <%= f.input_field :package_size, class: "form-control", min: 0 %> <% end %> - <% if Flipper.enabled?(:enable_packs) %> <%= f.input :request_units, label: "Additional Custom Request Units" do %> <%= f.association :request_units, as: :check_boxes, collection: current_organization.request_units, checked: selected_item_request_units(@item), label_method: :name, value_method: :id, class: "form-check-input" %> <% end %> - <% end %> <%= f.input :visible, label: "Item is Visible to Partners?", wrapper: :input_group do %> <%= f.check_box :visible_to_partners, {class: "input-group-text", id: "visible_to_partners"}, "true", "false" %> From 5191b5caddfb352cf35816f2cba0f4b8dcf86073 Mon Sep 17 00:00:00 2001 From: yahyaelganayni1 Date: Wed, 9 Jul 2025 14:30:45 +0300 Subject: [PATCH 08/29] Remove Flipper condition for displaying custom request units in item list --- app/views/items/_item_list.html.erb | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/app/views/items/_item_list.html.erb b/app/views/items/_item_list.html.erb index 5a3fe1e521..0a2278027a 100644 --- a/app/views/items/_item_list.html.erb +++ b/app/views/items/_item_list.html.erb @@ -11,10 +11,8 @@ Add. Info Quantity Per Individual Fair Market Value (per item) - <% if Flipper.enabled?(:enable_packs) %> - <% unless current_organization.request_units.empty? %> - Custom Request Units - <% end %> + <% unless current_organization.request_units.empty? %> + Custom Request Units <% end %> Actions From 62b1e3bcaf0507b3912e4afe8dbc5f4f729b6dfe Mon Sep 17 00:00:00 2001 From: yahyaelganayni1 Date: Wed, 9 Jul 2025 14:32:06 +0300 Subject: [PATCH 09/29] Remove Flipper condition for displaying request units in item row --- app/views/items/_item_row.html.erb | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/app/views/items/_item_row.html.erb b/app/views/items/_item_row.html.erb index 5efb0ab31d..0e1d160750 100644 --- a/app/views/items/_item_row.html.erb +++ b/app/views/items/_item_row.html.erb @@ -4,10 +4,8 @@ <%= truncate item_row.additional_info, length: 25 %> <%= item_row.distribution_quantity %> <%= dollar_value(item_row.value_in_cents) %> - <% if Flipper.enabled?(:enable_packs) %> - <% unless current_organization.request_units.empty? %> - <%= item_row.request_units.pluck(:name).join(', ') %> - <% end %> + <% unless current_organization.request_units.empty? %> + <%= item_row.request_units.pluck(:name).join(', ') %> <% end %> <%= view_button_to item_path(item_row) %> From 948cd645535419c022b133909207569e9f74a449 Mon Sep 17 00:00:00 2001 From: yahyaelganayni1 Date: Wed, 9 Jul 2025 14:33:26 +0300 Subject: [PATCH 10/29] Remove Flipper condition for displaying custom units in item show view --- app/views/items/show.html.erb | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/app/views/items/show.html.erb b/app/views/items/show.html.erb index 644f6e90e4..01a5e48dde 100644 --- a/app/views/items/show.html.erb +++ b/app/views/items/show.html.erb @@ -64,11 +64,9 @@ <%= @item.package_size || 0 %> - <% if Flipper.enabled?(:enable_packs) %> - Custom Units - <% item_units = @item.request_units&.pluck("item_units.name") %> - <%= item_units&.join("; ") %> - <% end %> + Custom Units + <% item_units = @item.request_units&.pluck("item_units.name") %> + <%= item_units&.join("; ") %> Item is visible to partners From ed61876c2ca3474d8754b319d0bcf5769d79b86f Mon Sep 17 00:00:00 2001 From: yahyaelganayni1 Date: Wed, 9 Jul 2025 14:37:14 +0300 Subject: [PATCH 11/29] Remove Flipper condition for displaying custom request units in organization details --- app/views/organizations/_details.html.erb | 30 +++++++++++------------ 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/app/views/organizations/_details.html.erb b/app/views/organizations/_details.html.erb index 0a1fae3d51..90dee8f736 100644 --- a/app/views/organizations/_details.html.erb +++ b/app/views/organizations/_details.html.erb @@ -149,24 +149,22 @@ <%= humanize_boolean(@organization.enable_quantity_based_requests) %>

- <% if Flipper.enabled?(:enable_packs) %> -
-
Custom Request units used (please use singular form -- e.g. pack, not packs)
-

- <% if @organization.request_units.length > 0 %> - <% @organization.request_units.map do |unit| %> - <%= fa_icon "angle-right" %> - - <%= unit.name.titlecase %> -
- <% end %> - <% else %> +

+
Custom Request units used (please use singular form -- e.g. pack, not packs)
+

+ <% if @organization.request_units.length > 0 %> + <% @organization.request_units.map do |unit| %> <%= fa_icon "angle-right" %> - None + + <%= unit.name.titlecase %> +
<% end %> -

-
- <% end %> + <% else %> + <%= fa_icon "angle-right" %> + None + <% end %> +

+

Other emails

From 365be4b994198da59150275d71e71d118469c17d Mon Sep 17 00:00:00 2001 From: yahyaelganayni1 Date: Thu, 10 Jul 2025 13:57:34 +0300 Subject: [PATCH 12/29] Remove Flipper condition for displaying custom request units in organization edit form --- app/views/organizations/edit.html.erb | 36 +++++++++++++-------------- 1 file changed, 17 insertions(+), 19 deletions(-) diff --git a/app/views/organizations/edit.html.erb b/app/views/organizations/edit.html.erb index 4e44a78e43..632ac18037 100644 --- a/app/views/organizations/edit.html.erb +++ b/app/views/organizations/edit.html.erb @@ -129,25 +129,23 @@ <%= f.input :enable_child_based_requests, label: 'Enable Partners to make child-based Requests?', as: :radio_buttons, collection: [[true, 'Yes'], [false, 'No']], label_method: :second, value_method: :first %> <%= f.input :enable_individual_requests, label: 'Enable Partners to make Requests by indicating number of individuals needing each Item?', as: :radio_buttons, collection: [[true, 'Yes'], [false, 'No']], label_method: :second, value_method: :first %> <%= f.input :enable_quantity_based_requests, label: 'Enable Partners to make quantity-based Requests?', as: :radio_buttons, collection: [[true, 'Yes'], [false, 'No']], label_method: :second, value_method: :first %> - <% if Flipper.enabled?(:enable_packs) %> - <%= label_tag "organization[request_unit_names]", 'Custom request units used. Please use singular form -- e.g. pack, not packs. There will be a default "unit" entry provided.' %> - <%= select_tag( - "organization[request_unit_names]", - options_from_collection_for_select( - current_organization.request_units, - 'name', - 'name', - ->(_) { true } # Select all of the current request units - ), - { - multiple: true, - class: 'form-control custom-select', - 'data-controller': 'select2', - 'data-select2-hide-dropdown-value': true, - 'data-select2-config-value': '{"selectOnClose": "true", "tags": "true", "tokenSeparators": [",", "\t"]}' - } - ) %> - <% end %> + <%= label_tag "organization[request_unit_names]", 'Custom request units used. Please use singular form -- e.g. pack, not packs. There will be a default "unit" entry provided.' %> + <%= select_tag( + "organization[request_unit_names]", + options_from_collection_for_select( + current_organization.request_units, + 'name', + 'name', + ->(_) { true } # Select all of the current request units + ), + { + multiple: true, + class: 'form-control custom-select', + 'data-controller': 'select2', + 'data-select2-hide-dropdown-value': true, + 'data-select2-config-value': '{"selectOnClose": "true", "tags": "true", "tokenSeparators": [",", "\t"]}' + } + ) %>

Other emails

From f6742e0d5194c51b184a525476b7d5136d297572 Mon Sep 17 00:00:00 2001 From: yahyaelganayni1 Date: Thu, 10 Jul 2025 13:58:48 +0300 Subject: [PATCH 13/29] Remove Flipper condition for displaying request units in requests in progress view --- app/views/partners/dashboards/_requests_in_progress.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/partners/dashboards/_requests_in_progress.html.erb b/app/views/partners/dashboards/_requests_in_progress.html.erb index 71a2f84151..5e1a16d287 100644 --- a/app/views/partners/dashboards/_requests_in_progress.html.erb +++ b/app/views/partners/dashboards/_requests_in_progress.html.erb @@ -24,7 +24,7 @@ <% request.item_requests.each do |item_request| %> - <% if Flipper.enabled?(:enable_packs) && item_request.request_unit %> + <% if item_request.request_unit %> <%= pluralize(item_request.quantity, item_request.request_unit) %> — <% else %> From 70000bde56d1141ebcc166bb502284d0424147ee Mon Sep 17 00:00:00 2001 From: yahyaelganayni1 Date: Thu, 10 Jul 2025 13:59:32 +0300 Subject: [PATCH 14/29] Remove Flipper condition for displaying request unit selection error message --- app/views/partners/requests/_error.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/partners/requests/_error.html.erb b/app/views/partners/requests/_error.html.erb index d4c4b6708b..71b68a6bb4 100644 --- a/app/views/partners/requests/_error.html.erb +++ b/app/views/partners/requests/_error.html.erb @@ -8,7 +8,7 @@

Oops! Something went wrong with your Request

Ensure each line item has a item selected AND a quantity greater than 0. - <% if Flipper.enabled?(:enable_packs) && (current_partner&.organization || current_organization).request_units.any? %> + <% if (current_partner&.organization || current_organization).request_units.any? %> Please ensure a single unit is selected for each item that supports it. <% end %>

From f5e6f4ff82080b8913170c90ea6c13a7feff2246 Mon Sep 17 00:00:00 2001 From: yahyaelganayni1 Date: Thu, 10 Jul 2025 14:00:18 +0300 Subject: [PATCH 15/29] Remove Flipper condition for displaying request unit selection --- app/views/partners/requests/_item_request.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/partners/requests/_item_request.html.erb b/app/views/partners/requests/_item_request.html.erb index 2afdbcc112..4a26c47044 100644 --- a/app/views/partners/requests/_item_request.html.erb +++ b/app/views/partners/requests/_item_request.html.erb @@ -12,7 +12,7 @@ <%= field.number_field :quantity, label: false, step: 1, min: 1, class: 'form-control' %> - <% if Flipper.enabled?(:enable_packs) && (current_partner ? current_partner.organization.request_units.any? : current_organization.request_units.any?) %> + <% if (current_partner ? current_partner.organization.request_units.any? : current_organization.request_units.any?) %> <%= field.label :request_unit, "Unit", {class: 'sr-only'} %> <%= field.select :request_unit, [], {include_blank: 'units'}, From b83faebc3b7c6185aea5df031e38aa51a431c4ae Mon Sep 17 00:00:00 2001 From: yahyaelganayni1 Date: Thu, 10 Jul 2025 14:00:52 +0300 Subject: [PATCH 16/29] Remove Flipper condition for displaying request units in new request form --- app/views/partners/requests/new.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/partners/requests/new.html.erb b/app/views/partners/requests/new.html.erb index 8392e17828..4a89ed1556 100644 --- a/app/views/partners/requests/new.html.erb +++ b/app/views/partners/requests/new.html.erb @@ -42,7 +42,7 @@ Item Requested Quantity - <% if Flipper.enabled?(:enable_packs) && (current_partner ? current_partner.organization.request_units.any? : current_organization.request_units.any?) %> + <% if (current_partner ? current_partner.organization.request_units.any? : current_organization.request_units.any?) %> Units (if applicable) <% end %> From 7b3943ea61615cd4d7dde418797482b6c4ed0240 Mon Sep 17 00:00:00 2001 From: yahyaelganayni1 Date: Thu, 10 Jul 2025 14:02:25 +0300 Subject: [PATCH 17/29] Remove Flipper condition for displaying request units in request items --- app/views/partners/requests/show.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/partners/requests/show.html.erb b/app/views/partners/requests/show.html.erb index c658860818..4306be174d 100644 --- a/app/views/partners/requests/show.html.erb +++ b/app/views/partners/requests/show.html.erb @@ -56,7 +56,7 @@ <% @partner_request.item_requests.each do |item| %>
  • <%= item.name %> - <%= item.quantity %> - <% if Flipper.enabled?(:enable_packs) && item.request_unit %> + <% if item.request_unit %> <%= item.request_unit.pluralize(item.quantity.to_i) %> <% end %>
  • From 86f541026a2d7019a26f873909d2de2a5537b81d Mon Sep 17 00:00:00 2001 From: yahyaelganayni1 Date: Thu, 10 Jul 2025 14:03:23 +0300 Subject: [PATCH 18/29] Remove Flipper condition for displaying request units in validation modal --- app/views/partners/requests/validate.html.erb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/views/partners/requests/validate.html.erb b/app/views/partners/requests/validate.html.erb index 87be2655b2..0020859e6f 100644 --- a/app/views/partners/requests/validate.html.erb +++ b/app/views/partners/requests/validate.html.erb @@ -11,7 +11,7 @@ Item Name Total Items - <% if Flipper.enabled?(:enable_packs) && @partner_request.item_requests.any?( &:request_unit ) %> + <% if @partner_request.item_requests.any?( &:request_unit ) %> Units <% end %> @@ -21,7 +21,7 @@ <%= line_item.name %> <%= line_item.quantity %> - <% if Flipper.enabled?(:enable_packs) && @partner_request.item_requests.any?( &:request_unit ) %> + <% if @partner_request.item_requests.any?( &:request_unit ) %> <%= line_item.request_unit&.pluralize(line_item.quantity.to_i) %> <% end %> From 2b560ad12ce7ac01ba2bdf9289d992dd9cc8e9f5 Mon Sep 17 00:00:00 2001 From: yahyaelganayni1 Date: Thu, 10 Jul 2025 14:05:06 +0300 Subject: [PATCH 19/29] Remove Flipper condition for displaying request units in show view and confirmation email --- app/views/requests/show.html.erb | 3 +-- .../requests_confirmation_mailer/confirmation_email.html.erb | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/app/views/requests/show.html.erb b/app/views/requests/show.html.erb index c2560ce0cd..567fba50ed 100644 --- a/app/views/requests/show.html.erb +++ b/app/views/requests/show.html.erb @@ -67,8 +67,7 @@ Item Quantity - <% custom_units = Flipper.enabled?(:enable_packs) && - @request.item_requests.any? { |item| item.request_unit } %> + <% custom_units = @request.item_requests.any? { |item| item.request_unit } %> <% if custom_units %> Units (if applicable) <% end %> diff --git a/app/views/requests_confirmation_mailer/confirmation_email.html.erb b/app/views/requests_confirmation_mailer/confirmation_email.html.erb index ae7f75f4d4..26d6327f90 100644 --- a/app/views/requests_confirmation_mailer/confirmation_email.html.erb +++ b/app/views/requests_confirmation_mailer/confirmation_email.html.erb @@ -4,7 +4,7 @@
      <% @request_items.each do |item| %>
    • <%= item['name'] %> - - <% if Flipper.enabled?(:enable_packs) && item['unit'] %> + <% if item['unit'] %> <%= pluralize(item['quantity'] || item['person_count'], item['unit']) %> <% else %> <%= item['quantity'] || item['person_count'] %> From b901c820ac520e3da210ae268a18343c8005d697 Mon Sep 17 00:00:00 2001 From: yahyaelganayni1 Date: Thu, 10 Jul 2025 14:07:50 +0300 Subject: [PATCH 20/29] Remove Flipper condition for displaying signature lines and request quantity in DistributionPdf --- app/pdfs/distribution_pdf.rb | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/app/pdfs/distribution_pdf.rb b/app/pdfs/distribution_pdf.rb index a92259eba0..3dee5b3f5b 100644 --- a/app/pdfs/distribution_pdf.rb +++ b/app/pdfs/distribution_pdf.rb @@ -259,9 +259,7 @@ def insert_signature_fields else move_down 20 end - signature_lines_for "Received By:" - move_down 20 signature_lines_for "Delivered By:" end @@ -286,7 +284,7 @@ def signature_lines_for(label) end def request_display_qty(request_item) - if Flipper.enabled?(:enable_packs) && request_item&.unit + if request_item&.unit "#{request_item.quantity} #{request_item.unit.pluralize(request_item.quantity)}" else request_item&.quantity || "" From a868447bfb637eaec15ed77bd7493e4afc71c96d Mon Sep 17 00:00:00 2001 From: yahyaelganayni1 Date: Thu, 10 Jul 2025 14:17:53 +0300 Subject: [PATCH 21/29] Update DistributionPdf spec to include units in item quantities --- spec/pdfs/distribution_pdf_spec.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/spec/pdfs/distribution_pdf_spec.rb b/spec/pdfs/distribution_pdf_spec.rb index 765dc1a825..adaf10aca6 100644 --- a/spec/pdfs/distribution_pdf_spec.rb +++ b/spec/pdfs/distribution_pdf_spec.rb @@ -56,7 +56,7 @@ ["Item 1", "", 50], ["Item 2", 30, 100], ["Item 3", 50, ""], - ["Item 4", 120, ""], + ["Item 4", "120 packs", ""], ["", "", ""], ["Total Items Received", 200, 150] ]) @@ -71,7 +71,7 @@ ["Item 1", "", 50, "1"], ["Item 2", 30, 100, nil], ["Item 3", 50, "", nil], - ["Item 4", 120, "", nil], + ["Item 4", "120 packs", "", nil], ["", "", ""], ["Total Items Received", 200, 150, ""] ]) @@ -89,7 +89,7 @@ ["Item 1", "", 50], ["Item 2", 30, 100], ["Item 3", 50, ""], - ["Item 4", 120, ""], + ["Item 4", "120 packs", ""], ["", "", ""], ["Total Items Received", 200, 150] ]) @@ -104,7 +104,7 @@ ["Item 1", "", 50, "1"], ["Item 2", 30, 100, nil], ["Item 3", 50, "", nil], - ["Item 4", 120, "", nil], + ["Item 4", "120 packs", "", nil], ["", "", ""], ["Total Items Received", 200, 150, ""] ]) @@ -122,7 +122,7 @@ ["Item 1", "", 50, "$1.00", "$50.00"], ["Item 2", 30, 100, "$2.00", "$200.00"], ["Item 3", 50, "", "$3.00", nil], - ["Item 4", 120, "", "$4.00", nil], + ["Item 4", "120 packs", "", "$4.00", nil], ["", "", "", "", ""], ["Total Items Received", 200, 150, "", "$250.00"] ]) From b76d927843c7ec79cafaa9d1a7e6929166b0b8d2 Mon Sep 17 00:00:00 2001 From: yahyaelganayni1 Date: Thu, 10 Jul 2025 14:31:11 +0300 Subject: [PATCH 22/29] Refactor item request handling to remove Flipper conditions and ensure proper unit display in CSV export --- .../exports/export_request_service.rb | 28 +++++++++++-------- .../exports/export_request_service_spec.rb | 11 ++++++-- 2 files changed, 26 insertions(+), 13 deletions(-) diff --git a/app/services/exports/export_request_service.rb b/app/services/exports/export_request_service.rb index 02da2c4c83..fe8ba09b0b 100644 --- a/app/services/exports/export_request_service.rb +++ b/app/services/exports/export_request_service.rb @@ -70,16 +70,14 @@ def compute_item_headers if item_request.item item = item_request.item item_names << item.name - if Flipper.enabled?(:enable_packs) - item.request_units.each do |unit| - item_names << "#{item.name} - #{unit.name.pluralize}" - end - - # It's possible that the unit is no longer valid, so we'd - # add that individually - if item_request.request_unit.present? - item_names << "#{item.name} - #{item_request.request_unit.pluralize}" - end + item.request_units.each do |unit| + item_names << "#{item.name} - #{unit.name.pluralize}" + end + + # It's possible that the unit is no longer valid, so we'd + # add that individually + if item_request.request_unit.present? + item_names << "#{item.name} - #{item_request.request_unit.pluralize}" end end end @@ -97,7 +95,15 @@ def build_row_data(request) row += Array.new(item_headers.size, 0) request.item_requests.each do |item_request| - item_name = item_request.item.present? ? item_request.name_with_unit(0) : DELETED_ITEMS_COLUMN_HEADER + item_name = if item_request.item.present? + if item_request.request_unit.present? + item_request.name_with_unit(0) + else + item_request.item.name + end + else + DELETED_ITEMS_COLUMN_HEADER + end item_column_idx = headers_with_indexes[item_name] row[item_column_idx] ||= 0 row[item_column_idx] += item_request.quantity.to_i diff --git a/spec/services/exports/export_request_service_spec.rb b/spec/services/exports/export_request_service_spec.rb index 100994f0e7..cb1af4c749 100644 --- a/spec/services/exports/export_request_service_spec.rb +++ b/spec/services/exports/export_request_service_spec.rb @@ -234,6 +234,7 @@ "2T Diapers -- UPDATED", "3T Diapers", "4T Diapers", + "4T Diapers - packs", "" ]) end @@ -251,6 +252,7 @@ 0, # 2T Diapers 150, # 3T Diapers 0, # 4T Diapers + 0, # 4T Diapers - packs 0 # ]) end @@ -264,6 +266,7 @@ 100, # 2T Diapers 0, # 3T Diapers 0, # 4T Diapers + 0, # 4T Diapers - packs 0 # ]) end @@ -277,6 +280,7 @@ 0, # 2T Diapers 0, # 3T Diapers 0, # 4T Diapers + 0, # 4T Diapers - packs 400 # ]) end @@ -289,7 +293,8 @@ "Started", 3, # 2T Diapers 2, # 3T Diapers - 4, # 4T Diapers + 0, # 4T Diapers + 4, # 4T Diapers - packs 0 # ]) end @@ -303,6 +308,7 @@ 0, # 2T Diapers 0, # 3T Diapers 77, # 4T Diapers + 0, # 4T Diapers - packs 0 # ]) end @@ -315,7 +321,8 @@ "Started", 0, # 2T Diapers 0, # 3T Diapers - 1, # 4T Diapers + 0, # 4T Diapers + 1, # 4T Diapers - packs 0 # ]) end From 3a3c8151668daa019e1f3d0f8ff5cfdcac3ac8fd Mon Sep 17 00:00:00 2001 From: yahyaelganayni1 Date: Thu, 31 Jul 2025 10:39:17 +0300 Subject: [PATCH 23/29] Enhance RequestsTotalItemsService specs to handle request_unit variations and improve quantity calculations --- .../requests_total_items_service_spec.rb | 119 ++++++++++++------ 1 file changed, 84 insertions(+), 35 deletions(-) diff --git a/spec/services/requests_total_items_service_spec.rb b/spec/services/requests_total_items_service_spec.rb index 2ad28ba24a..c0b3f40bb0 100644 --- a/spec/services/requests_total_items_service_spec.rb +++ b/spec/services/requests_total_items_service_spec.rb @@ -14,51 +14,100 @@ let(:item_ids) { sample_items.pluck(:id) } let(:requests) do local_requests = [ - create(:request, :with_item_requests, request_items: item_ids.map { |k| { "item_id" => k, "quantity" => 20 } }), + create(:request, :with_item_requests, request_items: item_ids.map { |k| { "item_id" => k, "quantity" => 20, "request_unit" => "bundle" } }), create(:request, :with_item_requests, request_items: item_ids.map { |k| { "item_id" => k, "quantity" => 10, "request_unit" => "bundle" } }), create(:request, :with_item_requests, request_items: item_ids.map { |k| { "item_id" => k, "quantity" => 50, "request_unit" => "bundle" } }) ] Request.where(id: local_requests.map(&:id)) end - it 'return items with correct quantities calculated' do - expect(subject.first.last).to eq(80) + it 'returns items with correct quantities calculated' do + expect(subject.values.first).to eq(80) end - it 'return the names of items correctly' do - expect(subject.keys).to eq([ - "item_name_0", - "item_name_1", - "item_name_2" - ]) + it 'returns the names of items correctly' do + expect(subject.keys).to include("item_name_0 - bundles") end + end - context 'when custom request units are specified and enabled' do - before do - Flipper.enable(:enable_packs) - end + context 'when request_unit is blank' do + let(:item) { create(:item, :with_unit, name: "Test Item", organization: organization, unit: "piece") } + let(:requests) do + request = create(:request, :with_item_requests, request_items: [{"item_id" => item.id, "quantity" => 5, "request_unit" => nil}]) + Request.where(id: request.id) + end - it 'returns the names of items correctly' do - expect(subject.keys).to eq([ - "item_name_0", - "item_name_1", - "item_name_2", - "item_name_0 - bundles", - "item_name_1 - bundles", - "item_name_2 - bundles" - ]) - end + it 'handles nil request_unit gracefully' do + expect { subject }.not_to raise_error + end + end - it 'returns items with correct quantities calculated' do - expect(subject).to eq({ - "item_name_0" => 20, - "item_name_0 - bundles" => 60, - "item_name_1" => 20, - "item_name_1 - bundles" => 60, - "item_name_2" => 20, - "item_name_2 - bundles" => 60 - }) - end + context 'when request_unit is empty string' do + let(:item) { create(:item, :with_unit, name: "Test Item", organization: organization, unit: "piece") } + let(:requests) do + request = create(:request, :with_item_requests, request_items: [{"item_id" => item.id, "quantity" => 5, "request_unit" => ""}]) + Request.where(id: request.id) + end + + it 'handles empty request_unit gracefully' do + expect { subject }.not_to raise_error + end + end + + context 'when mixing items with and without request_unit' do + let(:item1) { create(:item, :with_unit, name: "Item 1", organization: organization, unit: "pack") } + let(:item2) { create(:item, :with_unit, name: "Item 2", organization: organization, unit: "bundle") } + let(:requests) do + local_requests = [ + create(:request, :with_item_requests, request_items: [{"item_id" => item1.id, "quantity" => 10, "request_unit" => "pack"}]), + create(:request, :with_item_requests, request_items: [{"item_id" => item2.id, "quantity" => 5, "request_unit" => nil}]) + ] + Request.where(id: local_requests.map(&:id)) + end + + it 'processes mixed request_unit scenarios' do + expect { subject }.not_to raise_error + expect(subject.size).to be >= 1 + end + end + + context 'when quantity is zero' do + let(:item) { create(:item, :with_unit, name: "Zero Item", organization: organization, unit: "piece") } + let(:requests) do + request = create(:request, :with_item_requests, request_items: [{"item_id" => item.id, "quantity" => 0, "request_unit" => "piece"}]) + Request.where(id: request.id) + end + + it 'includes items with zero quantity' do + expect(subject["Zero Item - pieces"]).to eq(0) + end + end + + context 'when quantity is string' do + let(:item) { create(:item, :with_unit, name: "String Qty Item", organization: organization, unit: "box") } + let(:requests) do + request = create(:request, :with_item_requests, request_items: [{"item_id" => item.id, "quantity" => "15", "request_unit" => "box"}]) + Request.where(id: request.id) + end + + it 'converts string quantity to integer' do + expect(subject["String Qty Item - boxes"]).to eq(15) + end + end + + context 'when multiple requests have same item' do + let(:item) { create(:item, :with_unit, name: "Duplicate Item", organization: organization, unit: "unit") } + let(:requests) do + local_requests = [ + create(:request, :with_item_requests, request_items: [{"item_id" => item.id, "quantity" => 10, "request_unit" => "unit"}]), + create(:request, :with_item_requests, request_items: [{"item_id" => item.id, "quantity" => 20, "request_unit" => "unit"}]), + create(:request, :with_item_requests, request_items: [{"item_id" => item.id, "quantity" => 30, "request_unit" => "unit"}]) + ] + Request.where(id: local_requests.map(&:id)) + end + + it 'sums quantities correctly' do + expect(subject["Duplicate Item - units"]).to eq(60) end end @@ -75,7 +124,7 @@ end context 'when request item belongs to deleted item' do - let(:item) { create(:item, :with_unit, name: "Diaper", organization:, unit: "pack") } + let(:item) { create(:item, :with_unit, name: "Diaper", organization: organization, unit: "pack") } let!(:requests) do request = create(:request, :with_item_requests, request_items: [{"item_id" => item.id, "quantity" => 10, "request_unit" => "pack"}]) Request.where(id: request.id) @@ -86,7 +135,7 @@ end it 'returns item with correct quantity calculated' do - expect(subject).to eq({"Diaper" => 10}) + expect(subject).to eq({"Diaper - packs" => 10}) end end end From 8828b0b0e23f5397809273e43d213b37afd7d3c0 Mon Sep 17 00:00:00 2001 From: yahyaelganayni1 Date: Thu, 31 Jul 2025 10:59:49 +0300 Subject: [PATCH 24/29] Fix quantity display in name_with_unit method and update test for zero quantity handling --- app/models/partners/item_request.rb | 3 ++- spec/services/requests_total_items_service_spec.rb | 5 ++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/app/models/partners/item_request.rb b/app/models/partners/item_request.rb index 823801d04b..b5932209b8 100644 --- a/app/models/partners/item_request.rb +++ b/app/models/partners/item_request.rb @@ -37,7 +37,8 @@ def request_unit_is_supported end def name_with_unit(quantity_override = nil) - "#{item&.name || name} - #{request_unit.pluralize(quantity_override || quantity.to_i)}" + unit_text = request_unit.present? ? request_unit.pluralize(quantity_override || quantity.to_i) : "items" + "#{item&.name || name} - #{unit_text}" end end end diff --git a/spec/services/requests_total_items_service_spec.rb b/spec/services/requests_total_items_service_spec.rb index c0b3f40bb0..f2cad8049a 100644 --- a/spec/services/requests_total_items_service_spec.rb +++ b/spec/services/requests_total_items_service_spec.rb @@ -74,7 +74,10 @@ context 'when quantity is zero' do let(:item) { create(:item, :with_unit, name: "Zero Item", organization: organization, unit: "piece") } let(:requests) do - request = create(:request, :with_item_requests, request_items: [{"item_id" => item.id, "quantity" => 0, "request_unit" => "piece"}]) + # Create a valid request first, then manually update to bypass validation + request = create(:request, :with_item_requests, request_items: [{"item_id" => item.id, "quantity" => 1, "request_unit" => "piece"}]) + # Update the quantity to 0 to bypass validation + request.item_requests.first.update_column(:quantity, 0) Request.where(id: request.id) end From ae3deff69fbf3b879ab555e453a058c9587175f6 Mon Sep 17 00:00:00 2001 From: yahyaelganayni1 Date: Thu, 31 Jul 2025 12:14:30 +0300 Subject: [PATCH 25/29] Refactor organization request specs to remove flipper checks for custom units display --- spec/requests/organization_requests_spec.rb | 54 ++++----------------- 1 file changed, 10 insertions(+), 44 deletions(-) diff --git a/spec/requests/organization_requests_spec.rb b/spec/requests/organization_requests_spec.rb index b0e294d3b0..56b5f501ac 100644 --- a/spec/requests/organization_requests_spec.rb +++ b/spec/requests/organization_requests_spec.rb @@ -137,20 +137,9 @@ expect(response.body).to include("Default Center") end - context "when enable_packs flipper is on" do - it "displays organization's custom units" do - Flipper.enable(:enable_packs) - get organization_path - expect(response.body).to include "Wolf Pack" - end - end - - context "when enable_packs flipper is off" do - it "does not display organization's custom units" do - Flipper.disable(:enable_packs) - get organization_path - expect(response.body).to_not include "Wolf Pack" - end + it "displays organization's custom units" do + get organization_path + expect(response.body).to include "Wolf Pack" end it "cannot see 'Demote to User' button for admins" do @@ -203,20 +192,9 @@ expect(html.text).to include("Receive email when Partner makes a Request?") end - context "when enable_packs flipper is on" do - it "displays organization's custom units" do - Flipper.enable(:enable_packs) - get organization_path - expect(response.body).to include "Wolf Pack" - end - end - - context "when enable_packs flipper is off" do - it "does not display organization's custom units" do - Flipper.disable(:enable_packs) - get organization_path - expect(response.body).to_not include "Wolf Pack" - end + it "displays organization's custom units" do + get organization_path + expect(response.body).to include "Wolf Pack" end it "can see 'Demote to User' button for admins" do @@ -259,22 +237,10 @@ ) end - context "when enable_packs flipper is on" do - it "should display custom units and units form" do - Flipper.enable(:enable_packs) - get edit_organization_path - expect(response.body).to include("Custom request units used") - expect(response.body).to include "WolfPack" - end - end - - context "when enable_packs flipper is off" do - it "should not display custom units and units form" do - Flipper.disable(:enable_packs) - get edit_organization_path - expect(response.body).to_not include("Custom request units used") - expect(response.body).to_not include "WolfPack" - end + it "should display custom units and units form" do + get edit_organization_path + expect(response.body).to include("Custom request units used") + expect(response.body).to include "WolfPack" end end From c24e5a4ebf5a99baa57d87891e447a247f69da7e Mon Sep 17 00:00:00 2001 From: yahyaelganayni1 Date: Thu, 31 Jul 2025 12:30:46 +0300 Subject: [PATCH 26/29] Remove Flipper checks for enable_packs feature across various specs and seed files --- db/seeds.rb | 4 +--- spec/controllers/items_controller_spec.rb | 2 -- .../requests_confirmation_mailer_spec.rb | 2 -- spec/pdfs/distribution_pdf_spec.rb | 3 --- spec/pdfs/picklists_pdf_spec.rb | 1 - spec/requests/distributions_requests_spec.rb | 2 -- spec/requests/items_requests_spec.rb | 18 +++--------------- .../partners/dashboard_requests_spec.rb | 2 -- spec/requests/partners/requests_spec.rb | 6 ------ spec/requests/requests_requests_spec.rb | 1 - .../exports/export_request_service_spec.rb | 2 -- .../organization_update_service_spec.rb | 1 - spec/system/partners/requests_system_spec.rb | 2 -- 13 files changed, 4 insertions(+), 42 deletions(-) diff --git a/db/seeds.rb b/db/seeds.rb index a5ab90bb63..68807394ac 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -349,7 +349,7 @@ def seed_random_item_with_name(organization, name) receives_essentials_from_other: Faker::Lorem.sentence, ) end - + if p.partials_to_show.include? "organizational_capacity" profile.update( client_capacity: Faker::Lorem.sentence, @@ -1111,8 +1111,6 @@ def seed_quantity(item_name, organization, storage_location, quantity) Flipper.enable(:read_events) Flipper::Adapters::ActiveRecord::Feature.find_or_create_by(key: "partner_step_form") Flipper.enable(:partner_step_form) -Flipper::Adapters::ActiveRecord::Feature.find_or_create_by(key: "enable_packs") -Flipper.enable(:enable_packs) # ---------------------------------------------------------------------------- # Account Requests # ---------------------------------------------------------------------------- diff --git a/spec/controllers/items_controller_spec.rb b/spec/controllers/items_controller_spec.rb index 31299f3bd9..b471266b9f 100644 --- a/spec/controllers/items_controller_spec.rb +++ b/spec/controllers/items_controller_spec.rb @@ -53,7 +53,6 @@ end context "request units" do - before(:each) { Flipper.enable(:enable_packs) } let(:item) { create(:item, organization:) } let(:unit) { create(:unit, organization:) } it "should add new item's request units" do @@ -168,7 +167,6 @@ end it "should accept request_unit ids and create request_units" do - Flipper.enable(:enable_packs) unit = create(:unit, organization: organization) item_params[:item] = item_params[:item].merge({request_unit_ids: [unit.id]}) post :create, params: item_params diff --git a/spec/mailers/requests_confirmation_mailer_spec.rb b/spec/mailers/requests_confirmation_mailer_spec.rb index 4a75e3b043..fbfc3e17d0 100644 --- a/spec/mailers/requests_confirmation_mailer_spec.rb +++ b/spec/mailers/requests_confirmation_mailer_spec.rb @@ -60,7 +60,6 @@ end it "shows units" do - Flipper.enable(:enable_packs) item1 = create(:item, organization:) item2 = create(:item, organization:) create(:item_unit, item: item1, name: "Pack") @@ -76,7 +75,6 @@ end it "skips units when are not provided" do - Flipper.enable(:enable_packs) item = create(:item, organization:) create(:item_unit, item: item, name: "Pack") request = create(:request, :pending, request_items: [{item_id: item.id, quantity: 7}]) diff --git a/spec/pdfs/distribution_pdf_spec.rb b/spec/pdfs/distribution_pdf_spec.rb index adaf10aca6..789e508d62 100644 --- a/spec/pdfs/distribution_pdf_spec.rb +++ b/spec/pdfs/distribution_pdf_spec.rb @@ -21,7 +21,6 @@ end specify "#request_data with custom units feature" do - Flipper.enable(:enable_packs) results = described_class.new(organization, distribution).request_data expect(results).to eq([ ["Items Received", "Requested", "Received", "Value/item", "In-Kind Value Received", "Packages"], @@ -137,7 +136,6 @@ def compare_pdf(distribution, expected_file_path) begin # Run the following from Rails sandbox console (bin/rails/console --sandbox) to regenerate these comparison PDFs: # => load "lib/test_helpers/pdf_comparison_test_factory.rb" - # => Flipper.enable(:enable_packs) # => PDFComparisonTestFactory.create_comparison_pdfs expect(pdf_file).to eq(IO.binread(expected_file_path)) rescue RSpec::Expectations::ExpectationNotMetError => e @@ -148,7 +146,6 @@ def compare_pdf(distribution, expected_file_path) # The generated PDFs (PDFs to use for comparison) are expecting the packs feature to be enabled. before(:each) do - Flipper.enable(:enable_packs) end let(:partner) { PDFComparisonTestFactory.create_partner(organization) } diff --git a/spec/pdfs/picklists_pdf_spec.rb b/spec/pdfs/picklists_pdf_spec.rb index 49171f5fc8..ba99e87361 100644 --- a/spec/pdfs/picklists_pdf_spec.rb +++ b/spec/pdfs/picklists_pdf_spec.rb @@ -123,7 +123,6 @@ end context "When packs are enabled" do - before { Flipper.enable(:enable_packs) } specify "#data_with_units" do item_with_units = create(:item, name: "Item with units", organization: organization) diff --git a/spec/requests/distributions_requests_spec.rb b/spec/requests/distributions_requests_spec.rb index 19670522bf..b2992e86e9 100644 --- a/spec/requests/distributions_requests_spec.rb +++ b/spec/requests/distributions_requests_spec.rb @@ -378,7 +378,6 @@ context 'with units' do before(:each) do - Flipper.enable(:enable_packs) end it 'should behave correctly' do @@ -738,7 +737,6 @@ ] } before(:each) do - Flipper.enable(:enable_packs) create(:line_item, itemizable: distribution, item_id: items[0].id, quantity: 25) create(:line_item, itemizable: distribution, item_id: items[2].id, quantity: 10) end diff --git a/spec/requests/items_requests_spec.rb b/spec/requests/items_requests_spec.rb index a3cc49ae14..bb8904812c 100644 --- a/spec/requests/items_requests_spec.rb +++ b/spec/requests/items_requests_spec.rb @@ -80,7 +80,6 @@ describe "GET #new" do it "shows the organization request_units options if they exist" do - Flipper.enable(:enable_packs) organization_units = create_list(:unit, 3, organization: organization) get new_item_path organization_units.each do |unit| @@ -91,7 +90,6 @@ describe "GET #edit" do it "shows the selected request_units" do - Flipper.enable(:enable_packs) organization_units = create_list(:unit, 3, organization: organization) selected_unit = organization_units.first item = create(:item, organization: organization) @@ -254,8 +252,6 @@ end context "custom request items" do - before(:each) { Flipper.enable(:enable_packs) } - it "does not show the column if the organization does not use custom request units" do get items_path expect(response.body).not_to include("Custom Request Units") @@ -280,7 +276,7 @@ let!(:item) { create(:item, organization: organization, name: "ACTIVEITEM", item_category_id: item_category.id, distribution_quantity: 2000, on_hand_recommended_quantity: 2348, package_size: 100, value_in_cents: 20000, on_hand_minimum_quantity: 1200, visible_to_partners: true) } let!(:item_unit_1) { create(:item_unit, item: item, name: 'ITEM1') } let!(:item_unit_2) { create(:item_unit, item: item, name: 'ITEM2') } - it 'shows complete item details except custom request' do + it 'shows complete item details including custom request units' do get item_path(id: item.id) expect(response.body).to include('Base Item') expect(response.body).to include('BASEITEM') @@ -298,18 +294,10 @@ expect(response.body).to include('2348') expect(response.body).to include('Package Size') expect(response.body).to include('100') - expect(response.body).not_to include('Custom Units') - expect(response.body).not_to include("#ITEM1; ITEM2") - expect(response.body).to include('Item is visible to partners') - expect(response.body).to include('Yes') - end - - it 'shows custom request units when flipper enabled' do - Flipper.enable(:enable_packs) - get item_path(id: item.id) - expect(response.body).to include('Custom Units') expect(response.body).to include("ITEM1; ITEM2") + expect(response.body).to include('Item is visible to partners') + expect(response.body).to include('Yes') end end end diff --git a/spec/requests/partners/dashboard_requests_spec.rb b/spec/requests/partners/dashboard_requests_spec.rb index 7475387487..dac880f2b3 100644 --- a/spec/requests/partners/dashboard_requests_spec.rb +++ b/spec/requests/partners/dashboard_requests_spec.rb @@ -38,7 +38,6 @@ end it "shows units" do - Flipper.enable(:enable_packs) create(:item_unit, item: item1, name: "Pack") create(:item_unit, item: item2, name: "Pack") request = create(:request, :pending, partner: partner, request_items: []) @@ -51,7 +50,6 @@ end it "skips units when are not provided" do - Flipper.enable(:enable_packs) create(:item_unit, item: item1, name: "Pack") request = create(:request, :pending, partner: partner, request_items: []) create(:item_request, request: request, quantity: 7, item: item1) diff --git a/spec/requests/partners/requests_spec.rb b/spec/requests/partners/requests_spec.rb index 55b88df00a..584bc5e972 100644 --- a/spec/requests/partners/requests_spec.rb +++ b/spec/requests/partners/requests_spec.rb @@ -54,11 +54,9 @@ context "when packs are enabled but there are no requestable items" do before do allow_any_instance_of(PartnerFetchRequestableItemsService).to receive(:call).and_return({}) - Flipper.enable(:enable_packs) end after do - Flipper.disable(:enable_packs) end it 'should render without any issues' do @@ -181,13 +179,11 @@ ] ) - Flipper.enable(:enable_packs) get partners_request_path(request) expect(response.body).to match(/First item - 125/m) expect(response.body).to match(/Second item - 559\s+flats/m) expect(response.body).to match(/Third item - 1\s+flat/m) - Flipper.disable(:enable_packs) get partners_request_path(request) expect(response.body).to match(/First item - 125/m) expect(response.body).to match(/Second item - 559/m) @@ -290,7 +286,6 @@ end it "creates without error" do - Flipper.enable(:enable_packs) expect { subject }.to change { Request.count }.by(1) expect(response).to redirect_to(partners_request_path(Request.last.id)) expect(response.request.flash[:success]).to eql "Request was successfully created." @@ -319,7 +314,6 @@ end it "results in an error" do - Flipper.enable(:enable_packs) expect { post partners_requests_path, params: request_attributes }.to_not change { Request.count } expect(response).to be_unprocessable expect(response.body).to include("Please ensure a single unit is selected for each item") diff --git a/spec/requests/requests_requests_spec.rb b/spec/requests/requests_requests_spec.rb index 6ff8095bfc..68157a168d 100644 --- a/spec/requests/requests_requests_spec.rb +++ b/spec/requests/requests_requests_spec.rb @@ -91,7 +91,6 @@ end context 'When packs are enabled' do - before { Flipper.enable(:enable_packs) } let(:item) { create(:item, name: "Item", organization: organization) } let(:request) { create(:request, organization: organization) } diff --git a/spec/services/exports/export_request_service_spec.rb b/spec/services/exports/export_request_service_spec.rb index cb1af4c749..0d15b4f2d7 100644 --- a/spec/services/exports/export_request_service_spec.rb +++ b/spec/services/exports/export_request_service_spec.rb @@ -96,7 +96,6 @@ context "with custom units feature enabled" do before do - Flipper.enable(:enable_packs) end describe ".generate_csv_data" do @@ -221,7 +220,6 @@ context "with custom units feature disabled" do before do - Flipper.disable(:enable_packs) end describe ".generate_csv_data" do diff --git a/spec/services/organization_update_service_spec.rb b/spec/services/organization_update_service_spec.rb index 1a9e980aa6..f738fc9ef3 100644 --- a/spec/services/organization_update_service_spec.rb +++ b/spec/services/organization_update_service_spec.rb @@ -11,7 +11,6 @@ end it "Should set request_units on the organization" do - Flipper.enable(:enable_packs) params = {request_unit_names: ["newpack"]} described_class.update(organization, params) expect(organization.errors.none?).to eq(true) diff --git a/spec/system/partners/requests_system_spec.rb b/spec/system/partners/requests_system_spec.rb index 4238d7c25d..975004c034 100644 --- a/spec/system/partners/requests_system_spec.rb +++ b/spec/system/partners/requests_system_spec.rb @@ -16,7 +16,6 @@ context "with packs off" do before(:each) do - Flipper.disable(:enable_packs) end it "should not show packs on selection" do @@ -28,7 +27,6 @@ context "with packs on" do before(:each) do - Flipper.enable(:enable_packs) end it "should require a unit selection" do From 152e064a680df13b15b8bab770afc7bba2f4f860 Mon Sep 17 00:00:00 2001 From: yahyaelganayni1 Date: Thu, 31 Jul 2025 12:32:37 +0300 Subject: [PATCH 27/29] Remove unnecessary blank line in packs enabled context of picklists_pdf_spec --- spec/pdfs/picklists_pdf_spec.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/spec/pdfs/picklists_pdf_spec.rb b/spec/pdfs/picklists_pdf_spec.rb index ba99e87361..90e019de7a 100644 --- a/spec/pdfs/picklists_pdf_spec.rb +++ b/spec/pdfs/picklists_pdf_spec.rb @@ -123,7 +123,6 @@ end context "When packs are enabled" do - specify "#data_with_units" do item_with_units = create(:item, name: "Item with units", organization: organization) create(:item_unit, item: item_with_units, name: "Pack") From 335ffc8edd28ba34261907194c1709df704fb076 Mon Sep 17 00:00:00 2001 From: yahyaelganayni1 Date: Thu, 31 Jul 2025 12:39:49 +0300 Subject: [PATCH 28/29] Remove context for packs off in requests system spec --- spec/system/partners/requests_system_spec.rb | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/spec/system/partners/requests_system_spec.rb b/spec/system/partners/requests_system_spec.rb index 975004c034..cc9d656729 100644 --- a/spec/system/partners/requests_system_spec.rb +++ b/spec/system/partners/requests_system_spec.rb @@ -14,17 +14,6 @@ FactoryBot.create(:item_unit, name: "pack", item: item1) end - context "with packs off" do - before(:each) do - end - - it "should not show packs on selection" do - visit new_partners_request_path - select "Item 1", from: "request_item_requests_attributes_0_item_id" - expect(page).not_to have_selector("#request_item_requests_attributes_0_request_unit", visible: true) - end - end - context "with packs on" do before(:each) do end From 2ac64c43dcbf77e75e0679576bb149efa793c67e Mon Sep 17 00:00:00 2001 From: yahya Date: Mon, 11 Aug 2025 16:44:27 +0300 Subject: [PATCH 29/29] Refactor name_with_unit method for clarity and consistency in unit handling --- app/models/partners/item_request.rb | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/app/models/partners/item_request.rb b/app/models/partners/item_request.rb index b5932209b8..078b448cba 100644 --- a/app/models/partners/item_request.rb +++ b/app/models/partners/item_request.rb @@ -37,8 +37,11 @@ def request_unit_is_supported end def name_with_unit(quantity_override = nil) - unit_text = request_unit.present? ? request_unit.pluralize(quantity_override || quantity.to_i) : "items" - "#{item&.name || name} - #{unit_text}" + if request_unit.present? + "#{item&.name || name} - #{request_unit.pluralize(quantity_override || quantity.to_i)}" + else + item&.name || name + end end end end