kt-paperclip 4.4.0 → 5.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.codeclimate.yml +17 -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/NEWS +105 -31
- data/README.md +239 -153
- 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 +6 -6
- 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/attachment.rb +25 -14
- 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/geometry_detector_factory.rb +2 -2
- 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 +1 -1
- data/lib/paperclip/io_adapters/abstract_adapter.rb +29 -3
- data/lib/paperclip/io_adapters/attachment_adapter.rb +10 -5
- 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 +7 -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 +17 -14
- data/lib/paperclip/matchers/validate_attachment_content_type_matcher.rb +4 -4
- data/lib/paperclip/media_type_spoof_detector.rb +3 -2
- data/lib/paperclip/processor.rb +5 -4
- data/lib/paperclip/schema.rb +4 -10
- data/lib/paperclip/storage/filesystem.rb +13 -2
- data/lib/paperclip/storage/fog.rb +19 -13
- data/lib/paperclip/storage/s3.rb +87 -58
- data/lib/paperclip/thumbnail.rb +18 -8
- data/lib/paperclip/url_generator.rb +18 -14
- data/lib/paperclip/validators/attachment_size_validator.rb +1 -7
- data/lib/paperclip/validators.rb +1 -1
- data/lib/paperclip/version.rb +3 -1
- data/lib/paperclip.rb +13 -12
- data/lib/tasks/paperclip.rake +18 -4
- data/paperclip.gemspec +13 -11
- data/spec/paperclip/attachment_processing_spec.rb +2 -4
- data/spec/paperclip/attachment_registry_spec.rb +28 -0
- data/spec/paperclip/attachment_spec.rb +72 -18
- 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/has_attached_file_spec.rb +24 -8
- data/spec/paperclip/integration_spec.rb +4 -3
- data/spec/paperclip/io_adapters/abstract_adapter_spec.rb +76 -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 +18 -1
- 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 +48 -3
- data/spec/paperclip/matchers/validate_attachment_content_type_matcher_spec.rb +10 -0
- data/spec/paperclip/media_type_spoof_detector_spec.rb +15 -0
- data/spec/paperclip/paperclip_spec.rb +15 -45
- data/spec/paperclip/processor_spec.rb +4 -4
- data/spec/paperclip/storage/fog_spec.rb +26 -0
- data/spec/paperclip/storage/s3_live_spec.rb +20 -14
- data/spec/paperclip/storage/s3_spec.rb +357 -190
- data/spec/paperclip/tempfile_spec.rb +35 -0
- data/spec/paperclip/thumbnail_spec.rb +38 -35
- data/spec/paperclip/url_generator_spec.rb +53 -42
- data/spec/paperclip/validators/attachment_size_validator_spec.rb +26 -20
- data/spec/paperclip/validators_spec.rb +5 -5
- data/spec/spec_helper.rb +6 -2
- data/spec/support/assertions.rb +12 -1
- data/spec/support/conditional_filter_helper.rb +5 -0
- data/spec/support/mock_attachment.rb +2 -0
- data/spec/support/mock_url_generator_builder.rb +2 -2
- data/spec/support/model_reconstruction.rb +10 -2
- data/spec/support/reporting.rb +11 -0
- metadata +69 -75
- 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
|
|
@@ -221,7 +189,7 @@ describe Paperclip::Thumbnail do
|
|
221
189
|
it "lets us know when a command isn't found versus a processing error" do
|
222
190
|
old_path = ENV['PATH']
|
223
191
|
begin
|
224
|
-
|
192
|
+
Terrapin::CommandLine.path = ''
|
225
193
|
Paperclip.options[:command_path] = ''
|
226
194
|
ENV['PATH'] = ''
|
227
195
|
assert_raises(Paperclip::Errors::CommandNotFoundError) do
|
@@ -480,6 +448,41 @@ describe Paperclip::Thumbnail do
|
|
480
448
|
assert_equal "50x50", `#{cmd}`.chomp
|
481
449
|
end
|
482
450
|
end
|
451
|
+
|
452
|
+
context "with a specified frame_index" do
|
453
|
+
before do
|
454
|
+
@thumb = Paperclip::Thumbnail.new(
|
455
|
+
@file,
|
456
|
+
geometry: "50x50",
|
457
|
+
frame_index: 5,
|
458
|
+
format: :jpg,
|
459
|
+
)
|
460
|
+
end
|
461
|
+
|
462
|
+
it "creates the thumbnail from the frame index when sent #make" do
|
463
|
+
@thumb.make
|
464
|
+
assert_equal 5, @thumb.frame_index
|
465
|
+
end
|
466
|
+
end
|
467
|
+
|
468
|
+
context "with a specified frame_index out of bounds" do
|
469
|
+
before do
|
470
|
+
@thumb = Paperclip::Thumbnail.new(
|
471
|
+
@file,
|
472
|
+
geometry: "50x50",
|
473
|
+
frame_index: 20,
|
474
|
+
format: :jpg,
|
475
|
+
)
|
476
|
+
end
|
477
|
+
|
478
|
+
it "errors when trying to create the thumbnail" do
|
479
|
+
assert_raises(Paperclip::Error) do
|
480
|
+
silence_stream(STDERR) do
|
481
|
+
@thumb.make
|
482
|
+
end
|
483
|
+
end
|
484
|
+
end
|
485
|
+
end
|
483
486
|
end
|
484
487
|
|
485
488
|
context "with a really long file name" do
|
@@ -4,11 +4,10 @@ require 'spec_helper'
|
|
4
4
|
describe Paperclip::UrlGenerator do
|
5
5
|
it "uses the given interpolator" do
|
6
6
|
expected = "the expected result"
|
7
|
-
mock_attachment = MockAttachment.new
|
8
7
|
mock_interpolator = MockInterpolator.new(result: expected)
|
8
|
+
mock_attachment = MockAttachment.new(interpolator: mock_interpolator)
|
9
9
|
|
10
|
-
url_generator = Paperclip::UrlGenerator.new(mock_attachment
|
11
|
-
{ interpolator: mock_interpolator })
|
10
|
+
url_generator = Paperclip::UrlGenerator.new(mock_attachment)
|
12
11
|
result = url_generator.for(:style_name, {})
|
13
12
|
|
14
13
|
assert_equal expected, result
|
@@ -17,12 +16,12 @@ describe Paperclip::UrlGenerator do
|
|
17
16
|
end
|
18
17
|
|
19
18
|
it "uses the default URL when no file is assigned" do
|
20
|
-
mock_attachment = MockAttachment.new
|
21
19
|
mock_interpolator = MockInterpolator.new
|
22
20
|
default_url = "the default url"
|
23
|
-
options = { interpolator: mock_interpolator, default_url: default_url}
|
21
|
+
options = { interpolator: mock_interpolator, default_url: default_url }
|
22
|
+
mock_attachment = MockAttachment.new(options)
|
24
23
|
|
25
|
-
url_generator = Paperclip::UrlGenerator.new(mock_attachment
|
24
|
+
url_generator = Paperclip::UrlGenerator.new(mock_attachment)
|
26
25
|
url_generator.for(:style_name, {})
|
27
26
|
|
28
27
|
assert mock_interpolator.has_interpolated_pattern?(default_url),
|
@@ -30,12 +29,12 @@ describe Paperclip::UrlGenerator do
|
|
30
29
|
end
|
31
30
|
|
32
31
|
it "executes the default URL lambda when no file is assigned" do
|
33
|
-
mock_attachment = MockAttachment.new
|
34
32
|
mock_interpolator = MockInterpolator.new
|
35
33
|
default_url = lambda {|attachment| "the #{attachment.class.name} default url" }
|
36
34
|
options = { interpolator: mock_interpolator, default_url: default_url}
|
35
|
+
mock_attachment = MockAttachment.new(options)
|
37
36
|
|
38
|
-
url_generator = Paperclip::UrlGenerator.new(mock_attachment
|
37
|
+
url_generator = Paperclip::UrlGenerator.new(mock_attachment)
|
39
38
|
url_generator.for(:style_name, {})
|
40
39
|
|
41
40
|
assert mock_interpolator.has_interpolated_pattern?("the MockAttachment default url"),
|
@@ -44,12 +43,16 @@ describe Paperclip::UrlGenerator do
|
|
44
43
|
|
45
44
|
it "executes the method named by the symbol as the default URL when no file is assigned" do
|
46
45
|
mock_model = FakeModel.new
|
47
|
-
mock_attachment = MockAttachment.new(model: mock_model)
|
48
|
-
mock_interpolator = MockInterpolator.new
|
49
46
|
default_url = :to_s
|
50
|
-
|
47
|
+
mock_interpolator = MockInterpolator.new
|
48
|
+
options = {
|
49
|
+
interpolator: mock_interpolator,
|
50
|
+
default_url: default_url,
|
51
|
+
model: mock_model,
|
52
|
+
}
|
53
|
+
mock_attachment = MockAttachment.new(options)
|
51
54
|
|
52
|
-
url_generator = Paperclip::UrlGenerator.new(mock_attachment
|
55
|
+
url_generator = Paperclip::UrlGenerator.new(mock_attachment)
|
53
56
|
url_generator.for(:style_name, {})
|
54
57
|
|
55
58
|
assert mock_interpolator.has_interpolated_pattern?(mock_model.to_s),
|
@@ -58,10 +61,10 @@ describe Paperclip::UrlGenerator do
|
|
58
61
|
|
59
62
|
it "URL-escapes spaces if asked to" do
|
60
63
|
expected = "the expected result"
|
61
|
-
mock_attachment = MockAttachment.new
|
62
64
|
mock_interpolator = MockInterpolator.new(result: expected)
|
63
65
|
options = { interpolator: mock_interpolator }
|
64
|
-
|
66
|
+
mock_attachment = MockAttachment.new(options)
|
67
|
+
url_generator = Paperclip::UrlGenerator.new(mock_attachment)
|
65
68
|
|
66
69
|
result = url_generator.for(:style_name, {escape: true})
|
67
70
|
|
@@ -74,10 +77,10 @@ describe Paperclip::UrlGenerator do
|
|
74
77
|
"the escaped result"
|
75
78
|
end
|
76
79
|
end.new
|
77
|
-
mock_attachment = MockAttachment.new
|
78
80
|
mock_interpolator = MockInterpolator.new(result: expected)
|
79
81
|
options = { interpolator: mock_interpolator }
|
80
|
-
|
82
|
+
mock_attachment = MockAttachment.new(options)
|
83
|
+
url_generator = Paperclip::UrlGenerator.new(mock_attachment)
|
81
84
|
|
82
85
|
result = url_generator.for(:style_name, {escape: true})
|
83
86
|
|
@@ -86,10 +89,10 @@ describe Paperclip::UrlGenerator do
|
|
86
89
|
|
87
90
|
it "leaves spaces unescaped as asked to" do
|
88
91
|
expected = "the expected result"
|
89
|
-
mock_attachment = MockAttachment.new
|
90
92
|
mock_interpolator = MockInterpolator.new(result: expected)
|
91
93
|
options = { interpolator: mock_interpolator }
|
92
|
-
|
94
|
+
mock_attachment = MockAttachment.new(options)
|
95
|
+
url_generator = Paperclip::UrlGenerator.new(mock_attachment)
|
93
96
|
|
94
97
|
result = url_generator.for(:style_name, {escape: false})
|
95
98
|
|
@@ -98,10 +101,10 @@ describe Paperclip::UrlGenerator do
|
|
98
101
|
|
99
102
|
it "defaults to leaving spaces unescaped" do
|
100
103
|
expected = "the expected result"
|
101
|
-
mock_attachment = MockAttachment.new
|
102
104
|
mock_interpolator = MockInterpolator.new(result: expected)
|
103
105
|
options = { interpolator: mock_interpolator }
|
104
|
-
|
106
|
+
mock_attachment = MockAttachment.new(options)
|
107
|
+
url_generator = Paperclip::UrlGenerator.new(mock_attachment)
|
105
108
|
|
106
109
|
result = url_generator.for(:style_name, {})
|
107
110
|
|
@@ -111,9 +114,9 @@ describe Paperclip::UrlGenerator do
|
|
111
114
|
it "produces URLs without the updated_at value when the object does not respond to updated_at" do
|
112
115
|
expected = "the expected result"
|
113
116
|
mock_interpolator = MockInterpolator.new(result: expected)
|
114
|
-
|
115
|
-
|
116
|
-
url_generator = Paperclip::UrlGenerator.new(mock_attachment
|
117
|
+
options = { interpolator: mock_interpolator, responds_to_updated_at: false }
|
118
|
+
mock_attachment = MockAttachment.new(options)
|
119
|
+
url_generator = Paperclip::UrlGenerator.new(mock_attachment)
|
117
120
|
|
118
121
|
result = url_generator.for(:style_name, {timestamp: true})
|
119
122
|
|
@@ -123,9 +126,13 @@ describe Paperclip::UrlGenerator do
|
|
123
126
|
it "produces URLs without the updated_at value when the updated_at value is nil" do
|
124
127
|
expected = "the expected result"
|
125
128
|
mock_interpolator = MockInterpolator.new(result: expected)
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
+
options = {
|
130
|
+
responds_to_updated_at: true,
|
131
|
+
updated_at: nil,
|
132
|
+
interpolator: mock_interpolator,
|
133
|
+
}
|
134
|
+
mock_attachment = MockAttachment.new(options)
|
135
|
+
url_generator = Paperclip::UrlGenerator.new(mock_attachment)
|
129
136
|
|
130
137
|
result = url_generator.for(:style_name, {timestamp: true})
|
131
138
|
|
@@ -136,9 +143,9 @@ describe Paperclip::UrlGenerator do
|
|
136
143
|
expected = "the expected result"
|
137
144
|
updated_at = 1231231234
|
138
145
|
mock_interpolator = MockInterpolator.new(result: expected)
|
139
|
-
|
140
|
-
|
141
|
-
url_generator = Paperclip::UrlGenerator.new(mock_attachment
|
146
|
+
options = { interpolator: mock_interpolator, updated_at: updated_at }
|
147
|
+
mock_attachment = MockAttachment.new(options)
|
148
|
+
url_generator = Paperclip::UrlGenerator.new(mock_attachment)
|
142
149
|
|
143
150
|
result = url_generator.for(:style_name, {timestamp: true})
|
144
151
|
|
@@ -149,9 +156,9 @@ describe Paperclip::UrlGenerator do
|
|
149
156
|
expected = "the?expected=result"
|
150
157
|
updated_at = 1231231234
|
151
158
|
mock_interpolator = MockInterpolator.new(result: expected)
|
152
|
-
|
153
|
-
|
154
|
-
url_generator = Paperclip::UrlGenerator.new(mock_attachment
|
159
|
+
options = { interpolator: mock_interpolator, updated_at: updated_at }
|
160
|
+
mock_attachment = MockAttachment.new(options)
|
161
|
+
url_generator = Paperclip::UrlGenerator.new(mock_attachment)
|
155
162
|
|
156
163
|
result = url_generator.for(:style_name, {timestamp: true})
|
157
164
|
|
@@ -162,9 +169,9 @@ describe Paperclip::UrlGenerator do
|
|
162
169
|
expected = "the expected result"
|
163
170
|
updated_at = 1231231234
|
164
171
|
mock_interpolator = MockInterpolator.new(result: expected)
|
165
|
-
|
166
|
-
|
167
|
-
url_generator = Paperclip::UrlGenerator.new(mock_attachment
|
172
|
+
options = { interpolator: mock_interpolator, updated_at: updated_at }
|
173
|
+
mock_attachment = MockAttachment.new(options)
|
174
|
+
url_generator = Paperclip::UrlGenerator.new(mock_attachment)
|
168
175
|
|
169
176
|
result = url_generator.for(:style_name, {timestamp: false})
|
170
177
|
|
@@ -173,11 +180,15 @@ describe Paperclip::UrlGenerator do
|
|
173
180
|
|
174
181
|
it "produces the correct URL when the instance has a file name" do
|
175
182
|
expected = "the expected result"
|
176
|
-
mock_attachment = MockAttachment.new(original_filename: 'exists')
|
177
183
|
mock_interpolator = MockInterpolator.new
|
178
|
-
options = {
|
184
|
+
options = {
|
185
|
+
interpolator: mock_interpolator,
|
186
|
+
url: expected,
|
187
|
+
original_filename: "exists",
|
188
|
+
}
|
189
|
+
mock_attachment = MockAttachment.new(options)
|
179
190
|
|
180
|
-
url_generator = Paperclip::UrlGenerator.new(mock_attachment
|
191
|
+
url_generator = Paperclip::UrlGenerator.new(mock_attachment)
|
181
192
|
url_generator.for(:style_name, {})
|
182
193
|
|
183
194
|
assert mock_interpolator.has_interpolated_pattern?(expected),
|
@@ -189,17 +200,17 @@ describe Paperclip::UrlGenerator do
|
|
189
200
|
mock_interpolator = MockInterpolator.new(result: expected)
|
190
201
|
options = { interpolator: mock_interpolator }
|
191
202
|
mock_attachment = MockAttachment.new(options)
|
192
|
-
url_generator = Paperclip::UrlGenerator.new(mock_attachment
|
203
|
+
url_generator = Paperclip::UrlGenerator.new(mock_attachment)
|
193
204
|
|
194
205
|
expect { url_generator.for(:style_name, escape: true) }.to_not(output(/URI\.(un)?escape is obsolete/).to_stderr)
|
195
206
|
end
|
196
207
|
|
197
208
|
describe "should be able to escape (, ), [, and ]." do
|
198
209
|
def generate(expected, updated_at=nil)
|
199
|
-
mock_attachment = MockAttachment.new(updated_at: updated_at)
|
200
210
|
mock_interpolator = MockInterpolator.new(result: expected)
|
201
|
-
options = { interpolator: mock_interpolator }
|
202
|
-
|
211
|
+
options = { interpolator: mock_interpolator, updated_at: updated_at }
|
212
|
+
mock_attachment = MockAttachment.new(options)
|
213
|
+
url_generator = Paperclip::UrlGenerator.new(mock_attachment)
|
203
214
|
def url_generator.respond_to(params)
|
204
215
|
false if params == :escape
|
205
216
|
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
|
|
@@ -3,6 +3,7 @@ require 'spec_helper'
|
|
3
3
|
describe Paperclip::Validators do
|
4
4
|
context "using the helper" do
|
5
5
|
before do
|
6
|
+
rebuild_class
|
6
7
|
Dummy.validates_attachment :avatar, presence: true, content_type: { content_type: "image/jpeg" }, size: { in: 0..10240 }
|
7
8
|
end
|
8
9
|
|
@@ -30,8 +31,8 @@ describe Paperclip::Validators do
|
|
30
31
|
before do
|
31
32
|
rebuild_class
|
32
33
|
Dummy.validates_attachment :avatar, file_type_ignorance: true, file_name: [
|
33
|
-
{ matches: /\A.*\.jpe?g\
|
34
|
-
{ matches: /\A.{,8}\..+\
|
34
|
+
{ matches: /\A.*\.jpe?g\z/i, message: :invalid_extension },
|
35
|
+
{ matches: /\A.{,8}\..+\z/i, message: [:too_long, count: 8] },
|
35
36
|
]
|
36
37
|
end
|
37
38
|
|
@@ -64,12 +65,11 @@ describe Paperclip::Validators do
|
|
64
65
|
assert_raises(RuntimeError){ dummy.valid? }
|
65
66
|
end
|
66
67
|
|
67
|
-
it 'allows you to attach a file that does not
|
68
|
+
it 'allows you to attach a file that does not violate these validations' do
|
68
69
|
dummy = Dummy.new(avatar: File.new(fixture_file('rotated.jpg')))
|
69
|
-
expect(dummy.errors.
|
70
|
+
expect(dummy.errors.full_messages).to be_empty
|
70
71
|
assert dummy.valid?
|
71
72
|
end
|
72
|
-
|
73
73
|
end
|
74
74
|
|
75
75
|
context "using the helper with a conditional" do
|
data/spec/spec_helper.rb
CHANGED
@@ -7,6 +7,8 @@ require 'active_support/core_ext'
|
|
7
7
|
require 'mocha/api'
|
8
8
|
require 'bourne'
|
9
9
|
require 'ostruct'
|
10
|
+
require 'pathname'
|
11
|
+
require 'activerecord-import'
|
10
12
|
|
11
13
|
ROOT = Pathname(File.expand_path(File.join(File.dirname(__FILE__), '..')))
|
12
14
|
|
@@ -20,7 +22,8 @@ FIXTURES_DIR = File.join(File.dirname(__FILE__), "fixtures")
|
|
20
22
|
config = YAML::load(IO.read(File.dirname(__FILE__) + '/database.yml'))
|
21
23
|
ActiveRecord::Base.logger = Logger.new(File.dirname(__FILE__) + "/debug.log")
|
22
24
|
ActiveRecord::Base.establish_connection(config['test'])
|
23
|
-
|
25
|
+
if ActiveRecord::VERSION::STRING >= "4.2" &&
|
26
|
+
ActiveRecord::VERSION::STRING < "5.0"
|
24
27
|
ActiveRecord::Base.raise_in_transactional_callbacks = true
|
25
28
|
end
|
26
29
|
Paperclip.options[:logger] = ActiveRecord::Base.logger
|
@@ -34,8 +37,9 @@ RSpec.configure do |config|
|
|
34
37
|
config.include Assertions
|
35
38
|
config.include ModelReconstruction
|
36
39
|
config.include TestData
|
40
|
+
config.include Reporting
|
37
41
|
config.extend VersionHelper
|
38
|
-
config.extend
|
42
|
+
config.extend ConditionalFilterHelper
|
39
43
|
config.mock_framework = :mocha
|
40
44
|
config.before(:all) do
|
41
45
|
rebuild_model
|
data/spec/support/assertions.rb
CHANGED
@@ -48,19 +48,30 @@ module Assertions
|
|
48
48
|
end
|
49
49
|
|
50
50
|
def assert_success_response(url)
|
51
|
+
url = "http:#{url}" unless url =~ /http/
|
51
52
|
Net::HTTP.get_response(URI.parse(url)) do |response|
|
52
|
-
assert_equal "200",
|
53
|
+
assert_equal "200",
|
54
|
+
response.code,
|
53
55
|
"Expected HTTP response code 200, got #{response.code}"
|
54
56
|
end
|
55
57
|
end
|
56
58
|
|
57
59
|
def assert_not_found_response(url)
|
60
|
+
url = "http:#{url}" unless url =~ /http/
|
58
61
|
Net::HTTP.get_response(URI.parse(url)) do |response|
|
59
62
|
assert_equal "404", response.code,
|
60
63
|
"Expected HTTP response code 404, got #{response.code}"
|
61
64
|
end
|
62
65
|
end
|
63
66
|
|
67
|
+
def assert_forbidden_response(url)
|
68
|
+
url = "http:#{url}" unless url =~ /http/
|
69
|
+
Net::HTTP.get_response(URI.parse(url)) do |response|
|
70
|
+
assert_equal "403", response.code,
|
71
|
+
"Expected HTTP response code 403, got #{response.code}"
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
64
75
|
def assert_frame_dimensions(range, frames)
|
65
76
|
frames.each_with_index do |frame, frame_index|
|
66
77
|
frame.split('x').each_with_index do |dimension, dimension_index |
|
@@ -1,7 +1,9 @@
|
|
1
1
|
class MockAttachment
|
2
2
|
attr_accessor :updated_at, :original_filename
|
3
|
+
attr_reader :options
|
3
4
|
|
4
5
|
def initialize(options = {})
|
6
|
+
@options = options
|
5
7
|
@model = options[:model]
|
6
8
|
@responds_to_updated_at = options[:responds_to_updated_at]
|
7
9
|
@updated_at = options[:updated_at]
|
@@ -10,7 +10,15 @@ module ModelReconstruction
|
|
10
10
|
|
11
11
|
klass.reset_column_information
|
12
12
|
klass.connection_pool.clear_table_cache!(klass.table_name) if klass.connection_pool.respond_to?(:clear_table_cache!)
|
13
|
-
|
13
|
+
|
14
|
+
if klass.connection.respond_to?(:schema_cache)
|
15
|
+
if ActiveRecord::VERSION::STRING >= "5.0"
|
16
|
+
klass.connection.schema_cache.clear_data_source_cache!(klass.table_name)
|
17
|
+
else
|
18
|
+
klass.connection.schema_cache.clear_table_cache!(klass.table_name)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
14
22
|
klass
|
15
23
|
end
|
16
24
|
|
@@ -20,7 +28,7 @@ module ModelReconstruction
|
|
20
28
|
end
|
21
29
|
|
22
30
|
def modify_table table_name, &block
|
23
|
-
ActiveRecord::Base.connection.
|
31
|
+
ActiveRecord::Base.connection.change_table :dummies, &block
|
24
32
|
end
|
25
33
|
|
26
34
|
def rebuild_model options = {}
|