paperclip 4.3.7 → 6.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.codeclimate.yml +17 -0
- data/.github/issue_template.md +3 -0
- data/.hound.yml +5 -16
- data/.travis.yml +15 -12
- data/Appraisals +4 -8
- data/CONTRIBUTING.md +16 -5
- data/Gemfile +3 -8
- data/LICENSE +1 -1
- data/MIGRATING-ES.md +317 -0
- data/MIGRATING.md +375 -0
- data/NEWS +126 -31
- data/README.md +264 -156
- data/Rakefile +1 -1
- data/UPGRADING +12 -9
- data/features/basic_integration.feature +3 -2
- data/features/migration.feature +0 -24
- data/features/step_definitions/attachment_steps.rb +14 -14
- data/features/step_definitions/rails_steps.rb +29 -28
- data/features/step_definitions/s3_steps.rb +2 -2
- data/features/support/env.rb +1 -0
- data/features/support/paths.rb +1 -1
- data/features/support/rails.rb +0 -24
- data/gemfiles/4.2.gemfile +3 -5
- data/gemfiles/{3.2.gemfile → 5.0.gemfile} +4 -6
- data/lib/generators/paperclip/paperclip_generator.rb +9 -1
- data/lib/generators/paperclip/templates/paperclip_migration.rb.erb +1 -1
- data/lib/paperclip.rb +14 -12
- data/lib/paperclip/attachment.rb +44 -20
- data/lib/paperclip/attachment_registry.rb +2 -1
- data/lib/paperclip/callbacks.rb +8 -6
- data/lib/paperclip/content_type_detector.rb +3 -2
- data/lib/paperclip/errors.rb +3 -1
- data/lib/paperclip/file_command_content_type_detector.rb +1 -1
- data/lib/paperclip/filename_cleaner.rb +0 -1
- data/lib/paperclip/geometry_detector_factory.rb +3 -3
- data/lib/paperclip/glue.rb +1 -1
- data/lib/paperclip/has_attached_file.rb +7 -1
- data/lib/paperclip/helpers.rb +15 -11
- data/lib/paperclip/interpolations.rb +7 -2
- data/lib/paperclip/io_adapters/abstract_adapter.rb +31 -4
- data/lib/paperclip/io_adapters/attachment_adapter.rb +17 -6
- data/lib/paperclip/io_adapters/data_uri_adapter.rb +8 -8
- data/lib/paperclip/io_adapters/empty_string_adapter.rb +5 -4
- data/lib/paperclip/io_adapters/file_adapter.rb +12 -6
- data/lib/paperclip/io_adapters/http_url_proxy_adapter.rb +8 -7
- data/lib/paperclip/io_adapters/identity_adapter.rb +12 -6
- data/lib/paperclip/io_adapters/nil_adapter.rb +8 -5
- data/lib/paperclip/io_adapters/registry.rb +6 -2
- data/lib/paperclip/io_adapters/stringio_adapter.rb +9 -6
- data/lib/paperclip/io_adapters/uploaded_file_adapter.rb +10 -6
- data/lib/paperclip/io_adapters/uri_adapter.rb +22 -17
- data/lib/paperclip/logger.rb +1 -1
- data/lib/paperclip/matchers/validate_attachment_content_type_matcher.rb +4 -4
- data/lib/paperclip/media_type_spoof_detector.rb +11 -7
- data/lib/paperclip/processor.rb +15 -6
- data/lib/paperclip/schema.rb +3 -9
- data/lib/paperclip/storage/filesystem.rb +13 -2
- data/lib/paperclip/storage/fog.rb +21 -14
- data/lib/paperclip/storage/s3.rb +81 -61
- data/lib/paperclip/style.rb +0 -1
- data/lib/paperclip/thumbnail.rb +22 -9
- data/lib/paperclip/url_generator.rb +17 -13
- data/lib/paperclip/validators.rb +1 -1
- data/lib/paperclip/validators/attachment_size_validator.rb +1 -7
- data/lib/paperclip/validators/media_type_spoof_detection_validator.rb +4 -0
- data/lib/paperclip/version.rb +3 -1
- data/lib/tasks/paperclip.rake +18 -4
- data/paperclip.gemspec +13 -10
- data/spec/paperclip/attachment_processing_spec.rb +2 -5
- data/spec/paperclip/attachment_registry_spec.rb +28 -0
- data/spec/paperclip/attachment_spec.rb +89 -20
- data/spec/paperclip/content_type_detector_spec.rb +1 -1
- data/spec/paperclip/file_command_content_type_detector_spec.rb +15 -1
- data/spec/paperclip/filename_cleaner_spec.rb +0 -1
- data/spec/paperclip/has_attached_file_spec.rb +24 -8
- data/spec/paperclip/integration_spec.rb +42 -5
- data/spec/paperclip/interpolations_spec.rb +9 -0
- data/spec/paperclip/io_adapters/abstract_adapter_spec.rb +104 -22
- data/spec/paperclip/io_adapters/attachment_adapter_spec.rb +6 -3
- data/spec/paperclip/io_adapters/data_uri_adapter_spec.rb +7 -1
- data/spec/paperclip/io_adapters/file_adapter_spec.rb +2 -2
- data/spec/paperclip/io_adapters/http_url_proxy_adapter_spec.rb +47 -13
- data/spec/paperclip/io_adapters/identity_adapter_spec.rb +1 -1
- data/spec/paperclip/io_adapters/registry_spec.rb +2 -2
- data/spec/paperclip/io_adapters/stringio_adapter_spec.rb +1 -1
- data/spec/paperclip/io_adapters/uploaded_file_adapter_spec.rb +5 -5
- data/spec/paperclip/io_adapters/uri_adapter_spec.rb +104 -11
- data/spec/paperclip/matchers/validate_attachment_content_type_matcher_spec.rb +10 -0
- data/spec/paperclip/matchers/validate_attachment_size_matcher_spec.rb +1 -1
- data/spec/paperclip/media_type_spoof_detector_spec.rb +41 -0
- data/spec/paperclip/paperclip_spec.rb +15 -45
- data/spec/paperclip/processor_spec.rb +4 -4
- data/spec/paperclip/schema_spec.rb +46 -46
- data/spec/paperclip/storage/fog_spec.rb +31 -0
- data/spec/paperclip/storage/s3_live_spec.rb +20 -14
- data/spec/paperclip/storage/s3_spec.rb +359 -192
- data/spec/paperclip/style_spec.rb +0 -1
- data/spec/paperclip/tempfile_spec.rb +35 -0
- data/spec/paperclip/thumbnail_spec.rb +43 -38
- data/spec/paperclip/url_generator_spec.rb +54 -44
- data/spec/paperclip/validators/attachment_size_validator_spec.rb +26 -20
- data/spec/paperclip/validators_spec.rb +5 -5
- data/spec/spec_helper.rb +5 -2
- data/spec/support/assertions.rb +12 -1
- data/spec/support/mock_attachment.rb +2 -0
- data/spec/support/mock_url_generator_builder.rb +2 -2
- data/spec/support/model_reconstruction.rb +11 -3
- data/spec/support/reporting.rb +11 -0
- metadata +64 -61
- data/cucumber/paperclip_steps.rb +0 -6
- data/gemfiles/4.1.gemfile +0 -19
- data/lib/paperclip/deprecations.rb +0 -42
- data/lib/paperclip/locales/de.yml +0 -18
- data/lib/paperclip/locales/es.yml +0 -18
- data/lib/paperclip/locales/ja.yml +0 -18
- data/lib/paperclip/locales/pt-BR.yml +0 -18
- data/lib/paperclip/locales/zh-CN.yml +0 -18
- data/lib/paperclip/locales/zh-HK.yml +0 -18
- data/lib/paperclip/locales/zh-TW.yml +0 -18
- data/spec/paperclip/deprecations_spec.rb +0 -65
- data/spec/support/deprecations.rb +0 -9
- data/spec/support/rails_helpers.rb +0 -7
@@ -0,0 +1,35 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Paperclip::Tempfile do
|
4
|
+
context "A Paperclip Tempfile" do
|
5
|
+
before do
|
6
|
+
@tempfile = described_class.new(["file", ".jpg"])
|
7
|
+
end
|
8
|
+
|
9
|
+
after { @tempfile.close }
|
10
|
+
|
11
|
+
it "has its path contain a real extension" do
|
12
|
+
assert_equal ".jpg", File.extname(@tempfile.path)
|
13
|
+
end
|
14
|
+
|
15
|
+
it "is a real Tempfile" do
|
16
|
+
assert @tempfile.is_a?(::Tempfile)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
context "Another Paperclip Tempfile" do
|
21
|
+
before do
|
22
|
+
@tempfile = described_class.new("file")
|
23
|
+
end
|
24
|
+
|
25
|
+
after { @tempfile.close }
|
26
|
+
|
27
|
+
it "does not have an extension if not given one" do
|
28
|
+
assert_equal "", File.extname(@tempfile.path)
|
29
|
+
end
|
30
|
+
|
31
|
+
it "is a real Tempfile" do
|
32
|
+
assert @tempfile.is_a?(::Tempfile)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -1,38 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Paperclip::Thumbnail do
|
4
|
-
context "A Paperclip Tempfile" do
|
5
|
-
before do
|
6
|
-
@tempfile = Paperclip::Tempfile.new(["file", ".jpg"])
|
7
|
-
end
|
8
|
-
|
9
|
-
after { @tempfile.close }
|
10
|
-
|
11
|
-
it "has its path contain a real extension" do
|
12
|
-
assert_equal ".jpg", File.extname(@tempfile.path)
|
13
|
-
end
|
14
|
-
|
15
|
-
it "is a real Tempfile" do
|
16
|
-
assert @tempfile.is_a?(::Tempfile)
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
context "Another Paperclip Tempfile" do
|
21
|
-
before do
|
22
|
-
@tempfile = Paperclip::Tempfile.new("file")
|
23
|
-
end
|
24
|
-
|
25
|
-
after { @tempfile.close }
|
26
|
-
|
27
|
-
it "does not have an extension if not given one" do
|
28
|
-
assert_equal "", File.extname(@tempfile.path)
|
29
|
-
end
|
30
|
-
|
31
|
-
it "is a real Tempfile" do
|
32
|
-
assert @tempfile.is_a?(::Tempfile)
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
4
|
context "An image" do
|
37
5
|
before do
|
38
6
|
@file = File.new(fixture_file("5k.png"), 'rb')
|
@@ -80,7 +48,7 @@ describe Paperclip::Thumbnail do
|
|
80
48
|
it "lets us know when a command isn't found versus a processing error" do
|
81
49
|
old_path = ENV['PATH']
|
82
50
|
begin
|
83
|
-
|
51
|
+
Terrapin::CommandLine.path = ''
|
84
52
|
Paperclip.options[:command_path] = ''
|
85
53
|
ENV['PATH'] = ''
|
86
54
|
assert_raises(Paperclip::Errors::CommandNotFoundError) do
|
@@ -134,7 +102,7 @@ describe Paperclip::Thumbnail do
|
|
134
102
|
|
135
103
|
output_file = thumb.make
|
136
104
|
|
137
|
-
command =
|
105
|
+
command = Terrapin::CommandLine.new("identify", "-format %wx%h :file")
|
138
106
|
assert_equal "50x50", command.run(file: output_file.path).strip
|
139
107
|
end
|
140
108
|
|
@@ -211,17 +179,19 @@ describe Paperclip::Thumbnail do
|
|
211
179
|
end
|
212
180
|
|
213
181
|
it "errors when trying to create the thumbnail" do
|
214
|
-
|
215
|
-
|
182
|
+
silence_stream(STDERR) do
|
183
|
+
expect {
|
216
184
|
@thumb.make
|
217
|
-
|
185
|
+
}.to raise_error(
|
186
|
+
Paperclip::Error, /unrecognized option `-this-aint-no-option'/
|
187
|
+
)
|
218
188
|
end
|
219
189
|
end
|
220
190
|
|
221
191
|
it "lets us know when a command isn't found versus a processing error" do
|
222
192
|
old_path = ENV['PATH']
|
223
193
|
begin
|
224
|
-
|
194
|
+
Terrapin::CommandLine.path = ''
|
225
195
|
Paperclip.options[:command_path] = ''
|
226
196
|
ENV['PATH'] = ''
|
227
197
|
assert_raises(Paperclip::Errors::CommandNotFoundError) do
|
@@ -480,6 +450,41 @@ describe Paperclip::Thumbnail do
|
|
480
450
|
assert_equal "50x50", `#{cmd}`.chomp
|
481
451
|
end
|
482
452
|
end
|
453
|
+
|
454
|
+
context "with a specified frame_index" do
|
455
|
+
before do
|
456
|
+
@thumb = Paperclip::Thumbnail.new(
|
457
|
+
@file,
|
458
|
+
geometry: "50x50",
|
459
|
+
frame_index: 5,
|
460
|
+
format: :jpg,
|
461
|
+
)
|
462
|
+
end
|
463
|
+
|
464
|
+
it "creates the thumbnail from the frame index when sent #make" do
|
465
|
+
@thumb.make
|
466
|
+
assert_equal 5, @thumb.frame_index
|
467
|
+
end
|
468
|
+
end
|
469
|
+
|
470
|
+
context "with a specified frame_index out of bounds" do
|
471
|
+
before do
|
472
|
+
@thumb = Paperclip::Thumbnail.new(
|
473
|
+
@file,
|
474
|
+
geometry: "50x50",
|
475
|
+
frame_index: 20,
|
476
|
+
format: :jpg,
|
477
|
+
)
|
478
|
+
end
|
479
|
+
|
480
|
+
it "errors when trying to create the thumbnail" do
|
481
|
+
assert_raises(Paperclip::Error) do
|
482
|
+
silence_stream(STDERR) do
|
483
|
+
@thumb.make
|
484
|
+
end
|
485
|
+
end
|
486
|
+
end
|
487
|
+
end
|
483
488
|
end
|
484
489
|
|
485
490
|
context "with a really long file name" do
|
@@ -1,14 +1,12 @@
|
|
1
|
-
# encoding: utf-8
|
2
1
|
require 'spec_helper'
|
3
2
|
|
4
3
|
describe Paperclip::UrlGenerator do
|
5
4
|
it "uses the given interpolator" do
|
6
5
|
expected = "the expected result"
|
7
|
-
mock_attachment = MockAttachment.new
|
8
6
|
mock_interpolator = MockInterpolator.new(result: expected)
|
7
|
+
mock_attachment = MockAttachment.new(interpolator: mock_interpolator)
|
9
8
|
|
10
|
-
url_generator = Paperclip::UrlGenerator.new(mock_attachment
|
11
|
-
{ interpolator: mock_interpolator })
|
9
|
+
url_generator = Paperclip::UrlGenerator.new(mock_attachment)
|
12
10
|
result = url_generator.for(:style_name, {})
|
13
11
|
|
14
12
|
assert_equal expected, result
|
@@ -17,12 +15,12 @@ describe Paperclip::UrlGenerator do
|
|
17
15
|
end
|
18
16
|
|
19
17
|
it "uses the default URL when no file is assigned" do
|
20
|
-
mock_attachment = MockAttachment.new
|
21
18
|
mock_interpolator = MockInterpolator.new
|
22
19
|
default_url = "the default url"
|
23
|
-
options = { interpolator: mock_interpolator, default_url: default_url}
|
20
|
+
options = { interpolator: mock_interpolator, default_url: default_url }
|
21
|
+
mock_attachment = MockAttachment.new(options)
|
24
22
|
|
25
|
-
url_generator = Paperclip::UrlGenerator.new(mock_attachment
|
23
|
+
url_generator = Paperclip::UrlGenerator.new(mock_attachment)
|
26
24
|
url_generator.for(:style_name, {})
|
27
25
|
|
28
26
|
assert mock_interpolator.has_interpolated_pattern?(default_url),
|
@@ -30,12 +28,12 @@ describe Paperclip::UrlGenerator do
|
|
30
28
|
end
|
31
29
|
|
32
30
|
it "executes the default URL lambda when no file is assigned" do
|
33
|
-
mock_attachment = MockAttachment.new
|
34
31
|
mock_interpolator = MockInterpolator.new
|
35
32
|
default_url = lambda {|attachment| "the #{attachment.class.name} default url" }
|
36
33
|
options = { interpolator: mock_interpolator, default_url: default_url}
|
34
|
+
mock_attachment = MockAttachment.new(options)
|
37
35
|
|
38
|
-
url_generator = Paperclip::UrlGenerator.new(mock_attachment
|
36
|
+
url_generator = Paperclip::UrlGenerator.new(mock_attachment)
|
39
37
|
url_generator.for(:style_name, {})
|
40
38
|
|
41
39
|
assert mock_interpolator.has_interpolated_pattern?("the MockAttachment default url"),
|
@@ -44,12 +42,16 @@ describe Paperclip::UrlGenerator do
|
|
44
42
|
|
45
43
|
it "executes the method named by the symbol as the default URL when no file is assigned" do
|
46
44
|
mock_model = FakeModel.new
|
47
|
-
mock_attachment = MockAttachment.new(model: mock_model)
|
48
|
-
mock_interpolator = MockInterpolator.new
|
49
45
|
default_url = :to_s
|
50
|
-
|
51
|
-
|
52
|
-
|
46
|
+
mock_interpolator = MockInterpolator.new
|
47
|
+
options = {
|
48
|
+
interpolator: mock_interpolator,
|
49
|
+
default_url: default_url,
|
50
|
+
model: mock_model,
|
51
|
+
}
|
52
|
+
mock_attachment = MockAttachment.new(options)
|
53
|
+
|
54
|
+
url_generator = Paperclip::UrlGenerator.new(mock_attachment)
|
53
55
|
url_generator.for(:style_name, {})
|
54
56
|
|
55
57
|
assert mock_interpolator.has_interpolated_pattern?(mock_model.to_s),
|
@@ -58,10 +60,10 @@ describe Paperclip::UrlGenerator do
|
|
58
60
|
|
59
61
|
it "URL-escapes spaces if asked to" do
|
60
62
|
expected = "the expected result"
|
61
|
-
mock_attachment = MockAttachment.new
|
62
63
|
mock_interpolator = MockInterpolator.new(result: expected)
|
63
64
|
options = { interpolator: mock_interpolator }
|
64
|
-
|
65
|
+
mock_attachment = MockAttachment.new(options)
|
66
|
+
url_generator = Paperclip::UrlGenerator.new(mock_attachment)
|
65
67
|
|
66
68
|
result = url_generator.for(:style_name, {escape: true})
|
67
69
|
|
@@ -74,10 +76,10 @@ describe Paperclip::UrlGenerator do
|
|
74
76
|
"the escaped result"
|
75
77
|
end
|
76
78
|
end.new
|
77
|
-
mock_attachment = MockAttachment.new
|
78
79
|
mock_interpolator = MockInterpolator.new(result: expected)
|
79
80
|
options = { interpolator: mock_interpolator }
|
80
|
-
|
81
|
+
mock_attachment = MockAttachment.new(options)
|
82
|
+
url_generator = Paperclip::UrlGenerator.new(mock_attachment)
|
81
83
|
|
82
84
|
result = url_generator.for(:style_name, {escape: true})
|
83
85
|
|
@@ -86,10 +88,10 @@ describe Paperclip::UrlGenerator do
|
|
86
88
|
|
87
89
|
it "leaves spaces unescaped as asked to" do
|
88
90
|
expected = "the expected result"
|
89
|
-
mock_attachment = MockAttachment.new
|
90
91
|
mock_interpolator = MockInterpolator.new(result: expected)
|
91
92
|
options = { interpolator: mock_interpolator }
|
92
|
-
|
93
|
+
mock_attachment = MockAttachment.new(options)
|
94
|
+
url_generator = Paperclip::UrlGenerator.new(mock_attachment)
|
93
95
|
|
94
96
|
result = url_generator.for(:style_name, {escape: false})
|
95
97
|
|
@@ -98,10 +100,10 @@ describe Paperclip::UrlGenerator do
|
|
98
100
|
|
99
101
|
it "defaults to leaving spaces unescaped" do
|
100
102
|
expected = "the expected result"
|
101
|
-
mock_attachment = MockAttachment.new
|
102
103
|
mock_interpolator = MockInterpolator.new(result: expected)
|
103
104
|
options = { interpolator: mock_interpolator }
|
104
|
-
|
105
|
+
mock_attachment = MockAttachment.new(options)
|
106
|
+
url_generator = Paperclip::UrlGenerator.new(mock_attachment)
|
105
107
|
|
106
108
|
result = url_generator.for(:style_name, {})
|
107
109
|
|
@@ -111,9 +113,9 @@ describe Paperclip::UrlGenerator do
|
|
111
113
|
it "produces URLs without the updated_at value when the object does not respond to updated_at" do
|
112
114
|
expected = "the expected result"
|
113
115
|
mock_interpolator = MockInterpolator.new(result: expected)
|
114
|
-
|
115
|
-
|
116
|
-
url_generator = Paperclip::UrlGenerator.new(mock_attachment
|
116
|
+
options = { interpolator: mock_interpolator, responds_to_updated_at: false }
|
117
|
+
mock_attachment = MockAttachment.new(options)
|
118
|
+
url_generator = Paperclip::UrlGenerator.new(mock_attachment)
|
117
119
|
|
118
120
|
result = url_generator.for(:style_name, {timestamp: true})
|
119
121
|
|
@@ -123,9 +125,13 @@ describe Paperclip::UrlGenerator do
|
|
123
125
|
it "produces URLs without the updated_at value when the updated_at value is nil" do
|
124
126
|
expected = "the expected result"
|
125
127
|
mock_interpolator = MockInterpolator.new(result: expected)
|
126
|
-
|
127
|
-
|
128
|
-
|
128
|
+
options = {
|
129
|
+
responds_to_updated_at: true,
|
130
|
+
updated_at: nil,
|
131
|
+
interpolator: mock_interpolator,
|
132
|
+
}
|
133
|
+
mock_attachment = MockAttachment.new(options)
|
134
|
+
url_generator = Paperclip::UrlGenerator.new(mock_attachment)
|
129
135
|
|
130
136
|
result = url_generator.for(:style_name, {timestamp: true})
|
131
137
|
|
@@ -136,9 +142,9 @@ describe Paperclip::UrlGenerator do
|
|
136
142
|
expected = "the expected result"
|
137
143
|
updated_at = 1231231234
|
138
144
|
mock_interpolator = MockInterpolator.new(result: expected)
|
139
|
-
|
140
|
-
|
141
|
-
url_generator = Paperclip::UrlGenerator.new(mock_attachment
|
145
|
+
options = { interpolator: mock_interpolator, updated_at: updated_at }
|
146
|
+
mock_attachment = MockAttachment.new(options)
|
147
|
+
url_generator = Paperclip::UrlGenerator.new(mock_attachment)
|
142
148
|
|
143
149
|
result = url_generator.for(:style_name, {timestamp: true})
|
144
150
|
|
@@ -149,9 +155,9 @@ describe Paperclip::UrlGenerator do
|
|
149
155
|
expected = "the?expected=result"
|
150
156
|
updated_at = 1231231234
|
151
157
|
mock_interpolator = MockInterpolator.new(result: expected)
|
152
|
-
|
153
|
-
|
154
|
-
url_generator = Paperclip::UrlGenerator.new(mock_attachment
|
158
|
+
options = { interpolator: mock_interpolator, updated_at: updated_at }
|
159
|
+
mock_attachment = MockAttachment.new(options)
|
160
|
+
url_generator = Paperclip::UrlGenerator.new(mock_attachment)
|
155
161
|
|
156
162
|
result = url_generator.for(:style_name, {timestamp: true})
|
157
163
|
|
@@ -162,9 +168,9 @@ describe Paperclip::UrlGenerator do
|
|
162
168
|
expected = "the expected result"
|
163
169
|
updated_at = 1231231234
|
164
170
|
mock_interpolator = MockInterpolator.new(result: expected)
|
165
|
-
|
166
|
-
|
167
|
-
url_generator = Paperclip::UrlGenerator.new(mock_attachment
|
171
|
+
options = { interpolator: mock_interpolator, updated_at: updated_at }
|
172
|
+
mock_attachment = MockAttachment.new(options)
|
173
|
+
url_generator = Paperclip::UrlGenerator.new(mock_attachment)
|
168
174
|
|
169
175
|
result = url_generator.for(:style_name, {timestamp: false})
|
170
176
|
|
@@ -173,11 +179,15 @@ describe Paperclip::UrlGenerator do
|
|
173
179
|
|
174
180
|
it "produces the correct URL when the instance has a file name" do
|
175
181
|
expected = "the expected result"
|
176
|
-
mock_attachment = MockAttachment.new(original_filename: 'exists')
|
177
182
|
mock_interpolator = MockInterpolator.new
|
178
|
-
options = {
|
179
|
-
|
180
|
-
|
183
|
+
options = {
|
184
|
+
interpolator: mock_interpolator,
|
185
|
+
url: expected,
|
186
|
+
original_filename: "exists",
|
187
|
+
}
|
188
|
+
mock_attachment = MockAttachment.new(options)
|
189
|
+
|
190
|
+
url_generator = Paperclip::UrlGenerator.new(mock_attachment)
|
181
191
|
url_generator.for(:style_name, {})
|
182
192
|
|
183
193
|
assert mock_interpolator.has_interpolated_pattern?(expected),
|
@@ -186,10 +196,10 @@ describe Paperclip::UrlGenerator do
|
|
186
196
|
|
187
197
|
describe "should be able to escape (, ), [, and ]." do
|
188
198
|
def generate(expected, updated_at=nil)
|
189
|
-
mock_attachment = MockAttachment.new(updated_at: updated_at)
|
190
199
|
mock_interpolator = MockInterpolator.new(result: expected)
|
191
|
-
options = { interpolator: mock_interpolator }
|
192
|
-
|
200
|
+
options = { interpolator: mock_interpolator, updated_at: updated_at }
|
201
|
+
mock_attachment = MockAttachment.new(options)
|
202
|
+
url_generator = Paperclip::UrlGenerator.new(mock_attachment)
|
193
203
|
def url_generator.respond_to(params)
|
194
204
|
false if params == :escape
|
195
205
|
end
|
@@ -12,14 +12,6 @@ describe Paperclip::Validators::AttachmentSizeValidator do
|
|
12
12
|
))
|
13
13
|
end
|
14
14
|
|
15
|
-
def self.storage_units
|
16
|
-
if defined?(ActiveSupport::NumberHelper) # Rails 4.0+
|
17
|
-
{ 5120 => '5 KB', 10240 => '10 KB' }
|
18
|
-
else
|
19
|
-
{ 5120 => '5120 Bytes', 10240 => '10240 Bytes' }
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
15
|
def self.should_allow_attachment_file_size(size)
|
24
16
|
context "when the attachment size is #{size}" do
|
25
17
|
it "adds error to dummy object" do
|
@@ -158,8 +150,10 @@ describe Paperclip::Validators::AttachmentSizeValidator do
|
|
158
150
|
message: "is invalid. (Between %{min} and %{max} please.)"
|
159
151
|
end
|
160
152
|
|
161
|
-
should_not_allow_attachment_file_size
|
162
|
-
|
153
|
+
should_not_allow_attachment_file_size(
|
154
|
+
11.kilobytes,
|
155
|
+
message: "is invalid. (Between 5 KB and 10 KB please.)"
|
156
|
+
)
|
163
157
|
end
|
164
158
|
|
165
159
|
context "given :less_than and :greater_than" do
|
@@ -169,8 +163,10 @@ describe Paperclip::Validators::AttachmentSizeValidator do
|
|
169
163
|
message: "is invalid. (Between %{min} and %{max} please.)"
|
170
164
|
end
|
171
165
|
|
172
|
-
should_not_allow_attachment_file_size
|
173
|
-
|
166
|
+
should_not_allow_attachment_file_size(
|
167
|
+
11.kilobytes,
|
168
|
+
message: "is invalid. (Between 5 KB and 10 KB please.)"
|
169
|
+
)
|
174
170
|
end
|
175
171
|
end
|
176
172
|
|
@@ -181,10 +177,15 @@ describe Paperclip::Validators::AttachmentSizeValidator do
|
|
181
177
|
less_than: 10.kilobytes
|
182
178
|
end
|
183
179
|
|
184
|
-
should_not_allow_attachment_file_size
|
185
|
-
|
186
|
-
|
187
|
-
|
180
|
+
should_not_allow_attachment_file_size(
|
181
|
+
11.kilobytes,
|
182
|
+
message: "must be less than 10 KB"
|
183
|
+
)
|
184
|
+
|
185
|
+
should_not_allow_attachment_file_size(
|
186
|
+
4.kilobytes,
|
187
|
+
message: "must be greater than 5 KB"
|
188
|
+
)
|
188
189
|
end
|
189
190
|
|
190
191
|
context "given a size range" do
|
@@ -192,10 +193,15 @@ describe Paperclip::Validators::AttachmentSizeValidator do
|
|
192
193
|
build_validator in: (5.kilobytes..10.kilobytes)
|
193
194
|
end
|
194
195
|
|
195
|
-
should_not_allow_attachment_file_size
|
196
|
-
|
197
|
-
|
198
|
-
|
196
|
+
should_not_allow_attachment_file_size(
|
197
|
+
11.kilobytes,
|
198
|
+
message: "must be in between 5 KB and 10 KB"
|
199
|
+
)
|
200
|
+
|
201
|
+
should_not_allow_attachment_file_size(
|
202
|
+
4.kilobytes,
|
203
|
+
message: "must be in between 5 KB and 10 KB"
|
204
|
+
)
|
199
205
|
end
|
200
206
|
end
|
201
207
|
|