From 85fb94ffc656a4eb06d2d7a992030bcf1ef5781c Mon Sep 17 00:00:00 2001 From: wy1 Date: Wed, 24 Jul 2024 14:10:03 +0100 Subject: [PATCH 1/8] change the comments count to include asset comment --- app/models/request.rb | 4 ++++ app/views/shared/_batch.html.erb | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/app/models/request.rb b/app/models/request.rb index 527819e33d..be213c97e3 100644 --- a/app/models/request.rb +++ b/app/models/request.rb @@ -563,6 +563,10 @@ def product_line def manifest_processed! end + def all_comments + comments.count + asset.comments.count + end + private def calculate_next_request_type_id diff --git a/app/views/shared/_batch.html.erb b/app/views/shared/_batch.html.erb index 4148773978..1c1ab652b4 100644 --- a/app/views/shared/_batch.html.erb +++ b/app/views/shared/_batch.html.erb @@ -55,8 +55,8 @@ <% end %> <%= request.state.humanize %> - - <%= link_to (pluralize request.comments.size, 'comment'), request_comments_url(request) %> + + <%= link_to (pluralize request.all_comments, 'comment'), request_comments_url(request) %> <% end -%> From 2a0f5b36942bbf8fe0079b19c33ccf72a2d405fd Mon Sep 17 00:00:00 2001 From: wy1 Date: Fri, 26 Jul 2024 10:02:17 +0100 Subject: [PATCH 2/8] include the labware comments --- app/models/request.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/request.rb b/app/models/request.rb index be213c97e3..6343d8f2a2 100644 --- a/app/models/request.rb +++ b/app/models/request.rb @@ -564,7 +564,7 @@ def manifest_processed! end def all_comments - comments.count + asset.comments.count + comments.size + asset.comments.size + asset.labware.comments.size end private From 174c98b7a32ddbe8dba667fc27462e903103dd6d Mon Sep 17 00:00:00 2001 From: wy1 Date: Fri, 26 Jul 2024 10:12:54 +0100 Subject: [PATCH 3/8] fix the linting issue --- 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 6343d8f2a2..2297ad1fd8 100644 --- a/app/models/request.rb +++ b/app/models/request.rb @@ -564,8 +564,8 @@ def manifest_processed! end def all_comments - comments.size + asset.comments.size + asset.labware.comments.size - end + comments.size + asset.comments.size + asset.labware.comments.size + end private From e3b1dddc1e0fd738903036210b08f31673d7c516 Mon Sep 17 00:00:00 2001 From: wy1 Date: Mon, 29 Jul 2024 09:24:02 +0100 Subject: [PATCH 4/8] change the way to get request all comments --- app/models/request.rb | 5 +++-- app/views/shared/_batch.html.erb | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/app/models/request.rb b/app/models/request.rb index 2297ad1fd8..01ce817442 100644 --- a/app/models/request.rb +++ b/app/models/request.rb @@ -563,8 +563,9 @@ def product_line def manifest_processed! end - def all_comments - comments.size + asset.comments.size + asset.labware.comments.size + def self.get_all_comments(request) + counts = Comment.counts_for_requests([request]) + return counts[request.id] end private diff --git a/app/views/shared/_batch.html.erb b/app/views/shared/_batch.html.erb index 1c1ab652b4..250c2f16a2 100644 --- a/app/views/shared/_batch.html.erb +++ b/app/views/shared/_batch.html.erb @@ -56,7 +56,7 @@ <%= request.state.humanize %> - <%= link_to (pluralize request.all_comments, 'comment'), request_comments_url(request) %> + <%= link_to (pluralize Request.get_all_comments(request), 'comment'), request_comments_url(request) %> <% end -%> From db3e399d8a5b54dadcac02192909410efcaee138 Mon Sep 17 00:00:00 2001 From: wy1 Date: Mon, 29 Jul 2024 10:53:02 +0100 Subject: [PATCH 5/8] fix the format --- app/models/request.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/request.rb b/app/models/request.rb index 01ce817442..b5e3cff493 100644 --- a/app/models/request.rb +++ b/app/models/request.rb @@ -565,7 +565,7 @@ def manifest_processed! def self.get_all_comments(request) counts = Comment.counts_for_requests([request]) - return counts[request.id] + counts[request.id] end private From d09a0eb0fb1d00a1546fd270ba794cc75f1c13d2 Mon Sep 17 00:00:00 2001 From: wy1 Date: Tue, 30 Jul 2024 15:30:30 +0100 Subject: [PATCH 6/8] add test on get_all_comments --- spec/models/request_spec.rb | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/spec/models/request_spec.rb b/spec/models/request_spec.rb index 782bdaf7d5..81886ed366 100644 --- a/spec/models/request_spec.rb +++ b/spec/models/request_spec.rb @@ -494,4 +494,21 @@ expect(subject[request_type2].started).to eq(1) end end + + describe '.get_all_comments' do + let(:labware) { create :labware } + let(:receptacle) { create :receptacle, labware: labware } + let(:request) { create :request, asset: receptacle } + + before do + create :comment, commentable: labware, description: 'comment on labware' + create :comment, commentable: receptacle, description: 'comment on receptacle' + create :comment, commentable: request, description: 'first comment on request' + create :comment, commentable: request, description: 'second comment on request' + end + + it 'returns all of the comments including associated labware, receptacle and request itself' do + expect(described_class.get_all_comments(request)).to eq(4) + end + end end From f4e358c3475b33c7fcc965f420d966a13f1ad809 Mon Sep 17 00:00:00 2001 From: wy1 Date: Tue, 30 Jul 2024 16:16:25 +0100 Subject: [PATCH 7/8] fix the request page comment count --- 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 e13488be63..a16b61cb8d 100644 --- a/app/views/requests/show.html.erb +++ b/app/views/requests/show.html.erb @@ -1,7 +1,7 @@ <% add :about, "This page displays details of requests" %> <% add :menu, "View event history" => history_request_path(@request) -%> -<% add :menu, (pluralize @request.comments.size, "comment") => request_comments_path(@request) -%> +<% add :menu, (pluralize Request.get_all_comments(@request), "comment") => request_comments_path(@request) -%> <% if can?(:cancel, @request) && @request.try(:may_cancel_before_started?) %> <% add :menu, { "Cancel" => cancel_request_url(@request) }, { confirm: "Are you sure you want to cancel this request?" } -%> From 1b3075c47806775c6727c7e50c2a645f536e9555 Mon Sep 17 00:00:00 2001 From: wy1 Date: Wed, 31 Jul 2024 13:20:51 +0100 Subject: [PATCH 8/8] minor change in test to accomplish the convention --- spec/models/request_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/models/request_spec.rb b/spec/models/request_spec.rb index 81886ed366..03c05f2c55 100644 --- a/spec/models/request_spec.rb +++ b/spec/models/request_spec.rb @@ -495,7 +495,7 @@ end end - describe '.get_all_comments' do + describe '#get_all_comments' do let(:labware) { create :labware } let(:receptacle) { create :receptacle, labware: labware } let(:request) { create :request, asset: receptacle }