ontology_search_spec.rb revision 2ccb326df5485515157d8f4cc2116f9ac0857289
1516N/Arequire 'spec_helper'
565N/A
565N/Adescribe OntologySearch do
565N/A WebMock.allow_net_connect!(net_http_connect_on_start: true)
565N/A context 'OntologySearch' do
565N/A let!(:os) { OntologySearch.new }
565N/A
565N/A let!(:l1) { create :logic }
565N/A let!(:l2) { create :logic }
565N/A let!(:l3) { create :logic, name: o1.name }
565N/A
565N/A let!(:o1) { create :ontology, logic: l1 }
565N/A let!(:o2) { create :ontology, logic: l2 }
565N/A let!(:o3) { create :ontology, logic: l3 }
565N/A
565N/A let(:e1) { create :entity }
565N/A let(:e2) { create :entity, name: o1.name }
565N/A let(:e3) { create :entity }
565N/A
565N/A let(:ontologies) { [o1, o2, o3] }
565N/A let(:entities) { [e1, e2, e3] }
926N/A let(:logics) { [l1, l2, l3] }
926N/A
2197N/A let(:keywords) do
926N/A [
565N/A {'item' => nil, 'type' => 'OntologyType'},
2026N/A {'item' => nil, 'type' => 'Project'},
1050N/A {'item' => nil, 'type' => 'FormalityLevel'},
926N/A {'item' => nil, 'type' => 'LicenseModel'},
926N/A {'item' => nil, 'type' => 'Task'}
926N/A ]
926N/A end
926N/A
838N/A before do
565N/A o1.entities.push e1
2034N/A o2.entities.push e2
2034N/A o3.entities.push e3
2034N/A
1540N/A ontologies.map(&:save)
1540N/A
1540N/A ::Sunspot.session = ::Sunspot.session.original_session
1540N/A Ontology.reindex
1540N/A end
1968N/A
1540N/A after do
2034N/A ::Sunspot.session = ::Sunspot::Rails::StubSessionProxy.new(::Sunspot.session)
2034N/A end
2200N/A
2034N/A context 'bean list' do
2034N/A context 'with one keyword' do
2034N/A context 'be generated correctly' do
565N/A let(:keywords_search) do
1710N/A keywords + [{'type' => 'Mixed', 'item' => o1.name}]
1710N/A end
1710N/A let(:results) do
1710N/A os.make_bean_list_response(nil, keywords_search, 1).ontologies.
1710N/A map { |x| x[:name] }
1710N/A end
1710N/A
1710N/A it 'have enough results' do
1710N/A expect(results.size).to eq(ontologies.size)
1710N/A end
1710N/A
1710N/A it 'have all ontologies' do
1710N/A ontologies.each do |o|
1710N/A expect(results).to include(o.name)
1710N/A end
1710N/A end
1710N/A end
1710N/A end
1710N/A
1710N/A context 'with two keywords' do
1710N/A context 'be generated correctly' do
1710N/A let(:keywords_search) do
1710N/A keywords + [
1710N/A {'type' => 'Mixed', 'item' => o1.name},
1710N/A {'type' => 'Mixed', 'item' => e1.name}
1710N/A ]
1710N/A end
1710N/A let(:results) do
1710N/A os.make_bean_list_response(nil, keywords_search, 1).ontologies.
1710N/A map { |x| x[:name] }
1710N/A end
565N/A
565N/A it 'have one result' do
565N/A expect(results.size).to eq(1)
565N/A end
565N/A
565N/A it "have the correct ontology in the results" do
565N/A expect(results).to include(o1.name)
565N/A end
2144N/A end
2158N/A
2158N/A context 'return an empty set' do
2158N/A let(:keywords_search) do
2158N/A keywords + [
2158N/A {'type' => 'Mixed', 'item' => o2.name},
2158N/A {'type' => 'Mixed', 'item' => e1.name}
2158N/A ]
2158N/A end
2158N/A let(:results) do
2158N/A os.make_bean_list_response(nil, keywords_search, 1).ontologies.
2158N/A map { |x| x[:name] }
2158N/A end
2158N/A
2158N/A it 'have an empty result' do
2158N/A expect(results).to be_empty
2158N/A end
2158N/A end
2158N/A end
2144N/A end
2144N/A end
2144N/Aend
2144N/A