paperclip 2.3.3 → 2.3.4

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.

@@ -9,24 +9,22 @@ case ENV['RAILS_VERSION']
9
9
  when '2.1' then
10
10
  gem 'activerecord', '~>2.1.0'
11
11
  gem 'activesupport', '~>2.1.0'
12
- gem 'actionpack', '~>2.1.0'
13
12
  when '3.0' then
14
13
  gem 'activerecord', '~>3.0.0'
15
14
  gem 'activesupport', '~>3.0.0'
16
- gem 'actionpack', '~>3.0.0'
17
15
  else
18
16
  gem 'activerecord', '~>2.3.0'
19
17
  gem 'activesupport', '~>2.3.0'
20
- gem 'actionpack', '~>2.3.0'
21
18
  end
22
19
 
23
20
  require 'active_record'
24
21
  require 'active_record/version'
25
22
  require 'active_support'
26
- require 'action_pack'
27
23
 
28
24
  puts "Testing against version #{ActiveRecord::VERSION::STRING}"
29
25
 
26
+ `ruby -e 'exit 0'` # Prime $? with a value.
27
+
30
28
  begin
31
29
  require 'ruby-debug'
32
30
  rescue LoadError => e
@@ -59,14 +57,14 @@ require 'shoulda_macros/paperclip'
59
57
 
60
58
  FIXTURES_DIR = File.join(File.dirname(__FILE__), "fixtures")
61
59
  config = YAML::load(IO.read(File.dirname(__FILE__) + '/database.yml'))
62
- ActiveRecord::Base.logger = Logger.new(File.dirname(__FILE__) + "/debug.log")
60
+ ActiveRecord::Base.logger = ActiveSupport::BufferedLogger.new(File.dirname(__FILE__) + "/debug.log")
63
61
  ActiveRecord::Base.establish_connection(config['test'])
64
62
 
65
63
  def reset_class class_name
66
- ActiveRecord::Base.send(:include, Paperclip)
64
+ ActiveRecord::Base.send(:include, Paperclip::Glue)
67
65
  Object.send(:remove_const, class_name) rescue nil
68
66
  klass = Object.const_set(class_name, Class.new(ActiveRecord::Base))
69
- klass.class_eval{ include Paperclip }
67
+ klass.class_eval{ include Paperclip::Glue }
70
68
  klass
71
69
  end
72
70
 
@@ -86,16 +84,17 @@ def rebuild_model options = {}
86
84
  table.column :avatar_content_type, :string
87
85
  table.column :avatar_file_size, :integer
88
86
  table.column :avatar_updated_at, :datetime
87
+ table.column :avatar_fingerprint, :string
89
88
  end
90
89
  rebuild_class options
91
90
  end
92
91
 
93
92
  def rebuild_class options = {}
94
- ActiveRecord::Base.send(:include, Paperclip)
93
+ ActiveRecord::Base.send(:include, Paperclip::Glue)
95
94
  Object.send(:remove_const, "Dummy") rescue nil
96
95
  Object.const_set("Dummy", Class.new(ActiveRecord::Base))
97
96
  Dummy.class_eval do
98
- include Paperclip
97
+ include Paperclip::Glue
99
98
  has_attached_file :avatar, options
100
99
  end
101
100
  end
@@ -105,6 +104,7 @@ class FakeModel
105
104
  :avatar_file_size,
106
105
  :avatar_last_updated,
107
106
  :avatar_content_type,
107
+ :avatar_fingerprint,
108
108
  :id
109
109
 
110
110
  def errors
@@ -146,3 +146,13 @@ def should_reject_dummy_class
146
146
  assert_rejects @matcher, @dummy_class.new
147
147
  end
148
148
  end
149
+
150
+ def with_exitstatus_returning(code)
151
+ saved_exitstatus = $?.nil? ? 0 : $?.exitstatus
152
+ begin
153
+ `ruby -e 'exit #{code.to_i}'`
154
+ yield
155
+ ensure
156
+ `ruby -e 'exit #{saved_exitstatus.to_i}'`
157
+ end
158
+ end
@@ -204,7 +204,7 @@ class IntegrationTest < Test::Unit::TestCase
204
204
  @bad_file = File.new(File.join(FIXTURES_DIR, "bad.png"), 'rb')
