paperclip 2.1.5 → 2.2.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of paperclip might be problematic. Click here for more details.

@@ -4,6 +4,8 @@ require 'shoulda'
4
4
  require 'mocha'
5
5
  require 'tempfile'
6
6
 
7
+ gem 'sqlite3-ruby'
8
+
7
9
  require 'active_record'
8
10
  require 'active_support'
9
11
  begin
@@ -29,6 +29,8 @@ class IntegrationTest < Test::Unit::TestCase
29
29
  assert @dummy.save
30
30
  end
31
31
 
32
+ teardown { @file.close }
33
+
32
34
  should "create its thumbnails properly" do
33
35
  assert_match /\b50x50\b/, `identify "#{@dummy.avatar.path(:thumb)}"`
34
36
  end
@@ -49,6 +51,48 @@ class IntegrationTest < Test::Unit::TestCase
49
51
  end
50
52
  end
51
53
 
54
+ context "A model with attachments scoped under an id" do
55
+ setup do
56
+ rebuild_model :styles => { :large => "100x100",
57
+ :medium => "50x50" },
58
+ :path => ":rails_root/tmp/:id/:attachments/:style.:extension"
59
+ @dummy = Dummy.new
60
+ @file = File.new(File.join(File.dirname(__FILE__),
61
+ "fixtures",
62
+ "5k.png"), 'rb')
63
+ @dummy.avatar = @file
64
+ end
65
+
66
+ teardown { @file.close }
67
+
68
+ context "when saved" do
69
+ setup do
70
+ @dummy.save
71
+ @saved_path = @dummy.avatar.path(:large)
72
+ end
73
+
74
+ should "have a large file in the right place" do
75
+ assert File.exists?(@dummy.avatar.path(:large))
76
+ end
77
+
78
+ context "and deleted" do
79
+ setup do
80
+ @dummy.avatar = nil
81
+ @dummy.save
82
+ end
83
+
84
+ should "not have a large file in the right place anymore" do
85
+ assert ! File.exists?(@saved_path)
86
+ end
87
+
88
+ should "not have its next two parent directories" do
89
+ assert ! File.exists?(File.dirname(@saved_path))
90
+ assert ! File.exists?(File.dirname(File.dirname(@saved_path)))
91
+ end
92
+ end
93
+ end
94
+ end
95
+
52
96
  context "A model with no attachment validation" do
53
97
  setup do
