Skip to content

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.

2 participants