Skip to content

fix organization logo validation #720

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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