you should be able to reshare reshares again, first pass

This commit is contained in:
Dennis Collinson 2012-01-16 19:56:52 -08:00
parent d5563d8802
commit 66d71a217e
9 changed files with 88 additions and 18 deletions

View file

@ -15,6 +15,16 @@ app.models.Post = Backbone.Model.extend({
}
},
reshare : function(){
var reshare = new app.models.Reshare();
reshare.save({root_guid : this.baseGuid()}, {
success : function(){
app.stream.collection.add(reshare.toJSON());
}
});
return reshare;
},
toggleLike : function() {
var userLike = this.get("user_like")
if(userLike) {

View file

@ -1,3 +1,8 @@
app.models.Reshare = app.models.Post.extend({
url : function() { return "/reshares"; }
url : function() { return "/reshares"; },
rootPost : function(){
this._rootPost = this._rootPost || new app.models.Post(this.get("root"))
return this._rootPost
}
});

View file

@ -3,6 +3,11 @@ app.views.Base = Backbone.View.extend({
return this.defaultPresenter()
},
setupRenderEvents : function(){
this.model.bind('remove', this.remove, this);
this.model.bind('change', this.render, this);
},
defaultPresenter : function(){
var modelJson = this.model ? this.model.toJSON() : {}
return _.extend(modelJson, { current_user: app.user().current_user });

View file

@ -13,16 +13,14 @@ app.views.Feedback = app.views.StreamObject.extend({
this.model.toggleLike();
},
initialize: function(options){
this.setupRenderEvents();
this.reshareablePost = options.model;
},
resharePost : function(evt){
if(evt) { evt.preventDefault(); }
if(!window.confirm("Reshare " + this.model.baseAuthor().name + "'s post?")) { return }
var reshare = new app.models.Reshare();
reshare.save({root_guid : this.model.baseGuid()}, {
success : function(){
app.stream.collection.add(reshare.toJSON());
}
});
return reshare;
if(!window.confirm("Reshare " + this.reshareablePost.baseAuthor().name + "'s post?")) { return }
this.reshareablePost.reshare();
}
})

View file

@ -1,3 +1,6 @@
app.views.ReshareFeedback = app.views.Base.extend({
template_name: "#reshare-feedback-template",
app.views.ReshareFeedback = app.views.Feedback.extend({
initialize : function(){
this.reshareablePost = (this.model instanceof app.models.Reshare) ? this.model.rootPost() : new app.models.Reshare(this.model.attributes).rootPost();
this.setupRenderEvents();
}
});

View file

@ -1,7 +1,6 @@
app.views.StreamObject = app.views.Base.extend({
initialize: function(options) {
this.model.bind('remove', this.remove, this);
this.model.bind('change', this.render, this);
this.setupRenderEvents();
},
postRenderTemplate : function(){

View file

@ -0,0 +1,20 @@
describe("app.models.Reshare", function(){
describe("rootPost", function(){
beforeEach(function(){
this.reshare = new app.models.Reshare({root: {a:"namaste", be : "aloha", see : "community"}})
});
it("should be the root attrs", function(){
expect(this.reshare.rootPost().get("be")).toBe("aloha")
});
it("should return a post", function(){
expect(this.reshare.rootPost() instanceof app.models.Post).toBeTruthy()
});
it("does not create a new object every time", function(){
expect(this.reshare.rootPost()).toBe(this.reshare.rootPost())
});
});
});

View file

@ -15,6 +15,12 @@ describe("app.views.Feedback", function(){
this.view = new app.views.Feedback({model: this.post});
});
describe("initialization", function(){
it("sets the model as the reshareable post", function(){
expect(this.view.reshareablePost).toBe(this.post);
})
})
describe(".render", function(){
beforeEach(function(){
this.link = function(){ return this.view.$(".like_action"); }
@ -120,15 +126,15 @@ describe("app.views.Feedback", function(){
it("displays a confirmation dialog", function(){
spyOn(window, "confirm")
this.view.$(".reshare_action").first().click();
expect(window.confirm).toHaveBeenCalled();
})
it("creates a reshare if the confirmation dialog is accepted", function(){
it("reshares the reshareablePost", function(){
spyOn(window, "confirm").andReturn(true);
expect(this.view.resharePost().constructor).toBe(app.models.Reshare);
spyOn(this.view.reshareablePost, "reshare")
this.view.$(".reshare_action").first().click();
expect(this.view.reshareablePost.reshare).toHaveBeenCalled();
})
})
})

View file

@ -0,0 +1,24 @@
describe("app.views.ReshareFeedback", function(){
beforeEach(function(){
var posts = $.parseJSON(spec.readFixture("multi_stream_json"))["posts"];
this.reshare = new app.models.Reshare(_.extend(posts[1], {public : true}));
this.view = new app.views.ReshareFeedback({model : this.reshare }).render()
})
it("inherits from feedback view", function(){
expect(this.view instanceof app.views.Feedback).toBeTruthy()
})
it("sets Up the root Post as the reshareable post", function(){
expect(this.view.reshareablePost).toBe(this.reshare.rootPost())
})
it("reshares the rootPost", function(){
spyOn(window, "confirm").andReturn(true);
spyOn(this.reshare.rootPost(), "reshare")
console.log(this.view.el)
this.view.$(".reshare_action").first().click();
expect(this.reshare.rootPost().reshare).toHaveBeenCalled();
})
})