Skip to content

Commit 5d56ea6

Browse files
authored
fix organization logo validation (#720)
1 parent 87139a2 commit 5d56ea6

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed

app/models/organization.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ class Organization < ApplicationRecord
2626
has_many :petitions, dependent: :delete_all
2727

2828
validates :name, presence: true, uniqueness: true
29-
validates :logo, content_type: /\Aimage\/.*\z/
29+
30+
LOGO_CONTENT_TYPES = %w(image/jpeg image/png image/gif)
31+
validates :logo, content_type: LOGO_CONTENT_TYPES
3032

3133
before_validation :ensure_url
3234
after_create :create_account

app/views/organizations/_form.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@
99
<%= f.input :address %>
1010
<%= f.input :neighborhood %>
1111
<%= f.input :city %>
12-
<%= f.input :logo, input_html: { accept: "image/*" } %>
12+
<%= f.input :logo, input_html: { accept: Organization::LOGO_CONTENT_TYPES.join(',') } %>
1313
<%= f.button :submit %>
1414
<% end %>

spec/models/organization_spec.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@
88

99
expect(organization).to be_invalid
1010

11+
temp_file = Tempfile.new('test.svg')
12+
organization.logo.attach(io: File.open(temp_file.path), filename: 'test.svg')
13+
14+
expect(organization).to be_invalid
15+
1116
temp_file = Tempfile.new('test.png')
1217
organization.logo.attach(io: File.open(temp_file.path), filename: 'test.png')
1318

0 commit comments

Comments
 (0)