Sha256: 652c2d19c725d3649cf92b97325dfe319090ef78aefd0884f8631cef13005664
Contents?: true
Size: 1.98 KB
Versions: 6
Compression:
Stored size: 1.98 KB
Contents
require 'spec_helper' describe Gummi::Repository do let(:repository_model) { People } let(:entity_model) { Person } let(:db_model) { DB::Person } describe ".entity_model" do it "should default to singular version of repository_model" do People.entity_model.should == Person end end describe ".db_model" do it "should default to singular version of repository_model in the DB namespace" do People.db_model.should == DB::Person end end context "converting from db to entity" do let (:db_person) { DB::Person.new(name: 'Buzz Lightyear') } it "should map the attributes from db to entity" do person = People.to_entity_from_db(db_person) person.name.should == 'Buzz Lightyear' end it "should run hook for after_conversion" do person = People.to_entity_from_db(db_person) person.converted_name.should == db_person.name.reverse end end describe ".get" do context "existing record" do let (:db_person) { DB::Person.create(name: 'Buzz Lightyear') } it "should 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(:each) do DB::Person.create(name: 'Buzz Lightyear') DB::Person.create(name: 'Woody') Gummi::DefaultIndex.refresh end it "should find 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 "should convert 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
Version data entries
6 entries across 6 versions & 1 rubygems