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