summaryrefslogtreecommitdiff
path: root/vendor/plugins/paperclip/shoulda_macros/paperclip.rb
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/plugins/paperclip/shoulda_macros/paperclip.rb')
-rw-r--r--vendor/plugins/paperclip/shoulda_macros/paperclip.rb68
1 files changed, 0 insertions, 68 deletions
diff --git a/vendor/plugins/paperclip/shoulda_macros/paperclip.rb b/vendor/plugins/paperclip/shoulda_macros/paperclip.rb
deleted file mode 100644
index d690357..0000000
--- a/vendor/plugins/paperclip/shoulda_macros/paperclip.rb
+++ /dev/null
@@ -1,68 +0,0 @@
1require 'paperclip/matchers'
2
3module Paperclip
4 # =Paperclip Shoulda Macros
5 #
6 # These macros are intended for use with shoulda, and will be included into
7 # your tests automatically. All of the macros use the standard shoulda
8 # assumption that the name of the test is based on the name of the model
9 # you're testing (that is, UserTest is the test for the User model), and
10 # will load that class for testing purposes.
11 module Shoulda
12 include Matchers
13 # This will test whether you have defined your attachment correctly by
14 # checking for all the required fields exist after the definition of the
15 # attachment.
16 def should_have_attached_file name
17 klass = self.name.gsub(/Test$/, '').constantize
18 matcher = have_attached_file name
19 should matcher.description do
20 assert_accepts(matcher, klass)
21 end
22 end
23
24 # Tests for validations on the presence of the attachment.
25 def should_validate_attachment_presence name
26 klass = self.name.gsub(/Test$/, '').constantize
27 matcher = validate_attachment_presence name
28 should matcher.description do
29 assert_accepts(matcher, klass)
30 end
31 end
32
33 # Tests that you have content_type validations specified. There are two
34 # options, :valid and :invalid. Both accept an array of strings. The
35 # strings should be a list of content types which will pass and fail
36 # validation, respectively.
37 def should_validate_attachment_content_type name, options = {}
38 klass = self.name.gsub(/Test$/, '').constantize
39 valid = [options[:valid]].flatten
40 invalid = [options[:invalid]].flatten
41 matcher = validate_attachment_content_type(name).allowing(valid).rejecting(invalid)
42 should matcher.description do
43 assert_accepts(matcher, klass)
44 end
45 end
46
47 # Tests to ensure that you have file size validations turned on. You
48 # can pass the same options to this that you can to
49 # validate_attachment_file_size - :less_than, :greater_than, and :in.
50 # :less_than checks that a file is less than a certain size, :greater_than
51 # checks that a file is more than a certain size, and :in takes a Range or
52 # Array which specifies the lower and upper limits of the file size.
53 def should_validate_attachment_size name, options = {}
54 klass = self.name.gsub(/Test$/, '').constantize
55 min = options[:greater_than] || (options[:in] && options[:in].first) || 0
56 max = options[:less_than] || (options[:in] && options[:in].last) || (1.0/0)
57 range = (min..max)
58 matcher = validate_attachment_size(name).in(range)
59 should matcher.description do
60 assert_accepts(matcher, klass)
61 end
62 end
63 end
64end
65
66class Test::Unit::TestCase #:nodoc:
67 extend Paperclip::Shoulda
68end