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
be890c98
Commit
be890c98
authored
May 02, 2008
by
austin.bain
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Validating size and content_type no longer throws errors when no file is uploaded
parent
3d745db9
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
5 additions
and
3 deletions
+5
-3
lib/paperclip.rb
+2
-2
test/test_paperclip.rb
+3
-1
No files found.
lib/paperclip.rb
View file @
be890c98
...
@@ -156,7 +156,7 @@ module Paperclip
...
@@ -156,7 +156,7 @@ module Paperclip
unless
options
[
:less_than
].
nil?
unless
options
[
:less_than
].
nil?
options
[
:in
]
=
(
0
..
options
[
:less_than
])
options
[
:in
]
=
(
0
..
options
[
:less_than
])
end
end
unless
options
[
:in
].
include?
instance
[
:"
#{
name
}
_file_size"
].
to_i
unless
attachment
.
original_filename
.
blank?
||
options
[
:in
].
include?
(
instance
[
:"
#{
name
}
_file_size"
].
to_i
)
min
=
options
[
:in
].
first
min
=
options
[
:in
].
first
max
=
options
[
:in
].
last
max
=
options
[
:in
].
last
...
@@ -187,7 +187,7 @@ module Paperclip
...
@@ -187,7 +187,7 @@ module Paperclip
options
[
:content_type
]
=
[
options
[
:content_type
]].
flatten
.
collect!
{
|
t
|
t
==
:image
?
Paperclip
.
content_types
:
t
}.
flatten
unless
options
[
:content_type
].
nil?
options
[
:content_type
]
=
[
options
[
:content_type
]].
flatten
.
collect!
{
|
t
|
t
==
:image
?
Paperclip
.
content_types
:
t
}.
flatten
unless
options
[
:content_type
].
nil?
unless
options
[
:content_type
].
empty?
unless
options
[
:content_type
].
empty?
unless
options
[
:content_type
].
include?
(
instance
[
:"
#{
name
}
_content_type"
])
unless
attachment
.
original_filename
.
blank?
||
options
[
:content_type
].
include?
(
instance
[
:"
#{
name
}
_content_type"
])
options
[
:message
]
||
ActiveRecord
::
Errors
.
default_error_messages
[
:inclusion
]
options
[
:message
]
||
ActiveRecord
::
Errors
.
default_error_messages
[
:inclusion
]
end
end
end
end
...
...
test/test_paperclip.rb
View file @
be890c98
...
@@ -71,7 +71,9 @@ class PaperclipTest < Test::Unit::TestCase
...
@@ -71,7 +71,9 @@ class PaperclipTest < Test::Unit::TestCase
[
:content_type3
,
{
:content_type
=>
"text/plain"
},
"text.txt"
,
"5k.png"
],
[
:content_type3
,
{
:content_type
=>
"text/plain"
},
"text.txt"
,
"5k.png"
],
[
:presence2
,
{
:message
=>
"error"
},
"5k.png"
,
nil
,
"error"
],
[
:presence2
,
{
:message
=>
"error"
},
"5k.png"
,
nil
,
"error"
],
[
:size2
,
{
:in
=>
1
..
10240
,
:message
=>
'size is not between #{min} and #{max} bytes.'
},
"5k.png"
,
"12k.png"
,
"size is not between 1 and 10240 bytes."
],
[
:size2
,
{
:in
=>
1
..
10240
,
:message
=>
'size is not between #{min} and #{max} bytes.'
},
"5k.png"
,
"12k.png"
,
"size is not between 1 and 10240 bytes."
],
[
:content_type4
,{
:content_type
=>
"image/png"
,
:message
=>
"error"
},
"5k.png"
,
"text.txt"
,
"error"
]].
each
do
|
args
|
[
:size3
,
{
:in
=>
1
..
10240
},
nil
,
"12k.png"
],
[
:content_type4
,{
:content_type
=>
"image/png"
,
:message
=>
"error"
},
"5k.png"
,
"text.txt"
,
"error"
],
[
:content_type5
,{
:content_type
=>
"image/png"
},
nil
,
"text.txt"
]].
each
do
|
args
|
context
"with
#{
args
[
0
]
}
validations"
do
context
"with
#{
args
[
0
]
}
validations"
do
setup
do
setup
do
Dummy
.
class_eval
do
Dummy
.
class_eval
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