if a user is logged in, redirect them to the proper authenticated view, not the public route
This commit is contained in:
parent
4b0157f5b0
commit
a104f4e309
2 changed files with 16 additions and 3 deletions
|
|
@ -10,7 +10,13 @@ class PostsController < ApplicationController
|
||||||
def show
|
def show
|
||||||
@post = Post.where(:id => params[:id], :public => true).includes(:author, :comments => :author).first
|
@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 @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
|
@landing_page = true
|
||||||
@person = @post.author
|
@person = @post.author
|
||||||
if @person.owner_id
|
if @person.owner_id
|
||||||
|
|
|
||||||
|
|
@ -6,21 +6,28 @@ require 'spec_helper'
|
||||||
|
|
||||||
describe PostsController do
|
describe PostsController do
|
||||||
before do
|
before do
|
||||||
@user = alice
|
alice
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '#show' do
|
describe '#show' do
|
||||||
it 'shows a public post' 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
|
get :show, :id => status.id
|
||||||
response.status= 200
|
response.status= 200
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'does not show a private post' do
|
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
|
get :show, :id => status.id
|
||||||
response.status = 302
|
response.status = 302
|
||||||
end
|
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
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue