NoamB/sorcery — pull request #309 by pupeno (2012-06-13 16:51:11+00:00)
Title: Do not call save on the model when only a few attributes are being changed.

Hello Noam,

Sorry for the several pull requests. This one is the cleanest one so far. It works on top of master, and not a tag and **all the tests that passed before still pass now, including mongo_mapper**.

In our user model we have a couple of serialized attributes and Rails apparently always saves serialized attributes when calling save because it cannot keep track of whether they are dirty or not (I think). This meant that in many requests that used Sorcery, we end up doing a rather big update to a database. Also, we have some after filters that were unexpectedly run due to Sorcery calling save on the model.

We noticed this didn't always happen because some modules of Sorcery use update_single_attribute. We wrote a similar but more generic update_many_attributes and made sure it is used instead of save everywhere where it makes sense (it doesn't when changing the password or creating a new user).

We ran all the tests before and after this commit and we got the same amount of failures (everything passed but three oauth related tests). We also made sure we ran all the touched lines by manual testing from our application that is using Sorcery. **We run this code in production for a few weeks already**

We did this change pair-programming, @dmagliola and I.

Please, let me know if there are any changes you require to consider this commit.