Rspec - respond_to “user post” valid despite user is not valid (has_many/belongs_to association)?

The user does respond to posts, it just returns an empty array. Try this in a rails console.

The user does respond to posts, it just returns an empty array. Try this in a rails console: > @user = User. New > @user.

Posts => A better test may be: @user.posts. Should be_empty Honestly testing rails relationships is not usually recommended as you are essentially testing rails it self which is already very well tested. However, shoulda provides some nice matchers that work in rspec to check that relationships are set up correctly: it {should have_many(:posts)} Check it out on github: https://github.Com/thoughtbot/shoulda.

Thanks I tried to test without the before(:each) block and I get the following error: Failure/Error: @user. Should respond_to(:posts) expected nil to respond to :posts. Giving me the understanding.

I'll get a look at shoulda. Thank you! – benoitr Mar 19 at 17:29.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions