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.
This commit is contained in:
Javi Martín
2018-10-08 14:44:21 +02:00
committed by decabeza
parent a8f8a7bc4f
commit 5e6dfe6ed8
2 changed files with 25 additions and 1 deletions

View File

@@ -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)

View File

@@ -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?