do not 500 on public photo viewing, also redirect if there is no photo rather than 500ing
This commit is contained in:
parent
34dbc5a872
commit
4b47de5b9e
2 changed files with 21 additions and 3 deletions
|
|
@ -136,6 +136,7 @@ class PhotosController < ApplicationController
|
||||||
|
|
||||||
def show
|
def show
|
||||||
@photo = current_user.visible_photos.where(:id => params[:id]).includes(:person, :status_message => :photos).first
|
@photo = current_user.visible_photos.where(:id => params[:id]).includes(:person, :status_message => :photos).first
|
||||||
|
@photo ||= Photo.where(:public => true, :id => params[:id]).includes(:person, :status_message => :photos).first
|
||||||
if @photo
|
if @photo
|
||||||
@parent = @photo.status_message
|
@parent = @photo.status_message
|
||||||
|
|
||||||
|
|
@ -158,9 +159,11 @@ class PhotosController < ApplicationController
|
||||||
|
|
||||||
@ownership = current_user.owns? @photo
|
@ownership = current_user.owns? @photo
|
||||||
|
|
||||||
|
respond_with @photo
|
||||||
|
else
|
||||||
|
redirect_to :back
|
||||||
end
|
end
|
||||||
|
|
||||||
respond_with @photo
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def edit
|
def edit
|
||||||
|
|
|
||||||
|
|
@ -15,10 +15,11 @@ describe PhotosController do
|
||||||
@aspect2 = @user2.aspects.first
|
@aspect2 = @user2.aspects.first
|
||||||
|
|
||||||
@photo1 = @user1.post(:photo, :user_file => uploaded_photo, :to => @aspect1.id)
|
@photo1 = @user1.post(:photo, :user_file => uploaded_photo, :to => @aspect1.id)
|
||||||
@photo2 = @user2.post(:photo, :user_file => uploaded_photo, :to => @aspect2.id)
|
@photo2 = @user2.post(:photo, :user_file => uploaded_photo, :to => @aspect2.id, :public => true)
|
||||||
|
|
||||||
@controller.stub!(:current_user).and_return(@user1)
|
@controller.stub!(:current_user).and_return(@user1)
|
||||||
sign_in :user, @user1
|
sign_in :user, @user1
|
||||||
|
request.env["HTTP_REFERER"] = ''
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'has working context' do
|
it 'has working context' do
|
||||||
|
|
@ -78,6 +79,20 @@ describe PhotosController do
|
||||||
assigns[:photo].should == @photo2
|
assigns[:photo].should == @photo2
|
||||||
assigns[:ownership].should be_false
|
assigns[:ownership].should be_false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'shows a public photo of someone who is not friends' do
|
||||||
|
sign_out @user1
|
||||||
|
user3 = Factory(:user)
|
||||||
|
sign_in :user, user3
|
||||||
|
get :show, :id => @photo2.id
|
||||||
|
response.status.should == 200
|
||||||
|
assigns[:photo].should == @photo2
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'redirects to the root url if the photo if you can not see it' do
|
||||||
|
get :show, :id => 23424
|
||||||
|
response.status.should == 302
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '#edit' do
|
describe '#edit' do
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue