I usually check if my test returns the expected result like this:
company = company_fixture() # inserts a company in the database with default attributes
assert Profile.get_company!(company.id) == company
But this fails
Assertion with == failed
code: assert Profile.get_company!(company.id) == company
left: %MyApp.Profile.Company{
customers: [],
employees: [],
# more attributes, all matching
}
right: %Databaum.Profile.Company{
customers: #Ecto.Association.NotLoaded<association :customers is not loaded>,
employees: #Ecto.Association.NotLoaded<association :employees is not loaded>,
# more attributes, all matching
}
What is the recommended way of handling that? I want to obviously avoid preloading the associations in the test because that would avoid checking the fact that they are not preloaded in Profile.get_company!/1
.
I am afraid that your assert also fails because you are dealing with different structs. You could simply iterate through your struct and remove the fields with have
%Ecto.Association.NotLoaded{}
as value and then also remove those fields from your first struct, then assert both are equal, like this: