Skip to content

Commit

Permalink
413 User avatar upload validation error (#420)
Browse files Browse the repository at this point in the history
* Fix avatarable form render after validation error

* Add system tests for avatar upload

* Update registration system test to match avatarable_form
  • Loading branch information
jmilljr24 authored Jan 9, 2024
1 parent 7261dc0 commit 6c37310
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 4 deletions.
6 changes: 2 additions & 4 deletions app/views/partials/_avatarable_form.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<% if resource.avatar.attached? %>
<% if resource.avatar.id %>
<div class='form-group mt-3'>
<label class="form-label">
Current picture
Expand All @@ -9,7 +9,6 @@
<% elsif picture_shape == 'rectangle' %>
<%= image_tag resource.avatar, class: 'rounded-1', style: 'max-height:7.5rem;max-width:100%' %>
<% end %>

<%= link_to t('general.delete'),
purge_attachment_path(resource.avatar.id),
data: { turbo_method: "delete" },
Expand All @@ -21,6 +20,5 @@
<%= form.file_field :append_avatar,
class: "custom-attachments",
label: 'Attach picture' %>

</div>
<% end %>
<% end %>
Binary file added test/fixtures/files/blank.pdf
Binary file not shown.
37 changes: 37 additions & 0 deletions test/system/registration_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
require "application_system_test_case"

class RegistrationTest < ApplicationSystemTestCase
setup do
@user = create(:user, :verified_staff)
@organization = @user.organization
set_organization(@organization)

visit root_url
click_on "Log In"

fill_in "Email", with: @user.email
fill_in "Password", with: @user.password
click_on "Log in"
visit edit_user_registration_path
end

context "when uploading avatar" do
should "return error for invalid file type/size" do
attach_file("Attach picture", Rails.root + "test/fixtures/files/blank.pdf")
fill_in "Current password", with: @user.password
click_on "Update"

alert = first("div.alert")

assert !alert.nil?
end

should "direct to home index path with valid upload" do
attach_file("Attach picture", Rails.root + "test/fixtures/files/test.png")
fill_in "Current password", with: @user.password
click_on "Update"

assert_equal current_path, home_index_path
end
end
end

0 comments on commit 6c37310

Please sign in to comment.