Sha256: 37f744769afefe18decfe45f39acbd453d66be0d8d3878a618ff9b9dac2beb3c

Contents?: true

Size: 1.84 KB

Versions: 1

Compression:

Stored size: 1.84 KB

Contents

require 'spec_helper'

class ExampleModel
  include Gummi::Document

  attribute :test, String
end

describe Gummi::Document do

  context "included" do
    it "should add accessors for id and version" do
      m = ExampleModel.new
      m.respond_to?(:version).should be_true
      m.respond_to?(:id).should be_true
    end

    it "should add attributes methods" do
      m = ExampleModel.new(test: 'hello')
      m.test.should == 'hello'
    end
  end

  context "attributes" do

    context "date times" do
      it "should coerce from elastics strings to real Time" do
        time = Time.now
        person = DB::Person.new(born_at: time)
        person.overwrite
        person_from_es = DB::Person.get person.id
        person_from_es.born_at.should be_a Time
      end

      it "should always store time in UTC" do
        time = Time.now.in_time_zone 'CET'

        person = DB::Person.new(born_at: time)
        person.born_at.zone.should == 'UTC'
      end
    end

    context "computed_attributes" do

      let(:person) { DB::Person.new}

      it "should add them to the attributes hash" do
        person.name = "olof palme"
        person.attributes[:computed_name].should == 'OLOF PALME'
      end

      it "should compute every time" do
        person.name = "olof palme"
        person.computed_name.should == person.name.upcase
        person.name = "carl bildt"
        person.computed_name.should == person.name.upcase
      end

      it "should provide a mapping" do
        DB::Person.mapping.should include(:computed_name => {:type=>"string"})
      end
    end
  end

  context 'getting from elastic' do
    let (:person) { DB::Person.new(name: 'Buzz Lightyear') }

    it "should return an instance of the db_model" do
      person.overwrite
      person_from_es = DB::Person.get(person.id)
      person_from_es.should be_a DB::Person
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

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