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
80f9b309
Commit
80f9b309
authored
Aug 29, 2013
by
Scott Carleton
Committed by
Jon Yurek
Dec 20, 2013
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
slice for conditional lambda and add to options
parent
282f1161
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
31 additions
and
0 deletions
+31
-0
lib/paperclip/validators.rb
+2
-0
test/validators_test.rb
+29
-0
No files found.
lib/paperclip/validators.rb
View file @
80f9b309
...
...
@@ -37,6 +37,8 @@ module Paperclip
validator_options
=
options
.
delete
(
validator_kind
)
validator_options
=
{}
if
validator_options
==
true
local_options
=
attributes
+
[
validator_options
]
conditional_options
=
options
.
slice
(
:if
,
:unless
)
local_options
.
last
.
merge!
(
conditional_options
)
send
(
:"validates_attachment_
#{
validator_kind
}
"
,
*
local_options
)
end
end
...
...
test/validators_test.rb
View file @
80f9b309
...
...
@@ -29,4 +29,33 @@ class ValidatorsTest < Test::Unit::TestCase
assert_raise
(
RuntimeError
){
dummy
.
valid?
}
end
end
context
"using the helper with a conditional"
do
setup
do
Dummy
.
validates_attachment
:avatar
,
:presence
=>
true
,
:content_type
=>
{
:content_type
=>
"image/jpeg"
},
:size
=>
{
:in
=>
0
..
10
.
kilobytes
},
:if
=>
:title_present?
end
should
"validate the attachment if title is present"
do
Dummy
.
class_eval
do
def
title_present?
true
end
end
dummy
=
Dummy
.
new
(
:avatar
=>
File
.
new
(
fixture_file
(
"12k.png"
)))
assert_equal
[
:avatar_content_type
,
:avatar
,
:avatar_file_size
],
dummy
.
errors
.
keys
end
should
"not validate attachment if tile is not present"
do
Dummy
.
class_eval
do
def
title_present?
false
end
end
dummy
=
Dummy
.
new
(
:avatar
=>
File
.
new
(
fixture_file
(
"12k.png"
)))
assert_equal
[],
dummy
.
errors
.
keys
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