Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the request comments count #4235

Merged
merged 8 commits into from
Aug 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 manifest_processed!
end

def self.get_all_comments(request)
dasunpubudumal marked this conversation as resolved.
Show resolved Hide resolved
counts = Comment.counts_for_requests([request])
counts[request.id]
end

Check warning on line 569 in app/models/request.rb

View check run for this annotation

Codecov / codecov/patch

app/models/request.rb#L566-L569

Added lines #L566 - L569 were not covered by tests
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Handy that this counts_for_requests method existed already! Looks like that's used for a similar link on the Pipeline inbox page, e.g. here - https://training.sequencescape.psd.sanger.ac.uk/pipelines/51


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
Loading