From a104f4e309646d3b3d1c65856a06906f510716be Mon Sep 17 00:00:00 2001 From: Maxwell Salzberg Date: Sun, 3 Jul 2011 09:13:39 -0700 Subject: [PATCH] if a user is logged in, redirect them to the proper authenticated view, not the public route --- app/controllers/posts_controller.rb | 6 ++++++ spec/controllers/posts_controller_spec.rb | 13 ++++++++++--- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/app/controllers/posts_controller.rb b/app/controllers/posts_controller.rb index 838a0d39d..ff797a907 100644 --- a/app/controllers/posts_controller.rb +++ b/app/controllers/posts_controller.rb @@ -10,7 +10,13 @@ class PostsController < ApplicationController def show @post = Post.where(:id => params[:id], :public => true).includes(:author, :comments => :author).first + #hax to upgrade logged in users who can comment if @post + if user_signed_in? && current_user.find_visible_post_by_id(@post.id) + redirect_to "/#{@post.class.to_s.pluralize.underscore}/#{@post.id}" + return + end + @landing_page = true @person = @post.author if @person.owner_id diff --git a/spec/controllers/posts_controller_spec.rb b/spec/controllers/posts_controller_spec.rb index d1fb833de..951fd7b0b 100644 --- a/spec/controllers/posts_controller_spec.rb +++ b/spec/controllers/posts_controller_spec.rb @@ -6,21 +6,28 @@ require 'spec_helper' describe PostsController do before do - @user = alice + alice end describe '#show' do it 'shows a public post' do - status = @user.post(:status_message, :text => "hello", :public => true, :to => 'all') + status = alice.post(:status_message, :text => "hello", :public => true, :to => 'all') get :show, :id => status.id response.status= 200 end it 'does not show a private post' do - status = @user.post(:status_message, :text => "hello", :public => false, :to => 'all') + status = alice.post(:status_message, :text => "hello", :public => false, :to => 'all') get :show, :id => status.id response.status = 302 end + + it 'redirects to the proper show page if the user has visibility of the post' do + status = alice.post(:status_message, :text => "hello", :public => true, :to => 'all') + sign_in bob + get :show, :id => status.id + response.should be_redirect + end end end