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
0f4be8ac
Commit
0f4be8ac
authored
Dec 10, 2008
by
Jon Yurek
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed issue with size validations and the removal of size column requirements.
parent
c72812fb
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
33 additions
and
1 deletions
+33
-1
lib/paperclip.rb
+1
-1
lib/paperclip/attachment.rb
+4
-0
test/attachment_test.rb
+28
-0
No files found.
lib/paperclip.rb
View file @
0f4be8ac
...
...
@@ -181,7 +181,7 @@ module Paperclip
message = options[:message] || "file size must be between :min and :max bytes."
attachment_definitions[name][:validations][:size] = lambda do |attachment, instance|
if attachment.file? && !range.include?(attachment.
instance_read(:file_size)
.to_i)
if attachment.file? && !range.include?(attachment.
size
.to_i)
message.gsub(/:min/, min.to_s).gsub(/:max/, max.to_s)
end
end
...
...
lib/paperclip/attachment.rb
View file @
0f4be8ac
...
...
@@ -152,6 +152,10 @@ module Paperclip
instance_read
(
:file_name
)
end
def
size
instance_read
(
:file_size
)
||
(
@queued_for_write
[
:original
]
&&
@queued_for_write
[
:original
].
size
)
end
def
content_type
instance_read
(
:content_type
)
end
...
...
test/attachment_test.rb
View file @
0f4be8ac
...
...
@@ -387,6 +387,11 @@ class AttachmentTest < Test::Unit::TestCase
assert_nil
@dummy
.
avatar
.
updated_at
end
should
"return the right value when sent #avatar_file_size"
do
@dummy
.
avatar
=
@file
assert_equal
@file
.
size
,
@dummy
.
avatar
.
size
end
context
"and avatar_updated_at column"
do
setup
do
ActiveRecord
::
Base
.
connection
.
add_column
:dummies
,
:avatar_updated_at
,
:timestamp
...
...
@@ -423,5 +428,28 @@ class AttachmentTest < Test::Unit::TestCase
end
end
context
"and avatar_file_size column"
do
setup
do
ActiveRecord
::
Base
.
connection
.
add_column
:dummies
,
:avatar_file_size
,
:integer
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_file_size"
do
@dummy
.
avatar
=
@file
assert_equal
@file
.
size
,
@dummy
.
avatar
.
size
end
should
"return the right value when saved, reloaded, and sent #avatar_file_size"
do
@dummy
.
avatar
=
@file
@dummy
.
save
@dummy
=
Dummy
.
find
(
@dummy
.
id
)
assert_equal
@file
.
size
,
@dummy
.
avatar
.
size
end
end
end
end
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