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
9421f2d3
Commit
9421f2d3
authored
Aug 01, 2008
by
Jon Yurek
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added extra tests for mtime
parent
87d700dd
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
19 additions
and
3 deletions
+19
-3
lib/paperclip/attachment.rb
+2
-2
test/attachment_test.rb
+17
-1
No files found.
lib/paperclip/attachment.rb
View file @
9421f2d3
...
...
@@ -87,7 +87,7 @@ module Paperclip
# performance reasons.
def
url
style
=
default_style
url
=
original_filename
.
nil?
?
interpolate
(
@default_url
,
style
)
:
interpolate
(
@url
,
style
)
[
url
,
mtime
].
compact
.
join
(
url
.
include?
(
"?"
)
?
"&"
:
"?"
)
updated_at
?
[
url
,
updated_at
].
compact
.
join
(
url
.
include?
(
"?"
)
?
"&"
:
"?"
)
:
url
end
# Returns the path of the attachment as defined by the :path option. If the
...
...
@@ -141,7 +141,7 @@ module Paperclip
instance
[
:"
#{
name
}
_file_name"
]
end
def
mtime
def
updated_at
time
=
instance
[
:"
#{
name
}
_updated_at"
]
time
&&
time
.
to_i
end
...
...
test/attachment_test.rb
View file @
9421f2d3
...
...
@@ -174,6 +174,8 @@ class AttachmentTest < Test::Unit::TestCase
@instance
.
stubs
(
:[]
).
with
(
:test_file_name
).
returns
(
"5k.png"
)
@instance
.
stubs
(
:[]
).
with
(
:test_content_type
).
returns
(
"image/png"
)
@instance
.
stubs
(
:[]
).
with
(
:test_file_size
).
returns
(
12345
)
now
=
Time
.
now
Time
.
stubs
(
:now
).
returns
(
now
)
@instance
.
stubs
(
:[]
).
with
(
:test_updated_at
).
returns
(
Time
.
now
)
end
...
...
@@ -182,6 +184,20 @@ class AttachmentTest < Test::Unit::TestCase
assert_match
%r{^/tests/41/blah/5k
\.
png}
,
@attachment
.
url
(
:blah
)
end
should
"make sure the updated_at mtime is in the url if it is defined"
do
assert_match
%r{
#{
Time
.
now
.
to_i
}
$}
,
@attachment
.
url
(
:blah
)
end
context
"with the updated_at field removed"
do
setup
do
@instance
.
stubs
(
:[]
).
with
(
:test_updated_at
).
returns
(
nil
)
end
should
"only return the url without the updated_at when sent #url"
do
assert_match
"/tests/41/blah/5k.png"
,
@attachment
.
url
(
:blah
)
end
end
should
"return the proper path when filename has a single .'s"
do
assert_equal
"./test/../tmp/tests/dummies/original/41/5k.png"
,
@attachment
.
path
end
...
...
@@ -203,7 +219,7 @@ class AttachmentTest < Test::Unit::TestCase
context
"and assigned a file"
do
setup
do
now
=
Time
.
mktime
(
2008
)
now
=
Time
.
now
Time
.
stubs
(
:now
).
returns
(
now
)
@instance
.
expects
(
:[]=
).
with
(
:test_file_name
,
File
.
basename
(
@file
.
path
))
...
...
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