mirror of
https://github.com/danbee/danbarberphoto
synced 2025-03-04 08:49:07 +00:00
Add photo factory andn photo controller spec.
This commit is contained in:
parent
a8c59ec56c
commit
91351c7775
@ -1,16 +1,11 @@
|
|||||||
class PhotosController < ApplicationController
|
class PhotosController < ApplicationController
|
||||||
def new
|
|
||||||
@photo = Photo.new
|
|
||||||
@categories = Category.find(:all).map { |c| [c.name, c.id] }
|
|
||||||
end
|
|
||||||
|
|
||||||
def index
|
def index
|
||||||
if params[:category_id]
|
if params[:category_id]
|
||||||
@category = Category.find_by_id(params[:category_id])
|
@category = Category.find_by_id(params[:category_id])
|
||||||
@photos = @category.photos.enabled.order{taken_at.desc}.paginate(:page => params[:page], :per_page => 11)
|
@photos = @category.photos.enabled.order{taken_at.desc}.paginate(:page => params[:page], :per_page => 11)
|
||||||
@page_title = @category.name
|
@page_title = @category.name
|
||||||
else
|
else
|
||||||
@photos = Photo.enabled.order(:taken_at.desc).paginate :all, :page => params[:page], :per_page => 11
|
@photos = Photo.enabled.order{taken_at.desc}.paginate(:page => params[:page], :per_page => 11)
|
||||||
@page_title = 'All Photos'
|
@page_title = 'All Photos'
|
||||||
end
|
end
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
|
|||||||
19
spec/controllers/photos_controller_spec.rb
Normal file
19
spec/controllers/photos_controller_spec.rb
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
require 'spec_helper'
|
||||||
|
|
||||||
|
describe PhotosController do
|
||||||
|
describe "GET index" do
|
||||||
|
it "renders the index template" do
|
||||||
|
get :index
|
||||||
|
expect(response).to render_template(:index)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "GET log_view" do
|
||||||
|
let(:photo) { create(:photo) }
|
||||||
|
|
||||||
|
it "logs a photo view" do
|
||||||
|
photo.should_receive(:log_view).once
|
||||||
|
get :log_view, id: photo.id
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
8
spec/factories/photos.rb
Normal file
8
spec/factories/photos.rb
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
# Read about factories at https://github.com/thoughtbot/factory_girl
|
||||||
|
|
||||||
|
FactoryGirl.define do
|
||||||
|
factory :photo do
|
||||||
|
title "A Photo"
|
||||||
|
description "A lovely photo of a tree"
|
||||||
|
end
|
||||||
|
end
|
||||||
Loading…
Reference in New Issue
Block a user