delayed_paperclip 2.6.0.0 → 2.6.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +7 -0
- data/.rbenv-version +1 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/.travis.yml +27 -0
- data/Appraisals +15 -0
- data/CONTRIBUTING +19 -0
- data/ChangeLog +4 -0
- data/Gemfile +11 -0
- data/Rakefile +7 -2
- data/delayed_paperclip.gemspec +26 -0
- data/gemfiles/paperclip3_5.gemfile +11 -0
- data/gemfiles/paperclip3_5.gemfile.lock +160 -0
- data/gemfiles/rails3.gemfile +10 -0
- data/gemfiles/rails3.gemfile.lock +151 -0
- data/gemfiles/rails3_1.gemfile +10 -0
- data/gemfiles/rails3_1.gemfile.lock +161 -0
- data/gemfiles/rails3_2.gemfile +10 -0
- data/gemfiles/rails3_2.gemfile.lock +159 -0
- data/lib/delayed_paperclip/attachment.rb +9 -7
- data/lib/delayed_paperclip/jobs/delayed_job.rb +2 -2
- data/lib/delayed_paperclip/jobs.rb +2 -2
- data/lib/delayed_paperclip/railtie.rb +5 -0
- data/lib/delayed_paperclip/url_generator.rb +15 -2
- data/lib/delayed_paperclip/version.rb +3 -0
- data/lib/delayed_paperclip.rb +28 -17
- data/spec/delayed_paperclip/attachment_spec.rb +153 -0
- data/spec/delayed_paperclip/class_methods_spec.rb +85 -0
- data/spec/delayed_paperclip/instance_methods_spec.rb +80 -0
- data/spec/delayed_paperclip/url_generator_spec.rb +171 -0
- data/spec/delayed_paperclip_spec.rb +56 -0
- data/spec/fixtures/12k.png +0 -0
- data/spec/integration/delayed_job_spec.rb +55 -0
- data/spec/integration/examples/base.rb +316 -0
- data/spec/integration/resque_spec.rb +40 -0
- data/spec/integration/sidekiq_spec.rb +48 -0
- data/spec/spec_helper.rb +86 -0
- data/test/base_delayed_paperclip_test.rb +3 -3
- data/test/test_helper.rb +14 -7
- metadata +84 -51
@@ -0,0 +1,159 @@
|
|
1
|
+
PATH
|
2
|
+
remote: ..
|
3
|
+
specs:
|
4
|
+
delayed_paperclip (2.6.1)
|
5
|
+
paperclip (>= 3.3.0)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: http://rubygems.org/
|
9
|
+
specs:
|
10
|
+
actionmailer (3.2.13)
|
11
|
+
actionpack (= 3.2.13)
|
12
|
+
mail (~> 2.5.3)
|
13
|
+
actionpack (3.2.13)
|
14
|
+
activemodel (= 3.2.13)
|
15
|
+
activesupport (= 3.2.13)
|
16
|
+
builder (~> 3.0.0)
|
17
|
+
erubis (~> 2.7.0)
|
18
|
+
journey (~> 1.0.4)
|
19
|
+
rack (~> 1.4.5)
|
20
|
+
rack-cache (~> 1.2)
|
21
|
+
rack-test (~> 0.6.1)
|
22
|
+
sprockets (~> 2.2.1)
|
23
|
+
activemodel (3.2.13)
|
24
|
+
activesupport (= 3.2.13)
|
25
|
+
builder (~> 3.0.0)
|
26
|
+
activerecord (3.2.13)
|
27
|
+
activemodel (= 3.2.13)
|
28
|
+
activesupport (= 3.2.13)
|
29
|
+
arel (~> 3.0.2)
|
30
|
+
tzinfo (~> 0.3.29)
|
31
|
+
activeresource (3.2.13)
|
32
|
+
activemodel (= 3.2.13)
|
33
|
+
activesupport (= 3.2.13)
|
34
|
+
activesupport (3.2.13)
|
35
|
+
i18n (= 0.6.1)
|
36
|
+
multi_json (~> 1.0)
|
37
|
+
appraisal (0.5.2)
|
38
|
+
bundler
|
39
|
+
rake
|
40
|
+
arel (3.0.2)
|
41
|
+
builder (3.0.4)
|
42
|
+
celluloid (0.14.1)
|
43
|
+
timers (>= 1.0.0)
|
44
|
+
climate_control (0.0.3)
|
45
|
+
activesupport (>= 3.0)
|
46
|
+
cocaine (0.5.1)
|
47
|
+
climate_control (>= 0.0.3, < 1.0)
|
48
|
+
connection_pool (1.0.0)
|
49
|
+
delayed_job (3.0.5)
|
50
|
+
activesupport (~> 3.0)
|
51
|
+
delayed_job_active_record (0.4.4)
|
52
|
+
activerecord (>= 2.1.0, < 4)
|
53
|
+
delayed_job (~> 3.0)
|
54
|
+
diff-lcs (1.2.4)
|
55
|
+
erubis (2.7.0)
|
56
|
+
hike (1.2.2)
|
57
|
+
i18n (0.6.1)
|
58
|
+
journey (1.0.4)
|
59
|
+
json (1.8.0)
|
60
|
+
mail (2.5.4)
|
61
|
+
mime-types (~> 1.16)
|
62
|
+
treetop (~> 1.4.8)
|
63
|
+
metaclass (0.0.1)
|
64
|
+
mime-types (1.23)
|
65
|
+
mocha (0.14.0)
|
66
|
+
metaclass (~> 0.0.1)
|
67
|
+
mono_logger (1.1.0)
|
68
|
+
multi_json (1.7.5)
|
69
|
+
paperclip (3.5.0)
|
70
|
+
activemodel (>= 3.0.0)
|
71
|
+
activesupport (>= 3.0.0)
|
72
|
+
cocaine (~> 0.5.0)
|
73
|
+
mime-types
|
74
|
+
polyglot (0.3.3)
|
75
|
+
rack (1.4.5)
|
76
|
+
rack-cache (1.2)
|
77
|
+
rack (>= 0.4)
|
78
|
+
rack-protection (1.5.0)
|
79
|
+
rack
|
80
|
+
rack-ssl (1.3.3)
|
81
|
+
rack
|
82
|
+
rack-test (0.6.2)
|
83
|
+
rack (>= 1.0)
|
84
|
+
rails (3.2.13)
|
85
|
+
actionmailer (= 3.2.13)
|
86
|
+
actionpack (= 3.2.13)
|
87
|
+
activerecord (= 3.2.13)
|
88
|
+
activeresource (= 3.2.13)
|
89
|
+
activesupport (= 3.2.13)
|
90
|
+
bundler (~> 1.0)
|
91
|
+
railties (= 3.2.13)
|
92
|
+
railties (3.2.13)
|
93
|
+
actionpack (= 3.2.13)
|
94
|
+
activesupport (= 3.2.13)
|
95
|
+
rack-ssl (~> 1.3.2)
|
96
|
+
rake (>= 0.8.7)
|
97
|
+
rdoc (~> 3.4)
|
98
|
+
thor (>= 0.14.6, < 2.0)
|
99
|
+
rake (10.0.4)
|
100
|
+
rdoc (3.12.2)
|
101
|
+
json (~> 1.4)
|
102
|
+
redis (3.0.4)
|
103
|
+
redis-namespace (1.3.0)
|
104
|
+
redis (~> 3.0.0)
|
105
|
+
resque (1.24.1)
|
106
|
+
mono_logger (~> 1.0)
|
107
|
+
multi_json (~> 1.0)
|
108
|
+
redis-namespace (~> 1.2)
|
109
|
+
sinatra (>= 0.9.2)
|
110
|
+
vegas (~> 0.1.2)
|
111
|
+
rspec (2.14.1)
|
112
|
+
rspec-core (~> 2.14.0)
|
113
|
+
rspec-expectations (~> 2.14.0)
|
114
|
+
rspec-mocks (~> 2.14.0)
|
115
|
+
rspec-core (2.14.4)
|
116
|
+
rspec-expectations (2.14.0)
|
117
|
+
diff-lcs (>= 1.1.3, < 2.0)
|
118
|
+
rspec-mocks (2.14.1)
|
119
|
+
sidekiq (2.12.1)
|
120
|
+
celluloid (>= 0.14.1)
|
121
|
+
connection_pool (>= 1.0.0)
|
122
|
+
json
|
123
|
+
redis (>= 3.0)
|
124
|
+
redis-namespace
|
125
|
+
sinatra (1.3.6)
|
126
|
+
rack (~> 1.4)
|
127
|
+
rack-protection (~> 1.3)
|
128
|
+
tilt (~> 1.3, >= 1.3.3)
|
129
|
+
sprockets (2.2.2)
|
130
|
+
hike (~> 1.2)
|
131
|
+
multi_json (~> 1.0)
|
132
|
+
rack (~> 1.0)
|
133
|
+
tilt (~> 1.1, != 1.3.0)
|
134
|
+
sqlite3 (1.3.7)
|
135
|
+
thor (0.18.1)
|
136
|
+
tilt (1.4.1)
|
137
|
+
timers (1.1.0)
|
138
|
+
treetop (1.4.12)
|
139
|
+
polyglot
|
140
|
+
polyglot (>= 0.3.1)
|
141
|
+
tzinfo (0.3.37)
|
142
|
+
vegas (0.1.11)
|
143
|
+
rack (>= 1.0.0)
|
144
|
+
|
145
|
+
PLATFORMS
|
146
|
+
ruby
|
147
|
+
|
148
|
+
DEPENDENCIES
|
149
|
+
appraisal
|
150
|
+
delayed_job
|
151
|
+
delayed_job_active_record
|
152
|
+
delayed_paperclip!
|
153
|
+
json
|
154
|
+
mocha
|
155
|
+
rails (~> 3.2.8)
|
156
|
+
resque
|
157
|
+
rspec
|
158
|
+
sidekiq
|
159
|
+
sqlite3
|
@@ -12,6 +12,11 @@ module DelayedPaperclip
|
|
12
12
|
|
13
13
|
module InstanceMethods
|
14
14
|
|
15
|
+
def delayed_options
|
16
|
+
@instance.class.paperclip_definitions[@name][:delayed]
|
17
|
+
end
|
18
|
+
|
19
|
+
# Attr accessor in Paperclip
|
15
20
|
def post_processing_with_delay
|
16
21
|
!delay_processing?
|
17
22
|
end
|
@@ -20,15 +25,13 @@ module DelayedPaperclip
|
|
20
25
|
@post_processing_with_delay = value
|
21
26
|
end
|
22
27
|
|
23
|
-
|
24
|
-
|
25
|
-
end
|
26
|
-
|
28
|
+
# if nil, returns whether it has delayed options
|
29
|
+
# if set, then it returns
|
27
30
|
def delay_processing?
|
28
31
|
if @post_processing_with_delay.nil?
|
29
32
|
!!delayed_options
|
30
33
|
else
|
31
|
-
|
34
|
+
!@post_processing_with_delay
|
32
35
|
end
|
33
36
|
end
|
34
37
|
|
@@ -49,10 +52,9 @@ module DelayedPaperclip
|
|
49
52
|
processing_image_url
|
50
53
|
end
|
51
54
|
|
52
|
-
|
55
|
+
# Updates _processing column to false
|
53
56
|
def after_flush_writes_with_processing(*args)
|
54
57
|
after_flush_writes_without_processing(*args)
|
55
|
-
|
56
58
|
# update_column is available in rails 3.1 instead we can do this to update the attribute without callbacks
|
57
59
|
|
58
60
|
# instance.update_column("#{name}_processing", false) if instance.respond_to?(:"#{name}_processing?")
|
@@ -9,7 +9,7 @@ module DelayedPaperclip
|
|
9
9
|
def self.enqueue_delayed_paperclip(instance_klass, instance_id, attachment_name)
|
10
10
|
::Delayed::Job.enqueue(
|
11
11
|
:payload_object => new(instance_klass, instance_id, attachment_name),
|
12
|
-
:priority => instance_klass.constantize.
|
12
|
+
:priority => instance_klass.constantize.paperclip_definitions[attachment_name][:delayed][:priority].to_i
|
13
13
|
)
|
14
14
|
end
|
15
15
|
|
@@ -18,7 +18,7 @@ module DelayedPaperclip
|
|
18
18
|
def self.enqueue_delayed_paperclip(instance_klass, instance_id, attachment_name)
|
19
19
|
::Delayed::Job.enqueue(
|
20
20
|
new(instance_klass, instance_id, attachment_name),
|
21
|
-
instance_klass.constantize.
|
21
|
+
instance_klass.constantize.paperclip_definitions[attachment_name][:delayed][:priority].to_i
|
22
22
|
)
|
23
23
|
end
|
24
24
|
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module DelayedPaperclip
|
2
2
|
module Jobs
|
3
3
|
autoload :DelayedJob, 'delayed_paperclip/jobs/delayed_job'
|
4
|
-
autoload :Resque,
|
5
|
-
autoload :Sidekiq,
|
4
|
+
autoload :Resque, 'delayed_paperclip/jobs/resque'
|
5
|
+
autoload :Sidekiq, 'delayed_paperclip/jobs/sidekiq'
|
6
6
|
end
|
7
7
|
end
|
@@ -4,6 +4,8 @@ require 'delayed_paperclip'
|
|
4
4
|
module DelayedPaperclip
|
5
5
|
if defined? Rails::Railtie
|
6
6
|
require 'rails'
|
7
|
+
|
8
|
+
# On initialzation, include DelayedPaperclip
|
7
9
|
class Railtie < Rails::Railtie
|
8
10
|
initializer 'delayed_paperclip.insert_into_active_record' do
|
9
11
|
ActiveSupport.on_load :active_record do
|
@@ -14,6 +16,9 @@ module DelayedPaperclip
|
|
14
16
|
end
|
15
17
|
|
16
18
|
class Railtie
|
19
|
+
|
20
|
+
# Glue includes DelayedPaperclip Class Methods and Instance Methods into ActiveRecord
|
21
|
+
# Attachment and URL Generator extends Paperclip
|
17
22
|
def self.insert
|
18
23
|
ActiveRecord::Base.send(:include, DelayedPaperclip::Glue)
|
19
24
|
Paperclip::Attachment.send(:include, DelayedPaperclip::Attachment)
|
@@ -1,8 +1,8 @@
|
|
1
1
|
require 'uri'
|
2
|
+
|
2
3
|
module DelayedPaperclip
|
3
4
|
module UrlGenerator
|
4
5
|
def self.included(base)
|
5
|
-
base.send :include, InstanceMethods
|
6
6
|
base.alias_method_chain :most_appropriate_url, :processed
|
7
7
|
base.alias_method_chain :timestamp_possible?, :processed
|
8
8
|
end
|
@@ -28,7 +28,20 @@ module DelayedPaperclip
|
|
28
28
|
end
|
29
29
|
|
30
30
|
def delayed_default_url?
|
31
|
-
|
31
|
+
return false if @attachment.job_is_processing
|
32
|
+
return false if @attachment.dirty?
|
33
|
+
return false if not @attachment.delayed_options.try(:[], :url_with_processing)
|
34
|
+
return false if not (@attachment.instance.respond_to?(:"#{@attachment.name}_processing?") && @attachment.processing?)
|
35
|
+
true
|
36
|
+
|
37
|
+
# OLD CRAZY CONDITIONAL
|
38
|
+
# TODO: Delete
|
39
|
+
# !(
|
40
|
+
# @attachment.job_is_processing ||
|
41
|
+
# @attachment.dirty? ||
|
42
|
+
# !@attachment.delayed_options.try(:[], :url_with_processing) ||
|
43
|
+
# !(@attachment.instance.respond_to?(:"#{@attachment.name}_processing?") && @attachment.processing?)
|
44
|
+
# )
|
32
45
|
end
|
33
46
|
end
|
34
47
|
|
data/lib/delayed_paperclip.rb
CHANGED
@@ -38,50 +38,51 @@ module DelayedPaperclip
|
|
38
38
|
end
|
39
39
|
|
40
40
|
module Glue
|
41
|
-
def self.included
|
41
|
+
def self.included(base)
|
42
42
|
base.extend(ClassMethods)
|
43
|
+
base.send :include, InstanceMethods
|
43
44
|
end
|
44
45
|
end
|
45
46
|
|
46
47
|
module ClassMethods
|
47
48
|
|
48
49
|
def process_in_background(name, options = {})
|
49
|
-
|
50
|
+
# initialize as hash
|
51
|
+
paperclip_definitions[name][:delayed] = {}
|
50
52
|
|
51
|
-
|
53
|
+
# Set Defaults
|
52
54
|
{
|
53
55
|
:priority => 0,
|
54
|
-
:only_process =>
|
56
|
+
:only_process => paperclip_definitions[name][:only_process],
|
55
57
|
:url_with_processing => DelayedPaperclip.options[:url_with_processing],
|
56
58
|
:processing_image_url => options[:processing_image_url]
|
57
59
|
}.each do |option, default|
|
58
60
|
|
59
|
-
|
61
|
+
paperclip_definitions[name][:delayed][option] = options.key?(option) ? options[option] : default
|
60
62
|
|
61
63
|
end
|
62
64
|
|
65
|
+
# Sets callback
|
63
66
|
if respond_to?(:after_commit)
|
64
67
|
after_commit :enqueue_delayed_processing
|
65
68
|
else
|
66
|
-
after_save
|
69
|
+
after_save :enqueue_delayed_processing
|
67
70
|
end
|
68
71
|
end
|
69
|
-
end
|
70
|
-
|
71
|
-
module InstanceMethods
|
72
72
|
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
updates = ActiveRecord::Base.send(:sanitize_sql_array, [updates, {:true => true}])
|
79
|
-
self.class.where(:id => self.id).update_all(updates)
|
73
|
+
def paperclip_definitions
|
74
|
+
@paperclip_definitions ||= if respond_to? :attachment_definitions
|
75
|
+
attachment_definitions
|
76
|
+
else
|
77
|
+
Paperclip::Tasks::Attachments.definitions_for(self)
|
80
78
|
end
|
81
79
|
end
|
80
|
+
end
|
81
|
+
|
82
|
+
module InstanceMethods
|
82
83
|
|
83
84
|
# First mark processing
|
84
|
-
# then
|
85
|
+
# then enqueue
|
85
86
|
def enqueue_delayed_processing
|
86
87
|
mark_enqueue_delayed_processing
|
87
88
|
|
@@ -92,6 +93,16 @@ module DelayedPaperclip
|
|
92
93
|
@_enqued_for_processing = []
|
93
94
|
end
|
94
95
|
|
96
|
+
# setting each inididual NAME_processing to true, skipping the ActiveModel dirty setter
|
97
|
+
# Then immediately push the state to the database
|
98
|
+
def mark_enqueue_delayed_processing
|
99
|
+
unless @_enqued_for_processing_with_processing.blank? # catches nil and empty arrays
|
100
|
+
updates = @_enqued_for_processing_with_processing.collect{|n| "#{n}_processing = :true" }.join(", ")
|
101
|
+
updates = ActiveRecord::Base.send(:sanitize_sql_array, [updates, {:true => true}])
|
102
|
+
self.class.where(:id => self.id).update_all(updates)
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
95
106
|
def enqueue_post_processing_for name
|
96
107
|
DelayedPaperclip.enqueue(self.class.name, read_attribute(:id), name.to_sym)
|
97
108
|
end
|
@@ -0,0 +1,153 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe DelayedPaperclip::Attachment do
|
4
|
+
|
5
|
+
before :all do
|
6
|
+
DelayedPaperclip.options[:background_job_class] = DelayedPaperclip::Jobs::Resque
|
7
|
+
reset_dummy
|
8
|
+
end
|
9
|
+
|
10
|
+
let(:dummy) { Dummy.create }
|
11
|
+
|
12
|
+
describe "#delayed_options" do
|
13
|
+
|
14
|
+
it "returns the specific options for delayed paperclip" do
|
15
|
+
dummy.image.delayed_options.should == {
|
16
|
+
:priority => 0,
|
17
|
+
:only_process => nil,
|
18
|
+
:url_with_processing => true,
|
19
|
+
:processing_image_url => nil
|
20
|
+
}
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
|
25
|
+
describe "#post_processing_with_delay" do
|
26
|
+
it "is true if delay_processing? is false" do
|
27
|
+
dummy.image.stubs(:delay_processing?).returns false
|
28
|
+
dummy.image.post_processing_with_delay.should be_true
|
29
|
+
end
|
30
|
+
|
31
|
+
it "is false if delay_processing? is true" do
|
32
|
+
dummy.image.stubs(:delay_processing?).returns true
|
33
|
+
dummy.image.post_processing_with_delay.should be_false
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
describe "delay_processing?" do
|
38
|
+
it "returns delayed_options existence if post_processing_with_delay is nil" do
|
39
|
+
dummy.image.post_processing_with_delay = nil
|
40
|
+
dummy.image.delay_processing?.should be_true
|
41
|
+
end
|
42
|
+
|
43
|
+
it "returns inverse of post_processing_with_delay if it's set" do
|
44
|
+
dummy.image.post_processing_with_delay = true
|
45
|
+
dummy.image.delay_processing?.should be_false
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
describe "processing?" do
|
50
|
+
it "delegates to the dummy instance" do
|
51
|
+
dummy.expects(:image_processing?)
|
52
|
+
dummy.image.processing?
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
describe "process_delayed!" do
|
57
|
+
it "sets job_is_processing to true" do
|
58
|
+
dummy.image.expects(:job_is_processing=).with(true).once
|
59
|
+
dummy.image.expects(:job_is_processing=).with(false).once
|
60
|
+
dummy.image.process_delayed!
|
61
|
+
end
|
62
|
+
|
63
|
+
it "sets post_processing to true" do
|
64
|
+
dummy.image.expects(:post_processing=).with(true).once
|
65
|
+
dummy.image.process_delayed!
|
66
|
+
end
|
67
|
+
|
68
|
+
context "without only_process options" do
|
69
|
+
it "calls reprocess!" do
|
70
|
+
dummy.image.expects(:reprocess!)
|
71
|
+
dummy.image.process_delayed!
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
context "with only_process options" do
|
76
|
+
before :each do
|
77
|
+
reset_dummy(paperclip: { only_process: [:small, :large] } )
|
78
|
+
end
|
79
|
+
|
80
|
+
it "calls reprocess! with options" do
|
81
|
+
dummy.image.expects(:reprocess!).with(:small, :large)
|
82
|
+
dummy.image.process_delayed!
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
describe "#processing_image_url" do
|
88
|
+
context "no url" do
|
89
|
+
it "returns nil" do
|
90
|
+
dummy.image.processing_image_url.should be_nil
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
context "static url" do
|
95
|
+
before :each do
|
96
|
+
reset_dummy(:processing_image_url => "/foo/bar.jpg")
|
97
|
+
end
|
98
|
+
|
99
|
+
it "returns given url" do
|
100
|
+
dummy.image.processing_image_url.should == "/foo/bar.jpg"
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
context "proc" do
|
105
|
+
before :each do
|
106
|
+
reset_dummy(:processing_image_url => proc { "Hello/World" } )
|
107
|
+
end
|
108
|
+
|
109
|
+
it "returns evaluates proc" do
|
110
|
+
dummy.image.processing_image_url.should == "Hello/World"
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
describe "#after_flush_writes_with_processing" do
|
116
|
+
it "updates the column to false" do
|
117
|
+
dummy.update_attribute(:image_processing, true)
|
118
|
+
|
119
|
+
dummy.image.after_flush_writes_with_processing
|
120
|
+
|
121
|
+
dummy.image_processing.should be_false
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
describe "#save_with_prepare_enqueueing" do
|
126
|
+
context "delay processing and it was dirty" do
|
127
|
+
before :each do
|
128
|
+
dummy.image.stubs(:delay_processing?).returns true
|
129
|
+
dummy.image.instance_variable_set(:@dirty, true)
|
130
|
+
end
|
131
|
+
|
132
|
+
it "prepares the enqueing" do
|
133
|
+
dummy.expects(:prepare_enqueueing_for).with(:image)
|
134
|
+
dummy.image.save_with_prepare_enqueueing
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
context "without dirty or delay_processing" do
|
139
|
+
it "does not prepare_enqueueing" do
|
140
|
+
dummy.expects(:prepare_enqueueing_for).with(:image).never
|
141
|
+
dummy.image.save_with_prepare_enqueueing
|
142
|
+
end
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
describe "#reprocess_without_delay!" do
|
147
|
+
it "sets post post_processing_with_delay and reprocesses with given args" do
|
148
|
+
dummy.image.expects(:reprocess!).with(:small)
|
149
|
+
dummy.image.reprocess_without_delay!(:small)
|
150
|
+
dummy.image.instance_variable_get(:@post_processing_with_delay).should == true
|
151
|
+
end
|
152
|
+
end
|
153
|
+
end
|
@@ -0,0 +1,85 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe DelayedPaperclip::ClassMethods do
|
4
|
+
|
5
|
+
before :all do
|
6
|
+
DelayedPaperclip.options[:background_job_class] = DelayedPaperclip::Jobs::Resque
|
7
|
+
reset_dummy(with_processed: false)
|
8
|
+
end
|
9
|
+
|
10
|
+
describe ".process_in_background" do
|
11
|
+
|
12
|
+
it "is empty to start" do
|
13
|
+
Dummy.paperclip_definitions.should == { :image => {} }
|
14
|
+
end
|
15
|
+
|
16
|
+
it "adds basics to paperclip_definitions" do
|
17
|
+
Dummy.process_in_background(:image)
|
18
|
+
Dummy.paperclip_definitions.should == { :image => {
|
19
|
+
:delayed => {
|
20
|
+
:priority => 0,
|
21
|
+
:only_process => nil,
|
22
|
+
:url_with_processing => true,
|
23
|
+
:processing_image_url => nil}
|
24
|
+
}
|
25
|
+
}
|
26
|
+
end
|
27
|
+
|
28
|
+
context "with processing_image_url" do
|
29
|
+
before :each do
|
30
|
+
Dummy.process_in_background(:image, processing_image_url: "/processing/url")
|
31
|
+
end
|
32
|
+
|
33
|
+
it "incorporates processing url" do
|
34
|
+
Dummy.paperclip_definitions.should == { :image => {
|
35
|
+
:delayed => {
|
36
|
+
:priority => 0,
|
37
|
+
:only_process => nil,
|
38
|
+
:url_with_processing => true,
|
39
|
+
:processing_image_url => "/processing/url"}
|
40
|
+
}
|
41
|
+
}
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
context "inherits only_process options" do
|
46
|
+
before :each do
|
47
|
+
reset_class("Dummy", paperclip: { only_process: [:small, :large] } )
|
48
|
+
Dummy.process_in_background(:image)
|
49
|
+
end
|
50
|
+
|
51
|
+
it "incorporates processing url" do
|
52
|
+
Dummy.paperclip_definitions.should == { :image => {
|
53
|
+
:only_process => [:small, :large],
|
54
|
+
:delayed => {
|
55
|
+
:priority => 0,
|
56
|
+
:only_process => [:small, :large],
|
57
|
+
:url_with_processing => true,
|
58
|
+
:processing_image_url => nil }
|
59
|
+
}
|
60
|
+
}
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
context "sets callback" do
|
65
|
+
context "commit" do
|
66
|
+
it "sets after_commit callback" do
|
67
|
+
Dummy.expects(:after_commit).with(:enqueue_delayed_processing)
|
68
|
+
Dummy.process_in_background(:image)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
context "save" do
|
73
|
+
before :each do
|
74
|
+
Dummy.stubs(:respond_to?).with(:after_commit).returns(false)
|
75
|
+
end
|
76
|
+
|
77
|
+
it "sets after_save callback" do
|
78
|
+
Dummy.expects(:after_save).with(:enqueue_delayed_processing)
|
79
|
+
Dummy.process_in_background(:image)
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
end
|
@@ -0,0 +1,80 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe DelayedPaperclip::InstanceMethods do
|
4
|
+
|
5
|
+
before :all do
|
6
|
+
DelayedPaperclip.options[:background_job_class] = DelayedPaperclip::Jobs::Resque
|
7
|
+
reset_dummy
|
8
|
+
end
|
9
|
+
|
10
|
+
let(:dummy) { Dummy.create }
|
11
|
+
|
12
|
+
describe "#enqueue_delayed_processing" do
|
13
|
+
|
14
|
+
it "marks enqueue_delayed_processing" do
|
15
|
+
dummy.expects(:mark_enqueue_delayed_processing)
|
16
|
+
dummy.enqueue_delayed_processing
|
17
|
+
end
|
18
|
+
|
19
|
+
it "enqueues post processing for all enqueued" do
|
20
|
+
dummy.instance_variable_set(:@_enqued_for_processing, ['image'])
|
21
|
+
dummy.expects(:enqueue_post_processing_for).with('image')
|
22
|
+
dummy.enqueue_delayed_processing
|
23
|
+
end
|
24
|
+
|
25
|
+
it "clears instance variables" do
|
26
|
+
dummy.instance_variable_set(:@_enqued_for_processing, ['foo'])
|
27
|
+
dummy.instance_variable_set(:@_enqued_for_processing_with_processing, ['image'])
|
28
|
+
dummy.enqueue_delayed_processing
|
29
|
+
dummy.instance_variable_get(:@_enqued_for_processing).should == []
|
30
|
+
dummy.instance_variable_get(:@_enqued_for_processing_with_processing).should == []
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
describe "#mark_enqueue_delayed_processing" do
|
36
|
+
it "updates columns of _processing" do
|
37
|
+
dummy.image_processing.should be_false
|
38
|
+
dummy.instance_variable_set(:@_enqued_for_processing_with_processing, ['image'])
|
39
|
+
dummy.mark_enqueue_delayed_processing
|
40
|
+
dummy.reload.image_processing.should be_true
|
41
|
+
end
|
42
|
+
|
43
|
+
it "does nothing if instance variable not set" do
|
44
|
+
dummy.image_processing.should be_false
|
45
|
+
dummy.mark_enqueue_delayed_processing
|
46
|
+
dummy.reload.image_processing.should be_false
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
describe "#enqueue_post_processing_for" do
|
51
|
+
it "enqueues the instance and image" do
|
52
|
+
DelayedPaperclip.expects(:enqueue).with("Dummy", dummy.id, :image)
|
53
|
+
dummy.enqueue_post_processing_for("image")
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
describe "#prepare_enqueueing_for" do
|
58
|
+
|
59
|
+
it "updates processing column to true" do
|
60
|
+
pending
|
61
|
+
# TODO: Why would it be writing the attribute here as well as in mark_enqueue_delayed_processing
|
62
|
+
dummy.image_processing.should be_false
|
63
|
+
dummy.expects(:write_attribute).with("image_processing", true)
|
64
|
+
dummy.prepare_enqueueing_for("image")
|
65
|
+
dummy.image_processing.should be_true
|
66
|
+
end
|
67
|
+
|
68
|
+
it "sets instance variables for column updating" do
|
69
|
+
dummy.prepare_enqueueing_for("image")
|
70
|
+
dummy.instance_variable_get(:@_enqued_for_processing_with_processing).should == ["image"]
|
71
|
+
end
|
72
|
+
|
73
|
+
it "sets instance variables for processing" do
|
74
|
+
dummy.prepare_enqueueing_for("image")
|
75
|
+
dummy.instance_variable_get(:@_enqued_for_processing).should == ["image"]
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
|
80
|
+
end
|