1kplus/reader — pull request #22 by chrishunt (2013-06-01 04:31:15+00:00)
Title: Only set email if it's provided

Devise added a `not-null` constraint, with a default of `""`, on the email column in [`e9c5acd4`](https://github.com/1kplus/reader/blob/e9c5acd465111567fe14db686a5eddb621db774e/db/migrate/20120309055454_devise_create_users.rb#L5)

This default value is not used if we set the email before saving, even if we set it `nil`. Which means that PostgreSQL will still blow up if we manually set the email to `nil` and try to save:

```
PG::Error: ERROR: null value in column "email" violates not-null constraint
```

In [`users_controller#50`](https://github.com/1kplus/reader/blob/e9c5acd465111567fe14db686a5eddb621db774e/app/controllers/users_controller.rb#L50) the user email is being set to `nil` and causing [`oauth_spec`](https://github.com/1kplus/reader/blob/e9c5acd465111567fe14db686a5eddb621db774e/spec/features/oauth_spec.rb#L3) to fail when we [try to save](https://github.com/1kplus/reader/blob/e9c5acd465111567fe14db686a5eddb621db774e/app/controllers/users_controller.rb#L64)

We can fix this by only setting the email if an email is provided so that the column default is used and the exception isn't raised.