kt-paperclip 5.4.0 → 7.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/FUNDING.yml +3 -0
- data/.github/ISSUE_TEMPLATE/bug_report.md +38 -0
- data/.github/ISSUE_TEMPLATE/custom.md +10 -0
- data/.github/ISSUE_TEMPLATE/feature_request.md +20 -0
- data/.hound.yml +3 -1055
- data/.rubocop.yml +1061 -1
- data/.travis.yml +23 -4
- data/Appraisals +23 -0
- data/CONTRIBUTING.md +4 -5
- data/Gemfile +10 -7
- data/NEWS +52 -0
- data/README.md +58 -46
- 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 +23 -13
- 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/gemfiles/6.1.gemfile +21 -0
- data/gemfiles/7.0.gemfile +21 -0
- data/lib/generators/paperclip/paperclip_generator.rb +6 -8
- data/lib/paperclip/attachment.rb +103 -105
- data/lib/paperclip/attachment_registry.rb +2 -2
- data/lib/paperclip/content_type_detector.rb +10 -5
- 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 +1 -1
- 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 +21 -9
- 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 +16 -12
- data/lib/paperclip/storage/filesystem.rb +6 -8
- data/lib/paperclip/storage/fog.rb +36 -32
- data/lib/paperclip/storage/s3.rb +68 -76
- 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 -5
- data/lib/paperclip/validators/attachment_content_type_validator.rb +11 -4
- data/lib/paperclip/validators/attachment_file_name_validator.rb +14 -12
- 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 +28 -11
- data/lib/paperclip/validators/media_type_spoof_detection_validator.rb +3 -1
- data/lib/paperclip/validators.rb +16 -17
- 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 +18 -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 +58 -37
- 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 +90 -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 +29 -6
- data/spec/paperclip/storage/fog_spec.rb +122 -82
- data/spec/paperclip/storage/s3_live_spec.rb +22 -22
- data/spec/paperclip/storage/s3_spec.rb +649 -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 -19
- data/spec/paperclip/validators/attachment_content_type_validator_spec.rb +115 -27
- data/spec/paperclip/validators/attachment_file_name_validator_spec.rb +105 -16
- data/spec/paperclip/validators/attachment_presence_validator_spec.rb +5 -5
- data/spec/paperclip/validators/attachment_size_validator_spec.rb +111 -21
- data/spec/paperclip/validators/media_type_spoof_detection_validator_spec.rb +9 -13
- data/spec/paperclip/validators_spec.rb +61 -46
- 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/fixtures/aws_s3.yml +13 -0
- data/spec/support/fixtures/sample.xlsm +0 -0
- 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 +58 -106
- data/spec/support/conditional_filter_helper.rb +0 -5
@@ -1,20 +1,66 @@
|
|
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
|
8
8
|
before { Fog.mock! }
|
9
9
|
|
10
|
+
context "deleting attachment styles" do
|
11
|
+
before do
|
12
|
+
rebuild_model styles: { medium: "300x300>", thumb: "100x100>" },
|
13
|
+
storage: :fog,
|
14
|
+
url: "/:attachment/:style/:filename",
|
15
|
+
fog_directory: "paperclip",
|
16
|
+
fog_credentials: fixture_file("fog.yml")
|
17
|
+
@file = File.open(fixture_file("5k.png"))
|
18
|
+
@dummy = Dummy.new
|
19
|
+
@dummy.avatar = @file
|
20
|
+
@dummy.save
|
21
|
+
end
|
22
|
+
|
23
|
+
after do
|
24
|
+
@file.close
|
25
|
+
FileUtils.rm_rf("tmp")
|
26
|
+
end
|
27
|
+
|
28
|
+
it "only issues a delete call once for each unique attachment style when nullifying attachment" do
|
29
|
+
@dummy.avatar.clear(:thumb)
|
30
|
+
@dummy.avatar = nil
|
31
|
+
assert_equal 4, @dummy.avatar.queued_for_delete.size
|
32
|
+
|
33
|
+
original = double("original")
|
34
|
+
medium = double("medium")
|
35
|
+
thumb = double("thumb")
|
36
|
+
|
37
|
+
allow(Fog::AWS::Storage::File).to receive(:new).and_return(original, medium, thumb)
|
38
|
+
|
39
|
+
expect(original).to receive(:destroy).once
|
40
|
+
expect(medium).to receive(:destroy).once
|
41
|
+
expect(thumb).to receive(:destroy).once
|
42
|
+
@dummy.save
|
43
|
+
end
|
44
|
+
|
45
|
+
it "only issues a delete call once for each unique attachment style when destroying model" do
|
46
|
+
@dummy.avatar.clear(:thumb)
|
47
|
+
assert_equal 1, @dummy.avatar.queued_for_delete.size
|
48
|
+
|
49
|
+
file = double("file")
|
50
|
+
allow(Fog::AWS::Storage::File).to receive(:new).and_return(file)
|
51
|
+
expect(file).to receive(:destroy).exactly(3).times
|
52
|
+
@dummy.destroy
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
10
56
|
context "with credentials provided in a path string" do
|
11
57
|
before do
|
12
58
|
rebuild_model styles: { medium: "300x300>", thumb: "100x100>" },
|
13
59
|
storage: :fog,
|
14
|
-
url:
|
60
|
+
url: "/:attachment/:filename",
|
15
61
|
fog_directory: "paperclip",
|
16
|
-
fog_credentials: fixture_file(
|
17
|
-
@file = File.new(fixture_file(
|
62
|
+
fog_credentials: fixture_file("fog.yml")
|
63
|
+
@file = File.new(fixture_file("5k.png"), "rb")
|
18
64
|
@dummy = Dummy.new
|
19
65
|
@dummy.avatar = @file
|
20
66
|
end
|
@@ -22,7 +68,7 @@ describe Paperclip::Storage::Fog do
|
|
22
68
|
after { @file.close }
|
23
69
|
|
24
70
|
it "has the proper information loading credentials from a file" do
|
25
|
-
assert_equal @dummy.avatar.fog_credentials[:provider],
|
71
|
+
assert_equal @dummy.avatar.fog_credentials[:provider], "AWS"
|
26
72
|
end
|
27
73
|
end
|
28
74
|
|
@@ -30,10 +76,10 @@ describe Paperclip::Storage::Fog do
|
|
30
76
|
before do
|
31
77
|
rebuild_model styles: { medium: "300x300>", thumb: "100x100>" },
|
32
78
|
storage: :fog,
|
33
|
-
url:
|
79
|
+
url: "/:attachment/:filename",
|
34
80
|
fog_directory: "paperclip",
|
35
|
-
fog_credentials: File.open(fixture_file(
|
36
|
-
@file = File.new(fixture_file(
|
81
|
+
fog_credentials: File.open(fixture_file("fog.yml"))
|
82
|
+
@file = File.new(fixture_file("5k.png"), "rb")
|
37
83
|
@dummy = Dummy.new
|
38
84
|
@dummy.avatar = @file
|
39
85
|
end
|
@@ -41,7 +87,7 @@ describe Paperclip::Storage::Fog do
|
|
41
87
|
after { @file.close }
|
42
88
|
|
43
89
|
it "has the proper information loading credentials from a file" do
|
44
|
-
assert_equal @dummy.avatar.fog_credentials[:provider],
|
90
|
+
assert_equal @dummy.avatar.fog_credentials[:provider], "AWS"
|
45
91
|
end
|
46
92
|
end
|
47
93
|
|
@@ -49,14 +95,14 @@ describe Paperclip::Storage::Fog do
|
|
49
95
|
before do
|
50
96
|
rebuild_model styles: { medium: "300x300>", thumb: "100x100>" },
|
51
97
|
storage: :fog,
|
52
|
-
url:
|
98
|
+
url: "/:attachment/:filename",
|
53
99
|
fog_directory: "paperclip",
|
54
100
|
fog_credentials: {
|
55
|
-
provider:
|
56
|
-
aws_access_key_id:
|
57
|
-
aws_secret_access_key:
|
101
|
+
provider: "AWS",
|
102
|
+
aws_access_key_id: "AWS_ID",
|
103
|
+
aws_secret_access_key: "AWS_SECRET"
|
58
104
|
}
|
59
|
-
@file = File.new(fixture_file(
|
105
|
+
@file = File.new(fixture_file("5k.png"), "rb")
|
60
106
|
@dummy = Dummy.new
|
61
107
|
@dummy.avatar = @file
|
62
108
|
end
|
@@ -65,7 +111,7 @@ describe Paperclip::Storage::Fog do
|
|
65
111
|
|
66
112
|
it "is able to interpolate the path without blowing up" do
|
67
113
|
assert_equal File.expand_path(File.join(File.dirname(__FILE__), "../../../tmp/public/avatars/5k.png")),
|
68
|
-
|
114
|
+
@dummy.avatar.path
|
69
115
|
end
|
70
116
|
end
|
71
117
|
|
@@ -75,11 +121,11 @@ describe Paperclip::Storage::Fog do
|
|
75
121
|
storage: :fog,
|
76
122
|
fog_directory: "paperclip",
|
77
123
|
fog_credentials: {
|
78
|
-
provider:
|
79
|
-
aws_access_key_id:
|
80
|
-
aws_secret_access_key:
|
124
|
+
provider: "AWS",
|
125
|
+
aws_access_key_id: "AWS_ID",
|
126
|
+
aws_secret_access_key: "AWS_SECRET"
|
81
127
|
}
|
82
|
-
@file = File.new(fixture_file(
|
128
|
+
@file = File.new(fixture_file("5k.png"), "rb")
|
83
129
|
@dummy = Dummy.new
|
84
130
|
@dummy.id = 1
|
85
131
|
@dummy.avatar = @file
|
@@ -94,32 +140,31 @@ describe Paperclip::Storage::Fog do
|
|
94
140
|
|
95
141
|
context "with file params provided as lambda" do
|
96
142
|
before do
|
97
|
-
fog_file = lambda{ |a| { custom_header: a.instance.custom_method }}
|
143
|
+
fog_file = lambda { |a| { custom_header: a.instance.custom_method } }
|
98
144
|
klass = rebuild_model storage: :fog,
|
99
145
|
fog_file: fog_file
|
100
146
|
|
101
147
|
klass.class_eval do
|
102
148
|
def custom_method
|
103
|
-
|
149
|
+
"foobar"
|
104
150
|
end
|
105
151
|
end
|
106
152
|
|
107
|
-
|
108
153
|
@dummy = Dummy.new
|
109
154
|
end
|
110
155
|
|
111
156
|
it "is able to evaluate correct values for file headers" do
|
112
|
-
assert_equal @dummy.avatar.send(:fog_file),
|
157
|
+
assert_equal @dummy.avatar.send(:fog_file), custom_header: "foobar"
|
113
158
|
end
|
114
159
|
end
|
115
160
|
|
116
161
|
before do
|
117
|
-
@fog_directory =
|
162
|
+
@fog_directory = "papercliptests"
|
118
163
|
|
119
164
|
@credentials = {
|
120
|
-
provider:
|
121
|
-
aws_access_key_id:
|
122
|
-
aws_secret_access_key:
|
165
|
+
provider: "AWS",
|
166
|
+
aws_access_key_id: "ID",
|
167
|
+
aws_secret_access_key: "SECRET"
|
123
168
|
}
|
124
169
|
|
125
170
|
@connection = Fog::Storage.new(@credentials)
|
@@ -131,7 +176,7 @@ describe Paperclip::Storage::Fog do
|
|
131
176
|
fog_directory: @fog_directory,
|
132
177
|
fog_credentials: @credentials,
|
133
178
|
fog_host: nil,
|
134
|
-
fog_file: {cache_control: 1234},
|
179
|
+
fog_file: { cache_control: 1234 },
|
135
180
|
path: ":attachment/:basename:dotextension",
|
136
181
|
storage: :fog
|
137
182
|
}
|
@@ -145,7 +190,7 @@ describe Paperclip::Storage::Fog do
|
|
145
190
|
|
146
191
|
context "when assigned" do
|
147
192
|
before do
|
148
|
-
@file = File.new(fixture_file(
|
193
|
+
@file = File.new(fixture_file("5k.png"), "rb")
|
149
194
|
@dummy = Dummy.new
|
150
195
|
@dummy.avatar = @file
|
151
196
|
end
|
@@ -153,7 +198,7 @@ describe Paperclip::Storage::Fog do
|
|
153
198
|
after do
|
154
199
|
@file.close
|
155
200
|
directory = @connection.directories.new(key: @fog_directory)
|
156
|
-
directory.files.each
|
201
|
+
directory.files.each(&:destroy)
|
157
202
|
directory.destroy
|
158
203
|
end
|
159
204
|
|
@@ -168,11 +213,11 @@ describe Paperclip::Storage::Fog do
|
|
168
213
|
it "is removed after after_flush_writes" do
|
169
214
|
paths = @dummy.avatar.queued_for_write.values.map(&:path)
|
170
215
|
@dummy.save
|
171
|
-
assert paths.none?{ |path| File.exist?(path) },
|
172
|
-
|
216
|
+
assert paths.none? { |path| File.exist?(path) },
|
217
|
+
"Expect all the files to be deleted."
|
173
218
|
end
|
174
219
|
|
175
|
-
it
|
220
|
+
it "is able to be copied to a local file" do
|
176
221
|
@dummy.save
|
177
222
|
tempfile = Tempfile.new("known_location")
|
178
223
|
tempfile.binmode
|
@@ -183,7 +228,7 @@ describe Paperclip::Storage::Fog do
|
|
183
228
|
tempfile.close
|
184
229
|
end
|
185
230
|
|
186
|
-
it
|
231
|
+
it "is able to be handled when missing while copying to a local file" do
|
187
232
|
tempfile = Tempfile.new("known_location")
|
188
233
|
tempfile.binmode
|
189
234
|
assert_equal false, @dummy.avatar.copy_to_local_file(:original, tempfile.path)
|
@@ -191,9 +236,7 @@ describe Paperclip::Storage::Fog do
|
|
191
236
|
end
|
192
237
|
|
193
238
|
it "passes the content type to the Fog::Storage::AWS::Files instance" do
|
194
|
-
Fog::Storage::AWS::Files.
|
195
|
-
hash[:content_type]
|
196
|
-
end
|
239
|
+
expect_any_instance_of(Fog::Storage::AWS::Files).to receive(:create).with(hash_including(:content_type))
|
197
240
|
@dummy.save
|
198
241
|
end
|
199
242
|
|
@@ -223,7 +266,7 @@ describe Paperclip::Storage::Fog do
|
|
223
266
|
before do
|
224
267
|
rebuild_model(@options.merge(fog_host: nil))
|
225
268
|
@dummy = Dummy.new
|
226
|
-
@dummy.avatar = StringIO.new(
|
269
|
+
@dummy.avatar = StringIO.new(".")
|
227
270
|
@dummy.save
|
228
271
|
end
|
229
272
|
|
@@ -234,7 +277,7 @@ describe Paperclip::Storage::Fog do
|
|
234
277
|
|
235
278
|
context "with a fog_host" do
|
236
279
|
before do
|
237
|
-
rebuild_model(@options.merge(fog_host:
|
280
|
+
rebuild_model(@options.merge(fog_host: "http://example.com"))
|
238
281
|
@dummy = Dummy.new
|
239
282
|
@dummy.avatar = StringIO.new(".\n")
|
240
283
|
@dummy.save
|
@@ -250,7 +293,7 @@ describe Paperclip::Storage::Fog do
|
|
250
293
|
rebuild_model(
|
251
294
|
fog_directory: @fog_directory,
|
252
295
|
fog_credentials: @credentials,
|
253
|
-
fog_host:
|
296
|
+
fog_host: "http://img%d.example.com",
|
254
297
|
path: ":attachment/:basename:dotextension",
|
255
298
|
storage: :fog
|
256
299
|
)
|
@@ -268,12 +311,12 @@ describe Paperclip::Storage::Fog do
|
|
268
311
|
before do
|
269
312
|
rebuild_model(@options.merge(fog_public: false))
|
270
313
|
@dummy = Dummy.new
|
271
|
-
@dummy.avatar = StringIO.new(
|
314
|
+
@dummy.avatar = StringIO.new(".")
|
272
315
|
@dummy.save
|
273
316
|
end
|
274
317
|
|
275
|
-
it
|
276
|
-
assert_equal false, @dummy.avatar.instance_variable_get(
|
318
|
+
it "sets the @fog_public instance variable to false" do
|
319
|
+
assert_equal false, @dummy.avatar.instance_variable_get("@options")[:fog_public]
|
277
320
|
assert_equal false, @dummy.avatar.fog_public
|
278
321
|
end
|
279
322
|
end
|
@@ -297,28 +340,29 @@ describe Paperclip::Storage::Fog do
|
|
297
340
|
context "with styles set and fog_public set to false" do
|
298
341
|
before do
|
299
342
|
rebuild_model(@options.merge(fog_public: false, styles: { medium: "300x300>", thumb: "100x100>" }))
|
300
|
-
@file = File.new(fixture_file(
|
343
|
+
@file = File.new(fixture_file("5k.png"), "rb")
|
301
344
|
@dummy = Dummy.new
|
302
345
|
@dummy.avatar = @file
|
303
346
|
@dummy.save
|
304
347
|
end
|
305
348
|
|
306
|
-
it
|
307
|
-
assert_equal false, @dummy.avatar.instance_variable_get(
|
349
|
+
it "sets the @fog_public for a particular style to false" do
|
350
|
+
assert_equal false, @dummy.avatar.instance_variable_get("@options")[:fog_public]
|
308
351
|
assert_equal false, @dummy.avatar.fog_public(:thumb)
|
309
352
|
end
|
310
353
|
end
|
311
354
|
|
312
355
|
context "with styles set and fog_public set per-style" do
|
313
356
|
before do
|
314
|
-
rebuild_model(@options.merge(fog_public: { medium: false, thumb: true},
|
315
|
-
|
357
|
+
rebuild_model(@options.merge(fog_public: { medium: false, thumb: true },
|
358
|
+
styles: { medium: "300x300>", thumb: "100x100>" }))
|
359
|
+
@file = File.new(fixture_file("5k.png"), "rb")
|
316
360
|
@dummy = Dummy.new
|
317
361
|
@dummy.avatar = @file
|
318
362
|
@dummy.save
|
319
363
|
end
|
320
364
|
|
321
|
-
it
|
365
|
+
it "sets the fog_public for a particular style to correct value" do
|
322
366
|
assert_equal false, @dummy.avatar.fog_public(:medium)
|
323
367
|
assert_equal true, @dummy.avatar.fog_public(:thumb)
|
324
368
|
end
|
@@ -328,7 +372,7 @@ describe Paperclip::Storage::Fog do
|
|
328
372
|
before do
|
329
373
|
rebuild_model(@options)
|
330
374
|
@dummy = Dummy.new
|
331
|
-
@dummy.avatar = StringIO.new(
|
375
|
+
@dummy.avatar = StringIO.new(".")
|
332
376
|
@dummy.save
|
333
377
|
end
|
334
378
|
|
@@ -339,8 +383,8 @@ describe Paperclip::Storage::Fog do
|
|
339
383
|
|
340
384
|
context "with scheme set" do
|
341
385
|
before do
|
342
|
-
rebuild_model(@options.merge(:
|
343
|
-
@file = File.new(fixture_file(
|
386
|
+
rebuild_model(@options.merge(fog_credentials: @credentials.merge(scheme: "http")))
|
387
|
+
@file = File.new(fixture_file("5k.png"), "rb")
|
344
388
|
@dummy = Dummy.new
|
345
389
|
@dummy.avatar = @file
|
346
390
|
@dummy.save
|
@@ -357,7 +401,7 @@ describe Paperclip::Storage::Fog do
|
|
357
401
|
context "with scheme not set" do
|
358
402
|
before do
|
359
403
|
rebuild_model(@options)
|
360
|
-
@file = File.new(fixture_file(
|
404
|
+
@file = File.new(fixture_file("5k.png"), "rb")
|
361
405
|
@dummy = Dummy.new
|
362
406
|
@dummy.avatar = @file
|
363
407
|
@dummy.save
|
@@ -372,7 +416,7 @@ describe Paperclip::Storage::Fog do
|
|
372
416
|
end
|
373
417
|
|
374
418
|
context "with a valid bucket name for a subdomain" do
|
375
|
-
before { @dummy.
|
419
|
+
before { allow(@dummy).to receive(:new_record?).and_return(false) }
|
376
420
|
|
377
421
|
it "provides an url in subdomain style" do
|
378
422
|
assert_match(/^https:\/\/papercliptests.s3.amazonaws.com\/avatars\/5k.png/, @dummy.avatar.url)
|
@@ -389,19 +433,19 @@ describe Paperclip::Storage::Fog do
|
|
389
433
|
offset = 1234
|
390
434
|
rebuild_model(@options)
|
391
435
|
dummy = Dummy.new
|
392
|
-
dummy.avatar = StringIO.new(
|
436
|
+
dummy.avatar = StringIO.new(".")
|
393
437
|
|
394
438
|
assert_equal dummy.avatar.expiring_url(offset),
|
395
|
-
|
439
|
+
dummy.avatar.expiring_url(Time.now + offset)
|
396
440
|
end
|
397
441
|
end
|
398
442
|
|
399
|
-
it
|
443
|
+
it "matches the default url if there is no assignment" do
|
400
444
|
dummy = Dummy.new
|
401
445
|
assert_equal dummy.avatar.url, dummy.avatar.expiring_url
|
402
446
|
end
|
403
447
|
|
404
|
-
it
|
448
|
+
it "matches the default url when given a style if there is no assignment" do
|
405
449
|
dummy = Dummy.new
|
406
450
|
assert_equal dummy.avatar.url(:thumb), dummy.avatar.expiring_url(3600, :thumb)
|
407
451
|
end
|
@@ -429,15 +473,14 @@ describe Paperclip::Storage::Fog do
|
|
429
473
|
it "provides a url that expires in folder style" do
|
430
474
|
assert_match(/^https:\/\/s3.amazonaws.com\/this_is_invalid\/avatars\/5k.png.+Expires=.+$/, @dummy.avatar.expiring_url)
|
431
475
|
end
|
432
|
-
|
433
476
|
end
|
434
477
|
|
435
478
|
context "with a proc for a bucket name evaluating a model method" do
|
436
479
|
before do
|
437
|
-
@dynamic_fog_directory =
|
480
|
+
@dynamic_fog_directory = "dynamicpaperclip"
|
438
481
|
rebuild_model(@options.merge(fog_directory: lambda { |attachment| attachment.instance.bucket_name }))
|
439
482
|
@dummy = Dummy.new
|
440
|
-
@dummy.
|
483
|
+
allow(@dummy).to receive(:bucket_name).and_return(@dynamic_fog_directory)
|
441
484
|
@dummy.avatar = @file
|
442
485
|
@dummy.save
|
443
486
|
end
|
@@ -455,7 +498,7 @@ describe Paperclip::Storage::Fog do
|
|
455
498
|
before do
|
456
499
|
rebuild_model(@options.merge(fog_host: lambda { |attachment| attachment.instance.fog_host }))
|
457
500
|
@dummy = Dummy.new
|
458
|
-
@dummy.
|
501
|
+
allow(@dummy).to receive(:fog_host).and_return("http://dynamicfoghost.com")
|
459
502
|
@dummy.avatar = @file
|
460
503
|
@dummy.save
|
461
504
|
end
|
@@ -463,7 +506,6 @@ describe Paperclip::Storage::Fog do
|
|
463
506
|
it "provides a public url" do
|
464
507
|
assert_match(/http:\/\/dynamicfoghost\.com/, @dummy.avatar.url)
|
465
508
|
end
|
466
|
-
|
467
509
|
end
|
468
510
|
|
469
511
|
context "with a custom fog_host" do
|
@@ -484,7 +526,7 @@ describe Paperclip::Storage::Fog do
|
|
484
526
|
|
485
527
|
context "with an invalid bucket name for a subdomain" do
|
486
528
|
before do
|
487
|
-
rebuild_model(@options.merge(
|
529
|
+
rebuild_model(@options.merge(fog_directory: "this_is_invalid", fog_host: "http://dynamicfoghost.com"))
|
488
530
|
@dummy = Dummy.new
|
489
531
|
@dummy.avatar = @file
|
490
532
|
@dummy.save
|
@@ -494,19 +536,18 @@ describe Paperclip::Storage::Fog do
|
|
494
536
|
assert_match(/http:\/\/dynamicfoghost\.com/, @dummy.avatar.expiring_url)
|
495
537
|
end
|
496
538
|
end
|
497
|
-
|
498
539
|
end
|
499
540
|
|
500
541
|
context "with a proc for the fog_credentials evaluating a model method" do
|
501
542
|
before do
|
502
543
|
@dynamic_fog_credentials = {
|
503
|
-
provider:
|
504
|
-
aws_access_key_id:
|
505
|
-
aws_secret_access_key:
|
544
|
+
provider: "AWS",
|
545
|
+
aws_access_key_id: "DYNAMIC_ID",
|
546
|
+
aws_secret_access_key: "DYNAMIC_SECRET"
|
506
547
|
}
|
507
548
|
rebuild_model(@options.merge(fog_credentials: lambda { |attachment| attachment.instance.fog_credentials }))
|
508
549
|
@dummy = Dummy.new
|
509
|
-
@dummy.
|
550
|
+
allow(@dummy).to receive(:fog_credentials).and_return(@dynamic_fog_credentials)
|
510
551
|
@dummy.avatar = @file
|
511
552
|
@dummy.save
|
512
553
|
end
|
@@ -519,23 +560,22 @@ describe Paperclip::Storage::Fog do
|
|
519
560
|
context "with custom fog_options" do
|
520
561
|
before do
|
521
562
|
rebuild_model(
|
522
|
-
@options.merge(fog_options: { multipart_chunk_size: 104857600 })
|
563
|
+
@options.merge(fog_options: { multipart_chunk_size: 104857600 })
|
523
564
|
)
|
524
565
|
@dummy = Dummy.new
|
525
566
|
@dummy.avatar = @file
|
526
567
|
end
|
527
568
|
|
528
569
|
it "applies the options to the fog #create call" do
|
529
|
-
files =
|
530
|
-
@dummy.avatar.
|
531
|
-
files.
|
532
|
-
|
570
|
+
files = double
|
571
|
+
allow(@dummy.avatar).to receive(:directory).and_return double(files: files)
|
572
|
+
expect(files).to receive(:create).with(
|
573
|
+
hash_including(multipart_chunk_size: 104857600)
|
533
574
|
)
|
534
575
|
@dummy.save
|
535
576
|
end
|
536
577
|
end
|
537
578
|
end
|
538
|
-
|
539
579
|
end
|
540
580
|
|
541
581
|
context "when using local storage" do
|
@@ -543,15 +583,15 @@ describe Paperclip::Storage::Fog do
|
|
543
583
|
Fog.unmock!
|
544
584
|
rebuild_model styles: { medium: "300x300>", thumb: "100x100>" },
|
545
585
|
storage: :fog,
|
546
|
-
url:
|
586
|
+
url: "/:attachment/:filename",
|
547
587
|
fog_directory: "paperclip",
|
548
588
|
fog_credentials: { provider: :local, local_root: "." },
|
549
|
-
fog_host:
|
589
|
+
fog_host: "localhost"
|
550
590
|
|
551
|
-
@file = File.new(fixture_file(
|
591
|
+
@file = File.new(fixture_file("5k.png"), "rb")
|
552
592
|
@dummy = Dummy.new
|
553
593
|
@dummy.avatar = @file
|
554
|
-
@dummy.
|
594
|
+
allow(@dummy).to receive(:new_record?).and_return(false)
|
555
595
|
end
|
556
596
|
|
557
597
|
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
|
|