Commit e828e535
Changed files (4)
app
controllers
admin
spec
controllers
app/controllers/admin/photos_controller.rb
@@ -15,13 +15,7 @@ module Admin
end
def update
- photo = @photo_repository.find(params[:id])
- key = OriginalVersion.new(photo).create_key
- @storage.download(key) do |file|
- temp_file = move_to_temporary_storage(file.path, File.basename(key))
- ProcessPhotoJob.perform_later(photo, temp_file)
- end
-
+ ReProcessPhotoJob.perform_later(@photo_repository.find(params[:id]))
redirect_to admin_photos_path
end
app/jobs/re_process_photo_job.rb
@@ -0,0 +1,11 @@
+class ReProcessPhotoJob < ActiveJob::Base
+ queue_as :default
+
+ def perform(photo)
+ key = OriginalVersion.new(photo).create_key
+ @storage.download(key) do |file|
+ temp_file = move_to_temporary_storage(file.path, File.basename(key))
+ ProcessPhotoJob.perform_later(photo, temp_file)
+ end
+ end
+end
spec/controllers/admin/photos_controller_spec.rb
@@ -0,0 +1,23 @@
+require "rails_helper"
+
+module Admin
+ describe PhotosController do
+ let(:admin) { create(:admin) }
+
+ before :each do
+ http_login(admin)
+ end
+
+ describe "#update" do
+ let(:photo) { create(:photo) }
+
+ it "re-processes the photo" do
+ allow(ReProcessPhotoJob).to receive(:perform_later)
+
+ put :update, id: photo.id
+
+ expect(ReProcessPhotoJob).to have_received(:perform_later).with(photo)
+ end
+ end
+ end
+end
spec/jobs/re_process_photo_job_spec.rb
@@ -0,0 +1,5 @@
+require 'rails_helper'
+
+RSpec.describe ReProcessPhotoJob, :type => :job do
+ pending "add some examples to (or delete) #{__FILE__}"
+end