-
Notifications
You must be signed in to change notification settings - Fork 16
Open
Description
Summary
Add linting and/or tests that promote the addition of validation to Slice models.
Motivation
Templates that depend upon data which may not be available is a common source of errors in Slices.
For example, consider FooSlice
:
# app/slices/foo/foo_slice.rb
class FooSlice < Slice
field :bar, type: String
end
<!-- app/slices/foo/views/show.html.erb -->
<p><%= bar.upcase %></p>
If bar
is nil
(which it will be by default) this will raise a NoMethodError
and the entire page will fail to render.
Rather than introduce null checking to templates, we would prefer to enforce these dependencies at the slice-model level:
# app/slices/foo/foo_slice.rb
class FooSlice < Slice
field :bar, type: String
validates :bar, presence: true
end
This enforces consistency at a lower level and prevents both full blown render failures and incorrect renders.
Metadata
Metadata
Assignees
Labels
No labels