Add test case for when a user removes their own post from the show page.
Adjust redirection logic.
This commit is contained in:
parent
1b058cf908
commit
76c11b8d37
2 changed files with 28 additions and 3 deletions
|
|
@ -119,10 +119,12 @@ app.views.Post = app.views.StreamObject.extend({
|
||||||
return this.model.get("author").id != (!!app.user() && app.user().id)
|
return this.model.get("author").id != (!!app.user() && app.user().id)
|
||||||
},
|
},
|
||||||
|
|
||||||
destroy : function() {
|
isOnShowPage : function() {
|
||||||
var posts_uri = new RegExp(this.model.collection.url + '\/[0-9]+$');
|
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);
|
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