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
|
end
|
||||||
|
|
||||||
def log_view
|
def log_view
|
||||||
@photo = Photo.find(params[:id])
|
photo = Photo.find_by_id(params[:id])
|
||||||
@photo.log_view
|
if photo.present?
|
||||||
render :nothing => true
|
photo.log_view
|
||||||
|
head :ok
|
||||||
|
else
|
||||||
|
head :not_found
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -12,8 +12,14 @@ describe PhotosController do
|
|||||||
let(:photo) { create(:photo) }
|
let(:photo) { create(:photo) }
|
||||||
|
|
||||||
it "logs a photo view" do
|
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
|
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
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user