fix quiz_submission.quiz_points_possible
this column is copied from quiz.points_possible whenever the submission is updated, thus the type needs to match. test plan: confirm that quizzes with fractional points dislay the correct message when you go to edit fudge points on a submission. Change-Id: Ib3f2c920ac7392b3c4a4a92a273657fe8dfcbc43 Reviewed-on: https://gerrit.instructure.com/7111 Tested-by: Hudson <hudson@instructure.com> Reviewed-by: Brian Palmer <brianp@instructure.com>
This commit is contained in:
parent
5302be8782
commit
d1d6143ce7
|
@ -0,0 +1,9 @@
|
|||
class SubmissionPointsPossibleFixColumn < ActiveRecord::Migration
|
||||
def self.up
|
||||
change_column :quiz_submissions, :quiz_points_possible, :float
|
||||
end
|
||||
|
||||
def self.down
|
||||
change_column :quiz_submissions, :quiz_points_possible, :integer
|
||||
end
|
||||
end
|
|
@ -0,0 +1,23 @@
|
|||
class SubmissionPointsPossibleFixData < ActiveRecord::Migration
|
||||
def self.up
|
||||
case adapter_name
|
||||
when 'MySQL'
|
||||
execute <<-SQL
|
||||
UPDATE quiz_submissions, quizzes
|
||||
SET quiz_points_possible = points_possible
|
||||
WHERE quiz_id = quizzes.id AND quiz_points_possible <> points_possible AND (quiz_points_possible = CAST(points_possible AS SIGNED) OR quiz_points_possible = 2147483647)
|
||||
SQL
|
||||
when 'PostgreSQL'
|
||||
execute <<-SQL
|
||||
UPDATE quiz_submissions
|
||||
SET quiz_points_possible = points_possible
|
||||
FROM quizzes
|
||||
WHERE quiz_id = quizzes.id AND quiz_points_possible <> points_possible AND quiz_points_possible = CAST(points_possible AS INTEGER)
|
||||
SQL
|
||||
# no fix needed for sqlite
|
||||
end
|
||||
end
|
||||
|
||||
def self.down
|
||||
end
|
||||
end
|
|
@ -24,14 +24,26 @@ describe QuizSubmission do
|
|||
course
|
||||
@quiz = @course.quizzes.create!
|
||||
end
|
||||
|
||||
|
||||
it "should copy the quiz's points_possible whenever it's saved" do
|
||||
Quiz.update_all("points_possible = 1.1", "id = #{@quiz.id}")
|
||||
q = @quiz.quiz_submissions.create!
|
||||
q.reload.quiz_points_possible.should eql 1.1
|
||||
|
||||
Quiz.update_all("points_possible = 1.9", "id = #{@quiz.id}")
|
||||
q.reload.quiz_points_possible.should eql 1.1
|
||||
|
||||
q.save!
|
||||
q.reload.quiz_points_possible.should eql 1.9
|
||||
end
|
||||
|
||||
it "should not allow updating scores on an uncompleted submission" do
|
||||
q = @quiz.quiz_submissions.create!
|
||||
q.state.should eql(:untaken)
|
||||
res = q.update_scores rescue false
|
||||
res.should eql(false)
|
||||
end
|
||||
|
||||
|
||||
it "should allow updating scores on a completed version of a submission while the current version is in progress" do
|
||||
course_with_student(:active_all => true)
|
||||
@quiz = @course.quizzes.create!
|
||||
|
@ -39,14 +51,14 @@ describe QuizSubmission do
|
|||
qs.workflow_state = 'complete'
|
||||
qs.submission_data = [{ :points => 0, :text => "", :correct => "undefined", :question_id => -1 }]
|
||||
qs.with_versioning(true, &:save)
|
||||
|
||||
|
||||
qs = @quiz.generate_submission(@user)
|
||||
qs.submission_data = { "foo" => "bar" } # simulate k/v pairs we store for quizzes in progress
|
||||
qs.save
|
||||
lambda {qs.update_scores}.should raise_error
|
||||
lambda {qs.update_scores(:submission_version_number => 1) }.should_not raise_error
|
||||
end
|
||||
|
||||
|
||||
it "should not allowed grading on an already-graded submission" do
|
||||
q = @quiz.quiz_submissions.create!
|
||||
q.workflow_state = "complete"
|
||||
|
@ -64,13 +76,13 @@ describe QuizSubmission do
|
|||
end
|
||||
res.should eql(false)
|
||||
end
|
||||
|
||||
|
||||
it "should know if it is overdue" do
|
||||
now = Time.now
|
||||
q = @quiz.quiz_submissions.new
|
||||
q.end_at = now
|
||||
q.save!
|
||||
|
||||
|
||||
q.overdue?.should eql(false)
|
||||
q.end_at = now - (3 * 60)
|
||||
q.save!
|
||||
|
@ -82,7 +94,7 @@ describe QuizSubmission do
|
|||
q.overdue?.should eql(true)
|
||||
q.overdue?(true).should eql(true)
|
||||
end
|
||||
|
||||
|
||||
it "should calculate score based on quiz scoring policy" do
|
||||
q = @course.quizzes.create!(:scoring_policy => "keep_latest")
|
||||
s = q.quiz_submissions.new
|
||||
|
@ -92,13 +104,13 @@ describe QuizSubmission do
|
|||
s.with_versioning(true, &:save!)
|
||||
s.score.should eql(5.0)
|
||||
s.kept_score.should eql(5.0)
|
||||
|
||||
|
||||
s.score = 4.0
|
||||
s.attempt = 2
|
||||
s.with_versioning(true, &:save!)
|
||||
s.version_number.should eql(2)
|
||||
s.kept_score.should eql(4.0)
|
||||
|
||||
|
||||
q.update_attributes!(:scoring_policy => "keep_highest")
|
||||
s.reload
|
||||
s.score = 3.0
|
||||
|
@ -204,10 +216,10 @@ describe QuizSubmission do
|
|||
q.save!
|
||||
q.kept_score.should eql(5.0)
|
||||
s.reload
|
||||
|
||||
|
||||
s.score.should eql(5.0)
|
||||
end
|
||||
|
||||
|
||||
describe "learning outcomes" do
|
||||
it "should create learning outcome results when aligned to assessment questions" do
|
||||
course_with_student(:active_all => true)
|
||||
|
@ -240,7 +252,7 @@ describe QuizSubmission do
|
|||
@results.last.associated_asset.should eql(@q2.assessment_question)
|
||||
@results.last.mastery.should eql(false)
|
||||
end
|
||||
|
||||
|
||||
it "should update learning outcome results when aligned to assessment questions" do
|
||||
course_with_student(:active_all => true)
|
||||
@quiz = @course.quizzes.create!(:title => "new quiz", :shuffle_answers => true)
|
||||
|
@ -271,7 +283,7 @@ describe QuizSubmission do
|
|||
@results.first.mastery.should eql(true)
|
||||
@results.last.associated_asset.should eql(@q2.assessment_question)
|
||||
@results.last.mastery.should eql(false)
|
||||
|
||||
|
||||
@sub = @quiz.generate_submission(@user)
|
||||
@sub.attempt.should eql(2)
|
||||
@sub.submission_data = {}
|
||||
|
@ -329,7 +341,7 @@ describe QuizSubmission do
|
|||
user_answer[:correct].should be_false
|
||||
user_answer[:points].should == 0
|
||||
end
|
||||
|
||||
|
||||
it "should not escape user responses in fimb questions" do
|
||||
course_with_student(:active_all => true)
|
||||
q = {:neutral_comments=>"",
|
||||
|
|
Loading…
Reference in New Issue