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
e8518e0e
Commit
e8518e0e
authored
Dec 12, 2008
by
Jon Yurek
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
New shoulda macros that are actually useful
parent
e8f45902
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
50 additions
and
10 deletions
+50
-10
shoulda_macros/paperclip.rb
+50
-10
No files found.
shoulda_macros/paperclip.rb
View file @
e8518e0e
...
@@ -8,20 +8,60 @@ module Paperclip
...
@@ -8,20 +8,60 @@ module Paperclip
assert
klass
.
instance_methods
.
include?
(
meth
),
"
#{
klass
.
name
}
does not respond to
#{
name
}
."
assert
klass
.
instance_methods
.
include?
(
meth
),
"
#{
klass
.
name
}
does not respond to
#{
name
}
."
end
end
end
end
end
end
should
"have the correct definition"
do
def
should_validate_attachment_size
name
,
options
=
{}
expected
=
options
klass
=
self
.
name
.
gsub
(
/Test$/
,
''
).
constantize
actual
=
klass
.
attachment_definitions
[
name
]
min
=
options
[
:greater_than
]
||
(
options
[
:in
]
&&
options
[
:in
].
first
)
||
0
expected
.
delete
(
:validations
)
if
not
options
.
key?
(
:validations
)
max
=
options
[
:less_than
]
||
(
options
[
:in
]
&&
options
[
:in
].
last
)
||
(
1.0
/
0
)
expected
.
delete
(
:whiny_thumbnails
)
if
not
options
.
key?
(
:whiny_thumbnails
)
range
=
(
min
..
max
)
context
"Class
#{
klass
.
name
}
with attachment
#{
name
}
"
do
context
"with an attachment that is
#{
max
+
1
}
bytes"
do
setup
do
@file
=
StringIO
.
new
(
"."
*
(
max
+
1
))
@attachment
=
klass
.
new
.
send
(
name
)
@attachment
.
assign
(
@file
)
end
assert_equal
expected
,
actual
should
"have a :size validation error"
do
assert
@attachment
.
errors
[
:size
]
end
end
context
"with an attachment that us
#{
max
-
1
}
bytes"
do
setup
do
@file
=
StringIO
.
new
(
"."
*
(
max
-
1
))
@attachment
=
klass
.
new
.
send
(
name
)
@attachment
.
assign
(
@file
)
end
end
should
"ensure that ImageMagick is available"
do
should
"not have a :size validation error"
do
%w( convert identify )
.
each
do
|
command
|
assert
!
@attachment
.
errors
[
:size
]
`
#{
Paperclip
.
path_for_command
(
command
)
}
`
end
assert_equal
0
,
$?
,
"ImageMagick's
#{
command
}
returned with an error. Make sure that
#{
command
}
is available at
#{
Paperclip
.
path_for_command
(
command
)
}
"
end
if
min
>
0
context
"with an attachment that is
#{
min
-
1
}
bytes"
do
setup
do
@file
=
StringIO
.
new
(
"."
*
(
min
-
1
))
@attachment
=
klass
.
new
.
send
(
name
)
@attachment
.
assign
(
@file
)
end
should
"have a :size validation error"
do
assert
@attachment
.
errors
[
:size
]
end
end
context
"with an attachment that us
#{
min
+
1
}
bytes"
do
setup
do
@file
=
StringIO
.
new
(
"."
*
(
min
+
1
))
@attachment
=
klass
.
new
.
send
(
name
)
@attachment
.
assign
(
@file
)
end
should
"not have a :size validation error"
do
assert
!
@attachment
.
errors
[
:size
]
end
end
end
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