Skip to content

More, clearer, isolated tests describing how the relationship resolvers work #33

@christophersansone

Description

@christophersansone

While buiding #32, I took a deep dive into the relationships and how the different options relate to one another. I discovered a handful of issues, mostly around the lack of clarity of how all the options relate to one another.

Here are some examples. In these cases, can anyone tell me with certainty what should happen? Which serializer is used? What is the type outputted in the relationships hash? What is the type outputted in the included hash?

belongs_to :account

has_many :accounts

belongs_to :account, record_type: :employee_account

belongs_to :account, serializer: :employee_account

belongs_to :account, record_type: :user_account, serializer: :employee_account

belongs_to :account, serializer: EmployeeAccountSerializer

belongs_to :account, polymorphic: true

belongs_to :account, polymorphic: true, record_type: :employee_account

Other questions:

  • What happens if the relationship defines a record_type that is different from what is defined by the serializer's set_type? Does it output two different types? Does one take precedence over the other?

  • What happens if the id_method_name is defined on the relationship? How does it relate to the set_id method of the serializer? Do they conflict with one another if they are both set differently? Does one take precedence over the other?

I honestly don't think anyone can say with certainty how all of these scenarios actually work. And I think the actual results would be surprising. This is partly because there is some overlap in the API, and partly because we don't have the specs that describe the behavior in a concise way. We have some good test coverage, just not very specific, isolated, targeted tests to describe this behavior, to make sure it works as designed, and to prevent future changes from breaking the behavior.

Doing this exercise will also help us to identify areas of overlap and help refine the API.

I can take a shot at this after #32 is merged. That PR implements a couple changes / bug fixes to the record_type behavior. Without it, we would have several tests failing until it is merged.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions