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
726f183c
Commit
726f183c
authored
Oct 22, 2013
by
Jon Yurek
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
WIP
parent
fb13e2ec
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
71 additions
and
61 deletions
+71
-61
test/helper.rb
+15
-1
test/io_adapters/attachment_adapter_test.rb
+21
-8
test/io_adapters/file_adapter_test.rb
+34
-52
test/validators/attachment_content_type_validator_test.rb
+1
-0
No files found.
test/helper.rb
View file @
726f183c
...
@@ -32,6 +32,7 @@ end
...
@@ -32,6 +32,7 @@ end
ROOT
=
Pathname
(
File
.
expand_path
(
File
.
join
(
File
.
dirname
(
__FILE__
),
'..'
)))
ROOT
=
Pathname
(
File
.
expand_path
(
File
.
join
(
File
.
dirname
(
__FILE__
),
'..'
)))
$previous_count
=
0
class
Test
::
Unit
::
TestCase
class
Test
::
Unit
::
TestCase
def
setup
def
setup
silence_warnings
do
silence_warnings
do
...
@@ -42,8 +43,21 @@ class Test::Unit::TestCase
...
@@ -42,8 +43,21 @@ class Test::Unit::TestCase
end
end
end
end
def
teardown
report_files
end
def
report_files
def
report_files
ObjectSpace
.
each_object
(
IO
){
|
io
|
puts
"Open IO:
#{
io
.
inspect
}
"
unless
io
.
closed?
}
files
=
[]
ObjectSpace
.
each_object
(
IO
){
|
io
|
files
<<
io
unless
io
.
closed?
}
if
files
.
count
>
$previous_count
puts
__name__
puts
"
#{
files
.
count
}
files"
files
.
each
do
|
file
|
puts
"Open IO:
#{
file
.
inspect
}
"
end
end
$previous_count
=
files
.
count
end
end
end
end
...
...
test/io_adapters/attachment_adapter_test.rb
View file @
726f183c
require
'./test/helper'
require
'./test/helper'
# class File
# def initialize_with_logging(*args)
# p "NEW FILE #{args.inspect}"
# p caller
# initialize_without_logging(*args)
# end
# alias_method :initialize_without_logging, :initialize
# alias_method :initialize, :initialize_with_logging
# end
# class Tempfile
# def initialize_with_logging(*args)
# p "NEW #{args.inspect}"
# initialize_without_logging(*args)
# end
# alias_method :initialize_without_logging, :initialize
# alias_method :initialize, :initialize_with_logging
# end
class
AttachmentAdapterTest
<
Test
::
Unit
::
TestCase
class
AttachmentAdapterTest
<
Test
::
Unit
::
TestCase
def
setup
def
setup
...
@@ -7,10 +25,6 @@ class AttachmentAdapterTest < Test::Unit::TestCase
...
@@ -7,10 +25,6 @@ class AttachmentAdapterTest < Test::Unit::TestCase
@attachment
=
Dummy
.
new
.
avatar
@attachment
=
Dummy
.
new
.
avatar
end
end
def
teardown
report_files
end
context
"for an attachment"
do
context
"for an attachment"
do
setup
do
setup
do
@file
=
File
.
new
(
fixture_file
(
"5k.png"
))
@file
=
File
.
new
(
fixture_file
(
"5k.png"
))
...
@@ -22,7 +36,6 @@ class AttachmentAdapterTest < Test::Unit::TestCase
...
@@ -22,7 +36,6 @@ class AttachmentAdapterTest < Test::Unit::TestCase
end
end
teardown
do
teardown
do
@subject
.
close
@file
.
close
@file
.
close
end
end
...
@@ -63,8 +76,8 @@ class AttachmentAdapterTest < Test::Unit::TestCase
...
@@ -63,8 +76,8 @@ class AttachmentAdapterTest < Test::Unit::TestCase
context
"for a file with restricted characters in the name"
do
context
"for a file with restricted characters in the name"
do
setup
do
setup
do
file_contents
=
File
.
new
(
fixture_file
(
"animated.gif"
))
file_contents
=
IO
.
read
(
fixture_file
(
"animated.gif"
))
@file
=
StringIO
.
new
(
file_contents
.
read
)
@file
=
StringIO
.
new
(
file_contents
)
@file
.
stubs
(
:original_filename
).
returns
(
'image:restricted.gif'
)
@file
.
stubs
(
:original_filename
).
returns
(
'image:restricted.gif'
)
@file
.
binmode
@file
.
binmode
...
@@ -74,7 +87,7 @@ class AttachmentAdapterTest < Test::Unit::TestCase
...
@@ -74,7 +87,7 @@ class AttachmentAdapterTest < Test::Unit::TestCase
end
end
teardown
do
teardown
do
@
file
.
close
@
subject
.
close
end
end
should
"not generate paths that include restricted characters"
do
should
"not generate paths that include restricted characters"
do
...
...
test/io_adapters/file_adapter_test.rb
View file @
726f183c
require
'./test/helper'
require
'./test/helper'
class
File
def
initialize_with_logging
(
*
args
)
p
"NEW FILE
#{
args
.
inspect
}
"
p
caller
initialize_without_logging
(
*
args
)
end
alias_method
:initialize_without_logging
,
:initialize
alias_method
:initialize
,
:initialize_with_logging
end
# class Tempfile
# def initialize_with_logging(*args)
# p "NEW #{args.inspect}"
# initialize_without_logging(*args)
# end
# alias_method :initialize_without_logging, :initialize
# alias_method :initialize, :initialize_with_logging
# end
class
FileAdapterTest
<
Test
::
Unit
::
TestCase
class
FileAdapterTest
<
Test
::
Unit
::
TestCase
def
setup
p
self
end
def
teardown
report_files
end
context
"a new instance"
do
context
"a new instance"
do
context
"with normal file"
do
context
"with normal file"
do
setup
do
setup
do
@file
=
File
.
new
(
fixture_file
(
"5k.png"
))
@file
=
File
.
new
(
fixture_file
(
"5k.png"
))
@file
.
binmode
@file
.
binmode
@subject
=
Paperclip
.
io_adapters
.
for
(
@file
)
end
end
teardown
do
teardown
do
@file
.
close
@file
.
close
@subject
.
close
@subject
.
close
if
@subject
end
end
should
"get the right filename"
do
context
'doing normal things'
do
assert_equal
"5k.png"
,
@subject
.
original_filename
setup
do
end
@subject
=
Paperclip
.
io_adapters
.
for
(
@file
)
end
should
"force binmode on tempfil
e"
do
should
"get the right filenam
e"
do
assert
@subject
.
instance_variable_get
(
"@tempfile"
).
binmode?
assert_equal
"5k.png"
,
@subject
.
original_filename
end
end
should
"get the content typ
e"
do
should
"force binmode on tempfil
e"
do
assert_equal
"image/png"
,
@subject
.
content_type
assert
@subject
.
instance_variable_get
(
"@tempfile"
).
binmode?
end
end
should
"return content type as a string
"
do
should
"get the content type
"
do
assert_kind_of
String
,
@subject
.
content_type
assert_equal
"image/png"
,
@subject
.
content_type
end
end
should
"get the file's size
"
do
should
"return content type as a string
"
do
assert_equal
4456
,
@subject
.
siz
e
assert_kind_of
String
,
@subject
.
content_typ
e
end
end
should
"return false for a call to nil?
"
do
should
"get the file's size
"
do
assert
!
@subject
.
nil?
assert_equal
4456
,
@subject
.
size
end
end
should
"generate a MD5 hash of the contents"
do
should
"return false for a call to nil?"
do
expected
=
Digest
::
MD5
.
file
(
@file
.
path
).
to_s
assert
!
@subject
.
nil?
assert_equal
expected
,
@subject
.
fingerprint
end
end
should
"read the contents of the file"
do
should
"generate a MD5 hash of the contents"
do
expected
=
@file
.
read
expected
=
Digest
::
MD5
.
file
(
@file
.
path
).
to_s
assert
expected
.
length
>
0
assert_equal
expected
,
@subject
.
fingerprint
assert_equal
expected
,
@subject
.
read
end
should
"read the contents of the file"
do
expected
=
@file
.
read
assert
expected
.
length
>
0
assert_equal
expected
,
@subject
.
read
end
end
end
context
"file with multiple possible content type"
do
context
"file with multiple possible content type"
do
setup
do
setup
do
MIME
::
Types
.
stubs
(
:type_for
).
returns
([
MIME
::
Type
.
new
(
'image/x-png'
),
MIME
::
Type
.
new
(
'image/png'
)])
MIME
::
Types
.
stubs
(
:type_for
).
returns
([
MIME
::
Type
.
new
(
'image/x-png'
),
MIME
::
Type
.
new
(
'image/png'
)])
@subject
=
Paperclip
.
io_adapters
.
for
(
@file
)
end
end
should
"prefer officially registered mime type"
do
should
"prefer officially registered mime type"
do
...
...
test/validators/attachment_content_type_validator_test.rb
View file @
726f183c
...
@@ -4,6 +4,7 @@ class AttachmentContentTypeValidatorTest < Test::Unit::TestCase
...
@@ -4,6 +4,7 @@ class AttachmentContentTypeValidatorTest < Test::Unit::TestCase
def
setup
def
setup
rebuild_model
rebuild_model
@dummy
=
Dummy
.
new
@dummy
=
Dummy
.
new
super
end
end
def
build_validator
(
options
)
def
build_validator
(
options
)
...
...
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