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

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

Closed
mejibyte opened this issue Jul 11, 2012 · 8 comments

Comments

@mejibyte
Copy link

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?

@calebhearth
Copy link

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

@mejibyte
Copy link
Author

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

@calebhearth
Copy link

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

@jsmestad
Copy link

Would love to have this

@gabebw
Copy link

gabebw commented Aug 16, 2012

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.

calebhearth added a commit to calebhearth/shoulda-matchers that referenced this issue Aug 18, 2012
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.
@kitop
Copy link

kitop commented Dec 15, 2012

It would be really great to see something like this.

@brodock
Copy link

brodock commented Mar 10, 2013

+1 on this too

@drapergeek
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants