require 'spec_helper' describe DigitalAssetLookupService do subject { FactoryGirl.build :digital_asset } context '#document-query' do before do asset1 = FactoryGirl.create :digital_asset, :product_ids => ['303','420'], :audiences => ['690'], :sami_code => 'F000000.BAR' doc1 = FactoryGirl.build :document, :content_type => '909', :path => '/1/foo/bar/foobar.doc' doc2 = FactoryGirl.build :document, :path => '/2/foo/bar/foobar.doc' asset1.documents << doc1 asset1.documents << doc2 asset1.save! asset2 = FactoryGirl.create :digital_asset, :product_ids => ['420'], :sami_code => 'MEH12345.000' doc3 = FactoryGirl.build :document, :content_type => '549', :path => '/1/foo/bar/FINRA-foobar.doc' asset2.documents << doc3 asset2.save! end it 'supports query by product_id' do query = {} DigitalAsset.where(query).should have(2).digital_asset query[:product_ids.in] = [] DigitalAsset.where(query).should have(0).digital_asset query[:product_ids.in] = ['303'] DigitalAsset.where(query).should have(1).digital_asset query[:product_ids.in] = ['303','420'] DigitalAsset.where(query).should have(2).digital_asset end it 'supports query by content_type_id' do query = {} query[:'documents.content_type'] = '' DigitalAsset.where(query).should have(0).digital_asset query[:'documents.content_type'] = '909' DigitalAsset.where(query).should have(1).digital_asset DigitalAssetLookupService.find_documents_by_query(nil, '909').should have(1).digital_asset end it 'supports query by product_id and content_type_id' do query = {} query[:'documents.content_type'] = '909' query[:product_ids.in] = ['303','420'] DigitalAsset.where(query).should have(1).digital_asset end it 'supports query by product_id and content_type_id and audiences' do query = {} query[:'documents.content_type'] = '909' query[:product_ids.in] = ['303','420'] query[:audiences.in] = ['690'] DigitalAsset.where(query).should have(1).digital_asset end it 'supports service query by product_type_id' do DigitalAssetLookupService.find_documents_by_query(['420']).should have(2).digital_asset DigitalAssetLookupService.find_documents_by_query('420').should have(2).digital_asset DigitalAssetLookupService.find_documents_by_query('420').should have(2).digital_asset DigitalAssetLookupService.find_documents_by_query(['420','303']).should have(2).digital_asset DigitalAssetLookupService.find_documents_by_query('303').should have(1).digital_asset DigitalAssetLookupService.find_documents_by_query('333').should have(0).digital_asset DigitalAssetLookupService.find_documents_by_query().should have(2).digital_asset end it 'supports service query by content_type_id' do DigitalAssetLookupService.find_documents_by_query(nil, ['909']).should have(1).digital_asset DigitalAssetLookupService.find_documents_by_query(nil, '909').should have(1).digital_asset end it 'supports service query by product_type_id and content_type_id' do DigitalAssetLookupService.find_documents_by_query(['303','420'], '909').should have(1).digital_asset end it 'supports service query by product_type_id, content_type_id and audience_ids' do DigitalAssetLookupService.find_documents_by_query(['303','420'], '909', ['690']).should have(1).digital_asset end it 'supports service query by product_type_id and finra' do DigitalAssetLookupService.find_documents_by_query('420',nil,nil,true).should have(1).digital_asset end end end