Commit 3ed2fcbb by cahrens

Parse floats to ints in CourseGrader model.

Fixes STUD-826.
parent 30dc4418
...@@ -141,6 +141,7 @@ define([ ...@@ -141,6 +141,7 @@ define([
"coffee/spec/models/course_spec", "coffee/spec/models/metadata_spec", "coffee/spec/models/course_spec", "coffee/spec/models/metadata_spec",
"coffee/spec/models/module_spec", "coffee/spec/models/section_spec", "coffee/spec/models/module_spec", "coffee/spec/models/section_spec",
"coffee/spec/models/settings_course_grader_spec",
"coffee/spec/models/settings_grading_spec", "coffee/spec/models/textbook_spec", "coffee/spec/models/settings_grading_spec", "coffee/spec/models/textbook_spec",
"coffee/spec/models/upload_spec", "coffee/spec/models/upload_spec",
......
define ["js/models/settings/course_grader"], (CourseGrader) ->
describe "CourseGraderModel", ->
describe "parseWeight", ->
it "converts a float to an integer", ->
model = new CourseGrader({weight: 7.0001, min_count: 3.67, drop_count: 1.88}, {parse:true})
expect(model.get('weight')).toBe(7)
expect(model.get('min_count')).toBe(3)
expect(model.get('drop_count')).toBe(1)
it "converts a string to an integer", ->
model = new CourseGrader({weight: '7.0001', min_count: '3.67', drop_count: '1.88'}, {parse:true})
expect(model.get('weight')).toBe(7)
expect(model.get('min_count')).toBe(3)
expect(model.get('drop_count')).toBe(1)
it "does a no-op for integers", ->
model = new CourseGrader({weight: 7, min_count: 3, drop_count: 1}, {parse:true})
expect(model.get('weight')).toBe(7)
expect(model.get('min_count')).toBe(3)
expect(model.get('drop_count')).toBe(1)
...@@ -10,13 +10,13 @@ var CourseGrader = Backbone.Model.extend({ ...@@ -10,13 +10,13 @@ var CourseGrader = Backbone.Model.extend({
}, },
parse : function(attrs) { parse : function(attrs) {
if (attrs['weight']) { if (attrs['weight']) {
if (!_.isNumber(attrs.weight)) attrs.weight = parseInt(attrs.weight, 10); attrs.weight = parseInt(attrs.weight, 10);
} }
if (attrs['min_count']) { if (attrs['min_count']) {
if (!_.isNumber(attrs.min_count)) attrs.min_count = parseInt(attrs.min_count, 10); attrs.min_count = parseInt(attrs.min_count, 10);
} }
if (attrs['drop_count']) { if (attrs['drop_count']) {
if (!_.isNumber(attrs.drop_count)) attrs.drop_count = parseInt(attrs.drop_count, 10); attrs.drop_count = parseInt(attrs.drop_count, 10);
} }
return attrs; return attrs;
}, },
......
...@@ -20,7 +20,7 @@ var CourseGradingPolicy = Backbone.Model.extend({ ...@@ -20,7 +20,7 @@ var CourseGradingPolicy = Backbone.Model.extend({
graderCollection.reset(attributes.graders); graderCollection.reset(attributes.graders);
} }
else { else {
graderCollection = new CourseGraderCollection(attributes.graders); graderCollection = new CourseGraderCollection(attributes.graders, {parse:true});
graderCollection.course_location = attributes['course_location'] || this.get('course_location'); graderCollection.course_location = attributes['course_location'] || this.get('course_location');
} }
attributes.graders = graderCollection; attributes.graders = graderCollection;
......
...@@ -114,9 +114,8 @@ require(["domReady!", "jquery", "js/models/location", "js/views/overview_assignm ...@@ -114,9 +114,8 @@ require(["domReady!", "jquery", "js/models/location", "js/views/overview_assignm
// I believe that current (New Section/New Subsection) cause full page reloads which means these aren't needed globally // I believe that current (New Section/New Subsection) cause full page reloads which means these aren't needed globally
// but we really should change that behavior. // but we really should change that behavior.
if (!window.graderTypes) { if (!window.graderTypes) {
window.graderTypes = new CourseGraderCollection(); window.graderTypes = new CourseGraderCollection(${course_graders|n}, {parse:true});
window.graderTypes.course_location = new Location('${parent_location}'); window.graderTypes.course_location = new Location('${parent_location}');
window.graderTypes.reset(${course_graders|n});
} }
$(".gradable-status").each(function(index, ele) { $(".gradable-status").each(function(index, ele) {
......
...@@ -25,9 +25,8 @@ require(["domReady!", "jquery", "js/models/location", "js/models/section", "js/v ...@@ -25,9 +25,8 @@ require(["domReady!", "jquery", "js/models/location", "js/models/section", "js/v
// I believe that current (New Section/New Subsection) cause full page reloads which means these aren't needed globally // I believe that current (New Section/New Subsection) cause full page reloads which means these aren't needed globally
// but we really should change that behavior. // but we really should change that behavior.
if (!window.graderTypes) { if (!window.graderTypes) {
window.graderTypes = new CourseGraderCollection(); window.graderTypes = new CourseGraderCollection(${course_graders|n}, {parse:true});
window.graderTypes.course_location = new Location('${parent_location}'); window.graderTypes.course_location = new Location('${parent_location}');
window.graderTypes.reset(${course_graders|n});
} }
$(".gradable-status").each(function(index, ele) { $(".gradable-status").each(function(index, ele) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment