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

Use rescue_from in CommentsController

parent 800e701f
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
......@@ -9,6 +9,10 @@ class CommentsController < ApplicationController
respond_to :html, :mobile
respond_to :json, :only => :show
rescue_from ActiveRecord::RecordNotFound do
render :nothing => true, :status => 404
end
def create
target = current_user.find_visible_post_by_id params[:post_id]
text = params[:text]
......@@ -17,7 +21,8 @@ class CommentsController < ApplicationController
@comment = current_user.build_comment(:text => text, :post => target)
if @comment.save
Rails.logger.info("event=create type=comment user=#{current_user.diaspora_handle} status=success comment=#{@comment.id} chars=#{params[:text].length}")
Rails.logger.info(:event => :create, :type => :comment, :user => current_user.diaspora_handle,
:status => :success, :comment => @comment.id, :chars => params[:text].length)
Postzord::Dispatch.new(current_user, @comment).post
respond_to do |format|
......@@ -34,21 +39,18 @@ class CommentsController < ApplicationController
end
def destroy
if @comment = Comment.where(:id => params[:id]).first
if current_user.owns?(@comment) || current_user.owns?(@comment.parent)
current_user.retract(@comment)
respond_to do |format|
format.mobile{ redirect_to @comment.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
@comment = Comment.find(params[:id])
if current_user.owns?(@comment) || current_user.owns?(@comment.parent)
current_user.retract(@comment)
respond_to do |format|
format.mobile{ redirect_to @comment.post }
format.js {render :nothing => true, :status => 204}
end
else
render :nothing => true, :status => 404
respond_to do |format|
format.mobile {redirect_to :back}
format.js {render :nothing => true, :status => 403}
end
end
end
......
......@@ -111,5 +111,10 @@ describe CommentsController do
response.status.should == 403
end
end
it 'renders nothing and 404 on a nonexistent comment' do
delete :destroy, :id => 343415
response.status.should == 404
response.body.strip.should be_empty
end
end
end
\ No newline at end of file
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