title: Conditional allow_nil part of validation
body: <p>Writing a floating attribute validation, I stumbled upon a case where I always want to validate numericality, but only allow_nil in certain cases.</p>
  
  <p>Right now my solution is to generally allow_nil, but then write a separate presence validation.</p>
  
  <pre><code>validates :price, numericality: { greater_than: 0 }, allow_nil: true
  validates :price, presence: true,
    if: Proc.new { |v| v.voting.fan_priced? }
  </code></pre>
  
  <p>This works, but doesn't seem clean. Ideally, I would like something like this (kind of pseudo code):</p>
  
  <pre><code>validates :price, numericality: { greater_than: 0 },
    allow_nil: Proc.new { |v| v.voting.fan_priced? ? false : true }
  </code></pre>
  
  <p>But this obviously doesn't work.</p>
  
  <p>Is there any way to do this more efficiently? I also found <a href="https://stackoverflow.com/questions/11922154/rails-model-validation-conditional-allow-nil">this here on SO</a>, but this seems rather similar, using two separate validations for the same thing, essentially.</p>
  
  <p><strong>PS:</strong> Somehow, the proc in my validation is messing up my shoulda matchers. Simple stuff like</p>
  
  <pre><code>it { should_not allow_value(0).for(:user_id) }
  </code></pre>
  
  <p>in the same model now gives me</p>
  
  <pre><code>undefined method `fan_priced?' for nil:NilClass
  </code></pre>
  
  <p>Can't the shoulda matchers handle associations in procs?</p>