diff options
Diffstat (limited to 'vendor/plugins/paperclip/test/matchers')
4 files changed, 122 insertions, 0 deletions
diff --git a/vendor/plugins/paperclip/test/matchers/have_attached_file_matcher_test.rb b/vendor/plugins/paperclip/test/matchers/have_attached_file_matcher_test.rb new file mode 100644 index 00000000..b29ec372 --- /dev/null +++ b/vendor/plugins/paperclip/test/matchers/have_attached_file_matcher_test.rb | |||
| @@ -0,0 +1,21 @@ | |||
| 1 | require 'test/helper' | ||
| 2 | |||
| 3 | class HaveAttachedFileMatcherTest < Test::Unit::TestCase | ||
| 4 | context "have_attached_file" do | ||
| 5 | setup do | ||
| 6 | @dummy_class = reset_class "Dummy" | ||
| 7 | reset_table "dummies" | ||
| 8 | @matcher = self.class.have_attached_file(:avatar) | ||
| 9 | end | ||
| 10 | |||
| 11 | should "reject a class with no attachment" do | ||
| 12 | assert_rejects @matcher, @dummy_class | ||
| 13 | end | ||
| 14 | |||
| 15 | should "accept a class with an attachment" do | ||
| 16 | modify_table("dummies"){|d| d.string :avatar_file_name } | ||
| 17 | @dummy_class.has_attached_file :avatar | ||
| 18 | assert_accepts @matcher, @dummy_class | ||
| 19 | end | ||
| 20 | end | ||
| 21 | end | ||
diff --git a/vendor/plugins/paperclip/test/matchers/validate_attachment_content_type_matcher_test.rb b/vendor/plugins/paperclip/test/matchers/validate_attachment_content_type_matcher_test.rb new file mode 100644 index 00000000..241eb5f1 --- /dev/null +++ b/vendor/plugins/paperclip/test/matchers/validate_attachment_content_type_matcher_test.rb | |||
| @@ -0,0 +1,30 @@ | |||
| 1 | require 'test/helper' | ||
| 2 | |||
| 3 | class ValidateAttachmentContentTypeMatcherTest < Test::Unit::TestCase | ||
| 4 | context "validate_attachment_content_type" do | ||
| 5 | setup do | ||
| 6 | reset_table("dummies") do |d| | ||
| 7 | d.string :avatar_file_name | ||
| 8 | end | ||
| 9 | @dummy_class = reset_class "Dummy" | ||
| 10 | @dummy_class.has_attached_file :avatar | ||
| 11 | @matcher = self.class.validate_attachment_content_type(:avatar). | ||
| 12 | allowing(%w(image/png image/jpeg)). | ||
| 13 | rejecting(%w(audio/mp3 application/octet-stream)) | ||
| 14 | end | ||
| 15 | |||
| 16 | should "reject a class with no validation" do | ||
| 17 | assert_rejects @matcher, @dummy_class | ||
| 18 | end | ||
| 19 | |||
| 20 | should "reject a class with a validation that doesn't match" do | ||
| 21 | @dummy_class.validates_attachment_content_type :avatar, :content_type => %r{audio/.*} | ||
| 22 | assert_rejects @matcher, @dummy_class | ||
| 23 | end | ||
| 24 | |||
| 25 | should "accept a class with a validation" do | ||
| 26 | @dummy_class.validates_attachment_content_type :avatar, :content_type => %r{image/.*} | ||
| 27 | assert_accepts @matcher, @dummy_class | ||
| 28 | end | ||
| 29 | end | ||
| 30 | end | ||
diff --git a/vendor/plugins/paperclip/test/matchers/validate_attachment_presence_matcher_test.rb b/vendor/plugins/paperclip/test/matchers/validate_attachment_presence_matcher_test.rb new file mode 100644 index 00000000..860a7604 --- /dev/null +++ b/vendor/plugins/paperclip/test/matchers/validate_attachment_presence_matcher_test.rb | |||
| @@ -0,0 +1,21 @@ | |||
| 1 | require 'test/helper' | ||
| 2 | |||
| 3 | class ValidateAttachmentPresenceMatcherTest < Test::Unit::TestCase | ||
| 4 | context "validate_attachment_presence" do | ||
| 5 | setup do | ||
| 6 | reset_table("dummies"){|d| d.string :avatar_file_name } | ||
| 7 | @dummy_class = reset_class "Dummy" | ||
| 8 | @dummy_class.has_attached_file :avatar | ||
| 9 | @matcher = self.class.validate_attachment_presence(:avatar) | ||
| 10 | end | ||
| 11 | |||
| 12 | should "reject a class with no validation" do | ||
| 13 | assert_rejects @matcher, @dummy_class | ||
| 14 | end | ||
| 15 | |||
| 16 | should "accept a class with a validation" do | ||
| 17 | @dummy_class.validates_attachment_presence :avatar | ||
| 18 | assert_accepts @matcher, @dummy_class | ||
| 19 | end | ||
| 20 | end | ||
| 21 | end | ||
diff --git a/vendor/plugins/paperclip/test/matchers/validate_attachment_size_matcher_test.rb b/vendor/plugins/paperclip/test/matchers/validate_attachment_size_matcher_test.rb new file mode 100644 index 00000000..7e4c9b40 --- /dev/null +++ b/vendor/plugins/paperclip/test/matchers/validate_attachment_size_matcher_test.rb | |||
| @@ -0,0 +1,50 @@ | |||
| 1 | require 'test/helper' | ||
| 2 | |||
| 3 | class ValidateAttachmentSizeMatcherTest < Test::Unit::TestCase | ||
| 4 | context "validate_attachment_size" do | ||
| 5 | setup do | ||
| 6 | reset_table("dummies") do |d| | ||
| 7 | d.string :avatar_file_name | ||
| 8 | end | ||
| 9 | @dummy_class = reset_class "Dummy" | ||
| 10 | @dummy_class.has_attached_file :avatar | ||
| 11 | end | ||
| 12 | |||
| 13 | context "of limited size" do | ||
| 14 | setup{ @matcher = self.class.validate_attachment_size(:avatar).in(256..1024) } | ||
| 15 | |||
| 16 | should "reject a class with no validation" do | ||
| 17 | assert_rejects @matcher, @dummy_class | ||
| 18 | end | ||
| 19 | |||
| 20 | should "reject a class with a validation that's too high" do | ||
| 21 | @dummy_class.validates_attachment_size :avatar, :in => 256..2048 | ||
| 22 | assert_rejects @matcher, @dummy_class | ||
| 23 | end | ||
| 24 | |||
| 25 | should "reject a class with a validation that's too low" do | ||
| 26 | @dummy_class.validates_attachment_size :avatar, :in => 0..1024 | ||
| 27 | assert_rejects @matcher, @dummy_class | ||
| 28 | end | ||
| 29 | |||
| 30 | should "accept a class with a validation that matches" do | ||
| 31 | @dummy_class.validates_attachment_size :avatar, :in => 256..1024 | ||
| 32 | assert_accepts @matcher, @dummy_class | ||
| 33 | end | ||
| 34 | end | ||
| 35 | |||
| 36 | context "validates_attachment_size with infinite range" do | ||
| 37 | setup{ @matcher = self.class.validate_attachment_size(:avatar) } | ||
| 38 | |||
| 39 | should "accept a class with an upper limit" do | ||
| 40 | @dummy_class.validates_attachment_size :avatar, :less_than => 1 | ||
| 41 | assert_accepts @matcher, @dummy_class | ||
| 42 | end | ||
| 43 | |||
| 44 | should "accept a class with no upper limit" do | ||
| 45 | @dummy_class.validates_attachment_size :avatar, :greater_than => 1 | ||
| 46 | assert_accepts @matcher, @dummy_class | ||
| 47 | end | ||
| 48 | end | ||
| 49 | end | ||
| 50 | end | ||
