Sha256: 6ba43009db6b02bbb22c506c4030c05965eda2a074fad0c9acf6bb9170b71c17

Contents?: true

Size: 1.36 KB

Versions: 1

Compression:

Stored size: 1.36 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.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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
gummi-0.0.6 spec/lib/gummi/repository_spec.rb