working on image feature
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
require "rails_helper"
|
||||
require "stringio"
|
||||
|
||||
RSpec.describe MaintenanceEntry do
|
||||
it "has a valid factory" do
|
||||
@@ -50,4 +51,36 @@ RSpec.describe MaintenanceEntry do
|
||||
expect(unknown_entry).not_to be_valid
|
||||
expect(unknown_entry.errors[:name]).to be_present
|
||||
end
|
||||
|
||||
it "accepts multiple JPEG or PNG images" do
|
||||
entry = build(:maintenance_entry)
|
||||
entry.images.attach(image_attachment("service-one.png", "image/png"))
|
||||
entry.images.attach(image_attachment("service-two.jpg", "image/jpeg"))
|
||||
|
||||
expect(entry).to be_valid
|
||||
end
|
||||
|
||||
it "rejects non-JPEG and non-PNG images" do
|
||||
entry = build(:maintenance_entry)
|
||||
entry.images.attach(io: StringIO.new("not an image"), filename: "service.txt", content_type: "text/plain")
|
||||
|
||||
expect(entry).not_to be_valid
|
||||
expect(entry.errors[:images]).to include("must be JPEG or PNG")
|
||||
end
|
||||
|
||||
it "rejects images larger than 10 MB" do
|
||||
entry = build(:maintenance_entry)
|
||||
entry.images.attach(io: StringIO.new("a" * (10.megabytes + 1)), filename: "large.png", content_type: "image/png")
|
||||
|
||||
expect(entry).not_to be_valid
|
||||
expect(entry.errors[:images]).to include("must be 10 MB or smaller")
|
||||
end
|
||||
|
||||
def image_attachment(filename, content_type)
|
||||
{
|
||||
io: StringIO.new("image content for #{filename}"),
|
||||
filename: filename,
|
||||
content_type: content_type
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user