Merge pull request #6445 from MatMoore/forum_vote_race_condition
Vote buttons should be disabled while in use
This commit is contained in:
1
AUTHORS
1
AUTHORS
@@ -195,3 +195,4 @@ Dino Cikatić <dcikatic@edx.org>
|
||||
Davorin Šego <dsego@edx.org>
|
||||
Marko Jevtić <mjevtic@edx.org>
|
||||
Ahsan Ulhaq <ahsan@edx.org>
|
||||
Mat Moore <mat@mooresoftware.co.uk>
|
||||
|
||||
@@ -25,3 +25,24 @@ describe 'DiscussionUtil', ->
|
||||
# if the ajax call ends in failure, the model state should be reverted
|
||||
deferred.reject()
|
||||
expect(model.attributes).toEqual({hello: false, number: 42})
|
||||
|
||||
it "rolls back the changes if the associated element is disabled", ->
|
||||
spyOn(DiscussionUtil, "safeAjax").andCallThrough()
|
||||
|
||||
model = new Backbone.Model({hello: false, number: 42})
|
||||
updates = {hello: "world"}
|
||||
|
||||
# This is the element that is disabled/enabled while the ajax request is
|
||||
# in progress
|
||||
$elem = jasmine.createSpyObj('$elem', ['attr'])
|
||||
$elem.attr.andReturn(true)
|
||||
|
||||
res = DiscussionUtil.updateWithUndo(model, updates, {foo: "bar", $elem:$elem}, "error message")
|
||||
|
||||
expect($elem.attr).toHaveBeenCalledWith("disabled")
|
||||
expect(DiscussionUtil.safeAjax).toHaveBeenCalled()
|
||||
expect(model.attributes).toEqual({hello: false, number: 42})
|
||||
|
||||
failed = false
|
||||
res.fail(() => failed = true)
|
||||
expect(failed).toBe(true);
|
||||
|
||||
@@ -134,8 +134,12 @@ class @DiscussionUtil
|
||||
|
||||
@safeAjax: (params) ->
|
||||
$elem = params.$elem
|
||||
|
||||
if $elem and $elem.attr("disabled")
|
||||
return
|
||||
deferred = $.Deferred()
|
||||
deferred.reject()
|
||||
return deferred.promise()
|
||||
|
||||
params["url"] = URI(params["url"]).addSearch ajax: 1
|
||||
params["beforeSend"] = ->
|
||||
if $elem
|
||||
|
||||
@@ -127,7 +127,7 @@ if Backbone?
|
||||
$loading: elem
|
||||
takeFocus: true
|
||||
complete: =>
|
||||
@responseRequest = null
|
||||
@responsesRequest = null
|
||||
success: (data, textStatus, xhr) =>
|
||||
Content.loadContentInfos(data['annotated_content_info'])
|
||||
if @isQuestion()
|
||||
|
||||
Reference in New Issue
Block a user