Reload path for sluggable models

Sluggable models can update the slug when updating new translations,
so we make sure the path is correct before using it.
This commit is contained in:
Julian Herrero
2019-01-19 15:45:37 +01:00
parent 938d5eba43
commit 2eb2839ab0

View File

@@ -12,6 +12,7 @@ shared_examples "translatable" do |factory_name, path_name, input_fields, textar
let(:input_fields) { input_fields } # So it's accessible by methods let(:input_fields) { input_fields } # So it's accessible by methods
let(:textarea_fields) { textarea_fields } # So it's accessible by methods let(:textarea_fields) { textarea_fields } # So it's accessible by methods
let(:path_name) { path_name } # So it's accessible by methods
let(:fields) { input_fields + textarea_fields.keys } let(:fields) { input_fields + textarea_fields.keys }
@@ -136,6 +137,7 @@ shared_examples "translatable" do |factory_name, path_name, input_fields, textar
expect(page).not_to have_css "#error_explanation" expect(page).not_to have_css "#error_explanation"
expect(page).not_to have_link "English" expect(page).not_to have_link "English"
path = updated_path_for(translatable)
visit path visit path
expect(page).not_to have_link "English" expect(page).not_to have_link "English"
@@ -257,6 +259,10 @@ shared_examples "translatable" do |factory_name, path_name, input_fields, textar
end end
end end
def updated_path_for(resource)
send(path_name, *resource_hierarchy_for(resource.reload))
end
def text_for(field, locale) def text_for(field, locale)
I18n.with_locale(locale) do I18n.with_locale(locale) do
"#{translatable_class.human_attribute_name(field)} #{language_texts[locale]}" "#{translatable_class.human_attribute_name(field)} #{language_texts[locale]}"