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
d8a721f6
Commit
d8a721f6
authored
Jan 25, 2013
by
Mike Burns
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move validates_each into HasAttachedFile class
parent
2d28dbca
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
29 additions
and
6 deletions
+29
-6
lib/paperclip.rb
+0
-5
lib/paperclip/has_attached_file.rb
+8
-0
test/has_attached_file_test.rb
+21
-1
No files found.
lib/paperclip.rb
View file @
d8a721f6
...
...
@@ -187,11 +187,6 @@ module Paperclip
after_destroy
{
send
(
name
).
send
(
:flush_deletes
)
}
define_paperclip_callbacks
:post_process
,
:"
#{
name
}
_post_process"
validates_each
(
name
)
do
|
record
,
attr
,
value
|
attachment
=
record
.
send
(
name
)
attachment
.
send
(
:flush_errors
)
end
end
end
end
...
...
lib/paperclip/has_attached_file.rb
View file @
d8a721f6
...
...
@@ -11,6 +11,7 @@ module Paperclip
end
def
define
define_flush_errors
define_getter
define_setter
define_query
...
...
@@ -18,6 +19,13 @@ module Paperclip
private
def
define_flush_errors
@klass
.
send
(
:validates_each
,
@name
)
do
|
record
,
attr
,
value
|
attachment
=
record
.
send
(
@name
)
attachment
.
send
(
:flush_errors
)
end
end
def
define_getter
name
=
@name
options
=
@options
...
...
test/has_attached_file_test.rb
View file @
d8a721f6
...
...
@@ -14,6 +14,10 @@ class HasAttachedFileTest < Test::Unit::TestCase
should
'define a query on the class object'
do
assert_adding_attachment
(
'avatar'
).
defines_method
(
'avatar?'
)
end
should
'flush errors as part of validations'
do
assert_adding_attachment
(
'avatar'
).
defines_validation
end
end
private
...
...
@@ -31,7 +35,7 @@ class HasAttachedFileTest < Test::Unit::TestCase
end
def
defines_method
(
method_name
)
a_class
=
stub
(
'class'
,
define_method:
nil
)
a_class
=
stub
_class
Paperclip
::
HasAttachedFile
.
define_on
(
a_class
,
@attachment_name
,
{})
...
...
@@ -39,5 +43,21 @@ class HasAttachedFileTest < Test::Unit::TestCase
expect
.
with
(
method_name
)
end
end
def
defines_validation
a_class
=
stub_class
Paperclip
::
HasAttachedFile
.
define_on
(
a_class
,
@attachment_name
,
{})
assert_received
(
a_class
,
:validates_each
)
do
|
expect
|
expect
.
with
(
@attachment_name
)
end
end
private
def
stub_class
stub
(
'class'
,
validates_each:
nil
,
define_method:
nil
)
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