carrierwave_backgrounder 0.4.1 → 0.4.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/CHANGELOG.md +9 -1
- data/README.md +5 -4
- data/carrierwave_backgrounder.gemspec +1 -2
- data/lib/backgrounder/delay.rb +2 -1
- data/lib/backgrounder/support/backends.rb +12 -5
- data/lib/backgrounder/version.rb +1 -1
- data/lib/backgrounder/workers/process_asset.rb +1 -1
- 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 +46 -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 +16 -30
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ea7ccc20dfbd12f0d5ca49a22aed4df13af757fe
|
4
|
+
data.tar.gz: 9483744462a3c7de8ec21c01c033fe5c7722c1b7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a9ccbcd89a9f510723a6f512197cc3595ffe4bfa00a9ea21c3c1e6b2530fee1901b47670d1bf0e6e44427d40fd71c83064eab553f09c7e1d0b75cb3283d0291e
|
7
|
+
data.tar.gz: 437d6b11a142e94ae83699672299bf1a3da800846f4465aa557027bb4026970619ee425b6fc63ca7e5e11687a9dfe417c08213ddbc9300ed826a8361a95f6e61
|
data/.gitignore
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,4 +1,13 @@
|
|
1
1
|
|
2
|
+
## 0.4.2
|
3
|
+
|
4
|
+
### enhancements
|
5
|
+
* Allow overridden worker to set a queue name
|
6
|
+
* [#190] Respect Carrierwave's enable_processing flag if set to false [jherdman]
|
7
|
+
|
8
|
+
### bug fixes
|
9
|
+
* [#216] Fix for NoMethodError: undefined method `read' for nil:NilClass [kntmrkm]
|
10
|
+
|
2
11
|
## 0.4.1
|
3
12
|
|
4
13
|
### enhancements
|
@@ -88,4 +97,3 @@
|
|
88
97
|
### bug fixes
|
89
98
|
* Girl Friday incorrectly referenses class #92
|
90
99
|
* Add documentation for testing with rspec #84.
|
91
|
-
|
data/README.md
CHANGED
@@ -34,7 +34,7 @@ Backgrounder::ORM::Base::store_in_background
|
|
34
34
|
|
35
35
|
## Installation and Usage
|
36
36
|
|
37
|
-
These instructions assume you have previously set up [CarrierWave](https://github.com/jnicklas/carrierwave) and your
|
37
|
+
These instructions assume you have previously set up [CarrierWave](https://github.com/jnicklas/carrierwave) and your queuing lib of choice.
|
38
38
|
|
39
39
|
In Rails, add the following your Gemfile:
|
40
40
|
|
@@ -74,10 +74,11 @@ mount_uploader :avatar, AvatarUploader
|
|
74
74
|
process_in_background :avatar
|
75
75
|
```
|
76
76
|
|
77
|
-
Optionally you can add a column to the database which will be set to
|
77
|
+
Optionally you can add a column to the database which will be set to `true` when
|
78
|
+
the background processing is started and to `false` when the background processing is complete.
|
78
79
|
|
79
80
|
```ruby
|
80
|
-
add_column :users, :avatar_processing, :boolean
|
81
|
+
add_column :users, :avatar_processing, :boolean, null: false, default: false
|
81
82
|
```
|
82
83
|
|
83
84
|
### To use store_in_background
|
@@ -114,7 +115,7 @@ This must be set before you assign an upload:
|
|
114
115
|
```
|
115
116
|
|
116
117
|
### Override worker
|
117
|
-
To
|
118
|
+
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
119
|
second argument:
|
119
120
|
|
120
121
|
```ruby
|
@@ -19,7 +19,6 @@ Gem::Specification.new do |s|
|
|
19
19
|
|
20
20
|
s.add_dependency "carrierwave", ["~> 0.5"]
|
21
21
|
|
22
|
-
s.add_development_dependency "rspec", ["~>
|
23
|
-
s.add_development_dependency "mocha", ["~> 0.13.0"]
|
22
|
+
s.add_development_dependency "rspec", ["~> 3.1.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
|
|
@@ -23,10 +23,14 @@ module CarrierWave
|
|
23
23
|
private
|
24
24
|
|
25
25
|
def enqueue_delayed_job(worker, *args)
|
26
|
+
worker_args = {}
|
26
27
|
if ::Delayed::Job.new.respond_to?(:queue)
|
27
|
-
|
28
|
+
worker_args[:queue] = queue_options[:queue] if queue_options[:queue]
|
29
|
+
worker_args[:priority] = queue_options[:priority] if queue_options[:priority]
|
30
|
+
::Delayed::Job.enqueue worker.new(*args), worker_args
|
28
31
|
else
|
29
|
-
|
32
|
+
worker_args[:priority] = queue_options[:priority] if queue_options[:priority]
|
33
|
+
::Delayed::Job.enqueue worker.new(*args), worker_args
|
30
34
|
if queue_options[:queue]
|
31
35
|
::Rails.logger.warn("Queue name given but no queue column exists for Delayed::Job")
|
32
36
|
end
|
@@ -39,7 +43,8 @@ module CarrierWave
|
|
39
43
|
end
|
40
44
|
|
41
45
|
def enqueue_sidekiq(worker, *args)
|
42
|
-
|
46
|
+
override_queue_name = worker.sidekiq_options['queue'] == 'default' || worker.sidekiq_options['queue'].nil?
|
47
|
+
args = sidekiq_queue_options(override_queue_name, 'class' => worker, 'args' => args)
|
43
48
|
worker.client_push(args)
|
44
49
|
end
|
45
50
|
|
@@ -69,8 +74,10 @@ module CarrierWave
|
|
69
74
|
worker.new(*args).perform
|
70
75
|
end
|
71
76
|
|
72
|
-
def sidekiq_queue_options(args)
|
73
|
-
|
77
|
+
def sidekiq_queue_options(override_queue_name, args)
|
78
|
+
if override_queue_name && queue_options[:queue]
|
79
|
+
args['queue'] = queue_options[:queue]
|
80
|
+
end
|
74
81
|
args['retry'] = queue_options[:retry] unless queue_options[:retry].nil?
|
75
82
|
args['timeout'] = queue_options[:timeout] if queue_options[:timeout]
|
76
83
|
args['backtrace'] = queue_options[:backtrace] if queue_options[:backtrace]
|
data/lib/backgrounder/version.rb
CHANGED
@@ -7,7 +7,7 @@ module CarrierWave
|
|
7
7
|
def perform(*args)
|
8
8
|
record = super(*args)
|
9
9
|
|
10
|
-
if record
|
10
|
+
if record && record.send(:"#{column}").present?
|
11
11
|
record.send(:"process_#{column}_upload=", true)
|
12
12
|
if record.send(:"#{column}").recreate_versions! && record.respond_to?(:"#{column}_processing")
|
13
13
|
record.update_attribute :"#{column}_processing", false
|
@@ -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
|
@@ -37,19 +37,27 @@ module CarrierWave::Backgrounder
|
|
37
37
|
def self.perform(*args); new(*args).perform; end
|
38
38
|
end
|
39
39
|
|
40
|
-
MockWorker.
|
40
|
+
allow(MockWorker).to receive(:new).and_return(worker)
|
41
41
|
end
|
42
42
|
|
43
43
|
context 'queue column exists' do
|
44
|
-
it '
|
44
|
+
it 'does not pass the queue name if none passed to #backend' do
|
45
45
|
mock_module.backend :delayed_job
|
46
|
-
Delayed::Job.
|
46
|
+
expect(Delayed::Job).to receive(:enqueue).with(worker, {})
|
47
47
|
mock_module.enqueue_for_backend MockWorker, 'FakeClass', 1, :image
|
48
48
|
end
|
49
49
|
|
50
50
|
it 'sets the queue name to the queue name passed to #backend' do
|
51
51
|
mock_module.backend :delayed_job, :queue => :awesome_queue
|
52
|
-
Delayed::Job.
|
52
|
+
expect(Delayed::Job).to receive(:enqueue).with(worker, :queue => :awesome_queue)
|
53
|
+
mock_module.enqueue_for_backend MockWorker, 'FakeClass', 1, :image
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
context 'priority set in config' do
|
58
|
+
it 'sets the priority which is passed to #backend' do
|
59
|
+
mock_module.backend :delayed_job, :priority => 5
|
60
|
+
expect(Delayed::Job).to receive(:enqueue).with(worker, :priority => 5)
|
53
61
|
mock_module.enqueue_for_backend MockWorker, 'FakeClass', 1, :image
|
54
62
|
end
|
55
63
|
end
|
@@ -57,7 +65,7 @@ module CarrierWave::Backgrounder
|
|
57
65
|
context 'queue column does not exist' do
|
58
66
|
before do
|
59
67
|
column_names = Delayed::Job.column_names.tap { |cn| cn.delete('queue') }
|
60
|
-
Delayed::Job.
|
68
|
+
allow(Delayed::Job).to receive(:column_names).and_return(column_names)
|
61
69
|
Delayed::Job.class_eval { remove_method(:queue) }
|
62
70
|
end
|
63
71
|
|
@@ -67,14 +75,14 @@ module CarrierWave::Backgrounder
|
|
67
75
|
|
68
76
|
it 'does not pass a queue name if none passed to #backend' do
|
69
77
|
mock_module.backend :delayed_job
|
70
|
-
Delayed::Job.
|
78
|
+
expect(Delayed::Job).to receive(:enqueue).with(worker, {})
|
71
79
|
mock_module.enqueue_for_backend MockWorker, 'FakeClass', 1, :image
|
72
80
|
end
|
73
81
|
|
74
82
|
it 'does not pass a queue name and logs a warning message if a queue name is passed to #backend' do
|
75
83
|
mock_module.backend :delayed_job, :queue => :awesome_queue
|
76
|
-
|
77
|
-
|
84
|
+
expect(Rails.logger).to receive(:warn).with(instance_of(String))
|
85
|
+
expect(Delayed::Job).to receive(:enqueue).with(worker, {})
|
78
86
|
mock_module.enqueue_for_backend MockWorker, 'FakeClass', 1, :image
|
79
87
|
end
|
80
88
|
end
|
@@ -84,7 +92,7 @@ module CarrierWave::Backgrounder
|
|
84
92
|
let(:args) { [MockWorker, 'FakeClass', 1, :image] }
|
85
93
|
|
86
94
|
before do
|
87
|
-
Resque.
|
95
|
+
allow(Resque).to receive(:enqueue).with(*args)
|
88
96
|
end
|
89
97
|
|
90
98
|
it 'sets a variable with the queue name, defaults to :carrierwave' do
|
@@ -104,21 +112,31 @@ module CarrierWave::Backgrounder
|
|
104
112
|
let(:args) { ['FakeClass', 1, :image] }
|
105
113
|
|
106
114
|
it 'invokes client_push on the class with passed args' do
|
107
|
-
MockSidekiqWorker.
|
115
|
+
expect(MockSidekiqWorker).to receive(:client_push).with({ 'class' => MockSidekiqWorker, 'args' => args })
|
108
116
|
mock_module.backend :sidekiq
|
109
117
|
mock_module.enqueue_for_backend(MockSidekiqWorker, *args)
|
110
118
|
end
|
111
119
|
|
112
120
|
it 'invokes client_push and includes the options passed to backend' do
|
113
|
-
MockSidekiqWorker.
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
121
|
+
expect(MockSidekiqWorker).to receive(:client_push).with({ 'class' => MockSidekiqWorker,
|
122
|
+
'retry' => false,
|
123
|
+
'timeout' => 60,
|
124
|
+
'queue' => :awesome_queue,
|
125
|
+
'args' => args })
|
118
126
|
options = {:retry => false, :timeout => 60, :queue => :awesome_queue}
|
119
127
|
mock_module.backend :sidekiq, options
|
120
128
|
mock_module.enqueue_for_backend(MockSidekiqWorker, *args)
|
121
129
|
end
|
130
|
+
|
131
|
+
it 'does not override queue name if set it worker' do
|
132
|
+
expect(MockNamedSidekiqWorker).to receive(:client_push).with({ 'class' => MockNamedSidekiqWorker,
|
133
|
+
'retry' => false,
|
134
|
+
'timeout' => 60,
|
135
|
+
'args' => args })
|
136
|
+
options = {:retry => false, :timeout => 60}
|
137
|
+
mock_module.backend :sidekiq, options
|
138
|
+
mock_module.enqueue_for_backend(MockNamedSidekiqWorker, *args)
|
139
|
+
end
|
122
140
|
end
|
123
141
|
|
124
142
|
context 'girl_friday' do
|
@@ -126,20 +144,20 @@ module CarrierWave::Backgrounder
|
|
126
144
|
|
127
145
|
it 'instantiates a GirlFriday work queue if one does not exist' do
|
128
146
|
mock_module.backend :girl_friday
|
129
|
-
GirlFriday::WorkQueue.
|
147
|
+
expect(GirlFriday::WorkQueue).to receive(:new).with(:carrierwave, {}).and_return([])
|
130
148
|
mock_module.enqueue_for_backend(*args)
|
131
149
|
end
|
132
150
|
|
133
151
|
it 'instantiates a GirlFriday work queue passing the args to the queue' do
|
134
152
|
mock_module.backend :girl_friday, :queue => :awesome_queue, :size => 3
|
135
|
-
GirlFriday::WorkQueue.
|
153
|
+
expect(GirlFriday::WorkQueue).to receive(:new).with(:awesome_queue, {:size => 3}).and_return([])
|
136
154
|
mock_module.enqueue_for_backend(*args)
|
137
155
|
end
|
138
156
|
|
139
157
|
it 'does not instantiate a GirlFriday work queue if one exists' do
|
140
158
|
mock_module.backend :girl_friday
|
141
159
|
mock_module.instance_variable_set('@girl_friday_queue', [])
|
142
|
-
GirlFriday::WorkQueue.
|
160
|
+
expect(GirlFriday::WorkQueue).to receive(:new).never
|
143
161
|
mock_module.enqueue_for_backend(*args)
|
144
162
|
end
|
145
163
|
|
@@ -154,12 +172,12 @@ module CarrierWave::Backgrounder
|
|
154
172
|
|
155
173
|
context 'sucker_punch' do
|
156
174
|
let(:args) { [MockWorker, 'FakeClass', 1, :image] }
|
157
|
-
let(:job) {
|
175
|
+
let(:job) { double('job') }
|
158
176
|
|
159
177
|
it 'invokes a new worker' do
|
160
|
-
MockWorker.
|
161
|
-
worker.
|
162
|
-
job.
|
178
|
+
expect(MockWorker).to receive(:new).and_return(worker)
|
179
|
+
expect(worker).to receive(:async).and_return(job)
|
180
|
+
expect(job).to receive(:perform).with('FakeClass', 1, :image)
|
163
181
|
mock_module.backend :sucker_punch
|
164
182
|
mock_module.enqueue_for_backend(*args)
|
165
183
|
end
|
@@ -168,7 +186,7 @@ module CarrierWave::Backgrounder
|
|
168
186
|
context 'qu' do
|
169
187
|
let(:args) { [MockWorker, 'FakeClass', 1, :image] }
|
170
188
|
before do
|
171
|
-
Qu.
|
189
|
+
allow(Qu).to receive(:enqueue).with(*args)
|
172
190
|
end
|
173
191
|
|
174
192
|
it 'sets a variable with the queue name, defaults to :carrierwave' do
|
@@ -186,7 +204,7 @@ module CarrierWave::Backgrounder
|
|
186
204
|
|
187
205
|
context 'qc' do
|
188
206
|
it 'calls enqueue with the passed args' do
|
189
|
-
QC.
|
207
|
+
expect(QC).to receive(:enqueue).with("MockWorker.perform", 'FakeClass', 1, 'image')
|
190
208
|
mock_module.backend :qc
|
191
209
|
mock_module.enqueue_for_backend(MockWorker, 'FakeClass', 1, :image)
|
192
210
|
end
|
@@ -194,14 +212,13 @@ module CarrierWave::Backgrounder
|
|
194
212
|
|
195
213
|
context 'immediate' do
|
196
214
|
it 'instantiates a worker passing the args and calls perform' do
|
197
|
-
worker =
|
198
|
-
MockWorker.
|
199
|
-
worker.
|
215
|
+
worker = double('Worker')
|
216
|
+
expect(MockWorker).to receive(:new).with('FakeClass', 1, :image).and_return(worker)
|
217
|
+
expect(worker).to receive(:perform)
|
200
218
|
mock_module.backend :immediate
|
201
219
|
mock_module.enqueue_for_backend(MockWorker, 'FakeClass', 1, :image)
|
202
220
|
end
|
203
221
|
end
|
204
|
-
|
205
222
|
end
|
206
223
|
end
|
207
224
|
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,69 +1,55 @@
|
|
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.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Larry Sprock
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-08-26 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
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - ~>
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0.5'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rspec
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - ~>
|
31
|
+
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
33
|
+
version: 3.1.0
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - ~>
|
38
|
+
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
41
|
-
- !ruby/object:Gem::Dependency
|
42
|
-
name: mocha
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
44
|
-
requirements:
|
45
|
-
- - ~>
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
version: 0.13.0
|
48
|
-
type: :development
|
49
|
-
prerelease: false
|
50
|
-
version_requirements: !ruby/object:Gem::Requirement
|
51
|
-
requirements:
|
52
|
-
- - ~>
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version: 0.13.0
|
40
|
+
version: 3.1.0
|
55
41
|
- !ruby/object:Gem::Dependency
|
56
42
|
name: rake
|
57
43
|
requirement: !ruby/object:Gem::Requirement
|
58
44
|
requirements:
|
59
|
-
- -
|
45
|
+
- - ">="
|
60
46
|
- !ruby/object:Gem::Version
|
61
47
|
version: '0'
|
62
48
|
type: :development
|
63
49
|
prerelease: false
|
64
50
|
version_requirements: !ruby/object:Gem::Requirement
|
65
51
|
requirements:
|
66
|
-
- -
|
52
|
+
- - ">="
|
67
53
|
- !ruby/object:Gem::Version
|
68
54
|
version: '0'
|
69
55
|
description:
|
@@ -73,9 +59,9 @@ executables: []
|
|
73
59
|
extensions: []
|
74
60
|
extra_rdoc_files: []
|
75
61
|
files:
|
76
|
-
- .gitignore
|
77
|
-
- .rspec
|
78
|
-
- .travis.yml
|
62
|
+
- ".gitignore"
|
63
|
+
- ".rspec"
|
64
|
+
- ".travis.yml"
|
79
65
|
- CHANGELOG.md
|
80
66
|
- Gemfile
|
81
67
|
- README.md
|
@@ -115,17 +101,17 @@ require_paths:
|
|
115
101
|
- lib
|
116
102
|
required_ruby_version: !ruby/object:Gem::Requirement
|
117
103
|
requirements:
|
118
|
-
- -
|
104
|
+
- - ">="
|
119
105
|
- !ruby/object:Gem::Version
|
120
106
|
version: '0'
|
121
107
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
122
108
|
requirements:
|
123
|
-
- -
|
109
|
+
- - ">="
|
124
110
|
- !ruby/object:Gem::Version
|
125
111
|
version: '0'
|
126
112
|
requirements: []
|
127
113
|
rubyforge_project:
|
128
|
-
rubygems_version: 2.
|
114
|
+
rubygems_version: 2.2.2
|
129
115
|
signing_key:
|
130
116
|
specification_version: 4
|
131
117
|
summary: Offload CarrierWave's image processing and storage to a background process
|