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
3e6d9333
Commit
3e6d9333
authored
Sep 30, 2011
by
Jon Yurek
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Flesh out the tests for the options class to ensure future refactorings
parent
b948f968
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
71 additions
and
3 deletions
+71
-3
lib/paperclip/options.rb
+3
-3
test/options_test.rb
+68
-0
No files found.
lib/paperclip/options.rb
View file @
3e6d9333
...
...
@@ -62,17 +62,17 @@ module Paperclip
end
def
processors
@processors
.
respond_to?
(
:call
)
?
@processors
.
call
(
instance
)
:
@processors
@processors
.
respond_to?
(
:call
)
?
@processors
.
call
(
@attachment
.
instance
)
:
@processors
end
def
styles
if
@styles
.
respond_to?
(
:call
)
||
!
@normalized_styles
normalized_styles
=
ActiveSupport
::
OrderedHash
.
new
@
normalized_styles
=
ActiveSupport
::
OrderedHash
.
new
(
@styles
.
respond_to?
(
:call
)
?
@styles
.
call
(
@attachment
)
:
@styles
).
each
do
|
name
,
args
|
normalized_styles
[
name
]
=
Paperclip
::
Style
.
new
(
name
,
args
.
dup
,
@attachment
)
end
end
normalized_styles
@
normalized_styles
end
end
end
test/options_test.rb
0 → 100644
View file @
3e6d9333
# encoding: utf-8
require
'./test/helper'
class
MockAttachment
<
Struct
.
new
(
:one
,
:two
)
def
instance
self
end
end
class
OptionsTest
<
Test
::
Unit
::
TestCase
context
"#styles with a plain hash"
do
setup
do
@attachment
=
MockAttachment
.
new
(
nil
,
nil
)
@options
=
Paperclip
::
Options
.
new
(
@attachment
,
:styles
=>
{
:something
=>
[
"400x400"
,
:png
]
})
end
should
"return the right data for the style's geometry"
do
assert_equal
"400x400"
,
@options
.
styles
[
:something
][
:geometry
]
end
should
"return the right data for the style's format"
do
assert_equal
:png
,
@options
.
styles
[
:something
][
:format
]
end
end
context
"#styles is a proc"
do
setup
do
@attachment
=
MockAttachment
.
new
(
"123x456"
,
:doc
)
@options
=
Paperclip
::
Options
.
new
(
@attachment
,
:styles
=>
lambda
{
|
att
|
{
:something
=>
{
:geometry
=>
att
.
one
,
:format
=>
att
.
two
}}
})
end
should
"return the right data for the style's geometry"
do
assert_equal
"123x456"
,
@options
.
styles
[
:something
][
:geometry
]
end
should
"return the right data for the style's format"
do
assert_equal
:doc
,
@options
.
styles
[
:something
][
:format
]
end
should
"run the proc each time, giving dynamic results"
do
assert_equal
:doc
,
@options
.
styles
[
:something
][
:format
]
@attachment
.
two
=
:pdf
assert_equal
:pdf
,
@options
.
styles
[
:something
][
:format
]
end
end
context
"#processors"
do
setup
do
@attachment
=
MockAttachment
.
new
(
nil
,
nil
)
end
should
"return processors if not a proc"
do
@options
=
Paperclip
::
Options
.
new
(
@attachment
,
:processors
=>
[
:one
])
assert_equal
[
:one
],
@options
.
processors
end
should
"return processors if it is a proc"
do
@options
=
Paperclip
::
Options
.
new
(
@attachment
,
:processors
=>
lambda
{
|
att
|
[
att
.
one
]})
assert_equal
[
nil
],
@options
.
processors
@attachment
.
one
=
:other
assert_equal
[
:other
],
@options
.
processors
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