paperclip 3.3.1 → 3.4.0
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/.gitignore +2 -1
- data/.travis.yml +2 -0
- data/NEWS +1 -0
- data/README.md +1 -1
- data/lib/generators/paperclip/templates/paperclip_migration.rb.erb +1 -1
- data/lib/paperclip.rb +4 -1
- data/lib/paperclip/attachment.rb +27 -6
- data/lib/paperclip/callbacks.rb +2 -2
- data/lib/paperclip/content_type_detector.rb +1 -12
- data/lib/paperclip/file_command_content_type_detector.rb +32 -0
- data/lib/paperclip/geometry.rb +33 -30
- data/lib/paperclip/geometry_detector_factory.rb +41 -0
- data/lib/paperclip/geometry_parser_factory.rb +31 -0
- data/lib/paperclip/helpers.rb +7 -7
- data/lib/paperclip/io_adapters/uploaded_file_adapter.rb +17 -1
- data/lib/paperclip/io_adapters/uri_adapter.rb +1 -0
- data/lib/paperclip/storage/filesystem.rb +11 -2
- data/lib/paperclip/storage/fog.rb +28 -13
- data/lib/paperclip/storage/s3.rb +39 -18
- data/lib/paperclip/thumbnail.rb +3 -0
- data/lib/paperclip/validators/attachment_content_type_validator.rb +29 -8
- data/lib/paperclip/version.rb +1 -1
- data/paperclip.gemspec +1 -1
- data/test/attachment_processing_test.rb +29 -0
- data/test/attachment_test.rb +97 -11
- data/test/file_command_content_type_detector_test.rb +25 -0
- data/test/generator_test.rb +3 -3
- data/test/geometry_detector_test.rb +24 -0
- data/test/geometry_parser_test.rb +73 -0
- data/test/geometry_test.rb +39 -7
- data/test/helper.rb +5 -1
- data/test/integration_test.rb +46 -1
- data/test/io_adapters/uploaded_file_adapter_test.rb +28 -4
- data/test/io_adapters/uri_adapter_test.rb +4 -0
- data/test/paperclip_test.rb +17 -7
- data/test/storage/fog_test.rb +66 -7
- data/test/storage/s3_test.rb +1 -1
- data/test/style_test.rb +18 -14
- data/test/thumbnail_test.rb +10 -56
- data/test/validators/attachment_content_type_validator_test.rb +155 -55
- metadata +137 -127
@@ -0,0 +1,25 @@
|
|
1
|
+
require './test/helper'
|
2
|
+
|
3
|
+
class FileCommandContentTypeDetectorTest < Test::Unit::TestCase
|
4
|
+
should 'return a content type based on the content of the file' do
|
5
|
+
tempfile = Tempfile.new("something")
|
6
|
+
tempfile.write("This is a file.")
|
7
|
+
tempfile.rewind
|
8
|
+
|
9
|
+
assert_equal "text/plain", Paperclip::FileCommandContentTypeDetector.new(tempfile.path).detect
|
10
|
+
end
|
11
|
+
|
12
|
+
should 'return a sensible default when the file command is missing' do
|
13
|
+
Paperclip.stubs(:run).raises(Cocaine::CommandLineError.new)
|
14
|
+
@filename = "/path/to/something"
|
15
|
+
assert_equal "application/octet-stream",
|
16
|
+
Paperclip::FileCommandContentTypeDetector.new(@filename).detect
|
17
|
+
end
|
18
|
+
|
19
|
+
should 'return a sensible default on the odd chance that run returns nil' do
|
20
|
+
Paperclip.stubs(:run).returns(nil)
|
21
|
+
assert_equal "application/octet-stream",
|
22
|
+
Paperclip::FileCommandContentTypeDetector.new("windows").detect
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
data/test/generator_test.rb
CHANGED
@@ -20,7 +20,7 @@ class GeneratorTest < Rails::Generators::TestCase
|
|
20
20
|
assert_class_method :up, migration do |up|
|
21
21
|
expected = <<-migration
|
22
22
|
change_table :users do |t|
|
23
|
-
t.
|
23
|
+
t.attachment :avatar
|
24
24
|
end
|
25
25
|
migration
|
26
26
|
|
@@ -50,8 +50,8 @@ class GeneratorTest < Rails::Generators::TestCase
|
|
50
50
|
assert_class_method :up, migration do |up|
|
51
51
|
expected = <<-migration
|
52
52
|
change_table :users do |t|
|
53
|
-
t.
|
54
|
-
t.
|
53
|
+
t.attachment :avatar
|
54
|
+
t.attachment :photo
|
55
55
|
end
|
56
56
|
migration
|
57
57
|
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require './test/helper'
|
2
|
+
|
3
|
+
class GeometryDetectorTest < Test::Unit::TestCase
|
4
|
+
should 'identify an image and extract its dimensions' do
|
5
|
+
Paperclip::GeometryParser.stubs(:new).with("434x66,").returns(stub(:make => :correct))
|
6
|
+
file = fixture_file("5k.png")
|
7
|
+
factory = Paperclip::GeometryDetector.new(file)
|
8
|
+
|
9
|
+
output = factory.make
|
10
|
+
|
11
|
+
assert_equal :correct, output
|
12
|
+
end
|
13
|
+
|
14
|
+
should 'identify an image and extract its dimensions and orientation' do
|
15
|
+
Paperclip::GeometryParser.stubs(:new).with("300x200,6").returns(stub(:make => :correct))
|
16
|
+
file = fixture_file("rotated.jpg")
|
17
|
+
factory = Paperclip::GeometryDetector.new(file)
|
18
|
+
|
19
|
+
output = factory.make
|
20
|
+
|
21
|
+
assert_equal :correct, output
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
@@ -0,0 +1,73 @@
|
|
1
|
+
require './test/helper'
|
2
|
+
|
3
|
+
class GeometryParserTest < Test::Unit::TestCase
|
4
|
+
should 'identify an image and extract its dimensions with no orientation' do
|
5
|
+
Paperclip::Geometry.stubs(:new).with(
|
6
|
+
:height => '73',
|
7
|
+
:width => '434',
|
8
|
+
:modifier => nil,
|
9
|
+
:orientation => nil
|
10
|
+
).returns(:correct)
|
11
|
+
factory = Paperclip::GeometryParser.new("434x73")
|
12
|
+
|
13
|
+
output = factory.make
|
14
|
+
|
15
|
+
assert_equal :correct, output
|
16
|
+
end
|
17
|
+
|
18
|
+
should 'identify an image and extract its dimensions with an empty orientation' do
|
19
|
+
Paperclip::Geometry.stubs(:new).with(
|
20
|
+
:height => '73',
|
21
|
+
:width => '434',
|
22
|
+
:modifier => nil,
|
23
|
+
:orientation => ''
|
24
|
+
).returns(:correct)
|
25
|
+
factory = Paperclip::GeometryParser.new("434x73,")
|
26
|
+
|
27
|
+
output = factory.make
|
28
|
+
|
29
|
+
assert_equal :correct, output
|
30
|
+
end
|
31
|
+
|
32
|
+
should 'identify an image and extract its dimensions and orientation' do
|
33
|
+
Paperclip::Geometry.stubs(:new).with(
|
34
|
+
:height => '200',
|
35
|
+
:width => '300',
|
36
|
+
:modifier => nil,
|
37
|
+
:orientation => '6'
|
38
|
+
).returns(:correct)
|
39
|
+
factory = Paperclip::GeometryParser.new("300x200,6")
|
40
|
+
|
41
|
+
output = factory.make
|
42
|
+
|
43
|
+
assert_equal :correct, output
|
44
|
+
end
|
45
|
+
|
46
|
+
should 'identify an image and extract its dimensions and modifier' do
|
47
|
+
Paperclip::Geometry.stubs(:new).with(
|
48
|
+
:height => '64',
|
49
|
+
:width => '64',
|
50
|
+
:modifier => '#',
|
51
|
+
:orientation => nil
|
52
|
+
).returns(:correct)
|
53
|
+
factory = Paperclip::GeometryParser.new("64x64#")
|
54
|
+
|
55
|
+
output = factory.make
|
56
|
+
|
57
|
+
assert_equal :correct, output
|
58
|
+
end
|
59
|
+
|
60
|
+
should 'identify an image and extract its dimensions, orientation, and modifier' do
|
61
|
+
Paperclip::Geometry.stubs(:new).with(
|
62
|
+
:height => '50',
|
63
|
+
:width => '100',
|
64
|
+
:modifier => '>',
|
65
|
+
:orientation => '7'
|
66
|
+
).returns(:correct)
|
67
|
+
factory = Paperclip::GeometryParser.new("100x50,7>")
|
68
|
+
|
69
|
+
output = factory.make
|
70
|
+
|
71
|
+
assert_equal :correct, output
|
72
|
+
end
|
73
|
+
end
|
data/test/geometry_test.rb
CHANGED
@@ -49,6 +49,30 @@ class GeometryTest < Test::Unit::TestCase
|
|
49
49
|
assert_nil @geo.modifier
|
50
50
|
end
|
51
51
|
|
52
|
+
should "recognize an EXIF orientation and not rotate with auto_orient if not necessary" do
|
53
|
+
geo = Paperclip::Geometry.new(:width => 1024, :height => 768, :orientation => 1)
|
54
|
+
assert geo
|
55
|
+
assert_equal 1024, geo.width
|
56
|
+
assert_equal 768, geo.height
|
57
|
+
|
58
|
+
geo.auto_orient
|
59
|
+
|
60
|
+
assert_equal 1024, geo.width
|
61
|
+
assert_equal 768, geo.height
|
62
|
+
end
|
63
|
+
|
64
|
+
should "recognize an EXIF orientation and rotate with auto_orient if necessary" do
|
65
|
+
geo = Paperclip::Geometry.new(:width => 1024, :height => 768, :orientation => 6)
|
66
|
+
assert geo
|
67
|
+
assert_equal 1024, geo.width
|
68
|
+
assert_equal 768, geo.height
|
69
|
+
|
70
|
+
geo.auto_orient
|
71
|
+
|
72
|
+
assert_equal 768, geo.width
|
73
|
+
assert_equal 1024, geo.height
|
74
|
+
end
|
75
|
+
|
52
76
|
should "treat x and X the same in geometries" do
|
53
77
|
@lower = Paperclip::Geometry.parse("123x456")
|
54
78
|
@upper = Paperclip::Geometry.parse("123X456")
|
@@ -104,15 +128,23 @@ class GeometryTest < Test::Unit::TestCase
|
|
104
128
|
file = fixture_file("5k.png")
|
105
129
|
file = File.new(file, 'rb')
|
106
130
|
assert_nothing_raised{ @geo = Paperclip::Geometry.from_file(file) }
|
107
|
-
|
108
|
-
|
131
|
+
assert_equal 66, @geo.height
|
132
|
+
assert_equal 434, @geo.width
|
109
133
|
end
|
110
134
|
|
111
135
|
should "be generated from a file path" do
|
112
136
|
file = fixture_file("5k.png")
|
113
137
|
assert_nothing_raised{ @geo = Paperclip::Geometry.from_file(file) }
|
114
|
-
|
115
|
-
|
138
|
+
assert_equal 66, @geo.height
|
139
|
+
assert_equal 434, @geo.width
|
140
|
+
end
|
141
|
+
|
142
|
+
should 'calculate an EXIF-rotated image dimensions from a path' do
|
143
|
+
file = fixture_file("rotated.jpg")
|
144
|
+
assert_nothing_raised{ @geo = Paperclip::Geometry.from_file(file) }
|
145
|
+
@geo.auto_orient
|
146
|
+
assert_equal 300, @geo.height
|
147
|
+
assert_equal 200, @geo.width
|
116
148
|
end
|
117
149
|
|
118
150
|
should "not generate from a bad file" do
|
@@ -203,9 +235,9 @@ class GeometryTest < Test::Unit::TestCase
|
|
203
235
|
end
|
204
236
|
end
|
205
237
|
|
206
|
-
[['256x256', '150x150!' => [150, 150], '150x150#' => [150, 150], '150x150>' => [150, 150], '150x150<' => [256, 256], '150x150' => [150, 150]],
|
207
|
-
['256x256', '512x512!' => [512, 512], '512x512#' => [512, 512], '512x512>' => [256, 256], '512x512<' => [512, 512], '512x512' => [512, 512]],
|
208
|
-
['600x400', '512x512!' => [512, 512], '512x512#' => [512, 512], '512x512>' => [512, 341], '512x512<' => [600, 400], '512x512' => [512, 341]]].each do |original_size, options|
|
238
|
+
[['256x256', {'150x150!' => [150, 150], '150x150#' => [150, 150], '150x150>' => [150, 150], '150x150<' => [256, 256], '150x150' => [150, 150]}],
|
239
|
+
['256x256', {'512x512!' => [512, 512], '512x512#' => [512, 512], '512x512>' => [256, 256], '512x512<' => [512, 512], '512x512' => [512, 512]}],
|
240
|
+
['600x400', {'512x512!' => [512, 512], '512x512#' => [512, 512], '512x512>' => [512, 341], '512x512<' => [600, 400], '512x512' => [512, 341]}]].each do |original_size, options|
|
209
241
|
options.each_pair do |size, dimensions|
|
210
242
|
context "#{original_size} resize_to #{size}" do
|
211
243
|
setup do
|
data/test/helper.rb
CHANGED
@@ -125,6 +125,10 @@ class FakeModel
|
|
125
125
|
|
126
126
|
def run_paperclip_callbacks name, *args
|
127
127
|
end
|
128
|
+
|
129
|
+
def valid?
|
130
|
+
errors.empty?
|
131
|
+
end
|
128
132
|
end
|
129
133
|
|
130
134
|
def attachment(options={})
|
@@ -169,7 +173,7 @@ def with_exitstatus_returning(code)
|
|
169
173
|
end
|
170
174
|
|
171
175
|
def fixture_file(filename)
|
172
|
-
|
176
|
+
File.join(File.dirname(__FILE__), 'fixtures', filename)
|
173
177
|
end
|
174
178
|
|
175
179
|
def assert_success_response(url)
|
data/test/integration_test.rb
CHANGED
@@ -293,6 +293,35 @@ class IntegrationTest < Test::Unit::TestCase
|
|
293
293
|
end
|
294
294
|
end
|
295
295
|
|
296
|
+
[0666,0664,0640].each do |perms|
|
297
|
+
context "when the perms are #{perms}" do
|
298
|
+
setup do
|
299
|
+
rebuild_model :override_file_permissions => perms
|
300
|
+
@dummy = Dummy.new
|
301
|
+
@file = File.new(fixture_file("5k.png"), 'rb')
|
302
|
+
end
|
303
|
+
|
304
|
+
teardown do
|
305
|
+
@file.close
|
306
|
+
end
|
307
|
+
|
308
|
+
should "respect the current perms" do
|
309
|
+
@dummy.avatar = @file
|
310
|
+
@dummy.save
|
311
|
+
assert_equal perms, File.stat(@dummy.avatar.path).mode & 0777
|
312
|
+
end
|
313
|
+
end
|
314
|
+
end
|
315
|
+
|
316
|
+
should "skip chmod operation, when override_file_permissions is set to false (e.g. useful when using CIFS mounts)" do
|
317
|
+
FileUtils.expects(:chmod).never
|
318
|
+
|
319
|
+
rebuild_model :override_file_permissions => false
|
320
|
+
dummy = Dummy.create!
|
321
|
+
dummy.avatar = @file
|
322
|
+
dummy.save
|
323
|
+
end
|
324
|
+
|
296
325
|
context "A model with a filesystem attachment" do
|
297
326
|
setup do
|
298
327
|
rebuild_model :styles => { :large => "300x300>",
|
@@ -503,7 +532,13 @@ class IntegrationTest < Test::Unit::TestCase
|
|
503
532
|
setup do
|
504
533
|
rebuild_model :styles => { :large => "300x300>",
|
505
534
|
:medium => "100x100",
|
506
|
-
:thumb => ["32x32#", :gif]
|
535
|
+
:thumb => ["32x32#", :gif],
|
536
|
+
:custom => {
|
537
|
+
:geometry => "32x32#",
|
538
|
+
:s3_headers => { 'Cache-Control' => 'max-age=31557600' },
|
539
|
+
:s3_metadata => { 'foo' => 'bar'}
|
540
|
+
}
|
541
|
+
},
|
507
542
|
:storage => :s3,
|
508
543
|
:s3_credentials => File.new(fixture_file('s3.yml')),
|
509
544
|
:s3_options => { :logger => Paperclip.logger },
|
@@ -630,6 +665,16 @@ class IntegrationTest < Test::Unit::TestCase
|
|
630
665
|
assert_equal 'image/png', headers['content-type']
|
631
666
|
end
|
632
667
|
|
668
|
+
should "have the right style-specific headers" do
|
669
|
+
headers = s3_headers_for(@dummy.avatar, :custom)
|
670
|
+
assert_equal 'max-age=31557600', headers['cache-control']
|
671
|
+
end
|
672
|
+
|
673
|
+
should "have the right style-specific metadata" do
|
674
|
+
headers = s3_headers_for(@dummy.avatar, :custom)
|
675
|
+
assert_equal 'bar', headers['x-amz-meta-foo']
|
676
|
+
end
|
677
|
+
|
633
678
|
context "with non-english character in the file name" do
|
634
679
|
setup do
|
635
680
|
@file.stubs(:original_filename).returns("クリップ.png")
|
@@ -4,13 +4,15 @@ class UploadedFileAdapterTest < Test::Unit::TestCase
|
|
4
4
|
context "a new instance" do
|
5
5
|
context "with UploadedFile responding to #tempfile" do
|
6
6
|
setup do
|
7
|
+
Paperclip::UploadedFileAdapter.content_type_detector = nil
|
8
|
+
|
7
9
|
class UploadedFile < OpenStruct; end
|
8
10
|
tempfile = File.new(fixture_file("5k.png"))
|
9
11
|
tempfile.binmode
|
10
12
|
|
11
13
|
@file = UploadedFile.new(
|
12
14
|
:original_filename => "5k.png",
|
13
|
-
:content_type => "image/png\r",
|
15
|
+
:content_type => "image/x-png-by-browser\r",
|
14
16
|
:head => "",
|
15
17
|
:tempfile => tempfile,
|
16
18
|
:path => tempfile.path
|
@@ -27,7 +29,7 @@ class UploadedFileAdapterTest < Test::Unit::TestCase
|
|
27
29
|
end
|
28
30
|
|
29
31
|
should "get the content type" do
|
30
|
-
assert_equal "image/png", @subject.content_type
|
32
|
+
assert_equal "image/x-png-by-browser", @subject.content_type
|
31
33
|
end
|
32
34
|
|
33
35
|
should "get the file's size" do
|
@@ -52,10 +54,12 @@ class UploadedFileAdapterTest < Test::Unit::TestCase
|
|
52
54
|
|
53
55
|
context "with UploadFile responding to #path" do
|
54
56
|
setup do
|
57
|
+
Paperclip::UploadedFileAdapter.content_type_detector = nil
|
58
|
+
|
55
59
|
class UploadedFile < OpenStruct; end
|
56
60
|
@file = UploadedFile.new(
|
57
61
|
:original_filename => "5k.png",
|
58
|
-
:content_type => "image/png",
|
62
|
+
:content_type => "image/x-png-by-browser",
|
59
63
|
:head => "",
|
60
64
|
:path => fixture_file("5k.png")
|
61
65
|
)
|
@@ -71,7 +75,7 @@ class UploadedFileAdapterTest < Test::Unit::TestCase
|
|
71
75
|
end
|
72
76
|
|
73
77
|
should "get the content type" do
|
74
|
-
assert_equal "image/png", @subject.content_type
|
78
|
+
assert_equal "image/x-png-by-browser", @subject.content_type
|
75
79
|
end
|
76
80
|
|
77
81
|
should "get the file's size" do
|
@@ -94,6 +98,26 @@ class UploadedFileAdapterTest < Test::Unit::TestCase
|
|
94
98
|
assert expected.length > 0
|
95
99
|
assert_equal expected, @subject.read
|
96
100
|
end
|
101
|
+
|
102
|
+
context "don't trust client-given MIME type" do
|
103
|
+
setup do
|
104
|
+
Paperclip::UploadedFileAdapter.content_type_detector =
|
105
|
+
Paperclip::FileCommandContentTypeDetector
|
106
|
+
|
107
|
+
class UploadedFile < OpenStruct; end
|
108
|
+
@file = UploadedFile.new(
|
109
|
+
:original_filename => "5k.png",
|
110
|
+
:content_type => "image/x-png-by-browser",
|
111
|
+
:head => "",
|
112
|
+
:path => fixture_file("5k.png")
|
113
|
+
)
|
114
|
+
@subject = Paperclip.io_adapters.for(@file)
|
115
|
+
end
|
116
|
+
|
117
|
+
should "get the content type" do
|
118
|
+
assert_equal "image/png", @subject.content_type
|
119
|
+
end
|
120
|
+
end
|
97
121
|
end
|
98
122
|
end
|
99
123
|
end
|
@@ -14,6 +14,10 @@ class UriProxyTest < Test::Unit::TestCase
|
|
14
14
|
assert_equal "thoughtbot-logo.png", @subject.original_filename
|
15
15
|
end
|
16
16
|
|
17
|
+
should 'close open handle after reading' do
|
18
|
+
assert_equal true, @open_return.closed?
|
19
|
+
end
|
20
|
+
|
17
21
|
should "return a content type" do
|
18
22
|
assert_equal "image/png", @subject.content_type
|
19
23
|
end
|
data/test/paperclip_test.rb
CHANGED
@@ -114,24 +114,34 @@ class PaperclipTest < Test::Unit::TestCase
|
|
114
114
|
end
|
115
115
|
end
|
116
116
|
|
117
|
-
should "generate warning if attachment is redefined with the same
|
118
|
-
expected_log_msg = "Duplicate
|
117
|
+
should "generate warning if attachment is redefined with the same path string" do
|
118
|
+
expected_log_msg = "Duplicate path for blah with /system/:id/:style/:filename. This will clash with attachment defined in Dummy class"
|
119
119
|
Paperclip.expects(:log).with(expected_log_msg)
|
120
120
|
Dummy.class_eval do
|
121
|
-
has_attached_file :blah, :
|
121
|
+
has_attached_file :blah, :path => '/system/:id/:style/:filename'
|
122
122
|
end
|
123
123
|
Dummy2.class_eval do
|
124
|
-
has_attached_file :blah, :
|
124
|
+
has_attached_file :blah, :path => '/system/:id/:style/:filename'
|
125
125
|
end
|
126
126
|
end
|
127
127
|
|
128
|
-
should "not generate warning if attachment is
|
128
|
+
should "not generate warning if attachment is redefined with the same path string but has :class in it" do
|
129
129
|
Paperclip.expects(:log).never
|
130
130
|
Dummy.class_eval do
|
131
|
-
has_attached_file :blah, :
|
131
|
+
has_attached_file :blah, :path => "/system/:class/:attachment/:id/:style/:filename"
|
132
132
|
end
|
133
133
|
Dummy2.class_eval do
|
134
|
-
has_attached_file :blah, :
|
134
|
+
has_attached_file :blah, :path => "/system/:class/:attachment/:id/:style/:filename"
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
should "not generate warning if attachment is defined with the same URL string" do
|
139
|
+
Paperclip.expects(:log).never
|
140
|
+
Dummy.class_eval do
|
141
|
+
has_attached_file :blah, :path => "/system/:class/:attachment/:id/:style/:filename", :url => ":s3_alias_url"
|
142
|
+
end
|
143
|
+
Dummy2.class_eval do
|
144
|
+
has_attached_file :blah, :path => "/system/:class/:attachment/:id/:style/:filename", :url => ":s3_alias_url"
|
135
145
|
end
|
136
146
|
end
|
137
147
|
end
|
data/test/storage/fog_test.rb
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
require './test/helper'
|
2
2
|
require 'fog'
|
3
3
|
|
4
|
-
Fog.mock!
|
5
|
-
|
6
4
|
class FogTest < Test::Unit::TestCase
|
7
5
|
context "" do
|
6
|
+
setup { Fog.mock! }
|
7
|
+
|
8
8
|
context "with credentials provided in a path string" do
|
9
9
|
setup do
|
10
10
|
rebuild_model :styles => { :medium => "300x300>", :thumb => "100x100>" },
|
@@ -66,7 +66,7 @@ class FogTest < Test::Unit::TestCase
|
|
66
66
|
@dummy.avatar.path
|
67
67
|
end
|
68
68
|
end
|
69
|
-
|
69
|
+
|
70
70
|
context "with no path or url given and using defaults" do
|
71
71
|
setup do
|
72
72
|
rebuild_model :styles => { :medium => "300x300>", :thumb => "100x100>" },
|
@@ -82,14 +82,35 @@ class FogTest < Test::Unit::TestCase
|
|
82
82
|
@dummy.id = 1
|
83
83
|
@dummy.avatar = @file
|
84
84
|
end
|
85
|
-
|
85
|
+
|
86
86
|
teardown { @file.close }
|
87
|
-
|
87
|
+
|
88
88
|
should "have correct path and url from interpolated defaults" do
|
89
89
|
assert_equal "dummies/avatars/000/000/001/original/5k.png", @dummy.avatar.path
|
90
90
|
end
|
91
91
|
end
|
92
92
|
|
93
|
+
context "with file params provided as lambda" do
|
94
|
+
setup do
|
95
|
+
fog_file = lambda{ |a| { :custom_header => a.instance.custom_method }}
|
96
|
+
klass = rebuild_model :storage => :fog,
|
97
|
+
:fog_file => fog_file
|
98
|
+
|
99
|
+
klass.class_eval do
|
100
|
+
def custom_method
|
101
|
+
'foobar'
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
|
106
|
+
@dummy = Dummy.new
|
107
|
+
end
|
108
|
+
|
109
|
+
should "be able to evaluate correct values for file headers" do
|
110
|
+
assert_equal @dummy.avatar.send(:fog_file), { :custom_header => 'foobar' }
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
93
114
|
setup do
|
94
115
|
@fog_directory = 'papercliptests'
|
95
116
|
|
@@ -252,7 +273,7 @@ class FogTest < Test::Unit::TestCase
|
|
252
273
|
@dummy.save
|
253
274
|
end
|
254
275
|
|
255
|
-
should 'set the @fog_public for a
|
276
|
+
should 'set the @fog_public for a particular style to false' do
|
256
277
|
assert_equal false, @dummy.avatar.instance_variable_get('@options')[:fog_public]
|
257
278
|
assert_equal false, @dummy.avatar.fog_public(:thumb)
|
258
279
|
end
|
@@ -267,12 +288,25 @@ class FogTest < Test::Unit::TestCase
|
|
267
288
|
@dummy.save
|
268
289
|
end
|
269
290
|
|
270
|
-
should 'set the fog_public for a
|
291
|
+
should 'set the fog_public for a particular style to correct value' do
|
271
292
|
assert_equal false, @dummy.avatar.fog_public(:medium)
|
272
293
|
assert_equal true, @dummy.avatar.fog_public(:thumb)
|
273
294
|
end
|
274
295
|
end
|
275
296
|
|
297
|
+
context "with fog_public not set" do
|
298
|
+
setup do
|
299
|
+
rebuild_model(@options)
|
300
|
+
@dummy = Dummy.new
|
301
|
+
@dummy.avatar = StringIO.new('.')
|
302
|
+
@dummy.save
|
303
|
+
end
|
304
|
+
|
305
|
+
should "default fog_public to true" do
|
306
|
+
assert_equal true, @dummy.avatar.fog_public
|
307
|
+
end
|
308
|
+
end
|
309
|
+
|
276
310
|
context "with a valid bucket name for a subdomain" do
|
277
311
|
should "provide an url in subdomain style" do
|
278
312
|
assert_match @dummy.avatar.url, /^https:\/\/papercliptests.s3.amazonaws.com\/avatars\/5k.png/
|
@@ -391,4 +425,29 @@ class FogTest < Test::Unit::TestCase
|
|
391
425
|
end
|
392
426
|
|
393
427
|
end
|
428
|
+
|
429
|
+
context "when using local storage" do
|
430
|
+
setup do
|
431
|
+
Fog.unmock!
|
432
|
+
rebuild_model :styles => { :medium => "300x300>", :thumb => "100x100>" },
|
433
|
+
:storage => :fog,
|
434
|
+
:url => '/:attachment/:filename',
|
435
|
+
:fog_directory => "paperclip",
|
436
|
+
:fog_credentials => { :provider => :local, :local_root => "." },
|
437
|
+
:fog_host => 'localhost'
|
438
|
+
|
439
|
+
@file = File.new(fixture_file('5k.png'), 'rb')
|
440
|
+
@dummy = Dummy.new
|
441
|
+
@dummy.avatar = @file
|
442
|
+
end
|
443
|
+
|
444
|
+
teardown do
|
445
|
+
@file.close
|
446
|
+
Fog.mock!
|
447
|
+
end
|
448
|
+
|
449
|
+
should "return the public url in place of the expiring url" do
|
450
|
+
assert_match @dummy.avatar.public_url, @dummy.avatar.expiring_url
|
451
|
+
end
|
452
|
+
end
|
394
453
|
end
|