Move form field partial to a component

This way it's easier to test; changing it will also be easier.

During my experiments I made a mistake which wasn't covered by the test
suite. We're adding a test for this case.

Note we're using `i18n_content` in the component instead of `content`
because there's already a `content` method provided by ViewComponent.
This commit is contained in:
Javi Martín
2021-10-05 19:05:05 +02:00
parent ced55a58f8
commit b35c8bda4b
6 changed files with 43 additions and 18 deletions

View File

@@ -0,0 +1,14 @@
require "rails_helper"
describe Admin::SiteCustomization::InformationTexts::FormFieldComponent do
after { I18n.backend.reload! }
it "uses the I18n translation when the record exists without a database translation" do
I18n.backend.store_translations(:en, { testing: "It works!" })
content = I18nContent.create!(key: "testing")
render_inline Admin::SiteCustomization::InformationTexts::FormFieldComponent.new(content, locale: :en)
expect(page).to have_field with: "It works!"
end
end