diff --git a/app/controllers/photos_controller.rb b/app/controllers/photos_controller.rb index d2169b7..3214fd8 100644 --- a/app/controllers/photos_controller.rb +++ b/app/controllers/photos_controller.rb @@ -14,8 +14,12 @@ class PhotosController < ApplicationController end def log_view - @photo = Photo.find(params[:id]) - @photo.log_view - render :nothing => true + photo = Photo.find_by_id(params[:id]) + if photo.present? + photo.log_view + head :ok + else + head :not_found + end end end diff --git a/spec/controllers/photos_controller_spec.rb b/spec/controllers/photos_controller_spec.rb index 9cce455..e40b0a0 100644 --- a/spec/controllers/photos_controller_spec.rb +++ b/spec/controllers/photos_controller_spec.rb @@ -12,8 +12,14 @@ describe PhotosController do let(:photo) { create(:photo) } it "logs a photo view" do - photo.should_receive(:log_view).once + Photo.any_instance.should_receive(:log_view).once get :log_view, id: photo.id + should respond_with(:success) + end + + it "responds with not_found if the photo isn't present" do + get :log_view, id: 999 + should respond_with(:not_found) end end end