remove duplication in jasmine tests (Post view / Feedback view); one correclty failing jasmine spec for Feedback view; created a StatusMessage model for the publisher
This commit is contained in:
parent
02ca7a32f0
commit
0a4b4fb344
10 changed files with 71 additions and 44 deletions
|
|
@ -43,9 +43,9 @@
|
|||
|
||||
</div>
|
||||
|
||||
<% } else { %>
|
||||
<p>
|
||||
Original post deleted by author.
|
||||
</p>
|
||||
<% } %>
|
||||
<% } else { %>
|
||||
<p>
|
||||
Original post deleted by author.
|
||||
</p>
|
||||
<% } %>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ app.models.Post = Backbone.Model.extend({
|
|||
if(this.id) {
|
||||
return "/posts/" + this.id;
|
||||
} else {
|
||||
return "/status_messages"
|
||||
return "/posts"
|
||||
}
|
||||
},
|
||||
|
||||
|
|
@ -19,11 +19,19 @@ app.models.Post = Backbone.Model.extend({
|
|||
return +new Date(this.get("created_at")) / 1000;
|
||||
},
|
||||
|
||||
rootGuid : function() {
|
||||
baseGuid : function() {
|
||||
if(this.get("root")){
|
||||
return this.get("root").guid;
|
||||
} else {
|
||||
return this.get("guid");
|
||||
}
|
||||
},
|
||||
|
||||
baseAuthor : function() {
|
||||
if(this.get("root")){
|
||||
return this.get("root").author;
|
||||
} else {
|
||||
return this.get("author");
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,3 +1,3 @@
|
|||
app.models.Reshare = Backbone.Model.extend({
|
||||
urlRoot: "/reshares"
|
||||
app.models.Reshare = app.models.Post.extend({
|
||||
url : function() { return "/reshares"; }
|
||||
});
|
||||
|
|
|
|||
3
public/javascripts/app/models/status_message.js
Normal file
3
public/javascripts/app/models/status_message.js
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
app.models.StatusMessage = app.models.Post.extend({
|
||||
url : function() { return "/status_messages"; }
|
||||
});
|
||||
|
|
@ -36,9 +36,13 @@ app.views.Feedback = app.views.StreamObject.extend({
|
|||
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();
|
||||
if(window.confirm("Reshare " + this.model.baseAuthor().name + "'s post?")) {
|
||||
var reshare = new app.models.Reshare();
|
||||
reshare.save({root_guid : this.model.baseGuid()}, {
|
||||
success : $.proxy(function(data){
|
||||
app.stream.collection.add(this);
|
||||
}, reshare)
|
||||
});
|
||||
return reshare;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,12 +18,18 @@ app.views.Publisher = Backbone.View.extend({
|
|||
|
||||
var serializedForm = $(evt.target).closest("form").serializeObject();
|
||||
|
||||
this.collection.create({
|
||||
// save status message
|
||||
var statusMessage = new app.models.StatusMessage();
|
||||
statusMessage.save({
|
||||
"status_message" : {
|
||||
"text" : serializedForm["status_message[text]"]
|
||||
},
|
||||
"aspect_ids" : serializedForm["aspect_ids[]"],
|
||||
"photos" : serializedForm["photos[]"]
|
||||
}, {
|
||||
success : $.proxy(function(data) {
|
||||
app.stream.collection.add(this);
|
||||
}, statusMessage)
|
||||
});
|
||||
|
||||
// clear state
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ app.views.StreamObject = app.views.Base.extend({
|
|||
this.model.destroy();
|
||||
|
||||
$(this.el).slideUp(400, function(){
|
||||
this.remove();
|
||||
$(this).remove();
|
||||
});
|
||||
}
|
||||
});
|
||||
|
|
|
|||
|
|
@ -13,19 +13,35 @@ describe("app.models.Post", function() {
|
|||
});
|
||||
});
|
||||
|
||||
describe("rootGuid", function(){
|
||||
describe("baseGuid", 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")
|
||||
expect(this.post.baseGuid()).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")
|
||||
expect(this.post.baseGuid()).toBe("1234")
|
||||
})
|
||||
})
|
||||
|
||||
describe("baseAuthor", function(){
|
||||
it("returns the post's guid if the post does not have a root", function() {
|
||||
this.post.attributes.root = null;
|
||||
this.post.attributes.author = "abcd";
|
||||
|
||||
expect(this.post.baseAuthor()).toBe("abcd")
|
||||
})
|
||||
|
||||
it("returns the post's root guid if the post has a root", function() {
|
||||
this.post.attributes.root = {author : "1234"}
|
||||
this.post.attributes.author = "abcd";
|
||||
|
||||
expect(this.post.baseAuthor()).toBe("1234")
|
||||
})
|
||||
})
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
describe("app.views.Feedback", function(){
|
||||
beforeEach(function(){
|
||||
window.current_user = app.user({name: "alice", avatar : {small : "http://avatar.com/photo.jpg"}});
|
||||
window.current_user = app.user({id : 1, name: "alice", avatar : {small : "http://avatar.com/photo.jpg"}});
|
||||
|
||||
var posts = $.parseJSON(spec.readFixture("multi_stream_json"))["posts"];
|
||||
|
||||
|
|
@ -93,34 +93,43 @@ describe("app.views.Feedback", function(){
|
|||
|
||||
context("when the post is public", function(){
|
||||
beforeEach(function(){
|
||||
this.post.attributes.public = true
|
||||
this.post.attributes.public = true;
|
||||
this.view.render();
|
||||
})
|
||||
|
||||
it("shows a reshare_action link", function(){
|
||||
expect($(this.view.el).html()).toContain('reshare_action')
|
||||
});
|
||||
|
||||
it("does not show a reshare_action link if the original post has been deleted", function(){
|
||||
this.post.attributes.root = null
|
||||
this.view.render();
|
||||
|
||||
expect($(this.view.el).html()).not.toContain('reshare_action');
|
||||
})
|
||||
})
|
||||
|
||||
context("when the post is not public", function(){
|
||||
beforeEach(function(){
|
||||
this.post.attributes.public = false
|
||||
this.post.attributes.public = false;
|
||||
this.post.attributes.root = {author : {name : "susan"}};
|
||||
this.view.render();
|
||||
})
|
||||
|
||||
it("shows a reshare_action link", function(){
|
||||
expect($(this.view.el).html()).not.toContain('reshare_action')
|
||||
it("does not show 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.post.attributes.author = window.current_user;
|
||||
this.view.render();
|
||||
})
|
||||
|
||||
it("does not display a reshare_action link", function(){
|
||||
this.post.attributes.public = false
|
||||
this.view.render();
|
||||
expect($(this.view.el).html()).not.toContain('reshare_action')
|
||||
})
|
||||
})
|
||||
|
|
@ -128,6 +137,7 @@ describe("app.views.Feedback", function(){
|
|||
context("reshares", function(){
|
||||
beforeEach(function(){
|
||||
this.post.attributes.public = true
|
||||
this.post.attributes.root = {author : {name : "susan"}};
|
||||
this.view.render();
|
||||
})
|
||||
|
||||
|
|
|
|||
|
|
@ -37,25 +37,5 @@ describe("app.views.Post", function(){
|
|||
expect(statusElement.find(".shield").html()).toNotBe(null);
|
||||
})
|
||||
})
|
||||
|
||||
context("Reshare link", function(){
|
||||
it("is present if the post is public", function(){
|
||||
var view = new app.views.Post({model : this.statusMessage}).render();
|
||||
this.statusMessage.set({"public" : true});
|
||||
|
||||
var statusElement = $(view.el)
|
||||
|
||||
expect(statusElement.find(".reshare_action")).toNotBe(null);
|
||||
})
|
||||
|
||||
it("is not present if the post is not public", function(){
|
||||
this.statusMessage.set({"public" : false});
|
||||
|
||||
var view = new app.views.Post({model : this.statusMessage}).render();
|
||||
var statusElement = $(view.el)
|
||||
|
||||
expect(statusElement.find(".reshare_action").html()).toBeNull();
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
|
|||
Loading…
Reference in a new issue