205
205
 
206
206
  assert @dummy.avatar = @file
207
- assert @dummy.valid?
207
+ assert @dummy.valid?, @dummy.errors.full_messages.join(", ")
208
208
  assert @dummy.save
209
209
  end
210
210
 
@@ -363,7 +363,6 @@ class IntegrationTest < Test::Unit::TestCase
363
363
  :thumb => ["32x32#", :gif] },
364
364
  :storage => :s3,
365
365
  :whiny_thumbnails => true,
366
- # :s3_options => {:logger => Logger.new(StringIO.new)},
367
366
  :s3_credentials => File.new(File.join(File.dirname(__FILE__), "s3.yml")),
368
367
  :default_style => :medium,
369
368
  :bucket => ENV['S3_TEST_BUCKET'],
@@ -82,14 +82,17 @@ class InterpolationsTest < Test::Unit::TestCase
82
82
 
83
83
  should "reinterpolate :url" do
84
84
  attachment = mock
85
- attachment.expects(:options).returns({:url => ":id"})
86
85
  attachment.expects(:url).with(:style, false).returns("1234")
87
86
  assert_equal "1234", Paperclip::Interpolations.url(attachment, :style)
88
87
  end
89
88
 
90
89
  should "raise if infinite loop detcted reinterpolating :url" do
91
- attachment = mock
92
- attachment.expects(:options).returns({:url => ":url"})
90
+ attachment = Object.new
91
+ class << attachment
92
+ def url(*args)
93
+ Paperclip::Interpolations.url(self, :style)
94
+ end
95
+ end
93
96
  assert_raises(Paperclip::InfiniteInterpolationError){ Paperclip::Interpolations.url(attachment, :style) }
94
97
  end
95
98
 
@@ -4,6 +4,7 @@ class ValidateAttachmentContentTypeMatcherTest < Test::Unit::TestCase
4
4
  context "validate_attachment_content_type" do
5
5
  setup do
6
6
  reset_table("dummies") do |d|
7
+ d.string :title
7
8
  d.string :avatar_file_name
8
9
  d.string :avatar_content_type
9
10
  end
@@ -33,5 +34,14 @@ class ValidateAttachmentContentTypeMatcherTest < Test::Unit::TestCase
33
34
 
34
35
  should_accept_dummy_class
35
36
  end
37
+
38
+ context "given a class with other validations but matching types" do
39
+ setup do
40
+ @dummy_class.validates_presence_of :title
41
+ @dummy_class.validates_attachment_content_type :avatar, :content_type => %r{image/.*}
42
+ end
43
+
44
+ should_accept_dummy_class
45
+ end
36
46
  end
37
47
  end
@@ -1,118 +1,48 @@
1
1
  require 'test/helper'
2
2
 
3
3
  class PaperclipTest < Test::Unit::TestCase
4
- [:image_magick_path, :command_path].each do |path|
5
- context "Calling Paperclip.run with #{path} specified" do
6
- setup do
7
- Paperclip.options[:image_magick_path] = nil
8
- Paperclip.options[:command_path] = nil
9
- Paperclip.options[path] = "/usr/bin"
10
- end
11
-
12
- should "return the expected path for path_for_command" do
13
- assert_equal "/usr/bin/convert", Paperclip.path_for_command("convert")
14
- end
15
-
16
- should "execute the right command" do
17
- Paperclip.expects(:path_for_command).with("convert").returns("/usr/bin/convert")
18
- Paperclip.expects(:bit_bucket).returns("/dev/null")
19
- Paperclip.expects(:"`").with("/usr/bin/convert 'one.jpg' 'two.jpg' 2>/dev/null")
20
- Paperclip.run("convert", "one.jpg", "two.jpg")
21
- end
22
- end
23
- end
24
-
25
- context "Calling Paperclip.run with no path specified" do
4
+ context "Calling Paperclip.run" do
26
5
  setup do
27
6
  Paperclip.options[:image_magick_path] = nil
28
7
  Paperclip.options[:command_path] = nil
