{"action":"created","issue":{"url":"https://api.github.com/repos/alphagov/e-petitions/issues/59","labels_url":"https://api.github.com/repos/alphagov/e-petitions/issues/59/labels{/name}","comments_url":"https://api.github.com/repos/alphagov/e-petitions/issues/59/comments","events_url":"https://api.github.com/repos/alphagov/e-petitions/issues/59/events","html_url":"https://github.com/alphagov/e-petitions/pull/59","id":80918572,"number":59,"title":"Avoid short-circuiting ``valid?`` in Staged models","user":{"login":"h-lame","id":608,"avatar_url":"https://avatars.githubusercontent.com/u/608?v=3","gravatar_id":"","url":"https://api.github.com/users/h-lame","html_url":"https://github.com/h-lame","followers_url":"https://api.github.com/users/h-lame/followers","following_url":"https://api.github.com/users/h-lame/following{/other_user}","gists_url":"https://api.github.com/users/h-lame/gists{/gist_id}","starred_url":"https://api.github.com/users/h-lame/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/h-lame/subscriptions","organizations_url":"https://api.github.com/users/h-lame/orgs","repos_url":"https://api.github.com/users/h-lame/repos","events_url":"https://api.github.com/users/h-lame/events{/privacy}","received_events_url":"https://api.github.com/users/h-lame/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2015-05-26T11:22:49Z","updated_at":"2015-05-26T11:55:06Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/alphagov/e-petitions/pulls/59","html_url":"https://github.com/alphagov/e-petitions/pull/59","diff_url":"https://github.com/alphagov/e-petitions/pull/59.diff","patch_url":"https://github.com/alphagov/e-petitions/pull/59.patch"},"body":"In the classes where we have overridden ``valid?`` to also validate a child object (the ``HasCreatorSignature`` mixin and ``Sponsors`` model) we were doing:\r\n\r\n    def valid?\r\n      super && some_other_method_that_calls_valid_on_a_child_object\r\n    end\r\n\r\nThe problem here is that if ``super`` returned false we short-circuit the expression and don't run the other method and so don't validate the child object.  Instead we use ``validate`` to call the other method as part of the standard validation process.\r\n\r\nIn practice it wasn't a problem as I neither of the affected classes had any validations on the \"parent\" so ``super`` would never fail.  However it's not a good pattern to leave lying around."},"comment":{"url":"https://api.github.com/repos/alphagov/e-petitions/issues/comments/105498677","html_url":"https://github.com/alphagov/e-petitions/pull/59#issuecomment-105498677","issue_url":"https://api.github.com/repos/alphagov/e-petitions/issues/59","id":105498677,"user":{"login":"davidbasalla","id":5112255,"avatar_url":"https://avatars.githubusercontent.com/u/5112255?v=3","gravatar_id":"","url":"https://api.github.com/users/davidbasalla","html_url":"https://github.com/davidbasalla","followers_url":"https://api.github.com/users/davidbasalla/followers","following_url":"https://api.github.com/users/davidbasalla/following{/other_user}","gists_url":"https://api.github.com/users/davidbasalla/gists{/gist_id}","starred_url":"https://api.github.com/users/davidbasalla/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/davidbasalla/subscriptions","organizations_url":"https://api.github.com/users/davidbasalla/orgs","repos_url":"https://api.github.com/users/davidbasalla/repos","events_url":"https://api.github.com/users/davidbasalla/events{/privacy}","received_events_url":"https://api.github.com/users/davidbasalla/received_events","type":"User","site_admin":false},"created_at":"2015-05-26T11:55:06Z","updated_at":"2015-05-26T11:55:06Z","body":"Cool, good to know!"}}