always expose submission.posted_at to the api

fixes GRADE-2416

test plan:
 - specs pass

Change-Id: I56536b659c23542e74e21493c0f099909880ee18
Reviewed-on: https://gerrit.instructure.com/208350
Tested-by: Jenkins
Reviewed-by: Derek Bender <djbender@instructure.com>
Reviewed-by: Jeremy Neander <jneander@instructure.com>
QA-Review: Keith Garner <kgarner@instructure.com>
Product-Review: Keith Garner <kgarner@instructure.com>
This commit is contained in:
Keith T. Garner 2019-09-05 14:21:41 -05:00 committed by Keith Garner
parent 099cd4bd05
commit e0d26acb19
5 changed files with 17 additions and 4 deletions

View File

@ -119,7 +119,7 @@ module Api::V1::Submission
SUBMISSION_JSON_FIELDS = %w(id user_id url score grade excused attempt submission_type submitted_at body
assignment_id graded_at grade_matches_current_submission grader_id workflow_state late_policy_status
points_deducted grading_period_id cached_due_date extra_attempts).freeze
points_deducted grading_period_id cached_due_date extra_attempts posted_at).freeze
SUBMISSION_JSON_METHODS = %w(late missing seconds_late entered_grade entered_score).freeze
SUBMISSION_OTHER_FIELDS = %w(attachments discussion_entries).freeze
@ -128,7 +128,6 @@ module Api::V1::Submission
includes = Array.wrap(params[:include])
json_fields = SUBMISSION_JSON_FIELDS
json_fields += ['posted_at'] if context.post_policies_enabled?
json_methods = SUBMISSION_JSON_METHODS.dup # dup because AR#to_json modifies the :methods param in-place
other_fields = SUBMISSION_OTHER_FIELDS

View File

@ -4961,6 +4961,7 @@ describe AssignmentsApiController, type: :request do
"grading_period_id" => @submission.grading_period_id,
"grade_matches_current_submission" => true,
"graded_at" => nil,
"posted_at" => nil,
"grader_id" => @teacher.id,
"id" => @submission.id,
"score" => 99.0,
@ -5000,6 +5001,7 @@ describe AssignmentsApiController, type: :request do
"grading_period_id" => @submission.grading_period_id,
"grade_matches_current_submission" => true,
"graded_at" => nil,
"posted_at" => nil,
"grader_id" => @teacher.id,
"id" => @submission.id,
"score" => 99.0,

View File

@ -402,6 +402,7 @@ describe UsersController, type: :request do
'excused' => false,
'grader_id' => @teacher.id,
'graded_at' => @sub.graded_at.as_json,
'posted_at' => @sub.posted_at.as_json,
'score' => 12.0,
'entered_score' => 12.0,
'html_url' => "http://www.example.com/courses/#{@course.id}/assignments/#{@assignment.id}/submissions/#{@user.id}",
@ -531,6 +532,7 @@ describe UsersController, type: :request do
'excused' => false,
'grader_id' => @teacher.id,
'graded_at' => nil,
'posted_at' => nil,
'score' => nil,
'entered_score' => nil,
'html_url' => "http://www.example.com/courses/#{@course.id}/assignments/#{@assignment.id}/submissions/#{@user.id}",

View File

@ -900,6 +900,7 @@ describe 'Submissions API', type: :request do
"excused" => sub1.excused,
"grader_id"=>@teacher.id,
"graded_at"=>sub1.graded_at.as_json,
"posted_at"=>sub1.posted_at.as_json,
"body"=>"test!",
"assignment_id" => a1.id,
"cached_due_date" => nil,
@ -1081,6 +1082,7 @@ describe 'Submissions API', type: :request do
"excused" => sub1.excused,
"grader_id"=>@teacher.id,
"graded_at"=>sub1.graded_at.as_json,
"posted_at"=>sub1.posted_at.as_json,
"body"=>"test!",
"assignment_id" => a1.id,
"submitted_at"=>"1970-01-01T03:00:00Z",
@ -1122,6 +1124,7 @@ describe 'Submissions API', type: :request do
"excused" => nil,
"grader_id"=>nil,
"graded_at"=>nil,
"posted_at"=>nil,
"body"=>"test!",
"assignment_id" => a1.id,
"submitted_at"=>"1970-01-01T01:00:00Z",
@ -1148,6 +1151,7 @@ describe 'Submissions API', type: :request do
"excused" => nil,
"grader_id"=>nil,
"graded_at"=>nil,
"posted_at"=>nil,
"assignment_id" => a1.id,
"media_comment" =>
{ "media_type"=>"video",
@ -1180,6 +1184,7 @@ describe 'Submissions API', type: :request do
"excused" => false,
"grader_id"=>@teacher.id,
"graded_at"=>sub1.graded_at.as_json,
"posted_at"=>sub1.posted_at.as_json,
"assignment_id" => a1.id,
"media_comment" =>
{ "media_type"=>"video",
@ -1276,6 +1281,7 @@ describe 'Submissions API', type: :request do
"grader_id"=>@teacher.id,
"cached_due_date" => nil,
"graded_at"=>sub2.graded_at.as_json,
"posted_at"=>sub2.posted_at.as_json,
"assignment_id" => a1.id,
"body"=>nil,
"preview_url" => "http://www.example.com/courses/#{@course.id}/assignments/#{a1.id}/submissions/#{student2.id}?preview=1&version=1",
@ -1290,6 +1296,7 @@ describe 'Submissions API', type: :request do
"excused" => false,
"grader_id"=>@teacher.id,
"graded_at"=>sub2.graded_at.as_json,
"posted_at"=>sub2.posted_at.as_json,
"assignment_id" => a1.id,
"body"=>nil,
"submitted_at"=>"1970-01-01T04:00:00Z",

View File

@ -514,8 +514,11 @@ describe Api::V1::Submission do
expect(json.fetch('posted_at')).to eq posted_at
end
it "is not included if the owning course does not have post policies enabled" do
expect(json).not_to have_key('posted_at')
it "is included if the owning course does not have post policies enabled" do
posted_at = Time.zone.now
submission.update!(posted_at: posted_at)
expect(json.fetch('posted_at')).to eq posted_at
end
end
end