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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: abc9a18253e5769acf85ec7fe57cd8778d331f09
4
- data.tar.gz: 8317e2803900b1c724064ec3c759558946927aca
3
+ metadata.gz: ea7ccc20dfbd12f0d5ca49a22aed4df13af757fe
4
+ data.tar.gz: 9483744462a3c7de8ec21c01c033fe5c7722c1b7
5
5
  SHA512:
6
- metadata.gz: 469bc208573057e5934e8f42e21f0d95ff955b3b377b709b6aa504a4931ac80b29f42f83bd26986fa601b777b3ed9fa4b4af14b59981ca59cc14a7dc314ba4d0
7
- data.tar.gz: b4fcd8692e900393d94a9ee779a605d0c733785b425312b14c5c825464e21ed07aafc3c458b398dc42bafac88562716adbb2ddf31cfb4d252e915b00a28d039e
6
+ metadata.gz: a9ccbcd89a9f510723a6f512197cc3595ffe4bfa00a9ea21c3c1e6b2530fee1901b47670d1bf0e6e44427d40fd71c83064eab553f09c7e1d0b75cb3283d0291e
7
+ data.tar.gz: 437d6b11a142e94ae83699672299bf1a3da800846f4465aa557027bb4026970619ee425b6fc63ca7e5e11687a9dfe417c08213ddbc9300ed826a8361a95f6e61
data/.gitignore CHANGED
@@ -2,3 +2,4 @@
2
2
  .bundle
3
3
  Gemfile.lock
