Keep invalid translation params through requests
We were reloading the values from the database and ignoring the parameters sent by the browser.
This commit is contained in:
@@ -22,7 +22,7 @@ module TranslatableFormHelper
|
||||
def translatable_fields(&block)
|
||||
@object.globalize_locales.map do |locale|
|
||||
Globalize.with_locale(locale) do
|
||||
fields_for(:translations, @object.translations.where(locale: locale).first_or_initialize, builder: TranslationsFieldsBuilder) do |translations_form|
|
||||
fields_for(:translations, translation_for(locale), builder: TranslationsFieldsBuilder) do |translations_form|
|
||||
@template.concat translations_form.hidden_field(
|
||||
:_destroy,
|
||||
value: !@template.enable_locale?(@object, locale),
|
||||
@@ -37,6 +37,19 @@ module TranslatableFormHelper
|
||||
end.join.html_safe
|
||||
end
|
||||
|
||||
def translation_for(locale)
|
||||
existing_translation_for(locale) || new_translation_for(locale)
|
||||
end
|
||||
|
||||
def existing_translation_for(locale)
|
||||
# Use `select` because `where` uses the database and so ignores
|
||||
# the `params` sent by the browser
|
||||
@object.translations.select { |translation| translation.locale == locale }.first
|
||||
end
|
||||
|
||||
def new_translation_for(locale)
|
||||
@object.translations.new(locale: locale)
|
||||
end
|
||||
end
|
||||
|
||||
class TranslationsFieldsBuilder < FoundationRailsHelper::FormBuilder
|
||||
|
||||
@@ -95,7 +95,9 @@ shared_examples "translatable" do |factory_name, path_name, fields|
|
||||
|
||||
expect(page).to have_css "#error_explanation"
|
||||
|
||||
# TODO: check the field is now blank.
|
||||
click_link "Español"
|
||||
|
||||
expect(page).to have_field(field_for(field, :es), with: "")
|
||||
end
|
||||
|
||||
scenario "Remove a translation", :js do
|
||||
|
||||
Reference in New Issue
Block a user