carrierwave_backgrounder 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,8 +1,10 @@
1
1
  language: ruby
2
2
 
3
3
  rvm:
4
- - 1.8.7
5
- - 1.9.2
6
4
  - 1.9.3
7
5
  - 2.0.0
8
- - ree
6
+ - ruby-head
7
+
8
+ matrix:
9
+ allow_failures:
10
+ - rvm: ruby-head
data/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # CarrierWave Backgrounder
2
2
 
3
3
  [![Build Status](https://secure.travis-ci.org/lardawge/carrierwave_backgrounder.png)](http://travis-ci.org/lardawge/carrierwave_backgrounder)
4
- [![Code Quality](https://codeclimate.com/badge.png)](https://codeclimate.com/github/lardawge/carrierwave_backgrounder)
4
+ [![Code Climate](https://codeclimate.com/github/lardawge/carrierwave_backgrounder.png)](https://codeclimate.com/github/lardawge/carrierwave_backgrounder)
5
5
  [![Still Maintained](http://stillmaintained.com/lardawge/carrierwave_backgrounder.png)](http://stillmaintained.com/lardawge/carrierwave_backgrounder)
6
6
 
7
7
  I like CarrierWave. That being said, I don't like tying up app instances waiting for images to process.
@@ -58,13 +58,14 @@ end
58
58
  For SuckerPunch, you have to configure your queue with a specific worker.
59
59
 
60
60
  ```ruby
61
- SuckerPunch.config do
62
- queue name: :carrierwave, worker: CarrierWave::Workers::StoreAsset, size: 2
63
- end
64
-
65
61
  CarrierWave::Backgrounder.configure do |c|
66
62
  c.backend :sucker_punch, queue: :carrierwave
67
63
  end
64
+
65
+ # It is important to configure sucker_punch after carrierwave_backgrounder
66
+ SuckerPunch.config do
67
+ queue name: :carrierwave, worker: CarrierWave::Workers::StoreAsset, size: 2
68
+ end
68
69
  ```
69
70
 
70
71
 
@@ -117,6 +118,15 @@ If you need to process/store the upload immediately:
117
118
  @user.process_<column>_upload = true
118
119
  ```
119
120
 
121
+ This must be set before you assign an upload:
122
+
123
+ ```ruby
124
+ # In a controller
125
+ @user = User.new
126
+ @user.process_avatar_upload = true
127
+ @user.attributes = params[:user]
128
+ ```
129
+
120
130
  ### Override worker
121
131
  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
122
132
  second argument:
@@ -7,36 +7,30 @@ module CarrierWave
7
7
  module ActiveModel
8
8
  include CarrierWave::Backgrounder::ORM::Base
9
9
 
10
- def process_in_background(column, worker=::CarrierWave::Workers::ProcessAsset)
11
- before_save :"set_#{column}_processing", :if => :"enqueue_#{column}_background_job?"
12
- send _supported_am_after_callback, :"enqueue_#{column}_background_job", :if => :"enqueue_#{column}_background_job?"
13
- super
14
- end
15
-
16
- def store_in_background(column, worker=::CarrierWave::Workers::StoreAsset)
17
- send _supported_am_after_callback, :"enqueue_#{column}_background_job", :if => :"enqueue_#{column}_background_job?"
18
- super
19
- end
20
-
21
10
  private
22
11
 
23
- def _supported_am_after_callback
24
- respond_to?(:after_commit) ? :after_commit : :after_save
25
- end
26
-
27
12
  def _define_shared_backgrounder_methods(mod, column, worker)
13
+ before_save :"set_#{column}_processing", :if => :"enqueue_#{column}_background_job?"
14
+ send _supported_callback, :"enqueue_#{column}_background_job", :if => :"enqueue_#{column}_background_job?"
15
+
28
16
  super
29
17
 
30
18
  define_method :"#{column}_updated?" do
31
- send(:"#{column}_changed?") || # after_save support
32
- previous_changes.has_key?(:"#{column}") || # after_commit support
33
- send(:"remote_#{column}_url").present? || # Remote upload support
34
- send(:"#{column}_cache").present? # Form failure support
19
+ options = self.class.uploader_options[column] || {}
20
+ serialization_column = options[:mount_on] || column
21
+
22
+ send(:"#{serialization_column}_changed?") || # after_save support
23
+ previous_changes.has_key?(:"#{serialization_column}") || # after_commit support
24
+ send(:"remote_#{column}_url").present? || # Remote upload support
25
+ send(:"#{column}_cache").present? # Form failure support
35
26
  end
36
27
  end
28
+
29
+ def _supported_callback
30
+ respond_to?(:after_commit) ? :after_commit : :after_save
31
+ end
37
32
  end # ActiveModel
38
33
 
39
34
  end # ORM
40
35
  end # Backgrounder
41
36
  end # CarrierWave
42
-
@@ -43,11 +43,6 @@ module CarrierWave
43
43
 
44
44
  mod = Module.new
45
45
  include mod
46
- mod.class_eval <<-RUBY, __FILE__, __LINE__ + 1
47
- def set_#{column}_processing
48
- self.#{column}_processing = true if respond_to?(:#{column}_processing)
49
- end
50
- RUBY
51
46
 
52
47
  _define_shared_backgrounder_methods(mod, column, worker)
53
48
  end
@@ -88,6 +83,7 @@ module CarrierWave
88
83
  def store_#{column}!
89
84
  super if process_#{column}_upload
90
85
  end
86
+
91
87
  RUBY
92
88
 
93
89
  _define_shared_backgrounder_methods(mod, column, worker)
@@ -99,6 +95,10 @@ module CarrierWave
99
95
  mod.class_eval <<-RUBY, __FILE__, __LINE__ + 1
100
96
  def #{column}_updated?; true; end
101
97
 
98
+ def set_#{column}_processing
99
+ self.#{column}_processing = true if respond_to?(:#{column}_processing)
100
+ end
101
+
102
102
  def enqueue_#{column}_background_job?
103
103
  !remove_#{column}? && !process_#{column}_upload && #{column}_updated?
104
104
  end
@@ -108,7 +108,6 @@ module CarrierWave
108
108
  end
109
109
  RUBY
110
110
  end
111
-
112
111
  end # Base
113
112
 
114
113
  end #ORM
@@ -6,8 +6,7 @@ module CarrierWave
6
6
  include CarrierWave::Backgrounder::ORM::Base
7
7
 
8
8
  def process_in_background(column, worker=::CarrierWave::Workers::ProcessAsset)
9
- before :save, :"set_#{column}_processing"
10
- after :save, :"enqueue_#{column}_background_job"
9
+ super
11
10
 
12
11
  class_eval <<-RUBY, __FILE__, __LINE__ + 1
13
12
  def set_#{column}_processing
@@ -18,8 +17,7 @@ module CarrierWave
18
17
  end
19
18
 
20
19
  def store_in_background(column, worker=::CarrierWave::Workers::StoreAsset)
21
- before :save, :"set_#{column}_changed"
22
- after :save, :"enqueue_#{column}_background_job"
20
+ super
23
21
 
24
22
  class_eval <<-RUBY, __FILE__, __LINE__ + 1
25
23
  def set_#{column}_changed
@@ -36,7 +34,11 @@ module CarrierWave
36
34
  private
37
35
 
38
36
  def _define_shared_backgrounder_methods(mod, column, worker)
37
+ before :save, :"set_#{column}_changed"
38
+ after :save, :"enqueue_#{column}_background_job"
39
+
39
40
  super
41
+
40
42
  class_eval <<-RUBY, __FILE__, __LINE__ + 1
41
43
  attr_reader :#{column}_changed
42
44
 
@@ -1,72 +1,83 @@
1
- module Support
2
- module Backends
1
+ module CarrierWave
2
+ module Backgrounder
3
+ module Support
4
+ module Backends
3
5
 
4
- def self.included(base)
5
- base.extend ClassMethods
6
- end
6
+ def self.included(base)
7
+ base.extend ClassMethods
8
+ end
7
9
 
8
- module ClassMethods
9
- attr_reader :queue_options
10
+ module ClassMethods
11
+ attr_reader :queue_options
10
12
 
11
- def backend(queue_name=nil, args={})
12
- return @backend if @backend
13
- @queue_options = args
14
- @backend = queue_name
15
- end
13
+ def backend(queue_name=nil, args={})
14
+ return @backend if @backend
15
+ @queue_options = args
16
+ @backend = queue_name
17
+ end
16
18
 
17
- def enqueue_for_backend(worker, class_name, subject_id, mounted_as)
18
- self.send :"enqueue_#{backend}", worker, class_name, subject_id, mounted_as
19
- end
19
+ def enqueue_for_backend(worker, class_name, subject_id, mounted_as)
20
+ self.send :"enqueue_#{backend}", worker, class_name, subject_id, mounted_as
21
+ end
20
22
 
21
- private
23
+ private
22
24
 
23
- def enqueue_delayed_job(worker, *args)
24
- ::Delayed::Job.enqueue worker.new(*args), :queue => queue_options[:queue]
25
- end
25
+ def enqueue_delayed_job(worker, *args)
26
+ if ::Delayed::Job.new.respond_to?(:queue)
27
+ ::Delayed::Job.enqueue worker.new(*args), :queue => queue_options[:queue]
28
+ else
29
+ ::Delayed::Job.enqueue worker.new(*args)
30
+ if queue_options[:queue]
31
+ ::Rails.logger.warn("Queue name given but no queue column exists for Delayed::Job")
32
+ end
33
+ end
34
+ end
26
35
 
27
- def enqueue_resque(worker, *args)
28
- worker.instance_variable_set('@queue', queue_options[:queue] || :carrierwave)
29
- ::Resque.enqueue worker, *args
30
- end
36
+ def enqueue_resque(worker, *args)
37
+ worker.instance_variable_set('@queue', queue_options[:queue] || :carrierwave)
38
+ ::Resque.enqueue worker, *args
39
+ end
31
40
 
32
- def enqueue_sidekiq(worker, *args)
33
- args = sidekiq_queue_options('class' => worker, 'args' => args)
34
- worker.client_push(args)
35
- end
41
+ def enqueue_sidekiq(worker, *args)
42
+ args = sidekiq_queue_options('class' => worker, 'args' => args)
43
+ worker.client_push(args)
44
+ end
36
45
 
37
- def enqueue_girl_friday(worker, *args)
38
- @girl_friday_queue ||= GirlFriday::WorkQueue.new(queue_options.delete(:queue) || :carrierwave, queue_options) do |msg|
39
- worker = msg[:worker]
40
- worker.perform
41
- end
42
- @girl_friday_queue << { :worker => worker.new(*args) }
43
- end
46
+ def enqueue_girl_friday(worker, *args)
47
+ @girl_friday_queue ||= GirlFriday::WorkQueue.new(queue_options.delete(:queue) || :carrierwave, queue_options) do |msg|
48
+ worker = msg[:worker]
49
+ worker.perform
50
+ end
51
+ @girl_friday_queue << { :worker => worker.new(*args) }
52
+ end
44
53
 
45
- def enqueue_sucker_punch(worker, *args)
46
- @sucker_punch_queue ||= SuckerPunch::Queue[queue_options[:queue] || :carrierwave]
47
- @sucker_punch_queue.async.perform(*args)
48
- end
54
+ def enqueue_sucker_punch(worker, *args)
55
+ @sucker_punch_queue ||= SuckerPunch::Queue[queue_options[:queue] || :carrierwave]
56
+ @sucker_punch_queue.async.perform(*args)
57
+ end
49
58
 
50
- def enqueue_qu(worker, *args)
51
- worker.instance_variable_set('@queue', queue_options[:queue] || :carrierwave)
52
- ::Qu.enqueue worker, *args
53
- end
59
+ def enqueue_qu(worker, *args)
60
+ worker.instance_variable_set('@queue', queue_options[:queue] || :carrierwave)
61
+ ::Qu.enqueue worker, *args
62
+ end
54
63
 
55
- def enqueue_qc(worker, *args)
56
- class_name, subject_id, mounted_as = args
57
- ::QC.enqueue "#{worker.name}.perform", class_name, subject_id, mounted_as.to_s
58
- end
64
+ def enqueue_qc(worker, *args)
65
+ class_name, subject_id, mounted_as = args
66
+ ::QC.enqueue "#{worker.name}.perform", class_name, subject_id, mounted_as.to_s
67
+ end
59
68
 
60
- def enqueue_immediate(worker, *args)
61
- worker.new(*args).perform
62
- end
69
+ def enqueue_immediate(worker, *args)
70
+ worker.new(*args).perform
71
+ end
63
72
 
64
- def sidekiq_queue_options(args)
65
- args['queue'] = queue_options[:queue] if queue_options[:queue]
66
- args['retry'] = queue_options[:retry] unless queue_options[:retry].nil?
67
- args['timeout'] = queue_options[:timeout] if queue_options[:timeout]
68
- args['backtrace'] = queue_options[:backtrace] if queue_options[:backtrace]
69
- args
73
+ def sidekiq_queue_options(args)
74
+ args['queue'] = queue_options[:queue] if queue_options[:queue]
75
+ args['retry'] = queue_options[:retry] unless queue_options[:retry].nil?
76
+ args['timeout'] = queue_options[:timeout] if queue_options[:timeout]
77
+ args['backtrace'] = queue_options[:backtrace] if queue_options[:backtrace]
78
+ args
79
+ end
80
+ end
70
81
  end
71
82
  end
72
83
  end
@@ -1,5 +1,5 @@
1
1
  module CarrierWave
2
2
  module Backgrounder
3
- VERSION = "0.2.1"
3
+ VERSION = "0.2.2"
4
4
  end
5
5
  end
@@ -17,6 +17,7 @@ module CarrierWave
17
17
  store_directories(record)
18
18
  record.send :"process_#{column}_upload=", true
19
19
  record.send :"#{column}_tmp=", nil
20
+ record.send :"#{column}_processing=", nil if record.respond_to?(:"#{column}_processing")
20
21
  File.open(cache_path) { |f| record.send :"#{column}=", f }
21
22
  if record.save!
22
23
  FileUtils.rm_r(tmp_directory, :force => true)
@@ -7,28 +7,23 @@ module CarrierWave
7
7
  module Backgrounder
8
8
  include Support::Backends
9
9
 
10
- class UnsupportedBackendError < StandardError ; end
11
- class TooManyBackendsAvailableError < StandardError ; end
12
-
13
10
  def self.configure
14
11
  yield self
15
12
  case @backend
16
13
  when :sidekiq
14
+ require 'sidekiq'
17
15
  ::CarrierWave::Workers::ProcessAsset.class_eval do
18
- require 'sidekiq'
19
16
  include ::Sidekiq::Worker
20
17
  end
21
18
  ::CarrierWave::Workers::StoreAsset.class_eval do
22
- require 'sidekiq'
23
19
  include ::Sidekiq::Worker
24
20
  end
25
21
  when :sucker_punch
22
+ require 'sucker_punch'
26
23
  ::CarrierWave::Workers::ProcessAsset.class_eval do
27
- require 'sucker_punch'
28
24
  include ::SuckerPunch::Worker
29
25
  end
30
26
  ::CarrierWave::Workers::StoreAsset.class_eval do
31
- require 'sucker_punch'
32
27
  include ::SuckerPunch::Worker
33
28
  end
34
29
  end
@@ -3,6 +3,7 @@ CarrierWave::Backgrounder.configure do |c|
3
3
  # c.backend :resque, queue: :carrierwave
4
4
  # c.backend :sidekiq, queue: :carrierwave
5
5
  # c.backend :girl_friday, queue: :carrierwave
6
+ # c.backend :sucker_punch, queue: :carrierwave
6
7
  # c.backend :qu, queue: :carrierwave
7
8
  # c.backend :qc
8
9
  end
@@ -11,6 +11,7 @@ describe CarrierWave::Backgrounder::ORM::ActiveModel do
11
11
  def remote_avatar_url; OpenStruct.new(:present? => true); end
12
12
  def remove_avatar?; false; end
13
13
  def previous_changes; {}; end
14
+ def self.uploader_options; {}; end
14
15
  end
15
16
 
16
17
  @mock_class.extend CarrierWave::Backgrounder::ORM::ActiveModel
@@ -46,6 +47,18 @@ describe CarrierWave::Backgrounder::ORM::ActiveModel do
46
47
  @mock_class.process_in_background :avatar
47
48
  end
48
49
 
50
+ context 'mount_on option is set' do
51
+ before do
52
+ options_hash = {:avatar => {:mount_on => :some_other_column}}
53
+ @mock_class.expects(:uploader_options).returns(options_hash)
54
+ end
55
+
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
59
+ end
60
+ end
61
+
49
62
  it "returns true if process_avatar_upload is false" do
50
63
  instance.expects(:process_avatar_upload)
51
64
  expect(instance.enqueue_avatar_background_job?).to be_true
@@ -2,187 +2,215 @@ require 'spec_helper'
2
2
  require 'support/backend_constants'
3
3
  require 'support/mock_worker'
4
4
 
5
- describe Support::Backends do
6
- let(:mock_module) { Module.new }
5
+ module CarrierWave::Backgrounder
6
+ describe Support::Backends do
7
+ let(:mock_module) { Module.new }
7
8
 
8
- before do
9
- mock_module.send :include, Support::Backends
10
- end
11
-
12
- describe 'setting backend' do
13
- it 'using #backend=' do
14
- expect {
15
- mock_module.backend = :delayed_job
16
- }.to raise_error(NoMethodError)
9
+ before do
10
+ mock_module.send :include, Support::Backends
17
11
  end
18
12
 
19
- it 'using #backend' do
20
- mock_module.backend(:delayed_job)
21
- expect(mock_module.backend).to eql(:delayed_job)
22
- end
13
+ describe 'setting backend' do
14
+ it 'using #backend=' do
15
+ expect {
16
+ mock_module.backend = :delayed_job
17
+ }.to raise_error(NoMethodError)
18
+ end
23
19
 
24
- it 'allows passing of queue_options' do
25
- mock_module.backend(:delayed_job, :queue => :awesome_queue)
26
- expect(mock_module.queue_options).to eql({:queue => :awesome_queue})
20
+ it 'using #backend' do
21
+ mock_module.backend(:delayed_job)
22
+ expect(mock_module.backend).to eql(:delayed_job)
23
+ end
24
+
25
+ it 'allows passing of queue_options' do
26
+ mock_module.backend(:delayed_job, :queue => :awesome_queue)
27
+ expect(mock_module.queue_options).to eql({:queue => :awesome_queue})
28
+ end
27
29
  end
28
- end
29
30
 
30
- describe '#enqueue_for_backend' do
31
- let!(:worker) { MockWorker.new('FakeClass', 1, :image) }
31
+ describe '#enqueue_for_backend' do
32
+ let!(:worker) { MockWorker.new('FakeClass', 1, :image) }
33
+
34
+ context 'delayed_job' do
35
+ before do
36
+ @mock_worker = Class.new do
37
+ def self.perform(*args); new(*args).perform; end
38
+ end
32
39
 
33
- context 'delayed_job' do
34
- before do
35
- @mock_worker = Class.new do
36
- def self.perform(*args); new(*args).perform; end
40
+ MockWorker.expects(:new).returns(worker)
37
41
  end
38
42
 
39
- MockWorker.expects(:new).returns(worker)
40
- end
43
+ context 'queue column exists' do
44
+ it 'defaults the queue name to nil if none passed to #backend' do
45
+ mock_module.backend :delayed_job
46
+ Delayed::Job.expects(:enqueue).with(worker, :queue => nil)
47
+ mock_module.enqueue_for_backend MockWorker, 'FakeClass', 1, :image
48
+ end
49
+
50
+ it 'sets the queue name to the queue name passed to #backend' do
51
+ mock_module.backend :delayed_job, :queue => :awesome_queue
52
+ Delayed::Job.expects(:enqueue).with(worker, :queue => :awesome_queue)
53
+ mock_module.enqueue_for_backend MockWorker, 'FakeClass', 1, :image
54
+ end
55
+ end
41
56
 
42
- it 'defaults the queue name to nil if none passed to #backend' do
43
- mock_module.backend :delayed_job
44
- Delayed::Job.expects(:enqueue).with(worker, :queue => nil)
45
- mock_module.enqueue_for_backend MockWorker, 'FakeClass', 1, :image
57
+ context 'queue column does not exist' do
58
+ before do
59
+ column_names = Delayed::Job.column_names.tap { |cn| cn.delete('queue') }
60
+ Delayed::Job.stubs(:column_names).returns(column_names)
61
+ Delayed::Job.class_eval { remove_method(:queue) }
62
+ end
63
+
64
+ after do
65
+ Delayed::Job.class_eval { define_method(:queue) { nil } }
66
+ end
67
+
68
+ it 'does not pass a queue name if none passed to #backend' do
69
+ mock_module.backend :delayed_job
70
+ Delayed::Job.expects(:enqueue).with(worker)
71
+ mock_module.enqueue_for_backend MockWorker, 'FakeClass', 1, :image
72
+ end
73
+
74
+ it 'does not pass a queue name and logs a warning message if a queue name is passed to #backend' do
75
+ mock_module.backend :delayed_job, :queue => :awesome_queue
76
+ Delayed::Job.expects(:enqueue).with(worker)
77
+ Rails.logger.expects(:warn).with(instance_of(String))
78
+ mock_module.enqueue_for_backend MockWorker, 'FakeClass', 1, :image
79
+ end
80
+ end
46
81
  end
47
82
 
48
- it 'sets the queue name to the queue name passed to #backend' do
49
- mock_module.backend :delayed_job, :queue => :awesome_queue
50
- Delayed::Job.expects(:enqueue).with(worker, :queue => :awesome_queue)
51
- mock_module.enqueue_for_backend MockWorker, 'FakeClass', 1, :image
52
- end
53
- end
83
+ context 'resque' do
84
+ let(:args) { [MockWorker, 'FakeClass', 1, :image] }
54
85
 
55
- context 'resque' do
56
- let(:args) { [MockWorker, 'FakeClass', 1, :image] }
86
+ before do
87
+ Resque.expects(:enqueue).with(*args)
88
+ end
57
89
 
58
- before do
59
- Resque.expects(:enqueue).with(*args)
60
- end
90
+ it 'sets a variable with the queue name, defaults to :carrierwave' do
91
+ mock_module.backend :resque
92
+ mock_module.enqueue_for_backend(*args)
93
+ expect(MockWorker.instance_variable_get '@queue').to eql(:carrierwave)
94
+ end
61
95
 
62
- it 'sets a variable with the queue name, defaults to :carrierwave' do
63
- mock_module.backend :resque
64
- mock_module.enqueue_for_backend(*args)
65
- expect(MockWorker.instance_variable_get '@queue').to eql(:carrierwave)
96
+ it 'sets a variable to the queue name passed to #backend' do
97
+ mock_module.backend :resque, :queue => :awesome_queue
98
+ mock_module.enqueue_for_backend(*args)
99
+ expect(MockWorker.instance_variable_get '@queue').to eql(:awesome_queue)
100
+ end
66
101
  end
67
102
 
68
- it 'sets a variable to the queue name passed to #backend' do
69
- mock_module.backend :resque, :queue => :awesome_queue
70
- mock_module.enqueue_for_backend(*args)
71
- expect(MockWorker.instance_variable_get '@queue').to eql(:awesome_queue)
72
- end
73
- end
103
+ context 'sidekiq' do
104
+ let(:args) { ['FakeClass', 1, :image] }
74
105
 
75
- context 'sidekiq' do
76
- let(:args) { ['FakeClass', 1, :image] }
106
+ it 'invokes client_push on the class with passed args' do
107
+ MockSidekiqWorker.expects(:client_push).with({ 'class' => MockSidekiqWorker, 'args' => args })
108
+ mock_module.backend :sidekiq
109
+ mock_module.enqueue_for_backend(MockSidekiqWorker, *args)
110
+ end
77
111
 
78
- it 'invokes client_push on the class with passed args' do
79
- MockSidekiqWorker.expects(:client_push).with({ 'class' => MockSidekiqWorker, 'args' => args })
80
- mock_module.backend :sidekiq
81
- mock_module.enqueue_for_backend(MockSidekiqWorker, *args)
112
+ 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 })
118
+ options = {:retry => false, :timeout => 60, :queue => :awesome_queue}
119
+ mock_module.backend :sidekiq, options
120
+ mock_module.enqueue_for_backend(MockSidekiqWorker, *args)
121
+ end
82
122
  end
83
123
 
84
- it 'invokes client_push and includes the options passed to backend' do
85
- MockSidekiqWorker.expects(:client_push).with({ 'class' => MockSidekiqWorker,
86
- 'retry' => false,
87
- 'timeout' => 60,
88
- 'queue' => :awesome_queue,
89
- 'args' => args })
90
- options = {:retry => false, :timeout => 60, :queue => :awesome_queue}
91
- mock_module.backend :sidekiq, options
92
- mock_module.enqueue_for_backend(MockSidekiqWorker, *args)
93
- end
94
- end
124
+ context 'girl_friday' do
125
+ let(:args) { [MockWorker, 'FakeClass', 1, :image] }
95
126
 
96
- context 'girl_friday' do
97
- let(:args) { [MockWorker, 'FakeClass', 1, :image] }
127
+ it 'instantiates a GirlFriday work queue if one does not exist' do
128
+ mock_module.backend :girl_friday
129
+ GirlFriday::WorkQueue.expects(:new).with(:carrierwave, {}).returns([])
130
+ mock_module.enqueue_for_backend(*args)
131
+ end
98
132
 
99
- it 'instantiates a GirlFriday work queue if one does not exist' do
100
- mock_module.backend :girl_friday
101
- GirlFriday::WorkQueue.expects(:new).with(:carrierwave, {}).returns([])
102
- mock_module.enqueue_for_backend(*args)
103
- end
133
+ it 'instantiates a GirlFriday work queue passing the args to the queue' do
134
+ mock_module.backend :girl_friday, :queue => :awesome_queue, :size => 3
135
+ GirlFriday::WorkQueue.expects(:new).with(:awesome_queue, {:size => 3}).returns([])
136
+ mock_module.enqueue_for_backend(*args)
137
+ end
104
138
 
105
- it 'instantiates a GirlFriday work queue passing the args to the queue' do
106
- mock_module.backend :girl_friday, :queue => :awesome_queue, :size => 3
107
- GirlFriday::WorkQueue.expects(:new).with(:awesome_queue, {:size => 3}).returns([])
108
- mock_module.enqueue_for_backend(*args)
109
- end
139
+ it 'does not instantiate a GirlFriday work queue if one exists' do
140
+ mock_module.backend :girl_friday
141
+ mock_module.instance_variable_set('@girl_friday_queue', [])
142
+ GirlFriday::WorkQueue.expects(:new).never
143
+ mock_module.enqueue_for_backend(*args)
144
+ end
110
145
 
111
- it 'does not instantiate a GirlFriday work queue if one exists' do
112
- mock_module.backend :girl_friday
113
- mock_module.instance_variable_set('@girl_friday_queue', [])
114
- GirlFriday::WorkQueue.expects(:new).never
115
- mock_module.enqueue_for_backend(*args)
146
+ it 'add a worker to the girl_friday queue' do
147
+ expected = [{ :worker => MockWorker.new('FakeClass', 1, :image) }]
148
+ mock_module.backend :girl_friday
149
+ mock_module.instance_variable_set('@girl_friday_queue', [])
150
+ mock_module.enqueue_for_backend(*args)
151
+ expect(mock_module.instance_variable_get '@girl_friday_queue').to eql(expected)
152
+ end
116
153
  end
117
154
 
118
- it 'add a worker to the girl_friday queue' do
119
- expected = [{ :worker => MockWorker.new('FakeClass', 1, :image) }]
120
- mock_module.backend :girl_friday
121
- mock_module.instance_variable_set('@girl_friday_queue', [])
122
- mock_module.enqueue_for_backend(*args)
123
- expect(mock_module.instance_variable_get '@girl_friday_queue').to eql(expected)
124
- end
125
- end
155
+ context 'sucker_punch' do
156
+ let(:args) { [MockWorker, 'FakeClass', 1, :image] }
157
+ let(:mock_sp) { mock('SuckerPunch')}
126
158
 
127
- context 'sucker_punch' do
128
- let(:args) { [MockWorker, 'FakeClass', 1, :image] }
129
- let(:mock_sp) { mock('SuckerPunch')}
159
+ before do
160
+ mock_sp.expects(:async).returns(mock_sp)
161
+ mock_sp.expects(:perform).with('FakeClass', 1, :image)
162
+ end
130
163
 
131
- before do
132
- mock_sp.expects(:async).returns(mock_sp)
133
- mock_sp.expects(:perform).with('FakeClass', 1, :image)
134
- end
164
+ it 'sets the queue to :carrierwave by default' do
165
+ SuckerPunch::Queue.expects(:[]).with(:carrierwave).returns(mock_sp)
166
+ mock_module.backend :sucker_punch
167
+ mock_module.enqueue_for_backend(*args)
168
+ end
135
169
 
136
- it 'sets the queue to :carrierwave by default' do
137
- SuckerPunch::Queue.expects(:[]).with(:carrierwave).returns(mock_sp)
138
- mock_module.backend :sucker_punch
139
- mock_module.enqueue_for_backend(*args)
170
+ it 'sets the queue to backend :queue option' do
171
+ SuckerPunch::Queue.expects(:[]).with(:awesome_queue).returns(mock_sp)
172
+ mock_module.backend :sucker_punch, :queue => :awesome_queue
173
+ mock_module.enqueue_for_backend(*args)
174
+ end
140
175
  end
141
176
 
142
- it 'sets the queue to backend :queue option' do
143
- SuckerPunch::Queue.expects(:[]).with(:awesome_queue).returns(mock_sp)
144
- mock_module.backend :sucker_punch, :queue => :awesome_queue
145
- mock_module.enqueue_for_backend(*args)
146
- end
147
- end
177
+ context 'qu' do
178
+ let(:args) { [MockWorker, 'FakeClass', 1, :image] }
179
+ before do
180
+ Qu.expects(:enqueue).with(*args)
181
+ end
148
182
 
149
- context 'qu' do
150
- let(:args) { [MockWorker, 'FakeClass', 1, :image] }
151
- before do
152
- Qu.expects(:enqueue).with(*args)
153
- end
183
+ it 'sets a variable with the queue name, defaults to :carrierwave' do
184
+ mock_module.backend :qu
185
+ mock_module.enqueue_for_backend(*args)
186
+ expect(MockWorker.instance_variable_get '@queue').to eql(:carrierwave)
187
+ end
154
188
 
155
- it 'sets a variable with the queue name, defaults to :carrierwave' do
156
- mock_module.backend :qu
157
- mock_module.enqueue_for_backend(*args)
158
- expect(MockWorker.instance_variable_get '@queue').to eql(:carrierwave)
189
+ it 'sets a variable to the queue name passed to #backend' do
190
+ mock_module.backend :qu, :queue => :awesome_queue
191
+ mock_module.enqueue_for_backend(*args)
192
+ expect(MockWorker.instance_variable_get '@queue').to eql(:awesome_queue)
193
+ end
159
194
  end
160
195
 
161
- it 'sets a variable to the queue name passed to #backend' do
162
- mock_module.backend :qu, :queue => :awesome_queue
163
- mock_module.enqueue_for_backend(*args)
164
- expect(MockWorker.instance_variable_get '@queue').to eql(:awesome_queue)
196
+ context 'qc' do
197
+ it 'calls enqueue with the passed args' do
198
+ QC.expects(:enqueue).with("MockWorker.perform", 'FakeClass', 1, 'image')
199
+ mock_module.backend :qc
200
+ mock_module.enqueue_for_backend(MockWorker, 'FakeClass', 1, :image)
201
+ end
165
202
  end
166
- end
167
203
 
168
- context 'qc' do
169
- it 'calls enqueue with the passed args' do
170
- QC.expects(:enqueue).with("MockWorker.perform", 'FakeClass', 1, 'image')
171
- mock_module.backend :qc
172
- mock_module.enqueue_for_backend(MockWorker, 'FakeClass', 1, :image)
204
+ context 'immediate' do
205
+ it 'instantiates a worker passing the args and calls perform' do
206
+ worker = mock('Worker')
207
+ MockWorker.expects(:new).with('FakeClass', 1, :image).returns(worker)
208
+ worker.expects(:perform)
209
+ mock_module.backend :immediate
210
+ mock_module.enqueue_for_backend(MockWorker, 'FakeClass', 1, :image)
211
+ end
173
212
  end
174
- end
175
213
 
176
- context 'immediate' do
177
- it 'instantiates a worker passing the args and calls perform' do
178
- worker = mock('Worker')
179
- MockWorker.expects(:new).with('FakeClass', 1, :image).returns(worker)
180
- worker.expects(:perform)
181
- mock_module.backend :immediate
182
- mock_module.enqueue_for_backend(MockWorker, 'FakeClass', 1, :image)
183
- end
184
214
  end
185
-
186
215
  end
187
216
  end
188
-
@@ -6,7 +6,14 @@ module GirlFriday
6
6
  end
7
7
 
8
8
  module Delayed
9
- module Job
9
+ class Job
10
+ def self.column_names
11
+ %w(id priority attempts handler queue last_error run_at locked_at failed_at locked_by created_at updated_at)
12
+ end
13
+
14
+ column_names.each do |column_name|
15
+ define_method(column_name) { nil }
16
+ end
10
17
  end
11
18
  end
12
19
 
@@ -42,3 +49,9 @@ module SuckerPunch
42
49
  class Queue
43
50
  end
44
51
  end
52
+
53
+ module Rails
54
+ def self.logger
55
+ @logger ||= Object.new
56
+ end
57
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: carrierwave_backgrounder
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-03-16 00:00:00.000000000 Z
12
+ date: 2013-07-16 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: carrierwave
@@ -128,7 +128,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
128
128
  version: '0'
129
129
  segments:
130
130
  - 0
131
- hash: 1936252162021597709
131
+ hash: -3663801014250958457
132
132
  required_rubygems_version: !ruby/object:Gem::Requirement
133
133
  none: false
134
134
  requirements:
@@ -137,10 +137,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
137
137
  version: '0'
138
138
  segments:
139
139
  - 0
140
- hash: 1936252162021597709
140
+ hash: -3663801014250958457
141
141
  requirements: []
142
142
  rubyforge_project:
143
- rubygems_version: 1.8.24
143
+ rubygems_version: 1.8.25
144
144
  signing_key:
145
145
  specification_version: 3
146
146
  summary: Offload CarrierWave's image processing and storage to a background process