delayed_paperclip 3.0.0 → 3.0.1

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: 87f666e3339caae1a67262dc9d7a2e0a4735a4cb
4
- data.tar.gz: 17312387a6ca724e835abee1b1aac059c28e24b2
3
+ metadata.gz: ee7342bcd21ac1c386a6856db5e168f555542b13
4
+ data.tar.gz: 14abfc99f34f048e8e7db32be2950a2fe3ba097d
5
5
  SHA512:
6
- metadata.gz: cd54dd5bf121d9d9b1bec0feeb669d8afed6dbf0edecc4088f14c84578d976e2cab2e55e5959f03a3b6aba0ca6a75870285870938f6b156ee8bf8d1e0c0402d2
7
- data.tar.gz: 5731d670649b7b293b587192d7f569912caf43c717c100b384e24bbc2377b297f30346edf69c88a7c5320621ee1d5a1c9221abedeb59ee8f40e2c81b9ef83558
6
+ metadata.gz: 4a2126fd4538776b25d2e4f7e1e14880754807f3b2470fe6fac57d9ce1052adff8bca565333b7f2a12972513e5df2f1304e59de666084eda67fa1614c405e511
7
+ data.tar.gz: 2ba9ba29b2ef8a5ac1e1df24d412e035b7304e24224495edb751a95e03e42a5d38af1c198636a88a8cd2a4f4f00a60f6223cdb07777b78a3d26523334b290609
@@ -11,6 +11,7 @@ rvm:
11
11
  gemfile:
12
12
  - gemfiles/4.2.gemfile
13
13
  - gemfiles/5.0.gemfile
14
+ - gemfiles/5.0_paperclip_master.gemfile
14
15
 
15
16
  # Rails 5.0 requires Ruby >= 2.2.2
16
17
  matrix:
@@ -19,6 +20,10 @@ matrix:
19
20
  gemfile: gemfiles/5.0.gemfile
20
21
  - rvm: 2.0
21
22
  gemfile: gemfiles/5.0.gemfile
23
+ - rvm: 2.1.10
24
+ gemfile: gemfiles/5.0_paperclip_master.gemfile
25
+ - rvm: 2.0
26
+ gemfile: gemfiles/5.0_paperclip_master.gemfile
22
27
  # Paperclip >= 5.0 requires Ruby 2.1
23
28
  - rvm: 2.0
24
29
  gemfile: gemfiles/4.2.gemfile
data/Appraisals CHANGED
@@ -5,3 +5,8 @@ end
5
5
  appraise "5.0" do
6
6
  gem "rails", "~> 5.0.0"
7
7
  end
8
+
9
+ appraise "5.0-paperclip-master" do
10
+ gem "rails", "~> 5.0.0"
11
+ gem "paperclip", github: "thoughtbot/paperclip"
12
+ end
data/Gemfile CHANGED
@@ -1,3 +1,3 @@
1
1
  source "http://rubygems.org"
2
2
 
3
- gemspec
3
+ gemspec
data/Rakefile CHANGED
@@ -1,4 +1,5 @@
1
1
  require 'bundler/setup'
2
+ require 'bundler/gem_tasks'
2
3
  require 'rake'
3
4
  require 'rspec/core/rake_task'
4
5
 
@@ -0,0 +1 @@
1
+ --- {}
@@ -0,0 +1,8 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "http://rubygems.org"
4
+
5
+ gem "rails", "~> 5.0.0"
6
+ gem "paperclip", :github => "thoughtbot/paperclip"
7
+
8
+ gemspec :path => "../"
@@ -23,9 +23,9 @@ module DelayedPaperclip
23
23
  end
24
24
 
25
25
  def process_job(instance_klass, instance_id, attachment_name)
26
- if instance = instance_klass.constantize.unscoped.where(id: instance_id).first
27
- instance.send(attachment_name).process_delayed!
28
- end
26
+ instance_klass.constantize.unscoped.find(instance_id).
27
+ send(attachment_name).
28
+ process_delayed!
29
29
  end
