paperclip 2.3.1 → 2.3.1.1

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.

data/Rakefile CHANGED
@@ -76,7 +76,11 @@ spec = Gem::Specification.new do |s|
76
76
  s.rdoc_options << '--line-numbers' << '--inline-source'
77
77
  s.requirements << "ImageMagick"
78
78
  s.add_development_dependency 'thoughtbot-shoulda'
79
- s.add_development_dependency 'mocha'
79
+ s.add_development_dependency 'jferris-mocha', '= 0.9.5.0.1241126838'
80
+ s.add_development_dependency 'aws-s3'
81
+ s.add_development_dependency 'sqlite3-ruby'
82
+ s.add_development_dependency 'activerecord'
83
+ s.add_development_dependency 'activesupport'
80
84
  end
81
85
 
82
86
  desc "Print a list of the files to be put into the gem"
@@ -25,6 +25,7 @@
25
25
  #
26
26
  # See the +has_attached_file+ documentation for more details.
27
27
 
28
+ require 'erb'
28
29
  require 'tempfile'
29
30
  require 'paperclip/upfile'
30
31
  require 'paperclip/iostream'
@@ -44,7 +45,7 @@ end
44
45
  # documentation for Paperclip::ClassMethods for more useful information.
45
46
  module Paperclip
46
47
 
47
- VERSION = "2.3.1"
48
+ VERSION = "2.3.1.1"
48
49
 
49
50
  class << self
50
51
  # Provides configurability to Paperclip. There are a number of options available, such as:
@@ -187,7 +187,7 @@ module Paperclip
187
187
  # lives in the <attachment>_updated_at attribute of the model.
188
188
  def updated_at
189
189
  time = instance_read(:updated_at)
190
- time && time.to_i
190
+ time && time.to_f.to_i
191
191
  end
192
192
 
193
193
  # Paths and URLs can have a number of variables interpolated into them
@@ -95,9 +95,9 @@ module Paperclip
95
95
  # * +s3_permissions+: This is a String that should be one of the "canned" access
96
96
  # policies that S3 provides (more information can be found here:
97
97
  # http://docs.amazonwebservices.com/AmazonS3/2006-03-01/RESTAccessPolicy.html#RESTCannedAccessPolicies)
98
- # The default for Paperclip is "public-read".
98
+ # The default for Paperclip is :public_read.
99
99
  # * +s3_protocol+: The protocol for the URLs generated to your S3 assets. Can be either
100
- # 'http' or 'https'. Defaults to 'http' when your :s3_permissions are 'public-read' (the
100
+ # 'http' or 'https'. Defaults to 'http' when your :s3_permissions are :public_read (the
101
101
  # default), and 'https' when your :s3_permissions are anything else.
102
102
  # * +s3_headers+: A hash of headers such as {'Expires' => 1.year.from_now.httpdate}
103
103
  # * +bucket+: This is the name of the S3 bucket that will store your files. Remember
@@ -227,9 +227,9 @@ module Paperclip
227
227
  def find_credentials creds
228
228
  case creds
229
229
  when File
230
- YAML.load_file(creds.path)
230
+ YAML::load(ERB.new(File.read(creds.path)).result)
231
231
  when String
232
- YAML.load_file(creds)
232
+ YAML::load(ERB.new(File.read(creds)).result)
233
233
  when Hash
234
234
  creds
235
235
  else
@@ -8,12 +8,13 @@ module Paperclip
8
8
  def content_type
9
9
  type = (self.path.match(/\.(\w+)$/)[1] rescue "octet-stream").downcase
10
10
  case type
11
- when %r"jpe?g" then "image/jpeg"
11
+ when %r"jp(e|g|eg)" then "image/jpeg"
12
12
  when %r"tiff?" then "image/tiff"
13
13
  when %r"png", "gif", "bmp" then "image/#{type}"
14
14
  when "txt" then "text/plain"
15
15
  when %r"html?" then "text/html"
16
- when "csv", "xml", "css", "js" then "text/#{type}"
16
+ when "js" then "application/js"
17
+ when "csv", "xml", "css" then "text/#{type}"
17
18
  else "application/x-#{type}"
18
19
  end
19
20
  end
@@ -1,4 +1,5 @@
1
1
  require 'paperclip/matchers'
2
+ require 'action_controller'
2
3
 
3
4
  module Paperclip
4
5
  # =Paperclip Shoulda Macros
