vendredi 12 février 2016

Validation error while validating inclusion values:Rails

I am getting error while testing inclusion in my model validations.Here is my model.rb

class Resident < ActiveRecord::Base
  validates :room_number,presence: true,uniqueness: {case_sensitive: false}
  validates :roll_number,presence: true,uniqueness:{case_sensitive: false}
  validates :name, presence: true,length: { maximum: 50 }
  validates :hostel,presence: true,inclusion: {in:%w(a b c h pg j frc e g i),message: "%{value} is not a valid hostel"}
end

model_test.rb only inclusion test

 test "hostel must be valid" do
    if @resident.hostel == %w(a b c h pg j frc e g i)
      assert @resident.valid?
    else
      assert_not @resident.valid?
    end

and I am getting this error

     test_should_be_valid#ResidentTest (1455250549.01s)
        Failed assertion, no message given.
        test/models/resident_test.rb:9:in `block in <class:ResidentTest>'
8 tests, 8 assertions, 1 failures, 0 errors, 0 skips

How can I approach it.

Aucun commentaire:

Enregistrer un commentaire