30
30
 
31
31
  end
@@ -1,105 +1,89 @@
1
1
  module DelayedPaperclip
2
2
  module Attachment
3
+ attr_accessor :job_is_processing
3
4
 
4
- def self.included(base)
5
- base.send :include, InstanceMethods
6
- base.send :attr_accessor, :job_is_processing
7
-
8
- base.send :alias_method, :post_processing_without_delay, :post_processing
9
- base.send :alias_method, :post_processing, :post_processing_with_delay
10
-
11
- base.send :alias_method, :post_processing_without_delay=, :post_processing=
12
- base.send :alias_method, :post_processing=, :post_processing_with_delay=
13
-
14
- base.send :alias_method, :save_without_prepare_enqueueing, :save
15
- base.send :alias_method, :save, :save_with_prepare_enqueueing
5
+ def delayed_options
6
+ options[:delayed]
16
7
  end
17
8
 
18
- module InstanceMethods
19
-
20
- def delayed_options
21
- options[:delayed]
22
- end
23
-
24
- # Attr accessor in Paperclip
25
- def post_processing_with_delay
26
- !delay_processing? || split_processing?
27
- end
9
+ # Attr accessor in Paperclip
10
+ def post_processing
11
+ !delay_processing? || split_processing?
12
+ end
28
13
 
29
- def post_processing_with_delay=(value)
30
- @post_processing_with_delay = value
31
- end
14
+ def post_processing=(value)
15
+ @post_processing_with_delay = value
16
+ end
32
17
 
33
- # if nil, returns whether it has delayed options
34
- # if set, then it returns
35
- def delay_processing?
36
- if @post_processing_with_delay.nil?
37
- !!delayed_options
38
- else
39
- !@post_processing_with_delay
40
- end
18
+ # if nil, returns whether it has delayed options
19
+ # if set, then it returns
20
+ def delay_processing?
21
+ if @post_processing_with_delay.nil?
22
+ !!delayed_options
23
+ else
24
+ !@post_processing_with_delay
41
25
  end
26
+ end
42
27
 
43
- def split_processing?
44
- options[:only_process] && delayed_options &&
45
- options[:only_process] != delayed_only_process
46
- end
28
+ def split_processing?
29
+ options[:only_process] && delayed_options &&
30
+ options[:only_process] != delayed_only_process
31
+ end
47
32
 
48
- def processing?
49
- column_name = :"#{@name}_processing?"
50
- @instance.respond_to?(column_name) && @instance.send(column_name)
51
- end
33
+ def processing?
34
+ column_name = :"#{@name}_processing?"
35
+ @instance.respond_to?(column_name) && @instance.send(column_name)
36
+ end
52
37
 
53
- def processing_style?(style)
54
- return false if !processing?
38
+ def processing_style?(style)
39
+ return false if !processing?
55
40
 
56
- !split_processing? || delayed_only_process.include?(style)
57
- end
41
+ !split_processing? || delayed_only_process.include?(style)
42
+ end
58
43
 
59
- def delayed_only_process
60
- only_process = delayed_options.fetch(:only_process, []).dup
61
- only_process = only_process.call(self) if only_process.respond_to?(:call)
62
- only_process.map(&:to_sym)
63
- end
44
+ def delayed_only_process
45
+ only_process = delayed_options.fetch(:only_process, []).dup
46
+ only_process = only_process.call(self) if only_process.respond_to?(:call)
47
+ only_process.map(&:to_sym)
48
+ end
64
49
 
65
- def process_delayed!
66
- self.job_is_processing = true
67
- self.post_processing = true
68
- reprocess!(*delayed_only_process)
69
- self.job_is_processing = false
70
- update_processing_column
71
- end
50
+ def process_delayed!
51
+ self.job_is_processing = true
52
+ self.post_processing = true
53
+ reprocess!(*delayed_only_process)
54
+ self.job_is_processing = false
55
+ update_processing_column
56
+ end
72
57
 
