carrierwave_backgrounder 0.4.1 → 0.4.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.gitignore +1 -0
- data/.travis.yml +8 -2
- data/CHANGELOG.md +15 -1
- data/README.md +41 -6
- data/carrierwave_backgrounder.gemspec +2 -3
- data/lib/backgrounder/delay.rb +2 -1
- data/lib/backgrounder/orm/base.rb +1 -1
- data/lib/backgrounder/orm/data_mapper.rb +1 -1
- data/lib/backgrounder/support/backends.rb +16 -5
- data/lib/backgrounder/version.rb +1 -1
- data/lib/backgrounder/workers/base.rb +15 -7
- data/lib/backgrounder/workers/class_methods.rb +14 -0
- data/lib/backgrounder/workers/process_asset.rb +2 -13
- data/lib/backgrounder/workers/process_asset_mixin.rb +28 -0
- data/lib/backgrounder/workers/store_asset.rb +2 -26
- data/lib/backgrounder/workers/store_asset_mixin.rb +43 -0
- data/lib/backgrounder/workers.rb +3 -0
- data/lib/generators/carrierwave_backgrounder/templates/config/initializers/carrierwave_backgrounder.rb +1 -0
- data/spec/backgrounder/orm/activemodel_spec.rb +27 -27
- data/spec/backgrounder/orm/base_spec.rb +1 -1
- data/spec/backgrounder/support/backends_spec.rb +56 -29
- data/spec/backgrounder/workers/process_asset_spec.rb +20 -20
- data/spec/backgrounder/workers/store_asset_spec.rb +43 -43
- data/spec/spec_helper.rb +0 -1
- data/spec/support/backend_constants.rb +2 -1
- data/spec/support/mock_worker.rb +5 -0
- metadata +29 -35
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: c08d7bdb01034545507f0ef13305aa12764e2771148c4ddc22f1291fbba8f7f9
|
4
|
+
data.tar.gz: 21d4f4a1cd200c5b05f9b967d4fda436e7d11752ba6fb6307f619a7b32ae1924
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 683938ec5318b2727ae40e177a717fc6135f479f397cbdd39e0b3639a70ff3508ef98406ced8fd203b6d34d4017a84d2a2eab64f164d69bd8d24c64e2ff1786c
|
7
|
+
data.tar.gz: 44b9e651e679fa450dfbe9620e58e5472c0be9bc20bd7f4ce29894de28c30c7f6d5c04f7dd9aa56fc4277bd8d0a3ff0205aa287fb31439e8bfaa5d6158ccbe0b
|
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,4 +1,19 @@
|
|
1
1
|
|
2
|
+
## 0.4.3
|
3
|
+
|
4
|
+
### enhancements
|
5
|
+
* [#307] Add support for Sidekiq 7 [holstvoogd]
|
6
|
+
* [#278] Add sidekiq queue config [IlkhamGaysin]
|
7
|
+
|
8
|
+
## 0.4.2
|
9
|
+
|
10
|
+
### enhancements
|
11
|
+
* Allow overridden worker to set a queue name
|
12
|
+
* [#190] Respect Carrierwave's enable_processing flag if set to false [jherdman]
|
13
|
+
|
14
|
+
### bug fixes
|
15
|
+
* [#216] Fix for NoMethodError: undefined method `read' for nil:NilClass [kntmrkm]
|
16
|
+
|
2
17
|
## 0.4.1
|
3
18
|
|
4
19
|
### enhancements
|
@@ -88,4 +103,3 @@
|
|
88
103
|
### bug fixes
|
89
104
|
* Girl Friday incorrectly referenses class #92
|
90
105
|
* Add documentation for testing with rspec #84.
|
91
|
-
|
data/README.md
CHANGED
@@ -2,7 +2,6 @@
|
|
2
2
|
|
3
3
|
[![Build Status](https://secure.travis-ci.org/lardawge/carrierwave_backgrounder.png)](http://travis-ci.org/lardawge/carrierwave_backgrounder)
|
4
4
|
[![Code Climate](https://codeclimate.com/github/lardawge/carrierwave_backgrounder.png)](https://codeclimate.com/github/lardawge/carrierwave_backgrounder)
|
5
|
-
[![Still Maintained](http://stillmaintained.com/lardawge/carrierwave_backgrounder.png)](http://stillmaintained.com/lardawge/carrierwave_backgrounder)
|
6
5
|
|
7
6
|
I like CarrierWave. That being said, I don't like tying up app instances waiting for images to process.
|
8
7
|
|
@@ -34,7 +33,7 @@ Backgrounder::ORM::Base::store_in_background
|
|
34
33
|
|
35
34
|
## Installation and Usage
|
36
35
|
|
37
|
-
These instructions assume you have previously set up [CarrierWave](https://github.com/jnicklas/carrierwave) and your
|
36
|
+
These instructions assume you have previously set up [CarrierWave](https://github.com/jnicklas/carrierwave) and your queuing lib of choice.
|
38
37
|
|
39
38
|
In Rails, add the following your Gemfile:
|
40
39
|
|
@@ -55,6 +54,14 @@ CarrierWave::Backgrounder.configure do |c|
|
|
55
54
|
end
|
56
55
|
```
|
57
56
|
|
57
|
+
**IMPORTANT FOR SIDEKIQ BACKEND** - Custom queue should be defined inside the Sidekiq configuration otherwise jobs won't be processed:
|
58
|
+
|
59
|
+
```yml
|
60
|
+
:queues:
|
61
|
+
- [awesome_queue, 1]
|
62
|
+
- default
|
63
|
+
```
|
64
|
+
|
58
65
|
In your CarrierWave uploader file:
|
59
66
|
|
60
67
|
```ruby
|
@@ -74,10 +81,11 @@ mount_uploader :avatar, AvatarUploader
|
|
74
81
|
process_in_background :avatar
|
75
82
|
```
|
76
83
|
|
77
|
-
Optionally you can add a column to the database which will be set to
|
84
|
+
Optionally you can add a column to the database which will be set to `true` when
|
85
|
+
the background processing is started and to `false` when the background processing is complete.
|
78
86
|
|
79
87
|
```ruby
|
80
|
-
add_column :users, :avatar_processing, :boolean
|
88
|
+
add_column :users, :avatar_processing, :boolean, null: false, default: false
|
81
89
|
```
|
82
90
|
|
83
91
|
### To use store_in_background
|
@@ -114,7 +122,7 @@ This must be set before you assign an upload:
|
|
114
122
|
```
|
115
123
|
|
116
124
|
### Override worker
|
117
|
-
To
|
125
|
+
To override the worker in cases where additional methods need to be called or you have app specific requirements, pass the worker class as the
|
118
126
|
second argument:
|
119
127
|
|
120
128
|
```ruby
|
@@ -134,9 +142,36 @@ class MyParanoidWorker < ::CarrierWave::Workers::ProcessAsset
|
|
134
142
|
# other hooks you might care about
|
135
143
|
end
|
136
144
|
```
|
145
|
+
|
146
|
+
### ActiveJob
|
147
|
+
Use overriden worker that inherits from ActiveJob::Base and includes relevant worker mixin:
|
148
|
+
```ruby
|
149
|
+
class MyActiveJobWorker < ActiveJob::Base
|
150
|
+
include ::CarrierWave::Workers::ProcessAssetMixin
|
151
|
+
# ... or include ::CarrierWave::Workers::StoreAssetMixin
|
152
|
+
|
153
|
+
after_perform do
|
154
|
+
# your code here
|
155
|
+
end
|
156
|
+
|
157
|
+
# Sometimes job gets performed before the file is uploaded and ready.
|
158
|
+
# You can define how to handle that case by overriding `when_not_ready` method
|
159
|
+
# (by default it does nothing)
|
160
|
+
def when_not_ready
|
161
|
+
retry_job
|
162
|
+
end
|
163
|
+
end
|
164
|
+
```
|
165
|
+
Don't forget to set `active_job` as a backend in the config:
|
166
|
+
```ruby
|
167
|
+
CarrierWave::Backgrounder.configure do |c|
|
168
|
+
c.backend :active_job, queue: :carrierwave
|
169
|
+
end
|
170
|
+
```
|
171
|
+
|
137
172
|
### Testing with Rspec
|
138
173
|
We use the after_commit hook when using active_record. This creates a problem when testing with Rspec because after_commit never gets fired
|
139
|
-
if you're using
|
174
|
+
if you're using transactional fixtures. One solution to the problem is to use the [TestAfterCommit gem](https://github.com/grosser/test_after_commit).
|
140
175
|
There are various other solutions in which case google is your friend.
|
141
176
|
|
142
177
|
### Uploaders mounted on mongoid embedded documents
|
@@ -17,9 +17,8 @@ Gem::Specification.new do |s|
|
|
17
17
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
18
18
|
s.require_paths = ["lib"]
|
19
19
|
|
20
|
-
s.add_dependency "carrierwave", ["
|
20
|
+
s.add_dependency "carrierwave", [">= 0.5", "< 2.2"]
|
21
21
|
|
22
|
-
s.add_development_dependency "rspec", ["~>
|
23
|
-
s.add_development_dependency "mocha", ["~> 0.13.0"]
|
22
|
+
s.add_development_dependency "rspec", ["~> 3.10.0"]
|
24
23
|
s.add_development_dependency "rake"
|
25
24
|
end
|
data/lib/backgrounder/delay.rb
CHANGED
@@ -17,7 +17,8 @@ module CarrierWave
|
|
17
17
|
private
|
18
18
|
|
19
19
|
def proceed_with_versioning?
|
20
|
-
!model.respond_to?(:"process_#{mounted_as}_upload") ||
|
20
|
+
!model.respond_to?(:"process_#{mounted_as}_upload") && enable_processing ||
|
21
|
+
!!(model.send(:"process_#{mounted_as}_upload") && enable_processing)
|
21
22
|
end
|
22
23
|
end # Delay
|
23
24
|
|
@@ -82,7 +82,7 @@ module CarrierWave
|
|
82
82
|
|
83
83
|
def write_#{column}_identifier
|
84
84
|
super and return if process_#{column}_upload
|
85
|
-
self.#{column}_tmp =
|
85
|
+
self.#{column}_tmp = #{column}_cache if #{column}_cache
|
86
86
|
end
|
87
87
|
|
88
88
|
def store_#{column}!
|
@@ -22,11 +22,19 @@ module CarrierWave
|
|
22
22
|
|
23
23
|
private
|
24
24
|
|
25
|
+
def enqueue_active_job(worker, *args)
|
26
|
+
worker.perform_later(*args.map(&:to_s))
|
27
|
+
end
|
28
|
+
|
25
29
|
def enqueue_delayed_job(worker, *args)
|
30
|
+
worker_args = {}
|
26
31
|
if ::Delayed::Job.new.respond_to?(:queue)
|
27
|
-
|
32
|
+
worker_args[:queue] = queue_options[:queue] if queue_options[:queue]
|
33
|
+
worker_args[:priority] = queue_options[:priority] if queue_options[:priority]
|
34
|
+
::Delayed::Job.enqueue worker.new(*args), worker_args
|
28
35
|
else
|
29
|
-
|
36
|
+
worker_args[:priority] = queue_options[:priority] if queue_options[:priority]
|
37
|
+
::Delayed::Job.enqueue worker.new(*args), worker_args
|
30
38
|
if queue_options[:queue]
|
31
39
|
::Rails.logger.warn("Queue name given but no queue column exists for Delayed::Job")
|
32
40
|
end
|
@@ -39,7 +47,8 @@ module CarrierWave
|
|
39
47
|
end
|
40
48
|
|
41
49
|
def enqueue_sidekiq(worker, *args)
|
42
|
-
|
50
|
+
override_queue_name = worker.sidekiq_options['queue'] == 'default' || worker.sidekiq_options['queue'].nil?
|
51
|
+
args = sidekiq_queue_options(override_queue_name, 'class' => worker, 'args' => args.map(&:to_s))
|
43
52
|
worker.client_push(args)
|
44
53
|
end
|
45
54
|
|
@@ -69,8 +78,10 @@ module CarrierWave
|
|
69
78
|
worker.new(*args).perform
|
70
79
|
end
|
71
80
|
|
72
|
-
def sidekiq_queue_options(args)
|
73
|
-
|
81
|
+
def sidekiq_queue_options(override_queue_name, args)
|
82
|
+
if override_queue_name && queue_options[:queue]
|
83
|
+
args['queue'] = queue_options[:queue]
|
84
|
+
end
|
74
85
|
args['retry'] = queue_options[:retry] unless queue_options[:retry].nil?
|
75
86
|
args['timeout'] = queue_options[:timeout] if queue_options[:timeout]
|
76
87
|
args['backtrace'] = queue_options[:backtrace] if queue_options[:backtrace]
|
data/lib/backgrounder/version.rb
CHANGED
@@ -1,14 +1,18 @@
|
|
1
|
+
# encoding: utf-8
|
1
2
|
module CarrierWave
|
2
3
|
module Workers
|
3
|
-
class Base < Struct.new(:klass, :id, :column)
|
4
4
|
|
5
|
-
|
6
|
-
|
5
|
+
module Base
|
6
|
+
attr_accessor :klass, :id, :column, :record
|
7
|
+
|
8
|
+
def initialize(*args)
|
9
|
+
super(*args) unless self.class.superclass == Object
|
10
|
+
set_args(*args) if args.present?
|
7
11
|
end
|
8
12
|
|
9
13
|
def perform(*args)
|
10
14
|
set_args(*args) if args.present?
|
11
|
-
constantized_resource.find id
|
15
|
+
self.record = constantized_resource.find id
|
12
16
|
rescue *not_found_errors
|
13
17
|
end
|
14
18
|
|
@@ -29,6 +33,10 @@ module CarrierWave
|
|
29
33
|
klass.is_a?(String) ? klass.constantize : klass
|
30
34
|
end
|
31
35
|
|
32
|
-
|
33
|
-
|
34
|
-
|
36
|
+
def when_not_ready
|
37
|
+
end
|
38
|
+
|
39
|
+
end # Base
|
40
|
+
|
41
|
+
end # Workers
|
42
|
+
end # CarrierWave
|
@@ -2,19 +2,8 @@
|
|
2
2
|
module CarrierWave
|
3
3
|
module Workers
|
4
4
|
|
5
|
-
class ProcessAsset
|
6
|
-
|
7
|
-
def perform(*args)
|
8
|
-
record = super(*args)
|
9
|
-
|
10
|
-
if record
|
11
|
-
record.send(:"process_#{column}_upload=", true)
|
12
|
-
if record.send(:"#{column}").recreate_versions! && record.respond_to?(:"#{column}_processing")
|
13
|
-
record.update_attribute :"#{column}_processing", false
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
5
|
+
class ProcessAsset
|
6
|
+
include CarrierWave::Workers::ProcessAssetMixin
|
18
7
|
end # ProcessAsset
|
19
8
|
|
20
9
|
end # Workers
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
module CarrierWave
|
3
|
+
module Workers
|
4
|
+
|
5
|
+
module ProcessAssetMixin
|
6
|
+
include CarrierWave::Workers::Base
|
7
|
+
|
8
|
+
def self.included(base)
|
9
|
+
base.extend CarrierWave::Workers::ClassMethods
|
10
|
+
end
|
11
|
+
|
12
|
+
def perform(*args)
|
13
|
+
record = super(*args)
|
14
|
+
|
15
|
+
if record && record.send(:"#{column}").present?
|
16
|
+
record.send(:"process_#{column}_upload=", true)
|
17
|
+
if record.send(:"#{column}").recreate_versions! && record.respond_to?(:"#{column}_processing")
|
18
|
+
record.update_attribute :"#{column}_processing", false
|
19
|
+
end
|
20
|
+
else
|
21
|
+
when_not_ready
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
end # ProcessAssetMixin
|
26
|
+
|
27
|
+
end # Workers
|
28
|
+
end # Backgrounder
|
@@ -2,32 +2,8 @@
|
|
2
2
|
module CarrierWave
|
3
3
|
module Workers
|
4
4
|
|
5
|
-
class StoreAsset
|
6
|
-
|
7
|
-
|
8
|
-
def perform(*args)
|
9
|
-
record = super(*args)
|
10
|
-
|
11
|
-
if record && record.send(:"#{column}_tmp")
|
12
|
-
store_directories(record)
|
13
|
-
record.send :"process_#{column}_upload=", true
|
14
|
-
record.send :"#{column}_tmp=", nil
|
15
|
-
record.send :"#{column}_processing=", false if record.respond_to?(:"#{column}_processing")
|
16
|
-
File.open(cache_path) { |f| record.send :"#{column}=", f }
|
17
|
-
if record.save!
|
18
|
-
FileUtils.rm_r(tmp_directory, :force => true)
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
private
|
24
|
-
|
25
|
-
def store_directories(record)
|
26
|
-
asset, asset_tmp = record.send(:"#{column}"), record.send(:"#{column}_tmp")
|
27
|
-
cache_directory = File.expand_path(asset.cache_dir, asset.root)
|
28
|
-
@cache_path = File.join(cache_directory, asset_tmp)
|
29
|
-
@tmp_directory = File.join(cache_directory, asset_tmp.split("/").first)
|
30
|
-
end
|
5
|
+
class StoreAsset
|
6
|
+
include CarrierWave::Workers::StoreAssetMixin
|
31
7
|
end # StoreAsset
|
32
8
|
|
33
9
|
end # Workers
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
module CarrierWave
|
3
|
+
module Workers
|
4
|
+
|
5
|
+
module StoreAssetMixin
|
6
|
+
include CarrierWave::Workers::Base
|
7
|
+
|
8
|
+
def self.included(base)
|
9
|
+
base.extend CarrierWave::Workers::ClassMethods
|
10
|
+
end
|
11
|
+
|
12
|
+
attr_reader :cache_path, :tmp_directory
|
13
|
+
|
14
|
+
def perform(*args)
|
15
|
+
record = super(*args)
|
16
|
+
|
17
|
+
if record && record.send(:"#{column}_tmp")
|
18
|
+
store_directories(record)
|
19
|
+
record.send :"process_#{column}_upload=", true
|
20
|
+
record.send :"#{column}_tmp=", nil
|
21
|
+
record.send :"#{column}_processing=", false if record.respond_to?(:"#{column}_processing")
|
22
|
+
File.open(cache_path) { |f| record.send :"#{column}=", f }
|
23
|
+
if record.save!
|
24
|
+
FileUtils.rm_r(tmp_directory, :force => true)
|
25
|
+
end
|
26
|
+
else
|
27
|
+
when_not_ready
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
def store_directories(record)
|
34
|
+
asset, asset_tmp = record.send(:"#{column}"), record.send(:"#{column}_tmp")
|
35
|
+
cache_directory = File.expand_path(asset.cache_dir, asset.root)
|
36
|
+
@cache_path = File.join(cache_directory, asset_tmp)
|
37
|
+
@tmp_directory = File.join(cache_directory, asset_tmp.split("/").first)
|
38
|
+
end
|
39
|
+
|
40
|
+
end # StoreAssetMixin
|
41
|
+
|
42
|
+
end # Workers
|
43
|
+
end # Backgrounder
|
data/lib/backgrounder/workers.rb
CHANGED
@@ -1,3 +1,6 @@
|
|
1
1
|
require 'backgrounder/workers/base'
|
2
|
+
require 'backgrounder/workers/class_methods'
|
3
|
+
require 'backgrounder/workers/process_asset_mixin'
|
4
|
+
require 'backgrounder/workers/store_asset_mixin'
|
2
5
|
require 'backgrounder/workers/process_asset'
|
3
6
|
require 'backgrounder/workers/store_asset'
|
@@ -1,5 +1,6 @@
|
|
1
1
|
CarrierWave::Backgrounder.configure do |c|
|
2
2
|
c.backend :delayed_job, queue: :carrierwave
|
3
|
+
# c.backend :active_job, queue: :carrierwave
|
3
4
|
# c.backend :resque, queue: :carrierwave
|
4
5
|
# c.backend :sidekiq, queue: :carrierwave
|
5
6
|
# c.backend :girl_friday, queue: :carrierwave
|
@@ -2,7 +2,7 @@ require 'spec_helper'
|
|
2
2
|
require 'ostruct'
|
3
3
|
require 'backgrounder/orm/activemodel'
|
4
4
|
|
5
|
-
describe CarrierWave::Backgrounder::ORM::ActiveModel do
|
5
|
+
RSpec.describe CarrierWave::Backgrounder::ORM::ActiveModel do
|
6
6
|
before do
|
7
7
|
@mock_class = Class.new do
|
8
8
|
def self.before_save(method, opts); nil; end
|
@@ -20,7 +20,7 @@ describe CarrierWave::Backgrounder::ORM::ActiveModel do
|
|
20
20
|
describe '.store_in_background' do
|
21
21
|
context 'setting up callbacks' do
|
22
22
|
it 'creates an after_commit hook' do
|
23
|
-
@mock_class.
|
23
|
+
expect(@mock_class).to receive(:after_commit).with(:enqueue_avatar_background_job, :if => :enqueue_avatar_background_job?)
|
24
24
|
@mock_class.store_in_background :avatar
|
25
25
|
end
|
26
26
|
end
|
@@ -29,12 +29,12 @@ describe CarrierWave::Backgrounder::ORM::ActiveModel do
|
|
29
29
|
describe '.process_in_background' do
|
30
30
|
context 'setting up callbacks' do
|
31
31
|
it 'creates a before_save hook' do
|
32
|
-
@mock_class.
|
32
|
+
expect(@mock_class).to receive(:before_save).with(:set_avatar_processing, :if => :enqueue_avatar_background_job?)
|
33
33
|
@mock_class.process_in_background :avatar
|
34
34
|
end
|
35
35
|
|
36
36
|
it 'creates an after_save hook' do
|
37
|
-
@mock_class.
|
37
|
+
expect(@mock_class).to receive(:after_commit).with(:enqueue_avatar_background_job, :if => :enqueue_avatar_background_job?)
|
38
38
|
@mock_class.process_in_background :avatar
|
39
39
|
end
|
40
40
|
end
|
@@ -50,48 +50,48 @@ describe CarrierWave::Backgrounder::ORM::ActiveModel do
|
|
50
50
|
context 'mount_on option is set' do
|
51
51
|
before do
|
52
52
|
options_hash = {:avatar => {:mount_on => :some_other_column}}
|
53
|
-
@mock_class.
|
53
|
+
expect(@mock_class).to receive(:uploader_options).and_return(options_hash)
|
54
54
|
end
|
55
55
|
|
56
56
|
it "returns true if alternate column is changed" do
|
57
|
-
instance.
|
58
|
-
expect(instance.avatar_updated?).to
|
57
|
+
expect(instance).to receive(:some_other_column_changed?).and_return(true)
|
58
|
+
expect(instance.avatar_updated?).to be_truthy
|
59
59
|
end
|
60
60
|
end
|
61
61
|
|
62
62
|
it "returns true if process_avatar_upload is false" do
|
63
|
-
instance.
|
64
|
-
expect(instance.enqueue_avatar_background_job?).to
|
63
|
+
expect(instance).to receive(:process_avatar_upload)
|
64
|
+
expect(instance.enqueue_avatar_background_job?).to be_truthy
|
65
65
|
end
|
66
66
|
|
67
67
|
it "calls column_changed?" do
|
68
|
-
instance.
|
69
|
-
instance.
|
70
|
-
expect(instance.enqueue_avatar_background_job?).to
|
68
|
+
expect(instance).to receive(:process_avatar_upload).and_return(false)
|
69
|
+
expect(instance).to receive(:avatar_changed?)
|
70
|
+
expect(instance.enqueue_avatar_background_job?).to be_truthy
|
71
71
|
end
|
72
72
|
|
73
73
|
it "calls previous_changes" do
|
74
|
-
instance.
|
75
|
-
instance.
|
76
|
-
instance.
|
77
|
-
expect(instance.enqueue_avatar_background_job?).to
|
74
|
+
expect(instance).to receive(:process_avatar_upload).and_return(false)
|
75
|
+
expect(instance).to receive(:avatar_changed?).and_return(false)
|
76
|
+
expect(instance).to receive(:previous_changes).and_return({:avatar => true})
|
77
|
+
expect(instance.enqueue_avatar_background_job?).to be_truthy
|
78
78
|
end
|
79
79
|
|
80
80
|
it "calls avatar_remote_url" do
|
81
|
-
instance.
|
82
|
-
instance.
|
83
|
-
instance.
|
84
|
-
instance.
|
85
|
-
expect(instance.enqueue_avatar_background_job?).to
|
81
|
+
expect(instance).to receive(:process_avatar_upload).and_return(false)
|
82
|
+
expect(instance).to receive(:avatar_changed?).and_return(false)
|
83
|
+
expect(instance).to receive(:previous_changes).and_return({})
|
84
|
+
expect(instance).to receive(:remote_avatar_url).and_return('yup')
|
85
|
+
expect(instance.enqueue_avatar_background_job?).to be_truthy
|
86
86
|
end
|
87
87
|
|
88
88
|
it "calls avatar_cache" do
|
89
|
-
instance.
|
90
|
-
instance.
|
91
|
-
instance.
|
92
|
-
instance.
|
93
|
-
instance.
|
94
|
-
expect(instance.enqueue_avatar_background_job?).to
|
89
|
+
expect(instance).to receive(:process_avatar_upload).and_return(false)
|
90
|
+
expect(instance).to receive(:avatar_changed?).and_return(false)
|
91
|
+
expect(instance).to receive(:previous_changes).and_return({})
|
92
|
+
expect(instance).to receive(:remote_avatar_url).and_return(nil)
|
93
|
+
expect(instance).to receive(:avatar_cache).and_return('yup')
|
94
|
+
expect(instance.enqueue_avatar_background_job?).to be_truthy
|
95
95
|
end
|
96
96
|
end
|
97
97
|
end
|
@@ -3,7 +3,7 @@ require 'support/backend_constants'
|
|
3
3
|
require 'support/mock_worker'
|
4
4
|
|
5
5
|
module CarrierWave::Backgrounder
|
6
|
-
describe Support::Backends do
|
6
|
+
RSpec.describe Support::Backends do
|
7
7
|
let(:mock_module) { Module.new }
|
8
8
|
|
9
9
|
before do
|
@@ -31,25 +31,43 @@ module CarrierWave::Backgrounder
|
|
31
31
|
describe '#enqueue_for_backend' do
|
32
32
|
let!(:worker) { MockWorker.new('FakeClass', 1, :image) }
|
33
33
|
|
34
|
+
context 'active_job' do
|
35
|
+
let(:args) { ['FakeClass', 1, :image] }
|
36
|
+
|
37
|
+
it 'invokes perform_later with string arguments' do
|
38
|
+
expect(MockWorker).to receive(:perform_later).with('FakeClass', '1', 'image')
|
39
|
+
mock_module.backend :active_job
|
40
|
+
mock_module.enqueue_for_backend(MockWorker, *args)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
34
44
|
context 'delayed_job' do
|
35
45
|
before do
|
36
46
|
@mock_worker = Class.new do
|
37
47
|
def self.perform(*args); new(*args).perform; end
|
38
48
|
end
|
39
49
|
|
40
|
-
MockWorker.
|
50
|
+
allow(MockWorker).to receive(:new).and_return(worker)
|
41
51
|
end
|
42
52
|
|
43
53
|
context 'queue column exists' do
|
44
|
-
it '
|
54
|
+
it 'does not pass the queue name if none passed to #backend' do
|
45
55
|
mock_module.backend :delayed_job
|
46
|
-
Delayed::Job.
|
56
|
+
expect(Delayed::Job).to receive(:enqueue).with(worker, {})
|
47
57
|
mock_module.enqueue_for_backend MockWorker, 'FakeClass', 1, :image
|
48
58
|
end
|
49
59
|
|
50
60
|
it 'sets the queue name to the queue name passed to #backend' do
|
51
61
|
mock_module.backend :delayed_job, :queue => :awesome_queue
|
52
|
-
Delayed::Job.
|
62
|
+
expect(Delayed::Job).to receive(:enqueue).with(worker, :queue => :awesome_queue)
|
63
|
+
mock_module.enqueue_for_backend MockWorker, 'FakeClass', 1, :image
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
context 'priority set in config' do
|
68
|
+
it 'sets the priority which is passed to #backend' do
|
69
|
+
mock_module.backend :delayed_job, :priority => 5
|
70
|
+
expect(Delayed::Job).to receive(:enqueue).with(worker, :priority => 5)
|
53
71
|
mock_module.enqueue_for_backend MockWorker, 'FakeClass', 1, :image
|
54
72
|
end
|
55
73
|
end
|
@@ -57,7 +75,7 @@ module CarrierWave::Backgrounder
|
|
57
75
|
context 'queue column does not exist' do
|
58
76
|
before do
|
59
77
|
column_names = Delayed::Job.column_names.tap { |cn| cn.delete('queue') }
|
60
|
-
Delayed::Job.
|
78
|
+
allow(Delayed::Job).to receive(:column_names).and_return(column_names)
|
61
79
|
Delayed::Job.class_eval { remove_method(:queue) }
|
62
80
|
end
|
63
81
|
|
@@ -67,14 +85,14 @@ module CarrierWave::Backgrounder
|
|
67
85
|
|
68
86
|
it 'does not pass a queue name if none passed to #backend' do
|
69
87
|
mock_module.backend :delayed_job
|
70
|
-
Delayed::Job.
|
88
|
+
expect(Delayed::Job).to receive(:enqueue).with(worker, {})
|
71
89
|
mock_module.enqueue_for_backend MockWorker, 'FakeClass', 1, :image
|
72
90
|
end
|
73
91
|
|
74
92
|
it 'does not pass a queue name and logs a warning message if a queue name is passed to #backend' do
|
75
93
|
mock_module.backend :delayed_job, :queue => :awesome_queue
|
76
|
-
|
77
|
-
|
94
|
+
expect(Rails.logger).to receive(:warn).with(instance_of(String))
|
95
|
+
expect(Delayed::Job).to receive(:enqueue).with(worker, {})
|
78
96
|
mock_module.enqueue_for_backend MockWorker, 'FakeClass', 1, :image
|
79
97
|
end
|
80
98
|
end
|
@@ -84,7 +102,7 @@ module CarrierWave::Backgrounder
|
|
84
102
|
let(:args) { [MockWorker, 'FakeClass', 1, :image] }
|
85
103
|
|
86
104
|
before do
|
87
|
-
Resque.
|
105
|
+
allow(Resque).to receive(:enqueue).with(*args)
|
88
106
|
end
|
89
107
|
|
90
108
|
it 'sets a variable with the queue name, defaults to :carrierwave' do
|
@@ -104,21 +122,31 @@ module CarrierWave::Backgrounder
|
|
104
122
|
let(:args) { ['FakeClass', 1, :image] }
|
105
123
|
|
106
124
|
it 'invokes client_push on the class with passed args' do
|
107
|
-
MockSidekiqWorker.
|
125
|
+
expect(MockSidekiqWorker).to receive(:client_push).with({ 'class' => MockSidekiqWorker, 'args' => args.map(&:to_s) })
|
108
126
|
mock_module.backend :sidekiq
|
109
127
|
mock_module.enqueue_for_backend(MockSidekiqWorker, *args)
|
110
128
|
end
|
111
129
|
|
112
130
|
it 'invokes client_push and includes the options passed to backend' do
|
113
|
-
MockSidekiqWorker.
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
131
|
+
expect(MockSidekiqWorker).to receive(:client_push).with({ 'class' => MockSidekiqWorker,
|
132
|
+
'retry' => false,
|
133
|
+
'timeout' => 60,
|
134
|
+
'queue' => :awesome_queue,
|
135
|
+
'args' => args.map(&:to_s) })
|
118
136
|
options = {:retry => false, :timeout => 60, :queue => :awesome_queue}
|
119
137
|
mock_module.backend :sidekiq, options
|
120
138
|
mock_module.enqueue_for_backend(MockSidekiqWorker, *args)
|
121
139
|
end
|
140
|
+
|
141
|
+
it 'does not override queue name if set it worker' do
|
142
|
+
expect(MockNamedSidekiqWorker).to receive(:client_push).with({ 'class' => MockNamedSidekiqWorker,
|
143
|
+
'retry' => false,
|
144
|
+
'timeout' => 60,
|
145
|
+
'args' => args.map(&:to_s) })
|
146
|
+
options = {:retry => false, :timeout => 60}
|
147
|
+
mock_module.backend :sidekiq, options
|
148
|
+
mock_module.enqueue_for_backend(MockNamedSidekiqWorker, *args)
|
149
|
+
end
|
122
150
|
end
|
123
151
|
|
124
152
|
context 'girl_friday' do
|
@@ -126,20 +154,20 @@ module CarrierWave::Backgrounder
|
|
126
154
|
|
127
155
|
it 'instantiates a GirlFriday work queue if one does not exist' do
|
128
156
|
mock_module.backend :girl_friday
|
129
|
-
GirlFriday::WorkQueue.
|
157
|
+
expect(GirlFriday::WorkQueue).to receive(:new).with(:carrierwave, {}).and_return([])
|
130
158
|
mock_module.enqueue_for_backend(*args)
|
131
159
|
end
|
132
160
|
|
133
161
|
it 'instantiates a GirlFriday work queue passing the args to the queue' do
|
134
162
|
mock_module.backend :girl_friday, :queue => :awesome_queue, :size => 3
|
135
|
-
GirlFriday::WorkQueue.
|
163
|
+
expect(GirlFriday::WorkQueue).to receive(:new).with(:awesome_queue, {:size => 3}).and_return([])
|
136
164
|
mock_module.enqueue_for_backend(*args)
|
137
165
|
end
|
138
166
|
|
139
167
|
it 'does not instantiate a GirlFriday work queue if one exists' do
|
140
168
|
mock_module.backend :girl_friday
|
141
169
|
mock_module.instance_variable_set('@girl_friday_queue', [])
|
142
|
-
GirlFriday::WorkQueue.
|
170
|
+
expect(GirlFriday::WorkQueue).to receive(:new).never
|
143
171
|
mock_module.enqueue_for_backend(*args)
|
144
172
|
end
|
145
173
|
|
@@ -154,12 +182,12 @@ module CarrierWave::Backgrounder
|
|
154
182
|
|
155
183
|
context 'sucker_punch' do
|
156
184
|
let(:args) { [MockWorker, 'FakeClass', 1, :image] }
|
157
|
-
let(:job) {
|
185
|
+
let(:job) { double('job') }
|
158
186
|
|
159
187
|
it 'invokes a new worker' do
|
160
|
-
MockWorker.
|
161
|
-
worker.
|
162
|
-
job.
|
188
|
+
expect(MockWorker).to receive(:new).and_return(worker)
|
189
|
+
expect(worker).to receive(:async).and_return(job)
|
190
|
+
expect(job).to receive(:perform).with('FakeClass', 1, :image)
|
163
191
|
mock_module.backend :sucker_punch
|
164
192
|
mock_module.enqueue_for_backend(*args)
|
165
193
|
end
|
@@ -168,7 +196,7 @@ module CarrierWave::Backgrounder
|
|
168
196
|
context 'qu' do
|
169
197
|
let(:args) { [MockWorker, 'FakeClass', 1, :image] }
|
170
198
|
before do
|
171
|
-
Qu.
|
199
|
+
allow(Qu).to receive(:enqueue).with(*args)
|
172
200
|
end
|
173
201
|
|
174
202
|
it 'sets a variable with the queue name, defaults to :carrierwave' do
|
@@ -186,7 +214,7 @@ module CarrierWave::Backgrounder
|
|
186
214
|
|
187
215
|
context 'qc' do
|
188
216
|
it 'calls enqueue with the passed args' do
|
189
|
-
QC.
|
217
|
+
expect(QC).to receive(:enqueue).with("MockWorker.perform", 'FakeClass', 1, 'image')
|
190
218
|
mock_module.backend :qc
|
191
219
|
mock_module.enqueue_for_backend(MockWorker, 'FakeClass', 1, :image)
|
192
220
|
end
|
@@ -194,14 +222,13 @@ module CarrierWave::Backgrounder
|
|
194
222
|
|
195
223
|
context 'immediate' do
|
196
224
|
it 'instantiates a worker passing the args and calls perform' do
|
197
|
-
worker =
|
198
|
-
MockWorker.
|
199
|
-
worker.
|
225
|
+
worker = double('Worker')
|
226
|
+
expect(MockWorker).to receive(:new).with('FakeClass', 1, :image).and_return(worker)
|
227
|
+
expect(worker).to receive(:perform)
|
200
228
|
mock_module.backend :immediate
|
201
229
|
mock_module.enqueue_for_backend(MockWorker, 'FakeClass', 1, :image)
|
202
230
|
end
|
203
231
|
end
|
204
|
-
|
205
232
|
end
|
206
233
|
end
|
207
234
|
end
|
@@ -2,55 +2,55 @@
|
|
2
2
|
require 'spec_helper'
|
3
3
|
require 'backgrounder/workers/process_asset'
|
4
4
|
|
5
|
-
describe CarrierWave::Workers::ProcessAsset do
|
5
|
+
RSpec.describe CarrierWave::Workers::ProcessAsset do
|
6
6
|
let(:worker_class) { CarrierWave::Workers::ProcessAsset }
|
7
|
-
let(:user) {
|
7
|
+
let(:user) { double('User') }
|
8
8
|
let!(:worker) { worker_class.new(user, '22', :image) }
|
9
9
|
|
10
10
|
describe ".perform" do
|
11
11
|
it 'creates a new instance and calls perform' do
|
12
12
|
args = [user, '22', :image]
|
13
|
-
worker_class.
|
14
|
-
worker_class.
|
13
|
+
expect(worker_class).to receive(:new).with(*args).and_return(worker)
|
14
|
+
expect_any_instance_of(worker_class).to receive(:perform)
|
15
15
|
|
16
16
|
worker_class.perform(*args)
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
20
20
|
describe "#perform" do
|
21
|
-
let(:image) {
|
21
|
+
let(:image) { double('UserAsset') }
|
22
22
|
|
23
23
|
before do
|
24
|
-
user.
|
25
|
-
user.
|
26
|
-
user.
|
27
|
-
image.
|
24
|
+
allow(user).to receive(:find).with('22').and_return(user).once
|
25
|
+
allow(user).to receive(:image).twice.and_return(image)
|
26
|
+
allow(user).to receive(:process_image_upload=).with(true).once
|
27
|
+
allow(image).to receive(:recreate_versions!).once.and_return(true)
|
28
28
|
end
|
29
29
|
|
30
30
|
it 'processes versions with image_processing column' do
|
31
|
-
user.
|
32
|
-
user.
|
31
|
+
expect(user).to receive(:respond_to?).with(:image_processing).once.and_return(true)
|
32
|
+
expect(user).to receive(:update_attribute).with(:image_processing, false).once
|
33
33
|
worker.perform
|
34
34
|
end
|
35
35
|
|
36
36
|
it 'processes versions without image_processing column' do
|
37
|
-
user.
|
38
|
-
user.
|
37
|
+
expect(user).to receive(:respond_to?).with(:image_processing).once.and_return(false)
|
38
|
+
expect(user).to receive(:update_attribute).never
|
39
39
|
worker.perform
|
40
40
|
end
|
41
41
|
end
|
42
42
|
|
43
43
|
describe '#perform with args' do
|
44
|
-
let(:admin) {
|
45
|
-
let(:avatar) {
|
44
|
+
let(:admin) { double('Admin') }
|
45
|
+
let(:avatar) { double('AdminAsset') }
|
46
46
|
let(:worker) { worker_class.new }
|
47
47
|
|
48
48
|
before do
|
49
|
-
admin.
|
50
|
-
admin.
|
51
|
-
admin.
|
52
|
-
admin.
|
53
|
-
avatar.
|
49
|
+
allow(admin).to receive(:find).with('23').and_return(admin).once
|
50
|
+
allow(admin).to receive(:avatar).twice.and_return(avatar)
|
51
|
+
allow(admin).to receive(:process_avatar_upload=).with(true).once
|
52
|
+
allow(admin).to receive(:respond_to?).with(:avatar_processing).once.and_return(false)
|
53
|
+
allow(avatar).to receive(:recreate_versions!).once.and_return(true)
|
54
54
|
|
55
55
|
worker.perform admin, '23', :avatar
|
56
56
|
end
|
@@ -2,75 +2,75 @@
|
|
2
2
|
require 'spec_helper'
|
3
3
|
require 'backgrounder/workers/store_asset'
|
4
4
|
|
5
|
-
describe CarrierWave::Workers::StoreAsset do
|
5
|
+
RSpec.describe CarrierWave::Workers::StoreAsset do
|
6
6
|
let(:fixtures_path) { File.expand_path('../fixtures/images', __FILE__) }
|
7
7
|
let(:worker_class) { CarrierWave::Workers::StoreAsset }
|
8
|
-
let(:user) {
|
8
|
+
let(:user) { double('User') }
|
9
9
|
let!(:worker) { worker_class.new(user, '22', :image) }
|
10
10
|
|
11
11
|
describe ".perform" do
|
12
12
|
it 'creates a new instance and calls perform' do
|
13
13
|
args = [user, '22', :image]
|
14
|
-
worker_class.
|
15
|
-
worker_class.
|
14
|
+
expect(worker_class).to receive(:new).with(*args).and_return(worker)
|
15
|
+
expect_any_instance_of(worker_class).to receive(:perform)
|
16
16
|
worker_class.perform(*args)
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
20
20
|
describe "#perform" do
|
21
|
-
let(:image) {
|
21
|
+
let(:image) { double('UserAsset') }
|
22
22
|
|
23
23
|
before do
|
24
|
-
image.
|
25
|
-
image.
|
26
|
-
user.
|
27
|
-
user.
|
28
|
-
user.
|
29
|
-
user.
|
30
|
-
user.
|
31
|
-
user.
|
24
|
+
allow(image).to receive(:root).once.and_return(File.expand_path('..', __FILE__))
|
25
|
+
allow(image).to receive(:cache_dir).once.and_return('fixtures')
|
26
|
+
allow(user).to receive(:image_tmp).twice.and_return('images/test.jpg')
|
27
|
+
allow(user).to receive(:find).with('22').once.and_return(user)
|
28
|
+
allow(user).to receive(:image).once.and_return(image)
|
29
|
+
allow(user).to receive(:process_image_upload=).with(true).once
|
30
|
+
allow(user).to receive(:image=).once
|
31
|
+
allow(user).to receive(:image_tmp=).with(nil).once
|
32
32
|
end
|
33
33
|
|
34
34
|
it 'removes tmp directory on success' do
|
35
|
-
FileUtils.
|
36
|
-
user.
|
35
|
+
expect(FileUtils).to receive(:rm_r).with(fixtures_path, :force => true).once
|
36
|
+
expect(user).to receive(:save!).once.and_return(true)
|
37
37
|
worker.perform
|
38
38
|
end
|
39
39
|
|
40
40
|
it 'does not remove the tmp directory if save! fails' do
|
41
|
-
FileUtils.
|
42
|
-
user.
|
41
|
+
expect(FileUtils).to receive(:rm_r).never
|
42
|
+
expect(user).to receive(:save!).once.and_return(false)
|
43
43
|
worker.perform
|
44
44
|
end
|
45
45
|
|
46
46
|
it 'sets the cache_path' do
|
47
|
-
user.
|
47
|
+
expect(user).to receive(:save!).once.and_return(false)
|
48
48
|
worker.perform
|
49
49
|
expect(worker.cache_path).to eql(fixtures_path + '/test.jpg')
|
50
50
|
end
|
51
51
|
|
52
52
|
it 'sets the tmp_directory' do
|
53
|
-
user.
|
53
|
+
expect(user).to receive(:save!).once.and_return(false)
|
54
54
|
worker.perform
|
55
55
|
expect(worker.tmp_directory).to eql(fixtures_path)
|
56
56
|
end
|
57
57
|
end
|
58
58
|
|
59
59
|
describe '#perform with args' do
|
60
|
-
let(:admin) {
|
61
|
-
let(:image) {
|
60
|
+
let(:admin) { double('Admin') }
|
61
|
+
let(:image) { double('AdminAsset') }
|
62
62
|
let(:worker) { worker_class.new }
|
63
63
|
|
64
64
|
before do
|
65
|
-
image.
|
66
|
-
image.
|
67
|
-
admin.
|
68
|
-
admin.
|
69
|
-
admin.
|
70
|
-
admin.
|
71
|
-
admin.
|
72
|
-
admin.
|
73
|
-
admin.
|
65
|
+
allow(image).to receive(:root).once.and_return(File.expand_path('..', __FILE__))
|
66
|
+
allow(image).to receive(:cache_dir).once.and_return('fixtures')
|
67
|
+
allow(admin).to receive(:avatar_tmp).twice.and_return('images/test.jpg')
|
68
|
+
allow(admin).to receive(:find).with('23').once.and_return(admin)
|
69
|
+
allow(admin).to receive(:avatar).once.and_return(image)
|
70
|
+
allow(admin).to receive(:process_avatar_upload=).with(true).once
|
71
|
+
allow(admin).to receive(:avatar=).once
|
72
|
+
allow(admin).to receive(:avatar_tmp=).with(nil).once
|
73
|
+
allow(admin).to receive(:save!).once.and_return(false)
|
74
74
|
worker.perform admin, '23', :avatar
|
75
75
|
end
|
76
76
|
|
@@ -88,15 +88,15 @@ describe CarrierWave::Workers::StoreAsset do
|
|
88
88
|
end
|
89
89
|
|
90
90
|
describe '#store_directories' do
|
91
|
-
let(:record) {
|
91
|
+
let(:record) { double('Record') }
|
92
92
|
|
93
93
|
context 'cache_path' do
|
94
94
|
it 'sets the cache_path correctly if a full path is set for the cache_dir' do
|
95
95
|
root = '/Users/lar/Sites/bunker/public'
|
96
96
|
cache_dir = '/Users/lar/Sites/bunker/tmp/uploads'
|
97
|
-
asset =
|
98
|
-
record.
|
99
|
-
record.
|
97
|
+
asset = double(:cache_dir => cache_dir, :root => root)
|
98
|
+
expect(record).to receive(:image).and_return(asset)
|
99
|
+
expect(record).to receive(:image_tmp).and_return('images/test.jpg')
|
100
100
|
worker.send :store_directories, record
|
101
101
|
expect(worker.cache_path).to eql('/Users/lar/Sites/bunker/tmp/uploads/images/test.jpg')
|
102
102
|
end
|
@@ -104,9 +104,9 @@ describe CarrierWave::Workers::StoreAsset do
|
|
104
104
|
it 'sets the cache_path correctly if a partial path is set for cache_dir' do
|
105
105
|
root = '/Users/lar/Sites/bunker/public'
|
106
106
|
cache_dir = 'uploads/tmp'
|
107
|
-
asset =
|
108
|
-
record.
|
109
|
-
record.
|
107
|
+
asset = double(:cache_dir => cache_dir, :root => root)
|
108
|
+
expect(record).to receive(:image).and_return(asset)
|
109
|
+
expect(record).to receive(:image_tmp).and_return('images/test.jpg')
|
110
110
|
worker.send :store_directories, record
|
111
111
|
expect(worker.cache_path).to eql('/Users/lar/Sites/bunker/public/uploads/tmp/images/test.jpg')
|
112
112
|
end
|
@@ -116,9 +116,9 @@ describe CarrierWave::Workers::StoreAsset do
|
|
116
116
|
it 'sets the tmp_directory correctly if a full path is set for the cache_dir' do
|
117
117
|
root = '/Users/lar/Sites/bunker/public'
|
118
118
|
cache_dir = '/Users/lar/Sites/bunker/tmp/uploads'
|
119
|
-
asset =
|
120
|
-
record.
|
121
|
-
record.
|
119
|
+
asset = double(:cache_dir => cache_dir, :root => root)
|
120
|
+
expect(record).to receive(:image).and_return(asset)
|
121
|
+
expect(record).to receive(:image_tmp).and_return('images/test.jpg')
|
122
122
|
worker.send :store_directories, record
|
123
123
|
expect(worker.tmp_directory).to eql('/Users/lar/Sites/bunker/tmp/uploads/images')
|
124
124
|
end
|
@@ -126,9 +126,9 @@ describe CarrierWave::Workers::StoreAsset do
|
|
126
126
|
it 'sets the tmp_directory correctly if a partial path is set for cache_dir' do
|
127
127
|
root = '/Users/lar/Sites/bunker/public'
|
128
128
|
cache_dir = 'uploads/tmp'
|
129
|
-
asset =
|
130
|
-
record.
|
131
|
-
record.
|
129
|
+
asset = double(:cache_dir => cache_dir, :root => root)
|
130
|
+
expect(record).to receive(:image).and_return(asset)
|
131
|
+
expect(record).to receive(:image_tmp).and_return('images/test.jpg')
|
132
132
|
worker.send :store_directories, record
|
133
133
|
expect(worker.tmp_directory).to eql('/Users/lar/Sites/bunker/public/uploads/tmp/images')
|
134
134
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -34,6 +34,7 @@ module Sidekiq
|
|
34
34
|
|
35
35
|
module ClassMethods
|
36
36
|
def sidekiq_options(opts = {})
|
37
|
+
opts
|
37
38
|
end
|
38
39
|
|
39
40
|
def client_push(item)
|
@@ -52,6 +53,6 @@ end
|
|
52
53
|
|
53
54
|
module Rails
|
54
55
|
def self.logger
|
55
|
-
@logger ||=
|
56
|
+
@logger ||= Logger.new(STDOUT)
|
56
57
|
end
|
57
58
|
end
|
data/spec/support/mock_worker.rb
CHANGED
metadata
CHANGED
@@ -1,81 +1,73 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: carrierwave_backgrounder
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Larry Sprock
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-07-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: carrierwave
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '0.5'
|
20
|
+
- - "<"
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '2.2'
|
20
23
|
type: :runtime
|
21
24
|
prerelease: false
|
22
25
|
version_requirements: !ruby/object:Gem::Requirement
|
23
26
|
requirements:
|
24
|
-
- -
|
27
|
+
- - ">="
|
25
28
|
- !ruby/object:Gem::Version
|
26
29
|
version: '0.5'
|
27
|
-
-
|
28
|
-
name: rspec
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - ~>
|
30
|
+
- - "<"
|
32
31
|
- !ruby/object:Gem::Version
|
33
|
-
version: 2.
|
34
|
-
type: :development
|
35
|
-
prerelease: false
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - ~>
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: 2.12.0
|
32
|
+
version: '2.2'
|
41
33
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
34
|
+
name: rspec
|
43
35
|
requirement: !ruby/object:Gem::Requirement
|
44
36
|
requirements:
|
45
|
-
- - ~>
|
37
|
+
- - "~>"
|
46
38
|
- !ruby/object:Gem::Version
|
47
|
-
version:
|
39
|
+
version: 3.10.0
|
48
40
|
type: :development
|
49
41
|
prerelease: false
|
50
42
|
version_requirements: !ruby/object:Gem::Requirement
|
51
43
|
requirements:
|
52
|
-
- - ~>
|
44
|
+
- - "~>"
|
53
45
|
- !ruby/object:Gem::Version
|
54
|
-
version:
|
46
|
+
version: 3.10.0
|
55
47
|
- !ruby/object:Gem::Dependency
|
56
48
|
name: rake
|
57
49
|
requirement: !ruby/object:Gem::Requirement
|
58
50
|
requirements:
|
59
|
-
- -
|
51
|
+
- - ">="
|
60
52
|
- !ruby/object:Gem::Version
|
61
53
|
version: '0'
|
62
54
|
type: :development
|
63
55
|
prerelease: false
|
64
56
|
version_requirements: !ruby/object:Gem::Requirement
|
65
57
|
requirements:
|
66
|
-
- -
|
58
|
+
- - ">="
|
67
59
|
- !ruby/object:Gem::Version
|
68
60
|
version: '0'
|
69
|
-
description:
|
61
|
+
description:
|
70
62
|
email:
|
71
63
|
- larry@lucidbleu.com
|
72
64
|
executables: []
|
73
65
|
extensions: []
|
74
66
|
extra_rdoc_files: []
|
75
67
|
files:
|
76
|
-
- .gitignore
|
77
|
-
- .rspec
|
78
|
-
- .travis.yml
|
68
|
+
- ".gitignore"
|
69
|
+
- ".rspec"
|
70
|
+
- ".travis.yml"
|
79
71
|
- CHANGELOG.md
|
80
72
|
- Gemfile
|
81
73
|
- README.md
|
@@ -90,8 +82,11 @@ files:
|
|
90
82
|
- lib/backgrounder/version.rb
|
91
83
|
- lib/backgrounder/workers.rb
|
92
84
|
- lib/backgrounder/workers/base.rb
|
85
|
+
- lib/backgrounder/workers/class_methods.rb
|
93
86
|
- lib/backgrounder/workers/process_asset.rb
|
87
|
+
- lib/backgrounder/workers/process_asset_mixin.rb
|
94
88
|
- lib/backgrounder/workers/store_asset.rb
|
89
|
+
- lib/backgrounder/workers/store_asset_mixin.rb
|
95
90
|
- lib/carrierwave_backgrounder.rb
|
96
91
|
- lib/generators/carrierwave_backgrounder/USAGE
|
97
92
|
- lib/generators/carrierwave_backgrounder/install_generator.rb
|
@@ -109,24 +104,23 @@ homepage: https://github.com/lardawge/carrierwave_backgrounder
|
|
109
104
|
licenses:
|
110
105
|
- MIT
|
111
106
|
metadata: {}
|
112
|
-
post_install_message:
|
107
|
+
post_install_message:
|
113
108
|
rdoc_options: []
|
114
109
|
require_paths:
|
115
110
|
- lib
|
116
111
|
required_ruby_version: !ruby/object:Gem::Requirement
|
117
112
|
requirements:
|
118
|
-
- -
|
113
|
+
- - ">="
|
119
114
|
- !ruby/object:Gem::Version
|
120
115
|
version: '0'
|
121
116
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
122
117
|
requirements:
|
123
|
-
- -
|
118
|
+
- - ">="
|
124
119
|
- !ruby/object:Gem::Version
|
125
120
|
version: '0'
|
126
121
|
requirements: []
|
127
|
-
|
128
|
-
|
129
|
-
signing_key:
|
122
|
+
rubygems_version: 3.1.6
|
123
|
+
signing_key:
|
130
124
|
specification_version: 4
|
131
125
|
summary: Offload CarrierWave's image processing and storage to a background process
|
132
126
|
using Delayed Job, Resque, Sidekiq, Qu, Queue Classic or Girl Friday
|