From 0e7b08471355adb74eadf243eb3035fcb883c3fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonne=20Ha=C3=9F?= Date: Sun, 29 Jan 2012 14:47:51 +0100 Subject: [PATCH] fix 500 in PostsController#show for non existing post --- app/controllers/posts_controller.rb | 9 +++++---- spec/controllers/posts_controller_spec.rb | 5 +++++ 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/app/controllers/posts_controller.rb b/app/controllers/posts_controller.rb index 856dcc104..6f62abc6a 100644 --- a/app/controllers/posts_controller.rb +++ b/app/controllers/posts_controller.rb @@ -16,13 +16,12 @@ class PostsController < ApplicationController if user_signed_in? @post = current_user.find_visible_shareable_by_id(Post, params[:id], :key => key) - @commenting_disabled = user_can_not_comment_on_post? else @post = Post.where(key => params[:id], :public => true).includes(:author, :comments => :author).first - @commenting_disabled = true end if @post + @commenting_disabled = can_not_comment_on_post? # mark corresponding notification as read if user_signed_in? && notification = Notification.where(:recipient_id => current_user.id, :target_id => @post.id).first notification.unread = false @@ -65,8 +64,10 @@ class PostsController < ApplicationController request.format = :html if request.format == 'application/html+xml' end - def user_can_not_comment_on_post? - if @post.public && @post.author.local? + def can_not_comment_on_post? + if !user_signed_in? + true + elsif @post.public && @post.author.local? false elsif current_user.contact_for(@post.author) false diff --git a/spec/controllers/posts_controller_spec.rb b/spec/controllers/posts_controller_spec.rb index ffe8e6d65..2f6ba7994 100644 --- a/spec/controllers/posts_controller_spec.rb +++ b/spec/controllers/posts_controller_spec.rb @@ -49,6 +49,11 @@ describe PostsController do get :show, :id => photo.id response.should be_success end + + it 'redirects if the post is missing' do + get :show, :id => 523523523 + response.should be_redirect + end end context 'user not signed in' do