submission comments controller: allow changing comments
Allows changing the 'comment' attribute on a submission comment via the update action on the SubmissionCommentsController. In addition, adjusts the update action so that it returns string IDs when the request includes a header for canvas string IDs. refs GRADE-335 Test Plan: 1. Verify specs pass. A thorough test plan will be included in a follow-up commit to this one, where it will be possible to test this behavior via the UI. Change-Id: I0b8327e6911daff09e9150601685cfd0e30dab35 Reviewed-on: https://gerrit.instructure.com/129883 Tested-by: Jenkins Reviewed-by: Jeremy Neander <jneander@instructure.com> Reviewed-by: Shahbaz Javeed <sjaveed@instructure.com> QA-Review: Anju Reddy <areddy@instructure.com> Product-Review: Keith T. Garner <kgarner@instructure.com>
This commit is contained in:
parent
dc2e9d6790
commit
e9e98e9763
|
@ -25,7 +25,7 @@ class SubmissionCommentsController < ApplicationController
|
|||
submission_comment.reload unless submission_comment.update(submission_comment_params)
|
||||
|
||||
respond_to do |format|
|
||||
format.json { render json: submission_comment }
|
||||
format.json { render json: submission_comment.as_json }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -43,6 +43,6 @@ class SubmissionCommentsController < ApplicationController
|
|||
private
|
||||
|
||||
def submission_comment_params
|
||||
params.require(:submission_comment).permit(:draft)
|
||||
params.require(:submission_comment).permit(:draft, :comment)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -49,8 +49,41 @@ describe SubmissionCommentsController do
|
|||
user_session(@the_teacher)
|
||||
end
|
||||
|
||||
it 'allows updating the status field' do
|
||||
expect { patch 'update', params: @test_params }.to change { SubmissionComment.draft.count }.by(-1)
|
||||
it "allows updating the comment" do
|
||||
updated_comment = "an updated comment!"
|
||||
patch(
|
||||
:update,
|
||||
params: @test_params.merge(submission_comment: { comment: updated_comment })
|
||||
)
|
||||
comment = JSON.parse(response.body).dig("submission_comment", "comment")
|
||||
expect(comment).to eq updated_comment
|
||||
end
|
||||
|
||||
it "sets the edited_at if the comment is updated" do
|
||||
updated_comment = "an updated comment!"
|
||||
patch(
|
||||
:update,
|
||||
params: @test_params.merge(submission_comment: { comment: updated_comment })
|
||||
)
|
||||
edited_at = JSON.parse(response.body).dig("submission_comment", "edited_at")
|
||||
expect(edited_at).to be_present
|
||||
end
|
||||
|
||||
it "returns strings for numeric values when passed the json+canvas-string-ids header" do
|
||||
request.headers["HTTP_ACCEPT"] = "application/json+canvas-string-ids"
|
||||
patch :update, params: @test_params
|
||||
id = JSON.parse(response.body).dig("submission_comment", "id")
|
||||
expect(id).to be_a String
|
||||
end
|
||||
|
||||
it "does not set the edited_at if the comment is not updated" do
|
||||
patch :update, params: @test_params
|
||||
edited_at = JSON.parse(response.body).dig("submission_comment", "edited_at")
|
||||
expect(edited_at).to be_nil
|
||||
end
|
||||
|
||||
it "allows updating the status field" do
|
||||
expect { patch "update", params: @test_params }.to change { SubmissionComment.draft.count }.by(-1)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue