fix submitting comments on attempt 0 in a2
when submitted comments for attempt 0 (the case where we have no submissions) the attempt was reading as nil in the validation and failing to create the comment. Test Plan: * as a teacher, create an assignment * as a student in this assignment who has not yet submitted, navigate to the Comments tab * create a new comment on the assignment * it should successfully create the comment * comments for attempt 0 and attempt 1 should display together * on an assignment with one or more submissions, create a comment * it should successfully create the comment fixes COMMS-2174 Change-Id: If216a541aebf7db2ea7b6942a02d194113cd8e41 Reviewed-on: https://gerrit.instructure.com/199377 Reviewed-by: Steven Burnett <sburnett@instructure.com> QA-Review: Michelle Simmons <misimmons@instructure.com> Tested-by: Jenkins Product-Review: Ryan Norton <rnorton@instructure.com>
This commit is contained in:
parent
47a6893c20
commit
426b7b43b6
|
@ -49,7 +49,7 @@ class SubmissionComment < ActiveRecord::Base
|
|||
validates_length_of :comment, :minimum => 1, :allow_nil => true, :allow_blank => true
|
||||
validates_each :attempt do |record, attr, value|
|
||||
next if value.nil?
|
||||
if record.submission.attempt.nil? || value > record.submission.attempt
|
||||
if value > (record.submission.attempt || 0)
|
||||
record.errors.add(attr, 'attempt must not be larger than number of submission attempts')
|
||||
end
|
||||
end
|
||||
|
|
|
@ -648,6 +648,20 @@ This text has a http://www.google.com link in it...
|
|||
@comment4 = @submission.submission_comments.create!(valid_attributes.merge(attempt: nil))
|
||||
end
|
||||
|
||||
context 'when the submission attempt is nil' do
|
||||
before(:once) do
|
||||
@submission.update!(attempt: nil)
|
||||
end
|
||||
|
||||
it 'raises an error if the submission_comment attempt is greater than 0' do
|
||||
expect { @submission.submission_comments.create!(valid_attributes.merge(attempt: 1)) }.to raise_error(ActiveRecord::RecordInvalid)
|
||||
end
|
||||
|
||||
it 'does not raise an error if the submission_comment attempt is equal to 0' do
|
||||
expect { @submission.submission_comments.create!(valid_attributes.merge(attempt: 0)) }.not_to raise_error
|
||||
end
|
||||
end
|
||||
|
||||
it 'can limit comments to the specific attempt' do
|
||||
expect(@submission.submission_comments.where(attempt: 1)).to eq [@comment1]
|
||||
end
|
||||
|
@ -660,14 +674,14 @@ This text has a http://www.google.com link in it...
|
|||
expect(@submission.submission_comments.where(attempt: nil)).to eq [@comment4]
|
||||
end
|
||||
|
||||
it 'cannot be present? if submisssion#attempt is nil' do
|
||||
it 'cannot be present? if submission#attempt is nil' do
|
||||
@submission.update_column(:attempt, nil) # bypass infer_values callback
|
||||
@comment1.reload
|
||||
@comment1.attempt = 2
|
||||
expect(@comment1).not_to be_valid
|
||||
end
|
||||
|
||||
it 'cannot be larger then submisssion#attempt' do
|
||||
it 'cannot be larger then submission#attempt' do
|
||||
@comment1.attempt = @submission.attempt + 1
|
||||
expect(@comment1).not_to be_valid
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue