Files
nairobi/spec/models/site_customization/image_spec.rb
Javi Martín 8b13daad95 Add and apply rules for multi-line hashes
For the HashAlignment rule, we're using the default `key` style (keys
are aligned and values aren't) instead of the `table` style (both keys
and values are aligned) because, even if we used both in the
application, we used the `key` style a lot more. Furthermore, the
`table` style looks strange in places where there are both very long and
very short keys and sometimes we weren't even consistent with the
`table` style, aligning some keys without aligning other keys.

Ideally we could align hashes to "either key or table", so developers
can decide whether keeping the symmetry of the code is worth it in a
case-per-case basis, but Rubocop doesn't allow this option.
2023-08-18 14:56:16 +02:00

62 lines
2.0 KiB
Ruby

require "rails_helper"
describe SiteCustomization::Image do
it "stores images with Active Storage" do
image = create(:site_customization_image, name: "map",
image: fixture_file_upload("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: fixture_file_upload("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: fixture_file_upload("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: fixture_file_upload("logo_email_custom.png"))
expect(image).not_to be_valid
end
it "dynamically validates the valid images" do
stub_const("#{SiteCustomization::Image}::VALID_IMAGES", { "custom" => [223, 80] })
custom = build(:site_customization_image, name: "custom", image: fixture_file_upload("logo_header.png"))
expect(custom).to be_valid
map = build(:site_customization_image, name: "map", image: fixture_file_upload("custom_map.jpg"))
expect(map).not_to be_valid
end
end
it "dynamically validates the valid mime types" do
stub_const("#{SiteCustomization::Image}::VALID_MIME_TYPES", ["image/gif"])
gif = build(:site_customization_image,
name: "logo_header",
image: fixture_file_upload("logo_header.gif"))
expect(gif).to be_valid
png = build(:site_customization_image,
name: "logo_header",
image: fixture_file_upload("logo_header.png"))
expect(png).not_to be_valid
end
end