paperclip 2.1.2 → 2.1.5

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.

@@ -0,0 +1,186 @@
1
+ require 'test/helper'
2
+
3
+ class PaperclipTest < Test::Unit::TestCase
4
+ context "Calling Paperclip.run" do
5
+ should "execute the right command" do
6
+ Paperclip.expects(:path_for_command).with("convert").returns("/usr/bin/convert")
7
+ Paperclip.expects(:bit_bucket).returns("/dev/null")
8
+ Paperclip.expects(:"`").with("/usr/bin/convert one.jpg two.jpg 2>/dev/null")
9
+ Paperclip.run("convert", "one.jpg two.jpg")
10
+ end
11
+ end
12
+
13
+ context "Paperclip.bit_bucket" do
14
+ context "on systems without /dev/null" do
15
+ setup do
16
+ File.expects(:exists?).with("/dev/null").returns(false)
17
+ end
18
+
19
+ should "return 'NUL'" do
20
+ assert_equal "NUL", Paperclip.bit_bucket
21
+ end
22
+ end
23
+
24
+ context "on systems with /dev/null" do
25
+ setup do
26
+ File.expects(:exists?).with("/dev/null").returns(true)
27
+ end
28
+
29
+ should "return '/dev/null'" do
30
+ assert_equal "/dev/null", Paperclip.bit_bucket
31
+ end
32
+ end
33
+ end
34
+
35
+ context "An ActiveRecord model with an 'avatar' attachment" do
36
+ setup do
37
+ rebuild_model :path => "tmp/:class/omg/:style.:extension"
38
+ @file = File.new(File.join(FIXTURES_DIR, "5k.png"), 'rb')
39
+ end
40
+
41
+ should "not error when trying to also create a 'blah' attachment" do
42
+ assert_nothing_raised do
43
+ Dummy.class_eval do
44
+ has_attached_file :blah
45
+ end
46
+ end
47
+ end
48
+
49
+ context "that is attr_protected" do
50
+ setup do
51
+ Dummy.class_eval do
52
+ attr_protected :avatar
53
+ end
54
+ @dummy = Dummy.new
55
+ end
56
+
57
+ should "not assign the avatar on mass-set" do
58
+ @dummy.logger.expects(:debug)
59
+
60
+ @dummy.attributes = { :other => "I'm set!",
61
+ :avatar => @file }
62
+
63
+ assert_equal "I'm set!", @dummy.other
64
+ assert ! @dummy.avatar?
65
+ end
66
+
67
+ should "still allow assigment on normal set" do
68
+ @dummy.logger.expects(:debug).times(0)
69
+
70
+ @dummy.other = "I'm set!"
71
+ @dummy.avatar = @file
72
+
73
+ assert_equal "I'm set!", @dummy.other
74
+ assert @dummy.avatar?
75
+ end
76
+ end
77
+
78
+ context "with a subclass" do
79
+ setup do
80
+ class ::SubDummy < Dummy; end
81
+ end
82
+
83
+ should "be able to use the attachment from the subclass" do
84
+ assert_nothing_raised do
85
+ @subdummy = SubDummy.create(:avatar => @file)
86
+ end
87
+ end
88
+
89
+ should "be able to see the attachment definition from the subclass's class" do
90
+ assert_equal "tmp/:class/omg/:style.:extension", SubDummy.attachment_definitions[:avatar][:path]
91
+ end
92
+
93
+ teardown do
94
+ Object.send(:remove_const, "SubDummy") rescue nil
95
+ end
96
+ end
97
+
98
+ should "have an #avatar method" do
99
+ assert Dummy.new.respond_to?(:avatar)
100
+ end
101
+
102
+ should "have an #avatar= method" do
103
+ assert Dummy.new.respond_to?(:avatar=)
104
+ end
105
+
106
+ context "that is valid" do
107
+ setup do
108
+ @dummy = Dummy.new
109
+ @dummy.avatar = @file
110
+ end
111
+
112
+ should "be valid" do
113
+ assert @dummy.valid?
114
+ end
115
+
116
+ context "then has a validation added that makes it invalid" do
117
+ setup do
118
+ assert @dummy.save
119
+ Dummy.class_eval do
120
+ validates_attachment_content_type :avatar, :content_type => ["text/plain"]
121
+ end
122
+ @dummy2 = Dummy.find(@dummy.id)
123
+ end
124
+
125
+ should "be invalid when reloaded" do
126
+ assert ! @dummy2.valid?, @dummy2.errors.inspect
127
+ end
128
+
129
+ should "be able to call #valid? twice without having duplicate errors" do
130
+ @dummy2.avatar.valid?
131
+ first_errors = @dummy2.avatar.errors
132
+ @dummy2.avatar.valid?
133
+ assert_equal first_errors, @dummy2.avatar.errors
134
+ end
135
+ end
136
+ end
137
+
138
+ def self.should_validate validation, options, valid_file, invalid_file
139
+ context "with #{validation} validation and #{options.inspect} options" do
140
+ setup do
141
+ Dummy.send(:"validates_attachment_#{validation}", :avatar, options)
142
+ @dummy = Dummy.new
143
+ end
144
+ context "and assigned a valid file" do
145
+ setup do
146
+ @dummy.avatar = valid_file
147
+ @dummy.valid?
148
+ end
149
+ should "not have an error when assigned a valid file" do
150
+ assert ! @dummy.avatar.errors.key?(validation)
151
+ end
152
+ should "not have an error on the attachment" do
153
+ assert_nil @dummy.errors.on(:avatar)
154
+ end
155
+ end
156
+ context "and assigned an invalid file" do
157
+ setup do
158
+ @dummy.avatar = invalid_file
159
+ @dummy.valid?
160
+ end
161
+ should "have an error when assigned a valid file" do
162
+ assert_not_nil @dummy.avatar.errors[validation]
163
+ end
164
+ should "have an error on the attachment" do
165
+ assert @dummy.errors.on(:avatar)
166
+ end
167
+ end
168
+ end
169
+ end
170
+
171
+ [[:presence, {}, "5k.png", nil],
172
+ [:size, {:in => 1..10240}, nil, "12k.png"],
173
+ [:size, {:less_than => 10240}, "5k.png", "12k.png"],
174
+ [:size, {:greater_than => 8096}, "12k.png", "5k.png"],
175
+ [:content_type, {:content_type => "image/png"}, "5k.png", "text.txt"],
176
+ [:content_type, {:content_type => "text/plain"}, "text.txt", "5k.png"],
177
+ [:content_type, {:content_type => %r{image/.*}}, "5k.png", "text.txt"]].each do |args|
178
+ validation, options, valid_file, invalid_file = args
179
+ valid_file &&= File.open(File.join(FIXTURES_DIR, valid_file), "rb")
180
+ invalid_file &&= File.open(File.join(FIXTURES_DIR, invalid_file), "rb")
181
+
182
+ should_validate validation, options, valid_file, invalid_file
183
+ end
184
+
185
+ end
186
+ end
data/test/s3.yml CHANGED
@@ -1,2 +0,0 @@
1
- access_key_id: 11196XQ35WGRKEVQN782
2
- secret_access_key: TczVRadcH5sealaWUMpbY/Hnex90iCmJ3LDM5w74
@@ -1,9 +1,4 @@
1
- require 'rubygems'
2
- require 'test/unit'
3
- require 'shoulda'
4
- require 'right_aws'
5
-
6
- require File.join(File.dirname(__FILE__), '..', 'lib', 'paperclip', 'geometry.rb')
1
+ require 'test/helper'
7
2
 
