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
ac822448
Commit
ac822448
authored
Dec 13, 2011
by
Dimitrij Denissenko
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed ID partitioning interpolation, when cloning attachments
parent
989ec0ee
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
19 additions
and
2 deletions
+19
-2
lib/paperclip/interpolations.rb
+5
-2
test/interpolations_test.rb
+14
-0
No files found.
lib/paperclip/interpolations.rb
View file @
ac822448
...
...
@@ -150,10 +150,13 @@ module Paperclip
# Returns the id of the instance in a split path form. e.g. returns
# 000/001/234 for an id of 1234.
def
id_partition
attachment
,
style_name
if
(
id
=
attachment
.
instance
.
id
).
is_a?
(
Integer
)
case
id
=
attachment
.
instance
.
id
when
Integer
(
"%09d"
%
id
).
scan
(
/\d{3}/
).
join
(
"/"
)
else
when
String
id
.
scan
(
/.{3}/
).
first
(
3
).
join
(
"/"
)
else
nil
end
end
...
...
test/interpolations_test.rb
View file @
ac822448
...
...
@@ -88,6 +88,13 @@ class InterpolationsTest < Test::Unit::TestCase
assert_equal
23
,
Paperclip
::
Interpolations
.
id
(
attachment
,
:style
)
end
should
"return nil for attachments to new records"
do
attachment
=
mock
attachment
.
expects
(
:id
).
returns
(
nil
)
attachment
.
expects
(
:instance
).
returns
(
attachment
)
assert_nil
Paperclip
::
Interpolations
.
id
(
attachment
,
:style
)
end
should
"return the partitioned id of the attachment when the id is an integer"
do
attachment
=
mock
attachment
.
expects
(
:id
).
returns
(
23
)
...
...
@@ -102,6 +109,13 @@ class InterpolationsTest < Test::Unit::TestCase
assert_equal
"32f/nj2/3oi"
,
Paperclip
::
Interpolations
.
id_partition
(
attachment
,
:style
)
end
should
"return nil for the partitioned id of an attachment to a new record (when the id is nil)"
do
attachment
=
mock
attachment
.
expects
(
:id
).
returns
(
nil
)
attachment
.
expects
(
:instance
).
returns
(
attachment
)
assert_nil
Paperclip
::
Interpolations
.
id_partition
(
attachment
,
:style
)
end
should
"return the name of the attachment"
do
attachment
=
mock
attachment
.
expects
(
:name
).
returns
(
"file"
)
...
...
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