delayed_paperclip 2.6.1 → 2.7.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,14 +1,36 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe DelayedPaperclip::UrlGenerator do
4
- before :all do
4
+ before :each do
5
5
  DelayedPaperclip.options[:background_job_class] = DelayedPaperclip::Jobs::Resque
6
- reset_dummy
6
+ reset_dummy(dummy_options)
7
7
  end
8
8
 
9
9
  let(:dummy) { Dummy.create }
10
10
  let(:attachment) { dummy.image }
11
-
11
+ let(:dummy_options) { {} }
12
+
13
+ describe "for_with_processed" do
14
+ context "with split pcoessing" do
15
+ # everything in this hash is passed to delayed_paperclip, expect for the
16
+ # paperclip stuff
17
+ let(:dummy_options) { {
18
+ paperclip: {
19
+ styles: {
20
+ online: "400x400x",
21
+ background: "600x600x"
22
+ },
23
+ only_process: [:online]
24
+ },
25
+
26
+ only_process: [:background]
27
+ }}
28
+
29
+ it "returns the default_url when the style is still being processed" do
30
+ expect(attachment.url(:background)).to eql "/images/background/missing.png"
31
+ end
32
+ end
33
+ end
12
34
 
13
35
  describe "#most_appropriate_url_with_processed" do
14
36
  context "without delayed_default_url" do
@@ -17,7 +39,6 @@ describe DelayedPaperclip::UrlGenerator do
17
39
  before :each do
18
40
  subject.stubs(:delayed_default_url?).returns false
19
41
  end
20
-
21
42
  context "with original file name" do
22
43
  before :each do
23
44
  attachment.stubs(:original_filename).returns "blah"
@@ -121,6 +142,7 @@ describe DelayedPaperclip::UrlGenerator do
121
142
  attachment.delayed_options[:url_with_processing] = true
122
143
  attachment.instance.stubs(:respond_to?).with(:image_processing?).returns true
123
144
  attachment.stubs(:processing?).returns true
145
+ attachment.stubs(:processing_style?).with(anything).returns true
124
146
  end
125
147
 
126
148
  it "has all false, delayed_default_url returns true" do
@@ -167,5 +189,14 @@ describe DelayedPaperclip::UrlGenerator do
167
189
  subject.delayed_default_url?.should be_false
168
190
  end
169
191
  end
192
+
193
+ context "style is provided and is being processed" do
194
+ let(:style) { :main }
195
+ before :each do
196
+ attachment.stubs(:processing_style?).with(style).returns(true)
197
+ end
198
+
199
+ specify { expect(subject.delayed_default_url?(style)).to be }
200
+ end
170
201
  end
171
- end
202
+ end
@@ -31,7 +31,9 @@ describe DelayedPaperclip do
31
31
  let(:dummy) { Dummy.create! }
32
32
 
33
33
  it "finds dummy and calls #process_delayed!" do
34
- Dummy.expects(:find).with(dummy.id).returns(dummy)
34
+ dummy_stub = stub
35
+ dummy_stub.expects(:find).with(dummy.id).returns(dummy)
36
+ Dummy.expects(:unscoped).returns(dummy_stub)
35
37
  dummy.image.expects(:process_delayed!)
36
38
  DelayedPaperclip.process_job("Dummy", dummy.id, :image)
37
39
  end
@@ -45,9 +47,10 @@ describe DelayedPaperclip do
45
47
  it "returns paperclip options regardless of version" do
46
48
  Dummy.paperclip_definitions.should == {:image => { :styles => { :thumbnail => "25x25" },
47
49
  :delayed => { :priority => 0,
48
- :only_process => nil,
50
+ :only_process => [],
49
51
  :url_with_processing => true,
50
- :processing_image_url => nil}
52
+ :processing_image_url => nil,
53
+ :queue => nil}
51
54
  }
52
55
  }
53
56
  end
data/spec/spec_helper.rb CHANGED
@@ -1,11 +1,19 @@
1
1
  $LOAD_PATH.unshift(File.dirname(__FILE__))
