summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormo khan <mo@mokhan.ca>2015-01-11 09:48:43 -0700
committermo khan <mo@mokhan.ca>2015-01-11 09:48:43 -0700
commit50eaeae7ef98f66ed187ff8193d8b73dc390681b (patch)
tree0794607f3a1f405834846aba7610bb00bc134654
parent4f316113ce7a18ab44cdf9213a147d5b96236929 (diff)
load processed photos.
-rw-r--r--app/controllers/api/v2/cakes_controller.rb6
-rw-r--r--app/controllers/api/v2/photos_controller.rb2
-rw-r--r--app/models/photo.rb1
-rw-r--r--spec/controllers/api/v2/photos_controller_spec.rb7
4 files changed, 10 insertions, 6 deletions
diff --git a/app/controllers/api/v2/cakes_controller.rb b/app/controllers/api/v2/cakes_controller.rb
index 4c85fd90..b683c1e6 100644
--- a/app/controllers/api/v2/cakes_controller.rb
+++ b/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
diff --git a/app/controllers/api/v2/photos_controller.rb b/app/controllers/api/v2/photos_controller.rb
index c4240327..380f610c 100644
--- a/app/controllers/api/v2/photos_controller.rb
+++ b/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])
diff --git a/app/models/photo.rb b/app/models/photo.rb
index f4df5f41..a7be2acb 100644
--- a/app/models/photo.rb
+++ b/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)
diff --git a/spec/controllers/api/v2/photos_controller_spec.rb b/spec/controllers/api/v2/photos_controller_spec.rb
index 70550ff4..0ed39995 100644
--- a/spec/controllers/api/v2/photos_controller_spec.rb
+++ b/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