8
+ Paperclip::CommandLine.stubs(:'`')
29
9
  end
30
10
 
31
- should "return the expected path fro path_for_command" do
32
- assert_equal "convert", Paperclip.path_for_command("convert")
11
+ should "execute the right command with :image_magick_path" do
12
+ Paperclip.options[:image_magick_path] = "/usr/bin"
13
+ Paperclip.expects(:log).with(includes('[DEPRECATION]'))
14
+ Paperclip.expects(:log).with(regexp_matches(%r{/usr/bin/convert ['"]one.jpg['"] ['"]two.jpg['"]}))
15
+ Paperclip::CommandLine.expects(:"`").with(regexp_matches(%r{/usr/bin/convert ['"]one.jpg['"] ['"]two.jpg['"]}))
16
+ Paperclip.run("convert", ":one :two", :one => "one.jpg", :two => "two.jpg")
33
17
  end
34
18
 
35
- should "execute the right command" do
36
- Paperclip.expects(:path_for_command).with("convert").returns("convert")
37
- Paperclip.expects(:bit_bucket).returns("/dev/null")
38
- Paperclip.expects(:"`").with("convert 'one.jpg' 'two.jpg' 2>/dev/null")
39
- Paperclip.run("convert", "one.jpg", "two.jpg")
19
+ should "execute the right command with :command_path" do
20
+ Paperclip.options[:command_path] = "/usr/bin"
21
+ Paperclip::CommandLine.expects(:"`").with(regexp_matches(%r{/usr/bin/convert ['"]one.jpg['"] ['"]two.jpg['"]}))
22
+ Paperclip.run("convert", ":one :two", :one => "one.jpg", :two => "two.jpg")
40
23
  end
41
- end
42
24
 
43
- context "Calling Paperclip.run and logging" do
44
- should "log the command when :log_command is true" do
45
- Paperclip.options[:image_magick_path] = nil
46
- Paperclip.options[:command_path] = nil
47
- Paperclip.stubs(:bit_bucket).returns("/dev/null")
48
- Paperclip.expects(:log).with("this 'is the command' 2>/dev/null")
49
- Paperclip.expects(:"`").with("this 'is the command' 2>/dev/null")
50
- Paperclip.options[:log_command] = true
51
- Paperclip.run("this","is the command")
25
+ should "execute the right command with no path" do
26
+ Paperclip::CommandLine.expects(:"`").with(regexp_matches(%r{convert ['"]one.jpg['"] ['"]two.jpg['"]}))
27
+ Paperclip.run("convert", ":one :two", :one => "one.jpg", :two => "two.jpg")
52
28
  end
53
29
 
54
- should "not log the command when :log_command is false" do
55
- Paperclip.options[:image_magick_path] = nil
56
- Paperclip.options[:command_path] = nil
57
- Paperclip.stubs(:bit_bucket).returns("/dev/null")
58
- Paperclip.expects(:log).with("this 'is the command' 2>/dev/null").never
59
- Paperclip.expects(:"`").with("this 'is the command' 2>/dev/null")
60
- Paperclip.options[:log_command] = false
61
- Paperclip.run("this","is the command")
62
- end
63
- end
64
-
65
- context "Calling Paperclip.run when the command is not found" do
66
30
  should "tell you the command isn't there if the shell returns 127" do
67
- begin
31
+ with_exitstatus_returning(127) do
68
32
  assert_raises(Paperclip::CommandNotFoundError) do
69
- `ruby -e 'exit 127'` # Stub $?.exitstatus to be 127, i.e. Command Not Found.
70
- Paperclip.stubs(:"`").returns("")
71
33
  Paperclip.run("command")
72
34
  end
73
- ensure
74
- `ruby -e 'exit 0'` # Unstub $?.exitstatus
75
35
  end
76
36
  end
37
+
77
38
  should "tell you the command isn't there if an ENOENT is raised" do
78
39
  assert_raises(Paperclip::CommandNotFoundError) do
79
- Paperclip.stubs(:"`").raises(Errno::ENOENT)
40
+ Paperclip::CommandLine.stubs(:"`").raises(Errno::ENOENT)
80
41
  Paperclip.run("command")
81
42
  end
82
43
  end
83
44
  end
84
45
 
85
- should "prevent dangerous characters in the command via quoting" do
86
- Paperclip.options[:image_magick_path] = nil
87
- Paperclip.options[:command_path] = nil
88
- Paperclip.options[:log_command] = false
89
- Paperclip.options[:swallow_stderr] = false
90
- Paperclip.expects(:"`").with(%q[this 'is' 'jack'\''s' '`command`' 'line!'])
91
- Paperclip.run("this", "is", "jack's", "`command`", "line!")
92
- end
93
-
94
- context "Paperclip.bit_bucket" do
95
- context "on systems without /dev/null" do
96
- setup do
97
- File.expects(:exists?).with("/dev/null").returns(false)
98
- end
99
-
100
- should "return 'NUL'" do
101
- assert_equal "NUL", Paperclip.bit_bucket
102
- end
103
- end
104
-
105
- context "on systems with /dev/null" do
106
- setup do
107
- File.expects(:exists?).with("/dev/null").returns(true)
108
- end
109
-
110
- should "return '/dev/null'" do
111
- assert_equal "/dev/null", Paperclip.bit_bucket
112
- end
113
- end
114
- end
115
-
116
46
  should "raise when sent #processor and the name of a class that exists but isn't a subclass of Processor" do
117
47
  assert_raises(Paperclip::PaperclipError){ Paperclip.processor(:attachment) }
118
48
  end
@@ -242,9 +172,16 @@ class PaperclipTest < Test::Unit::TestCase
242
172
  end
243
173
  end
244
174
 
175
+ should "not have Attachment in the ActiveRecord::Base namespace" do
176
+ assert_raises(NameError) do
177
+ ActiveRecord::Base::Attachment
178
+ end
179
+ end
180
+
245
181
  def self.should_validate validation, options, valid_file, invalid_file
246
182
  context "with #{validation} validation and #{options.inspect} options" do
247
183
  setup do
184
+ rebuild_class
248
185
  Dummy.send(:"validates_attachment_#{validation}", :avatar, options)
249
186
  @dummy = Dummy.new
250
187
  end
@@ -259,7 +196,7 @@ class PaperclipTest < Test::Unit::TestCase
259
196
  end
260
197
  else
261
198
  should "not have an error on the attachment" do
262
- assert @dummy.errors[:avatar_file_name].blank?, @dummy.errors.full_messages.join(", ")
199
+ assert @dummy.errors.blank?, @dummy.errors.full_messages.join(", ")
263
200
  end
264
201
  end
265
202
  end
@@ -185,6 +185,21 @@ class StorageTest < Test::Unit::TestCase
185
185
  end
186
186
  end
187
187
 
188
+ context "and saved without a bucket" do
189
+ setup do
190
+ class AWS::S3::NoSuchBucket < AWS::S3::ResponseError
191
+ # Force the class to be created as a proper subclass of ResponseError thanks to AWS::S3's autocreation of exceptions
192
+ end
193
+ AWS::S3::Bucket.expects(:create).with("testing")
194
+ AWS::S3::S3Object.stubs(:store).raises(AWS::S3::NoSuchBucket.new(:message, :response)).then.returns(true)
195
+ @dummy.save
196
+ end
197
+
198
+ should "succeed" do
199
+ assert true
200
+ end
201
+ end
202
+
188
203
  context "and remove" do
189
204
  setup do
190
205
  AWS::S3::S3Object.stubs(:exists?).returns(true)
@@ -325,7 +340,7 @@ class StorageTest < Test::Unit::TestCase
325
340
  teardown { @file.close }
326
341
 
327
342
  should "still return a Tempfile when sent #to_file" do
328
- assert_equal Tempfile, @dummy.avatar.to_file.class
343
+ assert_equal Paperclip::Tempfile, @dummy.avatar.to_file.class
329
344
  end
330
345
 
331
346
  context "and saved" do
@@ -4,10 +4,11 @@ class ThumbnailTest < Test::Unit::TestCase
4
4
 
5
5
  context "A Paperclip Tempfile" do
6
6
  setup do
7
- @tempfile = Paperclip::Tempfile.new("file.jpg")
7
+ @tempfile = Paperclip::Tempfile.new(["file", ".jpg"])
8
8
  end
9
9
 
10
10
  should "have its path contain a real extension" do
11
+ p @tempfile.path
11
12
  assert_equal ".jpg", File.extname(@tempfile.path)
12
13
  end
13
14
 
@@ -91,8 +92,8 @@ class ThumbnailTest < Test::Unit::TestCase
91
92
  end
92
93
 
93
94
  should "send the right command to convert when sent #make" do
94
- Paperclip.expects(:"`").with do |arg|
95
- arg.match %r{convert '#{File.expand_path(@thumb.file.path)}\[0\]' '-resize' 'x50' '-crop' '100x50\+114\+0' '\+repage' '.*?'}
95
+ Paperclip::CommandLine.expects(:"`").with do |arg|
96
+ arg.match %r{convert ["']#{File.expand_path(@thumb.file.path)}\[0\]["'] -resize ["']x50["'] -crop ["']100x50\+114\+0["'] \+repage ["'].*?["']}
96
97
  end
97
98
  @thumb.make
98
99
  end
@@ -115,8 +116,8 @@ class ThumbnailTest < Test::Unit::TestCase
115
116
  end
116
117
 
117
118
  should "send the right command to convert when sent #make" do
118
- Paperclip.expects(:"`").with do |arg|
119
- arg.match %r{convert '-strip' '#{File.expand_path(@thumb.file.path)}\[0\]' '-resize' 'x50' '-crop' '100x50\+114\+0' '\+repage' '.*?'}
119
+ Paperclip::CommandLine.expects(:"`").with do |arg|
120
+ arg.match %r{convert -strip ["']#{File.expand_path(@thumb.file.path)}\[0\]["'] -resize ["']x50["'] -crop ["']100x50\+114\+0["'] \+repage ["'].*?["']}
120
121
  end
121
122
  @thumb.make
122
123
  end
@@ -153,8 +154,8 @@ class ThumbnailTest < Test::Unit::TestCase
153
154
  end
154
155
 
155
156
  should "send the right command to convert when sent #make" do
156
- Paperclip.expects(:"`").with do |arg|
157
- arg.match %r{convert '#{File.expand_path(@thumb.file.path)}\[0\]' '-resize' 'x50' '-crop' '100x50\+114\+0' '\+repage' '-strip' '-depth' '8' '.*?'}
157
+ Paperclip::CommandLine.expects(:"`").with do |arg|
158
+ arg.match %r{convert ["']#{File.expand_path(@thumb.file.path)}\[0\]["'] -resize ["']x50["'] -crop ["']100x50\+114\+0["'] \+repage -strip -depth 8 ["'].*?["']}
158
159
  end
159
160
  @thumb.make
160
161
  end
metadata CHANGED
@@ -1,12 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: paperclip
3
3
  version: !ruby/object:Gem::Version
4
+ hash: 11
4
5
  prerelease: false
5
6
  segments:
6
7
  - 2
7
8
  - 3
8
- - 3
9
- version: 2.3.3
9
+ - 4
10
+ version: 2.3.4
10
11
  platform: ruby
11
12
  authors:
12
13
  - Jon Yurek
@@ -14,16 +15,18 @@ autorequire:
14
15
  bindir: bin
15
16
  cert_chain: []
16
17
 
17
- date: 2010-06-09 00:00:00 -04:00
18
+ date: 2010-10-06 00:00:00 -04:00
18
19
  default_executable:
19
20
  dependencies:
20
21
  - !ruby/object:Gem::Dependency
21
22
  name: activerecord
22
23
  prerelease: false
23
24
  requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
24
26
  requirements:
25
27
  - - ">="
26
28
  - !ruby/object:Gem::Version
29
+ hash: 3
27
30
  segments:
28
31
  - 0
29
32
  version: "0"
@@ -33,9 +36,11 @@ dependencies:
33
36
  name: activesupport
34
37
  prerelease: false
35
38
  requirement: &id002 !ruby/object:Gem::Requirement
39
+ none: false
36
40
  requirements:
37
41
  - - ">="
38
42
  - !ruby/object:Gem::Version
43
+ hash: 3
39
44
  segments:
40
45
  - 0
41
46
  version: "0"
@@ -45,9 +50,11 @@ dependencies:
45
50
  name: shoulda
46
51
  prerelease: false
47
52
  requirement: &id003 !ruby/object:Gem::Requirement
53
+ none: false
48
54
  requirements:
49
55
  - - ">="
50
56
  - !ruby/object:Gem::Version
57
+ hash: 3
51
58
  segments:
52
59
  - 0
53
60
  version: "0"
@@ -57,9 +64,11 @@ dependencies:
57
64
  name: mocha
58
65
  prerelease: false
59
66
  requirement: &id004 !ruby/object:Gem::Requirement
67
+ none: false
60
68
  requirements:
61
69
  - - ">="
62
70
  - !ruby/object:Gem::Version
71
+ hash: 3
63
72
  segments:
64
73
  - 0
65
74
  version: "0"
@@ -69,9 +78,11 @@ dependencies:
69
78
  name: aws-s3
70
79
  prerelease: false
71
80
  requirement: &id005 !ruby/object:Gem::Requirement
81
+ none: false
72
82
  requirements:
73
83
  - - ">="
74
84
  - !ruby/object:Gem::Version
85
+ hash: 3
75
86
  segments:
76
87
  - 0
77
88
  version: "0"
@@ -81,9 +92,11 @@ dependencies:
81
92
  name: sqlite3-ruby
82
93
  prerelease: false
83
94
  requirement: &id006 !ruby/object:Gem::Requirement
95
+ none: false
84
96
  requirements:
85
97
  - - ">="
86
98
  - !ruby/object:Gem::Version
99
+ hash: 3
87
100
  segments:
88
101
  - 0
89
102
  version: "0"
@@ -107,6 +120,7 @@ files:
107
120
  - lib/generators/paperclip/USAGE
108
121
  - lib/paperclip/attachment.rb
109
122
  - lib/paperclip/callback_compatability.rb
123
+ - lib/paperclip/command_line.rb
110
124
  - lib/paperclip/geometry.rb
111
125
  - lib/paperclip/interpolations.rb
112
126
  - lib/paperclip/iostream.rb
@@ -117,6 +131,8 @@ files:
117
131
  - lib/paperclip/matchers.rb
118
132
  - lib/paperclip/processor.rb
119
133
  - lib/paperclip/railtie.rb
134
+ - lib/paperclip/storage/filesystem.rb
135
+ - lib/paperclip/storage/s3.rb
120
136
  - lib/paperclip/storage.rb
121
137
  - lib/paperclip/style.rb
122
138
  - lib/paperclip/thumbnail.rb
@@ -125,6 +141,7 @@ files:
125
141
  - lib/paperclip.rb
126
142
  - lib/tasks/paperclip.rake
127
143
  - test/attachment_test.rb
144
+ - test/command_line_test.rb
128
145
  - test/database.yml
129
146
  - test/fixtures/12k.png
130
147
  - test/fixtures/50x50.png
@@ -164,23 +181,27 @@ rdoc_options:
164
181
  require_paths:
165
182
  - lib
166
183
  required_ruby_version: !ruby/object:Gem::Requirement
184
+ none: false
167
185
  requirements:
168
186
  - - ">="
169
187
  - !ruby/object:Gem::Version
188
+ hash: 3
170
189
  segments:
171
190
  - 0
172
191
  version: "0"
173
192
  required_rubygems_version: !ruby/object:Gem::Requirement
193
+ none: false
174
194
  requirements:
175
195
  - - ">="
176
196
  - !ruby/object:Gem::Version
197
+ hash: 3
177
198
  segments:
178
199
  - 0
179
200
  version: "0"
180
201
  requirements:
181
202
  - ImageMagick
182
203
  rubyforge_project: paperclip
183
- rubygems_version: 1.3.6
204
+ rubygems_version: 1.3.7
184
205
  signing_key:
185
206
  specification_version: 3
186
207
  summary: File attachments as attributes for ActiveRecord