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?