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
211e9883
Commit
211e9883
authored
Dec 30, 2008
by
Jon Yurek
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
convert_options can take procs, based on code from Iffy
parent
7480516a
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
38 additions
and
1 deletions
+38
-1
lib/paperclip/attachment.rb
+6
-1
test/attachment_test.rb
+32
-0
No files found.
lib/paperclip/attachment.rb
View file @
211e9883
...
...
@@ -304,7 +304,12 @@ module Paperclip
end
def
extra_options_for
(
style
)
#:nodoc:
[
convert_options
[
style
],
convert_options
[
:all
]
].
compact
.
join
(
" "
)
all_options
=
convert_options
[
:all
]
all_options
=
all_options
.
call
(
instance
)
if
all_options
.
respond_to?
(
:call
)
style_options
=
convert_options
[
style
]
style_options
=
style_options
.
call
(
instance
)
if
style_options
.
respond_to?
(
:call
)
[
style_options
,
all_options
].
compact
.
join
(
" "
)
end
def
post_process
#:nodoc:
...
...
test/attachment_test.rb
View file @
211e9883
...
...
@@ -138,6 +138,38 @@ class AttachmentTest < Test::Unit::TestCase
end
end
context
"An attachment with :convert_options that is a proc"
do
setup
do
rebuild_model
:styles
=>
{
:thumb
=>
"100x100"
,
:large
=>
"400x400"
},
:convert_options
=>
{
:all
=>
lambda
{
|
i
|
i
.
all
},
:thumb
=>
lambda
{
|
i
|
i
.
thumb
}
}
Dummy
.
class_eval
do
def
all
;
"-all"
;
end
def
thumb
;
"-thumb"
;
end
end
@dummy
=
Dummy
.
new
@dummy
.
avatar
end
should
"report the correct options when sent #extra_options_for(:thumb)"
do
assert_equal
"-thumb -all"
,
@dummy
.
avatar
.
send
(
:extra_options_for
,
:thumb
),
@dummy
.
avatar
.
convert_options
.
inspect
end
should
"report the correct options when sent #extra_options_for(:large)"
do
assert_equal
"-all"
,
@dummy
.
avatar
.
send
(
:extra_options_for
,
:large
)
end
before_should
"call extra_options_for(:thumb/:large)"
do
Paperclip
::
Attachment
.
any_instance
.
expects
(
:extra_options_for
).
with
(
:thumb
)
Paperclip
::
Attachment
.
any_instance
.
expects
(
:extra_options_for
).
with
(
:large
)
end
end
context
"An attachment with both 'normal' and hash-style styles"
do
setup
do
rebuild_model
:styles
=>
{
...
...
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