Search code examples
ruby-on-railsminitest

testing join record creation


A method for creating a user, has a consequential method for creating a join table record

  if @user.save
    @roleshopuser = Rolehopuser.create(user_id: @user.id, shop_id: @site.shop_id, role_id: params[:role_id])  

However, when testing this method, teh test hits an error

NameError: uninitialized constant UsersController::Rolehopuser

The parent model defines

  accepts_nested_attributes_for :roleshopusers

and the method works in the applications normal processing.

How can this test be written to allow the creation of a join table record?


Solution

  • You should need to edit the variable @roleshopuser where 's' is missing.

    @roleshopuser = Roleshopuser.create(user_id: @user.id, shop_id: @site.shop_id, role_id: params[:role_id])