{"action":"created","issue":{"url":"https://api.github.com/repos/jdickey/new_poc/issues/276","labels_url":"https://api.github.com/repos/jdickey/new_poc/issues/276/labels{/name}","comments_url":"https://api.github.com/repos/jdickey/new_poc/issues/276/comments","events_url":"https://api.github.com/repos/jdickey/new_poc/issues/276/events","html_url":"https://github.com/jdickey/new_poc/issues/276","id":76621903,"number":276,"title":"Clean up/rethink `UserPasswordEntityFactory`.","user":{"login":"jdickey","id":157938,"avatar_url":"https://avatars.githubusercontent.com/u/157938?v=3","gravatar_id":"","url":"https://api.github.com/users/jdickey","html_url":"https://github.com/jdickey","followers_url":"https://api.github.com/users/jdickey/followers","following_url":"https://api.github.com/users/jdickey/following{/other_user}","gists_url":"https://api.github.com/users/jdickey/gists{/gist_id}","starred_url":"https://api.github.com/users/jdickey/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jdickey/subscriptions","organizations_url":"https://api.github.com/users/jdickey/orgs","repos_url":"https://api.github.com/users/jdickey/repos","events_url":"https://api.github.com/users/jdickey/events{/privacy}","received_events_url":"https://api.github.com/users/jdickey/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/jdickey/new_poc/labels/duplicate","name":"duplicate","color":"cccccc"}],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-05-15T06:49:16Z","updated_at":"2015-05-18T16:36:23Z","closed_at":"2015-05-18T16:36:23Z","body":"Barrelling through adding Contracts to everything, we plough into `UserPasswordEntityFactory` and its specs and discover a pathologically split personality.\r\n\r\nThere's an [`Internals::add_passwords`](https://github.com/jdickey/new_poc/blob/af1ee52/app/entity_factories/user_password_entity_factory.rb#L8-L13) method, which has *eight* possible logic paths through four lines of source code. There's one fork on whether the `password` *parameter* is set, another on whether the `attributes[:password]` value is set, and yet a third on whether `attributes[:password_confirmation`] is set. \r\n\r\nThis class is used in nine different places in the specs (not counting the specs for the class itself), but only [once](https://github.com/jdickey/new_poc/blob/af1ee52/app/controllers/users_controller/action/create.rb#L63) in the app code &mdash; *where its explicit `password` parameter is set from the `attributes` hash!* :anguished:\r\n\r\nQuestions arise:\r\n\r\n1. If the only *production* use of the `password` parameter is extracted from *another parameter to the class' action method*, how much trouble would it be to ensure that use in the *specs* has password(s) set in the `attributes` Hash, eliminating the `password:` argument entirely? (8 logic paths become 4.)\r\n1. It seems reasonable to think of each of those four remaining logic paths as specifying one of three scenarios:\r\n  1. Both the `:password` and `:password_confirmation` attributes are set, in which case definition (or change) of the password for the user is being commanded;\r\n  1. Both the `:password` and `:password_confirmation` attributes are blank (`nil`), in which case no change to the currently set password is being commended;\r\n  1. Either but not both of the `:password` and `:password_confirmation` attributes is set, which is to be treated as an error condition.\r\n\r\nOnce we get to that point, `UserPasswordEntityFactory` should become a *lot* simpler, along with the supporting code."},"comment":{"url":"https://api.github.com/repos/jdickey/new_poc/issues/comments/103121092","html_url":"https://github.com/jdickey/new_poc/issues/276#issuecomment-103121092","issue_url":"https://api.github.com/repos/jdickey/new_poc/issues/276","id":103121092,"user":{"login":"jdickey","id":157938,"avatar_url":"https://avatars.githubusercontent.com/u/157938?v=3","gravatar_id":"","url":"https://api.github.com/users/jdickey","html_url":"https://github.com/jdickey","followers_url":"https://api.github.com/users/jdickey/followers","following_url":"https://api.github.com/users/jdickey/following{/other_user}","gists_url":"https://api.github.com/users/jdickey/gists{/gist_id}","starred_url":"https://api.github.com/users/jdickey/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jdickey/subscriptions","organizations_url":"https://api.github.com/users/jdickey/orgs","repos_url":"https://api.github.com/users/jdickey/repos","events_url":"https://api.github.com/users/jdickey/events{/privacy}","received_events_url":"https://api.github.com/users/jdickey/received_events","type":"User","site_admin":false},"created_at":"2015-05-18T16:36:23Z","updated_at":"2015-05-18T16:36:23Z","body":"Closing in favour of #203."}}