paperclip 4.2.2 → 5.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.codeclimate.yml +17 -0
- data/.hound.yml +1055 -0
- data/.rubocop.yml +1 -0
- data/.travis.yml +17 -15
- data/Appraisals +4 -16
- data/CONTRIBUTING.md +19 -8
- data/Gemfile +5 -9
- data/LICENSE +1 -1
- data/NEWS +148 -31
- data/README.md +327 -191
- data/RELEASING.md +17 -0
- data/Rakefile +2 -2
- data/UPGRADING +12 -9
- data/features/basic_integration.feature +10 -6
- data/features/migration.feature +0 -24
- data/features/step_definitions/attachment_steps.rb +33 -27
- data/features/step_definitions/html_steps.rb +2 -2
- data/features/step_definitions/rails_steps.rb +39 -38
- data/features/step_definitions/s3_steps.rb +2 -2
- data/features/step_definitions/web_steps.rb +1 -103
- data/features/support/env.rb +1 -0
- data/features/support/file_helpers.rb +2 -2
- data/features/support/paths.rb +1 -1
- data/features/support/rails.rb +0 -24
- data/gemfiles/4.2.gemfile +6 -8
- data/gemfiles/5.0.gemfile +17 -0
- data/lib/paperclip/attachment.rb +32 -20
- data/lib/paperclip/attachment_registry.rb +3 -2
- data/lib/paperclip/callbacks.rb +8 -6
- data/lib/paperclip/content_type_detector.rb +27 -11
- data/lib/paperclip/errors.rb +3 -1
- data/lib/paperclip/file_command_content_type_detector.rb +6 -8
- data/lib/paperclip/geometry_parser_factory.rb +1 -1
- data/lib/paperclip/glue.rb +1 -1
- data/lib/paperclip/has_attached_file.rb +9 -2
- data/lib/paperclip/helpers.rb +14 -10
- data/lib/paperclip/interpolations/plural_cache.rb +6 -5
- data/lib/paperclip/interpolations.rb +19 -14
- data/lib/paperclip/io_adapters/abstract_adapter.rb +26 -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 +41 -19
- data/lib/paperclip/matchers/validate_attachment_content_type_matcher.rb +4 -4
- data/lib/paperclip/media_type_spoof_detector.rb +2 -2
- data/lib/paperclip/processor.rb +5 -4
- data/lib/paperclip/rails_environment.rb +25 -0
- data/lib/paperclip/schema.rb +3 -9
- data/lib/paperclip/storage/filesystem.rb +13 -2
- data/lib/paperclip/storage/fog.rb +30 -18
- data/lib/paperclip/storage/s3.rb +92 -65
- data/lib/paperclip/thumbnail.rb +16 -7
- data/lib/paperclip/url_generator.rb +16 -13
- 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 +25 -12
- data/lib/tasks/paperclip.rake +33 -3
- data/paperclip.gemspec +18 -15
- data/spec/paperclip/attachment_definitions_spec.rb +1 -1
- data/spec/paperclip/attachment_processing_spec.rb +2 -4
- data/spec/paperclip/attachment_registry_spec.rb +84 -13
- data/spec/paperclip/attachment_spec.rb +130 -39
- data/spec/paperclip/content_type_detector_spec.rb +8 -1
- data/spec/paperclip/file_command_content_type_detector_spec.rb +0 -1
- data/spec/paperclip/geometry_spec.rb +1 -1
- data/spec/paperclip/glue_spec.rb +44 -0
- data/spec/paperclip/has_attached_file_spec.rb +24 -8
- data/spec/paperclip/integration_spec.rb +4 -3
- data/spec/paperclip/interpolations_spec.rb +16 -13
- data/spec/paperclip/io_adapters/abstract_adapter_spec.rb +47 -23
- 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 +6 -3
- data/spec/paperclip/io_adapters/http_url_proxy_adapter_spec.rb +26 -6
- 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 +5 -1
- data/spec/paperclip/io_adapters/uploaded_file_adapter_spec.rb +5 -5
- data/spec/paperclip/io_adapters/uri_adapter_spec.rb +77 -7
- data/spec/paperclip/matchers/validate_attachment_content_type_matcher_spec.rb +10 -0
- data/spec/paperclip/media_type_spoof_detector_spec.rb +34 -11
- data/spec/paperclip/paperclip_spec.rb +4 -29
- data/spec/paperclip/plural_cache_spec.rb +17 -16
- data/spec/paperclip/rails_environment_spec.rb +33 -0
- data/spec/paperclip/storage/fog_spec.rb +58 -3
- data/spec/paperclip/storage/s3_live_spec.rb +20 -14
- data/spec/paperclip/storage/s3_spec.rb +398 -213
- data/spec/paperclip/tempfile_factory_spec.rb +4 -0
- data/spec/paperclip/tempfile_spec.rb +35 -0
- data/spec/paperclip/thumbnail_spec.rb +51 -32
- data/spec/paperclip/url_generator_spec.rb +55 -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 +8 -1
- data/spec/support/assertions.rb +12 -1
- data/spec/support/conditional_filter_helper.rb +5 -0
- data/spec/support/fake_model.rb +4 -0
- data/spec/support/fixtures/empty.xlsx +0 -0
- data/spec/support/matchers/have_column.rb +11 -2
- data/spec/support/mock_attachment.rb +2 -0
- data/spec/support/mock_url_generator_builder.rb +2 -2
- data/spec/support/model_reconstruction.rb +9 -1
- data/spec/support/reporting.rb +11 -0
- metadata +109 -162
- data/RUNNING_TESTS.md +0 -4
- data/cucumber/paperclip_steps.rb +0 -6
- data/gemfiles/3.2.gemfile +0 -19
- data/gemfiles/4.0.gemfile +0 -19
- data/gemfiles/4.1.gemfile +0 -19
- 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/support/mock_model.rb +0 -2
- 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')
|
|
@@ -480,5 +448,56 @@ 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
|
|
486
|
+
end
|
|
487
|
+
|
|
488
|
+
context "with a really long file name" do
|
|
489
|
+
before do
|
|
490
|
+
tempfile = Tempfile.new("f")
|
|
491
|
+
tempfile_additional_chars = tempfile.path.split("/")[-1].length + 15
|
|
492
|
+
image_file = File.new(fixture_file("5k.png"), "rb")
|
|
493
|
+
@file = Tempfile.new("f" * (255 - tempfile_additional_chars))
|
|
494
|
+
@file.write(image_file.read)
|
|
495
|
+
@file.rewind
|
|
496
|
+
end
|
|
497
|
+
|
|
498
|
+
it "does not throw Errno::ENAMETOOLONG" do
|
|
499
|
+
thumb = Paperclip::Thumbnail.new(@file, geometry: "50x50", format: :gif)
|
|
500
|
+
expect { thumb.make }.to_not raise_error
|
|
501
|
+
end
|
|
483
502
|
end
|
|
484
503
|
end
|
|
@@ -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"),
|
|
@@ -43,13 +42,17 @@ describe Paperclip::UrlGenerator do
|
|
|
43
42
|
end
|
|
44
43
|
|
|
45
44
|
it "executes the method named by the symbol as the default URL when no file is assigned" do
|
|
46
|
-
mock_model =
|
|
47
|
-
mock_attachment = MockAttachment.new(model: mock_model)
|
|
48
|
-
mock_interpolator = MockInterpolator.new
|
|
45
|
+
mock_model = FakeModel.new
|
|
49
46
|
default_url = :to_s
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
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)
|
|
54
|
+
|
|
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 = {
|
|
179
|
-
|
|
180
|
-
|
|
184
|
+
options = {
|
|
185
|
+
interpolator: mock_interpolator,
|
|
186
|
+
url: expected,
|
|
187
|
+
original_filename: "exists",
|
|
188
|
+
}
|
|
189
|
+
mock_attachment = MockAttachment.new(options)
|
|
190
|
+
|
|
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),
|
|
@@ -186,10 +197,10 @@ describe Paperclip::UrlGenerator do
|
|
|
186
197
|
|
|
187
198
|
describe "should be able to escape (, ), [, and ]." do
|
|
188
199
|
def generate(expected, updated_at=nil)
|
|
189
|
-
mock_attachment = MockAttachment.new(updated_at: updated_at)
|
|
190
200
|
mock_interpolator = MockInterpolator.new(result: expected)
|
|
191
|
-
options = { interpolator: mock_interpolator }
|
|
192
|
-
|
|
201
|
+
options = { interpolator: mock_interpolator, updated_at: updated_at }
|
|
202
|
+
mock_attachment = MockAttachment.new(options)
|
|
203
|
+
url_generator = Paperclip::UrlGenerator.new(mock_attachment)
|
|
193
204
|
def url_generator.respond_to(params)
|
|
194
205
|
false if params == :escape
|
|
195
206
|
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,6 +22,10 @@ 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'])
|
|
25
|
+
if ActiveRecord::VERSION::STRING >= "4.2" &&
|
|
26
|
+
ActiveRecord::VERSION::STRING < "5.0"
|
|
27
|
+
ActiveRecord::Base.raise_in_transactional_callbacks = true
|
|
28
|
+
end
|
|
23
29
|
Paperclip.options[:logger] = ActiveRecord::Base.logger
|
|
24
30
|
|
|
25
31
|
Dir[File.join(ROOT, 'spec', 'support', '**', '*.rb')].each{|f| require f }
|
|
@@ -31,8 +37,9 @@ RSpec.configure do |config|
|
|
|
31
37
|
config.include Assertions
|
|
32
38
|
config.include ModelReconstruction
|
|
33
39
|
config.include TestData
|
|
40
|
+
config.include Reporting
|
|
34
41
|
config.extend VersionHelper
|
|
35
|
-
config.extend
|
|
42
|
+
config.extend ConditionalFilterHelper
|
|
36
43
|
config.mock_framework = :mocha
|
|
37
44
|
config.before(:all) do
|
|
38
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 |
|
data/spec/support/fake_model.rb
CHANGED
|
Binary file
|
|
@@ -8,7 +8,16 @@ RSpec::Matchers.define :have_column do |column_name|
|
|
|
8
8
|
column && column.default.to_s == @default.to_s
|
|
9
9
|
end
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
failure_message_method =
|
|
12
|
+
if RSpec::Version::STRING.to_i >= 3
|
|
13
|
+
:failure_message
|
|
14
|
+
else
|
|
15
|
+
:failure_message_for_should
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
send(failure_message_method) do |columns|
|
|
19
|
+
"expected to find '#{column_name}', " +
|
|
20
|
+
"default '#{@default}' " +
|
|
21
|
+
"in #{columns.map { |column| [column.name, column.default] }}"
|
|
13
22
|
end
|
|
14
23
|
end
|
|
@@ -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
|
|