Files
nairobi/spec/components/application_component_spec.rb
Javi Martín 669472c800 Sanitize the output of a dummy component class
After commit 52ec5094f, we started to get a warning when running out
test suite:

```
WARNING: The #<Class:0x00007958c06fb8e0> component rendered HTML-unsafe
output. The output will be automatically escaped, but you may want to
investigate.
```

The reason is that, for security reasons, since version 3.9.0,
ViewComponent no longer renders unsafe output in the `call` method, so
we need to make sure the rendered text is safe. This is similar to what
Rails automatically does in views with `<%= %>`.

While this change doesn't affect the application (this class is only
used in a test), with it we avoid the warning.
2024-03-19 14:54:06 +01:00

22 lines
466 B
Ruby

require "rails_helper"
describe ApplicationComponent do
it "uses custom translations if present" do
I18nContent.update([{ id: "shared.yes", values: { "value_en" => "Affirmative" }}])
component_class = Class.new(ApplicationComponent) do
def call
sanitize(t("shared.yes"))
end
def self.name
""
end
end
render_inline component_class.new
expect(page).to be_rendered with: "<p>Affirmative</p>"
end
end