Skip to content

Use cache! call to Carrierwave so that base image process functions run in addition to version process calls. #321

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 6 additions & 9 deletions lib/backgrounder/workers/process_asset_mixin.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# encoding: utf-8
module CarrierWave
module Workers

module ProcessAssetMixin
include CarrierWave::Workers::Base

Expand All @@ -16,23 +14,22 @@ def perform(*args)

return unless record && asset_present?(asset)

recreate_asset_versions!(asset)
process_asset_by_cache!(asset)

return unless record.respond_to?(:"#{column}_processing")

if record.respond_to?(:"#{column}_processing")
record.update_attribute :"#{column}_processing", false
end
record.update_attribute :"#{column}_processing", false
end

private

def recreate_asset_versions!(asset)
asset.is_a?(Array) ? asset.map(&:recreate_versions!) : asset.recreate_versions!
def process_asset_by_cache!(asset)
asset.is_a?(Array) ? asset.map(&:cache!) : asset.cache!
end

def asset_present?(asset)
asset.is_a?(Array) ? asset.present? : asset.file.present?
end
end # ProcessAssetMixin

end # Workers
end # Backgrounder
4 changes: 2 additions & 2 deletions spec/backgrounder/workers/process_asset_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
allow(user).to receive(:image).thrice.and_return(image)

expect(user).to receive(:process_image_upload=).with(true).once
expect(image).to receive(:recreate_versions!).once.and_return(true)
expect(image).to receive(:cache!).once.and_return(true)
expect(image).to receive(:file).and_return(image)
end

Expand Down Expand Up @@ -53,7 +53,7 @@

expect(admin).to receive(:respond_to?).with(:avatar_processing).once.and_return(false)
expect(admin).to receive(:process_avatar_upload=).with(true).once
expect(avatar).to receive(:recreate_versions!).once.and_return(true)
expect(avatar).to receive(:cache!).once.and_return(true)
expect(avatar).to receive(:file).and_return(avatar)

worker.perform admin, '23', :avatar
Expand Down