kristjan/mockr — pull request #2 by kristjan (2014-01-21 05:30:02+00:00)
Title: Create Organizations

@nuprin

This creates the `Organization` and `Membership` models, and methods on `User`
to manage them:

- `#join!(organization)`
- `#member?(organization)`
- `#admin?(organization)`

After signing up, a new user must create an organization (invite flow up
next). As long as a user doesn't have at least one organization, they'll be
redirected to create one.

I tried a couple things to create an `Organization` alongside a new user, but
`Devise` got in the way of redirecting to the organization create flow in the
event that creation failed while creating the user, and the `Membership` join
table made it cumbersome to pass through `Organization` data in nested
attributes for `User` to deal with. Having two separate flows is simpler, more
robust, and more flexible, so that's what we get for now. I'm relying on the
user-must-have-an-organization filter to start the flow after signup even though
the Devise redirects to root.

Upon creating a new `Organization` the creator is immediately assigned
administratorship over it.

So that controller specs will function the way we expect with minimal effort,
the `User` factory now creates an `Organization` as well and joins them to it.
If you want a user without an organization, use the `:unaffiliated_user`
factory.