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
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
45 additions
and
35 deletions
+45
-35
test/helper.rb
+15
-1
test/io_adapters/attachment_adapter_test.rb
+21
-8
test/io_adapters/file_adapter_test.rb
+8
-26
test/validators/attachment_content_type_validator_test.rb
+1
-0
No files found.
test/helper.rb
View file @
726f183c
...
...
@@ -32,6 +32,7 @@ end
ROOT
=
Pathname
(
File
.
expand_path
(
File
.
join
(
File
.
dirname
(
__FILE__
),
'..'
)))
$previous_count
=
0
class
Test
::
Unit
::
TestCase
def
setup
silence_warnings
do
...
...
@@ -42,8 +43,21 @@ class Test::Unit::TestCase
end
end
def
teardown
report_files
end
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
...
...
test/io_adapters/attachment_adapter_test.rb
View file @
726f183c
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
def
setup
...
...
@@ -7,10 +25,6 @@ class AttachmentAdapterTest < Test::Unit::TestCase
@attachment
=
Dummy
.
new
.
avatar
end
def
teardown
report_files
end
context
"for an attachment"
do
setup
do
@file
=
File
.
new
(
fixture_file
(
"5k.png"
))
...
...
@@ -22,7 +36,6 @@ class AttachmentAdapterTest < Test::Unit::TestCase
end
teardown
do
@subject
.
close
@file
.
close
end
...
...
@@ -63,8 +76,8 @@ class AttachmentAdapterTest < Test::Unit::TestCase
context
"for a file with restricted characters in the name"
do
setup
do
file_contents
=
File
.
new
(
fixture_file
(
"animated.gif"
))
@file
=
StringIO
.
new
(
file_contents
.
read
)
file_contents
=
IO
.
read
(
fixture_file
(
"animated.gif"
))
@file
=
StringIO
.
new
(
file_contents
)
@file
.
stubs
(
:original_filename
).
returns
(
'image:restricted.gif'
)
@file
.
binmode
...
...
@@ -74,7 +87,7 @@ class AttachmentAdapterTest < Test::Unit::TestCase
end
teardown
do
@
file
.
close
@
subject
.
close
end
should
"not generate paths that include restricted characters"
do
...
...
test/io_adapters/file_adapter_test.rb
View file @
726f183c
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
def
setup
p
self
end
def
teardown
report_files
end
context
"a new instance"
do
context
"with normal file"
do
setup
do
@file
=
File
.
new
(
fixture_file
(
"5k.png"
))
@file
.
binmode
@subject
=
Paperclip
.
io_adapters
.
for
(
@file
)
end
teardown
do
@file
.
close
@subject
.
close
@subject
.
close
if
@subject
end
context
'doing normal things'
do
setup
do
@subject
=
Paperclip
.
io_adapters
.
for
(
@file
)
end
should
"get the right filename"
do
...
...
@@ -72,10 +52,12 @@ class FileAdapterTest < Test::Unit::TestCase
assert
expected
.
length
>
0
assert_equal
expected
,
@subject
.
read
end
end
context
"file with multiple possible content type"
do
setup
do
MIME
::
Types
.
stubs
(
:type_for
).
returns
([
MIME
::
Type
.
new
(
'image/x-png'
),
MIME
::
Type
.
new
(
'image/png'
)])
@subject
=
Paperclip
.
io_adapters
.
for
(
@file
)
end
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
def
setup
rebuild_model
@dummy
=
Dummy
.
new
super
end
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