paperclip 4.1.1 → 4.2.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.
- checksums.yaml +4 -4
- data/.gitignore +0 -6
- data/.travis.yml +4 -13
- data/Appraisals +0 -10
- data/CONTRIBUTING.md +10 -5
- data/Gemfile +8 -4
- data/NEWS +1 -1
- data/README.md +51 -10
- data/Rakefile +6 -8
- data/features/basic_integration.feature +5 -5
- data/features/step_definitions/attachment_steps.rb +4 -4
- data/features/step_definitions/rails_steps.rb +4 -4
- data/features/step_definitions/web_steps.rb +2 -2
- data/features/support/env.rb +2 -2
- data/features/support/fixtures/gemfile.txt +1 -1
- data/features/support/rails.rb +2 -1
- data/gemfiles/3.2.gemfile +5 -3
- data/gemfiles/4.0.gemfile +5 -3
- data/gemfiles/4.1.gemfile +5 -3
- data/lib/generators/paperclip/paperclip_generator.rb +0 -2
- data/lib/generators/paperclip/templates/paperclip_migration.rb.erb +1 -1
- data/lib/paperclip.rb +4 -1
- data/lib/paperclip/attachment.rb +90 -29
- data/lib/paperclip/content_type_detector.rb +1 -1
- data/lib/paperclip/geometry_detector_factory.rb +3 -1
- data/lib/paperclip/has_attached_file.rb +2 -1
- data/lib/paperclip/interpolations.rb +8 -0
- data/lib/paperclip/io_adapters/abstract_adapter.rb +1 -1
- data/lib/paperclip/io_adapters/data_uri_adapter.rb +1 -1
- data/lib/paperclip/io_adapters/stringio_adapter.rb +5 -11
- data/lib/paperclip/locales/de.yml +18 -0
- data/lib/paperclip/locales/es.yml +18 -0
- data/lib/paperclip/matchers/have_attached_file_matcher.rb +2 -1
- data/lib/paperclip/matchers/validate_attachment_presence_matcher.rb +2 -1
- data/lib/paperclip/matchers/validate_attachment_size_matcher.rb +2 -1
- data/lib/paperclip/media_type_spoof_detector.rb +10 -2
- data/lib/paperclip/storage/filesystem.rb +1 -1
- data/lib/paperclip/storage/s3.rb +26 -4
- data/lib/paperclip/style.rb +1 -1
- data/lib/paperclip/thumbnail.rb +6 -6
- data/lib/paperclip/validators.rb +5 -3
- data/lib/paperclip/validators/attachment_size_validator.rb +7 -3
- data/lib/paperclip/version.rb +1 -1
- data/lib/tasks/paperclip.rake +1 -2
- data/paperclip.gemspec +5 -3
- data/shoulda_macros/paperclip.rb +0 -1
- data/{test → spec}/database.yml +0 -0
- data/spec/paperclip/attachment_definitions_spec.rb +13 -0
- data/{test/attachment_processing_test.rb → spec/paperclip/attachment_processing_spec.rb} +20 -21
- data/{test/attachment_registry_test.rb → spec/paperclip/attachment_registry_spec.rb} +10 -11
- data/{test/attachment_test.rb → spec/paperclip/attachment_spec.rb} +367 -360
- data/{test/content_type_detector_test.rb → spec/paperclip/content_type_detector_spec.rb} +8 -8
- data/{test/file_command_content_type_detector_test.rb → spec/paperclip/file_command_content_type_detector_spec.rb} +5 -5
- data/spec/paperclip/filename_cleaner_spec.rb +14 -0
- data/spec/paperclip/geometry_detector_spec.rb +39 -0
- data/{test/geometry_parser_test.rb → spec/paperclip/geometry_parser_spec.rb} +27 -27
- data/{test/geometry_test.rb → spec/paperclip/geometry_spec.rb} +49 -51
- data/{test/has_attached_file_test.rb → spec/paperclip/has_attached_file_spec.rb} +18 -27
- data/{test/integration_test.rb → spec/paperclip/integration_spec.rb} +134 -126
- data/{test/interpolations_test.rb → spec/paperclip/interpolations_spec.rb} +54 -40
- data/{test/io_adapters/abstract_adapter_test.rb → spec/paperclip/io_adapters/abstract_adapter_spec.rb} +21 -10
- data/{test/io_adapters/attachment_adapter_test.rb → spec/paperclip/io_adapters/attachment_adapter_spec.rb} +27 -29
- data/{test/io_adapters/data_uri_adapter_test.rb → spec/paperclip/io_adapters/data_uri_adapter_spec.rb} +22 -18
- data/spec/paperclip/io_adapters/empty_string_adapter_spec.rb +17 -0
- data/{test/io_adapters/file_adapter_test.rb → spec/paperclip/io_adapters/file_adapter_spec.rb} +32 -28
- data/{test/io_adapters/http_url_proxy_adapter_test.rb → spec/paperclip/io_adapters/http_url_proxy_adapter_spec.rb} +22 -22
- data/spec/paperclip/io_adapters/identity_adapter_spec.rb +8 -0
- data/{test/io_adapters/nil_adapter_test.rb → spec/paperclip/io_adapters/nil_adapter_spec.rb} +7 -7
- data/{test/io_adapters/registry_test.rb → spec/paperclip/io_adapters/registry_spec.rb} +10 -7
- data/{test/io_adapters/stringio_adapter_test.rb → spec/paperclip/io_adapters/stringio_adapter_spec.rb} +16 -17
- data/{test/io_adapters/uploaded_file_adapter_test.rb → spec/paperclip/io_adapters/uploaded_file_adapter_spec.rb} +41 -41
- data/{test/io_adapters/uri_adapter_test.rb → spec/paperclip/io_adapters/uri_adapter_spec.rb} +22 -22
- data/spec/paperclip/matchers/have_attached_file_matcher_spec.rb +19 -0
- data/spec/paperclip/matchers/validate_attachment_content_type_matcher_spec.rb +99 -0
- data/spec/paperclip/matchers/validate_attachment_presence_matcher_spec.rb +69 -0
- data/spec/paperclip/matchers/validate_attachment_size_matcher_spec.rb +88 -0
- data/{test/media_type_spoof_detector_test.rb → spec/paperclip/media_type_spoof_detector_spec.rb} +13 -8
- data/spec/paperclip/meta_class_spec.rb +30 -0
- data/spec/paperclip/paperclip_missing_attachment_styles_spec.rb +84 -0
- data/{test/paperclip_test.rb → spec/paperclip/paperclip_spec.rb} +47 -47
- data/{test/plural_cache_test.rb → spec/paperclip/plural_cache_spec.rb} +6 -6
- data/{test/processor_test.rb → spec/paperclip/processor_spec.rb} +5 -5
- data/{test/rake_test.rb → spec/paperclip/rake_spec.rb} +15 -15
- data/spec/paperclip/schema_spec.rb +206 -0
- data/{test/storage/filesystem_test.rb → spec/paperclip/storage/filesystem_spec.rb} +18 -18
- data/{test/storage/fog_test.rb → spec/paperclip/storage/fog_spec.rb} +145 -140
- data/spec/paperclip/storage/s3_live_spec.rb +182 -0
- data/spec/paperclip/storage/s3_spec.rb +1475 -0
- data/spec/paperclip/style_spec.rb +255 -0
- data/spec/paperclip/tempfile_factory_spec.rb +29 -0
- data/{test/thumbnail_test.rb → spec/paperclip/thumbnail_spec.rb} +107 -107
- data/{test/url_generator_test.rb → spec/paperclip/url_generator_spec.rb} +55 -56
- data/spec/paperclip/validators/attachment_content_type_validator_spec.rb +322 -0
- data/spec/paperclip/validators/attachment_file_name_validator_spec.rb +160 -0
- data/{test/validators/attachment_presence_validator_test.rb → spec/paperclip/validators/attachment_presence_validator_spec.rb} +19 -19
- data/{test/validators/attachment_size_validator_test.rb → spec/paperclip/validators/attachment_size_validator_spec.rb} +65 -58
- data/{test/validators/media_type_spoof_detection_validator_test.rb → spec/paperclip/validators/media_type_spoof_detection_validator_spec.rb} +8 -8
- data/spec/paperclip/validators_spec.rb +164 -0
- data/spec/spec_helper.rb +40 -0
- data/spec/support/assertions.rb +71 -0
- data/spec/support/fake_model.rb +21 -0
- data/spec/support/fake_rails.rb +12 -0
- data/{test → spec/support}/fixtures/12k.png +0 -0
- data/{test → spec/support}/fixtures/50x50.png +0 -0
- data/{test → spec/support}/fixtures/5k.png +0 -0
- data/{test → spec/support}/fixtures/animated +0 -0
- data/{test → spec/support}/fixtures/animated.gif +0 -0
- data/{test → spec/support}/fixtures/animated.unknown +0 -0
- data/{test → spec/support}/fixtures/bad.png +0 -0
- data/{test → spec/support}/fixtures/empty.html +0 -0
- data/{test → spec/support}/fixtures/fog.yml +0 -0
- data/{test → spec/support}/fixtures/rotated.jpg +0 -0
- data/{test → spec/support}/fixtures/s3.yml +0 -0
- data/spec/support/fixtures/spaced file.jpg +0 -0
- data/test/fixtures/spaced file.png b/data/spec/support/fixtures/spaced → file.png +0 -0
- data/{test → spec/support}/fixtures/text.txt +0 -0
- data/{test → spec/support}/fixtures/twopage.pdf +0 -0
- data/{test → spec/support}/fixtures/uppercase.PNG +0 -0
- data/spec/support/matchers/accept.rb +5 -0
- data/spec/support/matchers/exist.rb +5 -0
- data/{test → spec}/support/mock_attachment.rb +0 -0
- data/{test → spec}/support/mock_interpolator.rb +0 -0
- data/{test → spec}/support/mock_model.rb +0 -0
- data/{test → spec}/support/mock_url_generator_builder.rb +0 -0
- data/spec/support/model_reconstruction.rb +60 -0
- data/spec/support/rails_helpers.rb +7 -0
- data/spec/support/test_data.rb +13 -0
- data/spec/support/version_helper.rb +9 -0
- metadata +256 -210
- data/gemfiles/3.0.gemfile +0 -11
- data/gemfiles/3.1.gemfile +0 -11
- data/test/attachment_definitions_test.rb +0 -13
- data/test/filename_cleaner_test.rb +0 -14
- data/test/generator_test.rb +0 -84
- data/test/geometry_detector_test.rb +0 -24
- data/test/helper.rb +0 -239
- data/test/io_adapters/empty_string_adapter_test.rb +0 -18
- data/test/io_adapters/identity_adapter_test.rb +0 -8
- data/test/matchers/have_attached_file_matcher_test.rb +0 -25
- data/test/matchers/validate_attachment_content_type_matcher_test.rb +0 -111
- data/test/matchers/validate_attachment_presence_matcher_test.rb +0 -70
- data/test/matchers/validate_attachment_size_matcher_test.rb +0 -87
- data/test/meta_class_test.rb +0 -32
- data/test/paperclip_missing_attachment_styles_test.rb +0 -90
- data/test/schema_test.rb +0 -206
- data/test/storage/s3_live_test.rb +0 -179
- data/test/storage/s3_test.rb +0 -1357
- data/test/style_test.rb +0 -251
- data/test/tempfile_factory_test.rb +0 -29
- data/test/validators/attachment_content_type_validator_test.rb +0 -324
- data/test/validators/attachment_file_name_validator_test.rb +0 -162
- data/test/validators_test.rb +0 -101
@@ -1,81 +1,82 @@
|
|
1
|
-
require '
|
1
|
+
require 'spec_helper'
|
2
2
|
require 'fog'
|
3
|
+
require 'timecop'
|
3
4
|
|
4
|
-
|
5
|
+
describe Paperclip::Storage::Fog do
|
5
6
|
context "" do
|
6
|
-
|
7
|
+
before { Fog.mock! }
|
7
8
|
|
8
9
|
context "with credentials provided in a path string" do
|
9
|
-
|
10
|
-
rebuild_model :
|
11
|
-
:
|
12
|
-
:
|
13
|
-
:
|
14
|
-
:
|
10
|
+
before do
|
11
|
+
rebuild_model styles: { medium: "300x300>", thumb: "100x100>" },
|
12
|
+
storage: :fog,
|
13
|
+
url: '/:attachment/:filename',
|
14
|
+
fog_directory: "paperclip",
|
15
|
+
fog_credentials: fixture_file('fog.yml')
|
15
16
|
@file = File.new(fixture_file('5k.png'), 'rb')
|
16
17
|
@dummy = Dummy.new
|
17
18
|
@dummy.avatar = @file
|
18
19
|
end
|
19
20
|
|
20
|
-
|
21
|
+
after { @file.close }
|
21
22
|
|
22
|
-
|
23
|
+
it "has the proper information loading credentials from a file" do
|
23
24
|
assert_equal @dummy.avatar.fog_credentials[:provider], 'AWS'
|
24
25
|
end
|
25
26
|
end
|
26
27
|
|
27
28
|
context "with credentials provided in a File object" do
|
28
|
-
|
29
|
-
rebuild_model :
|
30
|
-
:
|
31
|
-
:
|
32
|
-
:
|
33
|
-
:
|
29
|
+
before do
|
30
|
+
rebuild_model styles: { medium: "300x300>", thumb: "100x100>" },
|
31
|
+
storage: :fog,
|
32
|
+
url: '/:attachment/:filename',
|
33
|
+
fog_directory: "paperclip",
|
34
|
+
fog_credentials: File.open(fixture_file('fog.yml'))
|
34
35
|
@file = File.new(fixture_file('5k.png'), 'rb')
|
35
36
|
@dummy = Dummy.new
|
36
37
|
@dummy.avatar = @file
|
37
38
|
end
|
38
39
|
|
39
|
-
|
40
|
+
after { @file.close }
|
40
41
|
|
41
|
-
|
42
|
+
it "has the proper information loading credentials from a file" do
|
42
43
|
assert_equal @dummy.avatar.fog_credentials[:provider], 'AWS'
|
43
44
|
end
|
44
45
|
end
|
45
46
|
|
46
47
|
context "with default values for path and url" do
|
47
|
-
|
48
|
-
rebuild_model :
|
49
|
-
:
|
50
|
-
:
|
51
|
-
:
|
52
|
-
:
|
53
|
-
:
|
54
|
-
:
|
55
|
-
:
|
48
|
+
before do
|
49
|
+
rebuild_model styles: { medium: "300x300>", thumb: "100x100>" },
|
50
|
+
storage: :fog,
|
51
|
+
url: '/:attachment/:filename',
|
52
|
+
fog_directory: "paperclip",
|
53
|
+
fog_credentials: {
|
54
|
+
provider: 'AWS',
|
55
|
+
aws_access_key_id: 'AWS_ID',
|
56
|
+
aws_secret_access_key: 'AWS_SECRET'
|
56
57
|
}
|
57
58
|
@file = File.new(fixture_file('5k.png'), 'rb')
|
58
59
|
@dummy = Dummy.new
|
59
60
|
@dummy.avatar = @file
|
60
61
|
end
|
61
62
|
|
62
|
-
|
63
|
+
after { @file.close }
|
63
64
|
|
64
|
-
|
65
|
-
assert_equal File.expand_path(File.join(File.dirname(__FILE__), "
|
66
|
-
|
65
|
+
it "is able to interpolate the path without blowing up" do
|
66
|
+
assert_equal File.expand_path(File.join(File.dirname(__FILE__), "../../../tmp/public/avatars/5k.png")),
|
67
|
+
@dummy.avatar.path
|
67
68
|
end
|
68
69
|
end
|
69
70
|
|
70
71
|
context "with no path or url given and using defaults" do
|
71
|
-
|
72
|
-
rebuild_model :
|
73
|
-
:
|
74
|
-
:
|
75
|
-
:
|
76
|
-
:
|
77
|
-
:
|
78
|
-
:
|
72
|
+
before do
|
73
|
+
rebuild_model styles: { medium: "300x300>", thumb: "100x100>" },
|
74
|
+
storage: :fog,
|
75
|
+
fog_directory: "paperclip",
|
76
|
+
fog_credentials: {
|
77
|
+
provider: 'AWS',
|
78
|
+
aws_access_key_id: 'AWS_ID',
|
79
|
+
aws_secret_access_key: 'AWS_SECRET'
|
79
80
|
}
|
80
81
|
@file = File.new(fixture_file('5k.png'), 'rb')
|
81
82
|
@dummy = Dummy.new
|
@@ -83,18 +84,18 @@ class FogTest < Test::Unit::TestCase
|
|
83
84
|
@dummy.avatar = @file
|
84
85
|
end
|
85
86
|
|
86
|
-
|
87
|
+
after { @file.close }
|
87
88
|
|
88
|
-
|
89
|
+
it "has correct path and url from interpolated defaults" do
|
89
90
|
assert_equal "dummies/avatars/000/000/001/original/5k.png", @dummy.avatar.path
|
90
91
|
end
|
91
92
|
end
|
92
93
|
|
93
94
|
context "with file params provided as lambda" do
|
94
|
-
|
95
|
-
fog_file = lambda{ |a| { :
|
96
|
-
klass = rebuild_model :
|
97
|
-
:
|
95
|
+
before do
|
96
|
+
fog_file = lambda{ |a| { custom_header: a.instance.custom_method }}
|
97
|
+
klass = rebuild_model storage: :fog,
|
98
|
+
fog_file: fog_file
|
98
99
|
|
99
100
|
klass.class_eval do
|
100
101
|
def custom_method
|
@@ -106,56 +107,56 @@ class FogTest < Test::Unit::TestCase
|
|
106
107
|
@dummy = Dummy.new
|
107
108
|
end
|
108
109
|
|
109
|
-
|
110
|
-
assert_equal @dummy.avatar.send(:fog_file), { :
|
110
|
+
it "is able to evaluate correct values for file headers" do
|
111
|
+
assert_equal @dummy.avatar.send(:fog_file), { custom_header: 'foobar' }
|
111
112
|
end
|
112
113
|
end
|
113
114
|
|
114
|
-
|
115
|
+
before do
|
115
116
|
@fog_directory = 'papercliptests'
|
116
117
|
|
117
118
|
@credentials = {
|
118
|
-
:
|
119
|
-
:
|
120
|
-
:
|
119
|
+
provider: 'AWS',
|
120
|
+
aws_access_key_id: 'ID',
|
121
|
+
aws_secret_access_key: 'SECRET'
|
121
122
|
}
|
122
123
|
|
123
124
|
@connection = Fog::Storage.new(@credentials)
|
124
125
|
@connection.directories.create(
|
125
|
-
:
|
126
|
+
key: @fog_directory
|
126
127
|
)
|
127
128
|
|
128
129
|
@options = {
|
129
|
-
:
|
130
|
-
:
|
131
|
-
:
|
132
|
-
:
|
133
|
-
:
|
134
|
-
:
|
130
|
+
fog_directory: @fog_directory,
|
131
|
+
fog_credentials: @credentials,
|
132
|
+
fog_host: nil,
|
133
|
+
fog_file: {cache_control: 1234},
|
134
|
+
path: ":attachment/:basename:dotextension",
|
135
|
+
storage: :fog
|
135
136
|
}
|
136
137
|
|
137
138
|
rebuild_model(@options)
|
138
139
|
end
|
139
140
|
|
140
|
-
|
141
|
+
it "is extended by the Fog module" do
|
141
142
|
assert Dummy.new.avatar.is_a?(Paperclip::Storage::Fog)
|
142
143
|
end
|
143
144
|
|
144
145
|
context "when assigned" do
|
145
|
-
|
146
|
+
before do
|
146
147
|
@file = File.new(fixture_file('5k.png'), 'rb')
|
147
148
|
@dummy = Dummy.new
|
148
149
|
@dummy.avatar = @file
|
149
150
|
end
|
150
151
|
|
151
|
-
|
152
|
+
after do
|
152
153
|
@file.close
|
153
|
-
directory = @connection.directories.new(:
|
154
|
+
directory = @connection.directories.new(key: @fog_directory)
|
154
155
|
directory.files.each {|file| file.destroy}
|
155
156
|
directory.destroy
|
156
157
|
end
|
157
158
|
|
158
|
-
|
159
|
+
it "is rewound after flush_writes" do
|
159
160
|
@dummy.avatar.instance_eval "def after_flush_writes; end"
|
160
161
|
|
161
162
|
files = @dummy.avatar.queued_for_write.values
|
@@ -163,14 +164,14 @@ class FogTest < Test::Unit::TestCase
|
|
163
164
|
assert files.none?(&:eof?), "Expect all the files to be rewinded."
|
164
165
|
end
|
165
166
|
|
166
|
-
|
167
|
+
it "is removed after after_flush_writes" do
|
167
168
|
paths = @dummy.avatar.queued_for_write.values.map(&:path)
|
168
169
|
@dummy.save
|
169
|
-
assert paths.none?{ |path| File.
|
170
|
+
assert paths.none?{ |path| File.exist?(path) },
|
170
171
|
"Expect all the files to be deleted."
|
171
172
|
end
|
172
173
|
|
173
|
-
|
174
|
+
it 'is able to be copied to a local file' do
|
174
175
|
@dummy.save
|
175
176
|
tempfile = Tempfile.new("known_location")
|
176
177
|
tempfile.binmode
|
@@ -181,7 +182,7 @@ class FogTest < Test::Unit::TestCase
|
|
181
182
|
tempfile.close
|
182
183
|
end
|
183
184
|
|
184
|
-
|
185
|
+
it "passes the content type to the Fog::Storage::AWS::Files instance" do
|
185
186
|
Fog::Storage::AWS::Files.any_instance.expects(:create).with do |hash|
|
186
187
|
hash[:content_type]
|
187
188
|
end
|
@@ -189,235 +190,239 @@ class FogTest < Test::Unit::TestCase
|
|
189
190
|
end
|
190
191
|
|
191
192
|
context "without a bucket" do
|
192
|
-
|
193
|
+
before do
|
193
194
|
@connection.directories.get(@fog_directory).destroy
|
194
195
|
end
|
195
196
|
|
196
|
-
|
197
|
+
it "creates the bucket" do
|
197
198
|
assert @dummy.save
|
198
199
|
assert @connection.directories.get(@fog_directory)
|
199
200
|
end
|
200
201
|
end
|
201
202
|
|
202
203
|
context "with a bucket" do
|
203
|
-
|
204
|
+
it "succeeds" do
|
204
205
|
assert @dummy.save
|
205
206
|
end
|
206
207
|
end
|
207
208
|
|
208
209
|
context "without a fog_host" do
|
209
|
-
|
210
|
-
rebuild_model(@options.merge(:
|
210
|
+
before do
|
211
|
+
rebuild_model(@options.merge(fog_host: nil))
|
211
212
|
@dummy = Dummy.new
|
212
213
|
@dummy.avatar = StringIO.new('.')
|
213
214
|
@dummy.save
|
214
215
|
end
|
215
216
|
|
216
|
-
|
217
|
+
it "provides a public url" do
|
217
218
|
assert !@dummy.avatar.url.nil?
|
218
219
|
end
|
219
220
|
end
|
220
221
|
|
221
222
|
context "with a fog_host" do
|
222
|
-
|
223
|
-
rebuild_model(@options.merge(:
|
223
|
+
before do
|
224
|
+
rebuild_model(@options.merge(fog_host: 'http://example.com'))
|
224
225
|
@dummy = Dummy.new
|
225
226
|
@dummy.avatar = StringIO.new(".\n")
|
226
227
|
@dummy.save
|
227
228
|
end
|
228
229
|
|
229
|
-
|
230
|
-
|
230
|
+
it "provides a public url" do
|
231
|
+
expect(@dummy.avatar.url).to match(/^http:\/\/example\.com\/avatars\/data\?\d*$/)
|
231
232
|
end
|
232
233
|
end
|
233
234
|
|
234
235
|
context "with a fog_host that includes a wildcard placeholder" do
|
235
|
-
|
236
|
+
before do
|
236
237
|
rebuild_model(
|
237
|
-
:
|
238
|
-
:
|
239
|
-
:
|
240
|
-
:
|
241
|
-
:
|
238
|
+
fog_directory: @fog_directory,
|
239
|
+
fog_credentials: @credentials,
|
240
|
+
fog_host: 'http://img%d.example.com',
|
241
|
+
path: ":attachment/:basename:dotextension",
|
242
|
+
storage: :fog
|
242
243
|
)
|
243
244
|
@dummy = Dummy.new
|
244
245
|
@dummy.avatar = StringIO.new(".\n")
|
245
246
|
@dummy.save
|
246
247
|
end
|
247
248
|
|
248
|
-
|
249
|
-
|
249
|
+
it "provides a public url" do
|
250
|
+
expect(@dummy.avatar.url).to match(/^http:\/\/img[0123]\.example\.com\/avatars\/data\?\d*$/)
|
250
251
|
end
|
251
252
|
end
|
252
253
|
|
253
254
|
context "with fog_public set to false" do
|
254
|
-
|
255
|
-
rebuild_model(@options.merge(:
|
255
|
+
before do
|
256
|
+
rebuild_model(@options.merge(fog_public: false))
|
256
257
|
@dummy = Dummy.new
|
257
258
|
@dummy.avatar = StringIO.new('.')
|
258
259
|
@dummy.save
|
259
260
|
end
|
260
261
|
|
261
|
-
|
262
|
+
it 'sets the @fog_public instance variable to false' do
|
262
263
|
assert_equal false, @dummy.avatar.instance_variable_get('@options')[:fog_public]
|
263
264
|
assert_equal false, @dummy.avatar.fog_public
|
264
265
|
end
|
265
266
|
end
|
266
267
|
|
267
268
|
context "with styles set and fog_public set to false" do
|
268
|
-
|
269
|
-
rebuild_model(@options.merge(:
|
269
|
+
before do
|
270
|
+
rebuild_model(@options.merge(fog_public: false, styles: { medium: "300x300>", thumb: "100x100>" }))
|
270
271
|
@file = File.new(fixture_file('5k.png'), 'rb')
|
271
272
|
@dummy = Dummy.new
|
272
273
|
@dummy.avatar = @file
|
273
274
|
@dummy.save
|
274
275
|
end
|
275
276
|
|
276
|
-
|
277
|
+
it 'sets the @fog_public for a particular style to false' do
|
277
278
|
assert_equal false, @dummy.avatar.instance_variable_get('@options')[:fog_public]
|
278
279
|
assert_equal false, @dummy.avatar.fog_public(:thumb)
|
279
280
|
end
|
280
281
|
end
|
281
282
|
|
282
283
|
context "with styles set and fog_public set per-style" do
|
283
|
-
|
284
|
-
rebuild_model(@options.merge(:
|
284
|
+
before do
|
285
|
+
rebuild_model(@options.merge(fog_public: { medium: false, thumb: true}, styles: { medium: "300x300>", thumb: "100x100>" }))
|
285
286
|
@file = File.new(fixture_file('5k.png'), 'rb')
|
286
287
|
@dummy = Dummy.new
|
287
288
|
@dummy.avatar = @file
|
288
289
|
@dummy.save
|
289
290
|
end
|
290
291
|
|
291
|
-
|
292
|
+
it 'sets the fog_public for a particular style to correct value' do
|
292
293
|
assert_equal false, @dummy.avatar.fog_public(:medium)
|
293
294
|
assert_equal true, @dummy.avatar.fog_public(:thumb)
|
294
295
|
end
|
295
296
|
end
|
296
297
|
|
297
298
|
context "with fog_public not set" do
|
298
|
-
|
299
|
+
before do
|
299
300
|
rebuild_model(@options)
|
300
301
|
@dummy = Dummy.new
|
301
302
|
@dummy.avatar = StringIO.new('.')
|
302
303
|
@dummy.save
|
303
304
|
end
|
304
305
|
|
305
|
-
|
306
|
+
it "defaults fog_public to true" do
|
306
307
|
assert_equal true, @dummy.avatar.fog_public
|
307
308
|
end
|
308
309
|
end
|
309
310
|
|
310
311
|
context "with a valid bucket name for a subdomain" do
|
311
|
-
|
312
|
+
it "provides an url in subdomain style" do
|
312
313
|
assert_match(/^https:\/\/papercliptests.s3.amazonaws.com\/avatars\/5k.png/, @dummy.avatar.url)
|
313
314
|
end
|
314
315
|
|
315
|
-
|
316
|
+
it "provides an url that expires in subdomain style" do
|
316
317
|
assert_match(/^http:\/\/papercliptests.s3.amazonaws.com\/avatars\/5k.png\?AWSAccessKeyId=.+$/, @dummy.avatar.expiring_url)
|
317
318
|
end
|
318
319
|
end
|
319
320
|
|
320
321
|
context "generating an expiring url" do
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
322
|
+
it "generates the same url when using Times and Integer offsets" do
|
323
|
+
Timecop.freeze do
|
324
|
+
offset = 1234
|
325
|
+
rebuild_model(@options)
|
326
|
+
dummy = Dummy.new
|
327
|
+
dummy.avatar = StringIO.new('.')
|
328
|
+
|
329
|
+
assert_equal dummy.avatar.expiring_url(offset),
|
330
|
+
dummy.avatar.expiring_url(Time.now + offset )
|
331
|
+
end
|
327
332
|
end
|
328
333
|
|
329
|
-
|
334
|
+
it 'matches the default url if there is no assignment' do
|
330
335
|
dummy = Dummy.new
|
331
336
|
assert_equal dummy.avatar.url, dummy.avatar.expiring_url
|
332
337
|
end
|
333
338
|
|
334
|
-
|
339
|
+
it 'matches the default url when given a style if there is no assignment' do
|
335
340
|
dummy = Dummy.new
|
336
341
|
assert_equal dummy.avatar.url(:thumb), dummy.avatar.expiring_url(3600, :thumb)
|
337
342
|
end
|
338
343
|
end
|
339
344
|
|
340
345
|
context "with an invalid bucket name for a subdomain" do
|
341
|
-
|
342
|
-
rebuild_model(@options.merge(:
|
346
|
+
before do
|
347
|
+
rebuild_model(@options.merge(fog_directory: "this_is_invalid"))
|
343
348
|
@dummy = Dummy.new
|
344
349
|
@dummy.avatar = @file
|
345
350
|
@dummy.save
|
346
351
|
end
|
347
352
|
|
348
|
-
|
353
|
+
it "does not match the bucket-subdomain restrictions" do
|
349
354
|
invalid_subdomains = %w(this_is_invalid in iamareallylongbucketnameiamareallylongbucketnameiamareallylongbu invalid- inval..id inval-.id inval.-id -invalid 192.168.10.2)
|
350
355
|
invalid_subdomains.each do |name|
|
351
356
|
assert_no_match Paperclip::Storage::Fog::AWS_BUCKET_SUBDOMAIN_RESTRICTON_REGEX, name
|
352
357
|
end
|
353
358
|
end
|
354
359
|
|
355
|
-
|
360
|
+
it "provides an url in folder style" do
|
356
361
|
assert_match(/^https:\/\/s3.amazonaws.com\/this_is_invalid\/avatars\/5k.png\?\d*$/, @dummy.avatar.url)
|
357
362
|
end
|
358
363
|
|
359
|
-
|
364
|
+
it "provides a url that expires in folder style" do
|
360
365
|
assert_match(/^http:\/\/s3.amazonaws.com\/this_is_invalid\/avatars\/5k.png\?AWSAccessKeyId=.+$/, @dummy.avatar.expiring_url)
|
361
366
|
end
|
362
367
|
|
363
368
|
end
|
364
369
|
|
365
370
|
context "with a proc for a bucket name evaluating a model method" do
|
366
|
-
|
371
|
+
before do
|
367
372
|
@dynamic_fog_directory = 'dynamicpaperclip'
|
368
|
-
rebuild_model(@options.merge(:
|
373
|
+
rebuild_model(@options.merge(fog_directory: lambda { |attachment| attachment.instance.bucket_name }))
|
369
374
|
@dummy = Dummy.new
|
370
375
|
@dummy.stubs(:bucket_name).returns(@dynamic_fog_directory)
|
371
376
|
@dummy.avatar = @file
|
372
377
|
@dummy.save
|
373
378
|
end
|
374
379
|
|
375
|
-
|
380
|
+
it "has created the bucket" do
|
376
381
|
assert @connection.directories.get(@dynamic_fog_directory).inspect
|
377
382
|
end
|
378
383
|
|
379
384
|
end
|
380
385
|
|
381
386
|
context "with a proc for the fog_host evaluating a model method" do
|
382
|
-
|
383
|
-
rebuild_model(@options.merge(:
|
387
|
+
before do
|
388
|
+
rebuild_model(@options.merge(fog_host: lambda { |attachment| attachment.instance.fog_host }))
|
384
389
|
@dummy = Dummy.new
|
385
390
|
@dummy.stubs(:fog_host).returns('http://dynamicfoghost.com')
|
386
391
|
@dummy.avatar = @file
|
387
392
|
@dummy.save
|
388
393
|
end
|
389
394
|
|
390
|
-
|
395
|
+
it "provides a public url" do
|
391
396
|
assert_match(/http:\/\/dynamicfoghost\.com/, @dummy.avatar.url)
|
392
397
|
end
|
393
398
|
|
394
399
|
end
|
395
400
|
|
396
401
|
context "with a custom fog_host" do
|
397
|
-
|
398
|
-
rebuild_model(@options.merge(:
|
402
|
+
before do
|
403
|
+
rebuild_model(@options.merge(fog_host: "http://dynamicfoghost.com"))
|
399
404
|
@dummy = Dummy.new
|
400
405
|
@dummy.avatar = @file
|
401
406
|
@dummy.save
|
402
407
|
end
|
403
408
|
|
404
|
-
|
409
|
+
it "provides a public url" do
|
405
410
|
assert_match(/http:\/\/dynamicfoghost\.com/, @dummy.avatar.url)
|
406
411
|
end
|
407
412
|
|
408
|
-
|
413
|
+
it "provides an expiring url" do
|
409
414
|
assert_match(/http:\/\/dynamicfoghost\.com/, @dummy.avatar.expiring_url)
|
410
415
|
end
|
411
416
|
|
412
417
|
context "with an invalid bucket name for a subdomain" do
|
413
|
-
|
414
|
-
rebuild_model(@options.merge({:
|
418
|
+
before do
|
419
|
+
rebuild_model(@options.merge({fog_directory: "this_is_invalid", fog_host: "http://dynamicfoghost.com"}))
|
415
420
|
@dummy = Dummy.new
|
416
421
|
@dummy.avatar = @file
|
417
422
|
@dummy.save
|
418
423
|
end
|
419
424
|
|
420
|
-
|
425
|
+
it "provides an expiring url" do
|
421
426
|
assert_match(/http:\/\/dynamicfoghost\.com/, @dummy.avatar.expiring_url)
|
422
427
|
end
|
423
428
|
end
|
@@ -425,20 +430,20 @@ class FogTest < Test::Unit::TestCase
|
|
425
430
|
end
|
426
431
|
|
427
432
|
context "with a proc for the fog_credentials evaluating a model method" do
|
428
|
-
|
433
|
+
before do
|
429
434
|
@dynamic_fog_credentials = {
|
430
|
-
:
|
431
|
-
:
|
432
|
-
:
|
435
|
+
provider: 'AWS',
|
436
|
+
aws_access_key_id: 'DYNAMIC_ID',
|
437
|
+
aws_secret_access_key: 'DYNAMIC_SECRET'
|
433
438
|
}
|
434
|
-
rebuild_model(@options.merge(:
|
439
|
+
rebuild_model(@options.merge(fog_credentials: lambda { |attachment| attachment.instance.fog_credentials }))
|
435
440
|
@dummy = Dummy.new
|
436
441
|
@dummy.stubs(:fog_credentials).returns(@dynamic_fog_credentials)
|
437
442
|
@dummy.avatar = @file
|
438
443
|
@dummy.save
|
439
444
|
end
|
440
445
|
|
441
|
-
|
446
|
+
it "provides a public url" do
|
442
447
|
assert_equal @dummy.avatar.fog_credentials, @dynamic_fog_credentials
|
443
448
|
end
|
444
449
|
end
|
@@ -447,26 +452,26 @@ class FogTest < Test::Unit::TestCase
|
|
447
452
|
end
|
448
453
|
|
449
454
|
context "when using local storage" do
|
450
|
-
|
455
|
+
before do
|
451
456
|
Fog.unmock!
|
452
|
-
rebuild_model :
|
453
|
-
:
|
454
|
-
:
|
455
|
-
:
|
456
|
-
:
|
457
|
-
:
|
457
|
+
rebuild_model styles: { medium: "300x300>", thumb: "100x100>" },
|
458
|
+
storage: :fog,
|
459
|
+
url: '/:attachment/:filename',
|
460
|
+
fog_directory: "paperclip",
|
461
|
+
fog_credentials: { provider: :local, local_root: "." },
|
462
|
+
fog_host: 'localhost'
|
458
463
|
|
459
464
|
@file = File.new(fixture_file('5k.png'), 'rb')
|
460
465
|
@dummy = Dummy.new
|
461
466
|
@dummy.avatar = @file
|
462
467
|
end
|
463
468
|
|
464
|
-
|
469
|
+
after do
|
465
470
|
@file.close
|
466
471
|
Fog.mock!
|
467
472
|
end
|
468
473
|
|
469
|
-
|
474
|
+
it "returns the public url in place of the expiring url" do
|
470
475
|
assert_match @dummy.avatar.public_url, @dummy.avatar.expiring_url
|
471
476
|
end
|
472
477
|
end
|