validate_presence_of matcher doesn't seem to respect conditions #100

Open
ekampp opened this Issue May 8, 2013 · 4 comments

Comments

Projects
None yet
5 participants

ekampp commented May 8, 2013

Contextual validations seems to be failing. I'm uncertain if this is an issue with rspec or with the way that the validate_presence_of method is implemented.

Here is my test in rspec

describe "contextual validation" do
  context "article is not published" do
    before { subject.stub(:published?) { false } }
    it { should_not validate_presence_of(:publish_at) }
  end
  context "article is published" do
    before { subject.stub(:published?) { true } }
    it { should validate_presence_of(:publish_at) }
  end
end

Here is the validation on the model:

validates :publish_at, presence: true, if: :published?

Can anybody else replicate this?

Replicated. Reverted to using 'errors_on' method and testing both a valid and invalid model.

rodrigopinto was assigned Jan 18, 2014

rodrigopinto was unassigned by ekampp Aug 11, 2014

Owner

rodrigopinto commented Oct 3, 2014

@ekampp Do you still have this error?

For me, this bug is still present.

90yukke self-assigned this Mar 18, 2015

ekampp commented Mar 18, 2015

I haven't seen any fix for this, no.

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