Created
February 20, 2015 12:08
-
-
Save Raven24/fc470f2e55104af165c8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//# app/assets/javascripts/app/models/post/interactions.js | |
reshare : function(){ | |
var interactions = this | |
, reshare = this.post.reshare() | |
, flash = new Diaspora.Widgets.FlashMessages(); | |
reshare.save() | |
.done(function(){ | |
flash.render({ | |
success: true, | |
notice: Diaspora.I18n.t("reshares.successful") | |
}); | |
interactions.reshares.add(reshare); | |
if( app.stream ) app.stream.addNow(reshare); | |
interactions.trigger("change"); | |
}) | |
.fail(function(){ | |
flash.render({ | |
success: false, | |
notice: Diaspora.I18n.t("reshares.duplicate") | |
}); | |
}); | |
app.instrument("track", "Reshare"); | |
}, | |
//# spec/javascripts/app/models/post/interactions_spec.js | |
describe("reshare", function() { | |
var ajax_success = { status: 200, responseText: [] }; | |
beforeEach(function(){ | |
this.reshare = this.interactions.post.reshare(); | |
}); | |
it("triggers a change on the model", function() { | |
spyOn(this.interactions, "trigger"); | |
this.interactions.reshare(); | |
jasmine.Ajax.requests.mostRecent().respondWith(ajax_success); | |
expect(this.interactions.trigger).toHaveBeenCalledWith("change"); | |
}); | |
it("adds the reshare to the stream", function() { | |
app.stream = { addNow: $.noop }; | |
spyOn(app.stream, "addNow"); | |
this.interactions.reshare(); | |
jasmine.Ajax.requests.mostRecent().respondWith(ajax_success); | |
expect(app.stream.addNow).toHaveBeenCalledWith(this.reshare); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment