rails/rails — pull request #13665 by jdelStrother (2014-01-10 13:06:01+00:00)
Title:  RecordInvalid rollback is ignored when creating via has_many

I have an after_save hook that raises RecordInvalid if the record's associations aren't compatible. If the record is created via a has_many association, then the RecordInvalid exception is swallowed somewhere and doesn't cause the save to fail.

I was struggling to figure out a fix, but here's a failing test case demonstrating the problem.

The same problem also occurs via `has_many :through` - eg with Post->Tagging->Tag, `post.tags.create` would succeed even if Tag raises RecordInvalid in its after_save hook.

Interestingly, if you replace `topic.replies.create` with `topic.replies.build.save`, then the rollback works as expected.