Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
paperclip
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ikcrm_common
paperclip
Commits
be04cf02
Commit
be04cf02
authored
May 09, 2014
by
Prem Sichanugrist
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1515 from quainjn/allow_subclassed_validators
Ensure required validations accepts subclasses
parents
6b86636f
a250392d
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
31 additions
and
1 deletions
+31
-1
lib/paperclip/attachment.rb
+9
-1
spec/paperclip/validators_spec.rb
+22
-0
No files found.
lib/paperclip/attachment.rb
View file @
be04cf02
...
...
@@ -389,8 +389,16 @@ module Paperclip
@instance
.
class
.
validators
.
map
(
&
:class
)
end
def
required_validator_classes
Paperclip
::
REQUIRED_VALIDATORS
+
Paperclip
::
REQUIRED_VALIDATORS
.
flat_map
(
&
:descendants
)
end
def
missing_required_validator?
(
active_validator_classes
&
required_validator_classes
).
empty?
end
def
ensure_required_validations!
if
(
active_validator_classes
&
Paperclip
::
REQUIRED_VALIDATORS
).
empty
?
if
missing_required_validator
?
raise
Paperclip
::
Errors
::
MissingRequiredValidatorError
end
end
...
...
spec/paperclip/validators_spec.rb
View file @
be04cf02
...
...
@@ -77,6 +77,28 @@ describe Paperclip::Validators do
end
end
it
'does not raise an error when a content_type validation exists using validates_with'
do
Dummy
.
validates_with
Paperclip
::
Validators
::
AttachmentContentTypeValidator
,
attributes: :attachment
,
content_type:
'images/jpeg'
assert_nothing_raised
do
Dummy
.
new
(
avatar:
File
.
new
(
fixture_file
(
"12k.png"
)))
end
end
it
'does not raise an error when an inherited validator is used'
do
class
MyValidator
<
Paperclip
::
Validators
::
AttachmentContentTypeValidator
def
initialize
(
options
)
options
[
:content_type
]
=
"images/jpeg"
unless
options
.
has_key?
(
:content_type
)
super
end
end
Dummy
.
validates_with
MyValidator
,
attributes: :attachment
assert_nothing_raised
do
Dummy
.
new
(
avatar:
File
.
new
(
fixture_file
(
"12k.png"
)))
end
end
it
'does not raise an error when a file_name validation exists'
do
Dummy
.
validates_attachment
:avatar
,
file_name:
{
matches:
/png$/
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment