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

Already on GitHub? Sign in to your account

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

Closed
andmej opened this Issue Jul 11, 2012 · 8 comments

Comments

Projects
None yet
7 participants

andmej commented Jul 11, 2012

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?

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 commented Jul 16, 2012

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

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

Would love to have this

Contributor

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.

@calebthompson calebthompson added a commit to calebthompson/shoulda-matchers that referenced this issue Aug 18, 2012

@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 commented Dec 15, 2012

It would be really great to see something like this.

brodock commented Mar 10, 2013

+1 on this too

Owner

drapergeek commented May 3, 2013

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

@drapergeek drapergeek closed this May 3, 2013

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