whitby3001-paperclip-cloudfiles 2.3.8.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (61) hide show
  1. data/LICENSE +26 -0
  2. data/README.md +225 -0
  3. data/Rakefile +80 -0
  4. data/generators/paperclip/USAGE +5 -0
  5. data/generators/paperclip/paperclip_generator.rb +27 -0
  6. data/generators/paperclip/templates/paperclip_migration.rb.erb +19 -0
  7. data/init.rb +1 -0
  8. data/lib/generators/paperclip/USAGE +8 -0
  9. data/lib/generators/paperclip/paperclip_generator.rb +31 -0
  10. data/lib/generators/paperclip/templates/paperclip_migration.rb.erb +19 -0
  11. data/lib/paperclip.rb +376 -0
  12. data/lib/paperclip/attachment.rb +415 -0
  13. data/lib/paperclip/callback_compatability.rb +61 -0
  14. data/lib/paperclip/command_line.rb +80 -0
  15. data/lib/paperclip/geometry.rb +115 -0
  16. data/lib/paperclip/interpolations.rb +114 -0
  17. data/lib/paperclip/iostream.rb +45 -0
  18. data/lib/paperclip/matchers.rb +33 -0
  19. data/lib/paperclip/matchers/have_attached_file_matcher.rb +57 -0
  20. data/lib/paperclip/matchers/validate_attachment_content_type_matcher.rb +75 -0
  21. data/lib/paperclip/matchers/validate_attachment_presence_matcher.rb +54 -0
  22. data/lib/paperclip/matchers/validate_attachment_size_matcher.rb +95 -0
  23. data/lib/paperclip/processor.rb +58 -0
  24. data/lib/paperclip/railtie.rb +24 -0
  25. data/lib/paperclip/storage.rb +3 -0
  26. data/lib/paperclip/storage/cloud_files.rb +138 -0
  27. data/lib/paperclip/storage/filesystem.rb +73 -0
  28. data/lib/paperclip/storage/s3.rb +192 -0
  29. data/lib/paperclip/style.rb +93 -0
  30. data/lib/paperclip/thumbnail.rb +79 -0
  31. data/lib/paperclip/upfile.rb +55 -0
  32. data/lib/paperclip/version.rb +3 -0
  33. data/lib/tasks/paperclip.rake +72 -0
  34. data/rails/init.rb +2 -0
  35. data/shoulda_macros/paperclip.rb +118 -0
  36. data/test/attachment_test.rb +818 -0
  37. data/test/command_line_test.rb +133 -0
  38. data/test/database.yml +4 -0
  39. data/test/fixtures/12k.png +0 -0
  40. data/test/fixtures/50x50.png +0 -0
  41. data/test/fixtures/5k.png +0 -0
  42. data/test/fixtures/bad.png +1 -0
  43. data/test/fixtures/s3.yml +8 -0
  44. data/test/fixtures/text.txt +0 -0
  45. data/test/fixtures/twopage.pdf +0 -0
  46. data/test/geometry_test.rb +177 -0
  47. data/test/helper.rb +149 -0
  48. data/test/integration_test.rb +498 -0
  49. data/test/interpolations_test.rb +127 -0
  50. data/test/iostream_test.rb +71 -0
  51. data/test/matchers/have_attached_file_matcher_test.rb +24 -0
  52. data/test/matchers/validate_attachment_content_type_matcher_test.rb +47 -0
  53. data/test/matchers/validate_attachment_presence_matcher_test.rb +26 -0
  54. data/test/matchers/validate_attachment_size_matcher_test.rb +51 -0
  55. data/test/paperclip_test.rb +292 -0
  56. data/test/processor_test.rb +10 -0
  57. data/test/storage_test.rb +605 -0
  58. data/test/style_test.rb +141 -0
  59. data/test/thumbnail_test.rb +227 -0
  60. data/test/upfile_test.rb +36 -0
  61. metadata +242 -0
@@ -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, :three).returns(processor)
8
+ Paperclip::Processor.make(:one, :two, :three)
9
+ end
10
+ end
@@ -0,0 +1,605 @@
1
+ require './test/helper'
2
+ require 'aws/s3'
3
+
4
+ class StorageTest < Test::Unit::TestCase
5
+ def rails_env(env)
6
+ silence_warnings do
7
+ Object.const_set(:Rails, stub('Rails', :env => env))
8
+ end
9
+ end
10
+
11
+ context "filesystem" do
12
+ setup do
13
+ rebuild_model :styles => { :thumbnail => "25x25#" }
14
+ @dummy = Dummy.create!
15
+
16
+ @dummy.avatar = File.open(File.join(File.dirname(__FILE__), "fixtures", "5k.png"))
17
+ end
18
+
19
+ should "allow file assignment" do
20
+ assert @dummy.save
21
+ end
22
+
23
+ should "store the original" do
24
+ @dummy.save
25
+ assert File.exists?(@dummy.avatar.path)
26
+ end
27
+
28
+ should "store the thumbnail" do
29
+ @dummy.save
30
+ assert File.exists?(@dummy.avatar.path(:thumbnail))
31
+ end
32
+ end
33
+
34
+ context "Parsing S3 credentials" do
35
+ setup do
36
+ AWS::S3::Base.stubs(:establish_connection!)
37
+ rebuild_model :storage => :s3,
38
+ :bucket => "testing",
39
+ :s3_credentials => {:not => :important}
40
+
41
+ @dummy = Dummy.new
42
+ @avatar = @dummy.avatar
43
+ end
44
+
45
+ should "get the correct credentials when RAILS_ENV is production" do
46
+ rails_env("production")
47
+ assert_equal({:key => "12345"},
48
+ @avatar.parse_credentials('production' => {:key => '12345'},
49
+ :development => {:key => "54321"}))
50
+ end
51
+
52
+ should "get the correct credentials when RAILS_ENV is development" do
53
+ rails_env("development")
54
+ assert_equal({:key => "54321"},
55
+ @avatar.parse_credentials('production' => {:key => '12345'},
56
+ :development => {:key => "54321"}))
57
+ end
58
+
59
+ should "return the argument if the key does not exist" do
60
+ rails_env("not really an env")
61
+ assert_equal({:test => "12345"}, @avatar.parse_credentials(:test => "12345"))
62
+ end
63
+ end
64
+
65
+ context "Parsing Cloud Files credentials" do
66
+ setup do
67
+ CloudFiles::Connection.stubs(:new).returns(true)
68
+
69
+ rebuild_model :storage => :cloud_files,
70
+ :bucket => "testing",
71
+ :cloudfiles_credentials => {:not => :important}
72
+
73
+
74
+ @dummy = Dummy.new
75
+ @avatar = @dummy.avatar
76
+ @current_env = Rails.env
77
+ end
78
+
79
+ teardown do
80
+ rails_env(@current_env)
81
+ end
82
+
83
+ should "get the correct credentials when RAILS_ENV is production" do
84
+ rails_env("production")
85
+ assert_equal({:username => "minter"},
86
+ @avatar.parse_credentials('production' => {:username => 'minter'},
87
+ :development => {:username => "mcornick"}))
88
+ end
89
+
90
+ should "get the correct credentials when RAILS_ENV is development" do
91
+ rails_env("development")
92
+ assert_equal({:key => "mcornick"},
93
+ @avatar.parse_credentials('production' => {:key => 'minter'},
94
+ :development => {:key => "mcornick"}))
95
+ end
96
+
97
+ should "return the argument if the key does not exist" do
98
+ rails_env("not_valid")
99
+ assert_equal({:test => "minter"}, @avatar.parse_credentials(:test => "minter"))
100
+ end
101
+ end
102
+
103
+
104
+ context "" do
105
+ setup do
106
+ AWS::S3::Base.stubs(:establish_connection!)
107
+ rebuild_model :storage => :s3,
108
+ :s3_credentials => {},
109
+ :bucket => "bucket",
110
+ :path => ":attachment/:basename.:extension",
111
+ :url => ":s3_path_url"
112
+ @dummy = Dummy.new
113
+ @dummy.avatar = StringIO.new(".")
114
+ end
115
+
116
+ should "return a url based on an S3 path" do
117
+ assert_match %r{^http://s3.amazonaws.com/bucket/avatars/stringio.txt}, @dummy.avatar.url
118
+ end
119
+ end
120
+
121
+ context "" do
122
+ setup do
123
+ container = mock
124
+ container.stubs(:make_public).returns(true)
125
+ container.stubs(:public_url).returns('http://c0010181.cdn.cloudfiles.rackspacecloud.com/avatars/stringio.txt')
126
+ container.stubs(:cdn_url).returns('http://c0010181.cdn.cloudfiles.rackspacecloud.com')
127
+ connection = mock
128
+ connection.stubs(:create_container).returns(container)
129
+ CloudFiles::Connection.expects(:new).returns(connection)
130
+
131
+ rebuild_model :storage => :cloud_files,
132
+ :cloudfiles_credentials => {},
133
+ :container => "container",
134
+ :path => ":attachment/:basename.:extension"
135
+ @dummy = Dummy.new
136
+ @dummy.avatar = StringIO.new(".")
137
+ end
138
+
139
+ should "return a url based on an Cloud Files path" do
140
+ assert_match %r{^http://c0010181.cdn.cloudfiles.rackspacecloud.com/avatars/stringio.txt}, @dummy.avatar.url
141
+ end
142
+ end
143
+
144
+
145
+ context "" do
146
+ setup do
147
+ AWS::S3::Base.stubs(:establish_connection!)
148
+ rebuild_model :storage => :s3,
149
+ :s3_credentials => {},
150
+ :bucket => "bucket",
151
+ :path => ":attachment/:basename.:extension",
152
+ :url => ":s3_domain_url"
153
+ @dummy = Dummy.new
154
+ @dummy.avatar = StringIO.new(".")
155
+ end
156
+
157
+ should "return a url based on an S3 subdomain" do
158
+ assert_match %r{^http://bucket.s3.amazonaws.com/avatars/stringio.txt}, @dummy.avatar.url
159
+ end
160
+ end
161
+
162
+ context "" do
163
+ setup do
164
+ AWS::S3::Base.stubs(:establish_connection!)
165
+ rebuild_model :storage => :s3,
166
+ :s3_credentials => {
167
+ :production => { :bucket => "prod_bucket" },
168
+ :development => { :bucket => "dev_bucket" }
169
+ },
170
+ :s3_host_alias => "something.something.com",
171
+ :path => ":attachment/:basename.:extension",
172
+ :url => ":s3_alias_url"
173
+ @dummy = Dummy.new
174
+ @dummy.avatar = StringIO.new(".")
175
+ end
176
+
177
+ should "return a url based on the host_alias" do
178
+ assert_match %r{^http://something.something.com/avatars/stringio.txt}, @dummy.avatar.url
179
+ end
180
+ end
181
+
182
+ context "Generating a url with an expiration" do
183
+ setup do
184
+ AWS::S3::Base.stubs(:establish_connection!)
185
+ rebuild_model :storage => :s3,
186
+ :s3_credentials => {
187
+ :production => { :bucket => "prod_bucket" },
188
+ :development => { :bucket => "dev_bucket" }
189
+ },
190
+ :s3_host_alias => "something.something.com",
191
+ :path => ":attachment/:basename.:extension",
192
+ :url => ":s3_alias_url"
193
+
194
+ rails_env("production")
195
+
196
+ @dummy = Dummy.new
197
+ @dummy.avatar = StringIO.new(".")
198
+
199
+ AWS::S3::S3Object.expects(:url_for).with("avatars/stringio.txt", "prod_bucket", { :expires_in => 3600 })
200
+
201
+ @dummy.avatar.expiring_url
202
+ end
203
+
204
+ should "should succeed" do
205
+ assert true
206
+ end
207
+ end
208
+
209
+ context "Parsing S3 credentials with a bucket in them" do
210
+ setup do
211
+ AWS::S3::Base.stubs(:establish_connection!)
212
+ rebuild_model :storage => :s3,
213
+ :s3_credentials => {
214
+ :production => { :bucket => "prod_bucket" },
215
+ :development => { :bucket => "dev_bucket" }
216
+ }
217
+ @dummy = Dummy.new
218
+ end
219
+
220
+ should "get the right bucket in production" do
221
+ rails_env("production")
222
+ assert_equal "prod_bucket", @dummy.avatar.bucket_name
223
+ end
224
+
225
+ should "get the right bucket in development" do
226
+ rails_env("development")
227
+ assert_equal "dev_bucket", @dummy.avatar.bucket_name
228
+ end
229
+ end
230
+
231
+ context "Parsing Cloud Files credentials with a container in them" do
232
+ setup do
233
+ #CloudFiles::Connection.expects(:new).returns(true)
234
+ #CloudFiles::Connection.any_instance.stubs(:create_container).returns(true)
235
+ rebuild_model :storage => :cloud_files,
236
+ :cloudfiles_credentials => {
237
+ :production => { :container => "prod_container" },
238
+ :development => { :container => "dev_container" }
239
+ }
240
+ @dummy = Dummy.new
241
+ @old_env = Rails.env
242
+ end
243
+
244
+ teardown{ rails_env(@old_env) }
245
+
246
+ should "get the right container in production" do
247
+ rails_env("production")
248
+ assert_equal "prod_container", @dummy.avatar.container_name
249
+ end
250
+
251
+ should "get the right bucket in development" do
252
+ rails_env("development")
253
+ assert_equal "dev_container", @dummy.avatar.container_name
254
+ end
255
+ end
256
+
257
+
258
+ context "An attachment with S3 storage" do
259
+ setup do
260
+ rebuild_model :storage => :s3,
261
+ :bucket => "testing",
262
+ :path => ":attachment/:style/:basename.:extension",
263
+ :s3_credentials => {
264
+ 'access_key_id' => "12345",
265
+ 'secret_access_key' => "54321"
266
+ }
267
+ end
268
+
269
+ should "be extended by the S3 module" do
270
+ assert Dummy.new.avatar.is_a?(Paperclip::Storage::S3)
271
+ end
272
+
273
+ should "not be extended by the Filesystem module" do
274
+ assert ! Dummy.new.avatar.is_a?(Paperclip::Storage::Filesystem)
275
+ end
276
+
277
+ context "when assigned" do
278
+ setup do
279
+ @file = File.new(File.join(File.dirname(__FILE__), 'fixtures', '5k.png'), 'rb')
280
+ @dummy = Dummy.new
281
+ @dummy.avatar = @file
282
+ end
283
+
284
+ teardown { @file.close }
285
+
286
+ should "not get a bucket to get a URL" do
287
+ @dummy.avatar.expects(:s3).never
288
+ @dummy.avatar.expects(:s3_bucket).never
289
+ assert_match %r{^http://s3\.amazonaws\.com/testing/avatars/original/5k\.png}, @dummy.avatar.url
290
+ end
291
+
292
+ context "and saved" do
293
+ setup do
294
+ AWS::S3::S3Object.stubs(:store).with(@dummy.avatar.path, anything, 'testing', :content_type => 'image/png', :access => :public_read)
295
+ @dummy.save
296
+ end
297
+
298
+ should "succeed" do
299
+ assert true
300
+ end
301
+ end
302
+
303
+ context "and saved without a bucket" do
304
+ setup do
305
+ class AWS::S3::NoSuchBucket < AWS::S3::ResponseError
306
+ # Force the class to be created as a proper subclass of ResponseError thanks to AWS::S3's autocreation of exceptions
307
+ end
308
+ AWS::S3::Bucket.expects(:create).with("testing")
309
+ AWS::S3::S3Object.stubs(:store).raises(AWS::S3::NoSuchBucket.new(:message, :response)).then.returns(true)
310
+ @dummy.save
311
+ end
312
+
313
+ should "succeed" do
314
+ assert true
315
+ end
316
+ end
317
+
318
+ context "and remove" do
319
+ setup do
320
+ AWS::S3::S3Object.stubs(:exists?).returns(true)
321
+ AWS::S3::S3Object.stubs(:delete)
322
+ @dummy.destroy_attached_files
323
+ end
324
+
325
+ should "succeed" do
326
+ assert true
327
+ end
328
+ end
329
+ end
330
+ end
331
+
332
+ context "An attachment with Cloud Files storage" do
333
+ setup do
334
+ rebuild_model :storage => :cloud_files,
335
+ :container => "testing",
336
+ :path => ":attachment/:style/:basename.:extension",
337
+ :cloudfiles_credentials => {
338
+ 'username' => "minter",
339
+ 'api_key' => "xxxxxxx"
340
+ }
341
+ end
342
+
343
+ should "be extended by the CloudFile module" do
344
+ CloudFiles::Connection.stubs(:new).returns(true)
345
+ assert Dummy.new.avatar.is_a?(Paperclip::Storage::Cloud_files)
346
+ end
347
+
348
+ should "not be extended by the Filesystem module" do
349
+ CloudFiles::Connection.stubs(:new).returns(true)
350
+ assert ! Dummy.new.avatar.is_a?(Paperclip::Storage::Filesystem)
351
+ end
352
+
353
+ # context "when assigned" do
354
+ # setup do
355
+ # @cf_mock = stub
356
+ # CloudFiles::Connection.expects(:new).returns(@cf_mock)
357
+ # @file = File.new(File.join(File.dirname(__FILE__), 'fixtures', '5k.png'), 'rb')
358
+ # @dummy = Dummy.new
359
+ # @dummy.avatar = @file
360
+ # end
361
+ #
362
+ # teardown { @file.close }
363
+ #
364
+ # context "and saved" do
365
+ # setup do
366
+ # @container_mock = stub
367
+ # @object_mock = stub
368
+ # @cf_mock.expects(:create_container).with("testing").returns(@container_mock)
369
+ # @container_mock.expects(:make_public).returns(true)
370
+ # @container_mock.expects(:create_object).returns(@object_mock)
371
+ # @object_mock.expects(:write).returns(true)
372
+ # @dummy.save
373
+ # end
374
+ #
375
+ # should "succeed" do
376
+ # assert true
377
+ # end
378
+ # end
379
+ #
380
+ # context "and remove" do
381
+ # setup do
382
+ # @container_mock = stub
383
+ # print "DEBUG: ContainerMock is #{@container_mock}\n"
384
+ # @object_mock = stub
385
+ # print "DEBUG: Object Mock is #{@object_mock}\n"
386
+ # @cf_mock.expects(:create_container).with("testing").returns(@container_mock)
387
+ # @container_mock.expects(:make_public).returns(true)
388
+ # @container_mock.stubs(:object_exists?).returns(true)
389
+ # @container_mock.expects(:delete_object).with('avatars/original/5k.png').returns(true)
390
+ # @dummy.destroy_attached_files
391
+ # end
392
+ #
393
+ # should "succeed" do
394
+ # assert true
395
+ # end
396
+ # end
397
+ # end
398
+ end
399
+
400
+
401
+ context "An attachment with S3 storage and bucket defined as a Proc" do
402
+ setup do
403
+ AWS::S3::Base.stubs(:establish_connection!)
404
+ rebuild_model :storage => :s3,
405
+ :bucket => lambda { |attachment| "bucket_#{attachment.instance.other}" },
406
+ :s3_credentials => {:not => :important}
407
+ end
408
+
409
+ should "get the right bucket name" do
410
+ assert "bucket_a", Dummy.new(:other => 'a').avatar.bucket_name
411
+ assert "bucket_b", Dummy.new(:other => 'b').avatar.bucket_name
412
+ end
413
+ end
414
+
415
+ context "An attachment with Cloud Files storage and container defined as a Proc" do
416
+ setup do
417
+ CloudFiles::Connection.stubs(:new).returns(true)
418
+ rebuild_model :storage => :cloud_files,
419
+ :bucket => lambda { |attachment| "container_#{attachment.instance.other}" },
420
+ :cloudfiles_credentials => {:not => :important}
421
+ end
422
+
423
+ should "get the right container name" do
424
+ assert "container_a", Dummy.new(:other => 'a').avatar.container_name
425
+ assert "container_b", Dummy.new(:other => 'b').avatar.container_name
426
+ end
427
+ end
428
+
429
+
430
+ context "An attachment with S3 storage and specific s3 headers set" do
431
+ setup do
432
+ AWS::S3::Base.stubs(:establish_connection!)
433
+ rebuild_model :storage => :s3,
434
+ :bucket => "testing",
435
+ :path => ":attachment/:style/:basename.:extension",
436
+ :s3_credentials => {
437
+ 'access_key_id' => "12345",
438
+ 'secret_access_key' => "54321"
439
+ },
440
+ :s3_headers => {'Cache-Control' => 'max-age=31557600'}
441
+ end
442
+
443
+ context "when assigned" do
444
+ setup do
445
+ @file = File.new(File.join(File.dirname(__FILE__), 'fixtures', '5k.png'), 'rb')
446
+ @dummy = Dummy.new
447
+ @dummy.avatar = @file
448
+ end
449
+
450
+ teardown { @file.close }
451
+
452
+ context "and saved" do
453
+ setup do
454
+ AWS::S3::Base.stubs(:establish_connection!)
455
+ AWS::S3::S3Object.stubs(:store).with(@dummy.avatar.path,
456
+ anything,
457
+ 'testing',
458
+ :content_type => 'image/png',
459
+ :access => :public_read,
460
+ 'Cache-Control' => 'max-age=31557600')
461
+ @dummy.save
462
+ end
463
+
464
+ should "succeed" do
465
+ assert true
466
+ end
467
+ end
468
+ end
469
+ end
470
+
471
+ context "with S3 credentials supplied as Pathname" do
472
+ setup do
473
+ ENV['S3_KEY'] = 'pathname_key'
474
+ ENV['S3_BUCKET'] = 'pathname_bucket'
475
+ ENV['S3_SECRET'] = 'pathname_secret'
476
+
477
+ rails_env('test')
478
+
479
+ rebuild_model :storage => :s3,
480
+ :s3_credentials => Pathname.new(File.join(File.dirname(__FILE__))).join("fixtures/s3.yml")
481
+
482
+ Dummy.delete_all
483
+ @dummy = Dummy.new
484
+ end
485
+
486
+ should "parse the credentials" do
487
+ assert_equal 'pathname_bucket', @dummy.avatar.bucket_name
488
+ assert_equal 'pathname_key', AWS::S3::Base.connection.options[:access_key_id]
489
+ assert_equal 'pathname_secret', AWS::S3::Base.connection.options[:secret_access_key]
490
+ end
491
+ end
492
+
493
+ context "with S3 credentials in a YAML file" do
494
+ setup do
495
+ ENV['S3_KEY'] = 'env_key'
496
+ ENV['S3_BUCKET'] = 'env_bucket'
497
+ ENV['S3_SECRET'] = 'env_secret'
498
+
499
+ rails_env('test')
500
+
501
+ rebuild_model :storage => :s3,
502
+ :s3_credentials => File.new(File.join(File.dirname(__FILE__), "fixtures/s3.yml"))
503
+
504
+ Dummy.delete_all
505
+
506
+ @dummy = Dummy.new
507
+ end
508
+
509
+ should "run it the file through ERB" do
510
+ assert_equal 'env_bucket', @dummy.avatar.bucket_name
511
+ assert_equal 'env_key', AWS::S3::Base.connection.options[:access_key_id]
512
+ assert_equal 'env_secret', AWS::S3::Base.connection.options[:secret_access_key]
513
+ end
514
+ end
515
+
516
+ unless ENV["S3_TEST_BUCKET"].blank?
517
+ context "Using S3 for real, an attachment with S3 storage" do
518
+ setup do
519
+ rebuild_model :styles => { :thumb => "100x100", :square => "32x32#" },
520
+ :storage => :s3,
521
+ :bucket => ENV["S3_TEST_BUCKET"],
522
+ :path => ":class/:attachment/:id/:style.:extension",
523
+ :s3_credentials => File.new(File.join(File.dirname(__FILE__), "s3.yml"))
524
+
525
+ Dummy.delete_all
526
+ @dummy = Dummy.new
527
+ end
528
+
529
+ should "be extended by the S3 module" do
530
+ assert Dummy.new.avatar.is_a?(Paperclip::Storage::S3)
531
+ end
532
+
533
+ context "when assigned" do
534
+ setup do
535
+ @file = File.new(File.join(File.dirname(__FILE__), 'fixtures', '5k.png'), 'rb')
536
+ @dummy.avatar = @file
537
+ end
538
+
539
+ teardown { @file.close }
540
+
541
+ should "still return a Tempfile when sent #to_file" do
542
+ assert_equal Paperclip::Tempfile, @dummy.avatar.to_file.class
543
+ end
544
+
545
+ context "and saved" do
546
+ setup do
547
+ @dummy.save
548
+ end
549
+
550
+ should "be on S3" do
551
+ assert true
552
+ end
553
+
554
+ should "generate a tempfile with the right name" do
555
+ file = @dummy.avatar.to_file
556
+ assert_match /^original.*\.png$/, File.basename(file.path)
557
+ end
558
+ end
559
+ end
560
+ end
561
+ end
562
+
563
+ unless ENV["CF_TEST_BUCKET"].blank?
564
+ context "Using CloudFiles for real, an attachment with CloudFiles storage" do
565
+ setup do
566
+ rebuild_model :styles => { :thumb => "100x100", :square => "32x32#" },
567
+ :storage => :cloud_files,
568
+ :container => ENV["CF_TEST_BUCKET"],
569
+ :path => ":class/:attachment/:id/:style.:extension",
570
+ :cloudfiles_credentials => File.new(File.join(File.dirname(__FILE__), "cloudfiles.yml"))
571
+
572
+ Dummy.delete_all
573
+ @dummy = Dummy.new
574
+ end
575
+
576
+ should "be extended by the CloudFile module" do
577
+ assert Dummy.new.avatar.is_a?(Paperclip::Storage::CloudFile)
578
+ end
579
+
580
+ context "when assigned" do
581
+ setup do
582
+ @file = File.new(File.join(File.dirname(__FILE__), 'fixtures', '5k.png'), 'rb')
583
+ @dummy.avatar = @file
584
+ end
585
+
586
+ teardown { @file.close }
587
+
588
+ should "still return a Tempfile when sent #to_io" do
589
+ assert_equal Tempfile, @dummy.avatar.to_io.class
590
+ end
591
+
592
+ context "and saved" do
593
+ setup do
594
+ @dummy.save
595
+ end
596
+
597
+ should "be on Cloud Files" do
598
+ assert true
599
+ end
600
+ end
601
+ end
602
+ end
603
+ end
604
+
605
+ end