From 5e6dfe6ed889462d7385f84d63bacce77c7ed556 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Mon, 8 Oct 2018 14:44:21 +0200 Subject: [PATCH] Disable removed translations After removing a translation while editing another one with invalid data and sending the form, we were displaying the removed translation to the user. We now remove that translation from the form, but we don't remove it from the database until the form has been sent without errors. --- app/helpers/globalize_helper.rb | 2 +- spec/shared/features/translatable.rb | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/app/helpers/globalize_helper.rb b/app/helpers/globalize_helper.rb index c6170260a..15ad85da5 100644 --- a/app/helpers/globalize_helper.rb +++ b/app/helpers/globalize_helper.rb @@ -25,7 +25,7 @@ module GlobalizeHelper def enable_locale?(resource, locale) # Use `map` instead of `pluck` in order to keep the `params` sent # by the browser when there's invalid data - resource.translations.map(&:locale).include?(locale) || locale == I18n.locale + resource.translations.reject(&:_destroy).map(&:locale).include?(locale) || locale == I18n.locale end def highlight_current?(locale) diff --git a/spec/shared/features/translatable.rb b/spec/shared/features/translatable.rb index 4c7144511..edec51356 100644 --- a/spec/shared/features/translatable.rb +++ b/spec/shared/features/translatable.rb @@ -131,6 +131,30 @@ shared_examples "translatable" do |factory_name, path_name, fields| expect(page).not_to have_link "Español" end + scenario "Remove a translation with invalid data", :js do + skip("can't have invalid translations") if required_fields.empty? + + field = required_fields.sample + + visit path + + click_link "Español" + click_link "Remove language" + + click_link "English" + fill_in field_for(field, :en), with: "" + click_button update_button_text + + expect(page).to have_css "#error_explanation" + expect(page).to have_field(field_for(field, :en), with: "") + expect(page).not_to have_link "Español" + + visit path + click_link "Español" + + expect(page).to have_field(field_for(field, :es), with: text_for(field, :es)) + end + scenario 'Change value of a translated field to blank', :js do skip("can't have translatable blank fields") if optional_fields.empty?