From 35c4e27baf7d84d5bcc4a9029142f7c44c7b1512 Mon Sep 17 00:00:00 2001 From: nathan Date: Fri, 15 Mar 2024 13:31:27 -0600 Subject: [PATCH 01/33] Adds type enum to request model. --- app/models/request.rb | 2 ++ config/database.yml | 3 ++- db/migrate/20240315190152_add_type_to_requests.rb | 5 +++++ db/schema.rb | 3 ++- spec/factories/requests.rb | 1 + spec/models/request_spec.rb | 1 + 6 files changed, 13 insertions(+), 2 deletions(-) create mode 100644 db/migrate/20240315190152_add_type_to_requests.rb diff --git a/app/models/request.rb b/app/models/request.rb index c6963aeeb3..ad6f954a45 100644 --- a/app/models/request.rb +++ b/app/models/request.rb @@ -8,6 +8,7 @@ # discarded_at :datetime # request_items :jsonb # status :integer default("pending") +# type :integer # created_at :datetime not null # updated_at :datetime not null # distribution_id :integer @@ -31,6 +32,7 @@ class Request < ApplicationRecord has_many :child_item_requests, through: :item_requests enum status: { pending: 0, started: 1, fulfilled: 2, discarded: 3 }, _prefix: true + enum type: { quantity: 0, by_individuals: 1, child_based: 2 }, _prefix: true validates :distribution_id, uniqueness: true, allow_nil: true before_save :sanitize_items_data diff --git a/config/database.yml b/config/database.yml index 76003ae519..8e13af1716 100644 --- a/config/database.yml +++ b/config/database.yml @@ -1,7 +1,8 @@ default: &default adapter: postgresql encoding: unicode - host: <%= ENV.fetch("PG_HOST", 'localhost') %> + host: <%= ENV['DB_HOST'] || 'localhost' %> + database: diaper_dev username: <%= ENV.fetch("PG_USERNAME", 'postgres') %> password: <%= ENV.fetch("PG_PASSWORD", nil) %> diff --git a/db/migrate/20240315190152_add_type_to_requests.rb b/db/migrate/20240315190152_add_type_to_requests.rb new file mode 100644 index 0000000000..2cb10e0d6d --- /dev/null +++ b/db/migrate/20240315190152_add_type_to_requests.rb @@ -0,0 +1,5 @@ +class AddTypeToRequests < ActiveRecord::Migration[7.0] + def change + add_column :requests, :type, :integer + end +end diff --git a/db/schema.rb b/db/schema.rb index fc8f9f5a5c..7bb7b0ddaf 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.0].define(version: 2024_02_07_202431) do +ActiveRecord::Schema[7.0].define(version: 2024_03_15_190152) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -731,6 +731,7 @@ t.datetime "discarded_at", precision: nil t.text "discard_reason" t.integer "partner_user_id" + t.integer "type" t.index ["discarded_at"], name: "index_requests_on_discarded_at" t.index ["distribution_id"], name: "index_requests_on_distribution_id", unique: true t.index ["organization_id"], name: "index_requests_on_organization_id" diff --git a/spec/factories/requests.rb b/spec/factories/requests.rb index 572178795b..3828e3d1e4 100644 --- a/spec/factories/requests.rb +++ b/spec/factories/requests.rb @@ -8,6 +8,7 @@ # discarded_at :datetime # request_items :jsonb # status :integer default("pending") +# type :integer # created_at :datetime not null # updated_at :datetime not null # distribution_id :integer diff --git a/spec/models/request_spec.rb b/spec/models/request_spec.rb index a396f847ee..7f90892779 100644 --- a/spec/models/request_spec.rb +++ b/spec/models/request_spec.rb @@ -8,6 +8,7 @@ # discarded_at :datetime # request_items :jsonb # status :integer default("pending") +# type :integer # created_at :datetime not null # updated_at :datetime not null # distribution_id :integer From d1911fe5990a5d34cc7effa46de414468e920b27 Mon Sep 17 00:00:00 2001 From: nathan Date: Tue, 19 Mar 2024 08:15:49 -0600 Subject: [PATCH 02/33] Adds request type enum to request model. --- app/models/request.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/models/request.rb b/app/models/request.rb index ad6f954a45..e5659254b2 100644 --- a/app/models/request.rb +++ b/app/models/request.rb @@ -7,8 +7,8 @@ # discard_reason :text # discarded_at :datetime # request_items :jsonb +# request_type :integer # status :integer default("pending") -# type :integer # created_at :datetime not null # updated_at :datetime not null # distribution_id :integer @@ -32,7 +32,7 @@ class Request < ApplicationRecord has_many :child_item_requests, through: :item_requests enum status: { pending: 0, started: 1, fulfilled: 2, discarded: 3 }, _prefix: true - enum type: { quantity: 0, by_individuals: 1, child_based: 2 }, _prefix: true + enum request_type: { quantity: 0, by_individuals: 1, child_based: 2 }, _prefix: true validates :distribution_id, uniqueness: true, allow_nil: true before_save :sanitize_items_data From 3007e644dcf7365afda611c019e4a46a5257ff95 Mon Sep 17 00:00:00 2001 From: nathan Date: Tue, 19 Mar 2024 08:16:45 -0600 Subject: [PATCH 03/33] Adds request_type to request. --- db/migrate/20240315190152_add_type_to_requests.rb | 2 +- db/schema.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/db/migrate/20240315190152_add_type_to_requests.rb b/db/migrate/20240315190152_add_type_to_requests.rb index 2cb10e0d6d..a41b65e99a 100644 --- a/db/migrate/20240315190152_add_type_to_requests.rb +++ b/db/migrate/20240315190152_add_type_to_requests.rb @@ -1,5 +1,5 @@ class AddTypeToRequests < ActiveRecord::Migration[7.0] def change - add_column :requests, :type, :integer + add_column :requests, :request_type, :integer end end diff --git a/db/schema.rb b/db/schema.rb index 7bb7b0ddaf..55eb1ec56e 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -731,7 +731,7 @@ t.datetime "discarded_at", precision: nil t.text "discard_reason" t.integer "partner_user_id" - t.integer "type" + t.integer "request_type" t.index ["discarded_at"], name: "index_requests_on_discarded_at" t.index ["distribution_id"], name: "index_requests_on_distribution_id", unique: true t.index ["organization_id"], name: "index_requests_on_organization_id" From 7ae36b4d7356dbd29dc727e38faf562997267448 Mon Sep 17 00:00:00 2001 From: nathan Date: Tue, 19 Mar 2024 08:17:58 -0600 Subject: [PATCH 04/33] Adds request_type to request. --- spec/factories/requests.rb | 2 +- spec/models/request_spec.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/factories/requests.rb b/spec/factories/requests.rb index 3828e3d1e4..7934938247 100644 --- a/spec/factories/requests.rb +++ b/spec/factories/requests.rb @@ -7,8 +7,8 @@ # discard_reason :text # discarded_at :datetime # request_items :jsonb +# request_type :integer # status :integer default("pending") -# type :integer # created_at :datetime not null # updated_at :datetime not null # distribution_id :integer diff --git a/spec/models/request_spec.rb b/spec/models/request_spec.rb index 7f90892779..4062f58fc6 100644 --- a/spec/models/request_spec.rb +++ b/spec/models/request_spec.rb @@ -7,8 +7,8 @@ # discard_reason :text # discarded_at :datetime # request_items :jsonb +# request_type :integer # status :integer default("pending") -# type :integer # created_at :datetime not null # updated_at :datetime not null # distribution_id :integer From a2c79dffb9cc822609fcf547efd6fe532117eba5 Mon Sep 17 00:00:00 2001 From: nathan Date: Tue, 19 Mar 2024 08:28:52 -0600 Subject: [PATCH 05/33] Passes request_type to FamilyRequestCreateService.new --- app/controllers/partners/family_requests_controller.rb | 1 + app/controllers/partners/requests_controller.rb | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/app/controllers/partners/family_requests_controller.rb b/app/controllers/partners/family_requests_controller.rb index ff91b4b9bc..8080045bc4 100644 --- a/app/controllers/partners/family_requests_controller.rb +++ b/app/controllers/partners/family_requests_controller.rb @@ -31,6 +31,7 @@ def create end create_service = Partners::FamilyRequestCreateService.new( + request_type: params[:request_type], partner_user_id: current_user.id, family_requests_attributes: family_requests_attributes, for_families: true diff --git a/app/controllers/partners/requests_controller.rb b/app/controllers/partners/requests_controller.rb index 5beb0c406a..25ff235919 100644 --- a/app/controllers/partners/requests_controller.rb +++ b/app/controllers/partners/requests_controller.rb @@ -20,6 +20,7 @@ def show def create create_service = Partners::RequestCreateService.new( + request_type: params[:request_type], partner_user_id: current_user.id, comments: partner_request_params[:comments], item_requests_attributes: partner_request_params[:item_requests_attributes]&.values || [] @@ -45,7 +46,7 @@ def create private def partner_request_params - params.require(:request).permit(:comments, item_requests_attributes: [:item_id, :quantity]) + params.require(:request).permit(:request_type, :comments, item_requests_attributes: [:item_id, :quantity]) end end end From 7e17565519f3197932e6ce27804fd204b2a97b17 Mon Sep 17 00:00:00 2001 From: nathan Date: Tue, 19 Mar 2024 08:30:25 -0600 Subject: [PATCH 06/33] Passes request_type to FamilyRequestCreateService.new --- app/controllers/partners/individuals_requests_controller.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/controllers/partners/individuals_requests_controller.rb b/app/controllers/partners/individuals_requests_controller.rb index dff8560914..3ac4b93a9a 100644 --- a/app/controllers/partners/individuals_requests_controller.rb +++ b/app/controllers/partners/individuals_requests_controller.rb @@ -10,6 +10,7 @@ def new def create create_service = Partners::FamilyRequestCreateService.new( + request_type: params[:request_type], partner_user_id: current_user.id, comments: individuals_request_params[:comments], family_requests_attributes: individuals_request_params[:items_attributes]&.values @@ -36,7 +37,7 @@ def create def individuals_request_params params.require(:partners_family_request) - .permit(:comments, items_attributes: %i[item_id person_count]) + .permit(:request_type, :comments, items_attributes: %i[item_id person_count]) end end end From 9b5977e066c1343945cbb0acb0cbbc2f73385f7d Mon Sep 17 00:00:00 2001 From: nathan Date: Tue, 19 Mar 2024 08:32:49 -0600 Subject: [PATCH 07/33] Passes request_type to RequestCreateService.new --- app/services/partners/family_request_create_service.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/services/partners/family_request_create_service.rb b/app/services/partners/family_request_create_service.rb index e181d3e2f7..3433403136 100644 --- a/app/services/partners/family_request_create_service.rb +++ b/app/services/partners/family_request_create_service.rb @@ -8,7 +8,8 @@ class FamilyRequestCreateService attr_reader :partner_user_id, :comments, :family_requests_attributes, :partner_request - def initialize(partner_user_id:, family_requests_attributes:, comments: nil, for_families: false) + def initialize(request_type:, partner_user_id:, family_requests_attributes:, comments: nil, for_families: false) + @request_type = request_type @partner_user_id = partner_user_id @comments = comments @family_requests_attributes = family_requests_attributes.presence || [] @@ -19,6 +20,7 @@ def call return self unless valid? request_create_svc = Partners::RequestCreateService.new( + request_type: @request_type.to_i, partner_user_id: partner_user_id, comments: comments, for_families: @for_families, From 854cd39389bf3be851ec6aaf64bf17396cec5ec6 Mon Sep 17 00:00:00 2001 From: nathan Date: Tue, 19 Mar 2024 08:34:00 -0600 Subject: [PATCH 08/33] Passes request_type to Request.new. --- app/services/partners/request_create_service.rb | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/app/services/partners/request_create_service.rb b/app/services/partners/request_create_service.rb index e5c4058083..aa1ae1031f 100644 --- a/app/services/partners/request_create_service.rb +++ b/app/services/partners/request_create_service.rb @@ -4,7 +4,8 @@ class RequestCreateService attr_reader :partner_request - def initialize(partner_user_id:, comments: nil, for_families: false, item_requests_attributes: [], additional_attrs: {}) + def initialize(request_type:, partner_user_id:, comments: nil, for_families: false, item_requests_attributes: [], additional_attrs: {}) + @request_type = request_type @partner_user_id = partner_user_id @comments = comments @for_families = for_families @@ -13,7 +14,9 @@ def initialize(partner_user_id:, comments: nil, for_families: false, item_reques end def call - @partner_request = ::Request.new(partner_id: partner.id, + @partner_request = ::Request.new( + request_type: @request_type.to_i, + partner_id: partner.id, organization_id: organization_id, comments: comments, partner_user_id: partner_user_id) From 8435518633c6410cf556bebc772a552cea779a59 Mon Sep 17 00:00:00 2001 From: nathan Date: Tue, 19 Mar 2024 08:35:44 -0600 Subject: [PATCH 09/33] Adds hidden field in order to pass request_type param on submit. --- app/views/partners/family_requests/new.html.erb | 1 + app/views/partners/individuals_requests/new.html.erb | 1 + app/views/partners/requests/new.html.erb | 1 + 3 files changed, 3 insertions(+) diff --git a/app/views/partners/family_requests/new.html.erb b/app/views/partners/family_requests/new.html.erb index 496c2884b2..d137602080 100644 --- a/app/views/partners/family_requests/new.html.erb +++ b/app/views/partners/family_requests/new.html.erb @@ -82,6 +82,7 @@
diff --git a/app/views/partners/individuals_requests/new.html.erb b/app/views/partners/individuals_requests/new.html.erb index b5cc48cb30..12da20f3af 100644 --- a/app/views/partners/individuals_requests/new.html.erb +++ b/app/views/partners/individuals_requests/new.html.erb @@ -57,6 +57,7 @@
From 45a9495d2e72dd7176d7add62a593572bfa4323f Mon Sep 17 00:00:00 2001 From: nathan Date: Tue, 19 Mar 2024 12:42:23 -0600 Subject: [PATCH 10/33] Adds request type flag to index and show pages as well as the requests export. Adds filter by request type to index. --- app/views/requests/_request_row.html.erb | 3 +++ app/views/requests/_request_type.html.erb | 8 ++++++++ app/views/requests/index.html.erb | 4 ++++ app/views/requests/show.html.erb | 2 ++ 4 files changed, 17 insertions(+) create mode 100644 app/views/requests/_request_type.html.erb diff --git a/app/views/requests/_request_row.html.erb b/app/views/requests/_request_row.html.erb index 202c0a4501..581ab3fc13 100644 --- a/app/views/requests/_request_row.html.erb +++ b/app/views/requests/_request_row.html.erb @@ -12,6 +12,9 @@ <%= request_row.comments %> + + <%= render partial: "request_type", locals: {request_type: request_row.request_type} %> + <%= render partial: "status", locals: {status: request_row.status} %> diff --git a/app/views/requests/_request_type.html.erb b/app/views/requests/_request_type.html.erb new file mode 100644 index 0000000000..96f12ac874 --- /dev/null +++ b/app/views/requests/_request_type.html.erb @@ -0,0 +1,8 @@ +<% case request_type %> +<% when "quantity" %> + Quantity +<% when "by_individuals" %> + By Individuals +<% when "child_based" %> + Child Based +<% end %> diff --git a/app/views/requests/index.html.erb b/app/views/requests/index.html.erb index 5e02fc6b4e..397a0ae05a 100644 --- a/app/views/requests/index.html.erb +++ b/app/views/requests/index.html.erb @@ -47,6 +47,9 @@ <%= filter_select(scope: :by_partner, collection: @partners, selected: @selected_partner) %> <% end %> +
+ <%= filter_select(scope: :by_request_type, collection: @request_types, key: :last, value: :first, selected: @selected_request_type) %> +
<%= filter_select(scope: :by_status, collection: @statuses, key: :last, value: :first, selected: @selected_status) %>
@@ -92,6 +95,7 @@ Request Sender # of Items (Request Limit) Comments + Type Status Actions diff --git a/app/views/requests/show.html.erb b/app/views/requests/show.html.erb index 018f657b04..1058427f6e 100644 --- a/app/views/requests/show.html.erb +++ b/app/views/requests/show.html.erb @@ -37,6 +37,7 @@ Request was sent by: Request Sender: + Request Type: Request Status: Comments: @@ -45,6 +46,7 @@ <%= @request.partner.name %> <%= @request.partner_user&.formatted_email %> + <%= render partial: "request_type", locals: {request_type: @request.request_type} %> <%= render partial: "status", locals: {status: @request.status} %> <%= @request.comments || 'None' %> From 4791021cbc22978b46c0e36a186af216bb217fd7 Mon Sep 17 00:00:00 2001 From: nathan Date: Tue, 19 Mar 2024 12:43:12 -0600 Subject: [PATCH 11/33] Adds by_request_type scope for filtering by request type. --- app/models/request.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/models/request.rb b/app/models/request.rb index e5659254b2..3f12e25e89 100644 --- a/app/models/request.rb +++ b/app/models/request.rb @@ -44,6 +44,7 @@ class Request < ApplicationRecord scope :by_partner, ->(partner_id) { where(partner_id: partner_id) } # status scope to allow filtering by status scope :by_status, ->(status) { where(status: status) } + scope :by_request_type, ->(request_type) { where(request_type: request_type) } scope :during, ->(range) { where(created_at: range) } scope :for_csv_export, ->(organization, *) { where(organization: organization) From 3866a8ff003fc71e32fa3618064ed0fd06d2c7a1 Mon Sep 17 00:00:00 2001 From: nathan Date: Tue, 19 Mar 2024 12:43:47 -0600 Subject: [PATCH 12/33] Adds request type flag to index and show pages as well as the requests export. Adds filter by request type to index. --- app/services/exports/export_request_service.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/services/exports/export_request_service.rb b/app/services/exports/export_request_service.rb index e7bfba43af..0fba4d1bd9 100644 --- a/app/services/exports/export_request_service.rb +++ b/app/services/exports/export_request_service.rb @@ -46,6 +46,9 @@ def base_table "Requestor" => ->(request) { request.partner.name }, + "Type" => ->(request) { + request.request_type&.humanize + }, "Status" => ->(request) { request.status.humanize } From 8a775ec126de020293252088eab3876bd213fe3f Mon Sep 17 00:00:00 2001 From: nathan Date: Tue, 19 Mar 2024 12:45:04 -0600 Subject: [PATCH 13/33] Adds by_request_type filter. --- app/controllers/requests_controller.rb | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/app/controllers/requests_controller.rb b/app/controllers/requests_controller.rb index d44f022e3d..1593b68bd7 100644 --- a/app/controllers/requests_controller.rb +++ b/app/controllers/requests_controller.rb @@ -13,10 +13,12 @@ def index @calculate_product_totals = RequestsTotalItemsService.new(requests: @requests).calculate @items = current_organization.items.alphabetized @partners = current_organization.partners.order(:name) - @statuses = Request.statuses.transform_keys(&:humanize) + @selected_partner = filter_params[:by_partner] @partner_users = User.where(id: @paginated_requests.pluck(:partner_user_id)) + @request_types = Request.request_types.transform_keys(&:humanize) + @selected_request_type = filter_params[:by_request_type] @selected_request_item = filter_params[:by_request_item_id] - @selected_partner = filter_params[:by_partner] + @statuses = Request.statuses.transform_keys(&:humanize) @selected_status = filter_params[:by_status] respond_to do |format| @@ -57,6 +59,6 @@ def load_items def filter_params return {} unless params.key?(:filters) - params.require(:filters).permit(:by_request_item_id, :by_partner, :by_status) + params.require(:filters).permit(:by_request_item_id, :by_partner, :by_status, :by_request_type) end end From a037b1cd3347485aa13dba46187a1e2368be3f62 Mon Sep 17 00:00:00 2001 From: nathan Date: Tue, 2 Apr 2024 08:36:39 -0600 Subject: [PATCH 14/33] Updates flag names and removes flag styles based on feedback from ruby for good. --- app/models/request.rb | 2 +- app/views/requests/_request_type.html.erb | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/app/models/request.rb b/app/models/request.rb index 3f12e25e89..a1007c67f0 100644 --- a/app/models/request.rb +++ b/app/models/request.rb @@ -32,7 +32,7 @@ class Request < ApplicationRecord has_many :child_item_requests, through: :item_requests enum status: { pending: 0, started: 1, fulfilled: 2, discarded: 3 }, _prefix: true - enum request_type: { quantity: 0, by_individuals: 1, child_based: 2 }, _prefix: true + enum request_type: { quantity: 0, individual: 1, child: 2 }, _prefix: true validates :distribution_id, uniqueness: true, allow_nil: true before_save :sanitize_items_data diff --git a/app/views/requests/_request_type.html.erb b/app/views/requests/_request_type.html.erb index 96f12ac874..c573071cd4 100644 --- a/app/views/requests/_request_type.html.erb +++ b/app/views/requests/_request_type.html.erb @@ -1,8 +1,8 @@ <% case request_type %> <% when "quantity" %> - Quantity -<% when "by_individuals" %> - By Individuals -<% when "child_based" %> - Child Based +
Quantity
+<% when "individual" %> +
Individual
+<% when "child" %> +
Child
<% end %> From 26afeb485e5318cf10cd2e24c70562fcfedf7ca6 Mon Sep 17 00:00:00 2001 From: nathan Date: Wed, 3 Apr 2024 16:23:39 -0600 Subject: [PATCH 15/33] Adds test for request_type enum. --- spec/models/request_spec.rb | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/spec/models/request_spec.rb b/spec/models/request_spec.rb index 4062f58fc6..fb7a657172 100644 --- a/spec/models/request_spec.rb +++ b/spec/models/request_spec.rb @@ -24,13 +24,29 @@ let!(:request_started) { create(:request, :started) } let!(:request_fulfilled) { create(:request, :fulfilled) } - it "scopes" do + it "scopes by status" do expect(Request.status_pending).to eq([request_pending]) expect(Request.status_started).to eq([request_started]) expect(Request.status_fulfilled).to eq([request_fulfilled]) end end - end + + describe "#request_type" do + it "scopes by request_type" do + + request = Request.new + + request.request_type = :quantity + assert_equal "quantity", request.request_type + + request.request_type = :individual + assert_equal "individual", request.request_type + + request.request_type = :child + assert_equal "child", request.request_type + end + end + end describe "item data" do it "coerces item quantity and id to always be an integer before saving" do From 5c2997ba58c61bf5405017b5fcead0aaca8c9f54 Mon Sep 17 00:00:00 2001 From: nathan Date: Mon, 8 Apr 2024 10:55:01 -0600 Subject: [PATCH 16/33] Removes unnecessary line. --- spec/models/request_spec.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/spec/models/request_spec.rb b/spec/models/request_spec.rb index fb7a657172..91d5716d89 100644 --- a/spec/models/request_spec.rb +++ b/spec/models/request_spec.rb @@ -33,7 +33,6 @@ describe "#request_type" do it "scopes by request_type" do - request = Request.new request.request_type = :quantity @@ -46,7 +45,7 @@ assert_equal "child", request.request_type end end - end + end describe "item data" do it "coerces item quantity and id to always be an integer before saving" do From 0cd4451e993c34b7cda13e3658987d9b841ef16b Mon Sep 17 00:00:00 2001 From: nathan Date: Mon, 8 Apr 2024 10:55:21 -0600 Subject: [PATCH 17/33] Adds Type to expected_headers. --- spec/services/exports/export_request_service_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/services/exports/export_request_service_spec.rb b/spec/services/exports/export_request_service_spec.rb index 17e547dfad..2240111365 100644 --- a/spec/services/exports/export_request_service_spec.rb +++ b/spec/services/exports/export_request_service_spec.rb @@ -56,7 +56,7 @@ let(:expected_headers) do expected_headers_item_headers = [item_2t, item_3t].map(&:name).sort expected_headers_item_headers << Exports::ExportRequestService::DELETED_ITEMS_COLUMN_HEADER - %w(Date Requestor Status) + expected_headers_item_headers + %w(Date Requestor Type Status) + expected_headers_item_headers end it "includes headers as the first row with ordered item names alphabetically with deleted item included at the end" do From 94a1be4065f8ee66c24a8cfe939fd862118fff9b Mon Sep 17 00:00:00 2001 From: nathan Date: Mon, 8 Apr 2024 12:25:00 -0600 Subject: [PATCH 18/33] Adds request_type traits to request factory. --- spec/factories/requests.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/spec/factories/requests.rb b/spec/factories/requests.rb index 7934938247..0a4bed1520 100644 --- a/spec/factories/requests.rb +++ b/spec/factories/requests.rb @@ -43,6 +43,18 @@ def random_request_items status { 'pending' } end + trait :quantity do + request_type { 'quantity' } + end + + trait :individual do + request_type { 'individual' } + end + + trait :child do + request_type { 'child' } + end + trait :with_duplicates do request_items { # get 3 unique item ids From 42f1f846c8ce47e393fb99eff54c4f2c2b0da25a Mon Sep 17 00:00:00 2001 From: nathan Date: Mon, 8 Apr 2024 12:25:51 -0600 Subject: [PATCH 19/33] Adds request_type to family_request_create_service_spec args. --- spec/services/partners/family_request_create_service_spec.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/spec/services/partners/family_request_create_service_spec.rb b/spec/services/partners/family_request_create_service_spec.rb index 964534af1e..779084e882 100644 --- a/spec/services/partners/family_request_create_service_spec.rb +++ b/spec/services/partners/family_request_create_service_spec.rb @@ -5,12 +5,14 @@ subject { described_class.new(**args).call } let(:args) do { + request_type: 0, partner_user_id: partner_user.id, comments: comments, for_families: for_families, family_requests_attributes: family_requests_attributes } end + let(:request) { create(:request, :quantity)} let(:partner_user) { partner.primary_user } let(:partner) { create(:partner) } let(:comments) { Faker::Lorem.paragraph } @@ -108,7 +110,7 @@ let(:fake_request_create_service) { instance_double(Partners::RequestCreateService, call: -> {}, errors: [], partner_request: -> {}) } before do - allow(Partners::RequestCreateService).to receive(:new).with(partner_user_id: partner_user.id, comments: comments, for_families: false, item_requests_attributes: contain_exactly(*expected_item_request_attributes)).and_return(fake_request_create_service) + allow(Partners::RequestCreateService).to receive(:new).with(request_type: 0, partner_user_id: partner_user.id, comments: comments, for_families: false, item_requests_attributes: contain_exactly(*expected_item_request_attributes)).and_return(fake_request_create_service) end it 'should send the correct request payload to the Partners::RequestCreateService and call it' do From c6e45c8b91dab65331a5f86f0a4621be79aa17cc Mon Sep 17 00:00:00 2001 From: nathan Date: Mon, 8 Apr 2024 12:50:24 -0600 Subject: [PATCH 20/33] Adds request_type to args. --- spec/services/partners/family_request_create_service_spec.rb | 1 - spec/services/partners/request_create_service_spec.rb | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/services/partners/family_request_create_service_spec.rb b/spec/services/partners/family_request_create_service_spec.rb index 779084e882..10d43135e6 100644 --- a/spec/services/partners/family_request_create_service_spec.rb +++ b/spec/services/partners/family_request_create_service_spec.rb @@ -12,7 +12,6 @@ family_requests_attributes: family_requests_attributes } end - let(:request) { create(:request, :quantity)} let(:partner_user) { partner.primary_user } let(:partner) { create(:partner) } let(:comments) { Faker::Lorem.paragraph } diff --git a/spec/services/partners/request_create_service_spec.rb b/spec/services/partners/request_create_service_spec.rb index aad585c2d1..7931a35b22 100644 --- a/spec/services/partners/request_create_service_spec.rb +++ b/spec/services/partners/request_create_service_spec.rb @@ -5,6 +5,7 @@ subject { described_class.new(**args).call } let(:args) do { + request_type: 0, partner_user_id: partner_user.id, comments: comments, item_requests_attributes: item_requests_attributes From 67e9d7148c6102c1c7560a72a7dea0f502b64429 Mon Sep 17 00:00:00 2001 From: nathan Date: Mon, 22 Apr 2024 14:02:04 -0600 Subject: [PATCH 21/33] Pass request_type directly. --- app/controllers/partners/family_requests_controller.rb | 3 +-- app/controllers/partners/individuals_requests_controller.rb | 4 ++-- app/controllers/partners/requests_controller.rb | 4 ++-- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/app/controllers/partners/family_requests_controller.rb b/app/controllers/partners/family_requests_controller.rb index 8080045bc4..cf3d3b7860 100644 --- a/app/controllers/partners/family_requests_controller.rb +++ b/app/controllers/partners/family_requests_controller.rb @@ -29,9 +29,8 @@ def create family_requests_attributes = children_grouped_by_item_id.map do |item_id, item_requested_children| { item_id: item_id, person_count: item_requested_children.size, children: item_requested_children } end - create_service = Partners::FamilyRequestCreateService.new( - request_type: params[:request_type], + request_type: 2, partner_user_id: current_user.id, family_requests_attributes: family_requests_attributes, for_families: true diff --git a/app/controllers/partners/individuals_requests_controller.rb b/app/controllers/partners/individuals_requests_controller.rb index 3ac4b93a9a..6d1eef116e 100644 --- a/app/controllers/partners/individuals_requests_controller.rb +++ b/app/controllers/partners/individuals_requests_controller.rb @@ -10,7 +10,7 @@ def new def create create_service = Partners::FamilyRequestCreateService.new( - request_type: params[:request_type], + request_type: 1, partner_user_id: current_user.id, comments: individuals_request_params[:comments], family_requests_attributes: individuals_request_params[:items_attributes]&.values @@ -37,7 +37,7 @@ def create def individuals_request_params params.require(:partners_family_request) - .permit(:request_type, :comments, items_attributes: %i[item_id person_count]) + .permit(:comments, items_attributes: %i[item_id person_count]) end end end diff --git a/app/controllers/partners/requests_controller.rb b/app/controllers/partners/requests_controller.rb index 25ff235919..e04d534ba1 100644 --- a/app/controllers/partners/requests_controller.rb +++ b/app/controllers/partners/requests_controller.rb @@ -20,7 +20,7 @@ def show def create create_service = Partners::RequestCreateService.new( - request_type: params[:request_type], + request_type: 0, partner_user_id: current_user.id, comments: partner_request_params[:comments], item_requests_attributes: partner_request_params[:item_requests_attributes]&.values || [] @@ -46,7 +46,7 @@ def create private def partner_request_params - params.require(:request).permit(:request_type, :comments, item_requests_attributes: [:item_id, :quantity]) + params.require(:request).permit(:comments, item_requests_attributes: [:item_id, :quantity]) end end end From d8e9806c18118bacaa8ac3e707af1d958669af28 Mon Sep 17 00:00:00 2001 From: nathan Date: Mon, 22 Apr 2024 14:13:57 -0600 Subject: [PATCH 22/33] Remove request_type partial and enter text directly into reqest_row --- app/views/requests/_request_row.html.erb | 2 +- app/views/requests/_request_type.html.erb | 8 -------- 2 files changed, 1 insertion(+), 9 deletions(-) delete mode 100644 app/views/requests/_request_type.html.erb diff --git a/app/views/requests/_request_row.html.erb b/app/views/requests/_request_row.html.erb index 581ab3fc13..73d5d84d21 100644 --- a/app/views/requests/_request_row.html.erb +++ b/app/views/requests/_request_row.html.erb @@ -13,7 +13,7 @@ <%= request_row.comments %> - <%= render partial: "request_type", locals: {request_type: request_row.request_type} %> + <%= request_row&.request_type&.titleize %> <%= render partial: "status", locals: {status: request_row.status} %> diff --git a/app/views/requests/_request_type.html.erb b/app/views/requests/_request_type.html.erb deleted file mode 100644 index c573071cd4..0000000000 --- a/app/views/requests/_request_type.html.erb +++ /dev/null @@ -1,8 +0,0 @@ -<% case request_type %> -<% when "quantity" %> -
Quantity
-<% when "individual" %> -
Individual
-<% when "child" %> -
Child
-<% end %> From 1e19d307e8e6b420e8e47e43c6884b3d642fb5a1 Mon Sep 17 00:00:00 2001 From: nathan Date: Mon, 22 Apr 2024 14:15:27 -0600 Subject: [PATCH 23/33] Revert changes to database.yml --- config/database.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/config/database.yml b/config/database.yml index 8e13af1716..76003ae519 100644 --- a/config/database.yml +++ b/config/database.yml @@ -1,8 +1,7 @@ default: &default adapter: postgresql encoding: unicode - host: <%= ENV['DB_HOST'] || 'localhost' %> - + host: <%= ENV.fetch("PG_HOST", 'localhost') %> database: diaper_dev username: <%= ENV.fetch("PG_USERNAME", 'postgres') %> password: <%= ENV.fetch("PG_PASSWORD", nil) %> From 43f73655c8897ee91dfa0718b75450ecc7d49928 Mon Sep 17 00:00:00 2001 From: nathan Date: Mon, 22 Apr 2024 14:16:55 -0600 Subject: [PATCH 24/33] Revert changes to request_spec.rb --- spec/models/request_spec.rb | 17 +---------------- 1 file changed, 1 insertion(+), 16 deletions(-) diff --git a/spec/models/request_spec.rb b/spec/models/request_spec.rb index 91d5716d89..4062f58fc6 100644 --- a/spec/models/request_spec.rb +++ b/spec/models/request_spec.rb @@ -24,27 +24,12 @@ let!(:request_started) { create(:request, :started) } let!(:request_fulfilled) { create(:request, :fulfilled) } - it "scopes by status" do + it "scopes" do expect(Request.status_pending).to eq([request_pending]) expect(Request.status_started).to eq([request_started]) expect(Request.status_fulfilled).to eq([request_fulfilled]) end end - - describe "#request_type" do - it "scopes by request_type" do - request = Request.new - - request.request_type = :quantity - assert_equal "quantity", request.request_type - - request.request_type = :individual - assert_equal "individual", request.request_type - - request.request_type = :child - assert_equal "child", request.request_type - end - end end describe "item data" do From c1792ac2bf9462705857c639904f12da5d47998e Mon Sep 17 00:00:00 2001 From: nathan Date: Mon, 22 Apr 2024 14:54:28 -0600 Subject: [PATCH 25/33] Remove request_type --- app/services/partners/family_request_create_service.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/app/services/partners/family_request_create_service.rb b/app/services/partners/family_request_create_service.rb index 3433403136..0217d5adfb 100644 --- a/app/services/partners/family_request_create_service.rb +++ b/app/services/partners/family_request_create_service.rb @@ -20,7 +20,6 @@ def call return self unless valid? request_create_svc = Partners::RequestCreateService.new( - request_type: @request_type.to_i, partner_user_id: partner_user_id, comments: comments, for_families: @for_families, From 6441532c8606c5c742bdeece02c2a19430eee18c Mon Sep 17 00:00:00 2001 From: nathan Date: Mon, 22 Apr 2024 15:53:29 -0600 Subject: [PATCH 26/33] Remove hidden request_type fields. --- app/services/partners/family_request_create_service.rb | 1 + app/views/partners/family_requests/new.html.erb | 1 - app/views/partners/individuals_requests/new.html.erb | 1 - app/views/partners/requests/new.html.erb | 1 - 4 files changed, 1 insertion(+), 3 deletions(-) diff --git a/app/services/partners/family_request_create_service.rb b/app/services/partners/family_request_create_service.rb index 0217d5adfb..3433403136 100644 --- a/app/services/partners/family_request_create_service.rb +++ b/app/services/partners/family_request_create_service.rb @@ -20,6 +20,7 @@ def call return self unless valid? request_create_svc = Partners::RequestCreateService.new( + request_type: @request_type.to_i, partner_user_id: partner_user_id, comments: comments, for_families: @for_families, diff --git a/app/views/partners/family_requests/new.html.erb b/app/views/partners/family_requests/new.html.erb index d137602080..496c2884b2 100644 --- a/app/views/partners/family_requests/new.html.erb +++ b/app/views/partners/family_requests/new.html.erb @@ -82,7 +82,6 @@
diff --git a/app/views/partners/individuals_requests/new.html.erb b/app/views/partners/individuals_requests/new.html.erb index 12da20f3af..b5cc48cb30 100644 --- a/app/views/partners/individuals_requests/new.html.erb +++ b/app/views/partners/individuals_requests/new.html.erb @@ -57,7 +57,6 @@
From d53785c3fb0b4ab9d84db0ff4ded70ff3fadf00e Mon Sep 17 00:00:00 2001 From: nathan Date: Wed, 15 May 2024 12:41:22 -0600 Subject: [PATCH 27/33] Change request_type data_type to string, replace request_type string in view to display only the first letter, pull request_type from service instead of defining with an instance var. --- app/controllers/partners/family_requests_controller.rb | 2 +- .../partners/individuals_requests_controller.rb | 2 +- app/controllers/partners/requests_controller.rb | 2 +- app/models/request.rb | 4 ++-- app/services/partners/family_request_create_service.rb | 4 +--- app/services/partners/request_create_service.rb | 9 ++++++--- app/views/requests/_request_row.html.erb | 2 +- app/views/requests/show.html.erb | 2 +- db/migrate/20240315190152_add_type_to_requests.rb | 2 +- db/schema.rb | 7 ++++--- spec/factories/requests.rb | 2 +- spec/models/request_spec.rb | 2 +- .../partners/family_request_create_service_spec.rb | 4 ++-- spec/services/partners/request_create_service_spec.rb | 2 +- 14 files changed, 24 insertions(+), 22 deletions(-) diff --git a/app/controllers/partners/family_requests_controller.rb b/app/controllers/partners/family_requests_controller.rb index cf3d3b7860..efa0f45eb3 100644 --- a/app/controllers/partners/family_requests_controller.rb +++ b/app/controllers/partners/family_requests_controller.rb @@ -30,7 +30,7 @@ def create { item_id: item_id, person_count: item_requested_children.size, children: item_requested_children } end create_service = Partners::FamilyRequestCreateService.new( - request_type: 2, + request_type: "child", partner_user_id: current_user.id, family_requests_attributes: family_requests_attributes, for_families: true diff --git a/app/controllers/partners/individuals_requests_controller.rb b/app/controllers/partners/individuals_requests_controller.rb index 6d1eef116e..015d88035e 100644 --- a/app/controllers/partners/individuals_requests_controller.rb +++ b/app/controllers/partners/individuals_requests_controller.rb @@ -10,7 +10,7 @@ def new def create create_service = Partners::FamilyRequestCreateService.new( - request_type: 1, + request_type: "individual", partner_user_id: current_user.id, comments: individuals_request_params[:comments], family_requests_attributes: individuals_request_params[:items_attributes]&.values diff --git a/app/controllers/partners/requests_controller.rb b/app/controllers/partners/requests_controller.rb index e04d534ba1..017f7cef82 100644 --- a/app/controllers/partners/requests_controller.rb +++ b/app/controllers/partners/requests_controller.rb @@ -20,7 +20,7 @@ def show def create create_service = Partners::RequestCreateService.new( - request_type: 0, + request_type: "quantity", partner_user_id: current_user.id, comments: partner_request_params[:comments], item_requests_attributes: partner_request_params[:item_requests_attributes]&.values || [] diff --git a/app/models/request.rb b/app/models/request.rb index a1007c67f0..96bafed332 100644 --- a/app/models/request.rb +++ b/app/models/request.rb @@ -7,7 +7,7 @@ # discard_reason :text # discarded_at :datetime # request_items :jsonb -# request_type :integer +# request_type :string # status :integer default("pending") # created_at :datetime not null # updated_at :datetime not null @@ -32,7 +32,7 @@ class Request < ApplicationRecord has_many :child_item_requests, through: :item_requests enum status: { pending: 0, started: 1, fulfilled: 2, discarded: 3 }, _prefix: true - enum request_type: { quantity: 0, individual: 1, child: 2 }, _prefix: true + enum request_type: %w[quantity individual child].map { |v| [v, v] }.to_h validates :distribution_id, uniqueness: true, allow_nil: true before_save :sanitize_items_data diff --git a/app/services/partners/family_request_create_service.rb b/app/services/partners/family_request_create_service.rb index 3433403136..e181d3e2f7 100644 --- a/app/services/partners/family_request_create_service.rb +++ b/app/services/partners/family_request_create_service.rb @@ -8,8 +8,7 @@ class FamilyRequestCreateService attr_reader :partner_user_id, :comments, :family_requests_attributes, :partner_request - def initialize(request_type:, partner_user_id:, family_requests_attributes:, comments: nil, for_families: false) - @request_type = request_type + def initialize(partner_user_id:, family_requests_attributes:, comments: nil, for_families: false) @partner_user_id = partner_user_id @comments = comments @family_requests_attributes = family_requests_attributes.presence || [] @@ -20,7 +19,6 @@ def call return self unless valid? request_create_svc = Partners::RequestCreateService.new( - request_type: @request_type.to_i, partner_user_id: partner_user_id, comments: comments, for_families: @for_families, diff --git a/app/services/partners/request_create_service.rb b/app/services/partners/request_create_service.rb index aa1ae1031f..1ad0270b59 100644 --- a/app/services/partners/request_create_service.rb +++ b/app/services/partners/request_create_service.rb @@ -4,8 +4,7 @@ class RequestCreateService attr_reader :partner_request - def initialize(request_type:, partner_user_id:, comments: nil, for_families: false, item_requests_attributes: [], additional_attrs: {}) - @request_type = request_type + def initialize(partner_user_id:, comments: nil, for_families: false, item_requests_attributes: [], additional_attrs: {}) @partner_user_id = partner_user_id @comments = comments @for_families = for_families @@ -15,7 +14,7 @@ def initialize(request_type:, partner_user_id:, comments: nil, for_families: fal def call @partner_request = ::Request.new( - request_type: @request_type.to_i, + request_type: request_type, partner_id: partner.id, organization_id: organization_id, comments: comments, @@ -103,5 +102,9 @@ def organization_id def partner @partner ||= ::User.find(partner_user_id).partner end + + def request_type + @for_families ? "child" : "individual" + end end end diff --git a/app/views/requests/_request_row.html.erb b/app/views/requests/_request_row.html.erb index 73d5d84d21..21fe51535e 100644 --- a/app/views/requests/_request_row.html.erb +++ b/app/views/requests/_request_row.html.erb @@ -13,7 +13,7 @@ <%= request_row.comments %> - <%= request_row&.request_type&.titleize %> + <%= request_row&.request_type&.first&.capitalize %> <%= render partial: "status", locals: {status: request_row.status} %> diff --git a/app/views/requests/show.html.erb b/app/views/requests/show.html.erb index 1058427f6e..9aadc88626 100644 --- a/app/views/requests/show.html.erb +++ b/app/views/requests/show.html.erb @@ -46,7 +46,7 @@ <%= @request.partner.name %> <%= @request.partner_user&.formatted_email %> - <%= render partial: "request_type", locals: {request_type: @request.request_type} %> + <%= @request.request_type&.first&.capitalize %> <%= render partial: "status", locals: {status: @request.status} %> <%= @request.comments || 'None' %> diff --git a/db/migrate/20240315190152_add_type_to_requests.rb b/db/migrate/20240315190152_add_type_to_requests.rb index a41b65e99a..335f3908bc 100644 --- a/db/migrate/20240315190152_add_type_to_requests.rb +++ b/db/migrate/20240315190152_add_type_to_requests.rb @@ -1,5 +1,5 @@ class AddTypeToRequests < ActiveRecord::Migration[7.0] def change - add_column :requests, :request_type, :integer + add_column :requests, :request_type, :string end end diff --git a/db/schema.rb b/db/schema.rb index d3d30aff5f..02e951fd97 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.0].define(version: 2024_03_15_190152) do +ActiveRecord::Schema[7.0].define(version: 2024_04_02_230156) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -735,7 +735,7 @@ t.datetime "discarded_at", precision: nil t.text "discard_reason" t.integer "partner_user_id" - t.integer "request_type" + t.string "request_type" t.index ["discarded_at"], name: "index_requests_on_discarded_at" t.index ["distribution_id"], name: "index_requests_on_distribution_id", unique: true t.index ["organization_id"], name: "index_requests_on_organization_id" @@ -845,7 +845,8 @@ end create_table "versions", force: :cascade do |t| - t.string "item_type", null: false + t.string "item_type" + t.string "{:null=>false}" t.bigint "item_id", null: false t.string "event", null: false t.string "whodunnit" diff --git a/spec/factories/requests.rb b/spec/factories/requests.rb index a4c1f8c2c1..aa3930c82d 100644 --- a/spec/factories/requests.rb +++ b/spec/factories/requests.rb @@ -7,7 +7,7 @@ # discard_reason :text # discarded_at :datetime # request_items :jsonb -# request_type :integer +# request_type :string # status :integer default("pending") # created_at :datetime not null # updated_at :datetime not null diff --git a/spec/models/request_spec.rb b/spec/models/request_spec.rb index 4062f58fc6..6d63cb98f6 100644 --- a/spec/models/request_spec.rb +++ b/spec/models/request_spec.rb @@ -7,7 +7,7 @@ # discard_reason :text # discarded_at :datetime # request_items :jsonb -# request_type :integer +# request_type :string # status :integer default("pending") # created_at :datetime not null # updated_at :datetime not null diff --git a/spec/services/partners/family_request_create_service_spec.rb b/spec/services/partners/family_request_create_service_spec.rb index 10d43135e6..095ac74a4c 100644 --- a/spec/services/partners/family_request_create_service_spec.rb +++ b/spec/services/partners/family_request_create_service_spec.rb @@ -5,7 +5,7 @@ subject { described_class.new(**args).call } let(:args) do { - request_type: 0, + request_type: "quantity", partner_user_id: partner_user.id, comments: comments, for_families: for_families, @@ -109,7 +109,7 @@ let(:fake_request_create_service) { instance_double(Partners::RequestCreateService, call: -> {}, errors: [], partner_request: -> {}) } before do - allow(Partners::RequestCreateService).to receive(:new).with(request_type: 0, partner_user_id: partner_user.id, comments: comments, for_families: false, item_requests_attributes: contain_exactly(*expected_item_request_attributes)).and_return(fake_request_create_service) + allow(Partners::RequestCreateService).to receive(:new).with(request_type: "quantity", partner_user_id: partner_user.id, comments: comments, for_families: false, item_requests_attributes: contain_exactly(*expected_item_request_attributes)).and_return(fake_request_create_service) end it 'should send the correct request payload to the Partners::RequestCreateService and call it' do diff --git a/spec/services/partners/request_create_service_spec.rb b/spec/services/partners/request_create_service_spec.rb index 7931a35b22..e622cf7a2a 100644 --- a/spec/services/partners/request_create_service_spec.rb +++ b/spec/services/partners/request_create_service_spec.rb @@ -5,7 +5,7 @@ subject { described_class.new(**args).call } let(:args) do { - request_type: 0, + request_type: "quantity", partner_user_id: partner_user.id, comments: comments, item_requests_attributes: item_requests_attributes From 41a0429a527f2727f2bb506fd4e2bf2050323607 Mon Sep 17 00:00:00 2001 From: nathan Date: Wed, 15 May 2024 12:58:33 -0600 Subject: [PATCH 28/33] Remove request_type from tests --- spec/services/partners/family_request_create_service_spec.rb | 3 +-- spec/services/partners/request_create_service_spec.rb | 1 - 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/spec/services/partners/family_request_create_service_spec.rb b/spec/services/partners/family_request_create_service_spec.rb index 095ac74a4c..964534af1e 100644 --- a/spec/services/partners/family_request_create_service_spec.rb +++ b/spec/services/partners/family_request_create_service_spec.rb @@ -5,7 +5,6 @@ subject { described_class.new(**args).call } let(:args) do { - request_type: "quantity", partner_user_id: partner_user.id, comments: comments, for_families: for_families, @@ -109,7 +108,7 @@ let(:fake_request_create_service) { instance_double(Partners::RequestCreateService, call: -> {}, errors: [], partner_request: -> {}) } before do - allow(Partners::RequestCreateService).to receive(:new).with(request_type: "quantity", partner_user_id: partner_user.id, comments: comments, for_families: false, item_requests_attributes: contain_exactly(*expected_item_request_attributes)).and_return(fake_request_create_service) + allow(Partners::RequestCreateService).to receive(:new).with(partner_user_id: partner_user.id, comments: comments, for_families: false, item_requests_attributes: contain_exactly(*expected_item_request_attributes)).and_return(fake_request_create_service) end it 'should send the correct request payload to the Partners::RequestCreateService and call it' do diff --git a/spec/services/partners/request_create_service_spec.rb b/spec/services/partners/request_create_service_spec.rb index 8fcd8ab7c1..f3f45bd254 100644 --- a/spec/services/partners/request_create_service_spec.rb +++ b/spec/services/partners/request_create_service_spec.rb @@ -5,7 +5,6 @@ subject { described_class.new(**args).call } let(:args) do { - request_type: "quantity", partner_user_id: partner_user.id, comments: comments, item_requests_attributes: item_requests_attributes From f46736ee5b568d4226517840a242c71f0df07419 Mon Sep 17 00:00:00 2001 From: nathan Date: Thu, 16 May 2024 08:09:14 -0600 Subject: [PATCH 29/33] Add request_type_label method --- app/models/request.rb | 4 ++++ app/views/requests/_request_row.html.erb | 2 +- spec/models/request_spec.rb | 10 ++++++++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/app/models/request.rb b/app/models/request.rb index 96bafed332..56959a0a10 100644 --- a/app/models/request.rb +++ b/app/models/request.rb @@ -60,6 +60,10 @@ def user_email partner_user_id ? User.find_by(id: partner_user_id).email : Partner.find_by(id: partner_id).email end + def request_type_label + request_type&.first&.capitalize + end + private def sanitize_items_data diff --git a/app/views/requests/_request_row.html.erb b/app/views/requests/_request_row.html.erb index 21fe51535e..f039847b87 100644 --- a/app/views/requests/_request_row.html.erb +++ b/app/views/requests/_request_row.html.erb @@ -13,7 +13,7 @@ <%= request_row.comments %> - <%= request_row&.request_type&.first&.capitalize %> + <%= request_row.request_type_label %> <%= render partial: "status", locals: {status: request_row.status} %> diff --git a/spec/models/request_spec.rb b/spec/models/request_spec.rb index 2a45f60eb6..f4a7ac8d05 100644 --- a/spec/models/request_spec.rb +++ b/spec/models/request_spec.rb @@ -57,6 +57,16 @@ end end + describe "request_type_label" do + let(:id_one) { create(:item).id } + let(:id_two) { create(:item).id } + let(:request) { create(:request, request_items: [{ item_id: id_one, quantity: 15 }, { item_id: id_two, quantity: 18 }], request_type: "individual") } + + it "returns the the first letter of the request_type capitalized" do + expect(request.request_type_label).to eq("I") + end + end + describe "versioning" do it { is_expected.to be_versioned } end From 656e71213973dc27232d16325cb65297bfe3a5a7 Mon Sep 17 00:00:00 2001 From: nathan Date: Thu, 16 May 2024 08:14:52 -0600 Subject: [PATCH 30/33] Undo changes to versions --- db/schema.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/db/schema.rb b/db/schema.rb index d4099a4916..05f4a7dcd2 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -849,8 +849,7 @@ end create_table "versions", force: :cascade do |t| - t.string "item_type" - t.string "{:null=>false}" + t.string "item_type", null: false t.bigint "item_id", null: false t.string "event", null: false t.string "whodunnit" From 3a0e8411723244dbef14b98ac505dea668d4c03b Mon Sep 17 00:00:00 2001 From: nathan Date: Thu, 16 May 2024 08:26:07 -0600 Subject: [PATCH 31/33] Add request_type_label method --- app/views/requests/show.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/requests/show.html.erb b/app/views/requests/show.html.erb index 9aadc88626..0ab1b19d58 100644 --- a/app/views/requests/show.html.erb +++ b/app/views/requests/show.html.erb @@ -46,7 +46,7 @@ <%= @request.partner.name %> <%= @request.partner_user&.formatted_email %> - <%= @request.request_type&.first&.capitalize %> + <%= @request.request_type_label %> <%= render partial: "status", locals: {status: @request.status} %> <%= @request.comments || 'None' %> From 389e6d9a7d037370c8872bea52831d9c91592805 Mon Sep 17 00:00:00 2001 From: nathan Date: Fri, 17 May 2024 14:54:21 -0600 Subject: [PATCH 32/33] Add request_type to initialize --- app/services/partners/family_request_create_service.rb | 6 ++++-- app/services/partners/request_create_service.rb | 3 ++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/app/services/partners/family_request_create_service.rb b/app/services/partners/family_request_create_service.rb index e181d3e2f7..c3c284ec8f 100644 --- a/app/services/partners/family_request_create_service.rb +++ b/app/services/partners/family_request_create_service.rb @@ -6,9 +6,10 @@ module Partners class FamilyRequestCreateService include ServiceObjectErrorsMixin - attr_reader :partner_user_id, :comments, :family_requests_attributes, :partner_request + attr_reader :request_type, :partner_user_id, :comments, :family_requests_attributes, :partner_request - def initialize(partner_user_id:, family_requests_attributes:, comments: nil, for_families: false) + def initialize(request_type:, partner_user_id:, family_requests_attributes:, comments: nil, for_families: false) + @request_type = request_type @partner_user_id = partner_user_id @comments = comments @family_requests_attributes = family_requests_attributes.presence || [] @@ -19,6 +20,7 @@ def call return self unless valid? request_create_svc = Partners::RequestCreateService.new( + request_type: request_type, partner_user_id: partner_user_id, comments: comments, for_families: @for_families, diff --git a/app/services/partners/request_create_service.rb b/app/services/partners/request_create_service.rb index 1ad0270b59..225e897575 100644 --- a/app/services/partners/request_create_service.rb +++ b/app/services/partners/request_create_service.rb @@ -4,7 +4,8 @@ class RequestCreateService attr_reader :partner_request - def initialize(partner_user_id:, comments: nil, for_families: false, item_requests_attributes: [], additional_attrs: {}) + def initialize(request_type:, partner_user_id:, comments: nil, for_families: false, item_requests_attributes: [], additional_attrs: {}) + @request_type = request_type @partner_user_id = partner_user_id @comments = comments @for_families = for_families From 15ecc793be2caaff5f644b5baaeca1567d004172 Mon Sep 17 00:00:00 2001 From: nathan Date: Tue, 21 May 2024 10:49:16 -0600 Subject: [PATCH 33/33] Fix request_type bug --- .../partners/family_request_create_service.rb | 11 +++++++++-- app/services/partners/request_create_service.rb | 6 +----- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/app/services/partners/family_request_create_service.rb b/app/services/partners/family_request_create_service.rb index c3c284ec8f..b967d20003 100644 --- a/app/services/partners/family_request_create_service.rb +++ b/app/services/partners/family_request_create_service.rb @@ -6,10 +6,9 @@ module Partners class FamilyRequestCreateService include ServiceObjectErrorsMixin - attr_reader :request_type, :partner_user_id, :comments, :family_requests_attributes, :partner_request + attr_reader :partner_user_id, :comments, :family_requests_attributes, :partner_request def initialize(request_type:, partner_user_id:, family_requests_attributes:, comments: nil, for_families: false) - @request_type = request_type @partner_user_id = partner_user_id @comments = comments @family_requests_attributes = family_requests_attributes.presence || [] @@ -74,5 +73,13 @@ def convert_person_count_to_item_quantity(item_id:, person_count:) def included_items_by_id @included_items_by_id ||= Item.where(id: family_requests_attributes.pluck(:item_id)).index_by(&:id) end + + def request_type + if @for_families + "child" + else + "individual" + end + end end end diff --git a/app/services/partners/request_create_service.rb b/app/services/partners/request_create_service.rb index 225e897575..a3709b5c4e 100644 --- a/app/services/partners/request_create_service.rb +++ b/app/services/partners/request_create_service.rb @@ -2,7 +2,7 @@ module Partners class RequestCreateService include ServiceObjectErrorsMixin - attr_reader :partner_request + attr_reader :partner_request, :request_type def initialize(request_type:, partner_user_id:, comments: nil, for_families: false, item_requests_attributes: [], additional_attrs: {}) @request_type = request_type @@ -103,9 +103,5 @@ def organization_id def partner @partner ||= ::User.find(partner_user_id).partner end - - def request_type - @for_families ? "child" : "individual" - end end end