kt-paperclip 5.4.0 → 6.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/issue_template.md +3 -0
- data/.hound.yml +27 -32
- data/.travis.yml +23 -2
- data/Appraisals +17 -0
- data/Gemfile +9 -7
- data/NEWS +21 -0
- data/README.md +27 -37
- data/Rakefile +29 -21
- data/UPGRADING +3 -3
- data/features/basic_integration.feature +4 -0
- data/features/migration.feature +10 -51
- data/features/step_definitions/attachment_steps.rb +12 -12
- data/features/step_definitions/html_steps.rb +5 -5
- data/features/step_definitions/rails_steps.rb +29 -9
- data/features/step_definitions/s3_steps.rb +3 -3
- data/features/step_definitions/web_steps.rb +5 -6
- data/features/support/env.rb +4 -4
- data/features/support/fakeweb.rb +3 -5
- data/features/support/file_helpers.rb +2 -2
- data/features/support/paths.rb +4 -4
- data/features/support/rails.rb +7 -7
- data/features/support/selectors.rb +1 -1
- data/gemfiles/4.2.gemfile +7 -4
- data/gemfiles/5.0.gemfile +7 -4
- data/gemfiles/5.1.gemfile +20 -0
- data/gemfiles/5.2.gemfile +20 -0
- data/gemfiles/6.0.gemfile +20 -0
- data/lib/generators/paperclip/paperclip_generator.rb +6 -8
- data/lib/paperclip/attachment.rb +102 -104
- data/lib/paperclip/attachment_registry.rb +2 -2
- data/lib/paperclip/file_command_content_type_detector.rb +1 -3
- data/lib/paperclip/filename_cleaner.rb +0 -1
- data/lib/paperclip/geometry.rb +18 -19
- data/lib/paperclip/geometry_detector_factory.rb +13 -16
- data/lib/paperclip/geometry_parser_factory.rb +5 -5
- data/lib/paperclip/glue.rb +3 -3
- data/lib/paperclip/has_attached_file.rb +5 -4
- data/lib/paperclip/helpers.rb +3 -3
- data/lib/paperclip/interpolations.rb +42 -38
- data/lib/paperclip/io_adapters/abstract_adapter.rb +16 -14
- data/lib/paperclip/io_adapters/attachment_adapter.rb +12 -6
- data/lib/paperclip/io_adapters/data_uri_adapter.rb +1 -1
- data/lib/paperclip/io_adapters/file_adapter.rb +1 -3
- data/lib/paperclip/io_adapters/http_url_proxy_adapter.rb +3 -3
- data/lib/paperclip/io_adapters/identity_adapter.rb +1 -2
- data/lib/paperclip/io_adapters/registry.rb +1 -1
- data/lib/paperclip/io_adapters/stringio_adapter.rb +1 -1
- data/lib/paperclip/io_adapters/uploaded_file_adapter.rb +6 -8
- data/lib/paperclip/io_adapters/uri_adapter.rb +9 -7
- data/lib/paperclip/logger.rb +1 -1
- data/lib/paperclip/matchers/have_attached_file_matcher.rb +4 -4
- data/lib/paperclip/matchers/validate_attachment_content_type_matcher.rb +19 -18
- data/lib/paperclip/matchers/validate_attachment_presence_matcher.rb +4 -4
- data/lib/paperclip/matchers/validate_attachment_size_matcher.rb +11 -10
- data/lib/paperclip/matchers.rb +4 -4
- data/lib/paperclip/media_type_spoof_detector.rb +13 -13
- data/lib/paperclip/missing_attachment_styles.rb +11 -6
- data/lib/paperclip/processor.rb +13 -6
- data/lib/paperclip/processor_helpers.rb +3 -1
- data/lib/paperclip/rails_environment.rb +1 -5
- data/lib/paperclip/railtie.rb +5 -5
- data/lib/paperclip/schema.rb +18 -14
- data/lib/paperclip/storage/filesystem.rb +5 -7
- data/lib/paperclip/storage/fog.rb +36 -32
- data/lib/paperclip/storage/s3.rb +67 -75
- data/lib/paperclip/style.rb +3 -6
- data/lib/paperclip/tempfile.rb +4 -5
- data/lib/paperclip/tempfile_factory.rb +0 -1
- data/lib/paperclip/thumbnail.rb +11 -11
- data/lib/paperclip/url_generator.rb +5 -12
- data/lib/paperclip/validators/attachment_content_type_validator.rb +3 -3
- data/lib/paperclip/validators/attachment_file_name_validator.rb +5 -10
- data/lib/paperclip/validators/attachment_file_type_ignorance_validator.rb +1 -2
- data/lib/paperclip/validators/attachment_presence_validator.rb +3 -5
- data/lib/paperclip/validators/attachment_size_validator.rb +8 -8
- data/lib/paperclip/validators/media_type_spoof_detection_validator.rb +3 -1
- data/lib/paperclip/validators.rb +12 -13
- data/lib/paperclip/version.rb +1 -3
- data/lib/paperclip.rb +49 -48
- data/lib/tasks/paperclip.rake +23 -24
- data/paperclip.gemspec +29 -33
- data/shoulda_macros/paperclip.rb +16 -16
- data/spec/paperclip/attachment_definitions_spec.rb +5 -5
- data/spec/paperclip/attachment_processing_spec.rb +22 -23
- data/spec/paperclip/attachment_registry_spec.rb +15 -15
- data/spec/paperclip/attachment_spec.rb +238 -196
- data/spec/paperclip/content_type_detector_spec.rb +11 -12
- data/spec/paperclip/file_command_content_type_detector_spec.rb +10 -10
- data/spec/paperclip/filename_cleaner_spec.rb +3 -4
- data/spec/paperclip/geometry_detector_spec.rb +7 -8
- data/spec/paperclip/geometry_parser_spec.rb +31 -31
- data/spec/paperclip/geometry_spec.rb +24 -24
- data/spec/paperclip/glue_spec.rb +3 -5
- data/spec/paperclip/has_attached_file_spec.rb +46 -126
- data/spec/paperclip/integration_spec.rb +111 -77
- data/spec/paperclip/interpolations_spec.rb +101 -93
- data/spec/paperclip/io_adapters/abstract_adapter_spec.rb +41 -13
- data/spec/paperclip/io_adapters/attachment_adapter_spec.rb +8 -10
- data/spec/paperclip/io_adapters/data_uri_adapter_spec.rb +13 -14
- data/spec/paperclip/io_adapters/empty_string_adapter_spec.rb +4 -4
- data/spec/paperclip/io_adapters/file_adapter_spec.rb +12 -12
- data/spec/paperclip/io_adapters/http_url_proxy_adapter_spec.rb +42 -26
- data/spec/paperclip/io_adapters/identity_adapter_spec.rb +1 -1
- data/spec/paperclip/io_adapters/nil_adapter_spec.rb +2 -2
- data/spec/paperclip/io_adapters/registry_spec.rb +4 -4
- data/spec/paperclip/io_adapters/stringio_adapter_spec.rb +10 -10
- data/spec/paperclip/io_adapters/uploaded_file_adapter_spec.rb +6 -6
- data/spec/paperclip/io_adapters/uri_adapter_spec.rb +80 -31
- data/spec/paperclip/matchers/have_attached_file_matcher_spec.rb +3 -3
- data/spec/paperclip/matchers/validate_attachment_content_type_matcher_spec.rb +4 -5
- data/spec/paperclip/matchers/validate_attachment_presence_matcher_spec.rb +4 -4
- data/spec/paperclip/matchers/validate_attachment_size_matcher_spec.rb +4 -4
- data/spec/paperclip/media_type_spoof_detector_spec.rb +50 -24
- data/spec/paperclip/meta_class_spec.rb +3 -3
- data/spec/paperclip/paperclip_missing_attachment_styles_spec.rb +28 -24
- data/spec/paperclip/paperclip_spec.rb +15 -11
- data/spec/paperclip/plural_cache_spec.rb +8 -8
- data/spec/paperclip/processor_helpers_spec.rb +35 -35
- data/spec/paperclip/processor_spec.rb +8 -8
- data/spec/paperclip/rails_environment_spec.rb +7 -10
- data/spec/paperclip/rake_spec.rb +39 -39
- data/spec/paperclip/schema_spec.rb +57 -53
- data/spec/paperclip/storage/filesystem_spec.rb +6 -6
- data/spec/paperclip/storage/fog_spec.rb +76 -82
- data/spec/paperclip/storage/s3_live_spec.rb +22 -22
- data/spec/paperclip/storage/s3_spec.rb +585 -583
- data/spec/paperclip/style_spec.rb +67 -71
- data/spec/paperclip/tempfile_factory_spec.rb +5 -5
- data/spec/paperclip/thumbnail_spec.rb +68 -67
- data/spec/paperclip/url_generator_spec.rb +18 -29
- data/spec/paperclip/validators/attachment_content_type_validator_spec.rb +27 -27
- data/spec/paperclip/validators/attachment_file_name_validator_spec.rb +15 -16
- data/spec/paperclip/validators/attachment_presence_validator_spec.rb +5 -5
- data/spec/paperclip/validators/attachment_size_validator_spec.rb +21 -21
- data/spec/paperclip/validators/media_type_spoof_detection_validator_spec.rb +9 -13
- data/spec/paperclip/validators_spec.rb +40 -40
- data/spec/spec_helper.rb +21 -23
- data/spec/support/assertions.rb +8 -6
- data/spec/support/fake_model.rb +1 -2
- data/spec/support/fake_rails.rb +1 -1
- data/spec/support/matchers/exist.rb +1 -1
- data/spec/support/matchers/have_column.rb +1 -1
- data/spec/support/mock_url_generator_builder.rb +2 -3
- data/spec/support/model_reconstruction.rb +16 -12
- data/spec/support/reporting.rb +1 -1
- data/spec/support/test_data.rb +2 -2
- metadata +49 -105
- data/lib/kt-paperclip.rb +0 -1
- data/spec/support/conditional_filter_helper.rb +0 -5
@@ -1,5 +1,4 @@
|
|
1
|
-
|
2
|
-
require 'spec_helper'
|
1
|
+
require "spec_helper"
|
3
2
|
|
4
3
|
describe Paperclip::UrlGenerator do
|
5
4
|
it "uses the given interpolator" do
|
@@ -25,20 +24,20 @@ describe Paperclip::UrlGenerator do
|
|
25
24
|
url_generator.for(:style_name, {})
|
26
25
|
|
27
26
|
assert mock_interpolator.has_interpolated_pattern?(default_url),
|
28
|
-
|
27
|
+
"expected the interpolator to be passed #{default_url.inspect} but it wasn't"
|
29
28
|
end
|
30
29
|
|
31
30
|
it "executes the default URL lambda when no file is assigned" do
|
32
31
|
mock_interpolator = MockInterpolator.new
|
33
|
-
default_url = lambda {|attachment| "the #{attachment.class.name} default url" }
|
34
|
-
options = { interpolator: mock_interpolator, default_url: default_url}
|
32
|
+
default_url = lambda { |attachment| "the #{attachment.class.name} default url" }
|
33
|
+
options = { interpolator: mock_interpolator, default_url: default_url }
|
35
34
|
mock_attachment = MockAttachment.new(options)
|
36
35
|
|
37
36
|
url_generator = Paperclip::UrlGenerator.new(mock_attachment)
|
38
37
|
url_generator.for(:style_name, {})
|
39
38
|
|
40
39
|
assert mock_interpolator.has_interpolated_pattern?("the MockAttachment default url"),
|
41
|
-
|
40
|
+
%{expected the interpolator to be passed "the MockAttachment default url", but it wasn't}
|
42
41
|
end
|
43
42
|
|
44
43
|
it "executes the method named by the symbol as the default URL when no file is assigned" do
|
@@ -56,7 +55,7 @@ describe Paperclip::UrlGenerator do
|
|
56
55
|
url_generator.for(:style_name, {})
|
57
56
|
|
58
57
|
assert mock_interpolator.has_interpolated_pattern?(mock_model.to_s),
|
59
|
-
|
58
|
+
%{expected the interpolator to be passed #{mock_model}, but it wasn't}
|
60
59
|
end
|
61
60
|
|
62
61
|
it "URL-escapes spaces if asked to" do
|
@@ -66,7 +65,7 @@ describe Paperclip::UrlGenerator do
|
|
66
65
|
mock_attachment = MockAttachment.new(options)
|
67
66
|
url_generator = Paperclip::UrlGenerator.new(mock_attachment)
|
68
67
|
|
69
|
-
result = url_generator.for(:style_name,
|
68
|
+
result = url_generator.for(:style_name, escape: true)
|
70
69
|
|
71
70
|
assert_equal "the%20expected%20result", result
|
72
71
|
end
|
@@ -82,7 +81,7 @@ describe Paperclip::UrlGenerator do
|
|
82
81
|
mock_attachment = MockAttachment.new(options)
|
83
82
|
url_generator = Paperclip::UrlGenerator.new(mock_attachment)
|
84
83
|
|
85
|
-
result = url_generator.for(:style_name,
|
84
|
+
result = url_generator.for(:style_name, escape: true)
|
86
85
|
|
87
86
|
assert_equal "the escaped result", result
|
88
87
|
end
|
@@ -94,7 +93,7 @@ describe Paperclip::UrlGenerator do
|
|
94
93
|
mock_attachment = MockAttachment.new(options)
|
95
94
|
url_generator = Paperclip::UrlGenerator.new(mock_attachment)
|
96
95
|
|
97
|
-
result = url_generator.for(:style_name,
|
96
|
+
result = url_generator.for(:style_name, escape: false)
|
98
97
|
|
99
98
|
assert_equal "the expected result", result
|
100
99
|
end
|
@@ -118,7 +117,7 @@ describe Paperclip::UrlGenerator do
|
|
118
117
|
mock_attachment = MockAttachment.new(options)
|
119
118
|
url_generator = Paperclip::UrlGenerator.new(mock_attachment)
|
120
119
|
|
121
|
-
result = url_generator.for(:style_name,
|
120
|
+
result = url_generator.for(:style_name, timestamp: true)
|
122
121
|
|
123
122
|
assert_equal expected, result
|
124
123
|
end
|
@@ -134,7 +133,7 @@ describe Paperclip::UrlGenerator do
|
|
134
133
|
mock_attachment = MockAttachment.new(options)
|
135
134
|
url_generator = Paperclip::UrlGenerator.new(mock_attachment)
|
136
135
|
|
137
|
-
result = url_generator.for(:style_name,
|
136
|
+
result = url_generator.for(:style_name, timestamp: true)
|
138
137
|
|
139
138
|
assert_equal expected, result
|
140
139
|
end
|
@@ -147,7 +146,7 @@ describe Paperclip::UrlGenerator do
|
|
147
146
|
mock_attachment = MockAttachment.new(options)
|
148
147
|
url_generator = Paperclip::UrlGenerator.new(mock_attachment)
|
149
148
|
|
150
|
-
result = url_generator.for(:style_name,
|
149
|
+
result = url_generator.for(:style_name, timestamp: true)
|
151
150
|
|
152
151
|
assert_equal "#{expected}?#{updated_at}", result
|
153
152
|
end
|
@@ -160,7 +159,7 @@ describe Paperclip::UrlGenerator do
|
|
160
159
|
mock_attachment = MockAttachment.new(options)
|
161
160
|
url_generator = Paperclip::UrlGenerator.new(mock_attachment)
|
162
161
|
|
163
|
-
result = url_generator.for(:style_name,
|
162
|
+
result = url_generator.for(:style_name, timestamp: true)
|
164
163
|
|
165
164
|
assert_equal "#{expected}&#{updated_at}", result
|
166
165
|
end
|
@@ -173,7 +172,7 @@ describe Paperclip::UrlGenerator do
|
|
173
172
|
mock_attachment = MockAttachment.new(options)
|
174
173
|
url_generator = Paperclip::UrlGenerator.new(mock_attachment)
|
175
174
|
|
176
|
-
result = url_generator.for(:style_name,
|
175
|
+
result = url_generator.for(:style_name, timestamp: false)
|
177
176
|
|
178
177
|
assert_equal expected, result
|
179
178
|
end
|
@@ -192,21 +191,11 @@ describe Paperclip::UrlGenerator do
|
|
192
191
|
url_generator.for(:style_name, {})
|
193
192
|
|
194
193
|
assert mock_interpolator.has_interpolated_pattern?(expected),
|
195
|
-
|
196
|
-
end
|
197
|
-
|
198
|
-
it "doesn't emit deprecation warnings" do
|
199
|
-
expected = "the expected result"
|
200
|
-
mock_interpolator = MockInterpolator.new(result: expected)
|
201
|
-
options = { interpolator: mock_interpolator }
|
202
|
-
mock_attachment = MockAttachment.new(options)
|
203
|
-
url_generator = Paperclip::UrlGenerator.new(mock_attachment)
|
204
|
-
|
205
|
-
expect { url_generator.for(:style_name, escape: true) }.to_not(output(/URI\.(un)?escape is obsolete/).to_stderr)
|
194
|
+
"expected the interpolator to be passed #{expected.inspect} but it wasn't"
|
206
195
|
end
|
207
196
|
|
208
197
|
describe "should be able to escape (, ), [, and ]." do
|
209
|
-
def generate(expected, updated_at=nil)
|
198
|
+
def generate(expected, updated_at = nil)
|
210
199
|
mock_interpolator = MockInterpolator.new(result: expected)
|
211
200
|
options = { interpolator: mock_interpolator, updated_at: updated_at }
|
212
201
|
mock_attachment = MockAttachment.new(options)
|
@@ -214,7 +203,7 @@ describe Paperclip::UrlGenerator do
|
|
214
203
|
def url_generator.respond_to(params)
|
215
204
|
false if params == :escape
|
216
205
|
end
|
217
|
-
url_generator.for(:style_name,
|
206
|
+
url_generator.for(:style_name, escape: true, timestamp: !!updated_at)
|
218
207
|
end
|
219
208
|
|
220
209
|
it "not timestamp" do
|
@@ -226,7 +215,7 @@ describe Paperclip::UrlGenerator do
|
|
226
215
|
expected = "the(expected)result[]"
|
227
216
|
updated_at = 1231231234
|
228
217
|
assert_equal "the%28expected%29result%5B%5D?#{updated_at}",
|
229
|
-
|
218
|
+
generate(expected, updated_at)
|
230
219
|
end
|
231
220
|
end
|
232
221
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
3
|
describe Paperclip::Validators::AttachmentContentTypeValidator do
|
4
4
|
before do
|
@@ -8,14 +8,14 @@ describe Paperclip::Validators::AttachmentContentTypeValidator do
|
|
8
8
|
|
9
9
|
def build_validator(options)
|
10
10
|
@validator = Paperclip::Validators::AttachmentContentTypeValidator.new(options.merge(
|
11
|
-
|
12
|
-
|
11
|
+
attributes: :avatar
|
12
|
+
))
|
13
13
|
end
|
14
14
|
|
15
15
|
context "with a nil content type" do
|
16
16
|
before do
|
17
17
|
build_validator content_type: "image/jpg"
|
18
|
-
@dummy.
|
18
|
+
allow(@dummy).to receive_messages(avatar_content_type: nil)
|
19
19
|
@validator.validate(@dummy)
|
20
20
|
end
|
21
21
|
|
@@ -28,7 +28,7 @@ describe Paperclip::Validators::AttachmentContentTypeValidator do
|
|
28
28
|
context "as true" do
|
29
29
|
before do
|
30
30
|
build_validator content_type: "image/png", allow_nil: true
|
31
|
-
@dummy.
|
31
|
+
allow(@dummy).to receive_messages(avatar_content_type: nil)
|
32
32
|
@validator.validate(@dummy)
|
33
33
|
end
|
34
34
|
|
@@ -40,7 +40,7 @@ describe Paperclip::Validators::AttachmentContentTypeValidator do
|
|
40
40
|
context "as false" do
|
41
41
|
before do
|
42
42
|
build_validator content_type: "image/png", allow_nil: false
|
43
|
-
@dummy.
|
43
|
+
allow(@dummy).to receive_messages(avatar_content_type: nil)
|
44
44
|
@validator.validate(@dummy)
|
45
45
|
end
|
46
46
|
|
@@ -53,13 +53,13 @@ describe Paperclip::Validators::AttachmentContentTypeValidator do
|
|
53
53
|
context "with a failing validation" do
|
54
54
|
before do
|
55
55
|
build_validator content_type: "image/png", allow_nil: false
|
56
|
-
@dummy.
|
56
|
+
allow(@dummy).to receive_messages(avatar_content_type: nil)
|
57
57
|
@validator.validate(@dummy)
|
58
58
|
end
|
59
59
|
|
60
60
|
it "adds error to the base object" do
|
61
61
|
assert @dummy.errors[:avatar].present?,
|
62
|
-
|
62
|
+
"Error not added to base attribute"
|
63
63
|
end
|
64
64
|
|
65
65
|
it "adds error to base object as a string" do
|
@@ -70,13 +70,13 @@ describe Paperclip::Validators::AttachmentContentTypeValidator do
|
|
70
70
|
context "with a successful validation" do
|
71
71
|
before do
|
72
72
|
build_validator content_type: "image/png", allow_nil: false
|
73
|
-
@dummy.
|
73
|
+
allow(@dummy).to receive_messages(avatar_content_type: "image/png")
|
74
74
|
@validator.validate(@dummy)
|
75
75
|
end
|
76
76
|
|
77
77
|
it "does not add error to the base object" do
|
78
78
|
assert @dummy.errors[:avatar].blank?,
|
79
|
-
|
79
|
+
"Error was added to base attribute"
|
80
80
|
end
|
81
81
|
end
|
82
82
|
|
@@ -84,7 +84,7 @@ describe Paperclip::Validators::AttachmentContentTypeValidator do
|
|
84
84
|
context "as true" do
|
85
85
|
before do
|
86
86
|
build_validator content_type: "image/png", allow_blank: true
|
87
|
-
@dummy.
|
87
|
+
allow(@dummy).to receive_messages(avatar_content_type: "")
|
88
88
|
@validator.validate(@dummy)
|
89
89
|
end
|
90
90
|
|
@@ -96,7 +96,7 @@ describe Paperclip::Validators::AttachmentContentTypeValidator do
|
|
96
96
|
context "as false" do
|
97
97
|
before do
|
98
98
|
build_validator content_type: "image/png", allow_blank: false
|
99
|
-
@dummy.
|
99
|
+
allow(@dummy).to receive_messages(avatar_content_type: "")
|
100
100
|
@validator.validate(@dummy)
|
101
101
|
end
|
102
102
|
|
@@ -111,7 +111,7 @@ describe Paperclip::Validators::AttachmentContentTypeValidator do
|
|
111
111
|
context "as a string" do
|
112
112
|
before do
|
113
113
|
build_validator content_type: "image/jpg"
|
114
|
-
@dummy.
|
114
|
+
allow(@dummy).to receive_messages(avatar_content_type: "image/jpg")
|
115
115
|
@validator.validate(@dummy)
|
116
116
|
end
|
117
117
|
|
@@ -123,7 +123,7 @@ describe Paperclip::Validators::AttachmentContentTypeValidator do
|
|
123
123
|
context "as an regexp" do
|
124
124
|
before do
|
125
125
|
build_validator content_type: /^image\/.*/
|
126
|
-
@dummy.
|
126
|
+
allow(@dummy).to receive_messages(avatar_content_type: "image/jpg")
|
127
127
|
@validator.validate(@dummy)
|
128
128
|
end
|
129
129
|
|
@@ -135,7 +135,7 @@ describe Paperclip::Validators::AttachmentContentTypeValidator do
|
|
135
135
|
context "as a list" do
|
136
136
|
before do
|
137
137
|
build_validator content_type: ["image/png", "image/jpg", "image/jpeg"]
|
138
|
-
@dummy.
|
138
|
+
allow(@dummy).to receive_messages(avatar_content_type: "image/jpg")
|
139
139
|
@validator.validate(@dummy)
|
140
140
|
end
|
141
141
|
|
@@ -149,7 +149,7 @@ describe Paperclip::Validators::AttachmentContentTypeValidator do
|
|
149
149
|
context "as a string" do
|
150
150
|
before do
|
151
151
|
build_validator content_type: "image/png"
|
152
|
-
@dummy.
|
152
|
+
allow(@dummy).to receive_messages(avatar_content_type: "image/jpg")
|
153
153
|
@validator.validate(@dummy)
|
154
154
|
end
|
155
155
|
|
@@ -162,7 +162,7 @@ describe Paperclip::Validators::AttachmentContentTypeValidator do
|
|
162
162
|
context "as a regexp" do
|
163
163
|
before do
|
164
164
|
build_validator content_type: /^text\/.*/
|
165
|
-
@dummy.
|
165
|
+
allow(@dummy).to receive_messages(avatar_content_type: "image/jpg")
|
166
166
|
@validator.validate(@dummy)
|
167
167
|
end
|
168
168
|
|
@@ -176,7 +176,7 @@ describe Paperclip::Validators::AttachmentContentTypeValidator do
|
|
176
176
|
context "without interpolation" do
|
177
177
|
before do
|
178
178
|
build_validator content_type: "image/png", message: "should be a PNG image"
|
179
|
-
@dummy.
|
179
|
+
allow(@dummy).to receive_messages(avatar_content_type: "image/jpg")
|
180
180
|
@validator.validate(@dummy)
|
181
181
|
end
|
182
182
|
|
@@ -188,7 +188,7 @@ describe Paperclip::Validators::AttachmentContentTypeValidator do
|
|
188
188
|
context "with interpolation" do
|
189
189
|
before do
|
190
190
|
build_validator content_type: "image/png", message: "should have content type %{types}"
|
191
|
-
@dummy.
|
191
|
+
allow(@dummy).to receive_messages(avatar_content_type: "image/jpg")
|
192
192
|
@validator.validate(@dummy)
|
193
193
|
end
|
194
194
|
|
@@ -205,7 +205,7 @@ describe Paperclip::Validators::AttachmentContentTypeValidator do
|
|
205
205
|
context "as a string" do
|
206
206
|
before do
|
207
207
|
build_validator not: "image/gif"
|
208
|
-
@dummy.
|
208
|
+
allow(@dummy).to receive_messages(avatar_content_type: "image/jpg")
|
209
209
|
@validator.validate(@dummy)
|
210
210
|
end
|
211
211
|
|
@@ -217,7 +217,7 @@ describe Paperclip::Validators::AttachmentContentTypeValidator do
|
|
217
217
|
context "as an regexp" do
|
218
218
|
before do
|
219
219
|
build_validator not: /^text\/.*/
|
220
|
-
@dummy.
|
220
|
+
allow(@dummy).to receive_messages(avatar_content_type: "image/jpg")
|
221
221
|
@validator.validate(@dummy)
|
222
222
|
end
|
223
223
|
|
@@ -229,7 +229,7 @@ describe Paperclip::Validators::AttachmentContentTypeValidator do
|
|
229
229
|
context "as a list" do
|
230
230
|
before do
|
231
231
|
build_validator not: ["image/png", "image/jpg", "image/jpeg"]
|
232
|
-
@dummy.
|
232
|
+
allow(@dummy).to receive_messages(avatar_content_type: "image/gif")
|
233
233
|
@validator.validate(@dummy)
|
234
234
|
end
|
235
235
|
|
@@ -243,7 +243,7 @@ describe Paperclip::Validators::AttachmentContentTypeValidator do
|
|
243
243
|
context "as a string" do
|
244
244
|
before do
|
245
245
|
build_validator not: "image/png"
|
246
|
-
@dummy.
|
246
|
+
allow(@dummy).to receive_messages(avatar_content_type: "image/png")
|
247
247
|
@validator.validate(@dummy)
|
248
248
|
end
|
249
249
|
|
@@ -256,7 +256,7 @@ describe Paperclip::Validators::AttachmentContentTypeValidator do
|
|
256
256
|
context "as a regexp" do
|
257
257
|
before do
|
258
258
|
build_validator not: /^text\/.*/
|
259
|
-
@dummy.
|
259
|
+
allow(@dummy).to receive_messages(avatar_content_type: "text/plain")
|
260
260
|
@validator.validate(@dummy)
|
261
261
|
end
|
262
262
|
|
@@ -270,7 +270,7 @@ describe Paperclip::Validators::AttachmentContentTypeValidator do
|
|
270
270
|
context "without interpolation" do
|
271
271
|
before do
|
272
272
|
build_validator not: "image/png", message: "should not be a PNG image"
|
273
|
-
@dummy.
|
273
|
+
allow(@dummy).to receive_messages(avatar_content_type: "image/png")
|
274
274
|
@validator.validate(@dummy)
|
275
275
|
end
|
276
276
|
|
@@ -282,7 +282,7 @@ describe Paperclip::Validators::AttachmentContentTypeValidator do
|
|
282
282
|
context "with interpolation" do
|
283
283
|
before do
|
284
284
|
build_validator not: "image/png", message: "should not have content type %{types}"
|
285
|
-
@dummy.
|
285
|
+
allow(@dummy).to receive_messages(avatar_content_type: "image/png")
|
286
286
|
@validator.validate(@dummy)
|
287
287
|
end
|
288
288
|
|
@@ -300,7 +300,7 @@ describe Paperclip::Validators::AttachmentContentTypeValidator do
|
|
300
300
|
end
|
301
301
|
|
302
302
|
it "adds the validator to the class" do
|
303
|
-
assert Dummy.validators_on(:avatar).any?{ |validator| validator.kind == :attachment_content_type }
|
303
|
+
assert Dummy.validators_on(:avatar).any? { |validator| validator.kind == :attachment_content_type }
|
304
304
|
end
|
305
305
|
end
|
306
306
|
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
3
|
describe Paperclip::Validators::AttachmentFileNameValidator do
|
4
4
|
before do
|
@@ -8,20 +8,20 @@ describe Paperclip::Validators::AttachmentFileNameValidator do
|
|
8
8
|
|
9
9
|
def build_validator(options)
|
10
10
|
@validator = Paperclip::Validators::AttachmentFileNameValidator.new(options.merge(
|
11
|
-
|
12
|
-
|
11
|
+
attributes: :avatar
|
12
|
+
))
|
13
13
|
end
|
14
14
|
|
15
15
|
context "with a failing validation" do
|
16
16
|
before do
|
17
17
|
build_validator matches: /.*\.png$/, allow_nil: false
|
18
|
-
@dummy.
|
18
|
+
allow(@dummy).to receive_messages(avatar_file_name: "data.txt")
|
19
19
|
@validator.validate(@dummy)
|
20
20
|
end
|
21
21
|
|
22
22
|
it "adds error to the base object" do
|
23
23
|
assert @dummy.errors[:avatar].present?,
|
24
|
-
|
24
|
+
"Error not added to base attribute"
|
25
25
|
end
|
26
26
|
|
27
27
|
it "adds error to base object as a string" do
|
@@ -31,7 +31,7 @@ describe Paperclip::Validators::AttachmentFileNameValidator do
|
|
31
31
|
|
32
32
|
it "does not add error to the base object with a successful validation" do
|
33
33
|
build_validator matches: /.*\.png$/, allow_nil: false
|
34
|
-
@dummy.
|
34
|
+
allow(@dummy).to receive_messages(avatar_file_name: "image.png")
|
35
35
|
@validator.validate(@dummy)
|
36
36
|
|
37
37
|
assert @dummy.errors[:avatar].blank?, "Error was added to base attribute"
|
@@ -42,7 +42,7 @@ describe Paperclip::Validators::AttachmentFileNameValidator do
|
|
42
42
|
context "as a single regexp" do
|
43
43
|
before do
|
44
44
|
build_validator matches: /.*\.jpg$/
|
45
|
-
@dummy.
|
45
|
+
allow(@dummy).to receive_messages(avatar_file_name: "image.jpg")
|
46
46
|
@validator.validate(@dummy)
|
47
47
|
end
|
48
48
|
|
@@ -54,7 +54,7 @@ describe Paperclip::Validators::AttachmentFileNameValidator do
|
|
54
54
|
context "as a list" do
|
55
55
|
before do
|
56
56
|
build_validator matches: [/.*\.png$/, /.*\.jpe?g$/]
|
57
|
-
@dummy.
|
57
|
+
allow(@dummy).to receive_messages(avatar_file_name: "image.jpg")
|
58
58
|
@validator.validate(@dummy)
|
59
59
|
end
|
60
60
|
|
@@ -67,7 +67,7 @@ describe Paperclip::Validators::AttachmentFileNameValidator do
|
|
67
67
|
context "with a disallowed type" do
|
68
68
|
it "sets a correct default error message" do
|
69
69
|
build_validator matches: /^text\/.*/
|
70
|
-
@dummy.
|
70
|
+
allow(@dummy).to receive_messages(avatar_file_name: "image.jpg")
|
71
71
|
@validator.validate(@dummy)
|
72
72
|
|
73
73
|
assert @dummy.errors[:avatar_file_name].present?
|
@@ -76,7 +76,7 @@ describe Paperclip::Validators::AttachmentFileNameValidator do
|
|
76
76
|
|
77
77
|
it "sets a correct custom error message" do
|
78
78
|
build_validator matches: /.*\.png$/, message: "should be a PNG image"
|
79
|
-
@dummy.
|
79
|
+
allow(@dummy).to receive_messages(avatar_file_name: "image.jpg")
|
80
80
|
@validator.validate(@dummy)
|
81
81
|
|
82
82
|
expect(@dummy.errors[:avatar_file_name]).to include "should be a PNG image"
|
@@ -89,7 +89,7 @@ describe Paperclip::Validators::AttachmentFileNameValidator do
|
|
89
89
|
context "as a single regexp" do
|
90
90
|
before do
|
91
91
|
build_validator not: /^text\/.*/
|
92
|
-
@dummy.
|
92
|
+
allow(@dummy).to receive_messages(avatar_file_name: "image.jpg")
|
93
93
|
@validator.validate(@dummy)
|
94
94
|
end
|
95
95
|
|
@@ -101,7 +101,7 @@ describe Paperclip::Validators::AttachmentFileNameValidator do
|
|
101
101
|
context "as a list" do
|
102
102
|
before do
|
103
103
|
build_validator not: [/.*\.png$/, /.*\.jpe?g$/]
|
104
|
-
@dummy.
|
104
|
+
allow(@dummy).to receive_messages(avatar_file_name: "image.gif")
|
105
105
|
@validator.validate(@dummy)
|
106
106
|
end
|
107
107
|
|
@@ -114,7 +114,7 @@ describe Paperclip::Validators::AttachmentFileNameValidator do
|
|
114
114
|
context "with a disallowed type" do
|
115
115
|
it "sets a correct default error message" do
|
116
116
|
build_validator not: /data.*/
|
117
|
-
@dummy.
|
117
|
+
allow(@dummy).to receive_messages(avatar_file_name: "data.txt")
|
118
118
|
@validator.validate(@dummy)
|
119
119
|
|
120
120
|
assert @dummy.errors[:avatar_file_name].present?
|
@@ -123,7 +123,7 @@ describe Paperclip::Validators::AttachmentFileNameValidator do
|
|
123
123
|
|
124
124
|
it "sets a correct custom error message" do
|
125
125
|
build_validator not: /.*\.png$/, message: "should not be a PNG image"
|
126
|
-
@dummy.
|
126
|
+
allow(@dummy).to receive_messages(avatar_file_name: "image.png")
|
127
127
|
@validator.validate(@dummy)
|
128
128
|
|
129
129
|
expect(@dummy.errors[:avatar_file_name]).to include "should not be a PNG image"
|
@@ -137,7 +137,7 @@ describe Paperclip::Validators::AttachmentFileNameValidator do
|
|
137
137
|
end
|
138
138
|
|
139
139
|
it "adds the validator to the class" do
|
140
|
-
assert Dummy.validators_on(:avatar).any?{ |validator| validator.kind == :attachment_file_name }
|
140
|
+
assert Dummy.validators_on(:avatar).any? { |validator| validator.kind == :attachment_file_name }
|
141
141
|
end
|
142
142
|
end
|
143
143
|
|
@@ -157,4 +157,3 @@ describe Paperclip::Validators::AttachmentFileNameValidator do
|
|
157
157
|
end
|
158
158
|
end
|
159
159
|
end
|
160
|
-
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
3
|
describe Paperclip::Validators::AttachmentPresenceValidator do
|
4
4
|
before do
|
@@ -6,10 +6,10 @@ describe Paperclip::Validators::AttachmentPresenceValidator do
|
|
6
6
|
@dummy = Dummy.new
|
7
7
|
end
|
8
8
|
|
9
|
-
def build_validator(options={})
|
9
|
+
def build_validator(options = {})
|
10
10
|
@validator = Paperclip::Validators::AttachmentPresenceValidator.new(options.merge(
|
11
|
-
|
12
|
-
|
11
|
+
attributes: :avatar
|
12
|
+
))
|
13
13
|
end
|
14
14
|
|
15
15
|
context "nil attachment" do
|
@@ -79,7 +79,7 @@ describe Paperclip::Validators::AttachmentPresenceValidator do
|
|
79
79
|
end
|
80
80
|
|
81
81
|
it "adds the validator to the class" do
|
82
|
-
assert Dummy.validators_on(:avatar).any?{ |validator| validator.kind == :attachment_presence }
|
82
|
+
assert Dummy.validators_on(:avatar).any? { |validator| validator.kind == :attachment_presence }
|
83
83
|
end
|
84
84
|
end
|
85
85
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
3
|
describe Paperclip::Validators::AttachmentSizeValidator do
|
4
4
|
before do
|
@@ -8,22 +8,22 @@ describe Paperclip::Validators::AttachmentSizeValidator do
|
|
8
8
|
|
9
9
|
def build_validator(options)
|
10
10
|
@validator = Paperclip::Validators::AttachmentSizeValidator.new(options.merge(
|
11
|
-
|
12
|
-
|
11
|
+
attributes: :avatar
|
12
|
+
))
|
13
13
|
end
|
14
14
|
|
15
15
|
def self.should_allow_attachment_file_size(size)
|
16
16
|
context "when the attachment size is #{size}" do
|
17
17
|
it "adds error to dummy object" do
|
18
|
-
@dummy.
|
18
|
+
allow(@dummy).to receive(:avatar_content_type).and_return(size)
|
19
19
|
@validator.validate(@dummy)
|
20
20
|
assert @dummy.errors[:avatar_file_size].blank?,
|
21
|
-
|
21
|
+
"Expect an error message on :avatar_file_size, got none."
|
22
22
|
end
|
23
23
|
|
24
24
|
it "does not add error to the base dummy object" do
|
25
25
|
assert @dummy.errors[:avatar].blank?,
|
26
|
-
|
26
|
+
"Error added to base attribute"
|
27
27
|
end
|
28
28
|
end
|
29
29
|
end
|
@@ -31,18 +31,18 @@ describe Paperclip::Validators::AttachmentSizeValidator do
|
|
31
31
|
def self.should_not_allow_attachment_file_size(size, options = {})
|
32
32
|
context "when the attachment size is #{size}" do
|
33
33
|
before do
|
34
|
-
@dummy.
|
34
|
+
allow(@dummy).to receive(:avatar_file_size).and_return(size)
|
35
35
|
@validator.validate(@dummy)
|
36
36
|
end
|
37
37
|
|
38
38
|
it "adds error to dummy object" do
|
39
39
|
assert @dummy.errors[:avatar_file_size].present?,
|
40
|
-
|
40
|
+
"Unexpected error message on :avatar_file_size"
|
41
41
|
end
|
42
42
|
|
43
43
|
it "adds error to the base dummy object" do
|
44
44
|
assert @dummy.errors[:avatar].present?,
|
45
|
-
|
45
|
+
"Error not added to base attribute"
|
46
46
|
end
|
47
47
|
|
48
48
|
it "adds error to base object as a string" do
|
@@ -70,7 +70,7 @@ describe Paperclip::Validators::AttachmentSizeValidator do
|
|
70
70
|
|
71
71
|
context "as a proc" do
|
72
72
|
before do
|
73
|
-
build_validator in: lambda { |
|
73
|
+
build_validator in: lambda { |_avatar| (5.kilobytes..10.kilobytes) }
|
74
74
|
end
|
75
75
|
|
76
76
|
should_allow_attachment_file_size(7.kilobytes)
|
@@ -91,7 +91,7 @@ describe Paperclip::Validators::AttachmentSizeValidator do
|
|
91
91
|
|
92
92
|
context "as a proc" do
|
93
93
|
before do
|
94
|
-
build_validator greater_than: lambda { |
|
94
|
+
build_validator greater_than: lambda { |_avatar| 10.kilobytes }
|
95
95
|
end
|
96
96
|
|
97
97
|
should_allow_attachment_file_size 11.kilobytes
|
@@ -111,7 +111,7 @@ describe Paperclip::Validators::AttachmentSizeValidator do
|
|
111
111
|
|
112
112
|
context "as a proc" do
|
113
113
|
before do
|
114
|
-
build_validator less_than: lambda { |
|
114
|
+
build_validator less_than: lambda { |_avatar| 10.kilobytes }
|
115
115
|
end
|
116
116
|
|
117
117
|
should_allow_attachment_file_size 9.kilobytes
|
@@ -123,7 +123,7 @@ describe Paperclip::Validators::AttachmentSizeValidator do
|
|
123
123
|
context "as numbers" do
|
124
124
|
before do
|
125
125
|
build_validator greater_than: 5.kilobytes,
|
126
|
-
|
126
|
+
less_than: 10.kilobytes
|
127
127
|
end
|
128
128
|
|
129
129
|
should_allow_attachment_file_size 7.kilobytes
|
@@ -133,8 +133,8 @@ describe Paperclip::Validators::AttachmentSizeValidator do
|
|
133
133
|
|
134
134
|
context "as a proc" do
|
135
135
|
before do
|
136
|
-
build_validator greater_than: lambda { |
|
137
|
-
|
136
|
+
build_validator greater_than: lambda { |_avatar| 5.kilobytes },
|
137
|
+
less_than: lambda { |_avatar| 10.kilobytes }
|
138
138
|
end
|
139
139
|
|
140
140
|
should_allow_attachment_file_size 7.kilobytes
|
@@ -147,7 +147,7 @@ describe Paperclip::Validators::AttachmentSizeValidator do
|
|
147
147
|
context "given a range" do
|
148
148
|
before do
|
149
149
|
build_validator in: (5.kilobytes..10.kilobytes),
|
150
|
-
|
150
|
+
message: "is invalid. (Between %{min} and %{max} please.)"
|
151
151
|
end
|
152
152
|
|
153
153
|
should_not_allow_attachment_file_size(
|
@@ -159,8 +159,8 @@ describe Paperclip::Validators::AttachmentSizeValidator do
|
|
159
159
|
context "given :less_than and :greater_than" do
|
160
160
|
before do
|
161
161
|
build_validator less_than: 10.kilobytes,
|
162
|
-
|
163
|
-
|
162
|
+
greater_than: 5.kilobytes,
|
163
|
+
message: "is invalid. (Between %{min} and %{max} please.)"
|
164
164
|
end
|
165
165
|
|
166
166
|
should_not_allow_attachment_file_size(
|
@@ -174,7 +174,7 @@ describe Paperclip::Validators::AttachmentSizeValidator do
|
|
174
174
|
context "given :less_than and :greater_than" do
|
175
175
|
before do
|
176
176
|
build_validator greater_than: 5.kilobytes,
|
177
|
-
|
177
|
+
less_than: 10.kilobytes
|
178
178
|
end
|
179
179
|
|
180
180
|
should_not_allow_attachment_file_size(
|
@@ -211,7 +211,7 @@ describe Paperclip::Validators::AttachmentSizeValidator do
|
|
211
211
|
end
|
212
212
|
|
213
213
|
it "adds the validator to the class" do
|
214
|
-
assert Dummy.validators_on(:avatar).any?{ |validator| validator.kind == :attachment_size }
|
214
|
+
assert Dummy.validators_on(:avatar).any? { |validator| validator.kind == :attachment_size }
|
215
215
|
end
|
216
216
|
end
|
217
217
|
|
@@ -222,7 +222,7 @@ describe Paperclip::Validators::AttachmentSizeValidator do
|
|
222
222
|
end
|
223
223
|
end
|
224
224
|
|
225
|
-
|
225
|
+
Paperclip::Validators::AttachmentSizeValidator::AVAILABLE_CHECKS.each do |argument|
|
226
226
|
it "does not raise arguemnt error if #{argument} was given" do
|
227
227
|
build_validator argument => 5.kilobytes
|
228
228
|
end
|