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

Server side of ajaxy comments done, need to modify comments/_comments and make it work.

parent 71dbfce2
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
......@@ -6,7 +6,8 @@ class CommentsController < ApplicationController
include ApplicationHelper
before_filter :authenticate_user!
respond_to :html, :mobile
respond_to :html, :mobile, :only => [:create, :destroy]
respond_to :js, :only => [:index]
rescue_from ActiveRecord::RecordNotFound do
render :nothing => true, :status => 404
......@@ -53,4 +54,13 @@ class CommentsController < ApplicationController
end
end
def index
@post = current_user.find_visible_post_by_id(params[:post_id])
if @post
@comments = @post.comments
else
raise ActiveRecord::RecordNotFound.new
end
end
end
......@@ -3,9 +3,9 @@
-# the COPYRIGHT file.
- unless comments_expanded
%ul.show_comments{:class => ("hidden" if comments.size <= 3)}
%ul.show_comments{:class => ("hidden" if post.comments.count <= 3)}
%li
%b= comment_toggle(comments.size)
%b= comment_toggle( post.comments.count )
%ul.comments{:id => post.id, :class => ("hidden" if comments.size == 0 && !comments_expanded)}
-if comments.size > 3
......
var html = <%= render :partial => 'comments/comment', :collection => @comments, :locals => {:post => @post} %>
$('.comments', '.stream_element[data-guid="<%= @post.id %>"]').html(html);
......@@ -16,7 +16,7 @@ Diaspora::Application.routes.draw do
resources :posts, :only => [:show, :destroy] do
resources :likes, :only => [:create, :destroy, :index]
resources :comments, :only => [:create, :destroy]
resources :comments, :only => [:create, :destroy, :index]
end
get 'bookmarklet' => 'status_messages#bookmarklet'
......
......@@ -117,4 +117,25 @@ describe CommentsController do
response.body.strip.should be_empty
end
end
describe '#index' do
before do
@message = bob.post(:status_message, :text => "hey", :to => bob.aspects.first.id)
@comments = [alice, bob, eve].map{ |u| u.comment("hey", :post => @message) }
end
it 'returns all the comments for a post' do
get :index, :post_id => @message.id, :format => 'js'
assigns[:comments].should == @comments
end
it 'returns a 404 on a nonexistent post' do
get :index, :post_id => 235236, :format => 'js'
response.status.should == 404
end
it 'returns a 404 on a post that is not visible to the signed in user' do
message = eve.post(:status_message, :text => "hey", :to => eve.aspects.first.id)
bob.comment("hey", :post => @message)
get :index, :post_id => message.id, :format => 'js'
response.status.should == 404
end
end
end
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