Skip to content
Extraits de code Groupes Projets
Valider 2fb0fce1 rédigé par Raphael Sofaer's avatar Raphael Sofaer
Parcourir les fichiers

Nest likes and comments routes in the post route

parent 875eaffd
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
......@@ -9,7 +9,7 @@ class LikesController < ApplicationController
respond_to :html, :mobile, :json
def create
target = current_user.find_visible_post_by_id params[:status_message_id]
target = current_user.find_visible_post_by_id params[:post_id]
positive = (params[:positive] == 'true') ? true : false
if target
@like = current_user.build_like(:positive => positive, :post => target)
......@@ -32,7 +32,7 @@ class LikesController < ApplicationController
end
def destroy
if @like = Like.where(:id => params[:id], :author_id => current_user.person.id, :post_id => params[:status_message_id]).first
if @like = Like.where(:id => params[:id], :author_id => current_user.person.id, :post_id => params[:post_id]).first
current_user.retract(@like)
else
respond_to do |format|
......@@ -43,7 +43,7 @@ class LikesController < ApplicationController
end
def index
if target = current_user.find_visible_post_by_id(params[:status_message_id])
if target = current_user.find_visible_post_by_id(params[:post_id])
@likes = target.likes.includes(:author => :profile)
render :layout => false
else
......
......@@ -10,9 +10,9 @@ module LikesHelper
def like_action(post, current_user=current_user)
if current_user.liked?(post)
link_to t('shared.stream_element.unlike'), status_message_like_path(post, current_user.like_for(post)), :method => :delete, :class => 'unlike', :remote => true
link_to t('shared.stream_element.unlike'), post_like_path(post, current_user.like_for(post)), :method => :delete, :class => 'unlike', :remote => true
else
link_to t('shared.stream_element.like'), status_message_likes_path(post, :positive => 'true'), :method => :post, :class => 'like', :remote => true
link_to t('shared.stream_element.like'), post_likes_path(post, :positive => 'true'), :method => :post, :class => 'like', :remote => true
end
end
end
......@@ -5,7 +5,7 @@
%li.comment.posted{:data=>{:guid => comment.id}, :class => ("hidden" if(defined? hidden))}
- if current_user && (current_user.owns?(comment) || current_user.owns?(post))
.right.controls
= link_to image_tag('deletelabel.png'), comment_path(comment), :confirm => t('are_you_sure'), :method => :delete, :remote => true, :class => "delete comment_delete", :title => t('delete')
= link_to image_tag('deletelabel.png'), post_comment_path(comment.post_id, comment), :confirm => t('are_you_sure'), :method => :delete, :remote => true, :class => "delete comment_delete", :title => t('delete')
= person_image_link(comment.author)
.content
%span.from
......
......@@ -2,12 +2,11 @@
-# licensed under the Affero General Public License version 3 or later. See
-# the COPYRIGHT file.
= form_tag( comments_path, :id => "new_comment_on_#{post_id}", :class => 'new_comment', :remote => true) do
= form_tag( post_comments_path(post_id), :id => "new_comment_on_#{post_id}", :class => 'new_comment', :remote => true) do
= person_image_tag(current_user)
%p
= label_tag "comment_text_on_#{post_id}", t('.comment')
= text_area_tag :text, nil, :rows => 2, :class => "comment_box",:id => "comment_text_on_#{post_id}"
= hidden_field_tag :post_id, post_id, :id => "post_id_on_#{post_id}"
.submit_button
= submit_tag t('.comment'), :id => "comment_submit_#{post_id}", :class => "comment_submit button creation", :disable_with => t('.commenting')
......@@ -2,7 +2,7 @@
-# licensed under the Affero General Public License version 3 or later. See
-# the COPYRIGHT file.
= form_tag( comments_path, :id => "new_comment_on_#{post_id}", :class => 'new_comment') do
= form_tag( post_comments_path(post_id), :id => "new_comment_on_#{post_id}", :class => 'new_comment') do
= hidden_field_tag :post_id, post_id, :id => "post_id_on_#{post_id}"
= text_area_tag :text, nil, :rows => 2, :class => "comment_box",:id => "comment_text_on_#{post_id}"
......
......@@ -6,7 +6,7 @@
.likes_container
.likes
= image_tag('icons/heart.svg')
= link_to t('likes.likes.people_like_this', :count => likes_count), status_message_likes_path(post_id), :class => "expand_likes"
= link_to t('likes.likes.people_like_this', :count => likes_count), post_likes_path(post_id), :class => "expand_likes"
%span.hidden.likes_list
/= render 'likes/likes', :likes => likes
......@@ -12,11 +12,12 @@ Diaspora::Application.routes.draw do
end
resources :status_messages, :only => [:new, :create] do
resources :likes, :only => [:create, :destroy, :index]
end
resources :comments, :only => [:create, :destroy]
resources :posts, :only => [:show, :destroy]
resources :posts, :only => [:show, :destroy] do
resources :likes, :only => [:create, :destroy, :index]
resources :comments, :only => [:create, :destroy]
end
get 'bookmarklet' => 'status_messages#bookmarklet'
get 'p/:id' => 'publics#post', :as => 'public_post'
......
......@@ -80,13 +80,13 @@ describe CommentsController do
it 'lets the user delete his comment' do
alice.should_receive(:retract).with(@comment)
delete :destroy, :format => "js", :id => @comment.id
delete :destroy, :format => "js", :post_id => 1, :id => @comment.id
response.status.should == 204
end
it "lets the user destroy other people's comments" do
alice.should_receive(:retract).with(@comment2)
delete :destroy, :format => "js", :id => @comment2.id
delete :destroy, :format => "js", :post_id => 1, :id => @comment2.id
response.status.should == 204
end
end
......@@ -101,18 +101,18 @@ describe CommentsController do
it 'let the user delete his comment' do
alice.should_receive(:retract).with(@comment)
delete :destroy, :format => "js", :id => @comment.id
delete :destroy, :format => "js", :post_id => 1, :id => @comment.id
response.status.should == 204
end
it 'does not let the user destroy comments he does not own' do
alice.should_not_receive(:retract).with(@comment2)
delete :destroy, :format => "js", :id => @comment3.id
delete :destroy, :format => "js", :post_id => 1, :id => @comment3.id
response.status.should == 403
end
end
it 'renders nothing and 404 on a nonexistent comment' do
delete :destroy, :id => 343415
delete :destroy, :post_id => 1, :id => 343415
response.status.should == 404
response.body.strip.should be_empty
end
......
......@@ -18,11 +18,11 @@ describe LikesController do
describe '#create' do
let(:like_hash) {
{:positive => 1,
:status_message_id => "#{@post.id}"}
:post_id => "#{@post.id}"}
}
let(:dislike_hash) {
{:positive => 0,
:status_message_id => "#{@post.id}"}
:post_id => "#{@post.id}"}
}
context "on my own post" do
......@@ -77,19 +77,19 @@ describe LikesController do
end
it 'returns a 404 for a post not visible to the user' do
sign_in eve
get :index, :status_message_id => @message.id
get :index, :post_id => @message.id
end
it 'returns an array of likes for a post' do
like = bob.build_like(:positive => true, :post => @message)
like.save!
get :index, :status_message_id => @message.id
get :index, :post_id => @message.id
assigns[:likes].map(&:id).should == @message.likes.map(&:id)
end
it 'returns an empty array for a post with no likes' do
get :index, :status_message_id => @message.id
get :index, :post_id => @message.id
assigns[:likes].should == []
end
end
......@@ -103,7 +103,7 @@ describe LikesController do
it 'lets a user destroy their like' do
expect {
delete :destroy, :format => "js", :status_message_id => @like.post_id, :id => @like.id
delete :destroy, :format => "js", :post_id => @like.post_id, :id => @like.id
}.should change(Like, :count).by(-1)
response.status.should == 200
end
......@@ -113,7 +113,7 @@ describe LikesController do
like2.save
expect {
delete :destroy, :format => "js", :status_message_id => like2.post_id, :id => like2.id
delete :destroy, :format => "js", :post_id => like2.post_id, :id => like2.id
}.should_not change(Like, :count)
response.status.should == 403
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter