Closed denisse-dev closed 6 years ago
Thanks to thelp of Igor Drozdov I was able to figure out what was wrong (in case someone gets to this Issue with the same problem).
I defined my associations with:
association :sender_account, factory: :account, strategy: :build
association :recipient_account, factory: :account, strategy: :build
When the strategy was not needed as it didn't save the accounts and therefore the tests were failing.
I have a
User
model thathas_many
accounts, eachAccount
belongs_to
one user andhas_many
transactions, eachTransactions
to two different accounts (sender_account
andrecipient_account
), the originalbelongs_to
method that adds the factory (likeaccount
) will not work since I need asender_account
andrecipient_account
.If I manually set the ID with
sender_account 1
and runrpsec
I get:Even when the ID's are stored as
Integer
.How can I add an association when my model
belongs_to
to different instances of the same model? I already have my Account and User factory defined and they work as expected.