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
491e9f59
Commit
491e9f59
authored
Aug 01, 2008
by
Henrik N
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow assigning another paperclip: new_user.avatar = old_user.avatar.
parent
cae3a9f5
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
0 deletions
+21
-0
lib/paperclip/attachment.rb
+6
-0
test/integration_test.rb
+15
-0
No files found.
lib/paperclip/attachment.rb
View file @
491e9f59
...
@@ -50,7 +50,13 @@ module Paperclip
...
@@ -50,7 +50,13 @@ module Paperclip
# What gets called when you call instance.attachment = File. It clears errors,
# What gets called when you call instance.attachment = File. It clears errors,
# assigns attributes, processes the file, and runs validations. It also queues up
# assigns attributes, processes the file, and runs validations. It also queues up
# the previous file for deletion, to be flushed away on #save of its host.
# the previous file for deletion, to be flushed away on #save of its host.
# In addition to form uploads, you can also assign another Paperclip attachment:
# new_user.avatar = old_user.avatar
def
assign
uploaded_file
def
assign
uploaded_file
if
uploaded_file
.
is_a?
(
Paperclip
::
Attachment
)
uploaded_file
=
uploaded_file
.
to_file
(
:original
)
end
return
nil
unless
valid_assignment?
(
uploaded_file
)
return
nil
unless
valid_assignment?
(
uploaded_file
)
logger
.
info
(
"[paperclip] Assigning
#{
uploaded_file
}
to
#{
name
}
"
)
logger
.
info
(
"[paperclip] Assigning
#{
uploaded_file
}
to
#{
name
}
"
)
...
...
test/integration_test.rb
View file @
491e9f59
...
@@ -198,6 +198,21 @@ class IntegrationTest < Test::Unit::TestCase
...
@@ -198,6 +198,21 @@ class IntegrationTest < Test::Unit::TestCase
@dummy
.
reload
@dummy
.
reload
assert_equal
"5k.png"
,
@dummy
.
avatar_file_name
assert_equal
"5k.png"
,
@dummy
.
avatar_file_name
end
end
should
"assign images from other Paperclips as well"
do
@dummy2
=
Dummy
.
new
@file2
=
File
.
new
(
File
.
join
(
FIXTURES_DIR
,
"12k.png"
))
assert
@dummy2
.
avatar
=
@file2
@dummy2
.
save
assert_not_equal
`identify -format "%wx%h"
#{
@dummy
.
avatar
.
to_file
(
:original
).
path
}
`
,
`identify -format "%wx%h"
#{
@dummy2
.
avatar
.
to_file
(
:original
).
path
}
`
assert
@dummy
.
avatar
=
@dummy2
.
avatar
@dummy
.
save
assert_equal
`identify -format "%wx%h"
#{
@dummy
.
avatar
.
to_file
(
:original
).
path
}
`
,
`identify -format "%wx%h"
#{
@dummy2
.
avatar
.
to_file
(
:original
).
path
}
`
end
end
end
if
ENV
[
'S3_TEST_BUCKET'
]
if
ENV
[
'S3_TEST_BUCKET'
]
...
...
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