From eadede966f5f505e03c75bcbd86f6ad0e310a914 Mon Sep 17 00:00:00 2001 From: danielgrippi Date: Fri, 6 May 2011 11:38:07 -0700 Subject: [PATCH] unliking works right now minus on-page feedback --- app/controllers/likes_controller.rb | 2 +- app/views/shared/_stream_element.html.haml | 2 +- spec/controllers/likes_controller_spec.rb | 5 +++-- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/app/controllers/likes_controller.rb b/app/controllers/likes_controller.rb index 72a9032fd..9cee8143d 100644 --- a/app/controllers/likes_controller.rb +++ b/app/controllers/likes_controller.rb @@ -43,7 +43,7 @@ class LikesController < ApplicationController end def destroy - if @like = Like.where(:id => params[:id], :author_id => current_user.person.id).first + if @like = Like.where(:post_id => params[:post_id], :author_id => current_user.person.id).first current_user.retract(@like) respond_to do |format| format.mobile{ redirect_to @like.post } diff --git a/app/views/shared/_stream_element.html.haml b/app/views/shared/_stream_element.html.haml index 3ccf84159..b91323a95 100644 --- a/app/views/shared/_stream_element.html.haml +++ b/app/views/shared/_stream_element.html.haml @@ -45,7 +45,7 @@ - if !current_user.liked?(post) = link_to t('.like'), likes_path(:positive => 'true', :post_id => post.id ), :method => :post, :class => "like_it", :remote => true - else - = link_to t('.unlike'), likes_path(:post_id => post.id ), :method => :delete, :class => "like_it", :remote => true + = link_to t('.unlike'), like_path(:post_id => post.id, :id => 'xxx'), :method => :delete, :class => "like_it", :remote => true /| /= link_to t('.dislike'), like_path(:positive => 'false', :post_id => post.id), :method => :post, :class => "dislike_it", :remote => true diff --git a/spec/controllers/likes_controller_spec.rb b/spec/controllers/likes_controller_spec.rb index d336d1981..d09303e2d 100644 --- a/spec/controllers/likes_controller_spec.rb +++ b/spec/controllers/likes_controller_spec.rb @@ -82,16 +82,17 @@ describe LikesController do it 'lets a user destroy their like' do alice.should_receive(:retract).with(@like) - delete :destroy, :format => "js", :id => @like.id + delete :destroy, :format => "js", :post_id => @like.post_id, :id => @like.id response.status.should == 204 end it 'does not let a user destroy other likes' do + pending "not really relevant to how we're using the destory method. not totally RESTful right now" like2 = eve.build_like(true, :on => @message) like2.save alice.should_not_receive(:retract) - delete :destroy, :format => "js", :id => like2.id + delete :destroy, :format => "js", :post_id => like2.post_id, :id => like2.id response.status.should == 403 end end