Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add support for validating multiple attributes at once #1651

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Commits on Sep 13, 2024

  1. feat: Add support for validating multiple attributes at once

    This commit adds support for validating multiple attributes at once with
    `validate_presence_of`. This is useful when you want to ensure that
    multiple attributes are required.
    
    ```ruby
    class Example
      include ActiveModel::Model
    
      attr_accessor :attr1, :attr2
    
      validates_presence_of :attr1, :attr2
    end
    
    RSpec.describe Example do
      it do
        expect(subject).to validate_presence_of(:attr1, :attr2)
      end
    end
    ```
    
    We also add support for using qualifiers with multiple attributes.
    There's two caveats: if you use a qualifier, it will apply to all
    attributes and only the first failure will be reported.
    
    ```ruby
    class Example
      include ActiveModel::Model
    
      attr_accessor :attr1, :attr2
    
      validates_presence_of :attr1, allow_nil: true
      validates_presence_of :attr2, allow_nil: true
    end
    
    RSpec.describe Example do
      it do
        expect(subject).to validate_presence_of(:attr1, :attr2)
      end
    end
    
    ```
    matsales28 committed Sep 13, 2024
    Configuration menu
    Copy the full SHA
    22c7f16 View commit details
    Browse the repository at this point in the history