DEV Community

Di Wu
Di Wu

Posted on

Rails Minitest Has Many And Belongs To Model Test ActiveRecord::UnknownPrimaryKey Error

When I try to run minitest with simpleCov, I want the join table model UserMessages to be covered.

I have setup fixture, to run test and keep getting an ActiveRecord::UnknownPrimaryKey error. This is expected since I don't have a primary key on the UserMessage table.

Is there a way to…

Top comments (5)

Collapse
 
rhymes profile image
rhymes

I don't think this has much to do with minitest, it has more to do with Rails fixtures.

You need explicit IDs if you want HABTM relations to work with those: api.rubyonrails.org/classes/Active...

Hope I understood correctly and that this helps!

Collapse
 
captainawesomedi profile image
Di Wu

I figured it out myself, I dont need fixture to do it.

Collapse
 
rhymes profile image
rhymes

Good!

You might want to share the solution, for future readers :)

Thread Thread
 
captainawesomedi profile image
Di Wu

I have posted on stackoverflow haha

Collapse
 
devdrake0 profile image
Si

Please don't just post a link to Stack Overflow, at least provide a summary.