require 'spec_helper' require 'people' describe Gummi::RepositoryLayer::Repository do let(:repository_class) { People } let(:entity_class) { Person } let(:db_class) { DB::Person } describe 'Repobahn' do it 'is included' do repository_class.should respond_to :db_class repository_class.should respond_to :entity_class repository_class.should respond_to :db_instance_to_entity end end describe '.get' do context 'existing record' do let (:db_person) { DB::Person.create name: 'Buzz Lightyear' } it 'return an entity' do person = People.get(db_person.id) person.id.should == db_person.id end end context 'missing record' do it 'returns nil' do person = People.get 'missing_id' person.should be_nil end end end describe '.search' do before do DB::Person.create name: 'Buzz Lightyear' DB::Person.create name: 'Woody' Gummi::DbLayer::DefaultIndex.refresh end it 'finds the correct documents' do result = People.search do |search| search.query_string = 'Woody' end result.total.should == 1 result.records.first.name.should == 'Woody' end it 'converts the result to entities' do result = People.search do |search| search.query_string = 'Woody' end woody = result.records.first woody.converted_name.should == 'ydooW' woody.should be_a Person end end end