Today I learned
Read about some cool stuff.
FactoryBot aliases and foreign keys
May 06, 2024

By default, FactoryBot assumes that {attribute}_id is the foreign key for ActiveRecord associations, which can lead to errors in other parts of your application that may be difficult to diagnose.

let!(:dog) {
  create(
    name: "Azor",
    tag: "Azor 000 000 000",
    tag_id: "#12",
  )
}

Dog.last.tag # nil
Dog.last.tag_id # nil

Since this is a common naming convention, it's better to avoid names like this and use more straightforward alternatives. For example tag_number.

More information here

ul. Powstańców Warszawy 5
15-129 Białystok
+48 668 842 999
CONTACT US