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
bd528ba7
Commit
bd528ba7
authored
Mar 27, 2012
by
Prem Sichanugrist
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #792 from tony-brewerio/patch-1
Fix AttachmentContentTypeValidator to work with multiple values
parents
8390516f
c4c22f8a
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
17 additions
and
7 deletions
+17
-7
lib/paperclip/validators/attachment_content_type_validator.rb
+5
-7
test/validators/attachment_content_type_validator_test.rb
+12
-0
No files found.
lib/paperclip/validators/attachment_content_type_validator.rb
View file @
bd528ba7
...
...
@@ -6,13 +6,11 @@ module Paperclip
value
=
record
.
send
(
:read_attribute_for_validation
,
attribute
)
allowed_types
=
[
options
[
:content_type
]].
flatten
unless
value
.
blank?
allowed_types
.
any?
do
|
type
|
unless
type
===
value
record
.
errors
.
add
(
attribute
,
:invalid
,
options
.
merge
(
:types
=>
allowed_types
.
join
(
', '
)
))
end
if
value
.
present?
unless
allowed_types
.
any?
{
|
type
|
type
===
value
}
record
.
errors
.
add
(
attribute
,
:invalid
,
options
.
merge
(
:types
=>
allowed_types
.
join
(
', '
)
))
end
end
end
...
...
test/validators/attachment_content_type_validator_test.rb
View file @
bd528ba7
...
...
@@ -48,6 +48,18 @@ class AttachmentContentTypeValidatorTest < Test::Unit::TestCase
assert
@dummy
.
errors
[
:avatar_content_type
].
blank?
end
end
context
"as a list"
do
setup
do
build_validator
:content_type
=>
[
"image/png"
,
"image/jpg"
,
"image/jpeg"
]
@dummy
.
stubs
(
:avatar_content_type
=>
"image/jpg"
)
@validator
.
validate
(
@dummy
)
end
should
"not set an error message"
do
assert
@dummy
.
errors
[
:avatar_content_type
].
blank?
end
end
end
context
"with a disallowed type"
do
...
...
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