diff --git a/test/attachment_test.rb b/test/attachment_test.rb index b602b70..db9d149 100644 --- a/test/attachment_test.rb +++ b/test/attachment_test.rb @@ -134,6 +134,19 @@ class AttachmentTest < Test::Unit::TestCase @attachment.assign(@file) assert_equal "file.png", @attachment.path end + + context "fast upload via nginx" do + should "return the right extension for the path" do + Tempfile.create do |tempfile| + content = "file contents" + tempfile.write(content) + upload = { 'original_name' => 'foo.jpg', 'content_type' => 'application/jpg', 'filepath' => tempfile.tap(&:rewind).path } + @attachment.assign(upload) + assert_equal "foo.png", @attachment.path + assert_equal content, @attachment.queued_for_write[:original].tap(&:rewind).read + end + end + end end context "An attachment with both 'normal' and hash-style styles" do diff --git a/test/matchers/have_attached_file_matcher_test.rb b/test/matchers/have_attached_file_matcher_test.rb index ad1a279..9d80a0d 100644 --- a/test/matchers/have_attached_file_matcher_test.rb +++ b/test/matchers/have_attached_file_matcher_test.rb @@ -19,5 +19,11 @@ class HaveAttachedFileMatcherTest < Test::Unit::TestCase @dummy_class.has_attached_file :avatar assert_accepts @matcher, @dummy_class end + + should "have messages" do + assert_equal "have an attachment named avatar", @matcher.description + assert_equal "Should have an attachment named avatar", @matcher.failure_message + assert_equal "Should not have an attachment named avatar", @matcher.negative_failure_message + end end end diff --git a/test/matchers/validate_attachment_content_type_matcher_test.rb b/test/matchers/validate_attachment_content_type_matcher_test.rb index b12dd4e..ff9f8f2 100644 --- a/test/matchers/validate_attachment_content_type_matcher_test.rb +++ b/test/matchers/validate_attachment_content_type_matcher_test.rb @@ -26,5 +26,11 @@ class ValidateAttachmentContentTypeMatcherTest < Test::Unit::TestCase @dummy_class.validates_attachment_content_type :avatar, :content_type => %r{image/.*} assert_accepts @matcher, @dummy_class end + + should "have messages" do + assert_equal "validate the content types allowed on attachment avatar", @matcher.description + assert_equal "Content types image/png, image/jpeg should be accepted and audio/mp3, application/octet-stream rejected by avatar", @matcher.failure_message + assert_equal "Content types image/png, image/jpeg should be rejected and audio/mp3, application/octet-stream accepted by avatar", @matcher.negative_failure_message + end end end diff --git a/test/matchers/validate_attachment_presence_matcher_test.rb b/test/matchers/validate_attachment_presence_matcher_test.rb index 450253c..c7bb1c6 100644 --- a/test/matchers/validate_attachment_presence_matcher_test.rb +++ b/test/matchers/validate_attachment_presence_matcher_test.rb @@ -17,5 +17,11 @@ class ValidateAttachmentPresenceMatcherTest < Test::Unit::TestCase @dummy_class.validates_attachment_presence :avatar assert_accepts @matcher, @dummy_class end + + should "have messages" do + assert_equal "require presence of attachment avatar", @matcher.description + assert_equal "Attachment avatar should be required", @matcher.failure_message + assert_equal "Attachment avatar should not be required", @matcher.negative_failure_message + end end end diff --git a/test/matchers/validate_attachment_size_matcher_test.rb b/test/matchers/validate_attachment_size_matcher_test.rb index 75bf1bb..5668635 100644 --- a/test/matchers/validate_attachment_size_matcher_test.rb +++ b/test/matchers/validate_attachment_size_matcher_test.rb @@ -31,6 +31,12 @@ class ValidateAttachmentSizeMatcherTest < Test::Unit::TestCase @dummy_class.validates_attachment_size :avatar, :in => 256..1024 assert_accepts @matcher, @dummy_class end + + should "have messages" do + assert_equal "validate the size of attachment avatar", @matcher.description + assert_equal "Attachment avatar must be between 256 and 1024 bytes", @matcher.failure_message + assert_equal "Attachment avatar cannot be between 256 and 1024 bytes", @matcher.negative_failure_message + end end context "validates_attachment_size with infinite range" do