4
4
  pkg/*
5
+ vendor/*
@@ -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 queing lib of choice.
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 nil when the background processing is complete.
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 overide the worker in cases where additional methods need to be called or you have app specific requirements, pass the worker class as the
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", ["~> 2.12.0"]
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
@@ -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") || model.send(:"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
- ::Delayed::Job.enqueue worker.new(*args), :queue => queue_options[:queue]
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
- ::Delayed::Job.enqueue worker.new(*args)
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
- args = sidekiq_queue_options('class' => worker, 'args' => args)
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
- args['queue'] = queue_options[:queue] if queue_options[:queue]
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]
@@ -1,5 +1,5 @@
1
1
  module CarrierWave
2
2
  module Backgrounder
3
- VERSION = "0.4.1"
3
+ VERSION = "0.4.2"
4
4
  end
5
5
  end
@@ -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.expects(:after_commit).with(:enqueue_avatar_background_job, :if => :enqueue_avatar_background_job?)
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.expects(:before_save).with(:set_avatar_processing, :if => :enqueue_avatar_background_job?)
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.expects(:after_commit).with(:enqueue_avatar_background_job, :if => :enqueue_avatar_background_job?)
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.expects(:uploader_options).returns(options_hash)
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.expects(:some_other_column_changed?).returns(true)
58
- expect(instance.avatar_updated?).to be_true
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.expects(:process_avatar_upload)
64
- expect(instance.enqueue_avatar_background_job?).to be_true
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.expects(:process_avatar_upload).returns(false)
69
- instance.expects(:avatar_changed?)
70
- expect(instance.enqueue_avatar_background_job?).to be_true
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.expects(:process_avatar_upload).returns(false)
75
- instance.expects(:avatar_changed?).returns(false)
76
- instance.expects(:previous_changes).returns({:avatar => true})
77
- expect(instance.enqueue_avatar_background_job?).to be_true
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.expects(:process_avatar_upload).returns(false)
82
- instance.expects(:avatar_changed?).returns(false)
83
- instance.expects(:previous_changes).returns({})
84
- instance.expects(:remote_avatar_url).returns('yup')
85
- expect(instance.enqueue_avatar_background_job?).to be_true
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.expects(:process_avatar_upload).returns(false)
90
- instance.expects(:avatar_changed?).returns(false)
91
- instance.expects(:previous_changes).returns({})
92
- instance.expects(:remote_avatar_url).returns(nil)
93
- instance.expects(:avatar_cache).returns('yup')
94
- expect(instance.enqueue_avatar_background_job?).to be_true
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
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
3
 
4
- describe CarrierWave::Backgrounder::ORM::Base do
4
+ RSpec.describe CarrierWave::Backgrounder::ORM::Base do
5
5
  before do
6
6
  @mock_class = Class.new do
7
7
  def self.before_save(method, opts); nil; 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.expects(:new).returns(worker)
40
+ allow(MockWorker).to receive(:new).and_return(worker)
41
41
  end
42
42
 
43
43
  context 'queue column exists' do
44
- it 'defaults the queue name to nil if none passed to #backend' do
44
+ it 'does not pass the queue name if none passed to #backend' do
45
45
  mock_module.backend :delayed_job
46
- Delayed::Job.expects(:enqueue).with(worker, :queue => nil)
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.expects(:enqueue).with(worker, :queue => :awesome_queue)
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.stubs(:column_names).returns(column_names)
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.expects(:enqueue).with(worker)
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
- Delayed::Job.expects(:enqueue).with(worker)
77
- Rails.logger.expects(:warn).with(instance_of(String))
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.expects(:enqueue).with(*args)
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.expects(:client_push).with({ 'class' => MockSidekiqWorker, 'args' => args })
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.expects(:client_push).with({ 'class' => MockSidekiqWorker,
114
- 'retry' => false,
115
- 'timeout' => 60,
116
- 'queue' => :awesome_queue,
117
- 'args' => args })
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.expects(:new).with(:carrierwave, {}).returns([])
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.expects(:new).with(:awesome_queue, {:size => 3}).returns([])
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.expects(:new).never
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) { mock('job') }
175
+ let(:job) { double('job') }
158
176
 
159
177
  it 'invokes a new worker' do
160
- MockWorker.expects(:new).returns(worker)
161
- worker.expects(:async).returns(job)
162
- job.expects(:perform).with('FakeClass', 1, :image)
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.expects(:enqueue).with(*args)
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.expects(:enqueue).with("MockWorker.perform", 'FakeClass', 1, 'image')
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 = mock('Worker')
198
- MockWorker.expects(:new).with('FakeClass', 1, :image).returns(worker)
199
- worker.expects(:perform)
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) { mock('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.expects(:new).with(*args).returns(worker)
14
- worker_class.any_instance.expects(:perform)
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) { mock('UserAsset') }
21
+ let(:image) { double('UserAsset') }
22
22
 
23
23
  before do
24
- user.expects(:find).with('22').returns(user).once
25
- user.expects(:image).once.returns(image)
26
- user.expects(:process_image_upload=).with(true).once
27
- image.expects(:recreate_versions!).once.returns(true)
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.expects(:respond_to?).with(:image_processing).once.returns(true)
32
- user.expects(:update_attribute).with(:image_processing, false).once
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.expects(:respond_to?).with(:image_processing).once.returns(false)
38
- user.expects(:update_attribute).never
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) { mock('Admin') }
45
- let(:avatar) { mock('AdminAsset') }
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.expects(:find).with('23').returns(admin).once
50
- admin.expects(:avatar).once.returns(avatar)
51
- admin.expects(:process_avatar_upload=).with(true).once
52
- admin.expects(:respond_to?).with(:avatar_processing).once.returns(false)
53
- avatar.expects(:recreate_versions!).once.returns(true)
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) { mock('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.expects(:new).with(*args).returns(worker)
15
- worker_class.any_instance.expects(:perform)
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) { mock('UserAsset') }
21
+ let(:image) { double('UserAsset') }
22
22
 
23
23
  before do
24
- image.expects(:root).once.returns(File.expand_path('..', __FILE__))
25
- image.expects(:cache_dir).once.returns('fixtures')
26
- user.expects(:image_tmp).twice.returns('images/test.jpg')
27
- user.expects(:find).with('22').once.returns(user)
28
- user.expects(:image).once.returns(image)
29
- user.expects(:process_image_upload=).with(true).once
30
- user.expects(:image=).once
31
- user.expects(:image_tmp=).with(nil).once
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.expects(:rm_r).with(fixtures_path, :force => true).once
36
- user.expects(:save!).once.returns(true)
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.expects(:rm_r).never
42
- user.expects(:save!).once.returns(false)
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.expects(:save!).once.returns(false)
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.expects(:save!).once.returns(false)
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) { mock('Admin') }
61
- let(:image) { mock('AdminAsset') }
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.expects(:root).once.returns(File.expand_path('..', __FILE__))
66
- image.expects(:cache_dir).once.returns('fixtures')
67
- admin.expects(:avatar_tmp).twice.returns('images/test.jpg')
68
- admin.expects(:find).with('23').once.returns(admin)
69
- admin.expects(:avatar).once.returns(image)
70
- admin.expects(:process_avatar_upload=).with(true).once
71
- admin.expects(:avatar=).once
72
- admin.expects(:avatar_tmp=).with(nil).once
73
- admin.expects(:save!).once.returns(false)
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) { mock('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 = mock(:cache_dir => cache_dir, :root => root)
98
- record.expects(:image).returns(asset)
99
- record.expects(:image_tmp).returns('images/test.jpg')
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 = mock(:cache_dir => cache_dir, :root => root)
108
- record.expects(:image).returns(asset)
109
- record.expects(:image_tmp).returns('images/test.jpg')
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 = mock(:cache_dir => cache_dir, :root => root)
120
- record.expects(:image).returns(asset)
121
- record.expects(:image_tmp).returns('images/test.jpg')
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 = mock(:cache_dir => cache_dir, :root => root)
130
- record.expects(:image).returns(asset)
131
- record.expects(:image_tmp).returns('images/test.jpg')
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
@@ -15,7 +15,6 @@ module WarningSuppression
15
15
  end
16
16
 
17
17
  RSpec.configure do |c|
18
- c.mock_with :mocha
19
18
  c.include WarningSuppression
20
19
  end
21
20
 
@@ -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 ||= Object.new
56
+ @logger ||= Logger.new(STDOUT)
56
57
  end
57
58
  end
@@ -15,3 +15,8 @@ end
15
15
  class MockSidekiqWorker < MockWorker
16
16
  include Sidekiq::Worker
17
17
  end
18
+
19
+ class MockNamedSidekiqWorker < MockWorker
20
+ include Sidekiq::Worker
21
+ sidekiq_options queue: :even_better_name
22
+ end
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.1
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: 2014-06-04 00:00:00.000000000 Z
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: 2.12.0
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: 2.12.0
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.0.6
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