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
cdf85a20
Commit
cdf85a20
authored
Jun 15, 2012
by
Prem Sichanugrist
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add test helper for assert file existence
parent
3275f690
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
51 additions
and
43 deletions
+51
-43
test/attachment_test.rb
+17
-17
test/helper.rb
+8
-0
test/integration_test.rb
+23
-23
test/storage/filesystem_test.rb
+3
-3
No files found.
test/attachment_test.rb
View file @
cdf85a20
...
...
@@ -28,15 +28,15 @@ class AttachmentTest < Test::Unit::TestCase
dummy
.
avatar
=
file
dummy
.
save
assert
File
.
exists?
(
dummy
.
avatar
.
path
(
:small
))
assert
File
.
exists?
(
dummy
.
avatar
.
path
(
:large
))
assert
File
.
exists?
(
dummy
.
avatar
.
path
(
:original
))
assert
_file_exists
(
dummy
.
avatar
.
path
(
:small
))
assert
_file_exists
(
dummy
.
avatar
.
path
(
:large
))
assert
_file_exists
(
dummy
.
avatar
.
path
(
:original
))
dummy
.
avatar
.
reprocess!
(
:small
)
assert
File
.
exists?
(
dummy
.
avatar
.
path
(
:small
))
assert
File
.
exists?
(
dummy
.
avatar
.
path
(
:large
))
assert
File
.
exists?
(
dummy
.
avatar
.
path
(
:original
))
assert
_file_exists
(
dummy
.
avatar
.
path
(
:small
))
assert
_file_exists
(
dummy
.
avatar
.
path
(
:large
))
assert
_file_exists
(
dummy
.
avatar
.
path
(
:original
))
end
should
"handle a boolean second argument to #url"
do
...
...
@@ -957,7 +957,7 @@ class AttachmentTest < Test::Unit::TestCase
should
"commit the files to disk"
do
[
:large
,
:medium
,
:small
].
each
do
|
style
|
assert
File
.
exists?
(
@attachment
.
path
(
style
))
assert
_file_exists
(
@attachment
.
path
(
style
))
end
end
...
...
@@ -989,7 +989,7 @@ class AttachmentTest < Test::Unit::TestCase
@attachment
.
expects
(
:instance_write
).
with
(
:updated_at
,
nil
)
@attachment
.
assign
nil
@attachment
.
save
@existing_names
.
each
{
|
f
|
assert
!
File
.
exists?
(
f
)
}
@existing_names
.
each
{
|
f
|
assert
_file_not_exists
(
f
)
}
end
should
"delete the files when you call #clear and #save"
do
...
...
@@ -1000,7 +1000,7 @@ class AttachmentTest < Test::Unit::TestCase
@attachment
.
expects
(
:instance_write
).
with
(
:updated_at
,
nil
)
@attachment
.
clear
@attachment
.
save
@existing_names
.
each
{
|
f
|
assert
!
File
.
exists?
(
f
)
}
@existing_names
.
each
{
|
f
|
assert
_file_not_exists
(
f
)
}
end
should
"delete the files when you call #delete"
do
...
...
@@ -1010,7 +1010,7 @@ class AttachmentTest < Test::Unit::TestCase
@attachment
.
expects
(
:instance_write
).
with
(
:fingerprint
,
nil
)
@attachment
.
expects
(
:instance_write
).
with
(
:updated_at
,
nil
)
@attachment
.
destroy
@existing_names
.
each
{
|
f
|
assert
!
File
.
exists?
(
f
)
}
@existing_names
.
each
{
|
f
|
assert
_file_not_exists
(
f
)
}
end
context
"when keeping old files"
do
...
...
@@ -1026,7 +1026,7 @@ class AttachmentTest < Test::Unit::TestCase
@attachment
.
expects
(
:instance_write
).
with
(
:updated_at
,
nil
)
@attachment
.
assign
nil
@attachment
.
save
@existing_names
.
each
{
|
f
|
assert
File
.
exists?
(
f
)
}
@existing_names
.
each
{
|
f
|
assert
_file_exists
(
f
)
}
end
should
"keep the files when you call #clear and #save"
do
...
...
@@ -1037,7 +1037,7 @@ class AttachmentTest < Test::Unit::TestCase
@attachment
.
expects
(
:instance_write
).
with
(
:updated_at
,
nil
)
@attachment
.
clear
@attachment
.
save
@existing_names
.
each
{
|
f
|
assert
File
.
exists?
(
f
)
}
@existing_names
.
each
{
|
f
|
assert
_file_exists
(
f
)
}
end
should
"keep the files when you call #delete"
do
...
...
@@ -1047,7 +1047,7 @@ class AttachmentTest < Test::Unit::TestCase
@attachment
.
expects
(
:instance_write
).
with
(
:fingerprint
,
nil
)
@attachment
.
expects
(
:instance_write
).
with
(
:updated_at
,
nil
)
@attachment
.
destroy
@existing_names
.
each
{
|
f
|
assert
File
.
exists?
(
f
)
}
@existing_names
.
each
{
|
f
|
assert
_file_exists
(
f
)
}
end
end
end
...
...
@@ -1206,12 +1206,12 @@ class AttachmentTest < Test::Unit::TestCase
should
"not delete the files from storage when attachment is destroyed"
do
@attachment
.
destroy
assert
File
.
exists?
(
@path
)
assert
_file_exists
(
@path
)
end
should
"not delete the file when model is destroyed"
do
@dummy
.
destroy
assert
File
.
exists?
(
@path
)
assert
_file_exists
(
@path
)
end
end
...
...
@@ -1235,12 +1235,12 @@ class AttachmentTest < Test::Unit::TestCase
@dummy
.
destroy
end
assert
File
.
exists?
(
@path
),
"
#{
@path
}
does not exist."
assert
_file_exists
(
@path
)
end
should
"be deleted when the model is destroyed"
do
@dummy
.
destroy
assert
!
File
.
exists?
(
@path
),
"
#{
@path
}
does not exist."
assert
_file_not_exists
(
@path
)
end
end
...
...
test/helper.rb
View file @
cdf85a20
...
...
@@ -177,3 +177,11 @@ def assert_not_found_response(url)
"Expected HTTP response code 404, got
#{
response
.
code
}
"
end
end
def
assert_file_exists
(
path
)
assert
File
.
exists?
(
path
),
%(Expect "#{path}" to be exists.)
end
def
assert_file_not_exists
(
path
)
assert
!
File
.
exists?
(
path
),
%(Expect "#{path}" to not exists.)
end
test/integration_test.rb
View file @
cdf85a20
...
...
@@ -96,14 +96,14 @@ class IntegrationTest < Test::Unit::TestCase
@dummy
.
avatar
.
post_processing
=
false
@dummy
.
avatar
=
@file
assert
@dummy
.
save
assert
!
File
.
exists?
(
@thumb_path
)
assert
_file_not_exists
@thumb_path
end
should
"create the thumbnails upon saving when post_processing is enabled"
do
@dummy
.
avatar
.
post_processing
=
true
@dummy
.
avatar
=
@file
assert
@dummy
.
save
assert
File
.
exists?
(
@thumb_path
)
assert
_file_exists
@thumb_path
end
end
...
...
@@ -126,25 +126,25 @@ class IntegrationTest < Test::Unit::TestCase
teardown
{
@file
.
close
}
should
"allow us to create all thumbnails in one go"
do
assert
!
File
.
exists?
(
@thumb_small_path
)
assert
!
File
.
exists?
(
@thumb_large_path
)
assert
_file_not_exists
(
@thumb_small_path
)
assert
_file_not_exists
(
@thumb_large_path
)
@dummy
.
avatar
.
reprocess!
assert
File
.
exists?
(
@thumb_small_path
)
assert
File
.
exists?
(
@thumb_large_path
)
assert
_file_exists
(
@thumb_small_path
)
assert
_file_exists
(
@thumb_large_path
)
end
should
"allow us to selectively create each thumbnail"
do
assert
!
File
.
exists?
(
@thumb_small_path
)
assert
!
File
.
exists?
(
@thumb_large_path
)
assert
_file_not_exists
(
@thumb_small_path
)
assert
_file_not_exists
(
@thumb_large_path
)
@dummy
.
avatar
.
reprocess!
:thumb_small
assert
File
.
exists?
(
@thumb_small_path
)
assert
!
File
.
exists?
(
@thumb_large_path
)
assert
_file_exists
(
@thumb_small_path
)
assert
_file_not_exists
(
@thumb_large_path
)
@dummy
.
avatar
.
reprocess!
:thumb_large
assert
File
.
exists?
(
@thumb_large_path
)
assert
_file_exists
(
@thumb_large_path
)
end
end
...
...
@@ -182,7 +182,7 @@ class IntegrationTest < Test::Unit::TestCase
end
should
"have a large file in the right place"
do
assert
File
.
exists?
(
@dummy
.
avatar
.
path
(
:large
))
assert
_file_exists
(
@dummy
.
avatar
.
path
(
:large
))
end
context
"and deleted"
do
...
...
@@ -192,12 +192,12 @@ class IntegrationTest < Test::Unit::TestCase
end
should
"not have a large file in the right place anymore"
do
assert
!
File
.
exists?
(
@saved_path
)
assert
_file_not_exists
(
@saved_path
)
end
should
"not have its next two parent directories"
do
assert
!
File
.
exists?
(
File
.
dirname
(
@saved_path
))
assert
!
File
.
exists?
(
File
.
dirname
(
File
.
dirname
(
@saved_path
)))
assert
_file_not_exists
(
File
.
dirname
(
@saved_path
))
assert
_file_not_exists
(
File
.
dirname
(
File
.
dirname
(
@saved_path
)))
end
before_should
"not die if an unexpected SystemCallError happens"
do
...
...
@@ -334,7 +334,7 @@ class IntegrationTest < Test::Unit::TestCase
assert
@dummy
.
save
saved_paths
.
each
do
|
p
|
assert
File
.
exists?
(
p
)
assert
_file_exists
(
p
)
end
@dummy
.
avatar
.
clear
...
...
@@ -343,7 +343,7 @@ class IntegrationTest < Test::Unit::TestCase
assert
@dummy
.
save
saved_paths
.
each
do
|
p
|
assert
!
File
.
exists?
(
p
)
assert
_file_not_exists
(
p
)
end
@d2
=
Dummy
.
find
(
@dummy
.
id
)
...
...
@@ -364,7 +364,7 @@ class IntegrationTest < Test::Unit::TestCase
assert
@d2
.
save
saved_paths
.
each
do
|
p
|
assert
!
File
.
exists?
(
p
)
assert
_file_not_exists
(
p
)
end
end
...
...
@@ -457,8 +457,8 @@ class IntegrationTest < Test::Unit::TestCase
end
should
"be accessible"
do
assert
File
.
exists?
(
@dummy
.
avatar
.
path
(
:original
))
assert
File
.
exists?
(
@dummy
.
avatar
.
path
(
:thumb
))
assert
_file_exists
(
@dummy
.
avatar
.
path
(
:original
))
assert
_file_exists
(
@dummy
.
avatar
.
path
(
:thumb
))
end
context
"when new style is added"
do
...
...
@@ -469,9 +469,9 @@ class IntegrationTest < Test::Unit::TestCase
end
should
"make all the styles accessible"
do
assert
File
.
exists?
(
@dummy
.
avatar
.
path
(
:original
))
assert
File
.
exists?
(
@dummy
.
avatar
.
path
(
:thumb
))
assert
File
.
exists?
(
@dummy
.
avatar
.
path
(
:mini
))
assert
_file_exists
(
@dummy
.
avatar
.
path
(
:original
))
assert
_file_exists
(
@dummy
.
avatar
.
path
(
:thumb
))
assert
_file_exists
(
@dummy
.
avatar
.
path
(
:mini
))
end
end
end
...
...
test/storage/filesystem_test.rb
View file @
cdf85a20
...
...
@@ -19,12 +19,12 @@ class FileSystemTest < Test::Unit::TestCase
should
"store the original"
do
@dummy
.
save
assert
File
.
exists?
(
@dummy
.
avatar
.
path
)
assert
_file_exists
(
@dummy
.
avatar
.
path
)
end
should
"store the thumbnail"
do
@dummy
.
save
assert
File
.
exists?
(
@dummy
.
avatar
.
path
(
:thumbnail
))
assert
_file_exists
(
@dummy
.
avatar
.
path
(
:thumbnail
))
end
end
...
...
@@ -41,7 +41,7 @@ class FileSystemTest < Test::Unit::TestCase
teardown
{
@file
.
close
}
should
"store the file"
do
assert
File
.
exists?
(
@dummy
.
avatar
.
path
)
assert
_file_exists
(
@dummy
.
avatar
.
path
)
end
should
"return a replaced version for path"
do
...
...
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