Skip to content

Commit

Permalink
Merge pull request #4235 from sanger/4107-y24-077-comments-not-fully-…
Browse files Browse the repository at this point in the history
…displayed

Fix the request comments count
  • Loading branch information
wendyyang authored Aug 1, 2024
2 parents 598aa9a + 1b3075c commit c57a789
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 3 deletions.
5 changes: 5 additions & 0 deletions app/models/request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,11 @@ def product_line
def manifest_processed!
end

def self.get_all_comments(request)
counts = Comment.counts_for_requests([request])
counts[request.id]
end

private

def calculate_next_request_type_id
Expand Down
2 changes: 1 addition & 1 deletion app/views/requests/show.html.erb
Original file line number Diff line number Diff line change
@@ -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?" } -%>
Expand Down
4 changes: 2 additions & 2 deletions app/views/shared/_batch.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@
<% end %>

<td><%= request.state.humanize %></td>

<td><%= link_to (pluralize request.comments.size, 'comment'), request_comments_url(request) %></td>
<td><%= link_to (pluralize Request.get_all_comments(request), 'comment'), request_comments_url(request) %></td>

</tr>
<% end -%>
Expand Down
17 changes: 17 additions & 0 deletions spec/models/request_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit c57a789

Please sign in to comment.