In FactoryBot, getting error: 'Stack Level too deep' when creating a HABTM association

Viewed 129

I am trying to set up a HABTM association between two models, Master and Genre. Each attempt from suggestions in the documentation and from stackoverflow give the error SystemStackError: stack level too deep

The factories are defined as follows:

  factory :master do
    title        { 'Master title' }
    release_type { 'Album' }

    artist
    contributor
   end

And

  factory :genre do
    name { 'Blues' }

    master
  end

I have tried various examples of adding the HABTM relationship in the master factory but all return the 'stack level too deep' error.

These include

genres { create_list(:genre, 5) }

genres { [association(:genre)] }

transient do
  genres_count { 2 }
end

after(:create) do |master, evaluator|
 create_list(:genre, evaluator.genres_count, masters: [master])
end

If I don't include one of the above examples in the master factory the tests run fine but fail where multiple genres are expected to belong to a master, as expected. When they are included, each test taks 3 minutes to run and fails with the above described error.

Any suggestions would be greatly appreciated

0 Answers
Related