raj
raj

Reputation: 6094

Rails fixtures entries can be invalid?

I have a Hunt model where I validate it with

validates :title,:clue, :user_id,presence: true

My understanding of fixtures is that , the entries would be saved to the database so it needs to be valid. But in my fixtures , I have

one:
  title: MyString
  user: raj

which is not valid. But it works without any errors.

If it is saved to the database, shouldnt it fail when it validates? Or is this the intended behaiour and validations are not run?

Upvotes: 2

Views: 926

Answers (1)

Igor Springer
Igor Springer

Reputation: 496

The data in fixtures does not have to pass model validation before it is loaded into database.

As a side note, fixtures are generally considered as not the best way of testing. A better, commonly used alternative for build-in are factories (I recommend Factory Bot).

I advise to ignore fixtures from the beginning and go straight to factories.

Upvotes: -1

Related Questions