added reshare logic back (doesn't append it to the stream...)
This commit is contained in:
parent
027bb3dee7
commit
02ca7a32f0
8 changed files with 107 additions and 10 deletions
|
|
@ -9,6 +9,9 @@ class ResharesController < ApplicationController
|
||||||
current_user.dispatch_post(@reshare, :url => post_url(@reshare), :additional_subscribers => @reshare.root.author)
|
current_user.dispatch_post(@reshare, :url => post_url(@reshare), :additional_subscribers => @reshare.root.author)
|
||||||
end
|
end
|
||||||
|
|
||||||
respond_with @reshare
|
respond_to do |format|
|
||||||
|
format.html { respond_with @reshare }
|
||||||
|
format.json{ render :json => @reshare.as_api_response(:backbone), :status => 201 }
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@
|
||||||
</a>
|
</a>
|
||||||
·
|
·
|
||||||
|
|
||||||
<% if(public) { %>
|
<% if(public && author.id != current_user.id) { %>
|
||||||
<a href="#" class="reshare_action" rel='nofollow'>
|
<a href="#" class="reshare_action" rel='nofollow'>
|
||||||
Reshare
|
Reshare
|
||||||
</a>
|
</a>
|
||||||
|
|
|
||||||
|
|
@ -47,7 +47,6 @@ javascripts:
|
||||||
|
|
||||||
- public/javascripts/view.js
|
- public/javascripts/view.js
|
||||||
- public/javascripts/stream.js
|
- public/javascripts/stream.js
|
||||||
- public/javascripts/content-updater.js
|
|
||||||
- public/javascripts/aspects-dropdown.js
|
- public/javascripts/aspects-dropdown.js
|
||||||
- public/javascripts/contact-edit.js
|
- public/javascripts/contact-edit.js
|
||||||
- public/javascripts/contact-list.js
|
- public/javascripts/contact-list.js
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
app.models.Post = Backbone.Model.extend({
|
app.models.Post = Backbone.Model.extend({
|
||||||
initialize: function() {
|
initialize : function() {
|
||||||
this.comments = new app.collections.Comments(this.get("last_three_comments"));
|
this.comments = new app.collections.Comments(this.get("last_three_comments"));
|
||||||
this.comments.url = this.url() + '/comments';
|
this.comments.url = this.url() + '/comments';
|
||||||
|
|
||||||
|
|
@ -7,7 +7,7 @@ app.models.Post = Backbone.Model.extend({
|
||||||
this.likes.url = this.url() + '/likes';
|
this.likes.url = this.url() + '/likes';
|
||||||
},
|
},
|
||||||
|
|
||||||
url: function(){
|
url : function() {
|
||||||
if(this.id) {
|
if(this.id) {
|
||||||
return "/posts/" + this.id;
|
return "/posts/" + this.id;
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -15,7 +15,15 @@ app.models.Post = Backbone.Model.extend({
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
createdAt: function(){
|
createdAt : function() {
|
||||||
return +new Date(this.get("created_at")) / 1000;
|
return +new Date(this.get("created_at")) / 1000;
|
||||||
|
},
|
||||||
|
|
||||||
|
rootGuid : function() {
|
||||||
|
if(this.get("root")){
|
||||||
|
return this.get("root").guid;
|
||||||
|
} else {
|
||||||
|
return this.get("guid");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
||||||
3
public/javascripts/app/models/reshare.js
Normal file
3
public/javascripts/app/models/reshare.js
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
app.models.Reshare = Backbone.Model.extend({
|
||||||
|
urlRoot: "/reshares"
|
||||||
|
});
|
||||||
|
|
@ -3,6 +3,7 @@ app.views.Feedback = app.views.StreamObject.extend({
|
||||||
|
|
||||||
events: {
|
events: {
|
||||||
"click .like_action": "toggleLike",
|
"click .like_action": "toggleLike",
|
||||||
|
"click .reshare_action": "resharePost"
|
||||||
},
|
},
|
||||||
|
|
||||||
initialize : function() {
|
initialize : function() {
|
||||||
|
|
@ -31,4 +32,14 @@ app.views.Feedback = app.views.StreamObject.extend({
|
||||||
this.like = this.model.likes.create();
|
this.like = this.model.likes.create();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
resharePost : function(evt){
|
||||||
|
if(evt) { evt.preventDefault(); }
|
||||||
|
|
||||||
|
if(window.confirm("Reshare " + this.model.get("author").name + "'s post?")) {
|
||||||
|
var reshare = new app.models.Reshare({root_guid : this.model.rootGuid()});
|
||||||
|
reshare.save();
|
||||||
|
return reshare;
|
||||||
|
}
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,31 @@
|
||||||
describe("app.models.Post", function() {
|
describe("app.models.Post", function() {
|
||||||
|
beforeEach(function(){
|
||||||
|
this.post = new app.models.Post();
|
||||||
|
})
|
||||||
|
|
||||||
describe("createdAt", function() {
|
describe("createdAt", function() {
|
||||||
var post = new app.models.Post();
|
|
||||||
it("returns the post's created_at as an integer", function() {
|
it("returns the post's created_at as an integer", function() {
|
||||||
var date = new Date;
|
var date = new Date;
|
||||||
post.set({ created_at: +date * 1000 });
|
this.post.set({ created_at: +date * 1000 });
|
||||||
|
|
||||||
expect(typeof post.createdAt()).toEqual("number");
|
expect(typeof this.post.createdAt()).toEqual("number");
|
||||||
expect(post.createdAt()).toEqual(+date);
|
expect(this.post.createdAt()).toEqual(+date);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe("rootGuid", function(){
|
||||||
|
it("returns the post's guid if the post does not have a root", function() {
|
||||||
|
this.post.attributes.root = null;
|
||||||
|
this.post.attributes.guid = "abcd";
|
||||||
|
|
||||||
|
expect(this.post.rootGuid()).toBe("abcd")
|
||||||
|
})
|
||||||
|
|
||||||
|
it("returns the post's root guid if the post has a root", function() {
|
||||||
|
this.post.attributes.root = {guid : "1234"}
|
||||||
|
this.post.attributes.guid = "abcd";
|
||||||
|
|
||||||
|
expect(this.post.rootGuid()).toBe("1234")
|
||||||
|
})
|
||||||
|
})
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -90,6 +90,60 @@ describe("app.views.Feedback", function(){
|
||||||
expect(this.link().text()).toContain('Like');
|
expect(this.link().text()).toContain('Like');
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
context("when the post is public", function(){
|
||||||
|
beforeEach(function(){
|
||||||
|
this.post.attributes.public = true
|
||||||
|
this.view.render();
|
||||||
|
})
|
||||||
|
|
||||||
|
it("shows a reshare_action link", function(){
|
||||||
|
expect($(this.view.el).html()).toContain('reshare_action')
|
||||||
|
});
|
||||||
|
})
|
||||||
|
|
||||||
|
context("when the post is not public", function(){
|
||||||
|
beforeEach(function(){
|
||||||
|
this.post.attributes.public = false
|
||||||
|
this.view.render();
|
||||||
|
})
|
||||||
|
|
||||||
|
it("shows a reshare_action link", function(){
|
||||||
|
expect($(this.view.el).html()).not.toContain('reshare_action')
|
||||||
|
});
|
||||||
|
})
|
||||||
|
|
||||||
|
context("when the current user owns the post", function(){
|
||||||
|
beforeEach(function(){
|
||||||
|
this.post.attributes.author = window.current_user
|
||||||
|
this.post.attributes.public = true
|
||||||
|
this.view.render();
|
||||||
|
})
|
||||||
|
|
||||||
|
it("does not display a reshare_action link", function(){
|
||||||
|
expect($(this.view.el).html()).not.toContain('reshare_action')
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
context("reshares", function(){
|
||||||
|
beforeEach(function(){
|
||||||
|
this.post.attributes.public = true
|
||||||
|
this.view.render();
|
||||||
|
})
|
||||||
|
|
||||||
|
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(){
|
||||||
|
spyOn(window, "confirm").andReturn(true);
|
||||||
|
|
||||||
|
expect(this.view.resharePost().constructor).toBe(app.models.Reshare);
|
||||||
|
})
|
||||||
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue