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
17ecc58a
Commit
17ecc58a
authored
Feb 28, 2014
by
Arjun Anand
Committed by
Jon Yurek
Aug 27, 2015
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix exception that is raised if after_commit callback hooks are absent
parent
3b087ee8
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
27 additions
and
8 deletions
+27
-8
lib/paperclip/has_attached_file.rb
+4
-0
spec/paperclip/has_attached_file_spec.rb
+23
-8
No files found.
lib/paperclip/has_attached_file.rb
View file @
17ecc58a
...
...
@@ -91,7 +91,11 @@ module Paperclip
name
=
@name
@klass
.
send
(
:after_save
)
{
send
(
name
).
send
(
:save
)
}
@klass
.
send
(
:before_destroy
)
{
send
(
name
).
send
(
:queue_all_for_delete
)
}
if
@klass
.
respond_to?
(
:after_commit
)
@klass
.
send
(
:after_commit
,
:on
=>
:destroy
)
{
send
(
name
).
send
(
:flush_deletes
)
}
else
@klass
.
send
(
:after_destroy
)
{
send
(
name
).
send
(
:flush_deletes
)
}
end
end
def
add_paperclip_callbacks
...
...
spec/paperclip/has_attached_file_spec.rb
View file @
17ecc58a
...
...
@@ -38,6 +38,14 @@ describe Paperclip::HasAttachedFile do
assert_adding_attachment
(
'avatar'
).
defines_callback
(
'after_commit'
)
end
it
'defines an after_commit callback if the class allows after_commit callbacks'
do
assert_adding_attachment
(
'avatar'
).
defines_callback
(
'after_commit'
)
end
it
'defines an after_destroy callback if the class does not allow after_commit callbacks'
do
assert_adding_attachment
(
'avatar'
,
:unstub_methods
=>
[
:after_commit
]).
defines_callback
(
'after_destroy'
)
end
it
'defines the Paperclip-specific callbacks'
do
assert_adding_attachment
(
'avatar'
).
defines_callback
(
'define_paperclip_callbacks'
)
end
...
...
@@ -53,20 +61,26 @@ describe Paperclip::HasAttachedFile do
private
def
assert_adding_attachment
(
attachment_name
)
AttachmentAdder
.
new
(
attachment_name
)
def
assert_adding_attachment
(
attachment_name
,
options
=
{}
)
AttachmentAdder
.
new
(
attachment_name
,
options
)
end
class
AttachmentAdder
include
Mocha
::
API
include
RSpec
::
Matchers
def
initialize
(
attachment_name
)
def
initialize
(
attachment_name
,
options
=
{}
)
@attachment_name
=
attachment_name
@stubbed_class
=
stub_class
if
options
.
present?
options
[
:unstub_methods
].
each
do
|
method
|
@stubbed_class
.
unstub
(
method
)
end
end
end
def
defines_method
(
method_name
)
a_class
=
stub
_class
a_class
=
@stubbed
_class
Paperclip
::
HasAttachedFile
.
define_on
(
a_class
,
@attachment_name
,
{})
...
...
@@ -74,7 +88,7 @@ describe Paperclip::HasAttachedFile do
end
def
defines_class_method
(
method_name
)
a_class
=
stub
_class
a_class
=
@stubbed
_class
a_class
.
class
.
stubs
(
:define_method
)
Paperclip
::
HasAttachedFile
.
define_on
(
a_class
,
@attachment_name
,
{})
...
...
@@ -83,7 +97,7 @@ describe Paperclip::HasAttachedFile do
end
def
defines_validation
a_class
=
stub
_class
a_class
=
@stubbed
_class
Paperclip
::
HasAttachedFile
.
define_on
(
a_class
,
@attachment_name
,
{})
...
...
@@ -91,7 +105,7 @@ describe Paperclip::HasAttachedFile do
end
def
registers_attachment
a_class
=
stub
_class
a_class
=
@stubbed
_class
Paperclip
::
AttachmentRegistry
.
stubs
(
:register
)
Paperclip
::
HasAttachedFile
.
define_on
(
a_class
,
@attachment_name
,
{
size:
1
})
...
...
@@ -100,7 +114,7 @@ describe Paperclip::HasAttachedFile do
end
def
defines_callback
(
callback_name
)
a_class
=
stub
_class
a_class
=
@stubbed
_class
Paperclip
::
HasAttachedFile
.
define_on
(
a_class
,
@attachment_name
,
{})
...
...
@@ -132,6 +146,7 @@ describe Paperclip::HasAttachedFile do
after_save:
nil
,
before_destroy:
nil
,
after_commit:
nil
,
after_destroy:
nil
,
define_paperclip_callbacks:
nil
,
extend:
nil
,
name:
'Billy'
,
...
...
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