Sha256: 5b04de632dcfae58acef5150139d6754f9e670b5c877883979e783cc54aa4ed1

Contents?: true

Size: 1.18 KB

Versions: 3

Compression:

Stored size: 1.18 KB

Contents

require 'spec_helper'

describe "Inspect" do
  context "#inspect" do
    before do
      @document = Doc('User') do
        key :name,  String
        key :age,   Integer
        key :email, String
      end

      @doc = @document.new(:name => 'John', :age => 29)
    end

    it "should print out non-nil attributes in alpha sorted order" do
      @doc.inspect.should =~ /_id:.*, age: 29, name: "John"/
    end

    it "should print out all attributes when (optional) include_super argument is true" do
      @doc.inspect(true).should =~ /_id:.*, age: 29, email: nil, name: "John"/
    end

    it "should include class name" do
      @doc.inspect.should =~ /^#<User/
    end

    it "should include embedded documents" do
      klass = Doc()
      pets = EDoc()

      klass.many :pets, :class => pets

      doc = klass.new(:pets => [{:name => "Kitten"}])
      doc.inspect.should =~ /_id:.*, pets: .*\[.*_id.*, name: "Kitten".*\]/
    end

    it "should include embedded document" do
      klass = Doc()
      pet = EDoc()

      klass.one :pet, :class => pet

      doc = klass.new(:pet => {:name => "Kitten"})
      doc.inspect.should =~ /_id:.*, pet: .*_id.*, name: "Kitten".*/
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
mongo_mapper-0.15.6 spec/unit/inspect_spec.rb
mongo_mapper-0.15.5 spec/unit/inspect_spec.rb
mongo_mapper-0.15.4 spec/unit/inspect_spec.rb