add default points_possible for assignments via API

test plan:
* trying to use a blank string when creating or
updating an assignment's points_possible via the API
(or alternatively through the assignment group level
 add dialog on the assignments index)
should fallback to 0

closes #LA-135

Change-Id: I482b36462c7eb06b72fbe9a38e0fb847f603cbeb
Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/218554
Tested-by: Service Cloud Jenkins <svc.cloudjenkins@instructure.com>
Tested-by: Jenkins
Reviewed-by: Jeremy Stanley <jeremy@instructure.com>
QA-Review: Mysti Lilla <mysti@instructure.com>
Product-Review: James Williams <jamesw@instructure.com>
This commit is contained in:
James Williams 2019-11-25 11:22:47 -07:00
parent c72bf19e9d
commit 55a592a80b
2 changed files with 37 additions and 0 deletions

View File

@ -851,6 +851,12 @@ module Api::V1::Assignment
def prepare_assignment_create_or_update(assignment, assignment_params, user, context = assignment.context)
raise "needs strong params" unless assignment_params.is_a?(ActionController::Parameters)
if assignment_params[:points_possible].blank?
if assignment.new_record? || assignment_params.has_key?(:points_possible) # only change if they're deliberately updating to blank
assignment_params[:points_possible] = 0
end
end
unless assignment.new_record?
assignment.restore_attributes
old_assignment = assignment.clone

View File

@ -5253,6 +5253,37 @@ describe AssignmentsApiController, type: :request do
expect(update_grade_value).to be true
end
end
context "points possible defaulting" do
it "should assume 0 for a new assignment" do
course_with_teacher(:active_all => true)
json = api_create_assignment_in_course(@course, {'name' => 'some name'})
a = Assignment.find(json["id"])
expect(a.points_possible).to eq 0
end
it "should assume 0 for a new assignment even if set to blank" do
course_with_teacher(:active_all => true)
json = api_create_assignment_in_course(@course, {'name' => 'some name', 'points_possible' => ''})
a = Assignment.find(json["id"])
expect(a.points_possible).to eq 0
end
it "should not set to 0 if not included in params for update" do
course_with_teacher(:active_all => true)
a = @course.assignments.create!(:points_possible => 5)
json = api_update_assignment_call(@course, a, {'name' => 'some new name'})
expect(a.points_possible).to eq 5
expect(a.name).to eq 'some new name'
end
it "should set to 0 if included in params for update and blank" do
course_with_teacher(:active_all => true)
a = @course.assignments.create!(:points_possible => 5)
json = api_update_assignment_call(@course, a, {'points_possible' => ''})
expect(a.points_possible).to eq 0
end
end
end
def api_get_assignments_index_from_course(course, params = {})