How/where to test entities that belong to an aggregate root?

Hi all,

I’m making an app that deals with a Book as an aggregate root. A book will have many chapters. Thus we’re looking at two models: Book and Chapter.

I will only ever access these chapters through the root (the book). Thus, book.chapter.some_method and never chapter.some_method.

What are the Rails idioms for testing this sort of thing? Would all of my tests be in book_test.rb or should I make book_test.rb and chapter_test.rb files? If the latter, what sort of tests would I put in one vs the other?

Thanks!

Place all tests related to chapter behavior inside book_test.rb, since chapters are accessed exclusively through the Book aggregate root. This aligns with your design where Chapter is conceptually a part of Book. Avoid creating a separate chapter_test.rb unless Chapter has standalone logic or methods unrelated to the Book aggregate.

Keep tests for chapters in book_test.rb if chapters are strictly accessed through the Book aggregate root. This keeps the focus on the behavior of the aggregate as a whole. Test chapter-related methods via the Book model, e.g., book.chapter.some_method.