You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Mar 15, 2021. It is now read-only.
with ActiveRecord, suppose I have a Book model and an Author model and
class Book < ActiveRecord::Base
has_many :authors, through: :books_authors
end
class Author < ActiveRecord::Base
has_many :books, through: :books_authors
end
And the requirement is that a book has to have at least an author, therefore in my book fabricator, I have
Fabricator(:book) do
authors! { Fabricate(:author) }
end
In my cucumber test, I want to be able to say
Given 1 book
And that book has the following author:
| name | John Doe |
.....
Currently if I do this the book will have two authors, one created with the book fabricator and John Doe. I'd like to be able to only have John Doe has the author for the book.
The text was updated successfully, but these errors were encountered:
I don't think authors are "on top of" books in this example - they "have many through" each other. But agree with you that coming from the other direction would solve this problem.
The base fabricator should never build things that aren't necessary to persist the object. You should make a :book_with_author fabricator for when you need them together. This will reduce the "magic" in your test suite and make cucumber work a lot better.
with ActiveRecord, suppose I have a Book model and an Author model and
class Book < ActiveRecord::Base
has_many :authors, through: :books_authors
end
class Author < ActiveRecord::Base
has_many :books, through: :books_authors
end
And the requirement is that a book has to have at least an author, therefore in my book fabricator, I have
Fabricator(:book) do
authors! { Fabricate(:author) }
end
In my cucumber test, I want to be able to say
Given 1 book
And that book has the following author:
| name | John Doe |
.....
Currently if I do this the book will have two authors, one created with the book fabricator and John Doe. I'd like to be able to only have John Doe has the author for the book.
The text was updated successfully, but these errors were encountered: