Rails conditional validation not working correctly
<p>I'm trying to setup a conditional validation, and whether or not the method I pass to it returns <code>true</code> or <code>false</code> the object will save. </p>

<p>When <code>test</code> returns <code>false</code>, I don't want the object to save</p>

<pre><code>class Foo &lt; ActiveRecord::Base
  belongs_to :order
  belongs_to :user

  validates :order, presence: true
  validates :user, presence: true, if: :test

  private

  def test
    false
  end
end
</code></pre>

<p>controller:</p>

<pre><code>def create
  foo = Foo.new(foo_params)

  if foo.save
    render json: delivery, status: 201
  else
    render json: { errors: foo }, status: 422
  end
end
</code></pre>