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
d9de7ba5
Commit
d9de7ba5
authored
Jun 15, 2012
by
Prem Sichanugrist
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use ActiveSupport::Delegation to delegate method
parent
2059c5ea
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
19 additions
and
52 deletions
+19
-52
lib/paperclip/io_adapters/abstract_adapter.rb
+4
-37
test/io_adapters/abstract_adapter_test.rb
+15
-15
No files found.
lib/paperclip/io_adapters/abstract_adapter.rb
View file @
d9de7ba5
require
'active_support/core_ext/module/delegation'
module
Paperclip
class
AbstractAdapter
def
original_filename
@original_filename
end
def
content_type
@content_type
end
def
size
@size
end
attr_reader
:content_type
,
:original_filename
,
:size
delegate
:close
,
:closed?
,
:eof?
,
:path
,
:rewind
,
:to
=>
:@tempfile
def
fingerprint
@fingerprint
||=
Digest
::
MD5
.
file
(
path
).
to_s
end
def
nil?
false
end
def
read
(
length
=
nil
,
buffer
=
nil
)
@tempfile
.
read
(
length
,
buffer
)
end
# We don't use this directly, but aws/sdk does.
def
rewind
@tempfile
.
rewind
end
def
eof?
@tempfile
.
eof?
end
def
path
@tempfile
.
path
end
def
close
@tempfile
.
close
end
def
closed?
@tempfile
.
closed?
end
private
def
destination
...
...
test/io_adapters/abstract_adapter_test.rb
View file @
d9de7ba5
...
...
@@ -2,7 +2,7 @@ require './test/helper'
class
AbstractAdapterTest
<
Test
::
Unit
::
TestCase
class
TestAdapter
<
Paperclip
::
AbstractAdapter
attr_accessor
:
path
,
:
original_file_name
,
:tempfile
attr_accessor
:original_file_name
,
:tempfile
def
content_type
type_from_file_command
...
...
@@ -11,11 +11,19 @@ class AbstractAdapterTest < Test::Unit::TestCase
context
"content type from file command"
do
setup
do
@adapter
=
TestAdapter
.
new
@adapter
.
stubs
(
:path
)
Paperclip
.
stubs
(
:run
).
returns
(
"image/png
\n
"
)
end
should
"return the content type without newline"
do
assert_equal
"image/png"
,
TestAdapter
.
new
.
content_type
assert_equal
"image/png"
,
@adapter
.
content_type
end
end
context
"nil?"
do
should
"return false"
do
assert
!
TestAdapter
.
new
.
nil?
end
end
...
...
@@ -25,19 +33,11 @@ class AbstractAdapterTest < Test::Unit::TestCase
@adapter
.
tempfile
=
stub
(
"Tempfile"
)
end
context
"close"
do
should
"delegate to tempfile"
do
@adapter
.
tempfile
.
stubs
(
:close
)
@adapter
.
close
assert_received
@adapter
.
tempfile
,
:close
end
end
context
"closed?"
do
should
"delegate to tempfile"
do
@adapter
.
tempfile
.
stubs
(
:closed?
)
@adapter
.
closed?
assert_received
@adapter
.
tempfile
,
:closed?
[
:close
,
:closed?
,
:eof?
,
:path
,
:rewind
].
each
do
|
method
|
should
"delegate
#{
method
}
to @tempfile"
do
@adapter
.
tempfile
.
stubs
(
method
)
@adapter
.
public_send
(
method
)
assert_received
@adapter
.
tempfile
,
method
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