working on image feature
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
require "rails_helper"
|
||||
require "stringio"
|
||||
|
||||
RSpec.describe FuelEntry do
|
||||
it "has a valid factory" do
|
||||
@@ -57,4 +58,36 @@ RSpec.describe FuelEntry do
|
||||
|
||||
expect(entry).to be_valid
|
||||
end
|
||||
|
||||
it "accepts multiple JPEG or PNG images" do
|
||||
entry = build(:fuel_entry)
|
||||
entry.images.attach(image_attachment("receipt-one.png", "image/png"))
|
||||
entry.images.attach(image_attachment("receipt-two.jpg", "image/jpeg"))
|
||||
|
||||
expect(entry).to be_valid
|
||||
end
|
||||
|
||||
it "rejects non-JPEG and non-PNG images" do
|
||||
entry = build(:fuel_entry)
|
||||
entry.images.attach(io: StringIO.new("not an image"), filename: "receipt.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(:fuel_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