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.new(name: 'Buzz Lightyear') } it "should return an entity" do db_person.overwrite 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 end