Commit 50eaeae7
Changed files (4)
app
controllers
models
spec
controllers
api
app/controllers/api/v2/cakes_controller.rb
@@ -1,17 +1,19 @@
module Api
module V2
class CakesController < ApplicationController
+ attr_reader :repository
+
def initialize(repository = Spank::IOC.resolve(:cakes))
@repository = repository
super()
end
def index
- @cakes = paginate(@repository.search_with(params).includes(:category))
+ @cakes = paginate(repository.search_with(params).includes(:category))
end
def show(id = params[:id])
- @cake = @repository.find(id)
+ @cake = repository.find(id)
end
end
end
app/controllers/api/v2/photos_controller.rb
@@ -2,7 +2,7 @@ module Api
module V2
class PhotosController < ApplicationController
def index
- @photos = Photo.page(page).per(per_page)
+ @photos = paginate(Photo.processed)
end
def show(id = params[:id])
app/models/photo.rb
@@ -1,5 +1,6 @@
class Photo < ActiveRecord::Base
belongs_to :imageable, polymorphic: true, counter_cache: true, touch: true
+ scope :processed, ->{ where(image_processing: nil) }
def url_for(version_key, asset_host = ENV['ASSET_HOST'])
versions.find { |version| version.for?(version_key) }.url_for(asset_host)
spec/controllers/api/v2/photos_controller_spec.rb
@@ -4,11 +4,12 @@ module Api
module V2
describe PhotosController do
describe "#index" do
- let!(:photo) { create(:photo) }
+ let!(:processed_photo) { create(:photo, image_processing: nil) }
+ let!(:unprocessed_photo) { create(:photo, image_processing: true) }
- it 'should load all the photos' do
+ it 'loads all processed photos' do
xhr :get, :index
- expect(assigns(:photos)).to match_array([photo])
+ expect(assigns(:photos)).to match_array([processed_photo])
end
end