diff --git a/app/coffeescripts/views/assignments/AssignmentGroupListView.coffee b/app/coffeescripts/views/assignments/AssignmentGroupListView.coffee index 7252270ebfc..2a1bc1c9f04 100644 --- a/app/coffeescripts/views/assignments/AssignmentGroupListView.coffee +++ b/app/coffeescripts/views/assignments/AssignmentGroupListView.coffee @@ -60,6 +60,7 @@ define [ attachCollection: -> super @itemViewOptions = course: @course + @collection.on 'render', @render @collection.on 'add', @render @collection.on 'remove', @render @collection.on 'change:groupWeights', @render diff --git a/app/coffeescripts/views/assignments/CreateGroupView.coffee b/app/coffeescripts/views/assignments/CreateGroupView.coffee index 6c4d60fe930..f87d06a51e5 100644 --- a/app/coffeescripts/views/assignments/CreateGroupView.coffee +++ b/app/coffeescripts/views/assignments/CreateGroupView.coffee @@ -41,13 +41,16 @@ define [ onSaveSuccess: -> super - if @assignmentGroup # meaning we are editing - @model.collection.view.render() + # meaning we are editing + if @assignmentGroup + # trigger instead of calling render directly + @model.collection.trigger 'render', @model.collection else @assignmentGroups.add(@model) @model = new AssignmentGroup(assignments: []) - @render() + @render() + getFormData: -> data = super diff --git a/spec/coffeescripts/views/assignments/CreateGroupViewSpec.coffee b/spec/coffeescripts/views/assignments/CreateGroupViewSpec.coffee index bf0b133a2b1..ba8d4801403 100644 --- a/spec/coffeescripts/views/assignments/CreateGroupViewSpec.coffee +++ b/spec/coffeescripts/views/assignments/CreateGroupViewSpec.coffee @@ -17,10 +17,12 @@ define [ assignmentGroups = -> @groups = new AssignmentGroupCollection([group(), group()]) - createView = -> - view = new CreateGroupView + createView = (hasAssignmentGroup=true)-> + args = assignmentGroups: assignmentGroups() - assignmentGroup: @groups.first() + assignmentGroup: @groups.first() if hasAssignmentGroup + + view = new CreateGroupView(args) module 'CreateGroupView' @@ -59,3 +61,18 @@ define [ errors = view.validateFormData(data) ok errors equal _.keys(errors).length, 1 + + + test 'it should trigger a render event on save success when editing', -> + triggerSpy = sinon.spy(AssignmentGroupCollection::, 'trigger') + view = createView() + view.onSaveSuccess() + ok triggerSpy.calledWith 'render' + triggerSpy.restore() + + test 'it should call render on save success if adding an assignmentGroup', -> + view = createView(false) + renderStub = sinon.stub(view, 'render') + calls = renderStub.callCount + view.onSaveSuccess() + equal renderStub.callCount, calls + 1