{"action":"opened","issue":{"url":"https://api.github.com/repos/withassociates/slices/issues/79","labels_url":"https://api.github.com/repos/withassociates/slices/issues/79/labels{/name}","comments_url":"https://api.github.com/repos/withassociates/slices/issues/79/comments","events_url":"https://api.github.com/repos/withassociates/slices/issues/79/events","html_url":"https://github.com/withassociates/slices/issues/79","id":62660061,"number":79,"title":"[RFC] Slice Linting","user":{"login":"jgwhite","id":34030,"avatar_url":"https://avatars.githubusercontent.com/u/34030?v=3","gravatar_id":"","url":"https://api.github.com/users/jgwhite","html_url":"https://github.com/jgwhite","followers_url":"https://api.github.com/users/jgwhite/followers","following_url":"https://api.github.com/users/jgwhite/following{/other_user}","gists_url":"https://api.github.com/users/jgwhite/gists{/gist_id}","starred_url":"https://api.github.com/users/jgwhite/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jgwhite/subscriptions","organizations_url":"https://api.github.com/users/jgwhite/orgs","repos_url":"https://api.github.com/users/jgwhite/repos","events_url":"https://api.github.com/users/jgwhite/events{/privacy}","received_events_url":"https://api.github.com/users/jgwhite/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2015-03-18T10:59:18Z","updated_at":"2015-03-18T10:59:18Z","closed_at":null,"body":"### Summary\r\n\r\nAdd linting and/or tests that promote the addition of validation to Slice models.\r\n\r\n### Motivation\r\n\r\nTemplates that depend upon data which may not be available is a common source of errors in Slices.\r\n\r\nFor example, consider `FooSlice`:\r\n\r\n```rb\r\n# app/slices/foo/foo_slice.rb\r\n\r\nclass FooSlice < Slice\r\n  field :bar, type: String\r\nend\r\n```\r\n\r\n```erb\r\n<!-- app/slices/foo/views/show.html.erb -->\r\n\r\n<p><%= bar.upcase %></p>\r\n```\r\n\r\nIf `bar` is `nil` (which it will be by default) this will raise a `NoMethodError` and the entire page will fail to render.\r\n\r\nRather than introduce null checking to templates, we would prefer to enforce these dependencies at the slice-model level:\r\n\r\n```rb\r\n# app/slices/foo/foo_slice.rb\r\n\r\nclass FooSlice < Slice\r\n  field :bar, type: String\r\n  validates :bar, presence: true\r\nend\r\n```\r\n\r\nThis enforces consistency at a lower level and prevents both full blown render failures and incorrect renders."}}