Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Feature request: add .on(:create) and .on(:update) for model validation matchers #131

Closed
andmej opened this Issue · 8 comments

7 participants

@andmej

Hi,

I would love to see something like:

describe Monkey do
    it { should validate_presence_of(:banana).on(:create) }
    it { should_not validate_presence_of(:age).on(:update) }
end

What do you think? Would that be possible?

@calebthompson

Validation options for validates_presence_of:

  • message - A custom error message (default is: "can‘t be blank").
  • on - Specifies when this validation is active (default is :save, other options :create, :update).
  • if - Specifies a method, proc or string to call to determine if the validation should occur (e.g. :if => :allow_validation, or :if => Proc.new { |user| user.signup_step > 2 }). The method, proc or string should return or evaluate to a true or false value.
  • unless - Specifies a method, proc or string to call to determine if the validation should not occur (e.g. :unless => :skip_validation, or :unless => Proc.new { |user| user.signup_step <= 2 }). The method, proc or string should return or evaluate to a true or false value.
  • strict - Specifies whether validation should be strict.

https://github.com/rails/rails/blob/3-2-stable/activemodel/lib/active_model/validations/presence.rb

@andmej

@calebthompson, yes, those are the options for validates_presence_of. What's your point?

@calebthompson

I was planning to take a stab at this later, just wanted to have those as notes for myself.

@jsmestad

Would love to have this

@gabebw
Owner

I agree that this would be a nice feature. I'll look into this, but I'd make more time for a pull request implementing this.

@calebthompson calebthompson referenced this issue from a commit in calebthompson/shoulda-matchers
@calebthompson calebthompson [#131] Refactor validate_presence_of_matcher
I'll be adding a number of new options, so I'm refactoring to use options hash
so that all of the arguments can be stored in once place.
373b0d8
@kitop

It would be really great to see something like this.

@brodock

+1 on this too

@drapergeek
Owner

This was added in #246. We will be releasing a new version which includes it later today.

@drapergeek drapergeek closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.