@@ -60,9 +61,57 @@ module Paperclip
60
61
  assert_accepts(matcher, klass)
61
62
  end
62
63
  end
64
+
65
+ # Stubs the HTTP PUT for an attachment using S3 storage.
66
+ #
67
+ # @example
68
+ # stub_paperclip_s3('user', 'avatar', 'png')
69
+ def stub_paperclip_s3(model, attachment, extension)
70
+ definition = model.gsub(" ", "_").classify.constantize.
71
+ attachment_definitions[attachment.to_sym]
72
+
73
+ path = "http://s3.amazonaws.com/:id/#{definition[:path]}"
74
+ path.gsub!(/:([^\/\.]+)/) do |match|
75
+ "([^\/\.]+)"
76
+ end
77
+
78
+ begin
79
+ FakeWeb.register_uri(:put, Regexp.new(path), :body => "OK")
80
+ rescue NameError
81
+ raise NameError, "the stub_paperclip_s3 shoulda macro requires the fakeweb gem."
82
+ end
83
+ end
84
+
85
+ # Stub S3 and return a file for attachment. Best with Factory Girl.
86
+ # Uses a strict directory convention:
87
+ #
88
+ # features/support/paperclip
89
+ #
90
+ # This method is used by the Paperclip-provided Cucumber step:
91
+ #
92
+ # When I attach a "demo_tape" "mp3" file to a "band" on S3
93
+ #
94
+ # @example
95
+ # Factory.define :band_with_demo_tape, :parent => :band do |band|
96
+ # band.demo_tape { band.paperclip_fixture("band", "demo_tape", "png") }
97
+ # end
98
+ def paperclip_fixture(model, attachment, extension)
99
+ stub_paperclip_s3(model, attachment, extension)
100
+ base_path = File.join(File.dirname(__FILE__), "..", "..",
101
+ "features", "support", "paperclip")
102
+ File.new(File.join(base_path, model, "#{attachment}.#{extension}"))
103
+ end
63
104
  end
64
105
  end
65
106
 
107
+ class ActionController::Integration::Session #:nodoc:
108
+ include Paperclip::Shoulda
109
+ end
110
+
111
+ class Factory
112
+ include Paperclip::Shoulda #:nodoc:
113
+ end
114
+
66
115
  class Test::Unit::TestCase #:nodoc:
67
116
  extend Paperclip::Shoulda
68
117
  end
@@ -531,9 +531,10 @@ class AttachmentTest < Test::Unit::TestCase
531
531
  @attachment.stubs(:instance_read).with(:file_name).returns("5k.png")
532
532
  @attachment.stubs(:instance_read).with(:content_type).returns("image/png")
533
533
  @attachment.stubs(:instance_read).with(:file_size).returns(12345)
534
- now = Time.now
535
- Time.stubs(:now).returns(now)
536
- @attachment.stubs(:instance_read).with(:updated_at).returns(Time.now)
534
+ dtnow = DateTime.now
535
+ @now = Time.now
536
+ Time.stubs(:now).returns(@now)
537
+ @attachment.stubs(:instance_read).with(:updated_at).returns(dtnow)
537
538
  end
538
539
 
539
540
  should "return a correct url even if the file does not exist" do
@@ -542,11 +543,11 @@ class AttachmentTest < Test::Unit::TestCase
542
543
  end
543
544
 
544
545
  should "make sure the updated_at mtime is in the url if it is defined" do
