delayed_paperclip 0.6.1 → 0.6.2

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.6.1
1
+ 0.6.2
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{delayed_paperclip}
8
- s.version = "0.6.1"
8
+ s.version = "0.6.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Jesse Storimer"]
12
- s.date = %q{2010-03-02}
12
+ s.date = %q{2010-03-08}
13
13
  s.description = %q{Process your Paperclip attachments in the background with delayed_job.}
14
14
  s.email = %q{jesse@jstorimer.com}
15
15
  s.extra_rdoc_files = [
@@ -2,7 +2,14 @@ class DelayedPaperclipJob < Struct.new(:instance_klass, :instance_id, :attachmen
2
2
  def perform
3
3
  instance = instance_klass.constantize.find(instance_id)
4
4
 
5
- instance.send(attachment_name).reprocess!
6
5
  instance.send("#{attachment_name}_processed!")
6
+ begin
7
+ instance.send(attachment_name).reprocess!
8
+ rescue Exception => e
9
+ instance.send("#{attachment_name}_processing!", :save => true)
10
+
11
+ # DJ will now pickup this error and do its error handling
12
+ raise(e)
13
+ end
7
14
  end
8
15
  end
@@ -4,7 +4,14 @@ class ResquePaperclipJob
4
4
  def self.perform(instance_klass, instance_id, attachment_name)
5
5
  instance = instance_klass.constantize.find(instance_id)
6
6
 
7
- instance.send(attachment_name).reprocess!
8
7
  instance.send("#{attachment_name}_processed!")
8
+ begin
9
+ instance.send(attachment_name).reprocess!
10
+ rescue Object => e
11
+ instance.send("#{attachment_name}_processing!", :save => true)
12
+
13
+ # Hand the error off to Resque
14
+ raise(e)
15
+ end
9
16
  end
10
17
  end
@@ -9,7 +9,7 @@ module Delayed
9
9
  include InstanceMethods
10
10
 
11
11
  define_method "#{name}_changed?" do
12
- attachment_changed?(name)
12
+ attachment_has_changed?(name)
13
13
  end
14
14
 
15
15
  define_method "halt_processing_for_#{name}" do
@@ -36,12 +36,17 @@ module Delayed
36
36
  self.save(false)
37
37
  end
38
38
 
39
- define_method "#{name}_processing!" do
39
+ define_method "#{name}_processing!" do |*args|
40
+ force_save = args.first
40
41
  return unless column_exists?(:"#{name}_processing")
41
- return if self.send(:"#{name}_processing?")
42
- return unless self.send(:"#{name}_changed?")
42
+
43
+ unless force_save
44
+ return if self.send(:"#{name}_processing?")
45
+ return unless self.send(:"#{name}_changed?")
46
+ end
43
47
 
44
48
  self.send("#{name}_processing=", true)
49
+ self.save(false) if force_save
45
50
  end
46
51
 
47
52
  self.send("before_#{name}_post_process", :"halt_processing_for_#{name}")
@@ -53,8 +58,8 @@ module Delayed
53
58
 
54
59
  module InstanceMethods
55
60
  PAPERCLIP_ATTRIBUTES = ['_file_size', '_file_name', '_content_type', '_updated_at']
56
-
57
- def attachment_changed?(name)
61
+
62
+ def attachment_has_changed?(name)
58
63
  PAPERCLIP_ATTRIBUTES.each do |attribute|
59
64
  full_attribute = "#{name}#{attribute}_changed?".to_sym
60
65
 
@@ -89,7 +94,11 @@ module Paperclip
89
94
  if !@instance.send(:"#{@name}_processing?")
90
95
  url_without_processed style, include_updated_timestamp
91
96
  else
92
- interpolate(@default_url, style)
97
+ if @instance.send(:"#{@name}_changed?")
98
+ url_without_processed style, include_updated_timestamp
99
+ else
100
+ interpolate(@default_url, style)
101
+ end
93
102
  end
94
103
  end
95
104
  end
@@ -59,6 +59,18 @@ class DelayedPaperclipTest < Test::Unit::TestCase
59
59
  @dummy.save!
60
60
  Delayed::Job.last.payload_object.perform
61
61
  end
62
+
63
+ def test_processing_column_kept_intact
64
+ @dummy = reset_dummy(true)
65
+
66
+ @dummy.stubs(:image_changed?).returns(true)
67
+ Paperclip::Attachment.any_instance.stubs(:reprocess!).raises(StandardError.new('oops'))
68
+
69
+ @dummy.save!
70
+ assert @dummy.image_processing?
71
+ Delayed::Job.work_off
72
+ assert @dummy.reload.image_processing?
73
+ end
62
74
 
63
75
  def test_after_callback_is_functional
64
76
  @dummy_class.send(:define_method, :done_processing) { puts 'done' }
@@ -109,10 +121,36 @@ class DelayedPaperclipTest < Test::Unit::TestCase
109
121
  @dummy.save!
110
122
 
111
123
  assert_match(/\/system\/images\/1\/original\/12k.png/, @dummy.image.url)
112
-
113
- # Delayed::Job.first.invoke_job
114
- #
115
- # @dummy.reload
116
- # assert_match(/\/system\/images\/1\/original\/12k.png/, @dummy.image.url)
117
124
  end
125
+
126
+ def test_original_url_if_image_changed
127
+ @dummy = reset_dummy(true)
128
+ @dummy.image_processing!
129
+ @dummy.image_content_type_will_change!
130
+
131
+ assert_match(/system\/images\/.*original.*/, @dummy.image.url)
132
+ end
133
+
134
+ def test_missing_url_if_image_hasnt_changed
135
+ @dummy = reset_dummy(true)
136
+ @dummy.image_processing!
137
+ @dummy.stubs(:image_changed?).returns(false)
138
+
139
+ assert_match(/images\/.*missing.*/, @dummy.image.url)
140
+ end
141
+
142
+ def test_attachment_processing_with_no_args
143
+ Dummy.any_instance.expects(:save).never
144
+
145
+ @dummy.image_processing!
146
+ end
147
+
148
+ def test_attachment_processing_with_args
149
+ Dummy.any_instance.stubs(:image_processing?).returns(true)
150
+ @dummy = reset_dummy(true)
151
+ @dummy.image_content_type_will_change!
152
+ @dummy.expects(:save).with(false)
153
+
154
+ @dummy.image_processing!(:save => true)
155
+ end
118
156
  end
@@ -7,6 +7,7 @@ class ResquePaperclipTest < Test::Unit::TestCase
7
7
  # Make sure that we just test Resque in here
8
8
  Object.send(:remove_const, :Delayed) if defined? Delayed
9
9
 
10
+ Resque.remove_queue(:paperclip)
10
11
  reset_dummy
11
12
  end
12
13
 
@@ -34,4 +35,19 @@ class ResquePaperclipTest < Test::Unit::TestCase
34
35
  @dummy.save!
35
36
  ResquePaperclipJob.perform(@dummy.class.name, @dummy.id, :image)
36
37
  end
38
+
39
+ def test_processing_column_kept_intact
40
+ @dummy = reset_dummy(true)
41
+
42
+ @dummy.stubs(:image_changed?).returns(true)
43
+ Paperclip::Attachment.any_instance.stubs(:reprocess!).raises(StandardError.new('oops'))
44
+
45
+ @dummy.save!
46
+ assert @dummy.image_processing?
47
+
48
+ worker = Resque::Worker.new(:paperclip)
49
+ worker.process
50
+
51
+ assert @dummy.reload.image_processing?
52
+ end
37
53
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 6
8
- - 1
9
- version: 0.6.1
8
+ - 2
9
+ version: 0.6.2
10
10
  platform: ruby
11
11
  authors:
12
12
  - Jesse Storimer
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-03-02 00:00:00 -05:00
17
+ date: 2010-03-08 00:00:00 -05:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency