require 'rails_helper' module CustomerVault RSpec.describe Person, :type => :model do describe '#links' do let(:c) {FactoryGirl.create(:customer_vault_corporation)} let(:c2) {FactoryGirl.create(:customer_vault_corporation)} let(:i) {FactoryGirl.create(:customer_vault_individual)} let(:i2) {FactoryGirl.create(:customer_vault_individual)} before :each do @l1 = FactoryGirl.create(:customer_vault_link, alice: c, bob: c2, title: 'h') @l2 = FactoryGirl.create(:customer_vault_link, alice: i, bob: c, title: 'm') @l3 = FactoryGirl.create(:customer_vault_link, alice: i2, bob: i, title: 'p') end describe 'corporations' do it 'should return all links wether its alice or bob' do expect(c.links).to include({title: 'h', person: c2, origin: @l1}) expect(c.links).to include({title: 'm', person: i, origin: @l2}) expect(c2.links).to eq [{title: 'h', person: c, origin: @l1}] end end describe 'individuals' do it 'should return all links wether its alice or bob' do expect(i.links).to include({title: 'm', person: c, origin: @l2}) expect(i.links).to include({title: 'p', person: i2, origin: @l3}) expect(i2.links).to eq [{title: 'p', person: i, origin: @l3}] end end end end end