73
- def processing_image_url
74
- processing_image_url = delayed_options[:processing_image_url]
75
- processing_image_url = processing_image_url.call(self) if processing_image_url.respond_to?(:call)
76
- processing_image_url
77
- end
58
+ def processing_image_url
59
+ processing_image_url = delayed_options[:processing_image_url]
60
+ processing_image_url = processing_image_url.call(self) if processing_image_url.respond_to?(:call)
61
+ processing_image_url
62
+ end
78
63
 
79
- def save_with_prepare_enqueueing
80
- was_dirty = @dirty
64
+ def save
65
+ was_dirty = @dirty
81
66
 
82
- save_without_prepare_enqueueing.tap do
83
- if delay_processing? && was_dirty
84
- instance.prepare_enqueueing_for name
85
- end
67
+ super.tap do
68
+ if delay_processing? && was_dirty
69
+ instance.prepare_enqueueing_for name
86
70
  end
87
71
  end
72
+ end
88
73
 
89
- def reprocess_without_delay!(*style_args)
90
- @post_processing_with_delay = true
91
- reprocess!(*style_args)
92
- end
74
+ def reprocess_without_delay!(*style_args)
75
+ @post_processing_with_delay = true
76
+ reprocess!(*style_args)
77
+ end
93
78
 
94
- private
79
+ private
95
80
 
96
- def update_processing_column
97
- if instance.respond_to?(:"#{name}_processing?")
98
- instance.send("#{name}_processing=", false)
99
- instance.class.where(instance.class.primary_key => instance.id).update_all({ "#{name}_processing" => false })
100
- end
81
+ def update_processing_column
82
+ if instance.respond_to?(:"#{name}_processing?")
83
+ instance.send("#{name}_processing=", false)
84
+ instance.class.where(instance.class.primary_key => instance.id).update_all({ "#{name}_processing" => false })
101
85
  end
102
-
103
86
  end
87
+
104
88
  end
105
89
  end
@@ -20,7 +20,7 @@ module DelayedPaperclip
20
20
  # Attachment and URL Generator extends Paperclip
21
21
  def self.insert
22
22
  ActiveRecord::Base.send(:include, DelayedPaperclip::Glue)
23
- Paperclip::Attachment.send(:include, DelayedPaperclip::Attachment)
23
+ Paperclip::Attachment.prepend(DelayedPaperclip::Attachment)
24
24
  Paperclip::Attachment.default_options[:url_generator] = DelayedPaperclip::UrlGenerator
25
25
  end
26
26
  end
@@ -3,9 +3,13 @@ require 'paperclip/url_generator'
3
3
 
4
4
  module DelayedPaperclip
5
5
  class UrlGenerator < ::Paperclip::UrlGenerator
6
+ def initialize(attachment, _compatibility = nil)
7
+ @attachment = attachment
8
+ @attachment_options = attachment.options
9
+ end
10
+
6
11
  def for(style_name, options)
7
12
  most_appropriate_url = @attachment.processing_style?(style_name) ? most_appropriate_url(style_name) : most_appropriate_url()
