require 'rails_helper' module Logistics module Core RSpec.describe AdditionalDocument, type: :model do let(:dt1) { create(:document_type) } let(:dt2) { create(:document_type) } let(:dt3) { create(:document_type) } let(:dt4) { create(:document_type) } it 'has a valid factory' do expect(create(:additional_document)).to be_valid end it 'treats lookups as documentable' do cc = create(:client_category) am = create(:acquisition_mode) create(:additional_document, documentable: cc, document_type: dt1) create(:additional_document, documentable: cc, document_type: dt2) create(:additional_document, documentable: am, document_type: dt3) create(:additional_document, documentable: am, document_type: dt4) cc_documents = AdditionalDocument.where(documentable_id: cc.id, documentable_type: 'Logistics::Core::Lookup') expect(cc_documents.count).to eq 2 expect(am.additional_documents.count).to eq 2 end end end end