Every time CleanupInvitationsJob runs (it currently is scheduled daily), the daily invitations limit for all users is set to the currently configured one.

The limit is configured in application.rb, in the daily_invitations_limit config value.

This enables us to change the configured limit and, after a restart, the next time the job runs this limit will be updated for all users. This enables changing the limit without manually making changes in the database.

This limit is ignored for admin users, who can send an unlimited number of invitations.
Minor change (name of test context).
When saving a user, if no invitation_limit has been set, it is set to the value currently configured in application.rb.

This means that a newly saved user has his invitation_limit set to the currently configured value.
Added index to Users table on the invitation_limit column.

This should speed up searching for users who need their invitation_limit attribute updated every time CleanupInvitationsJob runs.
Added "invitations_count_reset_at" datetime column to Users table.

It will store the last time the daily invitations count was reset for a given user, if ever.
Formatting changed (indentation).
Every time CleanupInvitationsJob runs, the daily invitations count for each user is reset to zero.

This completes the daily invitation limit feature. Previous commits had set limits to prevent a user from sending an invitation if all his invites had been used. This commits adds a daily reset to zero of the invitations count, which means that the invitations limit for each user is actually a daily limit.

Logic has been added to ensure that the count is not reset before one day has passed, regardless of how many times the job runs (because of deployments etc). This is necessary because otherwise users could have the count reset multiple times a day, which would result in the limit not being enforced. Also users that have their current invitations count at zero (they sent no invitations during the last day) are ignored, for performance reasons.
Added index to Users table on invitations_count, invitations_count_reset_at fields.

It should speed up selecting users who need their daily invitations count reset to zero every time CleanupInvitationsJob runs.