More tests

This commit is contained in:
Vasily Fedoseyev
2024-04-10 16:57:07 +03:00
parent 1c5237ecaf
commit e7ef0bf8a3
5 changed files with 37 additions and 0 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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