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
3eb7844c
Commit
3eb7844c
authored
May 08, 2009
by
Jon Yurek
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added :url and :timestamp interpolations.
parent
7661c317
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
32 additions
and
0 deletions
+32
-0
lib/paperclip.rb
+3
-0
lib/paperclip/interpolations.rb
+9
-0
test/interpolations_test.rb
+20
-0
No files found.
lib/paperclip.rb
View file @
3eb7844c
...
...
@@ -139,6 +139,9 @@ module Paperclip
class
NotIdentifiedByImageMagickError
<
PaperclipError
#:nodoc:
end
class
InfiniteInterpolationError
<
PaperclipError
#:nodoc:
end
module
ClassMethods
# +has_attached_file+ gives the class it is called on an attribute that maps to a file. This
# is typically a file stored somewhere on the filesystem and has been uploaded by a user.
...
...
lib/paperclip/interpolations.rb
View file @
3eb7844c
...
...
@@ -22,6 +22,15 @@ module Paperclip
end
end
def
url
attachment
,
style
raise
InfiniteInterpolationError
if
attachment
.
options
[
:url
].
include?
(
":url"
)
attachment
.
url
(
style
)
end
def
timestamp
attachment
,
style
attachment
.
instance_read
(
:updated_at
).
to_s
end
def
rails_root
attachment
,
style
RAILS_ROOT
end
...
...
test/interpolations_test.rb
View file @
3eb7844c
...
...
@@ -76,6 +76,26 @@ class InterpolationsTest < Test::Unit::TestCase
assert_equal
:default_style
,
Paperclip
::
Interpolations
.
style
(
attachment
,
nil
)
end
should
"reinterpolate :url"
do
attachment
=
mock
attachment
.
expects
(
:options
).
returns
({
:url
=>
":id"
})
attachment
.
expects
(
:url
).
with
(
:style
).
returns
(
"1234"
)
assert_equal
"1234"
,
Paperclip
::
Interpolations
.
url
(
attachment
,
:style
)
end
should
"raise if infinite loop detcted reinterpolatin :url"
do
attachment
=
mock
attachment
.
expects
(
:options
).
returns
({
:url
=>
":url"
})
assert_raises
(
Paperclip
::
InfiniteInterpolationError
){
Paperclip
::
Interpolations
.
url
(
attachment
,
:style
)
}
end
should
"return the timestamp"
do
now
=
Time
.
now
attachment
=
mock
attachment
.
expects
(
:instance_read
).
with
(
:updated_at
).
returns
(
now
)
assert_equal
now
.
to_s
,
Paperclip
::
Interpolations
.
timestamp
(
attachment
,
:style
)
end
should
"call all expected interpolations with the given arguments"
do
Paperclip
::
Interpolations
.
expects
(
:id
).
with
(
:attachment
,
:style
).
returns
(
1234
)
Paperclip
::
Interpolations
.
expects
(
:attachment
).
with
(
:attachment
,
:style
).
returns
(
"attachments"
)
...
...
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