diff --git a/public/javascripts/app/views/post_view.js b/public/javascripts/app/views/post_view.js index 0cf5de3a3..be6330683 100644 --- a/public/javascripts/app/views/post_view.js +++ b/public/javascripts/app/views/post_view.js @@ -119,10 +119,12 @@ app.views.Post = app.views.StreamObject.extend({ return this.model.get("author").id != (!!app.user() && app.user().id) }, - destroy : function() { - var posts_uri = new RegExp(this.model.collection.url + '\/[0-9]+$'); + isOnShowPage : function() { + return (!this.model.collection) && (this.model.url() == document.location.pathname); + }, - if ((this.model.collection.length == 1) && (posts_uri.test(document.location.pathname))) { + destroy : function() { + if (this.isOnShowPage()) { document.location.replace(Backbone.history.options.root); } } diff --git a/spec/javascripts/app/views/post_view_spec.js b/spec/javascripts/app/views/post_view_spec.js index 4ecb33569..9eb66d9a2 100644 --- a/spec/javascripts/app/views/post_view_spec.js +++ b/spec/javascripts/app/views/post_view_spec.js @@ -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(); + }) + }) + }) });