Files
nairobi/spec/models/site_customization/image_spec.rb
Javi Martín 4f232c3a25 Use the file_fixture helper in tests
This way we don't have to write `"spec/fixtures/files"` every time.

Note this method isn't included in factories. We could include it like
so:

```
FactoryBot::SyntaxRunner.class_eval do
  include ActiveSupport::Testing::FileFixtures
  self.file_fixture_path = RSpec.configuration.file_fixture_path
end
```

However, I'm not sure about the possible side effects, and since we only
use attachments in a few factories, there isn't much gain in applying
the monkey-patch.
2022-02-23 18:43:48 +01:00

38 lines
1.1 KiB
Ruby

require "rails_helper"
describe SiteCustomization::Image do
it "stores images with Active Storage" do
image = create(:site_customization_image, name: "map",
image: File.new(file_fixture("custom_map.jpg")))
expect(image.image).to be_attached
expect(image.image.filename).to eq "custom_map.jpg"
end
describe "logo" do
it "is valid with a 260x80 image" do
image = build(:site_customization_image,
name: "logo_header",
image: File.new(file_fixture("logo_header-260x80.png")))
expect(image).to be_valid
end
it "is valid with a 223x80 image" do
image = build(:site_customization_image,
name: "logo_header",
image: File.new(file_fixture("logo_header.png")))
expect(image).to be_valid
end
it "is not valid with a 400x80 image" do
image = build(:site_customization_image,
name: "logo_header",
image: File.new(file_fixture("logo_email_custom.png")))
expect(image).not_to be_valid
end
end
end