mirror of
https://github.com/danbee/danbarberphoto
synced 2025-03-04 08:49:07 +00:00
Refactor log_views and fix spec.
This commit is contained in:
parent
49ff2389cd
commit
c47c7e4d3c
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
Loading…
Reference in New Issue
Block a user