8
-
9
13
  timestamp_as_needed(
10
14
  escape_url_as_needed(
11
15
  @attachment_options[:interpolator].interpolate(most_appropriate_url, @attachment, style_name),
@@ -1,3 +1,3 @@
1
1
  module DelayedPaperclip
2
- VERSION = "3.0.0"
2
+ VERSION = "3.0.1"
3
3
  end
@@ -23,12 +23,12 @@ describe DelayedPaperclip::Attachment do
23
23
  describe "#post_processing_with_delay" do
24
24
  it "is true if delay_processing? is false" do
25
25
  dummy.image.stubs(:delay_processing?).returns false
26
- dummy.image.post_processing_with_delay.should be_truthy
26
+ dummy.image.post_processing.should be_truthy
27
27
  end
28
28
 
29
29
  it "is false if delay_processing? is true" do
30
30
  dummy.image.stubs(:delay_processing?).returns true
31
- dummy.image.post_processing_with_delay.should be_falsey
31
+ dummy.image.post_processing.should be_falsey
32
32
  end
33
33
 
34
34
  context "on a non-delayed image" do
@@ -36,19 +36,19 @@ describe DelayedPaperclip::Attachment do
36
36
 
37
37
  it "is false if delay_processing? is true" do
38
38
  dummy.image.stubs(:delay_processing?).returns true
39
- dummy.image.post_processing_with_delay.should be_falsey
39
+ dummy.image.post_processing.should be_falsey
40
40
  end
41
41
  end
42
42
  end
43
43
 
44
44
  describe "#delay_processing?" do
45
- it "returns delayed_options existence if post_processing_with_delay is nil" do
46
- dummy.image.post_processing_with_delay = nil
45
+ it "returns delayed_options existence if post_processing is nil" do
46
+ dummy.image.post_processing = nil
47
47
  dummy.image.delay_processing?.should be_truthy
48
48
  end
49
49
 
50
- it "returns inverse of post_processing_with_delay if it's set" do
51
- dummy.image.post_processing_with_delay = true
50
+ it "returns inverse of post_processing if it's set" do
51
+ dummy.image.post_processing = true
52
52
  dummy.image.delay_processing?.should be_falsey
53
53
  end
54
54
  end
@@ -151,7 +151,8 @@ describe DelayedPaperclip::Attachment do
151
151
  reset_dummy(paperclip: { only_process: lambda { |a| [:small, :large] } } )
152
152
  end
153
153
 
154
- it "returns [:small, :large]" do
154
+ # Enable when https://github.com/thoughtbot/paperclip/pull/2289 is resolved
155
+ xit "returns [:small, :large]" do
155
156
  expect(dummy.image.delayed_only_process).to eq [:small, :large]
156
157
  end
157
158
  end
@@ -192,7 +193,8 @@ describe DelayedPaperclip::Attachment do
192
193
  reset_dummy(paperclip: { only_process: lambda { |a| [:small, :large] } } )
193
194
  end
194
195
 
195
- it "calls reprocess! with options" do
196
+ # Enable when https://github.com/thoughtbot/paperclip/pull/2289 is resolved
197
+ xit "calls reprocess! with options" do
196
198
  dummy.image.expects(:reprocess!).with(:small, :large)
197
199
  dummy.image.process_delayed!
198
200
  end
@@ -237,7 +239,7 @@ describe DelayedPaperclip::Attachment do
237
239
  end
238
240
  end
239
241
 
240
- describe "#save_with_prepare_enqueueing" do
242
+ describe "#save" do
241
243
  context "delay processing and it was dirty" do
242
244
  before :each do
243
245
  dummy.image.stubs(:delay_processing?).returns true
@@ -246,14 +248,14 @@ describe DelayedPaperclip::Attachment do
246
248
 
247
249
  it "prepares the enqueing" do
248
250
  dummy.expects(:prepare_enqueueing_for).with(:image)
249
- dummy.image.save_with_prepare_enqueueing
251
+ dummy.image.save
250
252
  end
251
253
  end
252
254
 
253
255
  context "without dirty or delay_processing" do
254
256
  it "does not prepare_enqueueing" do
255
257
  dummy.expects(:prepare_enqueueing_for).with(:image).never
256
- dummy.image.save_with_prepare_enqueueing
258
+ dummy.image.save
257
259
  end
258
260
  end
259
261
  end
@@ -2,12 +2,13 @@ require 'spec_helper'
2
2
 
3
3
  describe DelayedPaperclip::UrlGenerator do
4
4
  before :each do
5
- reset_dummy(dummy_options)
5
+ reset_dummy({})
6
6
  end
7
7
 
8
- let(:dummy) { Dummy.create }
9
- let(:attachment) { dummy.image }
10
- let(:dummy_options) { {} }
8
+ def make_attachment(options = {})
9
+ reset_dummy(options)
10
+ Dummy.create.image
11
+ end
11
12
 
12
13
  describe "for" do
13
14
  before :each do
@@ -15,19 +16,21 @@ describe DelayedPaperclip::UrlGenerator do
15
16
  end
16
17
 
17
18
  context "with split processing" do
18
- # everything in this hash is passed to delayed_paperclip, except for the
19
- # paperclip stuff
20
- let(:dummy_options) { {
21
- paperclip: {
22
- styles: {
23
- online: "400x400x",
24
- background: "600x600x"
25
- },
26
- only_process: [:online]
27
- },
28
-
29
- only_process: [:background]
30
- }}
19
+ let(:attachment) do
20
+ make_attachment(
21
+ {
22
+ paperclip: {
23
+ styles: {
24
+ online: "400x400x",
25
+ background: "600x600x"
26
+ },
27
+ only_process: [:online]
28
+ },
29
+
30
+ only_process: [:background]
31
+ }
32
+ )
33
+ end
31
34
 
32
35
  context "processing" do
33
36
  before :each do
@@ -58,19 +61,30 @@ describe DelayedPaperclip::UrlGenerator do
58
61
  end
59
62
 
60
63
  context "should be able to escape (, ), [, and ]." do
61
- def generate(expected, updated_at=nil)
62
- mock_interpolator = MockInterpolator.new(result: expected)
63
- options = { interpolator: mock_interpolator }
64
- url_generator = Paperclip::UrlGenerator.new(attachment, options)
64
+ def generate(expected, updated_at = nil)
65
+ attachment = make_attachment(
66
+ {
67
+ paperclip: {
68
+ styles: {
69
+ online: "400x400x",
70
+ background: "600x600x"
71
+ },
72
+ only_process: [:online],
73
+ interpolator: MockInterpolator.new(result: expected)
74
+ },
75
+
76
+ only_process: [:background]
77
+ }
78
+ )
79
+ url_generator = DelayedPaperclip::UrlGenerator.new(attachment, {})
65
80
  attachment.stubs(:updated_at).returns updated_at
66
81
  url_generator.for(:style_name, {escape: true, timestamp: !!updated_at})
67
82
  end
68
83
 
69
-
70
84
  it "interpolates correctly without timestamp" do
71
85
  expect(
72
86
  "the%28expected%29result%5B%5D"
73
- ).to be == generate("the(expected)result[]")
87
+ ).to eq(generate("the(expected)result[]"))
74
88
  end
75
89
 
76
90
  it "does not interpolate timestamp" do
@@ -79,7 +93,7 @@ describe DelayedPaperclip::UrlGenerator do
79
93
 
80
94
  expect(
81
95
  "the%28expected%29result%5B%5D?#{updated_at}"
82
- ).to be == generate(expected, updated_at)
96
+ ).to eq(generate(expected, updated_at))
83
97
  end
