likes controller now has destroy method. commented out dislikes from views. unlike links not functional.

This commit is contained in:
danielgrippi 2011-04-27 12:00:58 -07:00 committed by Raphael Sofaer
parent 4a24e90671
commit 8b081a48b4
8 changed files with 86 additions and 37 deletions

View file

@ -3,7 +3,7 @@
# the COPYRIGHT file.
class AspectsController < ApplicationController
helper :comments, :aspect_memberships
helper :comments, :aspect_memberships, :likes
before_filter :authenticate_user!
before_filter :save_sort_order, :only => :index
before_filter :ensure_page, :only => :index

View file

@ -1,4 +1,4 @@
# Copyright (c) 2010, Diaspora Inc. This file is
# licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file.
@ -41,4 +41,20 @@ class LikesController < ApplicationController
render :nothing => true, :status => 422
end
end
def destroy
if @like = Like.where(:id => params[:id], :author_id => current_user.person.id).first
current_user.retract(@like)
respond_to do |format|
format.mobile{ redirect_to @like.post }
format.js {render :nothing => true, :status => 204}
end
else
respond_to do |format|
format.mobile {redirect_to :back}
format.js {render :nothing => true, :status => 403}
end
end
end
end

View file

@ -2,16 +2,16 @@
-# licensed under the Affero General Public License version 3 or later. See
-# the COPYRIGHT file.
- if likes.length > 0
- if likes.size > 0
.likes
= image_tag('icons/happy_smiley.png')
= link_to t('.people_like_this', :count => likes.length), "#", :class => "expand_likes"
%span.hidden.likes_list
= likes_list(likes)
- if dislikes.length > 0
.dislikes
= image_tag('icons/sad_smiley.png')
= link_to t('.people_dislike_this', :count => dislikes.length), "#", :class => "expand_dislikes"
%span.hidden.dislikes_list
= likes_list(dislikes)
/- if dislikes.length > 0
/ .dislikes
/ = image_tag('icons/sad_smiley.png')
/ = link_to t('.people_dislike_this', :count => dislikes.length), "#", :class => "expand_dislikes"
/ %span.hidden.dislikes_list
/ = likes_list(dislikes)

View file

@ -39,15 +39,18 @@
- unless (defined?(@commenting_disabled) && @commenting_disabled)
= link_to t('comments.new_comment.comment'), '#', :class => 'focus_comment_textarea'
/ TODO(likes)
/- if (defined?(current_user) && !current_user.liked?(post))
/ %span.like_links
/ |
/ = link_to t('.like'), likes_path(:positive => 'true', :post_id => post.id ), :method => :post, :class => "like_it", :remote => true
/ |
/ = link_to t('.dislike'), likes_path(:positive => 'false', :post_id => post.id), :method => :post, :class => "dislike_it", :remote => true
- if defined?(current_user)
%span.like_links
|
- 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
/.likes_container
/ = render "likes/likes", :post_id => post.id, :likes => post.likes, :dislikes => post.dislikes, :current_user => current_user
/|
/= link_to t('.dislike'), like_path(:positive => 'false', :post_id => post.id), :method => :post, :class => "dislike_it", :remote => true
.likes_container
= render "likes/likes", :post_id => post.id, :likes => post.likes, :dislikes => post.dislikes, :current_user => current_user
= render "comments/comments", :post => post, :comments => post.comments, :current_user => current_user, :condensed => true, :commenting_disabled => (defined?(@commenting_disabled) && @commenting_disabled)

View file

@ -271,17 +271,17 @@ en:
likes:
likes:
people_like_this:
zero: "no people liked this"
one: "1 person liked this"
few: "%{count} people liked this"
many: "%{count} people liked this"
other: "%{count} people liked this"
zero: "no likes"
one: "%{count} like"
few: "%{count} likes"
many: "%{count} likes"
other: "%{count} likes"
people_dislike_this:
zero: "no people disliked this"
one: "1 person disliked this"
few: "%{count} people disliked this"
many: "%{count} people disliked this"
other: "%{count} people disliked this"
zero: "no dislikes"
one: "%{count} dislike"
few: "%{count} dislikes"
many: "%{count} dislikes"
other: "%{count} dislikes"
notifications:
request_accepted: "accepted your share request."
@ -570,8 +570,9 @@ en:
all_contacts: "All contacts"
cannot_remove: "Cannot remove person from last aspect. (If you want to disconnect from this person you must remove contact.)"
stream_element:
like: "I like this"
dislike: "I dislike this"
like: "Like"
unlike: "Unlike"
dislike: "Dislike"
footer:
logged_in_as: "logged in as %{name}"
your_aspects: "your aspects"

View file

@ -20,8 +20,8 @@ Diaspora::Application.routes.draw do
end
resources :comments, :only => [:create, :destroy]
resource :like, :only => [:create]
resources :likes, :only => [:create, :destroy]
resources :conversations do
resources :messages, :only => [:create, :show]

View file

@ -2828,11 +2828,14 @@ h1.tag
a
:padding 1px
:vertical-align middle
:font-size smaller
:font-size 11px
img
:width 12px
:height 12px
:margin-left 0.5em
:position relative
:width 14px
:height 14px
:margin-left 5px
:top 2px
#contacts_of_contact
.section

View file

@ -12,6 +12,7 @@ describe LikesController do
@aspect1 = @user1.aspects.first
@aspect2 = @user2.aspects.first
@controller.stub(:current_user).and_return(alice)
sign_in :user, @user1
end
@ -70,4 +71,29 @@ describe LikesController do
end
end
end
describe '#destroy' do
context 'your like' do
before do
@message = bob.post(:status_message, :text => "hey", :to => @aspect1.id)
@like = alice.build_like(true, :on => @message)
@like.save
end
it 'lets a user destroy their like' do
alice.should_receive(:retract).with(@like)
delete :destroy, :format => "js", :id => @like.id
response.status.should == 204
end
it 'does not let a user destroy other likes' do
like2 = eve.build_like(true, :on => @message)
like2.save
alice.should_not_receive(:retract)
delete :destroy, :format => "js", :id => like2.id
response.status.should == 403
end
end
end
end