545
- assert_match %r{#{Time.now.to_i}$}, @attachment.url(:blah)
546
+ assert_match %r{#{@now.to_i}$}, @attachment.url(:blah)
546
547
  end
547
548
 
548
549
  should "make sure the updated_at mtime is NOT in the url if false is passed to the url method" do
549
- assert_no_match %r{#{Time.now.to_i}$}, @attachment.url(:blah, false)
550
+ assert_no_match %r{#{@now.to_i}$}, @attachment.url(:blah, false)
550
551
  end
551
552
 
552
553
  context "with the updated_at field removed" do
@@ -2,3 +2,7 @@ development:
2
2
  key: 54321
3
3
  production:
4
4
  key: 12345
5
+ test:
6
+ bucket: <%= ENV['S3_BUCKET'] %>
7
+ access_key_id: <%= ENV['S3_KEY'] %>
8
+ secret_access_key: <%= ENV['S3_SECRET'] %>
@@ -236,6 +236,29 @@ class StorageTest < Test::Unit::TestCase
236
236
  end
237
237
  end
238
238
 
239
+ context "with S3 credentials in a YAML file" do
240
+ setup do
241
+ ENV['S3_KEY'] = 'env_key'
242
+ ENV['S3_BUCKET'] = 'env_bucket'
243
+ ENV['S3_SECRET'] = 'env_secret'
244
+
245
+ rails_env('test')
246
+
247
+ rebuild_model :storage => :s3,
248
+ :s3_credentials => File.new(File.join(File.dirname(__FILE__), "fixtures/s3.yml"))
249
+
250
+ Dummy.delete_all
251
+
252
+ @dummy = Dummy.new
253
+ end
254
+
255
+ should "run it the file through ERB" do
256
+ assert_equal 'env_bucket', @dummy.avatar.bucket_name
257
+ assert_equal 'env_key', AWS::S3::Base.connection.options[:access_key_id]
258
+ assert_equal 'env_secret', AWS::S3::Base.connection.options[:secret_access_key]
259
+ end
260
+ end
261
+
239
262
  unless ENV["S3_TEST_BUCKET"].blank?
240
263
  context "Using S3 for real, an attachment with S3 storage" do
241
264
  setup do
@@ -0,0 +1,28 @@
1
+ require 'test/helper'
2
+
3
+ class UpfileTest < Test::Unit::TestCase
4
+ { %w(jpg jpe jpeg) => 'image/jpeg',
5
+ %w(tif tiff) => 'image/tiff',
6
+ %w(png) => 'image/png',
7
+ %w(gif) => 'image/gif',
8
+ %w(bmp) => 'image/bmp',
9
+ %w(txt) => 'text/plain',
10
+ %w(htm html) => 'text/html',
11
+ %w(csv) => 'text/csv',
12
+ %w(xml) => 'text/xml',
13
+ %w(css) => 'text/css',
14
+ %w(js) => 'application/js',
15
+ %w(foo) => 'application/x-foo'
16
+ }.each do |extensions, content_type|
17
+ extensions.each do |extension|
18
+ should "return a content_type of #{content_type} for a file with extension .#{extension}" do
19
+ file = stub('file', :path => "basename.#{extension}")
20
+ class << file
21
+ include Paperclip::Upfile
22
+ end
23
+
24
+ assert_equal content_type, file.content_type
25
+ end
26
+ end
27
+ end
28
+ end
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.3.1
4
+ version: 2.3.1.1
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: 2009-08-21 00:00:00 -04:00
12
+ date: 2009-10-09 00:00:00 -04:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -23,7 +23,47 @@ dependencies:
23
23
  version: "0"
24
24
  version:
25
25
  - !ruby/object:Gem::Dependency
26
- name: mocha
26
+ name: jferris-mocha
27
+ type: :development
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "="
32
+ - !ruby/object:Gem::Version
33
+ version: 0.9.5.0.1241126838
34
+ version:
35
+ - !ruby/object:Gem::Dependency
36
+ name: aws-s3
37
+ type: :development
38
+ version_requirement:
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: "0"
44
+ version:
45
+ - !ruby/object:Gem::Dependency
46
+ name: sqlite3-ruby
47
+ type: :development
48
+ version_requirement:
49
+ version_requirements: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: "0"
54
+ version:
55
+ - !ruby/object:Gem::Dependency
56
+ name: activerecord
57
+ type: :development
58
+ version_requirement:
59
+ version_requirements: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ version: "0"
64
+ version:
65
+ - !ruby/object:Gem::Dependency
66
+ name: activesupport
27
67
  type: :development
28
68
  version_requirement:
29
69
  version_requirements: !ruby/object:Gem::Requirement
@@ -86,6 +126,7 @@ files:
86
126
  - test/processor_test.rb
87
127
  - test/storage_test.rb
88
128
  - test/thumbnail_test.rb
129
+ - test/upfile_test.rb
89
130
  - shoulda_macros/paperclip.rb
90
131
  has_rdoc: true
91
132
  homepage: http://www.thoughtbot.com/projects/paperclip
@@ -114,7 +155,7 @@ requirements:
114
155
  rubyforge_project: paperclip
115
156
  rubygems_version: 1.3.5
116
157
  signing_key:
117
- specification_version: 2
158
+ specification_version: 3
118
159
  summary: File attachments as attributes for ActiveRecord
119
160
  test_files: []
120
161