84
98
  end
85
99
  end
@@ -87,18 +101,20 @@ describe DelayedPaperclip::UrlGenerator do
87
101
 
88
102
  describe "#most_appropriate_url" do
89
103
  context "without delayed_default_url" do
90
- subject { DelayedPaperclip::UrlGenerator.new(attachment, {url: "/blah/url.jpg"})}
104
+ let(:attachment) { make_attachment(paperclip: {url: "/blah/url.jpg"}) }
105
+
106
+ subject { DelayedPaperclip::UrlGenerator.new(attachment) }
91
107
 
92
108
  before :each do
93
109
  subject.stubs(:delayed_default_url?).returns false
94
110
  end
95
- context "with original file name" do
96
- before :each do
97
- attachment.stubs(:original_filename).returns "blah"
98
- end
99
111
 
112
+ context "with original file name" do
100
113
  it "returns options url" do
101
- subject.most_appropriate_url.should == "/blah/url.jpg"
114
+ attachment.stubs(:original_filename).returns "blah"
115
+ subjec = DelayedPaperclip::UrlGenerator.new(attachment)
116
+ subjec.stubs(:delayed_default_url?).returns false
117
+ subjec.most_appropriate_url.should == "/blah/url.jpg"
102
118
  end
103
119
  end
104
120
 