2
2
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), "..", "lib"))
3
3
 
4
- require 'rails'
5
4
  require 'active_record'
5
+ require 'active_record/version'
6
+ require 'active_support'
7
+ require 'active_support/core_ext'
6
8
  require 'rspec'
7
9
  require 'mocha/api'
8
10
 
11
+ begin
12
+ require 'pry'
13
+ rescue LoadError
14
+ # Pry is not available, just ignore.
15
+ end
16
+
9
17
  require 'paperclip/railtie'
10
18
  Paperclip::Railtie.insert
11
19
 
@@ -37,20 +45,21 @@ Dir["./spec/integration/examples/*.rb"].sort.each {|f| require f}
37
45
  # Reset table and class with image_processing column or not
38
46
  def reset_dummy(options = {})
39
47
  options[:with_processed] = true unless options.key?(:with_processed)
40
- build_dummy_table(options[:with_processed])
48
+ options[:processed_column] = options[:with_processed] unless options.has_key?(:processed_column)
49
+ build_dummy_table(options.delete(:processed_column))
41
50
  reset_class("Dummy", options)
42
51
  end
43
52
 
44
53
  # Dummy Table for images
45
54
  # with or without image_processing column
46
- def build_dummy_table(with_processed)
55
+ def build_dummy_table(with_column)
47
56
  ActiveRecord::Base.connection.create_table :dummies, :force => true do |t|
48
57
  t.string :name
49
58
  t.string :image_file_name
50
59
  t.string :image_content_type
51
60
  t.integer :image_file_size
52
61
  t.datetime :image_updated_at
53
- t.boolean(:image_processing, :default => false) if with_processed
62
+ t.boolean(:image_processing, :default => false) if with_column
54
63
  end
55
64
  end
56
65
 
@@ -67,9 +76,11 @@ def reset_class(class_name, options)
67
76
  klass.class_eval do
68
77
  include Paperclip::Glue
69
78
 
70
- has_attached_file :image, options[:paperclip]
79
+ has_attached_file :image, options[:paperclip]
71
80
  options.delete(:paperclip)
72
81
 
82
+ validates_attachment :image, :content_type => { :content_type => "image/png" }
83
+
73
84
  process_in_background :image, options if options[:with_processed]
74
85
 
75
86
  after_update :reprocess if options[:with_after_update_callback]
@@ -186,6 +186,20 @@ module BaseDelayedPaperclipTest
186
186
  process_jobs
187
187
  end
188
188
 
189
+ def test_delayed_paperclip_functioning_with_only_process_and_paperclip_only_process_option
190
+ reset_class "Dummy", :with_processed => true, :only_process => [:small], :paperclip => { :only_process => [:thumbnail] }
191
+
192
+ Paperclip::Attachment.any_instance.expects(:post_process).with(:thumbnail)
193
+ Paperclip::Attachment.any_instance.expects(:post_process).with(:small).never
194
+
195
+ Paperclip::Attachment.any_instance.expects(:reprocess!).with(:small)
196
+ Paperclip::Attachment.any_instance.expects(:reprocess!).with(:thumbnail).never
197
+
198
+ dummy = Dummy.new(:image => File.open("#{RAILS_ROOT}/test/fixtures/12k.png"))
199
+ dummy.save!
200
+ process_jobs
201
+ end
202
+
189
203
  def test_delayed_paperclip_should_convert_image_formats
190
204
  reset_class "Dummy", :with_processed => true, :paperclip => { :styles => {:thumbnail => ['12x12', :jpg]} }
191
205
  dummy = Dummy.new(:image => File.open("#{RAILS_ROOT}/test/fixtures/12k.png"))
data/test/test_helper.rb CHANGED
@@ -2,10 +2,19 @@ require 'rubygems'
2
2
  require 'test/unit'
3
3
  require 'mocha/setup'
4
4
  require 'active_record'
