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
61a05368
Commit
61a05368
authored
Oct 20, 2011
by
Jon Yurek
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixes validates_attachment_presence just flat out not working
parent
93faccfa
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
5 additions
and
3 deletions
+5
-3
lib/paperclip.rb
+3
-1
test/paperclip_test.rb
+2
-2
No files found.
lib/paperclip.rb
View file @
61a05368
...
@@ -388,7 +388,9 @@ module Paperclip
...
@@ -388,7 +388,9 @@ module Paperclip
def
validates_attachment_presence
name
,
options
=
{}
def
validates_attachment_presence
name
,
options
=
{}
message
=
options
[
:message
]
||
:empty
message
=
options
[
:message
]
||
:empty
validates_each
:"
#{
name
}
_file_name"
do
|
record
,
attr
,
value
|
validates_each
:"
#{
name
}
_file_name"
do
|
record
,
attr
,
value
|
record
.
errors
.
add
(
name
,
message
)
if
attr
.
blank?
if_clause_passed
=
options
[
:if
].
nil?
||
(
options
[
:if
].
call
(
record
)
!=
false
)
unless_clause_passed
=
options
[
:unless
].
nil?
||
(
!!
options
[
:unless
].
call
(
record
)
==
false
)
record
.
errors
.
add
(
name
,
message
)
if
if_clause_passed
&&
unless_clause_passed
&&
value
.
blank?
end
end
end
end
...
...
test/paperclip_test.rb
View file @
61a05368
...
@@ -238,7 +238,7 @@ class PaperclipTest < Test::Unit::TestCase
...
@@ -238,7 +238,7 @@ class PaperclipTest < Test::Unit::TestCase
@dummy
.
avatar
=
valid_file
@dummy
.
avatar
=
valid_file
@dummy
.
valid?
@dummy
.
valid?
end
end
should
"not have an error
when assigned a valid file
"
do
should
"not have an error"
do
assert_equal
0
,
@dummy
.
errors
.
size
,
@dummy
.
errors
.
full_messages
.
join
(
", "
)
assert_equal
0
,
@dummy
.
errors
.
size
,
@dummy
.
errors
.
full_messages
.
join
(
", "
)
end
end
end
end
...
@@ -247,7 +247,7 @@ class PaperclipTest < Test::Unit::TestCase
...
@@ -247,7 +247,7 @@ class PaperclipTest < Test::Unit::TestCase
@dummy
.
avatar
=
invalid_file
@dummy
.
avatar
=
invalid_file
@dummy
.
valid?
@dummy
.
valid?
end
end
should
"have an error
when assigned a valid file
"
do
should
"have an error"
do
assert
@dummy
.
errors
.
size
>
0
assert
@dummy
.
errors
.
size
>
0
end
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