@@ -162,7 +178,8 @@ describe DelayedPaperclip::UrlGenerator do
162
178
  end
163
179
 
164
180
  describe "#timestamp_possible?" do
165
- subject { DelayedPaperclip::UrlGenerator.new(attachment, {})}
181
+ let(:attachment) { make_attachment }
182
+ subject { DelayedPaperclip::UrlGenerator.new(attachment) }
166
183
 
167
184
  context "with delayed_default_url" do
168
185
  before :each do
@@ -187,7 +204,8 @@ describe DelayedPaperclip::UrlGenerator do
187
204
  end
188
205
 
189
206
  describe "#delayed_default_url?" do
190
- subject { DelayedPaperclip::UrlGenerator.new(attachment, {})}
207
+ let(:attachment) { make_attachment }
208
+ subject { DelayedPaperclip::UrlGenerator.new(attachment) }
191
209
 
192
210
  before :each do
193
211
  attachment.stubs(:job_is_processing).returns false
@@ -32,20 +32,11 @@ describe DelayedPaperclip do
32
32
 
33
33
  it "finds dummy and calls #process_delayed!" do
34
34
  dummy_stub = stub
35
- dummy_stub.expects(:where).with(id: dummy.id).returns([dummy])
35
+ dummy_stub.expects(:find).with(dummy.id).returns(dummy)
36
36
  Dummy.expects(:unscoped).returns(dummy_stub)
37
37
  dummy.image.expects(:process_delayed!)
38
38
  DelayedPaperclip.process_job("Dummy", dummy.id, :image)
39
39
  end
40
-
41
- it "doesn't find dummy and it doesn't raise any exceptions" do
42
- dummy_stub = stub
43
- dummy_stub.expects(:where).with(id: dummy.id).returns([])
44
- Dummy.expects(:unscoped).returns(dummy_stub)
45
- expect do
46
- DelayedPaperclip.process_job("Dummy", dummy.id, :image)
47
- end.not_to raise_exception
48
- end
49
40
  end
50
41
 
51
42
  describe "paperclip definitions" do
@@ -64,4 +55,4 @@ describe DelayedPaperclip do
64
55
  })
65
56
  end
66
57
  end
67
- end
58
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: delayed_paperclip
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.0
4
+ version: 3.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jesse Storimer
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2016-08-01 00:00:00.000000000 Z
14
+ date: 2016-08-26 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: paperclip
@@ -171,8 +171,10 @@ files:
171
171
  - README.md
172
172
  - Rakefile
173
173
  - delayed_paperclip.gemspec
174
+ - gemfiles/.bundle/config
174
175
  - gemfiles/4.2.gemfile
175
176
  - gemfiles/5.0.gemfile
177
+ - gemfiles/5.0_paperclip_master.gemfile
176
178
  - lib/delayed_paperclip.rb
177
179
  - lib/delayed_paperclip/attachment.rb
178
180
  - lib/delayed_paperclip/process_job.rb
@@ -210,20 +212,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
210
212
  version: '0'
211
213
  requirements: []
212
214
  rubyforge_project:
213
- rubygems_version: 2.4.5
215
+ rubygems_version: 2.6.6
214
216
  signing_key:
215
217
  specification_version: 4
216
218
  summary: Process your Paperclip attachments in the background
217
- test_files:
218
- - spec/delayed_paperclip/attachment_spec.rb
219
- - spec/delayed_paperclip/class_methods_spec.rb
220
- - spec/delayed_paperclip/instance_methods_spec.rb
221
- - spec/delayed_paperclip/url_generator_spec.rb
222
- - spec/delayed_paperclip_spec.rb
223
- - spec/fixtures/12k.png
224
- - spec/fixtures/missing.png
225
- - spec/integration/base_delayed_paperclip_spec.rb
226
- - spec/integration/examples/base.rb
227
- - spec/integration/process_job_spec.rb
228
- - spec/spec_helper.rb
229
- - spec/tmp/.keep
219
+ test_files: []