fixed likes_controller; half of the failing jasmine tests
This commit is contained in:
parent
a7627fabea
commit
c6e4172926
5 changed files with 36 additions and 30 deletions
|
|
@ -63,14 +63,29 @@ App.Views.Post = App.Views.StreamObject.extend({
|
|||
if(evt) { evt.preventDefault(); }
|
||||
|
||||
var link = $(evt.target);
|
||||
var post = this.model;
|
||||
|
||||
if(link.hasClass('like')) {
|
||||
this.model.likes.create();
|
||||
var like = this.model.likes.create();
|
||||
if(like) {
|
||||
console.log(like);
|
||||
this.model.set({
|
||||
user_like : like,
|
||||
likes_count : post.get("likes_count") + 1
|
||||
});
|
||||
}
|
||||
} else {
|
||||
this.model.likes.get(link.data("id")).destroy();
|
||||
this.model.likes.get(link.data("id")).destroy({
|
||||
success : function(){
|
||||
post.set({
|
||||
user_like : null,
|
||||
likes_count : post.get("likes_count") - 1
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return this
|
||||
return this;
|
||||
},
|
||||
|
||||
expandLikes: function(evt){
|
||||
|
|
@ -98,7 +113,6 @@ App.Views.Post = App.Views.StreamObject.extend({
|
|||
},
|
||||
|
||||
appendLike: function(model){
|
||||
console.log(model.get('author'));
|
||||
$(this.el).append("<a>", {
|
||||
href : "/person/" + model.get("author")["id"]
|
||||
}).html($("<img>", {
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ App.Views.StreamObject = Backbone.View.extend({
|
|||
initialize: function(options) {
|
||||
this.model = options.model;
|
||||
this.model.bind('remove', this.remove, this);
|
||||
this.model.bind('change', this.render, this);
|
||||
},
|
||||
|
||||
destroyModel: function(evt){
|
||||
|
|
|
|||
|
|
@ -29,14 +29,10 @@ describe LikesController do
|
|||
}
|
||||
|
||||
context "on my own post" do
|
||||
before do
|
||||
it 'succeeds' do
|
||||
@target = alice.post :status_message, :text => "AWESOME", :to => @alices_aspect.id
|
||||
|
||||
@target = alice.comment "hey", :post => @target if class_const == Comment
|
||||
end
|
||||
|
||||
it 'responds to format js' do
|
||||
post :create, like_hash.merge(:format => 'js')
|
||||
post :create, like_hash.merge(:format => :json)
|
||||
response.code.should == '201'
|
||||
end
|
||||
end
|
||||
|
|
@ -119,9 +115,9 @@ describe LikesController do
|
|||
|
||||
it 'lets a user destroy their like' do
|
||||
expect {
|
||||
delete :destroy, :format => "js", id_field => @like.target_id, :id => @like.id
|
||||
delete :destroy, :format => :json, id_field => @like.target_id, :id => @like.id
|
||||
}.should change(Like, :count).by(-1)
|
||||
response.status.should == 200
|
||||
response.status.should == 204
|
||||
end
|
||||
|
||||
it 'does not let a user destroy other likes' do
|
||||
|
|
@ -129,7 +125,7 @@ describe LikesController do
|
|||
like2.save
|
||||
|
||||
expect {
|
||||
delete :destroy, :format => "js", id_field => like2.target_id, :id => like2.id
|
||||
delete :destroy, :format => :json, id_field => like2.target_id, :id => like2.id
|
||||
}.should_not change(Like, :count)
|
||||
|
||||
response.status.should == 403
|
||||
|
|
|
|||
|
|
@ -211,12 +211,6 @@ describe PeopleController do
|
|||
get :show, :id => @user.person.id
|
||||
response.should be_success
|
||||
end
|
||||
|
||||
it 'passes through the includes option for json requests' do
|
||||
json = @user.person.as_json
|
||||
Person.any_instance.should_receive(:as_json).with(:includes => "horses").and_return(json)
|
||||
get :show, :format => :json, :id => @user.person.id, :includes => "horses"
|
||||
end
|
||||
end
|
||||
|
||||
context "with no user signed in" do
|
||||
|
|
|
|||
|
|
@ -55,26 +55,27 @@ describe("App.views.Post", function(){
|
|||
context("Like link", function(){
|
||||
beforeEach(function(){
|
||||
this.view = new App.Views.Post({model : this.statusMessage})
|
||||
this.link = function(){ return this.view.$(".like_action"); }
|
||||
})
|
||||
|
||||
it("clicking 'Like' toggles appropriately", function(){
|
||||
this.statusMessage.set({user_like : null});
|
||||
this.view.render()
|
||||
var link = this.view.$(".like_action");
|
||||
this.view.render();
|
||||
|
||||
expect(link.text()).toContain('Like');
|
||||
link.click();
|
||||
expect(link.text()).toContain('Unlike');
|
||||
expect(this.link().text()).toContain('Like');
|
||||
this.link().click();
|
||||
expect(this.link().text()).toContain('Unlike');
|
||||
expect($(this.view.el).html()).toContain('1 like');
|
||||
})
|
||||
|
||||
it("clicking 'UnLike' toggles appropriately", function(){
|
||||
it("clicking 'Unlike' toggles appropriately", function(){
|
||||
this.statusMessage.set({user_like : { id : 1 }});
|
||||
this.view.render()
|
||||
var link = this.view.$(".like_action");
|
||||
this.view.render();
|
||||
|
||||
expect(link.text()).toContain('Unlike');
|
||||
link.click();
|
||||
expect(link.text()).toContain('Like');
|
||||
expect(this.link().text()).toContain('Unlike');
|
||||
this.link().click();
|
||||
expect(this.link().text()).toContain('Like');
|
||||
expect($(this.view.el).html()).toNotContain('1 Like');
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
|
|||
Loading…
Reference in a new issue