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

Conversation

matsales28
Copy link
Member

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.

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.

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 matsales28 force-pushed the mus-add-matcher-collection-feature branch from 696f08e to 8fd0a26 Compare September 13, 2024 14:57
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 matsales28 force-pushed the mus-add-matcher-collection-feature branch from 8fd0a26 to 22c7f16 Compare September 13, 2024 16:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant