{"action":"created","issue":{"url":"https://api.github.com/repos/thoughtbot/ex_machina/issues/33","labels_url":"https://api.github.com/repos/thoughtbot/ex_machina/issues/33/labels{/name}","comments_url":"https://api.github.com/repos/thoughtbot/ex_machina/issues/33/comments","events_url":"https://api.github.com/repos/thoughtbot/ex_machina/issues/33/events","html_url":"https://github.com/thoughtbot/ex_machina/issues/33","id":110499981,"number":33,"title":"Add ExMachina.with/1","user":{"login":"paulcsmith","id":22394,"avatar_url":"https://avatars.githubusercontent.com/u/22394?v=3","gravatar_id":"","url":"https://api.github.com/users/paulcsmith","html_url":"https://github.com/paulcsmith","followers_url":"https://api.github.com/users/paulcsmith/followers","following_url":"https://api.github.com/users/paulcsmith/following{/other_user}","gists_url":"https://api.github.com/users/paulcsmith/gists{/gist_id}","starred_url":"https://api.github.com/users/paulcsmith/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/paulcsmith/subscriptions","organizations_url":"https://api.github.com/users/paulcsmith/orgs","repos_url":"https://api.github.com/users/paulcsmith/repos","events_url":"https://api.github.com/users/paulcsmith/events{/privacy}","received_events_url":"https://api.github.com/users/paulcsmith/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":4,"created_at":"2015-10-08T17:07:57Z","updated_at":"2015-10-09T21:00:46Z","closed_at":null,"body":"Recently I had to create a lot of events that all had the same `user_id`\r\n\r\n```elixir\r\nuser_id = 123\r\ncreate(:event, name: \"cancelled\", user_id: user_id)\r\ncreate(:event, name: \"started exercise\", user_id: user_id)\r\ncreate(:event, name: \"finished exercise\", user_id: user_id)\r\n```\r\n\r\nI think it would be nice to have a function that allows you do to something like this\r\n\r\n```elixir\r\nExMachina.with(user_id: user_id) do\r\n    create(:event, name: \"cancelled\")\r\n    create(:event, name: \"started exercise\")\r\nend\r\n```\r\n\r\nI'm not exactly sure how this would work, or if this is the syntax/naming we want, but I think we could come up with something"},"comment":{"url":"https://api.github.com/repos/thoughtbot/ex_machina/issues/comments/146985025","html_url":"https://github.com/thoughtbot/ex_machina/issues/33#issuecomment-146985025","issue_url":"https://api.github.com/repos/thoughtbot/ex_machina/issues/33","id":146985025,"user":{"login":"henrik","id":216,"avatar_url":"https://avatars.githubusercontent.com/u/216?v=3","gravatar_id":"","url":"https://api.github.com/users/henrik","html_url":"https://github.com/henrik","followers_url":"https://api.github.com/users/henrik/followers","following_url":"https://api.github.com/users/henrik/following{/other_user}","gists_url":"https://api.github.com/users/henrik/gists{/gist_id}","starred_url":"https://api.github.com/users/henrik/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/henrik/subscriptions","organizations_url":"https://api.github.com/users/henrik/orgs","repos_url":"https://api.github.com/users/henrik/repos","events_url":"https://api.github.com/users/henrik/events{/privacy}","received_events_url":"https://api.github.com/users/henrik/received_events","type":"User","site_admin":false},"created_at":"2015-10-09T21:00:46Z","updated_at":"2015-10-09T21:00:46Z","body":"If it's a common use case for a single attribute to vary, one could even do this:\r\n\r\n``` elixir\r\n  def example do\r\n    user_event = curry(:create, :event, :name, user: 123)\r\n\r\n    user_event.(\"started\")\r\n    user_event.(\"finished\")\r\n  end\r\n\r\n  def curry(action, model, attribute_name, defaults) do\r\n    fn (attribute_value) ->\r\n      full_attrs = Keyword.merge(defaults, [{attribute_name, attribute_value}])\r\n      apply(__MODULE__, action, [model, full_attrs])\r\n    end\r\n  end\r\n```"}}