Skip to content

Commit

Permalink
fix organization logo validation (#720)
Browse files Browse the repository at this point in the history
  • Loading branch information
nflorentin authored Dec 8, 2023
1 parent 87139a2 commit 5d56ea6
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
4 changes: 3 additions & 1 deletion app/models/organization.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ class Organization < ApplicationRecord
has_many :petitions, dependent: :delete_all

validates :name, presence: true, uniqueness: true
validates :logo, content_type: /\Aimage\/.*\z/

LOGO_CONTENT_TYPES = %w(image/jpeg image/png image/gif)
validates :logo, content_type: LOGO_CONTENT_TYPES

before_validation :ensure_url
after_create :create_account
Expand Down
2 changes: 1 addition & 1 deletion app/views/organizations/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@
<%= f.input :address %>
<%= f.input :neighborhood %>
<%= f.input :city %>
<%= f.input :logo, input_html: { accept: "image/*" } %>
<%= f.input :logo, input_html: { accept: Organization::LOGO_CONTENT_TYPES.join(',') } %>
<%= f.button :submit %>
<% end %>
5 changes: 5 additions & 0 deletions spec/models/organization_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@

expect(organization).to be_invalid

temp_file = Tempfile.new('test.svg')
organization.logo.attach(io: File.open(temp_file.path), filename: 'test.svg')

expect(organization).to be_invalid

temp_file = Tempfile.new('test.png')
organization.logo.attach(io: File.open(temp_file.path), filename: 'test.png')

Expand Down

0 comments on commit 5d56ea6

Please sign in to comment.