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
5046dfcb
Commit
5046dfcb
authored
Mar 01, 2013
by
George Brocklehurst
Committed by
Mike Burns
Jun 14, 2013
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move after_save callback to HasAttachedFile
parent
32548249
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
21 additions
and
1 deletions
+21
-1
lib/paperclip.rb
+0
-1
lib/paperclip/has_attached_file.rb
+6
-0
test/has_attached_file_test.rb
+15
-0
No files found.
lib/paperclip.rb
View file @
5046dfcb
...
...
@@ -175,7 +175,6 @@ module Paperclip
def
has_attached_file
(
name
,
options
=
{})
HasAttachedFile
.
define_on
(
self
,
name
,
options
)
after_save
{
send
(
name
).
send
(
:save
)
}
before_destroy
{
send
(
name
).
send
(
:queue_all_for_delete
)
}
after_destroy
{
send
(
name
).
send
(
:flush_deletes
)
}
...
...
lib/paperclip/has_attached_file.rb
View file @
5046dfcb
...
...
@@ -17,6 +17,7 @@ module Paperclip
define_query
check_for_path_clash
register_with_rake_tasks
add_active_record_callbacks
end
private
...
...
@@ -72,5 +73,10 @@ module Paperclip
def
register_with_rake_tasks
Paperclip
::
Tasks
::
Attachments
.
add
(
@klass
,
@name
,
@options
)
end
def
add_active_record_callbacks
name
=
@name
@klass
.
send
(
:after_save
)
{
send
(
name
).
send
(
:save
)
}
end
end
end
test/has_attached_file_test.rb
View file @
5046dfcb
...
...
@@ -26,6 +26,10 @@ class HasAttachedFileTest < Test::Unit::TestCase
should
'register the attachment with Paperclip::Tasks'
do
assert_adding_attachment
(
'avatar'
).
registers_with_tasks
end
should
'define an after_save callback'
do
assert_adding_attachment
(
'avatar'
).
defines_callback
(
'after_save'
)
end
end
private
...
...
@@ -84,12 +88,23 @@ class HasAttachedFileTest < Test::Unit::TestCase
end
end
def
defines_callback
(
callback_name
)
a_class
=
stub_class
Paperclip
::
HasAttachedFile
.
define_on
(
a_class
,
@attachment_name
,
{})
assert_received
(
a_class
,
callback_name
.
to_sym
)
end
private
def
stub_class
stub
(
'class'
,
validates_each:
nil
,
define_method:
nil
,
after_save:
nil
,
before_destroy:
nil
,
after_destroy:
nil
,
name:
'Billy'
)
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