Merge pull request #2876 from jbivins/2354-empty-post-page-redirect-3
Go to root page if deleting post from the show page
This commit is contained in:
commit
0a49cfd866
2 changed files with 34 additions and 0 deletions
|
|
@ -27,6 +27,7 @@ app.views.Post = app.views.StreamObject.extend({
|
|||
$(this.el).attr("id", this.model.get("guid"));
|
||||
|
||||
this.model.bind('remove', this.remove, this);
|
||||
this.model.bind('destroy', this.destroy, this);
|
||||
|
||||
//subviews
|
||||
this.commentStreamView = new app.views.CommentStream({ model : this.model});
|
||||
|
|
@ -116,5 +117,15 @@ app.views.Post = app.views.StreamObject.extend({
|
|||
|
||||
authorIsNotCurrentUser : function() {
|
||||
return this.model.get("author").id != (!!app.user() && app.user().id)
|
||||
},
|
||||
|
||||
isOnShowPage : function() {
|
||||
return (!this.model.collection) && (this.model.url() == document.location.pathname);
|
||||
},
|
||||
|
||||
destroy : function() {
|
||||
if (this.isOnShowPage()) {
|
||||
document.location.replace(Backbone.history.options.root);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
|
|||
|
|
@ -96,5 +96,28 @@ describe("app.views.Post", function(){
|
|||
});
|
||||
})
|
||||
})
|
||||
|
||||
context("user views their own post", function(){
|
||||
beforeEach(function(){
|
||||
this.statusMessage.set({ author: {
|
||||
id : app.user().id
|
||||
}});
|
||||
this.view = new app.views.Post({model : this.statusMessage}).render();
|
||||
})
|
||||
|
||||
it("contains remove post", function(){
|
||||
expect(this.view.$(".remove_post")).toExist();
|
||||
})
|
||||
|
||||
it("destroys the view when they delete a their post from the show page", function(){
|
||||
spyOn(window, "confirm").andReturn(true);
|
||||
|
||||
this.view.$(".remove_post").click();
|
||||
|
||||
expect(window.confirm).toHaveBeenCalled();
|
||||
expect(this.view).not.toExist();
|
||||
})
|
||||
})
|
||||
|
||||
})
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in a new issue