diff --git a/app/components/error/_error.html.erb b/app/components/error/_error.html.erb index 038793cff..8c1f8ac81 100644 --- a/app/components/error/_error.html.erb +++ b/app/components/error/_error.html.erb @@ -1,14 +1,14 @@ <% if properties[:object].errors.any? %> -
-
<%= pluralize(properties[:object].errors.count, "error") %> prohibited this <%= properties[:object].class.name %> from being saved
-
-
-
    - <% properties[:object].errors.full_messages.each do |message| %> -
  • <%= message %>
  • - <% end %> -
+
+
<%= pluralize(properties[:object].errors.count, "error") %> prohibited this <%= properties[:object].class.name %> from being saved
+
+
+
    + <% properties[:object].errors.full_messages.each do |message| %> +
  • <%= message %>
  • + <% end %> +
+
-
<% end %> diff --git a/app/controllers/admin/sites_controller.rb b/app/controllers/admin/sites_controller.rb index c7b5c202c..f3842deee 100644 --- a/app/controllers/admin/sites_controller.rb +++ b/app/controllers/admin/sites_controller.rb @@ -76,7 +76,7 @@ def destroy private def set_site - @site = Site.friendly.find(params[:id]) + @site ||= Site.friendly.find(params[:id]) end def set_variables_for_sites_neighbourhoods_selection diff --git a/app/views/admin/users/_form.html.erb b/app/views/admin/users/_form.html.erb index dc2b80d3b..87c229f4b 100644 --- a/app/views/admin/users/_form.html.erb +++ b/app/views/admin/users/_form.html.erb @@ -1,4 +1,4 @@ -<%= render_component "error", object: current_user %> +<%= render_component "error", object: f.object %>
<%= render "contact", f: f %> diff --git a/test/fixtures/files/bad-cat-picture.bmp b/test/fixtures/files/bad-cat-picture.bmp new file mode 100644 index 000000000..53d0f9fef Binary files /dev/null and b/test/fixtures/files/bad-cat-picture.bmp differ diff --git a/test/integration/admin/articles_integration_test.rb b/test/integration/admin/articles_integration_test.rb index e0608e6dc..82d6a2d7b 100644 --- a/test/integration/admin/articles_integration_test.rb +++ b/test/integration/admin/articles_integration_test.rb @@ -55,4 +55,53 @@ class Admin::ArticlesTest < ActionDispatch::IntegrationTest assert_select 'select#article_author_id option[selected="selected"]', @partner_admin.admin_name end + + test 'new article image upload problem feedback' do + sign_in @root + + new_article_params = { + title: 'a new article', + body: 'alpha beta cappa delta epsilon foxtrot etc', + author_id: @root.id, + article_image: fixture_file_upload("bad-cat-picture.bmp") + } + + post admin_articles_path, params: { article: new_article_params } + assert_not response.redirect? + + assert_select "h6", text: "1 error prohibited this Article from being saved" + + # top of page form error box + assert_select '#form-errors li', + text: "Article image You are not allowed to upload \"bmp\" files, allowed types: svg, jpg, jpeg, png" + + assert_select 'form .article_article_image .invalid-feedback', + text: "Article image You are not allowed to upload \"bmp\" files, allowed types: svg, jpg, jpeg, png" + end + + test 'update article image upload problem feedback' do + sign_in @root + + article = create(:article) + + article_params = { + title: article.title, + body: article.body, + author_id: article.author_id, + article_image: fixture_file_upload("bad-cat-picture.bmp") + } + + put admin_article_path(article), params: { article: article_params } + assert_not response.successful? + + assert_select "h6", text: "1 error prohibited this Article from being saved" + + # top of page form error box + assert_select '#form-errors li', + text: "Article image You are not allowed to upload \"bmp\" files, allowed types: svg, jpg, jpeg, png" + + assert_select 'form .article_article_image .invalid-feedback', + text: "Article image You are not allowed to upload \"bmp\" files, allowed types: svg, jpg, jpeg, png" + end + end diff --git a/test/integration/admin/partner_integration_test.rb b/test/integration/admin/partner_integration_test.rb index 4a2c492f1..6b7c87fe9 100644 --- a/test/integration/admin/partner_integration_test.rb +++ b/test/integration/admin/partner_integration_test.rb @@ -115,6 +115,47 @@ class PartnerIntegrationTest < ActionDispatch::IntegrationTest tag = tag_options.first assert tag.attributes.key?('selected') end + + test 'Partner create form gives feedback on bad image selection' do + new_partner_params = { + name: 'A partner', + address_attributes: { + street_address: @partner.address.street_address, + postcode: @partner.address.postcode + }, + image: fixture_file_upload("bad-cat-picture.bmp") + } + + sign_in @admin + post admin_partners_path, params: { partner: new_partner_params } + + assert_not response.redirect? + + assert_select "h6", text: "1 error prohibited this Partner from being saved" + assert_select '#form-errors li', text: "Image You are not allowed to upload \"bmp\" files, allowed types: jpg, jpeg, gif, png" + assert_select 'form .partner_image .invalid-feedback', text: "Image You are not allowed to upload \"bmp\" files, allowed types: jpg, jpeg, gif, png" + end + + test 'Partner update form gives feedback on bad image selection' do + partner_params = { + name: @partner.name, + address_attributes: { + street_address: @partner.address.street_address, + postcode: @partner.address.postcode + }, + image: fixture_file_upload("bad-cat-picture.bmp") + } + + sign_in @admin + put admin_partner_path(@partner), params: { partner: partner_params } + + assert_not response.redirect? + + assert_select "h6", text: "1 error prohibited this Partner from being saved" + assert_select '#form-errors li', text: "Image You are not allowed to upload \"bmp\" files, allowed types: jpg, jpeg, gif, png" + assert_select 'form .partner_image .invalid-feedback', text: "Image You are not allowed to upload \"bmp\" files, allowed types: jpg, jpeg, gif, png" + end + end # Capybara feature test that doesn't work and i have no time to fix diff --git a/test/integration/admin/sites_integration_test.rb b/test/integration/admin/sites_integration_test.rb index d49a7596c..2eb9f938e 100644 --- a/test/integration/admin/sites_integration_test.rb +++ b/test/integration/admin/sites_integration_test.rb @@ -110,4 +110,58 @@ class AdminSitesIntegrationTest < ActionDispatch::IntegrationTest tag = tag_options.first assert tag.attributes.key?('selected') end + + test 'new site image upload problem feedback' do + sign_in @root + + new_site_params = { + name: 'a new site', + domain: 'a-domain', + slug: 'a-slug', + logo: fixture_file_upload("bad-cat-picture.bmp"), + footer_logo: fixture_file_upload("bad-cat-picture.bmp"), + hero_image: fixture_file_upload("bad-cat-picture.bmp"), + } + + post admin_sites_path, params: { site: new_site_params } + assert_not response.successful? + + assert_select "h6", text: "3 errors prohibited this Site from being saved" + + # top of page form error box + assert_select '#form-errors li', text: "Logo You are not allowed to upload \"bmp\" files, allowed types: svg, png" + assert_select '#form-errors li', text: "Footer logo You are not allowed to upload \"bmp\" files, allowed types: svg, png" + assert_select '#form-errors li', text: "Hero image You are not allowed to upload \"bmp\" files, allowed types: jpg, jpeg, png" + + assert_select 'form .site_logo .invalid-feedback', text: "Logo You are not allowed to upload \"bmp\" files, allowed types: svg, png" + assert_select 'form .site_footer_logo .invalid-feedback', text: "Footer logo You are not allowed to upload \"bmp\" files, allowed types: svg, png" + assert_select 'form .site_hero_image .invalid-feedback', text: "Hero image You are not allowed to upload \"bmp\" files, allowed types: jpg, jpeg, png" + end + + test 'update site image upload problem feedback' do + sign_in @root + + site_params = { + name: 'a new site', + domain: 'a-domain', + slug: 'a-slug', + logo: fixture_file_upload("bad-cat-picture.bmp"), + footer_logo: fixture_file_upload("bad-cat-picture.bmp"), + hero_image: fixture_file_upload("bad-cat-picture.bmp"), + } + + put admin_site_path(@site), params: { site: site_params } + assert_not response.successful? + + assert_select "h6", text: "3 errors prohibited this Site from being saved" + + # top of page form error box + assert_select '#form-errors li', text: "Logo You are not allowed to upload \"bmp\" files, allowed types: svg, png" + assert_select '#form-errors li', text: "Footer logo You are not allowed to upload \"bmp\" files, allowed types: svg, png" + assert_select '#form-errors li', text: "Hero image You are not allowed to upload \"bmp\" files, allowed types: jpg, jpeg, png" + + assert_select 'form .site_logo .invalid-feedback', text: "Logo You are not allowed to upload \"bmp\" files, allowed types: svg, png" + assert_select 'form .site_footer_logo .invalid-feedback', text: "Footer logo You are not allowed to upload \"bmp\" files, allowed types: svg, png" + assert_select 'form .site_hero_image .invalid-feedback', text: "Hero image You are not allowed to upload \"bmp\" files, allowed types: jpg, jpeg, png" + end end diff --git a/test/integration/admin/user_integration_test.rb b/test/integration/admin/user_integration_test.rb index 7ca873911..1f8eb5029 100644 --- a/test/integration/admin/user_integration_test.rb +++ b/test/integration/admin/user_integration_test.rb @@ -236,4 +236,64 @@ class AdminUserIntegrationTest < ActionDispatch::IntegrationTest assert_select "p.has-no-admin-rights-warning" end + + test 'new user avatar upload problem feedback' do + sign_in @root + + new_user_params = { + email: 'user@example.com', + role: 'root', + avatar: fixture_file_upload("bad-cat-picture.bmp"), + } + + post admin_users_path, params: { user: new_user_params } + assert_not response.redirect? + + assert_select "h6", text: "1 error prohibited this User from being saved" + + # top of page form error box + assert_select '#form-errors li', text: "Avatar You are not allowed to upload \"bmp\" files, allowed types: jpg, jpeg, png" + + assert_select 'form .user_avatar .invalid-feedback', text: "Avatar You are not allowed to upload \"bmp\" files, allowed types: jpg, jpeg, png" + end + + test 'update user avatar upload problem feedback' do + sign_in @root + + user_params = { + email: @root.email, + role: @root.role, + avatar: fixture_file_upload("bad-cat-picture.bmp"), + } + + put admin_user_path(@root), params: { user: user_params } + assert_not response.redirect? + + assert_select "h6", text: "1 error prohibited this User from being saved" + + # top of page form error box + assert_select '#form-errors li', text: "Avatar You are not allowed to upload \"bmp\" files, allowed types: jpg, jpeg, png" + + assert_select 'form .user_avatar .invalid-feedback', text: "Avatar You are not allowed to upload \"bmp\" files, allowed types: jpg, jpeg, png" + end + + test 'update profile avatar upload problem feedback' do + sign_in @root + + user_params = { + email: @root.email, + avatar: fixture_file_upload("bad-cat-picture.bmp"), + } + + patch update_profile_admin_user_path(@root), params: { user: user_params } + assert_not response.redirect? + + assert_select "h6", text: "1 error prohibited this User from being saved" + + # top of page form error box + assert_select '#form-errors li', text: "Avatar You are not allowed to upload \"bmp\" files, allowed types: jpg, jpeg, png" + + assert_select 'form .user_avatar .invalid-feedback', text: "Avatar You are not allowed to upload \"bmp\" files, allowed types: jpg, jpeg, png" + end + end