Skip to content

Commit

Permalink
Merge pull request expertiza#2741 from expertiza/bugfix/reviews
Browse files Browse the repository at this point in the history
Update response.rb to fix teammate review
  • Loading branch information
ameyagv committed Feb 27, 2024
2 parents 28a27bc + afd824c commit a7466d8
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 6 deletions.
2 changes: 1 addition & 1 deletion app/controllers/response_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ def new
# So do the answers, otherwise the response object can't find the questionnaire when the user hasn't saved his new review and closed the window.
# A new response has to be created when there hasn't been any reviews done for the current round,
# or when there has been a submission after the most recent review in this round.
@response = @response.create_or_get_response(@map, @current_round)
@response = @response.create_or_get_response(@map, @current_round.to_i)
questions = sort_questions(@questionnaire.questions)
store_total_cake_score
init_answers(questions)
Expand Down
6 changes: 5 additions & 1 deletion app/helpers/response_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,11 @@ def set_content(new_response = false)
# The new response is created here so that the controller has access to it in the new method
# This response object is populated later in the new method
if new_response
@response = Response.create(map_id: @map.id, additional_comment: '', round: @current_round, is_submitted: 0)
#Sometimes the response is already created and the new controller is called again (page refresh)
@response = Response.where(map_id: @map.id, round: @current_round.to_i).order(updated_at: :desc).first
if @response.nil?
@response = Response.create(map_id: @map.id, additional_comment: '', round: @current_round.to_i, is_submitted: 0)
end
end
end
end
2 changes: 1 addition & 1 deletion app/models/response.rb
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def create_or_get_response(response_map, current_round)
most_recent_submission_by_reviewee = reviewee_team.most_recent_submission if reviewee_team

if response.nil? || (most_recent_submission_by_reviewee && most_recent_submission_by_reviewee.updated_at > response.updated_at)
response = Response.create(map_id: response_map.id, additional_comment: '', round: current_round, is_submitted: 0)
response = Response.create(map_id: response_map.id, additional_comment: '', round: current_round.to_i, is_submitted: 0)
end
response
end
Expand Down
2 changes: 1 addition & 1 deletion app/views/response/response.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@


<h2>Directions for the reviewer</h2>
<input type="checkbox" id="autosave_cbx" checked>
<input type="checkbox" id="autosave_cbx">
<label id="autosave_cbx_lbl" for="autosave_cbx"></label>
<div id="save_progress"></div>
<%= form_tag({ :action => @next_action }, :id => @modified_object, :class => "review_form") do %>
Expand Down
4 changes: 2 additions & 2 deletions spec/models/response_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@
new_response = double('Response')

allow(AssignmentTeam).to receive(:find_by).with(id: response_map.reviewee_id).and_return(team)
allow(Response).to receive(:create).with(map_id: response_map.id, additional_comment: '', round: '1', is_submitted: 0).and_return(new_response)
allow(Response).to receive(:create).with(map_id: response_map.id, additional_comment: '', round: 1, is_submitted: 0).and_return(new_response)
expect(response.create_or_get_response(response_map, '1')).to eq(new_response)
end

Expand All @@ -185,7 +185,7 @@
new_response = double('Response', order: {})
allow(Response).to receive(:where).with(map_id: response_map.id, round: 1).and_return(new_response)
allow(AssignmentTeam).to receive(:find_by).with(id: response_map.reviewee_id).and_return(team)
allow(Response).to receive(:create).with(map_id: response_map.id, additional_comment: '', round: '1', is_submitted: 0).and_return(new_response)
allow(Response).to receive(:create).with(map_id: response_map.id, additional_comment: '', round: 1, is_submitted: 0).and_return(new_response)
expect(response.create_or_get_response(response_map, '1')).to eq(new_response)
end
end
Expand Down

0 comments on commit a7466d8

Please sign in to comment.