kt-paperclip 5.4.0 → 6.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/issue_template.md +3 -0
- data/.hound.yml +27 -32
- data/.travis.yml +23 -2
- data/Appraisals +17 -0
- data/Gemfile +9 -7
- data/NEWS +21 -0
- data/README.md +27 -37
- data/Rakefile +29 -21
- data/UPGRADING +3 -3
- data/features/basic_integration.feature +4 -0
- data/features/migration.feature +10 -51
- data/features/step_definitions/attachment_steps.rb +12 -12
- data/features/step_definitions/html_steps.rb +5 -5
- data/features/step_definitions/rails_steps.rb +29 -9
- data/features/step_definitions/s3_steps.rb +3 -3
- data/features/step_definitions/web_steps.rb +5 -6
- data/features/support/env.rb +4 -4
- data/features/support/fakeweb.rb +3 -5
- data/features/support/file_helpers.rb +2 -2
- data/features/support/paths.rb +4 -4
- data/features/support/rails.rb +7 -7
- data/features/support/selectors.rb +1 -1
- data/gemfiles/4.2.gemfile +7 -4
- data/gemfiles/5.0.gemfile +7 -4
- data/gemfiles/5.1.gemfile +20 -0
- data/gemfiles/5.2.gemfile +20 -0
- data/gemfiles/6.0.gemfile +20 -0
- data/lib/generators/paperclip/paperclip_generator.rb +6 -8
- data/lib/paperclip/attachment.rb +102 -104
- data/lib/paperclip/attachment_registry.rb +2 -2
- data/lib/paperclip/file_command_content_type_detector.rb +1 -3
- data/lib/paperclip/filename_cleaner.rb +0 -1
- data/lib/paperclip/geometry.rb +18 -19
- data/lib/paperclip/geometry_detector_factory.rb +13 -16
- data/lib/paperclip/geometry_parser_factory.rb +5 -5
- data/lib/paperclip/glue.rb +3 -3
- data/lib/paperclip/has_attached_file.rb +5 -4
- data/lib/paperclip/helpers.rb +3 -3
- data/lib/paperclip/interpolations.rb +42 -38
- data/lib/paperclip/io_adapters/abstract_adapter.rb +16 -14
- data/lib/paperclip/io_adapters/attachment_adapter.rb +12 -6
- data/lib/paperclip/io_adapters/data_uri_adapter.rb +1 -1
- data/lib/paperclip/io_adapters/file_adapter.rb +1 -3
- data/lib/paperclip/io_adapters/http_url_proxy_adapter.rb +3 -3
- data/lib/paperclip/io_adapters/identity_adapter.rb +1 -2
- data/lib/paperclip/io_adapters/registry.rb +1 -1
- data/lib/paperclip/io_adapters/stringio_adapter.rb +1 -1
- data/lib/paperclip/io_adapters/uploaded_file_adapter.rb +6 -8
- data/lib/paperclip/io_adapters/uri_adapter.rb +9 -7
- data/lib/paperclip/logger.rb +1 -1
- data/lib/paperclip/matchers/have_attached_file_matcher.rb +4 -4
- data/lib/paperclip/matchers/validate_attachment_content_type_matcher.rb +19 -18
- data/lib/paperclip/matchers/validate_attachment_presence_matcher.rb +4 -4
- data/lib/paperclip/matchers/validate_attachment_size_matcher.rb +11 -10
- data/lib/paperclip/matchers.rb +4 -4
- data/lib/paperclip/media_type_spoof_detector.rb +13 -13
- data/lib/paperclip/missing_attachment_styles.rb +11 -6
- data/lib/paperclip/processor.rb +13 -6
- data/lib/paperclip/processor_helpers.rb +3 -1
- data/lib/paperclip/rails_environment.rb +1 -5
- data/lib/paperclip/railtie.rb +5 -5
- data/lib/paperclip/schema.rb +18 -14
- data/lib/paperclip/storage/filesystem.rb +5 -7
- data/lib/paperclip/storage/fog.rb +36 -32
- data/lib/paperclip/storage/s3.rb +67 -75
- data/lib/paperclip/style.rb +3 -6
- data/lib/paperclip/tempfile.rb +4 -5
- data/lib/paperclip/tempfile_factory.rb +0 -1
- data/lib/paperclip/thumbnail.rb +11 -11
- data/lib/paperclip/url_generator.rb +5 -12
- data/lib/paperclip/validators/attachment_content_type_validator.rb +3 -3
- data/lib/paperclip/validators/attachment_file_name_validator.rb +5 -10
- data/lib/paperclip/validators/attachment_file_type_ignorance_validator.rb +1 -2
- data/lib/paperclip/validators/attachment_presence_validator.rb +3 -5
- data/lib/paperclip/validators/attachment_size_validator.rb +8 -8
- data/lib/paperclip/validators/media_type_spoof_detection_validator.rb +3 -1
- data/lib/paperclip/validators.rb +12 -13
- data/lib/paperclip/version.rb +1 -3
- data/lib/paperclip.rb +49 -48
- data/lib/tasks/paperclip.rake +23 -24
- data/paperclip.gemspec +29 -33
- data/shoulda_macros/paperclip.rb +16 -16
- data/spec/paperclip/attachment_definitions_spec.rb +5 -5
- data/spec/paperclip/attachment_processing_spec.rb +22 -23
- data/spec/paperclip/attachment_registry_spec.rb +15 -15
- data/spec/paperclip/attachment_spec.rb +238 -196
- data/spec/paperclip/content_type_detector_spec.rb +11 -12
- data/spec/paperclip/file_command_content_type_detector_spec.rb +10 -10
- data/spec/paperclip/filename_cleaner_spec.rb +3 -4
- data/spec/paperclip/geometry_detector_spec.rb +7 -8
- data/spec/paperclip/geometry_parser_spec.rb +31 -31
- data/spec/paperclip/geometry_spec.rb +24 -24
- data/spec/paperclip/glue_spec.rb +3 -5
- data/spec/paperclip/has_attached_file_spec.rb +46 -126
- data/spec/paperclip/integration_spec.rb +111 -77
- data/spec/paperclip/interpolations_spec.rb +101 -93
- data/spec/paperclip/io_adapters/abstract_adapter_spec.rb +41 -13
- data/spec/paperclip/io_adapters/attachment_adapter_spec.rb +8 -10
- data/spec/paperclip/io_adapters/data_uri_adapter_spec.rb +13 -14
- data/spec/paperclip/io_adapters/empty_string_adapter_spec.rb +4 -4
- data/spec/paperclip/io_adapters/file_adapter_spec.rb +12 -12
- data/spec/paperclip/io_adapters/http_url_proxy_adapter_spec.rb +42 -26
- data/spec/paperclip/io_adapters/identity_adapter_spec.rb +1 -1
- data/spec/paperclip/io_adapters/nil_adapter_spec.rb +2 -2
- data/spec/paperclip/io_adapters/registry_spec.rb +4 -4
- data/spec/paperclip/io_adapters/stringio_adapter_spec.rb +10 -10
- data/spec/paperclip/io_adapters/uploaded_file_adapter_spec.rb +6 -6
- data/spec/paperclip/io_adapters/uri_adapter_spec.rb +80 -31
- data/spec/paperclip/matchers/have_attached_file_matcher_spec.rb +3 -3
- data/spec/paperclip/matchers/validate_attachment_content_type_matcher_spec.rb +4 -5
- data/spec/paperclip/matchers/validate_attachment_presence_matcher_spec.rb +4 -4
- data/spec/paperclip/matchers/validate_attachment_size_matcher_spec.rb +4 -4
- data/spec/paperclip/media_type_spoof_detector_spec.rb +50 -24
- data/spec/paperclip/meta_class_spec.rb +3 -3
- data/spec/paperclip/paperclip_missing_attachment_styles_spec.rb +28 -24
- data/spec/paperclip/paperclip_spec.rb +15 -11
- data/spec/paperclip/plural_cache_spec.rb +8 -8
- data/spec/paperclip/processor_helpers_spec.rb +35 -35
- data/spec/paperclip/processor_spec.rb +8 -8
- data/spec/paperclip/rails_environment_spec.rb +7 -10
- data/spec/paperclip/rake_spec.rb +39 -39
- data/spec/paperclip/schema_spec.rb +57 -53
- data/spec/paperclip/storage/filesystem_spec.rb +6 -6
- data/spec/paperclip/storage/fog_spec.rb +76 -82
- data/spec/paperclip/storage/s3_live_spec.rb +22 -22
- data/spec/paperclip/storage/s3_spec.rb +585 -583
- data/spec/paperclip/style_spec.rb +67 -71
- data/spec/paperclip/tempfile_factory_spec.rb +5 -5
- data/spec/paperclip/thumbnail_spec.rb +68 -67
- data/spec/paperclip/url_generator_spec.rb +18 -29
- data/spec/paperclip/validators/attachment_content_type_validator_spec.rb +27 -27
- data/spec/paperclip/validators/attachment_file_name_validator_spec.rb +15 -16
- data/spec/paperclip/validators/attachment_presence_validator_spec.rb +5 -5
- data/spec/paperclip/validators/attachment_size_validator_spec.rb +21 -21
- data/spec/paperclip/validators/media_type_spoof_detection_validator_spec.rb +9 -13
- data/spec/paperclip/validators_spec.rb +40 -40
- data/spec/spec_helper.rb +21 -23
- data/spec/support/assertions.rb +8 -6
- data/spec/support/fake_model.rb +1 -2
- data/spec/support/fake_rails.rb +1 -1
- data/spec/support/matchers/exist.rb +1 -1
- data/spec/support/matchers/have_column.rb +1 -1
- data/spec/support/mock_url_generator_builder.rb +2 -3
- data/spec/support/model_reconstruction.rb +16 -12
- data/spec/support/reporting.rb +1 -1
- data/spec/support/test_data.rb +2 -2
- metadata +49 -105
- data/lib/kt-paperclip.rb +0 -1
- data/spec/support/conditional_filter_helper.rb +0 -5
@@ -1,7 +1,7 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require
|
1
|
+
require "spec_helper"
|
2
|
+
require "fog/aws"
|
3
|
+
require "fog/local"
|
4
|
+
require "timecop"
|
5
5
|
|
6
6
|
describe Paperclip::Storage::Fog do
|
7
7
|
context "" do
|
@@ -11,10 +11,10 @@ describe Paperclip::Storage::Fog do
|
|
11
11
|
before do
|
12
12
|
rebuild_model styles: { medium: "300x300>", thumb: "100x100>" },
|
13
13
|
storage: :fog,
|
14
|
-
url:
|
14
|
+
url: "/:attachment/:filename",
|
15
15
|
fog_directory: "paperclip",
|
16
|
-
fog_credentials: fixture_file(
|
17
|
-
@file = File.new(fixture_file(
|
16
|
+
fog_credentials: fixture_file("fog.yml")
|
17
|
+
@file = File.new(fixture_file("5k.png"), "rb")
|
18
18
|
@dummy = Dummy.new
|
19
19
|
@dummy.avatar = @file
|
20
20
|
end
|
@@ -22,7 +22,7 @@ describe Paperclip::Storage::Fog do
|
|
22
22
|
after { @file.close }
|
23
23
|
|
24
24
|
it "has the proper information loading credentials from a file" do
|
25
|
-
assert_equal @dummy.avatar.fog_credentials[:provider],
|
25
|
+
assert_equal @dummy.avatar.fog_credentials[:provider], "AWS"
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
@@ -30,10 +30,10 @@ describe Paperclip::Storage::Fog do
|
|
30
30
|
before do
|
31
31
|
rebuild_model styles: { medium: "300x300>", thumb: "100x100>" },
|
32
32
|
storage: :fog,
|
33
|
-
url:
|
33
|
+
url: "/:attachment/:filename",
|
34
34
|
fog_directory: "paperclip",
|
35
|
-
fog_credentials: File.open(fixture_file(
|
36
|
-
@file = File.new(fixture_file(
|
35
|
+
fog_credentials: File.open(fixture_file("fog.yml"))
|
36
|
+
@file = File.new(fixture_file("5k.png"), "rb")
|
37
37
|
@dummy = Dummy.new
|
38
38
|
@dummy.avatar = @file
|
39
39
|
end
|
@@ -41,7 +41,7 @@ describe Paperclip::Storage::Fog do
|
|
41
41
|
after { @file.close }
|
42
42
|
|
43
43
|
it "has the proper information loading credentials from a file" do
|
44
|
-
assert_equal @dummy.avatar.fog_credentials[:provider],
|
44
|
+
assert_equal @dummy.avatar.fog_credentials[:provider], "AWS"
|
45
45
|
end
|
46
46
|
end
|
47
47
|
|
@@ -49,14 +49,14 @@ describe Paperclip::Storage::Fog do
|
|
49
49
|
before do
|
50
50
|
rebuild_model styles: { medium: "300x300>", thumb: "100x100>" },
|
51
51
|
storage: :fog,
|
52
|
-
url:
|
52
|
+
url: "/:attachment/:filename",
|
53
53
|
fog_directory: "paperclip",
|
54
54
|
fog_credentials: {
|
55
|
-
provider:
|
56
|
-
aws_access_key_id:
|
57
|
-
aws_secret_access_key:
|
55
|
+
provider: "AWS",
|
56
|
+
aws_access_key_id: "AWS_ID",
|
57
|
+
aws_secret_access_key: "AWS_SECRET"
|
58
58
|
}
|
59
|
-
@file = File.new(fixture_file(
|
59
|
+
@file = File.new(fixture_file("5k.png"), "rb")
|
60
60
|
@dummy = Dummy.new
|
61
61
|
@dummy.avatar = @file
|
62
62
|
end
|
@@ -65,7 +65,7 @@ describe Paperclip::Storage::Fog do
|
|
65
65
|
|
66
66
|
it "is able to interpolate the path without blowing up" do
|
67
67
|
assert_equal File.expand_path(File.join(File.dirname(__FILE__), "../../../tmp/public/avatars/5k.png")),
|
68
|
-
|
68
|
+
@dummy.avatar.path
|
69
69
|
end
|
70
70
|
end
|
71
71
|
|
@@ -75,11 +75,11 @@ describe Paperclip::Storage::Fog do
|
|
75
75
|
storage: :fog,
|
76
76
|
fog_directory: "paperclip",
|
77
77
|
fog_credentials: {
|
78
|
-
provider:
|
79
|
-
aws_access_key_id:
|
80
|
-
aws_secret_access_key:
|
78
|
+
provider: "AWS",
|
79
|
+
aws_access_key_id: "AWS_ID",
|
80
|
+
aws_secret_access_key: "AWS_SECRET"
|
81
81
|
}
|
82
|
-
@file = File.new(fixture_file(
|
82
|
+
@file = File.new(fixture_file("5k.png"), "rb")
|
83
83
|
@dummy = Dummy.new
|
84
84
|
@dummy.id = 1
|
85
85
|
@dummy.avatar = @file
|
@@ -94,32 +94,31 @@ describe Paperclip::Storage::Fog do
|
|
94
94
|
|
95
95
|
context "with file params provided as lambda" do
|
96
96
|
before do
|
97
|
-
fog_file = lambda{ |a| { custom_header: a.instance.custom_method }}
|
97
|
+
fog_file = lambda { |a| { custom_header: a.instance.custom_method } }
|
98
98
|
klass = rebuild_model storage: :fog,
|
99
99
|
fog_file: fog_file
|
100
100
|
|
101
101
|
klass.class_eval do
|
102
102
|
def custom_method
|
103
|
-
|
103
|
+
"foobar"
|
104
104
|
end
|
105
105
|
end
|
106
106
|
|
107
|
-
|
108
107
|
@dummy = Dummy.new
|
109
108
|
end
|
110
109
|
|
111
110
|
it "is able to evaluate correct values for file headers" do
|
112
|
-
assert_equal @dummy.avatar.send(:fog_file),
|
111
|
+
assert_equal @dummy.avatar.send(:fog_file), custom_header: "foobar"
|
113
112
|
end
|
114
113
|
end
|
115
114
|
|
116
115
|
before do
|
117
|
-
@fog_directory =
|
116
|
+
@fog_directory = "papercliptests"
|
118
117
|
|
119
118
|
@credentials = {
|
120
|
-
provider:
|
121
|
-
aws_access_key_id:
|
122
|
-
aws_secret_access_key:
|
119
|
+
provider: "AWS",
|
120
|
+
aws_access_key_id: "ID",
|
121
|
+
aws_secret_access_key: "SECRET"
|
123
122
|
}
|
124
123
|
|
125
124
|
@connection = Fog::Storage.new(@credentials)
|
@@ -131,7 +130,7 @@ describe Paperclip::Storage::Fog do
|
|
131
130
|
fog_directory: @fog_directory,
|
132
131
|
fog_credentials: @credentials,
|
133
132
|
fog_host: nil,
|
134
|
-
fog_file: {cache_control: 1234},
|
133
|
+
fog_file: { cache_control: 1234 },
|
135
134
|
path: ":attachment/:basename:dotextension",
|
136
135
|
storage: :fog
|
137
136
|
}
|
@@ -145,7 +144,7 @@ describe Paperclip::Storage::Fog do
|
|
145
144
|
|
146
145
|
context "when assigned" do
|
147
146
|
before do
|
148
|
-
@file = File.new(fixture_file(
|
147
|
+
@file = File.new(fixture_file("5k.png"), "rb")
|
149
148
|
@dummy = Dummy.new
|
150
149
|
@dummy.avatar = @file
|
151
150
|
end
|
@@ -153,7 +152,7 @@ describe Paperclip::Storage::Fog do
|
|
153
152
|
after do
|
154
153
|
@file.close
|
155
154
|
directory = @connection.directories.new(key: @fog_directory)
|
156
|
-
directory.files.each
|
155
|
+
directory.files.each(&:destroy)
|
157
156
|
directory.destroy
|
158
157
|
end
|
159
158
|
|
@@ -168,11 +167,11 @@ describe Paperclip::Storage::Fog do
|
|
168
167
|
it "is removed after after_flush_writes" do
|
169
168
|
paths = @dummy.avatar.queued_for_write.values.map(&:path)
|
170
169
|
@dummy.save
|
171
|
-
assert paths.none?{ |path| File.exist?(path) },
|
172
|
-
|
170
|
+
assert paths.none? { |path| File.exist?(path) },
|
171
|
+
"Expect all the files to be deleted."
|
173
172
|
end
|
174
173
|
|
175
|
-
it
|
174
|
+
it "is able to be copied to a local file" do
|
176
175
|
@dummy.save
|
177
176
|
tempfile = Tempfile.new("known_location")
|
178
177
|
tempfile.binmode
|
@@ -183,7 +182,7 @@ describe Paperclip::Storage::Fog do
|
|
183
182
|
tempfile.close
|
184
183
|
end
|
185
184
|
|
186
|
-
it
|
185
|
+
it "is able to be handled when missing while copying to a local file" do
|
187
186
|
tempfile = Tempfile.new("known_location")
|
188
187
|
tempfile.binmode
|
189
188
|
assert_equal false, @dummy.avatar.copy_to_local_file(:original, tempfile.path)
|
@@ -191,9 +190,7 @@ describe Paperclip::Storage::Fog do
|
|
191
190
|
end
|
192
191
|
|
193
192
|
it "passes the content type to the Fog::Storage::AWS::Files instance" do
|
194
|
-
Fog::Storage::AWS::Files.
|
195
|
-
hash[:content_type]
|
196
|
-
end
|
193
|
+
expect_any_instance_of(Fog::Storage::AWS::Files).to receive(:create).with(hash_including(:content_type))
|
197
194
|
@dummy.save
|
198
195
|
end
|
199
196
|
|
@@ -223,7 +220,7 @@ describe Paperclip::Storage::Fog do
|
|
223
220
|
before do
|
224
221
|
rebuild_model(@options.merge(fog_host: nil))
|
225
222
|
@dummy = Dummy.new
|
226
|
-
@dummy.avatar = StringIO.new(
|
223
|
+
@dummy.avatar = StringIO.new(".")
|
227
224
|
@dummy.save
|
228
225
|
end
|
229
226
|
|
@@ -234,7 +231,7 @@ describe Paperclip::Storage::Fog do
|
|
234
231
|
|
235
232
|
context "with a fog_host" do
|
236
233
|
before do
|
237
|
-
rebuild_model(@options.merge(fog_host:
|
234
|
+
rebuild_model(@options.merge(fog_host: "http://example.com"))
|
238
235
|
@dummy = Dummy.new
|
239
236
|
@dummy.avatar = StringIO.new(".\n")
|
240
237
|
@dummy.save
|
@@ -250,7 +247,7 @@ describe Paperclip::Storage::Fog do
|
|
250
247
|
rebuild_model(
|
251
248
|
fog_directory: @fog_directory,
|
252
249
|
fog_credentials: @credentials,
|
253
|
-
fog_host:
|
250
|
+
fog_host: "http://img%d.example.com",
|
254
251
|
path: ":attachment/:basename:dotextension",
|
255
252
|
storage: :fog
|
256
253
|
)
|
@@ -268,12 +265,12 @@ describe Paperclip::Storage::Fog do
|
|
268
265
|
before do
|
269
266
|
rebuild_model(@options.merge(fog_public: false))
|
270
267
|
@dummy = Dummy.new
|
271
|
-
@dummy.avatar = StringIO.new(
|
268
|
+
@dummy.avatar = StringIO.new(".")
|
272
269
|
@dummy.save
|
273
270
|
end
|
274
271
|
|
275
|
-
it
|
276
|
-
assert_equal false, @dummy.avatar.instance_variable_get(
|
272
|
+
it "sets the @fog_public instance variable to false" do
|
273
|
+
assert_equal false, @dummy.avatar.instance_variable_get("@options")[:fog_public]
|
277
274
|
assert_equal false, @dummy.avatar.fog_public
|
278
275
|
end
|
279
276
|
end
|
@@ -297,28 +294,29 @@ describe Paperclip::Storage::Fog do
|
|
297
294
|
context "with styles set and fog_public set to false" do
|
298
295
|
before do
|
299
296
|
rebuild_model(@options.merge(fog_public: false, styles: { medium: "300x300>", thumb: "100x100>" }))
|
300
|
-
@file = File.new(fixture_file(
|
297
|
+
@file = File.new(fixture_file("5k.png"), "rb")
|
301
298
|
@dummy = Dummy.new
|
302
299
|
@dummy.avatar = @file
|
303
300
|
@dummy.save
|
304
301
|
end
|
305
302
|
|
306
|
-
it
|
307
|
-
assert_equal false, @dummy.avatar.instance_variable_get(
|
303
|
+
it "sets the @fog_public for a particular style to false" do
|
304
|
+
assert_equal false, @dummy.avatar.instance_variable_get("@options")[:fog_public]
|
308
305
|
assert_equal false, @dummy.avatar.fog_public(:thumb)
|
309
306
|
end
|
310
307
|
end
|
311
308
|
|
312
309
|
context "with styles set and fog_public set per-style" do
|
313
310
|
before do
|
314
|
-
rebuild_model(@options.merge(fog_public: { medium: false, thumb: true},
|
315
|
-
|
311
|
+
rebuild_model(@options.merge(fog_public: { medium: false, thumb: true },
|
312
|
+
styles: { medium: "300x300>", thumb: "100x100>" }))
|
313
|
+
@file = File.new(fixture_file("5k.png"), "rb")
|
316
314
|
@dummy = Dummy.new
|
317
315
|
@dummy.avatar = @file
|
318
316
|
@dummy.save
|
319
317
|
end
|
320
318
|
|
321
|
-
it
|
319
|
+
it "sets the fog_public for a particular style to correct value" do
|
322
320
|
assert_equal false, @dummy.avatar.fog_public(:medium)
|
323
321
|
assert_equal true, @dummy.avatar.fog_public(:thumb)
|
324
322
|
end
|
@@ -328,7 +326,7 @@ describe Paperclip::Storage::Fog do
|
|
328
326
|
before do
|
329
327
|
rebuild_model(@options)
|
330
328
|
@dummy = Dummy.new
|
331
|
-
@dummy.avatar = StringIO.new(
|
329
|
+
@dummy.avatar = StringIO.new(".")
|
332
330
|
@dummy.save
|
333
331
|
end
|
334
332
|
|
@@ -339,8 +337,8 @@ describe Paperclip::Storage::Fog do
|
|
339
337
|
|
340
338
|
context "with scheme set" do
|
341
339
|
before do
|
342
|
-
rebuild_model(@options.merge(:
|
343
|
-
@file = File.new(fixture_file(
|
340
|
+
rebuild_model(@options.merge(fog_credentials: @credentials.merge(scheme: "http")))
|
341
|
+
@file = File.new(fixture_file("5k.png"), "rb")
|
344
342
|
@dummy = Dummy.new
|
345
343
|
@dummy.avatar = @file
|
346
344
|
@dummy.save
|
@@ -357,7 +355,7 @@ describe Paperclip::Storage::Fog do
|
|
357
355
|
context "with scheme not set" do
|
358
356
|
before do
|
359
357
|
rebuild_model(@options)
|
360
|
-
@file = File.new(fixture_file(
|
358
|
+
@file = File.new(fixture_file("5k.png"), "rb")
|
361
359
|
@dummy = Dummy.new
|
362
360
|
@dummy.avatar = @file
|
363
361
|
@dummy.save
|
@@ -372,7 +370,7 @@ describe Paperclip::Storage::Fog do
|
|
372
370
|
end
|
373
371
|
|
374
372
|
context "with a valid bucket name for a subdomain" do
|
375
|
-
before { @dummy.
|
373
|
+
before { allow(@dummy).to receive(:new_record?).and_return(false) }
|
376
374
|
|
377
375
|
it "provides an url in subdomain style" do
|
378
376
|
assert_match(/^https:\/\/papercliptests.s3.amazonaws.com\/avatars\/5k.png/, @dummy.avatar.url)
|
@@ -389,19 +387,19 @@ describe Paperclip::Storage::Fog do
|
|
389
387
|
offset = 1234
|
390
388
|
rebuild_model(@options)
|
391
389
|
dummy = Dummy.new
|
392
|
-
dummy.avatar = StringIO.new(
|
390
|
+
dummy.avatar = StringIO.new(".")
|
393
391
|
|
394
392
|
assert_equal dummy.avatar.expiring_url(offset),
|
395
|
-
|
393
|
+
dummy.avatar.expiring_url(Time.now + offset)
|
396
394
|
end
|
397
395
|
end
|
398
396
|
|
399
|
-
it
|
397
|
+
it "matches the default url if there is no assignment" do
|
400
398
|
dummy = Dummy.new
|
401
399
|
assert_equal dummy.avatar.url, dummy.avatar.expiring_url
|
402
400
|
end
|
403
401
|
|
404
|
-
it
|
402
|
+
it "matches the default url when given a style if there is no assignment" do
|
405
403
|
dummy = Dummy.new
|
406
404
|
assert_equal dummy.avatar.url(:thumb), dummy.avatar.expiring_url(3600, :thumb)
|
407
405
|
end
|
@@ -429,15 +427,14 @@ describe Paperclip::Storage::Fog do
|
|
429
427
|
it "provides a url that expires in folder style" do
|
430
428
|
assert_match(/^https:\/\/s3.amazonaws.com\/this_is_invalid\/avatars\/5k.png.+Expires=.+$/, @dummy.avatar.expiring_url)
|
431
429
|
end
|
432
|
-
|
433
430
|
end
|
434
431
|
|
435
432
|
context "with a proc for a bucket name evaluating a model method" do
|
436
433
|
before do
|
437
|
-
@dynamic_fog_directory =
|
434
|
+
@dynamic_fog_directory = "dynamicpaperclip"
|
438
435
|
rebuild_model(@options.merge(fog_directory: lambda { |attachment| attachment.instance.bucket_name }))
|
439
436
|
@dummy = Dummy.new
|
440
|
-
@dummy.
|
437
|
+
allow(@dummy).to receive(:bucket_name).and_return(@dynamic_fog_directory)
|
441
438
|
@dummy.avatar = @file
|
442
439
|
@dummy.save
|
443
440
|
end
|
@@ -455,7 +452,7 @@ describe Paperclip::Storage::Fog do
|
|
455
452
|
before do
|
456
453
|
rebuild_model(@options.merge(fog_host: lambda { |attachment| attachment.instance.fog_host }))
|
457
454
|
@dummy = Dummy.new
|
458
|
-
@dummy.
|
455
|
+
allow(@dummy).to receive(:fog_host).and_return("http://dynamicfoghost.com")
|
459
456
|
@dummy.avatar = @file
|
460
457
|
@dummy.save
|
461
458
|
end
|
@@ -463,7 +460,6 @@ describe Paperclip::Storage::Fog do
|
|
463
460
|
it "provides a public url" do
|
464
461
|
assert_match(/http:\/\/dynamicfoghost\.com/, @dummy.avatar.url)
|
465
462
|
end
|
466
|
-
|
467
463
|
end
|
468
464
|
|
469
465
|
context "with a custom fog_host" do
|
@@ -484,7 +480,7 @@ describe Paperclip::Storage::Fog do
|
|
484
480
|
|
485
481
|
context "with an invalid bucket name for a subdomain" do
|
486
482
|
before do
|
487
|
-
rebuild_model(@options.merge(
|
483
|
+
rebuild_model(@options.merge(fog_directory: "this_is_invalid", fog_host: "http://dynamicfoghost.com"))
|
488
484
|
@dummy = Dummy.new
|
489
485
|
@dummy.avatar = @file
|
490
486
|
@dummy.save
|
@@ -494,19 +490,18 @@ describe Paperclip::Storage::Fog do
|
|
494
490
|
assert_match(/http:\/\/dynamicfoghost\.com/, @dummy.avatar.expiring_url)
|
495
491
|
end
|
496
492
|
end
|
497
|
-
|
498
493
|
end
|
499
494
|
|
500
495
|
context "with a proc for the fog_credentials evaluating a model method" do
|
501
496
|
before do
|
502
497
|
@dynamic_fog_credentials = {
|
503
|
-
provider:
|
504
|
-
aws_access_key_id:
|
505
|
-
aws_secret_access_key:
|
498
|
+
provider: "AWS",
|
499
|
+
aws_access_key_id: "DYNAMIC_ID",
|
500
|
+
aws_secret_access_key: "DYNAMIC_SECRET"
|
506
501
|
}
|
507
502
|
rebuild_model(@options.merge(fog_credentials: lambda { |attachment| attachment.instance.fog_credentials }))
|
508
503
|
@dummy = Dummy.new
|
509
|
-
@dummy.
|
504
|
+
allow(@dummy).to receive(:fog_credentials).and_return(@dynamic_fog_credentials)
|
510
505
|
@dummy.avatar = @file
|
511
506
|
@dummy.save
|
512
507
|
end
|
@@ -519,23 +514,22 @@ describe Paperclip::Storage::Fog do
|
|
519
514
|
context "with custom fog_options" do
|
520
515
|
before do
|
521
516
|
rebuild_model(
|
522
|
-
@options.merge(fog_options: { multipart_chunk_size: 104857600 })
|
517
|
+
@options.merge(fog_options: { multipart_chunk_size: 104857600 })
|
523
518
|
)
|
524
519
|
@dummy = Dummy.new
|
525
520
|
@dummy.avatar = @file
|
526
521
|
end
|
527
522
|
|
528
523
|
it "applies the options to the fog #create call" do
|
529
|
-
files =
|
530
|
-
@dummy.avatar.
|
531
|
-
files.
|
532
|
-
|
524
|
+
files = double
|
525
|
+
allow(@dummy.avatar).to receive(:directory).and_return double(files: files)
|
526
|
+
expect(files).to receive(:create).with(
|
527
|
+
hash_including(multipart_chunk_size: 104857600)
|
533
528
|
)
|
534
529
|
@dummy.save
|
535
530
|
end
|
536
531
|
end
|
537
532
|
end
|
538
|
-
|
539
533
|
end
|
540
534
|
|
541
535
|
context "when using local storage" do
|
@@ -543,15 +537,15 @@ describe Paperclip::Storage::Fog do
|
|
543
537
|
Fog.unmock!
|
544
538
|
rebuild_model styles: { medium: "300x300>", thumb: "100x100>" },
|
545
539
|
storage: :fog,
|
546
|
-
url:
|
540
|
+
url: "/:attachment/:filename",
|
547
541
|
fog_directory: "paperclip",
|
548
542
|
fog_credentials: { provider: :local, local_root: "." },
|
549
|
-
fog_host:
|
543
|
+
fog_host: "localhost"
|
550
544
|
|
551
|
-
@file = File.new(fixture_file(
|
545
|
+
@file = File.new(fixture_file("5k.png"), "rb")
|
552
546
|
@dummy = Dummy.new
|
553
547
|
@dummy.avatar = @file
|
554
|
-
@dummy.
|
548
|
+
allow(@dummy).to receive(:new_record?).and_return(false)
|
555
549
|
end
|
556
550
|
|
557
551
|
after do
|
@@ -1,7 +1,7 @@
|
|
1
|
-
require
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
3
|
unless ENV["S3_BUCKET"].blank?
|
4
|
-
describe Paperclip::Storage::S3,
|
4
|
+
describe Paperclip::Storage::S3, "Live S3" do
|
5
5
|
context "when assigning an S3 attachment directly to another model" do
|
6
6
|
before do
|
7
7
|
rebuild_model styles: { thumb: "100x100", square: "32x32#" },
|
@@ -10,8 +10,8 @@ unless ENV["S3_BUCKET"].blank?
|
|
10
10
|
path: ":class/:attachment/:id/:style.:extension",
|
11
11
|
s3_region: ENV["S3_REGION"],
|
12
12
|
s3_credentials: {
|
13
|
-
access_key_id: ENV[
|
14
|
-
secret_access_key: ENV[
|
13
|
+
access_key_id: ENV["AWS_ACCESS_KEY_ID"],
|
14
|
+
secret_access_key: ENV["AWS_SECRET_ACCESS_KEY"]
|
15
15
|
}
|
16
16
|
|
17
17
|
@file = File.new(fixture_file("5k.png"))
|
@@ -48,8 +48,8 @@ unless ENV["S3_BUCKET"].blank?
|
|
48
48
|
path: ":class/:attachment/:id/:style.:extension",
|
49
49
|
s3_region: ENV["S3_REGION"],
|
50
50
|
s3_credentials: {
|
51
|
-
access_key_id: ENV[
|
52
|
-
secret_access_key: ENV[
|
51
|
+
access_key_id: ENV["AWS_ACCESS_KEY_ID"],
|
52
|
+
secret_access_key: ENV["AWS_SECRET_ACCESS_KEY"]
|
53
53
|
}
|
54
54
|
|
55
55
|
@dummy = Dummy.new
|
@@ -68,8 +68,8 @@ unless ENV["S3_BUCKET"].blank?
|
|
68
68
|
path: ":class/:attachment/:id/:style.:extension",
|
69
69
|
s3_region: ENV["S3_REGION"],
|
70
70
|
s3_credentials: {
|
71
|
-
access_key_id: ENV[
|
72
|
-
secret_access_key: ENV[
|
71
|
+
access_key_id: ENV["AWS_ACCESS_KEY_ID"],
|
72
|
+
secret_access_key: ENV["AWS_SECRET_ACCESS_KEY"]
|
73
73
|
}
|
74
74
|
|
75
75
|
Dummy.delete_all
|
@@ -82,7 +82,7 @@ unless ENV["S3_BUCKET"].blank?
|
|
82
82
|
|
83
83
|
context "when assigned" do
|
84
84
|
before do
|
85
|
-
@file = File.new(fixture_file(
|
85
|
+
@file = File.new(fixture_file("5k.png"), "rb")
|
86
86
|
@dummy.avatar = @file
|
87
87
|
end
|
88
88
|
|
@@ -106,18 +106,18 @@ unless ENV["S3_BUCKET"].blank?
|
|
106
106
|
context "An attachment that uses S3 for storage and has spaces in file name" do
|
107
107
|
before do
|
108
108
|
rebuild_model styles: { thumb: "100x100", square: "32x32#" },
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
109
|
+
storage: :s3,
|
110
|
+
bucket: ENV["S3_BUCKET"],
|
111
|
+
s3_region: ENV["S3_REGION"],
|
112
|
+
url: ":s3_domain_url",
|
113
|
+
path: "/:class/:attachment/:id_partition/:style/:filename",
|
114
|
+
s3_credentials: {
|
115
|
+
access_key_id: ENV["AWS_ACCESS_KEY_ID"],
|
116
|
+
secret_access_key: ENV["AWS_SECRET_ACCESS_KEY"]
|
117
|
+
}
|
118
118
|
|
119
119
|
Dummy.delete_all
|
120
|
-
@file = File.new(fixture_file(
|
120
|
+
@file = File.new(fixture_file("spaced file.png"), "rb")
|
121
121
|
@dummy = Dummy.new
|
122
122
|
@dummy.avatar = @file
|
123
123
|
@dummy.save
|
@@ -154,8 +154,8 @@ unless ENV["S3_BUCKET"].blank?
|
|
154
154
|
path: ":class/:attachment/:id/:style.:extension",
|
155
155
|
s3_region: ENV["S3_REGION"],
|
156
156
|
s3_credentials: {
|
157
|
-
access_key_id: ENV[
|
158
|
-
secret_access_key: ENV[
|
157
|
+
access_key_id: ENV["AWS_ACCESS_KEY_ID"],
|
158
|
+
secret_access_key: ENV["AWS_SECRET_ACCESS_KEY"]
|
159
159
|
},
|
160
160
|
s3_server_side_encryption: "AES256"
|
161
161
|
Dummy.delete_all
|
@@ -164,7 +164,7 @@ unless ENV["S3_BUCKET"].blank?
|
|
164
164
|
|
165
165
|
context "when assigned" do
|
166
166
|
before do
|
167
|
-
@file = File.new(fixture_file(
|
167
|
+
@file = File.new(fixture_file("5k.png"), "rb")
|
168
168
|
@dummy.avatar = @file
|
169
169
|
end
|
170
170
|
|