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
b54904e0
Commit
b54904e0
authored
Mar 16, 2012
by
Prem Sichanugrist
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add #check_validity! to validators
parent
d3a74275
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
64 additions
and
0 deletions
+64
-0
lib/paperclip/validators/attachment_content_type_validator.rb
+6
-0
lib/paperclip/validators/attachment_size_validator.rb
+6
-0
test/paperclip_test.rb
+2
-0
test/validators/attachment_content_type_validator_test.rb
+22
-0
test/validators/attachment_size_validator_test.rb
+28
-0
No files found.
lib/paperclip/validators/attachment_content_type_validator.rb
View file @
b54904e0
...
...
@@ -16,6 +16,12 @@ module Paperclip
end
end
end
def
check_validity!
unless
options
.
has_key?
(
:content_type
)
raise
ArgumentError
,
"You must pass in :content_type to the validator"
end
end
end
module
HelperMethods
...
...
lib/paperclip/validators/attachment_size_validator.rb
View file @
b54904e0
...
...
@@ -31,6 +31,12 @@ module Paperclip
end
end
def
check_validity!
unless
(
AVAILABLE_CHECKS
+
[
:in
]).
any?
{
|
argument
|
options
.
has_key?
(
argument
)
}
raise
ArgumentError
,
"You must pass either :less_than, :greater_than, or :in to the validator"
end
end
private
def
extract_options
(
options
)
...
...
test/paperclip_test.rb
View file @
b54904e0
...
...
@@ -49,6 +49,7 @@ class PaperclipTest < Test::Unit::TestCase
d3
=
Dummy
.
create
(
:avatar
=>
@file
)
@expected
=
[
d1
,
d3
]
end
should
"yield every instance of a model that has an attachment"
do
actual
=
[]
Paperclip
.
each_instance_with_attachment
(
"Dummy"
,
"avatar"
)
do
|
instance
|
...
...
@@ -166,6 +167,7 @@ class PaperclipTest < Test::Unit::TestCase
end
teardown
do
SubDummy
.
delete_all
Object
.
send
(
:remove_const
,
"SubDummy"
)
rescue
nil
end
end
...
...
test/validators/attachment_content_type_validator_test.rb
View file @
b54904e0
...
...
@@ -103,4 +103,26 @@ class AttachmentContentTypeValidatorTest < Test::Unit::TestCase
end
end
end
context
"using the helper"
do
setup
do
Dummy
.
validates_attachment_content_type
:avatar
,
:content_type
=>
"image/jpg"
end
should
"add the validator to the class"
do
assert
Dummy
.
validators_on
(
:avatar
).
any?
{
|
validator
|
validator
.
kind
==
:attachment_content_type
}
end
end
context
"given options"
do
should
"raise argument error if no required argument was given"
do
assert_raises
(
ArgumentError
)
do
build_validator
:message
=>
"Some message"
end
end
should
"not raise arguemnt error if :content_type was given"
do
build_validator
:content_type
=>
"image/jpg"
end
end
end
test/validators/attachment_size_validator_test.rb
View file @
b54904e0
...
...
@@ -176,4 +176,32 @@ class AttachmentSizeValidatorTest < Test::Unit::TestCase
:message
=>
"must be in between 5120 Bytes and 10240 Bytes"
end
end
context
"using the helper"
do
setup
do
Dummy
.
validates_attachment_size
:avatar
,
:in
=>
(
5
.
kilobytes
..
10
.
kilobytes
)
end
should
"add the validator to the class"
do
assert
Dummy
.
validators_on
(
:avatar
).
any?
{
|
validator
|
validator
.
kind
==
:attachment_size
}
end
end
context
"given options"
do
should
"raise argument error if no required argument was given"
do
assert_raises
(
ArgumentError
)
do
build_validator
:message
=>
"Some message"
end
end
(
Paperclip
::
Validators
::
AttachmentSizeValidator
::
AVAILABLE_CHECKS
).
each
do
|
argument
|
should
"not raise arguemnt error if
#{
argument
}
was given"
do
build_validator
argument
=>
5
.
kilobytes
end
end
should
"not raise argument error if :in was given"
do
build_validator
:in
=>
(
5
.
kilobytes
..
10
.
kilobytes
)
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