8
3
  class StorageTest < Test::Unit::TestCase
9
4
  context "Parsing S3 credentials" do
@@ -42,6 +37,25 @@ class StorageTest < Test::Unit::TestCase
42
37
  end
43
38
  end
44
39
 
40
+ context "Parsing S3 credentials with a bucket in them" do
41
+ setup do
42
+ rebuild_model :storage => :s3,
43
+ :s3_credentials => {
44
+ :production => { :bucket => "prod_bucket" },
45
+ :development => { :bucket => "dev_bucket" }
46
+ }
47
+ @dummy = Dummy.new
48
+ end
49
+
50
+ should "get the right bucket in production", :before => lambda{ ENV.expects(:[]).returns('production') } do
51
+ assert_equal "prod_bucket", @dummy.avatar.bucket_name
52
+ end
53
+
54
+ should "get the right bucket in development", :before => lambda{ ENV.expects(:[]).returns('development') } do
55
+ assert_equal "dev_bucket", @dummy.avatar.bucket_name
56
+ end
57
+ end
58
+
45
59
  context "An attachment with S3 storage" do
46
60
  setup do
47
61
  rebuild_model :storage => :s3,
@@ -63,7 +77,7 @@ class StorageTest < Test::Unit::TestCase
63
77
 
64
78
  context "when assigned" do
