From 5b4b37032c248a48687306ad764ee75c0d8f9a40 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Bellet Date: Thu, 10 Aug 2023 15:22:35 +0200 Subject: [PATCH] Add translation for invalid URL in white label context --- app/models/enterprise.rb | 2 +- config/locales/en.yml | 3 +++ spec/system/admin/enterprises_spec.rb | 14 ++++++++++++++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/app/models/enterprise.rb b/app/models/enterprise.rb index b65738c189..8a2c559eff 100644 --- a/app/models/enterprise.rb +++ b/app/models/enterprise.rb @@ -453,7 +453,7 @@ class Enterprise < ApplicationRecord uri = URI(white_label_logo_link) self.white_label_logo_link = "http://#{white_label_logo_link}" if uri.scheme.nil? rescue URI::InvalidURIError - errors.add(:white_label_logo_link, I18n.t(:invalid_url)) + errors.add(:white_label_logo_link, I18n.t(:invalid_url, url: white_label_logo_link)) end def image_url_for(image, name) diff --git a/config/locales/en.yml b/config/locales/en.yml index f41990576f..31814bee2c 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -90,6 +90,8 @@ en: preferred_discount_amount: "Calculator Discount Amount:" preferred_unit_from_list: "Calculator Unit From List:" preferred_per_unit: "Calculator Per Unit:" + enterprise: + white_label_logo_link: "Link for the logo used in shopfront" errors: models: enterprise_fee: @@ -3174,6 +3176,7 @@ See the %{link} to find out more about %{sitename}'s features and to start using amount: "Amount" invoice_number: "Invoice Number" invoice_file: "File" + invalid_url: "'%{url}' is an invalid URL" state_names: ready: Ready pending: Pending diff --git a/spec/system/admin/enterprises_spec.rb b/spec/system/admin/enterprises_spec.rb index 339898e673..c07c006595 100644 --- a/spec/system/admin/enterprises_spec.rb +++ b/spec/system/admin/enterprises_spec.rb @@ -716,6 +716,20 @@ describe ' it_behaves_like "edit link with", "www.openfoodnetwork.org", "http://www.openfoodnetwork.org" it_behaves_like "edit link with", "openfoodnetwork.org", "http://openfoodnetwork.org" end + + shared_examples "edit link with invalid" do |url| + it "url: #{url}" do + fill_in "enterprise_white_label_logo_link", with: url + click_button 'Update' + expect(page) + .to have_content "Link for the logo used in shopfront '#{url}' is an invalid URL" + expect(distributor1.reload.white_label_logo_link).to be_nil + end + end + + context "can not edit white label logo link" do + it_behaves_like "edit link with invalid", "invalid url" + end end it "can check/uncheck the hide_groups_tab attribute" do