diff --git a/app/controllers/photos_controller.rb b/app/controllers/photos_controller.rb index 5d820f595..309fe888a 100644 --- a/app/controllers/photos_controller.rb +++ b/app/controllers/photos_controller.rb @@ -149,8 +149,10 @@ class PhotosController < ApplicationController if @photo respond_with @photo - else + elsif user_signed_in? redirect_to :back + else + redirect_to new_user_session_path end end diff --git a/spec/controllers/photos_controller_spec.rb b/spec/controllers/photos_controller_spec.rb index 167f0d184..c0a5502b2 100644 --- a/spec/controllers/photos_controller_spec.rb +++ b/spec/controllers/photos_controller_spec.rb @@ -137,6 +137,12 @@ describe PhotosController do get :show, :id => @photo.to_param response.should redirect_to(aspects_path) end + + it 'redirects to the sign in page if not logged in' do + controller.stub(:user_signed_in?).and_return(false) #sign_out :user doesn't work + get :show, :id => @photo.to_param + response.should redirect_to new_user_session_path + end end context "public photo" do