dm-paperclip-r3 2.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,324 @@
1
+ require 'test/helper'
2
+ require 'aws/s3'
3
+
4
+ class StorageTest < Test::Unit::TestCase
5
+ context "Parsing S3 credentials" do
6
+ setup do
7
+ AWS::S3::Base.stubs(:establish_connection!)
8
+ rebuild_model :storage => :s3,
9
+ :bucket => "testing",
10
+ :s3_credentials => {:not => :important}
11
+
12
+ @dummy = Dummy.new
13
+ @avatar = @dummy.avatar
14
+
15
+ @current_env = Merb.env
16
+ end
17
+
18
+ teardown do
19
+ Merb.env(@current_env)
20
+ end
21
+
22
+ should "get the correct credentials when environment is production" do
23
+ Merb.env("production")
24
+ assert_equal({:key => "12345"},
25
+ @avatar.parse_credentials('production' => {:key => '12345'},
26
+ :development => {:key => "54321"}))
27
+ end
28
+
29
+ should "get the correct credentials when environment is development" do
30
+ Merb.env("development")
31
+ assert_equal({:key => "54321"},
32
+ @avatar.parse_credentials('production' => {:key => '12345'},
33
+ :development => {:key => "54321"}))
34
+ end
35
+
36
+ should "return the argument if the key does not exist" do
37
+ Merb.env("not really an env")
38
+ assert_equal({:test => "12345"}, @avatar.parse_credentials(:test => "12345"))
39
+ end
40
+ end
41
+
42
+ context "" do
43
+ setup do
44
+ AWS::S3::Base.stubs(:establish_connection!)
45
+ rebuild_model :storage => :s3,
46
+ :s3_credentials => {},
47
+ :bucket => "bucket",
48
+ :path => ":attachment/:basename.:extension",
49
+ :url => ":s3_path_url"
50
+ @dummy = Dummy.new
51
+ @dummy.avatar = StringIO.new(".")
52
+ end
53
+
54
+ should "return a url based on an S3 path" do
55
+ assert_match %r{^http://s3.amazonaws.com/bucket/avatars/stringio.txt}, @dummy.avatar.url
56
+ end
57
+ end
58
+ context "" do
59
+ setup do
60
+ AWS::S3::Base.stubs(:establish_connection!)
61
+ rebuild_model :storage => :s3,
62
+ :s3_credentials => {},
63
+ :bucket => "bucket",
64
+ :path => ":attachment/:basename.:extension",
65
+ :url => ":s3_domain_url"
66
+ @dummy = Dummy.new
67
+ @dummy.avatar = StringIO.new(".")
68
+ end
69
+
70
+ should "return a url based on an S3 subdomain" do
71
+ assert_match %r{^http://bucket.s3.amazonaws.com/avatars/stringio.txt}, @dummy.avatar.url
72
+ end
73
+ end
74
+ context "" do
75
+ setup do
76
+ AWS::S3::Base.stubs(:establish_connection!)
77
+ rebuild_model :storage => :s3,
78
+ :s3_credentials => {
79
+ :production => { :bucket => "prod_bucket" },
80
+ :development => { :bucket => "dev_bucket" }
81
+ },
82
+ :s3_host_alias => "something.something.com",
83
+ :path => ":attachment/:basename.:extension",
84
+ :url => ":s3_alias_url"
85
+ @dummy = Dummy.new
86
+ @dummy.avatar = StringIO.new(".")
87
+ end
88
+
89
+ should "return a url based on the host_alias" do
90
+ assert_match %r{^http://something.something.com/avatars/stringio.txt}, @dummy.avatar.url
91
+ end
92
+ end
93
+
94
+ context "Generating a url with an expiration" do
95
+ setup do
96
+ AWS::S3::Base.stubs(:establish_connection!)
97
+ rebuild_model :storage => :s3,
98
+ :s3_credentials => {
99
+ :production => { :bucket => "prod_bucket" },
100
+ :development => { :bucket => "dev_bucket" }
101
+ },
102
+ :s3_host_alias => "something.something.com",
103
+ :path => ":attachment/:basename.:extension",
104
+ :url => ":s3_alias_url"
105
+
106
+ Merb.env("production")
107
+
108
+ @dummy = Dummy.new
109
+ @dummy.avatar = StringIO.new(".")
110
+
111
+ AWS::S3::S3Object.expects(:url_for).with("avatars/stringio.txt", "prod_bucket", { :expires_in => 3600 })
112
+
113
+ @dummy.avatar.expiring_url
114
+ end
115
+
116
+ should "should succeed" do
117
+ assert true
118
+ end
119
+ end
120
+
121
+ context "Parsing S3 credentials with a bucket in them" do
122
+ setup do
123
+ AWS::S3::Base.stubs(:establish_connection!)
124
+ rebuild_model :storage => :s3,
125
+ :s3_credentials => {
126
+ :production => { :bucket => "prod_bucket" },
127
+ :development => { :bucket => "dev_bucket" }
128
+ }
129
+ @dummy = Dummy.new
130
+ @old_env = Merb.env
131
+ end
132
+
133
+ teardown{ Merb.env(@old_env) }
134
+
135
+ should "get the right bucket in production" do
136
+ Merb.env("production")
137
+ assert_equal "prod_bucket", @dummy.avatar.bucket_name
138
+ end
139
+
140
+ should "get the right bucket in development" do
141
+ Merb.env("development")
142
+ assert_equal "dev_bucket", @dummy.avatar.bucket_name
143
+ end
144
+ end
145
+
146
+ context "An attachment with S3 storage" do
147
+ setup do
148
+ rebuild_model :storage => :s3,
149
+ :bucket => "testing",
150
+ :path => ":attachment/:style/:basename.:extension",
151
+ :s3_credentials => {
152
+ 'access_key_id' => "12345",
153
+ 'secret_access_key' => "54321"
154
+ }
155
+ end
156
+
157
+ should "be extended by the S3 module" do
158
+ assert Dummy.new.avatar.is_a?(Paperclip::Storage::S3)
159
+ end
160
+
161
+ should "not be extended by the Filesystem module" do
162
+ assert ! Dummy.new.avatar.is_a?(Paperclip::Storage::Filesystem)
163
+ end
164
+
165
+ context "when assigned" do
166
+ setup do
167
+ @file = File.new(File.join(File.dirname(__FILE__), 'fixtures', '5k.png'), 'rb')
168
+ @dummy = Dummy.new
169
+ @dummy.avatar = @file
170
+ end
171
+
172
+ teardown { @file.close }
173
+
174
+ should "not get a bucket to get a URL" do
175
+ @dummy.avatar.expects(:s3).never
176
+ @dummy.avatar.expects(:s3_bucket).never
177
+ assert_match %r{^http://s3\.amazonaws\.com/testing/avatars/original/5k\.png}, @dummy.avatar.url
178
+ end
179
+
180
+ context "and saved" do
181
+ setup do
182
+ AWS::S3::S3Object.stubs(:store).with(@dummy.avatar.path, anything, 'testing', :content_type => 'image/png', :access => :public_read)
183
+ @dummy.save
184
+ end
185
+
186
+ should "succeed" do
187
+ assert true
188
+ end
189
+ end
190
+
191
+ context "and remove" do
192
+ setup do
193
+ AWS::S3::S3Object.stubs(:exists?).returns(true)
194
+ AWS::S3::S3Object.stubs(:delete)
195
+ @dummy.destroy_attached_files
196
+ end
197
+
198
+ should "succeed" do
199
+ assert true
200
+ end
201
+ end
202
+ end
203
+ end
204
+
205
+ context "An attachment with S3 storage and bucket defined as a Proc" do
206
+ setup do
207
+ AWS::S3::Base.stubs(:establish_connection!)
208
+ rebuild_model :storage => :s3,
209
+ :bucket => lambda { |attachment| "bucket_#{attachment.instance.other}" },
210
+ :s3_credentials => {:not => :important}
211
+ end
212
+
213
+ should "get the right bucket name" do
214
+ assert "bucket_a", Dummy.new(:other => 'a').avatar.bucket_name
215
+ assert "bucket_b", Dummy.new(:other => 'b').avatar.bucket_name
216
+ end
217
+ end
218
+
219
+ context "An attachment with S3 storage and specific s3 headers set" do
220
+ setup do
221
+ AWS::S3::Base.stubs(:establish_connection!)
222
+ rebuild_model :storage => :s3,
223
+ :bucket => "testing",
224
+ :path => ":attachment/:style/:basename.:extension",
225
+ :s3_credentials => {
226
+ 'access_key_id' => "12345",
227
+ 'secret_access_key' => "54321"
228
+ },
229
+ :s3_headers => {'Cache-Control' => 'max-age=31557600'}
230
+ end
231
+
232
+ context "when assigned" do
233
+ setup do
234
+ @file = File.new(File.join(File.dirname(__FILE__), 'fixtures', '5k.png'), 'rb')
235
+ @dummy = Dummy.new
236
+ @dummy.avatar = @file
237
+ end
238
+
239
+ teardown { @file.close }
240
+
241
+ context "and saved" do
242
+ setup do
243
+ AWS::S3::Base.stubs(:establish_connection!)
244
+ AWS::S3::S3Object.stubs(:store).with(@dummy.avatar.path,
245
+ anything,
246
+ 'testing',
247
+ :content_type => 'image/png',
248
+ :access => :public_read,
249
+ 'Cache-Control' => 'max-age=31557600')
250
+ @dummy.save
251
+ end
252
+
253
+ should "succeed" do
254
+ assert true
255
+ end
256
+ end
257
+ end
258
+ end
259
+
260
+ context "with S3 credentials in a YAML file" do
261
+ setup do
262
+ ENV['S3_KEY'] = 'env_key'
263
+ ENV['S3_BUCKET'] = 'env_bucket'
264
+ ENV['S3_SECRET'] = 'env_secret'
265
+
266
+ Merb.env('test')
267
+
268
+ rebuild_model :storage => :s3,
269
+ :s3_credentials => File.new(File.join(File.dirname(__FILE__), "fixtures/s3.yml"))
270
+
271
+ Dummy.auto_migrate!
272
+
273
+ @dummy = Dummy.new
274
+ end
275
+
276
+ should "run it the file through ERB" do
277
+ assert_equal 'env_bucket', @dummy.avatar.bucket_name
278
+ assert_equal 'env_key', AWS::S3::Base.connection.options[:access_key_id]
279
+ assert_equal 'env_secret', AWS::S3::Base.connection.options[:secret_access_key]
280
+ end
281
+ end
282
+
283
+ unless ENV["S3_TEST_BUCKET"].blank?
284
+ context "Using S3 for real, an attachment with S3 storage" do
285
+ setup do
286
+ rebuild_model :styles => { :thumb => "100x100", :square => "32x32#" },
287
+ :storage => :s3,
288
+ :bucket => ENV["S3_TEST_BUCKET"],
289
+ :path => ":class/:attachment/:id/:style.:extension",
290
+ :s3_credentials => File.new(File.join(File.dirname(__FILE__), "s3.yml"))
291
+
292
+ Dummy.auto_migrate!
293
+ @dummy = Dummy.new
294
+ end
295
+
296
+ should "be extended by the S3 module" do
297
+ assert Dummy.new.avatar.is_a?(Paperclip::Storage::S3)
298
+ end
299
+
300
+ context "when assigned" do
301
+ setup do
302
+ @file = File.new(File.join(File.dirname(__FILE__), 'fixtures', '5k.png'), 'rb')
303
+ @dummy.avatar = @file
304
+ end
305
+
306
+ teardown { @file.close }
307
+
308
+ should "still return a Tempfile when sent #to_file" do
309
+ assert_equal Tempfile, @dummy.avatar.to_file.class
310
+ end
311
+
312
+ context "and saved" do
313
+ setup do
314
+ @dummy.save
315
+ end
316
+
317
+ should "be on S3" do
318
+ assert true
319
+ end
320
+ end
321
+ end
322
+ end
323
+ end
324
+ end
@@ -0,0 +1,147 @@
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', 'dm-paperclip', 'geometry.rb')
8
+ require File.join(File.dirname(__FILE__), '..', 'lib', 'dm-paperclip', 'thumbnail.rb')
9
+
10
+ class ThumbnailTest < Test::Unit::TestCase
11
+
12
+ context "A Paperclip Tempfile" do
13
+ setup do
14
+ @tempfile = Paperclip::Tempfile.new("file.jpg")
15
+ end
16
+
17
+ should "have its path contain a real extension" do
18
+ assert_equal ".jpg", File.extname(@tempfile.path)
19
+ end
20
+
21
+ should "be a real Tempfile" do
22
+ assert @tempfile.is_a?(::Tempfile)
23
+ end
24
+ end
25
+
26
+ context "Another Paperclip Tempfile" do
27
+ setup do
28
+ @tempfile = Paperclip::Tempfile.new("file")
29
+ end
30
+
31
+ should "not have an extension if not given one" do
32
+ assert_equal "", File.extname(@tempfile.path)
33
+ end
34
+
35
+ should "still be a real Tempfile" do
36
+ assert @tempfile.is_a?(::Tempfile)
37
+ end
38
+ end
39
+
40
+ context "An image" do
41
+ setup do
42
+ @file = File.new(File.join(File.dirname(__FILE__), "fixtures", "5k.png"))
43
+ end
44
+
45
+ [["600x600>", "434x66"],
46
+ ["400x400>", "400x61"],
47
+ ["32x32<", "434x66"]
48
+ ].each do |args|
49
+ context "being thumbnailed with a geometry of #{args[0]}" do
50
+ setup do
51
+ @thumb = Paperclip::Thumbnail.new(@file, :geometry => args[0])
52
+ end
53
+
54
+ should "start with dimensions of 434x66" do
55
+ cmd = %Q[identify -format "%wx%h" #{@file.path}]
56
+ assert_equal "434x66", `#{cmd}`.chomp
57
+ end
58
+
59
+ should "report the correct target geometry" do
60
+ assert_equal args[0], @thumb.target_geometry.to_s
61
+ end
62
+
63
+ context "when made" do
64
+ setup do
65
+ @thumb_result = @thumb.make
66
+ end
67
+
68
+ should "be the size we expect it to be" do
69
+ cmd = %Q[identify -format "%wx%h" #{@thumb_result.path}]
70
+ assert_equal args[1], `#{cmd}`.chomp
71
+ end
72
+ end
73
+ end
74
+ end
75
+
76
+ context "being thumbnailed at 100x50 with cropping" do
77
+ setup do
78
+ @thumb = Paperclip::Thumbnail.new(@file, :geometry => "100x50#")
79
+ end
80
+
81
+ should "report its correct current and target geometries" do
82
+ assert_equal "100x50#", @thumb.target_geometry.to_s
83
+ assert_equal "434x66", @thumb.current_geometry.to_s
84
+ end
85
+
86
+ should "report its correct format" do
87
+ assert_nil @thumb.format
88
+ end
89
+
90
+ should "have whiny_thumbnails turned on by default" do
91
+ assert @thumb.whiny
92
+ end
93
+
94
+ should "have convert_options set to nil by default" do
95
+ assert_equal nil, @thumb.convert_options
96
+ end
97
+
98
+ should "send the right command to convert when sent #make" do
99
+ Paperclip.expects(:run).with do |cmd, arg|
100
+ cmd.match 'convert'
101
+ arg.match %r{"#{File.expand_path(@thumb.file.path)}\[0\]"\s+-resize\s+\"x50\"\s+-crop\s+\"100x50\+114\+0\"\s+\+repage\s+".*?"}
102
+ end
103
+ @thumb.make
104
+ end
105
+
106
+ should "create the thumbnail when sent #make" do
107
+ dst = @thumb.make
108
+ assert_match /100x50/, `identify #{dst.path}`
109
+ end
110
+ end
111
+
112
+ context "being thumbnailed with convert options set" do
113
+ setup do
114
+ @thumb = Paperclip::Thumbnail.new(@file, :geometry => "100x50#", :format => (format = nil), :convert_options => (convert_options="-strip -depth 8"), :whiny => (whiny_thumbnails=true))
115
+ end
116
+
117
+ should "have convert_options value set" do
118
+ assert_equal "-strip -depth 8", @thumb.convert_options
119
+ end
120
+
121
+ should "send the right command to convert when sent #make" do
122
+ Paperclip.expects(:run).with do |cmd, arg|
123
+ cmd.match 'convert'
124
+ arg.match %r{"#{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+".*?"}
125
+ end
126
+ @thumb.make
127
+ end
128
+
129
+ should "create the thumbnail when sent #make" do
130
+ dst = @thumb.make
131
+ assert_match /100x50/, `identify #{dst.path}`
132
+ end
133
+
134
+ context "redefined to have bad convert_options setting" do
135
+ setup do
136
+ @thumb = Paperclip::Thumbnail.new(@file, :geometry => "100x50#", :format => nil, :convert_options => "-this-aint-no-option", :whiny => true)
137
+ end
138
+
139
+ should "error when trying to create the thumbnail" do
140
+ assert_raises(Paperclip::PaperclipError) do
141
+ @thumb.make
142
+ end
143
+ end
144
+ end
145
+ end
146
+ end
147
+ end
metadata ADDED
@@ -0,0 +1,181 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dm-paperclip-r3
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease: false
6
+ segments:
7
+ - 2
8
+ - 4
9
+ - 1
10
+ version: 2.4.1
11
+ platform: ruby
12
+ authors:
13
+ - Joel Reed
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-04-21 00:00:00 -04:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: extlib
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 3
30
+ segments:
31
+ - 0
32
+ version: "0"
33
+ type: :runtime
34
+ version_requirements: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ name: datamapper
37
+ prerelease: false
38
+ requirement: &id002 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ hash: 3
44
+ segments:
45
+ - 0
46
+ version: "0"
47
+ type: :runtime
48
+ version_requirements: *id002
49
+ - !ruby/object:Gem::Dependency
50
+ name: shoulda
51
+ prerelease: false
52
+ requirement: &id003 !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ hash: 3
58
+ segments:
59
+ - 0
60
+ version: "0"
61
+ type: :development
62
+ version_requirements: *id003
63
+ - !ruby/object:Gem::Dependency
64
+ name: mocha
65
+ prerelease: false
66
+ requirement: &id004 !ruby/object:Gem::Requirement
67
+ none: false
68
+ requirements:
69
+ - - "="
70
+ - !ruby/object:Gem::Version
71
+ hash: 43
72
+ segments:
73
+ - 0
74
+ - 9
75
+ - 8
76
+ version: 0.9.8
77
+ type: :development
78
+ version_requirements: *id004
79
+ - !ruby/object:Gem::Dependency
80
+ name: aws-s3
81
+ prerelease: false
82
+ requirement: &id005 !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ hash: 3
88
+ segments:
89
+ - 0
90
+ version: "0"
91
+ type: :development
92
+ version_requirements: *id005
93
+ - !ruby/object:Gem::Dependency
94
+ name: do_sqlite3
95
+ prerelease: false
96
+ requirement: &id006 !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ">="
100
+ - !ruby/object:Gem::Version
101
+ hash: 3
102
+ segments:
103
+ - 0
104
+ version: "0"
105
+ type: :development
106
+ version_requirements: *id006
107
+ description:
108
+ email: joelwreed@gmail.com
109
+ executables: []
110
+
111
+ extensions: []
112
+
113
+ extra_rdoc_files:
114
+ - README.rdoc
115
+ files:
116
+ - README.rdoc
117
+ - LICENSE
118
+ - Rakefile
119
+ - init.rb
120
+ - lib/dm-paperclip/attachment.rb
121
+ - lib/dm-paperclip/callback_compatability.rb
122
+ - lib/dm-paperclip/geometry.rb
123
+ - lib/dm-paperclip/interpolations.rb
124
+ - lib/dm-paperclip/iostream.rb
125
+ - lib/dm-paperclip/processor.rb
126
+ - lib/dm-paperclip/storage.rb
127
+ - lib/dm-paperclip/thumbnail.rb
128
+ - lib/dm-paperclip/upfile.rb
129
+ - lib/dm-paperclip/validations.rb
130
+ - lib/dm-paperclip.rb
131
+ - tasks/paperclip_tasks.rake
132
+ - test/attachment_test.rb
133
+ - test/fixtures/12k.png
134
+ - test/fixtures/50x50.png
135
+ - test/fixtures/5k.png
136
+ - test/fixtures/bad.png
137
+ - test/fixtures/text.txt
138
+ - test/geometry_test.rb
139
+ - test/helper.rb
140
+ - test/integration_test.rb
141
+ - test/iostream_test.rb
142
+ - test/paperclip_test.rb
143
+ - test/storage_test.rb
144
+ - test/thumbnail_test.rb
145
+ has_rdoc: true
146
+ homepage: http://github.com/joelwreed/dm-paperclip
147
+ licenses: []
148
+
149
+ post_install_message:
150
+ rdoc_options:
151
+ - --line-numbers
152
+ - --inline-source
153
+ require_paths:
154
+ - lib
155
+ required_ruby_version: !ruby/object:Gem::Requirement
156
+ none: false
157
+ requirements:
158
+ - - ">="
159
+ - !ruby/object:Gem::Version
160
+ hash: 3
161
+ segments:
162
+ - 0
163
+ version: "0"
164
+ required_rubygems_version: !ruby/object:Gem::Requirement
165
+ none: false
166
+ requirements:
167
+ - - ">="
168
+ - !ruby/object:Gem::Version
169
+ hash: 3
170
+ segments:
171
+ - 0
172
+ version: "0"
173
+ requirements:
174
+ - ImageMagick
175
+ rubyforge_project:
176
+ rubygems_version: 1.3.7
177
+ signing_key:
178
+ specification_version: 3
179
+ summary: Ken Robertson's dm-paperclip with patches for rails > 3.0.0
180
+ test_files: []
181
+