winston/rails_utils — pull request #11 by choonkeat (2014-12-01 06:34:14+00:00)
Title: Add proper "at_least_one" validation

- `marked_for_destruction` is needed to catch "accepts_nested_attributes_for allow_destroy: true"
- test isolates existence of `errors.keys` instead of worrying about entire model being valid (unnecessary fixture setup)
- detect for at least one `valid?` and `not marked_for_destruction?`

Sample

``` ruby
class Photo < ActiveRecord::Base
end

class Album < ActiveRecord::Base
has_many :photos
validates :photos, at_least_one: true
end
```

related https://github.com/rails/rails/issues/3961