65
79
  setup do
66
- @file = File.new(File.join(File.dirname(__FILE__), 'fixtures', '5k.png'))
80
+ @file = File.new(File.join(File.dirname(__FILE__), 'fixtures', '5k.png'), 'rb')
67
81
  @dummy = Dummy.new
68
82
  @dummy.avatar = @file
69
83
  end
@@ -71,7 +85,7 @@ class StorageTest < Test::Unit::TestCase
71
85
  should "not get a bucket to get a URL" do
72
86
  @dummy.avatar.expects(:s3).never
73
87
  @dummy.avatar.expects(:s3_bucket).never
74
- assert_equal "https://s3.amazonaws.com/testing/avatars/original/5k.png", @dummy.avatar.url
88
+ assert_match %r{^http://s3\.amazonaws\.com/testing/avatars/original/5k\.png}, @dummy.avatar.url
75
89
  end
76
90
 
77
91
  context "and saved" do
@@ -83,7 +97,7 @@ class StorageTest < Test::Unit::TestCase
83
97
  @key_mock = stub
84
98
  @bucket_mock.expects(:key).returns(@key_mock)
85
99
  @key_mock.expects(:data=)
86
- @key_mock.expects(:put)
100
+ @key_mock.expects(:put).with(nil, 'public-read', 'Content-type' => 'image/png')
87
101
  @dummy.save
88
102
  end
89
103
 
@@ -91,6 +105,23 @@ class StorageTest < Test::Unit::TestCase
91
105
  assert true
92
106
  end
93
107
  end
108
+
109
+ context "and remove" do
110
+ setup do
111
+ @s3_mock = stub
112
+ @bucket_mock = stub
113
+ RightAws::S3.expects(:new).with("12345", "54321", {}).returns(@s3_mock)
114
+ @s3_mock.expects(:bucket).with("testing", true, "public-read").returns(@bucket_mock)
115
+ @key_mock = stub
116
+ @bucket_mock.expects(:key).at_least(2).returns(@key_mock)
117
+ @key_mock.expects(:delete)
118
+ @dummy.destroy_attached_files
119
+ end
120
+
121
+ should "succeed" do
122
+ assert true
123
+ end
124
+ end
94
125
  end
95
126
  end
96
127
 
@@ -113,7 +144,7 @@ class StorageTest < Test::Unit::TestCase
113
144
 
114
145
  context "when assigned" do
115
146
  setup do
116
- @file = File.new(File.join(File.dirname(__FILE__), 'fixtures', '5k.png'))
147
+ @file = File.new(File.join(File.dirname(__FILE__), 'fixtures', '5k.png'), 'rb')
117
148
  @dummy.avatar = @file
118
149
  end
119
150
 
@@ -1,11 +1,4 @@
1
- require 'rubygems'
2
- require 'test/unit'
3
- require 'shoulda'
4
- require 'mocha'
5
- require 'tempfile'
6
-
7
- require File.join(File.dirname(__FILE__), '..', 'lib', 'paperclip', 'geometry.rb')
8
- require File.join(File.dirname(__FILE__), '..', 'lib', 'paperclip', 'thumbnail.rb')
1
+ require 'test/helper'
9
2
 
10
3
  class ThumbnailTest < Test::Unit::TestCase
11
4
 
@@ -39,7 +32,7 @@ class ThumbnailTest < Test::Unit::TestCase
39
32
 
40
33
  context "An image" do
41
34
  setup do
42
- @file = File.new(File.join(File.dirname(__FILE__), "fixtures", "5k.png"))
35
+ @file = File.new(File.join(File.dirname(__FILE__), "fixtures", "5k.png"), 'rb')
43
36
  end
44
37
 
45
38
  [["600x600>", "434x66"],
@@ -52,7 +45,7 @@ class ThumbnailTest < Test::Unit::TestCase
52
45
  end
53
46
 
54
47
  should "start with dimensions of 434x66" do
55
- cmd = %Q[identify -format "%wx%h" #{@file.path}]
48
+ cmd = %Q[identify -format "%wx%h" "#{@file.path}"]
56
49
  assert_equal "434x66", `#{cmd}`.chomp
57
50
  end
58
51
 
@@ -66,7 +59,7 @@ class ThumbnailTest < Test::Unit::TestCase
66
59
  end
67
60
 
68
61
  should "be the size we expect it to be" do
69
- cmd = %Q[identify -format "%wx%h" #{@thumb_result.path}]
62
+ cmd = %Q[identify -format "%wx%h" "#{@thumb_result.path}"]
70
63
  assert_equal args[1], `#{cmd}`.chomp
71
64
  end
72
65
  end
@@ -90,18 +83,56 @@ class ThumbnailTest < Test::Unit::TestCase
90
83
  should "have whiny_thumbnails turned on by default" do
91
84
  assert @thumb.whiny_thumbnails
92
85
  end
86
+
87
+ should "have convert_options set to nil by default" do
88
+ assert_equal nil, @thumb.convert_options
89
+ end
93
90
 
94
91
  should "send the right command to convert when sent #make" do
95
- @thumb.expects(:system).with do |arg|
96
- arg.match %r{convert\s+"#{File.expand_path(@thumb.file.path)}"\s+-scale\s+\"x50\"\s+-crop\s+\"100x50\+114\+0\"\s+\+repage\s+".*?"}
92
+ Paperclip.expects(:"`").with do |arg|
93
+ arg.match %r{convert\s+"#{File.expand_path(@thumb.file.path)}\[0\]"\s+-resize\s+\"x50\"\s+-crop\s+\"100x50\+114\+0\"\s+\+repage\s+".*?"}
97
94
  end
98
95
  @thumb.make
99
96
  end
100
97
 
101
98
  should "create the thumbnail when sent #make" do
102
99
  dst = @thumb.make
103
- assert_match /100x50/, `identify #{dst.path}`
100
+ assert_match /100x50/, `identify "#{dst.path}"`
101
+ end
102
+ end
103
+
104
+ context "being thumbnailed with convert options set" do
105
+ setup do
106
+ @thumb = Paperclip::Thumbnail.new(@file, "100x50#", format=nil, convert_options="-strip -depth 8", whiny_thumbnails=true)
104
107
  end
108
+
109
+ should "have convert_options value set" do
110
+ assert_equal "-strip -depth 8", @thumb.convert_options
111
+ end
112
+
113
+ should "send the right command to convert when sent #make" do
114
+ Paperclip.expects(:"`").with do |arg|
115
+ arg.match %r{convert\s+"#{File.expand_path(@thumb.file.path)}\[0\]"\s+-resize\s+"x50"\s+-crop\s+"100x50\+114\+0"\s+\+repage\s+-strip\s+-depth\s+8\s+".*?"}
116
+ end
117
+ @thumb.make
118
+ end
119
+
120
+ should "create the thumbnail when sent #make" do
121
+ dst = @thumb.make
122
+ assert_match /100x50/, `identify "#{dst.path}"`
123
+ end
124
+
125
+ context "redefined to have bad convert_options setting" do
126
+ setup do
127
+ @thumb = Paperclip::Thumbnail.new(@file, "100x50#", format=nil, convert_options="-this-aint-no-option", whiny_thumbnails=true)
128
+ end
129
+
130
+ should "error when trying to create the thumbnail" do
131
+ assert_raises(Paperclip::PaperclipError) do
132
+ @thumb.make
133
+ end
134
+ end
135
+ end
105
136
  end
106
137
  end
107
138
  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.1.2
4
+ version: 2.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jon Yurek
@@ -9,10 +9,39 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-05-13 00:00:00 -04:00
12
+ date: 2008-12-10 00:00:00 -05:00
13
13
  default_executable:
14
- dependencies: []
15
-
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: right_aws
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: thoughtbot-shoulda
27
+ type: :runtime
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: "0"
34
+ version:
35
+ - !ruby/object:Gem::Dependency
36
+ name: mocha
37
+ type: :runtime
38
+ version_requirement:
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: "0"
44
+ version:
16
45
  description:
17
46
  email: jyurek@thoughtbot.com
18
47
  executables: []
@@ -20,18 +49,15 @@ executables: []
20
49
  extensions: []
21
50
 
22
51
  extra_rdoc_files:
23
- - README
52
+ - README.rdoc
24
53
  files:
25
- - README
54
+ - README.rdoc
26
55
  - LICENSE
27
56
  - Rakefile
28
57
  - init.rb
29
- - generators/paperclip
30
58
  - generators/paperclip/paperclip_generator.rb
31
- - generators/paperclip/templates
32
- - generators/paperclip/templates/paperclip_migration.rb
59
+ - generators/paperclip/templates/paperclip_migration.rb.erb
33
60
  - generators/paperclip/USAGE
34
- - lib/paperclip
35
61
  - lib/paperclip/attachment.rb
36
62
  - lib/paperclip/geometry.rb
37
63
  - lib/paperclip/iostream.rb
@@ -40,25 +66,27 @@ files:
40
66
  - lib/paperclip/upfile.rb
41
67
  - lib/paperclip.rb
42
68
  - tasks/paperclip_tasks.rake
69
+ - test/attachment_test.rb
43
70
  - test/database.yml
44
71
  - test/debug.log
45
- - test/fixtures
46
72
  - test/fixtures/12k.png
47
73
  - test/fixtures/50x50.png
48
74
  - test/fixtures/5k.png
49
75
  - test/fixtures/bad.png
50
76
  - test/fixtures/text.txt
77
+ - test/geometry_test.rb
51
78
  - test/helper.rb
79
+ - test/integration_test.rb
80
+ - test/iostream_test.rb
81
+ - test/paperclip_test.rb
52
82
  - test/s3.yml
53
- - test/test_attachment.rb
54
- - test/test_geometry.rb
55
- - test/test_integration.rb
56
- - test/test_iostream.rb
57
- - test/test_paperclip.rb
58
- - test/test_storage.rb
59
- - test/test_thumbnail.rb
83
+ - test/storage_test.rb
84
+ - test/thumbnail_test.rb
85
+ - shoulda_macros/paperclip.rb
60
86
  has_rdoc: true
61
- homepage: http://www.thoughtbot.com/
87
+ homepage: http://www.thoughtbot.com/projects/paperclip
88
+ licenses: []
89
+
62
90
  post_install_message:
63
91
  rdoc_options:
64
92
  - --line-numbers
@@ -80,15 +108,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
80
108
  requirements:
81
109
  - ImageMagick
82
110
  rubyforge_project: paperclip
83
- rubygems_version: 1.1.1
111
+ rubygems_version: 1.3.5
84
112
  signing_key:
85
113
  specification_version: 2
86
114
  summary: File attachments as attributes for ActiveRecord
87
- test_files:
88
- - test/test_attachment.rb
89
- - test/test_geometry.rb
90
- - test/test_integration.rb
91
- - test/test_iostream.rb
92
- - test/test_paperclip.rb
93
- - test/test_storage.rb
94
- - test/test_thumbnail.rb
115
+ test_files: []
116
+