Correct way of testing “associations” with Rspec?

I usually use this approach:

describe User do
  it "should have many teams" do
    t = User.reflect_on_association(:teams)
    expect(t.macro).to eq(:has_many)
  end
end

A better solution would be to use the gem shoulda which will allow you to simply:

describe Team do
  it { should belong_to(:user) }
end

Leave a Comment