carrierwave_backgrounder 0.0.9 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -2,28 +2,35 @@
2
2
 
3
3
  I like CarrierWave. That being said, I don't like tying up app instances waiting for images to process.
4
4
 
5
- This gem addresses that issue by disabling processing until a background process initiates it.
6
- It supports Delayed Job, Resque and Girl Friday.
5
+ This gem addresses that moving processing or storage/processing to a background task.
6
+ We currently support Delayed Job, Resque, Sidekiq, Girl Friday, Qu, and Queue Classic.
7
7
 
8
8
  ## Background options
9
9
 
10
10
  There are currently two offerings for backgrounding upload tasks which are as follows;
11
11
 
12
12
  ```ruby
13
+ # This stores the original file with no processing/versioning.
14
+ # It will upload the original file to s3.
15
+ # This was developed to use where you do not have control over the cache location such as Heroku.
16
+
13
17
  Backgrounder::ORM::Base::process_in_background
14
18
  ```
15
19
 
16
- This method stores the original file and does no processing or versioning. Optionally you can add a column to the database which will be set to nil when the background processing is complete.
17
-
18
20
  ```ruby
21
+ # This does nothing to the file after it is cached which makes it super fast.
22
+ # It requires a column in the database which stores the cache location set by carrierwave so the background job can access it.
23
+ # The drawback to using this method is the need for a central location to store the cached files.
24
+ # Heroku may deploy workers on separate servers from where your dyno cached the files.
25
+ #
26
+ # IMPORTANT: Only use this method if you have full control over your tmp storage directory.
27
+
19
28
  Backgrounder::ORM::Base::store_in_background
20
29
  ```
21
30
 
22
- This method does nothing to the file after it is cached which makes it super fast. It requires a column in the database which stores the cache location set by carrierwave. The drawback to using this method is the need for a central location to store the cached files. This leave heroku out. Heroku may deploy workers on separate servers from where your dyno cached the files. That being said, I only recommend using this method if you have full control over your temp storage directory.
31
+ ## Installation and Usage
23
32
 
