3
votes

I got a problem when i testing validations in rails with mongoid This is for example my Person Model and my Rspec test.

class Person
    include Mongoid::Document

    validates :first_name , :presence => true
    validates :last_name , :presence => true

end



 [ :last_name, :first_name ].each do |attr|
  it "must have a #{attr}" do
    p = Person.new
    p.send("#{attr}=","")
    p.should_not be_valid
    p.errors[attr].should == [ "can't be blank" ] 
  end
end

But this tests fail because the return value is ["can't be blank", "can't be blank"]

  expected: ["can't be blank"]
        got: ["can't be blank", "can't be blank"]

Why are 2 Errors in this record?? i test this issue with many models and other validation rules. I got everytime the same result

Thx for help

Eric

1

1 Answers

0
votes

It's because you're setting one of your fields to empty string and the other retains default value of nil. That's why both of your validations fail each time.