Denis Papushaev
Denis Papushaev

Reputation: 205

Test that associated model exists

A user has one profile. The profile was created after creating the user. How can I test that the profile exists using rspec?

let(:user) { FactoryGirl.create(:student) }
subject { user }
it { is_expected.to be_valid }
it { is_expected.to (#profile exist))   # I don't know what goes here

Upvotes: 0

Views: 65

Answers (1)

Arup Rakshit
Arup Rakshit

Reputation: 118271

You probably can't write it in one line. Here is my thought -

let(:user) { FactoryGirl.create(:student) }
subject { user }
it { is_expected.to be_valid }
expect(user.profile).to be_present

Upvotes: 1

Related Questions