clear out stale submission fields on resubmit
fixes CNVS-5604 Test plan: * set up an assignment that takes online_url and online_text_entry submissions * make a online_url submission for an assignment * have the same student make an online_text_entry submission * the api response should now *not* include the url anymore Change-Id: I2389b0b3e8a565eed01f85ba2bed874c59585a2f Reviewed-on: https://gerrit.instructure.com/37796 Tested-by: Jenkins <jenkins@instructure.com> Reviewed-by: Simon Williams <simon@instructure.com> QA-Review: Anna Koalenz <akoalenz@instructure.com> Product-Review: Cameron Matheson <cameron@instructure.com>
This commit is contained in:
parent
70b38563df
commit
83cf8d9af9
|
@ -1130,11 +1130,16 @@ class Assignment < ActiveRecord::Base
|
|||
res
|
||||
end
|
||||
|
||||
SUBMIT_HOMEWORK_ATTRS = %w[body url attachments submission_type
|
||||
media_comment_id media_comment_type]
|
||||
ALLOWABLE_SUBMIT_HOMEWORK_OPTS = (SUBMIT_HOMEWORK_ATTRS +
|
||||
%w[comment group_comment]).to_set
|
||||
|
||||
def submit_homework(original_student, opts={})
|
||||
# Only allow a few fields to be submitted. Cannot submit the grade of a
|
||||
# homework assignment, for instance.
|
||||
opts.keys.each { |k|
|
||||
opts.delete(k) unless [:body, :url, :attachments, :submission_type, :comment, :media_comment_id, :media_comment_type, :group_comment].include?(k.to_sym)
|
||||
opts.delete(k) unless ALLOWABLE_SUBMIT_HOMEWORK_OPTS.include?(k.to_s)
|
||||
}
|
||||
raise "Student Required" unless original_student
|
||||
comment = opts.delete(:comment)
|
||||
|
@ -1155,6 +1160,11 @@ class Assignment < ActiveRecord::Base
|
|||
end
|
||||
transaction do
|
||||
find_or_create_submissions(students) do |homework|
|
||||
# clear out attributes from prior submissions
|
||||
if opts[:submission_type].present?
|
||||
SUBMIT_HOMEWORK_ATTRS.each { |attr| homework[attr] = nil }
|
||||
end
|
||||
|
||||
student = homework.user
|
||||
homework.grade_matches_current_submission = homework.score ? false : true
|
||||
homework.attributes = opts.merge({
|
||||
|
|
|
@ -583,11 +583,6 @@ describe Assignment do
|
|||
s.versions.length.should eql(1)
|
||||
s2[0].state.should eql(:graded)
|
||||
end
|
||||
|
||||
it "should not mark as submitted if no submission" do
|
||||
s = @a.submit_homework(@user)
|
||||
s.workflow_state.should == "unsubmitted"
|
||||
end
|
||||
end
|
||||
|
||||
describe "interpret_grade" do
|
||||
|
@ -611,13 +606,47 @@ describe Assignment do
|
|||
end
|
||||
end
|
||||
|
||||
it "should create a new version for each submission" do
|
||||
setup_assignment_without_submission
|
||||
@a.submit_homework(@user)
|
||||
@a.submit_homework(@user)
|
||||
@a.submit_homework(@user)
|
||||
@a.reload
|
||||
@a.submissions.first.versions.length.should eql(3)
|
||||
describe '#submit_homework' do
|
||||
before(:once) do
|
||||
course_with_student(active_all: true)
|
||||
@a = @course.assignments.create! title: "blah",
|
||||
submission_types: "online_text_entry,online_url",
|
||||
points_possible: 10
|
||||
end
|
||||
|
||||
it "creates a new version for each submission" do
|
||||
setup_assignment_without_submission
|
||||
@a.submit_homework(@user)
|
||||
@a.submit_homework(@user)
|
||||
@a.submit_homework(@user)
|
||||
@a.reload
|
||||
@a.submissions.first.versions.length.should eql(3)
|
||||
end
|
||||
|
||||
it "doesn't mark as submitted if no submission" do
|
||||
s = @a.submit_homework(@user)
|
||||
s.workflow_state.should == "unsubmitted"
|
||||
end
|
||||
|
||||
it "clears out stale submission information" do
|
||||
s = @a.submit_homework(@user, submission_type: "online_url",
|
||||
url: "http://example.com")
|
||||
s.submission_type.should == "online_url"
|
||||
s.url.should == "http://example.com"
|
||||
|
||||
s2 = @a.submit_homework(@user, submission_type: "online_text_entry",
|
||||
body: "blah blah blah blah blah blah blah")
|
||||
s2.submission_type.should == "online_text_entry"
|
||||
s2.body.should == "blah blah blah blah blah blah blah"
|
||||
s2.url.should be_nil
|
||||
s2.workflow_state.should == "submitted"
|
||||
|
||||
# comments shouldn't clear out submission data
|
||||
s3 = @a.submit_homework(@user, comment: "BLAH BLAH")
|
||||
s3.body.should == "blah blah blah blah blah blah blah"
|
||||
s3.submission_comments.first.comment.should == "BLAH BLAH"
|
||||
s3.submission_type.should == "online_text_entry"
|
||||
end
|
||||
end
|
||||
|
||||
describe "muting" do
|
||||
|
|
Loading…
Reference in New Issue