stephenmurdoch
stephenmurdoch

Reputation: 34603

Rspec: testing the identity of a relation with 'its'

The following spec ensures that a Project has a User:

it "requires a user" do
  expect(FactoryGirl.build_stubbed(:project, user_id: nil)).to_not be_valid
end

But for some reason I feel compelled to do the following too:

context "user identity" do
  let(:temp) { FactoryGirl.build_stubbed(:user) }
  subject(:project) { FactoryGirl.build_stubbed(:project, user: temp) }
  its(:user){ should == temp }
end

I know I need the first test, but I'm beginning to wonder if the second one is a waste of time, especially since the association is handled by the controller:

@project = current_user.projects.build

Is the second test pointless? Seems like it's just testing my factory more than anything.

Upvotes: 0

Views: 45

Answers (1)

gotva
gotva

Reputation: 5998

Is the second test pointless? Seems like it's just testing my factory more than anything.

I think it is not necessary to test. You test has_many and belongs_to relations from core of Rails.

Upvotes: 1

Related Questions