Testing assembly builds using Rspec in Rails 3

I have the following line in my action of creating my controller teacher.

 @rating = @teacher.ratings.build(params[:rating]) unless params[:rating][:rating].blank?

I know that my associations are true, because this line correctly creates a new rating along with a new teacher, if the rating does not remain empty. However, I try to follow TDD, and I don't know how to check this line with rspec. I was a little confused.

I use a factory girl and should, if that helps.

+1
source share
1 answer

You can say something like:

teacher = Factory(:teacher)
rating = Factory(:rating, :teacher_id => teacher.id)
#your_other_actions_here
teacher.rating.should be present

(That is, if the rating belongs to the user.)

Btw, , Rails. , - .

+3

Source: https://habr.com/ru/post/1538728/


All Articles