24
- ## Installation
25
-
26
- These instructions assume you have previously set up [CarrierWave](https://github.com/jnicklas/carrierwave) and [DelayedJob](https://github.com/collectiveidea/delayed_job) or Resque
33
+ These instructions assume you have previously set up [CarrierWave](https://github.com/jnicklas/carrierwave) and your queing lib of choice.
27
34
 
28
35
  In Rails, add the following your Gemfile:
29
36
 
@@ -31,14 +38,31 @@ In Rails, add the following your Gemfile:
31
38
  gem 'carrierwave_backgrounder'
32
39
  ```
33
40
 
34
- ## Getting Started
41
+ ### Setup
35
42
 
36
43
  In an initializer:
37
44
 
38
45
  ```ruby
39
46
  CarrierWave::Backgrounder.configure do |c|
40
47
  # :delayed_job, :girl_friday, :sidekiq, :qu, :resque, or :qc
41
- c.backend = :delayed_job
48
+ c.backend :delayed_job
49
+ end
50
+ ```
51
+
52
+ If you would like to use a custom queue name for Delayed Job, Resque, Girl Friday, Sidekiq and Qu pass in the following option.
53
+ The queue name will default to carrierwave.
54
+
55
+ ```ruby
56
+ CarrierWave::Backgrounder.configure do |c|
57
+ c.backend :delayed_job, queue: :awesome_queue
58
+ end
59
+ ```
60
+
61
+ You can also pass additional configuration options to Girl Friday
62
+
63
+ ```ruby
64
+ CarrierWave::Backgrounder.configure do |c|
65
+ c.backend :girl_friday, queue: :awesome_queue, size: 3, store: GirlFriday::Store::Redis
42
66
  end
43
67
  ```
44
68
 
@@ -84,32 +108,24 @@ add_column :users, :avatar_tmp, :string
84
108
 
85
109
  ## Usage Tips
86
110
 
111
+ ### Bypass backgrounding
87
112
  If you need to process/store the upload immediately:
88
113
 
89
114
  ```ruby
90
115
  @user.process_<column>_upload = true
91
116
  ```
92
117
 
118
+ ### Override worker
93
119
  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
94
120
  second argument:
95
121
 
96
122
  ```ruby
97
123
  process_in_background :avatar, MyAppsAwesomeProcessingWorker
98
124
  ```
99
-
100
- ## ORM
101
-
102
- Currently ActiveRecord is the default orm and I have not tested this with others but it should work by adding the following to your carrierwave initializer:
103
-
104
- ```ruby
105
- DataMapper::Model.send(:include, ::CarrierWave::Backgrounder::ORM::Base)
106
- # or
107
- Mongoid::Document::ClassMethods.send(:include, ::CarrierWave::Backgrounder::ORM::Base)
108
- # or
109
- Sequel::Model.send(:extend, ::CarrierWave::Backgrounder::ORM::Base)
110
- ```
111
-
112
- Contributions are gladly accepted from those who use these orms.
125
+ ### Testing with Rspec
126
+ We use the after_commit hook when using active_record. This creates a problem when testing with Rspec because after_commit never gets fired
127
+ if you're using trasactional fixtures. One solution to the problem is to use the [TestAfterCommit gem](https://github.com/grosser/test_after_commit).
128
+ There are various other solutions in which case google is your friend.
113
129
 
114
130
  ## License
115
131
 
@@ -20,7 +20,7 @@ Gem::Specification.new do |s|
20
20
 
21
21
  s.add_dependency "carrierwave", ["~> 0.5"]
22
22
 
23
- s.add_development_dependency "rspec", ["2.5.0"]
24
- s.add_development_dependency "mocha", ["~> 0.12.0"]
23
+ s.add_development_dependency "rspec", ["~> 2.12.0"]
24
+ s.add_development_dependency "mocha", ["~> 0.13.0"]
25
25
  s.add_development_dependency "rake"
26
26
  end
@@ -1,31 +1,25 @@
1
1
  module CarrierWave
2
2
  module Backgrounder
3
3
 
4
- module DelayStorage
5
- def self.included(klass)
6
- klass.send :include, Delay
7
- Logger.warn "Carrierwave::Backgrounder::DelayStorage is deprecated, use Carrierwave::Backgrounder::Delay instead"
8
- end
9
- end
10
-
11
4
  module Delay
12
-
13
- ##
14
- # Intercept carrierwave#cache_versions! so we can process versions later.
15
5
  def cache_versions!(new_file)
16
- super(new_file) if proceed_with_versioning?
6
+ super if proceed_with_versioning?
7
+ end
8
+
9
+ def store_versions!(*args)
10
+ super if proceed_with_versioning?
17
11
  end
18
12
 
19
13
  def process!(new_file=nil)
20
- super(new_file) if proceed_with_versioning?
14
+ super if proceed_with_versioning?
21
15
  end
22
-
16
+
23
17
  private
24
18
 
25
19
  def proceed_with_versioning?
26
20
  !model.respond_to?(:"process_#{mounted_as}_upload") || model.send(:"process_#{mounted_as}_upload")
27
21
  end
28
22
  end # Delay
29
-
23
+
30
24
  end # Backgrounder
31
25
  end # CarrierWave
@@ -10,11 +10,10 @@ module CarrierWave
10
10
  def process_in_background(column, worker=::CarrierWave::Workers::ProcessAsset)
11
11
  super
12
12
 
13
- mod = Module.new
14
- include mod
15
- mod.module_eval <<-RUBY, __FILE__, __LINE__ + 1
13
+ class_eval <<-RUBY, __FILE__, __LINE__ + 1
16
14
  def trigger_#{column}_background_processing?
17
- super && (#{column}_changed? || previous_changes.has_key?(:#{column}) || remote_#{column}_url.present?)
15
+ process_#{column}_upload != true &&
16
+ (#{column}_changed? || previous_changes.has_key?(:#{column}) || remote_#{column}_url.present?)
18
17
  end
19
18
  RUBY
20
19
  end
@@ -22,11 +21,10 @@ module CarrierWave
22
21
  def store_in_background(column, worker=::CarrierWave::Workers::StoreAsset)
23
22
  super
24
23
 
25
- mod = Module.new
26
- include mod
27
- mod.module_eval <<-RUBY, __FILE__, __LINE__ + 1
24
+ class_eval <<-RUBY, __FILE__, __LINE__ + 1
28
25
  def trigger_#{column}_background_storage?
29
- super && (#{column}_changed? || previous_changes.has_key?(:#{column}) || remote_#{column}_url.present?)
26
+ process_#{column}_upload != true &&
27
+ (#{column}_changed? || previous_changes.has_key?(:#{column}) || remote_#{column}_url.present?)
30
28
  end
31
29
  RUBY
32
30
  end
@@ -39,18 +39,13 @@ module CarrierWave
39
39
  # end
40
40
  #
41
41
  def process_in_background(column, worker=::CarrierWave::Workers::ProcessAsset)
42
- send :before_save, :"set_#{column}_processing", :if => :"trigger_#{column}_background_processing?"
43
- if self.respond_to?(:after_commit)
44
- send :after_commit, :"enqueue_#{column}_background_job", :if => :"trigger_#{column}_background_processing?"
45
- else
46
- send :after_save, :"enqueue_#{column}_background_job", :if => :"trigger_#{column}_background_processing?"
47
- end
48
42
  send :attr_accessor, :"process_#{column}_upload"
49
43
 
50
- mod = Module.new
51
- include mod
44
+ send :before_save, :"set_#{column}_processing", :if => :"trigger_#{column}_background_processing?"
45
+ callback = self.respond_to?(:after_commit) ? :after_commit : :after_save
46
+ send callback, :"enqueue_#{column}_background_job", :if => :"trigger_#{column}_background_processing?"
52
47
 
53
- mod.module_eval <<-RUBY, __FILE__, __LINE__ + 1
48
+ class_eval <<-RUBY, __FILE__, __LINE__ + 1
54
49
 
55
50
  def set_#{column}_processing
56
51
  self.#{column}_processing = true if respond_to?(:#{column}_processing)
@@ -90,16 +85,12 @@ module CarrierWave
90
85
  # end
91
86
  #
92
87
  def store_in_background(column, worker=::CarrierWave::Workers::StoreAsset)
93
- if self.respond_to?(:after_commit)
94
- send :after_commit, :"enqueue_#{column}_background_job", :if => :"trigger_#{column}_background_storage?"
95
- else
96
- send :after_save, :"enqueue_#{column}_background_job", :if => :"trigger_#{column}_background_storage?"
97
- end
98
88
  send :attr_accessor, :"process_#{column}_upload"
99
89
 
100
- mod = Module.new
101
- include mod
102
- mod.module_eval <<-RUBY, __FILE__, __LINE__ + 1
90
+ callback = self.respond_to?(:after_commit) ? :after_commit : :after_save
91
+ send callback, :"enqueue_#{column}_background_job", :if => :"trigger_#{column}_background_storage?"
92
+
93
+ class_eval <<-RUBY, __FILE__, __LINE__ + 1
103
94
 
104
95
  def write_#{column}_identifier
105
96
  super() and return if process_#{column}_upload
@@ -0,0 +1,75 @@
1
+ module Support
2
+ module Backends
3
+
4
+ def self.included(base)
5
+ base.extend ClassMethods
6
+ end
7
+
8
+ module ClassMethods
9
+ attr_writer :backend
10
+ attr_reader :queue_options
11
+
12
+ def backend(queue_name=nil, args={})
13
+ return @backend if @backend
14
+ @queue_options = args
15
+ @backend = queue_name and return if queue_name
16
+ determine_backend
17
+ end
18
+
19
+ def available_backends
20
+ @available_backends ||= begin
21
+ backends = []
22
+ backends << :girl_friday if defined? ::GirlFriday
23
+ backends << :delayed_job if defined? ::Delayed::Job
24
+ backends << :resque if defined? ::Resque
25
+ backends << :qu if defined? ::Qu
26
+ backends << :sidekiq if defined? ::Sidekiq
27
+ backends << :qc if defined? ::QC
28
+ backends << :immediate
29
+ end
30
+ end
31
+
32
+ def enqueue_for_backend(worker, class_name, subject_id, mounted_as)
33
+ case backend
34
+ when :girl_friday
35
+ @girl_friday_queue ||= GirlFriday::WorkQueue.new(queue_options.delete(:queue) || :carrierwave, queue_options) do |msg|
36
+ worker = msg[:worker]
37
+ worker.perform
38
+ end
39
+ @girl_friday_queue << { :worker => worker.new(class_name, subject_id, mounted_as) }
40
+ when :delayed_job
41
+ ::Delayed::Job.enqueue worker.new(class_name, subject_id, mounted_as), :queue => queue_options[:queue]
42
+ when :resque
43
+ worker.instance_variable_set('@queue', queue_options[:queue] || :carrierwave)
44
+ ::Resque.enqueue worker, class_name, subject_id, mounted_as
45
+ when :qu
46
+ worker.instance_variable_set('@queue', queue_options[:queue] || :carrierwave)
47
+ ::Qu.enqueue worker, class_name, subject_id, mounted_as
48
+ when :sidekiq
49
+ worker.extend ::Sidekiq::Worker
50
+ worker.sidekiq_options queue_options[:queue] || :carrierwave
51
+ ::Sidekiq::Client.enqueue worker, class_name, subject_id, mounted_as
52
+ when :qc
53
+ ::QC.enqueue "#{worker.name}.perform", class_name, subject_id, mounted_as.to_s
54
+ when :immediate
55
+ worker.new(class_name, subject_id, mounted_as).perform
56
+ end
57
+ end
58
+
59
+ private
60
+
61
+ def determine_backend
62
+ @backend = if available_backends.empty?
63
+ warn 'WARNING: No available queue backends found for CarrierWave::Backgrounder. Using the :immediate.'
64
+ :immediate
65
+ elsif available_backends.size > 1
66
+ raise ::CarrierWave::Backgrounder::ToManyBackendsAvailableError,
67
+ "You have to many backends available: #{available_backends.inspect}. Please specify which one to use in configuration block"
68
+ else
69
+ available_backends.first
70
+ end
71
+ end
72
+
73
+ end
74
+ end
75
+ end
@@ -1,5 +1,5 @@
1
1
  module CarrierWave
2
2
  module Backgrounder
3
- VERSION = "0.0.9"
3
+ VERSION = "0.1.0"
4
4
  end
5
5
  end
@@ -3,20 +3,11 @@ module CarrierWave
3
3
  module Workers
4
4
 
5
5
  class ProcessAsset < Struct.new(:klass, :id, :column)
6
- @queue = :process_asset
7
-
8
- if defined?(::Sidekiq)
9
- include ::Sidekiq::Worker
10
-
11
- sidekiq_options :queue => @queue
12
- end
13
-
14
6
  def self.perform(*args)
15
7
  new(*args).perform
16
8
  end
17
9
 
18
- def perform(*args)
19
- set_args(*args) unless args.empty?
10
+ def perform
20
11
  resource = klass.is_a?(String) ? klass.constantize : klass
21
12
  record = resource.find id
22
13
 
@@ -28,11 +19,6 @@ module CarrierWave
28
19
  end
29
20
  end
30
21
  end
31
-
32
- def set_args(klass, id, column)
33
- self.klass, self.id, self.column = klass, id, column
34
- end
35
-
36
22
  end # ProcessAsset
37
23
 
38
24
  end # Workers
@@ -3,20 +3,11 @@ module CarrierWave
3
3
  module Workers
4
4
 
5
5
  class StoreAsset < Struct.new(:klass, :id, :column)
6
- @queue = :store_asset
7
-
8
- if defined?(::Sidekiq)
9
- include ::Sidekiq::Worker
10
-
11
- sidekiq_options :queue => @queue
12
- end
13
-
14
6
  def self.perform(*args)
15
7
  new(*args).perform
16
8
  end
17
9
 
18
- def perform(*args)
19
- set_args(*args) unless args.empty?
10
+ def perform
20
11
  resource = klass.is_a?(String) ? klass.constantize : klass
21
12
  record = resource.find id
22
13
  if tmp = record.send(:"#{column}_tmp")
@@ -32,11 +23,6 @@ module CarrierWave
32
23
  end
33
24
  end
34
25
  end
35
-
36
- def set_args(klass, id, column)
37
- self.klass, self.id, self.column = klass, id, column
38
- end
39
-
40
26
  end # StoreAsset
41
27
 
42
28
  end # Workers
@@ -1,76 +1,16 @@
1
+ require 'backgrounder/support/backends'
2
+ require 'backgrounder/orm/base'
3
+ require 'backgrounder/delay'
4
+
1
5
  module CarrierWave
2
6
  module Backgrounder
7
+ include Support::Backends
3
8
 
4
- Logger = Logger.new(STDOUT)
5
-
6
- autoload :Delay, 'backgrounder/delay'
7
- autoload :DelayStorage, 'backgrounder/delay'
8
-
9
- module ORM
10
- autoload :Base, 'backgrounder/orm/base'
11
- end
12
-
13
- class << self
14
- def backend=(value)
15
- @backend = value
16
- self.configure_backend
17
- end
18
-
19
- def backend
20
- return @backend unless @backend.nil?
21
- if available_backends.empty?
22
- warn 'WARNING: No queue backends found to use for CarrierWave::Backgrounder'
23
- elsif available_backends.size == 1
24
- self.backend = available_backends.first
25
- elsif available_backends.size > 1
26
- warn 'WARNING: Multiple queue backends found for CarrierWave::Backgrounder. You need to set one explicitly.'
27
- end
28
- end
29
-
30
- def configure
31
- yield self
32
- end
33
-
34
- def available_backends
35
- @available_backends ||= begin
36
- backends = []
37
- backends << :girl_friday if defined? ::GirlFriday
38
- backends << :delayed_job if defined? ::Delayed::Job
39
- backends << :resque if defined? ::Resque
40
- backends << :qu if defined? ::Qu
41
- backends << :sidekiq if defined? ::Sidekiq
42
- backends << :qc if defined? ::QC
43
- backends
44
- end
45
- end
46
-
47
- def configure_backend
48
- if backend == :girl_friday
49
- require 'girl_friday'
50
- @girl_friday_queue = GirlFriday::WorkQueue.new(:carrierwave) do |msg|
51
- worker = msg[:worker]
52
- worker.perform
53
- end
54
- end
55
- end
56
-
57
- def enqueue_for_backend(worker, class_name, subject_id, mounted_as)
58
- case backend
59
- when :girl_friday
60
- @girl_friday_queue << { :worker => worker.new(self.class.name, subject_id, mounted_as) }
61
- when :delayed_job
62
- ::Delayed::Job.enqueue worker.new(class_name, subject_id, mounted_as)
63
- when :resque
64
- ::Resque.enqueue worker, class_name, subject_id, mounted_as
65
- when :qu
66
- ::Qu.enqueue worker, class_name, subject_id, column.mounted_as
67
- when :sidekiq
68
- ::Sidekiq::Client.enqueue worker, class_name, subject_id, mounted_as
69
- when :qc
70
- ::QC.enqueue "#{worker.name}.perform", class_name, subject_id, mounted_as.to_s
71
- end
72
- end
9
+ class UnsupportedBackendError < StandardError ; end
10
+ class ToManyBackendsAvailableError < StandardError ; end
73
11
 
12
+ def self.configure
13
+ yield self
74
14
  end
75
15
 
76
16
  end
@@ -103,4 +43,3 @@ if defined?(Rails)
103
43
  end
104
44
  end
105
45
  end
106
-
@@ -0,0 +1,87 @@
1
+ require 'spec_helper'
2
+
3
+ describe Support::Backends do
4
+ let(:test_module) { Module.new }
5
+
6
+ before do
7
+ test_module.send :include, Support::Backends
8
+ end
9
+
10
+ describe 'enumerating available backends' do
11
+ it 'detects GirlFriday' do
12
+ test_module.available_backends.should include(:girl_friday)
13
+ end
14
+
15
+ it 'detects Delayed::Job' do
16
+ test_module.available_backends.should include(:delayed_job)
17
+ end
18
+
19
+ it 'detects Resque' do
20
+ test_module.available_backends.should include(:resque)
21
+ end
22
+
23
+ it 'detects Qu' do
24
+ test_module.available_backends.should include(:qu)
25
+ end
26
+
27
+ it 'detects Sidekiq' do
28
+ test_module.available_backends.should include(:sidekiq)
29
+ end
30
+
31
+ it 'detects QC' do
32
+ test_module.available_backends.should include(:qc)
33
+ end
34
+
35
+ it 'detects Immediate' do
36
+ test_module.available_backends.should include(:immediate)
37
+ end
38
+ end
39
+
40
+ describe 'setting backend' do
41
+ it 'using #backend=' do
42
+ test_module.backend = :delayed_job
43
+ expect(test_module.backend).to eql(:delayed_job)
44
+ end
45
+
46
+ it 'using #backend' do
47
+ test_module.backend(:delayed_job)
48
+ expect(test_module.backend).to eql(:delayed_job)
49
+ end
50
+
51
+ it 'allows passing of queue_options' do
52
+ test_module.backend(:delayed_job, queue: :awesome_queue)
53
+ expect(test_module.queue_options).to eql({queue: :awesome_queue})
54
+ end
55
+ end
56
+
57
+ describe 'automatically setting backends' do
58
+ before do
59
+ test_module.instance_variable_set('@backend', nil)
60
+ end
61
+
62
+ it 'sets the backend to immediate if none available' do
63
+ suppress_warnings do
64
+ test_module.stubs(:available_backends).returns([])
65
+ expect(test_module.backend).to eql(:immediate)
66
+ end
67
+ end
68
+
69
+ it 'sets a backend automatically if only one is available' do
70
+ test_module.stubs(:available_backends).returns([ :qu ])
71
+ test_module.backend.should eq(:qu)
72
+ end
73
+
74
+ it 'raises an error if more than one backend is available' do
75
+ test_module.stubs(:available_backends).returns([:qu, :resque])
76
+ expect {
77
+ test_module.backend
78
+ }.to raise_error(CarrierWave::Backgrounder::ToManyBackendsAvailableError)
79
+ end
80
+
81
+ it 'does not clobber a manually set backend' do
82
+ test_module.backend = :not_a_backend
83
+ test_module.backend.should eq(:not_a_backend)
84
+ end
85
+ end
86
+ end
87
+
data/spec/spec_helper.rb CHANGED
@@ -3,6 +3,7 @@ require 'rubygems'
3
3
  require 'bundler/setup'
4
4
  require 'support/backend_constants'
5
5
  require 'logger'
6
+ require 'carrierwave_backgrounder'
6
7
 
7
8
  module WarningSuppression
8
9
  def suppress_warnings
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.0.9
4
+ version: 0.1.0
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: 2012-11-13 00:00:00.000000000 Z
12
+ date: 2012-12-13 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: carrierwave
@@ -32,17 +32,17 @@ dependencies:
32
32
  requirement: !ruby/object:Gem::Requirement
33
33
  none: false
34
34
  requirements:
35
- - - '='
35
+ - - ~>
36
36
  - !ruby/object:Gem::Version
37
- version: 2.5.0
37
+ version: 2.12.0
38
38
  type: :development
39
39
  prerelease: false
40
40
  version_requirements: !ruby/object:Gem::Requirement
41
41
  none: false
42
42
  requirements:
43
- - - '='
43
+ - - ~>
44
44
  - !ruby/object:Gem::Version
45
- version: 2.5.0
45
+ version: 2.12.0
46
46
  - !ruby/object:Gem::Dependency
47
47
  name: mocha
48
48
  requirement: !ruby/object:Gem::Requirement
@@ -50,7 +50,7 @@ dependencies:
50
50
  requirements:
51
51
  - - ~>
52
52
  - !ruby/object:Gem::Version
53
- version: 0.12.0
53
+ version: 0.13.0
54
54
  type: :development
55
55
  prerelease: false
56
56
  version_requirements: !ruby/object:Gem::Requirement
@@ -58,7 +58,7 @@ dependencies:
58
58
  requirements:
59
59
  - - ~>
60
60
  - !ruby/object:Gem::Version
61
- version: 0.12.0
61
+ version: 0.13.0
62
62
  - !ruby/object:Gem::Dependency
63
63
  name: rake
64
64
  requirement: !ruby/object:Gem::Requirement
@@ -92,14 +92,15 @@ files:
92
92
  - lib/backgrounder/orm/activemodel.rb
93
93
  - lib/backgrounder/orm/base.rb
94
94
  - lib/backgrounder/orm/data_mapper.rb
95
+ - lib/backgrounder/support/backends.rb
95
96
  - lib/backgrounder/version.rb
96
97
  - lib/backgrounder/workers.rb
97
98
  - lib/backgrounder/workers/process_asset.rb
98
99
  - lib/backgrounder/workers/store_asset.rb
99
100
  - lib/carrierwave_backgrounder.rb
100
- - spec/backgrounder/backends_spec.rb
101
101
  - spec/backgrounder/orm/activemodel_spec.rb
102
102
  - spec/backgrounder/orm/base_spec.rb
103
+ - spec/backgrounder/support/backends_spec.rb
103
104
  - spec/backgrounder/workers/fixtures/test.jpg
104
105
  - spec/backgrounder/workers/process_asset_spec.rb
105
106
  - spec/backgrounder/workers/store_asset_spec.rb
@@ -119,7 +120,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
119
120
  version: '0'
120
121
  segments:
121
122
  - 0
122
- hash: 1188528619388271900
123
+ hash: 1110196865602212339
123
124
  required_rubygems_version: !ruby/object:Gem::Requirement
124
125
  none: false
125
126
  requirements:
@@ -128,7 +129,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
128
129
  version: '0'
129
130
  segments:
130
131
  - 0
131
- hash: 1188528619388271900
132
+ hash: 1110196865602212339
132
133
  requirements: []
133
134
  rubyforge_project: carrierwave_backgrounder
134
135
  rubygems_version: 1.8.24
@@ -137,9 +138,9 @@ specification_version: 3
137
138
  summary: Offload CarrierWave's image processing and storage to a background process
138
139
  using Delayed Job
139
140
  test_files:
140
- - spec/backgrounder/backends_spec.rb
141
141
  - spec/backgrounder/orm/activemodel_spec.rb
142
142
  - spec/backgrounder/orm/base_spec.rb
143
+ - spec/backgrounder/support/backends_spec.rb
143
144
  - spec/backgrounder/workers/fixtures/test.jpg
144
145
  - spec/backgrounder/workers/process_asset_spec.rb
145
146
  - spec/backgrounder/workers/store_asset_spec.rb
@@ -1,67 +0,0 @@
1
- require 'spec_helper'
2
- require 'carrierwave_backgrounder'
3
-
4
- describe CarrierWave::Backgrounder do
5
-
6
- describe 'enumerating available backends' do
7
-
8
- it 'detects GirlFriday' do
9
- CarrierWave::Backgrounder.available_backends.should include(:girl_friday)
10
- end
11
- it 'detects Delayed::Job' do
12
- CarrierWave::Backgrounder.available_backends.should include(:delayed_job)
13
- end
14
- it 'detects Resque' do
15
- CarrierWave::Backgrounder.available_backends.should include(:resque)
16
- end
17
- it 'detects Qu' do
18
- CarrierWave::Backgrounder.available_backends.should include(:qu)
19
- end
20
- it 'detects Sidekiq' do
21
- CarrierWave::Backgrounder.available_backends.should include(:sidekiq)
22
- end
23
- it 'detects QC' do
24
- CarrierWave::Backgrounder.available_backends.should include(:qc)
25
- end
26
- end
27
-
28
- describe 'automatically setting backends' do
29
-
30
- before do
31
- CarrierWave::Backgrounder.instance_variable_set('@backend', nil)
32
- end
33
-
34
- it 'does not set a backend if none are available' do
35
- suppress_warnings do
36
- CarrierWave::Backgrounder.stubs(:available_backends).returns([])
37
- CarrierWave::Backgrounder.backend.should be_nil
38
- end
39
- end
40
- it 'sets a backend automatically if only one is available' do
41
- CarrierWave::Backgrounder.stubs(:available_backends).returns([ :qu ])
42
- CarrierWave::Backgrounder.backend.should eq(:qu)
43
- end
44
- it 'does not set a backend if more than one is available' do
45
- suppress_warnings do
46
- CarrierWave::Backgrounder.stubs(:available_backends).returns([:qu, :resque])
47
- CarrierWave::Backgrounder.backend.should be_nil
48
- end
49
- end
50
-
51
- it 'does not clobber a manually set backend' do
52
- CarrierWave::Backgrounder.backend = :not_a_backend
53
- CarrierWave::Backgrounder.backend.should eq(:not_a_backend)
54
- end
55
-
56
- it 'calls configure_backend when setting the backend' do
57
- CarrierWave::Backgrounder.stubs(:available_backends).returns([ :qu ])
58
- CarrierWave::Backgrounder.expects(:configure_backend).once
59
- CarrierWave::Backgrounder.backend.should eq(:qu)
60
- end
61
-
62
- end
63
-
64
-
65
-
66
- end
67
-