Skip to content

Commit d498350

Browse files
committed
don't 404 for submission that was not created yet
Change-Id: I67dffd8f8fce13e3ac21f988e67f7e84d9eba4d0 Reviewed-on: https://gerrit.instructure.com/6090 Tested-by: Hudson <hudson@instructure.com> Reviewed-by: Brian Palmer <brianp@instructure.com>
1 parent 403bd09 commit d498350

2 files changed

Lines changed: 18 additions & 4 deletions

File tree

app/controllers/submissions_api_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ def for_students
132132
def show
133133
@assignment = @context.assignments.active.find(params[:assignment_id])
134134
@user = get_user_considering_section(params[:id])
135-
@submission = @assignment.submissions.find_by_user_id(@user.id) or raise ActiveRecord::RecordNotFound
135+
@submission = @assignment.submissions.find_or_initialize_by_user_id(@user.id) or raise ActiveRecord::RecordNotFound
136136
if authorized_action(@submission, @current_user, :read)
137137
includes = Array(params[:include])
138138
render :json => submission_json(@submission, @assignment, includes).to_json

spec/apis/v1/submissions_api_spec.rb

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,18 +36,32 @@ def submit_homework(assignment, student, opts = {:body => "test!"})
3636
sub
3737
end
3838

39-
it "should 404 if there is no submission" do
39+
it "should not 404 if there is no submission" do
4040
student = user(:active_all => true)
4141
course_with_teacher(:active_all => true)
4242
@course.enroll_student(student).accept!
4343
@assignment = @course.assignments.create!(:title => 'assignment1', :grading_type => 'points', :points_possible => 12)
44-
raw_api_call(:get,
44+
json = api_call(:get,
4545
"/api/v1/courses/#{@course.id}/assignments/#{@assignment.id}/submissions/#{student.id}.json",
4646
{ :controller => 'submissions_api', :action => 'show',
4747
:format => 'json', :course_id => @course.id.to_s,
4848
:assignment_id => @assignment.id.to_s, :id => student.id.to_s },
4949
{ :include => %w(submission_history submission_comments rubric_assessment) })
50-
response.status.should match /404/
50+
json.should == {
51+
"assignment_id" => @assignment.id,
52+
"preview_url" => "http://www.example.com/courses/#{@course.id}/assignments/#{@assignment.id}/submissions/#{student.id}?preview=1",
53+
"user_id"=>student.id,
54+
"grade"=>nil,
55+
"body"=>nil,
56+
"submitted_at"=>nil,
57+
"submission_history"=>[],
58+
"attempt"=>nil,
59+
"url"=>nil,
60+
"submission_type"=>nil,
61+
"submission_comments"=>[],
62+
"grade_matches_current_submission"=>nil,
63+
"score"=>nil
64+
}
5165
end
5266

5367
describe "using section ids" do

0 commit comments

Comments
 (0)