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
3b3f8eae
Commit
3b3f8eae
authored
Jun 18, 2010
by
Jon Yurek
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed size and content type validations to not care about presence.
parent
e7410db7
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
9 additions
and
6 deletions
+9
-6
lib/paperclip.rb
+7
-5
test/paperclip_test.rb
+2
-1
No files found.
lib/paperclip.rb
View file @
3b3f8eae
...
...
@@ -305,7 +305,8 @@ module Paperclip
:in
=>
range
,
:message
=>
message
,
:if
=>
options
[
:if
],
:unless
=>
options
[
:unless
]
:unless
=>
options
[
:unless
],
:allow_nil
=>
true
end
# Adds errors if thumbnail creation fails. The same as specifying :whiny_thumbnails => true.
...
...
@@ -346,11 +347,12 @@ module Paperclip
# model, content_type validation will work _ONLY upon assignment_ and
# re-validation after the instance has been reloaded will always succeed.
def
validates_attachment_content_type
name
,
options
=
{}
types
=
[
options
.
delete
(
:content_type
)].
flatten
validates_each
(
:"
#{
name
}
_content_type"
,
options
)
do
|
record
,
attr
,
value
|
unless
types
.
any?
{
|
t
|
t
===
value
}
validation_options
=
options
.
dup
allowed_types
=
[
validation_options
[
:content_type
]].
flatten
validates_each
(
:"
#{
name
}
_content_type"
,
validation_options
)
do
|
record
,
attr
,
value
|
if
!
allowed_types
.
any?
{
|
t
|
t
===
value
}
&&
value
.
present?
if
record
.
errors
.
method
(
:add
).
arity
==
-
2
message
=
options
[
:message
]
||
"is not one of
#{
types
.
join
(
", "
)
}
"
message
=
options
[
:message
]
||
"is not one of
#{
allowed_
types
.
join
(
", "
)
}
"
record
.
errors
.
add
(
:"
#{
name
}
_content_type"
,
message
)
else
record
.
errors
.
add
(
:"
#{
name
}
_content_type"
,
:inclusion
,
:default
=>
options
[
:message
],
:value
=>
value
)
...
...
test/paperclip_test.rb
View file @
3b3f8eae
...
...
@@ -245,6 +245,7 @@ class PaperclipTest < Test::Unit::TestCase
def
self
.
should_validate
validation
,
options
,
valid_file
,
invalid_file
context
"with
#{
validation
}
validation and
#{
options
.
inspect
}
options"
do
setup
do
rebuild_class
Dummy
.
send
(
:"validates_attachment_
#{
validation
}
"
,
:avatar
,
options
)
@dummy
=
Dummy
.
new
end
...
...
@@ -259,7 +260,7 @@ class PaperclipTest < Test::Unit::TestCase
end
else
should
"not have an error on the attachment"
do
assert
@dummy
.
errors
[
:avatar_file_name
]
.
blank?
,
@dummy
.
errors
.
full_messages
.
join
(
", "
)
assert
@dummy
.
errors
.
blank?
,
@dummy
.
errors
.
full_messages
.
join
(
", "
)
end
end
end
...
...
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