5
+ require 'active_record/version'
6
+ require 'active_support'
7
+ require 'active_support/core_ext'
5
8
  require 'logger'
6
9
  require 'sqlite3'
7
- require 'paperclip/railtie'
8
10
 
11
+ begin
12
+ require 'pry'
13
+ rescue LoadError
14
+ # Pry is not available, just ignore.
15
+ end
16
+
17
+ require 'paperclip/railtie'
9
18
  Paperclip::Railtie.insert
10
19
 
11
20
  ROOT = File.join(File.dirname(__FILE__), '..')
@@ -64,9 +73,11 @@ def reset_class(class_name, options)
64
73
  klass.class_eval do
65
74
  include Paperclip::Glue
66
75
 
67
- has_attached_file :image, options[:paperclip]
76
+ has_attached_file :image, options[:paperclip]
68
77
  options.delete(:paperclip)
69
78
 
79
+ validates_attachment :image, :content_type => { :content_type => "image/png" }
80
+
70
81
  process_in_background :image, options if options[:with_processed]
71
82
 
72
83
  after_update :reprocess if options[:with_after_update_callback]
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: 2.6.1
4
+ version: 2.7.0
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: 2013-07-31 00:00:00.000000000 Z
14
+ date: 2014-02-19 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: paperclip
@@ -19,14 +19,14 @@ dependencies:
19
19
  requirements:
20
20
  - - '>='
21
21
  - !ruby/object:Gem::Version
22
- version: 3.3.0
22
+ version: '3.3'
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
26
26
  requirements:
27
27
  - - '>='
28
28
  - !ruby/object:Gem::Version
29
- version: 3.3.0
29
+ version: '3.3'
30
30
  - !ruby/object:Gem::Dependency
31
31
  name: mocha
32
32
  requirement: !ruby/object:Gem::Requirement
@@ -83,6 +83,20 @@ dependencies:
83
83
  - - '>='
84
84
  - !ruby/object:Gem::Version
85
85
  version: '0'
86
+ - !ruby/object:Gem::Dependency
87
+ name: delayed_job_active_record
88
+ requirement: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - '>='
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ type: :development
94
+ prerelease: false
95
+ version_requirements: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - '>='
98
+ - !ruby/object:Gem::Version
99
+ version: '0'
86
100
  - !ruby/object:Gem::Dependency
87
101
  name: resque
88
102
  requirement: !ruby/object:Gem::Requirement
@@ -111,9 +125,67 @@ dependencies:
111
125
  - - '>='
112
126
  - !ruby/object:Gem::Version
113
127
  version: '0'
114
- description: Process your Paperclip attachments in the background with delayed_job,
115
- Resque or your own processor.
116
- email: james@jamesrgifford.com
128
+ - !ruby/object:Gem::Dependency
129
+ name: appraisal
130
+ requirement: !ruby/object:Gem::Requirement
131
+ requirements:
132
+ - - '>='
133
+ - !ruby/object:Gem::Version
134
+ version: '0'
135
+ type: :development
136
+ prerelease: false
137
+ version_requirements: !ruby/object:Gem::Requirement
138
+ requirements:
139
+ - - '>='
140
+ - !ruby/object:Gem::Version
141
+ version: '0'
142
+ - !ruby/object:Gem::Dependency
143
+ name: rake
144
+ requirement: !ruby/object:Gem::Requirement
145
+ requirements:
146
+ - - '>='
147
+ - !ruby/object:Gem::Version
148
+ version: '0'
149
+ type: :development
150
+ prerelease: false
151
+ version_requirements: !ruby/object:Gem::Requirement
152
+ requirements:
153
+ - - '>='
154
+ - !ruby/object:Gem::Version
155
+ version: '0'
156
+ - !ruby/object:Gem::Dependency
157
+ name: bundler
158
+ requirement: !ruby/object:Gem::Requirement
159
+ requirements:
160
+ - - '>='
161
+ - !ruby/object:Gem::Version
162
+ version: '0'
163
+ type: :development
164
+ prerelease: false
165
+ version_requirements: !ruby/object:Gem::Requirement
166
+ requirements:
167
+ - - '>='
168
+ - !ruby/object:Gem::Version
169
+ version: '0'
170
+ - !ruby/object:Gem::Dependency
171
+ name: railties
172
+ requirement: !ruby/object:Gem::Requirement
173
+ requirements:
174
+ - - '>='
175
+ - !ruby/object:Gem::Version
176
+ version: '0'
177
+ type: :development
178
+ prerelease: false
179
+ version_requirements: !ruby/object:Gem::Requirement
180
+ requirements:
181
+ - - '>='
182
+ - !ruby/object:Gem::Version
183
+ version: '0'
184
+ description: Process your Paperclip attachments in the background with DelayedJob,
185
+ Resque, Sidekiq or your own processor.
186
+ email:
187
+ - james@jamesrgifford.com
188
+ - scott@artsicle.com
117
189
  executables: []
118
190
  extensions: []
119
191
  extra_rdoc_files: []
@@ -131,14 +203,12 @@ files:
131
203
  - README.textile
132
204
  - Rakefile
133
205
  - delayed_paperclip.gemspec
134
- - gemfiles/paperclip3_5.gemfile
135
- - gemfiles/paperclip3_5.gemfile.lock
136
- - gemfiles/rails3.gemfile
137
- - gemfiles/rails3.gemfile.lock
138
206
  - gemfiles/rails3_1.gemfile
139
207
  - gemfiles/rails3_1.gemfile.lock
140
208
  - gemfiles/rails3_2.gemfile
141
209
  - gemfiles/rails3_2.gemfile.lock
210
+ - gemfiles/rails4.gemfile
211
+ - gemfiles/rails4.gemfile.lock
142
212
  - init.rb
143
213
  - lib/delayed_paperclip.rb
144
214
  - lib/delayed_paperclip/attachment.rb
@@ -187,7 +257,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
187
257
  version: '0'
188
258
  requirements: []
189
259
  rubyforge_project:
190
- rubygems_version: 2.0.3
260
+ rubygems_version: 2.1.11
191
261
  signing_key:
192
262
  specification_version: 4
193
263
  summary: Process your Paperclip attachments in the background.
@@ -1,11 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "http://rubygems.org"
4
-
5
- gem "appraisal"
6
- gem "json", :platforms=>:ruby_18
7
- gem "delayed_job_active_record", :require=>false
8
- gem "rails"
9
- gem "paperclip", "~> 3.5"
10
-
11
- gemspec :path=>"../"
@@ -1,160 +0,0 @@
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.14)
11
- actionpack (= 3.2.14)
12
- mail (~> 2.5.4)
13
- actionpack (3.2.14)
14
- activemodel (= 3.2.14)
15
- activesupport (= 3.2.14)
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.14)
24
- activesupport (= 3.2.14)
25
- builder (~> 3.0.0)
26
- activerecord (3.2.14)
27
- activemodel (= 3.2.14)
28
- activesupport (= 3.2.14)
29
- arel (~> 3.0.2)
30
- tzinfo (~> 0.3.29)
31
- activeresource (3.2.14)
32
- activemodel (= 3.2.14)
33
- activesupport (= 3.2.14)
34
- activesupport (3.2.14)
35
- i18n (~> 0.6, >= 0.6.4)
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.3)
57
- i18n (0.6.4)
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.7)
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.14)
85
- actionmailer (= 3.2.14)
86
- actionpack (= 3.2.14)
87
- activerecord (= 3.2.14)
88
- activeresource (= 3.2.14)
89
- activesupport (= 3.2.14)
90
- bundler (~> 1.0)
91
- railties (= 3.2.14)
92
- railties (3.2.14)
93
- actionpack (= 3.2.14)
94
- activesupport (= 3.2.14)
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.14)
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
- paperclip (~> 3.5)
156
- rails
157
- resque
158
- rspec
159
- sidekiq
160
- sqlite3