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
c72812fb
Commit
c72812fb
authored
Dec 10, 2008
by
Jon Yurek
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fields other than <name>_file_name are not required for operation.
parent
9c510875
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
70 additions
and
5 deletions
+70
-5
lib/paperclip/attachment.rb
+10
-5
test/attachment_test.rb
+57
-0
test/helper.rb
+3
-0
No files found.
lib/paperclip/attachment.rb
View file @
c72812fb
...
...
@@ -62,7 +62,6 @@ module Paperclip
if
uploaded_file
.
is_a?
(
Paperclip
::
Attachment
)
uploaded_file
=
uploaded_file
.
to_file
(
:original
)
close_uploaded_file
=
true
if
uploaded_file
.
respond_to?
(
:close
)
end
return
nil
unless
valid_assignment?
(
uploaded_file
)
...
...
@@ -89,7 +88,6 @@ module Paperclip
# Reset the file size if the original file was reprocessed.
instance_write
(
:file_size
,
uploaded_file
.
size
.
to_i
)
ensure
uploaded_file
.
close
if
close_uploaded_file
validate
end
...
...
@@ -153,6 +151,10 @@ module Paperclip
def
original_filename
instance_read
(
:file_name
)
end
def
content_type
instance_read
(
:content_type
)
end
def
updated_at
time
=
instance_read
(
:updated_at
)
...
...
@@ -193,7 +195,6 @@ module Paperclip
# again.
def
reprocess!
new_original
=
Tempfile
.
new
(
"paperclip-reprocess"
)
new_original
.
binmode
if
old_original
=
to_file
(
:original
)
new_original
.
write
(
old_original
.
read
)
new_original
.
rewind
...
...
@@ -214,11 +215,15 @@ module Paperclip
end
def
instance_write
(
attr
,
value
)
instance
.
send
(
:"
#{
name
}
_
#{
attr
}
="
,
value
)
setter
=
:"
#{
name
}
_
#{
attr
}
="
responds
=
instance
.
respond_to?
(
setter
)
instance
.
send
(
setter
,
value
)
if
responds
||
attr
.
to_s
==
"file_name"
end
def
instance_read
(
attr
)
instance
.
send
(
:"
#{
name
}
_
#{
attr
}
"
)
getter
=
:"
#{
name
}
_
#{
attr
}
"
responds
=
instance
.
respond_to?
(
getter
)
instance
.
send
(
getter
)
if
responds
||
attr
.
to_s
==
"file_name"
end
private
...
...
test/attachment_test.rb
View file @
c72812fb
...
...
@@ -367,4 +367,61 @@ class AttachmentTest < Test::Unit::TestCase
end
end
end
context
"An attachment with only a avatar_file_name column"
do
setup
do
ActiveRecord
::
Base
.
connection
.
create_table
:dummies
,
:force
=>
true
do
|
table
|
table
.
column
:avatar_file_name
,
:string
end
rebuild_class
@dummy
=
Dummy
.
new
@file
=
File
.
new
(
File
.
join
(
File
.
dirname
(
__FILE__
),
"fixtures"
,
"5k.png"
),
'rb'
)
end
should
"not error when assigned an attachment"
do
assert_nothing_raised
{
@dummy
.
avatar
=
@file
}
end
should
"return nil when sent #avatar_updated_at"
do
@dummy
.
avatar
=
@file
assert_nil
@dummy
.
avatar
.
updated_at
end
context
"and avatar_updated_at column"
do
setup
do
ActiveRecord
::
Base
.
connection
.
add_column
:dummies
,
:avatar_updated_at
,
:timestamp
rebuild_class
@dummy
=
Dummy
.
new
end
should
"not error when assigned an attachment"
do
assert_nothing_raised
{
@dummy
.
avatar
=
@file
}
end
should
"return the right value when sent #avatar_updated_at"
do
now
=
Time
.
now
Time
.
stubs
(
:now
).
returns
(
now
)
@dummy
.
avatar
=
@file
assert_equal
now
.
to_i
,
@dummy
.
avatar
.
updated_at
end
end
context
"and avatar_content_type column"
do
setup
do
ActiveRecord
::
Base
.
connection
.
add_column
:dummies
,
:avatar_content_type
,
:string
rebuild_class
@dummy
=
Dummy
.
new
end
should
"not error when assigned an attachment"
do
assert_nothing_raised
{
@dummy
.
avatar
=
@file
}
end
should
"return the right value when sent #avatar_content_type"
do
@dummy
.
avatar
=
@file
assert_equal
"image/png"
,
@dummy
.
avatar
.
content_type
end
end
end
end
test/helper.rb
View file @
c72812fb
...
...
@@ -35,7 +35,10 @@ def rebuild_model options = {}
table
.
column
:avatar_file_size
,
:integer
table
.
column
:avatar_updated_at
,
:datetime
end
rebuild_class
options
end
def
rebuild_class
options
=
{}
ActiveRecord
::
Base
.
send
(
:include
,
Paperclip
)
Object
.
send
(
:remove_const
,
"Dummy"
)
rescue
nil
Object
.
const_set
(
"Dummy"
,
Class
.
new
(
ActiveRecord
::
Base
))
...
...
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