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
280a85a6
Commit
280a85a6
authored
Mar 17, 2010
by
Joe Ferris
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Changed rspec matchers to accept an instance or a class
parent
ae97ec66
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
72 additions
and
36 deletions
+72
-36
lib/paperclip/matchers/have_attached_file_matcher.rb
+1
-0
lib/paperclip/matchers/validate_attachment_content_type_matcher.rb
+1
-0
lib/paperclip/matchers/validate_attachment_presence_matcher.rb
+1
-0
lib/paperclip/matchers/validate_attachment_size_matcher.rb
+1
-0
test/helper.rb
+20
-0
test/matchers/have_attached_file_matcher_test.rb
+9
-6
test/matchers/validate_attachment_content_type_matcher_test.rb
+14
-8
test/matchers/validate_attachment_presence_matcher_test.rb
+8
-5
test/matchers/validate_attachment_size_matcher_test.rb
+17
-17
No files found.
lib/paperclip/matchers/have_attached_file_matcher.rb
View file @
280a85a6
...
...
@@ -12,6 +12,7 @@ module Paperclip
def
matches?
subject
@subject
=
subject
@subject
=
@subject
.
class
unless
Class
===
@subject
responds?
&&
has_column?
&&
included?
end
...
...
lib/paperclip/matchers/validate_attachment_content_type_matcher.rb
View file @
280a85a6
...
...
@@ -22,6 +22,7 @@ module Paperclip
def
matches?
subject
@subject
=
subject
@subject
=
@subject
.
class
unless
Class
===
@subject
@allowed_types
&&
@rejected_types
&&
allowed_types_allowed?
&&
rejected_types_rejected?
end
...
...
lib/paperclip/matchers/validate_attachment_presence_matcher.rb
View file @
280a85a6
...
...
@@ -12,6 +12,7 @@ module Paperclip
def
matches?
subject
@subject
=
subject
@subject
=
@subject
.
class
unless
Class
===
@subject
error_when_not_valid?
&&
no_error_when_valid?
end
...
...
lib/paperclip/matchers/validate_attachment_size_matcher.rb
View file @
280a85a6
...
...
@@ -28,6 +28,7 @@ module Paperclip
def
matches?
subject
@subject
=
subject
@subject
=
@subject
.
class
unless
Class
===
@subject
lower_than_low?
&&
higher_than_low?
&&
lower_than_high?
&&
higher_than_high?
end
...
...
test/helper.rb
View file @
280a85a6
...
...
@@ -106,3 +106,23 @@ def silence_warnings
ensure
$VERBOSE
=
old_verbose
end
def
should_accept_dummy_class
should
"accept the class"
do
assert_accepts
@matcher
,
@dummy_class
end
should
"accept an instance of that class"
do
assert_accepts
@matcher
,
@dummy_class
.
new
end
end
def
should_reject_dummy_class
should
"reject the class"
do
assert_rejects
@matcher
,
@dummy_class
end
should
"reject an instance of that class"
do
assert_rejects
@matcher
,
@dummy_class
.
new
end
end
test/matchers/have_attached_file_matcher_test.rb
View file @
280a85a6
...
...
@@ -8,14 +8,17 @@ class HaveAttachedFileMatcherTest < Test::Unit::TestCase
@matcher
=
self
.
class
.
have_attached_file
(
:avatar
)
end
should
"reject
a class with no attachment"
do
assert_rejects
@matcher
,
@
dummy_class
context
"given
a class with no attachment"
do
should_reject_
dummy_class
end
should
"accept a class with an attachment"
do
modify_table
(
"dummies"
){
|
d
|
d
.
string
:avatar_file_name
}
@dummy_class
.
has_attached_file
:avatar
assert_accepts
@matcher
,
@dummy_class
context
"given a class with an attachment"
do
setup
do
modify_table
(
"dummies"
){
|
d
|
d
.
string
:avatar_file_name
}
@dummy_class
.
has_attached_file
:avatar
end
should_accept_dummy_class
end
end
end
test/matchers/validate_attachment_content_type_matcher_test.rb
View file @
280a85a6
...
...
@@ -14,18 +14,24 @@ class ValidateAttachmentContentTypeMatcherTest < Test::Unit::TestCase
rejecting
(
%w(audio/mp3 application/octet-stream)
)
end
should
"reject
a class with no validation"
do
assert_rejects
@matcher
,
@
dummy_class
context
"given
a class with no validation"
do
should_reject_
dummy_class
end
should
"reject a class with a validation that doesn't match"
do
@dummy_class
.
validates_attachment_content_type
:avatar
,
:content_type
=>
%r{audio/.*}
assert_rejects
@matcher
,
@dummy_class
context
"given a class with a validation that doesn't match"
do
setup
do
@dummy_class
.
validates_attachment_content_type
:avatar
,
:content_type
=>
%r{audio/.*}
end
should_reject_dummy_class
end
should
"accept a class with a validation"
do
@dummy_class
.
validates_attachment_content_type
:avatar
,
:content_type
=>
%r{image/.*}
assert_accepts
@matcher
,
@dummy_class
context
"given a class with a matching validation"
do
setup
do
@dummy_class
.
validates_attachment_content_type
:avatar
,
:content_type
=>
%r{image/.*}
end
should_accept_dummy_class
end
end
end
test/matchers/validate_attachment_presence_matcher_test.rb
View file @
280a85a6
...
...
@@ -11,13 +11,16 @@ class ValidateAttachmentPresenceMatcherTest < Test::Unit::TestCase
@matcher
=
self
.
class
.
validate_attachment_presence
(
:avatar
)
end
should
"reject
a class with no validation"
do
assert_rejects
@matcher
,
@
dummy_class
context
"given
a class with no validation"
do
should_reject_
dummy_class
end
should
"accept a class with a validation"
do
@dummy_class
.
validates_attachment_presence
:avatar
assert_accepts
@matcher
,
@dummy_class
context
"given a class with a matching validation"
do
setup
do
@dummy_class
.
validates_attachment_presence
:avatar
end
should_accept_dummy_class
end
end
end
test/matchers/validate_attachment_size_matcher_test.rb
View file @
280a85a6
...
...
@@ -14,37 +14,37 @@ class ValidateAttachmentSizeMatcherTest < Test::Unit::TestCase
context
"of limited size"
do
setup
{
@matcher
=
self
.
class
.
validate_attachment_size
(
:avatar
).
in
(
256
..
1024
)
}
should
"reject
a class with no validation"
do
assert_rejects
@matcher
,
@
dummy_class
context
"given
a class with no validation"
do
should_reject_
dummy_class
end
should
"reject
a class with a validation that's too high"
do
@dummy_class
.
validates_attachment_size
:avatar
,
:in
=>
256
..
2048
assert_rejects
@matcher
,
@
dummy_class
context
"given
a class with a validation that's too high"
do
setup
{
@dummy_class
.
validates_attachment_size
:avatar
,
:in
=>
256
..
2048
}
should_reject_
dummy_class
end
should
"reject
a class with a validation that's too low"
do
@dummy_class
.
validates_attachment_size
:avatar
,
:in
=>
0
..
1024
assert_rejects
@matcher
,
@
dummy_class
context
"given
a class with a validation that's too low"
do
setup
{
@dummy_class
.
validates_attachment_size
:avatar
,
:in
=>
0
..
1024
}
should_reject_
dummy_class
end
should
"accept
a class with a validation that matches"
do
@dummy_class
.
validates_attachment_size
:avatar
,
:in
=>
256
..
1024
assert_accepts
@matcher
,
@
dummy_class
context
"given
a class with a validation that matches"
do
setup
{
@dummy_class
.
validates_attachment_size
:avatar
,
:in
=>
256
..
1024
}
should_accept_
dummy_class
end
end
context
"validates_attachment_size with infinite range"
do
setup
{
@matcher
=
self
.
class
.
validate_attachment_size
(
:avatar
)
}
should
"accept
a class with an upper limit"
do
@dummy_class
.
validates_attachment_size
:avatar
,
:less_than
=>
1
assert_accepts
@matcher
,
@
dummy_class
context
"given
a class with an upper limit"
do
setup
{
@dummy_class
.
validates_attachment_size
:avatar
,
:less_than
=>
1
}
should_accept_
dummy_class
end
should
"accept
a class with no upper limit"
do
@dummy_class
.
validates_attachment_size
:avatar
,
:greater_than
=>
1
assert_accepts
@matcher
,
@
dummy_class
context
"given
a class with no upper limit"
do
setup
{
@dummy_class
.
validates_attachment_size
:avatar
,
:greater_than
=>
1
}
should_accept_
dummy_class
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