Fix updating translatables without current locale
The current locale wasn't being marked for destruction and so saving the record tried to create a new translation for the current locale.
This commit is contained in:
@@ -39,7 +39,9 @@ module TranslatableFormHelper
|
||||
|
||||
def new_translation_for(locale)
|
||||
@object.translations.new(locale: locale).tap do |translation|
|
||||
translation.mark_for_destruction unless locale == I18n.locale
|
||||
unless locale == I18n.locale && no_other_translations?(translation)
|
||||
translation.mark_for_destruction
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -50,6 +52,10 @@ module TranslatableFormHelper
|
||||
data: { locale: locale }
|
||||
}
|
||||
end
|
||||
|
||||
def no_other_translations?(translation)
|
||||
(@object.translations - [translation]).reject(&:_destroy).empty?
|
||||
end
|
||||
end
|
||||
|
||||
class TranslationsFieldsBuilder < FoundationRailsHelper::FormBuilder
|
||||
|
||||
@@ -119,6 +119,29 @@ shared_examples "translatable" do |factory_name, path_name, input_fields, textar
|
||||
expect_page_to_have_translatable_field field, :es, with: ""
|
||||
end
|
||||
|
||||
scenario "Update a translation not having the current locale", :js do
|
||||
translatable.translations.destroy_all
|
||||
|
||||
translatable.translations.create(
|
||||
fields.map { |field| [field, text_for(field, :fr)] }.to_h.merge(locale: :fr)
|
||||
)
|
||||
|
||||
visit path
|
||||
|
||||
expect(page).not_to have_link "English"
|
||||
expect(page).to have_link "Français"
|
||||
|
||||
click_button update_button_text
|
||||
|
||||
expect(page).not_to have_css "#error_explanation"
|
||||
expect(page).not_to have_link "English"
|
||||
|
||||
visit path
|
||||
|
||||
expect(page).not_to have_link "English"
|
||||
expect(page).to have_link "Français"
|
||||
end
|
||||
|
||||
scenario "Remove a translation", :js do
|
||||
visit path
|
||||
|
||||
|
||||
Reference in New Issue
Block a user