54
98
  rebuild_model :styles => { :large => "300x300>",
@@ -209,7 +253,7 @@ class IntegrationTest < Test::Unit::TestCase
209
253
  @dummy.avatar = @bad_file
210
254
  assert ! @dummy.valid?
211
255
  @dummy.avatar = nil
212
- assert @dummy.valid?
256
+ assert @dummy.valid?, @dummy.errors.inspect
213
257
  end
214
258
 
215
259
  should "know the difference between good files, bad files, not files, and nil when validating" do
@@ -263,6 +307,25 @@ class IntegrationTest < Test::Unit::TestCase
263
307
 
264
308
  end
265
309
 
310
+ context "A model with an attachments association and a Paperclip attachment" do
311
+ setup do
312
+ Dummy.class_eval do
313
+ has_many :attachments, :class_name => 'Dummy'
314
+ end
315
+
316
+ @dummy = Dummy.new
317
+ @dummy.avatar = File.new(File.join(File.dirname(__FILE__),
318
+ "fixtures",
319
+ "5k.png"), 'rb')
320
+ end
321
+
322
+ should "should not error when saving" do
323
+ assert_nothing_raised do
324
+ @dummy.save!
325
+ end
326
+ end
327
+ end
328
+
266
329
  if ENV['S3_TEST_BUCKET']
267
330
  def s3_files_for attachment
268
331
  [:thumb, :medium, :large, :original].inject({}) do |files, style|
@@ -14,6 +14,8 @@ class IOStreamTest < Test::Unit::TestCase
14
14
  @file = File.new(File.join(File.dirname(__FILE__), "fixtures", "5k.png"), 'rb')
15
15
  end
16
16
 
17
+ teardown { @file.close }
18
+
17
19
  context "that is sent #stream_to" do
18
20
 
19
21
  context "and given a String" do
@@ -1,15 +1,49 @@
1
1
  require 'test/helper'
2
2
 
3
3
  class PaperclipTest < Test::Unit::TestCase
4
- context "Calling Paperclip.run" do
4
+ [:image_magick_path, :convert_path].each do |path|
5
+ context "Calling Paperclip.run with an #{path} specified" do
6
+ setup do
7
+ Paperclip.options[:image_magick_path] = nil
8
+ Paperclip.options[:convert_path] = nil
9
+ Paperclip.options[path] = "/usr/bin"
10
+ end
11
+
12
+ should "execute the right command" do
13
+ Paperclip.expects(:path_for_command).with("convert").returns("/usr/bin/convert")
14
+ Paperclip.expects(:bit_bucket).returns("/dev/null")
15
+ Paperclip.expects(:"`").with("/usr/bin/convert one.jpg two.jpg 2>/dev/null")
16
+ Paperclip.run("convert", "one.jpg two.jpg")
17
+ end
18
+ end
19
+ end
20
+
21
+ context "Calling Paperclip.run with no path specified" do
22
+ setup do
23
+ Paperclip.options[:image_magick_path] = nil
24
+ Paperclip.options[:convert_path] = nil
25
+ end
26
+
5
27
  should "execute the right command" do
6
- Paperclip.expects(:path_for_command).with("convert").returns("/usr/bin/convert")
28
+ Paperclip.expects(:path_for_command).with("convert").returns("convert")
7
29
  Paperclip.expects(:bit_bucket).returns("/dev/null")
8
- Paperclip.expects(:"`").with("/usr/bin/convert one.jpg two.jpg 2>/dev/null")
30
+ Paperclip.expects(:"`").with("convert one.jpg two.jpg 2>/dev/null")
9
31
  Paperclip.run("convert", "one.jpg two.jpg")
10
32
  end
11
33
  end
12
34
 
35
+ should "raise when sent #processor and the name of a class that exists but isn't a subclass of Processor" do
36
+ assert_raises(Paperclip::PaperclipError){ Paperclip.processor(:attachment) }
37
+ end
38
+
39
+ should "raise when sent #processor and the name of a class that doesn't exist" do
40
+ assert_raises(NameError){ Paperclip.processor(:boogey_man) }
41
+ end
42
+
43
+ should "return a class when sent #processor and the name of a class under Paperclip" do
44
+ assert_equal ::Paperclip::Thumbnail, Paperclip.processor(:thumbnail)
45
+ end
46
+
13
47
  context "Paperclip.bit_bucket" do
14
48
  context "on systems without /dev/null" do
15
49
  setup do
@@ -38,6 +72,8 @@ class PaperclipTest < Test::Unit::TestCase
38
72
  @file = File.new(File.join(FIXTURES_DIR, "5k.png"), 'rb')
39
73
  end
40
74
 
75
+ teardown { @file.close }
76
+
41
77
  should "not error when trying to also create a 'blah' attachment" do
42
78
  assert_nothing_raised do
43
79
  Dummy.class_eval do
@@ -0,0 +1,10 @@
1
+ require 'test/helper'
2
+
3
+ class ProcessorTest < Test::Unit::TestCase
4
+ should "instantiate and call #make when sent #make to the class" do
5
+ processor = mock
6
+ processor.expects(:make).with()
7
+ Paperclip::Processor.expects(:new).with(:one, :two).returns(processor)
8
+ Paperclip::Processor.make(:one, :two)
9
+ end
10
+ end
@@ -82,6 +82,8 @@ class StorageTest < Test::Unit::TestCase
82
82
  @dummy.avatar = @file
83
83
  end
84
84
 
85
+ teardown { @file.close }
86
+
85
87
  should "not get a bucket to get a URL" do
86
88
  @dummy.avatar.expects(:s3).never
87
89
  @dummy.avatar.expects(:s3_bucket).never
@@ -125,6 +127,50 @@ class StorageTest < Test::Unit::TestCase
125
127
  end
126
128
  end
127
129
 
130
+ context "An attachment with S3 storage and specific s3 headers set" do
131
+ setup do
132
+ rebuild_model :storage => :s3,
133
+ :bucket => "testing",
134
+ :path => ":attachment/:style/:basename.:extension",
135
+ :s3_credentials => {
136
+ 'access_key_id' => "12345",
137
+ 'secret_access_key' => "54321"
138
+ },
139
+ :s3_headers => {'Cache-Control' => 'max-age=31557600'}
140
+ end
141
+
142
+ context "when assigned" do
143
+ setup do
144
+ @file = File.new(File.join(File.dirname(__FILE__), 'fixtures', '5k.png'), 'rb')
145
+ @dummy = Dummy.new
146
+ @dummy.avatar = @file
147
+ end
148
+
149
+ teardown { @file.close }
150
+
151
+ context "and saved" do
152
+ setup do
153
+ @s3_mock = stub
154
+ @bucket_mock = stub
155
+ RightAws::S3.expects(:new).with("12345", "54321", {}).returns(@s3_mock)
156
+ @s3_mock.expects(:bucket).with("testing", true, "public-read").returns(@bucket_mock)
157
+ @key_mock = stub
158
+ @bucket_mock.expects(:key).returns(@key_mock)
159
+ @key_mock.expects(:data=)
160
+ @key_mock.expects(:put).with(nil,
161
+ 'public-read',
162
+ 'Content-type' => 'image/png',
163
+ 'Cache-Control' => 'max-age=31557600')
164
+ @dummy.save
165
+ end
166
+
167
+ should "succeed" do
168
+ assert true
169
+ end
170
+ end
171
+ end
172
+ end
173
+
128
174
  unless ENV["S3_TEST_BUCKET"].blank?
129
175
  context "Using S3 for real, an attachment with S3 storage" do
130
176
  setup do
@@ -148,6 +194,8 @@ class StorageTest < Test::Unit::TestCase
148
194
  @dummy.avatar = @file
149
195
  end
150
196
 
197
+ teardown { @file.close }
198
+
151
199
  should "still return a Tempfile when sent #to_io" do
152
200
  assert_equal Tempfile, @dummy.avatar.to_io.class
153
201
  end
@@ -35,13 +35,15 @@ class ThumbnailTest < Test::Unit::TestCase
35
35
  @file = File.new(File.join(File.dirname(__FILE__), "fixtures", "5k.png"), 'rb')
36
36
  end
37
37
 
38
+ teardown { @file.close }
39
+
38
40
  [["600x600>", "434x66"],
39
41
  ["400x400>", "400x61"],
40
42
  ["32x32<", "434x66"]
41
43
  ].each do |args|
42
44
  context "being thumbnailed with a geometry of #{args[0]}" do
43
45
  setup do
44
- @thumb = Paperclip::Thumbnail.new(@file, args[0])
46
+ @thumb = Paperclip::Thumbnail.new(@file, :geometry => args[0])
45
47
  end
46
48
 
47
49
  should "start with dimensions of 434x66" do
@@ -68,7 +70,7 @@ class ThumbnailTest < Test::Unit::TestCase
68
70
 
69
71
  context "being thumbnailed at 100x50 with cropping" do
70
72
  setup do
71
- @thumb = Paperclip::Thumbnail.new(@file, "100x50#")
73
+ @thumb = Paperclip::Thumbnail.new(@file, :geometry => "100x50#")
72
74
  end
73
75
 
74
76
  should "report its correct current and target geometries" do
@@ -80,8 +82,8 @@ class ThumbnailTest < Test::Unit::TestCase
80
82
  assert_nil @thumb.format
81
83
  end
82
84
 
83
- should "have whiny_thumbnails turned on by default" do
84
- assert @thumb.whiny_thumbnails
85
+ should "have whiny turned on by default" do
86
+ assert @thumb.whiny
85
87
  end
86
88
 
87
89
  should "have convert_options set to nil by default" do
@@ -103,7 +105,9 @@ class ThumbnailTest < Test::Unit::TestCase
103
105
 
104
106
  context "being thumbnailed with convert options set" do
105
107
  setup do
106
- @thumb = Paperclip::Thumbnail.new(@file, "100x50#", format=nil, convert_options="-strip -depth 8", whiny_thumbnails=true)
108
+ @thumb = Paperclip::Thumbnail.new(@file,
109
+ :geometry => "100x50#",
110
+ :convert_options => "-strip -depth 8")
107
111
  end
108
112
 
109
113
  should "have convert_options value set" do
@@ -124,7 +128,9 @@ class ThumbnailTest < Test::Unit::TestCase
124
128
 
125
129
  context "redefined to have bad convert_options setting" do
126
130
  setup do
127
- @thumb = Paperclip::Thumbnail.new(@file, "100x50#", format=nil, convert_options="-this-aint-no-option", whiny_thumbnails=true)
131
+ @thumb = Paperclip::Thumbnail.new(@file,
132
+ :geometry => "100x50#",
133
+ :convert_options => "-this-aint-no-option")
128
134
  end
129
135
 
130
136
  should "error when trying to create the thumbnail" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: paperclip
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.5
4
+ version: 2.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jon Yurek
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-12-10 00:00:00 -05:00
12
+ date: 2008-12-29 00:00:00 -05:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -59,8 +59,10 @@ files:
59
59
  - generators/paperclip/templates/paperclip_migration.rb.erb
60
60
  - generators/paperclip/USAGE
61
61
  - lib/paperclip/attachment.rb
62
+ - lib/paperclip/callback_compatability.rb
62
63
  - lib/paperclip/geometry.rb
63
64
  - lib/paperclip/iostream.rb
65
+ - lib/paperclip/processor.rb
64
66
  - lib/paperclip/storage.rb
65
67
  - lib/paperclip/thumbnail.rb
66
68
  - lib/paperclip/upfile.rb
@@ -79,6 +81,7 @@ files:
79
81
  - test/integration_test.rb
80
82
  - test/iostream_test.rb
81
83
  - test/paperclip_test.rb
84
+ - test/processor_test.rb
82
85
  - test/s3.yml
83
86
  - test/storage_test.rb
84
87
  - test/thumbnail_test.rb