paperclip 4.1.1 → 4.2.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of paperclip might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/.gitignore +0 -6
- data/.travis.yml +4 -13
- data/Appraisals +0 -10
- data/CONTRIBUTING.md +10 -5
- data/Gemfile +8 -4
- data/NEWS +1 -1
- data/README.md +51 -10
- data/Rakefile +6 -8
- data/features/basic_integration.feature +5 -5
- data/features/step_definitions/attachment_steps.rb +4 -4
- data/features/step_definitions/rails_steps.rb +4 -4
- data/features/step_definitions/web_steps.rb +2 -2
- data/features/support/env.rb +2 -2
- data/features/support/fixtures/gemfile.txt +1 -1
- data/features/support/rails.rb +2 -1
- data/gemfiles/3.2.gemfile +5 -3
- data/gemfiles/4.0.gemfile +5 -3
- data/gemfiles/4.1.gemfile +5 -3
- data/lib/generators/paperclip/paperclip_generator.rb +0 -2
- data/lib/generators/paperclip/templates/paperclip_migration.rb.erb +1 -1
- data/lib/paperclip.rb +4 -1
- data/lib/paperclip/attachment.rb +90 -29
- data/lib/paperclip/content_type_detector.rb +1 -1
- data/lib/paperclip/geometry_detector_factory.rb +3 -1
- data/lib/paperclip/has_attached_file.rb +2 -1
- data/lib/paperclip/interpolations.rb +8 -0
- data/lib/paperclip/io_adapters/abstract_adapter.rb +1 -1
- data/lib/paperclip/io_adapters/data_uri_adapter.rb +1 -1
- data/lib/paperclip/io_adapters/stringio_adapter.rb +5 -11
- data/lib/paperclip/locales/de.yml +18 -0
- data/lib/paperclip/locales/es.yml +18 -0
- data/lib/paperclip/matchers/have_attached_file_matcher.rb +2 -1
- data/lib/paperclip/matchers/validate_attachment_presence_matcher.rb +2 -1
- data/lib/paperclip/matchers/validate_attachment_size_matcher.rb +2 -1
- data/lib/paperclip/media_type_spoof_detector.rb +10 -2
- data/lib/paperclip/storage/filesystem.rb +1 -1
- data/lib/paperclip/storage/s3.rb +26 -4
- data/lib/paperclip/style.rb +1 -1
- data/lib/paperclip/thumbnail.rb +6 -6
- data/lib/paperclip/validators.rb +5 -3
- data/lib/paperclip/validators/attachment_size_validator.rb +7 -3
- data/lib/paperclip/version.rb +1 -1
- data/lib/tasks/paperclip.rake +1 -2
- data/paperclip.gemspec +5 -3
- data/shoulda_macros/paperclip.rb +0 -1
- data/{test → spec}/database.yml +0 -0
- data/spec/paperclip/attachment_definitions_spec.rb +13 -0
- data/{test/attachment_processing_test.rb → spec/paperclip/attachment_processing_spec.rb} +20 -21
- data/{test/attachment_registry_test.rb → spec/paperclip/attachment_registry_spec.rb} +10 -11
- data/{test/attachment_test.rb → spec/paperclip/attachment_spec.rb} +367 -360
- data/{test/content_type_detector_test.rb → spec/paperclip/content_type_detector_spec.rb} +8 -8
- data/{test/file_command_content_type_detector_test.rb → spec/paperclip/file_command_content_type_detector_spec.rb} +5 -5
- data/spec/paperclip/filename_cleaner_spec.rb +14 -0
- data/spec/paperclip/geometry_detector_spec.rb +39 -0
- data/{test/geometry_parser_test.rb → spec/paperclip/geometry_parser_spec.rb} +27 -27
- data/{test/geometry_test.rb → spec/paperclip/geometry_spec.rb} +49 -51
- data/{test/has_attached_file_test.rb → spec/paperclip/has_attached_file_spec.rb} +18 -27
- data/{test/integration_test.rb → spec/paperclip/integration_spec.rb} +134 -126
- data/{test/interpolations_test.rb → spec/paperclip/interpolations_spec.rb} +54 -40
- data/{test/io_adapters/abstract_adapter_test.rb → spec/paperclip/io_adapters/abstract_adapter_spec.rb} +21 -10
- data/{test/io_adapters/attachment_adapter_test.rb → spec/paperclip/io_adapters/attachment_adapter_spec.rb} +27 -29
- data/{test/io_adapters/data_uri_adapter_test.rb → spec/paperclip/io_adapters/data_uri_adapter_spec.rb} +22 -18
- data/spec/paperclip/io_adapters/empty_string_adapter_spec.rb +17 -0
- data/{test/io_adapters/file_adapter_test.rb → spec/paperclip/io_adapters/file_adapter_spec.rb} +32 -28
- data/{test/io_adapters/http_url_proxy_adapter_test.rb → spec/paperclip/io_adapters/http_url_proxy_adapter_spec.rb} +22 -22
- data/spec/paperclip/io_adapters/identity_adapter_spec.rb +8 -0
- data/{test/io_adapters/nil_adapter_test.rb → spec/paperclip/io_adapters/nil_adapter_spec.rb} +7 -7
- data/{test/io_adapters/registry_test.rb → spec/paperclip/io_adapters/registry_spec.rb} +10 -7
- data/{test/io_adapters/stringio_adapter_test.rb → spec/paperclip/io_adapters/stringio_adapter_spec.rb} +16 -17
- data/{test/io_adapters/uploaded_file_adapter_test.rb → spec/paperclip/io_adapters/uploaded_file_adapter_spec.rb} +41 -41
- data/{test/io_adapters/uri_adapter_test.rb → spec/paperclip/io_adapters/uri_adapter_spec.rb} +22 -22
- data/spec/paperclip/matchers/have_attached_file_matcher_spec.rb +19 -0
- data/spec/paperclip/matchers/validate_attachment_content_type_matcher_spec.rb +99 -0
- data/spec/paperclip/matchers/validate_attachment_presence_matcher_spec.rb +69 -0
- data/spec/paperclip/matchers/validate_attachment_size_matcher_spec.rb +88 -0
- data/{test/media_type_spoof_detector_test.rb → spec/paperclip/media_type_spoof_detector_spec.rb} +13 -8
- data/spec/paperclip/meta_class_spec.rb +30 -0
- data/spec/paperclip/paperclip_missing_attachment_styles_spec.rb +84 -0
- data/{test/paperclip_test.rb → spec/paperclip/paperclip_spec.rb} +47 -47
- data/{test/plural_cache_test.rb → spec/paperclip/plural_cache_spec.rb} +6 -6
- data/{test/processor_test.rb → spec/paperclip/processor_spec.rb} +5 -5
- data/{test/rake_test.rb → spec/paperclip/rake_spec.rb} +15 -15
- data/spec/paperclip/schema_spec.rb +206 -0
- data/{test/storage/filesystem_test.rb → spec/paperclip/storage/filesystem_spec.rb} +18 -18
- data/{test/storage/fog_test.rb → spec/paperclip/storage/fog_spec.rb} +145 -140
- data/spec/paperclip/storage/s3_live_spec.rb +182 -0
- data/spec/paperclip/storage/s3_spec.rb +1475 -0
- data/spec/paperclip/style_spec.rb +255 -0
- data/spec/paperclip/tempfile_factory_spec.rb +29 -0
- data/{test/thumbnail_test.rb → spec/paperclip/thumbnail_spec.rb} +107 -107
- data/{test/url_generator_test.rb → spec/paperclip/url_generator_spec.rb} +55 -56
- data/spec/paperclip/validators/attachment_content_type_validator_spec.rb +322 -0
- data/spec/paperclip/validators/attachment_file_name_validator_spec.rb +160 -0
- data/{test/validators/attachment_presence_validator_test.rb → spec/paperclip/validators/attachment_presence_validator_spec.rb} +19 -19
- data/{test/validators/attachment_size_validator_test.rb → spec/paperclip/validators/attachment_size_validator_spec.rb} +65 -58
- data/{test/validators/media_type_spoof_detection_validator_test.rb → spec/paperclip/validators/media_type_spoof_detection_validator_spec.rb} +8 -8
- data/spec/paperclip/validators_spec.rb +164 -0
- data/spec/spec_helper.rb +40 -0
- data/spec/support/assertions.rb +71 -0
- data/spec/support/fake_model.rb +21 -0
- data/spec/support/fake_rails.rb +12 -0
- data/{test → spec/support}/fixtures/12k.png +0 -0
- data/{test → spec/support}/fixtures/50x50.png +0 -0
- data/{test → spec/support}/fixtures/5k.png +0 -0
- data/{test → spec/support}/fixtures/animated +0 -0
- data/{test → spec/support}/fixtures/animated.gif +0 -0
- data/{test → spec/support}/fixtures/animated.unknown +0 -0
- data/{test → spec/support}/fixtures/bad.png +0 -0
- data/{test → spec/support}/fixtures/empty.html +0 -0
- data/{test → spec/support}/fixtures/fog.yml +0 -0
- data/{test → spec/support}/fixtures/rotated.jpg +0 -0
- data/{test → spec/support}/fixtures/s3.yml +0 -0
- data/spec/support/fixtures/spaced file.jpg +0 -0
- data/test/fixtures/spaced file.png b/data/spec/support/fixtures/spaced → file.png +0 -0
- data/{test → spec/support}/fixtures/text.txt +0 -0
- data/{test → spec/support}/fixtures/twopage.pdf +0 -0
- data/{test → spec/support}/fixtures/uppercase.PNG +0 -0
- data/spec/support/matchers/accept.rb +5 -0
- data/spec/support/matchers/exist.rb +5 -0
- data/{test → spec}/support/mock_attachment.rb +0 -0
- data/{test → spec}/support/mock_interpolator.rb +0 -0
- data/{test → spec}/support/mock_model.rb +0 -0
- data/{test → spec}/support/mock_url_generator_builder.rb +0 -0
- data/spec/support/model_reconstruction.rb +60 -0
- data/spec/support/rails_helpers.rb +7 -0
- data/spec/support/test_data.rb +13 -0
- data/spec/support/version_helper.rb +9 -0
- metadata +256 -210
- data/gemfiles/3.0.gemfile +0 -11
- data/gemfiles/3.1.gemfile +0 -11
- data/test/attachment_definitions_test.rb +0 -13
- data/test/filename_cleaner_test.rb +0 -14
- data/test/generator_test.rb +0 -84
- data/test/geometry_detector_test.rb +0 -24
- data/test/helper.rb +0 -239
- data/test/io_adapters/empty_string_adapter_test.rb +0 -18
- data/test/io_adapters/identity_adapter_test.rb +0 -8
- data/test/matchers/have_attached_file_matcher_test.rb +0 -25
- data/test/matchers/validate_attachment_content_type_matcher_test.rb +0 -111
- data/test/matchers/validate_attachment_presence_matcher_test.rb +0 -70
- data/test/matchers/validate_attachment_size_matcher_test.rb +0 -87
- data/test/meta_class_test.rb +0 -32
- data/test/paperclip_missing_attachment_styles_test.rb +0 -90
- data/test/schema_test.rb +0 -206
- data/test/storage/s3_live_test.rb +0 -179
- data/test/storage/s3_test.rb +0 -1357
- data/test/style_test.rb +0 -251
- data/test/tempfile_factory_test.rb +0 -29
- data/test/validators/attachment_content_type_validator_test.rb +0 -324
- data/test/validators/attachment_file_name_validator_test.rb +0 -162
- data/test/validators_test.rb +0 -101
@@ -1,162 +0,0 @@
|
|
1
|
-
require './test/helper'
|
2
|
-
|
3
|
-
class AttachmentFileNameValidatorTest < Test::Unit::TestCase
|
4
|
-
def setup
|
5
|
-
rebuild_model
|
6
|
-
@dummy = Dummy.new
|
7
|
-
super
|
8
|
-
end
|
9
|
-
|
10
|
-
def build_validator(options)
|
11
|
-
@validator = Paperclip::Validators::AttachmentFileNameValidator.new(options.merge(
|
12
|
-
:attributes => :avatar
|
13
|
-
))
|
14
|
-
end
|
15
|
-
|
16
|
-
context "with a failing validation" do
|
17
|
-
setup do
|
18
|
-
build_validator :matches => /.*\.png$/, :allow_nil => false
|
19
|
-
@dummy.stubs(:avatar_file_name => "data.txt")
|
20
|
-
@validator.validate(@dummy)
|
21
|
-
end
|
22
|
-
|
23
|
-
should "add error to the base object" do
|
24
|
-
assert @dummy.errors[:avatar].present?,
|
25
|
-
"Error not added to base attribute"
|
26
|
-
end
|
27
|
-
|
28
|
-
should "add error to base object as a string" do
|
29
|
-
assert_kind_of String, @dummy.errors[:avatar].first,
|
30
|
-
"Error added to base attribute as something other than a String"
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
should "not add error to the base object with a successful validation" do
|
35
|
-
build_validator :matches => /.*\.png$/, :allow_nil => false
|
36
|
-
@dummy.stubs(:avatar_file_name => "image.png")
|
37
|
-
@validator.validate(@dummy)
|
38
|
-
|
39
|
-
assert @dummy.errors[:avatar].blank?, "Error was added to base attribute"
|
40
|
-
end
|
41
|
-
|
42
|
-
context "whitelist format" do
|
43
|
-
context "with an allowed type" do
|
44
|
-
context "as a single regexp" do
|
45
|
-
setup do
|
46
|
-
build_validator :matches => /.*\.jpg$/
|
47
|
-
@dummy.stubs(:avatar_file_name => "image.jpg")
|
48
|
-
@validator.validate(@dummy)
|
49
|
-
end
|
50
|
-
|
51
|
-
should "not set an error message" do
|
52
|
-
assert @dummy.errors[:avatar_file_name].blank?
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
context "as a list" do
|
57
|
-
setup do
|
58
|
-
build_validator :matches => [/.*\.png$/, /.*\.jpe?g$/]
|
59
|
-
@dummy.stubs(:avatar_file_name => "image.jpg")
|
60
|
-
@validator.validate(@dummy)
|
61
|
-
end
|
62
|
-
|
63
|
-
should "not set an error message" do
|
64
|
-
assert @dummy.errors[:avatar_file_name].blank?
|
65
|
-
end
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
context "with a disallowed type" do
|
70
|
-
should "set a correct default error message" do
|
71
|
-
build_validator :matches => /^text\/.*/
|
72
|
-
@dummy.stubs(:avatar_file_name => "image.jpg")
|
73
|
-
@validator.validate(@dummy)
|
74
|
-
|
75
|
-
assert @dummy.errors[:avatar_file_name].present?
|
76
|
-
assert_includes @dummy.errors[:avatar_file_name], "is invalid"
|
77
|
-
end
|
78
|
-
|
79
|
-
should "set a correct custom error message" do
|
80
|
-
build_validator :matches => /.*\.png$/, :message => "should be a PNG image"
|
81
|
-
@dummy.stubs(:avatar_file_name => "image.jpg")
|
82
|
-
@validator.validate(@dummy)
|
83
|
-
|
84
|
-
assert_includes @dummy.errors[:avatar_file_name], "should be a PNG image"
|
85
|
-
end
|
86
|
-
end
|
87
|
-
end
|
88
|
-
|
89
|
-
context "blacklist format" do
|
90
|
-
context "with an allowed type" do
|
91
|
-
context "as a single regexp" do
|
92
|
-
setup do
|
93
|
-
build_validator :not => /^text\/.*/
|
94
|
-
@dummy.stubs(:avatar_file_name => "image.jpg")
|
95
|
-
@validator.validate(@dummy)
|
96
|
-
end
|
97
|
-
|
98
|
-
should "not set an error message" do
|
99
|
-
assert @dummy.errors[:avatar_file_name].blank?
|
100
|
-
end
|
101
|
-
end
|
102
|
-
|
103
|
-
context "as a list" do
|
104
|
-
setup do
|
105
|
-
build_validator :not => [/.*\.png$/, /.*\.jpe?g$/]
|
106
|
-
@dummy.stubs(:avatar_file_name => "image.gif")
|
107
|
-
@validator.validate(@dummy)
|
108
|
-
end
|
109
|
-
|
110
|
-
should "not set an error message" do
|
111
|
-
assert @dummy.errors[:avatar_file_name].blank?
|
112
|
-
end
|
113
|
-
end
|
114
|
-
end
|
115
|
-
|
116
|
-
context "with a disallowed type" do
|
117
|
-
should "set a correct default error message" do
|
118
|
-
build_validator :not => /data.*/
|
119
|
-
@dummy.stubs(:avatar_file_name => "data.txt")
|
120
|
-
@validator.validate(@dummy)
|
121
|
-
|
122
|
-
assert @dummy.errors[:avatar_file_name].present?
|
123
|
-
assert_includes @dummy.errors[:avatar_file_name], "is invalid"
|
124
|
-
end
|
125
|
-
|
126
|
-
should "set a correct custom error message" do
|
127
|
-
build_validator :not => /.*\.png$/, :message => "should not be a PNG image"
|
128
|
-
@dummy.stubs(:avatar_file_name => "image.png")
|
129
|
-
@validator.validate(@dummy)
|
130
|
-
|
131
|
-
assert_includes @dummy.errors[:avatar_file_name], "should not be a PNG image"
|
132
|
-
end
|
133
|
-
end
|
134
|
-
end
|
135
|
-
|
136
|
-
context "using the helper" do
|
137
|
-
setup do
|
138
|
-
Dummy.validates_attachment_file_name :avatar, :matches => /.*\.jpg$/
|
139
|
-
end
|
140
|
-
|
141
|
-
should "add the validator to the class" do
|
142
|
-
assert Dummy.validators_on(:avatar).any?{ |validator| validator.kind == :attachment_file_name }
|
143
|
-
end
|
144
|
-
end
|
145
|
-
|
146
|
-
context "given options" do
|
147
|
-
should "raise argument error if no required argument was given" do
|
148
|
-
assert_raises(ArgumentError) do
|
149
|
-
build_validator :message => "Some message"
|
150
|
-
end
|
151
|
-
end
|
152
|
-
|
153
|
-
should "not raise argument error if :matches was given" do
|
154
|
-
build_validator :matches => /.*\.jpg$/
|
155
|
-
end
|
156
|
-
|
157
|
-
should "not raise argument error if :not was given" do
|
158
|
-
build_validator :not => /.*\.jpg$/
|
159
|
-
end
|
160
|
-
end
|
161
|
-
end
|
162
|
-
|
data/test/validators_test.rb
DELETED
@@ -1,101 +0,0 @@
|
|
1
|
-
require './test/helper'
|
2
|
-
|
3
|
-
class ValidatorsTest < Test::Unit::TestCase
|
4
|
-
include ActiveSupport::Testing::Deprecation
|
5
|
-
|
6
|
-
def setup
|
7
|
-
rebuild_model
|
8
|
-
end
|
9
|
-
|
10
|
-
context "using the helper" do
|
11
|
-
setup do
|
12
|
-
Dummy.validates_attachment :avatar, :presence => true, :content_type => { :content_type => "image/jpeg" }, :size => { :in => 0..10.kilobytes }
|
13
|
-
end
|
14
|
-
|
15
|
-
should "add the attachment_presence validator to the class" do
|
16
|
-
assert Dummy.validators_on(:avatar).any?{ |validator| validator.kind == :attachment_presence }
|
17
|
-
end
|
18
|
-
|
19
|
-
should "add the attachment_content_type validator to the class" do
|
20
|
-
assert Dummy.validators_on(:avatar).any?{ |validator| validator.kind == :attachment_content_type }
|
21
|
-
end
|
22
|
-
|
23
|
-
should "add the attachment_size validator to the class" do
|
24
|
-
assert Dummy.validators_on(:avatar).any?{ |validator| validator.kind == :attachment_size }
|
25
|
-
end
|
26
|
-
|
27
|
-
should 'prevent you from attaching a file that violates that validation' do
|
28
|
-
Dummy.class_eval{ validate(:name) { raise "DO NOT RUN THIS" } }
|
29
|
-
dummy = Dummy.new(:avatar => File.new(fixture_file("12k.png")))
|
30
|
-
assert_equal [:avatar_content_type, :avatar, :avatar_file_size], dummy.errors.keys
|
31
|
-
assert_raise(RuntimeError){ dummy.valid? }
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
context "using the helper with a conditional" do
|
36
|
-
setup do
|
37
|
-
Dummy.validates_attachment :avatar, :presence => true,
|
38
|
-
:content_type => { :content_type => "image/jpeg" },
|
39
|
-
:size => { :in => 0..10.kilobytes },
|
40
|
-
:if => :title_present?
|
41
|
-
end
|
42
|
-
|
43
|
-
should "validate the attachment if title is present" do
|
44
|
-
Dummy.class_eval do
|
45
|
-
def title_present?
|
46
|
-
true
|
47
|
-
end
|
48
|
-
end
|
49
|
-
dummy = Dummy.new(:avatar => File.new(fixture_file("12k.png")))
|
50
|
-
assert_equal [:avatar_content_type, :avatar, :avatar_file_size], dummy.errors.keys
|
51
|
-
end
|
52
|
-
|
53
|
-
should "not validate attachment if tile is not present" do
|
54
|
-
Dummy.class_eval do
|
55
|
-
def title_present?
|
56
|
-
false
|
57
|
-
end
|
58
|
-
end
|
59
|
-
dummy = Dummy.new(:avatar => File.new(fixture_file("12k.png")))
|
60
|
-
assert_equal [], dummy.errors.keys
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
context 'with no other validations on the Dummy#avatar attachment' do
|
65
|
-
setup do
|
66
|
-
reset_class("Dummy")
|
67
|
-
Dummy.has_attached_file :avatar
|
68
|
-
Paperclip.reset_duplicate_clash_check!
|
69
|
-
end
|
70
|
-
|
71
|
-
should 'raise an error when no content_type validation exists' do
|
72
|
-
assert_raises(Paperclip::Errors::MissingRequiredValidatorError) do
|
73
|
-
Dummy.new(:avatar => File.new(fixture_file("12k.png")))
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
should 'not raise an error when a content_type validation exists' do
|
78
|
-
Dummy.validates_attachment :avatar, :content_type => { :content_type => "image/jpeg" }
|
79
|
-
|
80
|
-
assert_nothing_raised(Paperclip::Errors::MissingRequiredValidatorError) do
|
81
|
-
Dummy.new(:avatar => File.new(fixture_file("12k.png")))
|
82
|
-
end
|
83
|
-
end
|
84
|
-
|
85
|
-
should 'not raise an error when a file_name validation exists' do
|
86
|
-
Dummy.validates_attachment :avatar, :file_name => { :matches => /png$/ }
|
87
|
-
|
88
|
-
assert_nothing_raised(Paperclip::Errors::MissingRequiredValidatorError) do
|
89
|
-
Dummy.new(:avatar => File.new(fixture_file("12k.png")))
|
90
|
-
end
|
91
|
-
end
|
92
|
-
|
93
|
-
should 'not raise an error when a the validation has been explicitly rejected' do
|
94
|
-
Dummy.validates_attachment :avatar, :file_type_ignorance => true
|
95
|
-
|
96
|
-
assert_nothing_raised(Paperclip::Errors::MissingRequiredValidatorError) do
|
97
|
-
Dummy.new(:avatar => File.new(fixture_file("12k.png")))
|
98
|
-
end
|
99
|
-
end
|
100
|
-
end
|
101
|
-
end
|